Reconcile controls from provider receipts
This commit is contained in:
parent
72631873c8
commit
c490c1e77f
3 changed files with 32 additions and 1 deletions
1
packages/eve-browser-lowering/dist/index.js
vendored
1
packages/eve-browser-lowering/dist/index.js
vendored
|
|
@ -1307,6 +1307,7 @@ function renderSlider(props, children, options) {
|
|||
const max = Number(props.max ?? 1);
|
||||
const slider = el("div", "cultui-slider");
|
||||
slider.dataset.skin = stringProp(props.skin, "default");
|
||||
slider.dataset.bind = stringProp(props.bind, "");
|
||||
applyControlBoxProps(slider, box);
|
||||
const visual = el("div", "cultui-slider-visual");
|
||||
const input = el("input", "cultui-slider-input");
|
||||
|
|
|
|||
|
|
@ -1540,6 +1540,7 @@ function renderSlider(
|
|||
const max = Number(props.max ?? 1);
|
||||
const slider = el("div", "cultui-slider");
|
||||
slider.dataset.skin = stringProp(props.skin, "default");
|
||||
slider.dataset.bind = stringProp(props.bind, "");
|
||||
applyControlBoxProps(slider, box);
|
||||
const visual = el("div", "cultui-slider-visual");
|
||||
const input = el("input", "cultui-slider-input") as HTMLInputElement;
|
||||
|
|
|
|||
|
|
@ -244,6 +244,35 @@ async function publishCommandIntent(intent, component) {
|
|||
console.error("Eve command failed", receipt);
|
||||
return;
|
||||
}
|
||||
statusEl.textContent = `command accepted ${command.command}`;
|
||||
if (
|
||||
receipt.schema !== "gamecult.eve.command_receipt.v1" ||
|
||||
!receipt.commandId ||
|
||||
receipt.command !== command.command ||
|
||||
receipt.state !== "reconciled"
|
||||
) {
|
||||
statusEl.textContent = `command failed ${command.command}`;
|
||||
console.error("Eve command returned no correlated provider receipt", receipt);
|
||||
return;
|
||||
}
|
||||
applyCommandReceipt(receipt);
|
||||
statusEl.textContent = `command ${receipt.state} ${command.command}`;
|
||||
console.info("Eve command receipt", receipt);
|
||||
}
|
||||
|
||||
function applyCommandReceipt(receipt) {
|
||||
for (const diagnostic of receipt.diagnostics || []) {
|
||||
if (!diagnostic?.binding || diagnostic.value === undefined) continue;
|
||||
for (const control of document.querySelectorAll(`[data-bind="${CSS.escape(diagnostic.binding)}"]`)) {
|
||||
const input = control.querySelector("input[type=range]");
|
||||
if (input) {
|
||||
input.value = String(diagnostic.value);
|
||||
const min = Number(input.min || 0);
|
||||
const max = Number(input.max || 1);
|
||||
const value = Number(diagnostic.value);
|
||||
const percent = max === min ? 0 : ((value - min) / (max - min)) * 100;
|
||||
control.style.setProperty("--cultui-slider-value", `${Math.max(0, Math.min(100, percent))}%`);
|
||||
}
|
||||
control.dataset.value = String(diagnostic.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue