@stll/folio-core 0.22.3 → 0.23.1

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.
Files changed (78) hide show
  1. package/dist/ai-edits/apply.d.ts +1 -1
  2. package/dist/controller/layoutPipeline.js +7 -3
  3. package/dist/document-operations.d.ts +4 -4
  4. package/dist/document-operations.js +17 -1
  5. package/dist/docx/blockContentParser.js +2 -47
  6. package/dist/docx/fieldParser.d.ts +1 -1
  7. package/dist/docx/fieldParser.js +12 -4
  8. package/dist/docx/numberingParser.d.ts +2 -11
  9. package/dist/docx/numberingParser.js +3 -79
  10. package/dist/docx/ooxmlCounterFormatter.d.ts +8 -0
  11. package/dist/docx/ooxmlCounterFormatter.js +134 -0
  12. package/dist/docx/rezip.d.ts +1 -1
  13. package/dist/docx/rezip.js +12 -31
  14. package/dist/docx/serializer/tableSerializer.js +1 -1
  15. package/dist/docx/tableParser.js +2 -1
  16. package/dist/fields/bookmarkPages.js +1 -1
  17. package/dist/fields/evaluateField.js +1 -1
  18. package/dist/fields/fieldContext.d.ts +2 -0
  19. package/dist/fields/resolveFieldValues.js +5 -2
  20. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -0
  21. package/dist/layout-bridge/convert/toFlowBlocks.js +51 -109
  22. package/dist/layout-engine/index.d.ts +3 -2
  23. package/dist/layout-engine/index.js +40 -16
  24. package/dist/layout-engine/measure/cache.js +1 -1
  25. package/dist/layout-engine/measure/complexScriptFormatting.d.ts +18 -0
  26. package/dist/layout-engine/measure/complexScriptFormatting.js +11 -0
  27. package/dist/layout-engine/measure/measureContainer.js +31 -16
  28. package/dist/layout-engine/measure/measureHelpers.js +4 -0
  29. package/dist/layout-engine/measure/measureParagraph.js +13 -3
  30. package/dist/layout-engine/measure/measureTypes.d.ts +4 -0
  31. package/dist/layout-engine/paginator.d.ts +5 -3
  32. package/dist/layout-engine/paginator.js +34 -13
  33. package/dist/layout-engine/types.d.ts +31 -4
  34. package/dist/layout-painter/imageLayout.d.ts +1 -1
  35. package/dist/layout-painter/index.js +2 -1
  36. package/dist/layout-painter/renderPage.js +9 -3
  37. package/dist/layout-painter/renderParagraph.js +42 -25
  38. package/dist/layout-painter/renderUtils.d.ts +2 -0
  39. package/dist/managers/AutoSaveManager.js +8 -40
  40. package/dist/managers/TableSelectionManager.d.ts +1 -1
  41. package/dist/managers/autoSaveCodec.d.ts +17 -0
  42. package/dist/managers/autoSaveCodec.js +109 -0
  43. package/dist/paged-layout/sectionGeometry.d.ts +3 -2
  44. package/dist/paged-layout/sectionGeometry.js +17 -1
  45. package/dist/prosemirror/attrs/index.js +278 -25
  46. package/dist/prosemirror/commands/comments.js +3 -3
  47. package/dist/prosemirror/commands/formatting.js +19 -19
  48. package/dist/prosemirror/commands/index.d.ts +2 -2
  49. package/dist/prosemirror/commands/paragraph.js +32 -32
  50. package/dist/prosemirror/commands/propertyChangeScope.d.ts +4 -2
  51. package/dist/prosemirror/commands/propertyChangeScope.js +8 -8
  52. package/dist/prosemirror/commands/table.d.ts +10 -52
  53. package/dist/prosemirror/commands/table.js +34 -34
  54. package/dist/prosemirror/conversion/fromProseDoc.js +24 -33
  55. package/dist/prosemirror/conversion/sdtAttrs.d.ts +2 -1
  56. package/dist/prosemirror/conversion/sdtAttrs.js +9 -4
  57. package/dist/prosemirror/conversion/toProseDoc.js +4 -1
  58. package/dist/prosemirror/extensions/ExtensionManager.d.ts +6 -3
  59. package/dist/prosemirror/extensions/ExtensionManager.js +5 -3
  60. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +1 -1
  61. package/dist/prosemirror/extensions/features/ListExtension.js +4 -4
  62. package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +3 -2
  63. package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +31 -17
  64. package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +1 -1
  65. package/dist/prosemirror/extensions/nodes/TableExtension.js +1 -0
  66. package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +1 -1
  67. package/dist/prosemirror/extensions/types.d.ts +134 -1
  68. package/dist/prosemirror/index.d.ts +2 -2
  69. package/dist/prosemirror/plugins/selectionTracker.js +25 -99
  70. package/dist/prosemirror/revisionCarriers.js +3 -1
  71. package/dist/prosemirror/schema/index.d.ts +2 -2
  72. package/dist/prosemirror/schema/index.js +87 -0
  73. package/dist/prosemirror/schema/marks.d.ts +8 -0
  74. package/dist/prosemirror/schema/nodes.d.ts +15 -2
  75. package/dist/prosemirror/selectionState.d.ts +11 -5
  76. package/dist/prosemirror/selectionState.js +94 -57
  77. package/dist/utils/tableOperations.d.ts +7 -6
  78. package/package.json +3 -3
