@stll/folio-core 0.52.0 → 0.53.0
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 +23 -0
- package/dist/ai-edits/apply.d.ts +26 -1
- package/dist/ai-edits/apply.js +1519 -105
- package/dist/ai-edits/batch-claims.d.ts +130 -0
- package/dist/ai-edits/batch-claims.js +244 -0
- package/dist/ai-edits/blockRange.js +9 -3
- package/dist/ai-edits/character-boundaries.d.ts +43 -0
- package/dist/ai-edits/character-boundaries.js +95 -0
- package/dist/ai-edits/clean-text.d.ts +33 -3
- package/dist/ai-edits/clean-text.js +52 -6
- package/dist/ai-edits/comment-lifecycle.d.ts +18 -0
- package/dist/ai-edits/comment-lifecycle.js +52 -0
- package/dist/ai-edits/headless.d.ts +71 -7
- package/dist/ai-edits/headless.js +381 -41
- package/dist/ai-edits/index.d.ts +2 -1
- package/dist/ai-edits/index.js +2 -1
- package/dist/ai-edits/minimal-replacement.d.ts +21 -6
- package/dist/ai-edits/minimal-replacement.js +134 -15
- package/dist/ai-edits/newListNumbering.d.ts +23 -0
- package/dist/ai-edits/newListNumbering.js +94 -0
- package/dist/ai-edits/note-references.d.ts +96 -0
- package/dist/ai-edits/note-references.js +139 -0
- package/dist/ai-edits/pending-suggestions.d.ts +79 -0
- package/dist/ai-edits/pending-suggestions.js +306 -0
- package/dist/ai-edits/read.d.ts +1 -1
- package/dist/ai-edits/read.js +56 -43
- package/dist/ai-edits/result-validation.d.ts +29 -0
- package/dist/ai-edits/result-validation.js +164 -0
- package/dist/ai-edits/snapshot.d.ts +36 -3
- package/dist/ai-edits/snapshot.js +177 -23
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +4 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +38 -16
- package/dist/ai-edits/table-row-column-mutations.js +61 -26
- package/dist/ai-edits/types.d.ts +155 -16
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/compare.js +65 -16
- package/dist/compare/content-alignment.js +13 -2
- package/dist/compare/content-types.d.ts +7 -0
- package/dist/compare/content.d.ts +4 -1
- package/dist/compare/content.js +6 -1
- package/dist/compare/formatting.js +2 -1
- package/dist/compare/inline-atoms.d.ts +21 -4
- package/dist/compare/inline-atoms.js +138 -16
- package/dist/compare/plan.js +10 -5
- package/dist/compare/scenario.js +14 -3
- package/dist/compare/section-boundary-properties.js +1 -1
- package/dist/compare/types.d.ts +4 -2
- package/dist/compare/types.js +2 -1
- package/dist/compare/verification.d.ts +1 -1
- package/dist/compare/verification.js +15 -3
- package/dist/controller/committedLayoutDiff.d.ts +25 -0
- package/dist/controller/committedLayoutDiff.js +71 -0
- package/dist/controller/contentControlWidgetController.d.ts +1 -1
- package/dist/controller/folioEditor.d.ts +1 -1
- package/dist/controller/fontReadiness.d.ts +70 -3
- package/dist/controller/fontReadiness.js +100 -10
- package/dist/controller/headerFooterEditorManager.js +6 -1
- package/dist/controller/layoutPipeline.d.ts +12 -10
- package/dist/controller/layoutPipeline.js +62 -9
- package/dist/controller/layoutRunOptions.d.ts +24 -0
- package/dist/controller/layoutRunOptions.js +17 -0
- package/dist/controller/layoutScheduler.d.ts +19 -14
- package/dist/controller/layoutScheduler.js +15 -12
- package/dist/controller/layoutSession.d.ts +26 -2
- package/dist/controller/layoutSession.js +1 -1
- package/dist/controller/noteEditorManager.js +8 -3
- package/dist/document-operations.d.ts +11 -2
- package/dist/document-operations.js +230 -21
- package/dist/docx/altChunk.d.ts +8 -0
- package/dist/docx/altChunk.js +17 -0
- package/dist/docx/attributeRemainder.d.ts +1 -1
- package/dist/docx/blockContentParser.d.ts +64 -1
- package/dist/docx/blockContentParser.js +17 -4
- package/dist/docx/blockCustomXmlShell.d.ts +7 -0
- package/dist/docx/blockCustomXmlShell.js +14 -0
- package/dist/docx/blockPlainText.js +7 -0
- package/dist/docx/commentAnchorIndex.js +1 -1
- package/dist/docx/commentRangeIntegrity.js +8 -3
- package/dist/docx/commentReferenceNormalization.js +1 -1
- package/dist/docx/commentReplyMarkers.js +20 -1
- package/dist/docx/compatibility.d.ts +1 -1
- package/dist/docx/compatibility.js +34 -13
- package/dist/docx/containerChildren.gen.d.ts +1 -1
- package/dist/docx/containerChildren.gen.js +1 -0
- package/dist/docx/documentParser.js +12 -12
- package/dist/docx/drawingIdNormalization.d.ts +3 -1
- package/dist/docx/drawingIdNormalization.js +6 -1
- package/dist/docx/ensureParaIds.js +119 -97
- package/dist/docx/footnoteParser.js +8 -4
- package/dist/docx/headerFooterParser.js +3 -3
- package/dist/docx/headerFooterReferenceNormalization.d.ts +20 -1
- package/dist/docx/headerFooterReferenceNormalization.js +52 -27
- package/dist/docx/hyperlinkParser.d.ts +1 -1
- package/dist/docx/index.d.ts +1 -1
- package/dist/docx/listNumberingInstances.d.ts +59 -0
- package/dist/docx/listNumberingInstances.js +249 -0
- package/dist/docx/normalizeBaseDirection.js +2 -1
- package/dist/docx/opaqueCarrier.d.ts +7 -0
- package/dist/docx/opaqueCarrier.js +38 -0
- package/dist/docx/packageParts.js +4 -1
- package/dist/docx/paragraphParser.js +91 -24
- package/dist/docx/paragraphPropertySource.d.ts +4 -2
- package/dist/docx/paragraphPropertySource.js +7 -1
- package/dist/docx/paragraphTraversal.js +1 -0
- package/dist/docx/parseWarningMessage.js +4 -1
- package/dist/docx/parser.js +173 -20
- package/dist/docx/rezip.js +27 -5
- package/dist/docx/sdtProperties.js +1 -1
- package/dist/docx/sdtPropertiesPatch.js +3 -0
- package/dist/docx/selectiveSave.js +16 -9
- package/dist/docx/selectiveXmlPatch.js +106 -37
- package/dist/docx/serializer/blockCustomXmlSerializer.d.ts +5 -0
- package/dist/docx/serializer/blockCustomXmlSerializer.js +4 -0
- package/dist/docx/serializer/documentSerializer.js +2 -0
- package/dist/docx/serializer/headerFooterSerializer.js +2 -0
- package/dist/docx/serializer/noteSerializer.js +3 -1
- package/dist/docx/serializer/paragraphSerializer.js +33 -9
- package/dist/docx/serializer/tableSerializer.js +25 -38
- package/dist/docx/server/createBilingualDocument.js +3 -3
- package/dist/docx/tableParser.d.ts +157 -1
- package/dist/docx/tableParser.js +89 -10
- package/dist/docx/textBoxParser.js +1 -1
- package/dist/docx/unzip.d.ts +2 -1
- package/dist/docx/unzip.js +1 -1
- package/dist/docx/wordprocessingPrefixes.d.ts +78 -0
- package/dist/docx/wordprocessingPrefixes.js +286 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +136 -0
- package/dist/i18n/messages/catalogs.gen.js +153 -17
- package/dist/i18n/messages/messages.gen.d.ts +8 -0
- package/dist/internal/compare/inline-presentation.d.ts +2 -1
- package/dist/internal/compare/inline-presentation.js +11 -10
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +2 -8
- package/dist/internal/headlessRevisionResolutionGuard.js +2 -11
- package/dist/internal/indexedPositionMap.d.ts +11 -0
- package/dist/internal/indexedPositionMap.js +42 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +2 -1
- package/dist/internal/revisionResolutionEdits.d.ts +13 -0
- package/dist/internal/revisionResolutionEdits.js +19 -0
- package/dist/internal/revisionResolutionInline.d.ts +24 -0
- package/dist/internal/{headlessRevisionResolution.js → revisionResolutionInline.js} +61 -43
- package/dist/internal/revisionResolutionStep.d.ts +34 -0
- package/dist/internal/revisionResolutionStep.js +282 -0
- package/dist/internal/revisionResolutionTracking.d.ts +11 -0
- package/dist/internal/revisionResolutionTracking.js +124 -0
- package/dist/internal/wholeStoryRevisionResolution.d.ts +56 -0
- package/dist/internal/wholeStoryRevisionResolution.js +530 -0
- package/dist/layout-bridge/convert/markupViewFlow.d.ts +20 -0
- package/dist/layout-bridge/convert/markupViewFlow.js +123 -0
- package/dist/layout-bridge/convert/tableConversion.js +1 -1
- package/dist/layout-bridge/convert/toFlowBlocks.js +10 -1
- package/dist/layout-engine/layoutInstrumentation.d.ts +9 -1
- package/dist/layout-engine/layoutInstrumentation.js +4 -1
- package/dist/layout-engine/measure/cache.d.ts +18 -1
- package/dist/layout-engine/measure/cache.js +31 -1
- package/dist/layout-engine/measure/font-metrics.worker.js +3 -7
- package/dist/layout-engine/measure/measureContainer.js +7 -47
- package/dist/layout-engine/measure/measureHelpers.d.ts +6 -1
- package/dist/layout-engine/measure/measureHelpers.js +22 -2
- package/dist/layout-engine/measure/measureWorker.js +2 -3
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +6 -7
- package/dist/layout-engine/measure/measureWorkerProtocol.js +1 -2
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/renderPage.js +1 -0
- package/dist/layout-painter/renderParagraph.js +1 -1
- package/dist/managers/ContextMenuManager.js +5 -2
- package/dist/managers/types.d.ts +3 -0
- package/dist/markdown/fromMarkdown.js +2 -1
- package/dist/markdown/internals.d.ts +11 -1
- package/dist/markdown/internals.js +24 -3
- package/dist/markdown/renderBlock.js +39 -9
- package/dist/markdown/renderParagraph.d.ts +13 -1
- package/dist/markdown/renderParagraph.js +85 -38
- package/dist/markdown/renderRuns.js +3 -10
- package/dist/markdown/renderTable.js +24 -12
- package/dist/markdown/trailers.js +2 -2
- package/dist/markdown/types.d.ts +29 -7
- package/dist/paged-layout/incrementalMeasure.d.ts +1 -2
- package/dist/paged-layout/incrementalMeasure.js +1 -9
- package/dist/paged-layout/transactionDirtyRange.d.ts +1 -3
- package/dist/paged-layout/transactionDirtyRange.js +29 -41
- package/dist/panel-layout.d.ts +83 -0
- package/dist/panel-layout.js +96 -0
- package/dist/prosemirror/anchoredTextBoxes.d.ts +37 -0
- package/dist/prosemirror/anchoredTextBoxes.js +156 -0
- package/dist/prosemirror/attrs/index.d.ts +6 -2
- package/dist/prosemirror/attrs/index.js +172 -1
- package/dist/prosemirror/commands/comments.d.ts +7 -8
- package/dist/prosemirror/commands/comments.js +241 -207
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +2 -2
- package/dist/prosemirror/commands/index.js +2 -2
- package/dist/prosemirror/commands/paragraph.d.ts +7 -1
- package/dist/prosemirror/commands/paragraph.js +9 -1
- package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +13 -0
- package/dist/prosemirror/commands/paragraphBookmarkJoin.js +22 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +40 -0
- package/dist/prosemirror/commands/resolveAllTableChanges.js +615 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +15 -0
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +46 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.d.ts +16 -0
- package/dist/prosemirror/commands/resolveParagraphProperties.js +59 -0
- package/dist/prosemirror/commands/sectionBreak.js +2 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +8 -2
- package/dist/prosemirror/commands/tableCellMergeResolution.js +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +181 -31
- package/dist/prosemirror/conversion/toProseDoc.js +39 -4
- package/dist/prosemirror/emptyFieldResultRuns.d.ts +18 -0
- package/dist/prosemirror/emptyFieldResultRuns.js +33 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +3 -1
- package/dist/prosemirror/extensions/StarterKit.js +3 -1
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +12 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +161 -123
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +19 -2
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +33 -20
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +31 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +270 -99
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +3 -2
- package/dist/prosemirror/extensions/features/pasteCleanup.js +2 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.d.ts +12 -0
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +126 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +21 -5
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +21 -18
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +37 -17
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +7 -2
- package/dist/prosemirror/extensions/marks/markUtils.js +8 -2
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/noteReferenceDeletion.js +35 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/BlockCustomXmlExtension.js +52 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +3 -3
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +50 -15
- package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +4 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +19 -18
- package/dist/prosemirror/extensions/types.d.ts +4 -1
- package/dist/prosemirror/findReplaceSelection.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -2
- package/dist/prosemirror/index.js +3 -2
- package/dist/prosemirror/indexedNodeLookup.d.ts +17 -0
- package/dist/prosemirror/indexedNodeLookup.js +103 -0
- package/dist/prosemirror/listAutoformatMarkers.d.ts +19 -0
- package/dist/prosemirror/listAutoformatMarkers.js +98 -0
- package/dist/prosemirror/listInstanceReferences.d.ts +12 -0
- package/dist/prosemirror/listInstanceReferences.js +72 -0
- package/dist/prosemirror/listLabels.d.ts +24 -0
- package/dist/prosemirror/listLabels.js +111 -0
- package/dist/prosemirror/listNumbering.d.ts +110 -0
- package/dist/prosemirror/listNumbering.js +345 -0
- package/dist/prosemirror/listRenderingAttrs.d.ts +11 -2
- package/dist/prosemirror/listRenderingAttrs.js +8 -1
- package/dist/prosemirror/markupViewProjection.d.ts +95 -0
- package/dist/prosemirror/markupViewProjection.js +83 -0
- package/dist/prosemirror/numberingAttr.d.ts +9 -1
- package/dist/prosemirror/numberingAttr.js +9 -1
- package/dist/prosemirror/outlineLevelAttr.js +1 -1
- package/dist/prosemirror/paragraphIndentation.d.ts +10 -1
- package/dist/prosemirror/paragraphIndentation.js +29 -7
- package/dist/prosemirror/paragraphMarkJoin.d.ts +19 -0
- package/dist/prosemirror/paragraphMarkJoin.js +24 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +27 -1
- package/dist/prosemirror/plugins/documentNumbering.js +97 -11
- package/dist/prosemirror/plugins/documentStyles.d.ts +10 -1
- package/dist/prosemirror/plugins/documentStyles.js +14 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +16 -2
- package/dist/prosemirror/plugins/suggestionMode.js +116 -52
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/plugins/transactionInvariants.d.ts +32 -0
- package/dist/prosemirror/plugins/transactionInvariants.js +86 -0
- package/dist/prosemirror/positionSweep.d.ts +24 -0
- package/dist/prosemirror/positionSweep.js +222 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +33 -1
- package/dist/prosemirror/replacedAnnotations.js +170 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/schema/index.d.ts +2 -2
- package/dist/prosemirror/schema/index.js +3 -0
- package/dist/prosemirror/schema/nodes.d.ts +42 -11
- package/dist/prosemirror/sectionMarkEdits.d.ts +20 -0
- package/dist/prosemirror/sectionMarkEdits.js +59 -0
- package/dist/prosemirror/storyListNumbering.d.ts +17 -0
- package/dist/prosemirror/storyListNumbering.js +102 -0
- package/dist/prosemirror/tableGridMutation.d.ts +48 -2
- package/dist/prosemirror/tableGridMutation.js +106 -1
- package/dist/prosemirror/validation.js +5 -1
- package/dist/redline.js +93 -9
- package/dist/render-dom/BodySelectionOverlay.d.ts +4 -1
- package/dist/render-dom/BodySelectionOverlay.js +3 -2
- package/dist/utils/findReplace.js +2 -2
- package/dist/utils/mergeDocumentContent.js +1 -1
- package/dist/utils/noteReferenceLabels.d.ts +36 -0
- package/dist/utils/noteReferenceLabels.js +32 -0
- package/dist/utils/replaceText.js +1 -1
- package/dist/version-comparison.d.ts +1 -0
- package/dist/version-comparison.js +1 -0
- package/package.json +3 -2
- package/dist/internal/headlessRevisionResolution.d.ts +0 -23
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { mintListInstance } from "../../../docx/listNumberingInstances.js";
|
|
2
|
+
import { createNumberingMap } from "../../../docx/numberingParser.js";
|
|
3
|
+
import { expectParagraphAttrs } from "../../attrs/index.js";
|
|
4
|
+
import { completeNumberingForDoc } from "../../listInstanceReferences.js";
|
|
5
|
+
import { listItemAttrs } from "../../listNumbering.js";
|
|
6
|
+
import { getPackageNumberingDefinitions } from "../../plugins/documentNumbering.js";
|
|
7
|
+
import { panic } from "better-result";
|
|
8
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
9
|
+
//#region src/prosemirror/extensions/features/pastedHtmlLists.ts
|
|
10
|
+
/** Convert browser list markup into the editor's numbered-paragraph model. */
|
|
11
|
+
const isList = (element) => element.localName === "ul" || element.localName === "ol";
|
|
12
|
+
const hasListHint = (node) => node?.type.name === "paragraph" && Boolean(expectParagraphAttrs(node)._pastedHtmlList);
|
|
13
|
+
/**
|
|
14
|
+
* Flatten only list containers. Other HTML remains in place for the normal
|
|
15
|
+
* clipboard parser, including tables and inline formatting inside list items.
|
|
16
|
+
*/
|
|
17
|
+
const flattenPastedHtmlLists = (html) => {
|
|
18
|
+
if (!/<(?:ul|ol)\b/iu.test(html)) return html;
|
|
19
|
+
const host = document.createElement("div");
|
|
20
|
+
host.innerHTML = html;
|
|
21
|
+
let nextGroup = 0;
|
|
22
|
+
const flatten = (list, level) => {
|
|
23
|
+
const fragment = document.createDocumentFragment();
|
|
24
|
+
const group = ++nextGroup;
|
|
25
|
+
const kind = list.localName === "ul" ? "bullet" : "numbered";
|
|
26
|
+
const rawStart = Number(list.getAttribute("start"));
|
|
27
|
+
const start = Number.isSafeInteger(rawStart) && rawStart > 0 ? rawStart : void 0;
|
|
28
|
+
for (const item of Array.from(list.children)) {
|
|
29
|
+
if (item.localName !== "li") continue;
|
|
30
|
+
let paragraph = document.createElement("p");
|
|
31
|
+
let emitted = false;
|
|
32
|
+
const mark = (element) => {
|
|
33
|
+
element.setAttribute("data-folio-list-group", String(group));
|
|
34
|
+
element.setAttribute("data-folio-list-level", String(Math.min(level, 8)));
|
|
35
|
+
element.setAttribute("data-folio-list-kind", kind);
|
|
36
|
+
if (start !== void 0) element.setAttribute("data-folio-list-start", String(start));
|
|
37
|
+
};
|
|
38
|
+
const flush = () => {
|
|
39
|
+
if (!paragraph.hasChildNodes()) return;
|
|
40
|
+
mark(paragraph);
|
|
41
|
+
fragment.append(paragraph);
|
|
42
|
+
paragraph = document.createElement("p");
|
|
43
|
+
emitted = true;
|
|
44
|
+
};
|
|
45
|
+
for (const child of Array.from(item.childNodes)) if (child instanceof Element && isList(child)) {
|
|
46
|
+
flush();
|
|
47
|
+
fragment.append(flatten(child, level + 1));
|
|
48
|
+
} else if (child instanceof Element && child.localName === "p") {
|
|
49
|
+
flush();
|
|
50
|
+
mark(child);
|
|
51
|
+
fragment.append(child);
|
|
52
|
+
emitted = true;
|
|
53
|
+
} else if (child.nodeType !== Node.TEXT_NODE || child.textContent?.trim()) paragraph.append(child);
|
|
54
|
+
flush();
|
|
55
|
+
if (!emitted) {
|
|
56
|
+
mark(paragraph);
|
|
57
|
+
fragment.append(paragraph);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return fragment;
|
|
61
|
+
};
|
|
62
|
+
for (const list of Array.from(host.querySelectorAll("ul,ol"))) {
|
|
63
|
+
if (!list.parentNode || list.parentElement?.closest("ul,ol")) continue;
|
|
64
|
+
list.replaceWith(flatten(list, 0));
|
|
65
|
+
}
|
|
66
|
+
return host.innerHTML;
|
|
67
|
+
};
|
|
68
|
+
/** Resolve clipboard-only list hints against fresh document numbering ids. */
|
|
69
|
+
const numberPastedHtmlLists = (slice, view) => {
|
|
70
|
+
let hasList = false;
|
|
71
|
+
slice.content.descendants((node) => {
|
|
72
|
+
if (hasListHint(node)) {
|
|
73
|
+
hasList = true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return !hasList;
|
|
77
|
+
});
|
|
78
|
+
if (!hasList) return slice;
|
|
79
|
+
const startsWithList = hasListHint(slice.content.firstChild);
|
|
80
|
+
const endsWithList = hasListHint(slice.content.lastChild);
|
|
81
|
+
let definitions = completeNumberingForDoc(getPackageNumberingDefinitions(view.state) ?? void 0, view.state.doc);
|
|
82
|
+
let numbering = null;
|
|
83
|
+
const groups = /* @__PURE__ */ new Map();
|
|
84
|
+
let changed = false;
|
|
85
|
+
const convert = (node) => {
|
|
86
|
+
let result = node;
|
|
87
|
+
if (node.type.name === "paragraph") {
|
|
88
|
+
const attrs = expectParagraphAttrs(node);
|
|
89
|
+
const hint = attrs._pastedHtmlList;
|
|
90
|
+
if (hint) {
|
|
91
|
+
let group = groups.get(hint.group);
|
|
92
|
+
if (!group || group.kind !== hint.kind) {
|
|
93
|
+
const minted = mintListInstance(definitions, {
|
|
94
|
+
kind: hint.kind,
|
|
95
|
+
...hint.start === void 0 ? {} : { start: hint.start }
|
|
96
|
+
});
|
|
97
|
+
definitions = minted.definitions;
|
|
98
|
+
numbering = createNumberingMap(definitions);
|
|
99
|
+
group = {
|
|
100
|
+
numId: minted.numId,
|
|
101
|
+
kind: hint.kind
|
|
102
|
+
};
|
|
103
|
+
groups.set(hint.group, group);
|
|
104
|
+
}
|
|
105
|
+
if (!numbering) panic("Pasted list group has no numbering definition");
|
|
106
|
+
result = node.type.create(listItemAttrs({
|
|
107
|
+
...attrs,
|
|
108
|
+
_pastedHtmlList: void 0
|
|
109
|
+
}, {
|
|
110
|
+
numId: group.numId,
|
|
111
|
+
ilvl: hint.level
|
|
112
|
+
}, numbering), node.content, node.marks);
|
|
113
|
+
changed = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (result.childCount === 0) return result;
|
|
117
|
+
const children = [];
|
|
118
|
+
result.forEach((child) => children.push(convert(child)));
|
|
119
|
+
return result.copy(Fragment.fromArray(children));
|
|
120
|
+
};
|
|
121
|
+
const children = [];
|
|
122
|
+
slice.content.forEach((node) => children.push(convert(node)));
|
|
123
|
+
return changed ? new Slice(Fragment.fromArray(children), startsWithList ? 0 : slice.openStart, endsWithList ? 0 : slice.openEnd) : slice;
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
export { flattenPastedHtmlLists, numberPastedHtmlLists };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { expectFootnoteRefMarkAttrs } from "../../attrs/index.js";
|
|
2
|
+
import { suggestionModeKey } from "../../plugins/suggestionMode.js";
|
|
2
3
|
import { createMarkExtension } from "../create.js";
|
|
4
|
+
import { expandNoteReferenceDeletionRange } from "./noteReferenceDeletion.js";
|
|
3
5
|
import { panic } from "better-result";
|
|
4
6
|
//#region src/prosemirror/extensions/marks/FootnoteRefExtension.ts
|
|
5
7
|
/**
|
|
@@ -59,6 +61,14 @@ const FootnoteRefExtension = createMarkExtension({
|
|
|
59
61
|
},
|
|
60
62
|
onSchemaReady(ctx) {
|
|
61
63
|
const { schema } = ctx;
|
|
64
|
+
const deleteWholeNoteReference = (direction) => (state, dispatch) => {
|
|
65
|
+
if (suggestionModeKey.getState(state)?.active) return false;
|
|
66
|
+
const { from, to, empty } = state.selection;
|
|
67
|
+
const range = expandNoteReferenceDeletionRange(state.doc, empty && direction === "backward" ? Math.max(0, from - 1) : from, empty && direction === "forward" ? Math.min(state.doc.content.size, to + 1) : to);
|
|
68
|
+
if (!range) return false;
|
|
69
|
+
dispatch?.(state.tr.delete(range.from, range.to).scrollIntoView());
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
62
72
|
function makeInsertNote(noteType) {
|
|
63
73
|
return (id) => (state, dispatch) => {
|
|
64
74
|
if (!dispatch) return true;
|
|
@@ -83,11 +93,17 @@ const FootnoteRefExtension = createMarkExtension({
|
|
|
83
93
|
dispatch(tr.scrollIntoView());
|
|
84
94
|
return true;
|
|
85
95
|
};
|
|
86
|
-
return {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
return {
|
|
97
|
+
keyboardShortcuts: {
|
|
98
|
+
Backspace: deleteWholeNoteReference("backward"),
|
|
99
|
+
Delete: deleteWholeNoteReference("forward")
|
|
100
|
+
},
|
|
101
|
+
commands: {
|
|
102
|
+
insertFootnote: makeInsertNote("footnote"),
|
|
103
|
+
insertEndnote: makeInsertNote("endnote"),
|
|
104
|
+
deleteNoteRef: () => deleteNoteRef
|
|
105
|
+
}
|
|
106
|
+
};
|
|
91
107
|
}
|
|
92
108
|
});
|
|
93
109
|
//#endregion
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { MarkExtension } from "../types.js";
|
|
2
|
+
import { Transaction } from "prosemirror-state";
|
|
2
3
|
//#region src/prosemirror/extensions/marks/RunIdentityExtension.d.ts
|
|
4
|
+
type InsertedRange = {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
};
|
|
3
8
|
/**
|
|
4
|
-
*
|
|
5
|
-
* carried which no formatting mark holds.
|
|
9
|
+
* Every range `transactions` inserted, in the document they produced.
|
|
6
10
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* A step map reports each replacement as an old span and the new span it
|
|
12
|
+
* became; a new span longer than nothing is content the step put there, which
|
|
13
|
+
* is exactly the text that may not claim an authored run. Each range is then
|
|
14
|
+
* carried through the steps that followed it — the rest of its own
|
|
15
|
+
* transaction, then every later one — so a batch applied together reports
|
|
16
|
+
* positions in the document this hook is looking at rather than in an
|
|
17
|
+
* intermediate one.
|
|
13
18
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* never write a session id it did not read. Typed text becomes its own run
|
|
21
|
-
* with no attributes instead, and `w:rsidRDefault` on the parent `w:p`
|
|
22
|
-
* supplies the session the format itself says such a run belongs to.
|
|
19
|
+
* An undo is not an insertion: it puts back what an edit took away, identity
|
|
20
|
+
* included, and stripping that would leave the restored text claiming no run
|
|
21
|
+
* it came from. `skip` names the transactions to pass over; they still carry
|
|
22
|
+
* the ranges of the others forward.
|
|
23
|
+
*
|
|
24
|
+
* @internal Exported for the per-step equivalence test.
|
|
23
25
|
*/
|
|
26
|
+
declare const insertedRanges: (transactions: readonly Transaction[], skip?: (transaction: Transaction) => boolean) => InsertedRange[];
|
|
24
27
|
declare const RunIdentityExtension: (options?: Partial<Record<string, unknown>> | undefined) => MarkExtension;
|
|
25
28
|
//#endregion
|
|
26
|
-
export { RunIdentityExtension };
|
|
29
|
+
export { RunIdentityExtension, insertedRanges };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { expectRunIdentityMarkAttrs } from "../../attrs/index.js";
|
|
2
|
+
import { nodesBetweenIndexed } from "../../indexedNodeLookup.js";
|
|
3
|
+
import { sweepPositions } from "../../positionSweep.js";
|
|
2
4
|
import { RUN_IDENTITY_ATTRIBUTE, RUN_IDENTITY_MARK_NAME, runIdentityAttrs } from "../../runIdentity.js";
|
|
3
5
|
import { createMarkExtension } from "../create.js";
|
|
4
6
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
7
|
+
import { isHistoryTransaction, undoDepth } from "prosemirror-history";
|
|
5
8
|
//#region src/prosemirror/extensions/marks/RunIdentityExtension.ts
|
|
6
9
|
/**
|
|
7
10
|
* Editor-side identity for one authored `w:r`, and the payload that element
|
|
@@ -36,27 +39,43 @@ const runIdentityStripKey = new PluginKey("runIdentityStrip");
|
|
|
36
39
|
* transaction, then every later one — so a batch applied together reports
|
|
37
40
|
* positions in the document this hook is looking at rather than in an
|
|
38
41
|
* intermediate one.
|
|
42
|
+
*
|
|
43
|
+
* An undo is not an insertion: it puts back what an edit took away, identity
|
|
44
|
+
* included, and stripping that would leave the restored text claiming no run
|
|
45
|
+
* it came from. `skip` names the transactions to pass over; they still carry
|
|
46
|
+
* the ranges of the others forward.
|
|
47
|
+
*
|
|
48
|
+
* @internal Exported for the per-step equivalence test.
|
|
39
49
|
*/
|
|
40
|
-
const insertedRanges = (transactions) => {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return mapped;
|
|
48
|
-
};
|
|
50
|
+
const insertedRanges = (transactions, skip = () => false) => {
|
|
51
|
+
const queries = [];
|
|
52
|
+
let stepOffset = 0;
|
|
53
|
+
for (const transaction of transactions) {
|
|
54
|
+
const offset = stepOffset;
|
|
55
|
+
stepOffset += transaction.mapping.maps.length;
|
|
56
|
+
if (skip(transaction)) continue;
|
|
49
57
|
transaction.mapping.maps.forEach((stepMap, stepIndex) => {
|
|
50
|
-
const
|
|
58
|
+
const from = offset + stepIndex + 1;
|
|
51
59
|
stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
52
60
|
if (newEnd <= newStart) return;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
queries.push({
|
|
62
|
+
pos: newStart,
|
|
63
|
+
assoc: -1,
|
|
64
|
+
from
|
|
65
|
+
}, {
|
|
66
|
+
pos: newEnd,
|
|
67
|
+
assoc: 1,
|
|
68
|
+
from
|
|
56
69
|
});
|
|
57
70
|
});
|
|
58
71
|
});
|
|
59
72
|
}
|
|
73
|
+
const mapped = sweepPositions(transactions.map((transaction) => transaction.mapping), queries);
|
|
74
|
+
const ranges = [];
|
|
75
|
+
for (let index = 0; index < mapped.length; index += 2) ranges.push({
|
|
76
|
+
from: mapped[index].pos,
|
|
77
|
+
to: mapped[index + 1].pos
|
|
78
|
+
});
|
|
60
79
|
return ranges;
|
|
61
80
|
};
|
|
62
81
|
/**
|
|
@@ -69,11 +88,12 @@ const insertedRanges = (transactions) => {
|
|
|
69
88
|
*/
|
|
70
89
|
const createRunIdentityStripPlugin = () => new Plugin({
|
|
71
90
|
key: runIdentityStripKey,
|
|
72
|
-
appendTransaction(transactions,
|
|
91
|
+
appendTransaction(transactions, oldState, newState) {
|
|
73
92
|
if (!transactions.some((transaction) => transaction.docChanged)) return null;
|
|
74
93
|
const markType = newState.schema.marks[RUN_IDENTITY_MARK_NAME];
|
|
75
94
|
if (markType === void 0) return null;
|
|
76
|
-
const
|
|
95
|
+
const undoing = undoDepth(newState) < undoDepth(oldState);
|
|
96
|
+
const ranges = insertedRanges(transactions, (transaction) => undoing && isHistoryTransaction(transaction));
|
|
77
97
|
if (ranges.length === 0) return null;
|
|
78
98
|
const tr = newState.tr;
|
|
79
99
|
const stripRange = ({ from, to }) => {
|
|
@@ -81,7 +101,7 @@ const createRunIdentityStripPlugin = () => new Plugin({
|
|
|
81
101
|
const clampedFrom = Math.min(from, clampedTo);
|
|
82
102
|
if (clampedFrom === clampedTo) return false;
|
|
83
103
|
let rangeStripped = false;
|
|
84
|
-
newState.doc
|
|
104
|
+
nodesBetweenIndexed(newState.doc, clampedFrom, clampedTo, (node, pos) => {
|
|
85
105
|
if (!node.isInline || !markType.isInSet(node.marks)) return true;
|
|
86
106
|
tr.removeMark(Math.max(pos, clampedFrom), Math.min(pos + node.nodeSize, clampedTo), markType);
|
|
87
107
|
rangeStripped = true;
|
|
@@ -132,4 +152,4 @@ const RunIdentityExtension = createMarkExtension({
|
|
|
132
152
|
}
|
|
133
153
|
});
|
|
134
154
|
//#endregion
|
|
135
|
-
export { RunIdentityExtension };
|
|
155
|
+
export { RunIdentityExtension, insertedRanges };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { document_d_exports } from "../../../types/document.js";
|
|
2
|
-
import { Command, EditorState } from "prosemirror-state";
|
|
3
2
|
import { Attrs, Mark, MarkType, Schema } from "prosemirror-model";
|
|
3
|
+
import { Command, EditorState } from "prosemirror-state";
|
|
4
4
|
//#region src/prosemirror/extensions/marks/markUtils.d.ts
|
|
5
5
|
type MarkAttrs = Record<string, unknown>;
|
|
6
6
|
declare function marksToTextFormatting(marks: readonly Mark[]): document_d_exports.TextFormatting;
|
|
@@ -39,7 +39,12 @@ type TextFormattingToMarksOptions = {
|
|
|
39
39
|
};
|
|
40
40
|
declare function textFormattingToMarks(formatting: document_d_exports.TextFormatting | undefined, schema: Schema, options?: TextFormattingToMarksOptions): Mark[];
|
|
41
41
|
/**
|
|
42
|
-
* Clear
|
|
42
|
+
* Clear character formatting from the selection.
|
|
43
|
+
*
|
|
44
|
+
* Only the marks that carry run formatting go. A comment anchor, a hyperlink,
|
|
45
|
+
* a note reference, a tracked insertion or deletion and a run's identity are
|
|
46
|
+
* not formatting, and removing them deleted the comment's range, unlinked the
|
|
47
|
+
* text, orphaned the note and silently resolved the revision.
|
|
43
48
|
*/
|
|
44
49
|
declare const clearFormatting: Command;
|
|
45
50
|
/**
|
|
@@ -4,6 +4,7 @@ import { normalizeHorizontalScalePercent } from "../../../utils/horizontalScale.
|
|
|
4
4
|
import { expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectEmphasisMarkAttrs, expectFontFamilyMarkAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectStrikeMarkAttrs, expectTextEffectMarkAttrs } from "../../attrs/index.js";
|
|
5
5
|
import { runShadingAttrsToShading, shadingToRunShadingAttrs } from "../../conversion/runShadingMark.js";
|
|
6
6
|
import { selectRunFormattingCarrierRepresentations } from "../../runFormattingInlineCarriers.js";
|
|
7
|
+
import { RUN_FORMATTING_MARK_NAMES } from "../../runFormattingMarkNames.js";
|
|
7
8
|
import { hasRunFormattingOverrideAttrs } from "../../runFormattingProvenance.js";
|
|
8
9
|
import { COMPLEX_SCRIPT_RUN_PROPERTY_KEYS } from "../../schema/marks.js";
|
|
9
10
|
import { applyRunFormattingOverrideMark, buildRunFormattingOverrideAttrs } from "./RunFormattingOverrideExtension.js";
|
|
@@ -480,7 +481,12 @@ function textFormattingToMarks(formatting, schema, options) {
|
|
|
480
481
|
return marks;
|
|
481
482
|
}
|
|
482
483
|
/**
|
|
483
|
-
* Clear
|
|
484
|
+
* Clear character formatting from the selection.
|
|
485
|
+
*
|
|
486
|
+
* Only the marks that carry run formatting go. A comment anchor, a hyperlink,
|
|
487
|
+
* a note reference, a tracked insertion or deletion and a run's identity are
|
|
488
|
+
* not formatting, and removing them deleted the comment's range, unlinked the
|
|
489
|
+
* text, orphaned the note and silently resolved the revision.
|
|
484
490
|
*/
|
|
485
491
|
const clearFormatting = (state, dispatch) => {
|
|
486
492
|
const { from, to, empty } = state.selection;
|
|
@@ -498,7 +504,7 @@ const clearFormatting = (state, dispatch) => {
|
|
|
498
504
|
if (node.isText && node.marks.length > 0) {
|
|
499
505
|
const start = Math.max(from, pos);
|
|
500
506
|
const end = Math.min(to, pos + node.nodeSize);
|
|
501
|
-
for (const mark of node.marks) tr = tr.removeMark(start, end, mark.type);
|
|
507
|
+
for (const mark of node.marks) if (RUN_FORMATTING_MARK_NAMES.has(mark.type.name)) tr = tr.removeMark(start, end, mark.type);
|
|
502
508
|
}
|
|
503
509
|
});
|
|
504
510
|
dispatch(tr.scrollIntoView());
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
//#region src/prosemirror/extensions/marks/noteReferenceDeletion.d.ts
|
|
3
|
+
type DeletionRange = {
|
|
4
|
+
from: number;
|
|
5
|
+
to: number;
|
|
6
|
+
};
|
|
7
|
+
/** Keep the text carrying one OOXML note reference together during deletion. */
|
|
8
|
+
declare const expandNoteReferenceDeletionRange: (doc: Node, from: number, to: number) => DeletionRange | null;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { expandNoteReferenceDeletionRange };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/prosemirror/extensions/marks/noteReferenceDeletion.ts
|
|
2
|
+
/** Keep the text carrying one OOXML note reference together during deletion. */
|
|
3
|
+
const expandNoteReferenceDeletionRange = (doc, from, to) => {
|
|
4
|
+
let expandedFrom = from;
|
|
5
|
+
let expandedTo = to;
|
|
6
|
+
let intersectsReference = false;
|
|
7
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
8
|
+
const reference = node.marks.find((mark) => mark.type.name === "footnoteRef");
|
|
9
|
+
if (!node.isText || !reference) return;
|
|
10
|
+
intersectsReference = true;
|
|
11
|
+
const $pos = doc.resolve(pos);
|
|
12
|
+
const parent = $pos.parent;
|
|
13
|
+
const index = $pos.index();
|
|
14
|
+
let referenceFrom = pos;
|
|
15
|
+
let referenceTo = pos + node.nodeSize;
|
|
16
|
+
for (let left = index - 1; left >= 0; left--) {
|
|
17
|
+
const sibling = parent.child(left);
|
|
18
|
+
if (!sibling.isText || !sibling.marks.some((mark) => mark.eq(reference))) break;
|
|
19
|
+
referenceFrom -= sibling.nodeSize;
|
|
20
|
+
}
|
|
21
|
+
for (let right = index + 1; right < parent.childCount; right++) {
|
|
22
|
+
const sibling = parent.child(right);
|
|
23
|
+
if (!sibling.isText || !sibling.marks.some((mark) => mark.eq(reference))) break;
|
|
24
|
+
referenceTo += sibling.nodeSize;
|
|
25
|
+
}
|
|
26
|
+
expandedFrom = Math.min(expandedFrom, referenceFrom);
|
|
27
|
+
expandedTo = Math.max(expandedTo, referenceTo);
|
|
28
|
+
});
|
|
29
|
+
return intersectsReference ? {
|
|
30
|
+
from: expandedFrom,
|
|
31
|
+
to: expandedTo
|
|
32
|
+
} : null;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { expandNoteReferenceDeletionRange };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NodeExtension } from "../types.js";
|
|
2
|
+
//#region src/prosemirror/extensions/nodes/BlockCustomXmlExtension.d.ts
|
|
3
|
+
/** An editable block sequence inside an authored custom XML wrapper. */
|
|
4
|
+
declare const BlockCustomXmlExtension: (options?: Partial<Record<string, unknown>> | undefined) => NodeExtension;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { BlockCustomXmlExtension };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createNodeExtension } from "../create.js";
|
|
2
|
+
//#region src/prosemirror/extensions/nodes/BlockCustomXmlExtension.ts
|
|
3
|
+
/** An editable block sequence inside an authored custom XML wrapper. */
|
|
4
|
+
const BlockCustomXmlExtension = createNodeExtension({
|
|
5
|
+
name: "blockCustomXml",
|
|
6
|
+
schemaNodeName: "blockCustomXml",
|
|
7
|
+
nodeSpec: {
|
|
8
|
+
group: "block",
|
|
9
|
+
content: "block+",
|
|
10
|
+
isolating: true,
|
|
11
|
+
defining: true,
|
|
12
|
+
attrs: {
|
|
13
|
+
openingXml: { default: null },
|
|
14
|
+
closingXml: { default: null },
|
|
15
|
+
_originallyEmpty: { default: false }
|
|
16
|
+
},
|
|
17
|
+
parseDOM: [{
|
|
18
|
+
tag: "div[data-docx-block-custom-xml-open]",
|
|
19
|
+
getAttrs(dom) {
|
|
20
|
+
if (!(dom instanceof HTMLElement)) return false;
|
|
21
|
+
const openingXml = dom.dataset["docxBlockCustomXmlOpen"];
|
|
22
|
+
const closingXml = dom.dataset["docxBlockCustomXmlClose"];
|
|
23
|
+
if (!openingXml || !closingXml) return false;
|
|
24
|
+
return {
|
|
25
|
+
openingXml,
|
|
26
|
+
closingXml,
|
|
27
|
+
_originallyEmpty: dom.dataset["docxBlockCustomXmlEmpty"] === "true"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}],
|
|
31
|
+
toDOM(node) {
|
|
32
|
+
const { openingXml, closingXml, _originallyEmpty } = node.attrs;
|
|
33
|
+
if (typeof openingXml !== "string" || typeof closingXml !== "string") return [
|
|
34
|
+
"div",
|
|
35
|
+
{ class: "docx-block-custom-xml" },
|
|
36
|
+
0
|
|
37
|
+
];
|
|
38
|
+
return [
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
class: "docx-block-custom-xml",
|
|
42
|
+
"data-docx-block-custom-xml-open": openingXml,
|
|
43
|
+
"data-docx-block-custom-xml-close": closingXml,
|
|
44
|
+
"data-docx-block-custom-xml-empty": String(_originallyEmpty === true)
|
|
45
|
+
},
|
|
46
|
+
0
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
//#endregion
|
|
52
|
+
export { BlockCustomXmlExtension };
|
|
@@ -8,10 +8,10 @@ import { NodeExtension } from "../types.js";
|
|
|
8
8
|
* Simple fields that must preserve hyperlink structure use a distinct atomic
|
|
9
9
|
* node with inline children; their visible text comes from those children.
|
|
10
10
|
*/
|
|
11
|
-
type
|
|
11
|
+
type FieldOptions = {
|
|
12
12
|
getInternalClipboardToken?: () => string;
|
|
13
13
|
};
|
|
14
|
-
declare const FieldExtension: (options?: Partial<
|
|
15
|
-
declare const StructuredFieldExtension: (options?: Partial<
|
|
14
|
+
declare const FieldExtension: (options?: Partial<FieldOptions> | undefined) => NodeExtension;
|
|
15
|
+
declare const StructuredFieldExtension: (options?: Partial<FieldOptions> | undefined) => NodeExtension;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { FieldExtension, StructuredFieldExtension };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseFieldInstruction } from "../../../docx/fieldParser.js";
|
|
2
|
-
import { expectFieldAttrs } from "../../attrs/index.js";
|
|
2
|
+
import { expectFieldAttrs, isValidEmptyFieldResultRuns, isValidFieldCode } from "../../attrs/index.js";
|
|
3
3
|
import { createNodeExtension } from "../create.js";
|
|
4
4
|
//#region src/prosemirror/extensions/nodes/FieldExtension.ts
|
|
5
5
|
const createFieldAttrs = () => ({
|
|
@@ -10,21 +10,48 @@ const createFieldAttrs = () => ({
|
|
|
10
10
|
fieldKind: { default: "simple" },
|
|
11
11
|
fldLock: { default: null },
|
|
12
12
|
dirty: { default: null },
|
|
13
|
-
fieldResultIsFallback: { default: null }
|
|
13
|
+
fieldResultIsFallback: { default: null },
|
|
14
|
+
formFieldDataXml: { default: null },
|
|
15
|
+
_docxEmptyResultRuns: { default: null },
|
|
16
|
+
_docxFieldCode: { default: null }
|
|
14
17
|
});
|
|
15
18
|
/** A `data-` flag a pasted field carried: absent states nothing. */
|
|
16
19
|
const statedFlag = (value) => value === void 0 ? null : value === "true";
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
20
|
+
const readEmptyResultRuns = (value) => {
|
|
21
|
+
if (value === void 0) return null;
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(value);
|
|
24
|
+
return isValidEmptyFieldResultRuns(parsed) ? parsed : null;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const readFieldCode = (value) => {
|
|
30
|
+
if (value === void 0) return null;
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(value);
|
|
33
|
+
return isValidFieldCode(parsed) ? parsed : null;
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const readFieldDomAttrs = (dom) => {
|
|
39
|
+
const emptyResultRuns = readEmptyResultRuns(dom.dataset["emptyResultRuns"]);
|
|
40
|
+
return {
|
|
41
|
+
fieldType: dom.dataset["fieldType"] ?? "UNKNOWN",
|
|
42
|
+
instruction: dom.dataset["instruction"] ?? "",
|
|
43
|
+
displayText: (emptyResultRuns === null ? void 0 : dom.dataset["displayText"]) ?? dom.textContent ?? "",
|
|
44
|
+
fieldKind: dom.dataset["fieldKind"] ?? "simple",
|
|
45
|
+
fldLock: statedFlag(dom.dataset["fldLock"]),
|
|
46
|
+
dirty: statedFlag(dom.dataset["dirty"]),
|
|
47
|
+
fieldResultIsFallback: statedFlag(dom.dataset["fieldResultIsFallback"]),
|
|
48
|
+
formFieldDataXml: dom.dataset["formFieldDataXml"] ?? null,
|
|
49
|
+
_docxEmptyResultRuns: emptyResultRuns,
|
|
50
|
+
_docxFieldCode: readFieldCode(dom.dataset["fieldCode"])
|
|
51
|
+
};
|
|
52
|
+
};
|
|
26
53
|
const getFieldDomAttrs = (node) => {
|
|
27
|
-
const { fieldType, instruction, fieldKind, fldLock, dirty, fieldResultIsFallback } = expectFieldAttrs(node);
|
|
54
|
+
const { fieldType, instruction, fieldKind, fldLock, dirty, fieldResultIsFallback, formFieldDataXml, _docxEmptyResultRuns, _docxFieldCode } = expectFieldAttrs(node);
|
|
28
55
|
return {
|
|
29
56
|
class: `docx-field docx-field-${fieldType.toLowerCase()}`,
|
|
30
57
|
"data-field-type": fieldType,
|
|
@@ -33,6 +60,9 @@ const getFieldDomAttrs = (node) => {
|
|
|
33
60
|
...fldLock === void 0 ? {} : { "data-fld-lock": String(fldLock) },
|
|
34
61
|
...dirty === void 0 ? {} : { "data-dirty": String(dirty) },
|
|
35
62
|
...fieldResultIsFallback === void 0 ? {} : { "data-field-result-is-fallback": String(fieldResultIsFallback) },
|
|
63
|
+
...formFieldDataXml === void 0 ? {} : { "data-form-field-data-xml": formFieldDataXml },
|
|
64
|
+
..._docxEmptyResultRuns === void 0 ? {} : { "data-empty-result-runs": JSON.stringify(_docxEmptyResultRuns) },
|
|
65
|
+
..._docxFieldCode === void 0 ? {} : { "data-field-code": JSON.stringify(_docxFieldCode) },
|
|
36
66
|
style: "outline: 1px solid var(--doc-field-outline, rgba(200,200,200,0.4)); padding: 0 1px; border-radius: 2px;"
|
|
37
67
|
};
|
|
38
68
|
};
|
|
@@ -53,7 +83,7 @@ const getFieldVisibleText = (node) => {
|
|
|
53
83
|
const FieldExtension = createNodeExtension({
|
|
54
84
|
name: "field",
|
|
55
85
|
schemaNodeName: "field",
|
|
56
|
-
nodeSpec: {
|
|
86
|
+
nodeSpec: (options) => ({
|
|
57
87
|
inline: true,
|
|
58
88
|
group: "inline",
|
|
59
89
|
atom: true,
|
|
@@ -65,13 +95,18 @@ const FieldExtension = createNodeExtension({
|
|
|
65
95
|
getAttrs: readFieldDomAttrs
|
|
66
96
|
}],
|
|
67
97
|
toDOM(node) {
|
|
98
|
+
const { displayText, _docxEmptyResultRuns } = expectFieldAttrs(node);
|
|
68
99
|
return [
|
|
69
100
|
"span",
|
|
70
|
-
|
|
101
|
+
{
|
|
102
|
+
...getFieldDomAttrs(node),
|
|
103
|
+
...options.getInternalClipboardToken ? { "data-docx-internal-clipboard": options.getInternalClipboardToken() } : {},
|
|
104
|
+
..._docxEmptyResultRuns ? { "data-display-text": displayText } : {}
|
|
105
|
+
},
|
|
71
106
|
getFieldVisibleText(node)
|
|
72
107
|
];
|
|
73
108
|
}
|
|
74
|
-
}
|
|
109
|
+
})
|
|
75
110
|
});
|
|
76
111
|
const StructuredFieldExtension = createNodeExtension({
|
|
77
112
|
name: "structuredField",
|
|
@@ -35,7 +35,10 @@ const PreservedBlockExtension = createNodeExtension({
|
|
|
35
35
|
group: "block",
|
|
36
36
|
atom: true,
|
|
37
37
|
selectable: false,
|
|
38
|
-
attrs: {
|
|
38
|
+
attrs: {
|
|
39
|
+
xml: {},
|
|
40
|
+
readerText: { default: null }
|
|
41
|
+
},
|
|
39
42
|
parseDOM: [{
|
|
40
43
|
tag: "div[data-docx-preserved-block]",
|
|
41
44
|
getAttrs(dom) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColorValue } from "../../../types/colors.js";
|
|
2
2
|
import { AnyExtension, Extension, NodeExtension } from "../types.js";
|
|
3
|
-
import { Command, EditorState } from "prosemirror-state";
|
|
4
3
|
import { Node } from "prosemirror-model";
|
|
4
|
+
import { Command, EditorState } from "prosemirror-state";
|
|
5
5
|
//#region src/prosemirror/extensions/nodes/TableExtension.d.ts
|
|
6
6
|
type TableContextInfo = {
|
|
7
7
|
isInTable: boolean;
|