@harbour-enterprises/superdoc 0.23.0-next.25 → 0.23.0-next.27

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 (34) hide show
  1. package/dist/chunks/{PdfViewer-D5j64OT4.es.js → PdfViewer-C8baB1bn.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-CYMwWMP6.cjs → PdfViewer-DJ7UGyBT.cjs} +1 -1
  3. package/dist/chunks/{index-CIz8zQ3h.cjs → index-BjwQD_um.cjs} +2 -2
  4. package/dist/chunks/{index-ePxDRT3A.es.js → index-DScOqhcx.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-BhyobyII.es.js → super-editor.es-D0-dqxm2.es.js} +328 -133
  6. package/dist/chunks/{super-editor.es-DZWnc89F.cjs → super-editor.es-DpCRbxmi.cjs} +328 -133
  7. package/dist/style.css +6 -1
  8. package/dist/super-editor/ai-writer.es.js +2 -2
  9. package/dist/super-editor/chunks/{converter-CL8NqbzP.js → converter-B2Y-pDXk.js} +120 -24
  10. package/dist/super-editor/chunks/{docx-zipper-Ab__pf6Y.js → docx-zipper-bhLh8OB6.js} +1 -1
  11. package/dist/super-editor/chunks/{editor-DDXA7n3I.js → editor-GN9xFFdh.js} +2 -2
  12. package/dist/super-editor/chunks/{toolbar-BkZURoPS.js → toolbar-Bq8miKER.js} +14 -12
  13. package/dist/super-editor/converter.es.js +1 -1
  14. package/dist/super-editor/docx-zipper.es.js +2 -2
  15. package/dist/super-editor/editor.es.js +3 -3
  16. package/dist/super-editor/file-zipper.es.js +1 -1
  17. package/dist/super-editor/style.css +6 -1
  18. package/dist/super-editor/super-editor/src/components/slash-menu/constants.d.ts +4 -0
  19. package/dist/super-editor/super-editor/src/components/slash-menu/menuItems.d.ts +4 -36
  20. package/dist/super-editor/super-editor/src/components/slash-menu/tests/testHelpers.d.ts +5 -12
  21. package/dist/super-editor/super-editor/src/core/super-converter/field-references/fld-preprocessors/num-pages-preprocessor.d.ts +1 -3
  22. package/dist/super-editor/super-editor/src/core/super-converter/field-references/fld-preprocessors/page-preprocessor.d.ts +1 -3
  23. package/dist/super-editor/super-editor/src/core/super-converter/field-references/fld-preprocessors/page-ref-preprocessor.d.ts +1 -2
  24. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/pict/helpers/handle-shape-textbox-import.d.ts +1 -1
  25. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/pict/helpers/handle-v-rect-import.d.ts +1 -1
  26. package/dist/super-editor/super-editor.es.js +212 -113
  27. package/dist/super-editor/toolbar.es.js +2 -2
  28. package/dist/super-editor.cjs +1 -1
  29. package/dist/super-editor.es.js +1 -1
  30. package/dist/superdoc.cjs +2 -2
  31. package/dist/superdoc.es.js +2 -2
  32. package/dist/superdoc.umd.js +328 -133
  33. package/dist/superdoc.umd.js.map +1 -1
  34. package/package.json +1 -1
