@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/api/v3.cjs CHANGED
@@ -41761,7 +41761,52 @@ function compileReplacement(inputs) {
41761
41761
 
41762
41762
  // src/runtime/scopes/replacement/apply.ts
41763
41763
  function documentHash(doc) {
41764
- return JSON.stringify(doc.content);
41764
+ let hash = 2166136261;
41765
+ const mix = (value) => {
41766
+ for (let i = 0; i < value.length; i += 1) {
41767
+ hash ^= value.charCodeAt(i);
41768
+ hash = Math.imul(hash, 16777619);
41769
+ }
41770
+ };
41771
+ const visit = (value) => {
41772
+ if (value === null) {
41773
+ mix("null");
41774
+ return;
41775
+ }
41776
+ switch (typeof value) {
41777
+ case "string":
41778
+ case "number":
41779
+ case "boolean":
41780
+ case "bigint":
41781
+ mix(`${typeof value}:${String(value)}`);
41782
+ return;
41783
+ case "undefined":
41784
+ mix("undefined");
41785
+ return;
41786
+ case "object":
41787
+ if (Array.isArray(value)) {
41788
+ mix(`[${value.length}`);
41789
+ for (const item of value) visit(item);
41790
+ mix("]");
41791
+ return;
41792
+ }
41793
+ {
41794
+ const record = value;
41795
+ const keys = Object.keys(record).sort();
41796
+ mix(`{${keys.length}`);
41797
+ for (const key of keys) {
41798
+ mix(key);
41799
+ visit(record[key]);
41800
+ }
41801
+ mix("}");
41802
+ }
41803
+ return;
41804
+ default:
41805
+ mix(typeof value);
41806
+ }
41807
+ };
41808
+ visit(doc.content);
41809
+ return (hash >>> 0).toString(36).padStart(7, "0");
41765
41810
  }
41766
41811
  function compileScopeById(document2, overlay, scopeId) {
41767
41812
  const paragraphIndexByBlockIndex = buildParagraphIndexMap(document2);
@@ -57465,6 +57510,18 @@ function createTableActionFamily(runtime) {
57465
57510
  }
57466
57511
  };
57467
57512
  }
57513
+ function findTableActionDescriptor(runtime, actionHandle) {
57514
+ const document2 = runtime.getCanonicalDocument();
57515
+ const seed = documentSeed(runtime);
57516
+ const surface = runtime.getRenderSnapshot().surface?.blocks ?? [];
57517
+ for (const target of collectEditableTargetRefs(document2)) {
57518
+ if (!target.table || callableOperationsForScope(target.table.operationScope).length === 0 || tableActionHandle(seed, target.targetKey) !== actionHandle || !isResolvableCurrentTableActionTarget(runtime, surface, target)) {
57519
+ continue;
57520
+ }
57521
+ return projectCurrentTableTarget(document2, seed, target);
57522
+ }
57523
+ return null;
57524
+ }
57468
57525
  function isSupportedTableActionEvidence(entry) {
57469
57526
  return isSupportedTableStructureEvidence(entry) || isSupportedTableTextEvidence(entry);
57470
57527
  }
