@arbidocs/blocks 0.5.114 → 0.5.116

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 (166) hide show
  1. package/dist/{ConnectedCallDock-2KXEQENS.cjs → ConnectedCallDock-WER7R222.cjs} +21 -21
  2. package/dist/{ConnectedCallDock-2KXEQENS.cjs.map → ConnectedCallDock-WER7R222.cjs.map} +1 -1
  3. package/dist/{ConnectedCallRoom-MU3NPNXF.cjs → ConnectedCallRoom-T7OBQTYP.cjs} +14 -14
  4. package/dist/{ConnectedCallRoom-MU3NPNXF.cjs.map → ConnectedCallRoom-T7OBQTYP.cjs.map} +1 -1
  5. package/dist/{ConnectedNativeDocxComparison-VH3I65H6.cjs → ConnectedNativeDocxComparison-546ILGLW.cjs} +19 -19
  6. package/dist/{ConnectedNativeDocxComparison-VH3I65H6.cjs.map → ConnectedNativeDocxComparison-546ILGLW.cjs.map} +1 -1
  7. package/dist/{ConnectedProductionSetDialog-4EAY6KAZ.cjs → ConnectedProductionSetDialog-LHB4VQWC.cjs} +3 -3
  8. package/dist/{ConnectedProductionSetDialog-4EAY6KAZ.cjs.map → ConnectedProductionSetDialog-LHB4VQWC.cjs.map} +1 -1
  9. package/dist/{ConnectedStreamedWordArtifact-KQSHCA75.cjs → ConnectedStreamedWordArtifact-S2ZFZLZQ.cjs} +19 -19
  10. package/dist/{ConnectedStreamedWordArtifact-KQSHCA75.cjs.map → ConnectedStreamedWordArtifact-S2ZFZLZQ.cjs.map} +1 -1
  11. package/dist/{DocumentReviewCard-OCPFVMLD.cjs → DocumentReviewCard-ZSBZBGFK.cjs} +15 -15
  12. package/dist/{DocumentReviewCard-OCPFVMLD.cjs.map → DocumentReviewCard-ZSBZBGFK.cjs.map} +1 -1
  13. package/dist/{FilesViewerDialog-BAGOEMXW.cjs → FilesViewerDialog-6UKR5WEF.cjs} +44 -44
  14. package/dist/{FilesViewerDialog-BAGOEMXW.cjs.map → FilesViewerDialog-6UKR5WEF.cjs.map} +1 -1
  15. package/dist/{NativeDocxEditor-EJEIJDOC.cjs → NativeDocxEditor-2LQY2CTV.cjs} +6 -6
  16. package/dist/{NativeDocxEditor-EJEIJDOC.cjs.map → NativeDocxEditor-2LQY2CTV.cjs.map} +1 -1
  17. package/dist/{WorkspaceTableView-IMAZICIZ.cjs → WorkspaceTableView-J3C6VH4T.cjs} +8 -8
  18. package/dist/{WorkspaceTableView-IMAZICIZ.cjs.map → WorkspaceTableView-J3C6VH4T.cjs.map} +1 -1
  19. package/dist/agents/index.cjs +297 -297
  20. package/dist/{ai-7U4B4CVF.cjs → ai-IM4A23YT.cjs} +24 -24
  21. package/dist/ai-IM4A23YT.cjs.map +1 -0
  22. package/dist/calls/index.cjs +121 -121
  23. package/dist/chat/DraftingDocChip.d.ts +3 -1
  24. package/dist/chat/DraftingDocChip.js +7 -4
  25. package/dist/chat/DraftingDocChip.js.map +2 -2
  26. package/dist/chat/index.cjs +37 -37
  27. package/dist/{chunk-4ED7CNOX.cjs → chunk-2CSLFAGF.cjs} +430 -150
  28. package/dist/chunk-2CSLFAGF.cjs.map +1 -0
  29. package/dist/{chunk-Q6DQGGP4.cjs → chunk-325GVZE6.cjs} +3 -3
  30. package/dist/{chunk-Q6DQGGP4.cjs.map → chunk-325GVZE6.cjs.map} +1 -1
  31. package/dist/{chunk-LFRNBT2I.cjs → chunk-557MJ4IH.cjs} +20 -20
  32. package/dist/{chunk-LFRNBT2I.cjs.map → chunk-557MJ4IH.cjs.map} +1 -1
  33. package/dist/{chunk-JSQQV23D.cjs → chunk-6UTKM5AB.cjs} +3 -3
  34. package/dist/{chunk-JSQQV23D.cjs.map → chunk-6UTKM5AB.cjs.map} +1 -1
  35. package/dist/{chunk-H5OLHP2U.cjs → chunk-7OPOPYV6.cjs} +3 -3
  36. package/dist/{chunk-H5OLHP2U.cjs.map → chunk-7OPOPYV6.cjs.map} +1 -1
  37. package/dist/{chunk-AHT6DQNI.cjs → chunk-B2HNNG25.cjs} +50 -50
  38. package/dist/{chunk-AHT6DQNI.cjs.map → chunk-B2HNNG25.cjs.map} +1 -1
  39. package/dist/{chunk-WW6LXQY6.cjs → chunk-B3LZITVF.cjs} +12 -12
  40. package/dist/{chunk-WW6LXQY6.cjs.map → chunk-B3LZITVF.cjs.map} +1 -1
  41. package/dist/{chunk-V5IMYLYK.cjs → chunk-BQ5RIWWT.cjs} +3 -3
  42. package/dist/{chunk-V5IMYLYK.cjs.map → chunk-BQ5RIWWT.cjs.map} +1 -1
  43. package/dist/{chunk-INEPPS4H.cjs → chunk-COD5ENHK.cjs} +4 -4
  44. package/dist/{chunk-INEPPS4H.cjs.map → chunk-COD5ENHK.cjs.map} +1 -1
  45. package/dist/{chunk-MC4F2URI.cjs → chunk-CPG7II4E.cjs} +28 -28
  46. package/dist/{chunk-MC4F2URI.cjs.map → chunk-CPG7II4E.cjs.map} +1 -1
  47. package/dist/{chunk-7XT5B2DZ.cjs → chunk-CPR6EHG7.cjs} +47 -47
  48. package/dist/{chunk-7XT5B2DZ.cjs.map → chunk-CPR6EHG7.cjs.map} +1 -1
  49. package/dist/{chunk-3U36VYMD.cjs → chunk-DDIW4HLU.cjs} +27 -27
  50. package/dist/{chunk-3U36VYMD.cjs.map → chunk-DDIW4HLU.cjs.map} +1 -1
  51. package/dist/chunk-HB2O4THB.cjs +18 -0
  52. package/dist/{chunk-ZZA756I4.cjs.map → chunk-HB2O4THB.cjs.map} +1 -1
  53. package/dist/{chunk-IFOGBMAE.cjs → chunk-KLMNCBLY.cjs} +9 -6
  54. package/dist/chunk-KLMNCBLY.cjs.map +1 -0
  55. package/dist/{chunk-TDN33HSK.cjs → chunk-KTQOGT2L.cjs} +6 -6
  56. package/dist/{chunk-TDN33HSK.cjs.map → chunk-KTQOGT2L.cjs.map} +1 -1
  57. package/dist/{chunk-UUENH4BJ.cjs → chunk-KXIRVKCJ.cjs} +3 -3
  58. package/dist/{chunk-UUENH4BJ.cjs.map → chunk-KXIRVKCJ.cjs.map} +1 -1
  59. package/dist/{chunk-436I7PQL.cjs → chunk-NIE3N6OM.cjs} +9 -9
  60. package/dist/{chunk-436I7PQL.cjs.map → chunk-NIE3N6OM.cjs.map} +1 -1
  61. package/dist/{chunk-XKDUPU7B.cjs → chunk-NJCK6V6U.cjs} +4 -4
  62. package/dist/{chunk-XKDUPU7B.cjs.map → chunk-NJCK6V6U.cjs.map} +1 -1
  63. package/dist/{chunk-5QUL5BZO.cjs → chunk-NNUK5ZM7.cjs} +4 -4
  64. package/dist/{chunk-5QUL5BZO.cjs.map → chunk-NNUK5ZM7.cjs.map} +1 -1
  65. package/dist/{chunk-4NPCDS2X.cjs → chunk-NY3YUCOW.cjs} +3 -3
  66. package/dist/{chunk-4NPCDS2X.cjs.map → chunk-NY3YUCOW.cjs.map} +1 -1
  67. package/dist/{chunk-6DCIZA3X.cjs → chunk-OEREKAAP.cjs} +75 -75
  68. package/dist/{chunk-6DCIZA3X.cjs.map → chunk-OEREKAAP.cjs.map} +1 -1
  69. package/dist/{chunk-3ODEWSRO.cjs → chunk-P77YTTJ3.cjs} +4 -4
  70. package/dist/{chunk-3ODEWSRO.cjs.map → chunk-P77YTTJ3.cjs.map} +1 -1
  71. package/dist/{chunk-3R6YHJ3G.cjs → chunk-QHOHDNBU.cjs} +6 -6
  72. package/dist/{chunk-3R6YHJ3G.cjs.map → chunk-QHOHDNBU.cjs.map} +1 -1
  73. package/dist/{chunk-LYTIQQQ2.cjs → chunk-R7CJEIA5.cjs} +3 -3
  74. package/dist/{chunk-LYTIQQQ2.cjs.map → chunk-R7CJEIA5.cjs.map} +1 -1
  75. package/dist/{chunk-MGQSLMTC.cjs → chunk-SB4M3ITT.cjs} +239 -85
  76. package/dist/chunk-SB4M3ITT.cjs.map +1 -0
  77. package/dist/{chunk-2W5E62EY.cjs → chunk-SGYSDABK.cjs} +6 -6
  78. package/dist/{chunk-2W5E62EY.cjs.map → chunk-SGYSDABK.cjs.map} +1 -1
  79. package/dist/{chunk-UNDQYTRF.cjs → chunk-T23UTIRI.cjs} +6 -6
  80. package/dist/{chunk-UNDQYTRF.cjs.map → chunk-T23UTIRI.cjs.map} +1 -1
  81. package/dist/{chunk-E4BLRF2L.cjs → chunk-TDO5UWXF.cjs} +5 -5
  82. package/dist/{chunk-E4BLRF2L.cjs.map → chunk-TDO5UWXF.cjs.map} +1 -1
  83. package/dist/{chunk-4IOYQLKG.cjs → chunk-TP5PGWIO.cjs} +3 -3
  84. package/dist/{chunk-4IOYQLKG.cjs.map → chunk-TP5PGWIO.cjs.map} +1 -1
  85. package/dist/{chunk-7X3FS5HQ.cjs → chunk-TT4IF52H.cjs} +35 -35
  86. package/dist/{chunk-7X3FS5HQ.cjs.map → chunk-TT4IF52H.cjs.map} +1 -1
  87. package/dist/{chunk-NHHEMBXQ.cjs → chunk-VGCTYTEW.cjs} +22 -14
  88. package/dist/chunk-VGCTYTEW.cjs.map +1 -0
  89. package/dist/{chunk-HM5L4SBC.cjs → chunk-VKH3BEZE.cjs} +3 -3
  90. package/dist/{chunk-HM5L4SBC.cjs.map → chunk-VKH3BEZE.cjs.map} +1 -1
  91. package/dist/{chunk-GQXPNIRE.cjs → chunk-WAV762GP.cjs} +6 -6
  92. package/dist/{chunk-GQXPNIRE.cjs.map → chunk-WAV762GP.cjs.map} +1 -1
  93. package/dist/{chunk-MZ2KZXNU.cjs → chunk-WXUU3COI.cjs} +3 -3
  94. package/dist/{chunk-MZ2KZXNU.cjs.map → chunk-WXUU3COI.cjs.map} +1 -1
  95. package/dist/{chunk-BW5MF464.cjs → chunk-XKVPSOKP.cjs} +4 -4
  96. package/dist/{chunk-BW5MF464.cjs.map → chunk-XKVPSOKP.cjs.map} +1 -1
  97. package/dist/{chunk-57EE6CMW.cjs → chunk-Y24V6HPR.cjs} +15 -15
  98. package/dist/{chunk-57EE6CMW.cjs.map → chunk-Y24V6HPR.cjs.map} +1 -1
  99. package/dist/{chunk-ET3NVY27.cjs → chunk-YGBHY67W.cjs} +5 -5
  100. package/dist/{chunk-ET3NVY27.cjs.map → chunk-YGBHY67W.cjs.map} +1 -1
  101. package/dist/{chunk-7TEUGFIL.cjs → chunk-YGXOKB5Z.cjs} +4 -4
  102. package/dist/{chunk-7TEUGFIL.cjs.map → chunk-YGXOKB5Z.cjs.map} +1 -1
  103. package/dist/connect/docx.cjs +23 -23
  104. package/dist/connect/index.cjs +1231 -1069
  105. package/dist/connect/index.cjs.map +1 -1
  106. package/dist/connect/viewer.cjs +33 -33
  107. package/dist/connection/conversation/ConnectedConversation.js +143 -55
  108. package/dist/connection/conversation/ConnectedConversation.js.map +2 -2
  109. package/dist/connection/conversation/ConversationSendButton.d.ts +1 -0
  110. package/dist/connection/conversation/ConversationSendButton.js +3 -2
  111. package/dist/connection/conversation/ConversationSendButton.js.map +2 -2
  112. package/dist/connection/conversation/DocumentTargetNotice.d.ts +7 -0
  113. package/dist/connection/conversation/DocumentTargetNotice.js +45 -0
  114. package/dist/connection/conversation/DocumentTargetNotice.js.map +7 -0
  115. package/dist/connection/conversation/documentSwitch.d.ts +9 -0
  116. package/dist/connection/conversation/documentSwitch.js +40 -0
  117. package/dist/connection/conversation/documentSwitch.js.map +7 -0
  118. package/dist/connection/docx/ConnectedNativeDocxEditor.js +10 -2
  119. package/dist/connection/docx/ConnectedNativeDocxEditor.js.map +2 -2
  120. package/dist/connection/viewer/ConnectedDocumentViewer.js +124 -21
  121. package/dist/connection/viewer/ConnectedDocumentViewer.js.map +2 -2
  122. package/dist/connection/viewer/VersionDropdown.d.ts +9 -0
  123. package/dist/connection/viewer/VersionDropdown.js +39 -0
  124. package/dist/connection/viewer/VersionDropdown.js.map +7 -0
  125. package/dist/connection/viewer/ViewerPdfPane.js +4 -1
  126. package/dist/connection/viewer/ViewerPdfPane.js.map +2 -2
  127. package/dist/connection/viewer/useViewerBlobs.d.ts +3 -1
  128. package/dist/connection/viewer/useViewerBlobs.js +14 -8
  129. package/dist/connection/viewer/useViewerBlobs.js.map +2 -2
  130. package/dist/connection/viewer/useViewerTabs.js +10 -0
  131. package/dist/connection/viewer/useViewerTabs.js.map +2 -2
  132. package/dist/dashboards/index.cjs +1 -1
  133. package/dist/docx/DocxCommandMenu.d.ts +8 -0
  134. package/dist/docx/DocxCommandMenu.js +202 -0
  135. package/dist/docx/DocxCommandMenu.js.map +7 -0
  136. package/dist/docx/NativeDocxEditor.d.ts +4 -2
  137. package/dist/docx/NativeDocxEditor.js +54 -13
  138. package/dist/docx/NativeDocxEditor.js.map +2 -2
  139. package/dist/docx/RibbonMenu.d.ts +3 -1
  140. package/dist/docx/RibbonMenu.js +10 -3
  141. package/dist/docx/RibbonMenu.js.map +2 -2
  142. package/dist/docx/RibbonOverflow.d.ts +3 -0
  143. package/dist/docx/RibbonOverflow.js +24 -1
  144. package/dist/docx/RibbonOverflow.js.map +2 -2
  145. package/dist/docx/index.cjs +38 -38
  146. package/dist/docx/signatures/SignatureFields.d.ts +5 -1
  147. package/dist/docx/signatures/SignatureFields.js +57 -10
  148. package/dist/docx/signatures/SignatureFields.js.map +2 -2
  149. package/dist/embed/index.cjs +38 -38
  150. package/dist/files/index.cjs +224 -224
  151. package/dist/index.cjs +1731 -1731
  152. package/dist/settings/index.cjs +147 -147
  153. package/dist/shell/index.cjs +90 -90
  154. package/dist/site/index.cjs +5 -5
  155. package/dist/studio/index.cjs +27 -27
  156. package/dist/styles.css +1 -1
  157. package/dist/workflow-canvas/index.cjs +54 -54
  158. package/node_modules/@arbidocs/coedit/package.json +1 -1
  159. package/package.json +5 -5
  160. package/src/docx/styles.css +94 -0
  161. package/dist/ai-7U4B4CVF.cjs.map +0 -1
  162. package/dist/chunk-4ED7CNOX.cjs.map +0 -1
  163. package/dist/chunk-IFOGBMAE.cjs.map +0 -1
  164. package/dist/chunk-MGQSLMTC.cjs.map +0 -1
  165. package/dist/chunk-NHHEMBXQ.cjs.map +0 -1
  166. package/dist/chunk-ZZA756I4.cjs +0 -18
