@arbidocs/blocks 0.5.115 → 0.5.117

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 (147) hide show
  1. package/dist/{ConnectedCallDock-WER7R222.cjs → ConnectedCallDock-OZBTU3IT.cjs} +20 -20
  2. package/dist/{ConnectedCallDock-WER7R222.cjs.map → ConnectedCallDock-OZBTU3IT.cjs.map} +1 -1
  3. package/dist/{ConnectedCallRoom-T7OBQTYP.cjs → ConnectedCallRoom-VMZE2NFP.cjs} +13 -13
  4. package/dist/{ConnectedCallRoom-T7OBQTYP.cjs.map → ConnectedCallRoom-VMZE2NFP.cjs.map} +1 -1
  5. package/dist/{ConnectedNativeDocxComparison-YXMYJWXY.cjs → ConnectedNativeDocxComparison-7OUKTKYP.cjs} +20 -20
  6. package/dist/{ConnectedNativeDocxComparison-YXMYJWXY.cjs.map → ConnectedNativeDocxComparison-7OUKTKYP.cjs.map} +1 -1
  7. package/dist/{ConnectedProductionSetDialog-LHB4VQWC.cjs → ConnectedProductionSetDialog-4EAY6KAZ.cjs} +3 -3
  8. package/dist/{ConnectedProductionSetDialog-LHB4VQWC.cjs.map → ConnectedProductionSetDialog-4EAY6KAZ.cjs.map} +1 -1
  9. package/dist/{ConnectedStreamedWordArtifact-2RTCHVPI.cjs → ConnectedStreamedWordArtifact-7V24ZDAC.cjs} +20 -20
  10. package/dist/{ConnectedStreamedWordArtifact-2RTCHVPI.cjs.map → ConnectedStreamedWordArtifact-7V24ZDAC.cjs.map} +1 -1
  11. package/dist/{DocumentReviewCard-ZSBZBGFK.cjs → DocumentReviewCard-OCPFVMLD.cjs} +15 -15
  12. package/dist/{DocumentReviewCard-ZSBZBGFK.cjs.map → DocumentReviewCard-OCPFVMLD.cjs.map} +1 -1
  13. package/dist/{FilesViewerDialog-I5QIHQZT.cjs → FilesViewerDialog-KLRDIYEH.cjs} +45 -45
  14. package/dist/{FilesViewerDialog-I5QIHQZT.cjs.map → FilesViewerDialog-KLRDIYEH.cjs.map} +1 -1
  15. package/dist/{NativeDocxEditor-H6TAEVGY.cjs → NativeDocxEditor-2LQY2CTV.cjs} +6 -6
  16. package/dist/{NativeDocxEditor-H6TAEVGY.cjs.map → NativeDocxEditor-2LQY2CTV.cjs.map} +1 -1
  17. package/dist/{WorkspaceTableView-J3C6VH4T.cjs → WorkspaceTableView-IMAZICIZ.cjs} +8 -8
  18. package/dist/{WorkspaceTableView-J3C6VH4T.cjs.map → WorkspaceTableView-IMAZICIZ.cjs.map} +1 -1
  19. package/dist/agents/index.cjs +297 -297
  20. package/dist/{ai-IM4A23YT.cjs → ai-7U4B4CVF.cjs} +24 -24
  21. package/dist/ai-7U4B4CVF.cjs.map +1 -0
  22. package/dist/calls/index.cjs +121 -121
  23. package/dist/chat/index.cjs +1 -1
  24. package/dist/{chunk-M6IKVKU5.cjs → chunk-2CSLFAGF.cjs} +392 -149
  25. package/dist/chunk-2CSLFAGF.cjs.map +1 -0
  26. package/dist/{chunk-SGYSDABK.cjs → chunk-2W5E62EY.cjs} +6 -6
  27. package/dist/{chunk-SGYSDABK.cjs.map → chunk-2W5E62EY.cjs.map} +1 -1
  28. package/dist/{chunk-P77YTTJ3.cjs → chunk-3ODEWSRO.cjs} +4 -4
  29. package/dist/{chunk-P77YTTJ3.cjs.map → chunk-3ODEWSRO.cjs.map} +1 -1
  30. package/dist/{chunk-DDIW4HLU.cjs → chunk-3U36VYMD.cjs} +27 -27
  31. package/dist/{chunk-DDIW4HLU.cjs.map → chunk-3U36VYMD.cjs.map} +1 -1
  32. package/dist/{chunk-TP5PGWIO.cjs → chunk-4IOYQLKG.cjs} +3 -3
  33. package/dist/{chunk-TP5PGWIO.cjs.map → chunk-4IOYQLKG.cjs.map} +1 -1
  34. package/dist/{chunk-NY3YUCOW.cjs → chunk-4NPCDS2X.cjs} +3 -3
  35. package/dist/{chunk-NY3YUCOW.cjs.map → chunk-4NPCDS2X.cjs.map} +1 -1
  36. package/dist/{chunk-BQ5RIWWT.cjs → chunk-4VZZWYEC.cjs} +3 -3
  37. package/dist/{chunk-BQ5RIWWT.cjs.map → chunk-4VZZWYEC.cjs.map} +1 -1
  38. package/dist/{chunk-Y24V6HPR.cjs → chunk-57EE6CMW.cjs} +15 -15
  39. package/dist/{chunk-Y24V6HPR.cjs.map → chunk-57EE6CMW.cjs.map} +1 -1
  40. package/dist/{chunk-NNUK5ZM7.cjs → chunk-5QUL5BZO.cjs} +4 -4
  41. package/dist/{chunk-NNUK5ZM7.cjs.map → chunk-5QUL5BZO.cjs.map} +1 -1
  42. package/dist/{chunk-OEREKAAP.cjs → chunk-6DCIZA3X.cjs} +75 -75
  43. package/dist/{chunk-OEREKAAP.cjs.map → chunk-6DCIZA3X.cjs.map} +1 -1
  44. package/dist/{chunk-YGXOKB5Z.cjs → chunk-7TEUGFIL.cjs} +4 -4
  45. package/dist/{chunk-YGXOKB5Z.cjs.map → chunk-7TEUGFIL.cjs.map} +1 -1
  46. package/dist/{chunk-TT4IF52H.cjs → chunk-7X3FS5HQ.cjs} +35 -35
  47. package/dist/{chunk-TT4IF52H.cjs.map → chunk-7X3FS5HQ.cjs.map} +1 -1
  48. package/dist/{chunk-CPR6EHG7.cjs → chunk-7XT5B2DZ.cjs} +47 -47
  49. package/dist/{chunk-CPR6EHG7.cjs.map → chunk-7XT5B2DZ.cjs.map} +1 -1
  50. package/dist/chunk-BKY2LAV2.cjs +18 -0
  51. package/dist/{chunk-CIHERNDO.cjs.map → chunk-BKY2LAV2.cjs.map} +1 -1
  52. package/dist/{chunk-XKVPSOKP.cjs → chunk-BW5MF464.cjs} +4 -4
  53. package/dist/{chunk-XKVPSOKP.cjs.map → chunk-BW5MF464.cjs.map} +1 -1
  54. package/dist/{chunk-IW7CDJTA.cjs → chunk-COD5ENHK.cjs} +4 -4
  55. package/dist/{chunk-IW7CDJTA.cjs.map → chunk-COD5ENHK.cjs.map} +1 -1
  56. package/dist/{chunk-A3T3IC3K.cjs → chunk-D7ICHGWM.cjs} +239 -85
  57. package/dist/chunk-D7ICHGWM.cjs.map +1 -0
  58. package/dist/{chunk-TDO5UWXF.cjs → chunk-E4BLRF2L.cjs} +5 -5
  59. package/dist/{chunk-TDO5UWXF.cjs.map → chunk-E4BLRF2L.cjs.map} +1 -1
  60. package/dist/{chunk-WR2SF44W.cjs → chunk-E4DUXU5K.cjs} +9 -9
  61. package/dist/{chunk-WR2SF44W.cjs.map → chunk-E4DUXU5K.cjs.map} +1 -1
  62. package/dist/{chunk-WAV762GP.cjs → chunk-GQXPNIRE.cjs} +6 -6
  63. package/dist/{chunk-WAV762GP.cjs.map → chunk-GQXPNIRE.cjs.map} +1 -1
  64. package/dist/{chunk-7OPOPYV6.cjs → chunk-H5OLHP2U.cjs} +3 -3
  65. package/dist/{chunk-7OPOPYV6.cjs.map → chunk-H5OLHP2U.cjs.map} +1 -1
  66. package/dist/{chunk-6UTKM5AB.cjs → chunk-JSQQV23D.cjs} +3 -3
  67. package/dist/{chunk-6UTKM5AB.cjs.map → chunk-JSQQV23D.cjs.map} +1 -1
  68. package/dist/{chunk-557MJ4IH.cjs → chunk-LFRNBT2I.cjs} +20 -20
  69. package/dist/{chunk-557MJ4IH.cjs.map → chunk-LFRNBT2I.cjs.map} +1 -1
  70. package/dist/{chunk-R7CJEIA5.cjs → chunk-LYTIQQQ2.cjs} +3 -3
  71. package/dist/{chunk-R7CJEIA5.cjs.map → chunk-LYTIQQQ2.cjs.map} +1 -1
  72. package/dist/{chunk-CPG7II4E.cjs → chunk-MC4F2URI.cjs} +28 -28
  73. package/dist/{chunk-CPG7II4E.cjs.map → chunk-MC4F2URI.cjs.map} +1 -1
  74. package/dist/{chunk-WXUU3COI.cjs → chunk-MZ2KZXNU.cjs} +3 -3
  75. package/dist/{chunk-WXUU3COI.cjs.map → chunk-MZ2KZXNU.cjs.map} +1 -1
  76. package/dist/{chunk-ZTXQIIFV.cjs → chunk-OZVDOAXG.cjs} +6 -6
  77. package/dist/{chunk-ZTXQIIFV.cjs.map → chunk-OZVDOAXG.cjs.map} +1 -1
  78. package/dist/{chunk-325GVZE6.cjs → chunk-Q6DQGGP4.cjs} +3 -3
  79. package/dist/{chunk-325GVZE6.cjs.map → chunk-Q6DQGGP4.cjs.map} +1 -1
  80. package/dist/{chunk-KTQOGT2L.cjs → chunk-TDN33HSK.cjs} +6 -6
  81. package/dist/{chunk-KTQOGT2L.cjs.map → chunk-TDN33HSK.cjs.map} +1 -1
  82. package/dist/{chunk-T23UTIRI.cjs → chunk-UNDQYTRF.cjs} +6 -6
  83. package/dist/{chunk-T23UTIRI.cjs.map → chunk-UNDQYTRF.cjs.map} +1 -1
  84. package/dist/{chunk-KXIRVKCJ.cjs → chunk-UUENH4BJ.cjs} +3 -3
  85. package/dist/{chunk-KXIRVKCJ.cjs.map → chunk-UUENH4BJ.cjs.map} +1 -1
  86. package/dist/{chunk-24EDG4PC.cjs → chunk-VBL3SHWX.cjs} +50 -50
  87. package/dist/{chunk-24EDG4PC.cjs.map → chunk-VBL3SHWX.cjs.map} +1 -1
  88. package/dist/{chunk-3A7QWUAW.cjs → chunk-VKH3BEZE.cjs} +3 -3
  89. package/dist/{chunk-3A7QWUAW.cjs.map → chunk-VKH3BEZE.cjs.map} +1 -1
  90. package/dist/{chunk-X5LANJDZ.cjs → chunk-VTYJAZDU.cjs} +23 -15
  91. package/dist/chunk-VTYJAZDU.cjs.map +1 -0
  92. package/dist/{chunk-B3LZITVF.cjs → chunk-WW6LXQY6.cjs} +12 -12
  93. package/dist/{chunk-B3LZITVF.cjs.map → chunk-WW6LXQY6.cjs.map} +1 -1
  94. package/dist/{chunk-NJCK6V6U.cjs → chunk-XKDUPU7B.cjs} +4 -4
  95. package/dist/{chunk-NJCK6V6U.cjs.map → chunk-XKDUPU7B.cjs.map} +1 -1
  96. package/dist/{chunk-42TURFHF.cjs → chunk-YGBHY67W.cjs} +5 -5
  97. package/dist/{chunk-42TURFHF.cjs.map → chunk-YGBHY67W.cjs.map} +1 -1
  98. package/dist/connect/docx.cjs +24 -24
  99. package/dist/connect/index.cjs +983 -983
  100. package/dist/connect/viewer.cjs +34 -34
  101. package/dist/connection/docx/ConnectedNativeDocxEditor.js +10 -2
  102. package/dist/connection/docx/ConnectedNativeDocxEditor.js.map +2 -2
  103. package/dist/connection/viewer/ConnectedDocumentViewer.js +124 -21
  104. package/dist/connection/viewer/ConnectedDocumentViewer.js.map +2 -2
  105. package/dist/connection/viewer/VersionDropdown.d.ts +9 -0
  106. package/dist/connection/viewer/VersionDropdown.js +39 -0
  107. package/dist/connection/viewer/VersionDropdown.js.map +7 -0
  108. package/dist/connection/viewer/ViewerPdfPane.js +4 -1
  109. package/dist/connection/viewer/ViewerPdfPane.js.map +2 -2
  110. package/dist/connection/viewer/useViewerBlobs.d.ts +3 -1
  111. package/dist/connection/viewer/useViewerBlobs.js +14 -8
  112. package/dist/connection/viewer/useViewerBlobs.js.map +2 -2
  113. package/dist/connection/viewer/useViewerTabs.js +10 -0
  114. package/dist/connection/viewer/useViewerTabs.js.map +2 -2
  115. package/dist/dashboards/index.cjs +1 -1
  116. package/dist/docx/DocxCommandMenu.d.ts +8 -0
  117. package/dist/docx/DocxCommandMenu.js +202 -0
  118. package/dist/docx/DocxCommandMenu.js.map +7 -0
  119. package/dist/docx/NativeDocxEditor.d.ts +4 -2
  120. package/dist/docx/NativeDocxEditor.js +51 -12
  121. package/dist/docx/NativeDocxEditor.js.map +2 -2
  122. package/dist/docx/RibbonMenu.d.ts +3 -1
  123. package/dist/docx/RibbonMenu.js +10 -3
  124. package/dist/docx/RibbonMenu.js.map +2 -2
  125. package/dist/docx/RibbonOverflow.d.ts +3 -0
  126. package/dist/docx/RibbonOverflow.js +24 -1
  127. package/dist/docx/RibbonOverflow.js.map +2 -2
  128. package/dist/docx/index.cjs +38 -38
  129. package/dist/docx/signatures/SignatureFields.d.ts +3 -1
  130. package/dist/docx/signatures/SignatureFields.js +17 -8
  131. package/dist/docx/signatures/SignatureFields.js.map +2 -2
  132. package/dist/embed/index.cjs +38 -38
  133. package/dist/files/index.cjs +224 -224
  134. package/dist/index.cjs +1590 -1590
  135. package/dist/settings/index.cjs +147 -147
  136. package/dist/shell/index.cjs +90 -90
  137. package/dist/studio/index.cjs +26 -26
  138. package/dist/styles.css +1 -1
  139. package/dist/workflow-canvas/index.cjs +55 -55
  140. package/node_modules/@arbidocs/coedit/package.json +1 -1
  141. package/package.json +5 -5
  142. package/src/docx/styles.css +94 -0
  143. package/dist/ai-IM4A23YT.cjs.map +0 -1
  144. package/dist/chunk-A3T3IC3K.cjs.map +0 -1
  145. package/dist/chunk-CIHERNDO.cjs +0 -18
  146. package/dist/chunk-M6IKVKU5.cjs.map +0 -1
  147. package/dist/chunk-X5LANJDZ.cjs.map +0 -1
