@tiptap/core 2.0.0-beta.17 → 2.0.0-beta.170
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +2 -2
- package/dist/packages/core/src/CommandManager.d.ts +13 -6
- package/dist/packages/core/src/Editor.d.ts +23 -18
- package/dist/packages/core/src/EventEmitter.d.ts +8 -4
- package/dist/packages/core/src/Extension.d.ts +102 -26
- package/dist/packages/core/src/ExtensionManager.d.ts +7 -12
- package/dist/packages/core/src/InputRule.d.ts +42 -0
- package/dist/packages/core/src/Mark.d.ts +134 -30
- package/dist/packages/core/src/Node.d.ts +160 -32
- package/dist/packages/core/src/NodeView.d.ts +5 -9
- package/dist/packages/core/src/PasteRule.d.ts +42 -0
- package/dist/packages/core/src/Tracker.d.ts +11 -0
- package/dist/packages/core/src/commands/blur.d.ts +3 -3
- package/dist/packages/core/src/commands/clearContent.d.ts +3 -3
- package/dist/packages/core/src/commands/clearNodes.d.ts +3 -3
- package/dist/packages/core/src/commands/command.d.ts +2 -2
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +3 -3
- package/dist/packages/core/src/commands/deleteNode.d.ts +13 -0
- package/dist/packages/core/src/commands/deleteRange.d.ts +3 -3
- package/dist/packages/core/src/commands/deleteSelection.d.ts +3 -3
- package/dist/packages/core/src/commands/enter.d.ts +3 -3
- package/dist/packages/core/src/commands/exitCode.d.ts +3 -3
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +3 -3
- package/dist/packages/core/src/commands/first.d.ts +3 -3
- package/dist/packages/core/src/commands/focus.d.ts +5 -3
- package/dist/packages/core/src/commands/forEach.d.ts +14 -0
- package/dist/packages/core/src/commands/insertContent.d.ts +7 -3
- package/dist/packages/core/src/commands/insertContentAt.d.ts +16 -0
- package/dist/packages/core/src/commands/joinBackward.d.ts +3 -3
- package/dist/packages/core/src/commands/joinForward.d.ts +3 -3
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +3 -3
- package/dist/packages/core/src/commands/lift.d.ts +3 -3
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +3 -3
- package/dist/packages/core/src/commands/liftListItem.d.ts +3 -3
- package/dist/packages/core/src/commands/newlineInCode.d.ts +3 -3
- package/dist/packages/core/src/commands/resetAttributes.d.ts +13 -0
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +3 -3
- package/dist/packages/core/src/commands/selectAll.d.ts +3 -3
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +3 -3
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +3 -3
- package/dist/packages/core/src/commands/selectParentNode.d.ts +3 -3
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +12 -0
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +12 -0
- package/dist/packages/core/src/commands/setContent.d.ts +4 -3
- package/dist/packages/core/src/commands/setMark.d.ts +3 -3
- package/dist/packages/core/src/commands/setMeta.d.ts +12 -0
- package/dist/packages/core/src/commands/setNode.d.ts +3 -3
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +12 -0
- package/dist/packages/core/src/commands/setTextSelection.d.ts +12 -0
- package/dist/packages/core/src/commands/sinkListItem.d.ts +3 -3
- package/dist/packages/core/src/commands/splitBlock.d.ts +3 -3
- package/dist/packages/core/src/commands/splitListItem.d.ts +3 -3
- package/dist/packages/core/src/commands/toggleList.d.ts +3 -3
- package/dist/packages/core/src/commands/toggleMark.d.ts +8 -3
- package/dist/packages/core/src/commands/toggleNode.d.ts +3 -3
- package/dist/packages/core/src/commands/toggleWrap.d.ts +3 -3
- package/dist/packages/core/src/commands/undoInputRule.d.ts +3 -3
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +3 -3
- package/dist/packages/core/src/commands/unsetMark.d.ts +8 -3
- package/dist/packages/core/src/commands/updateAttributes.d.ts +13 -0
- package/dist/packages/core/src/commands/wrapIn.d.ts +3 -3
- package/dist/packages/core/src/commands/wrapInList.d.ts +3 -3
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +1 -1
- package/dist/packages/core/src/extensions/commands.d.ts +21 -15
- package/dist/packages/core/src/extensions/editable.d.ts +1 -1
- package/dist/packages/core/src/extensions/focusEvents.d.ts +1 -1
- package/dist/packages/core/src/extensions/index.d.ts +1 -0
- package/dist/packages/core/src/extensions/keymap.d.ts +1 -1
- package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +7 -0
- package/dist/packages/core/src/helpers/createChainableState.d.ts +5 -0
- package/dist/packages/core/src/helpers/createDocument.d.ts +3 -4
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +4 -5
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +2 -0
- package/dist/packages/core/src/helpers/findChildren.d.ts +3 -0
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +6 -0
- package/dist/packages/core/src/helpers/findParentNode.d.ts +1 -1
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +1 -1
- package/dist/packages/core/src/helpers/generateHTML.d.ts +2 -2
- package/dist/packages/core/src/helpers/generateJSON.d.ts +2 -0
- package/dist/packages/core/src/helpers/generateText.d.ts +5 -0
- package/dist/packages/core/src/helpers/getAttributes.d.ts +3 -0
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +1 -1
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +2 -0
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +1 -2
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarkType.d.ts +1 -1
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +2 -2
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +1 -2
- package/dist/packages/core/src/helpers/getNodeType.d.ts +1 -1
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +2 -2
- package/dist/packages/core/src/helpers/getSchema.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +3 -0
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +1 -1
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +2 -2
- package/dist/packages/core/src/helpers/getText.d.ts +6 -0
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +6 -0
- package/dist/packages/core/src/helpers/getTextSeralizersFromSchema.d.ts +3 -0
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +1 -1
- package/dist/packages/core/src/helpers/isActive.d.ts +1 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
- package/dist/packages/core/src/helpers/isList.d.ts +1 -1
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +1 -2
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +1 -2
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +1 -1
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +1 -1
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +1 -1
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +1 -1
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +4 -4
- package/dist/packages/core/src/index.d.ts +51 -20
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +11 -2
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +11 -2
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +9 -0
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +14 -0
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +23 -0
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +11 -2
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +9 -0
- package/dist/packages/core/src/style.d.ts +1 -2
- package/dist/packages/core/src/types.d.ts +105 -52
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +2 -1
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +1 -2
- package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
- package/dist/packages/core/src/utilities/fromString.d.ts +1 -1
- package/dist/packages/core/src/utilities/isClass.d.ts +1 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
- package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
- package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
- package/dist/packages/core/src/utilities/isObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
- package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -2
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -2
- package/dist/packages/core/src/utilities/minMax.d.ts +1 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +3 -2
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
- package/dist/tiptap-core.cjs.js +3572 -2041
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +3544 -2044
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +3430 -1898
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +20 -16
- package/src/CommandManager.ts +60 -62
- package/src/Editor.ts +109 -74
- package/src/EventEmitter.ts +14 -4
- package/src/Extension.ts +196 -41
- package/src/ExtensionManager.ts +242 -78
- package/src/InputRule.ts +268 -0
- package/src/Mark.ts +242 -47
- package/src/Node.ts +279 -52
- package/src/NodeView.ts +105 -42
- package/src/PasteRule.ts +246 -0
- package/src/Tracker.ts +42 -0
- package/src/commands/blur.ts +12 -6
- package/src/commands/clearContent.ts +3 -3
- package/src/commands/clearNodes.ts +29 -18
- package/src/commands/command.ts +2 -2
- package/src/commands/createParagraphNear.ts +3 -3
- package/src/commands/deleteNode.ts +36 -0
- package/src/commands/deleteRange.ts +3 -3
- package/src/commands/deleteSelection.ts +3 -3
- package/src/commands/enter.ts +3 -3
- package/src/commands/exitCode.ts +3 -3
- package/src/commands/extendMarkRange.ts +10 -10
- package/src/commands/first.ts +3 -3
- package/src/commands/focus.ts +45 -44
- package/src/commands/forEach.ts +24 -0
- package/src/commands/insertContent.ts +12 -24
- package/src/commands/insertContentAt.ts +107 -0
- package/src/commands/joinBackward.ts +3 -3
- package/src/commands/joinForward.ts +3 -3
- package/src/commands/keyboardShortcut.ts +6 -6
- package/src/commands/lift.ts +5 -5
- package/src/commands/liftEmptyBlock.ts +3 -3
- package/src/commands/liftListItem.ts +4 -4
- package/src/commands/newlineInCode.ts +3 -3
- package/src/commands/resetAttributes.ts +61 -0
- package/src/commands/scrollIntoView.ts +3 -3
- package/src/commands/selectAll.ts +8 -6
- package/src/commands/selectNodeBackward.ts +3 -3
- package/src/commands/selectNodeForward.ts +3 -3
- package/src/commands/selectParentNode.ts +3 -3
- package/src/commands/selectTextblockEnd.ts +19 -0
- package/src/commands/selectTextblockStart.ts +19 -0
- package/src/commands/setContent.ts +7 -11
- package/src/commands/setMark.ts +35 -12
- package/src/commands/setMeta.ts +18 -0
- package/src/commands/setNode.ts +27 -6
- package/src/commands/setNodeSelection.ts +28 -0
- package/src/commands/setTextSelection.ts +32 -0
- package/src/commands/sinkListItem.ts +4 -4
- package/src/commands/splitBlock.ts +14 -9
- package/src/commands/splitListItem.ts +41 -15
- package/src/commands/toggleList.ts +82 -18
- package/src/commands/toggleMark.ts +17 -7
- package/src/commands/toggleNode.ts +5 -5
- package/src/commands/toggleWrap.ts +8 -9
- package/src/commands/undoInputRule.ts +34 -5
- package/src/commands/unsetAllMarks.ts +7 -11
- package/src/commands/unsetMark.ts +34 -22
- package/src/commands/updateAttributes.ts +72 -0
- package/src/commands/wrapIn.ts +4 -10
- package/src/commands/wrapInList.ts +4 -4
- package/src/extensions/clipboardTextSerializer.ts +13 -35
- package/src/extensions/commands.ts +30 -21
- package/src/extensions/focusEvents.ts +0 -3
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +111 -13
- package/src/extensions/tabindex.ts +19 -0
- package/src/helpers/combineTransactionSteps.ts +18 -0
- package/src/helpers/createChainableState.ts +37 -0
- package/src/helpers/createDocument.ts +5 -7
- package/src/helpers/createNodeFromContent.ts +15 -18
- package/src/helpers/defaultBlockAt.ts +13 -0
- package/src/helpers/findChildren.ts +17 -0
- package/src/helpers/findChildrenInRange.ts +31 -0
- package/src/helpers/findParentNode.ts +2 -2
- package/src/helpers/findParentNodeClosestToPos.ts +1 -1
- package/src/helpers/generateHTML.ts +5 -5
- package/src/helpers/generateJSON.ts +13 -0
- package/src/helpers/generateText.ts +29 -0
- package/src/helpers/getAttributes.ts +27 -0
- package/src/helpers/getAttributesFromExtensions.ts +28 -7
- package/src/helpers/getChangedRanges.ts +82 -0
- package/src/helpers/getDebugJSON.ts +53 -0
- package/src/helpers/getExtensionField.ts +25 -0
- package/src/helpers/getHTMLFromFragment.ts +6 -5
- package/src/helpers/getMarkAttributes.ts +12 -9
- package/src/helpers/getMarkRange.ts +34 -6
- package/src/helpers/getMarkType.ts +5 -1
- package/src/helpers/getMarksBetween.ts +31 -10
- package/src/helpers/getNodeAttributes.ts +7 -8
- package/src/helpers/getNodeType.ts +5 -1
- package/src/helpers/getRenderedAttributes.ts +4 -6
- package/src/helpers/getSchema.ts +6 -133
- package/src/helpers/getSchemaByResolvedExtensions.ts +147 -0
- package/src/helpers/getSchemaTypeByName.ts +2 -10
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getSplittedAttributes.ts +4 -4
- package/src/helpers/getText.ts +18 -0
- package/src/helpers/getTextBetween.ts +45 -0
- package/src/helpers/getTextSeralizersFromSchema.ts +9 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +15 -17
- package/src/helpers/isActive.ts +4 -5
- package/src/helpers/isExtensionRulesEnabled.ts +15 -0
- package/src/helpers/isList.ts +14 -7
- package/src/helpers/isMarkActive.ts +43 -19
- package/src/helpers/isNodeActive.ts +26 -34
- package/src/helpers/isNodeEmpty.ts +1 -1
- package/src/helpers/isNodeSelection.ts +2 -2
- package/src/helpers/isTextSelection.ts +2 -2
- package/src/helpers/posToDOMRect.ts +34 -0
- package/src/helpers/resolveFocusPosition.ts +34 -0
- package/src/helpers/selectionToInsertionEnd.ts +1 -1
- package/src/helpers/splitExtensions.ts +1 -1
- package/src/index.ts +53 -20
- package/src/inputRules/markInputRule.ts +58 -39
- package/src/inputRules/nodeInputRule.ts +44 -11
- package/src/inputRules/textInputRule.ts +35 -0
- package/src/inputRules/textblockTypeInputRule.ts +37 -0
- package/src/inputRules/wrappingInputRule.ts +59 -0
- package/src/pasteRules/markPasteRule.ts +61 -53
- package/src/pasteRules/textPasteRule.ts +35 -0
- package/src/style.ts +16 -3
- package/src/types.ts +119 -37
- package/src/utilities/callOrReturn.ts +6 -3
- package/src/utilities/createStyleTag.ts +8 -1
- package/src/utilities/deleteProps.ts +2 -4
- package/src/utilities/elementFromString.ts +4 -5
- package/src/utilities/escapeForRegEx.ts +4 -0
- package/src/utilities/findDuplicates.ts +5 -0
- package/src/utilities/fromString.ts +2 -2
- package/src/utilities/isClass.ts +2 -2
- package/src/utilities/isEmptyObject.ts +2 -2
- package/src/utilities/isFunction.ts +3 -0
- package/src/utilities/isMacOS.ts +5 -0
- package/src/utilities/isNumber.ts +3 -0
- package/src/utilities/isObject.ts +6 -6
- package/src/utilities/isPlainObject.ts +8 -5
- package/src/utilities/isRegExp.ts +3 -0
- package/src/utilities/isString.ts +3 -0
- package/src/utilities/isiOS.ts +12 -0
- package/src/utilities/mergeAttributes.ts +2 -3
- package/src/utilities/mergeDeep.ts +2 -3
- package/src/utilities/minMax.ts +1 -1
- package/src/utilities/objectIncludes.ts +17 -5
- package/src/utilities/removeDuplicates.ts +15 -0
- package/CHANGELOG.md +0 -324
- package/dist/packages/core/src/commands/insertHTML.d.ts +0 -12
- package/dist/packages/core/src/commands/insertNode.d.ts +0 -13
- package/dist/packages/core/src/commands/insertText.d.ts +0 -12
- package/dist/packages/core/src/commands/replace.d.ts +0 -13
- package/dist/packages/core/src/commands/replaceRange.d.ts +0 -13
- package/dist/packages/core/src/commands/resetNodeAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/updateNodeAttributes.d.ts +0 -13
- package/dist/packages/core/src/utilities/removeElement.d.ts +0 -1
- package/dist/tiptap-core.bundle.umd.min.js +0 -17
- package/dist/tiptap-core.bundle.umd.min.js.map +0 -1
- package/src/commands/insertHTML.ts +0 -30
- package/src/commands/insertNode.ts +0 -33
- package/src/commands/insertText.ts +0 -22
- package/src/commands/replace.ts +0 -20
- package/src/commands/replaceRange.ts +0 -36
- package/src/commands/resetNodeAttributes.ts +0 -31
- package/src/commands/updateNodeAttributes.ts +0 -33
- package/src/utilities/removeElement.ts +0 -5
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Node as ProseMirrorNode } from 'prosemirror-model'
|
|
2
|
+
import { JSONContent } from '../types'
|
|
3
|
+
|
|
4
|
+
interface DebugJSONContent extends JSONContent {
|
|
5
|
+
from: number,
|
|
6
|
+
to: number,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONContent {
|
|
10
|
+
const isTopNode = node.type === node.type.schema.topNodeType
|
|
11
|
+
const increment = isTopNode ? 0 : 1
|
|
12
|
+
const from = startOffset
|
|
13
|
+
const to = from + node.nodeSize
|
|
14
|
+
const marks = node.marks.map(mark => {
|
|
15
|
+
const output: { type: string, attrs?: Record<string, any> } = {
|
|
16
|
+
type: mark.type.name,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (Object.keys(mark.attrs).length) {
|
|
20
|
+
output.attrs = { ...mark.attrs }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return output
|
|
24
|
+
})
|
|
25
|
+
const attrs = { ...node.attrs }
|
|
26
|
+
const output: DebugJSONContent = {
|
|
27
|
+
type: node.type.name,
|
|
28
|
+
from,
|
|
29
|
+
to,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Object.keys(attrs).length) {
|
|
33
|
+
output.attrs = attrs
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (marks.length) {
|
|
37
|
+
output.marks = marks
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (node.content.childCount) {
|
|
41
|
+
output.content = []
|
|
42
|
+
|
|
43
|
+
node.forEach((child, offset) => {
|
|
44
|
+
output.content?.push(getDebugJSON(child, startOffset + offset + increment))
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (node.text) {
|
|
49
|
+
output.text = node.text
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return output
|
|
53
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AnyExtension, RemoveThis, MaybeThisParameterType } from '../types'
|
|
2
|
+
|
|
3
|
+
export function getExtensionField<T = any>(
|
|
4
|
+
extension: AnyExtension,
|
|
5
|
+
field: string,
|
|
6
|
+
context?: Omit<MaybeThisParameterType<T>, 'parent'>,
|
|
7
|
+
): RemoveThis<T> {
|
|
8
|
+
|
|
9
|
+
if (extension.config[field] === undefined && extension.parent) {
|
|
10
|
+
return getExtensionField(extension.parent, field, context)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof extension.config[field] === 'function') {
|
|
14
|
+
const value = extension.config[field].bind({
|
|
15
|
+
...context,
|
|
16
|
+
parent: extension.parent
|
|
17
|
+
? getExtensionField(extension.parent, field, context)
|
|
18
|
+
: null,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return value
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return extension.config[field]
|
|
25
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DOMSerializer, Schema, Fragment } from 'prosemirror-model'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
const
|
|
3
|
+
export function getHTMLFromFragment(fragment: Fragment, schema: Schema): string {
|
|
4
|
+
const documentFragment = DOMSerializer
|
|
5
5
|
.fromSchema(schema)
|
|
6
|
-
.serializeFragment(
|
|
6
|
+
.serializeFragment(fragment)
|
|
7
7
|
|
|
8
8
|
const temporaryDocument = document.implementation.createHTMLDocument()
|
|
9
9
|
const container = temporaryDocument.createElement('div')
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
container.appendChild(documentFragment)
|
|
11
12
|
|
|
12
13
|
return container.innerHTML
|
|
13
14
|
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { EditorState } from 'prosemirror-state'
|
|
2
2
|
import { Mark, MarkType } from 'prosemirror-model'
|
|
3
|
-
import getMarkType from './getMarkType'
|
|
4
|
-
import { AnyObject } from '../types'
|
|
3
|
+
import { getMarkType } from './getMarkType'
|
|
5
4
|
|
|
6
|
-
export
|
|
5
|
+
export function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): Record<string, any> {
|
|
7
6
|
const type = getMarkType(typeOrName, state.schema)
|
|
8
7
|
const { from, to, empty } = state.selection
|
|
9
|
-
|
|
8
|
+
const marks: Mark[] = []
|
|
10
9
|
|
|
11
10
|
if (empty) {
|
|
12
|
-
|
|
11
|
+
if (state.storedMarks) {
|
|
12
|
+
marks.push(...state.storedMarks)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
marks.push(...state.selection.$head.marks())
|
|
13
16
|
} else {
|
|
14
17
|
state.doc.nodesBetween(from, to, node => {
|
|
15
|
-
marks
|
|
18
|
+
marks.push(...node.marks)
|
|
16
19
|
})
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
const mark = marks.find(markItem => markItem.type.name === type.name)
|
|
20
23
|
|
|
21
|
-
if (mark) {
|
|
22
|
-
return {
|
|
24
|
+
if (!mark) {
|
|
25
|
+
return {}
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
return {}
|
|
28
|
+
return { ...mark.attrs }
|
|
26
29
|
}
|
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
import { MarkType, ResolvedPos } from 'prosemirror-model'
|
|
1
|
+
import { Mark as ProseMirrorMark, MarkType, ResolvedPos } from 'prosemirror-model'
|
|
2
|
+
import { objectIncludes } from '../utilities/objectIncludes'
|
|
2
3
|
import { Range } from '../types'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
function findMarkInSet(
|
|
6
|
+
marks: ProseMirrorMark[],
|
|
7
|
+
type: MarkType,
|
|
8
|
+
attributes: Record<string, any> = {},
|
|
9
|
+
): ProseMirrorMark | undefined {
|
|
10
|
+
return marks.find(item => {
|
|
11
|
+
return item.type === type && objectIncludes(item.attrs, attributes)
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isMarkInSet(
|
|
16
|
+
marks: ProseMirrorMark[],
|
|
17
|
+
type: MarkType,
|
|
18
|
+
attributes: Record<string, any> = {},
|
|
19
|
+
): boolean {
|
|
20
|
+
return !!findMarkInSet(marks, type, attributes)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getMarkRange(
|
|
24
|
+
$pos: ResolvedPos,
|
|
25
|
+
type: MarkType,
|
|
26
|
+
attributes: Record<string, any> = {},
|
|
27
|
+
): Range | void {
|
|
5
28
|
if (!$pos || !type) {
|
|
6
29
|
return
|
|
7
30
|
}
|
|
@@ -12,9 +35,9 @@ export default function getMarkRange($pos: ResolvedPos, type: MarkType): Range |
|
|
|
12
35
|
return
|
|
13
36
|
}
|
|
14
37
|
|
|
15
|
-
const
|
|
38
|
+
const mark = findMarkInSet(start.node.marks, type, attributes)
|
|
16
39
|
|
|
17
|
-
if (!
|
|
40
|
+
if (!mark) {
|
|
18
41
|
return
|
|
19
42
|
}
|
|
20
43
|
|
|
@@ -23,12 +46,17 @@ export default function getMarkRange($pos: ResolvedPos, type: MarkType): Range |
|
|
|
23
46
|
let endIndex = startIndex + 1
|
|
24
47
|
let endPos = startPos + start.node.nodeSize
|
|
25
48
|
|
|
26
|
-
|
|
49
|
+
findMarkInSet(start.node.marks, type, attributes)
|
|
50
|
+
|
|
51
|
+
while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
|
|
27
52
|
startIndex -= 1
|
|
28
53
|
startPos -= $pos.parent.child(startIndex).nodeSize
|
|
29
54
|
}
|
|
30
55
|
|
|
31
|
-
while (
|
|
56
|
+
while (
|
|
57
|
+
endIndex < $pos.parent.childCount
|
|
58
|
+
&& isMarkInSet($pos.parent.child(endIndex).marks, type, attributes)
|
|
59
|
+
) {
|
|
32
60
|
endPos += $pos.parent.child(endIndex).nodeSize
|
|
33
61
|
endIndex += 1
|
|
34
62
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { MarkType, Schema } from 'prosemirror-model'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function getMarkType(nameOrType: string | MarkType, schema: Schema): MarkType {
|
|
4
4
|
if (typeof nameOrType === 'string') {
|
|
5
|
+
if (!schema.marks[nameOrType]) {
|
|
6
|
+
throw Error(`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`)
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
return schema.marks[nameOrType]
|
|
6
10
|
}
|
|
7
11
|
|
|
@@ -1,16 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Node as ProseMirrorNode } from 'prosemirror-model'
|
|
2
2
|
import { MarkRange } from '../types'
|
|
3
|
+
import { getMarkRange } from './getMarkRange'
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
-
|
|
5
|
+
export function getMarksBetween(from: number, to: number, doc: ProseMirrorNode): MarkRange[] {
|
|
6
|
+
const marks: MarkRange[] = []
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
// get all inclusive marks on empty selection
|
|
9
|
+
if (from === to) {
|
|
10
|
+
doc
|
|
11
|
+
.resolve(from)
|
|
12
|
+
.marks()
|
|
13
|
+
.forEach(mark => {
|
|
14
|
+
const $pos = doc.resolve(from - 1)
|
|
15
|
+
const range = getMarkRange($pos, mark.type)
|
|
16
|
+
|
|
17
|
+
if (!range) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
marks.push({
|
|
22
|
+
mark,
|
|
23
|
+
...range,
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
} else {
|
|
27
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
28
|
+
marks.push(...node.marks.map(mark => ({
|
|
29
|
+
from: pos,
|
|
30
|
+
to: pos + node.nodeSize,
|
|
31
|
+
mark,
|
|
32
|
+
})))
|
|
33
|
+
})
|
|
34
|
+
}
|
|
14
35
|
|
|
15
36
|
return marks
|
|
16
37
|
}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { EditorState } from 'prosemirror-state'
|
|
2
2
|
import { Node, NodeType } from 'prosemirror-model'
|
|
3
|
-
import getNodeType from './getNodeType'
|
|
4
|
-
import { AnyObject } from '../types'
|
|
3
|
+
import { getNodeType } from './getNodeType'
|
|
5
4
|
|
|
6
|
-
export
|
|
5
|
+
export function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): Record<string, any> {
|
|
7
6
|
const type = getNodeType(typeOrName, state.schema)
|
|
8
7
|
const { from, to } = state.selection
|
|
9
|
-
|
|
8
|
+
const nodes: Node[] = []
|
|
10
9
|
|
|
11
10
|
state.doc.nodesBetween(from, to, node => {
|
|
12
|
-
nodes
|
|
11
|
+
nodes.push(node)
|
|
13
12
|
})
|
|
14
13
|
|
|
15
14
|
const node = nodes
|
|
16
15
|
.reverse()
|
|
17
16
|
.find(nodeItem => nodeItem.type.name === type.name)
|
|
18
17
|
|
|
19
|
-
if (node) {
|
|
20
|
-
return {
|
|
18
|
+
if (!node) {
|
|
19
|
+
return {}
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
return {}
|
|
22
|
+
return { ...node.attrs }
|
|
24
23
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { NodeType, Schema } from 'prosemirror-model'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType {
|
|
4
4
|
if (typeof nameOrType === 'string') {
|
|
5
|
+
if (!schema.nodes[nameOrType]) {
|
|
6
|
+
throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`)
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
return schema.nodes[nameOrType]
|
|
6
10
|
}
|
|
7
11
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Node, Mark } from 'prosemirror-model'
|
|
2
|
-
import { ExtensionAttribute
|
|
3
|
-
import mergeAttributes from '../utilities/mergeAttributes'
|
|
2
|
+
import { ExtensionAttribute } from '../types'
|
|
3
|
+
import { mergeAttributes } from '../utilities/mergeAttributes'
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): Record<string, any> {
|
|
6
6
|
return extensionAttributes
|
|
7
7
|
.filter(item => item.attribute.rendered)
|
|
8
8
|
.map(item => {
|
|
@@ -14,7 +14,5 @@ export default function getRenderedAttributes(nodeOrMark: Node | Mark, extension
|
|
|
14
14
|
|
|
15
15
|
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
|
|
16
16
|
})
|
|
17
|
-
.reduce((attributes, attribute) => {
|
|
18
|
-
return mergeAttributes(attributes, attribute)
|
|
19
|
-
}, {})
|
|
17
|
+
.reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})
|
|
20
18
|
}
|
package/src/helpers/getSchema.ts
CHANGED
|
@@ -1,137 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from 'prosemirror-model'
|
|
2
|
+
import { getSchemaByResolvedExtensions } from './getSchemaByResolvedExtensions'
|
|
3
|
+
import { ExtensionManager } from '../ExtensionManager'
|
|
2
4
|
import { Extensions } from '../types'
|
|
3
|
-
import { ExtensionConfig, NodeConfig, MarkConfig } from '..'
|
|
4
|
-
import splitExtensions from './splitExtensions'
|
|
5
|
-
import getAttributesFromExtensions from './getAttributesFromExtensions'
|
|
6
|
-
import getRenderedAttributes from './getRenderedAttributes'
|
|
7
|
-
import isEmptyObject from '../utilities/isEmptyObject'
|
|
8
|
-
import injectExtensionAttributesToParseRule from './injectExtensionAttributesToParseRule'
|
|
9
|
-
import callOrReturn from '../utilities/callOrReturn'
|
|
10
5
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
if (key === 'attrs' && isEmptyObject(value)) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
6
|
+
export function getSchema(extensions: Extensions): Schema {
|
|
7
|
+
const resolvedExtensions = ExtensionManager.resolve(extensions)
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
})) as T
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default function getSchema(extensions: Extensions): Schema {
|
|
22
|
-
const allAttributes = getAttributesFromExtensions(extensions)
|
|
23
|
-
const { nodeExtensions, markExtensions } = splitExtensions(extensions)
|
|
24
|
-
const topNode = nodeExtensions.find(extension => extension.config.topNode)?.config.name
|
|
25
|
-
const nodeSchemaExtenders: (
|
|
26
|
-
| ExtensionConfig['extendNodeSchema']
|
|
27
|
-
| NodeConfig['extendNodeSchema']
|
|
28
|
-
| MarkConfig['extendNodeSchema']
|
|
29
|
-
)[] = []
|
|
30
|
-
const markSchemaExtenders: (
|
|
31
|
-
| ExtensionConfig['extendNodeSchema']
|
|
32
|
-
| NodeConfig['extendNodeSchema']
|
|
33
|
-
| MarkConfig['extendNodeSchema']
|
|
34
|
-
)[] = []
|
|
35
|
-
|
|
36
|
-
extensions.forEach(extension => {
|
|
37
|
-
if (typeof extension.config.extendNodeSchema === 'function') {
|
|
38
|
-
nodeSchemaExtenders.push(extension.config.extendNodeSchema)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (typeof extension.config.extendMarkSchema === 'function') {
|
|
42
|
-
markSchemaExtenders.push(extension.config.extendMarkSchema)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const nodes = Object.fromEntries(nodeExtensions.map(extension => {
|
|
47
|
-
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.config.name)
|
|
48
|
-
const context = { options: extension.options }
|
|
49
|
-
|
|
50
|
-
const extraNodeFields = nodeSchemaExtenders.reduce((fields, nodeSchemaExtender) => {
|
|
51
|
-
const extraFields = callOrReturn(nodeSchemaExtender, context, extension)
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
...fields,
|
|
55
|
-
...extraFields,
|
|
56
|
-
}
|
|
57
|
-
}, {})
|
|
58
|
-
|
|
59
|
-
const schema: NodeSpec = cleanUpSchemaItem({
|
|
60
|
-
...extraNodeFields,
|
|
61
|
-
content: callOrReturn(extension.config.content, context),
|
|
62
|
-
marks: callOrReturn(extension.config.marks, context),
|
|
63
|
-
group: callOrReturn(extension.config.group, context),
|
|
64
|
-
inline: callOrReturn(extension.config.inline, context),
|
|
65
|
-
atom: callOrReturn(extension.config.atom, context),
|
|
66
|
-
selectable: callOrReturn(extension.config.selectable, context),
|
|
67
|
-
draggable: callOrReturn(extension.config.draggable, context),
|
|
68
|
-
code: callOrReturn(extension.config.code, context),
|
|
69
|
-
defining: callOrReturn(extension.config.defining, context),
|
|
70
|
-
isolating: callOrReturn(extension.config.isolating, context),
|
|
71
|
-
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
|
|
72
|
-
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
|
|
73
|
-
})),
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
if (extension.config.parseHTML) {
|
|
77
|
-
schema.parseDOM = extension.config.parseHTML
|
|
78
|
-
.bind(context)()
|
|
79
|
-
?.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (extension.config.renderHTML) {
|
|
83
|
-
schema.toDOM = node => (extension.config.renderHTML as Function)?.bind(context)({
|
|
84
|
-
node,
|
|
85
|
-
HTMLAttributes: getRenderedAttributes(node, extensionAttributes),
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return [extension.config.name, schema]
|
|
90
|
-
}))
|
|
91
|
-
|
|
92
|
-
const marks = Object.fromEntries(markExtensions.map(extension => {
|
|
93
|
-
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.config.name)
|
|
94
|
-
const context = { options: extension.options }
|
|
95
|
-
|
|
96
|
-
const extraMarkFields = markSchemaExtenders.reduce((fields, markSchemaExtender) => {
|
|
97
|
-
const extraFields = callOrReturn(markSchemaExtender, context, extension)
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
...fields,
|
|
101
|
-
...extraFields,
|
|
102
|
-
}
|
|
103
|
-
}, {})
|
|
104
|
-
|
|
105
|
-
const schema: MarkSpec = cleanUpSchemaItem({
|
|
106
|
-
...extraMarkFields,
|
|
107
|
-
inclusive: callOrReturn(extension.config.inclusive, context),
|
|
108
|
-
excludes: callOrReturn(extension.config.excludes, context),
|
|
109
|
-
group: callOrReturn(extension.config.group, context),
|
|
110
|
-
spanning: callOrReturn(extension.config.spanning, context),
|
|
111
|
-
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
|
|
112
|
-
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
|
|
113
|
-
})),
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
if (extension.config.parseHTML) {
|
|
117
|
-
schema.parseDOM = extension.config.parseHTML
|
|
118
|
-
.bind(context)()
|
|
119
|
-
?.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (extension.config.renderHTML) {
|
|
123
|
-
schema.toDOM = mark => (extension.config.renderHTML as Function)?.bind(context)({
|
|
124
|
-
mark,
|
|
125
|
-
HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return [extension.config.name, schema]
|
|
130
|
-
}))
|
|
131
|
-
|
|
132
|
-
return new Schema({
|
|
133
|
-
topNode,
|
|
134
|
-
nodes,
|
|
135
|
-
marks,
|
|
136
|
-
})
|
|
9
|
+
return getSchemaByResolvedExtensions(resolvedExtensions)
|
|
137
10
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { NodeSpec, MarkSpec, Schema } from 'prosemirror-model'
|
|
2
|
+
import { AnyConfig, Extensions } from '../types'
|
|
3
|
+
import { NodeConfig, MarkConfig } from '..'
|
|
4
|
+
import { splitExtensions } from './splitExtensions'
|
|
5
|
+
import { getAttributesFromExtensions } from './getAttributesFromExtensions'
|
|
6
|
+
import { getRenderedAttributes } from './getRenderedAttributes'
|
|
7
|
+
import { isEmptyObject } from '../utilities/isEmptyObject'
|
|
8
|
+
import { injectExtensionAttributesToParseRule } from './injectExtensionAttributesToParseRule'
|
|
9
|
+
import { callOrReturn } from '../utilities/callOrReturn'
|
|
10
|
+
import { getExtensionField } from './getExtensionField'
|
|
11
|
+
|
|
12
|
+
function cleanUpSchemaItem<T>(data: T) {
|
|
13
|
+
return Object.fromEntries(Object.entries(data).filter(([key, value]) => {
|
|
14
|
+
if (key === 'attrs' && isEmptyObject(value)) {
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return value !== null && value !== undefined
|
|
19
|
+
})) as T
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getSchemaByResolvedExtensions(extensions: Extensions): Schema {
|
|
23
|
+
const allAttributes = getAttributesFromExtensions(extensions)
|
|
24
|
+
const { nodeExtensions, markExtensions } = splitExtensions(extensions)
|
|
25
|
+
const topNode = nodeExtensions.find(extension => getExtensionField(extension, 'topNode'))?.name
|
|
26
|
+
|
|
27
|
+
const nodes = Object.fromEntries(nodeExtensions.map(extension => {
|
|
28
|
+
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
|
29
|
+
const context = {
|
|
30
|
+
name: extension.name,
|
|
31
|
+
options: extension.options,
|
|
32
|
+
storage: extension.storage,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const extraNodeFields = extensions.reduce((fields, e) => {
|
|
36
|
+
const extendNodeSchema = getExtensionField<AnyConfig['extendNodeSchema']>(
|
|
37
|
+
e,
|
|
38
|
+
'extendNodeSchema',
|
|
39
|
+
context,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
...fields,
|
|
44
|
+
...(extendNodeSchema ? extendNodeSchema(extension) : {}),
|
|
45
|
+
}
|
|
46
|
+
}, {})
|
|
47
|
+
|
|
48
|
+
const schema: NodeSpec = cleanUpSchemaItem({
|
|
49
|
+
...extraNodeFields,
|
|
50
|
+
content: callOrReturn(getExtensionField<NodeConfig['content']>(extension, 'content', context)),
|
|
51
|
+
marks: callOrReturn(getExtensionField<NodeConfig['marks']>(extension, 'marks', context)),
|
|
52
|
+
group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),
|
|
53
|
+
inline: callOrReturn(getExtensionField<NodeConfig['inline']>(extension, 'inline', context)),
|
|
54
|
+
atom: callOrReturn(getExtensionField<NodeConfig['atom']>(extension, 'atom', context)),
|
|
55
|
+
selectable: callOrReturn(getExtensionField<NodeConfig['selectable']>(extension, 'selectable', context)),
|
|
56
|
+
draggable: callOrReturn(getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context)),
|
|
57
|
+
code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),
|
|
58
|
+
defining: callOrReturn(getExtensionField<NodeConfig['defining']>(extension, 'defining', context)),
|
|
59
|
+
isolating: callOrReturn(getExtensionField<NodeConfig['isolating']>(extension, 'isolating', context)),
|
|
60
|
+
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
|
|
61
|
+
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
|
|
62
|
+
})),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const parseHTML = callOrReturn(getExtensionField<NodeConfig['parseHTML']>(extension, 'parseHTML', context))
|
|
66
|
+
|
|
67
|
+
if (parseHTML) {
|
|
68
|
+
schema.parseDOM = parseHTML
|
|
69
|
+
.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const renderHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)
|
|
73
|
+
|
|
74
|
+
if (renderHTML) {
|
|
75
|
+
schema.toDOM = node => renderHTML({
|
|
76
|
+
node,
|
|
77
|
+
HTMLAttributes: getRenderedAttributes(node, extensionAttributes),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const renderText = getExtensionField<NodeConfig['renderText']>(extension, 'renderText', context)
|
|
82
|
+
|
|
83
|
+
if (renderText) {
|
|
84
|
+
schema.toText = renderText
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return [extension.name, schema]
|
|
88
|
+
}))
|
|
89
|
+
|
|
90
|
+
const marks = Object.fromEntries(markExtensions.map(extension => {
|
|
91
|
+
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
|
92
|
+
const context = {
|
|
93
|
+
name: extension.name,
|
|
94
|
+
options: extension.options,
|
|
95
|
+
storage: extension.storage,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const extraMarkFields = extensions.reduce((fields, e) => {
|
|
99
|
+
const extendMarkSchema = getExtensionField<AnyConfig['extendMarkSchema']>(
|
|
100
|
+
e,
|
|
101
|
+
'extendMarkSchema',
|
|
102
|
+
context,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
...fields,
|
|
107
|
+
...(extendMarkSchema ? extendMarkSchema(extension) : {}),
|
|
108
|
+
}
|
|
109
|
+
}, {})
|
|
110
|
+
|
|
111
|
+
const schema: MarkSpec = cleanUpSchemaItem({
|
|
112
|
+
...extraMarkFields,
|
|
113
|
+
inclusive: callOrReturn(getExtensionField<MarkConfig['inclusive']>(extension, 'inclusive', context)),
|
|
114
|
+
excludes: callOrReturn(getExtensionField<MarkConfig['excludes']>(extension, 'excludes', context)),
|
|
115
|
+
group: callOrReturn(getExtensionField<MarkConfig['group']>(extension, 'group', context)),
|
|
116
|
+
spanning: callOrReturn(getExtensionField<MarkConfig['spanning']>(extension, 'spanning', context)),
|
|
117
|
+
code: callOrReturn(getExtensionField<MarkConfig['code']>(extension, 'code', context)),
|
|
118
|
+
attrs: Object.fromEntries(extensionAttributes.map(extensionAttribute => {
|
|
119
|
+
return [extensionAttribute.name, { default: extensionAttribute?.attribute?.default }]
|
|
120
|
+
})),
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const parseHTML = callOrReturn(getExtensionField<MarkConfig['parseHTML']>(extension, 'parseHTML', context))
|
|
124
|
+
|
|
125
|
+
if (parseHTML) {
|
|
126
|
+
schema.parseDOM = parseHTML
|
|
127
|
+
.map(parseRule => injectExtensionAttributesToParseRule(parseRule, extensionAttributes))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const renderHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)
|
|
131
|
+
|
|
132
|
+
if (renderHTML) {
|
|
133
|
+
schema.toDOM = mark => renderHTML({
|
|
134
|
+
mark,
|
|
135
|
+
HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return [extension.name, schema]
|
|
140
|
+
}))
|
|
141
|
+
|
|
142
|
+
return new Schema({
|
|
143
|
+
topNode,
|
|
144
|
+
nodes,
|
|
145
|
+
marks,
|
|
146
|
+
})
|
|
147
|
+
}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { MarkType, NodeType, Schema } from 'prosemirror-model'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
return schema.nodes[name]
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (schema.marks[name]) {
|
|
9
|
-
return schema.marks[name]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return null
|
|
3
|
+
export function getSchemaTypeByName(name: string, schema: Schema): NodeType | MarkType | null {
|
|
4
|
+
return schema.nodes[name] || schema.marks[name] || null
|
|
13
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from 'prosemirror-model'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function getSchemaTypeNameByName(name: string, schema: Schema): 'node' | 'mark' | null {
|
|
4
4
|
if (schema.nodes[name]) {
|
|
5
5
|
return 'node'
|
|
6
6
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtensionAttribute } from '../types'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function getSplittedAttributes(
|
|
4
4
|
extensionAttributes: ExtensionAttribute[],
|
|
5
5
|
typeName: string,
|
|
6
|
-
attributes:
|
|
7
|
-
):
|
|
6
|
+
attributes: Record<string, any>,
|
|
7
|
+
): Record<string, any> {
|
|
8
8
|
return Object.fromEntries(Object
|
|
9
9
|
.entries(attributes)
|
|
10
10
|
.filter(([name]) => {
|