platejs 54.0.0-beta.2 → 54.0.0-beta.4
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/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +56 -0
- package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/react/AIChatPlugin.js +113 -78
- package/dist/ai/react/CopilotPlugin.js +1 -1
- package/dist/ai/react/index.d.ts +23 -16
- package/dist/authored/index.d.ts +4 -4
- package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
- package/dist/code-block/codemirror/index.d.ts +1 -1
- package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
- package/dist/diff/index.d.ts +2 -2
- package/dist/docs/ai.md +4 -3
- package/dist/docs/api/core/plate-components.md +0 -19
- package/dist/docs/api/core/plate-controller.md +5 -3
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/core.md +45 -5
- package/dist/docs/api/dom.md +11 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +45 -13
- package/dist/docs/authored-changes.md +9 -4
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/block-placeholder.md +4 -2
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +118 -10
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/comment.md +2 -2
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/document-model.md +15 -3
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- package/dist/docs/editor.md +50 -4
- package/dist/docs/examples/editable-voids.md +2 -3
- package/dist/docs/external-text.md +2 -0
- package/dist/docs/field.md +370 -0
- package/dist/docs/find.md +9 -6
- package/dist/docs/form.md +2 -0
- package/dist/docs/heading.md +6 -0
- package/dist/docs/installation/manual.md +0 -4
- package/dist/docs/link.md +3 -3
- package/dist/docs/llms.txt +4 -2
- package/dist/docs/markdown.md +270 -14
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +66 -15
- package/dist/docs/prompt-editor.md +205 -0
- package/dist/docs/roots.md +8 -6
- package/dist/docs/rtl.md +6 -4
- package/dist/docs/selection.md +7 -4
- package/dist/docs/suggestion.md +1 -1
- package/dist/docs/toolbar.md +26 -30
- package/dist/docs/upload.md +106 -17
- package/dist/docx/export/index.d.ts +3 -3
- package/dist/docx/export/lib/docxStaticComponents.js +12 -2
- package/dist/docx/export/lib/exportDocx.js +46 -17
- package/dist/docx/export/lib/internal/xml-builder.js +11 -16
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +52 -10
- package/dist/docx/import/index.d.ts +4 -4
- package/dist/docx/paste/index.d.ts +4 -4
- package/dist/dom/index.d.ts +1 -6
- package/dist/dom/plite-dom.internal.js +2 -2
- package/dist/excalidraw/index.d.ts +3 -2
- package/dist/excalidraw/react/index.d.ts +3 -2
- package/dist/facade.js +2 -2
- package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
- package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
- package/dist/features/board/index.d.ts +2 -2
- package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
- package/dist/features/board/lib/boardStroke.internal.js +13 -1
- package/dist/features/board/lib/boardTypes.internal.js +16 -0
- package/dist/features/callout/index.d.ts +3 -2
- package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
- package/dist/features/combobox/index.d.ts +2 -2
- package/dist/features/comments/BaseCommentsPlugin.js +33 -17
- package/dist/features/comments/index.d.ts +1 -1
- package/dist/features/date/index.d.ts +3 -2
- package/dist/features/details/index.d.ts +3 -2
- package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +4 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
- package/dist/features/field/lib/applyFieldValues.js +188 -0
- package/dist/features/field/lib/fieldRules.internal.js +204 -0
- package/dist/features/find/index.d.ts +3 -2
- package/dist/features/footnote/index.d.ts +1 -1
- package/dist/features/ink/index.d.ts +1 -1
- package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
- package/dist/features/ink/lib/inkCodec.internal.js +130 -0
- package/dist/features/ink/lib/inkGone.internal.js +229 -48
- package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
- package/dist/features/layout/index.d.ts +1 -1
- package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
- package/dist/features/lint/index.d.ts +3 -2
- package/dist/features/media/index.d.ts +2 -2
- package/dist/features/media/index.js +2 -2
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
- package/dist/features/mention/index.d.ts +5 -4
- package/dist/features/suggestion/index.d.ts +1 -1
- package/dist/features/table/index.d.ts +1 -1
- package/dist/features/table/lib/BaseTablePlugin.js +64 -15
- package/dist/features/table/lib/internal/selection.js +4 -2
- package/dist/features/toc/index.d.ts +1 -1
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
- package/dist/history/index.d.ts +2 -2
- package/dist/html/index.d.ts +3 -3
- package/dist/html/server/index.d.ts +1 -1
- package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
- package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
- package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
- package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
- package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
- package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
- package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
- package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
- package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
- package/dist/index-C9Fu-P4E.d.ts +773 -0
- package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
- package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
- package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
- package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
- package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
- package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
- package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
- package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
- package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
- package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
- package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
- package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
- package/dist/index.d.ts +4 -4
- package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
- package/dist/internal/plugin/OverridePlugin.js +101 -119
- package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
- package/dist/internal/plugin/pastedUploadFiles.js +4 -0
- package/dist/internal/plugin/resolvePlugin.js +1 -1
- package/dist/internal/plugin/resolvePlugins.js +3 -0
- package/dist/internal/plugin/uploadDrafts.js +6 -0
- package/dist/internal/utils/mergePlugins.js +1 -0
- package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
- package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
- package/dist/lib/plugins/html/htmlSafety.js +1 -1
- package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +3 -1
- package/dist/markdown/lib/MarkdownPlugin.js +14 -11
- package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +776 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
- package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
- package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
- package/dist/markdown/lib/internal/markdownLine.js +5 -3
- package/dist/markdown/lib/internal/markdownMappings.js +19 -7
- package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
- package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +29 -9
- package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
- package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
- package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
- package/dist/math/index.d.ts +3 -2
- package/dist/math/react/index.d.ts +4 -3
- package/dist/migrations/index.d.ts +3 -3
- package/dist/migrations/migratePlateV54.js +4 -6
- package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
- package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
- package/dist/migrations/v53-manifest.internal.js +4 -0
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +42 -23
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +102 -128
- package/dist/react/components/PlateContainer.js +40 -32
- package/dist/react/components/PlateController.js +28 -16
- package/dist/react/components/PlateRoot.internal.js +3 -2
- package/dist/react/core.js +4 -4
- package/dist/react/features/board/BoardSurface.js +116 -87
- package/dist/react/features/board/boardClipboard.internal.js +15 -5
- package/dist/react/features/board/boardExport.internal.js +470 -0
- package/dist/react/features/board/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +190 -50
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +108 -18
- package/dist/react/features/callout/index.d.ts +3 -2
- package/dist/react/features/combobox/index.d.ts +8 -8
- package/dist/react/features/comments/index.d.ts +6 -5
- package/dist/react/features/date/index.d.ts +4 -3
- package/dist/react/features/details/index.d.ts +4 -3
- package/dist/react/features/field/FieldPlugin.js +35 -0
- package/dist/react/features/field/index.d.ts +315 -0
- package/dist/react/features/field/index.js +2 -0
- package/dist/react/features/footnote/index.d.ts +7 -6
- package/dist/react/features/format-painter/index.d.ts +4 -3
- package/dist/react/features/ink/InkContent.js +313 -0
- package/dist/react/features/ink/index.d.ts +57 -33
- package/dist/react/features/ink/index.js +2 -2
- package/dist/react/features/ink/inkCapture.internal.js +39 -17
- package/dist/react/features/ink/inkInput.internal.js +1 -1
- package/dist/react/features/ink/inkLayout.internal.js +6 -3
- package/dist/react/features/ink/inkPaint.internal.js +78 -2
- package/dist/react/features/ink/inkPlacement.internal.js +332 -104
- package/dist/react/features/ink/inkWatch.internal.js +7 -5
- package/dist/react/features/layout/index.d.ts +5 -4
- package/dist/react/features/media/index.d.ts +5 -4
- package/dist/react/features/mention/index.d.ts +6 -5
- package/dist/react/features/resizable/Resizable.js +4 -6
- package/dist/react/features/resizable/index.d.ts +5 -5
- package/dist/react/features/suggestion/index.d.ts +6 -5
- package/dist/react/features/table/TablePlugin.js +4 -11
- package/dist/react/features/table/index.d.ts +10 -8
- package/dist/react/features/table/useTableResize.js +10 -1
- package/dist/react/features/toc/index.d.ts +2 -2
- package/dist/react/features/upload/index.d.ts +11 -6
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +4 -4
- package/dist/react/internal/plate-context.js +434 -188
- package/dist/react/plite-react.js +2 -2
- package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
- package/dist/react/stores/plate/useEditor.js +32 -14
- package/dist/react/stores/plate/useEditorHistory.js +55 -0
- package/dist/react/stores/plate/useEditorSelector.js +79 -21
- package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
- package/dist/react/utils/pipeRenderElement.internal.js +1 -1
- package/dist/react/utils/pluginRenderElement.internal.js +1 -1
- package/dist/react/virtualized.d.ts +4 -4
- package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
- package/dist/static/index.d.ts +18 -18
- package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
- package/dist/static/internal/staticPresentation.js +4 -4
- package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
- package/dist/tabbable/index.d.ts +1 -1
- package/dist/tabbable/react/index.d.ts +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/react/index.d.ts +6 -6
- package/package.json +20 -2
- package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
- package/dist/react/components/EditorSelectionView.js +0 -40
- package/dist/react/features/ink/InkLayer.js +0 -218
- package/dist/react/internal/createPlateTargetScope.js +0 -62
|
@@ -35,132 +35,114 @@ const OverridePlugin = definePlugin("override", {}).extend(({ editor }) => {
|
|
|
35
35
|
};
|
|
36
36
|
const shouldRemoveEmptyMergeTarget = (node, path) => resolveStructuralRule("merge.removeEmpty", node, path) === true;
|
|
37
37
|
return {
|
|
38
|
-
commands: ({ around, handle }) => [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const isAtStart = state.selection.isAtBlockStart();
|
|
92
|
-
const result = next();
|
|
93
|
-
if (result === false) return false;
|
|
94
|
-
return state.transaction.extend(result, (tx) => {
|
|
95
|
-
tx.blocks.reset({ at: isAtStart ? blockPath : PathApi.next(blockPath) });
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return next();
|
|
99
|
-
}),
|
|
100
|
-
around(editorCommands.delete, ({ state, next }) => {
|
|
101
|
-
const selection = state.selection();
|
|
102
|
-
if (!selection || !state.selection.isCollapsed()) return next();
|
|
103
|
-
const block = state.nodes.block({ at: selection.focus });
|
|
104
|
-
if (!block) return next();
|
|
105
|
-
const [blockNode, blockPath] = block;
|
|
106
|
-
if (resolveStructuralRule("delete.empty", blockNode, blockPath) !== "reset") return next();
|
|
38
|
+
commands: ({ around, handle }) => [around(editorCommands.insertBreak, ({ next, state }) => {
|
|
39
|
+
const selection = state.selection();
|
|
40
|
+
const block = selection ? state.nodes.block({ at: selection.focus }) : void 0;
|
|
41
|
+
if (!selection || !block) return next();
|
|
42
|
+
const [blockNode, blockPath] = block;
|
|
43
|
+
const runAction = (action) => {
|
|
44
|
+
if (!action || ![
|
|
45
|
+
"none",
|
|
46
|
+
"reset",
|
|
47
|
+
"lineBreak",
|
|
48
|
+
"lift",
|
|
49
|
+
"exit",
|
|
50
|
+
"deleteExit"
|
|
51
|
+
].includes(action) || action === "lift" && blockPath.length === 0) return null;
|
|
52
|
+
if ((action === "exit" || action === "deleteExit") && !state.selection.isCollapsed()) return null;
|
|
53
|
+
let exitRefused = false;
|
|
54
|
+
let resetRefused = false;
|
|
55
|
+
const transaction = state.transaction((tx) => {
|
|
56
|
+
if (action === "none") return;
|
|
57
|
+
if (action === "reset") {
|
|
58
|
+
resetRefused = !tx.blocks.reset({ at: blockPath });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (action === "lineBreak") {
|
|
62
|
+
tx.break.insertSoft();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (action === "lift") {
|
|
66
|
+
tx.nodes.lift({ at: blockPath });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (action === "deleteExit") tx.text.deleteBackward({ unit: "character" });
|
|
70
|
+
exitRefused = !tx.break.exit();
|
|
71
|
+
});
|
|
72
|
+
if (resetRefused) return null;
|
|
73
|
+
return exitRefused ? false : transaction;
|
|
74
|
+
};
|
|
75
|
+
if (state.selection.isCollapsed() && state.nodes.isEmpty(blockNode)) {
|
|
76
|
+
const action = runAction(resolveStructuralRule("break.empty", blockNode, blockPath));
|
|
77
|
+
if (action !== null) return action;
|
|
78
|
+
}
|
|
79
|
+
if (state.selection.isCollapsed() && !state.nodes.isEmpty(blockNode) && state.points.isEnd(selection.anchor, blockPath) && (() => {
|
|
80
|
+
const before = state.points.before(selection, { unit: "character" });
|
|
81
|
+
const range = before ? state.ranges.get(before, selection) : void 0;
|
|
82
|
+
return range ? state.text.string(range) : "";
|
|
83
|
+
})() === "\n") {
|
|
84
|
+
const action = runAction(resolveStructuralRule("break.emptyLineEnd", blockNode, blockPath));
|
|
85
|
+
if (action !== null) return action;
|
|
86
|
+
}
|
|
87
|
+
const defaultAction = runAction(resolveStructuralRule("break.default", blockNode, blockPath));
|
|
88
|
+
if (defaultAction !== null) return defaultAction;
|
|
89
|
+
if (resolveStructuralRule("break.splitReset", blockNode, blockPath) === true && !state.selection.isAcrossBlocks()) {
|
|
90
|
+
const isAtStart = state.selection.isAtBlockStart();
|
|
107
91
|
const result = next();
|
|
108
92
|
if (result === false) return false;
|
|
109
93
|
return state.transaction.extend(result, (tx) => {
|
|
110
|
-
|
|
111
|
-
const nextBlock = nextSelection ? tx.nodes.block({ at: nextSelection.focus }) : void 0;
|
|
112
|
-
if (nextBlock && PathApi.equals(nextBlock[1], blockPath) && tx.nodes.isEmpty(nextBlock[0])) tx.blocks.reset({ at: blockPath });
|
|
94
|
+
tx.blocks.reset({ at: isAtStart ? blockPath : PathApi.next(blockPath) });
|
|
113
95
|
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
96
|
+
}
|
|
97
|
+
return next();
|
|
98
|
+
}), handle(editorCommands.delete, ({ input, state }) => {
|
|
99
|
+
const selectAdjacentBlockVoid = (adjacent, current) => {
|
|
100
|
+
if (!adjacent || !ElementApi.isElement(adjacent[0]) || !state.schema.isVoid(adjacent[0])) return null;
|
|
101
|
+
const start = state.points.start(adjacent[1]);
|
|
102
|
+
if (!start) return null;
|
|
103
|
+
return state.transaction((tx) => {
|
|
104
|
+
tx.selection.set(start);
|
|
105
|
+
if (tx.nodes.isEmpty(current[0])) tx.nodes.remove({ at: current[1] });
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const runDeleteAction = (action, blockPath) => {
|
|
109
|
+
if (action !== "reset" && !(action === "lift" && blockPath.length > 0)) return null;
|
|
110
|
+
let applied = true;
|
|
111
|
+
const transaction = state.transaction((tx) => {
|
|
112
|
+
if (action === "reset") applied = tx.blocks.reset({ at: blockPath });
|
|
113
|
+
else tx.nodes.lift({ at: blockPath });
|
|
114
|
+
});
|
|
115
|
+
return applied ? transaction : null;
|
|
116
|
+
};
|
|
117
|
+
const selection = state.selection();
|
|
118
|
+
if (!selection || !state.selection.isCollapsed()) return false;
|
|
119
|
+
const block = state.nodes.block({ at: selection.focus });
|
|
120
|
+
if (input.direction === "forward") {
|
|
121
|
+
if (block && state.points.isEnd(selection.anchor, block[1])) {
|
|
122
|
+
const transaction = selectAdjacentBlockVoid(state.nodes.next({ at: block[1] }), block);
|
|
123
|
+
if (transaction) return transaction;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (block) {
|
|
128
|
+
const [blockNode, blockPath] = block;
|
|
129
|
+
if (state.points.isStart(selection.anchor, blockPath)) {
|
|
130
|
+
const previous = state.nodes.previous({ at: blockPath });
|
|
131
|
+
if (previous && ElementApi.isElement(previous[0]) && !state.schema.isVoid(previous[0]) && !state.schema.isIsolating(previous[0]) && previous[0].children.length > 0 && NodeApi.string(previous[0]).length === 0 && (!shouldRemoveEmptyMergeTarget(previous[0], previous[1]) || state.nodes.isEmpty(previous[0]) && !shouldMergeNodesRemovePrevNode(editor, previous, block))) return state.transaction((tx) => {
|
|
132
|
+
tx.nodes.merge({ at: blockPath });
|
|
131
133
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const block = state.nodes.block({ at: selection.focus });
|
|
137
|
-
if (input.direction === "forward") {
|
|
138
|
-
if (block && state.points.isEnd(selection.anchor, block[1])) {
|
|
139
|
-
const transaction = selectAdjacentBlockVoid(state.nodes.next({ at: block[1] }), block);
|
|
140
|
-
if (transaction) return transaction;
|
|
141
|
-
}
|
|
142
|
-
return false;
|
|
134
|
+
const selectAdjacent = selectAdjacentBlockVoid(previous, [blockNode, blockPath]);
|
|
135
|
+
if (selectAdjacent) return selectAdjacent;
|
|
136
|
+
const ruleTransaction = runDeleteAction(resolveStructuralRule("delete.start", blockNode, blockPath), blockPath);
|
|
137
|
+
if (ruleTransaction) return ruleTransaction;
|
|
143
138
|
}
|
|
144
|
-
if (
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
const previous = state.nodes.previous({ at: blockPath });
|
|
148
|
-
if (previous && ElementApi.isElement(previous[0]) && !state.schema.isVoid(previous[0]) && !state.schema.isIsolating(previous[0]) && previous[0].children.length > 0 && NodeApi.string(previous[0]).length === 0 && (!shouldRemoveEmptyMergeTarget(previous[0], previous[1]) || state.nodes.isEmpty(previous[0]) && !shouldMergeNodesRemovePrevNode(editor, previous, block))) return state.transaction((tx) => {
|
|
149
|
-
tx.nodes.merge({ at: blockPath });
|
|
150
|
-
});
|
|
151
|
-
const selectAdjacent = selectAdjacentBlockVoid(previous, [blockNode, blockPath]);
|
|
152
|
-
if (selectAdjacent) return selectAdjacent;
|
|
153
|
-
const ruleTransaction = runDeleteAction(resolveStructuralRule("delete.start", blockNode, blockPath), blockPath);
|
|
154
|
-
if (ruleTransaction) return ruleTransaction;
|
|
155
|
-
}
|
|
156
|
-
if (ElementApi.isElement(blockNode) && state.nodes.isEmpty(blockNode)) {
|
|
157
|
-
const ruleTransaction = runDeleteAction(resolveStructuralRule("delete.empty", blockNode, blockPath), blockPath);
|
|
158
|
-
if (ruleTransaction) return ruleTransaction;
|
|
159
|
-
}
|
|
139
|
+
if (ElementApi.isElement(blockNode) && state.nodes.isEmpty(blockNode)) {
|
|
140
|
+
const ruleTransaction = runDeleteAction(resolveStructuralRule("delete.empty", blockNode, blockPath), blockPath);
|
|
141
|
+
if (ruleTransaction) return ruleTransaction;
|
|
160
142
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
],
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
})],
|
|
164
146
|
readMiddleware: ({ around }) => [around(editorReads.nodes.shouldMergeNodesRemovePrevNode, ({ input: { current, previous }, next, state }) => {
|
|
165
147
|
const [previousNode, previousPath] = previous;
|
|
166
148
|
const [, currentPath] = current;
|
|
@@ -13,7 +13,11 @@ const collect = (editor) => {
|
|
|
13
13
|
getPlateRuntime(editor).pluginList.forEach((owner) => {
|
|
14
14
|
if (!isRecord(owner.formats)) return;
|
|
15
15
|
const { formats } = owner;
|
|
16
|
-
[
|
|
16
|
+
[
|
|
17
|
+
"docx",
|
|
18
|
+
"markdown",
|
|
19
|
+
"plainText"
|
|
20
|
+
].forEach((format) => {
|
|
17
21
|
const value = formats[format];
|
|
18
22
|
if (value === void 0) return;
|
|
19
23
|
(Array.isArray(value) ? value : [value]).forEach((declaration) => {
|
|
@@ -59,7 +59,7 @@ const assertNativeTopology = (plugin, field, contribution) => {
|
|
|
59
59
|
const applyFormats = (plugin, formats) => {
|
|
60
60
|
if (formats[pluginFormatMapDeclaration] !== true) throw new Error(`Plate plugin "${plugin.name}" formats must be declared with the context-bound \`defineFormats(...)\` helper.`);
|
|
61
61
|
const { html: htmlMapping, ...productMappings } = formats;
|
|
62
|
-
for (const format of Object.keys(productMappings)) if (format !== "markdown" && format !== "plainText") throw new Error(`Plate plugin "${plugin.name}" declares unknown format "${format}".`);
|
|
62
|
+
for (const format of Object.keys(productMappings)) if (format !== "docx" && format !== "markdown" && format !== "plainText") throw new Error(`Plate plugin "${plugin.name}" declares unknown format "${format}".`);
|
|
63
63
|
let currentFormats = Reflect.get(plugin, "formats");
|
|
64
64
|
if (Reflect.ownKeys(productMappings).length > 0) {
|
|
65
65
|
if (isObjectRecord(currentFormats)) {
|
|
@@ -71,6 +71,7 @@ const createMutablePlatePluginCache = () => ({
|
|
|
71
71
|
afterNodeChildren: [],
|
|
72
72
|
beforeContainer: [],
|
|
73
73
|
beforeEditable: [],
|
|
74
|
+
caret: [],
|
|
74
75
|
wrapContent: [],
|
|
75
76
|
wrapNode: [],
|
|
76
77
|
wrapNodeChildren: [],
|
|
@@ -365,6 +366,7 @@ const createPlateModelPublication = (editor, identity, applicationSchema, plugin
|
|
|
365
366
|
if (plugin.slots.afterEditable) pluginCache.slots.afterEditable.push(plugin.name);
|
|
366
367
|
if (plugin.slots.beforeContainer) pluginCache.slots.beforeContainer.push(plugin.name);
|
|
367
368
|
if (plugin.slots.beforeEditable) pluginCache.slots.beforeEditable.push(plugin.name);
|
|
369
|
+
if (plugin.slots.caret) pluginCache.slots.caret.push(plugin.name);
|
|
368
370
|
if (plugin.slots.wrapNodeChildren) pluginCache.slots.wrapNodeChildren.push(plugin.name);
|
|
369
371
|
if (plugin.slots.afterNodeChildren) pluginCache.slots.afterNodeChildren.push(plugin.name);
|
|
370
372
|
for (const key of STRUCTURAL_RULE_KEYS) {
|
|
@@ -407,6 +409,7 @@ const createPlateModelPublication = (editor, identity, applicationSchema, plugin
|
|
|
407
409
|
afterNodeChildren: freezeList(pluginCache.slots.afterNodeChildren),
|
|
408
410
|
beforeContainer: freezeList(pluginCache.slots.beforeContainer),
|
|
409
411
|
beforeEditable: freezeList(pluginCache.slots.beforeEditable),
|
|
412
|
+
caret: freezeList(pluginCache.slots.caret),
|
|
410
413
|
wrapContent: freezeList(pluginCache.slots.wrapContent),
|
|
411
414
|
wrapNode: freezeList(pluginCache.slots.wrapNode),
|
|
412
415
|
wrapNodeChildren: freezeList(pluginCache.slots.wrapNodeChildren),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PLUGINS } from "../../utils/plate-keys.js";
|
|
2
|
+
//#region src/internal/plugin/uploadDrafts.ts
|
|
3
|
+
const UPLOAD_COMMIT_TAG = "upload";
|
|
4
|
+
const uploadDraftsOf = (tx) => tx.plugins.has(PLUGINS.upload) ? { admit: tx.plugin(PLUGINS.upload).admit } : void 0;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { UPLOAD_COMMIT_TAG, uploadDraftsOf };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ElementApi, MAIN_ROOT_KEY, getEditorCommitNode, property, registerEditorTransactionGuard, schema, target } from "../../../facade.js";
|
|
1
|
+
import { ElementApi, MAIN_ROOT_KEY, getEditorCommitNode, property, readElementById, registerEditorTransactionGuard, schema, target } from "../../../facade.js";
|
|
2
2
|
import { definePlugin } from "../../plugin/definePlugin.js";
|
|
3
3
|
import { assertElementId, elementIdDocumentRoots } from "./elementIdAdmission.internal.js";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
5
|
+
//#region src/lib/plugins/element-id/ElementIdPlugin.ts
|
|
6
|
+
const onlyRemovesNodes = (changed, root, presence) => presence.length > 0 && changed.nodeKeys("text", root).length === 0 && presence.every((key) => !changed.hasNodeKey(key, "path", root));
|
|
5
7
|
const ElementIdPlugin = definePlugin("elementId", {
|
|
6
8
|
initialState: { generateId: () => nanoid() },
|
|
7
9
|
schema: ({ initialState }) => ({ properties: { id: schema.elementProperty(property.string({ generate: initialState.generateId }), {
|
|
@@ -16,31 +18,25 @@ const ElementIdPlugin = definePlugin("elementId", {
|
|
|
16
18
|
return {
|
|
17
19
|
activate({ onCleanup }) {
|
|
18
20
|
onCleanup(registerEditorTransactionGuard(editor, ({ after, commit }) => {
|
|
21
|
+
const { changed } = commit;
|
|
19
22
|
for (const root of elementIdDocumentRoots(after)) {
|
|
20
23
|
const publicRoot = root === MAIN_ROOT_KEY ? void 0 : root;
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const writesIds = changed.has("properties", publicRoot) || changed.has("replace", publicRoot);
|
|
25
|
+
if (!writesIds && !changed.has("structure", publicRoot)) continue;
|
|
26
|
+
const presence = changed.nodeKeys("presence", publicRoot);
|
|
27
|
+
if (!writesIds && onlyRemovesNodes(changed, publicRoot, presence)) continue;
|
|
28
|
+
for (const nodeKey of /* @__PURE__ */ new Set([...changed.nodeKeys("node", publicRoot), ...presence])) {
|
|
23
29
|
const [node, path] = getEditorCommitNode(commit, nodeKey, root) ?? [];
|
|
24
30
|
if (ElementApi.isElement(node) && node.id !== void 0) assertElementId(node.id, `Element ID at ${root}:[${path}]`);
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
}));
|
|
28
34
|
},
|
|
29
|
-
read: ({ state }) => ({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...holder,
|
|
35
|
-
node
|
|
36
|
-
}) : void 0;
|
|
37
|
-
},
|
|
38
|
-
id(key) {
|
|
39
|
-
const node = state.nodes.get(key)?.[0];
|
|
40
|
-
const id = ElementApi.isElement(node) && state.schema.getProperty(node, idProperty);
|
|
41
|
-
return typeof id === "string" && state.unique.holder("id", id)?.key === key ? id : void 0;
|
|
42
|
-
}
|
|
43
|
-
})
|
|
35
|
+
read: ({ state }) => ({ id(key) {
|
|
36
|
+
const node = state.nodes.get(key)?.[0];
|
|
37
|
+
const id = ElementApi.isElement(node) && state.schema.getProperty(node, idProperty);
|
|
38
|
+
return typeof id === "string" && readElementById(state.nodes, id)?.key === key ? id : void 0;
|
|
39
|
+
} })
|
|
44
40
|
};
|
|
45
41
|
});
|
|
46
42
|
//#endregion
|
|
@@ -799,6 +799,15 @@ const PLATE_HTML_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
799
799
|
"data-editor-mention-ref",
|
|
800
800
|
"data-editor-natural-height",
|
|
801
801
|
"data-editor-natural-width",
|
|
802
|
+
"data-field-condition",
|
|
803
|
+
"data-field-default-value",
|
|
804
|
+
"data-field-id",
|
|
805
|
+
"data-field-kind",
|
|
806
|
+
"data-field-label",
|
|
807
|
+
"data-field-options",
|
|
808
|
+
"data-field-required",
|
|
809
|
+
"data-field-role",
|
|
810
|
+
"data-field-value",
|
|
802
811
|
"data-indent",
|
|
803
812
|
"data-language",
|
|
804
813
|
"data-list-id",
|
|
@@ -147,4 +147,4 @@ const sanitizeHtmlDom = (root, report) => {
|
|
|
147
147
|
sanitizeContent(root, tag);
|
|
148
148
|
};
|
|
149
149
|
//#endregion
|
|
150
|
-
export { HTML_UNSAFE_TAGS, decideHtmlAttribute, decideHtmlElement, sanitizeHtmlDom };
|
|
150
|
+
export { HTML_SURROUNDING_WHITESPACE, HTML_UNSAFE_TAGS, decideHtmlAttribute, decideHtmlElement, sanitizeHtmlDom };
|
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import { PointApi, RangeApi, editorCommands,
|
|
1
|
+
import { PointApi, RangeApi, attachTransactionSpecAfterCommit, editorCommands, getActiveCommandEditor, readEditorCommitHistoryEntry, reportEditorLifecycleError, runEditorObserver } from "../../../facade.js";
|
|
2
2
|
import { domCommands } from "../../../dom/plite-dom.internal.js";
|
|
3
3
|
import { getPlateRuntime } from "../../../internal/plugin/compilePlateModel.js";
|
|
4
4
|
import { createPlatePluginPortal } from "../../plugin/createPluginContext.internal.js";
|
|
5
5
|
import { definePlugin } from "../../plugin/definePlugin.js";
|
|
6
6
|
import { createInputRuleContinuation, createInputRuleDecline, isInputRuleContinuation, isInputRuleDecline } from "./inputRuleContinuation.internal.js";
|
|
7
|
-
import {
|
|
7
|
+
import { isInputRuleVetoed } from "./inputRuleVeto.internal.js";
|
|
8
8
|
//#region src/lib/plugins/input-rules/InputRulesPlugin.ts
|
|
9
9
|
const insertsAtCaret = (at, selection) => !at || !!selection && (RangeApi.isRange(at) ? RangeApi.equals(at, selection) : PointApi.isPoint(at) && RangeApi.isCollapsed(selection) && PointApi.equals(at, selection.anchor));
|
|
10
10
|
const INPUT_RULE_TAG = "input-rule";
|
|
11
|
+
const PEER_SKIPPED_TAGS = /* @__PURE__ */ new Set(["collaboration", "skip-collab"]);
|
|
12
|
+
const followUpRuleCache = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
const followUpRulesOf = (rules) => {
|
|
14
|
+
let followUps = followUpRuleCache.get(rules);
|
|
15
|
+
if (!followUps) {
|
|
16
|
+
followUps = rules.filter((rule) => rule.followUp !== void 0);
|
|
17
|
+
followUpRuleCache.set(rules, followUps);
|
|
18
|
+
}
|
|
19
|
+
return followUps;
|
|
20
|
+
};
|
|
21
|
+
const isThenable = (value) => (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
11
22
|
const invalidApplyResult = () => /* @__PURE__ */ new Error("An input rule must return undefined or the result of next(...) or decline().");
|
|
12
23
|
const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend(({ editor }) => {
|
|
24
|
+
const refuseThenable = (value, pluginName, message) => {
|
|
25
|
+
new Promise((resolve) => {
|
|
26
|
+
resolve(value);
|
|
27
|
+
}).then(void 0, (error) => reportEditorLifecycleError(Object.freeze({
|
|
28
|
+
cause: error,
|
|
29
|
+
editor,
|
|
30
|
+
phase: "after-commit",
|
|
31
|
+
pluginName
|
|
32
|
+
})));
|
|
33
|
+
throw new Error(message);
|
|
34
|
+
};
|
|
13
35
|
const createCachedGetter = (compute) => {
|
|
14
36
|
let hasValue = false;
|
|
15
37
|
let value;
|
|
@@ -69,6 +91,7 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
69
91
|
return value;
|
|
70
92
|
});
|
|
71
93
|
return {
|
|
94
|
+
key: state.key,
|
|
72
95
|
plugin,
|
|
73
96
|
read: state
|
|
74
97
|
};
|
|
@@ -124,16 +147,6 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
124
147
|
isCollapsed
|
|
125
148
|
};
|
|
126
149
|
};
|
|
127
|
-
const vetoTypesByRules = /* @__PURE__ */ new WeakMap();
|
|
128
|
-
const isVetoed = (state) => {
|
|
129
|
-
const { inputRules } = getPlateRuntime(editor);
|
|
130
|
-
let types = vetoTypesByRules.get(inputRules);
|
|
131
|
-
if (!types) {
|
|
132
|
-
types = [...new Set(getPluginContributions(editor, inputRuleVeto))];
|
|
133
|
-
vetoTypesByRules.set(inputRules, types);
|
|
134
|
-
}
|
|
135
|
-
return types.length > 0 && state.nodes.some({ type: types });
|
|
136
|
-
};
|
|
137
150
|
let pendingRuleKey;
|
|
138
151
|
let revertible;
|
|
139
152
|
return {
|
|
@@ -160,7 +173,7 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
160
173
|
around(domCommands.insertData, ({ input, state, next }) => {
|
|
161
174
|
const rules = getPlateRuntime(editor).inputRules.insertData;
|
|
162
175
|
const firstRule = rules[0];
|
|
163
|
-
if (!firstRule ||
|
|
176
|
+
if (!firstRule || isInputRuleVetoed(editor, state)) return next();
|
|
164
177
|
const dataTypes = new Set(input.types);
|
|
165
178
|
const selectionContext = createSelectionContext({ state });
|
|
166
179
|
const context = {
|
|
@@ -170,11 +183,9 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
170
183
|
text: input.getData("text/plain") || null,
|
|
171
184
|
...selectionContext
|
|
172
185
|
};
|
|
173
|
-
|
|
174
|
-
for (const rule of rules) {
|
|
175
|
-
context.plugin = rule.plugin;
|
|
186
|
+
const resolveRule = (rule, ruleContext) => {
|
|
176
187
|
const { enabled } = rule;
|
|
177
|
-
if (typeof enabled === "function" && !enabled(
|
|
188
|
+
if (typeof enabled === "function" && !enabled(ruleContext)) return;
|
|
178
189
|
if (rule.mimeTypes?.length && !rule.mimeTypes.some((type) => {
|
|
179
190
|
if (type === "Files") return (input.files?.length ?? 0) > 0;
|
|
180
191
|
if (dataTypes.has(type)) return true;
|
|
@@ -183,18 +194,55 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
183
194
|
} catch {
|
|
184
195
|
return false;
|
|
185
196
|
}
|
|
186
|
-
}))
|
|
197
|
+
})) return;
|
|
187
198
|
const { resolve } = rule;
|
|
188
|
-
|
|
199
|
+
return typeof resolve === "function" ? resolve(ruleContext) : true;
|
|
200
|
+
};
|
|
201
|
+
let accepted;
|
|
202
|
+
for (const rule of rules) {
|
|
203
|
+
const { apply } = rule;
|
|
204
|
+
if (!apply) continue;
|
|
205
|
+
context.plugin = rule.plugin;
|
|
206
|
+
const match = resolveRule(rule, context);
|
|
189
207
|
if (match === void 0) continue;
|
|
190
208
|
accepted = {
|
|
191
|
-
|
|
209
|
+
apply,
|
|
192
210
|
match,
|
|
193
211
|
rule
|
|
194
212
|
};
|
|
195
213
|
break;
|
|
196
214
|
}
|
|
197
|
-
|
|
215
|
+
let following;
|
|
216
|
+
for (const rule of followUpRulesOf(rules)) {
|
|
217
|
+
const match = resolveRule(rule, {
|
|
218
|
+
...context,
|
|
219
|
+
plugin: rule.plugin
|
|
220
|
+
});
|
|
221
|
+
if (match === void 0) continue;
|
|
222
|
+
if (isThenable(match)) refuseThenable(match, rule.plugin.name, "An input rule follow-up must resolve synchronously.");
|
|
223
|
+
following = {
|
|
224
|
+
match,
|
|
225
|
+
rule
|
|
226
|
+
};
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
const pastingView = following ? getActiveCommandEditor() : void 0;
|
|
230
|
+
const followed = (result) => {
|
|
231
|
+
if (!following || !pastingView || result === false || result.changes.empty) return result;
|
|
232
|
+
const { match, rule } = following;
|
|
233
|
+
return attachTransactionSpecAfterCommit(result, ({ commit }) => {
|
|
234
|
+
const replacedSelection = commit.tags.includes("replace-range");
|
|
235
|
+
const changedViewRoot = commit.changed.has("document", pastingView.read.view.root());
|
|
236
|
+
if (!readEditorCommitHistoryEntry(editor, commit) || commit.tags.some((tag) => PEER_SKIPPED_TAGS.has(tag)) || replacedSelection || !changedViewRoot || pastingView.read.view.isReadOnly()) return;
|
|
237
|
+
runEditorObserver(editor, "after-commit", () => {
|
|
238
|
+
pastingView.update({ tags: ["history-push"] }, (tx) => {
|
|
239
|
+
const returned = rule.followUp.call(rule, { tx }, match);
|
|
240
|
+
if (isThenable(returned)) refuseThenable(returned, rule.plugin.name, "An input rule follow-up must be synchronous.");
|
|
241
|
+
});
|
|
242
|
+
}, rule.plugin.name);
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
if (!accepted) return followed(next());
|
|
198
246
|
let outcome;
|
|
199
247
|
const prefix = state.transaction((tx) => {
|
|
200
248
|
let continued = false;
|
|
@@ -203,23 +251,24 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
203
251
|
continued = true;
|
|
204
252
|
return createInputRuleContinuation(data);
|
|
205
253
|
};
|
|
206
|
-
outcome = accepted.
|
|
207
|
-
...
|
|
254
|
+
outcome = accepted.apply.call(accepted.rule, {
|
|
255
|
+
...context,
|
|
208
256
|
decline: createInputRuleDecline,
|
|
209
257
|
next: ruleNext,
|
|
258
|
+
plugin: accepted.rule.plugin,
|
|
210
259
|
tx
|
|
211
260
|
}, accepted.match);
|
|
212
261
|
if (outcome !== void 0 && !isInputRuleContinuation(outcome) && !isInputRuleDecline(outcome)) throw invalidApplyResult();
|
|
213
262
|
});
|
|
214
|
-
if (outcome === void 0) return prefix;
|
|
215
|
-
if (isInputRuleDecline(outcome)) return next();
|
|
263
|
+
if (outcome === void 0) return followed(prefix);
|
|
264
|
+
if (isInputRuleDecline(outcome)) return followed(next());
|
|
216
265
|
const continuation = outcome;
|
|
217
|
-
return continuation.input === void 0 ? next.after(prefix) : next.after(prefix, continuation.input);
|
|
266
|
+
return followed(continuation.input === void 0 ? next.after(prefix) : next.after(prefix, continuation.input));
|
|
218
267
|
}),
|
|
219
268
|
around(editorCommands.insertBreak, ({ state, next }) => {
|
|
220
269
|
const rules = getPlateRuntime(editor).inputRules.insertBreak;
|
|
221
270
|
const firstRule = rules[0];
|
|
222
|
-
if (!firstRule ||
|
|
271
|
+
if (!firstRule || isInputRuleVetoed(editor, state)) return next();
|
|
223
272
|
const selectionContext = createSelectionContext({ state });
|
|
224
273
|
const context = {
|
|
225
274
|
cause: "insertBreak",
|
|
@@ -265,7 +314,7 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
265
314
|
around(editorCommands.insertText, ({ input, state, next }) => {
|
|
266
315
|
const rules = getPlateRuntime(editor).inputRules.insertText.byTrigger[input.text] ?? [];
|
|
267
316
|
const firstRule = rules[0];
|
|
268
|
-
if (!firstRule || !insertsAtCaret(input.options?.at, state.selection()) ||
|
|
317
|
+
if (!firstRule || !insertsAtCaret(input.options?.at, state.selection()) || isInputRuleVetoed(editor, state)) return next();
|
|
269
318
|
const selectionContext = createSelectionContext({ state });
|
|
270
319
|
const context = {
|
|
271
320
|
cause: "insertText",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getPluginContributions } from "../../../facade.js";
|
|
2
|
+
import { getPlateRuntime } from "../../../internal/plugin/compilePlateModel.js";
|
|
3
|
+
import { inputRuleVeto } from "./inputRuleVeto.js";
|
|
4
|
+
//#region src/lib/plugins/input-rules/inputRuleVeto.internal.ts
|
|
5
|
+
const vetoTypesByRules = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
const isInputRuleVetoed = (editor, state) => {
|
|
7
|
+
const { inputRules } = getPlateRuntime(editor);
|
|
8
|
+
let types = vetoTypesByRules.get(inputRules);
|
|
9
|
+
if (!types) {
|
|
10
|
+
types = [...new Set(getPluginContributions(editor, inputRuleVeto))];
|
|
11
|
+
vetoTypesByRules.set(inputRules, types);
|
|
12
|
+
}
|
|
13
|
+
return types.length > 0 && state.nodes.some({ type: types });
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isInputRuleVetoed };
|
package/dist/markdown/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
export { type MarkdownApi, type MarkdownDefinition, type MarkdownDiagnostic, type MarkdownDocumentParseResult, type MarkdownEditor, type MarkdownEditorSerializeOptions, type MarkdownErrorDiagnostic, type MarkdownModelLocation, type MarkdownParseLimits, type MarkdownParseOptions, type MarkdownParsePolicy, MarkdownPlugin, type MarkdownPluginState, type MarkdownSerializeOptions, type MarkdownSerializePolicy, type MarkdownSerializeResult, type MarkdownSliceParseResult, type MarkdownSourceLocation, type MarkdownSyncPluggable, type MarkdownSyncPlugin, type MarkdownSyncTransformer, type MarkdownWarningDiagnostic, parseMarkdown, serializeMarkdown };
|
|
1
|
+
import { A as MarkdownWarningDiagnostic, C as MarkdownSerializePolicy, D as MarkdownSyncPluggable, E as MarkdownSourceLocation, O as MarkdownSyncPlugin, S as MarkdownSerializeOptions, T as MarkdownSliceParseResult, _ as MarkdownFrontmatter, a as MarkdownPlugin, b as MarkdownParseOptions, c as serializeMarkdown, f as getMarkdownFrontmatter, g as MarkdownErrorDiagnostic, h as MarkdownEditorSerializeOptions, i as MarkdownEditor, k as MarkdownSyncTransformer, m as MarkdownDocumentParseResult, n as MarkdownApi, o as MarkdownPluginState, p as MarkdownDiagnostic, r as MarkdownDefinition, s as parseMarkdown, t as RawHtmlPlugin, v as MarkdownModelLocation, w as MarkdownSerializeResult, x as MarkdownParsePolicy, y as MarkdownParseLimits } from "../index-Cob_iBdu.js";
|
|
2
|
+
export { type MarkdownApi, type MarkdownDefinition, type MarkdownDiagnostic, type MarkdownDocumentParseResult, type MarkdownEditor, type MarkdownEditorSerializeOptions, type MarkdownErrorDiagnostic, type MarkdownFrontmatter, type MarkdownModelLocation, type MarkdownParseLimits, type MarkdownParseOptions, type MarkdownParsePolicy, MarkdownPlugin, type MarkdownPluginState, type MarkdownSerializeOptions, type MarkdownSerializePolicy, type MarkdownSerializeResult, type MarkdownSliceParseResult, type MarkdownSourceLocation, type MarkdownSyncPluggable, type MarkdownSyncPlugin, type MarkdownSyncTransformer, type MarkdownWarningDiagnostic, RawHtmlPlugin, getMarkdownFrontmatter, parseMarkdown, serializeMarkdown };
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { getMarkdownFrontmatter } from "./lib/internal/markdownFrontmatter.js";
|
|
2
|
+
import { RawHtmlPlugin } from "./lib/RawHtmlPlugin.js";
|
|
1
3
|
import { MarkdownPlugin, parseMarkdown, serializeMarkdown } from "./lib/MarkdownPlugin.js";
|
|
2
|
-
export { MarkdownPlugin, parseMarkdown, serializeMarkdown };
|
|
4
|
+
export { MarkdownPlugin, RawHtmlPlugin, getMarkdownFrontmatter, parseMarkdown, serializeMarkdown };
|