@@ -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?.(
@@ -4274,6 +4303,42 @@ function MySignatureContextItems() {
4274
4303
  )
4275
4304
  ] });
4276
4305
  }
4306
+ function SignatureFieldContextItem() {
4307
+ const context = React4.useContext(SignatureFieldsContext);
4308
+ const editor = react.useDocxEditor();
4309
+ const target = react.useContextMenuTarget();
4310
+ const surface = editor?.surface;
4311
+ const head = surface?.state().selection?.head;
4312
+ const run = target?.closest("[data-paragraph-id][data-start][data-end]");
4313
+ const start = Number(run?.dataset.start);
4314
+ const end = Number(run?.dataset.end);
4315
+ const onSelectedRun = run && head && run.dataset.paragraphId === head.paragraphId && head.offset >= start && head.offset <= end;
4316
+ const control = onSelectedRun && surface?.contentControls.atCaret();
4317
+ if (!context?.fields || !control || !commands.parseSignatureFieldTag(control.tag)) return null;
4318
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4319
+ /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.ContextMenu.Separator, {}),
4320
+ /* @__PURE__ */ jsxRuntime.jsx(
4321
+ react.DocxEditor.ContextMenu.Item,
4322
+ {
4323
+ label: "Remove selected signature field",
4324
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 14 }),
4325
+ disabled: !context.editable || control.effectiveLock === "sdtLocked" || control.effectiveLock === "sdtContentLocked",
4326
+ onSelect: () => {
4327
+ try {
4328
+ if (!editor || !surface) return;
4329
+ const result = withDirectEditing(
4330
+ editor,
4331
+ () => surface.session.removeCustomNode(control.id)
4332
+ );
4333
+ if (!result.ok) throw new Error("The signature field could not be removed.");
4334
+ } catch (failure) {
4335
+ context.notify?.(failure instanceof Error ? failure.message : String(failure), "error");
4336
+ }
4337
+ }
4338
+ }
4339
+ )
4340
+ ] });
4341
+ }
4277
4342
  var OTHER = "__other__";
