@beyondwork/docx-react-component 1.0.126 → 1.0.128

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 (59) hide show
  1. package/dist/api/public-types.d.cts +1 -1
  2. package/dist/api/public-types.d.ts +1 -1
  3. package/dist/api/v3.cjs +507 -24
  4. package/dist/api/v3.d.cts +2 -2
  5. package/dist/api/v3.d.ts +2 -2
  6. package/dist/api/v3.js +2 -2
  7. package/dist/{chunk-GL7XRYBY.js → chunk-6EROGFUF.js} +29 -13
  8. package/dist/{chunk-6IGWPAR4.js → chunk-LCYYR57Q.js} +462 -24
  9. package/dist/{chunk-4G3OS2H6.js → chunk-LZVBNDGU.js} +3 -0
  10. package/dist/{chunk-FPRWV54X.js → chunk-XRACP43Q.js} +46 -1
  11. package/dist/core/commands/formatting-commands.d.cts +1 -1
  12. package/dist/core/commands/formatting-commands.d.ts +1 -1
  13. package/dist/core/commands/image-commands.d.cts +1 -1
  14. package/dist/core/commands/image-commands.d.ts +1 -1
  15. package/dist/core/commands/section-layout-commands.d.cts +1 -1
  16. package/dist/core/commands/section-layout-commands.d.ts +1 -1
  17. package/dist/core/commands/style-commands.d.cts +1 -1
  18. package/dist/core/commands/style-commands.d.ts +1 -1
  19. package/dist/core/commands/table-structure-commands.d.cts +1 -1
  20. package/dist/core/commands/table-structure-commands.d.ts +1 -1
  21. package/dist/core/commands/text-commands.cjs +3 -0
  22. package/dist/core/commands/text-commands.d.cts +2 -1
  23. package/dist/core/commands/text-commands.d.ts +2 -1
  24. package/dist/core/commands/text-commands.js +1 -1
  25. package/dist/core/selection/mapping.d.cts +1 -1
  26. package/dist/core/selection/mapping.d.ts +1 -1
  27. package/dist/core/state/editor-state.d.cts +1 -1
  28. package/dist/core/state/editor-state.d.ts +1 -1
  29. package/dist/index.cjs +549 -37
  30. package/dist/index.d.cts +4 -4
  31. package/dist/index.d.ts +4 -4
  32. package/dist/index.js +16 -6
  33. package/dist/io/docx-session.d.cts +3 -3
  34. package/dist/io/docx-session.d.ts +3 -3
  35. package/dist/{loader-CS9-9KFa.d.ts → loader-19ct2Be0.d.ts} +2 -2
  36. package/dist/{loader-OoWJ1_17.d.cts → loader-CoXQ2wGd.d.cts} +2 -2
  37. package/dist/{public-types-DdcHqcow.d.ts → public-types-7KZsNGE2.d.ts} +93 -0
  38. package/dist/{public-types-BP3vqJR5.d.cts → public-types-B-CskQen.d.cts} +93 -0
  39. package/dist/public-types.d.cts +1 -1
  40. package/dist/public-types.d.ts +1 -1
  41. package/dist/runtime/collab.d.cts +2 -2
  42. package/dist/runtime/collab.d.ts +2 -2
  43. package/dist/runtime/document-runtime.cjs +76 -12
  44. package/dist/runtime/document-runtime.d.cts +1 -1
  45. package/dist/runtime/document-runtime.d.ts +1 -1
  46. package/dist/runtime/document-runtime.js +3 -3
  47. package/dist/{session-Cq-fzx3B.d.cts → session-B5015J4v.d.cts} +2 -2
  48. package/dist/{session-DyFQt8Ph.d.ts → session-C2i8-d6v.d.ts} +2 -2
  49. package/dist/session.d.cts +4 -4
  50. package/dist/session.d.ts +4 -4
  51. package/dist/tailwind.d.cts +1 -1
  52. package/dist/tailwind.d.ts +1 -1
  53. package/dist/{types-Bg7D-GD3.d.cts → types-DNhN0WeN.d.cts} +1 -1
  54. package/dist/{types-bJAgMq1M.d.ts → types-yvrQuGX9.d.ts} +1 -1
  55. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +2 -2
  56. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +2 -2
  57. package/dist/ui-tailwind.d.cts +2 -2
  58. package/dist/ui-tailwind.d.ts +2 -2
  59. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -28074,6 +28074,9 @@ function splitParagraph(document2, selection, context) {
28074
28074
  if (scope?.kind !== "top-level") {
28075
28075
  return result;
28076
28076
  }
28077
+ if (context.preserveNumberingOnSplit && scope.paragraph.numbering) {
28078
+ return result;
28079
+ }
28077
28080
  const originalStyleId = scope.paragraph.styleId;
28078
28081
  const nextStyleId = originalStyleId !== void 0 ? resolveNextStyle(originalStyleId, document2.styles) : void 0;
28079
28082
  if (nextStyleId !== void 0) {
@@ -52092,7 +52095,52 @@ function compileReplacement(inputs) {
52092
52095
 
52093
52096
  // src/runtime/scopes/replacement/apply.ts
52094
52097
  function documentHash2(doc) {
52095
- return JSON.stringify(doc.content);
52098
+ let hash = 2166136261;
52099
+ const mix = (value) => {
52100
+ for (let i = 0; i < value.length; i += 1) {
52101
+ hash ^= value.charCodeAt(i);
52102
+ hash = Math.imul(hash, 16777619);
52103
+ }
52104
+ };
52105
+ const visit = (value) => {
52106
+ if (value === null) {
52107
+ mix("null");
52108
+ return;
52109
+ }
52110
+ switch (typeof value) {
52111
+ case "string":
52112
+ case "number":
52113
+ case "boolean":
52114
+ case "bigint":
52115
+ mix(`${typeof value}:${String(value)}`);
52116
+ return;
52117
+ case "undefined":
52118
+ mix("undefined");
52119
+ return;
52120
+ case "object":
52121
+ if (Array.isArray(value)) {
52122
+ mix(`[${value.length}`);
52123
+ for (const item of value) visit(item);
52124
+ mix("]");
52125
+ return;
52126
+ }
52127
+ {
52128
+ const record = value;
52129
+ const keys = Object.keys(record).sort();
52130
+ mix(`{${keys.length}`);
52131
+ for (const key of keys) {
52132
+ mix(key);
52133
+ visit(record[key]);
52134
+ }
52135
+ mix("}");
52136
+ }
52137
+ return;
52138
+ default:
52139
+ mix(typeof value);
52140
+ }
52141
+ };
52142
+ visit(doc.content);
52143
+ return (hash >>> 0).toString(36).padStart(7, "0");
52096
52144
  }
52097
52145
  function compileScopeById(document2, overlay, scopeId) {
52098
52146
  const paragraphIndexByBlockIndex = buildParagraphIndexMap(document2);
@@ -69250,15 +69298,17 @@ function createDocumentRuntime(options) {
69250
69298
  ...resolution.textTarget ? { textTarget: resolution.textTarget } : {}
69251
69299
  };
69252
69300
  }
69253
- function prepareFragmentInsertCommandForExecution(command, document2, surface, storyTarget) {
69301
+ function prepareFragmentInsertCommandForExecution(command, document2, surface, storyTarget, selection) {
69254
69302
  if (!command.editableTarget) {
69255
- return { kind: "accepted", selection: state.selection };
69303
+ return { kind: "accepted", selection };
69256
69304
  }
69305
+ const preserveCallerSelection = command.editableTarget.listAddress?.operationScope === "list-text";
69257
69306
  const resolution = resolveEditableTextTarget({
69258
69307
  document: document2,
69259
69308
  surface,
69260
69309
  target: command.editableTarget,
69261
69310
  activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
69311
+ ...preserveCallerSelection ? { selection } : {},
69262
69312
  editableTargetCache: editableTargetBlockCache
69263
69313
  });
69264
69314
  if (resolution.kind === "rejected") {
@@ -69276,7 +69326,7 @@ function createDocumentRuntime(options) {
69276
69326
  }
69277
69327
  return {
69278
69328
  kind: "accepted",
69279
- selection: createSelectionSnapshot(resolution.range.from, resolution.range.to),
69329
+ selection: preserveCallerSelection ? selection : createSelectionSnapshot(resolution.range.from, resolution.range.to),
69280
69330
  ...resolution.textTarget ? { textTarget: resolution.textTarget } : {}
69281
69331
  };
69282
69332
  }
@@ -69448,7 +69498,8 @@ function createDocumentRuntime(options) {
69448
69498
  command,
69449
69499
  state.document,
69450
69500
  cachedRenderSnapshot.surface?.blocks ?? [],
69451
- activeStory
69501
+ activeStory,
69502
+ commandSelection
69452
69503
  );
69453
69504
  if (prepared.kind === "rejected") {
69454
69505
  return;
@@ -69611,7 +69662,8 @@ function createDocumentRuntime(options) {
69611
69662
  command,
69612
69663
  replayState.document,
69613
69664
  replaySnapshot.surface?.blocks ?? [],
69614
- replayStory
69665
+ replayStory,
69666
+ replayState.selection
69615
69667
  );
69616
69668
  if (prepared.kind === "rejected") {
69617
69669
  return;
@@ -69754,7 +69806,8 @@ function createDocumentRuntime(options) {
69754
69806
  command,
69755
69807
  stateForCommand.document,
69756
69808
  snapshotForCommand.surface?.blocks ?? [],
69757
- replayStory
69809
+ replayStory,
69810
+ stateForCommand.selection
69758
69811
  );
69759
69812
  if (prepared.kind === "rejected") {
69760
69813
  continue;
@@ -70318,7 +70371,7 @@ function createDocumentRuntime(options) {
70318
70371
  try {
70319
70372
  const timestamp = clock();
70320
70373
  const selection = target ? createSelectionFromPublicAnchor(target) : state.selection;
70321
- const editableTarget = editContext?.editableTarget && isTableParagraphEditableTarget(editContext.editableTarget) ? editContext.editableTarget : inferEditableTargetForFragmentInsert(
70374
+ const editableTarget = editContext?.editableTarget && isFragmentInsertEditableTarget(editContext.editableTarget) ? editContext.editableTarget : inferEditableTargetForFragmentInsert(
70322
70375
  cachedRenderSnapshot.surface?.blocks ?? [],
70323
70376
  selection
70324
70377
  );
@@ -72125,7 +72178,8 @@ function createDocumentRuntime(options) {
72125
72178
  blockedReasons: [blockedReason]
72126
72179
  });
72127
72180
  }
72128
- const textTarget = targetResolution?.kind === "accepted" ? targetResolution.textTarget : legacyTextTarget;
72181
+ const listBoundaryDeleteUsesStoryText = targetResolution?.kind === "accepted" && editableTarget?.listAddress?.operationScope === "list-text" && isTopLevelMainStoryBlockPath(editableTarget.blockPath) && selection.isCollapsed && (commandForDispatch.type === "text.delete-backward" && selection.anchor === targetResolution.range.from || commandForDispatch.type === "text.delete-forward" && selection.anchor === targetResolution.range.to);
72182
+ const textTarget = targetResolution?.kind === "accepted" && !listBoundaryDeleteUsesStoryText ? targetResolution.textTarget : legacyTextTarget;
72129
72183
  const context = {
72130
72184
  timestamp,
72131
72185
  documentMode: textOptions.documentModeOverride ?? workflowCoordinator.getEffectiveDocumentMode(selection),
@@ -72135,6 +72189,7 @@ function createDocumentRuntime(options) {
72135
72189
  editableTargetCache: editableTargetBlockCache,
72136
72190
  activeStorySize: cachedRenderSnapshot.surface?.storySize,
72137
72191
  textTarget,
72192
+ preserveNumberingOnSplit: (commandForDispatch.type === "paragraph.split" || commandForDispatch.type === "fragment.insert") && targetResolution?.kind === "accepted" && editableTarget?.listAddress?.operationScope === "list-text",
72138
72193
  rejectTargetlessTableStructureInsert: true
72139
72194
  };
72140
72195
  const baseState = selection === state.selection ? state : {
@@ -72956,7 +73011,7 @@ function canonicalEditableTargetStoryKey(storyTarget) {
72956
73011
  function inferEditableTargetForFragmentInsert(blocks, selection) {
72957
73012
  const position = Math.min(selection.anchor, selection.head);
72958
73013
  const target = findEditableTargetAtSurfacePosition(blocks, position);
72959
- return target && isTableParagraphEditableTarget(target) ? target : void 0;
73014
+ return target && isFragmentInsertEditableTarget(target) ? target : void 0;
72960
73015
  }
72961
73016
  function findEditableTargetAtSurfacePosition(blocks, position) {
72962
73017
  for (const block of blocks) {
@@ -72985,8 +73040,14 @@ function findEditableTargetInSurfaceCell(cell, position) {
72985
73040
  }
72986
73041
  return findEditableTargetAtSurfacePosition(cell.content, position);
72987
73042
  }
72988
- function isTableParagraphEditableTarget(target) {
72989
- return target.editability === "editable" && target.posture.blockers.length === 0 && target.commandFamily === "text-leaf" && (target.kind === "table-cell-paragraph-text" || target.kind === "nested-table-cell-paragraph-text" || target.kind === "sdt-table-cell-paragraph-text");
73043
+ function isFragmentInsertEditableTarget(target) {
73044
+ if (target.editability !== "editable" || target.posture.blockers.length > 0 || target.commandFamily !== "text-leaf") {
73045
+ return false;
73046
+ }
73047
+ if (target.listAddress?.operationScope === "list-text") {
73048
+ return true;
73049
+ }
73050
+ return target.kind === "table-cell-paragraph-text" || target.kind === "nested-table-cell-paragraph-text" || target.kind === "sdt-table-cell-paragraph-text";
72990
73051
  }
72991
73052
  function extractSelectionFragment(document2, selection, activeStory) {
72992
73053
  const from = Math.min(selection.anchor, selection.head);
@@ -74983,6 +75044,9 @@ function stripStoryTarget2(selection) {
74983
75044
  const { storyTarget: _storyTarget, ...rest } = selection;
74984
75045
  return rest;
74985
75046
  }
75047
+ function isTopLevelMainStoryBlockPath(blockPath) {
75048
+ return typeof blockPath === "string" && /^main\/block\[\d+\]$/u.test(blockPath);
75049
+ }
74986
75050
  function toInternalSelectionSnapshot2(selection) {
74987
75051
  return {
74988
75052
  anchor: selection.anchor,
@@ -127907,6 +127971,18 @@ function createTableActionFamily(runtime) {
127907
127971
  }
127908
127972
  };
127909
127973
  }
127974
+ function findTableActionDescriptor(runtime, actionHandle) {
127975
+ const document2 = runtime.getCanonicalDocument();
127976
+ const seed = documentSeed(runtime);
127977
+ const surface = runtime.getRenderSnapshot().surface?.blocks ?? [];
127978
+ for (const target of collectEditableTargetRefs(document2)) {
127979
+ if (!target.table || callableOperationsForScope(target.table.operationScope).length === 0 || tableActionHandle(seed, target.targetKey) !== actionHandle || !isResolvableCurrentTableActionTarget(runtime, surface, target)) {
127980
+ continue;
127981
+ }
127982
+ return projectCurrentTableTarget(document2, seed, target);
127983
+ }
127984
+ return null;
127985
+ }
127910
127986
  function isSupportedTableActionEvidence(entry) {
127911
127987
  return isSupportedTableStructureEvidence(entry) || isSupportedTableTextEvidence(entry);
127912
127988
  }
@@ -127925,6 +128001,7 @@ function projectTableActionDescriptor(document2, seed, entry) {
127925
128001
  const callableOperations = callableOperationsForScope(scope);
127926
128002
  const supportedOperations = operationsForScope(scope);
127927
128003
  if (callableOperations.length === 0) return [];
128004
+ const selectionRequiredOperations = selectionRequiredOperationsForScope(scope);
127928
128005
  return [
127929
128006
  {
127930
128007
  actionHandle: tableActionHandle(seed, entry.targetKey),
@@ -127933,6 +128010,7 @@ function projectTableActionDescriptor(document2, seed, entry) {
127933
128010
  relation: entry.relation,
127934
128011
  operationScope: scope,
127935
128012
  callableOperations,
128013
+ ...selectionRequiredOperations.length > 0 ? { selectionRequiredOperations } : {},
127936
128014
  supportedOperations,
127937
128015
  ...scope === "text" ? { readback: tableTextReadback(readBlockPathText(document2, entry.blockPath)) } : {},
127938
128016
  reason: entry.runtimeCommand.reason
@@ -127944,6 +128022,7 @@ function projectCurrentTableTarget(document2, seed, target) {
127944
128022
  if (!table) return null;
127945
128023
  const callableOperations = callableOperationsForScope(table.operationScope);
127946
128024
  if (callableOperations.length === 0) return null;
128025
+ const selectionRequiredOperations = selectionRequiredOperationsForScope(table.operationScope);
127947
128026
  return {
127948
128027
  actionHandle: tableActionHandle(seed, target.targetKey),
127949
128028
  family: table.operationScope === "text" ? "table-text" : "table-structure",
@@ -127951,6 +128030,7 @@ function projectCurrentTableTarget(document2, seed, target) {
127951
128030
  relation: "contained-by-scope",
127952
128031
  operationScope: table.operationScope,
127953
128032
  callableOperations,
128033
+ ...selectionRequiredOperations.length > 0 ? { selectionRequiredOperations } : {},
127954
128034
  supportedOperations: operationsForScope(table.operationScope),
127955
128035
  ...table.operationScope === "text" ? { readback: tableTextReadback(readEditableTargetText(document2, target)) } : {},
127956
128036
  reason: table.operationScope === "text" ? "l07:table-text-target-supported" : "l07:table-structure-target-supported"
@@ -128028,11 +128108,14 @@ function callableOperationsForScope(scope) {
128028
128108
  case "text":
128029
128109
  return TEXT_TRANSFER_OPERATIONS;
128030
128110
  case "cell":
128031
- return [...CELL_STRUCTURE_OPERATIONS, "merge-cells"];
128111
+ return CELL_STRUCTURE_OPERATIONS;
128032
128112
  default:
128033
128113
  return operationsForScope(scope);
128034
128114
  }
128035
128115
  }
128116
+ function selectionRequiredOperationsForScope(scope) {
128117
+ return scope === "cell" ? ["merge-cells"] : [];
128118
+ }
128036
128119
  function operationsForScope(scope) {
128037
128120
  switch (scope) {
128038
128121
  case "text":
@@ -128390,6 +128473,31 @@ var hyperlinkTextEditMetadata = actionMethodMetadata(
128390
128473
  expectedDelta: "hyperlink display text changes"
128391
128474
  }
128392
128475
  );
128476
+ var validateTemplateTargetsMetadata = actionMethodMetadata(
128477
+ "validateTemplateTargets",
128478
+ "read",
128479
+ "actions-template-targets",
128480
+ "Validate template field/clause targets against current document readback, duplicate ranges, and exact action/scope handles before fill.",
128481
+ { uiVisible: false, expectsUxResponse: "none" }
128482
+ );
128483
+ var templateTargetReadMetadata = actionMethodMetadata(
128484
+ "templateTargetRead",
128485
+ "read",
128486
+ "actions-template-targets",
128487
+ "Read a template field/clause target through its exact scope/action handle when present, or diagnostic placeholder occurrence evidence otherwise.",
128488
+ { uiVisible: false, expectsUxResponse: "none" }
128489
+ );
128490
+ var templateFieldFillMetadata = actionMethodMetadata(
128491
+ "templateFieldFill",
128492
+ "mutate",
128493
+ "actions-template-targets",
128494
+ "Fill one template field only through an exact scope/action handle after same-target readback validation; raw ranges are diagnostics only.",
128495
+ {
128496
+ uiVisible: true,
128497
+ expectsUxResponse: "inline-change",
128498
+ expectedDelta: "the exact template field target text changes"
128499
+ }
128500
+ );
128393
128501
  var listOperationMetadata = actionMethodMetadata(
128394
128502
  "listOperation",
128395
128503
  "mutate",
@@ -128450,6 +128558,9 @@ var ACTION_METHODS = Object.freeze([
128450
128558
  "bookmarkEdit",
128451
128559
  "hyperlinkDestinationEdit",
128452
128560
  "hyperlinkTextEdit",
128561
+ "validateTemplateTargets",
128562
+ "templateTargetRead",
128563
+ "templateFieldFill",
128453
128564
  "listOperation",
128454
128565
  "tableFragment",
128455
128566
  "tableSelection",
@@ -128459,9 +128570,6 @@ var DEFAULT_LOCATE_LIMIT = 20;
128459
128570
  var DEFAULT_REWRITE_ALL_LIMIT = 10;
128460
128571
  var DEFAULT_TABLE_TEXT_SCOPE_LIMIT = 3;
128461
128572
  var DEFAULT_PLAN_STEP_LIMIT = 20;
128462
- function documentContentHash(runtime) {
128463
- return JSON.stringify(runtime.getCanonicalDocument().content);
128464
- }
128465
128573
  function createActionsFamily(runtime) {
128466
128574
  const category = {
128467
128575
  discover(input) {
@@ -128821,6 +128929,25 @@ function createActionsFamily(runtime) {
128821
128929
  origin: input.origin
128822
128930
  });
128823
128931
  },
128932
+ validateTemplateTargets(input) {
128933
+ return validateTemplateTargets(runtime, input);
128934
+ },
128935
+ templateTargetRead(input) {
128936
+ const item = validateTemplateTarget(runtime, input.target, {
128937
+ duplicateRanges: /* @__PURE__ */ new Set(),
128938
+ allowDuplicateRanges: true
128939
+ });
128940
+ return {
128941
+ status: item.status === "blocked" ? "blocked" : "read",
128942
+ ...item.target ? { target: item.target } : {},
128943
+ ...item.readback ? { readback: item.readback } : {},
128944
+ ...item.blockers ? { blockers: item.blockers } : {},
128945
+ ...item.blockerDetails ? { blockerDetails: item.blockerDetails } : {}
128946
+ };
128947
+ },
128948
+ templateFieldFill(input) {
128949
+ return applyTemplateFieldFill(runtime, input);
128950
+ },
128824
128951
  listOperation(input) {
128825
128952
  return applyListOperation(runtime, input);
128826
128953
  },
@@ -128890,6 +129017,9 @@ function runPlanStep(runtime, mode, step, plan) {
128890
129017
  if (step.kind === "tableAction" || step.kind === "tableFragment" || step.kind === "tableSelection") {
128891
129018
  return runPlanTableActionStep(runtime, mode, step, plan);
128892
129019
  }
129020
+ if (step.kind === "templateFieldFill") {
129021
+ return runPlanTemplateFieldFillStep(runtime, mode, step, plan);
129022
+ }
128893
129023
  const before = step.target ? readPlanTarget(runtime, step.target) : readDocumentPlanTarget(runtime);
128894
129024
  if (!before.ok) {
128895
129025
  return blockedPlanStepFromDetails(step.id, step.kind, before.blockerDetails);
@@ -128934,10 +129064,10 @@ function runPlanStep(runtime, mode, step, plan) {
128934
129064
  ...before.readback ? { beforeReadback: before.readback } : {}
128935
129065
  };
128936
129066
  }
128937
- const documentHashBeforeApply = documentContentHash(runtime);
129067
+ const documentBeforeApply = runtime.getCanonicalDocument();
128938
129068
  const applied = applyPlanStep(runtime, step, plan);
128939
- const documentHashAfterApply = documentContentHash(runtime);
128940
- const projectedApply = !applied.applied && documentHashAfterApply !== documentHashBeforeApply ? withSuspectMutationApplyResult(applied, step.id, applied.target ?? before.target) : applied;
129069
+ const documentAfterApply = runtime.getCanonicalDocument();
129070
+ const projectedApply = !applied.applied && documentAfterApply !== documentBeforeApply ? withSuspectMutationApplyResult(applied, step.id, applied.target ?? before.target) : applied;
128941
129071
  const after = step.kind === "flag" ? before : step.target ? readPlanTarget(runtime, step.target) : before;
128942
129072
  return {
128943
129073
  id: step.id,
@@ -128988,7 +129118,8 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
128988
129118
  tableAction: tableAction2
128989
129119
  });
128990
129120
  }
128991
- if (!operationKind || !tableAction2.callableOperations.includes(operationKind)) {
129121
+ const isSelectionRequiredOperation = step.kind === "tableSelection" && operationKind !== void 0 && (tableAction2.selectionRequiredOperations ?? []).includes(operationKind) && tableSelectionStepHasDescriptor(step.operation);
129122
+ if (!operationKind || !tableAction2.callableOperations.includes(operationKind) && !isSelectionRequiredOperation) {
128992
129123
  return blockedPlanStepFromDetails(
128993
129124
  step.id,
128994
129125
  step.kind,
@@ -129048,6 +129179,72 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
129048
129179
  ...result.commandReference ? { commandReference: result.commandReference } : {}
129049
129180
  };
129050
129181
  }
129182
+ function runPlanTemplateFieldFillStep(runtime, mode, step, plan) {
129183
+ const validation = validateTemplateTarget(runtime, step.field, {
129184
+ duplicateRanges: /* @__PURE__ */ new Set(),
129185
+ allowDuplicateRanges: true
129186
+ });
129187
+ if (validation.status === "blocked" || !validation.canFill) {
129188
+ return blockedPlanStepFromDetails(
129189
+ step.id,
129190
+ step.kind,
129191
+ validation.blockerDetails ?? [
129192
+ blocker(
129193
+ `actions:template-field-fill:not-fillable:${templateTargetDebugId(step.field)}`,
129194
+ "blocked",
129195
+ "The template field target is not backed by an exact fill handle.",
129196
+ "Plant the field through editor APIs and pass the returned scope handle or actionHandle; raw ranges are diagnostics only."
129197
+ )
129198
+ ],
129199
+ {
129200
+ ...validation.target ? { target: validation.target } : {},
129201
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
129202
+ }
129203
+ );
129204
+ }
129205
+ const precondition = checkPlanPreconditions(step, templateReadbackToPlanReadback(validation.readback));
129206
+ if (precondition) {
129207
+ return blockedPlanStepFromDetails(step.id, step.kind, [precondition], {
129208
+ ...validation.target ? { target: validation.target } : {},
129209
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
129210
+ });
129211
+ }
129212
+ if (mode === "preview") {
129213
+ return {
129214
+ id: step.id,
129215
+ kind: step.kind,
129216
+ status: "planned",
129217
+ applied: false,
129218
+ changed: false,
129219
+ ...validation.target ? { target: validation.target } : {},
129220
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
129221
+ };
129222
+ }
129223
+ const applied = applyTemplateFieldFill(runtime, {
129224
+ field: step.field,
129225
+ text: step.text,
129226
+ actorId: step.actorId ?? plan.actorId,
129227
+ origin: step.origin ?? plan.origin,
129228
+ ...step.proposalId ? { proposalId: step.proposalId } : {}
129229
+ });
129230
+ const after = step.field.target ? readPlanTarget(runtime, step.field.target) : null;
129231
+ return {
129232
+ id: step.id,
129233
+ kind: step.kind,
129234
+ status: applied.status === "unsupported" ? "unsupported" : applied.applied ? "applied" : "blocked",
129235
+ applied: applied.applied,
129236
+ changed: applied.changed,
129237
+ ...applied.target ?? validation.target ? { target: applied.target ?? validation.target } : {},
129238
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {},
129239
+ ...after?.ok && after.readback ? { afterReadback: after.readback } : {},
129240
+ ...applied.proposalId ? { proposalId: applied.proposalId } : {},
129241
+ ...applied.posture ? { posture: applied.posture } : {},
129242
+ ...applied.blockers ? { blockers: applied.blockers } : {},
129243
+ ...applied.blockerDetails ? { blockerDetails: applied.blockerDetails } : {},
129244
+ ...applied.auditReference ? { auditReference: applied.auditReference } : {},
129245
+ ...applied.commandReference ? { commandReference: applied.commandReference } : {}
129246
+ };
129247
+ }
129051
129248
  function locateAll(runtime, input) {
129052
129249
  if (!input.query) {
129053
129250
  const detail = blocker(
@@ -129130,6 +129327,310 @@ function locateAll(runtime, input) {
129130
129327
  ...matches.length === 0 ? { blockers: Object.freeze([`actions:locate:not-found:${input.query}`]) } : {}
129131
129328
  };
129132
129329
  }
129330
+ function validateTemplateTargets(runtime, input) {
129331
+ if (!Array.isArray(input.targets) || input.targets.length === 0) {
129332
+ const detail = blocker(
129333
+ "actions:template-targets:empty",
129334
+ "input",
129335
+ "Template target validation requires at least one field or clause target.",
129336
+ "Pass the analyzer targets before saving the template."
129337
+ );
129338
+ return {
129339
+ status: "blocked",
129340
+ targets: Object.freeze([]),
129341
+ blockers: Object.freeze([detail.code]),
129342
+ blockerDetails: Object.freeze([detail])
129343
+ };
129344
+ }
129345
+ const duplicateRanges = /* @__PURE__ */ new Set();
129346
+ const items = input.targets.map(
129347
+ (target) => validateTemplateTarget(runtime, target, {
129348
+ duplicateRanges,
129349
+ allowDuplicateRanges: input.allowDuplicateRanges === true
129350
+ })
129351
+ );
129352
+ const blockers = items.flatMap((item) => item.blockers ?? []);
129353
+ const blockerDetails = items.flatMap((item) => item.blockerDetails ?? []);
129354
+ return {
129355
+ status: blockerDetails.length === 0 ? "valid" : items.some((item) => item.status !== "blocked") ? "partial" : "blocked",
129356
+ targets: Object.freeze(items),
129357
+ ...blockers.length > 0 ? { blockers: Object.freeze(blockers) } : {},
129358
+ ...blockerDetails.length > 0 ? { blockerDetails: Object.freeze(blockerDetails) } : {}
129359
+ };
129360
+ }
129361
+ function validateTemplateTarget(runtime, target, context) {
129362
+ const targetKind = templateTargetKind(target);
129363
+ const details = [];
129364
+ const warnings = [];
129365
+ const expected = templateExpectedText(target);
129366
+ const occurrenceCount = expected ? countOccurrences(documentText(runtime.getCanonicalDocument()), expected) : void 0;
129367
+ const rangeKey = templateLocationKey(target.location);
129368
+ if (target.fieldId && target.clauseId) {
129369
+ details.push(
129370
+ blocker(
129371
+ `actions:template-targets:mixed-field-clause:${templateTargetDebugId(target)}`,
129372
+ "input",
129373
+ "A template target cannot be both a field and a clause.",
129374
+ "Split clause boundaries from fillable fields and save them as separate template targets."
129375
+ )
129376
+ );
129377
+ }
129378
+ if (!expected && !target.target) {
129379
+ details.push(
129380
+ blocker(
129381
+ `actions:template-targets:expected-text-required:${templateTargetDebugId(target)}`,
129382
+ "input",
129383
+ "A template target without an exact handle requires placeholderText or expectedText for validation.",
129384
+ "Store the visible placeholder/current text with the target before saving the template."
129385
+ )
129386
+ );
129387
+ }
129388
+ if (rangeKey && !context.allowDuplicateRanges) {
129389
+ if (context.duplicateRanges.has(rangeKey)) {
129390
+ details.push(
129391
+ blocker(
129392
+ `actions:template-targets:duplicate-range:${rangeKey}`,
129393
+ "ambiguous-target",
129394
+ "More than one template target claims the same document range.",
129395
+ "Create one shared grouped field target, or give each field a distinct occurrence identity."
129396
+ )
129397
+ );
129398
+ } else {
129399
+ context.duplicateRanges.add(rangeKey);
129400
+ }
129401
+ }
129402
+ if (isTableTemplateLocation(target.location) && !hasTableCellIdentity(target.location)) {
129403
+ details.push(
129404
+ blocker(
129405
+ `actions:template-targets:table-cell-identity-required:${templateTargetDebugId(target)}`,
129406
+ "input",
129407
+ "A table template target must carry stable cell identity.",
129408
+ "Include cellSourceRef/cellRefId or row and column identity plus the exact actionHandle returned for the cell text."
129409
+ )
129410
+ );
129411
+ }
129412
+ if (expected && occurrenceCount !== void 0 && occurrenceCount > 1 && !hasOccurrenceIdentity(target) && !target.target) {
129413
+ details.push(
129414
+ blocker(
129415
+ `actions:template-targets:ambiguous-placeholder:${templateTargetDebugId(target)}`,
129416
+ "ambiguous-target",
129417
+ "The placeholder/current text appears more than once and the target has no occurrence identity or exact handle.",
129418
+ "Persist an occurrence refId/index or the exact scope/action handle returned by ai.actions.locateAll."
129419
+ )
129420
+ );
129421
+ }
129422
+ let summary;
129423
+ let readback = occurrenceCount !== void 0 && expected !== void 0 ? { text: expected, excerpt: excerpt(expected), isEmpty: expected.trim().length === 0, occurrenceCount } : void 0;
129424
+ if (target.target) {
129425
+ const read = readPlanTarget(runtime, target.target);
129426
+ if (!read.ok) {
129427
+ details.push(...read.blockerDetails);
129428
+ } else {
129429
+ summary = read.target;
129430
+ readback = {
129431
+ text: read.readback?.text,
129432
+ excerpt: read.readback?.excerpt,
129433
+ isEmpty: read.readback?.isEmpty,
129434
+ ...occurrenceCount !== void 0 ? { occurrenceCount } : {}
129435
+ };
129436
+ const text = read.readback?.text ?? "";
129437
+ if (expected && !text.includes(expected)) {
129438
+ details.push(
129439
+ blocker(
129440
+ `actions:template-targets:stale-readback:${templateTargetDebugId(target)}`,
129441
+ "blocked",
129442
+ "The exact handle readback no longer contains the analyzer's expected text.",
129443
+ "Re-run template analysis against the current document and save fresh targets before filling."
129444
+ )
129445
+ );
129446
+ }
129447
+ }
129448
+ }
129449
+ const canFill = targetKind === "template-field" && target.target !== void 0 && details.length === 0;
129450
+ if (targetKind === "template-field" && !target.target) {
129451
+ details.push(
129452
+ blocker(
129453
+ `actions:template-field-fill:exact-target-required:${templateTargetDebugId(target)}`,
129454
+ "blocked",
129455
+ "Template field fill requires an exact scope handle or opaque actionHandle.",
129456
+ "Plant fields through editor APIs and store the returned handle; raw offsets and YAML ranges are diagnostics only."
129457
+ )
129458
+ );
129459
+ }
129460
+ if (targetKind === "template-clause") {
129461
+ warnings.push("template-clause targets are boundary evidence; fillable placeholders must be separate template-field targets.");
129462
+ }
129463
+ const status = details.length > 0 ? "blocked" : warnings.length > 0 ? "warning" : "valid";
129464
+ return {
129465
+ status,
129466
+ targetKind,
129467
+ ...target.fieldId ? { fieldId: target.fieldId } : {},
129468
+ ...target.clauseId ? { clauseId: target.clauseId } : {},
129469
+ ...target.name ? { name: target.name } : {},
129470
+ ...target.groupId ? { groupId: target.groupId } : {},
129471
+ canFill,
129472
+ ...summary ? { target: summary } : {},
129473
+ ...readback ? { readback } : {},
129474
+ ...details.length > 0 ? { blockers: Object.freeze(details.map((detail) => detail.code)) } : {},
129475
+ ...details.length > 0 ? { blockerDetails: Object.freeze(details) } : {},
129476
+ ...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}
129477
+ };
129478
+ }
129479
+ function applyTemplateFieldFill(runtime, input) {
129480
+ if (input.text === void 0) {
129481
+ return blockedApply(
129482
+ "actions:template-field-fill:text-required",
129483
+ "input",
129484
+ "Template field fill requires a text value.",
129485
+ "Retry with the field fill text."
129486
+ );
129487
+ }
129488
+ if (templateTargetKind(input.field) !== "template-field") {
129489
+ return blockedApply(
129490
+ `actions:template-field-fill:field-target-required:${templateTargetDebugId(input.field)}`,
129491
+ "input",
129492
+ "Template field fill accepts only template-field targets.",
129493
+ "Split clause boundaries from fields and call templateFieldFill only for fillable fields."
129494
+ );
129495
+ }
129496
+ const validation = validateTemplateTarget(runtime, input.field, {
129497
+ duplicateRanges: /* @__PURE__ */ new Set(),
129498
+ allowDuplicateRanges: true
129499
+ });
129500
+ if (validation.status === "blocked" || !validation.canFill || !input.field.target) {
129501
+ return blockedApply(
129502
+ validation.blockerDetails?.[0]?.code ?? `actions:template-field-fill:exact-target-required:${templateTargetDebugId(input.field)}`,
129503
+ validation.blockerDetails?.[0]?.category ?? "blocked",
129504
+ validation.blockerDetails?.[0]?.message ?? "Template field fill requires a validated exact scope handle or opaque actionHandle.",
129505
+ validation.blockerDetails?.[0]?.nextStep ?? "Plant the field through editor APIs and pass the returned handle; raw ranges are diagnostics only.",
129506
+ validation.blockerDetails
129507
+ );
129508
+ }
129509
+ const exactnessBlocker = templateFillExactnessBlocker(input.field, validation);
129510
+ if (exactnessBlocker) {
129511
+ return blockedApply(
129512
+ exactnessBlocker.code,
129513
+ exactnessBlocker.category,
129514
+ exactnessBlocker.message,
129515
+ exactnessBlocker.nextStep,
129516
+ [exactnessBlocker]
129517
+ );
129518
+ }
129519
+ const resolved = resolveTarget(runtime, input.field.target);
129520
+ if (!resolved.ok) return blockedApplyFromResolution(resolved);
129521
+ const result = applyRewrite(runtime, resolved.target, {
129522
+ target: input.field.target,
129523
+ text: input.text,
129524
+ actorId: input.actorId,
129525
+ origin: input.origin,
129526
+ ...input.proposalId ? { proposalId: input.proposalId } : {}
129527
+ });
129528
+ if (!result.applied) return result;
129529
+ const after = readPlanTarget(runtime, input.field.target);
129530
+ if (!after.ok || after.readback?.text !== input.text) {
129531
+ const detail = blockerWithOwner(
129532
+ `actions:template-field-fill:readback-mismatch:${templateTargetDebugId(input.field)}`,
129533
+ "blocked",
129534
+ "The field fill reported applied, but same-target readback did not match the requested text.",
129535
+ "Treat this as failed, inspect export/reopen evidence, and route the target lowering to L08/L07 before retrying.",
129536
+ "L08 semantic scopes and L07 runtime text commands"
129537
+ );
129538
+ return {
129539
+ ...result,
129540
+ status: "blocked",
129541
+ applied: false,
129542
+ changed: result.changed,
129543
+ posture: "suspect-readback",
129544
+ blockers: Object.freeze([...result.blockers ?? [], detail.code]),
129545
+ blockerDetails: Object.freeze([...result.blockerDetails ?? [], detail])
129546
+ };
129547
+ }
129548
+ return result;
129549
+ }
129550
+ function templateFillExactnessBlocker(target, validation) {
129551
+ const readback = validation.readback?.text ?? "";
129552
+ const expected = templateExpectedText(target);
129553
+ if (!expected) return null;
129554
+ if (readback === expected) return null;
129555
+ return blocker(
129556
+ `actions:template-field-fill:exact-target-not-isolated:${templateTargetDebugId(target)}`,
129557
+ "blocked",
129558
+ "The exact handle readback contains surrounding document text, not just the template field text.",
129559
+ "Plant an isolated template-field scope/action handle for the placeholder; do not fill by broad paragraph, clause, or raw range."
129560
+ );
129561
+ }
129562
+ function templateReadbackToPlanReadback(readback) {
129563
+ if (!readback) return void 0;
129564
+ return {
129565
+ ...readback.text !== void 0 ? { text: readback.text } : {},
129566
+ ...readback.excerpt !== void 0 ? { excerpt: readback.excerpt } : {},
129567
+ ...readback.isEmpty !== void 0 ? { isEmpty: readback.isEmpty } : {}
129568
+ };
129569
+ }
129570
+ function templateTargetKind(target) {
129571
+ return target.kind ?? (target.clauseId && !target.fieldId ? "template-clause" : "template-field");
129572
+ }
129573
+ function templateExpectedText(target) {
129574
+ const text = target.expectedText ?? target.placeholderText;
129575
+ return text && text.length > 0 ? text : void 0;
129576
+ }
129577
+ function templateTargetDebugId(target) {
129578
+ return target.fieldId ?? target.clauseId ?? target.name ?? target.placeholderText ?? "unknown";
129579
+ }
129580
+ function templateLocationKey(location) {
129581
+ if (!location?.refId && location?.start === void 0 && location?.end === void 0) return null;
129582
+ return [
129583
+ location.story ?? "main",
129584
+ location.refId ?? "no-ref",
129585
+ location.start ?? "no-start",
129586
+ location.end ?? "no-end"
129587
+ ].join(":");
129588
+ }
129589
+ function isTableTemplateLocation(location) {
129590
+ return Boolean(
129591
+ location?.blockKind === "table-cell" || location?.tableRefId || location?.rowRefId || location?.cellRefId
129592
+ );
129593
+ }
129594
+ function hasTableCellIdentity(location) {
129595
+ return Boolean(
129596
+ location?.cellRefId || location?.rowRefId && location.columnIndex !== void 0 || location?.rowIndex !== void 0 && location?.columnIndex !== void 0
129597
+ );
129598
+ }
129599
+ function hasOccurrenceIdentity(target) {
129600
+ return Boolean(
129601
+ target.occurrence?.refId || target.occurrence?.occurrenceIndexInRef !== void 0 || target.occurrence?.occurrenceIndexGlobal !== void 0 || target.location?.refId || target.location?.cellRefId
129602
+ );
129603
+ }
129604
+ function countOccurrences(text, query) {
129605
+ if (!query) return 0;
129606
+ let count = 0;
129607
+ let index = 0;
129608
+ while (index <= text.length) {
129609
+ const found = text.indexOf(query, index);
129610
+ if (found === -1) break;
129611
+ count += 1;
129612
+ index = found + Math.max(1, query.length);
129613
+ }
129614
+ return count;
129615
+ }
129616
+ function documentText(document2) {
129617
+ return document2.content.children.map((block) => blockText(block)).join("\n");
129618
+ }
129619
+ function blockText(block) {
129620
+ switch (block.type) {
129621
+ case "paragraph":
129622
+ return collectInlineText3(block.children);
129623
+ case "table":
129624
+ return block.rows.map(
129625
+ (row2) => row2.cells.map((cell) => cell.children.map((child) => blockText(child)).join("\n")).join(" ")
129626
+ ).join("\n");
129627
+ case "sdt":
129628
+ case "custom_xml":
129629
+ return block.children.map((child) => blockText(child)).join("\n");
129630
+ default:
129631
+ return "";
129632
+ }
129633
+ }
129133
129634
  function resolveTarget(runtime, target) {
129134
129635
  if ("actionHandle" in target) {
129135
129636
  const action = findTableAction(runtime, target.actionHandle);
@@ -129252,7 +129753,7 @@ function applyRewrite(runtime, target, input) {
129252
129753
  );
129253
129754
  }
129254
129755
  const beforeText = target.scope.content.text;
129255
- const documentHashBeforeApply = documentContentHash(runtime);
129756
+ const documentBeforeApply = runtime.getCanonicalDocument();
129256
129757
  const result = createReplacementFamily(runtime).applyReplacementScope({
129257
129758
  targetScopeId: target.handle.scopeId,
129258
129759
  operation: "replace",
@@ -129264,7 +129765,7 @@ function applyRewrite(runtime, target, input) {
129264
129765
  ...input.origin ? { origin: input.origin } : {},
129265
129766
  ...input.proposalId ? { proposalId: input.proposalId } : {}
129266
129767
  });
129267
- const documentMutated = documentContentHash(runtime) !== documentHashBeforeApply;
129768
+ const documentMutated = runtime.getCanonicalDocument() !== documentBeforeApply;
129268
129769
  if (!result.applied) {
129269
129770
  return documentMutated ? withSuspectMutationApplyResult(
129270
129771
  projectApplyResult(result, target),
@@ -129521,19 +130022,7 @@ function findTableAction(runtime, actionHandle) {
129521
130022
  return action?.family === "table-text" ? action : null;
129522
130023
  }
129523
130024
  function findAnyTableAction(runtime, actionHandle) {
129524
- const compiler = createScopeCompilerService(runtime);
129525
- for (const scope of compiler.compileAllScopes()) {
129526
- if (scope.kind !== "table") continue;
129527
- const result = createTableActionFamily(runtime).listTableActions({
129528
- handle: scope.handle,
129529
- nowUtc: currentAuditTimestamp(runtime)
129530
- });
129531
- const action = result.actions.find(
129532
- (candidate) => candidate.actionHandle === actionHandle
129533
- );
129534
- if (action) return action;
129535
- }
129536
- return null;
130025
+ return findTableActionDescriptor(runtime, actionHandle);
129537
130026
  }
129538
130027
  function findEditableTextAction(runtime, actionHandle) {
129539
130028
  if (!actionHandle.startsWith("scope-command:text-leaf:")) return null;
@@ -129852,6 +130341,14 @@ function applyPlanStep(runtime, step, plan) {
129852
130341
  actorId: step.actorId ?? plan.actorId,
129853
130342
  origin: step.origin ?? plan.origin
129854
130343
  });
130344
+ case "templateFieldFill":
130345
+ return createActionsFamily(runtime).actions.templateFieldFill({
130346
+ field: step.field,
130347
+ text: step.text,
130348
+ actorId: step.actorId ?? plan.actorId,
130349
+ origin: step.origin ?? plan.origin,
130350
+ ...step.proposalId ? { proposalId: step.proposalId } : {}
130351
+ });
129855
130352
  case "listOperation":
129856
130353
  return createActionsFamily(runtime).actions.listOperation({
129857
130354
  target: step.target,
@@ -130101,6 +130598,11 @@ function tablePlanOperationFamilyBlocker(stepKind, operationKind) {
130101
130598
  }
130102
130599
  return null;
130103
130600
  }
130601
+ function tableSelectionStepHasDescriptor(operation) {
130602
+ return Boolean(
130603
+ operation && "selectionDescriptor" in operation && operation.selectionDescriptor
130604
+ );
130605
+ }
130104
130606
  function listCommandForOperation(operation, paragraphIndex, origin) {
130105
130607
  switch (operation.kind) {
130106
130608
  case "toggle":
@@ -132875,7 +133377,12 @@ var WordReviewEditor = (0, import_react71.forwardRef)(
132875
133377
  activeRuntime.endAction();
132876
133378
  }
132877
133379
  } else {
132878
- activeRuntime.insertFragment(meta.fragment);
133380
+ const editableTarget = activeRuntime.getRenderSnapshot().selection.editableTarget;
133381
+ activeRuntime.insertFragment(
133382
+ meta.fragment,
133383
+ void 0,
133384
+ editableTarget ? { editableTarget } : void 0
133385
+ );
132879
133386
  }
132880
133387
  },
132881
133388
  onInsertHardBreak: () => dispatchTextCommand(activeRuntime, { type: "insert-hard-break" }, DISPATCH_CONTEXT),
@@ -132900,7 +133407,12 @@ var WordReviewEditor = (0, import_react71.forwardRef)(
132900
133407
  // insertFragment auto-bracket (R.5.a Phase 2) makes the paste a
132901
133408
  // single-undo action.
132902
133409
  onPasteFragment: (meta) => {
132903
- activeRuntime.insertFragment(meta.fragment);
133410
+ const editableTarget = activeRuntime.getRenderSnapshot().selection.editableTarget;
133411
+ activeRuntime.insertFragment(
133412
+ meta.fragment,
133413
+ void 0,
133414
+ editableTarget ? { editableTarget } : void 0
133415
+ );
132904
133416
  },
132905
133417
  // v5 close-out: image paste via existing insertImage ref method.
132906
133418
  // Width/height are omitted so the renderer picks sensible defaults