@superdoc-dev/cli 0.3.0-next.16 → 0.3.0-next.17

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 (2) hide show
  1. package/dist/index.js +532 -126
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -144322,7 +144322,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
144322
144322
  init_remark_gfm_z_sDF4ss_es();
144323
144323
  });
144324
144324
 
144325
- // ../../packages/superdoc/dist/chunks/src-Bdp40qhn.es.js
144325
+ // ../../packages/superdoc/dist/chunks/src-BAlN4OvK.es.js
144326
144326
  function deleteProps(obj, propOrProps) {
144327
144327
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
144328
144328
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -151880,15 +151880,6 @@ function requireEditorCommand(command$1, operationName) {
151880
151880
  return command$1;
151881
151881
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `${operationName} command is not available.`, { reason: "missing_command" });
151882
151882
  }
151883
- function requireSchemaMark(editor, markName, operationName) {
151884
- const mark2 = editor.schema?.marks?.[markName];
151885
- if (mark2)
151886
- return mark2;
151887
- throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `${operationName} requires the "${markName}" mark.`, {
151888
- reason: "missing_mark",
151889
- markName
151890
- });
151891
- }
151892
151883
  function ensureTrackedCapability(editor, config2) {
151893
151884
  if (typeof editor.commands?.insertTrackedChange !== "function")
151894
151885
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `${config2.operation} requires the insertTrackedChange command.`, { reason: "missing_command" });
@@ -154274,7 +154265,16 @@ function isInlinePropertyAvailable(editor, property) {
154274
154265
  if (property.storage === "mark") {
154275
154266
  if (property.carrier.storage !== "mark")
154276
154267
  return false;
154277
- return hasMarkCapability(editor, property.carrier.markName === "textStyle" ? "textStyle" : property.carrier.markName);
154268
+ const markName = property.carrier.markName;
154269
+ if (!hasMarkCapability(editor, markName))
154270
+ return false;
154271
+ if (markName === "textStyle" && property.carrier.textStyleAttr) {
154272
+ const textStyleMark = editor.schema.marks.textStyle;
154273
+ const markAttrs = textStyleMark?.spec?.attrs ?? textStyleMark?.attrs;
154274
+ if (!markAttrs || !Object.prototype.hasOwnProperty.call(markAttrs, property.carrier.textStyleAttr))
154275
+ return false;
154276
+ }
154277
+ return true;
154278
154278
  }
154279
154279
  return Boolean(editor.schema?.nodes?.run);
154280
154280
  }
@@ -157290,6 +157290,82 @@ function collectBlockIds(fragment2) {
157290
157290
  }
157291
157291
  return ids;
157292
157292
  }
157293
+ function getSchemaMarks(editor) {
157294
+ return editor.schema?.marks ?? editor.state.schema?.marks ?? {};
157295
+ }
157296
+ function getSchemaNodes(editor) {
157297
+ return editor.state.schema?.nodes ?? editor.schema?.nodes ?? {};
157298
+ }
157299
+ function getMarkAttrs(markType) {
157300
+ if (!markType || typeof markType !== "object")
157301
+ return;
157302
+ const specAttrs = markType.spec?.attrs;
157303
+ if (specAttrs && typeof specAttrs === "object")
157304
+ return specAttrs;
157305
+ const attrs = markType.attrs;
157306
+ if (attrs && typeof attrs === "object")
157307
+ return attrs;
157308
+ }
157309
+ function getInlinePropertyCapabilityIssue(editor, keys$1, operationName = "format.apply") {
157310
+ const schemaMarks = getSchemaMarks(editor);
157311
+ const requiredTextStyleAttrs = /* @__PURE__ */ new Set;
157312
+ let requiresRunNode = false;
157313
+ for (const key$1 of keys$1) {
157314
+ const entry = INLINE_PROPERTY_BY_KEY2[key$1];
157315
+ if (!entry)
157316
+ continue;
157317
+ if (entry.storage === "mark") {
157318
+ const carrier = entry.carrier;
157319
+ if (carrier.storage !== "mark")
157320
+ continue;
157321
+ if (!schemaMarks[carrier.markName])
157322
+ return {
157323
+ code: "CAPABILITY_UNAVAILABLE",
157324
+ message: `${operationName} requires the "${carrier.markName}" mark.`,
157325
+ details: {
157326
+ reason: "missing_mark",
157327
+ markName: carrier.markName
157328
+ }
157329
+ };
157330
+ if (carrier.markName === "textStyle" && carrier.textStyleAttr)
157331
+ requiredTextStyleAttrs.add(carrier.textStyleAttr);
157332
+ continue;
157333
+ }
157334
+ requiresRunNode = true;
157335
+ }
157336
+ if (requiredTextStyleAttrs.size > 0) {
157337
+ const markAttrs = getMarkAttrs(schemaMarks.textStyle);
157338
+ for (const attr of requiredTextStyleAttrs)
157339
+ if (!markAttrs || !Object.prototype.hasOwnProperty.call(markAttrs, attr))
157340
+ return {
157341
+ code: "CAPABILITY_UNAVAILABLE",
157342
+ message: `${operationName} requires the "${attr}" attribute on the textStyle mark.`,
157343
+ details: {
157344
+ reason: "missing_mark_attribute",
157345
+ markName: "textStyle",
157346
+ attribute: attr
157347
+ }
157348
+ };
157349
+ }
157350
+ if (requiresRunNode && !getSchemaNodes(editor).run)
157351
+ return {
157352
+ code: "CAPABILITY_UNAVAILABLE",
157353
+ message: `${operationName} requires a run node in the schema.`
157354
+ };
157355
+ }
157356
+ function getTrackedInlinePropertySupportIssue(keys$1, operationName = "format.apply") {
157357
+ const unsupportedTrackedKeys = keys$1.filter((key$1) => INLINE_PROPERTY_BY_KEY2[key$1]?.tracked === false);
157358
+ if (unsupportedTrackedKeys.length === 0)
157359
+ return;
157360
+ return {
157361
+ code: "CAPABILITY_UNAVAILABLE",
157362
+ message: `${operationName} tracked mode is not available for: ${unsupportedTrackedKeys.join(", ")}`,
157363
+ details: {
157364
+ keys: unsupportedTrackedKeys,
157365
+ changeMode: "tracked"
157366
+ }
157367
+ };
157368
+ }
157293
157369
  function editorHasDom(editor) {
157294
157370
  const opts = editor.options;
157295
157371
  return !!(opts?.document ?? opts?.mockDocument ?? (typeof document !== "undefined" ? document : null));
@@ -157473,38 +157549,16 @@ function writeWrapper(editor, request, options) {
157473
157549
  }), resolved.resolution);
157474
157550
  }
157475
157551
  function ensureInlinePropertyCapabilities(editor, keys$1) {
157476
- let requiresTextStyle = false;
157477
- let requiresRunNode = false;
157478
- for (const key$1 of keys$1) {
157479
- const entry = INLINE_PROPERTY_BY_KEY2[key$1];
157480
- if (!entry)
157481
- continue;
157482
- if (entry.storage === "mark") {
157483
- const carrier = entry.carrier;
157484
- if (carrier.storage !== "mark")
157485
- continue;
157486
- if (carrier.markName === "textStyle") {
157487
- requiresTextStyle = true;
157488
- continue;
157489
- }
157490
- requireSchemaMark(editor, carrier.markName, "format.apply");
157491
- continue;
157492
- }
157493
- requiresRunNode = true;
157494
- }
157495
- if (requiresTextStyle)
157496
- requireSchemaMark(editor, "textStyle", "format.apply");
157497
- if (requiresRunNode && !editor.state.schema.nodes.run)
157498
- throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "format.apply requires a run node in the schema.");
157552
+ const issue = getInlinePropertyCapabilityIssue(editor, keys$1);
157553
+ if (!issue)
157554
+ return;
157555
+ throw new DocumentApiAdapterError(issue.code, issue.message, issue.details);
157499
157556
  }
157500
157557
  function ensureTrackedInlinePropertySupport(keys$1) {
157501
- const unsupportedTrackedKeys = keys$1.filter((key$1) => INLINE_PROPERTY_BY_KEY2[key$1]?.tracked === false);
157502
- if (unsupportedTrackedKeys.length === 0)
157558
+ const issue = getTrackedInlinePropertySupportIssue(keys$1);
157559
+ if (!issue)
157503
157560
  return;
157504
- throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `format.apply tracked mode is not available for: ${unsupportedTrackedKeys.join(", ")}`, {
157505
- keys: unsupportedTrackedKeys,
157506
- changeMode: "tracked"
157507
- });
157561
+ throw new DocumentApiAdapterError(issue.code, issue.message, issue.details);
157508
157562
  }