@@ -2050,17 +2050,23 @@ function RibbonMenu({
2050
2050
  testId,
2051
2051
  title,
2052
2052
  keepMounted = false,
2053
- popoverClassName
2053
+ popoverClassName,
2054
+ restoreFocus = false
2054
2055
  }) {
2055
2056
  const [open, setOpen] = React4.useState(false);
2056
2057
  const element = React4.useRef(null);
2058
+ const trigger = React4.useRef(null);
2057
2059
  React4.useEffect(() => {
2058
2060
  if (!open) return;
2059
2061
  const dismiss = (event) => {
2060
2062
  if (!element.current?.contains(event.target)) setOpen(false);
2061
2063
  };
2062
2064
  const escape = (event) => {
2063
- if (event.key === "Escape") setOpen(false);
2065
+ if (event.key === "Escape") {
2066
+ if (restoreFocus && element.current?.contains(document.activeElement))
2067
+ trigger.current?.focus();
2068
+ setOpen(false);
2069
+ }
2064
2070
  };
2065
2071
  document.addEventListener("pointerdown", dismiss);
2066
2072
  document.addEventListener("keydown", escape);
@@ -2068,12 +2074,13 @@ function RibbonMenu({
2068
2074
  document.removeEventListener("pointerdown", dismiss);
2069
2075
  document.removeEventListener("keydown", escape);
2070
2076
  };
2071
- }, [open]);
2077
+ }, [open, restoreFocus]);
2072
2078
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-ribbon-menu", ref: element, children: [
2073
2079
  /* @__PURE__ */ jsxRuntime.jsx(
2074
2080
  "button",
2075
2081
  {
2076
2082
  type: "button",
2083
+ ref: trigger,
2077
2084
  className: ["native-docx-ribbon-trigger", className].filter(Boolean).join(" "),
2078
2085
  "aria-label": label,
2079
2086
  title: title ?? label,
@@ -2116,6 +2123,10 @@ function planOverflow(items, available, moreWidth) {
2116
2123
  return collapsed;
2117
2124
  }
2118
2125
  var Overflow = React4.createContext(null);
2126
+ var NamedCommands = React4.createContext(false);
2127
+ function NamedCommandList({ children }) {
2128
+ return /* @__PURE__ */ jsxRuntime.jsx(NamedCommands.Provider, { value: true, children });
2129
+ }
2119
2130
  var MORE_WIDTH = 32;
2120
2131
  var sameSet = (a, b) => a.size === b.size && [...a].every((id) => b.has(id));
2121
2132
  function RibbonOverflow({ tab, children }) {
@@ -2237,13 +2248,31 @@ function RibbonItem({
2237
2248
  children
2238
2249
  }) {
2239
2250
  const context = React4.useContext(Overflow);
2251
+ const named = React4.useContext(NamedCommands);
2240
2252
  const element = React4.useRef(null);
2241
2253
  const register = context?.register;
2242
2254
  React4.useLayoutEffect(() => {
2243
2255
  if (!register || !element.current) return;
2244
2256
  return register(id, { label, priority, element: element.current });
2245
2257
  }, [register, id, label, priority]);
2246
- if (!context) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2258
+ if (!context) {
2259
+ if (!named) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2260
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2261
+ "span",
2262
+ {
2263
+ className: "native-docx-command-item",
2264
+ "data-ribbon-item": id,
2265
+ onClick: (event) => {
2266
+ if (event.target.classList.contains("native-docx-command-label"))
2267
+ event.currentTarget.querySelector("button:not([disabled])")?.click();
2268
+ },
2269
+ children: [
2270
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "native-docx-command-control", children }),
2271
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "native-docx-command-label", children: label })
2272
+ ]
2273
+ }
2274
+ );
2275
+ }
2247
2276
  const collapsed = context.collapsed.has(id);
