@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
@@ -14038,15 +14038,17 @@ function createDocumentRuntime(options) {
14038
14038
  ...resolution.textTarget ? { textTarget: resolution.textTarget } : {}
14039
14039
  };
14040
14040
  }
14041
- function prepareFragmentInsertCommandForExecution(command, document, surface, storyTarget) {
14041
+ function prepareFragmentInsertCommandForExecution(command, document, surface, storyTarget, selection) {
14042
14042
  if (!command.editableTarget) {
14043
- return { kind: "accepted", selection: state.selection };
14043
+ return { kind: "accepted", selection };
14044
14044
  }
14045
+ const preserveCallerSelection = command.editableTarget.listAddress?.operationScope === "list-text";
14045
14046
  const resolution = resolveEditableTextTarget({
14046
14047
  document,
14047
14048
  surface,
14048
14049
  target: command.editableTarget,
14049
14050
  activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
14051
+ ...preserveCallerSelection ? { selection } : {},
14050
14052
  editableTargetCache: editableTargetBlockCache
14051
14053
  });
14052
14054
  if (resolution.kind === "rejected") {
@@ -14064,7 +14066,7 @@ function createDocumentRuntime(options) {
14064
14066
  }
14065
14067
  return {
14066
14068
  kind: "accepted",
14067
- selection: createSelectionSnapshot(resolution.range.from, resolution.range.to),
14069
+ selection: preserveCallerSelection ? selection : createSelectionSnapshot(resolution.range.from, resolution.range.to),
14068
14070
  ...resolution.textTarget ? { textTarget: resolution.textTarget } : {}
14069
14071
  };
14070
14072
  }
@@ -14236,7 +14238,8 @@ function createDocumentRuntime(options) {
14236
14238
  command,
14237
14239
  state.document,
14238
14240
  cachedRenderSnapshot.surface?.blocks ?? [],
14239
- activeStory
14241
+ activeStory,
14242
+ commandSelection
14240
14243
  );
14241
14244
  if (prepared.kind === "rejected") {
14242
14245
  return;
@@ -14399,7 +14402,8 @@ function createDocumentRuntime(options) {
14399
14402
  command,
14400
14403
  replayState.document,
14401
14404
  replaySnapshot.surface?.blocks ?? [],
14402
- replayStory
14405
+ replayStory,
14406
+ replayState.selection
14403
14407
  );
14404
14408
  if (prepared.kind === "rejected") {
14405
14409
  return;
@@ -14542,7 +14546,8 @@ function createDocumentRuntime(options) {
14542
14546
  command,
14543
14547
  stateForCommand.document,
14544
14548
  snapshotForCommand.surface?.blocks ?? [],
14545
- replayStory
14549
+ replayStory,
14550
+ stateForCommand.selection
14546
14551
  );
14547
14552
  if (prepared.kind === "rejected") {
14548
14553
  continue;
@@ -15106,7 +15111,7 @@ function createDocumentRuntime(options) {
15106
15111
  try {
15107
15112
  const timestamp = clock();
15108
15113
  const selection = target ? createSelectionFromPublicAnchor(target) : state.selection;
15109
- const editableTarget = editContext?.editableTarget && isTableParagraphEditableTarget(editContext.editableTarget) ? editContext.editableTarget : inferEditableTargetForFragmentInsert(
15114
+ const editableTarget = editContext?.editableTarget && isFragmentInsertEditableTarget(editContext.editableTarget) ? editContext.editableTarget : inferEditableTargetForFragmentInsert(
15110
15115
  cachedRenderSnapshot.surface?.blocks ?? [],
15111
15116
  selection
15112
15117
  );
@@ -16924,7 +16929,7 @@ function createDocumentRuntime(options) {
16924
16929
  editableTargetCache: editableTargetBlockCache,
16925
16930
  activeStorySize: cachedRenderSnapshot.surface?.storySize,
16926
16931
  textTarget,
16927
- preserveNumberingOnSplit: commandForDispatch.type === "paragraph.split" && targetResolution?.kind === "accepted" && editableTarget?.listAddress?.operationScope === "list-text",
16932
+ preserveNumberingOnSplit: (commandForDispatch.type === "paragraph.split" || commandForDispatch.type === "fragment.insert") && targetResolution?.kind === "accepted" && editableTarget?.listAddress?.operationScope === "list-text",
16928
16933
  rejectTargetlessTableStructureInsert: true
16929
16934
  };
16930
16935
  const baseState = selection === state.selection ? state : {
@@ -17746,7 +17751,7 @@ function canonicalEditableTargetStoryKey(storyTarget) {
17746
17751
  function inferEditableTargetForFragmentInsert(blocks, selection) {
17747
17752
  const position = Math.min(selection.anchor, selection.head);
17748
17753
  const target = findEditableTargetAtSurfacePosition(blocks, position);
17749
- return target && isTableParagraphEditableTarget(target) ? target : void 0;
17754
+ return target && isFragmentInsertEditableTarget(target) ? target : void 0;
17750
17755
  }
17751
17756
  function findEditableTargetAtSurfacePosition(blocks, position) {
17752
17757
  for (const block of blocks) {
@@ -17775,8 +17780,14 @@ function findEditableTargetInSurfaceCell(cell, position) {
17775
17780
  }
17776
17781
  return findEditableTargetAtSurfacePosition(cell.content, position);
17777
17782
  }
17778
- function isTableParagraphEditableTarget(target) {
17779
- 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");
17783
+ function isFragmentInsertEditableTarget(target) {
17784
+ if (target.editability !== "editable" || target.posture.blockers.length > 0 || target.commandFamily !== "text-leaf") {
17785
+ return false;
17786
+ }
17787
+ if (target.listAddress?.operationScope === "list-text") {
17788
+ return true;
17789
+ }
17790
+ return target.kind === "table-cell-paragraph-text" || target.kind === "nested-table-cell-paragraph-text" || target.kind === "sdt-table-cell-paragraph-text";
17780
17791
  }
17781
17792
  function extractSelectionFragment(document, selection, activeStory) {
17782
17793
  const from = Math.min(selection.anchor, selection.head);
@@ -6332,6 +6332,31 @@ var hyperlinkTextEditMetadata = actionMethodMetadata(
6332
6332
  expectedDelta: "hyperlink display text changes"
6333
6333
  }
6334
6334
  );
6335
+ var validateTemplateTargetsMetadata = actionMethodMetadata(
6336
+ "validateTemplateTargets",
6337
+ "read",
6338
+ "actions-template-targets",
6339
+ "Validate template field/clause targets against current document readback, duplicate ranges, and exact action/scope handles before fill.",
6340
+ { uiVisible: false, expectsUxResponse: "none" }
6341
+ );
6342
+ var templateTargetReadMetadata = actionMethodMetadata(
6343
+ "templateTargetRead",
6344
+ "read",
6345
+ "actions-template-targets",
6346
+ "Read a template field/clause target through its exact scope/action handle when present, or diagnostic placeholder occurrence evidence otherwise.",
6347
+ { uiVisible: false, expectsUxResponse: "none" }
6348
+ );
6349
+ var templateFieldFillMetadata = actionMethodMetadata(
6350
+ "templateFieldFill",
6351
+ "mutate",
6352
+ "actions-template-targets",
6353
+ "Fill one template field only through an exact scope/action handle after same-target readback validation; raw ranges are diagnostics only.",
6354
+ {
6355
+ uiVisible: true,
6356
+ expectsUxResponse: "inline-change",
6357
+ expectedDelta: "the exact template field target text changes"
6358
+ }
6359
+ );
6335
6360
  var listOperationMetadata = actionMethodMetadata(
6336
6361
  "listOperation",
6337
6362
  "mutate",
@@ -6392,6 +6417,9 @@ var ACTION_METHODS = Object.freeze([
6392
6417
  "bookmarkEdit",
6393
6418
  "hyperlinkDestinationEdit",
6394
6419
  "hyperlinkTextEdit",
6420
+ "validateTemplateTargets",
6421
+ "templateTargetRead",
6422
+ "templateFieldFill",
6395
6423
  "listOperation",
6396
6424
  "tableFragment",
6397
6425
  "tableSelection",
@@ -6760,6 +6788,25 @@ function createActionsFamily(runtime) {
6760
6788
  origin: input.origin
6761
6789
  });
6762
6790
  },
6791
+ validateTemplateTargets(input) {
6792
+ return validateTemplateTargets(runtime, input);
6793
+ },
6794
+ templateTargetRead(input) {
6795
+ const item = validateTemplateTarget(runtime, input.target, {
6796
+ duplicateRanges: /* @__PURE__ */ new Set(),
6797
+ allowDuplicateRanges: true
6798
+ });
6799
+ return {
6800
+ status: item.status === "blocked" ? "blocked" : "read",
6801
+ ...item.target ? { target: item.target } : {},
6802
+ ...item.readback ? { readback: item.readback } : {},
6803
+ ...item.blockers ? { blockers: item.blockers } : {},
6804
+ ...item.blockerDetails ? { blockerDetails: item.blockerDetails } : {}
6805
+ };
6806
+ },
6807
+ templateFieldFill(input) {
6808
+ return applyTemplateFieldFill(runtime, input);
6809
+ },
6763
6810
  listOperation(input) {
6764
6811
  return applyListOperation(runtime, input);
6765
6812
  },
@@ -6829,6 +6876,9 @@ function runPlanStep(runtime, mode, step, plan) {
6829
6876
  if (step.kind === "tableAction" || step.kind === "tableFragment" || step.kind === "tableSelection") {
6830
6877
  return runPlanTableActionStep(runtime, mode, step, plan);
6831
6878
  }
6879
+ if (step.kind === "templateFieldFill") {
6880
+ return runPlanTemplateFieldFillStep(runtime, mode, step, plan);
6881
+ }
6832
6882
  const before = step.target ? readPlanTarget(runtime, step.target) : readDocumentPlanTarget(runtime);
6833
6883
  if (!before.ok) {
6834
6884
  return blockedPlanStepFromDetails(step.id, step.kind, before.blockerDetails);
@@ -6988,6 +7038,72 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
6988
7038
  ...result.commandReference ? { commandReference: result.commandReference } : {}
6989
7039
  };
6990
7040
  }
7041
+ function runPlanTemplateFieldFillStep(runtime, mode, step, plan) {
7042
+ const validation = validateTemplateTarget(runtime, step.field, {
7043
+ duplicateRanges: /* @__PURE__ */ new Set(),
7044
+ allowDuplicateRanges: true
7045
+ });
7046
+ if (validation.status === "blocked" || !validation.canFill) {
7047
+ return blockedPlanStepFromDetails(
7048
+ step.id,
7049
+ step.kind,
7050
+ validation.blockerDetails ?? [
7051
+ blocker(
7052
+ `actions:template-field-fill:not-fillable:${templateTargetDebugId(step.field)}`,
7053
+ "blocked",
7054
+ "The template field target is not backed by an exact fill handle.",
7055
+ "Plant the field through editor APIs and pass the returned scope handle or actionHandle; raw ranges are diagnostics only."
7056
+ )
7057
+ ],
7058
+ {
7059
+ ...validation.target ? { target: validation.target } : {},
7060
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
7061
+ }
7062
+ );
7063
+ }
7064
+ const precondition = checkPlanPreconditions(step, templateReadbackToPlanReadback(validation.readback));
7065
+ if (precondition) {
7066
+ return blockedPlanStepFromDetails(step.id, step.kind, [precondition], {
7067
+ ...validation.target ? { target: validation.target } : {},
7068
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
7069
+ });
7070
+ }
7071
+ if (mode === "preview") {
7072
+ return {
7073
+ id: step.id,
7074
+ kind: step.kind,
7075
+ status: "planned",
7076
+ applied: false,
7077
+ changed: false,
7078
+ ...validation.target ? { target: validation.target } : {},
7079
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
7080
+ };
7081
+ }
7082
+ const applied = applyTemplateFieldFill(runtime, {
7083
+ field: step.field,
7084
+ text: step.text,
7085
+ actorId: step.actorId ?? plan.actorId,
7086
+ origin: step.origin ?? plan.origin,
7087
+ ...step.proposalId ? { proposalId: step.proposalId } : {}
7088
+ });
7089
+ const after = step.field.target ? readPlanTarget(runtime, step.field.target) : null;
7090
+ return {
7091
+ id: step.id,
7092
+ kind: step.kind,
7093
+ status: applied.status === "unsupported" ? "unsupported" : applied.applied ? "applied" : "blocked",
7094
+ applied: applied.applied,
7095
+ changed: applied.changed,
7096
+ ...applied.target ?? validation.target ? { target: applied.target ?? validation.target } : {},
7097
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {},
7098
+ ...after?.ok && after.readback ? { afterReadback: after.readback } : {},
7099
+ ...applied.proposalId ? { proposalId: applied.proposalId } : {},
7100
+ ...applied.posture ? { posture: applied.posture } : {},
7101
+ ...applied.blockers ? { blockers: applied.blockers } : {},
7102
+ ...applied.blockerDetails ? { blockerDetails: applied.blockerDetails } : {},
7103
+ ...applied.auditReference ? { auditReference: applied.auditReference } : {},
7104
+ ...applied.commandReference ? { commandReference: applied.commandReference } : {}
7105
+ };
7106
+ }
6991
7107
  function locateAll(runtime, input) {
6992
7108
  if (!input.query) {
6993
7109
  const detail = blocker(
@@ -7070,6 +7186,310 @@ function locateAll(runtime, input) {
7070
7186
  ...matches.length === 0 ? { blockers: Object.freeze([`actions:locate:not-found:${input.query}`]) } : {}
7071
7187
  };
7072
7188
  }
7189
+ function validateTemplateTargets(runtime, input) {
7190
+ if (!Array.isArray(input.targets) || input.targets.length === 0) {
7191
+ const detail = blocker(
7192
+ "actions:template-targets:empty",
7193
+ "input",
7194
+ "Template target validation requires at least one field or clause target.",
7195
+ "Pass the analyzer targets before saving the template."
7196
+ );
7197
+ return {
7198
+ status: "blocked",
7199
+ targets: Object.freeze([]),
7200
+ blockers: Object.freeze([detail.code]),
7201
+ blockerDetails: Object.freeze([detail])
7202
+ };
7203
+ }
7204
+ const duplicateRanges = /* @__PURE__ */ new Set();
7205
+ const items = input.targets.map(
7206
+ (target) => validateTemplateTarget(runtime, target, {
7207
+ duplicateRanges,
7208
+ allowDuplicateRanges: input.allowDuplicateRanges === true
7209
+ })
7210
+ );
7211
+ const blockers = items.flatMap((item) => item.blockers ?? []);
7212
+ const blockerDetails = items.flatMap((item) => item.blockerDetails ?? []);
7213
+ return {
7214
+ status: blockerDetails.length === 0 ? "valid" : items.some((item) => item.status !== "blocked") ? "partial" : "blocked",
7215
+ targets: Object.freeze(items),
7216
+ ...blockers.length > 0 ? { blockers: Object.freeze(blockers) } : {},
7217
+ ...blockerDetails.length > 0 ? { blockerDetails: Object.freeze(blockerDetails) } : {}
7218
+ };
7219
+ }
7220
+ function validateTemplateTarget(runtime, target, context) {
7221
+ const targetKind = templateTargetKind(target);
7222
+ const details = [];
7223
+ const warnings = [];
7224
+ const expected = templateExpectedText(target);
7225
+ const occurrenceCount = expected ? countOccurrences(documentText(runtime.getCanonicalDocument()), expected) : void 0;
7226
+ const rangeKey = templateLocationKey(target.location);
7227
+ if (target.fieldId && target.clauseId) {
7228
+ details.push(
7229
+ blocker(
7230
+ `actions:template-targets:mixed-field-clause:${templateTargetDebugId(target)}`,
7231
+ "input",
7232
+ "A template target cannot be both a field and a clause.",
7233
+ "Split clause boundaries from fillable fields and save them as separate template targets."
7234
+ )
7235
+ );
7236
+ }
7237
+ if (!expected && !target.target) {
7238
+ details.push(
7239
+ blocker(
7240
+ `actions:template-targets:expected-text-required:${templateTargetDebugId(target)}`,
7241
+ "input",
7242
+ "A template target without an exact handle requires placeholderText or expectedText for validation.",
7243
+ "Store the visible placeholder/current text with the target before saving the template."
7244
+ )
7245
+ );
7246
+ }
7247
+ if (rangeKey && !context.allowDuplicateRanges) {
7248
+ if (context.duplicateRanges.has(rangeKey)) {
7249
+ details.push(
7250
+ blocker(
7251
+ `actions:template-targets:duplicate-range:${rangeKey}`,
7252
+ "ambiguous-target",
7253
+ "More than one template target claims the same document range.",
7254
+ "Create one shared grouped field target, or give each field a distinct occurrence identity."
7255
+ )
7256
+ );
7257
+ } else {
7258
+ context.duplicateRanges.add(rangeKey);
7259
+ }
7260
+ }
7261
+ if (isTableTemplateLocation(target.location) && !hasTableCellIdentity(target.location)) {
7262
+ details.push(
7263
+ blocker(
7264
+ `actions:template-targets:table-cell-identity-required:${templateTargetDebugId(target)}`,
7265
+ "input",
7266
+ "A table template target must carry stable cell identity.",
7267
+ "Include cellSourceRef/cellRefId or row and column identity plus the exact actionHandle returned for the cell text."
7268
+ )
7269
+ );
7270
+ }
7271
+ if (expected && occurrenceCount !== void 0 && occurrenceCount > 1 && !hasOccurrenceIdentity(target) && !target.target) {
7272
+ details.push(
7273
+ blocker(
7274
+ `actions:template-targets:ambiguous-placeholder:${templateTargetDebugId(target)}`,
7275
+ "ambiguous-target",
7276
+ "The placeholder/current text appears more than once and the target has no occurrence identity or exact handle.",
7277
+ "Persist an occurrence refId/index or the exact scope/action handle returned by ai.actions.locateAll."
7278
+ )
7279
+ );
7280
+ }
7281
+ let summary;
7282
+ let readback = occurrenceCount !== void 0 && expected !== void 0 ? { text: expected, excerpt: excerpt(expected), isEmpty: expected.trim().length === 0, occurrenceCount } : void 0;
7283
+ if (target.target) {
7284
+ const read = readPlanTarget(runtime, target.target);
7285
+ if (!read.ok) {
7286
+ details.push(...read.blockerDetails);
7287
+ } else {
7288
+ summary = read.target;
7289
+ readback = {
7290
+ text: read.readback?.text,
7291
+ excerpt: read.readback?.excerpt,
7292
+ isEmpty: read.readback?.isEmpty,
7293
+ ...occurrenceCount !== void 0 ? { occurrenceCount } : {}
7294
+ };
7295
+ const text = read.readback?.text ?? "";
7296
+ if (expected && !text.includes(expected)) {
7297
+ details.push(
7298
+ blocker(
7299
+ `actions:template-targets:stale-readback:${templateTargetDebugId(target)}`,
7300
+ "blocked",
7301
+ "The exact handle readback no longer contains the analyzer's expected text.",
7302
+ "Re-run template analysis against the current document and save fresh targets before filling."
7303
+ )
7304
+ );
7305
+ }
7306
+ }
7307
+ }
7308
+ const canFill = targetKind === "template-field" && target.target !== void 0 && details.length === 0;
7309
+ if (targetKind === "template-field" && !target.target) {
7310
+ details.push(
7311
+ blocker(
7312
+ `actions:template-field-fill:exact-target-required:${templateTargetDebugId(target)}`,
7313
+ "blocked",
7314
+ "Template field fill requires an exact scope handle or opaque actionHandle.",
7315
+ "Plant fields through editor APIs and store the returned handle; raw offsets and YAML ranges are diagnostics only."
7316
+ )
7317
+ );
7318
+ }
7319
+ if (targetKind === "template-clause") {
7320
+ warnings.push("template-clause targets are boundary evidence; fillable placeholders must be separate template-field targets.");
7321
+ }
7322
+ const status = details.length > 0 ? "blocked" : warnings.length > 0 ? "warning" : "valid";
7323
+ return {
7324
+ status,
7325
+ targetKind,
7326
+ ...target.fieldId ? { fieldId: target.fieldId } : {},
7327
+ ...target.clauseId ? { clauseId: target.clauseId } : {},
7328
+ ...target.name ? { name: target.name } : {},
7329
+ ...target.groupId ? { groupId: target.groupId } : {},
7330
+ canFill,
7331
+ ...summary ? { target: summary } : {},
7332
+ ...readback ? { readback } : {},
7333
+ ...details.length > 0 ? { blockers: Object.freeze(details.map((detail) => detail.code)) } : {},
7334
+ ...details.length > 0 ? { blockerDetails: Object.freeze(details) } : {},
7335
+ ...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}
7336
+ };
7337
+ }
7338
+ function applyTemplateFieldFill(runtime, input) {
7339
+ if (input.text === void 0) {
7340
+ return blockedApply(
7341
+ "actions:template-field-fill:text-required",
7342
+ "input",
7343
+ "Template field fill requires a text value.",
7344
+ "Retry with the field fill text."
7345
+ );
7346
+ }
7347
+ if (templateTargetKind(input.field) !== "template-field") {
7348
+ return blockedApply(
7349
+ `actions:template-field-fill:field-target-required:${templateTargetDebugId(input.field)}`,
7350
+ "input",
7351
+ "Template field fill accepts only template-field targets.",
7352
+ "Split clause boundaries from fields and call templateFieldFill only for fillable fields."
7353
+ );
7354
+ }
7355
+ const validation = validateTemplateTarget(runtime, input.field, {
7356
+ duplicateRanges: /* @__PURE__ */ new Set(),
7357
+ allowDuplicateRanges: true
7358
+ });
7359
+ if (validation.status === "blocked" || !validation.canFill || !input.field.target) {
7360
+ return blockedApply(
7361
+ validation.blockerDetails?.[0]?.code ?? `actions:template-field-fill:exact-target-required:${templateTargetDebugId(input.field)}`,
7362
+ validation.blockerDetails?.[0]?.category ?? "blocked",
7363
+ validation.blockerDetails?.[0]?.message ?? "Template field fill requires a validated exact scope handle or opaque actionHandle.",
7364
+ validation.blockerDetails?.[0]?.nextStep ?? "Plant the field through editor APIs and pass the returned handle; raw ranges are diagnostics only.",
7365
+ validation.blockerDetails
7366
+ );
7367
+ }
7368
+ const exactnessBlocker = templateFillExactnessBlocker(input.field, validation);
7369
+ if (exactnessBlocker) {
7370
+ return blockedApply(
7371
+ exactnessBlocker.code,
7372
+ exactnessBlocker.category,
7373
+ exactnessBlocker.message,
7374
+ exactnessBlocker.nextStep,
7375
+ [exactnessBlocker]
7376
+ );
7377
+ }
7378
+ const resolved = resolveTarget(runtime, input.field.target);
7379
+ if (!resolved.ok) return blockedApplyFromResolution(resolved);
7380
+ const result = applyRewrite(runtime, resolved.target, {
7381
+ target: input.field.target,
7382
+ text: input.text,
7383
+ actorId: input.actorId,
7384
+ origin: input.origin,
7385
+ ...input.proposalId ? { proposalId: input.proposalId } : {}
7386
+ });
7387
+ if (!result.applied) return result;
7388
+ const after = readPlanTarget(runtime, input.field.target);
7389
+ if (!after.ok || after.readback?.text !== input.text) {
7390
+ const detail = blockerWithOwner(
7391
+ `actions:template-field-fill:readback-mismatch:${templateTargetDebugId(input.field)}`,
7392
+ "blocked",
7393
+ "The field fill reported applied, but same-target readback did not match the requested text.",
7394
+ "Treat this as failed, inspect export/reopen evidence, and route the target lowering to L08/L07 before retrying.",
7395
+ "L08 semantic scopes and L07 runtime text commands"
7396
+ );
7397
+ return {
7398
+ ...result,
7399
+ status: "blocked",
7400
+ applied: false,
7401
+ changed: result.changed,
7402
+ posture: "suspect-readback",
7403
+ blockers: Object.freeze([...result.blockers ?? [], detail.code]),
7404
+ blockerDetails: Object.freeze([...result.blockerDetails ?? [], detail])
7405
+ };
7406
+ }
7407
+ return result;
7408
+ }
7409
+ function templateFillExactnessBlocker(target, validation) {
7410
+ const readback = validation.readback?.text ?? "";
7411
+ const expected = templateExpectedText(target);
7412
+ if (!expected) return null;
7413
+ if (readback === expected) return null;
7414
+ return blocker(
7415
+ `actions:template-field-fill:exact-target-not-isolated:${templateTargetDebugId(target)}`,
7416
+ "blocked",
7417
+ "The exact handle readback contains surrounding document text, not just the template field text.",
7418
+ "Plant an isolated template-field scope/action handle for the placeholder; do not fill by broad paragraph, clause, or raw range."
7419
+ );
7420
+ }
7421
+ function templateReadbackToPlanReadback(readback) {
7422
+ if (!readback) return void 0;
7423
+ return {
7424
+ ...readback.text !== void 0 ? { text: readback.text } : {},
7425
+ ...readback.excerpt !== void 0 ? { excerpt: readback.excerpt } : {},
7426
+ ...readback.isEmpty !== void 0 ? { isEmpty: readback.isEmpty } : {}
7427
+ };
7428
+ }
7429
+ function templateTargetKind(target) {
7430
+ return target.kind ?? (target.clauseId && !target.fieldId ? "template-clause" : "template-field");
7431
+ }
7432
+ function templateExpectedText(target) {
7433
+ const text = target.expectedText ?? target.placeholderText;
7434
+ return text && text.length > 0 ? text : void 0;
7435
+ }
7436
+ function templateTargetDebugId(target) {
7437
+ return target.fieldId ?? target.clauseId ?? target.name ?? target.placeholderText ?? "unknown";
7438
+ }
7439
+ function templateLocationKey(location) {
7440
+ if (!location?.refId && location?.start === void 0 && location?.end === void 0) return null;
7441
+ return [
7442
+ location.story ?? "main",
7443
+ location.refId ?? "no-ref",
7444
+ location.start ?? "no-start",
7445
+ location.end ?? "no-end"
7446
+ ].join(":");
7447
+ }
7448
+ function isTableTemplateLocation(location) {
7449
+ return Boolean(
7450
+ location?.blockKind === "table-cell" || location?.tableRefId || location?.rowRefId || location?.cellRefId
7451
+ );
7452
+ }
7453
+ function hasTableCellIdentity(location) {
7454
+ return Boolean(
7455
+ location?.cellRefId || location?.rowRefId && location.columnIndex !== void 0 || location?.rowIndex !== void 0 && location?.columnIndex !== void 0
7456
+ );
7457
+ }
7458
+ function hasOccurrenceIdentity(target) {
7459
+ return Boolean(
7460
+ target.occurrence?.refId || target.occurrence?.occurrenceIndexInRef !== void 0 || target.occurrence?.occurrenceIndexGlobal !== void 0 || target.location?.refId || target.location?.cellRefId
7461
+ );
7462
+ }
7463
+ function countOccurrences(text, query) {
7464
+ if (!query) return 0;
7465
+ let count = 0;
7466
+ let index = 0;
7467
+ while (index <= text.length) {
7468
+ const found = text.indexOf(query, index);
7469
+ if (found === -1) break;
7470
+ count += 1;
7471
+ index = found + Math.max(1, query.length);
7472
+ }
7473
+ return count;
7474
+ }
7475
+ function documentText(document) {
7476
+ return document.content.children.map((block) => blockText(block)).join("\n");
7477
+ }
7478
+ function blockText(block) {
7479
+ switch (block.type) {
7480
+ case "paragraph":
7481
+ return collectInlineText2(block.children);
7482
+ case "table":
7483
+ return block.rows.map(
7484
+ (row) => row.cells.map((cell) => cell.children.map((child) => blockText(child)).join("\n")).join(" ")
7485
+ ).join("\n");
7486
+ case "sdt":
7487
+ case "custom_xml":
7488
+ return block.children.map((child) => blockText(child)).join("\n");
7489
+ default:
7490
+ return "";
7491
+ }
7492
+ }
7073
7493
  function resolveTarget(runtime, target) {
7074
7494
  if ("actionHandle" in target) {
7075
7495
  const action = findTableAction(runtime, target.actionHandle);
@@ -7780,6 +8200,14 @@ function applyPlanStep(runtime, step, plan) {
7780
8200
  actorId: step.actorId ?? plan.actorId,
7781
8201
  origin: step.origin ?? plan.origin
7782
8202
  });
8203
+ case "templateFieldFill":
8204
+ return createActionsFamily(runtime).actions.templateFieldFill({
8205
+ field: step.field,
8206
+ text: step.text,
8207
+ actorId: step.actorId ?? plan.actorId,
8208
+ origin: step.origin ?? plan.origin,
8209
+ ...step.proposalId ? { proposalId: step.proposalId } : {}
8210
+ });
7783
8211
  case "listOperation":
7784
8212
  return createActionsFamily(runtime).actions.listOperation({
7785
8213
  target: step.target,
@@ -1,6 +1,6 @@
1
1
  import 'prosemirror-state';
2
2
  import 'prosemirror-model';
3
- export { g4 as Alignment, g5 as FormattingMutationResult, g6 as FormattingOperation, g7 as TextMarkClearTarget, g8 as TextMarkRangeOperation, g9 as applyFormattingOperationToDocument, ga as applyIndentation, gb as applyTextMarkOperationToDocumentRange, gc as getFormattingStateFromRenderSnapshot, gd as isMarkActive, ge as makeSetAlignment, gf as makeSetFontFamily, gg as makeSetFontSize, gh as makeSetHighlight, gi as makeSetTextColor, gj as makeToggleAllCaps, gk as makeToggleBold, gl as makeToggleItalic, gm as makeToggleSmallCaps, gn as makeToggleStrikethrough, go as makeToggleSubscript, gp as makeToggleSuperscript, gq as makeToggleUnderline } from '../../public-types-beSYFJRR.cjs';
3
+ export { g4 as Alignment, g5 as FormattingMutationResult, g6 as FormattingOperation, g7 as TextMarkClearTarget, g8 as TextMarkRangeOperation, g9 as applyFormattingOperationToDocument, ga as applyIndentation, gb as applyTextMarkOperationToDocumentRange, gc as getFormattingStateFromRenderSnapshot, gd as isMarkActive, ge as makeSetAlignment, gf as makeSetFontFamily, gg as makeSetFontSize, gh as makeSetHighlight, gi as makeSetTextColor, gj as makeToggleAllCaps, gk as makeToggleBold, gl as makeToggleItalic, gm as makeToggleSmallCaps, gn as makeToggleStrikethrough, go as makeToggleSubscript, gp as makeToggleSuperscript, gq as makeToggleUnderline } from '../../public-types-B-CskQen.cjs';
4
4
  import '../../canonical-document-CXCFCbAz.cjs';
5
5
  import 'react';
6
6
  import 'yjs';
@@ -1,6 +1,6 @@
1
1
  import 'prosemirror-state';
2
2
  import 'prosemirror-model';
3
- export { g4 as Alignment, g5 as FormattingMutationResult, g6 as FormattingOperation, g7 as TextMarkClearTarget, g8 as TextMarkRangeOperation, g9 as applyFormattingOperationToDocument, ga as applyIndentation, gb as applyTextMarkOperationToDocumentRange, gc as getFormattingStateFromRenderSnapshot, gd as isMarkActive, ge as makeSetAlignment, gf as makeSetFontFamily, gg as makeSetFontSize, gh as makeSetHighlight, gi as makeSetTextColor, gj as makeToggleAllCaps, gk as makeToggleBold, gl as makeToggleItalic, gm as makeToggleSmallCaps, gn as makeToggleStrikethrough, go as makeToggleSubscript, gp as makeToggleSuperscript, gq as makeToggleUnderline } from '../../public-types-Cgl3efbO.js';
3
+ export { g4 as Alignment, g5 as FormattingMutationResult, g6 as FormattingOperation, g7 as TextMarkClearTarget, g8 as TextMarkRangeOperation, g9 as applyFormattingOperationToDocument, ga as applyIndentation, gb as applyTextMarkOperationToDocumentRange, gc as getFormattingStateFromRenderSnapshot, gd as isMarkActive, ge as makeSetAlignment, gf as makeSetFontFamily, gg as makeSetFontSize, gh as makeSetHighlight, gi as makeSetTextColor, gj as makeToggleAllCaps, gk as makeToggleBold, gl as makeToggleItalic, gm as makeToggleSmallCaps, gn as makeToggleStrikethrough, go as makeToggleSubscript, gp as makeToggleSuperscript, gq as makeToggleUnderline } from '../../public-types-7KZsNGE2.js';
4
4
  import '../../canonical-document-CXCFCbAz.js';
5
5
  import 'react';
6
6
  import 'yjs';
@@ -1,4 +1,4 @@
1
- import { C as CanonicalDocumentEnvelope, S as SelectionSnapshot, g as TransactionMapping } from '../../public-types-beSYFJRR.cjs';
1
+ import { C as CanonicalDocumentEnvelope, S as SelectionSnapshot, g as TransactionMapping } 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
- import { C as CanonicalDocumentEnvelope, S as SelectionSnapshot, g as TransactionMapping } from '../../public-types-Cgl3efbO.js';
1
+ import { C as CanonicalDocumentEnvelope, S as SelectionSnapshot, 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
- import { h as SelectionSnapshot, M as MarginPresetDefinition, i as PageFormatDefinition, R as RuntimeRenderSnapshot } from '../../public-types-beSYFJRR.cjs';
1
+ import { h as SelectionSnapshot, M as MarginPresetDefinition, i as PageFormatDefinition, R as RuntimeRenderSnapshot } from '../../public-types-B-CskQen.cjs';
2
2
  import { C as CanonicalDocument, P as PageSize, a as PageMargins, b as ColumnProperties, c as PageNumbering } from '../../canonical-document-CXCFCbAz.cjs';
3
3
  import 'react';
4
4
  import 'yjs';
@@ -1,4 +1,4 @@
1
- import { h as SelectionSnapshot, M as MarginPresetDefinition, i as PageFormatDefinition, R as RuntimeRenderSnapshot } from '../../public-types-Cgl3efbO.js';
1
+ import { h as SelectionSnapshot, M as MarginPresetDefinition, i as PageFormatDefinition, R as RuntimeRenderSnapshot } from '../../public-types-7KZsNGE2.js';
2
2
  import { C as CanonicalDocument, P as PageSize, a as PageMargins, b as ColumnProperties, c as PageNumbering } from '../../canonical-document-CXCFCbAz.js';
3
3
  import 'react';
4
4
  import 'yjs';
@@ -1,4 +1,4 @@
1
- import { P as PersistedEditorSnapshot, R as RuntimeRenderSnapshot } from '../../public-types-beSYFJRR.cjs';
1
+ import { P as PersistedEditorSnapshot, R as RuntimeRenderSnapshot } 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
- import { P as PersistedEditorSnapshot, R as RuntimeRenderSnapshot } from '../../public-types-Cgl3efbO.js';
1
+ import { P as PersistedEditorSnapshot, R as RuntimeRenderSnapshot } 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 { gr as CellLocator, gs as TableStructureOperation, gt as applyTableStructureOperation, gu as applyTableStructureOperationForEditableTarget, gv as getTableStructureContext, gw as removeCellFromRow, gx as removeTableRowPure, gy as tableStructureActionHandleForTarget } from '../../public-types-beSYFJRR.cjs';
1
+ export { gr as CellLocator, gs as TableStructureOperation, gt as applyTableStructureOperation, gu as applyTableStructureOperationForEditableTarget, gv as getTableStructureContext, gw as removeCellFromRow, gx as removeTableRowPure, gy as tableStructureActionHandleForTarget } from '../../public-types-B-CskQen.cjs';
2
2
  import '../../canonical-document-CXCFCbAz.cjs';
3
3
  import 'react';
4
4
  import 'yjs';
@@ -1,4 +1,4 @@
1
- export { gr as CellLocator, gs as TableStructureOperation, gt as applyTableStructureOperation, gu as applyTableStructureOperationForEditableTarget, gv as getTableStructureContext, gw as removeCellFromRow, gx as removeTableRowPure, gy as tableStructureActionHandleForTarget } from '../../public-types-Cgl3efbO.js';
1
+ export { gr as CellLocator, gs as TableStructureOperation, gt as applyTableStructureOperation, gu as applyTableStructureOperationForEditableTarget, gv as getTableStructureContext, gw as removeCellFromRow, gx as removeTableRowPure, gy as tableStructureActionHandleForTarget } from '../../public-types-7KZsNGE2.js';
2
2
  import '../../canonical-document-CXCFCbAz.js';
3
3
  import 'react';
4
4
  import 'yjs';
@@ -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-beSYFJRR.cjs';
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-B-CskQen.cjs';
2
2
  import 'react';
3
3
  import 'yjs';
4
4
  import 'y-protocols/awareness';