157509
157563
  function buildSelectionWhere(request) {
157510
157564
  if (request.target)
@@ -164964,6 +165018,17 @@ function executeTextStep(ctx$1, targets, step3, rangeExecutor, spanExecutor) {
164964
165018
  data
164965
165019
  };
164966
165020
  }
165021
+ function ensureFormatStepCapabilities(ctx$1, step3) {
165022
+ const inlineKeys = Object.keys(step3.args.inline);
165023
+ const capabilityIssue = getInlinePropertyCapabilityIssue(ctx$1.editor, inlineKeys, step3.op);
165024
+ if (capabilityIssue)
165025
+ throw planError(capabilityIssue.code, capabilityIssue.message, step3.id, capabilityIssue.details);
165026
+ if (ctx$1.changeMode !== "tracked")
165027
+ return;
165028
+ const trackedIssue = getTrackedInlinePropertySupportIssue(inlineKeys, step3.op);
165029
+ if (trackedIssue)
165030
+ throw planError(trackedIssue.code, trackedIssue.message, step3.id, trackedIssue.details);
165031
+ }
164967
165032
  function buildTableInput(op, blockId, args$1) {
164968
165033
  const { target: _target, nodeId: _n, tableTarget: _tableTarget, tableNodeId: _t$1, ...safeArgs } = args$1;
164969
165034
  if (TABLE_SCOPED_OPS.has(op)) {
@@ -164989,7 +165054,10 @@ function registerBuiltInExecutors() {
164989
165054
  registerStepExecutor("text.rewrite", { execute: (ctx$1, targets, step3) => executeTextStep(ctx$1, targets, step3, (e, tr, t, s2, m$1) => executeTextRewrite(e, tr, t, s2, m$1), (e, tr, t, s2, m$1) => executeSpanTextRewrite(e, tr, t, s2, m$1)) });
164990
165055
  registerStepExecutor("text.insert", { execute: (ctx$1, targets, step3) => executeTextStep(ctx$1, targets, step3, (e, tr, t, s2, m$1) => executeTextInsert(e, tr, t, s2, m$1)) });
164991
165056
  registerStepExecutor("text.delete", { execute: (ctx$1, targets, step3) => executeTextStep(ctx$1, targets, step3, (e, tr, t, s2, m$1) => executeTextDelete(e, tr, t, s2, m$1), (e, tr, t, s2, m$1) => executeSpanTextDelete(e, tr, t, s2, m$1)) });
164992
- registerStepExecutor("format.apply", { execute: (ctx$1, targets, step3) => executeTextStep(ctx$1, targets, step3, (e, tr, t, s2, m$1) => executeStyleApply3(e, tr, t, s2, m$1), (e, tr, t, s2, m$1) => executeSpanStyleApply(e, tr, t, s2, m$1)) });
165057
+ registerStepExecutor("format.apply", { execute: (ctx$1, targets, step3) => {
165058
+ ensureFormatStepCapabilities(ctx$1, step3);
165059
+ return executeTextStep(ctx$1, targets, step3, (e, tr, t, s2, m$1) => executeStyleApply3(e, tr, t, s2, m$1), (e, tr, t, s2, m$1) => executeSpanStyleApply(e, tr, t, s2, m$1));
165060
+ } });
164993
165061
  registerStepExecutor("create.paragraph", { execute: (ctx$1, targets, step3) => executeCreateStep(ctx$1.editor, ctx$1.tr, step3, targets, ctx$1.mapping) });
164994
165062
  registerStepExecutor("create.heading", { execute: (ctx$1, targets, step3) => executeCreateStep(ctx$1.editor, ctx$1.tr, step3, targets, ctx$1.mapping) });
164995
165063
  registerStepExecutor("domain.command", { execute(ctx$1, _targets, step3) {
@@ -168758,6 +168826,130 @@ function applyTcPatch(existing, patch3) {
168758
168826
  function areTcConfigsEqual(a2, b$1) {
168759
168827
  return serializeTcInstruction(a2) === serializeTcInstruction(b$1);
168760
168828
  }
168829
+ function generateTocBookmarkName(blockId) {
168830
+ return `${TOC_BOOKMARK_PREFIX}${encodeBlockId(blockId)}`;
168831
+ }
168832
+ function encodeBlockId(input2) {
168833
+ let result = "";
168834
+ for (let i4 = 0;i4 < input2.length; i4++) {
168835
+ const ch = input2[i4];
168836
+ if (ch === "_")
168837
+ result += "__";
168838
+ else if (ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9")
168839
+ result += ch;
168840
+ else
168841
+ result += `_${ch.charCodeAt(0).toString(16).padStart(2, "0")}`;
168842
+ }
168843
+ return result;
168844
+ }
168845
+ function syncTocBookmarks(editor, sources) {
168846
+ const { schema, doc: doc$12 } = editor.state;
168847
+ if (!schema.nodes.bookmarkStart || !schema.nodes.bookmarkEnd)
168848
+ return;
168849
+ const needed = deduplicateByBlockId(sources);
168850
+ const existing = collectExistingTocBookmarkNames(doc$12);
168851
+ const missing = needed.filter((t) => !existing.has(t.bookmarkName));
168852
+ if (missing.length === 0)
168853
+ return;
168854
+ const insertions = resolveInsertionTargets(missing, buildBlockIdPositionMap(doc$12), doc$12);
168855
+ if (insertions.length === 0)
168856
+ return;
168857
+ const { tr } = editor.state;
168858
+ let nextId = findMaxBookmarkId(doc$12) + 1;
168859
+ for (const { bookmarkName, contentStart, contentEnd } of insertions) {
168860
+ const bookmarkId = String(nextId++);
168861
+ const endNode = schema.nodes.bookmarkEnd.create({ id: bookmarkId });
168862
+ const startNode = schema.nodes.bookmarkStart.create({
168863
+ name: bookmarkName,
168864
+ id: bookmarkId
168865
+ });
168866
+ tr.insert(tr.mapping.map(contentStart), startNode);
168867
+ tr.insert(tr.mapping.map(contentEnd), endNode);
168868
+ }
168869
+ if (tr.docChanged)
168870
+ dispatchTransaction$2(editor, tr);
168871
+ }
168872
+ function deduplicateByBlockId(sources) {
168873
+ const seenBlockIds = /* @__PURE__ */ new Set;
168874
+ const claimedNames = /* @__PURE__ */ new Map;
168875
+ const targets = [];
168876
+ for (const { sdBlockId } of sources) {
168877
+ if (seenBlockIds.has(sdBlockId))
168878
+ continue;
168879
+ seenBlockIds.add(sdBlockId);
168880
+ const bookmarkName = generateTocBookmarkName(sdBlockId);
168881
+ const existingOwner = claimedNames.get(bookmarkName);
168882
+ if (existingOwner !== undefined && existingOwner !== sdBlockId)
168883
+ continue;
168884
+ claimedNames.set(bookmarkName, sdBlockId);
168885
+ targets.push({
168886
+ blockId: sdBlockId,
168887
+ bookmarkName
168888
+ });
168889
+ }
168890
+ return targets;
168891
+ }
168892
+ function collectExistingTocBookmarkNames(doc$12) {
168893
+ const names = /* @__PURE__ */ new Set;
168894
+ doc$12.descendants((node3) => {
168895
+ if (node3.type.name === "bookmarkStart") {
168896
+ const name = node3.attrs?.name;
168897
+ if (name?.startsWith(TOC_BOOKMARK_PREFIX))
168898
+ names.add(name);
168899
+ }
168900
+ return true;
168901
+ });
168902
+ return names;
168903
+ }
168904
+ function buildBlockIdPositionMap(doc$12) {
168905
+ const map$12 = /* @__PURE__ */ new Map;
168906
+ doc$12.descendants((node3, pos) => {
168907
+ if (node3.type.name === "paragraph") {
168908
+ const id2 = node3.attrs?.sdBlockId ?? node3.attrs?.paraId;
168909
+ if (id2 && !map$12.has(id2))
168910
+ map$12.set(id2, pos);
168911
+ }
168912
+ return true;
168913
+ });
168914
+ return map$12;
168915
+ }
168916
+ function resolveInsertionTargets(missing, positions, doc$12) {
168917
+ const result = [];
168918
+ for (const { blockId, bookmarkName } of missing) {
168919
+ const pos = positions.get(blockId);
168920
+ if (pos === undefined)
168921
+ continue;
168922
+ const node3 = doc$12.nodeAt(pos);
168923
+ if (!node3 || node3.type.name !== "paragraph")
168924
+ continue;
168925
+ result.push({
168926
+ bookmarkName,
168927
+ contentStart: pos + 1,
168928
+ contentEnd: pos + node3.nodeSize - 1
168929
+ });
168930
+ }
168931
+ result.sort((a2, b$1) => b$1.contentStart - a2.contentStart);
168932
+ return result;
168933
+ }
168934
+ function findMaxBookmarkId(doc$12) {
168935
+ let maxId = -1;
168936
+ doc$12.descendants((node3) => {
168937
+ if (node3.type.name !== "bookmarkStart" && node3.type.name !== "bookmarkEnd")
168938
+ return true;
168939
+ const raw = node3.attrs?.id;
168940
+ const id2 = typeof raw === "string" ? parseInt(raw, 10) : typeof raw === "number" ? raw : NaN;
168941
+ if (!isNaN(id2) && id2 > maxId)
168942
+ maxId = id2;
168943
+ return true;
168944
+ });
168945
+ return maxId;
168946
+ }
168947
+ function dispatchTransaction$2(editor, tr) {
168948
+ if (typeof editor.dispatch === "function")
168949
+ editor.dispatch(tr);
168950
+ else if (typeof editor.view?.dispatch === "function")
168951
+ editor.view.dispatch(tr);
168952
+ }
168761
168953
  function collectTocSources(doc$12, config2) {
168762
168954
  const sources = [];
168763
168955
  const { outlineLevels, useAppliedOutlineLevel, tcFieldIdentifier, tcFieldLevels } = config2.source;
@@ -168848,7 +169040,7 @@ function buildEntryParagraph(source, config2) {
168848
169040
  textNode.marks = [{
168849
169041
  type: "link",
168850
169042
  attrs: {
168851
- anchor: source.sdBlockId,
169043
+ anchor: generateTocBookmarkName(source.sdBlockId),
168852
169044
  rId: null,
168853
169045
  history: true
168854
169046
  }
@@ -169047,8 +169239,12 @@ function sanitizeTocContentForSchema(content3, editor) {
169047
169239
  });
169048
169240
  }
169049
169241
  function materializeTocContent(doc$12, config2, editor) {
169050
- const entryParagraphs = buildTocEntryParagraphs(collectTocSources(doc$12, config2), config2);
169051
- return sanitizeTocContentForSchema(entryParagraphs.length > 0 ? entryParagraphs : NO_ENTRIES_PLACEHOLDER, editor);
169242
+ const sources = collectTocSources(doc$12, config2);
169243
+ const entryParagraphs = buildTocEntryParagraphs(sources, config2);
169244
+ return {
169245
+ content: sanitizeTocContentForSchema(entryParagraphs.length > 0 ? entryParagraphs : NO_ENTRIES_PLACEHOLDER, editor),
169246
+ sources
169247
+ };
169052
169248
  }
169053
169249
  function tocConfigureWrapper(editor, input2, options) {
169054
169250
  rejectTrackedMode("toc.configure", options);
@@ -169058,7 +169254,7 @@ function tocConfigureWrapper(editor, input2, options) {
169058
169254
  const instruction = serializeTocInstruction(patched);
169059
169255
  const rightAlignChanged = input2.patch.rightAlignPageNumbers !== undefined && input2.patch.rightAlignPageNumbers !== resolved.node.attrs?.rightAlignPageNumbers;
169060
169256
  const effectiveRightAlign = input2.patch.rightAlignPageNumbers ?? resolved.node.attrs?.rightAlignPageNumbers;
169061
- const nextContent = materializeTocContent(editor.state.doc, withRightAlign(patched, effectiveRightAlign), editor);
169257
+ const { content: nextContent, sources } = materializeTocContent(editor.state.doc, withRightAlign(patched, effectiveRightAlign), editor);
169062
169258
  if (areTocConfigsEqual(currentConfig, patched) && !rightAlignChanged)
169063
169259
  return tocFailure("NO_OP", "Configuration patch produced no change.");
169064
169260
  if (options?.dryRun)
@@ -169091,6 +169287,7 @@ function tocConfigureWrapper(editor, input2, options) {
169091
169287
  }
169092
169288
  }, options?.expectedRevision)))
169093
169289
  return tocFailure("NO_OP", "Configuration change could not be applied.");
169290
+ syncTocBookmarks(editor, sources);
169094
169291
  return tocSuccess(resolvePostMutationTocId(editor.state.doc, commandNodeId));
169095
169292
  }
169096
169293
  function tocUpdateWrapper(editor, input2, options) {
@@ -169103,13 +169300,13 @@ function tocUpdateAll(editor, input2, options) {
169103
169300
  const resolved = resolveTocTarget(editor.state.doc, input2.target);
169104
169301
  const config2 = parseTocInstruction(resolved.node.attrs?.instruction ?? "");
169105
169302
  const rightAlign = resolved.node.attrs?.rightAlignPageNumbers;
169106
- const content3 = materializeTocContent(editor.state.doc, withRightAlign(config2, rightAlign), editor);
169303
+ const { content: content3, sources } = materializeTocContent(editor.state.doc, withRightAlign(config2, rightAlign), editor);
169107
169304
  if (isTocContentUnchanged(resolved.node, content3))
169108
169305
  return tocFailure("NO_OP", "TOC update produced no change.");
169109
169306
  if (options?.dryRun)
169110
169307
  return tocSuccess(resolved.nodeId);
169111
169308
  const command$1 = editor.commands?.replaceTableOfContentsContentById;
169112
- return receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
169309
+ if (!receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
169113
169310
  sdBlockId: resolved.commandNodeId ?? resolved.nodeId,
169114
169311
  content: content3
169115
169312
  }, options?.expectedRevision) : runTocAction(editor, () => {
@@ -169123,7 +169320,10 @@ function tocUpdateAll(editor, input2, options) {
169123
169320
  } catch {
169124
169321
  return false;
169125
169322
  }
169126
- }, options?.expectedRevision)) ? tocSuccess(resolved.nodeId) : tocFailure("NO_OP", "TOC update produced no change.");
169323
+ }, options?.expectedRevision)))
169324
+ return tocFailure("NO_OP", "TOC update produced no change.");
169325
+ syncTocBookmarks(editor, sources);
169326
+ return tocSuccess(resolved.nodeId);
169127
169327
  }
169128
169328
  function getPageMap(editor) {
169129
169329
  const storage = editor.storage;
@@ -169242,7 +169442,7 @@ function createTableOfContentsWrapper(editor, input2, options) {
169242
169442
  pos = resolveCreateAnchor(editor, at.target, at.kind).pos;
169243
169443
  const config2 = input2.config ? applyTocPatchTyped(DEFAULT_TOC_CONFIG, input2.config) : DEFAULT_TOC_CONFIG;
169244
169444
  const instruction = serializeTocInstruction(config2);
169245
- const content3 = materializeTocContent(editor.state.doc, withRightAlign(config2, input2.config?.rightAlignPageNumbers), editor);
169445
+ const { content: content3, sources } = materializeTocContent(editor.state.doc, withRightAlign(config2, input2.config?.rightAlignPageNumbers), editor);
169246
169446
  const sdBlockId = v4_default();
169247
169447
  if (options?.dryRun)
169248
169448
  return {
@@ -169286,6 +169486,7 @@ function createTableOfContentsWrapper(editor, input2, options) {
169286
169486
  message: "Table of contents could not be inserted at the requested location."
169287
169487
  }
169288
169488
  };
169489
+ syncTocBookmarks(editor, sources);
169289
169490
  return {
169290
169491
  success: true,
169291
169492
  toc: buildTocAddress(resolvePostMutationTocId(editor.state.doc, sdBlockId))
@@ -200841,15 +201042,15 @@ var Node$13 = class Node$14 {
200841
201042
  return false;
200842
201043
  if ($from.parent.type.name !== "run")
200843
201044
  return false;
200844
- let dispatchTransaction$2 = null;
201045
+ let dispatchTransaction$3 = null;
200845
201046
  if (view?.dispatch)
200846
- dispatchTransaction$2 = view.dispatch.bind(view);
201047
+ dispatchTransaction$3 = view.dispatch.bind(view);
200847
201048
  else if (editor?.dispatch)
200848
- dispatchTransaction$2 = editor.dispatch.bind(editor);
200849
- if (!dispatchTransaction$2)
201049
+ dispatchTransaction$3 = editor.dispatch.bind(editor);
201050
+ if (!dispatchTransaction$3)
200850
201051
  return false;
200851
201052
  const handled = splitBlockPatch(state, (transaction) => {
200852
- dispatchTransaction$2(transaction);
201053
+ dispatchTransaction$3(transaction);
200853
201054
  }, editor);
200854
201055
  if (handled)
200855
201056
  tr.setMeta("preventDispatch", true);
@@ -205512,11 +205713,11 @@ var Node$13 = class Node$14 {
205512
205713
  this.eventListenerCleanups = [];
205513
205714
  this.resizeTimeoutId = null;
205514
205715
  }
205515
- attach({ element: element3, state, editorProps = {}, dispatchTransaction: dispatchTransaction$2, handleClick: handleClick$1 }) {
205716
+ attach({ element: element3, state, editorProps = {}, dispatchTransaction: dispatchTransaction$3, handleClick: handleClick$1 }) {
205516
205717
  this.view?.destroy();
205517
205718
  this.view = new EditorView(element3, {
205518
205719
  ...editorProps && typeof editorProps === "object" ? editorProps : {},
205519
- dispatchTransaction: dispatchTransaction$2,
205720
+ dispatchTransaction: dispatchTransaction$3,
205520
205721
  state,
205521
205722
  handleClick: handleClick$1
205522
205723
  });
@@ -205891,7 +206092,7 @@ var Node$13 = class Node$14 {
205891
206092
  type: mark2.type.name,
205892
206093
  attrs: mark2.attrs ?? {}
205893
206094
  }));
205894
- }, CANONICAL_COMMENT_IGNORED_KEYS, INITIAL_HASH, ROUND_CONSTANTS, V1_COVERAGE, SNAPSHOT_VERSION3 = "sd-diff-snapshot/v1", PAYLOAD_VERSION3 = "sd-diff-payload/v1", ENGINE_ID = "super-editor", STAGED_CONVERTER_KEYS, DiffServiceError, DEFAULT_LEVEL = 1, SWITCH_PATTERN, DEFAULT_RIGHT_TAB_POS = 9350, TAB_LEADER_MAP, NO_ENTRIES_PLACEHOLDER, TC_LEVEL_MIN = 1, TC_LEVEL_MAX = 9, DEFAULT_MIME_TYPE = "application/octet-stream", simpleHash2 = (str) => {
206095
+ }, CANONICAL_COMMENT_IGNORED_KEYS, INITIAL_HASH, ROUND_CONSTANTS, V1_COVERAGE, SNAPSHOT_VERSION3 = "sd-diff-snapshot/v1", PAYLOAD_VERSION3 = "sd-diff-payload/v1", ENGINE_ID = "super-editor", STAGED_CONVERTER_KEYS, DiffServiceError, DEFAULT_LEVEL = 1, SWITCH_PATTERN, TOC_BOOKMARK_PREFIX = "_Toc", DEFAULT_RIGHT_TAB_POS = 9350, TAB_LEADER_MAP, NO_ENTRIES_PLACEHOLDER, TC_LEVEL_MIN = 1, TC_LEVEL_MAX = 9, DEFAULT_MIME_TYPE = "application/octet-stream", simpleHash2 = (str) => {
205895
206096
  let hash$3 = 0;
205896
206097
  for (let i4 = 0;i4 < str.length; i4++) {
205897
206098
  const char = str.charCodeAt(i4);
@@ -224782,7 +224983,7 @@ var Node$13 = class Node$14 {
224782
224983
  return false;
224783
224984
  return Boolean(checker(attrs));
224784
224985
  }, SuperToolbar, ICONS, TEXTS, tableActionsOptions;
224785
- var init_src_Bdp40qhn_es = __esm(() => {
224986
+ var init_src_BAlN4OvK_es = __esm(() => {
224786
224987
  init_rolldown_runtime_B2q5OVn9_es();
224787
224988
  init_SuperConverter_hvBoS9gB_es();
224788
224989
  init_jszip_ChlR43oI_es();
@@ -257870,7 +258071,7 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
257870
258071
 
257871
258072
  // ../../packages/superdoc/dist/super-editor.es.js
257872
258073
  var init_super_editor_es = __esm(() => {
257873
- init_src_Bdp40qhn_es();
258074
+ init_src_BAlN4OvK_es();
257874
258075
  init_SuperConverter_hvBoS9gB_es();
257875
258076
  init_jszip_ChlR43oI_es();
257876
258077
  init_xml_js_BtmJ6bNs_es();
@@ -267052,15 +267253,6 @@ function requireEditorCommand2(command2, operationName) {
267052
267253
  reason: "missing_command"
267053
267254
  });
267054
267255
  }
267055
- function requireSchemaMark2(editor, markName, operationName) {
267056
- const mark2 = editor.schema?.marks?.[markName];
267057
- if (mark2)
267058
- return mark2;
267059
- throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", `${operationName} requires the "${markName}" mark.`, {
267060
- reason: "missing_mark",
267061
- markName
267062
- });
267063
- }
267064
267256
  function ensureTrackedCapability2(editor, config2) {
267065
267257
  if (typeof editor.commands?.insertTrackedChange !== "function") {
267066
267258
  throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", `${config2.operation} requires the insertTrackedChange command.`, { reason: "missing_command" });
@@ -328662,8 +328854,16 @@ function isInlinePropertyAvailable2(editor, property) {
328662
328854
  if (property.storage === "mark") {
328663
328855
  if (property.carrier.storage !== "mark")
328664
328856
  return false;
328665
- const markName = property.carrier.markName === "textStyle" ? "textStyle" : property.carrier.markName;
328666
- return hasMarkCapability2(editor, markName);
328857
+ const markName = property.carrier.markName;
328858
+ if (!hasMarkCapability2(editor, markName))
328859
+ return false;
328860
+ if (markName === "textStyle" && property.carrier.textStyleAttr) {
328861
+ const textStyleMark = editor.schema.marks.textStyle;
328862
+ const markAttrs = textStyleMark?.spec?.attrs ?? textStyleMark?.attrs;
328863
+ if (!markAttrs || !Object.prototype.hasOwnProperty.call(markAttrs, property.carrier.textStyleAttr))
328864
+ return false;
328865
+ }
328866
+ return true;
328667
328867
  }
328668
328868
  return Boolean(editor.schema?.nodes?.run);
328669
328869
  }
@@ -332195,6 +332395,84 @@ var init_structural_write_engine = __esm(() => {
332195
332395
  init_nesting_guard();
332196
332396
  });
332197
332397
 
332398
+ // ../../packages/super-editor/src/document-api-adapters/plan-engine/inline-property-guards.ts
332399
+ function getSchemaMarks2(editor) {
332400
+ return editor.schema?.marks ?? editor.state.schema?.marks ?? {};
332401
+ }
332402
+ function getSchemaNodes2(editor) {
332403
+ return editor.state.schema?.nodes ?? editor.schema?.nodes ?? {};
332404
+ }
332405
+ function getMarkAttrs2(markType) {
332406
+ if (!markType || typeof markType !== "object")
332407
+ return;
332408
+ const specAttrs = markType.spec?.attrs;
332409
+ if (specAttrs && typeof specAttrs === "object")
332410
+ return specAttrs;
332411
+ const attrs = markType.attrs;
332412
+ if (attrs && typeof attrs === "object")
332413
+ return attrs;
332414
+ return;
332415
+ }
332416
+ function getInlinePropertyCapabilityIssue2(editor, keys7, operationName = "format.apply") {
332417
+ const schemaMarks = getSchemaMarks2(editor);
332418
+ const requiredTextStyleAttrs = new Set;
332419
+ let requiresRunNode = false;
332420
+ for (const key2 of keys7) {
332421
+ const entry = INLINE_PROPERTY_BY_KEY[key2];
332422
+ if (!entry)
332423
+ continue;
332424
+ if (entry.storage === "mark") {
332425
+ const carrier = entry.carrier;
332426
+ if (carrier.storage !== "mark")
332427
+ continue;
332428
+ if (!schemaMarks[carrier.markName]) {
332429
+ return {
332430
+ code: "CAPABILITY_UNAVAILABLE",
332431
+ message: `${operationName} requires the "${carrier.markName}" mark.`,
332432
+ details: { reason: "missing_mark", markName: carrier.markName }
332433
+ };
332434
+ }
332435
+ if (carrier.markName === "textStyle" && carrier.textStyleAttr) {
332436
+ requiredTextStyleAttrs.add(carrier.textStyleAttr);
332437
+ }
332438
+ continue;
332439
+ }
332440
+ requiresRunNode = true;
332441
+ }
332442
+ if (requiredTextStyleAttrs.size > 0) {
332443
+ const markAttrs = getMarkAttrs2(schemaMarks.textStyle);
332444
+ for (const attr of requiredTextStyleAttrs) {
332445
+ if (!markAttrs || !Object.prototype.hasOwnProperty.call(markAttrs, attr)) {
332446
+ return {
332447
+ code: "CAPABILITY_UNAVAILABLE",
332448
+ message: `${operationName} requires the "${attr}" attribute on the textStyle mark.`,
332449
+ details: { reason: "missing_mark_attribute", markName: "textStyle", attribute: attr }
332450
+ };
332451
+ }
332452
+ }
332453
+ }
332454
+ if (requiresRunNode && !getSchemaNodes2(editor).run) {
332455
+ return {
332456
+ code: "CAPABILITY_UNAVAILABLE",
332457
+ message: `${operationName} requires a run node in the schema.`
332458
+ };
332459
+ }
332460
+ return;
332461
+ }
332462
+ function getTrackedInlinePropertySupportIssue2(keys7, operationName = "format.apply") {
332463
+ const unsupportedTrackedKeys = keys7.filter((key2) => INLINE_PROPERTY_BY_KEY[key2]?.tracked === false);
332464
+ if (unsupportedTrackedKeys.length === 0)
332465
+ return;
332466
+ return {
332467
+ code: "CAPABILITY_UNAVAILABLE",
332468
+ message: `${operationName} tracked mode is not available for: ${unsupportedTrackedKeys.join(", ")}`,
332469
+ details: { keys: unsupportedTrackedKeys, changeMode: "tracked" }
332470
+ };
332471
+ }
332472
+ var init_inline_property_guards = __esm(() => {
332473
+ init_src();
332474
+ });
332475
+
332198
332476
  // ../../packages/super-editor/src/document-api-adapters/plan-engine/plan-wrappers.ts
332199
332477
  function editorHasDom2(editor) {
332200
332478
  const opts = editor.options;
@@ -332372,37 +332650,16 @@ function writeWrapper2(editor, request, options) {
332372
332650
  return mapPlanReceiptToTextReceipt2(receipt2, resolved.resolution);
332373
332651
  }
332374
332652
  function ensureInlinePropertyCapabilities2(editor, keys7) {
332375
- let requiresTextStyle = false;
332376
- let requiresRunNode = false;
332377
- for (const key2 of keys7) {
332378
- const entry = INLINE_PROPERTY_BY_KEY[key2];
332379
- if (!entry)
332380
- continue;
332381
- if (entry.storage === "mark") {
332382
- const carrier = entry.carrier;
332383
- if (carrier.storage !== "mark")
332384
- continue;
332385
- if (carrier.markName === "textStyle") {
332386
- requiresTextStyle = true;
332387
- continue;
332388
- }
332389
- requireSchemaMark2(editor, carrier.markName, "format.apply");
332390
- continue;
332391
- }
332392
- requiresRunNode = true;
332393
- }
332394
- if (requiresTextStyle) {
332395
- requireSchemaMark2(editor, "textStyle", "format.apply");
332396
- }
332397
- if (requiresRunNode && !editor.state.schema.nodes.run) {
332398
- throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", "format.apply requires a run node in the schema.");
332399
- }
332653
+ const issue = getInlinePropertyCapabilityIssue2(editor, keys7);
332654
+ if (!issue)
332655
+ return;
332656
+ throw new DocumentApiAdapterError3(issue.code, issue.message, issue.details);
332400
332657
  }
332401
332658
  function ensureTrackedInlinePropertySupport2(keys7) {
332402
- const unsupportedTrackedKeys = keys7.filter((key2) => INLINE_PROPERTY_BY_KEY[key2]?.tracked === false);
332403
- if (unsupportedTrackedKeys.length === 0)
332659
+ const issue = getTrackedInlinePropertySupportIssue2(keys7);
332660
+ if (!issue)
332404
332661
  return;
332405
- throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", `format.apply tracked mode is not available for: ${unsupportedTrackedKeys.join(", ")}`, { keys: unsupportedTrackedKeys, changeMode: "tracked" });
332662
+ throw new DocumentApiAdapterError3(issue.code, issue.message, issue.details);
332406
332663
  }
332407
332664
  function buildSelectionWhere2(request) {
332408
332665
  if (request.target) {
@@ -333100,6 +333357,7 @@ var init_plan_wrappers = __esm(() => {
333100
333357
  init_selection_target_resolver();
333101
333358
  init_index_cache();
333102
333359
  init_node_address_resolver();
333360
+ init_inline_property_guards();
333103
333361
  STUB_WHERE2 = {
333104
333362
  by: "select",
333105
333363
  select: { type: "text", pattern: "", mode: "exact" },
@@ -339905,6 +340163,19 @@ function executeTextStep2(ctx2, targets, step3, rangeExecutor, spanExecutor) {
339905
340163
  };
339906
340164
  return { stepId: step3.id, op: step3.op, effect: effect2, matchCount: targets.length, data };
339907
340165
  }
340166
+ function ensureFormatStepCapabilities2(ctx2, step3) {
340167
+ const inlineKeys = Object.keys(step3.args.inline);
340168
+ const capabilityIssue = getInlinePropertyCapabilityIssue2(ctx2.editor, inlineKeys, step3.op);
340169
+ if (capabilityIssue) {
340170
+ throw planError2(capabilityIssue.code, capabilityIssue.message, step3.id, capabilityIssue.details);
340171
+ }
340172
+ if (ctx2.changeMode !== "tracked")
340173
+ return;
340174
+ const trackedIssue = getTrackedInlinePropertySupportIssue2(inlineKeys, step3.op);
340175
+ if (trackedIssue) {
340176
+ throw planError2(trackedIssue.code, trackedIssue.message, step3.id, trackedIssue.details);
340177
+ }
340178
+ }
339908
340179
  function buildTableInput2(op, blockId, args3) {
339909
340180
  const { target: _target, nodeId: _n, tableTarget: _tableTarget, tableNodeId: _t2, ...safeArgs } = args3;
339910
340181
  if (TABLE_SCOPED_OPS2.has(op)) {
@@ -339929,7 +340200,10 @@ function registerBuiltInExecutors2() {
339929
340200
  execute: (ctx2, targets, step3) => executeTextStep2(ctx2, targets, step3, (e, tr, t, s2, m2) => executeTextDelete2(e, tr, t, s2, m2), (e, tr, t, s2, m2) => executeSpanTextDelete2(e, tr, t, s2, m2))
339930
340201
  });
339931
340202
  registerStepExecutor2("format.apply", {
339932
- execute: (ctx2, targets, step3) => executeTextStep2(ctx2, targets, step3, (e, tr, t, s2, m2) => executeStyleApply4(e, tr, t, s2, m2), (e, tr, t, s2, m2) => executeSpanStyleApply2(e, tr, t, s2, m2))
340203
+ execute: (ctx2, targets, step3) => {
340204
+ ensureFormatStepCapabilities2(ctx2, step3);
340205
+ return executeTextStep2(ctx2, targets, step3, (e, tr, t, s2, m2) => executeStyleApply4(e, tr, t, s2, m2), (e, tr, t, s2, m2) => executeSpanStyleApply2(e, tr, t, s2, m2));
340206
+ }
339933
340207
  });
339934
340208
  registerStepExecutor2("create.paragraph", {
339935
340209
  execute: (ctx2, targets, step3) => executeCreateStep2(ctx2.editor, ctx2.tr, step3, targets, ctx2.mapping)
@@ -340156,6 +340430,7 @@ var TABLE_ADAPTER_DISPATCH2, ROW_OPS2, TABLE_SCOPED_OPS2, registered2 = false;
340156
340430
  var init_register_executors = __esm(() => {
340157
340431
  init_executor_registry();
340158
340432
  init_errors4();
340433
+ init_inline_property_guards();
340159
340434
  init_executor();
340160
340435
  init_structural_write_engine();
340161
340436
  init_tables_adapter();
@@ -344584,6 +344859,131 @@ var init_tc_switches = __esm(() => {
344584
344859
  SWITCH_PATTERN3 = /\\([a-z])(?:\s*(?:"([^"]*)"|([^\s\\]+)))?/gi;
344585
344860
  });
344586
344861
 
344862
+ // ../../packages/super-editor/src/document-api-adapters/helpers/toc-bookmark-sync.ts
344863
+ function generateTocBookmarkName2(blockId) {
344864
+ return `${TOC_BOOKMARK_PREFIX2}${encodeBlockId2(blockId)}`;
344865
+ }
344866
+ function encodeBlockId2(input2) {
344867
+ let result = "";
344868
+ for (let i5 = 0;i5 < input2.length; i5++) {
344869
+ const ch = input2[i5];
344870
+ if (ch === "_") {
344871
+ result += "__";
344872
+ } else if (ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9") {
344873
+ result += ch;
344874
+ } else {
344875
+ result += `_${ch.charCodeAt(0).toString(16).padStart(2, "0")}`;
344876
+ }
344877
+ }
344878
+ return result;
344879
+ }
344880
+ function syncTocBookmarks2(editor, sources) {
344881
+ const { schema, doc: doc4 } = editor.state;
344882
+ if (!schema.nodes.bookmarkStart || !schema.nodes.bookmarkEnd)
344883
+ return;
344884
+ const needed = deduplicateByBlockId2(sources);
344885
+ const existing = collectExistingTocBookmarkNames2(doc4);
344886
+ const missing = needed.filter((t) => !existing.has(t.bookmarkName));
344887
+ if (missing.length === 0)
344888
+ return;
344889
+ const paragraphPositions = buildBlockIdPositionMap2(doc4);
344890
+ const insertions = resolveInsertionTargets2(missing, paragraphPositions, doc4);
344891
+ if (insertions.length === 0)
344892
+ return;
344893
+ const { tr } = editor.state;
344894
+ let nextId = findMaxBookmarkId2(doc4) + 1;
344895
+ for (const { bookmarkName, contentStart, contentEnd } of insertions) {
344896
+ const bookmarkId = String(nextId++);
344897
+ const endNode = schema.nodes.bookmarkEnd.create({ id: bookmarkId });
344898
+ const startNode = schema.nodes.bookmarkStart.create({ name: bookmarkName, id: bookmarkId });
344899
+ tr.insert(tr.mapping.map(contentStart), startNode);
344900
+ tr.insert(tr.mapping.map(contentEnd), endNode);
344901
+ }
344902
+ if (tr.docChanged) {
344903
+ dispatchTransaction2(editor, tr);
344904
+ }
344905
+ }
344906
+ function deduplicateByBlockId2(sources) {
344907
+ const seenBlockIds = new Set;
344908
+ const claimedNames = new Map;
344909
+ const targets = [];
344910
+ for (const { sdBlockId } of sources) {
344911
+ if (seenBlockIds.has(sdBlockId))
344912
+ continue;
344913
+ seenBlockIds.add(sdBlockId);
344914
+ const bookmarkName = generateTocBookmarkName2(sdBlockId);
344915
+ const existingOwner = claimedNames.get(bookmarkName);
344916
+ if (existingOwner !== undefined && existingOwner !== sdBlockId)
344917
+ continue;
344918
+ claimedNames.set(bookmarkName, sdBlockId);
344919
+ targets.push({ blockId: sdBlockId, bookmarkName });
344920
+ }
344921
+ return targets;
344922
+ }
344923
+ function collectExistingTocBookmarkNames2(doc4) {
344924
+ const names = new Set;
344925
+ doc4.descendants((node4) => {
344926
+ if (node4.type.name === "bookmarkStart") {
344927
+ const name = node4.attrs?.name;
344928
+ if (name?.startsWith(TOC_BOOKMARK_PREFIX2))
344929
+ names.add(name);
344930
+ }
344931
+ return true;
344932
+ });
344933
+ return names;
344934
+ }
344935
+ function buildBlockIdPositionMap2(doc4) {
344936
+ const map10 = new Map;
344937
+ doc4.descendants((node4, pos) => {
344938
+ if (node4.type.name === "paragraph") {
344939
+ const id2 = node4.attrs?.sdBlockId ?? node4.attrs?.paraId;
344940
+ if (id2 && !map10.has(id2))
344941
+ map10.set(id2, pos);
344942
+ }
344943
+ return true;
344944
+ });
344945
+ return map10;
344946
+ }
344947
+ function resolveInsertionTargets2(missing, positions, doc4) {
344948
+ const result = [];
344949
+ for (const { blockId, bookmarkName } of missing) {
344950
+ const pos = positions.get(blockId);
344951
+ if (pos === undefined)
344952
+ continue;
344953
+ const node4 = doc4.nodeAt(pos);
344954
+ if (!node4 || node4.type.name !== "paragraph")
344955
+ continue;
344956
+ result.push({
344957
+ bookmarkName,
344958
+ contentStart: pos + 1,
344959
+ contentEnd: pos + node4.nodeSize - 1
344960
+ });
344961
+ }
344962
+ result.sort((a2, b2) => b2.contentStart - a2.contentStart);
344963
+ return result;
344964
+ }
344965
+ function findMaxBookmarkId2(doc4) {
344966
+ let maxId = -1;
344967
+ doc4.descendants((node4) => {
344968
+ if (node4.type.name !== "bookmarkStart" && node4.type.name !== "bookmarkEnd")
344969
+ return true;
344970
+ const raw = node4.attrs?.id;
344971
+ const id2 = typeof raw === "string" ? parseInt(raw, 10) : typeof raw === "number" ? raw : NaN;
344972
+ if (!isNaN(id2) && id2 > maxId)
344973
+ maxId = id2;
344974
+ return true;
344975
+ });
344976
+ return maxId;
344977
+ }
344978
+ function dispatchTransaction2(editor, tr) {
344979
+ if (typeof editor.dispatch === "function") {
344980
+ editor.dispatch(tr);
344981
+ } else if (typeof editor.view?.dispatch === "function") {
344982
+ editor.view.dispatch(tr);
344983
+ }
344984
+ }
344985
+ var TOC_BOOKMARK_PREFIX2 = "_Toc";
344986
+
344587
344987
  // ../../packages/super-editor/src/document-api-adapters/helpers/toc-entry-builder.ts
344588
344988
  function collectTocSources2(doc4, config41) {
344589
344989
  const sources = [];
@@ -344669,7 +345069,7 @@ function buildEntryParagraph2(source, config41) {
344669
345069
  {
344670
345070
  type: "link",
344671
345071
  attrs: {
344672
- anchor: source.sdBlockId,
345072
+ anchor: generateTocBookmarkName2(source.sdBlockId),
344673
345073
  rId: null,
344674
345074
  history: true
344675
345075
  }
@@ -344861,7 +345261,7 @@ function materializeTocContent2(doc4, config41, editor) {
344861
345261
  const sources = collectTocSources2(doc4, config41);
344862
345262
  const entryParagraphs = buildTocEntryParagraphs2(sources, config41);
344863
345263
  const content5 = entryParagraphs.length > 0 ? entryParagraphs : NO_ENTRIES_PLACEHOLDER2;
344864
- return sanitizeTocContentForSchema2(content5, editor);
345264
+ return { content: sanitizeTocContentForSchema2(content5, editor), sources };
344865
345265
  }
344866
345266
  function tocConfigureWrapper2(editor, input2, options) {
344867
345267
  rejectTrackedMode2("toc.configure", options);
@@ -344871,7 +345271,7 @@ function tocConfigureWrapper2(editor, input2, options) {
344871
345271
  const instruction = serializeTocInstruction2(patched);
344872
345272
  const rightAlignChanged = input2.patch.rightAlignPageNumbers !== undefined && input2.patch.rightAlignPageNumbers !== resolved.node.attrs?.rightAlignPageNumbers;
344873
345273
  const effectiveRightAlign = input2.patch.rightAlignPageNumbers ?? resolved.node.attrs?.rightAlignPageNumbers;
344874
- const nextContent = materializeTocContent2(editor.state.doc, withRightAlign2(patched, effectiveRightAlign), editor);
345274
+ const { content: nextContent, sources } = materializeTocContent2(editor.state.doc, withRightAlign2(patched, effectiveRightAlign), editor);
344875
345275
  if (areTocConfigsEqual2(currentConfig, patched) && !rightAlignChanged) {
344876
345276
  return tocFailure2("NO_OP", "Configuration patch produced no change.");
344877
345277
  }
@@ -344908,6 +345308,7 @@ function tocConfigureWrapper2(editor, input2, options) {
344908
345308
  if (!receiptApplied2(receipt2)) {
344909
345309
  return tocFailure2("NO_OP", "Configuration change could not be applied.");
344910
345310
  }
345311
+ syncTocBookmarks2(editor, sources);
344911
345312
  const postMutationId = resolvePostMutationTocId2(editor.state.doc, commandNodeId);
344912
345313
  return tocSuccess2(postMutationId);
344913
345314
  }
@@ -344923,7 +345324,7 @@ function tocUpdateAll2(editor, input2, options) {
344923
345324
  const resolved = resolveTocTarget2(editor.state.doc, input2.target);
344924
345325
  const config41 = parseTocInstruction2(resolved.node.attrs?.instruction ?? "");
344925
345326
  const rightAlign = resolved.node.attrs?.rightAlignPageNumbers;
344926
- const content5 = materializeTocContent2(editor.state.doc, withRightAlign2(config41, rightAlign), editor);
345327
+ const { content: content5, sources } = materializeTocContent2(editor.state.doc, withRightAlign2(config41, rightAlign), editor);
344927
345328
  if (isTocContentUnchanged2(resolved.node, content5)) {
344928
345329
  return tocFailure2("NO_OP", "TOC update produced no change.");
344929
345330
  }
@@ -344946,7 +345347,11 @@ function tocUpdateAll2(editor, input2, options) {
344946
345347
  return false;
344947
345348
  }
344948
345349
  }, options?.expectedRevision);
344949
- return receiptApplied2(receipt2) ? tocSuccess2(resolved.nodeId) : tocFailure2("NO_OP", "TOC update produced no change.");
345350
+ if (!receiptApplied2(receipt2)) {
345351
+ return tocFailure2("NO_OP", "TOC update produced no change.");
345352
+ }
345353
+ syncTocBookmarks2(editor, sources);
345354
+ return tocSuccess2(resolved.nodeId);
344950
345355
  }
344951
345356
  function getPageMap2(editor) {
344952
345357
  const storage = editor.storage;
@@ -345070,7 +345475,7 @@ function createTableOfContentsWrapper2(editor, input2, options) {
345070
345475
  }
345071
345476
  const config41 = input2.config ? applyTocPatchTyped2(DEFAULT_TOC_CONFIG2, input2.config) : DEFAULT_TOC_CONFIG2;
345072
345477
  const instruction = serializeTocInstruction2(config41);
345073
- const content5 = materializeTocContent2(editor.state.doc, withRightAlign2(config41, input2.config?.rightAlignPageNumbers), editor);
345478
+ const { content: content5, sources } = materializeTocContent2(editor.state.doc, withRightAlign2(config41, input2.config?.rightAlignPageNumbers), editor);
345074
345479
  const sdBlockId = v42();
345075
345480
  if (options?.dryRun) {
345076
345481
  return { success: true, toc: buildTocAddress2("(dry-run)") };
@@ -345116,6 +345521,7 @@ function createTableOfContentsWrapper2(editor, input2, options) {
345116
345521
  }
345117
345522
  };
345118
345523
  }
345524
+ syncTocBookmarks2(editor, sources);
345119
345525
  const postMutationId = resolvePostMutationTocId2(editor.state.doc, sdBlockId);
345120
345526
  return { success: true, toc: buildTocAddress2(postMutationId) };
345121
345527
  }
@@ -346416,13 +346822,13 @@ function getLinkMarkType2(editor) {
346416
346822
  }
346417
346823
  return markType;
346418
346824
  }
346419
- function dispatchTransaction2(editor, tr) {
346825
+ function dispatchTransaction3(editor, tr) {
346420
346826
  editor.dispatch(tr);
346421
346827
  }
346422
346828
  function dispatchIfChanged2(editor, tr) {
346423
346829
  if (!tr.docChanged)
346424
346830
  return false;
346425
- dispatchTransaction2(editor, tr);
346831
+ dispatchTransaction3(editor, tr);
346426
346832
  return true;
346427
346833
  }
346428
346834
  function createRelationshipId2(editor, href) {
@@ -346468,7 +346874,7 @@ function wrapWithLink2(editor, from4, to, spec) {
346468
346874
  const tr = editor.state.tr;
346469
346875
  tr.addMark(from4, to, linkMarkType.create(attrs));
346470
346876
  applyDirectMutationMeta2(tr);
346471
- dispatchTransaction2(editor, tr);
346877
+ dispatchTransaction3(editor, tr);
346472
346878
  return true;
346473
346879
  }
346474
346880
  function insertLinkedText2(editor, pos, text9, spec) {
@@ -346479,7 +346885,7 @@ function insertLinkedText2(editor, pos, text9, spec) {
346479
346885
  tr.insertText(text9, pos);
346480
346886
  tr.addMark(pos, pos + text9.length, mark2);
346481
346887
  applyDirectMutationMeta2(tr);
346482
- dispatchTransaction2(editor, tr);
346888
+ dispatchTransaction3(editor, tr);
346483
346889
  return true;
346484
346890
  }
346485
346891
  function patchLinkMark2(editor, from4, to, existingMark, patch3) {
@@ -346529,7 +346935,7 @@ function deleteLinkedText2(editor, from4, to) {
346529
346935
  const tr = editor.state.tr;
346530
346936
  tr.delete(from4, to);
346531
346937
  applyDirectMutationMeta2(tr);
346532
- dispatchTransaction2(editor, tr);
346938
+ dispatchTransaction3(editor, tr);
346533
346939
  return true;
346534
346940
  }
346535
346941
  var init_hyperlink_mutation_helper = __esm(() => {
@@ -347001,7 +347407,7 @@ function executeSdtMutation2(editor, target, options, handler3) {
347001
347407
  }
347002
347408
  return buildMutationSuccess2(target, updatedRef);
347003
347409
  }
347004
- function dispatchTransaction3(editor, tr) {
347410
+ function dispatchTransaction4(editor, tr) {
347005
347411
  if (editor.view?.dispatch) {
347006
347412
  editor.view.dispatch(tr);
347007
347413
  return;
@@ -347086,7 +347492,7 @@ function replaceSdtTextContent2(editor, target, text9) {
347086
347492
  const updatedNode2 = resolved.node.type.create({ ...resolved.node.attrs }, null, resolved.node.marks);
347087
347493
  const { tr: tr2 } = editor.state;
347088
347494
  tr2.replaceWith(resolved.pos, resolved.pos + resolved.node.nodeSize, updatedNode2);
347089
- dispatchTransaction3(editor, tr2);
347495
+ dispatchTransaction4(editor, tr2);
347090
347496
  return true;
347091
347497
  }
347092
347498
  const paragraph4 = buildEmptyBlockContent2(editor, resolved.node);
@@ -347095,7 +347501,7 @@ function replaceSdtTextContent2(editor, target, text9) {
347095
347501
  const updatedNode = resolved.node.type.create({ ...resolved.node.attrs }, updatedParagraph, resolved.node.marks);
347096
347502
  const { tr } = editor.state;
347097
347503
  tr.replaceWith(resolved.pos, resolved.pos + resolved.node.nodeSize, updatedNode);
347098
- dispatchTransaction3(editor, tr);
347504
+ dispatchTransaction4(editor, tr);
347099
347505
  return true;
347100
347506
  }
347101
347507
  function listWrapper2(editor, query2) {
@@ -347189,7 +347595,7 @@ function wrapWrapper2(editor, input2, options) {
347189
347595
  const wrapperNode = nodeType.create({ id: id2, tag: input2.tag, alias: input2.alias, lockMode: input2.lockMode ?? "unlocked" }, resolved.node);
347190
347596
  const { tr } = editor.state;
347191
347597
  tr.replaceWith(resolved.pos, resolved.pos + resolved.node.nodeSize, wrapperNode);
347192
- dispatchTransaction3(editor, tr);
347598
+ dispatchTransaction4(editor, tr);
347193
347599
  return wrapperTarget;
347194
347600
  });
347195
347601
  }
@@ -347201,7 +347607,7 @@ function unwrapWrapper2(editor, input2, options) {
347201
347607
  const resolved = resolveSdtByTarget2(editor.state.doc, input2.target);
347202
347608
  const { tr } = editor.state;
347203
347609
  tr.replaceWith(resolved.pos, resolved.pos + resolved.node.nodeSize, resolved.node.content);
347204
- dispatchTransaction3(editor, tr);
347610
+ dispatchTransaction4(editor, tr);
347205
347611
  return true;
347206
347612
  });
347207
347613
  }
@@ -347228,7 +347634,7 @@ function copyWrapper2(editor, input2, options) {
347228
347634
  const { tr } = editor.state;
347229
347635
  const insertPos = dest.pos + dest.node.nodeSize;
347230
347636
  tr.insert(insertPos, cloned);
347231
- dispatchTransaction3(editor, tr);
347637
+ dispatchTransaction4(editor, tr);
347232
347638
  return { kind: source.kind, nodeType: "sdt", nodeId: newId };
347233
347639
  });
347234
347640
  }
@@ -347243,7 +347649,7 @@ function moveWrapper2(editor, input2, options) {
347243
347649
  const destAfterDelete = resolveSdtByTarget2(tr.doc, input2.destination);
347244
347650
  const insertPos = destAfterDelete.pos + destAfterDelete.node.nodeSize;
347245
347651
  tr.insert(insertPos, source.node);
347246
- dispatchTransaction3(editor, tr);
347652
+ dispatchTransaction4(editor, tr);
347247
347653
  return true;
347248
347654
  });
347249
347655
  }
@@ -347519,7 +347925,7 @@ function insertBeforeWrapper2(editor, input2, options) {
347519
347925
  const textNode = editor.schema.text(input2.content);
347520
347926
  const { tr } = editor.state;
347521
347927
  tr.insert(resolved.pos, textNode);
347522
- dispatchTransaction3(editor, tr);
347928
+ dispatchTransaction4(editor, tr);
347523
347929
  return true;
347524
347930
  });
347525
347931
  }
@@ -347532,7 +347938,7 @@ function insertAfterWrapper2(editor, input2, options) {
347532
347938
  const textNode = editor.schema.text(input2.content);
347533
347939
  const { tr } = editor.state;
347534
347940
  tr.insert(insertPos, textNode);
347535
- dispatchTransaction3(editor, tr);
347941
+ dispatchTransaction4(editor, tr);
347536
347942
  return true;
347537
347943
  });
347538
347944
  }
@@ -347920,7 +348326,7 @@ function repeatingSectionInsertItemBeforeWrapper2(editor, input2, options) {
347920
348326
  const newItem = nodeType.create({ id: generateSdtId2(), controlType: "repeatingSectionItem", type: "repeatingSectionItem" }, paragraph4);
347921
348327
  const { tr } = editor.state;
347922
348328
  tr.insert(insertPos, newItem);
347923
- dispatchTransaction3(editor, tr);
348329
+ dispatchTransaction4(editor, tr);
347924
348330
  return true;
347925
348331
  });
347926
348332
  }
@@ -347942,7 +348348,7 @@ function repeatingSectionInsertItemAfterWrapper2(editor, input2, options) {
347942
348348
  const newItem = nodeType.create({ id: generateSdtId2(), controlType: "repeatingSectionItem", type: "repeatingSectionItem" }, paragraph4);
347943
348349
  const { tr } = editor.state;
347944
348350
  tr.insert(insertPos, newItem);
347945
- dispatchTransaction3(editor, tr);
348351
+ dispatchTransaction4(editor, tr);
347946
348352
  return true;
347947
348353
  });
347948
348354
  }
@@ -347962,7 +348368,7 @@ function repeatingSectionCloneItemWrapper2(editor, input2, options) {
347962
348368
  const insertPos = sourceItem.pos + sourceItem.node.nodeSize;
347963
348369
  const { tr } = editor.state;
347964
348370
  tr.insert(insertPos, cloned);
347965
- dispatchTransaction3(editor, tr);
348371
+ dispatchTransaction4(editor, tr);
347966
348372
  return true;
347967
348373
  });
347968
348374
  }
@@ -347980,7 +348386,7 @@ function repeatingSectionDeleteItemWrapper2(editor, input2, options) {
347980
348386
  const item = items[input2.index];
347981
348387
  const { tr } = editor.state;
347982
348388
  tr.delete(item.pos, item.pos + item.node.nodeSize);
347983
- dispatchTransaction3(editor, tr);
348389
+ dispatchTransaction4(editor, tr);
347984
348390
  return true;
347985
348391
  });
347986
348392
  }
@@ -348005,7 +348411,7 @@ function groupWrapWrapper2(editor, input2, options) {
348005
348411
  const groupNode = groupNodeType.create({ id: groupId, controlType: "group", type: "group" }, resolved.node);
348006
348412
  const { tr } = editor.state;
348007
348413
  tr.replaceWith(resolved.pos, resolved.pos + resolved.node.nodeSize, groupNode);
348008
- dispatchTransaction3(editor, tr);
348414
+ dispatchTransaction4(editor, tr);
348009
348415
  return { kind: "block", nodeType: "sdt", nodeId: groupId };
348010
348416
  });
348011
348417
  }
@@ -348018,7 +348424,7 @@ function groupUngroupWrapper2(editor, input2, options) {
348018
348424
  const resolved = resolveSdtByTarget2(editor.state.doc, input2.target);
348019
348425
  const { tr } = editor.state;
348020
348426
  tr.replaceWith(resolved.pos, resolved.pos + resolved.node.nodeSize, resolved.node.content);
348021
- dispatchTransaction3(editor, tr);
348427
+ dispatchTransaction4(editor, tr);
348022
348428
  return true;
348023
348429
  });
348024
348430
  }
@@ -348073,7 +348479,7 @@ function createWrapper2(editor, input2, options) {
348073
348479
  const insertPos = ref4.pos + ref4.node.nodeSize;
348074
348480
  const { tr } = editor.state;
348075
348481
  tr.insert(insertPos, newNode);
348076
- dispatchTransaction3(editor, tr);
348482
+ dispatchTransaction4(editor, tr);
348077
348483
  return true;
348078
348484
  }
348079
348485
  if (contentText !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.3.0-next.16",
3
+ "version": "0.3.0-next.17",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -21,20 +21,20 @@
21
21
  "@types/node": "22.19.2",
22
22
  "typescript": "^5.9.2",
23
23
  "@superdoc/document-api": "0.0.1",
24
- "@superdoc/pm-adapter": "0.0.0",
24
+ "superdoc": "1.19.0",
25
25
  "@superdoc/super-editor": "0.0.1",
26
- "superdoc": "1.19.0"
26
+ "@superdoc/pm-adapter": "0.0.0"
27
27
  },
28
28
  "module": "src/index.ts",
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@superdoc-dev/cli-darwin-arm64": "0.3.0-next.16",
34
- "@superdoc-dev/cli-linux-x64": "0.3.0-next.16",
35
- "@superdoc-dev/cli-linux-arm64": "0.3.0-next.16",
36
- "@superdoc-dev/cli-windows-x64": "0.3.0-next.16",
37
- "@superdoc-dev/cli-darwin-x64": "0.3.0-next.16"
33
+ "@superdoc-dev/cli-darwin-arm64": "0.3.0-next.17",
34
+ "@superdoc-dev/cli-darwin-x64": "0.3.0-next.17",
35
+ "@superdoc-dev/cli-linux-x64": "0.3.0-next.17",
36
+ "@superdoc-dev/cli-windows-x64": "0.3.0-next.17",
37
+ "@superdoc-dev/cli-linux-arm64": "0.3.0-next.17"
38
38
  },
39
39
  "scripts": {
40
40
  "dev": "bun run src/index.ts",