@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.
- package/dist/api/public-types.d.cts +1 -1
- package/dist/api/public-types.d.ts +1 -1
- package/dist/api/v3.cjs +507 -24
- package/dist/api/v3.d.cts +2 -2
- package/dist/api/v3.d.ts +2 -2
- package/dist/api/v3.js +2 -2
- package/dist/{chunk-GL7XRYBY.js → chunk-6EROGFUF.js} +29 -13
- package/dist/{chunk-6IGWPAR4.js → chunk-LCYYR57Q.js} +462 -24
- package/dist/{chunk-4G3OS2H6.js → chunk-LZVBNDGU.js} +3 -0
- package/dist/{chunk-FPRWV54X.js → chunk-XRACP43Q.js} +46 -1
- package/dist/core/commands/formatting-commands.d.cts +1 -1
- package/dist/core/commands/formatting-commands.d.ts +1 -1
- package/dist/core/commands/image-commands.d.cts +1 -1
- package/dist/core/commands/image-commands.d.ts +1 -1
- package/dist/core/commands/section-layout-commands.d.cts +1 -1
- package/dist/core/commands/section-layout-commands.d.ts +1 -1
- package/dist/core/commands/style-commands.d.cts +1 -1
- package/dist/core/commands/style-commands.d.ts +1 -1
- package/dist/core/commands/table-structure-commands.d.cts +1 -1
- package/dist/core/commands/table-structure-commands.d.ts +1 -1
- package/dist/core/commands/text-commands.cjs +3 -0
- package/dist/core/commands/text-commands.d.cts +2 -1
- package/dist/core/commands/text-commands.d.ts +2 -1
- package/dist/core/commands/text-commands.js +1 -1
- package/dist/core/selection/mapping.d.cts +1 -1
- package/dist/core/selection/mapping.d.ts +1 -1
- package/dist/core/state/editor-state.d.cts +1 -1
- package/dist/core/state/editor-state.d.ts +1 -1
- package/dist/index.cjs +549 -37
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +16 -6
- package/dist/io/docx-session.d.cts +3 -3
- package/dist/io/docx-session.d.ts +3 -3
- package/dist/{loader-CS9-9KFa.d.ts → loader-19ct2Be0.d.ts} +2 -2
- package/dist/{loader-OoWJ1_17.d.cts → loader-CoXQ2wGd.d.cts} +2 -2
- package/dist/{public-types-DdcHqcow.d.ts → public-types-7KZsNGE2.d.ts} +93 -0
- package/dist/{public-types-BP3vqJR5.d.cts → public-types-B-CskQen.d.cts} +93 -0
- package/dist/public-types.d.cts +1 -1
- package/dist/public-types.d.ts +1 -1
- package/dist/runtime/collab.d.cts +2 -2
- package/dist/runtime/collab.d.ts +2 -2
- package/dist/runtime/document-runtime.cjs +76 -12
- package/dist/runtime/document-runtime.d.cts +1 -1
- package/dist/runtime/document-runtime.d.ts +1 -1
- package/dist/runtime/document-runtime.js +3 -3
- package/dist/{session-Cq-fzx3B.d.cts → session-B5015J4v.d.cts} +2 -2
- package/dist/{session-DyFQt8Ph.d.ts → session-C2i8-d6v.d.ts} +2 -2
- package/dist/session.d.cts +4 -4
- package/dist/session.d.ts +4 -4
- package/dist/tailwind.d.cts +1 -1
- package/dist/tailwind.d.ts +1 -1
- package/dist/{types-Bg7D-GD3.d.cts → types-DNhN0WeN.d.cts} +1 -1
- package/dist/{types-bJAgMq1M.d.ts → types-yvrQuGX9.d.ts} +1 -1
- package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +2 -2
- package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +2 -2
- package/dist/ui-tailwind.d.cts +2 -2
- package/dist/ui-tailwind.d.ts +2 -2
- package/package.json +1 -1
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
resolveScopeRange,
|
|
18
18
|
scopeSpecificity,
|
|
19
19
|
searchDocument
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-XRACP43Q.js";
|
|
21
21
|
import {
|
|
22
22
|
BROADCAST_COMMAND_TYPES,
|
|
23
23
|
COMMAND_EVENT_SCHEMA_VERSION,
|
|
@@ -5830,6 +5830,18 @@ function createTableActionFamily(runtime) {
|
|
|
5830
5830
|
}
|
|
5831
5831
|
};
|
|
5832
5832
|
}
|
|
5833
|
+
function findTableActionDescriptor(runtime, actionHandle) {
|
|
5834
|
+
const document = runtime.getCanonicalDocument();
|
|
5835
|
+
const seed = documentSeed(runtime);
|
|
5836
|
+
const surface = runtime.getRenderSnapshot().surface?.blocks ?? [];
|
|
5837
|
+
for (const target of collectEditableTargetRefs(document)) {
|
|
5838
|
+
if (!target.table || callableOperationsForScope(target.table.operationScope).length === 0 || tableActionHandle(seed, target.targetKey) !== actionHandle || !isResolvableCurrentTableActionTarget(runtime, surface, target)) {
|
|
5839
|
+
continue;
|
|
5840
|
+
}
|
|
5841
|
+
return projectCurrentTableTarget(document, seed, target);
|
|
5842
|
+
}
|
|
5843
|
+
return null;
|
|
5844
|
+
}
|
|
5833
5845
|
function isSupportedTableActionEvidence(entry) {
|
|
5834
5846
|
return isSupportedTableStructureEvidence(entry) || isSupportedTableTextEvidence(entry);
|
|
5835
5847
|
}
|
|
@@ -5848,6 +5860,7 @@ function projectTableActionDescriptor(document, seed, entry) {
|
|
|
5848
5860
|
const callableOperations = callableOperationsForScope(scope);
|
|
5849
5861
|
const supportedOperations = operationsForScope(scope);
|
|
5850
5862
|
if (callableOperations.length === 0) return [];
|
|
5863
|
+
const selectionRequiredOperations = selectionRequiredOperationsForScope(scope);
|
|
5851
5864
|
return [
|
|
5852
5865
|
{
|
|
5853
5866
|
actionHandle: tableActionHandle(seed, entry.targetKey),
|
|
@@ -5856,6 +5869,7 @@ function projectTableActionDescriptor(document, seed, entry) {
|
|
|
5856
5869
|
relation: entry.relation,
|
|
5857
5870
|
operationScope: scope,
|
|
5858
5871
|
callableOperations,
|
|
5872
|
+
...selectionRequiredOperations.length > 0 ? { selectionRequiredOperations } : {},
|
|
5859
5873
|
supportedOperations,
|
|
5860
5874
|
...scope === "text" ? { readback: tableTextReadback(readBlockPathText(document, entry.blockPath)) } : {},
|
|
5861
5875
|
reason: entry.runtimeCommand.reason
|
|
@@ -5867,6 +5881,7 @@ function projectCurrentTableTarget(document, seed, target) {
|
|
|
5867
5881
|
if (!table) return null;
|
|
5868
5882
|
const callableOperations = callableOperationsForScope(table.operationScope);
|
|
5869
5883
|
if (callableOperations.length === 0) return null;
|
|
5884
|
+
const selectionRequiredOperations = selectionRequiredOperationsForScope(table.operationScope);
|
|
5870
5885
|
return {
|
|
5871
5886
|
actionHandle: tableActionHandle(seed, target.targetKey),
|
|
5872
5887
|
family: table.operationScope === "text" ? "table-text" : "table-structure",
|
|
@@ -5874,6 +5889,7 @@ function projectCurrentTableTarget(document, seed, target) {
|
|
|
5874
5889
|
relation: "contained-by-scope",
|
|
5875
5890
|
operationScope: table.operationScope,
|
|
5876
5891
|
callableOperations,
|
|
5892
|
+
...selectionRequiredOperations.length > 0 ? { selectionRequiredOperations } : {},
|
|
5877
5893
|
supportedOperations: operationsForScope(table.operationScope),
|
|
5878
5894
|
...table.operationScope === "text" ? { readback: tableTextReadback(readEditableTargetText(document, target)) } : {},
|
|
5879
5895
|
reason: table.operationScope === "text" ? "l07:table-text-target-supported" : "l07:table-structure-target-supported"
|
|
@@ -5951,11 +5967,14 @@ function callableOperationsForScope(scope) {
|
|
|
5951
5967
|
case "text":
|
|
5952
5968
|
return TEXT_TRANSFER_OPERATIONS;
|
|
5953
5969
|
case "cell":
|
|
5954
|
-
return
|
|
5970
|
+
return CELL_STRUCTURE_OPERATIONS;
|
|
5955
5971
|
default:
|
|
5956
5972
|
return operationsForScope(scope);
|
|
5957
5973
|
}
|
|
5958
5974
|
}
|
|
5975
|
+
function selectionRequiredOperationsForScope(scope) {
|
|
5976
|
+
return scope === "cell" ? ["merge-cells"] : [];
|
|
5977
|
+
}
|
|
5959
5978
|
function operationsForScope(scope) {
|
|
5960
5979
|
switch (scope) {
|
|
5961
5980
|
case "text":
|
|
@@ -6313,6 +6332,31 @@ var hyperlinkTextEditMetadata = actionMethodMetadata(
|
|
|
6313
6332
|
expectedDelta: "hyperlink display text changes"
|
|
6314
6333
|
}
|
|
6315
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
|
+
);
|
|
6316
6360
|
var listOperationMetadata = actionMethodMetadata(
|
|
6317
6361
|
"listOperation",
|
|
6318
6362
|
"mutate",
|
|
@@ -6373,6 +6417,9 @@ var ACTION_METHODS = Object.freeze([
|
|
|
6373
6417
|
"bookmarkEdit",
|
|
6374
6418
|
"hyperlinkDestinationEdit",
|
|
6375
6419
|
"hyperlinkTextEdit",
|
|
6420
|
+
"validateTemplateTargets",
|
|
6421
|
+
"templateTargetRead",
|
|
6422
|
+
"templateFieldFill",
|
|
6376
6423
|
"listOperation",
|
|
6377
6424
|
"tableFragment",
|
|
6378
6425
|
"tableSelection",
|
|
@@ -6382,9 +6429,6 @@ var DEFAULT_LOCATE_LIMIT = 20;
|
|
|
6382
6429
|
var DEFAULT_REWRITE_ALL_LIMIT = 10;
|
|
6383
6430
|
var DEFAULT_TABLE_TEXT_SCOPE_LIMIT = 3;
|
|
6384
6431
|
var DEFAULT_PLAN_STEP_LIMIT = 20;
|
|
6385
|
-
function documentContentHash(runtime) {
|
|
6386
|
-
return JSON.stringify(runtime.getCanonicalDocument().content);
|
|
6387
|
-
}
|
|
6388
6432
|
function createActionsFamily(runtime) {
|
|
6389
6433
|
const category = {
|
|
6390
6434
|
discover(input) {
|
|
@@ -6744,6 +6788,25 @@ function createActionsFamily(runtime) {
|
|
|
6744
6788
|
origin: input.origin
|
|
6745
6789
|
});
|
|
6746
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
|
+
},
|
|
6747
6810
|
listOperation(input) {
|
|
6748
6811
|
return applyListOperation(runtime, input);
|
|
6749
6812
|
},
|
|
@@ -6813,6 +6876,9 @@ function runPlanStep(runtime, mode, step, plan) {
|
|
|
6813
6876
|
if (step.kind === "tableAction" || step.kind === "tableFragment" || step.kind === "tableSelection") {
|
|
6814
6877
|
return runPlanTableActionStep(runtime, mode, step, plan);
|
|
6815
6878
|
}
|
|
6879
|
+
if (step.kind === "templateFieldFill") {
|
|
6880
|
+
return runPlanTemplateFieldFillStep(runtime, mode, step, plan);
|
|
6881
|
+
}
|
|
6816
6882
|
const before = step.target ? readPlanTarget(runtime, step.target) : readDocumentPlanTarget(runtime);
|
|
6817
6883
|
if (!before.ok) {
|
|
6818
6884
|
return blockedPlanStepFromDetails(step.id, step.kind, before.blockerDetails);
|
|
@@ -6857,10 +6923,10 @@ function runPlanStep(runtime, mode, step, plan) {
|
|
|
6857
6923
|
...before.readback ? { beforeReadback: before.readback } : {}
|
|
6858
6924
|
};
|
|
6859
6925
|
}
|
|
6860
|
-
const
|
|
6926
|
+
const documentBeforeApply = runtime.getCanonicalDocument();
|
|
6861
6927
|
const applied = applyPlanStep(runtime, step, plan);
|
|
6862
|
-
const
|
|
6863
|
-
const projectedApply = !applied.applied &&
|
|
6928
|
+
const documentAfterApply = runtime.getCanonicalDocument();
|
|
6929
|
+
const projectedApply = !applied.applied && documentAfterApply !== documentBeforeApply ? withSuspectMutationApplyResult(applied, step.id, applied.target ?? before.target) : applied;
|
|
6864
6930
|
const after = step.kind === "flag" ? before : step.target ? readPlanTarget(runtime, step.target) : before;
|
|
6865
6931
|
return {
|
|
6866
6932
|
id: step.id,
|
|
@@ -6911,7 +6977,8 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
|
|
|
6911
6977
|
tableAction
|
|
6912
6978
|
});
|
|
6913
6979
|
}
|
|
6914
|
-
|
|
6980
|
+
const isSelectionRequiredOperation = step.kind === "tableSelection" && operationKind !== void 0 && (tableAction.selectionRequiredOperations ?? []).includes(operationKind) && tableSelectionStepHasDescriptor(step.operation);
|
|
6981
|
+
if (!operationKind || !tableAction.callableOperations.includes(operationKind) && !isSelectionRequiredOperation) {
|
|
6915
6982
|
return blockedPlanStepFromDetails(
|
|
6916
6983
|
step.id,
|
|
6917
6984
|
step.kind,
|
|
@@ -6971,6 +7038,72 @@ function runPlanTableActionStep(runtime, mode, step, plan) {
|
|
|
6971
7038
|
...result.commandReference ? { commandReference: result.commandReference } : {}
|
|
6972
7039
|
};
|
|
6973
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
|
+
}
|
|
6974
7107
|
function locateAll(runtime, input) {
|
|
6975
7108
|
if (!input.query) {
|
|
6976
7109
|
const detail = blocker(
|
|
@@ -7053,6 +7186,310 @@ function locateAll(runtime, input) {
|
|
|
7053
7186
|
...matches.length === 0 ? { blockers: Object.freeze([`actions:locate:not-found:${input.query}`]) } : {}
|
|
7054
7187
|
};
|
|
7055
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
|
+
}
|
|
7056
7493
|
function resolveTarget(runtime, target) {
|
|
7057
7494
|
if ("actionHandle" in target) {
|
|
7058
7495
|
const action = findTableAction(runtime, target.actionHandle);
|
|
@@ -7175,7 +7612,7 @@ function applyRewrite(runtime, target, input) {
|
|
|
7175
7612
|
);
|
|
7176
7613
|
}
|
|
7177
7614
|
const beforeText = target.scope.content.text;
|
|
7178
|
-
const
|
|
7615
|
+
const documentBeforeApply = runtime.getCanonicalDocument();
|
|
7179
7616
|
const result = createReplacementFamily(runtime).applyReplacementScope({
|
|
7180
7617
|
targetScopeId: target.handle.scopeId,
|
|
7181
7618
|
operation: "replace",
|
|
@@ -7187,7 +7624,7 @@ function applyRewrite(runtime, target, input) {
|
|
|
7187
7624
|
...input.origin ? { origin: input.origin } : {},
|
|
7188
7625
|
...input.proposalId ? { proposalId: input.proposalId } : {}
|
|
7189
7626
|
});
|
|
7190
|
-
const documentMutated =
|
|
7627
|
+
const documentMutated = runtime.getCanonicalDocument() !== documentBeforeApply;
|
|
7191
7628
|
if (!result.applied) {
|
|
7192
7629
|
return documentMutated ? withSuspectMutationApplyResult(
|
|
7193
7630
|
projectApplyResult(result, target),
|
|
@@ -7444,19 +7881,7 @@ function findTableAction(runtime, actionHandle) {
|
|
|
7444
7881
|
return action?.family === "table-text" ? action : null;
|
|
7445
7882
|
}
|
|
7446
7883
|
function findAnyTableAction(runtime, actionHandle) {
|
|
7447
|
-
|
|
7448
|
-
for (const scope of compiler.compileAllScopes()) {
|
|
7449
|
-
if (scope.kind !== "table") continue;
|
|
7450
|
-
const result = createTableActionFamily(runtime).listTableActions({
|
|
7451
|
-
handle: scope.handle,
|
|
7452
|
-
nowUtc: currentAuditTimestamp(runtime)
|
|
7453
|
-
});
|
|
7454
|
-
const action = result.actions.find(
|
|
7455
|
-
(candidate) => candidate.actionHandle === actionHandle
|
|
7456
|
-
);
|
|
7457
|
-
if (action) return action;
|
|
7458
|
-
}
|
|
7459
|
-
return null;
|
|
7884
|
+
return findTableActionDescriptor(runtime, actionHandle);
|
|
7460
7885
|
}
|
|
7461
7886
|
function findEditableTextAction(runtime, actionHandle) {
|
|
7462
7887
|
if (!actionHandle.startsWith("scope-command:text-leaf:")) return null;
|
|
@@ -7775,6 +8200,14 @@ function applyPlanStep(runtime, step, plan) {
|
|
|
7775
8200
|
actorId: step.actorId ?? plan.actorId,
|
|
7776
8201
|
origin: step.origin ?? plan.origin
|
|
7777
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
|
+
});
|
|
7778
8211
|
case "listOperation":
|
|
7779
8212
|
return createActionsFamily(runtime).actions.listOperation({
|
|
7780
8213
|
target: step.target,
|
|
@@ -8024,6 +8457,11 @@ function tablePlanOperationFamilyBlocker(stepKind, operationKind) {
|
|
|
8024
8457
|
}
|
|
8025
8458
|
return null;
|
|
8026
8459
|
}
|
|
8460
|
+
function tableSelectionStepHasDescriptor(operation) {
|
|
8461
|
+
return Boolean(
|
|
8462
|
+
operation && "selectionDescriptor" in operation && operation.selectionDescriptor
|
|
8463
|
+
);
|
|
8464
|
+
}
|
|
8027
8465
|
function listCommandForOperation(operation, paragraphIndex, origin) {
|
|
8028
8466
|
switch (operation.kind) {
|
|
8029
8467
|
case "toggle":
|
|
@@ -199,6 +199,9 @@ function splitParagraph(document, selection, context) {
|
|
|
199
199
|
if (scope?.kind !== "top-level") {
|
|
200
200
|
return result;
|
|
201
201
|
}
|
|
202
|
+
if (context.preserveNumberingOnSplit && scope.paragraph.numbering) {
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
202
205
|
const originalStyleId = scope.paragraph.styleId;
|
|
203
206
|
const nextStyleId = originalStyleId !== void 0 ? resolveNextStyle(originalStyleId, document.styles) : void 0;
|
|
204
207
|
if (nextStyleId !== void 0) {
|