@beyondwork/docx-react-component 1.0.57 → 1.0.59

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 (135) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -1
  3. package/src/api/awareness-identity-types.ts +4 -2
  4. package/src/api/comment-negotiation-types.ts +4 -1
  5. package/src/api/external-custody-types.ts +16 -0
  6. package/src/api/internal/build-ref-projections.ts +108 -0
  7. package/src/api/package-version.ts +1 -1
  8. package/src/api/participants-types.ts +11 -1
  9. package/src/api/public-types.ts +1149 -8
  10. package/src/api/scope-metadata-resolver-types.ts +6 -0
  11. package/src/compare/diff-engine.ts +3 -0
  12. package/src/core/commands/formatting-commands.ts +1 -0
  13. package/src/core/commands/index.ts +225 -16
  14. package/src/core/commands/legacy-form-field-commands.ts +181 -0
  15. package/src/core/commands/table-structure-commands.ts +149 -31
  16. package/src/core/selection/mapping.ts +20 -0
  17. package/src/core/state/editor-state.ts +2 -1
  18. package/src/index.ts +28 -0
  19. package/src/io/docx-session.ts +22 -3
  20. package/src/io/export/export-session.ts +11 -7
  21. package/src/io/export/ooxml-namespaces.ts +47 -0
  22. package/src/io/export/reattach-preserved-parts.ts +4 -16
  23. package/src/io/export/serialize-comments.ts +3 -131
  24. package/src/io/export/serialize-ffdata.ts +89 -0
  25. package/src/io/export/serialize-headers-footers.ts +5 -0
  26. package/src/io/export/serialize-main-document.ts +224 -34
  27. package/src/io/export/serialize-numbering.ts +22 -2
  28. package/src/io/export/serialize-revisions.ts +99 -0
  29. package/src/io/export/serialize-tables.ts +9 -0
  30. package/src/io/export/split-review-boundaries.ts +1 -0
  31. package/src/io/export/table-properties-xml.ts +14 -0
  32. package/src/io/load-scheduler.ts +70 -28
  33. package/src/io/normalize/normalize-text.ts +13 -0
  34. package/src/io/ooxml/_mini-xml.ts +198 -0
  35. package/src/io/ooxml/canonicalize-payload.ts +1 -4
  36. package/src/io/ooxml/chart/chart-style-table.ts +4 -3
  37. package/src/io/ooxml/chart/parse-chart-space.ts +2 -4
  38. package/src/io/ooxml/chart/parse-series.ts +2 -1
  39. package/src/io/ooxml/chart/resolve-color.ts +2 -2
  40. package/src/io/ooxml/chart/types.ts +6 -434
  41. package/src/io/ooxml/comment-presentation-payload.ts +6 -5
  42. package/src/io/ooxml/highlight-colors.ts +8 -5
  43. package/src/io/ooxml/parse-anchor.ts +68 -53
  44. package/src/io/ooxml/parse-comments.ts +14 -142
  45. package/src/io/ooxml/parse-complex-content.ts +3 -106
  46. package/src/io/ooxml/parse-drawing.ts +100 -195
  47. package/src/io/ooxml/parse-ffdata.ts +93 -0
  48. package/src/io/ooxml/parse-fields.ts +7 -146
  49. package/src/io/ooxml/parse-fill.ts +88 -8
  50. package/src/io/ooxml/parse-font-table.ts +5 -105
  51. package/src/io/ooxml/parse-footnotes.ts +28 -152
  52. package/src/io/ooxml/parse-headers-footers.ts +106 -212
  53. package/src/io/ooxml/parse-inline-media.ts +3 -200
  54. package/src/io/ooxml/parse-main-document.ts +180 -217
  55. package/src/io/ooxml/parse-numbering.ts +154 -335
  56. package/src/io/ooxml/parse-object.ts +147 -0
  57. package/src/io/ooxml/parse-ole-relationship.ts +82 -0
  58. package/src/io/ooxml/parse-paragraph-formatting.ts +7 -10
  59. package/src/io/ooxml/parse-picture-sdt.ts +85 -0
  60. package/src/io/ooxml/parse-picture.ts +120 -39
  61. package/src/io/ooxml/parse-revisions.ts +285 -51
  62. package/src/io/ooxml/parse-settings.ts +6 -99
  63. package/src/io/ooxml/parse-shapes.ts +25 -140
  64. package/src/io/ooxml/parse-styles.ts +3 -218
  65. package/src/io/ooxml/parse-tables.ts +76 -256
  66. package/src/io/ooxml/parse-theme.ts +1 -4
  67. package/src/io/ooxml/property-grab-bag.ts +5 -47
  68. package/src/io/ooxml/xml-element-serialize.ts +32 -0
  69. package/src/io/ooxml/xml-parser.ts +183 -0
  70. package/src/legal/bookmarks.ts +1 -1
  71. package/src/legal/cross-references.ts +1 -1
  72. package/src/legal/defined-terms.ts +1 -1
  73. package/src/legal/{_document-root.ts → document-root.ts} +8 -0
  74. package/src/legal/signature-blocks.ts +1 -1
  75. package/src/model/canonical-document.ts +165 -6
  76. package/src/model/chart-types.ts +439 -0
  77. package/src/model/snapshot.ts +3 -1
  78. package/src/review/store/comment-remapping.ts +24 -11
  79. package/src/review/store/revision-actions.ts +482 -2
  80. package/src/review/store/revision-store.ts +15 -0
  81. package/src/review/store/revision-types.ts +76 -0
  82. package/src/runtime/collab/remote-cursor-awareness.ts +24 -0
  83. package/src/runtime/collab/runtime-collab-sync.ts +33 -0
  84. package/src/runtime/diagnostics/build-diagnostic.ts +151 -0
  85. package/src/runtime/diagnostics/code-metadata-table.ts +221 -0
  86. package/src/runtime/document-runtime.ts +544 -35
  87. package/src/runtime/document-search.ts +176 -0
  88. package/src/runtime/edit-ops/index.ts +18 -2
  89. package/src/runtime/footnote-resolver.ts +130 -0
  90. package/src/runtime/layout/layout-engine-instance.ts +31 -4
  91. package/src/runtime/layout/layout-engine-version.ts +37 -1
  92. package/src/runtime/layout/page-graph.ts +14 -1
  93. package/src/runtime/layout/resolved-formatting-state.ts +21 -0
  94. package/src/runtime/numbering-prefix.ts +17 -0
  95. package/src/runtime/query-scopes.ts +183 -0
  96. package/src/runtime/resolved-numbering-geometry.ts +37 -6
  97. package/src/runtime/revision-runtime.ts +27 -1
  98. package/src/runtime/scope-resolver.ts +60 -0
  99. package/src/runtime/selection/post-edit-validator.ts +60 -6
  100. package/src/runtime/structure-ops/index.ts +20 -4
  101. package/src/runtime/surface-projection.ts +293 -18
  102. package/src/runtime/table-schema.ts +6 -0
  103. package/src/runtime/theme-color-resolver.ts +2 -2
  104. package/src/runtime/units.ts +9 -0
  105. package/src/runtime/workflow-rail-segments.ts +4 -0
  106. package/src/ui/WordReviewEditor.tsx +258 -44
  107. package/src/ui/editor-runtime-boundary.ts +13 -0
  108. package/src/ui/editor-shell-view.tsx +4 -1
  109. package/src/ui/headless/chrome-registry.ts +53 -0
  110. package/src/ui/headless/selection-tool-resolver.ts +11 -1
  111. package/src/ui-tailwind/chrome/chrome-preset-model.ts +13 -0
  112. package/src/ui-tailwind/chrome/tw-command-palette-mount.tsx +96 -0
  113. package/src/ui-tailwind/chrome/tw-context-menu.tsx +2 -1
  114. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +5 -4
  115. package/src/ui-tailwind/chrome/tw-mode-dock.tsx +6 -2
  116. package/src/ui-tailwind/chrome/use-container-breakpoint.ts +111 -0
  117. package/src/ui-tailwind/chrome-overlay/tw-chrome-overlay.tsx +23 -9
  118. package/src/ui-tailwind/chrome-overlay/tw-object-selection-overlay.tsx +158 -0
  119. package/src/ui-tailwind/chrome-overlay/tw-page-stack-overlay-layer.tsx +6 -7
  120. package/src/ui-tailwind/editor-surface/pm-schema.ts +105 -17
  121. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +13 -0
  122. package/src/ui-tailwind/editor-surface/shape-renderer.ts +76 -14
  123. package/src/ui-tailwind/editor-surface/tw-page-block-view.helpers.ts +18 -1
  124. package/src/ui-tailwind/editor-surface/tw-page-block-view.tsx +2 -0
  125. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +18 -2
  126. package/src/ui-tailwind/index.ts +9 -0
  127. package/src/ui-tailwind/page-chrome-model.ts +77 -5
  128. package/src/ui-tailwind/page-stack/tw-page-stack-chrome-layer.tsx +56 -1
  129. package/src/ui-tailwind/page-stack/tw-region-block-renderer.tsx +2 -0
  130. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +116 -113
  131. package/src/ui-tailwind/review/tw-review-rail-footer.tsx +2 -2
  132. package/src/ui-tailwind/theme/tokens.ts +14 -0
  133. package/src/ui-tailwind/toolbar/tw-shell-header.tsx +5 -0
  134. package/src/ui-tailwind/tw-review-workspace.tsx +52 -87
  135. package/src/validation/diagnostics.ts +1 -0
