platejs 54.0.0-beta.2 → 54.0.0-beta.3
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-DY104TqL.d.ts} +2 -2
- package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-Deo6n6Fs.d.ts} +7 -3
- package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-CJX5bKuv.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-DAOYWuvC.d.ts} +2 -2
- package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-Dt-unJZY-DCddmbSD.d.ts} +10 -2
- package/dist/compiler/index.d.ts +2 -2
- package/dist/{core-BJG8l_mk.d.ts → core-ClHasORr.d.ts} +433 -95
- 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 +4 -2
- package/dist/docs/api/core/plate-plugin.md +3 -0
- package/dist/docs/api/core/plate-store.md +3 -3
- package/dist/docs/api/dom.md +14 -4
- package/dist/docs/api/editor-transforms.md +2 -1
- package/dist/docs/api/react-hooks.md +25 -11
- package/dist/docs/authored-changes.md +5 -2
- package/dist/docs/basic-blocks.md +42 -29
- package/dist/docs/blockquote.md +5 -3
- package/dist/docs/board.md +63 -8
- package/dist/docs/code-block.md +47 -0
- package/dist/docs/discussion.md +1 -1
- package/dist/docs/docx.md +1 -1
- package/dist/docs/dom-coverage.md +5 -0
- 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 +176 -8
- package/dist/docs/plugin-components.md +13 -10
- package/dist/docs/plugin-input-rules.md +4 -12
- 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 +29 -5
- package/dist/docx/export/lib/reviewPart.js +1 -1
- package/dist/docx/export/lib/reviewProjection.js +10 -8
- 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/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 +10 -10
- package/dist/features/field/index.d.ts +2 -0
- package/dist/features/field/index.js +2 -0
- package/dist/features/field/lib/BaseFieldPlugin.js +414 -0
- package/dist/features/field/lib/fieldRules.internal.js +42 -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 +533 -62
- 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 +1 -1
- package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
- package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +6 -2
- 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 +14 -8
- 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-cg_cWsaN.d.ts} +2 -31
- package/dist/hyperscript/index.d.ts +1 -1
- package/dist/{index-D1CFXA-i.d.ts → index-8WO2vI0U.d.ts} +475 -143
- package/dist/{index-DaM37gF6.d.ts → index-B5mYEawV.d.ts} +37 -21
- package/dist/{index-Bq3sdm3S.d.ts → index-BZWFoUXt.d.ts} +5 -4
- package/dist/{index-DdIRduDG.d.ts → index-C0POz7rg.d.ts} +3 -2
- package/dist/{index-Bxfvicyy.d.ts → index-C1_JIhL4.d.ts} +4 -3
- package/dist/{index-DC_MNGyu.d.ts → index-C35V_hj0.d.ts} +3 -3
- package/dist/{index-kLKMc-pI.d.ts → index-C6ql9pKw.d.ts} +2 -2
- package/dist/{index-hsC_sOn2.d.ts → index-C9DiGDVj.d.ts} +35 -5
- package/dist/{index-DTgaSxKr.d.ts → index-CLsEe3LY.d.ts} +40 -4
- package/dist/{index-CT7miqQN.d.ts → index-CdOLsPaW.d.ts} +29 -9
- package/dist/{index-DLA2DUR2.d.ts → index-CktYvOgk.d.ts} +4 -3
- package/dist/{index-BBKGrsG3.d.ts → index-Cmuluh6f.d.ts} +1 -1
- package/dist/{index-BiQerPJS.d.ts → index-CzLwBZpY.d.ts} +2 -2
- package/dist/{index-DzD6BIFJ.d.ts → index-D3-2iM1b.d.ts} +7 -5
- package/dist/{index-Cl77E9yr.d.ts → index-DKOFvteF.d.ts} +2 -2
- package/dist/{index-iaZOhA76.d.ts → index-DPWyk3lG-DOYwohXO.d.ts} +1 -1
- package/dist/index-DQnjqtQa.d.ts +678 -0
- package/dist/{index-CcZbqPqk.d.ts → index-Do9pj1GK.d.ts} +73 -39
- package/dist/{index-BU6k1Aev.d.ts → index-DpltOCot-A2b3p3Eb.d.ts} +4735 -4586
- package/dist/{index-Bc2Yg_2j.d.ts → index-HPYawTae-BCUQLEWF.d.ts} +2 -2
- package/dist/{index-BkR7-GLI.d.ts → index-baQOK89E.d.ts} +2 -2
- package/dist/{index-D5W-p9bS.d.ts → index-oIJAZxc2.d.ts} +49 -4
- package/dist/{index-xdmCBvlT.d.ts → index-r7yb77Wy.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 +8 -2
- 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 +5 -15
- package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
- package/dist/markdown/index.d.ts +2 -2
- package/dist/markdown/index.js +2 -1
- package/dist/markdown/lib/MarkdownPlugin.js +16 -9
- package/dist/markdown/lib/RawHtmlPlugin.js +24 -0
- package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
- package/dist/markdown/lib/internal/markdownConversion.js +773 -74
- package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
- 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 +314 -0
- package/dist/markdown/lib/internal/markdownSegments.js +57 -48
- package/dist/markdown/lib/internal/markdownTags.js +22 -8
- 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/pagination/index.d.ts +1 -1
- package/dist/pagination/react/index.d.ts +4 -4
- package/dist/react/components/EditorContentView.internal.js +17 -8
- package/dist/react/components/EditorProvider.js +5 -5
- package/dist/react/components/Plate.js +103 -122
- 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/boardGesture.internal.js +6 -3
- package/dist/react/features/board/boardIndex.internal.js +7 -18
- package/dist/react/features/board/boardPictures.internal.js +19 -13
- package/dist/react/features/board/boardView.internal.js +184 -49
- package/dist/react/features/board/boardVoice.internal.js +10 -11
- package/dist/react/features/board/index.d.ts +64 -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 +34 -0
- package/dist/react/features/field/index.d.ts +312 -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 -29
- 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 +331 -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 +8 -7
- 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 +425 -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 +66 -21
- 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-aUwpNnAw.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
|
@@ -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 };
|
|
@@ -2,6 +2,8 @@ import { ElementApi, MAIN_ROOT_KEY, getEditorCommitNode, property, registerEdito
|
|
|
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,10 +18,14 @@ 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
|
}
|
|
@@ -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,10 +1,10 @@
|
|
|
1
|
-
import { PointApi, RangeApi, editorCommands
|
|
1
|
+
import { PointApi, RangeApi, editorCommands } 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";
|
|
@@ -124,16 +124,6 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
124
124
|
isCollapsed
|
|
125
125
|
};
|
|
126
126
|
};
|
|
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
127
|
let pendingRuleKey;
|
|
138
128
|
let revertible;
|
|
139
129
|
return {
|
|
@@ -160,7 +150,7 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
160
150
|
around(domCommands.insertData, ({ input, state, next }) => {
|
|
161
151
|
const rules = getPlateRuntime(editor).inputRules.insertData;
|
|
162
152
|
const firstRule = rules[0];
|
|
163
|
-
if (!firstRule ||
|
|
153
|
+
if (!firstRule || isInputRuleVetoed(editor, state)) return next();
|
|
164
154
|
const dataTypes = new Set(input.types);
|
|
165
155
|
const selectionContext = createSelectionContext({ state });
|
|
166
156
|
const context = {
|
|
@@ -219,7 +209,7 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
219
209
|
around(editorCommands.insertBreak, ({ state, next }) => {
|
|
220
210
|
const rules = getPlateRuntime(editor).inputRules.insertBreak;
|
|
221
211
|
const firstRule = rules[0];
|
|
222
|
-
if (!firstRule ||
|
|
212
|
+
if (!firstRule || isInputRuleVetoed(editor, state)) return next();
|
|
223
213
|
const selectionContext = createSelectionContext({ state });
|
|
224
214
|
const context = {
|
|
225
215
|
cause: "insertBreak",
|
|
@@ -265,7 +255,7 @@ const InputRulesPlugin = definePlugin("inputRules", { editOnly: true }).extend((
|
|
|
265
255
|
around(editorCommands.insertText, ({ input, state, next }) => {
|
|
266
256
|
const rules = getPlateRuntime(editor).inputRules.insertText.byTrigger[input.text] ?? [];
|
|
267
257
|
const firstRule = rules[0];
|
|
268
|
-
if (!firstRule || !insertsAtCaret(input.options?.at, state.selection()) ||
|
|
258
|
+
if (!firstRule || !insertsAtCaret(input.options?.at, state.selection()) || isInputRuleVetoed(editor, state)) return next();
|
|
269
259
|
const selectionContext = createSelectionContext({ state });
|
|
270
260
|
const context = {
|
|
271
261
|
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 { C as MarkdownSerializeResult, D as MarkdownSyncPlugin, E as MarkdownSyncPluggable, O as MarkdownSyncTransformer, S as MarkdownSerializePolicy, T as MarkdownSourceLocation, _ as MarkdownModelLocation, a as MarkdownPluginState, b as MarkdownParsePolicy, d as getMarkdownFrontmatter, f as MarkdownDiagnostic, g as MarkdownFrontmatter, h as MarkdownErrorDiagnostic, i as MarkdownPlugin, k as MarkdownWarningDiagnostic, m as MarkdownEditorSerializeOptions, n as MarkdownDefinition, o as parseMarkdown, p as MarkdownDocumentParseResult, r as MarkdownEditor, s as serializeMarkdown, t as MarkdownApi, v as MarkdownParseLimits, w as MarkdownSliceParseResult, x as MarkdownSerializeOptions, y as MarkdownParseOptions } from "../index-Do9pj1GK.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, getMarkdownFrontmatter, parseMarkdown, serializeMarkdown };
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { getMarkdownFrontmatter } from "./lib/internal/markdownFrontmatter.js";
|
|
1
2
|
import { MarkdownPlugin, parseMarkdown, serializeMarkdown } from "./lib/MarkdownPlugin.js";
|
|
2
|
-
export { MarkdownPlugin, parseMarkdown, serializeMarkdown };
|
|
3
|
+
export { MarkdownPlugin, getMarkdownFrontmatter, parseMarkdown, serializeMarkdown };
|
|
@@ -6,7 +6,7 @@ import { isUrl } from "../../lib/utils/isUrl.js";
|
|
|
6
6
|
import { PLUGINS } from "../../utils/plate-keys.js";
|
|
7
7
|
import { ElementApi, NodeApi, TextApi } from "../../core.js";
|
|
8
8
|
import { markdownMappingsRegistryKey } from "./internal/markdownMappings.js";
|
|
9
|
-
import { createMarkdownOperationRuntime, createMarkdownRuntime, parseMarkdownDocumentWithRuntime, parseMarkdownInlineWithRuntime, parseMarkdownSliceWithRuntime, prepareMarkdownRuntime, serializeMarkdownSliceWithRuntime, serializeMarkdownWithRuntime, withMarkdownRuntime } from "./internal/markdownConversion.js";
|
|
9
|
+
import { createMarkdownOperationRuntime, createMarkdownRuntime, parseMarkdownDocumentWithRuntime, parseMarkdownInlineWithRuntime, parseMarkdownSliceWithRuntime, prepareMarkdownRuntime, serializeMarkdownSliceWithRuntime, serializeMarkdownWithRuntime, withMarkdownRuntime, writesRawHtml } from "./internal/markdownConversion.js";
|
|
10
10
|
//#region src/markdown/lib/MarkdownPlugin.ts
|
|
11
11
|
const shouldParseMarkdown = (data, source) => {
|
|
12
12
|
if (source.getData("text/html")) return false;
|
|
@@ -51,17 +51,24 @@ const toMarkdownBlocks = (runtime, children) => {
|
|
|
51
51
|
};
|
|
52
52
|
const serializeMarkdownDataTransferSlice = (runtime, slice, state) => {
|
|
53
53
|
if (slice.openStart === 0 && slice.openEnd === 0) {
|
|
54
|
-
const result = serializeMarkdownSliceWithRuntime(runtime, toMarkdownBlocks(runtime, slice.content), slice.roots);
|
|
54
|
+
const { result } = serializeMarkdownSliceWithRuntime(runtime, toMarkdownBlocks(runtime, slice.content), slice.roots);
|
|
55
55
|
return result.ok ? result.data : null;
|
|
56
56
|
}
|
|
57
57
|
let failed = false;
|
|
58
|
+
let previousKind;
|
|
59
|
+
const verbatim = (text) => {
|
|
60
|
+
if (text.trim()) previousKind = "list";
|
|
61
|
+
return text;
|
|
62
|
+
};
|
|
58
63
|
const serialize = (children) => {
|
|
59
|
-
const result = serializeMarkdownSliceWithRuntime(runtime, toMarkdownBlocks(runtime, children), slice.roots);
|
|
64
|
+
const { lastKind, result } = serializeMarkdownSliceWithRuntime(runtime, toMarkdownBlocks(runtime, children), slice.roots, previousKind);
|
|
60
65
|
if (!result.ok) {
|
|
61
66
|
failed = true;
|
|
62
67
|
return "";
|
|
63
68
|
}
|
|
64
|
-
|
|
69
|
+
const data = writesRawHtml(runtime, runtime.options.plainMarks) ? result.data.replace(/\n+$/, "") : result.data.trimEnd();
|
|
70
|
+
if (data.trim()) previousKind = lastKind;
|
|
71
|
+
return data;
|
|
65
72
|
};
|
|
66
73
|
const paragraphType = runtime.registry.type(PLUGINS.paragraph) ?? "paragraph";
|
|
67
74
|
const serializeOpenNodes = (nodes, openStart, openEnd) => {
|
|
@@ -69,16 +76,16 @@ const serializeMarkdownDataTransferSlice = (runtime, slice, state) => {
|
|
|
69
76
|
return nodes.map((node, index) => serializeOpenNode(node, index === 0 ? openStart : 0, index === lastIndex ? openEnd : 0)).join("\n\n");
|
|
70
77
|
};
|
|
71
78
|
const serializeOpenNode = (node, openStart, openEnd) => {
|
|
72
|
-
if (openStart === 0 && openEnd === 0 || !ElementApi.isElement(node)) return serialize([node])
|
|
73
|
-
if (typeof node.rawCode === "string") return node.rawCode;
|
|
79
|
+
if (openStart === 0 && openEnd === 0 || !ElementApi.isElement(node)) return serialize([node]);
|
|
80
|
+
if (typeof node.rawCode === "string") return verbatim(node.rawCode);
|
|
74
81
|
const hasOnlyInlineChildren = node.children.every((child) => !ElementApi.isElement(child) || state.schema.isInline(child));
|
|
75
|
-
if (hasOnlyInlineChildren && state.schema.element(node.type)?.slice.preserveContext) return NodeApi.string(node);
|
|
82
|
+
if (hasOnlyInlineChildren && state.schema.element(node.type)?.slice.preserveContext) return verbatim(NodeApi.string(node));
|
|
76
83
|
if (hasOnlyInlineChildren) return serialize([{
|
|
77
84
|
children: node.children,
|
|
78
85
|
type: paragraphType
|
|
79
|
-
}])
|
|
86
|
+
}]);
|
|
80
87
|
const unwrapped = serializeOpenNodes(node.children, Math.max(0, openStart - 1), Math.max(0, openEnd - 1));
|
|
81
|
-
return unwrapped.trim() ? unwrapped : node.children.map(NodeApi.string).join("\n");
|
|
88
|
+
return unwrapped.trim() ? unwrapped : verbatim(node.children.map(NodeApi.string).join("\n"));
|
|
82
89
|
};
|
|
83
90
|
const data = slice.content.length === 0 ? "" : `${serializeOpenNodes(slice.content, slice.openStart, slice.openEnd)}\n`;
|
|
84
91
|
return failed ? null : data;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { definePlugin } from "../../lib/plugin/definePlugin.js";
|
|
2
|
+
import { property } from "../../core.js";
|
|
3
|
+
//#region src/markdown/lib/RawHtmlPlugin.ts
|
|
4
|
+
/**
|
|
5
|
+
* Marks text that Markdown import kept from raw HTML, such as a README's
|
|
6
|
+
* centered header or an HTML comment. Every other format writes the text as
|
|
7
|
+
* plain visible text.
|
|
8
|
+
*/
|
|
9
|
+
const RawHtmlPlugin = definePlugin("rawHtml", {
|
|
10
|
+
schema: { mark: {
|
|
11
|
+
inclusive: false,
|
|
12
|
+
property: property.boolean({
|
|
13
|
+
default: false,
|
|
14
|
+
omitDefault: true
|
|
15
|
+
})
|
|
16
|
+
} },
|
|
17
|
+
formats: ({ defineFormats }) => defineFormats({ html: {
|
|
18
|
+
decode: () => void 0,
|
|
19
|
+
encode: ({ value }) => value ? { tag: "span" } : null,
|
|
20
|
+
match: [{ tag: "span" }]
|
|
21
|
+
} })
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
export { RawHtmlPlugin };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildSlateNode } from "./convertNodesDeserialize.js";
|
|
2
2
|
//#region src/markdown/lib/deserializer/mdastToSlate.ts
|
|
3
3
|
const mdastToSlate = (root, options) => {
|
|
4
4
|
root.children = root.children.map((child) => {
|
|
@@ -7,12 +7,22 @@ const mdastToSlate = (root, options) => {
|
|
|
7
7
|
type: "text",
|
|
8
8
|
value: ""
|
|
9
9
|
}],
|
|
10
|
+
position: child.position,
|
|
10
11
|
type: "paragraph"
|
|
11
12
|
};
|
|
12
13
|
return child;
|
|
13
14
|
});
|
|
14
15
|
options.onRootChildren?.(root.children);
|
|
15
|
-
|
|
16
|
+
const marks = {};
|
|
17
|
+
const nodes = [];
|
|
18
|
+
const counts = [];
|
|
19
|
+
root.children.forEach((child, index) => {
|
|
20
|
+
const converted = buildSlateNode(child, marks, options, index === 0 ? options.previousRootSibling ?? null : root.children[index - 1]);
|
|
21
|
+
counts.push(converted.length);
|
|
22
|
+
for (const node of converted) nodes.push(node);
|
|
23
|
+
});
|
|
24
|
+
options.onRootBlocks?.(counts);
|
|
25
|
+
return nodes;
|
|
16
26
|
};
|
|
17
27
|
//#endregion
|
|
18
28
|
export { mdastToSlate };
|