@@ -2,63 +2,63 @@ import { getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId }
2
2
  import { getListInfo, isInList } from "../extensions/features/ListExtension.js";
3
3
  import { singletonManager } from "../schema/index.js";
4
4
  //#region src/prosemirror/commands/paragraph.ts
5
- const cmds = singletonManager.getCommands();
5
+ const cmds = singletonManager;
6
6
  function setAlignment(alignment) {
7
- return cmds["setAlignment"](alignment);
7
+ return cmds.requireCommand("setAlignment")(alignment);
8
8
  }
9
- const alignLeft = cmds["alignLeft"]();
10
- const alignCenter = cmds["alignCenter"]();
11
- const alignRight = cmds["alignRight"]();
12
- const alignJustify = cmds["alignJustify"]();
9
+ const alignLeft = cmds.requireCommand("alignLeft")();
10
+ const alignCenter = cmds.requireCommand("alignCenter")();
11
+ const alignRight = cmds.requireCommand("alignRight")();
12
+ const alignJustify = cmds.requireCommand("alignJustify")();
13
13
  function setLineSpacing(value, rule = "auto") {
14
- return cmds["setLineSpacing"](value, rule);
14
+ return cmds.requireCommand("setLineSpacing")(value, rule);
15
15
  }
16
- const singleSpacing = cmds["singleSpacing"]();
17
- const oneAndHalfSpacing = cmds["oneAndHalfSpacing"]();
18
- const doubleSpacing = cmds["doubleSpacing"]();
16
+ const singleSpacing = cmds.requireCommand("singleSpacing")();
17
+ const oneAndHalfSpacing = cmds.requireCommand("oneAndHalfSpacing")();
18
+ const doubleSpacing = cmds.requireCommand("doubleSpacing")();
19
19
  function increaseIndent(amount = 720) {
20
- return cmds["increaseIndent"](amount);
20
+ return cmds.requireCommand("increaseIndent")(amount);
21
21
  }
22
22
  function decreaseIndent(amount = 720) {
23
- return cmds["decreaseIndent"](amount);
23
+ return cmds.requireCommand("decreaseIndent")(amount);
24
24
  }
25
25
  function setIndentLeft(twips) {
26
- return cmds["setIndentLeft"](twips);
26
+ return cmds.requireCommand("setIndentLeft")(twips);
27
27
  }
28
28
  function setIndentRight(twips) {
29
- return cmds["setIndentRight"](twips);
29
+ return cmds.requireCommand("setIndentRight")(twips);
30
30
  }
31
31
  function setIndentFirstLine(twips, hanging) {
32
- return cmds["setIndentFirstLine"](twips, hanging);
32
+ return cmds.requireCommand("setIndentFirstLine")(twips, hanging);
33
33
  }
34
- const toggleBulletList = cmds["toggleBulletList"]();
35
- const toggleNumberedList = cmds["toggleNumberedList"]();
36
- const increaseListLevel = cmds["increaseListLevel"]();
37
- const decreaseListLevel = cmds["decreaseListLevel"]();
38
- const removeList = cmds["removeList"]();
34
+ const toggleBulletList = cmds.requireCommand("toggleBulletList")();
35
+ const toggleNumberedList = cmds.requireCommand("toggleNumberedList")();
36
+ const increaseListLevel = cmds.requireCommand("increaseListLevel")();
37
+ const decreaseListLevel = cmds.requireCommand("decreaseListLevel")();
38
+ const removeList = cmds.requireCommand("removeList")();
39
39
  function setSpaceBefore(twips) {
40
- return cmds["setSpaceBefore"](twips);
40
+ return cmds.requireCommand("setSpaceBefore")(twips);
41
41
  }
42
42
  function setSpaceAfter(twips) {
43
- return cmds["setSpaceAfter"](twips);
43
+ return cmds.requireCommand("setSpaceAfter")(twips);
44
44
  }
45
45
  function applyStyle(styleId, resolvedAttrs) {
46
- return cmds["applyStyle"](styleId, resolvedAttrs);
46
+ return cmds.requireCommand("applyStyle")(styleId, resolvedAttrs);
47
47
  }
48
- const clearStyle = cmds["clearStyle"]();
48
+ const clearStyle = cmds.requireCommand("clearStyle")();
49
49
  function insertSectionBreak(breakType) {
50
- return cmds["insertSectionBreak"](breakType);
50
+ return cmds.requireCommand("insertSectionBreak")(breakType);
51
51
  }
52
- const removeSectionBreak = cmds["removeSectionBreak"]();
52
+ const removeSectionBreak = cmds.requireCommand("removeSectionBreak")();
53
53
  function addTabStop(position, alignment = "left", leader = "none") {
54
- return cmds["addTabStop"](position, alignment, leader);
54
+ return cmds.requireCommand("addTabStop")(position, alignment, leader);
55
55
  }
56
56
  function removeTabStop(position) {
57
- return cmds["removeTabStop"](position);
57
+ return cmds.requireCommand("removeTabStop")(position);
58
58
  }
59
- const toggleBidi = cmds["toggleBidi"]();
60
- const setRtl = cmds["setRtl"]();
61
- const setLtr = cmds["setLtr"]();
62
- const generateTOC = cmds["generateTOC"]();
59
+ const toggleBidi = cmds.requireCommand("toggleBidi")();
60
+ const setRtl = cmds.requireCommand("setRtl")();
61
+ const setLtr = cmds.requireCommand("setLtr")();
62
+ const generateTOC = cmds.requireCommand("generateTOC")();
63
63
  //#endregion