@@ -57483,6 +57540,7 @@ function projectTableActionDescriptor(document2, seed, entry) {
57483
57540
  const callableOperations = callableOperationsForScope(scope);
57484
57541
  const supportedOperations = operationsForScope(scope);
57485
57542
  if (callableOperations.length === 0) return [];
57543
+ const selectionRequiredOperations = selectionRequiredOperationsForScope(scope);
57486
57544
  return [
57487
57545
  {
57488
57546
  actionHandle: tableActionHandle(seed, entry.targetKey),
@@ -57491,6 +57549,7 @@ function projectTableActionDescriptor(document2, seed, entry) {
57491
57549
  relation: entry.relation,
57492
57550
  operationScope: scope,
57493
57551
  callableOperations,
57552
+ ...selectionRequiredOperations.length > 0 ? { selectionRequiredOperations } : {},
57494
57553
  supportedOperations,
57495
57554
  ...scope === "text" ? { readback: tableTextReadback(readBlockPathText(document2, entry.blockPath)) } : {},
57496
57555
  reason: entry.runtimeCommand.reason
@@ -57502,6 +57561,7 @@ function projectCurrentTableTarget(document2, seed, target) {
57502
57561
  if (!table) return null;
57503
57562
  const callableOperations = callableOperationsForScope(table.operationScope);
57504
57563
  if (callableOperations.length === 0) return null;
57564
+ const selectionRequiredOperations = selectionRequiredOperationsForScope(table.operationScope);
57505
57565
  return {
57506
57566
  actionHandle: tableActionHandle(seed, target.targetKey),
57507
57567
  family: table.operationScope === "text" ? "table-text" : "table-structure",
@@ -57509,6 +57569,7 @@ function projectCurrentTableTarget(document2, seed, target) {
57509
57569
  relation: "contained-by-scope",
57510
57570
  operationScope: table.operationScope,
57511
57571
  callableOperations,
57572
+ ...selectionRequiredOperations.length > 0 ? { selectionRequiredOperations } : {},
57512
57573
  supportedOperations: operationsForScope(table.operationScope),
57513
57574
  ...table.operationScope === "text" ? { readback: tableTextReadback(readEditableTargetText(document2, target)) } : {},
57514
57575
  reason: table.operationScope === "text" ? "l07:table-text-target-supported" : "l07:table-structure-target-supported"
@@ -57586,11 +57647,14 @@ function callableOperationsForScope(scope) {
57586
57647
  case "text":
57587
57648
  return TEXT_TRANSFER_OPERATIONS;
57588
57649
  case "cell":
57589
- return [...CELL_STRUCTURE_OPERATIONS, "merge-cells"];
57650
+ return CELL_STRUCTURE_OPERATIONS;
57590
57651
  default:
57591
57652
  return operationsForScope(scope);
57592
57653
  }
57593
57654
  }
57655
+ function selectionRequiredOperationsForScope(scope) {
57656
+ return scope === "cell" ? ["merge-cells"] : [];
57657
+ }
57594
57658
  function operationsForScope(scope) {
57595
57659
  switch (scope) {
57596
57660
  case "text":
@@ -57948,6 +58012,31 @@ var hyperlinkTextEditMetadata = actionMethodMetadata(
57948
58012
  expectedDelta: "hyperlink display text changes"
57949
58013
  }
57950
58014
  );
58015
+ var validateTemplateTargetsMetadata = actionMethodMetadata(
58016
+ "validateTemplateTargets",
58017
+ "read",
58018
+ "actions-template-targets",
58019
+ "Validate template field/clause targets against current document readback, duplicate ranges, and exact action/scope handles before fill.",
58020
+ { uiVisible: false, expectsUxResponse: "none" }
58021
+ );
58022
+ var templateTargetReadMetadata = actionMethodMetadata(
58023
+ "templateTargetRead",
58024
+ "read",
58025
+ "actions-template-targets",
58026
+ "Read a template field/clause target through its exact scope/action handle when present, or diagnostic placeholder occurrence evidence otherwise.",
58027
+ { uiVisible: false, expectsUxResponse: "none" }
58028
+ );
58029
+ var templateFieldFillMetadata = actionMethodMetadata(
58030
+ "templateFieldFill",
58031
+ "mutate",
58032
+ "actions-template-targets",
58033
+ "Fill one template field only through an exact scope/action handle after same-target readback validation; raw ranges are diagnostics only.",
58034
+ {
58035
+ uiVisible: true,
58036
+ expectsUxResponse: "inline-change",
58037
+ expectedDelta: "the exact template field target text changes"
58038
+ }
58039
+ );
57951
58040
  var listOperationMetadata = actionMethodMetadata(
57952
58041
  "listOperation",
57953
58042
  "mutate",
@@ -58008,6 +58097,9 @@ var ACTION_METHODS = Object.freeze([
58008
58097
  "bookmarkEdit",
58009
58098
  "hyperlinkDestinationEdit",
58010
58099
  "hyperlinkTextEdit",
58100
+ "validateTemplateTargets",
58101
+ "templateTargetRead",
58102
+ "templateFieldFill",
58011
58103
  "listOperation",
58012
58104
  "tableFragment",
58013
58105
  "tableSelection",
@@ -58017,9 +58109,6 @@ var DEFAULT_LOCATE_LIMIT = 20;
58017
58109
  var DEFAULT_REWRITE_ALL_LIMIT = 10;
58018
58110
  var DEFAULT_TABLE_TEXT_SCOPE_LIMIT = 3;
58019
58111
  var DEFAULT_PLAN_STEP_LIMIT = 20;
58020
- function documentContentHash(runtime) {
58021
- return JSON.stringify(runtime.getCanonicalDocument().content);
58022
- }
58023
58112
  function createActionsFamily(runtime) {
58024
58113
  const category = {
58025
58114
  discover(input) {
@@ -58379,6 +58468,25 @@ function createActionsFamily(runtime) {
58379
58468
  origin: input.origin
58380
58469
  });
58381
58470
  },
58471
+ validateTemplateTargets(input) {
58472
+ return validateTemplateTargets(runtime, input);
58473
+ },
58474
+ templateTargetRead(input) {
58475
+ const item = validateTemplateTarget(runtime, input.target, {
58476
+ duplicateRanges: /* @__PURE__ */ new Set(),
58477
+ allowDuplicateRanges: true
58478
+ });
58479
+ return {
58480
+ status: item.status === "blocked" ? "blocked" : "read",
58481
+ ...item.target ? { target: item.target } : {},
58482
+ ...item.readback ? { readback: item.readback } : {},
58483
+ ...item.blockers ? { blockers: item.blockers } : {},
58484
+ ...item.blockerDetails ? { blockerDetails: item.blockerDetails } : {}
58485
+ };
58486
+ },
58487
+ templateFieldFill(input) {
58488
+ return applyTemplateFieldFill(runtime, input);
58489
+ },
58382
58490
  listOperation(input) {
58383
58491
  return applyListOperation(runtime, input);
58384
58492
  },
@@ -58448,6 +58556,9 @@ function runPlanStep(runtime, mode, step, plan) {
58448
58556
  if (step.kind === "tableAction" || step.kind === "tableFragment" || step.kind === "tableSelection") {
58449
58557
  return runPlanTableActionStep(runtime, mode, step, plan);
58450
58558
  }
58559
+ if (step.kind === "templateFieldFill") {
58560
+ return runPlanTemplateFieldFillStep(runtime, mode, step, plan);
58561
+ }
58451
58562
  const before = step.target ? readPlanTarget(runtime, step.target) : readDocumentPlanTarget(runtime);
58452
58563
  if (!before.ok) {
58453
58564
  return blockedPlanStepFromDetails(step.id, step.kind, before.blockerDetails);
@@ -58492,10 +58603,10 @@ function runPlanStep(runtime, mode, step, plan) {
58492
58603
  ...before.readback ? { beforeReadback: before.readback } : {}
58493
58604
  };
58494
58605
  }
58495
- const documentHashBeforeApply = documentContentHash(runtime);
58606
+ const documentBeforeApply = runtime.getCanonicalDocument();
58496
58607
  const applied = applyPlanStep(runtime, step, plan);
58497
- const documentHashAfterApply = documentContentHash(runtime);
58498
- const projectedApply = !applied.applied && documentHashAfterApply !== documentHashBeforeApply ? withSuspectMutationApplyResult(applied, step.id, applied.target ?? before.target) : applied;
58608
+ const documentAfterApply = runtime.getCanonicalDocument();
58609
+ const projectedApply = !applied.applied && documentAfterApply !== documentBeforeApply ? withSuspectMutationApplyResult(applied, step.id, applied.target ?? before.target) : applied;
58499
58610
  const after = step.kind === "flag" ? before : step.target ? readPlanTarget(runtime, step.target) : before;
58500
58611
  return {
58501
58612
  id: step.id,
@@ -58546,7 +58657,8 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
58546
58657
  tableAction: tableAction2
58547
58658
  });
58548
58659
  }
58549
- if (!operationKind || !tableAction2.callableOperations.includes(operationKind)) {
58660
+ const isSelectionRequiredOperation = step.kind === "tableSelection" && operationKind !== void 0 && (tableAction2.selectionRequiredOperations ?? []).includes(operationKind) && tableSelectionStepHasDescriptor(step.operation);
58661
+ if (!operationKind || !tableAction2.callableOperations.includes(operationKind) && !isSelectionRequiredOperation) {
58550
58662
  return blockedPlanStepFromDetails(
58551
58663
  step.id,
58552
58664
  step.kind,
@@ -58606,6 +58718,72 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
58606
58718
  ...result.commandReference ? { commandReference: result.commandReference } : {}
58607
58719
  };
58608
58720
  }
58721
+ function runPlanTemplateFieldFillStep(runtime, mode, step, plan) {
58722
+ const validation = validateTemplateTarget(runtime, step.field, {
58723
+ duplicateRanges: /* @__PURE__ */ new Set(),
58724
+ allowDuplicateRanges: true
58725
+ });
58726
+ if (validation.status === "blocked" || !validation.canFill) {
58727
+ return blockedPlanStepFromDetails(
58728
+ step.id,
58729
+ step.kind,
58730
+ validation.blockerDetails ?? [
58731
+ blocker(
58732
+ `actions:template-field-fill:not-fillable:${templateTargetDebugId(step.field)}`,
58733
+ "blocked",
58734
+ "The template field target is not backed by an exact fill handle.",
58735
+ "Plant the field through editor APIs and pass the returned scope handle or actionHandle; raw ranges are diagnostics only."
58736
+ )
58737
+ ],
58738
+ {
58739
+ ...validation.target ? { target: validation.target } : {},
58740
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
58741
+ }
58742
+ );
58743
+ }
58744
+ const precondition = checkPlanPreconditions(step, templateReadbackToPlanReadback(validation.readback));
58745
+ if (precondition) {
58746
+ return blockedPlanStepFromDetails(step.id, step.kind, [precondition], {
58747
+ ...validation.target ? { target: validation.target } : {},
58748
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
58749
+ });
58750
+ }
58751
+ if (mode === "preview") {
58752
+ return {
58753
+ id: step.id,
58754
+ kind: step.kind,
58755
+ status: "planned",
58756
+ applied: false,
58757
+ changed: false,
58758
+ ...validation.target ? { target: validation.target } : {},
58759
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {}
58760
+ };
58761
+ }
58762
+ const applied = applyTemplateFieldFill(runtime, {
58763
+ field: step.field,
58764
+ text: step.text,
58765
+ actorId: step.actorId ?? plan.actorId,
58766
+ origin: step.origin ?? plan.origin,
58767
+ ...step.proposalId ? { proposalId: step.proposalId } : {}
58768
+ });
58769
+ const after = step.field.target ? readPlanTarget(runtime, step.field.target) : null;
58770
+ return {
58771
+ id: step.id,
58772
+ kind: step.kind,
58773
+ status: applied.status === "unsupported" ? "unsupported" : applied.applied ? "applied" : "blocked",
58774
+ applied: applied.applied,
58775
+ changed: applied.changed,
58776
+ ...applied.target ?? validation.target ? { target: applied.target ?? validation.target } : {},
58777
+ ...validation.readback ? { beforeReadback: templateReadbackToPlanReadback(validation.readback) } : {},
58778
+ ...after?.ok && after.readback ? { afterReadback: after.readback } : {},
58779
+ ...applied.proposalId ? { proposalId: applied.proposalId } : {},
58780
+ ...applied.posture ? { posture: applied.posture } : {},
58781
+ ...applied.blockers ? { blockers: applied.blockers } : {},
58782
+ ...applied.blockerDetails ? { blockerDetails: applied.blockerDetails } : {},
58783
+ ...applied.auditReference ? { auditReference: applied.auditReference } : {},
58784
+ ...applied.commandReference ? { commandReference: applied.commandReference } : {}
58785
+ };
58786
+ }
58609
58787
  function locateAll(runtime, input) {
58610
58788
  if (!input.query) {
58611
58789
  const detail = blocker(
@@ -58688,6 +58866,310 @@ function locateAll(runtime, input) {
58688
58866
  ...matches.length === 0 ? { blockers: Object.freeze([`actions:locate:not-found:${input.query}`]) } : {}
58689
58867
  };
58690
58868
  }
58869
+ function validateTemplateTargets(runtime, input) {
58870
+ if (!Array.isArray(input.targets) || input.targets.length === 0) {
58871
+ const detail = blocker(
58872
+ "actions:template-targets:empty",
58873
+ "input",
58874
+ "Template target validation requires at least one field or clause target.",
58875
+ "Pass the analyzer targets before saving the template."
58876
+ );
58877
+ return {
58878
+ status: "blocked",
58879
+ targets: Object.freeze([]),
58880
+ blockers: Object.freeze([detail.code]),
58881
+ blockerDetails: Object.freeze([detail])
58882
+ };
58883
+ }
58884
+ const duplicateRanges = /* @__PURE__ */ new Set();
58885
+ const items = input.targets.map(
58886
+ (target) => validateTemplateTarget(runtime, target, {
58887
+ duplicateRanges,
58888
+ allowDuplicateRanges: input.allowDuplicateRanges === true
58889
+ })
58890
+ );
58891
+ const blockers = items.flatMap((item) => item.blockers ?? []);
58892
+ const blockerDetails = items.flatMap((item) => item.blockerDetails ?? []);
58893
+ return {
58894
+ status: blockerDetails.length === 0 ? "valid" : items.some((item) => item.status !== "blocked") ? "partial" : "blocked",
58895
+ targets: Object.freeze(items),
58896
+ ...blockers.length > 0 ? { blockers: Object.freeze(blockers) } : {},
58897
+ ...blockerDetails.length > 0 ? { blockerDetails: Object.freeze(blockerDetails) } : {}
58898
+ };
58899
+ }
58900
+ function validateTemplateTarget(runtime, target, context) {
58901
+ const targetKind = templateTargetKind(target);
58902
+ const details = [];
58903
+ const warnings = [];
58904
+ const expected = templateExpectedText(target);
58905
+ const occurrenceCount = expected ? countOccurrences(documentText(runtime.getCanonicalDocument()), expected) : void 0;
58906
+ const rangeKey = templateLocationKey(target.location);
58907
+ if (target.fieldId && target.clauseId) {
58908
+ details.push(
58909
+ blocker(
58910
+ `actions:template-targets:mixed-field-clause:${templateTargetDebugId(target)}`,
58911
+ "input",
58912
+ "A template target cannot be both a field and a clause.",
58913
+ "Split clause boundaries from fillable fields and save them as separate template targets."
58914
+ )
58915
+ );
58916
+ }
58917
+ if (!expected && !target.target) {
58918
+ details.push(
58919
+ blocker(
58920
+ `actions:template-targets:expected-text-required:${templateTargetDebugId(target)}`,
58921
+ "input",
58922
+ "A template target without an exact handle requires placeholderText or expectedText for validation.",
58923
+ "Store the visible placeholder/current text with the target before saving the template."
58924
+ )
58925
+ );
58926
+ }
58927
+ if (rangeKey && !context.allowDuplicateRanges) {
58928
+ if (context.duplicateRanges.has(rangeKey)) {
58929
+ details.push(
58930
+ blocker(
58931
+ `actions:template-targets:duplicate-range:${rangeKey}`,
58932
+ "ambiguous-target",
58933
+ "More than one template target claims the same document range.",
58934
+ "Create one shared grouped field target, or give each field a distinct occurrence identity."
58935
+ )
58936
+ );
58937
+ } else {
58938
+ context.duplicateRanges.add(rangeKey);
58939
+ }
58940
+ }
58941
+ if (isTableTemplateLocation(target.location) && !hasTableCellIdentity(target.location)) {
58942
+ details.push(
58943
+ blocker(
58944
+ `actions:template-targets:table-cell-identity-required:${templateTargetDebugId(target)}`,
58945
+ "input",
58946
+ "A table template target must carry stable cell identity.",
58947
+ "Include cellSourceRef/cellRefId or row and column identity plus the exact actionHandle returned for the cell text."
58948
+ )
58949
+ );
58950
+ }
58951
+ if (expected && occurrenceCount !== void 0 && occurrenceCount > 1 && !hasOccurrenceIdentity(target) && !target.target) {
58952
+ details.push(
58953
+ blocker(
58954
+ `actions:template-targets:ambiguous-placeholder:${templateTargetDebugId(target)}`,
58955
+ "ambiguous-target",
58956
+ "The placeholder/current text appears more than once and the target has no occurrence identity or exact handle.",
58957
+ "Persist an occurrence refId/index or the exact scope/action handle returned by ai.actions.locateAll."
58958
+ )
58959
+ );
58960
+ }
58961
+ let summary;
58962
+ let readback = occurrenceCount !== void 0 && expected !== void 0 ? { text: expected, excerpt: excerpt(expected), isEmpty: expected.trim().length === 0, occurrenceCount } : void 0;
58963
+ if (target.target) {
58964
+ const read = readPlanTarget(runtime, target.target);
58965
+ if (!read.ok) {
58966
+ details.push(...read.blockerDetails);
58967
+ } else {
58968
+ summary = read.target;
58969
+ readback = {
58970
+ text: read.readback?.text,
58971
+ excerpt: read.readback?.excerpt,
58972
+ isEmpty: read.readback?.isEmpty,
58973
+ ...occurrenceCount !== void 0 ? { occurrenceCount } : {}
58974
+ };
58975
+ const text = read.readback?.text ?? "";
58976
+ if (expected && !text.includes(expected)) {
58977
+ details.push(
58978
+ blocker(
58979
+ `actions:template-targets:stale-readback:${templateTargetDebugId(target)}`,
58980
+ "blocked",
58981
+ "The exact handle readback no longer contains the analyzer's expected text.",
58982
+ "Re-run template analysis against the current document and save fresh targets before filling."
58983
+ )
58984
+ );
58985
+ }
58986
+ }
58987
+ }
58988
+ const canFill = targetKind === "template-field" && target.target !== void 0 && details.length === 0;
58989
+ if (targetKind === "template-field" && !target.target) {
58990
+ details.push(
58991
+ blocker(
58992
+ `actions:template-field-fill:exact-target-required:${templateTargetDebugId(target)}`,
58993
+ "blocked",
58994
+ "Template field fill requires an exact scope handle or opaque actionHandle.",
58995
+ "Plant fields through editor APIs and store the returned handle; raw offsets and YAML ranges are diagnostics only."
58996
+ )
58997
+ );
58998
+ }
58999
+ if (targetKind === "template-clause") {
59000
+ warnings.push("template-clause targets are boundary evidence; fillable placeholders must be separate template-field targets.");
59001
+ }
59002
+ const status = details.length > 0 ? "blocked" : warnings.length > 0 ? "warning" : "valid";
59003
+ return {
59004
+ status,
59005
+ targetKind,
59006
+ ...target.fieldId ? { fieldId: target.fieldId } : {},
59007
+ ...target.clauseId ? { clauseId: target.clauseId } : {},
59008
+ ...target.name ? { name: target.name } : {},
59009
+ ...target.groupId ? { groupId: target.groupId } : {},
59010
+ canFill,
59011
+ ...summary ? { target: summary } : {},
59012
+ ...readback ? { readback } : {},
59013
+ ...details.length > 0 ? { blockers: Object.freeze(details.map((detail) => detail.code)) } : {},
59014
+ ...details.length > 0 ? { blockerDetails: Object.freeze(details) } : {},
59015
+ ...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}
59016
+ };
59017
+ }
59018
+ function applyTemplateFieldFill(runtime, input) {
59019
+ if (input.text === void 0) {
59020
+ return blockedApply(
59021
+ "actions:template-field-fill:text-required",
59022
+ "input",
59023
+ "Template field fill requires a text value.",
59024
+ "Retry with the field fill text."
59025
+ );
59026
+ }
59027
+ if (templateTargetKind(input.field) !== "template-field") {
59028
+ return blockedApply(
59029
+ `actions:template-field-fill:field-target-required:${templateTargetDebugId(input.field)}`,
59030
+ "input",
59031
+ "Template field fill accepts only template-field targets.",
59032
+ "Split clause boundaries from fields and call templateFieldFill only for fillable fields."
59033
+ );
59034
+ }
59035
+ const validation = validateTemplateTarget(runtime, input.field, {
59036
+ duplicateRanges: /* @__PURE__ */ new Set(),
59037
+ allowDuplicateRanges: true
59038
+ });
59039
+ if (validation.status === "blocked" || !validation.canFill || !input.field.target) {
59040
+ return blockedApply(
59041
+ validation.blockerDetails?.[0]?.code ?? `actions:template-field-fill:exact-target-required:${templateTargetDebugId(input.field)}`,
59042
+ validation.blockerDetails?.[0]?.category ?? "blocked",
59043
+ validation.blockerDetails?.[0]?.message ?? "Template field fill requires a validated exact scope handle or opaque actionHandle.",
59044
+ validation.blockerDetails?.[0]?.nextStep ?? "Plant the field through editor APIs and pass the returned handle; raw ranges are diagnostics only.",
59045
+ validation.blockerDetails
59046
+ );
59047
+ }
59048
+ const exactnessBlocker = templateFillExactnessBlocker(input.field, validation);
59049
+ if (exactnessBlocker) {
59050
+ return blockedApply(
59051
+ exactnessBlocker.code,
59052
+ exactnessBlocker.category,
59053
+ exactnessBlocker.message,
59054
+ exactnessBlocker.nextStep,
59055
+ [exactnessBlocker]
59056
+ );
59057
+ }
59058
+ const resolved = resolveTarget(runtime, input.field.target);
59059
+ if (!resolved.ok) return blockedApplyFromResolution(resolved);
59060
+ const result = applyRewrite(runtime, resolved.target, {
59061
+ target: input.field.target,
59062
+ text: input.text,
59063
+ actorId: input.actorId,
59064
+ origin: input.origin,
59065
+ ...input.proposalId ? { proposalId: input.proposalId } : {}
59066
+ });
59067
+ if (!result.applied) return result;
59068
+ const after = readPlanTarget(runtime, input.field.target);
59069
+ if (!after.ok || after.readback?.text !== input.text) {
59070
+ const detail = blockerWithOwner(
59071
+ `actions:template-field-fill:readback-mismatch:${templateTargetDebugId(input.field)}`,
59072
+ "blocked",
59073
+ "The field fill reported applied, but same-target readback did not match the requested text.",
59074
+ "Treat this as failed, inspect export/reopen evidence, and route the target lowering to L08/L07 before retrying.",
59075
+ "L08 semantic scopes and L07 runtime text commands"
59076
+ );
59077
+ return {
59078
+ ...result,
59079
+ status: "blocked",
59080
+ applied: false,
59081
+ changed: result.changed,
59082
+ posture: "suspect-readback",
59083
+ blockers: Object.freeze([...result.blockers ?? [], detail.code]),
59084
+ blockerDetails: Object.freeze([...result.blockerDetails ?? [], detail])
59085
+ };
59086
+ }
59087
+ return result;
59088
+ }
59089
+ function templateFillExactnessBlocker(target, validation) {
59090
+ const readback = validation.readback?.text ?? "";
59091
+ const expected = templateExpectedText(target);
59092
+ if (!expected) return null;
59093
+ if (readback === expected) return null;
59094
+ return blocker(
59095
+ `actions:template-field-fill:exact-target-not-isolated:${templateTargetDebugId(target)}`,
59096
+ "blocked",
59097
+ "The exact handle readback contains surrounding document text, not just the template field text.",
59098
+ "Plant an isolated template-field scope/action handle for the placeholder; do not fill by broad paragraph, clause, or raw range."
59099
+ );
59100
+ }
59101
+ function templateReadbackToPlanReadback(readback) {
59102
+ if (!readback) return void 0;
59103
+ return {
59104
+ ...readback.text !== void 0 ? { text: readback.text } : {},
59105
+ ...readback.excerpt !== void 0 ? { excerpt: readback.excerpt } : {},
59106
+ ...readback.isEmpty !== void 0 ? { isEmpty: readback.isEmpty } : {}
59107
+ };
59108
+ }
59109
+ function templateTargetKind(target) {
59110
+ return target.kind ?? (target.clauseId && !target.fieldId ? "template-clause" : "template-field");
59111
+ }
59112
+ function templateExpectedText(target) {
59113
+ const text = target.expectedText ?? target.placeholderText;
59114
+ return text && text.length > 0 ? text : void 0;
59115
+ }
59116
+ function templateTargetDebugId(target) {
59117
+ return target.fieldId ?? target.clauseId ?? target.name ?? target.placeholderText ?? "unknown";
59118
+ }
59119
+ function templateLocationKey(location) {
59120
+ if (!location?.refId && location?.start === void 0 && location?.end === void 0) return null;
59121
+ return [
59122
+ location.story ?? "main",
59123
+ location.refId ?? "no-ref",
59124
+ location.start ?? "no-start",
59125
+ location.end ?? "no-end"
59126
+ ].join(":");
59127
+ }
59128
+ function isTableTemplateLocation(location) {
59129
+ return Boolean(
59130
+ location?.blockKind === "table-cell" || location?.tableRefId || location?.rowRefId || location?.cellRefId
59131
+ );
59132
+ }
59133
+ function hasTableCellIdentity(location) {
59134
+ return Boolean(
59135
+ location?.cellRefId || location?.rowRefId && location.columnIndex !== void 0 || location?.rowIndex !== void 0 && location?.columnIndex !== void 0
59136
+ );
59137
+ }
59138
+ function hasOccurrenceIdentity(target) {
59139
+ return Boolean(
59140
+ target.occurrence?.refId || target.occurrence?.occurrenceIndexInRef !== void 0 || target.occurrence?.occurrenceIndexGlobal !== void 0 || target.location?.refId || target.location?.cellRefId
59141
+ );
59142
+ }
59143
+ function countOccurrences(text, query) {
59144
+ if (!query) return 0;
59145
+ let count = 0;
59146
+ let index = 0;
59147
+ while (index <= text.length) {
59148
+ const found = text.indexOf(query, index);
59149
+ if (found === -1) break;
59150
+ count += 1;
59151
+ index = found + Math.max(1, query.length);
59152
+ }
59153
+ return count;
59154
+ }
59155
+ function documentText(document2) {
59156
+ return document2.content.children.map((block) => blockText(block)).join("\n");
59157
+ }
59158
+ function blockText(block) {
59159
+ switch (block.type) {
59160
+ case "paragraph":
59161
+ return collectInlineText2(block.children);
59162
+ case "table":
59163
+ return block.rows.map(
59164
+ (row) => row.cells.map((cell) => cell.children.map((child) => blockText(child)).join("\n")).join(" ")
59165
+ ).join("\n");
59166
+ case "sdt":
59167
+ case "custom_xml":
59168
+ return block.children.map((child) => blockText(child)).join("\n");
59169
+ default:
59170
+ return "";
59171
+ }
59172
+ }
58691
59173
  function resolveTarget(runtime, target) {
58692
59174
  if ("actionHandle" in target) {
58693
59175
  const action = findTableAction(runtime, target.actionHandle);
@@ -58810,7 +59292,7 @@ function applyRewrite(runtime, target, input) {
58810
59292
  );
58811
59293
  }
58812
59294
  const beforeText = target.scope.content.text;
58813
- const documentHashBeforeApply = documentContentHash(runtime);
59295
+ const documentBeforeApply = runtime.getCanonicalDocument();
58814
59296
  const result = createReplacementFamily(runtime).applyReplacementScope({
58815
59297
  targetScopeId: target.handle.scopeId,
58816
59298
  operation: "replace",
@@ -58822,7 +59304,7 @@ function applyRewrite(runtime, target, input) {
58822
59304
  ...input.origin ? { origin: input.origin } : {},
58823
59305
  ...input.proposalId ? { proposalId: input.proposalId } : {}
58824
59306
  });
58825
- const documentMutated = documentContentHash(runtime) !== documentHashBeforeApply;
59307
+ const documentMutated = runtime.getCanonicalDocument() !== documentBeforeApply;
58826
59308
  if (!result.applied) {
58827
59309
  return documentMutated ? withSuspectMutationApplyResult(
58828
59310
  projectApplyResult(result, target),
@@ -59079,19 +59561,7 @@ function findTableAction(runtime, actionHandle) {
59079
59561
  return action?.family === "table-text" ? action : null;
59080
59562
  }
59081
59563
  function findAnyTableAction(runtime, actionHandle) {
59082
- const compiler = createScopeCompilerService(runtime);
59083
- for (const scope of compiler.compileAllScopes()) {
59084
- if (scope.kind !== "table") continue;
59085
- const result = createTableActionFamily(runtime).listTableActions({
59086
- handle: scope.handle,
59087
- nowUtc: currentAuditTimestamp(runtime)
59088
- });
59089
- const action = result.actions.find(
59090
- (candidate) => candidate.actionHandle === actionHandle
59091
- );
59092
- if (action) return action;
59093
- }
59094
- return null;
59564
+ return findTableActionDescriptor(runtime, actionHandle);
59095
59565
  }
59096
59566
  function findEditableTextAction(runtime, actionHandle) {
59097
59567
  if (!actionHandle.startsWith("scope-command:text-leaf:")) return null;
@@ -59410,6 +59880,14 @@ function applyPlanStep(runtime, step, plan) {
59410
59880
  actorId: step.actorId ?? plan.actorId,
59411
59881
  origin: step.origin ?? plan.origin
59412
59882
  });
59883
+ case "templateFieldFill":
59884
+ return createActionsFamily(runtime).actions.templateFieldFill({
59885
+ field: step.field,
59886
+ text: step.text,
59887
+ actorId: step.actorId ?? plan.actorId,
59888
+ origin: step.origin ?? plan.origin,
59889
+ ...step.proposalId ? { proposalId: step.proposalId } : {}
59890
+ });
59413
59891
  case "listOperation":
59414
59892
  return createActionsFamily(runtime).actions.listOperation({
59415
59893
  target: step.target,
@@ -59659,6 +60137,11 @@ function tablePlanOperationFamilyBlocker(stepKind, operationKind) {
59659
60137
  }
59660
60138
  return null;
59661
60139
  }
60140
+ function tableSelectionStepHasDescriptor(operation) {
60141
+ return Boolean(
60142
+ operation && "selectionDescriptor" in operation && operation.selectionDescriptor
60143
+ );
60144
+ }
59662
60145
  function listCommandForOperation(operation, paragraphIndex, origin) {
59663
60146
  switch (operation.kind) {
59664
60147
  case "toggle":
package/dist/api/v3.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { u as MockPayload, A as ApiStatus, U as UxIntent, v as RuntimeApiHandle, w as UiControllerFactory, x as ApiV3Ui } from '../public-types-BP3vqJR5.cjs';
2
- export { y as AgentMetadata, z as AiPe2EvidenceOptions, B as AiPe2GraphOracleReference, D as AiPe2OracleEvidence, F as AiPe2OracleEvidenceProvider, G as AiPe2OracleEvidenceProviderInput, H as AiPe2OracleVerdict, J as ApiV3, K as ApiV3FnMetadata, N as ApiV3UiChrome, O as ApiV3UiDebug, Q as ApiV3UiOverlays, V as ApiV3UiSession, W as ApiV3UiSurface, X as ApiV3UiViewport, Y as BroadcastsVia, Z as ChromeDebugMode, _ as ChromeDocumentMode, $ as ChromeHostPosture, a0 as ChromeMarkupDisplay, a1 as ChromePosture, a2 as ChromeReviewMode, a3 as ChromeSurface, a4 as ChromeSurfaceKind, a5 as CreateApiV3Opts, a6 as DebugAttachment, a7 as DebugSession, a8 as GeometryRect, a9 as LiveEvidence, aa as MockShape, ab as OverlayAnchorQuery, ac as PersistsTo, ad as ScrollTarget, ae as ScrollTargetBehavior, af as SelectionRangeInput, ag as SourceLayer, ah as StateClass, ai as SubscriptionShape, aj as UiBinding, ak as UiController, al as UiControllerKind, am as UiListener, an as UiUnsubscribe, ao as ViewportState, ap as createApiV3, aq as validateApiV3Metadata } from '../public-types-BP3vqJR5.cjs';
1
+ import { u as MockPayload, A as ApiStatus, U as UxIntent, v as RuntimeApiHandle, w as UiControllerFactory, x as ApiV3Ui } from '../public-types-B-CskQen.cjs';
2
+ export { y as AgentMetadata, z as AiPe2EvidenceOptions, B as AiPe2GraphOracleReference, D as AiPe2OracleEvidence, F as AiPe2OracleEvidenceProvider, G as AiPe2OracleEvidenceProviderInput, H as AiPe2OracleVerdict, J as ApiV3, K as ApiV3FnMetadata, N as ApiV3UiChrome, O as ApiV3UiDebug, Q as ApiV3UiOverlays, V as ApiV3UiSession, W as ApiV3UiSurface, X as ApiV3UiViewport, Y as BroadcastsVia, Z as ChromeDebugMode, _ as ChromeDocumentMode, $ as ChromeHostPosture, a0 as ChromeMarkupDisplay, a1 as ChromePosture, a2 as ChromeReviewMode, a3 as ChromeSurface, a4 as ChromeSurfaceKind, a5 as CreateApiV3Opts, a6 as DebugAttachment, a7 as DebugSession, a8 as GeometryRect, a9 as LiveEvidence, aa as MockShape, ab as OverlayAnchorQuery, ac as PersistsTo, ad as ScrollTarget, ae as ScrollTargetBehavior, af as SelectionRangeInput, ag as SourceLayer, ah as StateClass, ai as SubscriptionShape, aj as UiBinding, ak as UiController, al as UiControllerKind, am as UiListener, an as UiUnsubscribe, ao as ViewportState, ap as createApiV3, aq as validateApiV3Metadata } from '../public-types-B-CskQen.cjs';
3
3
  import 'react';
4
4
  import 'yjs';
5
5
  import 'y-protocols/awareness';