@@ -28071,9 +28071,10 @@ function handleAnnotationNode(params2) {
28071
28071
  const tagValue = tag?.attributes["w:val"];
28072
28072
  const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
28073
28073
  let attrs = {};
28074
+ const aliasLabel = getSafeString(alias?.attributes?.["w:val"]);
28074
28075
  if (shouldProcessAsJson) {
28075
28076
  const parsedAttrs = parseTagValueJSON(tagValue);
28076
- const attrsFromJSON = {
28077
+ attrs = {
28077
28078
  type: parsedAttrs.fieldTypeShort,
28078
28079
  fieldId: parsedAttrs.fieldId,
28079
28080
  displayLabel: parsedAttrs.displayLabel,
@@ -28087,10 +28088,27 @@ function handleAnnotationNode(params2) {
28087
28088
  textHighlight: parsedAttrs.fieldTextHighlight,
28088
28089
  hash: parsedAttrs.hash
28089
28090
  };
28090
- attrs = attrsFromJSON;
28091
28091
  } else {
28092
- const attrsFromElements = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
28093
- attrs = attrsFromElements;
28092
+ attrs = getAttrsFromElements({ sdtPr, tag, alias, sdtId });
28093
+ }
28094
+ const initialDisplayLabel = getSafeString(attrs.displayLabel);
28095
+ const extractedContent = getTextFromSdtContent(sdtContent);
28096
+ if (!attrs.defaultDisplayLabel) {
28097
+ if (initialDisplayLabel) {
28098
+ attrs.defaultDisplayLabel = initialDisplayLabel;
28099
+ } else if (aliasLabel) {
28100
+ attrs.defaultDisplayLabel = aliasLabel;
28101
+ }
28102
+ }
28103
+ const placeholderLabel = getPlaceholderLabel(attrs, aliasLabel);
28104
+ const placeholderText = ensurePlaceholderFormat(placeholderLabel);
28105
+ const isAnnotationsEnabled = Boolean(params2.editor?.options?.annotations);
28106
+ const contentIsDistinct = shouldUseSdtContent(extractedContent, placeholderText);
28107
+ const shouldUseContent = !isAnnotationsEnabled && contentIsDistinct && (hasMoustache(extractedContent) || !placeholderText);
28108
+ if (contentIsDistinct) {
28109
+ attrs.displayLabel = extractedContent;
28110
+ } else if (!attrs.displayLabel && placeholderLabel) {
28111
+ attrs.displayLabel = placeholderLabel;
28094
28112
  }
28095
28113
  const { attrs: marksAsAttrs, marks } = parseAnnotationMarks(sdtContent);
28096
28114
  const allAttrs = { ...attrs, ...marksAsAttrs };
@@ -28098,13 +28116,14 @@ function handleAnnotationNode(params2) {
28098
28116
  if (!attrs.fieldId || !attrs.type) {
28099
28117
  return null;
28100
28118
  }
28119
+ const textContent2 = shouldUseContent ? extractedContent : placeholderText;
28101
28120
  let result = {
28102
28121
  type: "text",
28103
- text: `{{${attrs.displayLabel}}}`,
28122
+ text: textContent2,
28104
28123
  attrs: allAttrs,
28105
28124
  marks
28106
28125
  };
28107
- if (params2.editor.options.annotations) {
28126
+ if (isAnnotationsEnabled) {
28108
28127
  result = {
28109
28128
  type: "fieldAnnotation",
28110
28129
  attrs: allAttrs
@@ -28165,6 +28184,84 @@ function getAttrsFromElements({ sdtPr, tag, alias, sdtId }) {
28165
28184
  };
28166
28185
  return attrs;
28167
28186
  }
28187
+ function getTextFromSdtContent(sdtContent) {
28188
+ if (!sdtContent?.elements?.length) return "";
28189
+ const chunks = [];
28190
+ collectTextChunks(sdtContent.elements, chunks);
28191
+ if (chunks.length && chunks[chunks.length - 1] === "\n") {
28192
+ chunks.pop();
28193
+ }
28194
+ const text = chunks.join("");
28195
+ return text.replace(/\u00a0/g, " ");
28196
+ }
28197
+ function getPlaceholderLabel(attrs, aliasValue) {
28198
+ const displayLabel = trimSafeString(attrs.displayLabel);
28199
+ if (displayLabel) return displayLabel;
28200
+ const defaultLabel = trimSafeString(attrs.defaultDisplayLabel);
28201
+ if (defaultLabel) return defaultLabel;
28202
+ return trimSafeString(aliasValue);
28203
+ }
28204
+ function shouldUseSdtContent(extractedContent, placeholderText) {
28205
+ const normalizedContent = normalizePlaceholderText(extractedContent);
28206
+ if (!normalizedContent) return false;
28207
+ const normalizedPlaceholder = normalizePlaceholderText(placeholderText);
28208
+ return normalizedContent !== normalizedPlaceholder;
28209
+ }
28210
+ function ensurePlaceholderFormat(label) {
28211
+ const trimmed = trimSafeString(label);
28212
+ if (!trimmed) return "";
28213
+ if (trimmed.startsWith("{{") && trimmed.endsWith("}}")) {
28214
+ return trimmed;
28215
+ }
28216
+ return `{{${trimmed}}}`;
28217
+ }
28218
+ function normalizePlaceholderText(value = "") {
28219
+ const trimmed = trimSafeString(value);
28220
+ if (!trimmed) return "";
28221
+ return stripPlaceholderBraces(trimmed).toLowerCase();
28222
+ }
28223
+ function stripPlaceholderBraces(value = "") {
28224
+ if (value.startsWith("{{") && value.endsWith("}}")) {
28225
+ return trimSafeString(value.slice(2, -2));
28226
+ }
28227
+ return value;
28228
+ }
28229
+ function hasMoustache(value = "") {
28230
+ return /\{\{\s*.+?\s*\}\}/.test(getSafeString(value));
28231
+ }
28232
+ function collectTextChunks(elements, chunks) {
28233
+ if (!elements) return;
28234
+ elements.forEach((element) => {
28235
+ if (!element) return;
28236
+ if (element.type === "text") {
28237
+ chunks.push(element.text || "");
28238
+ return;
28239
+ }
28240
+ if (element.name === "w:tab") {
28241
+ chunks.push(" ");
28242
+ return;
28243
+ }
28244
+ if (element.name === "w:br") {
28245
+ chunks.push("\n");
28246
+ return;
28247
+ }
28248
+ const isParagraph = element.name === "w:p";
28249
+ const initialLength = chunks.length;
28250
+ if (element.elements?.length) {
28251
+ collectTextChunks(element.elements, chunks);
28252
+ }
28253
+ if (isParagraph && chunks.length > initialLength) {
28254
+ chunks.push("\n");
28255
+ }
28256
+ });
28257
+ }
28258
+ function getSafeString(value) {
28259
+ if (typeof value !== "string") return "";
28260
+ return value;
28261
+ }
28262
+ function trimSafeString(value) {
28263
+ return getSafeString(value).replace(/\u00a0/g, " ").trim();
28264
+ }
28168
28265
  function handleDocPartObj(params2) {
28169
28266
  const { nodes } = params2;
28170
28267
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
@@ -30824,7 +30921,7 @@ const attrConfig = Object.freeze({
30824
30921
  });
30825
30922
  const XML_NODE_NAME$4 = "w:commentRange";
30826
30923
  const SD_NODE_NAME$4 = "commentRange";
30827
- const decode$4 = (params2, decodedAttrs) => {
30924
+ const decode$4 = (params2) => {
30828
30925
  const { node, comments, commentsExportType, exportedCommentDefs } = params2;
30829
30926
  if (!node) return;
30830
30927
  if (!comments) return;
@@ -30879,7 +30976,7 @@ const commentRangeStartTranslator = NodeTranslator.from(getConfig("Start"));
30879
30976
  const commentRangeEndTranslator = NodeTranslator.from(getConfig("End"));
30880
30977
  const XML_NODE_NAME$3 = "sd:pageReference";
30881
30978
  const SD_NODE_NAME$3 = "pageReference";
30882
- const encode$3 = (params2, _2) => {
30979
+ const encode$3 = (params2) => {
30883
30980
  const { nodes = [], nodeListHandler } = params2 || {};
30884
30981
  const node = nodes[0];
30885
30982
  const processedText = nodeListHandler.handler({
@@ -30896,7 +30993,7 @@ const encode$3 = (params2, _2) => {
30896
30993
  };
30897
30994
  return processedNode;
30898
30995
  };
30899
- const decode$3 = (params2, _2) => {
30996
+ const decode$3 = (params2) => {
30900
30997
  const { node } = params2;
30901
30998
  const outputMarks = processOutputMarks(node.attrs?.marksAsAttrs || []);
30902
30999
  const contentNodes = (node.content ?? []).flatMap((n) => exportSchemaToJson({ ...params2, node: n }));
@@ -30979,7 +31076,7 @@ const config$3 = {
30979
31076
  const translator$3 = NodeTranslator.from(config$3);
30980
31077
  const XML_NODE_NAME$2 = "sd:tableOfContents";
30981
31078
  const SD_NODE_NAME$2 = "tableOfContents";
30982
- const encode$2 = (params2, _2) => {
31079
+ const encode$2 = (params2) => {
30983
31080
  const { nodes = [], nodeListHandler } = params2 || {};
30984
31081
  const node = nodes[0];
30985
31082
  const processedContent = nodeListHandler.handler({
@@ -30995,7 +31092,7 @@ const encode$2 = (params2, _2) => {
30995
31092
  };
30996
31093
  return processedNode;
30997
31094
  };
30998
- const decode$2 = (params2, _2) => {
31095
+ const decode$2 = (params2) => {
30999
31096
  const { node } = params2;
31000
31097
  const contentNodes = node.content.map((n) => exportSchemaToJson({ ...params2, node: n }));
31001
31098
  const tocBeginElements = [
@@ -31058,7 +31155,7 @@ function parseInlineStyles(styleString) {
31058
31155
  return acc;
31059
31156
  }, {});
31060
31157
  }
31061
- function handleVRectImport({ params: params2, pNode, pict }) {
31158
+ function handleVRectImport({ pNode, pict }) {
31062
31159
  const rect = pict.elements?.find((el) => el.name === "v:rect");
31063
31160
  const schemaAttrs = {};
31064
31161
  const rectAttrs = rect.attributes || {};
@@ -32064,7 +32161,7 @@ const tabNodeEntityHandler = {
32064
32161
  handler: handleTabNode
32065
32162
  };
32066
32163
  const tableOfContentsHandlerEntity = generateV2HandlerEntity("tableOfContentsHandler", translator$2);
32067
- function preProcessPageInstruction(nodesToCombine, _2, __) {
32164
+ function preProcessPageInstruction(nodesToCombine) {
32068
32165
  const pageNumNode = {
32069
32166
  name: "sd:autoPageNumber",
32070
32167
  type: "element"
@@ -32075,7 +32172,7 @@ function preProcessPageInstruction(nodesToCombine, _2, __) {
32075
32172
  });
32076
32173
  return [pageNumNode];
32077
32174
  }
32078
- function preProcessNumPagesInstruction(nodesToCombine, _2, __) {
32175
+ function preProcessNumPagesInstruction(nodesToCombine) {
32079
32176
  const totalPageNumNode = {
32080
32177
  name: "sd:totalPageNumber",
32081
32178
  type: "element"
@@ -32086,7 +32183,7 @@ function preProcessNumPagesInstruction(nodesToCombine, _2, __) {
32086
32183
  });
32087
32184
  return [totalPageNumNode];
32088
32185
  }
32089
- function preProcessPageRefInstruction(nodesToCombine, instrText, _2) {
32186
+ function preProcessPageRefInstruction(nodesToCombine, instrText) {
32090
32187
  const pageRefNode = {
32091
32188
  name: "sd:pageReference",
32092
32189
  type: "element",
@@ -32122,15 +32219,14 @@ function preProcessHyperlinkInstruction(nodesToCombine, instruction, docx) {
32122
32219
  }
32123
32220
  } else {
32124
32221
  const availableSwitches = {
32125
- "w:anchor": `l "(?<value>[^"]+)"`,
32126
- new_window: `
32127
- `,
32128
- "w:tgtFrame": ` "(?<value>[^"]+)"`,
32129
- "w:tooltip": `o "(?<value>[^"]+)"`
32222
+ "w:anchor": /(?:\\)?l "(?<value>[^"]+)"/,
32223
+ new_window: /(?:\\n|\n)/,
32224
+ "w:tgtFrame": /(?:\\t|\t) "(?<value>[^"]+)"/,
32225
+ "w:tooltip": /(?:\\)?o "(?<value>[^"]+)"/
32130
32226
  };
32131
32227
  const parsedSwitches = {};
32132
- for (const [key2, regex] of Object.entries(availableSwitches)) {
32133
- const match = instruction.match(new RegExp(regex));
32228
+ for (const [key2, pattern] of Object.entries(availableSwitches)) {
32229
+ const match = instruction.match(pattern);
32134
32230
  if (match) {
32135
32231
  parsedSwitches[key2] = match.groups?.value || true;
32136
32232
  }
@@ -32294,7 +32390,7 @@ const createDocumentJson = (docx, converter, editor) => {
32294
32390
  } else {
32295
32391
  trackStructure(identifierResult);
32296
32392
  }
32297
- } catch (error) {
32393
+ } catch {
32298
32394
  trackStructure();
32299
32395
  }
32300
32396
  }
@@ -32772,7 +32868,7 @@ const isAlternatingHeadersOddEven = (docx) => {
32772
32868
  const evenOdd = elements.find((el) => el.name === "w:evenAndOddHeaders");
32773
32869
  return !!evenOdd;
32774
32870
  };
32775
- function handleShapeTextboxImport({ params: params2, pNode, pict }) {
32871
+ function handleShapeTextboxImport({ params: params2, pict }) {
32776
32872
  const shape = pict.elements?.find((el) => el.name === "v:shape");
32777
32873
  const schemaAttrs = {};
32778
32874
  const schemaTextboxAttrs = {};
@@ -71876,7 +71972,7 @@ const fileHalfDashedIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="
71876
71972
  const commentIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M512 240c0 114.9-114.6 208-256 208c-37.1 0-72.3-6.4-104.1-17.9c-11.9 8.7-31.3 20.6-54.3 30.6C73.6 471.1 44.7 480 16 480c-6.5 0-12.3-3.9-14.8-9.9c-2.5-6-1.1-12.8 3.4-17.4c0 0 0 0 0 0s0 0 0 0s0 0 0 0c0 0 0 0 0 0l.3-.3c.3-.3 .7-.7 1.3-1.4c1.1-1.2 2.8-3.1 4.9-5.7c4.1-5 9.6-12.4 15.2-21.6c10-16.6 19.5-38.4 21.4-62.9C17.7 326.8 0 285.1 0 240C0 125.1 114.6 32 256 32s256 93.1 256 208z"/></svg>';
71877
71973
  const circleIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z"/></svg>';
71878
71974
  const checkIconSvg$1 = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg>';
71879
- const xmarkIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>';
71975
+ const xMarkIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>';
71880
71976
  const upRightFromSquareIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M352 0c-12.9 0-24.6 7.8-29.6 19.8s-2.2 25.7 6.9 34.9L370.7 96 201.4 265.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L416 141.3l41.4 41.4c9.2 9.2 22.9 11.9 34.9 6.9s19.8-16.6 19.8-29.6l0-128c0-17.7-14.3-32-32-32L352 0zM80 32C35.8 32 0 67.8 0 112L0 432c0 44.2 35.8 80 80 80l320 0c44.2 0 80-35.8 80-80l0-112c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 112c0 8.8-7.2 16-16 16L80 448c-8.8 0-16-7.2-16-16l0-320c0-8.8 7.2-16 16-16l112 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L80 32z"/></svg>';
71881
71977
  const ellipsisVerticalIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M64 360a56 56 0 1 0 0 112 56 56 0 1 0 0-112zm0-160a56 56 0 1 0 0 112 56 56 0 1 0 0-112zM120 96A56 56 0 1 0 8 96a56 56 0 1 0 112 0z"/></svg>';
71882
71978
  const caretUpIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M182.6 137.4c-12.5-12.5-32.8-12.5-45.3 0l-128 128c-9.2 9.2-11.9 22.9-6.9 34.9s16.6 19.8 29.6 19.8l256 0c12.9 0 24.6-7.8 29.6-19.8s2.2-25.7-6.9-34.9l-128-128z"/></svg>';
@@ -71931,7 +72027,7 @@ const toolbarIcons = {
71931
72027
  colorOption: circleIconSvg,
71932
72028
  colorOptionCheck: checkIconSvg$1,
71933
72029
  linkInput: linkIconSvg,
71934
- removeLink: xmarkIconSvg,
72030
+ removeLink: xMarkIconSvg,
71935
72031
  openLink: upRightFromSquareIconSvg,
71936
72032
  overflow: ellipsisVerticalIconSvg,
71937
72033
  dropdownCaretUp: caretUpIconSvg,
@@ -85770,7 +85866,9 @@ const ICONS = {
85770
85866
  copy: copyIconSvg,
85771
85867
  paste: pasteIconSvg,
85772
85868
  addDocumentSection: plusIconSvg,
85773
- removeDocumentSection: trashIconSvg
85869
+ removeDocumentSection: trashIconSvg,
85870
+ trackChangesAccept: checkIconSvg$1,
85871
+ trackChangesReject: xMarkIconSvg
85774
85872
  };
85775
85873
  const TEXTS = {
85776
85874
  addRowBefore: "Insert row above",
@@ -85793,7 +85891,9 @@ const TEXTS = {
85793
85891
  copy: "Copy",
85794
85892
  paste: "Paste",
85795
85893
  removeDocumentSection: "Remove section",
85796
- createDocumentSection: "Create section"
85894
+ createDocumentSection: "Create section",
85895
+ trackChangesAccept: "Accept change",
85896
+ trackChangesReject: "Reject change"
85797
85897
  };
85798
85898
  const tableActionsOptions = [
85799
85899
  {
@@ -85997,34 +86097,37 @@ async function getEditorContext(editor, event) {
85997
86097
  const isInSectionNode = structureFromResolvedPos?.isInSectionNode ?? selectionHasNodeOrMark(state2, "documentSection", { requireEnds: true });
85998
86098
  const currentNodeType = node?.type?.name || null;
85999
86099
  const activeMarks = [];
86100
+ let trackedChangeId = null;
86000
86101
  if (event && pos !== null) {
86001
86102
  const $pos = state2.doc.resolve(pos);
86002
- if ($pos.marks && typeof $pos.marks === "function") {
86003
- $pos.marks().forEach((mark) => activeMarks.push(mark.type.name));
86103
+ const processMark = (mark) => {
86104
+ if (!activeMarks.includes(mark.type.name)) {
86105
+ activeMarks.push(mark.type.name);
86106
+ }
86107
+ if (!trackedChangeId && (mark.type.name === "trackInsert" || mark.type.name === "trackDelete" || mark.type.name === "trackFormat")) {
86108
+ trackedChangeId = mark.attrs.id;
86109
+ }
86110
+ };
86111
+ for (let depth = 0; depth <= $pos.depth; depth++) {
86112
+ const nodeAtDepth = $pos.node(depth);
86113
+ if (nodeAtDepth && nodeAtDepth.marks) {
86114
+ nodeAtDepth.marks.forEach(processMark);
86115
+ }
86004
86116
  }
86005
- if (node && node.marks) {
86006
- node.marks.forEach((mark) => activeMarks.push(mark.type.name));
86117
+ if (state2.storedMarks) {
86118
+ state2.storedMarks.forEach(processMark);
86007
86119
  }
86008
86120
  } else {
86009
86121
  state2.storedMarks?.forEach((mark) => activeMarks.push(mark.type.name));
86010
86122
  state2.selection.$head.marks().forEach((mark) => activeMarks.push(mark.type.name));
86011
86123
  }
86012
- const isTrackedChange = activeMarks.includes("trackInsert") || activeMarks.includes("trackDelete");
86013
- let trackedChangeId = null;
86014
- if (isTrackedChange && event && pos !== null) {
86015
- const $pos = state2.doc.resolve(pos);
86016
- const marksAtPos = $pos.marks();
86017
- const trackedMark = marksAtPos.find((mark) => mark.type.name === "trackInsert" || mark.type.name === "trackDelete");
86018
- if (trackedMark) {
86019
- trackedChangeId = trackedMark.attrs.id;
86020
- }
86021
- }
86124
+ const isTrackedChange = activeMarks.includes("trackInsert") || activeMarks.includes("trackDelete") || activeMarks.includes("trackFormat");
86022
86125
  const cursorCoords = pos ? view.coordsAtPos(pos) : null;
86023
86126
  const cursorPosition = cursorCoords ? {
86024
86127
  x: cursorCoords.left,
86025
86128
  y: cursorCoords.top
86026
86129
  } : null;
86027
- return {
86130
+ const context = {
86028
86131
  // Selection info
86029
86132
  selectedText,
86030
86133
  hasSelection: !empty2,
@@ -86050,9 +86153,11 @@ async function getEditorContext(editor, event) {
86050
86153
  pos,
86051
86154
  node,
86052
86155
  event,
86156
+ trigger: event ? "click" : "slash",
86053
86157
  // Editor reference for advanced use cases
86054
86158
  editor
86055
86159
  };
86160
+ return context;
86056
86161
  }
86057
86162
  function computeCanUndo(editor, state2) {
86058
86163
  if (typeof editor?.can === "function") {
@@ -86133,160 +86238,209 @@ const isModuleEnabled = (editorOptions, moduleName) => {
86133
86238
  switch (moduleName) {
86134
86239
  case "ai":
86135
86240
  return !!editorOptions?.isAiEnabled;
86136
- // Example for future use cases
86137
- // case 'comments':
86138
- // return !!editorOptions?.isCommentsEnabled;
86139
86241
  default:
86140
86242
  return true;
86141
86243
  }
86142
86244
  };
86143
- function applyCustomMenuConfiguration(defaultSections, context) {
86144
- const { editor } = context;
86145
- const slashMenuConfig = editor.options?.slashMenuConfig;
86146
- if (!slashMenuConfig) {
86147
- return defaultSections;
86148
- }
86149
- let sections = [];
86150
- if (slashMenuConfig.includeDefaultItems !== false) {
86151
- sections = [...defaultSections];
86152
- }
86153
- if (slashMenuConfig.customItems && Array.isArray(slashMenuConfig.customItems)) {
86154
- sections = [...sections, ...slashMenuConfig.customItems];
86155
- }
86156
- if (typeof slashMenuConfig.menuProvider === "function") {
86245
+ const shouldShowItem = (item, context) => {
86246
+ if (typeof item.showWhen === "function") {
86157
86247
  try {
86158
- sections = slashMenuConfig.menuProvider(context, sections) || sections;
86248
+ return item.showWhen(context);
86159
86249
  } catch (error) {
86160
- console.warn("[SlashMenu] Error in custom menuProvider:", error);
86250
+ console.warn("[SlashMenu] showWhen error for item", item.id, ":", error);
86251
+ return false;
86161
86252
  }
86162
86253
  }
86163
- return sections;
86164
- }
86165
- function filterCustomItems(sections, context) {
86166
- return sections.map((section) => {
86167
- const filteredItems = section.items.filter((item) => {
86168
- if (typeof item.showWhen === "function") {
86169
- try {
86170
- return item.showWhen(context);
86171
- } catch (error) {
86172
- console.warn(`[SlashMenu] Error in showWhen for item ${item.id}:`, error);
86173
- return false;
86174
- }
86175
- }
86176
- return true;
86177
- });
86178
- return {
86179
- ...section,
86180
- items: filteredItems
86181
- };
86182
- }).filter((section) => section.items.length > 0);
86183
- }
86184
- function getItems(context) {
86185
- const { editor, selectedText, trigger: trigger2, clipboardContent } = context;
86186
- const clipboardHasContent = Boolean(
86187
- clipboardContent?.hasContent || clipboardContent?.html || clipboardContent?.text || typeof clipboardContent?.size === "number" && clipboardContent.size > 0 || clipboardContent && typeof clipboardContent?.content?.size === "number" && clipboardContent.content.size > 0 || clipboardContent?.raw && typeof clipboardContent.raw.size === "number" && clipboardContent.raw.size > 0 || clipboardContent?.raw && typeof clipboardContent.raw?.content?.size === "number" && clipboardContent.raw.content.size > 0
86188
- );
86189
- const isInTable2 = selectionHasNodeOrMark(editor.view.state, "table", { requireEnds: true });
86190
- const isInSectionNode = selectionHasNodeOrMark(editor.view.state, "documentSection", { requireEnds: true });
86191
- const sections = [
86254
+ };
86255
+ function getItems(context, customItems = [], includeDefaultItems = true) {
86256
+ const { selectedText, editor } = context;
86257
+ if (arguments.length === 1 && editor?.options?.slashMenuConfig) {
86258
+ customItems = editor.options.slashMenuConfig.items || editor.options.slashMenuConfig.customItems || [];
86259
+ includeDefaultItems = editor.options.slashMenuConfig.includeDefaultItems !== false;
86260
+ }
86261
+ const enhancedContext = {
86262
+ ...context,
86263
+ isInTable: context.isInTable ?? false,
86264
+ isInSectionNode: context.isInSectionNode ?? false,
86265
+ isTrackedChange: context.isTrackedChange ?? false,
86266
+ clipboardContent: context.clipboardContent ?? { hasContent: false },
86267
+ selectedText: context.selectedText ?? "",
86268
+ hasSelection: context.hasSelection ?? Boolean(context.selectedText)
86269
+ };
86270
+ const defaultSections = [
86192
86271
  {
86193
86272
  id: "ai-content",
86273
+ isDefault: true,
86194
86274
  items: [
86195
86275
  {
86196
86276
  id: "insert-text",
86197
86277
  label: selectedText ? TEXTS.replaceText : TEXTS.insertText,
86198
86278
  icon: ICONS.ai,
86199
86279
  component: AIWriter,
86280
+ isDefault: true,
86200
86281
  action: (editor2) => {
86201
86282
  if (editor2?.commands && typeof editor2.commands?.insertAiMark === "function") {
86202
86283
  editor2.commands.insertAiMark();
86203
86284
  }
86204
86285
  },
86205
- allowedTriggers: [TRIGGERS.slash, TRIGGERS.click],
86206
- requiresModule: "ai"
86286
+ showWhen: (context2) => {
86287
+ const { trigger: trigger2 } = context2;
86288
+ const allowedTriggers = [TRIGGERS.slash, TRIGGERS.click];
86289
+ return allowedTriggers.includes(trigger2) && isModuleEnabled(context2.editor?.options, "ai");
86290
+ }
86291
+ }
86292
+ ]
86293
+ },
86294
+ {
86295
+ id: "track-changes",
86296
+ isDefault: true,
86297
+ items: [
86298
+ {
86299
+ id: "track-changes-accept",
86300
+ icon: ICONS.trackChangesAccept,
86301
+ label: TEXTS.trackChangesAccept,
86302
+ isDefault: true,
86303
+ action: (editor2, context2) => {
86304
+ if (context2?.trackedChangeId) {
86305
+ editor2.commands.acceptTrackedChangeById(context2.trackedChangeId);
86306
+ } else {
86307
+ editor2.commands.acceptTrackedChangeBySelection();
86308
+ }
86309
+ },
86310
+ showWhen: (context2) => {
86311
+ const { trigger: trigger2, isTrackedChange } = context2;
86312
+ return trigger2 === TRIGGERS.click && isTrackedChange;
86313
+ }
86314
+ },
86315
+ {
86316
+ id: "track-changes-reject",
86317
+ label: TEXTS.trackChangesReject,
86318
+ icon: ICONS.trackChangesReject,
86319
+ isDefault: true,
86320
+ action: (editor2, context2) => {
86321
+ if (context2?.trackedChangeId) {
86322
+ editor2.commands.rejectTrackedChangeById(context2.trackedChangeId);
86323
+ } else {
86324
+ editor2.commands.rejectTrackedChangeOnSelection();
86325
+ }
86326
+ },
86327
+ showWhen: (context2) => {
86328
+ const { trigger: trigger2, isTrackedChange } = context2;
86329
+ return trigger2 === TRIGGERS.click && isTrackedChange;
86330
+ }
86207
86331
  }
86208
86332
  ]
86209
86333
  },
86210
86334
  {
86211
86335
  id: "document-sections",
86336
+ isDefault: true,
86212
86337
  items: [
86213
86338
  {
86214
86339
  id: "insert-document-section",
86215
86340
  label: TEXTS.createDocumentSection,
86216
86341
  icon: ICONS.addDocumentSection,
86342
+ isDefault: true,
86217
86343
  action: (editor2) => {
86218
86344
  editor2.commands.createDocumentSection();
86219
86345
  },
86220
- allowedTriggers: [TRIGGERS.click]
86346
+ showWhen: (context2) => {
86347
+ const { trigger: trigger2 } = context2;
86348
+ return trigger2 === TRIGGERS.click;
86349
+ }
86221
86350
  },
86222
86351
  {
86223
86352
  id: "remove-section",
86224
86353
  label: TEXTS.removeDocumentSection,
86225
86354
  icon: ICONS.removeDocumentSection,
86355
+ isDefault: true,
86226
86356
  action: (editor2) => {
86227
86357
  editor2.commands.removeSectionAtSelection();
86228
86358
  },
86229
- allowedTriggers: [TRIGGERS.click],
86230
- requiresSectionParent: true
86359
+ showWhen: (context2) => {
86360
+ const { trigger: trigger2, isInSectionNode } = context2;
86361
+ return trigger2 === TRIGGERS.click && isInSectionNode;
86362
+ }
86231
86363
  }
86232
86364
  ]
86233
86365
  },
86234
86366
  {
86235
86367
  id: "general",
86368
+ isDefault: true,
86236
86369
  items: [
86237
86370
  {
86238
86371
  id: "insert-link",
86239
86372
  label: TEXTS.insertLink,
86240
86373
  icon: ICONS.link,
86241
86374
  component: LinkInput,
86242
- allowedTriggers: [TRIGGERS.click]
86375
+ isDefault: true,
86376
+ showWhen: (context2) => {
86377
+ const { trigger: trigger2 } = context2;
86378
+ return trigger2 === TRIGGERS.click;
86379
+ }
86243
86380
  },
86244
86381
  {
86245
86382
  id: "insert-table",
86246
86383
  label: TEXTS.insertTable,
86247
86384
  icon: ICONS.table,
86248
86385
  component: TableGrid,
86249
- allowedTriggers: [TRIGGERS.slash, TRIGGERS.click]
86386
+ isDefault: true,
86387
+ showWhen: (context2) => {
86388
+ const { trigger: trigger2, isInTable: isInTable2 } = context2;
86389
+ const allowedTriggers = [TRIGGERS.slash, TRIGGERS.click];
86390
+ return allowedTriggers.includes(trigger2) && !isInTable2;
86391
+ }
86250
86392
  },
86251
86393
  {
86252
86394
  id: "edit-table",
86253
86395
  label: TEXTS.editTable,
86254
86396
  icon: ICONS.table,
86255
86397
  component: TableActions,
86256
- allowedTriggers: [TRIGGERS.slash, TRIGGERS.click],
86257
- requiresTableParent: true
86398
+ isDefault: true,
86399
+ showWhen: (context2) => {
86400
+ const { trigger: trigger2, isInTable: isInTable2 } = context2;
86401
+ const allowedTriggers = [TRIGGERS.slash, TRIGGERS.click];
86402
+ return allowedTriggers.includes(trigger2) && isInTable2;
86403
+ }
86258
86404
  }
86259
86405
  ]
86260
86406
  },
86261
86407
  {
86262
86408
  id: "clipboard",
86409
+ isDefault: true,
86263
86410
  items: [
86264
86411
  {
86265
86412
  id: "cut",
86266
86413
  label: TEXTS.cut,
86267
86414
  icon: ICONS.cut,
86415
+ isDefault: true,
86268
86416
  action: (editor2) => {
86269
86417
  editor2.view.focus();
86270
86418
  document.execCommand("cut");
86271
86419
  },
86272
- allowedTriggers: [TRIGGERS.click],
86273
- requiresSelection: true
86420
+ showWhen: (context2) => {
86421
+ const { trigger: trigger2, selectedText: selectedText2 } = context2;
86422
+ return trigger2 === TRIGGERS.click && selectedText2;
86423
+ }
86274
86424
  },
86275
86425
  {
86276
86426
  id: "copy",
86277
86427
  label: TEXTS.copy,
86278
86428
  icon: ICONS.copy,
86429
+ isDefault: true,
86279
86430
  action: (editor2) => {
86280
86431
  editor2.view.focus();
86281
86432
  document.execCommand("copy");
86282
86433
  },
86283
- allowedTriggers: [TRIGGERS.click],
86284
- requiresSelection: true
86434
+ showWhen: (context2) => {
86435
+ const { trigger: trigger2, selectedText: selectedText2 } = context2;
86436
+ return trigger2 === TRIGGERS.click && selectedText2;
86437
+ }
86285
86438
  },
86286
86439
  {
86287
86440
  id: "paste",
86288
86441
  label: TEXTS.paste,
86289
86442
  icon: ICONS.paste,
86443
+ isDefault: true,
86290
86444
  action: async (editor2) => {
86291
86445
  try {
86292
86446
  const clipboardItems = await navigator.clipboard.read();
@@ -86300,7 +86454,7 @@ function getItems(context) {
86300
86454
  text = await (await item.getType("text/plain")).text();
86301
86455
  }
86302
86456
  }
86303
- const handled = handleClipboardPaste({ editor: editor2, view: editor2.view }, html, text);
86457
+ const handled = handleClipboardPaste({ editor: editor2, view: editor2.view }, html);
86304
86458
  if (!handled) {
86305
86459
  const dataTransfer = new DataTransfer();
86306
86460
  if (html) dataTransfer.setData("text/html", html);
@@ -86316,30 +86470,52 @@ function getItems(context) {
86316
86470
  console.warn("Failed to paste:", error);
86317
86471
  }
86318
86472
  },
86319
- allowedTriggers: [TRIGGERS.click, TRIGGERS.slash],
86320
- requiresClipboard: true
86473
+ showWhen: (context2) => {
86474
+ const { trigger: trigger2, clipboardContent } = context2;
86475
+ const allowedTriggers = [TRIGGERS.click, TRIGGERS.slash];
86476
+ const hasContent = clipboardContent?.hasContent || clipboardContent?.size > 0 || clipboardContent?.content?.size > 0;
86477
+ return allowedTriggers.includes(trigger2) && hasContent;
86478
+ }
86321
86479
  }
86322
86480
  ]
86323
86481
  }
86324
86482
  ];
86325
- let allSections = applyCustomMenuConfiguration(sections, context);
86326
- const filteredSections = allSections.map((section) => {
86327
- const filteredItems = section.items.filter((item) => {
86328
- if (item.requiresModule && !isModuleEnabled(editor?.options, item.requiresModule)) return false;
86329
- if (item.requiresSelection && !selectedText) return false;
86330
- if (!item.allowedTriggers.includes(trigger2)) return false;
86331
- if (item.requiresClipboard && !clipboardHasContent) return false;
86332
- if (item.requiresTableParent && !isInTable2 || item.id === "insert-table" && isInTable2) return false;
86333
- if (item.requiresSectionParent && !isInSectionNode) return false;
86334
- return true;
86483
+ let allSections = [];
86484
+ if (includeDefaultItems) {
86485
+ allSections = [...defaultSections];
86486
+ }
86487
+ if (customItems.length > 0) {
86488
+ customItems.forEach((customSection) => {
86489
+ const existingSectionIndex = allSections.findIndex((section) => section.id === customSection.id);
86490
+ if (existingSectionIndex !== -1) {
86491
+ allSections[existingSectionIndex].items = [
86492
+ ...allSections[existingSectionIndex].items,
86493
+ ...customSection.items.map((item) => ({ ...item, isDefault: false }))
86494
+ ];
86495
+ } else {
86496
+ allSections.push({
86497
+ ...customSection,
86498
+ isDefault: false,
86499
+ items: customSection.items.map((item) => ({ ...item, isDefault: false }))
86500
+ });
86501
+ }
86335
86502
  });
86503
+ }
86504
+ if (editor?.options?.slashMenuConfig?.menuProvider) {
86505
+ try {
86506
+ allSections = editor.options.slashMenuConfig.menuProvider(enhancedContext, allSections) || allSections;
86507
+ } catch (error) {
86508
+ console.warn("[SlashMenu] menuProvider error:", error);
86509
+ }
86510
+ }
86511
+ const filteredSections = allSections.map((section) => {
86512
+ const filteredItems = section.items.filter((item) => shouldShowItem(item, enhancedContext));
86336
86513
  return {
86337
86514
  ...section,
86338
86515
  items: filteredItems
86339
86516
  };
86340
86517
  }).filter((section) => section.items.length > 0);
86341
- const finalSections = filterCustomItems(filteredSections, context);
86342
- return finalSections;
86518
+ return filteredSections;
86343
86519
  }
86344
86520
  const _hoisted_1$3 = { class: "slash-menu-items" };
86345
86521
  const _hoisted_2$1 = {
@@ -86422,13 +86598,28 @@ const _sfc_main$4 = {
86422
86598
  });
86423
86599
  const customItemRefs = /* @__PURE__ */ new Map();
86424
86600
  const setCustomItemRef = (el, item) => {
86425
- if (el && item.render) {
86601
+ if (el) {
86426
86602
  customItemRefs.set(item.id, { element: el, item });
86427
86603
  nextTick(() => {
86428
86604
  renderCustomItem(item.id);
86429
86605
  });
86430
86606
  }
86431
86607
  };
86608
+ const defaultRender = (context) => {
86609
+ const item = context.item || context.currentItem;
86610
+ const container = document.createElement("div");
86611
+ container.className = "slash-menu-default-content";
86612
+ if (item.icon) {
86613
+ const iconSpan = document.createElement("span");
86614
+ iconSpan.className = "slash-menu-item-icon";
86615
+ iconSpan.innerHTML = item.icon;
86616
+ container.appendChild(iconSpan);
86617
+ }
86618
+ const labelSpan = document.createElement("span");
86619
+ labelSpan.textContent = item.label;
86620
+ container.appendChild(labelSpan);
86621
+ return container;
86622
+ };
86432
86623
  const renderCustomItem = async (itemId) => {
86433
86624
  const refData = customItemRefs.get(itemId);
86434
86625
  if (!refData || refData.element.hasCustomContent) return;
@@ -86437,8 +86628,9 @@ const _sfc_main$4 = {
86437
86628
  if (!currentContext.value) {
86438
86629
  currentContext.value = await getEditorContext(props.editor);
86439
86630
  }
86440
- const context = currentContext.value;
86441
- const customElement = item.render(context);
86631
+ const contextWithItem = { ...currentContext.value, currentItem: item };
86632
+ const renderFunction = item.render || defaultRender;
86633
+ const customElement = renderFunction(contextWithItem);
86442
86634
  if (customElement instanceof HTMLElement) {
86443
86635
  element.innerHTML = "";
86444
86636
  element.appendChild(customElement);
@@ -86446,7 +86638,9 @@ const _sfc_main$4 = {
86446
86638
  }
86447
86639
  } catch (error) {
86448
86640
  console.warn(`[SlashMenu] Error rendering custom item ${itemId}:`, error);
86449
- element.innerHTML = `<span>${item.label || "Custom Item"}</span>`;
86641
+ const fallbackElement = defaultRender({ ...currentContext.value || {}, currentItem: item });
86642
+ element.innerHTML = "";
86643
+ element.appendChild(fallbackElement);
86450
86644
  element.hasCustomContent = true;
86451
86645
  }
86452
86646
  };
@@ -86641,19 +86835,20 @@ const _sfc_main$4 = {
86641
86835
  class: normalizeClass(["slash-menu-item", { "is-selected": item.id === selectedId.value }]),
86642
86836
  onClick: ($event) => executeCommand(item)
86643
86837
  }, [
86644
- item.render ? (openBlock(), createElementBlock("div", {
86645
- key: 0,
86838
+ createBaseVNode("div", {
86646
86839
  ref_for: true,
86647
86840
  ref: (el) => setCustomItemRef(el, item),
86648
86841
  class: "slash-menu-custom-item"
86649
- }, null, 512)) : (openBlock(), createElementBlock(Fragment$1, { key: 1 }, [
86650
- item.icon ? (openBlock(), createElementBlock("span", {
86651
- key: 0,
86652
- class: "slash-menu-item-icon",
86653
- innerHTML: item.icon
86654
- }, null, 8, _hoisted_4)) : createCommentVNode("", true),
86655
- createBaseVNode("span", null, toDisplayString(item.label), 1)
86656
- ], 64))
86842
+ }, [
86843
+ !item.render ? (openBlock(), createElementBlock(Fragment$1, { key: 0 }, [
86844
+ item.icon ? (openBlock(), createElementBlock("span", {
86845
+ key: 0,
86846
+ class: "slash-menu-item-icon",
86847
+ innerHTML: item.icon
86848
+ }, null, 8, _hoisted_4)) : createCommentVNode("", true),
86849
+ createBaseVNode("span", null, toDisplayString(item.label), 1)
86850
+ ], 64)) : createCommentVNode("", true)
86851
+ ], 512)
86657
86852
  ], 10, _hoisted_3$1);
86658
86853
  }), 128))
86659
86854
  ], 64);