@beyondwork/docx-react-component 1.0.127 → 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 (55) 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 +428 -0
  4. package/dist/api/v3.d.cts +2 -2
  5. package/dist/api/v3.d.ts +2 -2
  6. package/dist/api/v3.js +1 -1
  7. package/dist/{chunk-PUMZWE2D.js → chunk-6EROGFUF.js} +22 -11
  8. package/dist/{chunk-46KNRA4C.js → chunk-LCYYR57Q.js} +428 -0
  9. package/dist/core/commands/formatting-commands.d.cts +1 -1
  10. package/dist/core/commands/formatting-commands.d.ts +1 -1
  11. package/dist/core/commands/image-commands.d.cts +1 -1
  12. package/dist/core/commands/image-commands.d.ts +1 -1
  13. package/dist/core/commands/section-layout-commands.d.cts +1 -1
  14. package/dist/core/commands/section-layout-commands.d.ts +1 -1
  15. package/dist/core/commands/style-commands.d.cts +1 -1
  16. package/dist/core/commands/style-commands.d.ts +1 -1
  17. package/dist/core/commands/table-structure-commands.d.cts +1 -1
  18. package/dist/core/commands/table-structure-commands.d.ts +1 -1
  19. package/dist/core/commands/text-commands.d.cts +1 -1
  20. package/dist/core/commands/text-commands.d.ts +1 -1
  21. package/dist/core/selection/mapping.d.cts +1 -1
  22. package/dist/core/selection/mapping.d.ts +1 -1
  23. package/dist/core/state/editor-state.d.cts +1 -1
  24. package/dist/core/state/editor-state.d.ts +1 -1
  25. package/dist/index.cjs +462 -13
  26. package/dist/index.d.cts +4 -4
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.js +14 -4
  29. package/dist/io/docx-session.d.cts +3 -3
  30. package/dist/io/docx-session.d.ts +3 -3
  31. package/dist/{loader-CFICtb9m.d.ts → loader-19ct2Be0.d.ts} +2 -2
  32. package/dist/{loader-DveZOVuC.d.cts → loader-CoXQ2wGd.d.cts} +2 -2
  33. package/dist/{public-types-Cgl3efbO.d.ts → public-types-7KZsNGE2.d.ts} +92 -0
  34. package/dist/{public-types-beSYFJRR.d.cts → public-types-B-CskQen.d.cts} +92 -0
  35. package/dist/public-types.d.cts +1 -1
  36. package/dist/public-types.d.ts +1 -1
  37. package/dist/runtime/collab.d.cts +2 -2
  38. package/dist/runtime/collab.d.ts +2 -2
  39. package/dist/runtime/document-runtime.cjs +22 -11
  40. package/dist/runtime/document-runtime.d.cts +1 -1
  41. package/dist/runtime/document-runtime.d.ts +1 -1
  42. package/dist/runtime/document-runtime.js +1 -1
  43. package/dist/{session-B7u82EJF.d.cts → session-B5015J4v.d.cts} +2 -2
  44. package/dist/{session-BWMJ9jm4.d.ts → session-C2i8-d6v.d.ts} +2 -2
  45. package/dist/session.d.cts +4 -4
  46. package/dist/session.d.ts +4 -4
  47. package/dist/tailwind.d.cts +1 -1
  48. package/dist/tailwind.d.ts +1 -1
  49. package/dist/{types-BQjdVZsh.d.cts → types-DNhN0WeN.d.cts} +1 -1
  50. package/dist/{types-DvvmS5A7.d.ts → types-yvrQuGX9.d.ts} +1 -1
  51. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +2 -2
  52. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +2 -2
  53. package/dist/ui-tailwind.d.cts +2 -2
  54. package/dist/ui-tailwind.d.ts +2 -2
  55. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { T as TextTransactionTextTarget, C as CanonicalDocumentEnvelope, S as SelectionSnapshot, d as TextTransactionResult, e as StructuralMutationResult, I as InsertTableOptions, f as TextFormattingDirective, g as TransactionMapping } from '../../public-types-Cgl3efbO.js';
