-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/articles' into fix/#304-softbreak-plugin
- Loading branch information
Showing
17 changed files
with
211 additions
and
38 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
4 changes: 2 additions & 2 deletions
4
src/components/NFTArticle/SlateEditor/Elements/RenderElements.tsx
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
57 changes: 57 additions & 0 deletions
57
src/components/NFTArticle/SlateEditor/Plugins/SlateBreaksPlugin.ts
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 { Transforms, Path, NodeEntry, Node } from "slate"; | ||
import { EnhanceEditorWith, FxEditor } from "../../../../types/ArticleEditor/Editor"; | ||
import { lookupElementAtSelection } from "../utils"; | ||
import { getArticleBlockDefinition } from "../Elements/Blocks"; | ||
|
||
export enum EBreakBehavior { | ||
"default" = "default", | ||
"insertParagraph" = "insertParagraph", | ||
"insertParagraphIfEmpty" = "insertParagraphIfEmpty", | ||
"nothing" = "nothing", | ||
} | ||
|
||
export type ShouldDefaultInsertBreak = boolean; | ||
export type InsertBreakFunction = (editor: FxEditor, element: NodeEntry) => ShouldDefaultInsertBreak | void | ||
export const breakBehaviors: Record<EBreakBehavior, InsertBreakFunction> = { | ||
default: () => true, | ||
insertParagraph: (editor, element) => { | ||
const [, pathEl] = element; | ||
const pathNextEl = Path.next(pathEl) | ||
Transforms.splitNodes(editor, { always: true }); | ||
Transforms.setNodes(editor, { type: 'paragraph'}, { | ||
at: pathNextEl, | ||
}); | ||
}, | ||
insertParagraphIfEmpty: (editor, element) => { | ||
const [node] = element; | ||
const text = Node.string(node); | ||
if (text) return true; | ||
breakBehaviors.insertParagraph(editor, element) | ||
}, | ||
nothing: () => {}, | ||
} | ||
|
||
/** | ||
* Manage break behavior of elements | ||
*/ | ||
export const withBreaks: EnhanceEditorWith = (editor) => { | ||
const { insertBreak } = editor | ||
|
||
editor.insertBreak = () => { | ||
const { selection } = editor; | ||
const nodeEntry = lookupElementAtSelection(editor, selection); | ||
if (nodeEntry) { | ||
const [node] = nodeEntry; | ||
const definition = getArticleBlockDefinition(node.type); | ||
const behavior = definition.insertBreakBehavior; | ||
if (behavior) { | ||
const insertBreakFunction = typeof behavior === 'function' ? behavior : breakBehaviors[behavior] | ||
const shouldDefaultInsertBreak = insertBreakFunction(editor, nodeEntry); | ||
if (!shouldDefaultInsertBreak) return; | ||
} | ||
} | ||
insertBreak(); | ||
} | ||
|
||
return editor | ||
} |
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
7 changes: 5 additions & 2 deletions
7
src/components/NFTArticle/SlateEditor/Utils/BlockMenu.module.scss
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,11 +1,14 @@ | ||
.root { | ||
position: absolute; | ||
|
||
visibility: hidden; | ||
&.pos-up { | ||
bottom: -30px; | ||
} | ||
|
||
&.pos-down { | ||
top: -3px; | ||
} | ||
} | ||
} | ||
.show { | ||
visibility: visible; | ||
} |
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
Oops, something went wrong.