Preserve Eve input defaults and command receipts

This commit is contained in:
Meta Vens 2026-08-22 12:16:51 +02:00
commit 6b5faa6a77
5 changed files with 182 additions and 4 deletions

View file

@ -464,7 +464,9 @@ export function renderEveSurface(
options.statusElement.textContent = `${surface.title || surface.surface?.title || "surface"}${options.source ? ` (${options.source})` : ""}`;
}
if (surface.surface?.root) {
const commandResult = host.querySelector<HTMLElement>(":scope > .eve-command-result-region");
host.replaceChildren(renderEveComponent(surface.surface.root, scopedOptions));
if (commandResult) host.append(commandResult);
if (options.stateBindingResolver) {
const controller = new EveSurfaceBindingController(surface, host, scopedOptions);
activeSurfaceBindings.set(host, controller);
@ -1996,7 +1998,13 @@ export function createEveCommandIntent(
const captureBindings = stringArray(
descriptor?.captureBindings ?? action.captureBindings ?? props.captureBindings,
);
const bindings = options.draftStore?.capture(providerId, surfaceId, captureBindings) ?? {};
const bindings = captureBindingValues(
surface?.surface?.root,
providerId,
surfaceId,
captureBindings,
options.draftStore,
);
const payload = commandPayload(action);
if (captureBindings.length) payload.bindings = bindings;
const intent: EveCommandIntent = {
@ -2023,6 +2031,48 @@ export function createEveCommandIntent(
return intent;
}
function captureBindingValues(
root: EveSurfaceComponent | undefined,
providerId: string,
surfaceId: string,
bindingNames: readonly string[],
drafts: EveBrowserDraftStore | undefined,
): Record<string, unknown> {
const captured: Record<string, unknown> = {};
for (const name of bindingNames) {
if (drafts?.has(providerId, surfaceId, name)) {
captured[name] = drafts.get(providerId, surfaceId, name);
continue;
}
const authored = findAuthoredBindingValue(root, name);
if (authored.found) captured[name] = authored.value;
}
return captured;
}
function findAuthoredBindingValue(
node: EveSurfaceComponent | undefined,
bindingName: string,
): { found: boolean; value?: unknown } {
if (!node) return { found: false };
const props = objectProps(node.props);
const binding = (node.stateBindings || []).find(candidate =>
firstString(candidate.bindingName, candidate.pointerId) === bindingName,
);
const localName = firstString(binding?.bindingName, props.bind, binding?.pointerId, node.id);
if (localName === bindingName) {
const targetProp = firstString(binding?.targetProp, "value");
if (Object.prototype.hasOwnProperty.call(props, targetProp)) {
return { found: true, value: props[targetProp] };
}
}
for (const child of node.children || []) {
const match = findAuthoredBindingValue(child, bindingName);
if (match.found) return match;
}
return { found: false };
}
function commandPayload(action: Record<string, unknown>): Record<string, unknown> {
const payload = { ...action };
for (const key of ["command", "commandBoundary", "receiptSchema", "schemaId", "captureBindings", "transport"]) {