1
+ import { T as TextTransactionTextTarget, C as CanonicalDocumentEnvelope, S as SelectionSnapshot, d as TextTransactionResult, e as StructuralMutationResult, I as InsertTableOptions, f as TextFormattingDirective, g as TransactionMapping } from '../../public-types-7KZsNGE2.js';
2
2
  import 'react';
3
3
  import 'yjs';
4
4
  import 'y-protocols/awareness';
@@ -1,4 +1,4 @@
1
- export { fi as Assoc, fj as BoundaryAssoc, fk as DEFAULT_BOUNDARY_ASSOC, fl as DetachedAnchor, fm as DocRange, a$ as EditorAnchorProjection, fn as InternalEditorAnchorProjection, fo as MAIN_STORY_TARGET, fp as MappingResult, fq as MappingStep, fr as NodeAnchor, fs as Position, ft as RangeAnchor, g as TransactionMapping, fu as anchorUnaffectedByMapping, fv as areAnchorsEqual, fw as createDetachedAnchor, fx as createEmptyMapping, fy as createNodeAnchor, fz as createRangeAnchor, fA as getEffectiveRange, fB as mapAnchor, fC as mapPosition, fD as mapRange, fE as normalizeRange, fF as storyTargetsEqual } from '../../public-types-beSYFJRR.cjs';
1
+ export { fi as Assoc, fj as BoundaryAssoc, fk as DEFAULT_BOUNDARY_ASSOC, fl as DetachedAnchor, fm as DocRange, a$ as EditorAnchorProjection, fn as InternalEditorAnchorProjection, fo as MAIN_STORY_TARGET, fp as MappingResult, fq as MappingStep, fr as NodeAnchor, fs as Position, ft as RangeAnchor, g as TransactionMapping, fu as anchorUnaffectedByMapping, fv as areAnchorsEqual, fw as createDetachedAnchor, fx as createEmptyMapping, fy as createNodeAnchor, fz as createRangeAnchor, fA as getEffectiveRange, fB as mapAnchor, fC as mapPosition, fD as mapRange, fE as normalizeRange, fF as storyTargetsEqual } from '../../public-types-B-CskQen.cjs';
2
2
  import 'react';
3
3
  import 'yjs';
4
4
  import 'y-protocols/awareness';
@@ -1,4 +1,4 @@
1
- export { fi as Assoc, fj as BoundaryAssoc, fk as DEFAULT_BOUNDARY_ASSOC, fl as DetachedAnchor, fm as DocRange, a$ as EditorAnchorProjection, fn as InternalEditorAnchorProjection, fo as MAIN_STORY_TARGET, fp as MappingResult, fq as MappingStep, fr as NodeAnchor, fs as Position, ft as RangeAnchor, g as TransactionMapping, fu as anchorUnaffectedByMapping, fv as areAnchorsEqual, fw as createDetachedAnchor, fx as createEmptyMapping, fy as createNodeAnchor, fz as createRangeAnchor, fA as getEffectiveRange, fB as mapAnchor, fC as mapPosition, fD as mapRange, fE as normalizeRange, fF as storyTargetsEqual } from '../../public-types-Cgl3efbO.js';
1
+ export { fi as Assoc, fj as BoundaryAssoc, fk as DEFAULT_BOUNDARY_ASSOC, fl as DetachedAnchor, fm as DocRange, a$ as EditorAnchorProjection, fn as InternalEditorAnchorProjection, fo as MAIN_STORY_TARGET, fp as MappingResult, fq as MappingStep, fr as NodeAnchor, fs as Position, ft as RangeAnchor, g as TransactionMapping, fu as anchorUnaffectedByMapping, fv as areAnchorsEqual, fw as createDetachedAnchor, fx as createEmptyMapping, fy as createNodeAnchor, fz as createRangeAnchor, fA as getEffectiveRange, fB as mapAnchor, fC as mapPosition, fD as mapRange, fE as normalizeRange, fF as storyTargetsEqual } from '../../public-types-7KZsNGE2.js';
2
2
  import 'react';