64
64
  export { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, doubleSpacing, generateTOC, getListInfo, getParagraphAlignment, getParagraphBidi, getParagraphTabs, getStyleId, increaseIndent, increaseListLevel, insertSectionBreak, isInList, oneAndHalfSpacing, removeList, removeSectionBreak, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, setSpaceAfter, setSpaceBefore, singleSpacing, toggleBidi, toggleBulletList, toggleNumberedList };
@@ -1,6 +1,8 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { ParagraphPropertyChangeAttrs } from "../schema/nodes.js";
2
3
  //#region src/prosemirror/commands/propertyChangeScope.d.ts
3
4
  type AttrPatch = Record<string, unknown>;
5
+ type ParagraphPropertySnapshot = NonNullable<ParagraphPropertyChangeAttrs["previousFormatting"]>;
4
6
  /**
5
7
  * Paragraph attrs governed by a `w:pPrChange` — the attrs
6
8
  * `paragraphFormattingToAttrs` (conversion/toProseDoc.ts) can produce from a
@@ -27,7 +29,7 @@ declare const PPR_CHANGE_SCOPED_ATTR_KEYS: readonly ["styleId", "numPr", "alignm
27
29
  * the scoped set (editor-created list suggestions snapshot list-rendering
28
30
  * bookkeeping attrs) merge through 1:1 so their pre-change values restore too.
29
31
  */
30
- declare function paragraphRejectAttrPatch(previousFormatting: Record<string, unknown> | null | undefined): AttrPatch;
32
+ declare function paragraphRejectAttrPatch(previousFormatting: ParagraphPropertySnapshot | null | undefined): AttrPatch;
31
33
  /**
32
34
  * Rebuild the paragraph's `_originalFormatting` (the serializer's pPr source)
33
35
  * after a reject: the stored old pPr wholesale within CT_PPrBase scope, with
@@ -35,7 +37,7 @@ declare function paragraphRejectAttrPatch(previousFormatting: Record<string, unk
35
37
  * from the live original — a pPrChange cannot store them, so a reject must
36
38
  * not drop them.
37
39
  */