@@ -1,5 +1,7 @@
1
1
  import type { OpcRelationship } from "./part-manifest.ts";
2
2
  import { normalizePartPath, resolveRelationshipTarget } from "./part-manifest.ts";
3
+ import { parseXml } from "./xml-parser.ts";
4
+ import { localName } from "./xml-attr-helpers.ts";
3
5
 
4
6
  export interface InlineMediaPart {
5
7
  path: string;
@@ -35,19 +37,7 @@ export interface ParsedInlineMedia {
35
37
  };
36
38
  }
37
39
 
38
- interface XmlElementNode {
39
- type: "element";
40
- name: string;
41
- attributes: Record<string, string>;
42
- children: XmlNode[];
43
- }
44
-
45
- interface XmlTextNode {
46
- type: "text";
47
- text: string;
48
- }
49
-
50
- type XmlNode = XmlElementNode | XmlTextNode;
40
+ import type { XmlElementNode } from "./xml-element.ts";
51
41
 
52
42
  export function parseInlineMediaXml(
53
43
  xml: string,
@@ -246,10 +236,6 @@ function findDescendants(node: XmlElementNode, local: string): XmlElementNode[]
246
236
  return results;
247
237
  }
248
238
 
249
- function localName(name: string): string {
250
- const separatorIndex = name.indexOf(":");
251
- return separatorIndex >= 0 ? name.slice(separatorIndex + 1) : name;
252
- }
253
239
 