2248
2277
  const slot = context.slots[id];
2249
2278
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -4030,79 +4059,12 @@ function GenerateImageButton({ generation }) {
4030
4059
  }
4031
4060
  );
4032
4061
  }
4033
- var contains = (node, id) => node.id === id || (node.children ?? []).some((child) => contains(child, id));
4034
- function firstParagraph(node) {
4035
- for (const child of node.children ?? []) {
4036
- if (child.kind === "paragraph" && child.id) return child.id;
4037
- if (child.localName === "tbl") continue;
4038
- const nested = firstParagraph(child);
4039
- if (nested) return nested;
4040
- }
4041
- return null;
4042
- }
4043
- function tableCells(root, paragraphId) {
4044
- let table = null;
4045
- const find = (node) => {
4046
- if (node.localName === "tbl" && contains(node, paragraphId)) table = node;
4047
- for (const child of node.children ?? []) if (contains(child, paragraphId)) find(child);
4048
- };
4049
- find(root);
4050
- if (!table) return null;
4051
- const cells = [];
4052
- let index = -1;
4053
- const rows = (node) => (node.children ?? []).flatMap(
4054
- (child) => child.localName === "tr" ? [child] : child.localName === "tbl" ? [] : rows(child)
4055
- );
4056
- for (const row of rows(table))
4057
- for (const cell of (row.children ?? []).filter((child) => child.localName === "tc")) {
4058
- const first = firstParagraph(cell);
4059
- if (!first) continue;
4060
- if (contains(cell, paragraphId)) index = cells.length;
4061
- cells.push(first);
4062
- }
4063
- return index < 0 ? null : { cells, index };
4064
- }
4065
- function TableTabKeys({ scope }) {
4066
- const editor = react.useDocxEditor();
4067
- const latest = React4.useRef(editor);
4068
- latest.current = editor;
4069
- React4.useEffect(() => {
4070
- const element = scope.current;
4071
- if (!element) return;
4072
- const onKeyDown = (event) => {
4073
- if (event.key !== "Tab" || event.ctrlKey || event.metaKey || event.altKey) return;
4074
- const editor2 = latest.current;
4075
- const surface = editor2?.surface;
4076
- const head = surface?.state().selection?.head;
4077
- if (!editor2 || !surface || !head) return;
4078
- const root = () => surface.session.part().root;
4079
- const table = tableCells(root(), head.paragraphId);
4080
- if (!table) return;
4081
- event.preventDefault();
4082
- event.stopPropagation();
4083
- let target = table.cells[table.index + (event.shiftKey ? -1 : 1)];
4084
- if (!target && !event.shiftKey && editor2.exec({ type: "insertRow", where: "below" }).ok) {
4085
- const grown = tableCells(
4086
- root(),
4087
- surface.state().selection?.head.paragraphId ?? head.paragraphId
4088
- );
4089
- target = grown?.cells[table.cells.length] ?? "";
4090
- }
4091
- if (!target) return;
4092
- const point = { paragraphId: target, offset: 0 };
4093
- surface.setSelection({ anchor: point, head: point });
4094
- };
4095
- element.addEventListener("keydown", onKeyDown, true);
4096
- return () => element.removeEventListener("keydown", onKeyDown, true);
4097
- }, [scope]);
4098
- return null;
4099
- }
4100
4062
  function QuickParts() {
4101
4063
  const house = chunkGA5ZO4YA_cjs.useHouseTemplate();
4102
4064
  if (!house || house.blocks.length === 0) return null;
4103
- const categories = [...new Set(house.blocks.map((b) => b.category))];
4065
+ const categories2 = [...new Set(house.blocks.map((b) => b.category))];
4104
4066
  return /* @__PURE__ */ jsxRuntime.jsx(RibbonMenu, { label: "Quick Parts", icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Blocks, { size: 16 }), testId: "docx-quick-parts", children: (close) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-quick-parts", "data-testid": "docx-quick-parts-panel", children: [
4105
- categories.map((category) => /* @__PURE__ */ jsxRuntime.jsxs("section", { "aria-label": category, children: [
4067
+ categories2.map((category) => /* @__PURE__ */ jsxRuntime.jsxs("section", { "aria-label": category, children: [
4106
4068
  /* @__PURE__ */ jsxRuntime.jsx("h3", { children: category }),
4107
4069
  /* @__PURE__ */ jsxRuntime.jsx("ul", { children: house.blocks.filter((b) => b.category === category).map((block) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
4108
4070
  "button",
@@ -4127,6 +4089,65 @@ function QuickParts() {
4127
4089
  ] })
4128
4090
  ] }) });
4129
4091
  }
4092
+ var SOURCE = {
4093
+ workspace: "This workspace's house template",
4094
+ deployment: "The house template for all workspaces",
4095
+ builtin: "ARBI\u2019s built-in template (no house template has been set)"
4096
+ };
4097
+ function download(bytes, name) {
4098
+ const isTemplate = !/\.docx$/i.test(name);
4099
+ const url = URL.createObjectURL(
4100
+ new Blob([bytes], {
4101
+ type: isTemplate ? "application/vnd.openxmlformats-officedocument.wordprocessingml.template" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
4102
+ })
4103
+ );
4104
+ const a = document.createElement("a");
4105
+ a.href = url;
4106
+ a.download = /\.(dotx|docx)$/i.test(name) ? name : `${name}.dotx`;
4107
+ a.click();
4108
+ setTimeout(() => URL.revokeObjectURL(url), 5e3);
4109
+ }
4110
+ function HouseTemplatePanel() {
4111
+ const house = chunkGA5ZO4YA_cjs.useHouseTemplate();
4112
+ if (!house) return null;
4113
+ const summary = divergenceSummary(house.divergence);
4114
+ return /* @__PURE__ */ jsxRuntime.jsx(
4115
+ RibbonMenu,
4116
+ {
4117
+ label: "House template",
4118
+ className: "native-docx-style-trigger",
4119
+ testId: "docx-house-template",
4120
+ icon: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4121
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "native-docx-style-current", children: "House template" }),
4122
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { size: 12, "aria-hidden": true })
4123
+ ] }),
4124
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-house-template", "data-testid": "docx-house-template-panel", children: [
4125
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
4126
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: house.template.name }),
4127
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
4128
+ SOURCE[house.template.source],
4129
+ ". New documents start from it."
4130
+ ] }),
4131
+ /* @__PURE__ */ jsxRuntime.jsx("p", { "data-testid": "docx-house-template-status", children: house.divergence === null ? "Comparing this document\u2019s styles\u2026" : !house.basedOnTemplate ? "This document was not started from the house template." : summary ?? "This document\u2019s styles match the house template." }),
4132
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-house-template-actions", children: [
4133
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: () => download(house.template.bytes, house.template.name), children: [
4134
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { size: 14 }),
4135
+ " Download template"
4136
+ ] }),
4137
+ house.setAsHouseTemplate && /* @__PURE__ */ jsxRuntime.jsx(
4138
+ "button",
4139
+ {
4140
+ type: "button",
4141
+ "data-testid": "docx-set-house-template",
4142
+ onClick: () => void house.setAsHouseTemplate(),
4143
+ children: "Use this document as the house template"
4144
+ }
4145
+ )
4146
+ ] })
4147
+ ] })
4148
+ }
4149
+ );
4150
+ }
4130
4151
  var SignatureFieldsContext = React4.createContext(null);