3
3
  import 'yjs';
4
4
  import 'y-protocols/awareness';
@@ -1,4 +1,4 @@
1
- export { C as CanonicalDocumentEnvelope, fG as CommandStateSnapshot, fH as CommentEntryRecord, fI as CommentResolutionRecord, fJ as CommentSidebarSnapshot, fK as CommentThreadRecord, c2 as CompatibilityFeatureClass, c3 as CompatibilityFeatureEntry, fL as CompatibilityPanelSnapshot, q as CompatibilityReport, fM as CreateEditorStateOptions, fN as DocumentStats, r as EditorError, cm as EditorErrorCode, fO as EditorRuntimeState, fP as EditorState, cB as EditorWarning, cC as EditorWarningCode, fQ as PersistedEditorSnapshot, fR as ReviewStore, fS as RevisionMetadataRecord, fT as RevisionRecord, fU as RuntimePhase, fV as RuntimeRenderSnapshot, S as SelectionSnapshot, fW as TrackedChangesSnapshot, fX as createDefaultCanonicalDocument, fY as createEditorState, fZ as createEmptyCompatibilityReport, f_ as createEmptyReviewStore, f$ as createPersistedEditorSnapshot, g0 as createSelectionSnapshot, g1 as deriveDocumentStats, g2 as deriveRenderSnapshot, g3 as normalizeCommentThreadRecord } from '../../public-types-beSYFJRR.cjs';
1
+ export { C as CanonicalDocumentEnvelope, fG as CommandStateSnapshot, fH as CommentEntryRecord, fI as CommentResolutionRecord, fJ as CommentSidebarSnapshot, fK as CommentThreadRecord, c2 as CompatibilityFeatureClass, c3 as CompatibilityFeatureEntry, fL as CompatibilityPanelSnapshot, q as CompatibilityReport, fM as CreateEditorStateOptions, fN as DocumentStats, r as EditorError, cm as EditorErrorCode, fO as EditorRuntimeState, fP as EditorState, cB as EditorWarning, cC as EditorWarningCode, fQ as PersistedEditorSnapshot, fR as ReviewStore, fS as RevisionMetadataRecord, fT as RevisionRecord, fU as RuntimePhase, fV as RuntimeRenderSnapshot, S as SelectionSnapshot, fW as TrackedChangesSnapshot, fX as createDefaultCanonicalDocument, fY as createEditorState, fZ as createEmptyCompatibilityReport, f_ as createEmptyReviewStore, f$ as createPersistedEditorSnapshot, g0 as createSelectionSnapshot, g1 as deriveDocumentStats, g2 as deriveRenderSnapshot, g3 as normalizeCommentThreadRecord } from '../../public-types-B-CskQen.cjs';
2
2
  export { o as createCanonicalDocumentId } from '../../canonical-document-CXCFCbAz.cjs';
3
3
  import 'react';
4
4
  import 'yjs';