38
- declare function paragraphRejectOriginalFormatting(previousFormatting: Record<string, unknown> | null | undefined, liveOriginal: unknown): document_d_exports.ParagraphFormatting | null;
40
+ declare function paragraphRejectOriginalFormatting(previousFormatting: ParagraphPropertySnapshot | null | undefined, liveOriginal: unknown): document_d_exports.ParagraphFormatting | null;
39
41
  /**
40
42
  * Rejected section properties: the stored old sectPr wholesale, preserving
41
43
  * the live header/footer references — `EG_HdrFtrReferences` is not part of
@@ -112,7 +112,7 @@ function paragraphRejectAttrPatch(previousFormatting) {
112
112
  const prev = previousFormatting ?? {};
113
113
  const patch = {};
114
114
  for (const key of PPR_CHANGE_SCOPED_ATTR_KEYS) patch[key] = Object.hasOwn(prev, key) ? prev[key] ?? null : null;
115
- if (!Object.hasOwn(prev, "direction")) patch["direction"] = directionFromBidi(prev["bidi"]);
115
+ if (!Object.hasOwn(prev, "direction")) patch["direction"] = directionFromBidi(prev.bidi);
116
116
  if (!Object.hasOwn(prev, "_autospacingBase")) patch["_autospacingBase"] = autospacingBaseFromFormatting(prev);
117
117
  for (const [key, value] of Object.entries(prev)) {
118
118
  if (PPR_CHANGE_SCOPED_ATTR_KEY_SET.has(key) || PPR_PARSER_ONLY_KEYS.has(key)) continue;
@@ -132,21 +132,21 @@ function paragraphRejectOriginalFormatting(previousFormatting, liveOriginal) {
132
132
  const result = {};
133
133
  for (const key of PPR_CHANGE_SCOPED_FORMATTING_KEYS) {
134
134
  const value = Object.hasOwn(prev, key) ? prev[key] : void 0;
135
- if (value != null) result[key] = value;
135
+ if (value != null) Object.assign(result, { [key]: value });
136
136
  }
137
137
  const live = isRecord(liveOriginal) ? liveOriginal : {};
138
- if (live["runProperties"] != null) result["runProperties"] = live["runProperties"];
139
- if (live["runInWithNext"] != null) result["runInWithNext"] = live["runInWithNext"];
138
+ if (live["runProperties"] != null) Object.assign(result, { runProperties: live["runProperties"] });
139
+ if (live["runInWithNext"] != null) Object.assign(result, { runInWithNext: live["runInWithNext"] });
140
140
  if (Object.keys(result).length === 0) return null;
141
141
  return result;
142
142
  }
143
143
  function autospacingBaseFromFormatting(prev) {
144
- const before = prev["beforeAutospacing"] === true;
145
- const after = prev["afterAutospacing"] === true;
144
+ const before = prev.beforeAutospacing === true;
145
+ const after = prev.afterAutospacing === true;
146
146
  if (!before && !after) return null;
147
147
  const base = {};
148
- if (before) setAutospacingBaseValue(base, "before", prev["spaceBefore"]);
149
- if (after) setAutospacingBaseValue(base, "after", prev["spaceAfter"]);
148
+ if (before) setAutospacingBaseValue(base, "before", prev.spaceBefore);
149
+ if (after) setAutospacingBaseValue(base, "after", prev.spaceAfter);
150
150
  return base;
151
151
  }
152
152
  /**
@@ -1,4 +1,6 @@
1
+ import { TablePropertiesCommand } from "../../utils/tableOperations.js";
1
2
  import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
3
+ import { TableBorderCommandSpec, TableCellBorderCommandSpec, TableCellMarginsCommand, TableStyleCommand } from "../extensions/types.js";
2
4
  import { EditorState, Transaction } from "prosemirror-state";
3
5
  //#region src/prosemirror/commands/table.d.ts
4
6
  declare function insertTable(rows: number, cols: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
@@ -14,67 +16,23 @@ declare function selectRow(state: EditorState, dispatch?: (tr: Transaction) => v
14
16
  declare function selectColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
15
17
  declare function mergeCells(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
16
18
  declare function splitCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
17
- declare function setCellBorder(side: "top" | "bottom" | "left" | "right" | "all", spec: {
18
- style: string;
19
- size?: number;
20
- color?: {
21
- rgb: string;
22
- };
23
- } | null, clearOthers?: boolean): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
19
+ declare function setCellBorder(side: "top" | "bottom" | "left" | "right" | "all", spec: TableCellBorderCommandSpec | null, clearOthers?: boolean): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
24
20
  declare function setTableBorderPreset(preset: TableBorderPreset): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
25
- declare function setTableBorders(preset: BorderPreset, borderSpec?: {
26
- style: string;
27
- size: number;
28
- color: {
29
- rgb: string;
30
- };
31
- }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
21
+ declare function setTableBorders(preset: BorderPreset, borderSpec?: TableBorderCommandSpec): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
32
22
  declare function removeTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
33
- declare function setAllTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
34
- style: string;
35
- size: number;
36
- color: {
37
- rgb: string;
38
- };
39
- }): boolean;
40
- declare function setOutsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
41
- style: string;
42
- size: number;
43
- color: {
44
- rgb: string;
45
- };
46
- }): boolean;
47
- declare function setInsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: {
48
- style: string;
49
- size: number;
50
- color: {
51
- rgb: string;
52
- };
53
- }): boolean;
23
+ declare function setAllTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: TableBorderCommandSpec): boolean;
24
+ declare function setOutsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: TableBorderCommandSpec): boolean;
25
+ declare function setInsideTableBorders(state: EditorState, dispatch?: (tr: Transaction) => void, borderSpec?: TableBorderCommandSpec): boolean;
54
26
  declare function setCellVerticalAlign(align: "top" | "center" | "bottom"): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
55
- declare function setCellMargins(margins: {
56
- top?: number;
57
- bottom?: number;
58
- left?: number;
59
- right?: number;
60
- }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
27
+ declare function setCellMargins(margins: TableCellMarginsCommand): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
61
28
  declare function setCellTextDirection(direction: string | null): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
62
29
  declare function toggleNoWrap(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
63
30
  declare function setRowHeight(height: number | null, rule?: "auto" | "atLeast" | "exact"): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
64
31
  declare function toggleHeaderRow(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
65
32
  declare function distributeColumns(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
66
33
  declare function autoFitContents(): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
67
- declare function setTableProperties(props: {
68
- width?: number | null;
69
- widthType?: string | null;
70
- justification?: "left" | "center" | "right" | null;
71
- }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
72
- declare function applyTableStyle(styleData: {
73
- styleId: string;
74
- tableBorders?: Record<string, unknown>;
75
- conditionals?: Record<string, unknown>;
76
- look?: Record<string, boolean>;
77
- }): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
34
+ declare function setTableProperties(props: TablePropertiesCommand): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
35
+ declare function applyTableStyle(styleData: TableStyleCommand): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
78
36
  declare function setCellFillColor(color: string | null): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
79
37
  declare function setTableBorderColor(color: string): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
80
38
  declare function setTableBorderWidth(size: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
@@ -1,105 +1,105 @@
1
1
  import { getTableContext, isInTable as isInTableCell } from "../extensions/nodes/TableExtension.js";
2
2
  import { singletonManager } from "../schema/index.js";
3
3
  //#region src/prosemirror/commands/table.ts
4
- const cmds = singletonManager.getCommands();
4
+ const cmds = singletonManager;
5
5
  function insertTable(rows, cols) {
6
- return cmds["insertTable"](rows, cols);
6
+ return cmds.requireCommand("insertTable")(rows, cols);
7
7
  }
8
8
  function addRowAbove(state, dispatch) {
9
- return cmds["addRowAbove"]()(state, dispatch);
9
+ return cmds.requireCommand("addRowAbove")()(state, dispatch);
10
10
  }
11
11
  function addRowBelow(state, dispatch) {
12
- return cmds["addRowBelow"]()(state, dispatch);
12
+ return cmds.requireCommand("addRowBelow")()(state, dispatch);
13
13
  }
14
14
  function deleteRow(state, dispatch) {
15
- return cmds["deleteRow"]()(state, dispatch);
15
+ return cmds.requireCommand("deleteRow")()(state, dispatch);
16
16
  }
17
17
  function addColumnLeft(state, dispatch) {
18
- return cmds["addColumnLeft"]()(state, dispatch);
18
+ return cmds.requireCommand("addColumnLeft")()(state, dispatch);
19
19
  }
20
20
  function addColumnRight(state, dispatch) {
21
- return cmds["addColumnRight"]()(state, dispatch);
21
+ return cmds.requireCommand("addColumnRight")()(state, dispatch);
22
22
  }
23
23
  function deleteColumn(state, dispatch) {
24
- return cmds["deleteColumn"]()(state, dispatch);
24
+ return cmds.requireCommand("deleteColumn")()(state, dispatch);
25
25
  }
26
26
  function deleteTable(state, dispatch) {
27
- return cmds["deleteTable"]()(state, dispatch);
27
+ return cmds.requireCommand("deleteTable")()(state, dispatch);
28
28
  }
29
29
  function selectTable(state, dispatch) {
30
- return cmds["selectTable"]()(state, dispatch);
30
+ return cmds.requireCommand("selectTable")()(state, dispatch);
31
31
  }
32
32
  function selectRow(state, dispatch) {
33
- return cmds["selectRow"]()(state, dispatch);
33
+ return cmds.requireCommand("selectRow")()(state, dispatch);
34
34
  }
35
35
  function selectColumn(state, dispatch) {
36
- return cmds["selectColumn"]()(state, dispatch);
36
+ return cmds.requireCommand("selectColumn")()(state, dispatch);
37
37
  }
38
38
  function mergeCells(state, dispatch) {
39
- return cmds["mergeCells"]()(state, dispatch);
39
+ return cmds.requireCommand("mergeCells")()(state, dispatch);
40
40
  }
41
41
  function splitCell(state, dispatch) {
42
- return cmds["splitCell"]()(state, dispatch);
42
+ return cmds.requireCommand("splitCell")()(state, dispatch);
43
43
  }
44
44
  function setCellBorder(side, spec, clearOthers) {
45
- return cmds["setCellBorder"](side, spec, clearOthers);
45
+ return cmds.requireCommand("setCellBorder")(side, spec, clearOthers);
46
46
  }
47
47
  function setTableBorderPreset(preset) {
48
- return cmds["setTableBorderPreset"](preset);
48
+ return cmds.requireCommand("setTableBorderPreset")(preset);
49
49
  }
50
50
  function setTableBorders(preset, borderSpec) {
51
- return cmds["setTableBorders"](preset, borderSpec);
51
+ return cmds.requireCommand("setTableBorders")(preset, borderSpec);
52
52
  }
53
53
  function removeTableBorders(state, dispatch) {
54
- return cmds["removeTableBorders"]()(state, dispatch);
54
+ return cmds.requireCommand("removeTableBorders")()(state, dispatch);
55
55
  }
56
56
  function setAllTableBorders(state, dispatch, borderSpec) {
57
- return cmds["setAllTableBorders"](borderSpec)(state, dispatch);
57
+ return cmds.requireCommand("setAllTableBorders")(borderSpec)(state, dispatch);
58
58
  }
59
59
  function setOutsideTableBorders(state, dispatch, borderSpec) {
60
- return cmds["setOutsideTableBorders"](borderSpec)(state, dispatch);
60
+ return cmds.requireCommand("setOutsideTableBorders")(borderSpec)(state, dispatch);
61
61
  }
62
62
  function setInsideTableBorders(state, dispatch, borderSpec) {
63
- return cmds["setInsideTableBorders"](borderSpec)(state, dispatch);
63
+ return cmds.requireCommand("setInsideTableBorders")(borderSpec)(state, dispatch);
64
64
  }
65
65
  function setCellVerticalAlign(align) {
66
- return cmds["setCellVerticalAlign"](align);
66
+ return cmds.requireCommand("setCellVerticalAlign")(align);
67
67
  }
68
68
  function setCellMargins(margins) {
69
- return cmds["setCellMargins"](margins);
69
+ return cmds.requireCommand("setCellMargins")(margins);
70
70
  }
71
71
  function setCellTextDirection(direction) {
72
- return cmds["setCellTextDirection"](direction);
72
+ return cmds.requireCommand("setCellTextDirection")(direction);
73
73
  }
74
74
  function toggleNoWrap() {
75
- return cmds["toggleNoWrap"]();
75
+ return cmds.requireCommand("toggleNoWrap")();
76
76
  }
77
77
  function setRowHeight(height, rule) {
78
- return cmds["setRowHeight"](height, rule);
78
+ return cmds.requireCommand("setRowHeight")(height, rule);
79
79
  }
80
80
  function toggleHeaderRow() {
81
- return cmds["toggleHeaderRow"]();
81
+ return cmds.requireCommand("toggleHeaderRow")();
82
82
  }
83
83
  function distributeColumns() {
84
- return cmds["distributeColumns"]();
84
+ return cmds.requireCommand("distributeColumns")();
85
85
  }
86
86
  function autoFitContents() {
87
- return cmds["autoFitContents"]();
87
+ return cmds.requireCommand("autoFitContents")();
88
88
  }
89
89
  function setTableProperties(props) {
90
- return cmds["setTableProperties"](props);
90
+ return cmds.requireCommand("setTableProperties")(props);
91
91
  }
92
92
  function applyTableStyle(styleData) {
93
- return cmds["applyTableStyle"](styleData);
93
+ return cmds.requireCommand("applyTableStyle")(styleData);
94
94
  }
95
95
  function setCellFillColor(color) {
96
- return cmds["setCellFillColor"](color);
96
+ return cmds.requireCommand("setCellFillColor")(color);
97
97
  }
98
98
  function setTableBorderColor(color) {
99
- return cmds["setTableBorderColor"](color);
99
+ return cmds.requireCommand("setTableBorderColor")(color);
100
100
  }
101
101
  function setTableBorderWidth(size) {
102
- return cmds["setTableBorderWidth"](size);
102
+ return cmds.requireCommand("setTableBorderWidth")(size);
103
103
  }
104
104
  //#endregion
105
105
  export { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyle, autoFitContents, deleteColumn, deleteRow, deleteTable, distributeColumns, getTableContext, insertTable, isInTableCell as isInTable, mergeCells, removeTableBorders, selectColumn, selectRow, selectTable, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setInsideTableBorders, setOutsideTableBorders, setRowHeight, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, splitCell, toggleHeaderRow, toggleNoWrap };
@@ -4,12 +4,13 @@ import { OUTLINE_STYLE_CSS_ALIASES } from "../../types/documentEnumValues.js";
4
4
  import { pixelsToEmu } from "../../utils/units.js";
5
5
  import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectLanguageMarkAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunPropertyChangeMarkAttrs, expectRunShadingMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectStrikeMarkAttrs, expectSymbolAttrs, expectTabAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../attrs/index.js";
6
6
  import { autospacingMatchesBase, hasAutospacingBaseSide } from "../autospacingBase.js";
7
+ import { applyRunFormattingOverrideAttrs } from "../extensions/marks/RunFormattingOverrideExtension.js";
7
8
  import { directionToBidi } from "../paragraphDirection.js";
8
9
  import { RUN_FORMATTING_MARK_NAMES } from "../runFormattingMarkNames.js";
9
10
  import { expectTextBoxAnchorAttrs } from "../textBoxAnchorAttrs.js";
10
11
  import { assertValidProseMirrorDocument } from "../validation.js";
11
12
  import { runShadingAttrsToShading } from "./runShadingMark.js";
12
- import { sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
13
+ import { decodeSdtListItems, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs } from "./sdtAttrs.js";
13
14
  import { textFormattingToMarks } from "./toProseDoc.js";
14
15
  import { Fragment } from "prosemirror-model";
15
16
  //#region src/prosemirror/conversion/fromProseDoc.ts
@@ -248,10 +249,7 @@ function convertPMBlockSdt(node) {
248
249
  if (attrs.showingPlaceholder !== void 0) properties.showingPlaceholder = attrs.showingPlaceholder;
249
250
  if (attrs.dateFormat) properties.dateFormat = attrs.dateFormat;
250
251
  if (attrs.dateValueISO) properties.dateValueISO = attrs.dateValueISO;
251
- if (attrs.listItems) {
252
- const items = parseListItemsJson(attrs.listItems);
253
- if (items) properties.listItems = items;
254
- }
252
+ if (attrs.listItems) properties.listItems = decodeSdtListItems(attrs.listItems);
255
253
  if (typeof attrs.dropdownLastValue === "string") properties.dropdownLastValue = attrs.dropdownLastValue;
256
254
  if (typeof attrs.checked === "boolean") properties.checked = attrs.checked;
257
255
  if (attrs.rawPropertiesXml) properties.rawPropertiesXml = attrs.rawPropertiesXml;
@@ -276,17 +274,6 @@ function isStillSyntheticFiller(blocks) {
276
274
  if (block.pPrMark !== void 0) return false;
277
275
  return true;
278
276
  }
279
- function parseListItemsJson(raw) {
280
- try {
281
- const parsed = JSON.parse(raw);
282
- if (!Array.isArray(parsed)) return;
283
- const items = [];
284
- for (const entry of parsed) if (entry !== null && typeof entry === "object" && "displayText" in entry && "value" in entry && typeof entry.displayText === "string" && typeof entry.value === "string") items.push(entry);
285
- return items.length > 0 ? items : void 0;
286
- } catch {
287
- return;
288
- }
289
- }
290
277
  function appendTextBoxBlock(blocks, node, options) {
291
278
  const attrs = expectTextBoxAttrs(node);
292
279
  const paragraph = convertPMTextBox(node);
@@ -513,10 +500,27 @@ function convertPMParagraph(node, documentCounts, textBoxAnchorMarkers) {
513
500
  if (attrs.renderedPageBreakBefore) paragraph.renderedPageBreakBefore = true;
514
501
  if (attrs._sectionProperties) paragraph.sectionProperties = attrs._sectionProperties;
515
502
  else if (attrs.sectionBreakType) paragraph.sectionProperties = { sectionStart: attrs.sectionBreakType };
516
- if (Array.isArray(attrs._propertyChanges) && attrs._propertyChanges.length > 0) paragraph.propertyChanges = [...attrs._propertyChanges];
503
+ if (attrs._propertyChanges && attrs._propertyChanges.length > 0) paragraph.propertyChanges = attrs._propertyChanges.map(propertyChangeFromAttrs);
517
504
  if (attrs.pPrMark) paragraph.pPrMark = attrs.pPrMark;
518
505
  return paragraph;
519
506
  }
507
+ const propertyChangeFromAttrs = (change) => {
508
+ const { previousFormatting, currentFormatting, ...info } = change;
509
+ if (previousFormatting === void 0) return currentFormatting === void 0 ? info : {
510
+ ...info,
511
+ currentFormatting
512
+ };
513
+ const { numPr, ...previousWithoutNumPr } = previousFormatting;
514
+ const normalizedPrevious = numPr === null || numPr === void 0 ? previousWithoutNumPr : {
515
+ ...previousWithoutNumPr,
516
+ numPr
517
+ };
518
+ return {
519
+ ...info,
520
+ previousFormatting: normalizedPrevious,
521
+ ...currentFormatting !== void 0 && { currentFormatting }
522
+ };
523
+ };
520
524
  /**
521
525
  * Whether the paragraph's numbering still comes verbatim from its style —
522
526
  * serialize no direct `<w:numPr>` then. The moment a list command changes
@@ -1338,6 +1342,7 @@ function createShapeRun(node) {
1338
1342
  function marksToTextFormatting(marks) {
1339
1343
  const formatting = {};
1340
1344
  let characterStyleRPr;
1345
+ let runFormattingOverrideMark;
1341
1346
  for (const mark of marks) switch (mark.type.name) {
1342
1347
  case "bold":
1343
1348
  formatting.bold = true;
@@ -1450,7 +1455,7 @@ function marksToTextFormatting(marks) {
1450
1455
  formatting.effect = expectTextEffectMarkAttrs(mark).effect;
1451
1456
  break;
1452
1457
  case "runFormattingOverride":
1453
- applyRunFormattingOverrideAttrs(formatting, expectRunFormattingOverrideMarkAttrs(mark));
1458
+ runFormattingOverrideMark = mark;
1454
1459
  break;
1455
1460
  case "characterStyle": {
1456
1461
  const attrs = expectCharacterStyleMarkAttrs(mark);
@@ -1460,6 +1465,7 @@ function marksToTextFormatting(marks) {
1460
1465
  }
1461
1466
  default: break;
1462
1467
  }
1468
+ if (runFormattingOverrideMark) applyRunFormattingOverrideAttrs(formatting, expectRunFormattingOverrideMarkAttrs(runFormattingOverrideMark));
1463
1469
  if (characterStyleRPr) return subtractCharacterStyleFormatting(formatting, characterStyleRPr);
1464
1470
  return formatting;
1465
1471
  }
@@ -1519,21 +1525,6 @@ function subtractCharacterStyleFormatting(formatting, styleRPr) {
1519
1525
  }
1520
1526
  return result;
1521
1527
  }
1522
- function applyRunFormattingOverrideAttrs(formatting, attrs) {
1523
- if (attrs.bold === false) formatting.bold = false;
1524
- if (attrs.italic === false) formatting.italic = false;
1525
- if (attrs.underline === "none") formatting.underline = { style: "none" };
1526
- if (attrs.strike === false) formatting.strike = false;
1527
- if (attrs.doubleStrike === false) formatting.doubleStrike = false;
1528
- if (attrs.allCaps === false) formatting.allCaps = false;
1529
- if (attrs.smallCaps === false) formatting.smallCaps = false;
1530
- if (attrs.hidden === false) formatting.hidden = false;
1531
- if (attrs.emboss === false) formatting.emboss = false;
1532
- if (attrs.imprint === false) formatting.imprint = false;
1533
- if (attrs.shadow === false) formatting.shadow = false;
1534
- if (attrs.outline === false) formatting.outline = false;
1535
- if (attrs.rtl === false) formatting.rtl = false;
1536
- }
1537
1528
  /**
1538
1529
  * Convert a ProseMirror table node to our Table type
1539
1530
  */
