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.
480 lines
22 KiB
JavaScript
480 lines
22 KiB
JavaScript
// The automation flowchart's document model, with nothing on screen in it.
|
|
//
|
|
// An automation package (`.wauto` on a Warden, `.fauto` on FLARE) is an
|
|
// ordered list of steps. The engines run that list top to bottom; they have
|
|
// no jumps and no nested then/else (flare-edge wauto.rs, "flat by design").
|
|
// So the flowchart is a second view of the same list, never a second format:
|
|
//
|
|
// - the graph is derived from the document and holds no state of its own, so
|
|
// graph to document to graph is the identity and nothing is lost;
|
|
// - the only edges an operator draws are "next" edges, and connecting A to B
|
|
// means "B runs right after A": B leaves its old place in the chain;
|
|
// - the other edges are what the engine already does: a false `compare`
|
|
// stops a procedure (or ends a loop's iteration), a `loop_until` that times
|
|
// out does the same, and a loop starts again after its interval. They are
|
|
// drawn, never edited.
|
|
//
|
|
// It touches no element and reads no page. It is a plain global, like the
|
|
// dashboard editor's dashboard-doc.js, because the pages that load it have no
|
|
// build step.
|
|
(function () {
|
|
"use strict";
|
|
|
|
// --- the engines' numbers -------------------------------------------------
|
|
//
|
|
// Copied from the format so the editor can show a problem on the node
|
|
// before a save. The consumer pins each one to its own server constants.
|
|
var STEPS_MAX = 64;
|
|
var SCRIPT_MAX = 32 * 1024;
|
|
var PROMPT_MAX = 16 * 1024;
|
|
var TEXT_MAX = 4000;
|
|
var SUBJECT_MAX = 200;
|
|
var WAIT_MAX = 3600;
|
|
var TTL_MAX = 3600;
|
|
var CHANNEL_MAX = 64;
|
|
var CMPS = ["<", "<=", ">", ">=", "==", "!="];
|
|
var COMMAND_TYPES = ["run_stop_cmd", "setpoint", "reset_cmd", "outlet_cmd"];
|
|
var COMMAND_WORDS = {
|
|
run_stop_cmd: ["run", "stop"],
|
|
reset_cmd: ["reset"],
|
|
outlet_cmd: ["on", "off", "reboot"]
|
|
};
|
|
var MEASURE_TYPES = [
|
|
"voltage_ac", "voltage_dc", "current_ac", "current_dc", "power_active",
|
|
"power_reactive", "power_apparent", "energy", "frequency", "power_factor",
|
|
"state_of_charge", "state_of_health", "rpm", "torque", "vibration",
|
|
"pressure", "flow_rate", "level", "valve_position", "temperature",
|
|
"humidity", "gas_concentration", "wind_speed", "irradiance", "flow_total"
|
|
];
|
|
var CHANNELS = ["mail", "sms"];
|
|
var OUTPUT_NAME = /^[a-z][a-z0-9_]{0,31}$/;
|
|
// 1 to 16 printable ASCII characters, no space, quote or backslash.
|
|
var OUTPUT_UNIT = /^[!#-[\]-~]{1,16}$/;
|
|
var DEVICE = /^rs485:(\d{1,3})$/;
|
|
var SMS = /^\+\d{8,15}$/;
|
|
|
|
// --- the step schema --------------------------------------------------------
|
|
//
|
|
// One table drives both the node's parameter form and the checks shown on
|
|
// the node. A field is
|
|
// {key, label, type, required, options, min, max, tip, when, alias}
|
|
// where type is text, textarea, number, integer, select or value (a JSON
|
|
// scalar), `when(step)` says whether the field applies to this step, and
|
|
// `alias` is a second key the format accepts for the same value.
|
|
var SCRIPT = [
|
|
{ key: "source", label: "Rhai", type: "textarea", required: true, max: SCRIPT_MAX }
|
|
];
|
|
function setpoint(step) { return step.type === "setpoint"; }
|
|
function outlet(step) { return step.type === "outlet_cmd"; }
|
|
var WARDEN = {
|
|
read: [
|
|
{ key: "point", label: "Point", type: "text", required: true, tip: "topic#member, or $key of a point parameter" },
|
|
{ key: "as", label: "Variable", type: "text", required: true, tip: "Later steps read it as $name" }
|
|
],
|
|
compare: [
|
|
{ key: "left", label: "Value", type: "text", required: true, tip: "$variable or $parameter" },
|
|
{ key: "cmp", label: "Comparison", type: "select", options: CMPS, required: true },
|
|
{ key: "right", label: "Against", type: "value", required: true, tip: "Number, true, false or text" }
|
|
],
|
|
write: [
|
|
{ key: "target", label: "Relay", type: "text", required: true, tip: "relay:0, relay:1 or $parameter" },
|
|
{ key: "value", label: "Value", type: "value", required: true, tip: "true or false" }
|
|
],
|
|
wait: [
|
|
{ key: "seconds", label: "Seconds", type: "number", required: true, min: 0, max: WAIT_MAX }
|
|
],
|
|
loop_until: [
|
|
{ key: "point", label: "Point", type: "text", required: true, tip: "topic#member, or $key of a point parameter" },
|
|
{ key: "cmp", label: "Comparison", type: "select", options: CMPS, required: true },
|
|
{ key: "right", alias: "value", label: "Until", type: "value", required: true },
|
|
{ key: "timeout_s", label: "Timeout (s)", type: "integer", min: 0 },
|
|
{ key: "poll_s", label: "Poll every (s)", type: "integer", min: 0 }
|
|
],
|
|
command: [
|
|
{ key: "device", label: "Device", type: "text", required: true, tip: "rs485:<1-247> or $parameter" },
|
|
{ key: "type", label: "Command", type: "select", options: COMMAND_TYPES, required: true },
|
|
{ key: "of", label: "Sets", type: "select", options: MEASURE_TYPES, required: true, when: setpoint },
|
|
{ key: "channel", label: "Channel", type: "integer", required: true, min: 1, max: CHANNEL_MAX, when: outlet },
|
|
{ key: "value", label: "Value", type: "value", required: true }
|
|
],
|
|
output: [
|
|
{ key: "name", label: "Name", type: "text", required: true, tip: "a-z, 0-9 and _, starting with a letter" },
|
|
{ key: "value", label: "Value", type: "value", required: true, tip: "Number, true, false or $name" },
|
|
{ key: "unit", label: "Unit", type: "text" },
|
|
{ key: "ttl_s", label: "Lifetime (s)", type: "integer", min: 1, max: TTL_MAX }
|
|
],
|
|
script: SCRIPT
|
|
};
|
|
var BACKEND = {
|
|
ai: [
|
|
{ key: "prompt", label: "Prompt", type: "textarea", required: true, max: PROMPT_MAX }
|
|
],
|
|
notify: [
|
|
{ key: "channel", label: "Channel", type: "select", options: CHANNELS, required: true },
|
|
{ key: "to", label: "To", type: "text", required: true, tip: "A mail address, or +<digits> for SMS" },
|
|
{ key: "subject", label: "Subject", type: "text", max: SUBJECT_MAX },
|
|
{ key: "text", label: "Message", type: "textarea", required: true, max: TEXT_MAX }
|
|
],
|
|
script: SCRIPT
|
|
};
|
|
var LABELS = {
|
|
read: "Read", compare: "Compare", write: "Write", wait: "Wait",
|
|
loop_until: "Loop until", command: "Command", output: "Output",
|
|
script: "Rhai", ai: "AI", notify: "Notify"
|
|
};
|
|
|
|
function table(target) { return target === "backend" ? BACKEND : WARDEN; }
|
|
function isObject(value) { return value !== null && typeof value === "object" && !Array.isArray(value); }
|
|
function has(step, key) { return Object.prototype.hasOwnProperty.call(step, key) && step[key] !== null; }
|
|
// The key a field reads: its own, or the alias when only the alias is set.
|
|
function keyOf(step, field) {
|
|
return field.alias && !has(step, field.key) && has(step, field.alias) ? field.alias : field.key;
|
|
}
|
|
|
|
// The fields of one step: none for an op this target does not run.
|
|
function fields(target, step) {
|
|
if (!isObject(step) || typeof step.op !== "string" ||
|
|
!Object.prototype.hasOwnProperty.call(table(target), step.op)) return [];
|
|
var list = table(target)[step.op];
|
|
return list.filter(function (field) { return !field.when || field.when(step); });
|
|
}
|
|
|
|
function ops(target, version) {
|
|
return Object.keys(table(target)).filter(function (op) {
|
|
return op !== "output" || version === 2;
|
|
});
|
|
}
|
|
|
|
// --- value fields -----------------------------------------------------------
|
|
//
|
|
// A `value` field holds a JSON scalar. The text "5" is the number 5 and
|
|
// "true" the boolean; the string "5" is shown quoted so editing a field
|
|
// never turns a string into a number behind the operator's back.
|
|
var NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/;
|
|
function parseValue(text) {
|
|
var trimmed = String(text).trim();
|
|
if (trimmed === "") return undefined;
|
|
if (trimmed === "true") return true;
|
|
if (trimmed === "false") return false;
|
|
if (NUMBER.test(trimmed) && isFinite(Number(trimmed))) return Number(trimmed);
|
|
if (/^["[{]/.test(trimmed) || trimmed === "null") {
|
|
try { return JSON.parse(trimmed); } catch (_) { return text; }
|
|
}
|
|
return text;
|
|
}
|
|
function formatValue(value) {
|
|
if (value === undefined || value === null) return "";
|
|
if (typeof value === "string") {
|
|
return parseValue(value) === value ? value : JSON.stringify(value);
|
|
}
|
|
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
}
|
|
|
|
// --- checks -----------------------------------------------------------------
|
|
//
|
|
// What the server and the Warden would refuse, as far as the step alone
|
|
// shows it. Point grammar and Rhai compilation stay on the server; its
|
|
// refusal names the step, and the editor puts it on that node.
|
|
function fieldErrors(step, field) {
|
|
var key = keyOf(step, field);
|
|
var value = step[key];
|
|
if (!has(step, key) || value === "") {
|
|
return field.required ? [field.label + " is required."] : [];
|
|
}
|
|
switch (field.type) {
|
|
case "text":
|
|
case "textarea":
|
|
if (typeof value !== "string") return [field.label + " must be text."];
|
|
if (field.max && value.length > field.max) return [field.label + " is longer than " + field.max + " characters."];
|
|
return [];
|
|
case "select":
|
|
return field.options.indexOf(value) < 0 ? [field.label + " must be one of " + field.options.join(", ") + "."] : [];
|
|
case "number":
|
|
case "integer":
|
|
if (typeof value !== "number" || !isFinite(value) ||
|
|
(field.type === "integer" && !Number.isInteger(value))) {
|
|
return [field.label + " must be a " + (field.type === "integer" ? "whole number." : "number.")];
|
|
}
|
|
if ((field.min != null && value < field.min) || (field.max != null && value > field.max)) {
|
|
return [field.label + " must be from " + field.min + " to " + (field.max == null ? "any" : field.max) + "."];
|
|
}
|
|
return [];
|
|
default:
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function dollar(value) { return typeof value === "string" && value.length > 1 && value.charAt(0) === "$"; }
|
|
|
|
function opErrors(step) {
|
|
var out = [];
|
|
if (step.op === "command") {
|
|
var device = typeof step.device === "string" ? DEVICE.exec(step.device) : null;
|
|
if (typeof step.device === "string" && step.device && !dollar(step.device) &&
|
|
!(device && +device[1] >= 1 && +device[1] <= 247)) {
|
|
out.push("Device must be rs485:<1-247> or a $parameter.");
|
|
}
|
|
if (step.type !== "setpoint" && has(step, "of")) out.push("Only a setpoint names what it sets.");
|
|
if (step.type !== "outlet_cmd" && has(step, "channel")) out.push("Only an outlet command names a channel.");
|
|
var words = typeof step.type === "string" && Object.prototype.hasOwnProperty.call(COMMAND_WORDS, step.type)
|
|
? COMMAND_WORDS[step.type] : null;
|
|
if (words && has(step, "value") && words.indexOf(step.value) < 0) {
|
|
out.push("Value must be " + words.join(", ") + ".");
|
|
}
|
|
if (step.type === "setpoint" && has(step, "value") &&
|
|
!(typeof step.value === "number" && isFinite(step.value)) && !dollar(step.value)) {
|
|
out.push("A setpoint value must be a number or a $name.");
|
|
}
|
|
}
|
|
if (step.op === "output") {
|
|
if (typeof step.name === "string" && step.name && !OUTPUT_NAME.test(step.name)) {
|
|
out.push("Name must be a-z, 0-9 and _, starting with a letter, up to 32.");
|
|
}
|
|
if (has(step, "value") && !(typeof step.value === "number" && isFinite(step.value)) &&
|
|
typeof step.value !== "boolean" && !dollar(step.value)) {
|
|
out.push("Value must be a number, true, false or a $name.");
|
|
}
|
|
if (typeof step.unit === "string" && step.unit && !OUTPUT_UNIT.test(step.unit)) {
|
|
out.push("Unit must be 1 to 16 characters without spaces or quotes.");
|
|
}
|
|
}
|
|
if (step.op === "script" && has(step, "lang") && step.lang !== "rhai") {
|
|
out.push("A script step runs Rhai only.");
|
|
}
|
|
if (step.op === "notify" && typeof step.to === "string" && step.to) {
|
|
if (step.channel === "sms" && !SMS.test(step.to)) out.push("An SMS recipient is + and 8 to 15 digits.");
|
|
if (step.channel === "mail" && step.to.indexOf("@") < 1) out.push("A mail recipient needs an address.");
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// Every problem with one step, as sentences. `context` is
|
|
// {target, version}; the version gates the output step.
|
|
function stepErrors(step, context) {
|
|
if (!isObject(step)) return ["A step must be an object."];
|
|
var target = context.target;
|
|
if (typeof step.op !== "string" || !Object.prototype.hasOwnProperty.call(table(target), step.op)) {
|
|
return ["This editor target does not run " + JSON.stringify(step.op == null ? "" : step.op) + " steps."];
|
|
}
|
|
if (step.op === "output" && context.version !== 2) {
|
|
return ["An output step needs a version 2 package."];
|
|
}
|
|
var out = [];
|
|
fields(target, step).forEach(function (field) {
|
|
out = out.concat(fieldErrors(step, field));
|
|
});
|
|
return out.concat(opErrors(step));
|
|
}
|
|
|
|
// The problems of a whole package, by step index, plus the package's own.
|
|
function documentErrors(doc, context) {
|
|
var steps = Array.isArray(doc.steps) ? doc.steps : [];
|
|
var byStep = {};
|
|
var names = new Set();
|
|
steps.forEach(function (step, index) {
|
|
var list = stepErrors(step, context);
|
|
if (isObject(step) && step.op === "output" && typeof step.name === "string" && step.name) {
|
|
if (names.has(step.name)) list.push("Another output step already uses this name.");
|
|
names.add(step.name);
|
|
}
|
|
if (list.length) byStep[index] = list;
|
|
});
|
|
var own = steps.length > STEPS_MAX ? ["A package holds at most " + STEPS_MAX + " steps."] : [];
|
|
return { steps: byStep, package: own };
|
|
}
|
|
|
|
// One line that says what a step does, for its node.
|
|
function describe(step) {
|
|
if (!isObject(step)) return "Not a step";
|
|
var value = function (key) { return formatValue(step[key]); };
|
|
var text = function (key) {
|
|
var v = step[key];
|
|
return v == null ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
};
|
|
switch (step.op) {
|
|
case "read": return (text("point") || "Choose a point") + (step.as ? " as $" + text("as") : "");
|
|
case "compare": return [value("left") || "?", text("cmp") || "?", value("right") || "?"].join(" ");
|
|
case "write": return (text("target") || "Choose a relay") + " = " + (value("value") || "?");
|
|
case "wait": return (step.seconds == null ? "?" : text("seconds")) + " seconds";
|
|
case "loop_until": return (text("point") || "Choose a point") + " " + (text("cmp") || "?") + " " +
|
|
(value(has(step, "right") ? "right" : "value") || "?");
|
|
case "command": return [text("device") || "Choose a device", text("type"), text("of"), value("value")]
|
|
.filter(function (part) { return part != null && part !== ""; }).join(" ");
|
|
case "output": return (text("name") || "Name the output") + " = " + (value("value") || "?") + (step.unit ? " " + text("unit") : "");
|
|
case "script": return text("source") || "Add a Rhai expression";
|
|
case "ai": return text("prompt") || "Add a prompt";
|
|
case "notify": return (text("channel") || "mail") + " to " + (text("to") || "recipient");
|
|
default: return "Configure this step";
|
|
}
|
|
}
|
|
|
|
function label(step) {
|
|
return isObject(step) && typeof step.op === "string" && Object.prototype.hasOwnProperty.call(LABELS, step.op)
|
|
? LABELS[step.op] : formatValue(isObject(step) && step.op != null ? step.op : "step");
|
|
}
|
|
|
|
// --- the graph ----------------------------------------------------------------
|
|
//
|
|
// {kind, nodes, edges, next}. Nodes are `start`, one `s<n>` per step, `end`,
|
|
// and `stop` when a procedure has a step that can stop it. Edges are
|
|
// {from, to, kind}: `next` (drawn and connected by the operator), and the
|
|
// derived `false`, `timeout` and `repeat`. `next` numbers new step nodes.
|
|
function build(kind, chain, next) {
|
|
var loop = kind === "loop";
|
|
var nodes = [{ id: "start", type: "start" }];
|
|
var edges = [];
|
|
var exit = loop ? "end" : "stop";
|
|
var stops = false;
|
|
var previous = "start";
|
|
chain.forEach(function (node) {
|
|
nodes.push({ id: node.id, type: "step", step: node.step });
|
|
edges.push({ from: previous, to: node.id, kind: "next" });
|
|
previous = node.id;
|
|
});
|
|
edges.push({ from: previous, to: "end", kind: "next" });
|
|
nodes.push({ id: "end", type: "end" });
|
|
chain.forEach(function (node) {
|
|
var op = isObject(node.step) ? node.step.op : null;
|
|
if (op === "compare" || op === "loop_until") {
|
|
edges.push({ from: node.id, to: exit, kind: op === "compare" ? "false" : "timeout" });
|
|
stops = true;
|
|
}
|
|
});
|
|
if (stops && !loop) nodes.push({ id: "stop", type: "stop" });
|
|
if (loop) edges.push({ from: "end", to: "start", kind: "repeat" });
|
|
return { kind: loop ? "loop" : "procedure", nodes: nodes, edges: edges, next: next };
|
|
}
|
|
|
|
function toGraph(doc) {
|
|
var steps = Array.isArray(doc.steps) ? doc.steps : [];
|
|
return build(doc.kind, steps.map(function (step, index) {
|
|
return { id: "s" + index, step: step };
|
|
}), steps.length);
|
|
}
|
|
|
|
function node(graph, id) {
|
|
return graph.nodes.find(function (item) { return item.id === id; });
|
|
}
|
|
|
|
// The steps in run order: follow `next` from start to end. A graph where
|
|
// that walk skips a step, meets one twice or never ends is refused, so a
|
|
// document can only ever be written from one straight chain.
|
|
function order(graph) {
|
|
var steps = graph.nodes.filter(function (item) { return item.type === "step"; });
|
|
var next = {};
|
|
graph.edges.forEach(function (edge) {
|
|
if (edge.kind !== "next") return;
|
|
if (Object.prototype.hasOwnProperty.call(next, edge.from)) throw new Error("Two next edges leave " + edge.from + ".");
|
|
next[edge.from] = edge.to;
|
|
});
|
|
var chain = [];
|
|
var seen = {};
|
|
var at = next.start;
|
|
while (at !== "end") {
|
|
var item = at == null ? null : node(graph, at);
|
|
if (!item || item.type !== "step" || seen[at]) throw new Error("The chain from start does not reach end.");
|
|
seen[at] = true;
|
|
chain.push(item);
|
|
at = next[at];
|
|
}
|
|
if (chain.length !== steps.length) throw new Error("A step is not on the chain.");
|
|
return chain;
|
|
}
|
|
|
|
// The document a graph stands for: `doc` with its steps in chain order.
|
|
// Every other field, and each step object, is carried as it is; keys keep
|
|
// their order, so the JSON text of an unedited document does not change.
|
|
function toDocument(graph, doc) {
|
|
var steps = order(graph).map(function (item) { return item.step; });
|
|
var out = {};
|
|
Object.keys(doc).forEach(function (key) {
|
|
Object.defineProperty(out, key, { value: key === "steps" ? steps : doc[key],
|
|
enumerable: true, configurable: true, writable: true });
|
|
});
|
|
if (!Object.prototype.hasOwnProperty.call(out, "steps")) out.steps = steps;
|
|
return out;
|
|
}
|
|
|
|
function rebuild(graph, chain, next) {
|
|
return build(graph.kind, chain, next == null ? graph.next : next);
|
|
}
|
|
|
|
function refuse(graph, reason) { return { graph: graph, error: reason }; }
|
|
|
|
// Each edit returns {graph} or {graph: unchanged, error}. None of them can
|
|
// make a graph the format cannot hold.
|
|
function insert(graph, afterId, step) {
|
|
var chain = order(graph);
|
|
if (chain.length >= STEPS_MAX) return refuse(graph, "A package holds at most " + STEPS_MAX + " steps.");
|
|
var at = afterId === "start" ? 0 : chain.findIndex(function (item) { return item.id === afterId; }) + 1;
|
|
if (afterId === "end" || at === 0 && afterId !== "start") at = chain.length;
|
|
var id = "s" + graph.next;
|
|
chain.splice(at, 0, { id: id, step: step });
|
|
return { graph: rebuild(graph, chain, graph.next + 1), id: id };
|
|
}
|
|
|
|
function remove(graph, id) {
|
|
var chain = order(graph);
|
|
var at = chain.findIndex(function (item) { return item.id === id; });
|
|
if (at < 0) return refuse(graph, "Only a step can be removed.");
|
|
chain.splice(at, 1);
|
|
return { graph: rebuild(graph, chain) };
|
|
}
|
|
|
|
function move(graph, id, to) {
|
|
var chain = order(graph);
|
|
var from = chain.findIndex(function (item) { return item.id === id; });
|
|
if (from < 0) return refuse(graph, "Only a step can move.");
|
|
var target = Math.max(0, Math.min(chain.length - 1, to));
|
|
chain.splice(target, 0, chain.splice(from, 1)[0]);
|
|
return { graph: rebuild(graph, chain) };
|
|
}
|
|
|
|
// Connect `from`'s next edge to `to`: `to` runs right after `from`. From
|
|
// start, `to` runs first; to end, `from` runs last. Anything else, such as
|
|
// a second way out of a step, is not something the format can say.
|
|
function connect(graph, from, to) {
|
|
var chain = order(graph);
|
|
var index = function (id) { return chain.findIndex(function (item) { return item.id === id; }); };
|
|
if (from === to) return refuse(graph, "A step cannot run itself next.");
|
|
if (from === "end" || from === "stop") return refuse(graph, "Nothing runs after the end of a run.");
|
|
if (to === "start" || to === "stop") return refuse(graph, "Only a step or the end can run next.");
|
|
if (from === "start" && to === "end") return refuse(graph, "Remove steps to empty the flow.");
|
|
if (from !== "start" && index(from) < 0) return refuse(graph, "Choose a step to connect from.");
|
|
if (to !== "end" && index(to) < 0) return refuse(graph, "Choose a step to connect to.");
|
|
if (to === "end") return move(graph, from, chain.length - 1);
|
|
var moving = chain.splice(index(to), 1)[0];
|
|
chain.splice(from === "start" ? 0 : index(from) + 1, 0, moving);
|
|
return { graph: rebuild(graph, chain) };
|
|
}
|
|
|
|
function indexOf(graph, id) {
|
|
return order(graph).findIndex(function (item) { return item.id === id; });
|
|
}
|
|
|
|
window.FlareFlowDoc = {
|
|
STEPS_MAX: STEPS_MAX,
|
|
SCRIPT_MAX: SCRIPT_MAX,
|
|
CMPS: CMPS,
|
|
COMMAND_TYPES: COMMAND_TYPES,
|
|
MEASURE_TYPES: MEASURE_TYPES,
|
|
ops: ops,
|
|
fields: fields,
|
|
keyOf: keyOf,
|
|
label: label,
|
|
describe: describe,
|
|
parseValue: parseValue,
|
|
formatValue: formatValue,
|
|
stepErrors: stepErrors,
|
|
documentErrors: documentErrors,
|
|
toGraph: toGraph,
|
|
toDocument: toDocument,
|
|
order: order,
|
|
indexOf: indexOf,
|
|
insert: insert,
|
|
remove: remove,
|
|
move: move,
|
|
connect: connect
|
|
};
|
|
}());
|