@@ -1,4 +1,4 @@
1
- export { C as CanonicalDocumentEnvelope, fG as CommandStateSnapshot, fH as CommentEntryRecord, fI as CommentResolutionRecord, fJ as CommentSidebarSnapshot, fK as CommentThreadRecord, c2 as CompatibilityFeatureClass, c3 as CompatibilityFeatureEntry, fL as CompatibilityPanelSnapshot, q as CompatibilityReport, fM as CreateEditorStateOptions, fN as DocumentStats, r as EditorError, cm as EditorErrorCode, fO as EditorRuntimeState, fP as EditorState, cB as EditorWarning, cC as EditorWarningCode, fQ as PersistedEditorSnapshot, fR as ReviewStore, fS as RevisionMetadataRecord, fT as RevisionRecord, fU as RuntimePhase, fV as RuntimeRenderSnapshot, S as SelectionSnapshot, fW as TrackedChangesSnapshot, fX as createDefaultCanonicalDocument, fY as createEditorState, fZ as createEmptyCompatibilityReport, f_ as createEmptyReviewStore, f$ as createPersistedEditorSnapshot, g0 as createSelectionSnapshot, g1 as deriveDocumentStats, g2 as deriveRenderSnapshot, g3 as normalizeCommentThreadRecord } from '../../public-types-Cgl3efbO.js';
1
+ export { C as CanonicalDocumentEnvelope, fG as CommandStateSnapshot, fH as CommentEntryRecord, fI as CommentResolutionRecord, fJ as CommentSidebarSnapshot, fK as CommentThreadRecord, c2 as CompatibilityFeatureClass, c3 as CompatibilityFeatureEntry, fL as CompatibilityPanelSnapshot, q as CompatibilityReport, fM as CreateEditorStateOptions, fN as DocumentStats, r as EditorError, cm as EditorErrorCode, fO as EditorRuntimeState, fP as EditorState, cB as EditorWarning, cC as EditorWarningCode, fQ as PersistedEditorSnapshot, fR as ReviewStore, fS as RevisionMetadataRecord, fT as RevisionRecord, fU as RuntimePhase, fV as RuntimeRenderSnapshot, S as SelectionSnapshot, fW as TrackedChangesSnapshot, fX as createDefaultCanonicalDocument, fY as createEditorState, fZ as createEmptyCompatibilityReport, f_ as createEmptyReviewStore, f$ as createPersistedEditorSnapshot, g0 as createSelectionSnapshot, g1 as deriveDocumentStats, g2 as deriveRenderSnapshot, g3 as normalizeCommentThreadRecord } from '../../public-types-7KZsNGE2.js';
2
2
  export { o as createCanonicalDocumentId } from '../../canonical-document-CXCFCbAz.js';
3
3
  import 'react';
4
4
  import 'yjs';
package/dist/index.cjs CHANGED
@@ -69298,15 +69298,17 @@ function createDocumentRuntime(options) {
69298
69298
  ...resolution.textTarget ? { textTarget: resolution.textTarget } : {}
69299
69299
  };
69300
69300
  }
