@stll/folio-core 0.54.1 → 0.54.2

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 (69) hide show
  1. package/dist/ai-edits/apply.d.ts +1 -1
  2. package/dist/ai-edits/apply.js +18 -31
  3. package/dist/ai-edits/headless.d.ts +1 -2
  4. package/dist/ai-edits/headless.js +12 -27
  5. package/dist/ai-edits/read.d.ts +1 -0
  6. package/dist/ai-edits/read.js +7 -2
  7. package/dist/ai-edits/table-mutation-plan.d.ts +2 -1
  8. package/dist/ai-edits/table-mutation-plan.js +39 -1
  9. package/dist/ai-suggestions/apply.d.ts +1 -1
  10. package/dist/ai-suggestions/apply.js +3 -2
  11. package/dist/compare/compare.js +2 -1
  12. package/dist/docx/bookmarkIds.d.ts +11 -0
  13. package/dist/docx/bookmarkIds.js +33 -0
  14. package/dist/docx/documentParser.d.ts +14 -1
  15. package/dist/docx/documentParser.js +17 -4
  16. package/dist/docx/drawingIdNormalization.js +23 -8
  17. package/dist/docx/ensureParaIds.d.ts +5 -0
  18. package/dist/docx/ensureParaIds.js +10 -2
  19. package/dist/docx/listNumberingInstances.js +11 -9
  20. package/dist/docx/noteIds.d.ts +4 -0
  21. package/dist/docx/noteIds.js +13 -0
  22. package/dist/docx/numberingIds.d.ts +14 -0
  23. package/dist/docx/numberingIds.js +16 -0
  24. package/dist/docx/numericIdAllocator.d.ts +12 -0
  25. package/dist/docx/numericIdAllocator.js +33 -0
  26. package/dist/docx/numericIdNormalization.d.ts +16 -0
  27. package/dist/docx/numericIdNormalization.js +174 -0
  28. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  29. package/dist/docx/parser.js +17 -5
  30. package/dist/docx/rasterMime.d.ts +64 -0
  31. package/dist/docx/rasterMime.js +116 -0
  32. package/dist/docx/replyToComment.js +13 -6
  33. package/dist/docx/rezip.js +14 -7
  34. package/dist/docx/selectiveSave.js +10 -0
  35. package/dist/docx/serializer/partNamespaces.js +4 -2
  36. package/dist/docx/serializer/runSerializer.js +5 -4
  37. package/dist/docx/serializer/trackedChangeAttributes.js +7 -1
  38. package/dist/docx/server/build.js +14 -3
  39. package/dist/docx/server/createBilingualDocument.js +10 -9
  40. package/dist/docx/streamingXmlParser.d.ts +10 -1
  41. package/dist/docx/streamingXmlParser.js +88 -19
  42. package/dist/docx/unzip.d.ts +3 -1
  43. package/dist/docx/unzip.js +36 -16
  44. package/dist/layout-bridge/convert/fixedTableColumnWidths.d.ts +6 -0
  45. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +23 -0
  46. package/dist/layout-bridge/convert/tableConversion.js +4 -1
  47. package/dist/layout-painter/index.js +2 -5
  48. package/dist/paged-layout/editorScrollRoot.d.ts +15 -0
  49. package/dist/paged-layout/editorScrollRoot.js +72 -0
  50. package/dist/paged-layout/scrollToPmPosition.js +8 -22
  51. package/dist/prosemirror/commands/clearParagraphIndent.d.ts +6 -0
  52. package/dist/prosemirror/commands/clearParagraphIndent.js +25 -0
  53. package/dist/prosemirror/commentIdAllocator.d.ts +15 -22
  54. package/dist/prosemirror/commentIdAllocator.js +50 -25
  55. package/dist/prosemirror/extensions/core/HistoryExtension.js +97 -5
  56. package/dist/prosemirror/extensions/core/ParagraphExtension.js +3 -1
  57. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +22 -28
  58. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +8 -6
  59. package/dist/prosemirror/plugins/revisionIds.d.ts +23 -19
  60. package/dist/prosemirror/plugins/revisionIds.js +110 -29
  61. package/dist/prosemirror/plugins/suggestionMode.d.ts +2 -2
  62. package/dist/prosemirror/plugins/suggestionMode.js +196 -40
  63. package/dist/prosemirror/storyListNumbering.js +11 -9
  64. package/dist/prosemirror/textInput.d.ts +6 -1
  65. package/dist/prosemirror/textInput.js +9 -2
  66. package/dist/prosemirror/utils/visualLineNavigation.js +6 -8
  67. package/dist/utils/mergeDocumentContent.d.ts +2 -2
  68. package/dist/utils/mergeDocumentContent.js +11 -8
  69. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { createNumberingIdAllocator } from "../docx/numberingIds.js";