254
240
  function extractText(node: XmlElementNode): string {
255
241
  return node.children.map((child) => child.type === "text" ? child.text : extractText(child)).join("");
@@ -276,186 +262,3 @@ function readBooleanAttribute(node: XmlElementNode, name: string): boolean | und
276
262
  return value !== "0" && value !== "false" && value !== "off";
277
263
  }
278
264
 
279
- function parseXml(xml: string): XmlElementNode {
280
- const root: XmlElementNode = {
281
- type: "element",
282
- name: "__root__",
283
- attributes: {},
284
- children: [],
285
- };
286
- const stack: XmlElementNode[] = [root];
287
- let cursor = 0;
288
-
289
- while (cursor < xml.length) {
290
- if (xml.startsWith("<!--", cursor)) {
291
- const end = xml.indexOf("-->", cursor);
292
- cursor = end >= 0 ? end + 3 : xml.length;
293
- continue;
294
- }
295
-
296
- if (xml.startsWith("<?", cursor)) {
297
- const end = xml.indexOf("?>", cursor);
298
- cursor = end >= 0 ? end + 2 : xml.length;
299
- continue;
300
- }
301
-
302
- if (xml[cursor] !== "<") {
303
- const nextTag = xml.indexOf("<", cursor);
304
- const end = nextTag >= 0 ? nextTag : xml.length;
305
- const text = decodeXmlEntities(xml.slice(cursor, end));
306
- if (text.length > 0) {
307
- stack[stack.length - 1]?.children.push({ type: "text", text });
308
- }
309
- cursor = end;
310
- continue;
311
- }
312
-
313
- if (xml[cursor + 1] === "/") {
314
- const end = xml.indexOf(">", cursor);
315
- const current = stack.pop();
316
- const name = xml.slice(cursor + 2, end).trim();
317
- if (!current || localName(current.name) !== localName(name)) {
318
- throw new Error(`Malformed XML: unexpected closing tag </${name}>.`);
319
- }
320
- cursor = end + 1;
321
- continue;
322
- }
323
-
324
- const tagEnd = findTagEnd(xml, cursor);
325
- const tagBody = xml.slice(cursor + 1, tagEnd);
326
- const selfClosing = /\/\s*$/.test(tagBody);
327
- const { name, attributes } = parseTag(tagBody.replace(/\/\s*$/, "").trim());
328
- const element: XmlElementNode = {
329
- type: "element",
330
- name,
331
- attributes,
332
- children: [],
333
- };
334
- stack[stack.length - 1]?.children.push(element);
335
-
336
- if (!selfClosing) {
337
- stack.push(element);
338
- }
339
-
340
- cursor = tagEnd + 1;
341
- }
342
-
343
- if (stack.length !== 1) {
344
- throw new Error("Malformed XML: unclosed element.");
345
- }
346
-
347
- return root;
348
- }
349
-
350
- function parseTag(tagBody: string): { name: string; attributes: Record<string, string> } {
351
- let cursor = 0;
352
- while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
353
- cursor += 1;
354
- }
355
-
356
- const nameStart = cursor;
357
- while (cursor < tagBody.length && !/\s/.test(tagBody[cursor] ?? "")) {
358
- cursor += 1;
359
- }
360
- const name = tagBody.slice(nameStart, cursor);
361
- const attributes: Record<string, string> = {};
362
-
363
- while (cursor < tagBody.length) {
364
- while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
365
- cursor += 1;
366
- }
367
- if (cursor >= tagBody.length) {
368
- break;
369
- }
370
-
371
- const keyStart = cursor;
372
- while (cursor < tagBody.length && !/[\s=]/.test(tagBody[cursor] ?? "")) {
373
- cursor += 1;
374
- }
375
- const key = tagBody.slice(keyStart, cursor);
376
-
377
- while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
378
- cursor += 1;
379
- }
380
-
381
- if (tagBody[cursor] !== "=") {
382
- attributes[key] = "";
383
- continue;
384
- }
385
- cursor += 1;
386
-
387
- while (cursor < tagBody.length && /\s/.test(tagBody[cursor] ?? "")) {
388
- cursor += 1;
389
- }
390
-
391
- const quote = tagBody[cursor];
392
- if (quote !== `"` && quote !== `'`) {
393
- throw new Error(`Malformed XML attribute ${key}.`);
394
- }
395
- cursor += 1;
396
-
397
- const valueStart = cursor;
398
- while (cursor < tagBody.length && tagBody[cursor] !== quote) {
399
- cursor += 1;
400
- }
401
- attributes[key] = decodeXmlEntities(tagBody.slice(valueStart, cursor));
402
- cursor += 1;
403
- }
404
-
405
- return { name, attributes };
406
- }
407
-
408
- function findTagEnd(xml: string, start: number): number {
409
- let cursor = start + 1;
410
- let quote: string | null = null;
411
-
412
- while (cursor < xml.length) {
413
- const current = xml[cursor];
414
- if (quote) {
415
- if (current === quote) {
416
- quote = null;
417
- }
418
- cursor += 1;
419
- continue;
420
- }
421
-
422
- if (current === `"` || current === `'`) {
423
- quote = current;
424
- cursor += 1;
425
- continue;
426
- }
427
-
428
- if (current === ">") {
429
- return cursor;
430
- }
431
-
432
- cursor += 1;
433
- }
434
-
435
- throw new Error("Malformed XML: missing >.");
436
- }
437
-
438
- function decodeXmlEntities(value: string): string {
439
- return value.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
440
- switch (entity) {
441
- case "amp":
442
- return "&";
443
- case "lt":
444
- return "<";
445
- case "gt":
446
- return ">";
447
- case "quot":
448
- return `"`;
449
- case "apos":
450
- return "'";
451
- default:
452
- if (entity.startsWith("#x")) {
453
- return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
454
- }
455
- if (entity.startsWith("#")) {
456
- return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
457
- }
458
- return match;
459
- }
460
- });
461
- }