4131
4152
  function SignatureFieldsProvider({
4132
4153
  signers,
@@ -4135,13 +4156,21 @@ function SignatureFieldsProvider({
4135
4156
  mySignature,
4136
4157
  children
4137
4158
  }) {
4159
+ const [pending, setPending] = React4.useState(null);
4138
4160
  return /* @__PURE__ */ jsxRuntime.jsxs(
4139
4161
  SignatureFieldsContext.Provider,
4140
4162
  {
4141
- value: signers || mySignature ? { fields: !!signers, signers: signers ?? [], editable, notify, mySignature } : null,
4163
+ value: signers || mySignature ? {
4164
+ fields: !!signers,
4165
+ signers: signers ?? [],
4166
+ editable,
4167
+ notify,
4168
+ mySignature,
4169
+ openAdopt: setPending
4170
+ } : null,
4142
4171
  children: [
4143
4172
  children,
4144
- mySignature && /* @__PURE__ */ jsxRuntime.jsx(MySignatureDialog, {})
4173
+ mySignature && /* @__PURE__ */ jsxRuntime.jsx(MySignatureDialog, { pending, setPending })
4145
4174
  ]
4146
4175
  }
4147
4176
  );
@@ -4168,12 +4197,12 @@ async function insertSavedMark(editor$1, saved, mark) {
4168
4197
  });
4169
4198
  if (!result.ok) throw new Error(result.reason || "The picture could not be inserted here.");
4170
4199
  }
4171
- var openAdopt = null;
4172
- function MySignatureDialog() {
4200
+ function MySignatureDialog({
4201
+ pending,
4202
+ setPending
4203
+ }) {
4173
4204
  const context = React4.useContext(SignatureFieldsContext);
4174
4205
  const editor = react.useDocxEditor();
4175
- const [pending, setPending] = React4.useState(null);
4176
- openAdopt = setPending;
4177
4206
  const mine = context?.mySignature;
4178
4207
  if (!mine) return null;
4179
4208
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -4207,7 +4236,7 @@ function useInsertMySignature() {
4207
4236
  return async (mark) => {
4208
4237
  try {
4209
4238
  const saved = await mine.load();
4210
- if (!saved) return openAdopt?.(mark);
4239
+ if (!saved) return context?.openAdopt(mark);
4211
4240
  await insertSavedMark(editor, saved, mark);
4212
4241
  } catch (failure) {
4213
4242
  context?.notify?.(
@@ -4331,7 +4360,7 @@ function insertSignatureField(editor, spec) {
4331
4360
  }
4332
4361
  return tag;
4333
4362
  }
4334
- function SignatureFieldMenu() {
4363
+ function SignatureFieldMenu({ onInserted } = {}) {
4335
4364
  const context = React4.useContext(SignatureFieldsContext);
4336
4365
  const editor = react.useDocxEditor();
4337
4366
  const [kind, setKind] = React4.useState("signature");
@@ -4355,6 +4384,7 @@ function SignatureFieldMenu() {
4355
4384
  required
4356
4385
  });
4357
4386
  close();
4387
+ onInserted?.();
4358
4388
  setEmail("");
4359
4389
  setName("");
4360
4390
  } catch (failure) {
@@ -4467,65 +4497,240 @@ function SignatureFieldMenu() {
4467
4497
  }
4468
4498
  );
4469
4499
  }
4470
- var SOURCE = {
4471
- workspace: "This workspace's house template",
4472
- deployment: "The house template for all workspaces",
4473
- builtin: "ARBI\u2019s built-in template (no house template has been set)"
4474
- };
4475
- function download(bytes, name) {
4476
- const isTemplate = !/\.docx$/i.test(name);
4477
- const url = URL.createObjectURL(
4478
- new Blob([bytes], {
4479
- type: isTemplate ? "application/vnd.openxmlformats-officedocument.wordprocessingml.template" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
4480
- })
4481
- );
4482
- const a = document.createElement("a");
4483
- a.href = url;
4484
- a.download = /\.(dotx|docx)$/i.test(name) ? name : `${name}.dotx`;
4485
- a.click();
4486
- setTimeout(() => URL.revokeObjectURL(url), 5e3);
4487
- }
4488
- function HouseTemplatePanel() {
4489
- const house = chunkGA5ZO4YA_cjs.useHouseTemplate();
4490
- if (!house) return null;
4491
- const summary = divergenceSummary(house.divergence);
4500
+ function DefinedTermButton() {
4501
+ const terms = useDefinedTerms();
4502
+ if (!terms) return null;
4492
4503
  return /* @__PURE__ */ jsxRuntime.jsx(
4493
- RibbonMenu,
4504
+ "button",
4494
4505
  {
4495
- label: "House template",
4496
- className: "native-docx-style-trigger",
4497
- testId: "docx-house-template",
4498
- icon: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4499
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "native-docx-style-current", children: "House template" }),
4500
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { size: 12, "aria-hidden": true })
4501
- ] }),
4502
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-house-template", "data-testid": "docx-house-template-panel", children: [
4503
- /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
4504
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: house.template.name }),
4505
- /* @__PURE__ */ jsxRuntime.jsx("br", {}),
4506
- SOURCE[house.template.source],
4507
- ". New documents start from it."
4508
- ] }),
4509
- /* @__PURE__ */ jsxRuntime.jsx("p", { "data-testid": "docx-house-template-status", children: house.divergence === null ? "Comparing this document\u2019s styles\u2026" : !house.basedOnTemplate ? "This document was not started from the house template." : summary ?? "This document\u2019s styles match the house template." }),
4510
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-house-template-actions", children: [
4511
- /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: () => download(house.template.bytes, house.template.name), children: [
4512
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { size: 14 }),
4513
- " Download template"
4514
- ] }),
4515
- house.setAsHouseTemplate && /* @__PURE__ */ jsxRuntime.jsx(
4516
- "button",
4517
- {
4518
- type: "button",
4519
- "data-testid": "docx-set-house-template",
4520
- onClick: () => void house.setAsHouseTemplate(),
4521
- children: "Use this document as the house template"
4522
- }
4523
- )
4524
- ] })
4525
- ] })
4506
+ type: "button",
4507
+ className: "native-docx-ribbon-trigger",
4508
+ "aria-label": terms.labels.insert,
4509
+ title: `${terms.labels.insert} (type @@)`,
4510
+ "data-testid": "docx-insert-defined-term",
4511
+ onMouseDown: (event) => event.preventDefault(),
4512
+ onClick: (event) => terms.openPicker(event.currentTarget),
4513
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.BookA, { size: 16 })
4526
4514
  }
