This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
5fa9a52
commit 5a48fda
Showing
12 changed files
with
100 additions
and
16 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,62 @@ | ||
import { Text, Transforms, Element, Node } from 'slate'; | ||
import config from '@plone/volto/registry'; | ||
import { deconstructToVoltoBlocks } from 'volto-slate/utils'; | ||
|
||
export const normalizeBlocks = (editor) => { | ||
// enforce list rules (no block elements, only ol/ul/li as possible children | ||
const { normalizeNode } = editor; | ||
const { slate } = config.settings; | ||
const validListElements = [...slate.listTypes, slate.listItemType]; | ||
|
||
editor.normalizeNode = (entry) => { | ||
let isNormalizing = false; | ||
|
||
if (!editor.voltoBlockNormalizing) { | ||
editor.voltoBlockNormalizing = true; | ||
isNormalizing = true; | ||
} | ||
|
||
const [node, path] = entry; | ||
|
||
if ( | ||
!Text.isText(node) && | ||
Element.isElement(node) && | ||
!editor.isInline(node) && | ||
!validListElements.includes(node.type) && | ||
path.length > 1 | ||
) { | ||
console.log('not inline', node, path); | ||
Transforms.liftNodes(editor, { at: path, split: true }); | ||
// for (const [child, childPath] of Node.children(editor, path)) { | ||
// if (!validListElements.includes(child.type)) { | ||
// Transforms.liftNodes(editor, { at: childPath, split: true }); | ||
// return; | ||
// } | ||
// } | ||
} | ||
// if (node.type === 'ol' || node.type === 'ul') { | ||
// if (Element.isElement(node) && slate.listTypes.includes(node.type)) { | ||
// for (const [child, childPath] of Node.children(editor, path)) { | ||
// if (!validListElements.includes(child.type)) { | ||
// Transforms.liftNodes(editor, { at: childPath, split: true }); | ||
// return; | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
// if (node.type === slate.listItemType) { | ||
// console.log('node', node); | ||
// } | ||
|
||
normalizeNode(entry); | ||
|
||
if (isNormalizing) { | ||
editor.voltoBlockNormalizing = undefined; | ||
console.log('deconstruct', editor); | ||
deconstructToVoltoBlocks(editor); | ||
} | ||
}; | ||
|
||
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
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