@stll/folio-core 0.35.1 → 0.37.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 +59 -1
- package/dist/ai-edits/apply.js +878 -377
- package/dist/ai-edits/block-identity.d.ts +4 -1
- package/dist/ai-edits/block-identity.js +4 -1
- package/dist/ai-edits/blockRange.js +14 -14
- package/dist/ai-edits/clean-text.d.ts +40 -1
- package/dist/ai-edits/clean-text.js +52 -2
- package/dist/ai-edits/headless.d.ts +3 -1
- package/dist/ai-edits/headless.js +141 -73
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -2
- package/dist/ai-edits/read.js +38 -20
- package/dist/ai-edits/snapshot.d.ts +14 -6
- package/dist/ai-edits/snapshot.js +105 -20
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +7 -0
- package/dist/ai-edits/table-template.d.ts +11 -1
- package/dist/ai-edits/table-template.js +49 -17
- package/dist/ai-edits/types.d.ts +62 -61
- package/dist/ai-edits/word-diff.d.ts +18 -3
- package/dist/ai-edits/word-diff.js +556 -67
- package/dist/ai-suggestions/conflict.js +1 -4
- package/dist/ai-suggestions/text-positions.d.ts +8 -0
- package/dist/ai-suggestions/text-positions.js +27 -5
- package/dist/compare/__fixtures__/body-sequence.js +3 -4
- package/dist/compare/column-alignment.d.ts +13 -13
- package/dist/compare/column-alignment.js +78 -39
- package/dist/compare/compare.d.ts +4 -3
- package/dist/compare/compare.js +48 -21
- package/dist/compare/content-alignment.d.ts +95 -0
- package/dist/compare/content-alignment.js +1450 -0
- package/dist/compare/content-types.d.ts +100 -0
- package/dist/compare/content-types.js +0 -0
- package/dist/compare/content.d.ts +209 -0
- package/dist/compare/content.js +885 -0
- package/dist/compare/formatting.d.ts +5 -5
- package/dist/compare/formatting.js +6 -4
- package/dist/compare/plan.d.ts +6 -1
- package/dist/compare/plan.js +171 -566
- package/dist/compare/scenario.d.ts +2 -2
- package/dist/compare/types.d.ts +3 -3
- package/dist/compare/verification.d.ts +8 -9
- package/dist/compare/verification.js +72 -50
- package/dist/compat/eigenpal.d.ts +5 -3
- package/dist/compat/eigenpal.js +3 -2
- package/dist/controller/headerFooterEditorManager.js +18 -10
- package/dist/controller/hiddenEditorApi.js +1 -1
- package/dist/controller/hiddenEditorManager.d.ts +7 -2
- package/dist/controller/hiddenEditorManager.js +15 -6
- package/dist/controller/layoutPipeline.js +5 -3
- package/dist/controller/noteEditorManager.js +12 -7
- package/dist/display-list/build/headerFooterPrimitives.js +1 -0
- package/dist/display-list/build/storyPrimitives.d.ts +5 -2
- package/dist/display-list/build/storyPrimitives.js +60 -3
- package/dist/display-list/build/tablePrimitives.js +30 -0
- package/dist/display-list/primitives.d.ts +1 -1
- package/dist/document-operations.d.ts +8 -4
- package/dist/document-operations.js +104 -12
- package/dist/docx/blockContentParser.js +6 -27
- package/dist/docx/commentParser.js +2 -4
- package/dist/docx/commentRangeIntegrity.js +2 -4
- package/dist/docx/documentClone.d.ts +2 -0
- package/dist/docx/documentClone.js +2 -0
- package/dist/docx/ensureParaIds.js +9 -4
- package/dist/docx/headerFooterParser.js +2 -4
- package/dist/docx/normalizeBaseDirection.js +5 -7
- package/dist/docx/numberingParser.d.ts +3 -1
- package/dist/docx/numberingParser.js +4 -1
- package/dist/docx/paragraphParser.js +34 -35
- package/dist/docx/paragraphPropertySource.d.ts +49 -0
- package/dist/docx/paragraphPropertySource.js +113 -0
- package/dist/docx/paragraphTraversal.js +30 -34
- package/dist/docx/rezip.d.ts +0 -8
- package/dist/docx/rezip.js +41 -16
- package/dist/docx/runConsolidator.js +2 -4
- package/dist/docx/runParser.js +6 -17
- package/dist/docx/sectionParser.js +1 -15
- package/dist/docx/serializer/paragraphSerializer.js +289 -30
- package/dist/docx/serializer/runSerializer.js +6 -12
- package/dist/docx/serializer/sectionPropertiesSerializer.js +2 -10
- package/dist/docx/serializer/tableSerializer.js +4 -23
- package/dist/docx/serializer/trackedChangeAttributes.d.ts +11 -0
- package/dist/docx/serializer/trackedChangeAttributes.js +31 -0
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/server/createBilingualDocument.js +8 -10
- package/dist/docx/server/evaluateDocxXmlPatchProposal.js +22 -13
- package/dist/docx/server/validateDocxConformance.js +17 -13
- package/dist/docx/tableParser.js +1 -37
- package/dist/docx/trackedChangeInfo.d.ts +11 -0
- package/dist/docx/trackedChangeInfo.js +38 -0
- package/dist/docx/verbatimCapture.d.ts +20 -9
- package/dist/docx/verbatimCapture.js +208 -8
- package/dist/docx/xmlParser.d.ts +3 -1
- package/dist/docx/xmlParser.js +6 -1
- package/dist/docx/xmlSafety.d.ts +1 -1
- package/dist/docx/xmlSafety.js +157 -0
- package/dist/headless-layout.js +5 -4
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -2
- package/dist/internal/headlessRevisionResolution.d.ts +23 -0
- package/dist/internal/headlessRevisionResolution.js +155 -0
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +12 -0
- package/dist/internal/headlessRevisionResolutionGuard.js +28 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +9 -0
- package/dist/internal/pageBreakRunDescendantIndex.js +27 -0
- package/dist/internal/pageBreakRunPartition.d.ts +26 -0
- package/dist/internal/pageBreakRunPartition.js +35 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +15 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +126 -0
- package/dist/internal/sectionEndpointResolution.d.ts +32 -0
- package/dist/internal/sectionEndpointResolution.js +38 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +16 -4
- package/dist/layout-bridge/convert/headerFooterLayout.js +52 -9
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +4 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +391 -82
- package/dist/layout-bridge/dom/clickToPositionDom.d.ts +8 -1
- package/dist/layout-bridge/dom/clickToPositionDom.js +114 -40
- package/dist/layout-bridge/dom/textStreamDom.d.ts +24 -0
- package/dist/layout-bridge/dom/textStreamDom.js +75 -0
- package/dist/layout-bridge/headerFooterLayout.js +16 -30
- package/dist/layout-engine/index.js +12 -3
- package/dist/layout-engine/measure/tableFragmentBorderGeometry.d.ts +17 -0
- package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +24 -0
- package/dist/layout-engine/renderedBreakReconciliation.js +1 -1
- package/dist/layout-engine/types.d.ts +7 -0
- package/dist/layout-painter/imageLayout.d.ts +1 -1
- package/dist/layout-painter/renderTable.js +20 -0
- package/dist/markdown/renderBlock.js +7 -10
- package/dist/model.d.ts +1 -1
- package/dist/paged-layout/rangeProjection.js +6 -9
- package/dist/paged-layout/transactionDirtyRange.d.ts +3 -1
- package/dist/paged-layout/transactionDirtyRange.js +23 -1
- package/dist/prosemirror/attrs/index.d.ts +7 -3
- package/dist/prosemirror/attrs/index.js +128 -7
- package/dist/prosemirror/bookmarkBoundaryIntegrity.d.ts +9 -0
- package/dist/prosemirror/bookmarkBoundaryIntegrity.js +22 -0
- package/dist/prosemirror/commands/comments.d.ts +10 -1
- package/dist/prosemirror/commands/comments.js +551 -87
- package/dist/prosemirror/commands/formatPainter.d.ts +45 -10
- package/dist/prosemirror/commands/formatPainter.js +319 -63
- package/dist/prosemirror/commands/index.d.ts +2 -2
- package/dist/prosemirror/commands/pageBreak.d.ts +5 -2
- package/dist/prosemirror/commands/pageBreak.js +18 -36
- package/dist/prosemirror/commands/propertyChangeScope.d.ts +27 -3
- package/dist/prosemirror/commands/propertyChangeScope.js +85 -14
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +8 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +935 -223
- package/dist/prosemirror/conversion/runShadingMark.js +2 -2
- package/dist/prosemirror/conversion/toProseDoc.d.ts +26 -1
- package/dist/prosemirror/conversion/toProseDoc.js +439 -291
- package/dist/prosemirror/extensions/StarterKit.js +4 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +54 -6
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +7 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +95 -123
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +19 -6
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +27 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +134 -30
- package/dist/prosemirror/extensions/features/pasteCleanup.js +9 -15
- package/dist/prosemirror/extensions/marks/BoldExtension.js +4 -3
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +4 -7
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +5 -11
- package/dist/prosemirror/extensions/marks/FontSizeExtension.js +3 -3
- package/dist/prosemirror/extensions/marks/ItalicExtension.js +4 -3
- package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +39 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +7 -1
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +67 -21
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +8 -1
- package/dist/prosemirror/extensions/marks/markUtils.js +88 -2
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +44 -3
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +1 -1
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +15 -4
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +6 -0
- package/dist/prosemirror/extensions/nodes/PageBreakRunExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/PageBreakRunExtension.js +36 -0
- package/dist/prosemirror/findReplaceSelection.js +8 -3
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/listMarker.d.ts +26 -1
- package/dist/prosemirror/listMarker.js +108 -14
- package/dist/prosemirror/pageBreakRunProjection.d.ts +28 -0
- package/dist/prosemirror/pageBreakRunProjection.js +47 -0
- package/dist/prosemirror/paraText.js +6 -0
- package/dist/prosemirror/paragraphAlignment.d.ts +12 -0
- package/dist/prosemirror/paragraphAlignment.js +13 -0
- package/dist/prosemirror/paragraphSpacing.d.ts +29 -0
- package/dist/prosemirror/paragraphSpacing.js +125 -0
- package/dist/prosemirror/plugins/documentNumbering.d.ts +8 -0
- package/dist/prosemirror/plugins/documentNumbering.js +18 -0
- package/dist/prosemirror/plugins/pmTextScan.d.ts +3 -2
- package/dist/prosemirror/plugins/pmTextScan.js +14 -4
- package/dist/prosemirror/plugins/suggestionMode.js +9 -11
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +16 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +61 -0
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +64 -0
- package/dist/prosemirror/runFormattingInlineCarriers.js +121 -0
- package/dist/prosemirror/runFormattingProvenance.d.ts +12 -0
- package/dist/prosemirror/runFormattingProvenance.js +48 -0
- package/dist/prosemirror/runFormattingReconciliation.d.ts +25 -0
- package/dist/prosemirror/runFormattingReconciliation.js +54 -0
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +18 -0
- package/dist/prosemirror/runPropertyChangeResolution.js +18 -0
- package/dist/prosemirror/runStyleFormatting.d.ts +50 -0
- package/dist/prosemirror/runStyleFormatting.js +105 -0
- package/dist/prosemirror/schema/index.d.ts +3 -3
- package/dist/prosemirror/schema/marks.d.ts +84 -9
- package/dist/prosemirror/schema/marks.js +73 -1
- package/dist/prosemirror/schema/nodes.d.ts +30 -6
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +14 -2
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +45 -23
- package/dist/prosemirror/styles/styleResolver.d.ts +10 -13
- package/dist/prosemirror/styles/styleResolver.js +3 -3
- package/dist/prosemirror/styles/styleToggleCascade.d.ts +8 -1
- package/dist/prosemirror/styles/styleToggleCascade.js +24 -1
- package/dist/prosemirror/tableGridMutation.d.ts +20 -0
- package/dist/prosemirror/tableGridMutation.js +30 -0
- package/dist/prosemirror/trackedRunInlineAtoms.d.ts +31 -0
- package/dist/prosemirror/trackedRunInlineAtoms.js +39 -0
- package/dist/prosemirror/utils/visualLineNavigation.js +27 -31
- package/dist/prosemirror/validation.js +23 -4
- package/dist/redline.js +4 -1
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +20 -20
- package/dist/render-dom/RenderedDomContext.js +17 -34
- package/dist/server.d.ts +4 -4
- package/dist/server.js +2 -2
- package/dist/style-engine/styleEngine.d.ts +1 -1
- package/dist/utils/clipboard.js +1 -1
- package/dist/utils/findReplace.js +38 -21
- package/dist/utils/mergeDocumentContent.js +3 -3
- package/dist/utils/replaceText.js +2 -1
- package/dist/version-comparison.d.ts +38 -44
- package/dist/version-comparison.js +270 -399
- package/dist/watermark/index.js +2 -4
- package/package.json +8 -2
|
@@ -30,6 +30,7 @@ import { HighlightExtension } from "./marks/HighlightExtension.js";
|
|
|
30
30
|
import { HyperlinkExtension } from "./marks/HyperlinkExtension.js";
|
|
31
31
|
import { ItalicExtension } from "./marks/ItalicExtension.js";
|
|
32
32
|
import { LanguageExtension } from "./marks/LanguageExtension.js";
|
|
33
|
+
import { PageBreakRunOwnerExtension } from "./marks/PageBreakRunOwnerExtension.js";
|
|
33
34
|
import { RtlExtension } from "./marks/RtlExtension.js";
|
|
34
35
|
import { RunFormattingOverrideExtension } from "./marks/RunFormattingOverrideExtension.js";
|
|
35
36
|
import { RunShadingExtension } from "./marks/RunShadingExtension.js";
|
|
@@ -50,6 +51,7 @@ import { HorizontalRuleExtension } from "./nodes/HorizontalRuleExtension.js";
|
|
|
50
51
|
import { ImageExtension } from "./nodes/ImageExtension.js";
|
|
51
52
|
import { MathExtension } from "./nodes/MathExtension.js";
|
|
52
53
|
import { PageBreakExtension } from "./nodes/PageBreakExtension.js";
|
|
54
|
+
import { PageBreakRunExtension } from "./nodes/PageBreakRunExtension.js";
|
|
53
55
|
import { RenderedPageBreakExtension } from "./nodes/RenderedPageBreakExtension.js";
|
|
54
56
|
import { SdtExtension } from "./nodes/SdtExtension.js";
|
|
55
57
|
import { ShapeExtension } from "./nodes/ShapeExtension.js";
|
|
@@ -107,6 +109,7 @@ function createStarterKit(options = {}) {
|
|
|
107
109
|
add("textEffect", TextEffectExtension());
|
|
108
110
|
add("runFormattingOverride", RunFormattingOverrideExtension());
|
|
109
111
|
add("characterStyle", CharacterStyleExtension());
|
|
112
|
+
add("pageBreakRunOwner", PageBreakRunOwnerExtension());
|
|
110
113
|
add("comment", CommentExtension());
|
|
111
114
|
add("insertion", InsertionExtension());
|
|
112
115
|
add("deletion", DeletionExtension());
|
|
@@ -125,6 +128,7 @@ function createStarterKit(options = {}) {
|
|
|
125
128
|
add("gapCursor", GapCursorExtension());
|
|
126
129
|
add("horizontalRule", HorizontalRuleExtension());
|
|
127
130
|
add("pageBreak", PageBreakExtension());
|
|
131
|
+
add("pageBreakRun", PageBreakRunExtension());
|
|
128
132
|
add("renderedPageBreak", RenderedPageBreakExtension());
|
|
129
133
|
add("field", FieldExtension());
|
|
130
134
|
add("field", StructuredFieldExtension({ getInternalClipboardToken }));
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { PARAGRAPH_ALIGNMENT_VALUES } from "../../../types/documentEnumValues.js";
|
|
1
2
|
import { paragraphToStyle } from "../../../utils/formatToStyle.js";
|
|
2
3
|
import { collectHeadings } from "../../../utils/headingCollector.js";
|
|
3
4
|
import { tableOfContentsStyleLevel } from "../../../utils/tableOfContentsStyle.js";
|
|
4
5
|
import { expectParagraphAttrs } from "../../attrs/index.js";
|
|
5
6
|
import { autospacingMatchesBase } from "../../autospacingBase.js";
|
|
7
|
+
import { directParagraphAlignment } from "../../paragraphAlignment.js";
|
|
6
8
|
import { directionIsRtl } from "../../paragraphDirection.js";
|
|
9
|
+
import { withDirectParagraphSpacing } from "../../paragraphSpacing.js";
|
|
7
10
|
import { listAttrsFromResolvedStyle, paragraphAttrsFromResolvedStyle } from "../../styles/resolvedStyleAttrs.js";
|
|
8
11
|
import { createNodeExtension } from "../create.js";
|
|
9
12
|
import { Fragment } from "prosemirror-model";
|
|
@@ -95,6 +98,7 @@ function cssTextAlignToAlignment(value) {
|
|
|
95
98
|
default: return;
|
|
96
99
|
}
|
|
97
100
|
}
|
|
101
|
+
const parseParagraphAlignment = (value) => PARAGRAPH_ALIGNMENT_VALUES.find((alignment) => alignment === value);
|
|
98
102
|
/**
|
|
99
103
|
* Parse CSS line-height to twips.
|
|
100
104
|
* - Unitless multiplier (e.g. "1.5"): 240 twips * multiplier (single=240)
|
|
@@ -162,7 +166,7 @@ function extractParagraphAttrsFromStyle(element) {
|
|
|
162
166
|
if (spacing) {
|
|
163
167
|
attrs.lineSpacing = spacing.lineSpacing;
|
|
164
168
|
attrs.lineSpacingRule = spacing.lineSpacingRule;
|
|
165
|
-
attrs.lineSpacingExplicit =
|
|
169
|
+
attrs.lineSpacingExplicit = "both";
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
if (style.marginTop) {
|
|
@@ -180,8 +184,10 @@ const paragraphNodeSpec = {
|
|
|
180
184
|
group: "block",
|
|
181
185
|
attrs: {
|
|
182
186
|
paraId: { default: null },
|
|
187
|
+
idStability: { default: void 0 },
|
|
183
188
|
textId: { default: null },
|
|
184
189
|
alignment: { default: null },
|
|
190
|
+
alignmentFromStyle: { default: void 0 },
|
|
185
191
|
kinsoku: { default: null },
|
|
186
192
|
overflowPunctuation: { default: null },
|
|
187
193
|
suppressAutoHyphens: { default: null },
|
|
@@ -204,6 +210,7 @@ const paragraphNodeSpec = {
|
|
|
204
210
|
listIsBullet: { default: null },
|
|
205
211
|
listIsLegal: { default: null },
|
|
206
212
|
listMarker: { default: null },
|
|
213
|
+
listMarkerTemplate: { default: void 0 },
|
|
207
214
|
listMarkerHidden: { default: null },
|
|
208
215
|
listMarkerFormatting: { default: null },
|
|
209
216
|
listMarkerAlignment: { default: null },
|
|
@@ -249,23 +256,32 @@ const paragraphNodeSpec = {
|
|
|
249
256
|
if (!(dom instanceof HTMLElement)) return false;
|
|
250
257
|
const element = dom;
|
|
251
258
|
const paraId = element.dataset["paraId"];
|
|
252
|
-
const alignment = element.dataset["alignment"];
|
|
259
|
+
const alignment = parseParagraphAlignment(element.dataset["alignment"]);
|
|
260
|
+
const authoredAlignment = parseParagraphAlignment(element.dataset["directAlignment"]);
|
|
261
|
+
const alignmentFromStyle = parseParagraphAlignment(element.dataset["alignmentFromStyle"]);
|
|
253
262
|
const styleId = element.dataset["styleId"];
|
|
254
263
|
const tableOfContentsLevel = Number(element.dataset["tableOfContentsLevel"]);
|
|
255
264
|
const sectionBreakType = element.dataset["sectionBreak"];
|
|
256
265
|
const attrs = {
|
|
257
266
|
...paraId ? { paraId } : {},
|
|
258
267
|
...alignment ? { alignment } : {},
|
|
268
|
+
...alignmentFromStyle ? { alignmentFromStyle } : {},
|
|
259
269
|
...styleId ? { styleId } : {},
|
|
260
270
|
...Number.isSafeInteger(tableOfContentsLevel) && tableOfContentsLevel > 0 ? { _tableOfContentsLevel: tableOfContentsLevel } : {},
|
|
261
271
|
...sectionBreakType ? { sectionBreakType } : {}
|
|
262
272
|
};
|
|
263
273
|
const styleAttrs = extractParagraphAttrsFromStyle(element);
|
|
264
274
|
const mergedAlignment = attrs.alignment || styleAttrs.alignment;
|
|
275
|
+
const mergedDirectAlignment = authoredAlignment ?? (attrs.alignmentFromStyle === void 0 ? mergedAlignment : void 0);
|
|
276
|
+
const originalFormatting = {
|
|
277
|
+
...styleId ? { styleId } : {},
|
|
278
|
+
...mergedDirectAlignment ? { alignment: mergedDirectAlignment } : {}
|
|
279
|
+
};
|
|
265
280
|
return {
|
|
266
281
|
...styleAttrs,
|
|
267
282
|
...attrs,
|
|
268
|
-
...mergedAlignment !== void 0 ? { alignment: mergedAlignment } : {}
|
|
283
|
+
...mergedAlignment !== void 0 ? { alignment: mergedAlignment } : {},
|
|
284
|
+
...Object.keys(originalFormatting).length > 0 ? { _originalFormatting: originalFormatting } : {}
|
|
269
285
|
};
|
|
270
286
|
}
|
|
271
287
|
}, ...[
|
|
@@ -279,8 +295,10 @@ const paragraphNodeSpec = {
|
|
|
279
295
|
tag,
|
|
280
296
|
getAttrs(dom) {
|
|
281
297
|
const level = Number.parseInt(tag.charAt(1), 10);
|
|
298
|
+
const styleAttrs = extractParagraphAttrsFromStyle(dom);
|
|
282
299
|
return {
|
|
283
|
-
...
|
|
300
|
+
...styleAttrs,
|
|
301
|
+
...styleAttrs.alignment ? { _originalFormatting: { alignment: styleAttrs.alignment } } : {},
|
|
284
302
|
styleId: `Heading${level}`,
|
|
285
303
|
outlineLevel: level - 1
|
|
286
304
|
};
|
|
@@ -295,6 +313,9 @@ const paragraphNodeSpec = {
|
|
|
295
313
|
if (listClass) domAttrs["class"] = listClass;
|
|
296
314
|
if (attrs.paraId) domAttrs["data-para-id"] = attrs.paraId;
|
|
297
315
|
if (attrs.alignment) domAttrs["data-alignment"] = attrs.alignment;
|
|
316
|
+
const directAlignment = directParagraphAlignment(attrs);
|
|
317
|
+
if (directAlignment) domAttrs["data-direct-alignment"] = directAlignment;
|
|
318
|
+
if (attrs.alignmentFromStyle) domAttrs["data-alignment-from-style"] = attrs.alignmentFromStyle;
|
|
298
319
|
if (attrs.styleId) domAttrs["data-style-id"] = attrs.styleId;
|
|
299
320
|
if (typeof attrs._tableOfContentsLevel === "number") domAttrs["data-table-of-contents-level"] = String(attrs._tableOfContentsLevel);
|
|
300
321
|
if (attrs.listMarker) domAttrs["data-list-marker"] = attrs.listMarker;
|
|
@@ -373,13 +394,33 @@ function setParagraphAttrsCmd(attrs) {
|
|
|
373
394
|
};
|
|
374
395
|
}
|
|
375
396
|
function makeSetAlignment(alignment) {
|
|
376
|
-
return (state, dispatch) =>
|
|
397
|
+
return (state, dispatch) => {
|
|
398
|
+
const { $from, $to } = state.selection;
|
|
399
|
+
if (!dispatch) return true;
|
|
400
|
+
let tr = state.tr;
|
|
401
|
+
const seen = /* @__PURE__ */ new Set();
|
|
402
|
+
state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
403
|
+
if (node.type.name !== "paragraph" || seen.has(pos)) return;
|
|
404
|
+
seen.add(pos);
|
|
405
|
+
const attrs = expectParagraphAttrs(node);
|
|
406
|
+
tr = tr.setNodeMarkup(pos, void 0, {
|
|
407
|
+
...node.attrs,
|
|
408
|
+
alignment,
|
|
409
|
+
_originalFormatting: {
|
|
410
|
+
...attrs._originalFormatting,
|
|
411
|
+
alignment
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
dispatch(tr.scrollIntoView());
|
|
416
|
+
return true;
|
|
417
|
+
};
|
|
377
418
|
}
|
|
378
419
|
function makeSetLineSpacing(value, rule = "auto") {
|
|
379
420
|
return (state, dispatch) => setParagraphAttrsCmd({
|
|
380
421
|
lineSpacing: value,
|
|
381
422
|
lineSpacingRule: rule,
|
|
382
|
-
lineSpacingExplicit:
|
|
423
|
+
lineSpacingExplicit: "both"
|
|
383
424
|
})(state, dispatch);
|
|
384
425
|
}
|
|
385
426
|
function makeIncreaseIndent(amount = 720) {
|
|
@@ -474,6 +515,13 @@ function makeApplyStyle(schema) {
|
|
|
474
515
|
styleId,
|
|
475
516
|
...resolvedAttrs.styleName ? { styleName: resolvedAttrs.styleName } : {}
|
|
476
517
|
}));
|
|
518
|
+
const originalFormatting = {
|
|
519
|
+
...expectParagraphAttrs(node)._originalFormatting,
|
|
520
|
+
styleId
|
|
521
|
+
};
|
|
522
|
+
Reflect.deleteProperty(originalFormatting, "alignment");
|
|
523
|
+
newAttrs["_originalFormatting"] = withDirectParagraphSpacing(originalFormatting, void 0);
|
|
524
|
+
newAttrs["spacingExplicit"] = null;
|
|
477
525
|
const listAttrs = listAttrsFromResolvedStyle(resolvedAttrs, resolvedAttrs.numbering);
|
|
478
526
|
if (listAttrs) Object.assign(newAttrs, listAttrs);
|
|
479
527
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setProseParagraphMarkupWithPropertySource } from "../../../docx/paragraphPropertySource.js";
|
|
1
2
|
import { getTransactionDirtyRange } from "../../../paged-layout/transactionDirtyRange.js";
|
|
2
3
|
import { detectBaseDirection } from "../../../utils/baseDirection.js";
|
|
3
4
|
import { directionIsAutoManaged } from "../../paragraphDirection.js";
|
|
@@ -62,7 +63,12 @@ const collectBidiUpdatesInRange = (doc, range) => {
|
|
|
62
63
|
};
|
|
63
64
|
const applyBidiUpdates = (state, updates) => {
|
|
64
65
|
const tr = state.tr;
|
|
65
|
-
for (const update of updates)
|
|
66
|
+
for (const update of updates) setProseParagraphMarkupWithPropertySource({
|
|
67
|
+
attrs: update.attrs,
|
|
68
|
+
ownership: "preserve",
|
|
69
|
+
pos: update.pos,
|
|
70
|
+
transaction: tr
|
|
71
|
+
});
|
|
66
72
|
ignoreTrackedChanges(tr);
|
|
67
73
|
tr.setMeta(autoBidiDetectionKey, "applied");
|
|
68
74
|
tr.setMeta("addToHistory", false);
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { expectParagraphAttrs } from "../../attrs/index.js";
|
|
2
|
-
import { PPR_CHANGE_SCOPED_ATTR_KEYS } from "../../commands/propertyChangeScope.js";
|
|
2
|
+
import { PPR_CHANGE_SCOPED_ATTR_KEYS, hasSerializableParagraphPropertyChange } from "../../commands/propertyChangeScope.js";
|
|
3
|
+
import { CLEARED_LIST_RENDERING_ATTRS, LIST_RENDERING_ATTR_KEYS } from "../../listMarker.js";
|
|
4
|
+
import { getDocumentNumbering } from "../../plugins/documentNumbering.js";
|
|
3
5
|
import { SUGGESTION_META, makeRevisionInfo } from "../../plugins/suggestionMode.js";
|
|
6
|
+
import { listLevelAttrPatch } from "../../styles/resolvedStyleAttrs.js";
|
|
4
7
|
import { createExtension } from "../create.js";
|
|
5
8
|
import { goToNextCell, goToPrevCell } from "../nodes/TableExtension.js";
|
|
6
9
|
import { Priority } from "../types.js";
|
|
10
|
+
import { panic } from "better-result";
|
|
7
11
|
//#region src/prosemirror/extensions/features/ListExtension.ts
|
|
12
|
+
/**
|
|
13
|
+
* List Extension — list commands + keymaps
|
|
14
|
+
*
|
|
15
|
+
* No schema contribution — lists use paragraph attrs (numPr).
|
|
16
|
+
* Provides: toggle bullet/number, indent/outdent, enter/backspace handling.
|
|
17
|
+
*/
|
|
8
18
|
function chainCommands(...commands) {
|
|
9
19
|
return (state, dispatch, view) => {
|
|
10
20
|
for (const cmd of commands) if (cmd(state, dispatch, view)) return true;
|
|
@@ -25,65 +35,73 @@ function appendParagraphPropertyChange(attrs, existing, previousFormatting, rev)
|
|
|
25
35
|
}]
|
|
26
36
|
};
|
|
27
37
|
}
|
|
28
|
-
const LIST_FORMATTING_ATTRS = [
|
|
29
|
-
"numPr",
|
|
30
|
-
"listIsBullet",
|
|
31
|
-
"listIsLegal",
|
|
32
|
-
"listNumFmt",
|
|
33
|
-
"listMarker",
|
|
34
|
-
"listMarkerHidden",
|
|
35
|
-
"listMarkerFormatting",
|
|
36
|
-
"listMarkerAlignment",
|
|
37
|
-
"listMarkerSuffix",
|
|
38
|
-
"listLevelNumFmts",
|
|
39
|
-
"listLevelStarts",
|
|
40
|
-
"listAbstractNumId",
|
|
41
|
-
"listStartOverride"
|
|
42
|
-
];
|
|
43
38
|
function getPreviousListFormatting(attrs) {
|
|
44
39
|
const previousFormatting = {};
|
|
45
40
|
for (const key of PPR_CHANGE_SCOPED_ATTR_KEYS) {
|
|
46
41
|
const value = attrs[key];
|
|
47
42
|
if (value != null) previousFormatting[key] = value;
|
|
48
43
|
}
|
|
49
|
-
|
|
44
|
+
previousFormatting["numPr"] = attrs["numPr"] ?? null;
|
|
45
|
+
for (const key of LIST_RENDERING_ATTR_KEYS) previousFormatting[key] = attrs[key] ?? null;
|
|
50
46
|
return previousFormatting;
|
|
51
47
|
}
|
|
48
|
+
function clearListAttrs(attrs) {
|
|
49
|
+
const styleNumPr = attrs.numPrFromStyle;
|
|
50
|
+
const numPr = styleNumPr?.numId !== void 0 && styleNumPr.numId !== 0 ? {
|
|
51
|
+
numId: 0,
|
|
52
|
+
ilvl: attrs.numPr?.ilvl ?? styleNumPr.ilvl ?? 0
|
|
53
|
+
} : null;
|
|
54
|
+
return {
|
|
55
|
+
...attrs,
|
|
56
|
+
numPr,
|
|
57
|
+
...CLEARED_LIST_RENDERING_ATTRS
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function hasActiveListNumbering(attrs) {
|
|
61
|
+
return attrs.numPr?.numId !== void 0 && attrs.numPr.numId !== 0;
|
|
62
|
+
}
|
|
52
63
|
function toggleList(numId) {
|
|
53
64
|
return (state, dispatch) => {
|
|
54
65
|
const { $from, $to } = state.selection;
|
|
55
66
|
const paragraph = $from.parent;
|
|
56
67
|
if (paragraph.type.name !== "paragraph") return false;
|
|
57
68
|
const isInSameList = paragraph.attrs["numPr"]?.numId === numId;
|
|
69
|
+
const rev = makeRevisionInfo(state);
|
|
70
|
+
if (rev) {
|
|
71
|
+
let hasPendingChange = false;
|
|
72
|
+
state.doc.nodesBetween($from.pos, $to.pos, (node) => {
|
|
73
|
+
if (node.type.name === "paragraph" && hasSerializableParagraphPropertyChange(expectParagraphAttrs(node)._propertyChanges)) {
|
|
74
|
+
hasPendingChange = true;
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (hasPendingChange) return false;
|
|
79
|
+
}
|
|
58
80
|
if (!dispatch) return true;
|
|
59
81
|
let tr = state.tr;
|
|
60
82
|
const seen = /* @__PURE__ */ new Set();
|
|
61
|
-
const rev = makeRevisionInfo(state);
|
|
62
83
|
state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
63
84
|
if (node.type.name === "paragraph" && !seen.has(pos)) {
|
|
64
85
|
seen.add(pos);
|
|
65
86
|
let nextAttrs;
|
|
66
|
-
if (isInSameList) nextAttrs =
|
|
67
|
-
...node.attrs,
|
|
68
|
-
numPr: null,
|
|
69
|
-
listIsBullet: null,
|
|
70
|
-
listNumFmt: null,
|
|
71
|
-
listMarker: null
|
|
72
|
-
};
|
|
87
|
+
if (isInSameList) nextAttrs = clearListAttrs(expectParagraphAttrs(node));
|
|
73
88
|
else {
|
|
74
89
|
const isBullet = numId === 1;
|
|
75
90
|
nextAttrs = {
|
|
76
91
|
...node.attrs,
|
|
92
|
+
...CLEARED_LIST_RENDERING_ATTRS,
|
|
77
93
|
numPr: {
|
|
78
94
|
numId,
|
|
79
95
|
ilvl: node.attrs["numPr"]?.ilvl || 0
|
|
80
96
|
},
|
|
81
97
|
listIsBullet: isBullet,
|
|
82
|
-
listNumFmt: isBullet ? null : "decimal"
|
|
83
|
-
listMarker: null
|
|
98
|
+
listNumFmt: isBullet ? null : "decimal"
|
|
84
99
|
};
|
|
85
100
|
}
|
|
86
|
-
if (rev)
|
|
101
|
+
if (rev) {
|
|
102
|
+
const existing = expectParagraphAttrs(node)._propertyChanges;
|
|
103
|
+
nextAttrs = appendParagraphPropertyChange(nextAttrs, existing, getPreviousListFormatting(node.attrs), rev);
|
|
104
|
+
}
|
|
87
105
|
tr = tr.setNodeMarkup(pos, void 0, nextAttrs);
|
|
88
106
|
}
|
|
89
107
|
});
|
|
@@ -94,55 +112,45 @@ function toggleList(numId) {
|
|
|
94
112
|
}
|
|
95
113
|
const toggleBulletList = (state, dispatch) => toggleList(1)(state, dispatch);
|
|
96
114
|
const toggleNumberedList = (state, dispatch) => toggleList(2)(state, dispatch);
|
|
115
|
+
const attrsForListLevel = (state, attrs, level) => {
|
|
116
|
+
if (!hasActiveListNumbering(attrs)) panic("Cannot change the level of a list without a numbering id");
|
|
117
|
+
return {
|
|
118
|
+
...attrs,
|
|
119
|
+
...listLevelAttrPatch(attrs, {
|
|
120
|
+
numId: attrs.numPr.numId,
|
|
121
|
+
ilvl: level
|
|
122
|
+
}, getDocumentNumbering(state))
|
|
123
|
+
};
|
|
124
|
+
};
|
|
97
125
|
const increaseListLevel = (state, dispatch) => {
|
|
98
126
|
const { $from } = state.selection;
|
|
99
127
|
const paragraph = $from.parent;
|
|
100
128
|
if (paragraph.type.name !== "paragraph") return false;
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
const attrs = expectParagraphAttrs(paragraph);
|
|
130
|
+
if (!hasActiveListNumbering(attrs)) return false;
|
|
131
|
+
const currentLevel = attrs.numPr.ilvl || 0;
|
|
103
132
|
if (currentLevel >= 8) return false;
|
|
104
133
|
if (!dispatch) return true;
|
|
105
134
|
const paragraphPos = $from.before($from.depth);
|
|
106
|
-
dispatch(state.tr.setNodeMarkup(paragraphPos, void 0, {
|
|
107
|
-
...paragraph.attrs,
|
|
108
|
-
numPr: {
|
|
109
|
-
...paragraph.attrs["numPr"],
|
|
110
|
-
ilvl: currentLevel + 1
|
|
111
|
-
},
|
|
112
|
-
indentLeft: null,
|
|
113
|
-
indentFirstLine: null,
|
|
114
|
-
hangingIndent: null
|
|
115
|
-
}).scrollIntoView());
|
|
135
|
+
dispatch(state.tr.setNodeMarkup(paragraphPos, void 0, { ...attrsForListLevel(state, attrs, currentLevel + 1) }).scrollIntoView());
|
|
116
136
|
return true;
|
|
117
137
|
};
|
|
118
138
|
const decreaseListLevel = (state, dispatch) => {
|
|
119
139
|
const { $from } = state.selection;
|
|
120
140
|
const paragraph = $from.parent;
|
|
121
141
|
if (paragraph.type.name !== "paragraph") return false;
|
|
122
|
-
|
|
123
|
-
|
|
142
|
+
const attrs = expectParagraphAttrs(paragraph);
|
|
143
|
+
if (!hasActiveListNumbering(attrs)) return false;
|
|
144
|
+
const currentLevel = attrs.numPr.ilvl || 0;
|
|
124
145
|
if (!dispatch) return true;
|
|
125
146
|
const paragraphPos = $from.before($from.depth);
|
|
126
147
|
if (currentLevel <= 0) dispatch(state.tr.setNodeMarkup(paragraphPos, void 0, {
|
|
127
|
-
...
|
|
128
|
-
numPr: null,
|
|
129
|
-
listIsBullet: null,
|
|
130
|
-
listNumFmt: null,
|
|
131
|
-
listMarker: null,
|
|
132
|
-
indentLeft: null,
|
|
133
|
-
indentFirstLine: null,
|
|
134
|
-
hangingIndent: null
|
|
135
|
-
}).scrollIntoView());
|
|
136
|
-
else dispatch(state.tr.setNodeMarkup(paragraphPos, void 0, {
|
|
137
|
-
...paragraph.attrs,
|
|
138
|
-
numPr: {
|
|
139
|
-
...paragraph.attrs["numPr"],
|
|
140
|
-
ilvl: currentLevel - 1
|
|
141
|
-
},
|
|
148
|
+
...clearListAttrs(attrs),
|
|
142
149
|
indentLeft: null,
|
|
143
150
|
indentFirstLine: null,
|
|
144
151
|
hangingIndent: null
|
|
145
152
|
}).scrollIntoView());
|
|
153
|
+
else dispatch(state.tr.setNodeMarkup(paragraphPos, void 0, { ...attrsForListLevel(state, attrs, currentLevel - 1) }).scrollIntoView());
|
|
146
154
|
return true;
|
|
147
155
|
};
|
|
148
156
|
const removeList = (state, dispatch) => {
|
|
@@ -151,15 +159,9 @@ const removeList = (state, dispatch) => {
|
|
|
151
159
|
let tr = state.tr;
|
|
152
160
|
const seen = /* @__PURE__ */ new Set();
|
|
153
161
|
state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
154
|
-
if (node.type.name === "paragraph" && node
|
|
162
|
+
if (node.type.name === "paragraph" && hasActiveListNumbering(expectParagraphAttrs(node)) && !seen.has(pos)) {
|
|
155
163
|
seen.add(pos);
|
|
156
|
-
tr = tr.setNodeMarkup(pos, void 0,
|
|
157
|
-
...node.attrs,
|
|
158
|
-
numPr: null,
|
|
159
|
-
listIsBullet: null,
|
|
160
|
-
listNumFmt: null,
|
|
161
|
-
listMarker: null
|
|
162
|
-
});
|
|
164
|
+
tr = tr.setNodeMarkup(pos, void 0, clearListAttrs(expectParagraphAttrs(node)));
|
|
163
165
|
}
|
|
164
166
|
});
|
|
165
167
|
dispatch(tr.scrollIntoView());
|
|
@@ -169,16 +171,17 @@ function isInList(state) {
|
|
|
169
171
|
const { $from } = state.selection;
|
|
170
172
|
const paragraph = $from.parent;
|
|
171
173
|
if (paragraph.type.name !== "paragraph") return false;
|
|
172
|
-
return
|
|
174
|
+
return hasActiveListNumbering(expectParagraphAttrs(paragraph));
|
|
173
175
|
}
|
|
174
176
|
function getListInfo(state) {
|
|
175
177
|
const { $from } = state.selection;
|
|
176
178
|
const paragraph = $from.parent;
|
|
177
179
|
if (paragraph.type.name !== "paragraph") return null;
|
|
178
|
-
|
|
180
|
+
const attrs = expectParagraphAttrs(paragraph);
|
|
181
|
+
if (!hasActiveListNumbering(attrs)) return null;
|
|
179
182
|
return {
|
|
180
|
-
numId:
|
|
181
|
-
ilvl:
|
|
183
|
+
numId: attrs.numPr.numId,
|
|
184
|
+
ilvl: attrs.numPr.ilvl || 0
|
|
182
185
|
};
|
|
183
186
|
}
|
|
184
187
|
function exitListOnEmptyEnter() {
|
|
@@ -187,15 +190,10 @@ function exitListOnEmptyEnter() {
|
|
|
187
190
|
if (!empty) return false;
|
|
188
191
|
const paragraph = $from.parent;
|
|
189
192
|
if (paragraph.type.name !== "paragraph") return false;
|
|
190
|
-
|
|
193
|
+
const attrs = expectParagraphAttrs(paragraph);
|
|
194
|
+
if (!hasActiveListNumbering(attrs)) return false;
|
|
191
195
|
if (paragraph.textContent.length > 0) return false;
|
|
192
|
-
if (dispatch) dispatch(state.tr.setNodeMarkup($from.before(), void 0,
|
|
193
|
-
...paragraph.attrs,
|
|
194
|
-
numPr: null,
|
|
195
|
-
listIsBullet: null,
|
|
196
|
-
listNumFmt: null,
|
|
197
|
-
listMarker: null
|
|
198
|
-
}));
|
|
196
|
+
if (dispatch) dispatch(state.tr.setNodeMarkup($from.before(), void 0, clearListAttrs(attrs)));
|
|
199
197
|
return true;
|
|
200
198
|
};
|
|
201
199
|
}
|
|
@@ -205,7 +203,7 @@ function splitListItem() {
|
|
|
205
203
|
if (!empty) return false;
|
|
206
204
|
const paragraph = $from.parent;
|
|
207
205
|
if (paragraph.type.name !== "paragraph") return false;
|
|
208
|
-
if (!paragraph
|
|
206
|
+
if (!hasActiveListNumbering(expectParagraphAttrs(paragraph))) return false;
|
|
209
207
|
if (dispatch) {
|
|
210
208
|
const { tr } = state;
|
|
211
209
|
const pos = $from.pos;
|
|
@@ -225,14 +223,9 @@ function backspaceExitList() {
|
|
|
225
223
|
if ($from.parentOffset !== 0) return false;
|
|
226
224
|
const paragraph = $from.parent;
|
|
227
225
|
if (paragraph.type.name !== "paragraph") return false;
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
numPr: null,
|
|
232
|
-
listIsBullet: null,
|
|
233
|
-
listNumFmt: null,
|
|
234
|
-
listMarker: null
|
|
235
|
-
}));
|
|
226
|
+
const attrs = expectParagraphAttrs(paragraph);
|
|
227
|
+
if (!hasActiveListNumbering(attrs)) return false;
|
|
228
|
+
if (dispatch) dispatch(state.tr.setNodeMarkup($from.before(), void 0, clearListAttrs(attrs)));
|
|
236
229
|
return true;
|
|
237
230
|
};
|
|
238
231
|
}
|
|
@@ -241,29 +234,19 @@ function increaseListIndent() {
|
|
|
241
234
|
const { $from, $to } = state.selection;
|
|
242
235
|
const positions = [];
|
|
243
236
|
state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
244
|
-
if (node.type.name === "paragraph"
|
|
245
|
-
|
|
237
|
+
if (node.type.name === "paragraph") {
|
|
238
|
+
const attrs = expectParagraphAttrs(node);
|
|
239
|
+
if (!hasActiveListNumbering(attrs)) return;
|
|
240
|
+
if ((attrs.numPr?.ilvl ?? 0) < 8) positions.push({
|
|
246
241
|
pos,
|
|
247
|
-
attrs
|
|
242
|
+
attrs
|
|
248
243
|
});
|
|
249
244
|
}
|
|
250
245
|
});
|
|
251
246
|
if (positions.length === 0) return false;
|
|
252
247
|
if (dispatch) {
|
|
253
248
|
let tr = state.tr;
|
|
254
|
-
for (const { pos, attrs } of positions)
|
|
255
|
-
const numPr = attrs["numPr"];
|
|
256
|
-
tr = tr.setNodeMarkup(pos, void 0, {
|
|
257
|
-
...attrs,
|
|
258
|
-
numPr: {
|
|
259
|
-
...numPr,
|
|
260
|
-
ilvl: (numPr.ilvl ?? 0) + 1
|
|
261
|
-
},
|
|
262
|
-
indentLeft: null,
|
|
263
|
-
indentFirstLine: null,
|
|
264
|
-
hangingIndent: null
|
|
265
|
-
});
|
|
266
|
-
}
|
|
249
|
+
for (const { pos, attrs } of positions) tr = tr.setNodeMarkup(pos, void 0, attrsForListLevel(state, attrs, (attrs.numPr?.ilvl ?? 0) + 1));
|
|
267
250
|
dispatch(tr);
|
|
268
251
|
}
|
|
269
252
|
return true;
|
|
@@ -274,37 +257,26 @@ function decreaseListIndent() {
|
|
|
274
257
|
const { $from, $to } = state.selection;
|
|
275
258
|
const positions = [];
|
|
276
259
|
state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
277
|
-
if (node.type.name === "paragraph"
|
|
278
|
-
|
|
279
|
-
attrs
|
|
280
|
-
|
|
260
|
+
if (node.type.name === "paragraph") {
|
|
261
|
+
const attrs = expectParagraphAttrs(node);
|
|
262
|
+
if (hasActiveListNumbering(attrs)) positions.push({
|
|
263
|
+
pos,
|
|
264
|
+
attrs
|
|
265
|
+
});
|
|
266
|
+
}
|
|
281
267
|
});
|
|
282
268
|
if (positions.length === 0) return false;
|
|
283
269
|
if (dispatch) {
|
|
284
270
|
let tr = state.tr;
|
|
285
271
|
for (const { pos, attrs } of positions) {
|
|
286
|
-
const
|
|
287
|
-
const currentLevel = numPr.ilvl ?? 0;
|
|
272
|
+
const currentLevel = attrs.numPr?.ilvl ?? 0;
|
|
288
273
|
if (currentLevel <= 0) tr = tr.setNodeMarkup(pos, void 0, {
|
|
289
|
-
...attrs,
|
|
290
|
-
numPr: null,
|
|
291
|
-
listIsBullet: null,
|
|
292
|
-
listNumFmt: null,
|
|
293
|
-
listMarker: null,
|
|
294
|
-
indentLeft: null,
|
|
295
|
-
indentFirstLine: null,
|
|
296
|
-
hangingIndent: null
|
|
297
|
-
});
|
|
298
|
-
else tr = tr.setNodeMarkup(pos, void 0, {
|
|
299
|
-
...attrs,
|
|
300
|
-
numPr: {
|
|
301
|
-
...numPr,
|
|
302
|
-
ilvl: currentLevel - 1
|
|
303
|
-
},
|
|
274
|
+
...clearListAttrs(attrs),
|
|
304
275
|
indentLeft: null,
|
|
305
276
|
indentFirstLine: null,
|
|
306
277
|
hangingIndent: null
|
|
307
278
|
});
|
|
279
|
+
else tr = tr.setNodeMarkup(pos, void 0, { ...attrsForListLevel(state, attrs, currentLevel - 1) });
|
|
308
280
|
}
|
|
309
281
|
dispatch(tr);
|
|
310
282
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { recreateProseNodeWithParagraphPropertySource, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource } from "../../../docx/paragraphPropertySource.js";
|
|
1
2
|
import { deterministicHexId, generateHexId } from "../../../utils/hexId.js";
|
|
2
3
|
import { createExtension } from "../create.js";
|
|
3
4
|
import { ignoreTrackedChanges } from "./ParagraphChangeTrackerExtension.js";
|
|
@@ -169,14 +170,16 @@ const rewriteInitialParaIds = (parent, taken, seen) => {
|
|
|
169
170
|
while (taken.has(newId)) newId = generateHexId();
|
|
170
171
|
taken.add(newId);
|
|
171
172
|
seen.add(newId);
|
|
172
|
-
next = child
|
|
173
|
+
next = recreateProseNodeWithParagraphPropertySource(child, { attrs: {
|
|
173
174
|
...child.attrs,
|
|
174
175
|
paraId: newId
|
|
175
|
-
}
|
|
176
|
+
} });
|
|
176
177
|
} else seen.add(id);
|
|
178
|
+
const paraId = next.attrs["paraId"];
|
|
179
|
+
if (typeof paraId === "string") transferProseParagraphPropertySource(next, child, paraId);
|
|
177
180
|
} else if (child.childCount > 0) {
|
|
178
181
|
const content = rewriteInitialParaIds(child, taken, seen);
|
|
179
|
-
if (content !== child.content) next = child
|
|
182
|
+
if (content !== child.content) next = recreateProseNodeWithParagraphPropertySource(child, { content });
|
|
180
183
|
}
|
|
181
184
|
if (next !== child) changed = true;
|
|
182
185
|
children.push(next);
|
|
@@ -193,13 +196,18 @@ const rewriteInitialParaIds = (parent, taken, seen) => {
|
|
|
193
196
|
const ensureParaIdsInDoc = (doc) => {
|
|
194
197
|
const { needsRewrite, taken } = collectInitialParaIds(doc);
|
|
195
198
|
if (!needsRewrite) return doc;
|
|
196
|
-
return doc
|
|
199
|
+
return recreateProseNodeWithParagraphPropertySource(doc, { content: rewriteInitialParaIds(doc, taken, /* @__PURE__ */ new Set()) });
|
|
197
200
|
};
|
|
198
201
|
const ensureParaIdsInState = (state) => {
|
|
199
202
|
const updates = collectParaIdUpdates(state.doc);
|
|
200
203
|
if (updates.length === 0) return state;
|
|
201
204
|
const tr = state.tr;
|
|
202
|
-
for (const update of updates)
|
|
205
|
+
for (const update of updates) setProseParagraphMarkupWithPropertySource({
|
|
206
|
+
attrs: update.attrs,
|
|
207
|
+
ownership: "transfer-allocated-id",
|
|
208
|
+
pos: update.pos,
|
|
209
|
+
transaction: tr
|
|
210
|
+
});
|
|
203
211
|
ignoreTrackedChanges(tr);
|
|
204
212
|
tr.setMeta(paraIdAllocatorKey, "allocated");
|
|
205
213
|
tr.setMeta("addToHistory", false);
|
|
@@ -214,7 +222,12 @@ const createParaIdAllocatorPlugin = () => new Plugin({
|
|
|
214
222
|
const updates = collectParaIdUpdates(newState.doc, keeperPositions, seed);
|
|
215
223
|
if (updates.length === 0) return null;
|
|
216
224
|
const tr = newState.tr;
|
|
217
|
-
for (const u of updates)
|
|
225
|
+
for (const u of updates) setProseParagraphMarkupWithPropertySource({
|
|
226
|
+
attrs: u.attrs,
|
|
227
|
+
ownership: "transfer-allocated-id",
|
|
228
|
+
pos: u.pos,
|
|
229
|
+
transaction: tr
|
|
230
|
+
});
|
|
218
231
|
ignoreTrackedChanges(tr);
|
|
219
232
|
tr.setMeta(paraIdAllocatorKey, "allocated");
|
|
220
233
|
tr.setMeta("addToHistory", false);
|