@@ -4,5 +4,6 @@ import { SdtAttrs } from "../schema/nodes.js";
4
4
  declare const sdtAttrsFromProperties: (properties: document_d_exports.SdtProperties) => SdtAttrs;
5
5
  declare const sdtPropertiesFromAttrs: (attrs: SdtAttrs) => document_d_exports.SdtProperties;
6
6
  declare const sdtPropertiesMatchAttrs: (properties: document_d_exports.SdtProperties, attrs: SdtAttrs) => boolean;
7
+ declare const decodeSdtListItems: (rawItems: string) => NonNullable<document_d_exports.SdtProperties["listItems"]>;
7
8
  //#endregion
8
- export { sdtAttrsFromProperties, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs };
9
+ export { decodeSdtListItems, sdtAttrsFromProperties, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs };
@@ -25,7 +25,7 @@ const sdtPropertiesFromAttrs = (attrs) => {
25
25
  if (attrs.showingPlaceholder !== void 0) properties.showingPlaceholder = attrs.showingPlaceholder;
26
26
  if (attrs.dateFormat) properties.dateFormat = attrs.dateFormat;
27
27
  if (attrs.dateValueISO) properties.dateValueISO = attrs.dateValueISO;
28
- if (attrs.listItems) properties.listItems = parseSdtListItems(attrs.listItems);
28
+ if (attrs.listItems) properties.listItems = decodeSdtListItems(attrs.listItems);
29
29
  if (typeof attrs.dropdownLastValue === "string") properties.dropdownLastValue = attrs.dropdownLastValue;
30
30
  if (typeof attrs.checked === "boolean") properties.checked = attrs.checked;
31
31
  if (attrs.rawPropertiesXml) properties.rawPropertiesXml = attrs.rawPropertiesXml;
@@ -33,8 +33,13 @@ const sdtPropertiesFromAttrs = (attrs) => {
33
33
  return properties;
34
34
  };
35
35
  const sdtPropertiesMatchAttrs = (properties, attrs) => JSON.stringify(sdtAttrsFromProperties(properties)) === JSON.stringify(sdtAttrsFromProperties(sdtPropertiesFromAttrs(attrs)));
36
- const parseSdtListItems = (rawItems) => {
37
- const parsed = JSON.parse(rawItems);
36
+ const decodeSdtListItems = (rawItems) => {
37
+ let parsed;
38
+ try {
39
+ parsed = JSON.parse(rawItems);
40
+ } catch {
41
+ throw new TypeError("Invalid ProseMirror sdt attrs: listItems is not valid JSON");
42
+ }
38
43
  if (!Array.isArray(parsed)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems is not an array");
39
44
  return parsed.map((item) => {
40
45
  if (!item || typeof item !== "object" || Array.isArray(item)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
@@ -46,4 +51,4 @@ const parseSdtListItems = (rawItems) => {
46
51
  });
47
52
  };
48
53
  //#endregion
49
- export { sdtAttrsFromProperties, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs };
54
+ export { decodeSdtListItems, sdtAttrsFromProperties, sdtPropertiesFromAttrs, sdtPropertiesMatchAttrs };
@@ -645,7 +645,9 @@ function convertTable(table, styleResolver, context) {
645
645
  const fallbackTableStyle = tableStyleId ? void 0 : defaultTableStyle;
646
646
  const conditionalTableStyleId = tableStyle?.styleId ?? fallbackTableStyle?.styleId;
647
647
  const resolvedTableBorders = table.formatting?.borders ?? tableStyle?.tblPr?.borders ?? fallbackTableStyle?.tblPr?.borders;
648
- const resolvedTableIndent = table.formatting?.indent ?? tableStyle?.tblPr?.indent ?? fallbackTableStyle?.tblPr?.indent;
648
+ const fallbackTableIndent = fallbackTableStyle?.tblPr?.indent;
649
+ const resolvedTableIndent = table.formatting?.indent ?? tableStyle?.tblPr?.indent ?? (fallbackTableIndent?.value === 0 ? void 0 : fallbackTableIndent);
650
+ const resolvedTableBidi = table.formatting?.bidi ?? tableStyle?.tblPr?.bidi ?? fallbackTableStyle?.tblPr?.bidi;
649
651
  const tableCellMargins = table.formatting?.cellMargins ?? tableStyle?.tblPr?.cellMargins ?? fallbackTableStyle?.tblPr?.cellMargins;
650
652
  let cellMarginsAttr;
651
653
  if (tableCellMargins) {
@@ -667,6 +669,7 @@ function convertTable(table, styleResolver, context) {
667
669
  if (table.formatting?.look) attrs.look = table.formatting.look;
668
670
  if (table.formatting?.borders) attrs.borders = table.formatting.borders;
669
671
  if (resolvedTableIndent) attrs._resolvedIndent = resolvedTableIndent;
672
+ if (resolvedTableBidi !== void 0) attrs._resolvedBidi = resolvedTableBidi;
670
673
  if (table.formatting) attrs._originalFormatting = table.formatting;
671
674
  if (table.propertyChanges && table.propertyChanges.length > 0) attrs.tblPrChange = [...table.propertyChanges];
672
675
  const conditionalStyles = {};
@@ -1,5 +1,5 @@
1
- import { AnyExtension, CommandMap } from "./types.js";
2
- import { Command, Plugin } from "prosemirror-state";
1
+ import { AnyExtension, CommandFactory, CommandMap, FolioCommandArguments, FolioCommandName } from "./types.js";
2
+ import { Plugin } from "prosemirror-state";
3
3
  import { Schema } from "prosemirror-model";
4
4
  //#region src/prosemirror/extensions/ExtensionManager.d.ts
5
5
  declare class ExtensionManager {
@@ -32,7 +32,10 @@ declare class ExtensionManager {
32
32
  /**
33
33
  * Get a specific command by name
34
34
  */
35
- getCommand(name: string): ((...args: unknown[]) => Command) | undefined;
35
+ getCommand<Name extends FolioCommandName>(name: Name): CommandFactory<FolioCommandArguments[Name]> | undefined;
36
+ getCommand(name: string): CommandFactory | undefined;
37
+ requireCommand<Name extends FolioCommandName>(name: Name): CommandFactory<FolioCommandArguments[Name]>;
38
+ requireCommand(name: string): CommandFactory;
36
39
  /**
37
40
  * Lifecycle: destroy
38
41
  */
@@ -68,12 +68,14 @@ var ExtensionManager = class {
68
68
  getCommands() {
69
69
  return this.commands;
70
70
  }
71
- /**
72
- * Get a specific command by name
73
- */
74
71
  getCommand(name) {
75
72
  return this.commands[name];
76
73
  }
74
+ requireCommand(name) {
75
+ const command = this.getCommand(name);
76
+ if (!command) panic(`ExtensionManager: command "${name}" is not registered`);
77
+ return command;
78
+ }
77
79
  /**
78
80
  * Lifecycle: destroy
79
81
  */
@@ -1,6 +1,6 @@
1
1
  import { document_d_exports } from "../../../types/document.js";
2
- import { NodeExtension } from "../types.js";
3
2
  import { NumberingMap } from "../../../docx/numberingParser.js";
3
+ import { NodeExtension } from "../types.js";
4
4
  import { EditorState } from "prosemirror-state";
5
5
  //#region src/prosemirror/extensions/core/ParagraphExtension.d.ts
6
6
  type ResolvedStyleAttrs = {