4527
4515
  );
4528
4516
  }
4517
+ var categories = [
4518
+ { name: "Home", icon: lucideReact.Home },
4519
+ { name: "Insert", icon: lucideReact.Plus },
4520
+ { name: "Design", icon: lucideReact.FilePenLine },
4521
+ { name: LAYOUT_TAB, icon: lucideReact.LayoutGrid },
4522
+ { name: "References", icon: lucideReact.BookA },
4523
+ { name: "Review", icon: lucideReact.ListChecks }
4524
+ ];
4525
+ function DocxCommandMenu({
4526
+ onSave,
4527
+ badge,
4528
+ imageGeneration
4529
+ }) {
4530
+ const [selected, setSelected] = React4.useState("Home");
4531
+ const contextual = useContextualTabs(selected);
4532
+ const tab = contextual.shown;
4533
+ const t = react.useChromeTranslate();
4534
+ useGenerateImageTarget();
4535
+ const allCategories = [
4536
+ ...categories,
4537
+ ...contextual.tabs.map((name) => ({ name, icon: name === "Table" ? lucideReact.Table : lucideReact.Image }))
4538
+ ];
4539
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-ribbon native-docx-command-menu", children: [
4540
+ /* @__PURE__ */ jsxRuntime.jsxs(react.DocxEditor.Toolbar, { t, preset: false, onSave, children: [
4541
+ /* @__PURE__ */ jsxRuntime.jsx(
4542
+ RibbonMenu,
4543
+ {
4544
+ label: "Editing tools",
4545
+ icon: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4546
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Menu, { size: 16 }),
4547
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Editing tools" }),
4548
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { size: 14 })
4549
+ ] }),
4550
+ className: "native-docx-command-trigger",
4551
+ popoverClassName: "native-docx-command-panel",
4552
+ keepMounted: true,
4553
+ restoreFocus: true,
4554
+ children: (close) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-command-layout", children: [
4555
+ /* @__PURE__ */ jsxRuntime.jsx("nav", { className: "native-docx-command-categories", "aria-label": "Editing tool categories", children: allCategories.map(({ name, icon: Icon }) => /* @__PURE__ */ jsxRuntime.jsxs(
4556
+ "button",
4557
+ {
4558
+ type: "button",
4559
+ "aria-pressed": tab === name,
4560
+ onClick: () => setSelected(name),
4561
+ children: [
4562
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 16, "aria-hidden": "true" }),
4563
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: name })
4564
+ ]
4565
+ },
4566
+ name
4567
+ )) }),
4568
+ /* @__PURE__ */ jsxRuntime.jsx(
4569
+ "div",
4570
+ {
4571
+ className: "native-docx-command-list",
4572
+ role: "group",
4573
+ "aria-label": `${tab} commands`,
4574
+ onClick: (event) => {
4575
+ const target = event.target;
4576
+ const button = target.closest("button");
4577
+ const item = target.closest("[data-ribbon-item]")?.dataset.ribbonItem;
4578
+ const direct = /* @__PURE__ */ new Set([
4579
+ "home-undo",
4580
+ "home-redo",
4581
+ "home-save",
4582
+ "home-bold",
4583
+ "home-italic",
4584
+ "home-underline",
4585
+ "home-bullets",
4586
+ "home-numbers",
4587
+ "home-indent",
4588
+ "home-outdent",
4589
+ "home-strike",
4590
+ "home-clear",
4591
+ "references-footnote",
4592
+ "references-endnote",
4593
+ "references-update-cross-references",
4594
+ "table-row-above",
4595
+ "table-row-below",
4596
+ "table-column-left",
4597
+ "table-column-right"
4598
+ ]);
4599
+ if ((!button || !button.disabled) && target.closest('[aria-disabled="true"]') === null && (button && item && direct.has(item) || target.closest('[role="gridcell"]') || target.closest('[role="menuitemradio"]') || target.closest('[data-testid="docx-insert-my-signature"]') || target.closest('[data-testid="docx-insert-my-initials"]') || target.closest('.native-docx-style-gallery [role="option"]') || button && button.closest(".native-docx-style-gallery"))) {
4600
+ close();
4601
+ }
4602
+ },
4603
+ children: /* @__PURE__ */ jsxRuntime.jsxs(NamedCommandList, { children: [
4604
+ tab === "Home" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4605
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-undo", label: "Undo", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Undo, {}) }),
4606
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-redo", label: "Redo", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Redo, {}) }),
4607
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-save", label: "Save", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Save, {}) }),
4608
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-style", label: "Styles", children: /* @__PURE__ */ jsxRuntime.jsx(StyleGallery, {}) }),
4609
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-bold", label: "Bold", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Bold, {}) }),
4610
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-italic", label: "Italic", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Italic, {}) }),
4611
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-underline", label: "Underline", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Underline, {}) }),
4612
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-font-family", label: "Font family", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.FontFamily, {}) }),
4613
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-font-size", label: "Font size", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.FontSize, {}) }),
4614
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-font-color", label: "Font color", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.FontColor, {}) }),
4615
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-highlight", label: "Highlight", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Highlight, {}) }),
4616
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-alignment", label: "Alignment", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Alignment, {}) }),
4617
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-bullets", label: "Bulleted list", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.BulletList, {}) }),
4618
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-numbers", label: "Numbered list", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.NumberedList, {}) }),
4619
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-line-spacing", label: "Line spacing", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.LineSpacing, {}) }),
4620
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-indent", label: "Increase indent", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Indent, {}) }),
4621
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-outdent", label: "Decrease indent", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Outdent, {}) }),
4622
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-strike", label: "Strikethrough", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Strike, {}) }),
4623
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "home-clear", label: "Clear formatting", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.ClearFormatting, {}) })
4624
+ ] }),
4625
+ tab === "Insert" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4626
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-table", label: "Table", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.TableInsert, {}) }),
4627
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-picture", label: "Picture", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.ImageInsert, {}) }),
4628
+ imageGeneration && /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-generate-image", label: "Generate image", children: /* @__PURE__ */ jsxRuntime.jsx(GenerateImageButton, { generation: imageGeneration }) }),
4629
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-page-break", label: "Page break", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Button, { slotId: "insert.pageBreak" }) }),
4630
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-link", label: "Link", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Link, {}) }),
4631
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-defined-term", label: "Defined term", children: /* @__PURE__ */ jsxRuntime.jsx(DefinedTermButton, {}) }),
4632
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-quick-parts", label: "Quick Parts", children: /* @__PURE__ */ jsxRuntime.jsx(QuickParts, {}) }),
4633
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-signature-field", label: "Signature field", children: /* @__PURE__ */ jsxRuntime.jsx(SignatureFieldMenu, { onInserted: close }) }),
4634
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-my-signature", label: "My signature", children: /* @__PURE__ */ jsxRuntime.jsx(MySignatureMenu, {}) }),
4635
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "insert-cross-reference", label: "Cross-reference", children: /* @__PURE__ */ jsxRuntime.jsx(CrossReferenceButton, {}) })
4636
+ ] }),
4637
+ /* @__PURE__ */ jsxRuntime.jsx(LayoutTabContent, { tab }),
4638
+ tab === "Design" && /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "design-house-template", label: "House template", children: /* @__PURE__ */ jsxRuntime.jsx(HouseTemplatePanel, {}) }),
4639
+ tab === "References" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4640
+ /* @__PURE__ */ jsxRuntime.jsx(NoteButtons, {}),
4641
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "references-cross-reference", label: "Cross-reference", children: /* @__PURE__ */ jsxRuntime.jsx(CrossReferenceButton, {}) }),
4642
+ /* @__PURE__ */ jsxRuntime.jsx(
4643
+ RibbonItem,
4644
+ {
4645
+ id: "references-update-cross-references",
4646
+ label: "Update cross-references",
4647
+ children: /* @__PURE__ */ jsxRuntime.jsx(UpdateCrossReferencesButton, {})
4648
+ }
4649
+ )
4650
+ ] }),
4651
+ tab === "Review" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4652
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "review-editing-mode", label: "Editing mode", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.EditingMode, {}) }),
4653
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "review-comments", label: "Comments", children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Comments, {}) }),
4654
+ /* @__PURE__ */ jsxRuntime.jsx(RibbonItem, { id: "review-options", label: "Review options", children: /* @__PURE__ */ jsxRuntime.jsx(RibbonMenu, { label: "Review options", icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.UsersRound, { size: 16 }), children: /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.Reviewers, {}) }) })
4655
+ ] })
4656
+ ] })
4657
+ }
4658
+ )
4659
+ ] })
4660
+ }
4661
+ ),
4662
+ /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.Toolbar.TableCellFill, { hidden: true })
4663
+ ] }),
4664
+ badge && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "native-docx-ribbon-badge", "data-testid": "docx-ribbon-badge", children: badge })
4665
+ ] });
4666
+ }
4667
+ var contains = (node, id) => node.id === id || (node.children ?? []).some((child) => contains(child, id));
4668
+ function firstParagraph(node) {
4669
+ for (const child of node.children ?? []) {
4670
+ if (child.kind === "paragraph" && child.id) return child.id;
4671
+ if (child.localName === "tbl") continue;
4672
+ const nested = firstParagraph(child);
4673
+ if (nested) return nested;
4674
+ }
4675
+ return null;
4676
+ }
4677
+ function tableCells(root, paragraphId) {
4678
+ let table = null;
4679
+ const find = (node) => {
4680
+ if (node.localName === "tbl" && contains(node, paragraphId)) table = node;
4681
+ for (const child of node.children ?? []) if (contains(child, paragraphId)) find(child);
4682
+ };
4683
+ find(root);
4684
+ if (!table) return null;
4685
+ const cells = [];
4686
+ let index = -1;
4687
+ const rows = (node) => (node.children ?? []).flatMap(
4688
+ (child) => child.localName === "tr" ? [child] : child.localName === "tbl" ? [] : rows(child)
4689
+ );
4690
+ for (const row of rows(table))
4691
+ for (const cell of (row.children ?? []).filter((child) => child.localName === "tc")) {
4692
+ const first = firstParagraph(cell);
4693
+ if (!first) continue;
4694
+ if (contains(cell, paragraphId)) index = cells.length;
4695
+ cells.push(first);
4696
+ }
4697
+ return index < 0 ? null : { cells, index };
4698
+ }
4699
+ function TableTabKeys({ scope }) {
4700
+ const editor = react.useDocxEditor();
4701
+ const latest = React4.useRef(editor);
4702
+ latest.current = editor;
4703
+ React4.useEffect(() => {
4704
+ const element = scope.current;
4705
+ if (!element) return;
4706
+ const onKeyDown = (event) => {
4707
+ if (event.key !== "Tab" || event.ctrlKey || event.metaKey || event.altKey) return;
4708
+ const editor2 = latest.current;
4709
+ const surface = editor2?.surface;
4710
+ const head = surface?.state().selection?.head;
4711
+ if (!editor2 || !surface || !head) return;
4712
+ const root = () => surface.session.part().root;
4713
+ const table = tableCells(root(), head.paragraphId);
4714
+ if (!table) return;
4715
+ event.preventDefault();
4716
+ event.stopPropagation();
4717
+ let target = table.cells[table.index + (event.shiftKey ? -1 : 1)];
4718
+ if (!target && !event.shiftKey && editor2.exec({ type: "insertRow", where: "below" }).ok) {
4719
+ const grown = tableCells(
4720
+ root(),
4721
+ surface.state().selection?.head.paragraphId ?? head.paragraphId
4722
+ );
4723
+ target = grown?.cells[table.cells.length] ?? "";
4724
+ }
4725
+ if (!target) return;
4726
+ const point = { paragraphId: target, offset: 0 };
4727
+ surface.setSelection({ anchor: point, head: point });
4728
+ };
4729
+ element.addEventListener("keydown", onKeyDown, true);
4730
+ return () => element.removeEventListener("keydown", onKeyDown, true);
4731
+ }, [scope]);
4732
+ return null;
4733
+ }
4529
4734
  var drafts = /* @__PURE__ */ new Map();
