-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
138 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { LIST_ITEM_TYPE, LIST_SECTION_TYPE } from './types'; | ||
import { normalizeTagName } from '../utils/dom-utils'; | ||
import LinkedItem from '../utils/linked-item'; | ||
|
||
function isMarkerable(section) { | ||
return !!section.markers; | ||
} | ||
|
||
function isListSection(section) { | ||
return section.type === LIST_SECTION_TYPE; | ||
} | ||
|
||
function isListItem(section) { | ||
return section.type === LIST_ITEM_TYPE; | ||
} | ||
|
||
export default class Section extends LinkedItem { | ||
constructor(type) { | ||
super(); | ||
if (!type) { throw new Error('Cannot create section without type'); } | ||
this.type = type; | ||
} | ||
|
||
set tagName(val) { | ||
this._tagName = normalizeTagName(val); | ||
} | ||
|
||
get tagName() { | ||
return this._tagName; | ||
} | ||
|
||
immediatelyNextMarkerableSection() { | ||
const next = this.next; | ||
if (next) { | ||
if (isMarkerable(next)) { | ||
return next; | ||
} else if (isListSection(next)) { | ||
const firstListItem = next.items.head; | ||
return firstListItem; | ||
} | ||
} else if (isListItem(this)) { | ||
const listSection = this.parent; | ||
return listSection.immediatelyNextMarkerableSection(); | ||
} | ||
} | ||
|
||
immediatelyPreviousMarkerableSection() { | ||
const prev = this.prev; | ||
if (!prev) { return null; } | ||
if (isMarkerable(prev)) { | ||
return prev; | ||
} else if (isListSection(prev)) { | ||
const lastListItem = prev.items.tail; | ||
return lastListItem; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import LinkedItem from "content-kit-editor/utils/linked-item"; | ||
import Section from './_section'; | ||
import { CARD_TYPE } from './types'; | ||
|
||
export const CARD_TYPE = 'card-section'; | ||
|
||
export default class Card extends LinkedItem { | ||
export default class Card extends Section { | ||
constructor(name, payload) { | ||
super(); | ||
super(CARD_TYPE); | ||
this.name = name; | ||
this.payload = payload; | ||
this.type = CARD_TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
export const IMAGE_SECTION_TYPE = 'image-section'; | ||
import { IMAGE_SECTION_TYPE } from './types'; | ||
import Section from './_section'; | ||
|
||
export default class Image { | ||
export default class Image extends Section { | ||
constructor() { | ||
this.type = IMAGE_SECTION_TYPE; | ||
super(IMAGE_SECTION_TYPE); | ||
this.src = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const MARKUP_SECTION_TYPE = 'markup-section'; | ||
export const LIST_SECTION_TYPE = 'list-section'; | ||
export const MARKUP_TYPE = 'markup'; | ||
export const MARKER_TYPE = 'marker'; | ||
export const POST_TYPE = 'post'; | ||
export const LIST_ITEM_TYPE = 'list-item'; | ||
export const CARD_TYPE = 'card-section'; | ||
export const IMAGE_SECTION_TYPE = 'image-section'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.