Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's on-box pages, and what it costs. What works: - schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs); - src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so the unified sidebar, ordering and surface filtering come from the schema rather than from hand-written HTML; - the render uses the shared bf- design tokens, the same ones the rest of the suite uses. Size, measured rather than assumed (armv7, release, stripped): ui-baseline 323 KiB (maud + serde_json, no flare-ui) ui-spike 771 KiB (flare-ui + wschema + sha2) marginal 448 KiB Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in flare-ui/flare-ui.lock (a partial archive does not compile, since the crate include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo directory source with the new registry dependencies (maud, sha2, typenum, digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build still works offline. third-party/README.md records how to re-pin.
115 lines
4.3 KiB
JavaScript
115 lines
4.3 KiB
JavaScript
// The parameter form of one step, drawn from flow-doc.js's step schema, so
|
|
// the node's form and the checks on the node read one table. It edits only
|
|
// the field the operator changes; every other key of the step, known or not,
|
|
// stays as it was.
|
|
(function () {
|
|
"use strict";
|
|
|
|
var counter = 0;
|
|
|
|
function element(tag, className, text) {
|
|
var node = document.createElement(tag);
|
|
if (className) node.className = className;
|
|
if (text != null) node.textContent = text;
|
|
return node;
|
|
}
|
|
|
|
function controlFor(field, value) {
|
|
var model = window.FlareFlowDoc;
|
|
var control;
|
|
if (field.type === "select") {
|
|
control = element("select", "bf-select");
|
|
var known = field.options.indexOf(value) >= 0;
|
|
if (!known) {
|
|
var blank = element("option", null, value == null || value === "" ? "Choose" : model.formatValue(value));
|
|
blank.value = "";
|
|
control.appendChild(blank);
|
|
}
|
|
field.options.forEach(function (option) {
|
|
var item = element("option", null, option);
|
|
item.value = option;
|
|
control.appendChild(item);
|
|
});
|
|
control.value = known ? value : "";
|
|
} else if (field.type === "textarea") {
|
|
control = element("textarea", "bf-textarea bf-code");
|
|
control.rows = 4;
|
|
control.value = typeof value === "string" ? value : model.formatValue(value);
|
|
} else {
|
|
control = element("input", "bf-input");
|
|
control.type = field.type === "number" || field.type === "integer" ? "number" : "text";
|
|
if (field.type === "integer") control.step = "1";
|
|
if (field.type === "number") control.step = "any";
|
|
if (field.min != null) control.min = String(field.min);
|
|
if (field.max != null) control.max = String(field.max);
|
|
control.value = field.type === "value" || typeof value !== "string"
|
|
? model.formatValue(value) : value;
|
|
}
|
|
if (field.max && field.type !== "number" && field.type !== "integer") control.maxLength = field.max;
|
|
if (field.required) control.required = true;
|
|
return control;
|
|
}
|
|
|
|
function read(field, control) {
|
|
var model = window.FlareFlowDoc;
|
|
var text = control.value;
|
|
if (text === "") return undefined;
|
|
if (field.type === "number" || field.type === "integer") {
|
|
var number = Number(text);
|
|
return isFinite(number) ? number : undefined;
|
|
}
|
|
if (field.type === "value") return model.parseValue(text);
|
|
return text;
|
|
}
|
|
|
|
// render(host, step, context, change): context is {target, version}.
|
|
// change(step) gets a new step object after each edit. A select that
|
|
// changes which fields apply (a command's type) redraws the form and keeps
|
|
// the focus on it.
|
|
function render(host, step, context, change) {
|
|
var model = window.FlareFlowDoc;
|
|
var uid = "bf-flow-field-" + (counter += 1);
|
|
host.textContent = "";
|
|
var current = step;
|
|
model.fields(context.target, step).forEach(function (field) {
|
|
var key = model.keyOf(step, field);
|
|
var wrap = element("div", "bf-field");
|
|
wrap.dataset.flowField = field.key;
|
|
var id = uid + "-" + field.key;
|
|
var head = element("div");
|
|
var label = element("label", "bf-label", field.label);
|
|
label.htmlFor = id;
|
|
head.appendChild(label);
|
|
if (field.tip) {
|
|
var tip = element("button", "bf-tip", "?");
|
|
tip.type = "button";
|
|
tip.setAttribute("aria-label", field.tip);
|
|
head.append(" ", tip);
|
|
}
|
|
var control = controlFor(field, step[key]);
|
|
control.id = id;
|
|
control.addEventListener(field.type === "select" ? "change" : "input", function () {
|
|
var next = {};
|
|
Object.keys(current).forEach(function (name) {
|
|
Object.defineProperty(next, name, { value: current[name],
|
|
enumerable: true, configurable: true, writable: true });
|
|
});
|
|
var value = read(field, control);
|
|
if (value === undefined) delete next[key];
|
|
else next[key] = value;
|
|
current = next;
|
|
change(next);
|
|
if (field.type === "select") {
|
|
render(host, next, context, change);
|
|
var again = host.querySelector("[data-flow-field='" + field.key + "'] select");
|
|
if (again) again.focus();
|
|
}
|
|
});
|
|
wrap.append(head, control);
|
|
host.appendChild(wrap);
|
|
});
|
|
}
|
|
|
|
window.FlareFlowForm = { render: render };
|
|
}());
|