4278
4343
  var NONE2 = "";
4279
4344
  function insertSignatureField(editor, spec) {
@@ -4295,7 +4360,7 @@ function insertSignatureField(editor, spec) {
4295
4360
  }
4296
4361
  return tag;
4297
4362
  }
4298
- function SignatureFieldMenu() {
4363
+ function SignatureFieldMenu({ onInserted } = {}) {
4299
4364
  const context = React4.useContext(SignatureFieldsContext);
4300
4365
  const editor = react.useDocxEditor();
4301
4366
  const [kind, setKind] = React4.useState("signature");
@@ -4319,6 +4384,7 @@ function SignatureFieldMenu() {
4319
4384
  required
4320
4385
  });
4321
4386
  close();
4387
+ onInserted?.();
4322
4388
  setEmail("");
4323
4389
  setName("");
4324
4390
  } catch (failure) {
@@ -4431,65 +4497,240 @@ function SignatureFieldMenu() {
4431
4497
  }
4432
4498
  );
4433
4499
  }
4434
- var SOURCE = {
4435
- workspace: "This workspace's house template",
4436
- deployment: "The house template for all workspaces",
4437
- builtin: "ARBI\u2019s built-in template (no house template has been set)"
4438
- };
4439
- function download(bytes, name) {
4440
- const isTemplate = !/\.docx$/i.test(name);
4441
- const url = URL.createObjectURL(
4442
- new Blob([bytes], {
4443
- type: isTemplate ? "application/vnd.openxmlformats-officedocument.wordprocessingml.template" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
4444
- })
4445
- );
4446
- const a = document.createElement("a");
4447
- a.href = url;
4448
- a.download = /\.(dotx|docx)$/i.test(name) ? name : `${name}.dotx`;
4449
- a.click();
4450
- setTimeout(() => URL.revokeObjectURL(url), 5e3);
4451
- }
4452
- function HouseTemplatePanel() {
4453
- const house = chunkGA5ZO4YA_cjs.useHouseTemplate();
4454
- if (!house) return null;
4455
- const summary = divergenceSummary(house.divergence);
4500
+ function DefinedTermButton() {
4501
+ const terms = useDefinedTerms();
4502
+ if (!terms) return null;
4456
4503
  return /* @__PURE__ */ jsxRuntime.jsx(
4457
- RibbonMenu,
4504
+ "button",
4458
4505
  {
4459
- label: "House template",
4460
- className: "native-docx-style-trigger",
4461
- testId: "docx-house-template",
4462
- icon: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4463
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "native-docx-style-current", children: "House template" }),
4464
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { size: 12, "aria-hidden": true })
4465
- ] }),
4466
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-house-template", "data-testid": "docx-house-template-panel", children: [
4467
- /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
4468
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: house.template.name }),
4469
- /* @__PURE__ */ jsxRuntime.jsx("br", {}),
4470
- SOURCE[house.template.source],
4471
- ". New documents start from it."
4472
- ] }),
4473
- /* @__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." }),
4474
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "native-docx-house-template-actions", children: [
4475
- /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: () => download(house.template.bytes, house.template.name), children: [
4476
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { size: 14 }),
4477
- " Download template"
4478
- ] }),
4479
- house.setAsHouseTemplate && /* @__PURE__ */ jsxRuntime.jsx(
4480
- "button",
4481
- {
4482
- type: "button",
4483
- "data-testid": "docx-set-house-template",
4484
- onClick: () => void house.setAsHouseTemplate(),
4485
- children: "Use this document as the house template"
4486
- }
4487
- )
4488
- ] })
4489
- ] })
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 })
4490
4514
  }