69301
- function prepareFragmentInsertCommandForExecution(command, document2, surface, storyTarget) {
69301
+ function prepareFragmentInsertCommandForExecution(command, document2, surface, storyTarget, selection) {
69302
69302
  if (!command.editableTarget) {
69303
- return { kind: "accepted", selection: state.selection };
69303
+ return { kind: "accepted", selection };
69304
69304
  }
69305
+ const preserveCallerSelection = command.editableTarget.listAddress?.operationScope === "list-text";
69305
69306
  const resolution = resolveEditableTextTarget({
69306
69307
  document: document2,
69307
69308
  surface,
69308
69309
  target: command.editableTarget,
69309
69310
  activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
69311
+ ...preserveCallerSelection ? { selection } : {},
69310
69312
  editableTargetCache: editableTargetBlockCache
69311
69313
  });
69312
69314
  if (resolution.kind === "rejected") {
@@ -69324,7 +69326,7 @@ function createDocumentRuntime(options) {
69324
69326
  }
69325
69327
  return {
69326
69328
  kind: "accepted",
69327
- selection: createSelectionSnapshot(resolution.range.from, resolution.range.to),
69329
+ selection: preserveCallerSelection ? selection : createSelectionSnapshot(resolution.range.from, resolution.range.to),
69328
69330
  ...resolution.textTarget ? { textTarget: resolution.textTarget } : {}
69329
69331
  };
69330
69332
  }
@@ -69496,7 +69498,8 @@ function createDocumentRuntime(options) {
69496
69498
  command,
69497
69499
  state.document,
69498
69500
  cachedRenderSnapshot.surface?.blocks ?? [],
69499
- activeStory
69501
+ activeStory,
69502
+ commandSelection
69500
69503
  );
69501
69504
  if (prepared.kind === "rejected") {
69502
69505
  return;
@@ -69659,7 +69662,8 @@ function createDocumentRuntime(options) {
69659
69662
  command,
69660
69663
  replayState.document,
69661
69664
  replaySnapshot.surface?.blocks ?? [],
69662
- replayStory
69665
+ replayStory,
69666
+ replayState.selection
69663
69667
  );
69664
69668
  if (prepared.kind === "rejected") {
69665
69669
  return;
@@ -69802,7 +69806,8 @@ function createDocumentRuntime(options) {
69802
69806
  command,
69803
69807
  stateForCommand.document,
69804
69808
  snapshotForCommand.surface?.blocks ?? [],
69805
- replayStory
69809
+ replayStory,
69810
+ stateForCommand.selection
69806
69811
  );
69807
69812
  if (prepared.kind === "rejected") {
69808
69813
  continue;
@@ -70366,7 +70371,7 @@ function createDocumentRuntime(options) {
70366
70371
  try {
70367
70372
  const timestamp = clock();
70368
70373
  const selection = target ? createSelectionFromPublicAnchor(target) : state.selection;
70369
- const editableTarget = editContext?.editableTarget && isTableParagraphEditableTarget(editContext.editableTarget) ? editContext.editableTarget : inferEditableTargetForFragmentInsert(
70374
+ const editableTarget = editContext?.editableTarget && isFragmentInsertEditableTarget(editContext.editableTarget) ? editContext.editableTarget : inferEditableTargetForFragmentInsert(
70370
70375
  cachedRenderSnapshot.surface?.blocks ?? [],
70371
70376
  selection
70372
70377
  );
@@ -72184,7 +72189,7 @@ function createDocumentRuntime(options) {
72184
72189
  editableTargetCache: editableTargetBlockCache,
72185
72190
  activeStorySize: cachedRenderSnapshot.surface?.storySize,
72186
72191
  textTarget,
72187
- preserveNumberingOnSplit: commandForDispatch.type === "paragraph.split" && targetResolution?.kind === "accepted" && editableTarget?.listAddress?.operationScope === "list-text",
72192
+ preserveNumberingOnSplit: (commandForDispatch.type === "paragraph.split" || commandForDispatch.type === "fragment.insert") && targetResolution?.kind === "accepted" && editableTarget?.listAddress?.operationScope === "list-text",
72188
72193
  rejectTargetlessTableStructureInsert: true
72189
72194
  };
72190
72195
  const baseState = selection === state.selection ? state : {
@@ -73006,7 +73011,7 @@ function canonicalEditableTargetStoryKey(storyTarget) {
73006
73011
  function inferEditableTargetForFragmentInsert(blocks, selection) {
73007
73012
  const position = Math.min(selection.anchor, selection.head);
73008
73013
  const target = findEditableTargetAtSurfacePosition(blocks, position);
73009
- return target && isTableParagraphEditableTarget(target) ? target : void 0;
73014
+ return target && isFragmentInsertEditableTarget(target) ? target : void 0;
73010
73015
  }
73011
73016
  function findEditableTargetAtSurfacePosition(blocks, position) {
73012
73017
  for (const block of blocks) {
@@ -73035,8 +73040,14 @@ function findEditableTargetInSurfaceCell(cell, position) {
73035
73040
  }
73036
73041
  return findEditableTargetAtSurfacePosition(cell.content, position);
73037
73042
  }
73038
- function isTableParagraphEditableTarget(target) {
73039
- 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";
73040
73051
  }
73041
73052
  function extractSelectionFragment(document2, selection, activeStory) {
73042
73053
  const from = Math.min(selection.anchor, selection.head);
@@ -128462,6 +128473,31 @@ var hyperlinkTextEditMetadata = actionMethodMetadata(
128462
128473
  expectedDelta: "hyperlink display text changes"
128463
128474
  }
128464
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
+ );
128465
128501
  var listOperationMetadata = actionMethodMetadata(
128466
128502
  "listOperation",
128467
128503
  "mutate",
@@ -128522,6 +128558,9 @@ var ACTION_METHODS = Object.freeze([
128522
128558
  "bookmarkEdit",
128523
128559
  "hyperlinkDestinationEdit",
128524
128560
  "hyperlinkTextEdit",
128561
+ "validateTemplateTargets",
128562
+ "templateTargetRead",
128563
+ "templateFieldFill",
128525
128564
  "listOperation",
128526
128565
  "tableFragment",
128527
128566
  "tableSelection",
@@ -128890,6 +128929,25 @@ function createActionsFamily(runtime) {
128890
128929
  origin: input.origin
128891
128930
  });
128892
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
+ },
128893
128951
  listOperation(input) {
128894
128952
  return applyListOperation(runtime, input);
128895
128953
  },
@@ -128959,6 +129017,9 @@ function runPlanStep(runtime, mode, step, plan) {
128959
129017
  if (step.kind === "tableAction" || step.kind === "tableFragment" || step.kind === "tableSelection") {
128960
129018
  return runPlanTableActionStep(runtime, mode, step, plan);
128961
129019
  }
129020
+ if (step.kind === "templateFieldFill") {
129021
+ return runPlanTemplateFieldFillStep(runtime, mode, step, plan);
129022
+ }
128962
129023
  const before = step.target ? readPlanTarget(runtime, step.target) : readDocumentPlanTarget(runtime);
128963
129024
  if (!before.ok) {
128964
129025
  return blockedPlanStepFromDetails(step.id, step.kind, before.blockerDetails);
@@ -129118,6 +129179,72 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
129118
129179
  ...result.commandReference ? { commandReference: result.commandReference } : {}
129119
129180
  };
129120
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
+ }
129121
129248
  function locateAll(runtime, input) {
129122
129249
  if (!input.query) {
129123
129250
  const detail = blocker(
@@ -129200,6 +129327,310 @@ function locateAll(runtime, input) {
129200
129327
  ...matches.length === 0 ? { blockers: Object.freeze([`actions:locate:not-found:${input.query}`]) } : {}
129201
129328
  };
129202
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
+ }
129203
129634
  function resolveTarget(runtime, target) {
129204
129635
  if ("actionHandle" in target) {
129205
129636
  const action = findTableAction(runtime, target.actionHandle);
@@ -129910,6 +130341,14 @@ function applyPlanStep(runtime, step, plan) {
129910
130341
  actorId: step.actorId ?? plan.actorId,
129911
130342
  origin: step.origin ?? plan.origin
129912
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
+ });
129913
130352
  case "listOperation":
129914
130353
  return createActionsFamily(runtime).actions.listOperation({
129915
130354
  target: step.target,
@@ -132938,7 +133377,12 @@ var WordReviewEditor = (0, import_react71.forwardRef)(
132938
133377
  activeRuntime.endAction();
132939
133378
  }
132940
133379
  } else {
132941
- 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
+ );
132942
133386
  }
132943
133387
  },
132944
133388
  onInsertHardBreak: () => dispatchTextCommand(activeRuntime, { type: "insert-hard-break" }, DISPATCH_CONTEXT),
@@ -132963,7 +133407,12 @@ var WordReviewEditor = (0, import_react71.forwardRef)(
132963
133407
  // insertFragment auto-bracket (R.5.a Phase 2) makes the paste a
132964
133408
  // single-undo action.
132965
133409
  onPasteFragment: (meta) => {
132966
- 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
+ );
132967
133416
  },
132968
133417
  // v5 close-out: image paste via existing insertImage ref method.
132969
133418
  // Width/height are omitted so the renderer picks sensible defaults