@gemboss/ui 0.58.0 → 0.60.0
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/CHANGELOG.md +127 -0
- package/README.md +239 -5
- package/catalog/editor.html +1 -1
- package/catalog/index.html +2 -2
- package/gemboss-ui.css +2 -2
- package/node/skill-flow/layout.js +194 -0
- package/node/skill-flow/model.js +279 -0
- package/package.json +20 -2
- package/parts/components.css +1 -1
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/auth-sso-plain.js +1 -1
- package/src/auth.tsx +2 -0
- package/src/editor.css +1 -1
- package/src/index-table.tsx +10 -3
- package/src/index.ts +19 -1
- package/src/kind-art.css +1 -0
- package/src/kind-art.tsx +132 -0
- package/src/list-page.css +1 -1
- package/src/members-data.ts +278 -0
- package/src/members.css +1 -0
- package/src/members.tsx +868 -0
- package/src/menu-extras.css +1 -1
- package/src/menu-select.css +1 -0
- package/src/menu.tsx +39 -12
- package/src/notice.css +1 -0
- package/src/notice.tsx +34 -0
- package/src/progress-bar.css +1 -0
- package/src/progress-bar.tsx +45 -0
- package/src/skill-card.css +1 -0
- package/src/skill-card.tsx +146 -0
- package/src/skill-flow/canvas.tsx +43 -24
- package/src/skill-flow/index.ts +3 -1
- package/src/skill-flow/layout.ts +15 -6
- package/src/skill-flow/model.ts +216 -60
- package/src/skill-flow.css +1 -1
- package/src/skill-view.css +1 -1
- package/src/skill-view.tsx +101 -109
- package/src/theme-dark.css +1 -1
- package/src/versions.css +1 -0
- package/src/versions.tsx +62 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// @gemboss/ui: src/skill-flow/layout.ts as plain JavaScript, for Node (the "node" condition of the published manifest). Generated by
|
|
2
|
+
// scripts/pack-lib.mjs compileForNode at build; edit the .ts.
|
|
3
|
+
import * as dagreModule from "@dagrejs/dagre";
|
|
4
|
+
import { FLOW_DIRECTIONS, shortTool, validateFlow } from "./model.js";
|
|
5
|
+
const dagre = dagreModule.graphlib ? dagreModule : dagreModule.default;
|
|
6
|
+
const NODE_W = { start: 184, end: 184, step: 212, stop: 212, decision: 212, exit: 188 };
|
|
7
|
+
const LANE = { head: 34, pad: 14, gap: 44, min: 240, side: 40 };
|
|
8
|
+
function nodeSize(n) {
|
|
9
|
+
const width = NODE_W[n.kind] || 212;
|
|
10
|
+
const inner = width - (n.kind === "decision" ? 44 : 26);
|
|
11
|
+
const eyebrow = n.kind === "step" && !n.human ? 0 : 16;
|
|
12
|
+
const lines = Math.min(2, Math.max(1, Math.ceil(n.label.length / Math.floor(inner / 7.6))));
|
|
13
|
+
let rows = 0;
|
|
14
|
+
let used = Infinity;
|
|
15
|
+
for (const t of n.tools || []) {
|
|
16
|
+
const w = Math.ceil(shortTool(t).length * 6.7) + 14;
|
|
17
|
+
if (used + 4 + w > inner) {
|
|
18
|
+
rows += 1;
|
|
19
|
+
used = w;
|
|
20
|
+
} else used += 4 + w;
|
|
21
|
+
}
|
|
22
|
+
const height = 18 + eyebrow + lines * 18 + (rows ? 6 + rows * 18 + (rows - 1) * 4 : 0);
|
|
23
|
+
return { width, height: Math.max(height, 44) };
|
|
24
|
+
}
|
|
25
|
+
function dagreLayout(nodes, edges, rankdir) {
|
|
26
|
+
const tb = rankdir === "TB";
|
|
27
|
+
const ids = new Set(nodes.map((n) => n.id));
|
|
28
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
29
|
+
const side = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const n of nodes) {
|
|
31
|
+
if (n.kind !== "exit") continue;
|
|
32
|
+
const into = edges.find((e) => e.to === n.id && ids.has(e.from) && byId.get(e.from).kind !== "exit");
|
|
33
|
+
if (into) side.set(n.id, into.from);
|
|
34
|
+
}
|
|
35
|
+
const g = new dagre.graphlib.Graph();
|
|
36
|
+
g.setGraph({ rankdir, align: "UR", nodesep: 22, ranksep: 40, edgesep: 12, marginx: 0, marginy: 0 });
|
|
37
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
38
|
+
for (const n of nodes) if (!side.has(n.id)) g.setNode(n.id, { ...n.size });
|
|
39
|
+
for (const e of edges) {
|
|
40
|
+
if (e.kind === "loop" || !g.hasNode(e.from) || !g.hasNode(e.to)) continue;
|
|
41
|
+
g.setEdge(e.from, e.to, { minlen: 1, weight: e.kind === "no" ? 1 : 3 });
|
|
42
|
+
}
|
|
43
|
+
dagre.layout(g);
|
|
44
|
+
const gr = g.graph();
|
|
45
|
+
let width = gr.width || 0;
|
|
46
|
+
let height = gr.height || 0;
|
|
47
|
+
const pos = /* @__PURE__ */ new Map();
|
|
48
|
+
for (const n of nodes) {
|
|
49
|
+
if (side.has(n.id)) continue;
|
|
50
|
+
const p = g.node(n.id);
|
|
51
|
+
pos.set(n.id, tb ? { x: width - p.x - n.size.width / 2, y: p.y - n.size.height / 2 } : { x: p.x - n.size.width / 2, y: height - p.y - n.size.height / 2 });
|
|
52
|
+
}
|
|
53
|
+
const placed = () => [...pos.entries()].map(([id, p]) => ({ ...p, w: byId.get(id).size.width, h: byId.get(id).size.height }));
|
|
54
|
+
for (const [id, parent] of side) {
|
|
55
|
+
const n = byId.get(id);
|
|
56
|
+
const pn = byId.get(parent);
|
|
57
|
+
const p = pos.get(parent);
|
|
58
|
+
let q;
|
|
59
|
+
if (tb) {
|
|
60
|
+
const y = Math.max(0, p.y + (pn.size.height - n.size.height) / 2);
|
|
61
|
+
const row = placed().filter((b) => b.y < y + n.size.height && b.y + b.h > y && b.x >= p.x);
|
|
62
|
+
q = { x: Math.max(...row.map((b) => b.x + b.w)) + LANE.side, y };
|
|
63
|
+
} else {
|
|
64
|
+
const x = Math.max(0, p.x + (pn.size.width - n.size.width) / 2);
|
|
65
|
+
const col = placed().filter((b) => b.x < x + n.size.width && b.x + b.w > x && b.y >= p.y);
|
|
66
|
+
q = { x, y: Math.max(...col.map((b) => b.y + b.h)) + LANE.side };
|
|
67
|
+
}
|
|
68
|
+
pos.set(id, q);
|
|
69
|
+
width = Math.max(width, q.x + n.size.width);
|
|
70
|
+
height = Math.max(height, q.y + n.size.height);
|
|
71
|
+
}
|
|
72
|
+
return { pos, width, height };
|
|
73
|
+
}
|
|
74
|
+
function layoutFlow(input, { phases, direction, lanes = false, messages }) {
|
|
75
|
+
const bare = (n) => n && typeof n === "object" && !Array.isArray(n) ? (({ examples: _x, ...rest }) => rest)(n) : n;
|
|
76
|
+
const obj = input && typeof input === "object" && !Array.isArray(input) ? input : null;
|
|
77
|
+
const flow = validateFlow(obj ? { direction: obj.direction, nodes: Array.isArray(obj.nodes) ? obj.nodes.map(bare) : obj.nodes, edges: obj.edges } : input, { phases, messages });
|
|
78
|
+
const dir = direction && FLOW_DIRECTIONS.includes(direction) ? direction : flow.direction;
|
|
79
|
+
const tb = dir === "TB";
|
|
80
|
+
const list = flow.nodes.map((n) => ({ ...n, size: nodeSize(n) }));
|
|
81
|
+
const byId = new Map(list.map((n) => [n.id, n]));
|
|
82
|
+
const at = /* @__PURE__ */ new Map();
|
|
83
|
+
const laneOf = Object.fromEntries(phases.map((p, i) => [p.key, i]));
|
|
84
|
+
const labelOf = Object.fromEntries(phases.map((p) => [p.key, p.label]));
|
|
85
|
+
const present = phases.map((p) => p.key).filter((p) => list.some((n) => n.phase === p));
|
|
86
|
+
const laneIdx = Object.fromEntries(present.map((p, i) => [p, i]));
|
|
87
|
+
const bands = [];
|
|
88
|
+
let width;
|
|
89
|
+
let height;
|
|
90
|
+
if (lanes) {
|
|
91
|
+
let off = 0;
|
|
92
|
+
for (const ph of present) {
|
|
93
|
+
const sub = list.filter((n) => n.phase === ph);
|
|
94
|
+
const L = dagreLayout(sub, flow.edges.filter((e) => byId.get(e.from).phase === ph && byId.get(e.to).phase === ph), dir);
|
|
95
|
+
const cross = tb ? L.width : L.height;
|
|
96
|
+
const inner = Math.max(cross, LANE.min - 2 * LANE.pad);
|
|
97
|
+
const shift = (inner - cross) / 2;
|
|
98
|
+
for (const n of sub) {
|
|
99
|
+
const p = L.pos.get(n.id);
|
|
100
|
+
at.set(n.id, tb ? { x: off + LANE.pad + shift + p.x, y: LANE.head + LANE.pad + p.y } : { x: LANE.head + LANE.pad + p.x, y: off + LANE.pad + shift + p.y });
|
|
101
|
+
}
|
|
102
|
+
const main = LANE.head + 2 * LANE.pad + (tb ? L.height : L.width);
|
|
103
|
+
bands.push(tb ? { phase: ph, x: off, y: 0, width: inner + 2 * LANE.pad, height: main } : { phase: ph, x: 0, y: off, width: main, height: inner + 2 * LANE.pad });
|
|
104
|
+
off += inner + 2 * LANE.pad + LANE.gap;
|
|
105
|
+
}
|
|
106
|
+
const span = Math.max(...bands.map((b) => tb ? b.height : b.width));
|
|
107
|
+
for (const b of bands) {
|
|
108
|
+
if (tb) b.height = span;
|
|
109
|
+
else b.width = span;
|
|
110
|
+
}
|
|
111
|
+
width = tb ? off - LANE.gap : span;
|
|
112
|
+
height = tb ? span : off - LANE.gap;
|
|
113
|
+
} else {
|
|
114
|
+
const L = dagreLayout(list, flow.edges, dir);
|
|
115
|
+
for (const n of list) {
|
|
116
|
+
const p = L.pos.get(n.id);
|
|
117
|
+
at.set(n.id, tb ? { x: LANE.head + LANE.pad + p.x, y: LANE.pad + p.y } : { x: LANE.pad + p.x, y: LANE.head + LANE.pad + p.y });
|
|
118
|
+
}
|
|
119
|
+
width = tb ? LANE.head + LANE.pad + LANE.side * 2 + L.width : 2 * LANE.pad + L.width;
|
|
120
|
+
height = tb ? 2 * LANE.pad + L.height : LANE.head + LANE.pad + LANE.side * 2 + L.height;
|
|
121
|
+
const span = present.map((ph) => {
|
|
122
|
+
const own = list.filter((n) => n.phase === ph).map((n) => {
|
|
123
|
+
const p = at.get(n.id);
|
|
124
|
+
return tb ? [p.y, p.y + n.size.height] : [p.x, p.x + n.size.width];
|
|
125
|
+
});
|
|
126
|
+
return { phase: ph, a: Math.min(...own.map((r) => r[0])), b: Math.max(...own.map((r) => r[1])) };
|
|
127
|
+
});
|
|
128
|
+
const total = tb ? height : width;
|
|
129
|
+
span.forEach((s, i) => {
|
|
130
|
+
const lo = i === 0 ? 0 : (span[i - 1].b + s.a) / 2;
|
|
131
|
+
const hi = i === span.length - 1 ? total : (s.b + span[i + 1].a) / 2;
|
|
132
|
+
bands.push(tb ? { phase: s.phase, x: 0, y: lo, width, height: Math.max(hi - lo, 0) } : { phase: s.phase, x: lo, y: 0, width: Math.max(hi - lo, 0), height });
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const box = (id) => {
|
|
136
|
+
const n = byId.get(id);
|
|
137
|
+
const p = at.get(id);
|
|
138
|
+
const len = tb ? n.size.height : n.size.width;
|
|
139
|
+
const cross = tb ? n.size.width : n.size.height;
|
|
140
|
+
return { m: tb ? p.y : p.x, len, c: tb ? p.x : p.y, mid: (tb ? p.x : p.y) + cross / 2, end: (tb ? p.x : p.y) + cross };
|
|
141
|
+
};
|
|
142
|
+
const F = tb ? ["b", "t"] : ["r", "l"];
|
|
143
|
+
const PLUS = tb ? ["r", "l"] : ["b", "t"];
|
|
144
|
+
const MINUS = tb ? ["l", "r"] : ["t", "b"];
|
|
145
|
+
const BACK = tb ? ["r", "r"] : ["b", "b"];
|
|
146
|
+
const gapAfter = (ph) => {
|
|
147
|
+
const b = bands.find((x) => x.phase === ph);
|
|
148
|
+
return tb ? b.x + b.width + LANE.gap / 2 : b.y + b.height + LANE.gap / 2;
|
|
149
|
+
};
|
|
150
|
+
const edges = flow.edges.map((e, i) => {
|
|
151
|
+
const s = box(e.from);
|
|
152
|
+
const t = box(e.to);
|
|
153
|
+
const sp = byId.get(e.from).phase;
|
|
154
|
+
const tp = byId.get(e.to).phase;
|
|
155
|
+
const dl = lanes ? laneIdx[tp] - laneIdx[sp] : 0;
|
|
156
|
+
const data = { kind: e.kind, label: e.label };
|
|
157
|
+
let pick;
|
|
158
|
+
if (dl) {
|
|
159
|
+
pick = dl > 0 ? PLUS : MINUS;
|
|
160
|
+
data[tb ? "centerX" : "centerY"] = gapAfter(dl > 0 ? present[laneIdx[tp] - 1] : tp) + (e.kind === "loop" ? 8 : -8);
|
|
161
|
+
} else if (t.m >= s.m + s.len - 2) {
|
|
162
|
+
const sideways = byId.get(e.from).kind === "decision" && Math.abs(t.mid - s.mid) > 24;
|
|
163
|
+
pick = sideways ? [t.mid < s.mid ? MINUS[0] : PLUS[0], F[1]] : F;
|
|
164
|
+
const a = Math.min(s.mid, t.mid) - 4;
|
|
165
|
+
const b = Math.max(s.mid, t.mid) + 4;
|
|
166
|
+
const scope = list.filter((n) => n.id !== e.from && n.id !== e.to && (!lanes || n.phase === sp)).map((n) => box(n.id));
|
|
167
|
+
if (!sideways && scope.some((n) => n.m < t.m && n.m + n.len > s.m + s.len && n.c < b && n.end > a)) {
|
|
168
|
+
pick = BACK;
|
|
169
|
+
const far = Math.max(...scope.filter((n) => n.m < t.m + t.len && n.m + n.len > s.m).map((n) => n.end), s.end, t.end);
|
|
170
|
+
data.offset = Math.round(Math.max(20, far - Math.max(s.end, t.end) + 20));
|
|
171
|
+
}
|
|
172
|
+
} else if (t.m + t.len <= s.m + 2) {
|
|
173
|
+
pick = BACK;
|
|
174
|
+
const lo = Math.min(s.m, t.m);
|
|
175
|
+
const hi = Math.max(s.m + s.len, t.m + t.len);
|
|
176
|
+
const far = Math.max(...list.filter((n) => !lanes || n.phase === sp).map((n) => box(n.id)).filter((b) => b.m < hi && b.m + b.len > lo).map((b) => b.end));
|
|
177
|
+
data.offset = Math.round(Math.max(20, far - Math.max(s.end, t.end) + 20));
|
|
178
|
+
} else pick = t.c > s.c ? PLUS : MINUS;
|
|
179
|
+
return { id: `e${i}-${e.from}-${e.to}`, source: e.from, target: e.to, sourceHandle: `s-${pick[0]}`, targetHandle: `t-${pick[1]}`, type: "flow", data };
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
direction: dir,
|
|
183
|
+
lanes: Boolean(lanes),
|
|
184
|
+
width,
|
|
185
|
+
height,
|
|
186
|
+
bands: bands.map((b) => ({ ...b, label: labelOf[b.phase] ?? b.phase, lane: laneOf[b.phase] ?? 0 })),
|
|
187
|
+
nodes: list.map(({ size, ...n }) => ({ id: n.id, type: n.kind, lane: laneOf[n.phase] ?? 0, position: at.get(n.id), width: size.width, height: size.height, data: n })),
|
|
188
|
+
edges
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export {
|
|
192
|
+
layoutFlow,
|
|
193
|
+
nodeSize
|
|
194
|
+
};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// @gemboss/ui: src/skill-flow/model.ts as plain JavaScript, for Node (the "node" condition of the published manifest). Generated by
|
|
2
|
+
// scripts/pack-lib.mjs compileForNode at build; edit the .ts.
|
|
3
|
+
const FLOW_NODE_KINDS = ["start", "step", "decision", "stop", "exit", "end"];
|
|
4
|
+
const FLOW_EDGE_KINDS = ["normal", "yes", "no", "loop"];
|
|
5
|
+
const FLOW_DIRECTIONS = ["TB", "LR"];
|
|
6
|
+
const FLOW_EXAMPLE_KINDS = ["input", "output", "good", "bad", "tool"];
|
|
7
|
+
const FLOW_LIMITS = { nodes: 60, label: 48, detail: 700, edgeLabel: 28, tools: 4, examples: 3, exampleTitle: 60, exampleMd: 900 };
|
|
8
|
+
const TERMINAL = /* @__PURE__ */ new Set(["end", "exit"]);
|
|
9
|
+
const TOP_KEYS = /* @__PURE__ */ new Set(["direction", "nodes", "edges"]);
|
|
10
|
+
const NODE_KEYS = /* @__PURE__ */ new Set(["id", "label", "kind", "phase", "detail", "tools", "human", "examples"]);
|
|
11
|
+
const EXAMPLE_KEYS = /* @__PURE__ */ new Set(["title", "kind", "md"]);
|
|
12
|
+
const EDGE_KEYS = /* @__PURE__ */ new Set(["from", "to", "label", "kind"]);
|
|
13
|
+
const ID = /^[a-z0-9][a-z0-9-]*$/;
|
|
14
|
+
const TOOL = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)?$/;
|
|
15
|
+
const text = (v) => typeof v === "string" ? v.replace(/\s+/g, " ").trim() : "";
|
|
16
|
+
const isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
17
|
+
const FLOW_MESSAGES = {
|
|
18
|
+
notJson: () => "invalid flow: not JSON",
|
|
19
|
+
notObject: () => "invalid flow: must be an object { direction, nodes, edges }",
|
|
20
|
+
invalid: (lines) => `invalid flow (${lines.length} problem${lines.length === 1 ? "" : "s"}): ${lines.join("; ")}`,
|
|
21
|
+
node: ({ n, id }) => `node #${n}${id ? ` "${id}"` : ""}`,
|
|
22
|
+
example: ({ node, n }) => `${node}, example #${n}`,
|
|
23
|
+
edge: ({ n, from, to }) => `edge #${n}${from ? ` ${from} \u2192 ${to}` : ""}`,
|
|
24
|
+
topKey: ({ key }) => `unknown key "${key}" at the top (only direction, nodes, edges)`,
|
|
25
|
+
direction: ({ value, allowed }) => `direction "${value}" is not one of ${allowed}`,
|
|
26
|
+
nodesList: () => "nodes must be a list with at least one node",
|
|
27
|
+
edgesList: () => "edges must be a list",
|
|
28
|
+
tooManyNodes: ({ max }) => `more than ${max} nodes: split the skill or merge steps`,
|
|
29
|
+
notAnObject: () => "must be an object",
|
|
30
|
+
unknownKey: ({ key, known }) => `unknown key "${key}" (known: ${known})`,
|
|
31
|
+
idFormat: () => 'id must be lowercase letters, digits and dashes (e.g. "gather")',
|
|
32
|
+
idTwice: () => "id used twice",
|
|
33
|
+
noLabel: () => "no label",
|
|
34
|
+
labelLong: ({ length, max }) => `label is ${length} characters (at most ${max}; put the rest in detail)`,
|
|
35
|
+
kind: ({ value, allowed }) => `kind "${value}" is not one of ${allowed}`,
|
|
36
|
+
phase: ({ value, allowed }) => `phase "${value}" is not one of ${allowed}`,
|
|
37
|
+
detailText: () => "detail must be text",
|
|
38
|
+
detailLong: ({ max }) => `detail is longer than ${max} characters`,
|
|
39
|
+
toolsList: () => "tools must be a list of tool names",
|
|
40
|
+
toolName: ({ name }) => `tool name "${name}" is not valid`,
|
|
41
|
+
toolTwice: () => "a tool is named twice",
|
|
42
|
+
toolsMany: ({ max }) => `more than ${max} tools (the box is full: split the step)`,
|
|
43
|
+
humanBool: () => "human must be true or false",
|
|
44
|
+
examplesList: () => "examples must be a list",
|
|
45
|
+
examplesMany: ({ max }) => `more than ${max} examples`,
|
|
46
|
+
exampleObject: () => "must be an object { title, kind, md }",
|
|
47
|
+
htmlText: () => "html must be text",
|
|
48
|
+
noTitle: () => "no title",
|
|
49
|
+
titleLong: ({ max }) => `title is longer than ${max} characters`,
|
|
50
|
+
mdEmpty: () => "md is empty",
|
|
51
|
+
mdLong: ({ length, max }) => `md is ${length} characters (at most ${max})`,
|
|
52
|
+
noNode: ({ id }) => `no node "${id}"`,
|
|
53
|
+
selfEdge: () => "a node points at itself",
|
|
54
|
+
branchFromStep: ({ kind }) => `a ${kind} edge only leaves a decision`,
|
|
55
|
+
edgeLabelText: () => "label must be text",
|
|
56
|
+
edgeLabelLong: ({ max }) => `label is longer than ${max} characters`,
|
|
57
|
+
edgeTwice: () => "the same edge twice",
|
|
58
|
+
startCount: ({ count }) => count ? `${count} start nodes (only one)` : "no start node",
|
|
59
|
+
noEnd: () => "no end node",
|
|
60
|
+
startIncoming: ({ id }) => `start node "${id}" must have no edge coming in`,
|
|
61
|
+
endOutgoing: ({ id, kind }) => `node "${id}" (${kind}) ends the flow and must have no edge going out`,
|
|
62
|
+
deadEnd: ({ id }) => `node "${id}" is a dead end: no edge goes out (use kind end or exit to finish)`,
|
|
63
|
+
decisionBranches: ({ id }) => `node "${id}" (decision) needs at least two branches`,
|
|
64
|
+
unreachable: ({ ids }) => `not reachable from start: ${ids.join(", ")}`,
|
|
65
|
+
neverEnds: ({ ids }) => `loops forever, never reaches an end or exit: ${ids.join(", ")}`
|
|
66
|
+
};
|
|
67
|
+
class FlowError extends Error {
|
|
68
|
+
problems;
|
|
69
|
+
constructor(message, problems) {
|
|
70
|
+
super(message);
|
|
71
|
+
this.problems = problems;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function flowProblemText(p, messages) {
|
|
75
|
+
const M = messages ? { ...FLOW_MESSAGES, ...messages } : FLOW_MESSAGES;
|
|
76
|
+
const words = M[p.code](p.params);
|
|
77
|
+
if (!p.at) return words;
|
|
78
|
+
const a = p.at;
|
|
79
|
+
let where;
|
|
80
|
+
if ("edge" in a) where = M.edge({ n: a.edge, from: a.from, to: a.to });
|
|
81
|
+
else {
|
|
82
|
+
where = M.node({ n: a.node, id: a.id });
|
|
83
|
+
if (a.example) where = M.example({ node: where, n: a.example });
|
|
84
|
+
}
|
|
85
|
+
return `${where}: ${words}`;
|
|
86
|
+
}
|
|
87
|
+
function validateFlow(input, { phases, allowHtml = false, messages }) {
|
|
88
|
+
const M = messages ? { ...FLOW_MESSAGES, ...messages } : FLOW_MESSAGES;
|
|
89
|
+
const problems = [];
|
|
90
|
+
const add = (code, params, at) => {
|
|
91
|
+
problems.push(at ? { code, params, at } : { code, params });
|
|
92
|
+
};
|
|
93
|
+
const fail = () => new FlowError(M.invalid(problems.map((p) => flowProblemText(p, M))), problems);
|
|
94
|
+
const fatal = (code) => new FlowError(M[code]({}), [{ code, params: {} }]);
|
|
95
|
+
let x = input;
|
|
96
|
+
if (typeof x === "string") {
|
|
97
|
+
try {
|
|
98
|
+
x = JSON.parse(x);
|
|
99
|
+
} catch {
|
|
100
|
+
throw fatal("notJson");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!isObject(x)) throw fatal("notObject");
|
|
104
|
+
const keys = phases.map((p) => p.key);
|
|
105
|
+
for (const k of Object.keys(x)) if (!TOP_KEYS.has(k)) add("topKey", { key: k });
|
|
106
|
+
const direction = x.direction == null ? "TB" : x.direction;
|
|
107
|
+
if (!FLOW_DIRECTIONS.includes(direction)) add("direction", { value: String(direction), allowed: FLOW_DIRECTIONS.join(" | ") });
|
|
108
|
+
if (!Array.isArray(x.nodes) || !x.nodes.length) add("nodesList", {});
|
|
109
|
+
if (!Array.isArray(x.edges)) add("edgesList", {});
|
|
110
|
+
if (!Array.isArray(x.nodes) || !Array.isArray(x.edges)) throw fail();
|
|
111
|
+
if (x.nodes.length > FLOW_LIMITS.nodes) add("tooManyNodes", { max: FLOW_LIMITS.nodes });
|
|
112
|
+
const nodes = [];
|
|
113
|
+
const byId = /* @__PURE__ */ new Map();
|
|
114
|
+
x.nodes.forEach((n, i) => {
|
|
115
|
+
const at = isObject(n) && typeof n.id === "string" && n.id ? { node: i + 1, id: n.id } : { node: i + 1 };
|
|
116
|
+
if (!isObject(n)) {
|
|
117
|
+
add("notAnObject", {}, at);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
for (const k of Object.keys(n)) if (!NODE_KEYS.has(k)) add("unknownKey", { key: k, known: [...NODE_KEYS].join(", ") }, at);
|
|
121
|
+
const id = text(n.id);
|
|
122
|
+
if (!ID.test(id)) add("idFormat", {}, at);
|
|
123
|
+
else if (byId.has(id)) add("idTwice", {}, at);
|
|
124
|
+
const label = text(n.label);
|
|
125
|
+
if (!label) add("noLabel", {}, at);
|
|
126
|
+
else if (label.length > FLOW_LIMITS.label) add("labelLong", { length: label.length, max: FLOW_LIMITS.label }, at);
|
|
127
|
+
const kind = n.kind == null ? "step" : n.kind;
|
|
128
|
+
if (!FLOW_NODE_KINDS.includes(kind)) add("kind", { value: String(kind), allowed: FLOW_NODE_KINDS.join(" | ") }, at);
|
|
129
|
+
const phase = typeof n.phase === "string" ? n.phase : "";
|
|
130
|
+
if (!keys.includes(phase)) add("phase", { value: phase, allowed: keys.join(" | ") }, at);
|
|
131
|
+
if (n.detail != null && typeof n.detail !== "string") add("detailText", {}, at);
|
|
132
|
+
const detail = text(n.detail);
|
|
133
|
+
if (detail.length > FLOW_LIMITS.detail) add("detailLong", { max: FLOW_LIMITS.detail }, at);
|
|
134
|
+
let tools = [];
|
|
135
|
+
if (n.tools != null) {
|
|
136
|
+
if (!Array.isArray(n.tools)) add("toolsList", {}, at);
|
|
137
|
+
else {
|
|
138
|
+
tools = n.tools.map(text);
|
|
139
|
+
for (const t of tools) if (!TOOL.test(t)) add("toolName", { name: t }, at);
|
|
140
|
+
if (new Set(tools).size !== tools.length) add("toolTwice", {}, at);
|
|
141
|
+
if (tools.length > FLOW_LIMITS.tools) add("toolsMany", { max: FLOW_LIMITS.tools }, at);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (n.human != null && typeof n.human !== "boolean") add("humanBool", {}, at);
|
|
145
|
+
const examples = [];
|
|
146
|
+
if (n.examples != null) {
|
|
147
|
+
if (!Array.isArray(n.examples)) add("examplesList", {}, at);
|
|
148
|
+
else {
|
|
149
|
+
if (n.examples.length > FLOW_LIMITS.examples) add("examplesMany", { max: FLOW_LIMITS.examples }, at);
|
|
150
|
+
n.examples.forEach((ex, j) => {
|
|
151
|
+
const ea = { ...at, example: j + 1 };
|
|
152
|
+
if (!isObject(ex)) {
|
|
153
|
+
add("exampleObject", {}, ea);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
for (const k of Object.keys(ex)) if (!EXAMPLE_KEYS.has(k) && !(allowHtml && k === "html")) add("unknownKey", { key: k, known: "title, kind, md" }, ea);
|
|
157
|
+
if (allowHtml && ex.html != null && typeof ex.html !== "string") add("htmlText", {}, ea);
|
|
158
|
+
const title = text(ex.title);
|
|
159
|
+
if (!title) add("noTitle", {}, ea);
|
|
160
|
+
else if (title.length > FLOW_LIMITS.exampleTitle) add("titleLong", { max: FLOW_LIMITS.exampleTitle }, ea);
|
|
161
|
+
if (!FLOW_EXAMPLE_KINDS.includes(ex.kind)) add("kind", { value: String(ex.kind ?? ""), allowed: FLOW_EXAMPLE_KINDS.join(" | ") }, ea);
|
|
162
|
+
const md = typeof ex.md === "string" ? ex.md.replace(/\r\n?/g, "\n").trim() : "";
|
|
163
|
+
if (!md) add("mdEmpty", {}, ea);
|
|
164
|
+
else if (md.length > FLOW_LIMITS.exampleMd) add("mdLong", { length: md.length, max: FLOW_LIMITS.exampleMd }, ea);
|
|
165
|
+
examples.push({ title, kind: ex.kind, md, ...allowHtml && typeof ex.html === "string" ? { html: ex.html } : {} });
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const node = { id, label, kind, phase, detail, tools, human: n.human === true || kind === "stop", examples };
|
|
170
|
+
nodes.push(node);
|
|
171
|
+
if (ID.test(id) && !byId.has(id)) byId.set(id, node);
|
|
172
|
+
});
|
|
173
|
+
const edges = [];
|
|
174
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
175
|
+
x.edges.forEach((e, i) => {
|
|
176
|
+
const at = isObject(e) && e.from ? { edge: i + 1, from: String(e.from), to: String(e.to) } : { edge: i + 1 };
|
|
177
|
+
if (!isObject(e)) {
|
|
178
|
+
add("notAnObject", {}, at);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
for (const k of Object.keys(e)) if (!EDGE_KEYS.has(k)) add("unknownKey", { key: k, known: [...EDGE_KEYS].join(", ") }, at);
|
|
182
|
+
const from = text(e.from);
|
|
183
|
+
const to = text(e.to);
|
|
184
|
+
if (!byId.has(from)) add("noNode", { id: from }, at);
|
|
185
|
+
if (!byId.has(to)) add("noNode", { id: to }, at);
|
|
186
|
+
if (from && from === to) add("selfEdge", {}, at);
|
|
187
|
+
const kind = e.kind == null ? "normal" : e.kind;
|
|
188
|
+
if (!FLOW_EDGE_KINDS.includes(kind)) add("kind", { value: String(kind), allowed: FLOW_EDGE_KINDS.join(" | ") }, at);
|
|
189
|
+
if ((kind === "yes" || kind === "no") && byId.get(from) && byId.get(from).kind !== "decision") add("branchFromStep", { kind }, at);
|
|
190
|
+
if (e.label != null && typeof e.label !== "string") add("edgeLabelText", {}, at);
|
|
191
|
+
const label = text(e.label);
|
|
192
|
+
if (label.length > FLOW_LIMITS.edgeLabel) add("edgeLabelLong", { max: FLOW_LIMITS.edgeLabel }, at);
|
|
193
|
+
if (pairs.has(`${from}>${to}`)) add("edgeTwice", {}, at);
|
|
194
|
+
pairs.add(`${from}>${to}`);
|
|
195
|
+
edges.push({ from, to, label, kind });
|
|
196
|
+
});
|
|
197
|
+
const ok = edges.filter((e) => byId.has(e.from) && byId.has(e.to));
|
|
198
|
+
const outs = (id) => ok.filter((e) => e.from === id);
|
|
199
|
+
const starts = nodes.filter((n) => n.kind === "start");
|
|
200
|
+
if (starts.length !== 1) add("startCount", { count: starts.length });
|
|
201
|
+
if (!nodes.some((n) => n.kind === "end")) add("noEnd", {});
|
|
202
|
+
for (const n of byId.values()) {
|
|
203
|
+
const out = outs(n.id).length;
|
|
204
|
+
if (n.kind === "start" && ok.some((e) => e.to === n.id)) add("startIncoming", { id: n.id });
|
|
205
|
+
if (TERMINAL.has(n.kind) && out) add("endOutgoing", { id: n.id, kind: n.kind });
|
|
206
|
+
if (!TERMINAL.has(n.kind) && !out) add("deadEnd", { id: n.id });
|
|
207
|
+
if (n.kind === "decision" && out && out < 2) add("decisionBranches", { id: n.id });
|
|
208
|
+
}
|
|
209
|
+
if (starts.length === 1 && byId.has(starts[0].id)) {
|
|
210
|
+
const seen = walk(starts[0].id, ok, "from", "to");
|
|
211
|
+
const lost = [...byId.keys()].filter((id) => !seen.has(id));
|
|
212
|
+
if (lost.length) add("unreachable", { ids: lost });
|
|
213
|
+
}
|
|
214
|
+
const ends = [...byId.values()].filter((n) => TERMINAL.has(n.kind)).map((n) => n.id);
|
|
215
|
+
if (ends.length) {
|
|
216
|
+
const back = /* @__PURE__ */ new Set();
|
|
217
|
+
for (const id of ends) for (const s of walk(id, ok, "to", "from")) back.add(s);
|
|
218
|
+
const stuck = [...byId.keys()].filter((id) => !back.has(id));
|
|
219
|
+
if (stuck.length) add("neverEnds", { ids: stuck });
|
|
220
|
+
}
|
|
221
|
+
if (problems.length) throw fail();
|
|
222
|
+
return { direction, nodes, edges };
|
|
223
|
+
}
|
|
224
|
+
function walk(from, edges, a, b) {
|
|
225
|
+
const seen = /* @__PURE__ */ new Set([from]);
|
|
226
|
+
const queue = [from];
|
|
227
|
+
while (queue.length) {
|
|
228
|
+
const id = queue.shift();
|
|
229
|
+
for (const e of edges) if (e[a] === id && !seen.has(e[b])) {
|
|
230
|
+
seen.add(e[b]);
|
|
231
|
+
queue.push(e[b]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return seen;
|
|
235
|
+
}
|
|
236
|
+
function flowWithHtml(flow, render) {
|
|
237
|
+
return { ...flow, nodes: flow.nodes.map((n) => ({ ...n, examples: (n.examples || []).map((x) => ({ ...x, html: render(x.md) })) })) };
|
|
238
|
+
}
|
|
239
|
+
const phasesIn = (flow, phases) => phases.filter((p) => flow.nodes.some((n) => n.phase === p.key));
|
|
240
|
+
const shortTool = (t, prefixes = ["gemboss_", "gemboss.", "radar_"]) => {
|
|
241
|
+
const s = String(t);
|
|
242
|
+
const p = prefixes.find((x) => s.startsWith(x));
|
|
243
|
+
return p ? s.slice(p.length) : s;
|
|
244
|
+
};
|
|
245
|
+
const FLOW_ZOOM = { min: 0.1, max: 4 };
|
|
246
|
+
const flowWheelPans = ({ zoom, home, full = false }) => Boolean(full || home > 0 && zoom > home * 1.02);
|
|
247
|
+
function wheelZoom(vp, { px, py, deltaY, deltaMode = 0 }, { min = FLOW_ZOOM.min, max = FLOW_ZOOM.max } = {}) {
|
|
248
|
+
const d = -Number(deltaY || 0) * (deltaMode === 1 ? 0.05 : deltaMode ? 1 : 2e-3);
|
|
249
|
+
const zoom = Math.min(max, Math.max(min, vp.zoom * 2 ** d));
|
|
250
|
+
const r = zoom / vp.zoom;
|
|
251
|
+
return { x: px - (px - vp.x) * r, y: py - (py - vp.y) * r, zoom };
|
|
252
|
+
}
|
|
253
|
+
const zoomLabel = (z) => `${Math.round(Number(z || 0) * 100)}%`;
|
|
254
|
+
function flowZoomKey({ key, altKey = false } = {}) {
|
|
255
|
+
if (altKey) return null;
|
|
256
|
+
if (key === "+" || key === "=") return "in";
|
|
257
|
+
if (key === "-" || key === "_" || key === "\u2212") return "out";
|
|
258
|
+
if (key === "0") return "reset";
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
export {
|
|
262
|
+
FLOW_DIRECTIONS,
|
|
263
|
+
FLOW_EDGE_KINDS,
|
|
264
|
+
FLOW_EXAMPLE_KINDS,
|
|
265
|
+
FLOW_LIMITS,
|
|
266
|
+
FLOW_MESSAGES,
|
|
267
|
+
FLOW_NODE_KINDS,
|
|
268
|
+
FLOW_ZOOM,
|
|
269
|
+
FlowError,
|
|
270
|
+
flowProblemText,
|
|
271
|
+
flowWheelPans,
|
|
272
|
+
flowWithHtml,
|
|
273
|
+
flowZoomKey,
|
|
274
|
+
phasesIn,
|
|
275
|
+
shortTool,
|
|
276
|
+
validateFlow,
|
|
277
|
+
wheelZoom,
|
|
278
|
+
zoomLabel
|
|
279
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gemboss/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"description": "GemBoss design system for every surface in the fleet: the admin shell (topbar + rail + drawer) as React components, and the admin stylesheet exported as one CSS file.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -54,7 +54,9 @@
|
|
|
54
54
|
"./briefing-card.css": "./src/briefing-card.css",
|
|
55
55
|
"./range-bar.css": "./src/range-bar.css",
|
|
56
56
|
"./progress-ring.css": "./src/progress-ring.css",
|
|
57
|
+
"./progress-bar.css": "./src/progress-bar.css",
|
|
57
58
|
"./spot-art.css": "./src/spot-art.css",
|
|
59
|
+
"./kind-art.css": "./src/kind-art.css",
|
|
58
60
|
"./stage.css": "./src/stage.css",
|
|
59
61
|
"./gem-holo.css": "./src/gem-holo.css",
|
|
60
62
|
"./gems.css": "./src/gems.css",
|
|
@@ -67,9 +69,13 @@
|
|
|
67
69
|
"./translation-row.css": "./src/translation-row.css",
|
|
68
70
|
"./status-list.css": "./src/status-list.css",
|
|
69
71
|
"./job-card.css": "./src/job-card.css",
|
|
72
|
+
"./versions.css": "./src/versions.css",
|
|
73
|
+
"./notice.css": "./src/notice.css",
|
|
70
74
|
"./skill-view.css": "./src/skill-view.css",
|
|
75
|
+
"./skill-card.css": "./src/skill-card.css",
|
|
71
76
|
"./skill-stats.css": "./src/skill-stats.css",
|
|
72
77
|
"./skill-flow.css": "./src/skill-flow.css",
|
|
78
|
+
"./members.css": "./src/members.css",
|
|
73
79
|
"./minichart.css": "./src/minichart.css",
|
|
74
80
|
"./setup-guide.css": "./src/setup-guide.css",
|
|
75
81
|
"./sheet.css": "./src/sheet.css",
|
|
@@ -85,13 +91,23 @@
|
|
|
85
91
|
"./services": "./src/services.ts",
|
|
86
92
|
"./service-switcher": "./src/service-switcher.tsx",
|
|
87
93
|
"./reactions-data": "./src/reactions-data.ts",
|
|
94
|
+
"./members-data": "./src/members-data.ts",
|
|
88
95
|
"./editor": "./src/editor/index.ts",
|
|
89
96
|
"./editor/swatch": "./src/editor/swatch.ts",
|
|
90
97
|
"./segmented": "./src/segmented.tsx",
|
|
91
98
|
"./screens-arriving": "./src/screens-arriving.ts",
|
|
92
99
|
"./gem-holo": "./src/gem-holo.tsx",
|
|
93
100
|
"./skill-flow": "./src/skill-flow/index.ts",
|
|
94
|
-
"./skill-flow/model":
|
|
101
|
+
"./skill-flow/model": {
|
|
102
|
+
"types": "./src/skill-flow/model.ts",
|
|
103
|
+
"node": "./node/skill-flow/model.js",
|
|
104
|
+
"default": "./src/skill-flow/model.ts"
|
|
105
|
+
},
|
|
106
|
+
"./skill-flow/layout": {
|
|
107
|
+
"types": "./src/skill-flow/layout.ts",
|
|
108
|
+
"node": "./node/skill-flow/layout.js",
|
|
109
|
+
"default": "./src/skill-flow/layout.ts"
|
|
110
|
+
},
|
|
95
111
|
"./toggle-bar": "./src/toggle-bar.tsx",
|
|
96
112
|
"./editor/css-url": "./src/editor/css-url.ts",
|
|
97
113
|
"./editor-plain.js": "./src/editor-plain.js",
|
|
@@ -105,6 +121,7 @@
|
|
|
105
121
|
"./auth-steps.css": "./src/auth-steps.css",
|
|
106
122
|
"./menu.css": "./src/menu.css",
|
|
107
123
|
"./menu-extras.css": "./src/menu-extras.css",
|
|
124
|
+
"./menu-select.css": "./src/menu-select.css",
|
|
108
125
|
"./list-page.css": "./src/list-page.css",
|
|
109
126
|
"./pager.css": "./src/pager.css",
|
|
110
127
|
"./pager-extras.css": "./src/pager-extras.css",
|
|
@@ -146,6 +163,7 @@
|
|
|
146
163
|
"src/language-switcher-plain.js",
|
|
147
164
|
"src/menu-plain.js",
|
|
148
165
|
"src/icon.svg",
|
|
166
|
+
"node/skill-flow/*.js",
|
|
149
167
|
"!src/**/*.test.*",
|
|
150
168
|
"gemboss-ui.css",
|
|
151
169
|
"parts/*.css",
|