4530
4735
  var stateBytes = (room) => Y__namespace.encodeStateAsUpdate(room.ydoc);
4531
4736
  var encodeState = (room) => {
@@ -4560,12 +4765,21 @@ var EditorBoundary = class extends React4__default.default.Component {
4560
4765
  ] }) : this.props.children;
4561
4766
  }
4562
4767
  };
4563
- function RoomInputBinding({ session }) {
4768
+ function RoomInputBinding({
4769
+ session,
4770
+ flushRef
4771
+ }) {
4564
4772
  const editor = react.useDocxEditor();
4565
4773
  React4.useEffect(() => {
4566
- if (!editor || !session) return;
4567
- return session.bindEditorInput(() => editor.surface?.flushPendingInput());
4568
- }, [editor, session]);
4774
+ if (!editor) return;
4775
+ const flush = () => editor.surface?.flushPendingInput();
4776
+ flushRef.current = flush;
4777
+ const unbind = session?.bindEditorInput(flush);
4778
+ return () => {
4779
+ if (flushRef.current === flush) flushRef.current = null;
4780
+ unbind?.();
4781
+ };
4782
+ }, [editor, session, flushRef]);
4569
4783
  return null;
4570
4784
  }
4571
4785
  function DocxParticipants({ session }) {
@@ -4712,11 +4926,14 @@ function NativeDocxEditor({
4712
4926
  stream,
4713
4927
  adapter,
4714
4928
  compact = false,
4715
- stateRef
4929
+ stateRef,
4930
+ saveRef
4716
4931
  }) {
4717
4932
  const [ready, setReady] = React4.useState(), [error, setError] = React4.useState(""), [retry, setRetry] = React4.useState(0);
4718
4933
  const [status, setStatus] = React4.useState("Connecting\u2026"), [dirty, setDirty] = React4.useState(false), [saving, setSaving] = React4.useState(false), [offline, setOffline] = React4.useState(false);
4719
4934
  const revision = React4.useRef(0);
4935
+ const savingRef = React4.useRef(false);
4936
+ const flushInputRef = React4.useRef(null);
4720
4937
  const stageRef = React4.useRef(null), fitCleanup = React4.useRef(void 0), refit = React4.useRef(void 0);
4721
4938
  const fitting = React4.useRef(true), fitted = React4.useRef(void 0);
4722
4939
  const [fitWidth, setFitWidth] = React4.useState(true), [zoomPercent, setZoomPercent] = React4.useState(100);
@@ -4940,11 +5157,16 @@ function NativeDocxEditor({
4940
5157
  };
4941
5158
  }, [documentId, isDraft, ready]);
4942
5159
  async function saveVersion() {
4943
- if (!ready || saving || stream) return;
5160
+ if (!ready || savingRef.current || stream) return false;
5161
+ if (snapshot || !ready.canEdit) return true;
5162
+ if (offline) return false;
5163
+ savingRef.current = true;
4944
5164
  setSaving(true);
4945
- runBeforeSave(ref.current);
4946
- const atRevision = revision.current;
4947
5165
  try {
5166
+ if (!flushInputRef.current) throw new Error("The editor is not ready to save yet.");
5167
+ flushInputRef.current();
5168
+ runBeforeSave(ref.current);
5169
+ const atRevision = revision.current;
4948
5170
  const result = isDraft ? await (async () => {
4949
5171
  const bytes = await ref.current?.save();
4950
5172
  if (!bytes) throw new Error("The editor is not ready.");
@@ -4961,17 +5183,32 @@ function NativeDocxEditor({
4961
5183
  setDirty(false);
4962
5184
  drafts.delete(documentId);
4963
5185
  }
4964
- await Promise.resolve(adapter.onVersionSaved?.(result.document_ext_id)).catch(() => {
4965
- });
5186
+ const savedVersion = "version" in result && typeof result.version === "number" ? result.version : void 0;
5187
+ if (!isDraft && !savedVersion) throw new Error("Could not confirm the saved version.");
5188
+ await adapter.onVersionSaved?.(result.document_ext_id, savedVersion);
4966
5189
  onSaved?.(result.document_ext_id);
5190
+ if (revision.current !== atRevision) {
5191
+ adapter.notify?.("The document changed while saving. Please try again.", "error");
5192
+ return false;
5193
+ }
4967
5194
  adapter.notify?.(isDraft ? "Word note saved" : "DOCX version saved", "success");
5195
+ return savedVersion ?? true;
4968
5196
  } catch (e) {
4969
5197
  adapter.notify?.(e instanceof Error ? e.message : "Could not save this document.", "error");
4970
5198
  setStatus("Save failed \xB7 your draft is retained");
5199
+ return false;
4971
5200
  } finally {
5201
+ savingRef.current = false;
4972
5202
  setSaving(false);
4973
5203
  }
4974
5204
  }
5205
+ React4.useEffect(() => {
5206
+ if (!saveRef) return;
5207
+ saveRef.current = saveVersion;
5208
+ return () => {
5209
+ saveRef.current = null;
5210
+ };
5211
+ });
4975
5212
  function editorReady(editor) {
4976
5213
  ref.current = editor;
4977
5214
  if (streamRef.current) {
@@ -5132,7 +5369,7 @@ function NativeDocxEditor({
5132
5369
  ),
5133
5370
  compact && !stream && /* @__PURE__ */ jsxRuntime.jsx(CompactToolbar, {}),
5134
5371
  !compact && !stream && /* @__PURE__ */ jsxRuntime.jsx(
5135
- DocxRibbon,
5372
+ DocxCommandMenu,
5136
5373
  {
5137
5374
  onSave: () => void saveVersion(),
5138
5375
  imageGeneration: adapter.imageGeneration && {
@@ -5173,7 +5410,13 @@ function NativeDocxEditor({
5173
5410
  getAgentStatus: adapter.getAgentStatus,
5174
5411
  requestAgent: adapter.requestAgent ? (request) => adapter.requestAgent(documentId, request) : void 0,
5175
5412
  children: [
5176
- /* @__PURE__ */ jsxRuntime.jsx(RoomInputBinding, { session: ready.room?.session }),
5413
+ /* @__PURE__ */ jsxRuntime.jsx(
5414
+ RoomInputBinding,
5415
+ {
5416
+ session: ready.room?.session,
5417
+ flushRef: flushInputRef
5418
+ }
5419
+ ),
5177
5420
  /* @__PURE__ */ jsxRuntime.jsx(AgentUndoRoom.Provider, { value: ready.room?.ydoc ?? null, children: /* @__PURE__ */ jsxRuntime.jsx(DocxEditorReview, { children: () => /* @__PURE__ */ jsxRuntime.jsxs(DocxEditorReview.Card, { children: [
5178
5421
  /* @__PURE__ */ jsxRuntime.jsx(DocxCommentActivity, {}),
5179
5422
  /* @__PURE__ */ jsxRuntime.jsx(AgentUndo, {})
@@ -5312,5 +5555,5 @@ exports.useDefinedTerms = useDefinedTerms;
5312
5555
  exports.useReview = useReview;
5313
5556
  exports.useReviewItem = useReviewItem;
5314
5557
  exports.withDirectEditing = withDirectEditing;
5315
- //# sourceMappingURL=chunk-M6IKVKU5.cjs.map
5316
- //# sourceMappingURL=chunk-M6IKVKU5.cjs.map
5558
+ //# sourceMappingURL=chunk-2CSLFAGF.cjs.map
5559
+ //# sourceMappingURL=chunk-2CSLFAGF.cjs.map