1
2
  import { getCachedNumberingMap, isBulletLevel } from "../docx/numberingParser.js";
2
3
  import { paragraphNumberingLevel, paragraphNumberingReference, paragraphNumberingReferenceId } from "../docx/numberingReference.js";
3
4
  import { expectParagraphAttrs } from "./attrs/index.js";
@@ -20,16 +21,11 @@ const remappedAbstractNumId = (abstractNumId, remap) => {
20
21
  if (abstractNumId === null || abstractNumId === void 0 || remap.baseAbstractNumIds.has(abstractNumId)) return abstractNumId;
21
22
  let next = remap.abstractNumIds.get(abstractNumId);
22
23
  if (next === void 0) {
23
- next = remap.nextAbstractNumId++;
24
+ next = remap.abstractIds.next();
24
25
  remap.abstractNumIds.set(abstractNumId, next);
25
26
  }
26
27
  return next;
27
28
  };
28
- const maxOf = (ids, floor) => {
29
- let max = floor;
30
- for (const id of ids) max = Math.max(max, id);
31
- return max;
32
- };
33
29
  /**
34
30
  * The story in `state` as it should be written into a package whose numbering
35
31
  * is now `numbering`, and that numbering completed with the story's lists.
@@ -41,10 +37,16 @@ const storyListNumbering = (state, numbering) => {
41
37
  const definedMap = numbering ? getCachedNumberingMap(numbering) : null;
42
38
  const referenced = /* @__PURE__ */ new Set();
43
39
  const colliding = /* @__PURE__ */ new Set();