4491
4515
  );
4492
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
+ }
4493
4734
  var drafts = /* @__PURE__ */ new Map();
4494
4735
  var stateBytes = (room) => Y__namespace.encodeStateAsUpdate(room.ydoc);
4495
4736
  var encodeState = (room) => {
@@ -4524,12 +4765,21 @@ var EditorBoundary = class extends React4__default.default.Component {
4524
4765
  ] }) : this.props.children;
4525
4766
  }
4526
4767
  };
4527
- function RoomInputBinding({ session }) {
4768
+ function RoomInputBinding({
4769
+ session,
4770
+ flushRef
4771
+ }) {
4528
4772
  const editor = react.useDocxEditor();
4529
4773
  React4.useEffect(() => {
4530
- if (!editor || !session) return;
4531
- return session.bindEditorInput(() => editor.surface?.flushPendingInput());
4532
- }, [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]);
4533
4783
  return null;
4534
4784
  }
4535
4785
  function DocxParticipants({ session }) {
@@ -4676,11 +4926,14 @@ function NativeDocxEditor({
4676
4926
  stream,
4677
4927
  adapter,
4678
4928
  compact = false,
4679
- stateRef
4929
+ stateRef,
4930
+ saveRef
4680
4931
  }) {
4681
4932
  const [ready, setReady] = React4.useState(), [error, setError] = React4.useState(""), [retry, setRetry] = React4.useState(0);
4682
4933
  const [status, setStatus] = React4.useState("Connecting\u2026"), [dirty, setDirty] = React4.useState(false), [saving, setSaving] = React4.useState(false), [offline, setOffline] = React4.useState(false);
4683
4934
  const revision = React4.useRef(0);
4935
+ const savingRef = React4.useRef(false);
4936
+ const flushInputRef = React4.useRef(null);
4684
4937
  const stageRef = React4.useRef(null), fitCleanup = React4.useRef(void 0), refit = React4.useRef(void 0);
4685
4938
  const fitting = React4.useRef(true), fitted = React4.useRef(void 0);
4686
4939
  const [fitWidth, setFitWidth] = React4.useState(true), [zoomPercent, setZoomPercent] = React4.useState(100);
@@ -4904,11 +5157,16 @@ function NativeDocxEditor({
4904
5157
  };
4905
5158
  }, [documentId, isDraft, ready]);
4906
5159
  async function saveVersion() {
4907
- 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;
4908
5164
  setSaving(true);
4909
- runBeforeSave(ref.current);
4910
- const atRevision = revision.current;
4911
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;
4912
5170
  const result = isDraft ? await (async () => {
4913
5171
  const bytes = await ref.current?.save();
4914
5172
  if (!bytes) throw new Error("The editor is not ready.");
@@ -4925,17 +5183,32 @@ function NativeDocxEditor({
4925
5183
  setDirty(false);
4926
5184
  drafts.delete(documentId);
4927
5185
  }
4928
- await Promise.resolve(adapter.onVersionSaved?.(result.document_ext_id)).catch(() => {
4929
- });
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);
4930
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
+ }
4931
5194
  adapter.notify?.(isDraft ? "Word note saved" : "DOCX version saved", "success");
5195
+ return savedVersion ?? true;
4932
5196
  } catch (e) {
4933
5197
  adapter.notify?.(e instanceof Error ? e.message : "Could not save this document.", "error");
4934
5198
  setStatus("Save failed \xB7 your draft is retained");
5199
+ return false;
4935
5200
  } finally {
5201
+ savingRef.current = false;
4936
5202
  setSaving(false);
4937
5203
  }
4938
5204
  }
5205
+ React4.useEffect(() => {
5206
+ if (!saveRef) return;
5207
+ saveRef.current = saveVersion;
5208
+ return () => {
5209
+ saveRef.current = null;
5210
+ };
5211
+ });
4939
5212
  function editorReady(editor) {
4940
5213
  ref.current = editor;
4941
5214
  if (streamRef.current) {
@@ -5096,7 +5369,7 @@ function NativeDocxEditor({
5096
5369
  ),
5097
5370
  compact && !stream && /* @__PURE__ */ jsxRuntime.jsx(CompactToolbar, {}),
5098
5371
  !compact && !stream && /* @__PURE__ */ jsxRuntime.jsx(
5099
- DocxRibbon,
5372
+ DocxCommandMenu,
5100
5373
  {
5101
5374
  onSave: () => void saveVersion(),
5102
5375
  imageGeneration: adapter.imageGeneration && {
@@ -5137,7 +5410,13 @@ function NativeDocxEditor({
5137
5410
  getAgentStatus: adapter.getAgentStatus,
5138
5411
  requestAgent: adapter.requestAgent ? (request) => adapter.requestAgent(documentId, request) : void 0,
5139
5412
  children: [
5140
- /* @__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
+ ),
5141
5420
  /* @__PURE__ */ jsxRuntime.jsx(AgentUndoRoom.Provider, { value: ready.room?.ydoc ?? null, children: /* @__PURE__ */ jsxRuntime.jsx(DocxEditorReview, { children: () => /* @__PURE__ */ jsxRuntime.jsxs(DocxEditorReview.Card, { children: [
5142
5421
  /* @__PURE__ */ jsxRuntime.jsx(DocxCommentActivity, {}),
5143
5422
  /* @__PURE__ */ jsxRuntime.jsx(AgentUndo, {})
@@ -5151,7 +5430,8 @@ function NativeDocxEditor({
5151
5430
  /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.HyperLink, {}),
5152
5431
  /* @__PURE__ */ jsxRuntime.jsxs(react.DocxEditor.ContextMenu, { children: [
5153
5432
  /* @__PURE__ */ jsxRuntime.jsx(DocxContextMenuExtras, {}),
5154
- /* @__PURE__ */ jsxRuntime.jsx(MySignatureContextItems, {})
5433
+ /* @__PURE__ */ jsxRuntime.jsx(MySignatureContextItems, {}),
5434
+ /* @__PURE__ */ jsxRuntime.jsx(SignatureFieldContextItem, {})
5155
5435
  ] })
5156
5436
  ] }),
5157
5437
  !compact && /* @__PURE__ */ jsxRuntime.jsx(react.DocxEditor.PageNumber, {})
@@ -5275,5 +5555,5 @@ exports.useDefinedTerms = useDefinedTerms;
5275
5555
  exports.useReview = useReview;
5276
5556
  exports.useReviewItem = useReviewItem;
5277
5557
  exports.withDirectEditing = withDirectEditing;
5278
- //# sourceMappingURL=chunk-4ED7CNOX.cjs.map
5279
- //# sourceMappingURL=chunk-4ED7CNOX.cjs.map
5558
+ //# sourceMappingURL=chunk-2CSLFAGF.cjs.map
5559
+ //# sourceMappingURL=chunk-2CSLFAGF.cjs.map