@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
@@ -1,3 +1,4 @@
1
+ import { expectParagraphAttrs } from "../../attrs/index.js";
1
2
  import { PPR_CHANGE_SCOPED_ATTR_KEYS } from "../../commands/propertyChangeScope.js";
2
3
  import { SUGGESTION_META, makeRevisionInfo } from "../../plugins/suggestionMode.js";
3
4
  import { createExtension } from "../create.js";
@@ -10,11 +11,10 @@ function chainCommands(...commands) {
10
11
  return false;
11
12
  };
12
13
  }
13
- function appendParagraphPropertyChange(attrs, previousFormatting, rev) {
14
- const existing = Array.isArray(attrs["_propertyChanges"]) ? attrs["_propertyChanges"] : [];
14
+ function appendParagraphPropertyChange(attrs, existing, previousFormatting, rev) {
15
15
  return {
16
16
  ...attrs,
17
- _propertyChanges: [...existing, {
17
+ _propertyChanges: [...existing ?? [], {
18
18
  type: "paragraphPropertyChange",
19
19
  info: {
20
20
  id: rev.id,
@@ -85,7 +85,7 @@ function toggleList(numId) {
85
85
  listMarker: null
86
86
  };
87
87
  }
88
- if (rev) nextAttrs = appendParagraphPropertyChange(nextAttrs, getPreviousListFormatting(node.attrs), rev);
88
+ if (rev) nextAttrs = appendParagraphPropertyChange(nextAttrs, expectParagraphAttrs(node)._propertyChanges, getPreviousListFormatting(node.attrs), rev);
89
89
  tr = tr.setNodeMarkup(pos, void 0, nextAttrs);
90
90
  }
91
91
  });
@@ -1,10 +1,11 @@
1
1
  import { document_d_exports } from "../../../types/document.js";
2
+ import { RunFormattingOverrideAttrs } from "../../schema/marks.js";
2
3
  import { MarkExtension } from "../types.js";
3
4
  import { Mark } from "prosemirror-model";
4
5
  //#region src/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts
5
- type RunFormattingOverrideAttrs = Record<string, false | "none">;
6
6
  declare function buildRunFormattingOverrideAttrs(formatting: document_d_exports.TextFormatting | undefined): RunFormattingOverrideAttrs | undefined;
7
+ declare function applyRunFormattingOverrideAttrs(formatting: document_d_exports.TextFormatting, attrs: RunFormattingOverrideAttrs): void;
7
8
  declare function applyRunFormattingOverrideMark(formatting: document_d_exports.TextFormatting, mark: Mark): void;
8
9
  declare const RunFormattingOverrideExtension: (options?: Partial<Record<string, unknown>> | undefined) => MarkExtension;
9
10
  //#endregion
10
- export { RunFormattingOverrideExtension, applyRunFormattingOverrideMark, buildRunFormattingOverrideAttrs };
11
+ export { RunFormattingOverrideExtension, applyRunFormattingOverrideAttrs, applyRunFormattingOverrideMark, buildRunFormattingOverrideAttrs };
@@ -4,23 +4,26 @@ import { createMarkExtension } from "../create.js";
4
4
  function buildRunFormattingOverrideAttrs(formatting) {
5
5
  if (!formatting) return;
6
6
  const attrs = {};
7
- if (formatting.bold === false) attrs["bold"] = false;
8
- if (formatting.italic === false) attrs["italic"] = false;
9
- if (formatting.underline?.style === "none") attrs["underline"] = "none";
10
- if (formatting.strike === false) attrs["strike"] = false;
11
- if (formatting.doubleStrike === false) attrs["doubleStrike"] = false;
12
- if (formatting.allCaps === false) attrs["allCaps"] = false;
13
- if (formatting.smallCaps === false) attrs["smallCaps"] = false;
14
- if (formatting.hidden === false) attrs["hidden"] = false;
15
- if (formatting.emboss === false) attrs["emboss"] = false;
16
- if (formatting.imprint === false) attrs["imprint"] = false;
17
- if (formatting.shadow === false) attrs["shadow"] = false;
18
- if (formatting.outline === false) attrs["outline"] = false;
19
- if (formatting.rtl === false) attrs["rtl"] = false;
7
+ if (formatting.bold === false) attrs.bold = false;
8
+ if (formatting.italic === false) attrs.italic = false;
9
+ if (formatting.underline?.style === "none") attrs.underline = "none";
10
+ if (formatting.strike === false) attrs.strike = false;
11
+ if (formatting.doubleStrike === false) attrs.doubleStrike = false;
12
+ if (formatting.allCaps === false) attrs.allCaps = false;
13
+ if (formatting.smallCaps === false) attrs.smallCaps = false;
14
+ if (formatting.hidden === false) attrs.hidden = false;
15
+ if (formatting.emboss === false) attrs.emboss = false;
16
+ if (formatting.imprint === false) attrs.imprint = false;
17
+ if (formatting.shadow === false) attrs.shadow = false;
18
+ if (formatting.outline === false) attrs.outline = false;
19
+ if (formatting.rtl === false) attrs.rtl = false;
20
+ if (formatting.boldCs !== void 0 && formatting.boldCs !== formatting.bold) attrs.boldCs = formatting.boldCs;
21
+ if (formatting.italicCs !== void 0 && formatting.italicCs !== formatting.italic) attrs.italicCs = formatting.italicCs;
22
+ if (formatting.fontSizeCs !== void 0 && formatting.fontSizeCs !== formatting.fontSize) attrs.fontSizeCs = formatting.fontSizeCs;
23
+ if (formatting.cs !== void 0) attrs.cs = formatting.cs;
20
24
  return Object.keys(attrs).length > 0 ? attrs : void 0;
21
25
  }
22
- function applyRunFormattingOverrideMark(formatting, mark) {
23
- const attrs = expectRunFormattingOverrideMarkAttrs(mark);
26
+ function applyRunFormattingOverrideAttrs(formatting, attrs) {
24
27
  if (attrs.bold === false) formatting.bold = false;
25
28
  if (attrs.italic === false) formatting.italic = false;
26
29
  if (attrs.underline === "none") formatting.underline = { style: "none" };
@@ -34,6 +37,13 @@ function applyRunFormattingOverrideMark(formatting, mark) {
34
37
  if (attrs.shadow === false) formatting.shadow = false;
35
38
  if (attrs.outline === false) formatting.outline = false;
36
39
  if (attrs.rtl === false) formatting.rtl = false;
40
+ if (attrs.boldCs !== void 0) formatting.boldCs = attrs.boldCs;
41
+ if (attrs.italicCs !== void 0) formatting.italicCs = attrs.italicCs;
42
+ if (attrs.fontSizeCs !== void 0) formatting.fontSizeCs = attrs.fontSizeCs;
43
+ if (attrs.cs !== void 0) formatting.cs = attrs.cs;
44
+ }
45
+ function applyRunFormattingOverrideMark(formatting, mark) {
46
+ applyRunFormattingOverrideAttrs(formatting, expectRunFormattingOverrideMarkAttrs(mark));
37
47
  }
38
48
  const RunFormattingOverrideExtension = createMarkExtension({
39
49
  name: "runFormattingOverride",
@@ -52,7 +62,11 @@ const RunFormattingOverrideExtension = createMarkExtension({
52
62
  imprint: { default: null },
53
63
  shadow: { default: null },
54
64
  outline: { default: null },
55
- rtl: { default: null }
65
+ rtl: { default: null },
66
+ boldCs: { default: null },
67
+ italicCs: { default: null },
68
+ fontSizeCs: { default: null },
69
+ cs: { default: null }
56
70
  },
57
71
  toDOM(mark) {
58
72
  const attrs = expectRunFormattingOverrideMarkAttrs(mark);
@@ -72,4 +86,4 @@ const RunFormattingOverrideExtension = createMarkExtension({
72
86
  }
73
87
  });
74
88
  //#endregion
75
- export { RunFormattingOverrideExtension, applyRunFormattingOverrideMark, buildRunFormattingOverrideAttrs };
89
+ export { RunFormattingOverrideExtension, applyRunFormattingOverrideAttrs, applyRunFormattingOverrideMark, buildRunFormattingOverrideAttrs };
@@ -1,5 +1,5 @@
1
- import { NodeExtension } from "../types.js";
2
1
  import { ShapeAttrs as ShapeAttrs$1 } from "../../schema/nodes.js";
2
+ import { NodeExtension } from "../types.js";
3
3
  //#region src/prosemirror/extensions/nodes/ShapeExtension.d.ts
4
4
  type ShapeAttrs = ShapeAttrs$1;
5
5
  declare function sanitizeColor(value: string | null | undefined): string | null;
@@ -154,6 +154,7 @@ const tableSpec = {
154
154
  look: { default: null },
155
155
  borders: { default: null },
156
156
  _resolvedIndent: { default: null },
157
+ _resolvedBidi: { default: null },
157
158
  _originalFormatting: { default: null },
158
159
  tblPrChange: { default: null },
159
160
  _suggestedInsert: { default: null }
@@ -1,7 +1,7 @@
1
1
  import { document_d_exports } from "../../../types/document.js";
2
2
  import { OutlineStyleAttr } from "../../../types/documentEnumValues.js";
3
- import { NodeExtension } from "../types.js";
4
3
  import { ImagePositionAttrs, TextBoxAttrs as TextBoxAttrs$1 } from "../../schema/nodes.js";
4
+ import { NodeExtension } from "../types.js";
5
5
  //#region src/prosemirror/extensions/nodes/TextBoxExtension.d.ts
6
6
  type TextBoxAttrs = {
7
7
  /** Width in pixels */
@@ -1,6 +1,50 @@
1
+ import { document_d_exports } from "../../types/document.js";
2
+ import { TextColorAttrs } from "../schema/marks.js";
3
+ import "../schema/index.js";
4
+ import { TablePropertiesCommand } from "../../utils/tableOperations.js";
5
+ import { ResolvedStyleAttrs } from "./core/ParagraphExtension.js";
6
+ import { BorderPreset, TableBorderPreset } from "./nodes/TableExtension.js";
1
7
  import { Command, Plugin } from "prosemirror-state";
2
8
  import { MarkSpec, NodeSpec, Schema } from "prosemirror-model";
3
9
  //#region src/prosemirror/extensions/types.d.ts
10
+ type TableCellBorderCommandSpec = {
11
+ style: string;
12
+ size?: number;
13
+ color?: {
14
+ rgb: string;
15
+ };
16
+ };
17
+ type TableBorderCommandSpec = {
18
+ style: string;
19
+ size: number;
20
+ color: {
21
+ rgb: string;
22
+ };
23
+ };
24
+ type TableCellMarginsCommand = {
25
+ top?: number;
26
+ bottom?: number;
27
+ left?: number;
28
+ right?: number;
29
+ };
30
+ type TableStyleCommand = {
31
+ styleId: string;
32
+ tableBorders?: Partial<Record<"top" | "bottom" | "left" | "right" | "insideH" | "insideV", TableCellBorderCommandSpec>>;
33
+ conditionals?: Record<string, {
34
+ backgroundColor?: string;
35
+ borders?: Partial<Record<"top" | "bottom" | "left" | "right", TableCellBorderCommandSpec | null>>;
36
+ bold?: boolean;
37
+ color?: string;
38
+ }>;
39
+ look?: {
40
+ firstRow?: boolean;
41
+ lastRow?: boolean;
42
+ firstCol?: boolean;
43
+ lastCol?: boolean;
44
+ noHBand?: boolean;
45
+ noVBand?: boolean;
46
+ };
47
+ };
4
48
  type ExtensionPriority = number;
5
49
  declare const Priority: {
6
50
  readonly Highest: 0;
@@ -12,7 +56,96 @@ declare const Priority: {
12
56
  type ExtensionContext = {
13
57
  schema: Schema;
14
58
  };
59
+ type FolioCommandArguments = {
60
+ toggleBold: [];
61
+ toggleItalic: [];
62
+ toggleUnderline: [];
63
+ toggleStrike: [];
64
+ toggleSuperscript: [];
65
+ toggleSubscript: [];
66
+ setTextColor: [attrs: TextColorAttrs];
67
+ clearTextColor: [];
68
+ setHighlight: [color: string];
69
+ clearHighlight: [];
70
+ setFontSize: [size: number];
71
+ clearFontSize: [];
72
+ setFontFamily: [fontName: string];
73
+ clearFontFamily: [];
74
+ setUnderlineStyle: [style: string, color?: TextColorAttrs];
75
+ setHyperlink: [href: string, tooltip?: string];
76
+ removeHyperlink: [];
77
+ insertHyperlink: [text: string, href: string, tooltip?: string];
78
+ setAlignment: [alignment: document_d_exports.ParagraphAlignment];
79
+ alignLeft: [];
80
+ alignCenter: [];
81
+ alignRight: [];
82
+ alignJustify: [];
83
+ setLineSpacing: [value: number, rule?: document_d_exports.LineSpacingRule];
84
+ singleSpacing: [];
85
+ oneAndHalfSpacing: [];
86
+ doubleSpacing: [];
87
+ increaseIndent: [amount?: number];
88
+ decreaseIndent: [amount?: number];
89
+ setIndentLeft: [twips: number];
90
+ setIndentRight: [twips: number];
91
+ setIndentFirstLine: [twips: number, hanging?: boolean];
92
+ toggleBulletList: [];
93
+ toggleNumberedList: [];
94
+ increaseListLevel: [];
95
+ decreaseListLevel: [];
96
+ removeList: [];
97
+ setSpaceBefore: [twips: number];
98
+ setSpaceAfter: [twips: number];
99
+ applyStyle: [styleId: string, resolvedAttrs?: ResolvedStyleAttrs];
100
+ clearStyle: [];
101
+ insertSectionBreak: [breakType: "nextPage" | "continuous" | "oddPage" | "evenPage"];
102
+ removeSectionBreak: [];
103
+ addTabStop: [position: number, alignment?: document_d_exports.TabStopAlignment, leader?: document_d_exports.TabLeader];
104
+ removeTabStop: [position: number];
105
+ toggleBidi: [];
106
+ setRtl: [];
107
+ setLtr: [];
108
+ setTabs: [tabs: document_d_exports.TabStop[]];
109
+ generateTOC: [];
110
+ insertTable: [rows: number, cols: number];
111
+ addRowAbove: [];
112
+ addRowBelow: [];
113
+ deleteRow: [];
114
+ addColumnLeft: [];
115
+ addColumnRight: [];
116
+ deleteColumn: [];
117
+ deleteTable: [];
118
+ selectTable: [];
119
+ selectRow: [];
120
+ selectColumn: [];
121
+ mergeCells: [];
122
+ splitCell: [];
123
+ setCellBorder: [side: "top" | "bottom" | "left" | "right" | "all", spec: TableCellBorderCommandSpec | null, clearOthers?: boolean];
124
+ setTableBorderPreset: [preset: TableBorderPreset];
125
+ setTableBorders: [preset: BorderPreset, borderSpec?: TableBorderCommandSpec];
126
+ removeTableBorders: [];
127
+ setAllTableBorders: [borderSpec?: TableBorderCommandSpec];
128
+ setOutsideTableBorders: [borderSpec?: TableBorderCommandSpec];
129
+ setInsideTableBorders: [borderSpec?: TableBorderCommandSpec];
130
+ setCellVerticalAlign: [align: "top" | "center" | "bottom"];
131
+ setCellMargins: [margins: TableCellMarginsCommand];
132
+ setCellTextDirection: [direction: string | null];
133
+ toggleNoWrap: [];
134
+ setRowHeight: [height: number | null, rule?: "auto" | "atLeast" | "exact"];
135
+ toggleHeaderRow: [];
136
+ distributeColumns: [];
137
+ autoFitContents: [];
138
+ setTableProperties: [props: TablePropertiesCommand];
139
+ applyTableStyle: [styleData: TableStyleCommand];
140
+ setCellFillColor: [color: string | null];
141
+ setTableBorderColor: [color: string];
142
+ setTableBorderWidth: [size: number];
143
+ };
144
+ type FolioCommandName = keyof FolioCommandArguments;
145
+ type CommandFactory<Args extends readonly unknown[] = readonly unknown[]> = (...args: Args) => Command;
146
+ type FolioCommandMap = Partial<{ [Name in FolioCommandName]: CommandFactory<FolioCommandArguments[Name]>; }>;
15
147
  type CommandMap = Record<string, (...args: any[]) => Command>;
148
+ type ExtensionCommandMap = CommandMap & FolioCommandMap;
16
149
  type KeyboardShortcutMap = Record<string, Command>;
17
150
  type ExtensionRuntime = {
18
151
  commands?: CommandMap;
@@ -97,4 +230,4 @@ type MarkExtensionDefinitionWithoutDefaults<TOptions extends ExtensionOptions =
97
230
  };
98
231
  type MarkExtensionDefinition<TOptions extends ExtensionOptions = ExtensionOptions> = MarkExtensionDefinitionWithDefaults<TOptions> | MarkExtensionDefinitionWithoutDefaults<TOptions>;
99
232
  //#endregion
100
- export { AnyExtension, CommandMap, Extension, ExtensionConfig, ExtensionContext, ExtensionDefinition, ExtensionPriority, ExtensionRuntime, KeyboardShortcutMap, MarkExtension, MarkExtensionConfig, MarkExtensionDefinition, NodeExtension, NodeExtensionConfig, NodeExtensionDefinition, Priority };
233
+ export { AnyExtension, CommandFactory, CommandMap, Extension, ExtensionCommandMap, ExtensionConfig, ExtensionContext, ExtensionDefinition, ExtensionPriority, ExtensionRuntime, FolioCommandArguments, FolioCommandMap, FolioCommandName, KeyboardShortcutMap, MarkExtension, MarkExtensionConfig, MarkExtensionDefinition, NodeExtension, NodeExtensionConfig, NodeExtensionDefinition, Priority, TableBorderCommandSpec, TableCellBorderCommandSpec, TableCellMarginsCommand, type TablePropertiesCommand, TableStyleCommand };
@@ -1,15 +1,15 @@
1
1
  import { FontFamilyAttrs, FontSizeAttrs, HyperlinkAttrs, TextColorAttrs, UnderlineAttrs } from "./schema/marks.js";
2
2
  import { ImageAttrs, ParagraphAttrs } from "./schema/nodes.js";
3
3
  import { schema, singletonManager } from "./schema/index.js";
4
+ import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
5
+ import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
4
6
  import { PAINTABLE_MARK_NAMES, applyFormatMarks, captureFormatMarks } from "./commands/formatPainter.js";
5
7
  import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
6
8
  import { getHyperlinkAttrs, getSelectedText, isHyperlinkActive } from "./extensions/marks/HyperlinkExtension.js";
7
9
  import { clearFontFamily, clearFontSize, clearHighlight, clearTextColor, insertHyperlink, removeHyperlink, setFontFamily, setFontSize, setHighlight, setHyperlink, setTextColor, toggleBold, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "./commands/formatting.js";
8
10
  import { insertImageFromFile } from "./commands/image.js";
9
- import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
10
11
  import { getListInfo, isInList } from "./extensions/features/ListExtension.js";
11
12
  import { addTabStop, alignCenter, alignJustify, alignLeft, alignRight, applyStyle, clearStyle, decreaseIndent, decreaseListLevel, generateTOC, increaseIndent, increaseListLevel, removeList, removeTabStop, setAlignment, setIndentFirstLine, setIndentLeft, setIndentRight, setLineSpacing, setLtr, setRtl, toggleBidi, toggleBulletList, toggleNumberedList } from "./commands/paragraph.js";
12
- import { BorderPreset, TableBorderPreset, TableContextInfo, getTableContext, isInTable as isInTableCell } from "./extensions/nodes/TableExtension.js";
13
13
  import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyle, autoFitContents, deleteColumn, deleteRow, deleteTable, distributeColumns, insertTable, mergeCells, removeTableBorders, selectColumn, selectRow, selectTable, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setInsideTableBorders, setOutsideTableBorders, setRowHeight, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableBorders, setTableProperties, splitCell, toggleHeaderRow, toggleNoWrap } from "./commands/table.js";
14
14
  import { insertPageBreak } from "./commands/pageBreak.js";
15
15
  import "./commands/index.js";
@@ -1,4 +1,5 @@
1
- import { collectMarksInRange } from "../selectionMarks.js";
1
+ import { expectCommentMarkAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
2
+ import { extractSelectionSnapshot } from "../selectionState.js";
2
3
  import { Plugin, PluginKey } from "prosemirror-state";
3
4
  //#region src/prosemirror/plugins/selectionTracker.ts
4
5
  /**
@@ -18,56 +19,41 @@ const selectionTrackerKey = new PluginKey("selectionTracker");
18
19
  * Extract selection context from editor state
19
20
  */
20
21
  function extractSelectionContext(state) {
21
- const { selection, doc } = state;
22
- const { from, to, empty } = selection;
23
- const $from = doc.resolve(from);
24
- let startParagraphIndex = 0;
25
- let endParagraphIndex = 0;
26
- doc.forEach((_node, offset, index) => {
27
- if (offset > to) return;
28
- if (offset <= from) startParagraphIndex = index;
29
- if (offset <= to) endParagraphIndex = index;
30
- });
31
- const textFormatting = extractTextFormatting(state);
32
- const paragraph = $from.parent;
33
- const paragraphFormatting = {};
34
- if (paragraph.type.name === "paragraph") {
35
- if (paragraph.attrs["alignment"]) paragraphFormatting.alignment = paragraph.attrs["alignment"];
36
- if (typeof paragraph.attrs["lineSpacing"] === "number") {
37
- paragraphFormatting.lineSpacing = paragraph.attrs["lineSpacing"];
38
- paragraphFormatting.lineSpacingRule = paragraph.attrs["lineSpacingRule"];
39
- }
40
- if (typeof paragraph.attrs["snapToGrid"] === "boolean") paragraphFormatting.snapToGrid = paragraph.attrs["snapToGrid"];
41
- if (paragraph.attrs["indentLeft"]) paragraphFormatting.indentLeft = paragraph.attrs["indentLeft"];
42
- if (paragraph.attrs["indentRight"]) paragraphFormatting.indentRight = paragraph.attrs["indentRight"];
43
- if (paragraph.attrs["indentFirstLine"]) paragraphFormatting.indentFirstLine = paragraph.attrs["indentFirstLine"];
44
- if (paragraph.attrs["hangingIndent"]) paragraphFormatting.hangingIndent = paragraph.attrs["hangingIndent"];
45
- if (paragraph.attrs["tabs"]) paragraphFormatting.tabs = paragraph.attrs["tabs"];
46
- if (paragraph.attrs["numPr"]) paragraphFormatting.numPr = paragraph.attrs["numPr"];
47
- if (paragraph.attrs["styleId"]) paragraphFormatting.styleId = paragraph.attrs["styleId"];
48
- }
49
- const numPr = paragraph.attrs["numPr"];
22
+ const { selection } = state;
23
+ const { empty } = selection;
24
+ const snapshot = extractSelectionSnapshot(state);
25
+ const paragraphFormatting = snapshot.styleId === null ? snapshot.paragraphFormatting : {
26
+ ...snapshot.paragraphFormatting,
27
+ styleId: snapshot.styleId
28
+ };
29
+ const numPr = snapshot.paragraphFormatting.numPr;
50
30
  const inList = !!numPr?.numId;
51
31
  let listType;
52
32
  if (numPr?.numId === 1) listType = "bullet";
53
33
  else if (numPr?.numId) listType = "numbered";
54
34
  const listLevel = numPr?.ilvl;
55
- const allMarks = state.storedMarks || (empty ? $from.marks() : []);
35
+ const allMarks = state.storedMarks || (empty ? selection.$from.marks() : []);
56
36
  const activeCommentIds = [];
57
37
  let inInsertion = false;
58
38
  let inDeletion = false;
59
39
  for (const mark of allMarks) {
60
- if (mark.type.name === "comment" && mark.attrs["commentId"]) activeCommentIds.push(mark.attrs["commentId"]);
61
- if (mark.type.name === "insertion") inInsertion = true;
62
- if (mark.type.name === "deletion") inDeletion = true;
40
+ if (mark.type.name === "comment") activeCommentIds.push(expectCommentMarkAttrs(mark).commentId);
41
+ if (mark.type.name === "insertion") {
42
+ expectTrackedChangeMarkAttrs(mark);
43
+ inInsertion = true;
44
+ }
45
+ if (mark.type.name === "deletion") {
46
+ expectTrackedChangeMarkAttrs(mark);
47
+ inDeletion = true;
48
+ }
63
49
  }
64
50
  return {
65
- hasSelection: !empty,
66
- isMultiParagraph: startParagraphIndex !== endParagraphIndex,
67
- textFormatting,
51
+ hasSelection: snapshot.hasSelection,
52
+ isMultiParagraph: snapshot.isMultiParagraph,
53
+ textFormatting: snapshot.textFormatting,
68
54
  paragraphFormatting,
69
- startParagraphIndex,
70
- endParagraphIndex,
55
+ startParagraphIndex: snapshot.startParagraphIndex,
56
+ endParagraphIndex: snapshot.endParagraphIndex,
71
57
  inList,
72
58
  ...listType !== void 0 ? { listType } : {},
73
59
  ...listLevel !== void 0 ? { listLevel } : {},
@@ -77,66 +63,6 @@ function extractSelectionContext(state) {
77
63
  };
78
64
  }
79
65
  /**
80
- * Extract text formatting from current selection/cursor marks
81
- */
82
- function extractTextFormatting(state) {
83
- const { selection, doc } = state;
84
- const { from, to, empty, $from } = selection;
85
- const marks = empty ? state.storedMarks || $from.marks() : collectMarksInRange({
86
- doc,
87
- from,
88
- to
89
- });
90
- const formatting = {};
91
- for (const mark of marks) switch (mark.type.name) {
92
- case "bold":
93
- formatting.bold = true;
94
- break;
95
- case "italic":
96
- formatting.italic = true;
97
- break;
98
- case "underline":
99
- if (mark.attrs["style"] !== "none") formatting.underline = {
100
- style: mark.attrs["style"] || "single",
101
- color: mark.attrs["color"]
102
- };
103
- break;
104
- case "strike":
105
- if (mark.attrs["double"]) formatting.doubleStrike = true;
106
- else formatting.strike = true;
107
- break;
108
- case "textColor":
109
- formatting.color = {
110
- rgb: mark.attrs["rgb"],
111
- themeColor: mark.attrs["themeColor"],
112
- themeTint: mark.attrs["themeTint"],
113
- themeShade: mark.attrs["themeShade"]
114
- };
115
- break;
116
- case "highlight":
117
- formatting.highlight = mark.attrs["color"];
118
- break;
119
- case "fontSize":
120
- formatting.fontSize = mark.attrs["size"];
121
- break;
122
- case "fontFamily":
123
- formatting.fontFamily = {
124
- ascii: mark.attrs["ascii"],
125
- hAnsi: mark.attrs["hAnsi"],
126
- asciiTheme: mark.attrs["asciiTheme"]
127
- };
128
- break;
129
- case "superscript":
130
- formatting.vertAlign = "superscript";
131
- break;
132
- case "subscript":
133
- formatting.vertAlign = "subscript";
134
- break;
135
- default: break;
136
- }
137
- return formatting;
138
- }
139
- /**
140
66
  * Create selection tracker plugin
141
67
  */
142
68
  function createSelectionTrackerPlugin(onSelectionChange) {
@@ -1,3 +1,4 @@
1
+ import { expectParagraphAttrs } from "./attrs/index.js";
1
2
  //#region src/prosemirror/revisionCarriers.ts
2
3
  const isObjectRecord = (value) => typeof value === "object" && value !== null;
3
4
  const revisionMetadata = (value) => {
@@ -34,6 +35,7 @@ const getFolioNodeRevisionCarriers = (node, nodePos) => {
34
35
  if (node.type.name === "paragraph") {
35
36
  const from = nodePos + node.nodeSize - 1;
36
37
  const to = nodePos + node.nodeSize;
38
+ const paragraphAttrs = expectParagraphAttrs(node);
37
39
  const paragraphMark = node.attrs["pPrMark"];
38
40
  if (isObjectRecord(paragraphMark) && (paragraphMark["kind"] === "ins" || paragraphMark["kind"] === "del")) {
39
41
  const metadata = revisionMetadata(paragraphMark["info"]);
@@ -47,7 +49,7 @@ const getFolioNodeRevisionCarriers = (node, nodePos) => {
47
49
  }
48
50
  appendPropertyCarriers({
49
51
  carriers,
50
- changes: node.attrs["_propertyChanges"],
52
+ changes: paragraphAttrs._propertyChanges,
51
53
  type: "paragraphPropertiesChanged",
52
54
  node,
53
55
  from,
@@ -1,6 +1,6 @@
1
1
  import { CharacterSpacingAttrs, CharacterStyleAttrs, CommentAttrs, EmphasisMarkAttrs, FontFamilyAttrs, FontSizeAttrs, FootnoteRefAttrs, HighlightAttrs, HyperlinkAttrs, LanguageAttrs, RunFormattingOverrideAttrs, RunPropertyChangeMarkAttrs, RunShadingAttrs, StrikeAttrs, TextColorAttrs, TextEffectAttrs, TrackedChangeMarkAttrs, UnderlineAttrs } from "./marks.js";
2
+ import { BlockSdtAttrs, FieldAttrs, HardBreakAttrs, ImageAttrs, ImagePositionAttrs, MathAttrs, ParagraphAttrs, ParagraphPropertyChangeAttrs, SdtAttrs, ShapeAttrs, SymbolAttrs, TabAttrs, TableAttrs, TableCellAttrs, TableRowAttrs, TextBoxAttrs } from "./nodes.js";
2
3
  import { ExtensionManager } from "../extensions/ExtensionManager.js";
3
- import { BlockSdtAttrs, FieldAttrs, HardBreakAttrs, ImageAttrs, ImagePositionAttrs, MathAttrs, ParagraphAttrs, SdtAttrs, ShapeAttrs, SymbolAttrs, TabAttrs, TableAttrs, TableCellAttrs, TableRowAttrs, TextBoxAttrs } from "./nodes.js";
4
4
  //#region src/prosemirror/schema/index.d.ts
5
5
  declare const singletonManager: ExtensionManager;
6
6
  declare const schema: import("prosemirror-model").Schema<any, any>;
@@ -11,4 +11,4 @@ type DocxSchema = typeof schema;
11
11
  type DocxNode = ReturnType<typeof schema.node>;
12
12
  type DocxMark = ReturnType<typeof schema.mark>;
13
13
  //#endregion
14
- export { type BlockSdtAttrs, type CharacterSpacingAttrs, type CharacterStyleAttrs, type CommentAttrs, DocxMark, DocxNode, DocxSchema, type EmphasisMarkAttrs, type FieldAttrs, type FontFamilyAttrs, type FontSizeAttrs, type FootnoteRefAttrs, type HardBreakAttrs, type HighlightAttrs, type HyperlinkAttrs, type ImageAttrs, type ImagePositionAttrs, type LanguageAttrs, type MathAttrs, type ParagraphAttrs, type RunFormattingOverrideAttrs, type RunPropertyChangeMarkAttrs, type RunShadingAttrs, type SdtAttrs, type ShapeAttrs, type StrikeAttrs, type SymbolAttrs, type TabAttrs, type TableAttrs, type TableCellAttrs, type TableRowAttrs, type TextBoxAttrs, type TextColorAttrs, type TextEffectAttrs, type TrackedChangeMarkAttrs, type UnderlineAttrs, schema, singletonManager };
14
+ export { type BlockSdtAttrs, type CharacterSpacingAttrs, type CharacterStyleAttrs, type CommentAttrs, DocxMark, DocxNode, DocxSchema, type EmphasisMarkAttrs, type FieldAttrs, type FontFamilyAttrs, type FontSizeAttrs, type FootnoteRefAttrs, type HardBreakAttrs, type HighlightAttrs, type HyperlinkAttrs, type ImageAttrs, type ImagePositionAttrs, type LanguageAttrs, type MathAttrs, type ParagraphAttrs, type ParagraphPropertyChangeAttrs, type RunFormattingOverrideAttrs, type RunPropertyChangeMarkAttrs, type RunShadingAttrs, type SdtAttrs, type ShapeAttrs, type StrikeAttrs, type SymbolAttrs, type TabAttrs, type TableAttrs, type TableCellAttrs, type TableRowAttrs, type TextBoxAttrs, type TextColorAttrs, type TextEffectAttrs, type TrackedChangeMarkAttrs, type UnderlineAttrs, schema, singletonManager };
@@ -14,6 +14,93 @@ import { createStarterKit } from "../extensions/StarterKit.js";
14
14
  const mgr = new ExtensionManager(createStarterKit());
15
15
  mgr.buildSchema();
16
16
  mgr.initializeRuntime();
17
+ const completeCommandNames = (names) => names;
18
+ const requiredCommands = completeCommandNames([
19
+ "toggleBold",
20
+ "toggleItalic",
21
+ "toggleUnderline",
22
+ "toggleStrike",
23
+ "toggleSuperscript",
24
+ "toggleSubscript",
25
+ "setTextColor",
26
+ "clearTextColor",
27
+ "setHighlight",
28
+ "clearHighlight",
29
+ "setFontSize",
30
+ "clearFontSize",
31
+ "setFontFamily",
32
+ "clearFontFamily",
33
+ "setUnderlineStyle",
34
+ "setHyperlink",
35
+ "removeHyperlink",
36
+ "insertHyperlink",
37
+ "setAlignment",
38
+ "alignLeft",
39
+ "alignCenter",
40
+ "alignRight",
41
+ "alignJustify",
42
+ "setLineSpacing",
43
+ "singleSpacing",
44
+ "oneAndHalfSpacing",
45
+ "doubleSpacing",
46
+ "increaseIndent",
47
+ "decreaseIndent",
48
+ "setIndentLeft",
49
+ "setIndentRight",
50
+ "setIndentFirstLine",
51
+ "toggleBulletList",
52
+ "toggleNumberedList",
53
+ "increaseListLevel",
54
+ "decreaseListLevel",
55
+ "removeList",
56
+ "setSpaceBefore",
57
+ "setSpaceAfter",
58
+ "applyStyle",
59
+ "clearStyle",
60
+ "insertSectionBreak",
61
+ "removeSectionBreak",
62
+ "addTabStop",
63
+ "removeTabStop",
64
+ "toggleBidi",
65
+ "setRtl",
66
+ "setLtr",
67
+ "setTabs",
68
+ "generateTOC",
69
+ "insertTable",
70
+ "addRowAbove",
71
+ "addRowBelow",
72
+ "deleteRow",
73
+ "addColumnLeft",
74
+ "addColumnRight",
75
+ "deleteColumn",
76
+ "deleteTable",
77
+ "selectTable",
78
+ "selectRow",
79
+ "selectColumn",
80
+ "mergeCells",
81
+ "splitCell",
82
+ "setCellBorder",
83
+ "setTableBorderPreset",
84
+ "setTableBorders",
85
+ "removeTableBorders",
86
+ "setAllTableBorders",
87
+ "setOutsideTableBorders",
88
+ "setInsideTableBorders",
89
+ "setCellVerticalAlign",
90
+ "setCellMargins",
91
+ "setCellTextDirection",
92
+ "toggleNoWrap",
93
+ "setRowHeight",
94
+ "toggleHeaderRow",
95
+ "distributeColumns",
96
+ "autoFitContents",
97
+ "setTableProperties",
98
+ "applyTableStyle",
99
+ "setCellFillColor",
100
+ "setTableBorderColor",
101
+ "setTableBorderWidth"
102
+ ]);
103
+ for (const commandName of requiredCommands) mgr.requireCommand(commandName);
17
104
  const singletonManager = mgr;
18
105
  const schema = mgr.getSchema();
19
106
  //#endregion
@@ -122,6 +122,14 @@ type RunPropertyChangeMarkAttrs = {
122
122
  suggestionId?: string;
123
123
  };
124
124
  type RunFormattingOverrideAttrs = { [K in keyof Pick<document_d_exports.TextFormatting, "bold" | "italic" | "strike" | "doubleStrike" | "allCaps" | "smallCaps" | "hidden" | "emboss" | "imprint" | "shadow" | "outline" | "rtl">]?: false; } & {
125
+ /** Independent complex-script weight (`w:bCs`). */
126
+ boldCs?: boolean;
127
+ /** Force complex-script formatting for the full run (`w:cs`). */
128
+ cs?: boolean;
129
+ /** Independent complex-script size in half-points (`w:szCs`). */
130
+ fontSizeCs?: number;
131
+ /** Independent complex-script slant (`w:iCs`). */
132
+ italicCs?: boolean;
125
133
  underline?: "none";
126
134
  };
127
135
  /**