40
+ const existingAbstractNumIds = /* @__PURE__ */ new Set([...(numbering?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId), ...(packageDefinitions?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId)]);
44
41
  state.doc.descendants((node) => {
45
42
  if (node.type.name !== "paragraph") return true;
46
43
  for (const numId of paragraphListReferences(node)) referenced.add(numId);
47
44
  const attrs = expectParagraphAttrs(node);
45
+ if (typeof attrs.listAbstractNumId === "number") existingAbstractNumIds.add(attrs.listAbstractNumId);
46
+ for (const change of attrs._propertyChanges ?? []) {
47
+ const abstractId = change.previousFormatting?.listAbstractNumId;
48
+ if (typeof abstractId === "number") existingAbstractNumIds.add(abstractId);
49
+ }
48
50
  const numId = paragraphNumberingReferenceId(attrs.numPr);
49
51
  if (numId !== void 0 && !storyBase.has(numId) && definedMap?.hasNumbering(numId)) {
50
52
  const level = definedMap.getLevel(numId, paragraphNumberingLevel(attrs.numPr) ?? 0);
@@ -56,12 +58,12 @@ const storyListNumbering = (state, numbering) => {
56
58
  doc: state.doc,
57
59
  numbering: completeNumberingForDoc(numbering, state.doc)
58
60
  };
59
- let nextNumId = maxOf([...defined, ...referenced], 0) + 1;
61
+ const numIds = createNumberingIdAllocator("num", [...defined, ...referenced]);
60
62
  const remap = {
61
- numIds: new Map([...colliding].map((numId) => [numId, nextNumId++])),
63
+ numIds: new Map([...colliding].map((numId) => [numId, numIds.next()])),
62
64
  baseAbstractNumIds: new Set((packageDefinitions?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId)),
63
65
  abstractNumIds: /* @__PURE__ */ new Map(),
64
- nextAbstractNumId: maxOf((numbering?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId), -1) + 1
66
+ abstractIds: createNumberingIdAllocator("abstract", existingAbstractNumIds)
65
67
  };
66
68
  const tr = new Transform(state.doc);
67
69
  state.doc.descendants((node, pos) => {
@@ -15,7 +15,12 @@ type TextInput = {
15
15
  declare const dispatchEditorTextInput: <TView extends TextInputDispatchTarget<TView>>(view: TView, input: string | TextInput) => void;
16
16
  /** Shared DOM boundary for editor runtimes and standalone suggestion views. */
17
17
  declare const handleEditorBeforeInput: (view: EditorView, event: InputEvent) => boolean;
18
+ /**
19
+ * Plugin compositionend handlers run before ProseMirror queues its final DOM
20
+ * flush. A second microtask runs after that flush and sees the committed state.
21
+ */
22
+ declare const afterNativeCompositionFlush: (callback: () => void) => void;
18
23
  /** Route committed text through the model before the browser mutates mark spans. */
19
24
  declare const createTextInputPlugin: () => Plugin<any>;
20
25
  //#endregion
21
- export { createTextInputPlugin, dispatchEditorTextInput, handleEditorBeforeInput };
26
+ export { afterNativeCompositionFlush, createTextInputPlugin, dispatchEditorTextInput, handleEditorBeforeInput };
@@ -45,6 +45,13 @@ const handleEditorBeforeInput = (view, event) => {
45
45
  });
46
46
  return true;
47
47
  };
48
+ /**
49
+ * Plugin compositionend handlers run before ProseMirror queues its final DOM
50
+ * flush. A second microtask runs after that flush and sees the committed state.
51
+ */
52
+ const afterNativeCompositionFlush = (callback) => {
53
+ queueMicrotask(() => queueMicrotask(callback));
54
+ };
48
55
  /** Route committed text through the model before the browser mutates mark spans. */
49
56
  const createTextInputPlugin = () => {
50
57
  const compositions = /* @__PURE__ */ new WeakMap();
@@ -55,7 +62,7 @@ const createTextInputPlugin = () => {
55
62
  },
56
63
  compositionend(view, event) {
57
64
  compositions.set(view, event);
58
- queueMicrotask(() => {
65
+ afterNativeCompositionFlush(() => {
59
66
  if (compositions.get(view) === event) compositions.delete(view);
60
67
  });
61
68
  return false;
@@ -67,4 +74,4 @@ const createTextInputPlugin = () => {
67
74
  } } });
68
75
  };
69
76
  //#endregion
70
- export { createTextInputPlugin, dispatchEditorTextInput, handleEditorBeforeInput };
77
+ export { afterNativeCompositionFlush, createTextInputPlugin, dispatchEditorTextInput, handleEditorBeforeInput };
@@ -1,7 +1,7 @@
1
1
  import { findCollapsedLineEdgeCaretTarget } from "../../layout-bridge/dom/clickToPositionDom.js";
2
2
  import { findBodyEmptyRuns, findBodyPmSpans } from "../../layout-bridge/dom/findBodyPmSpans.js";
3
3
  import { createTextStreamRange, descendantTextNodes, totalTextLength } from "../../layout-bridge/dom/textStreamDom.js";
4
- import { findVerticalScrollParent } from "../../utils/findVerticalScrollParent.js";
4
+ import { scrollEditorElementIntoView } from "../../paged-layout/editorScrollRoot.js";
5
5
  import { Selection, TextSelection } from "prosemirror-state";
6
6
  //#region src/prosemirror/utils/visualLineNavigation.ts
7
7
  /**
@@ -24,13 +24,11 @@ function createVisualLineState() {
24
24
  return { step: null };
25
25
  }
26
26
  function scrollIntoViewIfNeeded(el) {
27
- const container = findVerticalScrollParent(el);
28
- if (!container) return;
29
- const elRect = el.getBoundingClientRect();
30
- const containerRect = container.getBoundingClientRect();
31
- const margin = 40;
32
- if (elRect.bottom > containerRect.bottom - margin) container.scrollTop += elRect.bottom - containerRect.bottom + margin;
33
- else if (elRect.top < containerRect.top + margin) container.scrollTop -= containerRect.top - elRect.top + margin;
27
+ scrollEditorElementIntoView(el, {
28
+ block: "nearest",
29
+ margin: 40,
30
+ behavior: "instant"
31
+ });
34
32
  }
35
33
  /** @internal */
36
34
  function getCaretClientX(container, pmPos) {
@@ -9,8 +9,8 @@ import { document_d_exports } from "../types/document.js";
9
9
  * merging markdown (or any other document) into a styled preset keeps that
10
10
  * preset's look. Only `source`'s numbering — the `w:abstractNum`/`w:num`
11
11
  * definitions its content's `numPr` references — travels with it, and every
12
- * `abstractNumId`/`numId` it carries is renumbered to sit strictly above
13
- * whatever `target` already uses. This is unconditional (not just on a
12
+ * `abstractNumId`/`numId` it carries moves to a fresh bounded id, preferring
13
+ * ids above the loaded range. This is unconditional (not just on a
14
14
  * detected collision): it is simpler to reason about, and makes repeated
15
15
  * merges into the same target safe too (merging two sources that each mint
16
16
  * `numId` 1 does not collide with each other either).
@@ -1,3 +1,4 @@
1
+ import { createNumberingIdAllocator } from "../docx/numberingIds.js";
1
2
  import { paragraphNumberingReferenceId } from "../docx/numberingReference.js";
2
3
  import { cloneParagraphWithoutPropertySource } from "../docx/paragraphPropertySource.js";
3
4
  //#region src/utils/mergeDocumentContent.ts
@@ -10,8 +11,8 @@ import { cloneParagraphWithoutPropertySource } from "../docx/paragraphPropertySo
10
11
  * merging markdown (or any other document) into a styled preset keeps that
11
12
  * preset's look. Only `source`'s numbering — the `w:abstractNum`/`w:num`
12
13
  * definitions its content's `numPr` references — travels with it, and every
13
- * `abstractNumId`/`numId` it carries is renumbered to sit strictly above
14
- * whatever `target` already uses. This is unconditional (not just on a
14
+ * `abstractNumId`/`numId` it carries moves to a fresh bounded id, preferring
15
+ * ids above the loaded range. This is unconditional (not just on a
15
16
  * detected collision): it is simpler to reason about, and makes repeated
16
17
  * merges into the same target safe too (merging two sources that each mint
17
18
  * `numId` 1 does not collide with each other either).
@@ -53,11 +54,13 @@ function mergeDocumentContent(target, source) {
53
54
  }
54
55
  };
55
56
  function remapContentNumbering(content, numbering) {
56
- const abstractNumIdBase = Math.max(0, ...(targetNumbering?.abstractNums ?? []).map((abstractNum) => abstractNum.abstractNumId));
57
- const numIdBase = Math.max(0, ...(targetNumbering?.nums ?? []).map((num) => num.numId));
57
+ const existingAbstractIds = [...(targetNumbering?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId), ...numbering.abstractNums.map(({ abstractNumId }) => abstractNumId)];
58
+ const existingNumIds = [...(targetNumbering?.nums ?? []).map(({ numId }) => numId), ...numbering.nums.map(({ numId }) => numId)];
59
+ const abstractIds = createNumberingIdAllocator("abstract", existingAbstractIds);
60
+ const numIds = createNumberingIdAllocator("num", existingNumIds);
58
61
  const abstractNumIdRemap = /* @__PURE__ */ new Map();
59
- const remappedAbstractNums = numbering.abstractNums.map((abstractNum, index) => {
60
- const remappedAbstractNumId = abstractNumIdBase + index + 1;
62
+ const remappedAbstractNums = numbering.abstractNums.map((abstractNum) => {
63
+ const remappedAbstractNumId = abstractIds.next();
61
64
  abstractNumIdRemap.set(abstractNum.abstractNumId, remappedAbstractNumId);
62
65
  return {
63
66
  ...abstractNum,
@@ -65,8 +68,8 @@ function mergeDocumentContent(target, source) {
65
68
  };
66
69
  });
67
70
  const numIdRemap = /* @__PURE__ */ new Map();
68
- const remappedNums = numbering.nums.map((num, index) => {
69
- const remappedNumId = numIdBase + index + 1;
71
+ const remappedNums = numbering.nums.map((num) => {
72
+ const remappedNumId = numIds.next();
70
73
  numIdRemap.set(num.numId, remappedNumId);
71
74
  return {
72
75
  ...num,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-core",
3
- "version": "0.54.1",
3
+ "version": "0.54.2",
4
4
  "description": "Headless, framework-neutral core of folio: the OOXML (.docx) parser, document model, ProseMirror integration, and page-layout engine. No React.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -134,7 +134,7 @@
134
134
  "perf": "bun scripts/profile-editor.ts"
135
135
  },
136
136
  "dependencies": {
137
- "@stll/docx-core": "^0.30.0",
137
+ "@stll/docx-core": "^0.30.1",
138
138
  "@stll/docx-utils": "^0.1.0",
139
139
  "@stll/template-conditions": "^0.6.2",
140
140
  "better-result": "3.0.1",