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
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { classifyCharacter, classifyPrecedingCharacter, isCjk, isCjkOrIvs, isIvs, isNonCjkPunctuation, isSpaceOrPunctuation, isUnicodeWhitespace } from "micromark-extension-cjk-friendly-util";
|
|
2
|
+
//#region src/markdown/lib/internal/markdownOpenTail.ts
|
|
3
|
+
const MARKERS = "*_~";
|
|
4
|
+
const STAR = 42;
|
|
5
|
+
const UNDERSCORE = 95;
|
|
6
|
+
const TILDE = 126;
|
|
7
|
+
const HIDDEN_BUDGET = 3;
|
|
8
|
+
const MAX_OFFERS = 4;
|
|
9
|
+
const WINDOW = 1e3;
|
|
10
|
+
const ANY_LETTER = "a";
|
|
11
|
+
const LETTER = /\p{L}/u;
|
|
12
|
+
const DIGIT = /\p{N}/u;
|
|
13
|
+
const PARAGRAPH_REST = /^[ \t]*(?:(?:\r\n?|\n)[ \t>]*)?$/;
|
|
14
|
+
const HEADING_REST = /^[ \t]*(?:#+[ \t]*)?$/;
|
|
15
|
+
const startOf = (node) => node.position?.start.offset ?? NaN;
|
|
16
|
+
const endOf = (node) => node.position?.end.offset ?? NaN;
|
|
17
|
+
const isPlaced = (node) => !Number.isNaN(startOf(node) + endOf(node)) && (!("children" in node) || node.children.every(isPlaced));
|
|
18
|
+
const codePointBefore = (text, at) => /.$/su.exec(text.slice(Math.max(0, at - 2), at))?.[0] ?? "";
|
|
19
|
+
const isEscaped = (text, at) => {
|
|
20
|
+
let slashes = 0;
|
|
21
|
+
while (text[at - 1 - slashes] === "\\") slashes += 1;
|
|
22
|
+
return slashes % 2 === 1;
|
|
23
|
+
};
|
|
24
|
+
const lengthOf = (run) => run.to - run.from;
|
|
25
|
+
const groupOf = (code) => {
|
|
26
|
+
if (code === null || /\s/u.test(String.fromCharCode(code))) return 1;
|
|
27
|
+
return /\p{P}|\p{S}/u.test(String.fromCharCode(code)) ? 2 : 0;
|
|
28
|
+
};
|
|
29
|
+
const pointBefore = (text, at) => {
|
|
30
|
+
if (at <= 0) return null;
|
|
31
|
+
const pair = at >= 2 ? text.codePointAt(at - 2) : void 0;
|
|
32
|
+
return pair !== void 0 && pair > 65535 ? pair : text.charCodeAt(at - 1);
|
|
33
|
+
};
|
|
34
|
+
const cjkSides = (text, from, after) => {
|
|
35
|
+
const previous = pointBefore(text, from);
|
|
36
|
+
const before = classifyCharacter(previous);
|
|
37
|
+
const width = previous !== null && previous > 65535 ? 2 : 1;
|
|
38
|
+
return {
|
|
39
|
+
after: classifyCharacter(after ? after.codePointAt(0) ?? null : null),
|
|
40
|
+
before,
|
|
41
|
+
beforePrimary: classifyPrecedingCharacter(before, () => from < 1 + width ? null : pointBefore(text, from - width), previous),
|
|
42
|
+
previous
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const coreAttentionOpens = (text, from, after, markers) => {
|
|
46
|
+
const previous = from > 0 ? text.charCodeAt(from - 1) : null;
|
|
47
|
+
const code = after ? after.charCodeAt(0) : null;
|
|
48
|
+
const before = groupOf(previous);
|
|
49
|
+
const next = groupOf(code);
|
|
50
|
+
const open = !next || next === 2 && before > 0 || code !== null && markers.includes(code);
|
|
51
|
+
if (text.charCodeAt(from) === STAR) return open;
|
|
52
|
+
const close = !before || before === 2 && next > 0 || previous !== null && markers.includes(previous);
|
|
53
|
+
return open && (before > 0 || !close);
|
|
54
|
+
};
|
|
55
|
+
const cjkAttentionOpens = (text, from, after, tildes) => {
|
|
56
|
+
const sides = cjkSides(text, from, after);
|
|
57
|
+
const code = after ? after.charCodeAt(0) : null;
|
|
58
|
+
const beforeNonCjkPunctuation = isNonCjkPunctuation(sides.beforePrimary);
|
|
59
|
+
const beforeSpaceOrNonCjkPunctuation = beforeNonCjkPunctuation || isUnicodeWhitespace(sides.beforePrimary) || sides.previous === STAR || sides.previous === UNDERSCORE;
|
|
60
|
+
const afterNonCjkPunctuation = isNonCjkPunctuation(sides.after);
|
|
61
|
+
const afterSpaceOrNonCjkPunctuation = afterNonCjkPunctuation || isUnicodeWhitespace(sides.after) || code === STAR || code === UNDERSCORE;
|
|
62
|
+
const open = !afterSpaceOrNonCjkPunctuation || afterNonCjkPunctuation && (beforeSpaceOrNonCjkPunctuation || isCjkOrIvs(sides.beforePrimary)) || tildes && code === TILDE;
|
|
63
|
+
if (text.charCodeAt(from) === STAR) return open;
|
|
64
|
+
const close = !beforeSpaceOrNonCjkPunctuation || beforeNonCjkPunctuation && (afterSpaceOrNonCjkPunctuation || isCjk(sides.after)) || tildes && sides.previous === TILDE;
|
|
65
|
+
return open && (isSpaceOrPunctuation(sides.beforePrimary) || !close);
|
|
66
|
+
};
|
|
67
|
+
const gfmTildesOpen = (text, from, after) => {
|
|
68
|
+
const before = groupOf(from > 0 ? text.charCodeAt(from - 1) : null);
|
|
69
|
+
const next = groupOf(after ? after.charCodeAt(0) : null);
|
|
70
|
+
return !next || next === 2 && before > 0;
|
|
71
|
+
};
|
|
72
|
+
const cjkTildesOpen = (text, from, after) => {
|
|
73
|
+
const sides = cjkSides(text, from, after);
|
|
74
|
+
const beforeSpaceOrNonCjkPunctuation = isNonCjkPunctuation(sides.beforePrimary) || isUnicodeWhitespace(sides.beforePrimary);
|
|
75
|
+
return !(isNonCjkPunctuation(sides.after) || isUnicodeWhitespace(sides.after)) || sides.after === 2 && (beforeSpaceOrNonCjkPunctuation || isCjk(sides.beforePrimary) || isIvs(sides.before));
|
|
76
|
+
};
|
|
77
|
+
const opens = (grammar, text, from, length, after) => {
|
|
78
|
+
if (text.charCodeAt(from) === TILDE) {
|
|
79
|
+
if (length > 2) return false;
|
|
80
|
+
return grammar.strikethrough === "cjkFriendly" ? cjkTildesOpen(text, from, after) : grammar.strikethrough === "gfm" && gfmTildesOpen(text, from, after);
|
|
81
|
+
}
|
|
82
|
+
if (grammar.attention === "cjkFriendly") return cjkAttentionOpens(text, from, after, grammar.strikethrough !== null);
|
|
83
|
+
return grammar.attention === "commonmark" && coreAttentionOpens(text, from, after, grammar.strikethrough ? [
|
|
84
|
+
STAR,
|
|
85
|
+
UNDERSCORE,
|
|
86
|
+
TILDE
|
|
87
|
+
] : [STAR, UNDERSCORE]);
|
|
88
|
+
};
|
|
89
|
+
const readsAsArithmetic = (marker, before) => marker === "*" && DIGIT.test(before);
|
|
90
|
+
const readsAsWordPart = (marker, length, before) => LETTER.test(before) && (marker === "_" || length === 1 && !isCjk(classifyCharacter(before.codePointAt(0) ?? null)));
|
|
91
|
+
const allows = (text, from, length) => {
|
|
92
|
+
const marker = text.charAt(from);
|
|
93
|
+
const before = codePointBefore(text, from);
|
|
94
|
+
if (marker === "~") return length === 2;
|
|
95
|
+
return length <= 3 && !readsAsArithmetic(marker, before) && !readsAsWordPart(marker, length, before);
|
|
96
|
+
};
|
|
97
|
+
const isOffered = (grammar, text, from, length, after) => opens(grammar, text, from, length, after) && allows(text, from, length);
|
|
98
|
+
const findOpenLeaf = (text, tree) => {
|
|
99
|
+
let node = tree;
|
|
100
|
+
while (node.type !== "heading" && node.type !== "paragraph") {
|
|
101
|
+
const last = "children" in node ? node.children.at(-1) : void 0;
|
|
102
|
+
if (!last) return null;
|
|
103
|
+
node = last;
|
|
104
|
+
}
|
|
105
|
+
const leaf = node;
|
|
106
|
+
const last = leaf.children.at(-1);
|
|
107
|
+
const rest = last ? text.slice(endOf(last)) : "";
|
|
108
|
+
return last && leaf.children.every(isPlaced) && (leaf.type === "paragraph" ? PARAGRAPH_REST : HEADING_REST).test(rest) ? leaf : null;
|
|
109
|
+
};
|
|
110
|
+
const firstOpenBacktick = (text, node) => {
|
|
111
|
+
if ("children" in node) return Math.min(Number.POSITIVE_INFINITY, ...node.children.map((child) => firstOpenBacktick(text, child)));
|
|
112
|
+
if (node.type !== "text") return Number.POSITIVE_INFINITY;
|
|
113
|
+
for (let at = startOf(node); at < endOf(node); at += 1) if (text[at] === "`" && !isEscaped(text, at)) return at;
|
|
114
|
+
return Number.POSITIVE_INFINITY;
|
|
115
|
+
};
|
|
116
|
+
const markerRuns = (text, from, to) => {
|
|
117
|
+
const runs = [];
|
|
118
|
+
for (let at = from; at < to; at += 1) {
|
|
119
|
+
const marker = text.charAt(at);
|
|
120
|
+
if (!MARKERS.includes(marker) || isEscaped(text, at)) continue;
|
|
121
|
+
let end = at + 1;
|
|
122
|
+
while (end < to && text[end] === marker) end += 1;
|
|
123
|
+
runs.push({
|
|
124
|
+
from: at,
|
|
125
|
+
to: end
|
|
126
|
+
});
|
|
127
|
+
at = end - 1;
|
|
128
|
+
}
|
|
129
|
+
return runs;
|
|
130
|
+
};
|
|
131
|
+
const isHeld = (grammar, text, run) => {
|
|
132
|
+
if (text[run.from] === "\\") return true;
|
|
133
|
+
if (run.to < text.length) return isOffered(grammar, text, run.from, lengthOf(run), text.slice(run.to, run.to + 2));
|
|
134
|
+
for (let length = lengthOf(run); length <= 3; length += 1) if (isOffered(grammar, text, run.from, length, ANY_LETTER)) return true;
|
|
135
|
+
return false;
|
|
136
|
+
};
|
|
137
|
+
const trailingCluster = (text, from) => {
|
|
138
|
+
const end = text.length;
|
|
139
|
+
const escape = text.endsWith("\\") && !isEscaped(text, end - 1);
|
|
140
|
+
const markersEnd = escape ? end - 1 : end;
|
|
141
|
+
let start = markersEnd;
|
|
142
|
+
while (start > from && MARKERS.includes(text.charAt(start - 1))) start -= 1;
|
|
143
|
+
return {
|
|
144
|
+
runs: [...markerRuns(text, start, markersEnd), ...escape ? [{
|
|
145
|
+
from: markersEnd,
|
|
146
|
+
to: end
|
|
147
|
+
}] : []],
|
|
148
|
+
start
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
const opensSplit = (leaf, next, run, runEnd) => next?.type === "emphasis" && next === leaf.children.at(-1) && run.to === startOf(next) && runEnd > run.to;
|
|
152
|
+
const offeredRuns = (grammar, text, leaf, end, backtick) => {
|
|
153
|
+
const offers = [];
|
|
154
|
+
const window = text.length - WINDOW;
|
|
155
|
+
leaf.children.forEach((child, index) => {
|
|
156
|
+
if (child.type !== "text") return;
|
|
157
|
+
const next = leaf.children[index + 1];
|
|
158
|
+
for (const run of markerRuns(text, Math.max(startOf(child), window), Math.min(endOf(child), end, backtick))) {
|
|
159
|
+
const marker = text.charAt(run.from);
|
|
160
|
+
let { from, to } = run;
|
|
161
|
+
while (from > startOf(child) && text[from - 1] === marker && !isEscaped(text, from - 1)) from -= 1;
|
|
162
|
+
while (text[to] === marker) to += 1;
|
|
163
|
+
if (from < window || !isOffered(grammar, text, from, to - from, text.slice(to, to + 2))) continue;
|
|
164
|
+
offers.push({
|
|
165
|
+
...run,
|
|
166
|
+
split: opensSplit(leaf, next, run, to)
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
return offers.length > MAX_OFFERS ? [] : offers;
|
|
171
|
+
};
|
|
172
|
+
const solidEnd = (text, last, held, marker) => {
|
|
173
|
+
if (last.type !== "text") return endOf(last);
|
|
174
|
+
let at = endOf(last);
|
|
175
|
+
for (; at > startOf(last); at -= 1) {
|
|
176
|
+
const char = text.charAt(at - 1);
|
|
177
|
+
if (!/\s/u.test(char) && !held.some((run) => run.from < at && at <= run.to) && !((char === "\\" || char === marker) && !isEscaped(text, at - 1))) break;
|
|
178
|
+
}
|
|
179
|
+
return at;
|
|
180
|
+
};
|
|
181
|
+
const holdTrailing = (grammar, text, runs, budget) => {
|
|
182
|
+
const held = [];
|
|
183
|
+
let left = budget;
|
|
184
|
+
for (const run of runs) {
|
|
185
|
+
if (lengthOf(run) > left || !isHeld(grammar, text, run)) continue;
|
|
186
|
+
held.push(run);
|
|
187
|
+
left -= lengthOf(run);
|
|
188
|
+
}
|
|
189
|
+
return held;
|
|
190
|
+
};
|
|
191
|
+
const fromEnd = (text, runs) => runs.map((run) => ({
|
|
192
|
+
from: run.from - text.length,
|
|
193
|
+
to: run.to - text.length
|
|
194
|
+
}));
|
|
195
|
+
const holdingPlan = (grammar, text, runs) => ({
|
|
196
|
+
copy: null,
|
|
197
|
+
heldFromEnd: fromEnd(text, holdTrailing(grammar, text, runs, HIDDEN_BUDGET))
|
|
198
|
+
});
|
|
199
|
+
const arrivingCloser = (text, inner, runs, budgetLeft) => {
|
|
200
|
+
const [trailing, ...others] = runs;
|
|
201
|
+
return trailing && others.length === 0 && text.charAt(trailing.from) === text.charAt(inner.from) && lengthOf(trailing) < lengthOf(inner) && lengthOf(trailing) <= budgetLeft && !/\s/u.test(codePointBefore(text, trailing.from)) ? trailing : null;
|
|
202
|
+
};
|
|
203
|
+
const characterCount = (node) => {
|
|
204
|
+
if (node.type === "break") return 1;
|
|
205
|
+
if (node.type === "text" || node.type === "inlineCode" || node.type === "html") return Array.from(node.value.replaceAll(/\r\n?/g, "\n")).length;
|
|
206
|
+
return "children" in node ? node.children.reduce((count, child) => count + characterCount(child), 0) : 0;
|
|
207
|
+
};
|
|
208
|
+
const planOpenTail = (text, tree, read) => {
|
|
209
|
+
const leaf = findOpenLeaf(text, tree);
|
|
210
|
+
const last = leaf?.children.at(-1);
|
|
211
|
+
if (!leaf || !last) return null;
|
|
212
|
+
const backtick = firstOpenBacktick(text, leaf);
|
|
213
|
+
const cluster = last.type === "text" && endOf(last) === text.length && backtick === Number.POSITIVE_INFINITY ? trailingCluster(text, startOf(last)) : null;
|
|
214
|
+
const runs = cluster?.runs ?? [];
|
|
215
|
+
const segment = tree.children.at(-1);
|
|
216
|
+
if (read.mode === "planHold" || !segment || startOf(segment) < read.from) return holdingPlan(read.grammar, text, runs);
|
|
217
|
+
const { from, grammar } = read;
|
|
218
|
+
const offers = offeredRuns(grammar, text, leaf, cluster?.start ?? text.length, backtick);
|
|
219
|
+
for (;;) {
|
|
220
|
+
let budget = HIDDEN_BUDGET;
|
|
221
|
+
const closing = offers.filter((offer) => {
|
|
222
|
+
if (lengthOf(offer) > budget) return false;
|
|
223
|
+
budget -= lengthOf(offer);
|
|
224
|
+
return true;
|
|
225
|
+
});
|
|
226
|
+
const inner = closing.at(-1);
|
|
227
|
+
if (!inner) return holdingPlan(grammar, text, runs);
|
|
228
|
+
const marker = text.charAt(inner.from);
|
|
229
|
+
const completion = arrivingCloser(text, inner, runs, budget);
|
|
230
|
+
const held = completion ? [] : holdTrailing(grammar, text, runs, budget);
|
|
231
|
+
const at = completion?.to ?? solidEnd(text, last, held, marker);
|
|
232
|
+
if (inner.to >= at) {
|
|
233
|
+
offers.splice(offers.indexOf(inner), 1);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const drops = [...closing, ...completion ? [completion] : []];
|
|
237
|
+
const dropped = drops.flatMap((run) => Array.from({ length: lengthOf(run) }, (_, i) => run.from + i));
|
|
238
|
+
const widened = inner.split ? [startOf(last), endOf(last) - 1] : [];
|
|
239
|
+
const closers = closing.map((offer) => offer === inner && completion ? marker.repeat(lengthOf(inner) - lengthOf(completion)) : text.slice(offer.from, offer.to)).reverse().join("");
|
|
240
|
+
return {
|
|
241
|
+
copy: {
|
|
242
|
+
closers: {
|
|
243
|
+
from: at - from,
|
|
244
|
+
to: at - from + closers.length
|
|
245
|
+
},
|
|
246
|
+
delimiters: [...dropped, ...widened].map((offset) => offset - from),
|
|
247
|
+
droppedRuns: drops.map((run) => text.slice(run.from, run.to)),
|
|
248
|
+
splitEmphasisLength: inner.split ? characterCount(last) : null,
|
|
249
|
+
text: text.slice(from, at) + closers + text.slice(at)
|
|
250
|
+
},
|
|
251
|
+
heldFromEnd: fromEnd(text, held)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const delimiterLength = (text, node) => {
|
|
256
|
+
if (node.type === "emphasis") return 1;
|
|
257
|
+
if (node.type === "strong") return 2;
|
|
258
|
+
let length = 0;
|
|
259
|
+
while (text[startOf(node) + length] === "~") length += 1;
|
|
260
|
+
return length;
|
|
261
|
+
};
|
|
262
|
+
const pairsAsPlanned = (text, tree, { closers, delimiters }) => {
|
|
263
|
+
const used = /* @__PURE__ */ new Set();
|
|
264
|
+
const closing = /* @__PURE__ */ new Set();
|
|
265
|
+
const visit = (node) => {
|
|
266
|
+
if (node.type === "emphasis" || node.type === "strong" || node.type === "delete") {
|
|
267
|
+
const start = startOf(node);
|
|
268
|
+
const end = endOf(node);
|
|
269
|
+
if (Number.isNaN(start + end)) return false;
|
|
270
|
+
const length = delimiterLength(text, node);
|
|
271
|
+
if (end > closers.from && end - length < closers.to) for (let at = 0; at < length; at += 1) {
|
|
272
|
+
used.add(start + at);
|
|
273
|
+
used.add(end - length + at);
|
|
274
|
+
closing.add(end - length + at);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return !("children" in node) || node.children.every(visit);
|
|
278
|
+
};
|
|
279
|
+
if (!visit(tree)) return false;
|
|
280
|
+
for (let at = closers.from; at < closers.to; at += 1) {
|
|
281
|
+
if (!closing.has(at)) return false;
|
|
282
|
+
used.delete(at);
|
|
283
|
+
}
|
|
284
|
+
return used.size === delimiters.length && delimiters.every((at) => used.has(at));
|
|
285
|
+
};
|
|
286
|
+
const cutHeld = (text, tree, heldFromEnd) => {
|
|
287
|
+
const [outermost] = heldFromEnd;
|
|
288
|
+
const last = (outermost ? findOpenLeaf(text, tree) : null)?.children.at(-1);
|
|
289
|
+
if (!outermost || last?.type !== "text" || endOf(last) !== text.length) return;
|
|
290
|
+
const start = text.length + outermost.from;
|
|
291
|
+
const tail = text.slice(start);
|
|
292
|
+
if (!last.value.endsWith(tail)) return;
|
|
293
|
+
let shown = "";
|
|
294
|
+
let at = start;
|
|
295
|
+
for (const run of heldFromEnd) {
|
|
296
|
+
shown += text.slice(at, text.length + run.from);
|
|
297
|
+
at = text.length + run.to;
|
|
298
|
+
}
|
|
299
|
+
last.value = last.value.slice(0, -tail.length) + shown + text.slice(at);
|
|
300
|
+
};
|
|
301
|
+
const remarkOpenTail = (read) => (tree, file) => {
|
|
302
|
+
const text = String(file);
|
|
303
|
+
if (read.mode === "pairCopy") {
|
|
304
|
+
if (!pairsAsPlanned(text, tree, read.copy)) throw new Error("The closed copy pairs other runs than its plan.");
|
|
305
|
+
cutHeld(text, tree, read.heldFromEnd);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const plan = planOpenTail(text, tree, read);
|
|
309
|
+
if (!plan) return;
|
|
310
|
+
cutHeld(text, tree, plan.heldFromEnd);
|
|
311
|
+
read.onPlan(plan);
|
|
312
|
+
};
|
|
313
|
+
const tokensOf = (blocks) => {
|
|
314
|
+
const tokens = [];
|
|
315
|
+
const lists = /* @__PURE__ */ new Map();
|
|
316
|
+
const visit = (node) => {
|
|
317
|
+
const { children, id: _id, text, ...props } = node;
|
|
318
|
+
if (typeof text === "string") {
|
|
319
|
+
for (const char of text) tokens.push({
|
|
320
|
+
char,
|
|
321
|
+
marks: props
|
|
322
|
+
});
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if ("listId" in props) {
|
|
326
|
+
if (!lists.has(props.listId)) lists.set(props.listId, lists.size);
|
|
327
|
+
props.listId = lists.get(props.listId);
|
|
328
|
+
}
|
|
329
|
+
tokens.push(JSON.stringify(Object.entries(props).sort(([a], [b]) => a < b ? -1 : 1)));
|
|
330
|
+
children?.forEach(visit);
|
|
331
|
+
tokens.push("/");
|
|
332
|
+
};
|
|
333
|
+
blocks.forEach(visit);
|
|
334
|
+
return tokens;
|
|
335
|
+
};
|
|
336
|
+
const isActive = (value) => value !== void 0 && value !== null && value !== false;
|
|
337
|
+
const hasAny = (marks, keys) => [...keys].some((key) => isActive(marks[key]));
|
|
338
|
+
const keeps = (token, other, split, kinds) => {
|
|
339
|
+
if (typeof token === "string" || typeof other === "string") return token === other;
|
|
340
|
+
return other?.char === token.char && [...kinds.exact].every((key) => isActive(token.marks[key]) === isActive(other.marks[key])) && Object.entries(token.marks).every(([key, value]) => !isActive(value) || JSON.stringify(other.marks[key]) === JSON.stringify(value) || split && kinds.emphasis.has(key) && hasAny(other.marks, kinds.strong));
|
|
341
|
+
};
|
|
342
|
+
const keepsReceived = (received, copy, { droppedRuns, splitEmphasisLength }, kinds) => {
|
|
343
|
+
const closed = tokensOf(copy);
|
|
344
|
+
let walks = [{
|
|
345
|
+
copyIndex: 0,
|
|
346
|
+
runIndex: 0,
|
|
347
|
+
runOffset: 0,
|
|
348
|
+
splitLeft: 0
|
|
349
|
+
}];
|
|
350
|
+
for (const token of tokensOf(received)) {
|
|
351
|
+
const next = /* @__PURE__ */ new Map();
|
|
352
|
+
const add = (walk) => next.set(`${walk.copyIndex} ${walk.runIndex} ${walk.runOffset} ${walk.splitLeft}`, walk);
|
|
353
|
+
for (const { copyIndex, runIndex, runOffset, splitLeft } of walks) {
|
|
354
|
+
if (runOffset === 0 && keeps(token, closed[copyIndex], splitLeft > 0, kinds)) add({
|
|
355
|
+
copyIndex: copyIndex + 1,
|
|
356
|
+
runIndex,
|
|
357
|
+
runOffset,
|
|
358
|
+
splitLeft: typeof token !== "string" && splitLeft > 0 ? splitLeft - 1 : splitLeft
|
|
359
|
+
});
|
|
360
|
+
const run = droppedRuns[runIndex];
|
|
361
|
+
if (typeof token === "string" || token.char !== run?.[runOffset] || Object.values(token.marks).some(isActive)) continue;
|
|
362
|
+
if (runOffset + 1 < run.length) add({
|
|
363
|
+
copyIndex,
|
|
364
|
+
runIndex,
|
|
365
|
+
runOffset: runOffset + 1,
|
|
366
|
+
splitLeft
|
|
367
|
+
});
|
|
368
|
+
else add({
|
|
369
|
+
copyIndex,
|
|
370
|
+
runIndex: runIndex + 1,
|
|
371
|
+
runOffset: 0,
|
|
372
|
+
splitLeft: runIndex + 1 === droppedRuns.length && splitEmphasisLength !== null ? splitEmphasisLength : splitLeft
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
walks = [...next.values()];
|
|
376
|
+
if (walks.length === 0) return false;
|
|
377
|
+
}
|
|
378
|
+
return walks.some(({ copyIndex, runIndex }) => copyIndex === closed.length && runIndex === droppedRuns.length);
|
|
379
|
+
};
|
|
380
|
+
//#endregion
|
|
381
|
+
export { keepsReceived, remarkOpenTail };
|