@skillstech/thunderlang 1.4.1 → 1.4.2
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 +19 -0
- package/dist/core.cjs +105 -32
- package/dist/index.cjs +1 -1
- package/dist/learn.cjs +1 -1
- package/package.json +1 -1
- package/src/core.d.ts +2 -2
- package/src/core.mjs +1 -1
- package/src/emit.mjs +1 -1
- package/src/react/reading.css +102 -0
- package/src/react/reading.d.mts +17 -7
- package/src/react/reading.mjs +172 -10
- package/src/reading-layout.d.mts +29 -1
- package/src/reading-layout.mjs +71 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# 1.4.2
|
|
2
|
+
|
|
3
|
+
**Upgrade note.** No command, flag, exit code, or JSON shape changed. New in `@skillstech/thunderlang/react`:
|
|
4
|
+
`IOBoxes`, `Flow`, and `Details` (`BigPicture` now draws the IO boxes when an action or rule is in focus). New in
|
|
5
|
+
`./core`: `flowEdgeLabel()` and `detailsLayout()`. `ioBoxes()` gains `getBack.items`; `getBack.text` is unchanged.
|
|
6
|
+
|
|
7
|
+
- **The drawing kit, second part: the IO boxes, Flow, and Details.** `@skillstech/thunderlang/react` now draws the
|
|
8
|
+
whole reading of one action or rule, so the three products show it the same way. `IOBoxes` ("You give it", "You get
|
|
9
|
+
back", "It can stop with" with each stop's line, and "Part of …" back to its Thing), which `BigPicture` now draws when
|
|
10
|
+
an action or rule is in focus. `Flow` (every step at the compiler's lane and row, its Yes / No / For each / Done / If
|
|
11
|
+
it fails edges, marks and colors from DOES, steps not read yet dashed, optional New / Gone marks for Thunder Diff).
|
|
12
|
+
`Details` (the counts at a glance, then You give it / You get back, When it stops, What it changes, Its answers,
|
|
13
|
+
Exact limits, Every step, It relies on, Used by, Questions the code cannot answer). The words come from
|
|
14
|
+
`./core`: `flowEdgeLabel(edge)` and `detailsLayout(readLevel(model, 'details', id))`, which keeps a section only when
|
|
15
|
+
the compiler gave it. Callbacks only (`onLine`, `onUse`, `onThing`); no buttons without them. The stylesheet gains
|
|
16
|
+
the matching `tl-` classes, all on the same color variables. `ioBoxes` gains `getBack.items`: the declared result,
|
|
17
|
+
else the Flow's end steps, so the Big Picture no longer says "Nothing it hands back" for a function whose returns
|
|
18
|
+
have no type (`getBack.text` is unchanged).
|
|
19
|
+
|
|
1
20
|
# 1.4.1
|
|
2
21
|
|
|
3
22
|
**Upgrade note.** No command, flag, exit code, or JSON shape changed. New: the drawing kit entry
|
package/dist/core.cjs
CHANGED
|
@@ -186,6 +186,7 @@ __export(core_exports, {
|
|
|
186
186
|
describeEdit: () => describeEdit,
|
|
187
187
|
detailOf: () => detailOf,
|
|
188
188
|
detailParts: () => detailParts,
|
|
189
|
+
detailsLayout: () => detailsLayout,
|
|
189
190
|
detectLanguage: () => detectLanguage,
|
|
190
191
|
diffGraphs: () => diffGraphs,
|
|
191
192
|
displayLabel: () => displayLabel,
|
|
@@ -198,6 +199,7 @@ __export(core_exports, {
|
|
|
198
199
|
explainPlain: () => explainPlain,
|
|
199
200
|
exprCounts: () => exprCounts,
|
|
200
201
|
findSameRule: () => findSameRule,
|
|
202
|
+
flowEdgeLabel: () => flowEdgeLabel,
|
|
201
203
|
flowOf: () => flowOf,
|
|
202
204
|
formatMoney: () => formatMoney,
|
|
203
205
|
formatValue: () => formatValue,
|
|
@@ -3820,9 +3822,9 @@ var Parser = class {
|
|
|
3820
3822
|
}
|
|
3821
3823
|
if (this.fam === "rs" && this.isOp(";")) {
|
|
3822
3824
|
this.next();
|
|
3823
|
-
const
|
|
3825
|
+
const count2 = this.expr(0.6);
|
|
3824
3826
|
this.eat("]");
|
|
3825
|
-
return { kind: "array", items, repeat:
|
|
3827
|
+
return { kind: "array", items, repeat: count2 };
|
|
3826
3828
|
}
|
|
3827
3829
|
if (!this.isOp("]")) fail2("expected , or ]");
|
|
3828
3830
|
}
|
|
@@ -13343,16 +13345,16 @@ function readTerraform(src, file = "main.tf") {
|
|
|
13343
13345
|
const what = d.kind === "module" ? `the module ${name}${src2 ? ` (${valueText(src2.value, refWords).text})` : ""}` : named(typeWords2(type), name);
|
|
13344
13346
|
const verb = d.kind === "data" ? "Looks up" : d.kind === "module" ? "Uses" : "Creates";
|
|
13345
13347
|
let step = { kind: "call", says: `${verb} ${what}${inWords}`, code: head, line: b.line };
|
|
13346
|
-
const
|
|
13347
|
-
if (
|
|
13348
|
-
const c =
|
|
13348
|
+
const count2 = attrOf(b.body, "count"), fe = attrOf(b.body, "for_each");
|
|
13349
|
+
if (count2) {
|
|
13350
|
+
const c = count2.value;
|
|
13349
13351
|
const cond = c.t === "cond" ? c : null;
|
|
13350
|
-
if (cond && isZero2(cond.no)) step = { kind: "branch", says: question(conditionWords(cond.test, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line:
|
|
13351
|
-
else if (cond && isZero2(cond.yes)) step = { kind: "branch", says: question(conditionWords({ t: "unary", op: "!", x: cond.test }, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line:
|
|
13352
|
+
if (cond && isZero2(cond.no)) step = { kind: "branch", says: question(conditionWords(cond.test, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count2.line, children: [step] };
|
|
13353
|
+
else if (cond && isZero2(cond.yes)) step = { kind: "branch", says: question(conditionWords({ t: "unary", op: "!", x: cond.test }, refWords)), code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count2.line, children: [step] };
|
|
13352
13354
|
else if (c.t === "num") {
|
|
13353
13355
|
if (c.v === 0) step.says += " (none: count is 0)";
|
|
13354
13356
|
else if (c.v !== 1) step.says = `${verb} ${c.v} of ${what}${inWords}`;
|
|
13355
|
-
} else step = { kind: "loop", says: `As many times as ${valueText(c, refWords).text.replace(` (${APPLIED})`, "")}`, code: `count = ${parsed.src.slice(c.s, c.e)}`, line:
|
|
13357
|
+
} else step = { kind: "loop", says: `As many times as ${valueText(c, refWords).text.replace(` (${APPLIED})`, "")}`, code: `count = ${parsed.src.slice(c.s, c.e)}`, line: count2.line, children: [step] };
|
|
13356
13358
|
} else if (fe) step = { kind: "loop", says: `For each ${forEachWords(fe.value, refWords).replace(/^one for each /, "")}`, code: `for_each = ${parsed.src.slice(fe.value.s, fe.value.e)}`, line: fe.line, children: [step] };
|
|
13357
13359
|
steps.push(step);
|
|
13358
13360
|
}
|
|
@@ -16344,13 +16346,13 @@ var CALLOC = new RegExp(String.raw`^${CAST}(?:z|x|je_|ck_)?calloc\(\s*([\w.]+)\s
|
|
|
16344
16346
|
function memoryFor(value) {
|
|
16345
16347
|
const v = String(value).trim().replace(/;$/, "");
|
|
16346
16348
|
const ofType = (t) => words7(String(t).replace(/\b(?:struct|const|unsigned)\s+/g, "").replace(/\s*\*+$/, "").trim().split("::").pop());
|
|
16347
|
-
const
|
|
16349
|
+
const count2 = (n) => /^\d+$/.test(n.trim()) ? n.trim() : words7(n.trim());
|
|
16348
16350
|
let m;
|
|
16349
16351
|
if (m = v.match(ALLOC_ONE)) return `memory for one ${ofType(m[1])}`;
|
|
16350
|
-
if (m = v.match(ALLOC_N)) return `memory for ${
|
|
16351
|
-
if (m = v.match(ALLOC_N2)) return `memory for ${
|
|
16352
|
-
if (m = v.match(CALLOC)) return m[1].trim() === "1" ? `memory for one ${ofType(m[2])}` : `memory for ${
|
|
16353
|
-
if (m = v.match(/^new\s+([\w:<>]+)\s*\[\s*([^\]]+?)\s*\]$/)) return `memory for ${
|
|
16352
|
+
if (m = v.match(ALLOC_N)) return `memory for ${count2(m[1])} ${pluralOf(ofType(m[2]))}`;
|
|
16353
|
+
if (m = v.match(ALLOC_N2)) return `memory for ${count2(m[2])} ${pluralOf(ofType(m[1]))}`;
|
|
16354
|
+
if (m = v.match(CALLOC)) return m[1].trim() === "1" ? `memory for one ${ofType(m[2])}` : `memory for ${count2(m[1])} ${pluralOf(ofType(m[2]))}`;
|
|
16355
|
+
if (m = v.match(/^new\s+([\w:<>]+)\s*\[\s*([^\]]+?)\s*\]$/)) return `memory for ${count2(m[2])} ${pluralOf(ofType(m[1]))}`;
|
|
16354
16356
|
if (new RegExp(String.raw`^${CAST}(?:z|x|je_|ck_)?(?:malloc|calloc|alloca|aligned_alloc)\(`).test(v)) return "memory";
|
|
16355
16357
|
return null;
|
|
16356
16358
|
}
|
|
@@ -19405,7 +19407,7 @@ function notesSummary(ast) {
|
|
|
19405
19407
|
byLens
|
|
19406
19408
|
};
|
|
19407
19409
|
}
|
|
19408
|
-
var COMPILER_VERSION = "1.4.
|
|
19410
|
+
var COMPILER_VERSION = "1.4.2";
|
|
19409
19411
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
19410
19412
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
19411
19413
|
function buildContractGraph(ast, generatedAt) {
|
|
@@ -37033,11 +37035,11 @@ function accessFlow(files, { maxRoutes = 2e3 } = {}) {
|
|
|
37033
37035
|
paths
|
|
37034
37036
|
});
|
|
37035
37037
|
}
|
|
37036
|
-
const
|
|
37038
|
+
const count2 = (v) => out.filter((x) => x.verdict === v).length;
|
|
37037
37039
|
return {
|
|
37038
37040
|
schema: ACCESS_SCHEMA,
|
|
37039
37041
|
routes: out,
|
|
37040
|
-
summary: { routes: out.length, guarded:
|
|
37042
|
+
summary: { routes: out.length, guarded: count2("guarded"), unguarded: count2("unguarded"), cannotTell: count2("cannot tell"), noLookup: count2(null) },
|
|
37041
37043
|
unread: project.failures
|
|
37042
37044
|
};
|
|
37043
37045
|
}
|
|
@@ -40302,11 +40304,11 @@ function fromTrace(trace) {
|
|
|
40302
40304
|
const out = [];
|
|
40303
40305
|
for (const [file, f] of Object.entries(trace?.files || {})) {
|
|
40304
40306
|
for (const [L, d] of Object.entries(f.decisions || {})) {
|
|
40305
|
-
for (const [k,
|
|
40307
|
+
for (const [k, count2] of Object.entries(d.obs || {})) {
|
|
40306
40308
|
const [where2, nRaw] = k.split("|");
|
|
40307
40309
|
const next = nRaw === "" || nRaw == null ? null : Number(nRaw);
|
|
40308
40310
|
const side2 = d.kind === "handler" ? "handled" : where2.startsWith("case:") ? where2 : d.kind === "for" ? where2 === "body" ? "each" : "done" : where2 === "body" ? "held" : "not held";
|
|
40309
|
-
out.push({ source: "trace", kind: "decision", file, line: Number(L), side: side2, count, question: d.kind, ...next != null ? { next } : {} });
|
|
40311
|
+
out.push({ source: "trace", kind: "decision", file, line: Number(L), side: side2, count: count2, question: d.kind, ...next != null ? { next } : {} });
|
|
40310
40312
|
}
|
|
40311
40313
|
}
|
|
40312
40314
|
for (const [L, fn] of Object.entries(f.functions || {})) {
|
|
@@ -40512,8 +40514,8 @@ function parseStacks(text2) {
|
|
|
40512
40514
|
}
|
|
40513
40515
|
return out;
|
|
40514
40516
|
}
|
|
40515
|
-
function fromStack(text2, { count = 1 } = {}) {
|
|
40516
|
-
return parseStacks(text2).map((s) => ({ source: "stack", kind: "raise", file: s.frames[0]?.file ?? null, line: s.frames[0]?.line ?? null, error: s.error, message: s.message, frames: s.frames, language: s.language, count, ends: true }));
|
|
40517
|
+
function fromStack(text2, { count: count2 = 1 } = {}) {
|
|
40518
|
+
return parseStacks(text2).map((s) => ({ source: "stack", kind: "raise", file: s.frames[0]?.file ?? null, line: s.frames[0]?.line ?? null, error: s.error, message: s.message, frames: s.frames, language: s.language, count: count2, ends: true }));
|
|
40517
40519
|
}
|
|
40518
40520
|
var LEVEL_NUM = { 10: "trace", 20: "debug", 30: "info", 40: "warn", 50: "error", 60: "fatal" };
|
|
40519
40521
|
var pick = (o, keys) => {
|
|
@@ -40953,8 +40955,8 @@ function hotPath(m, r) {
|
|
|
40953
40955
|
continue;
|
|
40954
40956
|
}
|
|
40955
40957
|
if (nr.sides) {
|
|
40956
|
-
const [label,
|
|
40957
|
-
out.push({ id: n.id, text: n.text, side: label, count });
|
|
40958
|
+
const [label, count2] = Object.entries(nr.sides).sort((a, b2) => b2[1] - a[1])[0];
|
|
40959
|
+
out.push({ id: n.id, text: n.text, side: label, count: count2 });
|
|
40958
40960
|
const key = label === "Yes" ? "yes" : label === "No" ? "no" : label === "For each" ? "each" : null;
|
|
40959
40961
|
const next = key ? b[key] : (b.cases || []).find((c) => c.label === label)?.blocks;
|
|
40960
40962
|
if (next?.length) {
|
|
@@ -41714,13 +41716,13 @@ function summaryOf(e) {
|
|
|
41714
41716
|
function compareThings(A, B, items) {
|
|
41715
41717
|
const key = (t) => `${stemKey2(t.file)}#${nameKey(t.name)}`;
|
|
41716
41718
|
let pairs2 = pairBy(A.model.things, B.model.things, key);
|
|
41717
|
-
const
|
|
41719
|
+
const count2 = (list3) => {
|
|
41718
41720
|
const c = /* @__PURE__ */ new Map();
|
|
41719
41721
|
for (const t of list3) c.set(nameKey(t.name), (c.get(nameKey(t.name)) || 0) + 1);
|
|
41720
41722
|
return c;
|
|
41721
41723
|
};
|
|
41722
41724
|
const lonelyA = pairs2.filter(([a, b]) => a && !b).map(([a]) => a), lonelyB = pairs2.filter(([a, b]) => b && !a).map(([, b]) => b);
|
|
41723
|
-
const ca =
|
|
41725
|
+
const ca = count2(lonelyA), cb = count2(lonelyB);
|
|
41724
41726
|
for (const a of lonelyA) {
|
|
41725
41727
|
if (ca.get(nameKey(a.name)) !== 1 || cb.get(nameKey(a.name)) !== 1) continue;
|
|
41726
41728
|
const b = lonelyB.find((t) => nameKey(t.name) === nameKey(a.name));
|
|
@@ -41949,8 +41951,8 @@ function thunderReview(oldFiles, newFiles) {
|
|
|
41949
41951
|
}
|
|
41950
41952
|
for (const x of items) if (x.also) x.subject = `${x.subject} and ${x.also.length} more`;
|
|
41951
41953
|
items.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) || KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) || String(a.where.file).localeCompare(String(b.where.file)) || (a.where.line ?? 0) - (b.where.line ?? 0));
|
|
41952
|
-
const
|
|
41953
|
-
const summary2 = { meaning:
|
|
41954
|
+
const count2 = (s) => items.filter((x) => x.severity === s).length;
|
|
41955
|
+
const summary2 = { meaning: count2("meaning"), risk: count2("risk"), form: count2("form"), unchanged, files: paths.filter((p) => A.sources.get(p) !== B.sources.get(p)).length };
|
|
41954
41956
|
const onlyNotRead = !items.length && summary2.files && notRead.length === summary2.files;
|
|
41955
41957
|
return { schema: REVIEW_SCHEMA, summary: summary2, says: onlyNotRead ? "Only files Thunder does not read changed." : summaryLine(summary2), items, notRead };
|
|
41956
41958
|
}
|
|
@@ -44268,8 +44270,8 @@ function renderLensDoc(ast, lens) {
|
|
|
44268
44270
|
};
|
|
44269
44271
|
ruleSection("Guarantees", ast.guarantees, "guarantee");
|
|
44270
44272
|
ruleSection("Never", ast.neverRules, "never");
|
|
44271
|
-
const
|
|
44272
|
-
L.push("---", `${
|
|
44273
|
+
const count2 = (ast.notes || []).filter((n) => n.lens === lens).length;
|
|
44274
|
+
L.push("---", `${count2} \`${lens}\` note${count2 === 1 ? "" : "s"} in this mission.`);
|
|
44273
44275
|
return L.join("\n");
|
|
44274
44276
|
}
|
|
44275
44277
|
function renderMermaid(ast) {
|
|
@@ -44787,8 +44789,8 @@ function resolveObligations(ast) {
|
|
|
44787
44789
|
...(ast.guarantees || []).map((g) => build("guarantee", g)),
|
|
44788
44790
|
...(ast.neverRules || []).map((n) => build("prohibition", n))
|
|
44789
44791
|
];
|
|
44790
|
-
const
|
|
44791
|
-
return { obligations, tests, verified:
|
|
44792
|
+
const count2 = (s) => obligations.filter((o) => o.status === s).length;
|
|
44793
|
+
return { obligations, tests, verified: count2("verified"), declared: count2("declared"), unverified: count2("unverified"), failed: count2("failed") };
|
|
44792
44794
|
}
|
|
44793
44795
|
|
|
44794
44796
|
// src/review-atlas.mjs
|
|
@@ -46218,7 +46220,31 @@ var READING_LABELS = Object.freeze({
|
|
|
46218
46220
|
givesNothing: "Nothing",
|
|
46219
46221
|
getsNothing: "Nothing it hands back",
|
|
46220
46222
|
partOf: (label) => `Part of ${label}`,
|
|
46221
|
-
io: "What goes in and out"
|
|
46223
|
+
io: "What goes in and out",
|
|
46224
|
+
// Flow: the words on each kind of edge. An edge label not listed here is shown as the compiler wrote it.
|
|
46225
|
+
edges: Object.freeze({ yes: "Yes", no: "No", each: "For each", done: "Done", error: "If it fails", nested: "Runs on its own", case: "When" }),
|
|
46226
|
+
openLine: (line) => `line ${line}`,
|
|
46227
|
+
openRule: "Open the rule",
|
|
46228
|
+
// Details: what each section is called.
|
|
46229
|
+
details: Object.freeze({
|
|
46230
|
+
stops: "When it stops",
|
|
46231
|
+
noStops: "Thunder found no place where it stops early.",
|
|
46232
|
+
noInputs: "Thunder found no inputs. Check Original if it reads a request or a file.",
|
|
46233
|
+
nothingBack: "Thunder found nothing it gives back.",
|
|
46234
|
+
changes: "What it changes, saves or sends",
|
|
46235
|
+
answers: "Its answers",
|
|
46236
|
+
limits: (fact) => `Exact limits for ${fact}`,
|
|
46237
|
+
limitsHow: "Found by running the rule on every whole number around each limit.",
|
|
46238
|
+
steps: "Every step, with its line",
|
|
46239
|
+
reliesOn: "It relies on",
|
|
46240
|
+
usedBy: "Used by",
|
|
46241
|
+
openQuestions: "Questions the code cannot answer",
|
|
46242
|
+
always: "Always",
|
|
46243
|
+
otherwise: "otherwise",
|
|
46244
|
+
when: (w) => `when ${w}`,
|
|
46245
|
+
usedOn: "used on",
|
|
46246
|
+
atAGlance: "At a glance"
|
|
46247
|
+
})
|
|
46222
46248
|
});
|
|
46223
46249
|
var memberSymbolId = (m) => m.kind === "action" || m.kind === "pipeline" ? "action" : m.kind === "rule" ? "rule" : m.kind === "setup" ? "setup" : m.kind === "not-read" ? "not-read" : "steps";
|
|
46224
46250
|
var knowsLine = (k) => {
|
|
@@ -46255,6 +46281,10 @@ function dataCard(thing) {
|
|
|
46255
46281
|
knows: thing.knows.map(knowsLine)
|
|
46256
46282
|
};
|
|
46257
46283
|
}
|
|
46284
|
+
var givesBackOf = (member) => {
|
|
46285
|
+
const list3 = member.youGetBack ? [member.youGetBack] : (member.flow?.nodes ?? []).filter((n) => n.kind === "end").map((n) => n.text.replace(/^Gives back\s+/i, ""));
|
|
46286
|
+
return [...new Set(list3.filter(Boolean))];
|
|
46287
|
+
};
|
|
46258
46288
|
function ioBoxes(model, member) {
|
|
46259
46289
|
const owner = member.owner ? model.things.find((t) => t.id === member.owner) : null;
|
|
46260
46290
|
const kinds = member.inputKinds ?? {};
|
|
@@ -46266,11 +46296,52 @@ function ioBoxes(model, member) {
|
|
|
46266
46296
|
doc: member.doc ?? null,
|
|
46267
46297
|
symbol: memberSymbolId(member),
|
|
46268
46298
|
give: { heading: READING_LABELS.give, items: member.youGive.map((label) => ({ label, kind: kinds[label] ?? null })), empty: READING_LABELS.givesNothing },
|
|
46269
|
-
|
|
46299
|
+
// What it gives back: what the code declares, else the Flow's end steps (the same facts Flow and Details show).
|
|
46300
|
+
getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, items: givesBackOf(member), empty: READING_LABELS.getsNothing },
|
|
46270
46301
|
stops: { heading: READING_LABELS.stops, items: stops },
|
|
46271
46302
|
partOf: owner ? { id: owner.id, text: READING_LABELS.partOf(owner.label) } : null
|
|
46272
46303
|
};
|
|
46273
46304
|
}
|
|
46305
|
+
function flowEdgeLabel(edge) {
|
|
46306
|
+
if (!edge.label || edge.label === "next") return null;
|
|
46307
|
+
if (edge.label === "case") return edge.text ?? READING_LABELS.edges.case;
|
|
46308
|
+
return READING_LABELS.edges[edge.label] ?? edge.text ?? edge.label;
|
|
46309
|
+
}
|
|
46310
|
+
var count = (n, one, many) => ({ count: n, text: n === 1 ? one : many });
|
|
46311
|
+
function detailsLayout(view2) {
|
|
46312
|
+
const L = READING_LABELS.details;
|
|
46313
|
+
const inputs = view2.inputs ?? (view2.youGive ?? []).map((label) => ({ label, lines: [] }));
|
|
46314
|
+
const givesBack = view2.givesBack?.length ? view2.givesBack.map((g) => ({ text: g.text, line: g.line ?? null, when: g.when ?? null })) : view2.youGetBack ? [{ text: view2.youGetBack, line: null, when: null }] : (view2.flow?.nodes ?? []).filter((n) => n.kind === "end").map((n) => ({ text: n.text, line: n.line ?? null, when: null }));
|
|
46315
|
+
const steps = view2.steps ?? [];
|
|
46316
|
+
const stops = view2.stops ?? null;
|
|
46317
|
+
const changes = view2.changes ?? null;
|
|
46318
|
+
const reliesOn = view2.reliesOn ?? (view2.uses ?? []).map((u) => ({ id: u.id, label: u.label, symbol: "rule", says: "" }));
|
|
46319
|
+
const stats = [
|
|
46320
|
+
...inputs.length ? [{ id: "inputs", ...count(inputs.length, "thing you give it", "things you give it") }] : [],
|
|
46321
|
+
{ id: "steps", ...count(steps.length, "step", "steps") },
|
|
46322
|
+
...stops ? [{ id: "stops", ...count(stops.length, "way to stop", "ways to stop") }] : [],
|
|
46323
|
+
...changes ? [{ id: "changes", ...count(changes.length, "change", "changes") }] : [],
|
|
46324
|
+
...reliesOn.length ? [{ id: "reliesOn", count: reliesOn.length, text: "relies on" }] : [],
|
|
46325
|
+
...(view2.notExplained ?? 0) > 0 ? [{ id: "notExplained", count: view2.notExplained, text: "not explained yet" }] : []
|
|
46326
|
+
];
|
|
46327
|
+
return {
|
|
46328
|
+
id: view2.id ?? null,
|
|
46329
|
+
title: view2.title ?? null,
|
|
46330
|
+
heading: L.atAGlance,
|
|
46331
|
+
stats,
|
|
46332
|
+
give: inputs.length || givesBack.length ? { heading: READING_LABELS.give, items: inputs.map((i) => ({ label: i.label, lines: i.lines ?? [] })), empty: L.noInputs } : null,
|
|
46333
|
+
getBack: inputs.length || givesBack.length ? { heading: READING_LABELS.getBack, items: givesBack, empty: L.nothingBack } : null,
|
|
46334
|
+
stops: stops ? { heading: L.stops, items: stops.map((s) => ({ error: s.error, message: s.message ?? null, line: s.line ?? null, when: s.when ?? [] })), empty: L.noStops } : null,
|
|
46335
|
+
changes: changes?.length ? { heading: L.changes, items: changes.map((c) => ({ text: c.text, does: c.does ?? null, line: c.line ?? null, when: c.when ?? [] })) } : null,
|
|
46336
|
+
answers: view2.answers?.length ? { heading: L.answers, items: view2.answers.map((a) => ({ answer: a.answer, when: a.when === "otherwise" ? L.otherwise : L.when(a.when) })) } : null,
|
|
46337
|
+
limits: view2.limits ? { heading: L.limits(view2.limits.fact), note: L.limitsHow, items: view2.limits.ranges.map((r) => ({ range: r.from == null ? `${r.to} or less` : r.to == null ? `${r.from} or more` : r.from === r.to ? `${r.from}` : `${r.from} to ${r.to}`, answer: r.answer })) } : null,
|
|
46338
|
+
steps: steps.length ? { heading: L.steps, items: steps.map((s) => ({ id: s.id, text: s.text, does: s.does ?? null, mark: s.mark ?? null, depth: s.depth ?? 0, line: s.line ?? null, notExplained: !!s.notExplained, via: s.via ?? null })) } : null,
|
|
46339
|
+
reliesOn: reliesOn.length ? { heading: L.reliesOn, items: reliesOn.map((r) => ({ id: r.id, label: r.label, symbol: r.symbol ?? "rule", says: r.says ?? "" })) } : null,
|
|
46340
|
+
usedBy: view2.usedBy?.length ? { heading: L.usedBy, items: view2.usedBy.map((u) => ({ id: u.id, label: u.label })) } : null,
|
|
46341
|
+
openQuestions: view2.openQuestions?.length ? { heading: L.openQuestions, items: [...view2.openQuestions] } : null,
|
|
46342
|
+
source: view2.source ?? null
|
|
46343
|
+
};
|
|
46344
|
+
}
|
|
46274
46345
|
var sectionsFor = (model, things) => {
|
|
46275
46346
|
const cards = things.filter((t) => t.kind === "thing").map((t) => thingCard(model, t));
|
|
46276
46347
|
const data = [...things.filter((t) => t.kind === "record"), ...things.filter((t) => t.kind === "choices")].map(dataCard);
|
|
@@ -46460,6 +46531,7 @@ function readingLayout(model, { focus = null } = {}) {
|
|
|
46460
46531
|
describeEdit,
|
|
46461
46532
|
detailOf,
|
|
46462
46533
|
detailParts,
|
|
46534
|
+
detailsLayout,
|
|
46463
46535
|
detectLanguage,
|
|
46464
46536
|
diffGraphs,
|
|
46465
46537
|
displayLabel,
|
|
@@ -46472,6 +46544,7 @@ function readingLayout(model, { focus = null } = {}) {
|
|
|
46472
46544
|
explainPlain,
|
|
46473
46545
|
exprCounts,
|
|
46474
46546
|
findSameRule,
|
|
46547
|
+
flowEdgeLabel,
|
|
46475
46548
|
flowOf,
|
|
46476
46549
|
formatMoney,
|
|
46477
46550
|
formatValue,
|
package/dist/index.cjs
CHANGED
|
@@ -2585,7 +2585,7 @@ function notesSummary(ast) {
|
|
|
2585
2585
|
byLens
|
|
2586
2586
|
};
|
|
2587
2587
|
}
|
|
2588
|
-
var COMPILER_VERSION = "1.4.
|
|
2588
|
+
var COMPILER_VERSION = "1.4.2";
|
|
2589
2589
|
var PROOF_SCHEMA_VERSION = "0.1.0";
|
|
2590
2590
|
var SOURCE_PRODUCT = "skillstech-compiler";
|
|
2591
2591
|
function buildContractGraph(ast, generatedAt) {
|
package/dist/learn.cjs
CHANGED
|
@@ -17250,7 +17250,7 @@ var SEMANTIC_TYPES = Object.keys(SEMANTIC);
|
|
|
17250
17250
|
var PRIMITIVE_TYPES = Object.keys(PRIMITIVE);
|
|
17251
17251
|
|
|
17252
17252
|
// src/emit.mjs
|
|
17253
|
-
var COMPILER_VERSION = "1.4.
|
|
17253
|
+
var COMPILER_VERSION = "1.4.2";
|
|
17254
17254
|
|
|
17255
17255
|
// src/lift.mjs
|
|
17256
17256
|
var IR_SCHEMA_VERSION = "0.1.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Thunder™, the human programming language: the deterministic ThunderLang™ compiler, CLI, and Language Server. No AI required. Reads code in seventeen languages into Thunder, changes TypeScript, JavaScript, Python, and Go code from Thunder with a proof, compiles rules to six languages, and executes them: run decisions, simulate lifecycles, and check outcome contracts. Interops with DMN, BPMN, JSON Schema, and OpenAPI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
package/src/core.d.ts
CHANGED
|
@@ -202,5 +202,5 @@ export function writeRuleAcross(files: WriteAcrossFile[], options: { decision: s
|
|
|
202
202
|
export function writeAcrossEvidence(result: WriteAcrossResult | { ok: false }): Array<{ kind: 'rule-write'; status: 'read'; claim: string; basis: unknown; scope: string; inputs: Array<{ part?: string; file: string }> }>;
|
|
203
203
|
|
|
204
204
|
// What a reading shows and in what order (src/reading-layout.mjs).
|
|
205
|
-
export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, memberSymbolId } from './reading-layout.mjs';
|
|
206
|
-
export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, KnowsLine, ThunderSymbolId } from './reading-layout.d.mts';
|
|
205
|
+
export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, memberSymbolId } from './reading-layout.mjs';
|
|
206
|
+
export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, DetailsLayout, When, KnowsLine, ThunderSymbolId } from './reading-layout.d.mts';
|
package/src/core.mjs
CHANGED
|
@@ -139,4 +139,4 @@ export { stepShape } from './write-steps.mjs';
|
|
|
139
139
|
export { PASSPORT_SCHEMA, ALWAYS_NOT_VERIFIED, assemblePassport, summarize, checkPassport, renderPassportSummary, renderPassportMarkdown } from './passport.mjs';
|
|
140
140
|
export { formatValue } from './plain-contract.mjs';
|
|
141
141
|
// What a reading shows and in what order (the drawing kit, @skillstech/thunderlang/react, draws from it).
|
|
142
|
-
export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, memberSymbolId } from './reading-layout.mjs';
|
|
142
|
+
export { READING_LAYOUT_SCHEMA, READING_LABELS, readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, memberSymbolId } from './reading-layout.mjs';
|
package/src/emit.mjs
CHANGED
|
@@ -30,7 +30,7 @@ export function notesSummary(ast) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const COMPILER_VERSION = '1.4.
|
|
33
|
+
export const COMPILER_VERSION = '1.4.2';
|
|
34
34
|
export const PROOF_SCHEMA_VERSION = '0.1.0';
|
|
35
35
|
// Identifies which ecosystem product emitted this proof. Consumed by SkillsTech
|
|
36
36
|
// Certified to key cert proofs to the compiler. Stable slug per the coordination bus.
|
package/src/react/reading.css
CHANGED
|
@@ -117,3 +117,105 @@
|
|
|
117
117
|
.tl-card-title { font-size: 21px; }
|
|
118
118
|
}
|
|
119
119
|
@media (prefers-reduced-motion: no-preference) { .tl-ability-button, .tl-starts-button { transition: border-color 120ms, color 120ms; } }
|
|
120
|
+
|
|
121
|
+
/* Shared small parts */
|
|
122
|
+
.tl-quiet { font-size: 13px; color: var(--tl-text-quiet); }
|
|
123
|
+
.tl-strong { font-size: 15px; color: var(--tl-text); }
|
|
124
|
+
.tl-line { flex: none; margin-left: auto; min-height: 28px; background: none; border: 0; padding: 2px 6px; border-radius: 6px; font: 12px ui-monospace, Menlo, monospace; color: var(--tl-text-quiet); cursor: pointer; }
|
|
125
|
+
.tl-line-inline { margin-left: 0; min-height: 0; padding: 0 2px; }
|
|
126
|
+
.tl-line:hover { background: color-mix(in srgb, var(--tl-text) 6%, transparent); color: var(--tl-text); }
|
|
127
|
+
.tl-line:focus-visible, .tl-node-use:focus-visible, .tl-part-of-button:focus-visible { outline: 2px solid var(--tl-focus); outline-offset: 2px; }
|
|
128
|
+
.tl-pills { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
129
|
+
.tl-pill { display: inline-block; border-radius: 8px; padding: 4px 10px; font-size: 14px; border: 1px solid; }
|
|
130
|
+
.tl-pill-fact { color: var(--tl-c-fact); border-color: color-mix(in srgb, var(--tl-c-fact) 30%, transparent); background: color-mix(in srgb, var(--tl-c-fact) 8%, transparent); }
|
|
131
|
+
.tl-pill-outcome { color: var(--tl-c-outcome); border-color: color-mix(in srgb, var(--tl-c-outcome) 30%, transparent); background: color-mix(in srgb, var(--tl-c-outcome) 8%, transparent); }
|
|
132
|
+
.tl-pill-kind { color: var(--tl-text-muted); }
|
|
133
|
+
|
|
134
|
+
/* What goes in and out (the Big Picture of one action or rule) */
|
|
135
|
+
.tl-io-card { display: grid; gap: 14px; }
|
|
136
|
+
.tl-io-doc { margin-top: 0 !important; }
|
|
137
|
+
.tl-io { display: grid; gap: 14px; grid-template-columns: 1fr; }
|
|
138
|
+
@media (min-width: 560px) { .tl-io { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
139
|
+
.tl-io-box { border: 1px solid var(--tl-border); border-radius: var(--tl-radius-small); background: var(--tl-surface-raised); padding: 14px 16px; }
|
|
140
|
+
.tl-io-give { border-left: 3px solid var(--tl-c-fact); }
|
|
141
|
+
.tl-io-back { border-left: 3px solid var(--tl-c-outcome); }
|
|
142
|
+
.tl-io-stops, .tl-details-stops { border-left: 3px solid var(--tl-c-failure); }
|
|
143
|
+
.tl-io-label, .tl-details-h { display: flex; align-items: center; gap: 6px; margin: 0 0 10px !important; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tl-text-muted); }
|
|
144
|
+
.tl-stop-list { display: grid; gap: 6px; }
|
|
145
|
+
.tl-stop-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tl-text-body); }
|
|
146
|
+
.tl-stop-row .tl-symbol, .tl-io-stops .tl-io-label .tl-symbol { color: var(--tl-c-failure); }
|
|
147
|
+
.tl-stop-text { min-width: 0; }
|
|
148
|
+
.tl-part-of { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tl-text-muted); }
|
|
149
|
+
.tl-part-of-button { min-height: 44px; border: 0; background: none; padding: 0; font: inherit; font-size: 14px; color: var(--tl-text-muted); cursor: pointer; text-align: left; }
|
|
150
|
+
.tl-part-of-button:hover { color: var(--tl-text); }
|
|
151
|
+
|
|
152
|
+
/* Flow */
|
|
153
|
+
.tl-flow { position: relative; display: grid; column-gap: 56px; row-gap: 22px; padding: 6px 4px 12px; overflow-x: auto; }
|
|
154
|
+
.tl-edges { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
|
|
155
|
+
.tl-edges marker path { fill: var(--tl-text-quiet); }
|
|
156
|
+
.tl-edge path { fill: none; stroke: var(--tl-text-quiet); stroke-width: 1.6; }
|
|
157
|
+
.tl-edge-yes path { stroke: var(--tl-c-question); }
|
|
158
|
+
.tl-edge-no path { stroke: var(--tl-c-unread); stroke-dasharray: 5 4; }
|
|
159
|
+
.tl-edge-error path { stroke: var(--tl-c-failure); }
|
|
160
|
+
.tl-edge text { font-size: 11px; font-weight: 600; fill: var(--tl-text-muted); paint-order: stroke; stroke: var(--tl-surface); stroke-width: 4px; }
|
|
161
|
+
.tl-edge-yes text { fill: var(--tl-c-question); }
|
|
162
|
+
.tl-node { --tl-tone: var(--tl-text-quiet); position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 9px 12px; border-radius: var(--tl-radius-small); border: 1px solid var(--tl-border); border-left: 3px solid var(--tl-tone); background: var(--tl-surface-raised); font-size: 14px; color: var(--tl-text-body); }
|
|
163
|
+
.tl-tone-structure { --tl-tone: var(--tl-c-structure); } .tl-tone-question { --tl-tone: var(--tl-c-question); } .tl-tone-fact { --tl-tone: var(--tl-c-fact); }
|
|
164
|
+
.tl-tone-comparison { --tl-tone: var(--tl-c-comparison); } .tl-tone-outcome { --tl-tone: var(--tl-c-outcome); } .tl-tone-failure { --tl-tone: var(--tl-c-failure); }
|
|
165
|
+
.tl-tone-unread { --tl-tone: var(--tl-c-unread); } .tl-tone-amount { --tl-tone: var(--tl-c-amount); }
|
|
166
|
+
.tl-node-mark { flex: none; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: var(--tl-tone); background: color-mix(in srgb, var(--tl-text) 5%, transparent); font-weight: 700; }
|
|
167
|
+
.tl-node-mark .tl-symbol { color: var(--tl-tone); }
|
|
168
|
+
.tl-node-text { flex: 1; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
|
|
169
|
+
.tl-node-decision { background: color-mix(in srgb, var(--tl-c-question) 7%, var(--tl-surface-raised)); }
|
|
170
|
+
.tl-node-decision .tl-node-text { font-weight: 600; }
|
|
171
|
+
.tl-node-stop { background: color-mix(in srgb, var(--tl-c-failure) 8%, var(--tl-surface-raised)); }
|
|
172
|
+
.tl-node-start { background: color-mix(in srgb, var(--tl-c-fact) 6%, var(--tl-surface-raised)); }
|
|
173
|
+
.tl-node-code { border-style: dashed; }
|
|
174
|
+
.tl-node-code code { font-size: 12px; color: var(--tl-text-muted); }
|
|
175
|
+
.tl-node-use { flex: none; min-height: 28px; background: none; border: 0; padding: 2px 6px; border-radius: 6px; font: inherit; font-size: 12px; color: var(--tl-c-question); cursor: pointer; }
|
|
176
|
+
.tl-node-use:hover { background: color-mix(in srgb, var(--tl-text) 6%, transparent); }
|
|
177
|
+
.tl-mark-added { box-shadow: 0 0 0 2px color-mix(in srgb, var(--tl-c-pass) 60%, transparent); }
|
|
178
|
+
.tl-mark-removed { box-shadow: 0 0 0 2px color-mix(in srgb, var(--tl-c-fail) 60%, transparent); opacity: 0.85; }
|
|
179
|
+
.tl-badge { flex: none; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 700; }
|
|
180
|
+
.tl-badge-added { color: var(--tl-c-pass); background: color-mix(in srgb, var(--tl-c-pass) 14%, transparent); }
|
|
181
|
+
.tl-badge-removed { color: var(--tl-c-fail); background: color-mix(in srgb, var(--tl-c-fail) 14%, transparent); }
|
|
182
|
+
|
|
183
|
+
/* Details */
|
|
184
|
+
.tl-details { display: flex; flex-direction: column; gap: 14px; }
|
|
185
|
+
.tl-details-card { padding: 14px 16px; border-radius: var(--tl-radius-small); }
|
|
186
|
+
.tl-details .tl-io-give, .tl-details .tl-io-back { border-left-width: 3px; }
|
|
187
|
+
.tl-stats { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
188
|
+
.tl-stat { padding: 6px 12px; border-radius: 999px; background: var(--tl-surface-raised); border: 1px solid var(--tl-border); font-size: 13px; color: var(--tl-text-muted); }
|
|
189
|
+
.tl-stat b { color: var(--tl-text); font-size: 14px; margin-right: 2px; }
|
|
190
|
+
.tl-stat-stops b { color: var(--tl-c-failure); }
|
|
191
|
+
.tl-stat-notExplained b { color: var(--tl-c-unread); }
|
|
192
|
+
.tl-rows { display: grid; gap: 10px; }
|
|
193
|
+
.tl-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
194
|
+
.tl-message { color: var(--tl-text-muted); font-size: 14px; }
|
|
195
|
+
.tl-inputs { display: grid; gap: 8px; }
|
|
196
|
+
.tl-inputs li { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
|
|
197
|
+
.tl-used { font-size: 12px; color: var(--tl-text-quiet); }
|
|
198
|
+
.tl-when { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; }
|
|
199
|
+
.tl-cond { display: inline-flex; align-items: center; gap: 6px; }
|
|
200
|
+
.tl-cond-q { color: var(--tl-text-body); }
|
|
201
|
+
.tl-cond-and { color: var(--tl-text-quiet); margin-left: 2px; }
|
|
202
|
+
.tl-ans { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; }
|
|
203
|
+
.tl-ans-yes { color: var(--tl-c-question); background: color-mix(in srgb, var(--tl-c-question) 12%, transparent); }
|
|
204
|
+
.tl-ans-no { color: var(--tl-text-muted); background: color-mix(in srgb, var(--tl-c-unread) 14%, transparent); }
|
|
205
|
+
.tl-ans-each { color: var(--tl-c-structure); background: color-mix(in srgb, var(--tl-c-structure) 12%, transparent); }
|
|
206
|
+
.tl-does { flex: none; width: 22px; text-align: center; font-weight: 700; }
|
|
207
|
+
.tl-answers { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
|
|
208
|
+
.tl-limits-note { margin: -4px 0 10px !important; }
|
|
209
|
+
.tl-limits { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
210
|
+
.tl-limit { display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--tl-border); }
|
|
211
|
+
.tl-range { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--tl-c-amount); }
|
|
212
|
+
.tl-steps { display: grid; gap: 2px; }
|
|
213
|
+
.tl-steps li { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--tl-border); font-size: 14px; }
|
|
214
|
+
.tl-steps li:last-child { border-bottom: 0; }
|
|
215
|
+
.tl-step-text { flex: 1; min-width: 0; }
|
|
216
|
+
.tl-step-code code, .tl-step-text code { font-size: 12px; color: var(--tl-text-muted); }
|
|
217
|
+
.tl-source { font-size: 12px; color: var(--tl-text-quiet); }
|
|
218
|
+
@media (max-width: 420px) {
|
|
219
|
+
.tl-io-box, .tl-details-card { padding: 12px; }
|
|
220
|
+
.tl-flow { column-gap: 32px; }
|
|
221
|
+
}
|
package/src/react/reading.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
2
|
-
import type { ThunderModel, Thing } from '../model.d.mts';
|
|
3
|
-
import type { ReadingLayout, ThingCardLayout, DataCardLayout, ThunderSymbolId } from '../reading-layout.d.mts';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { ThunderModel, Thing, Member } from '../model.d.mts';
|
|
3
|
+
import type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, DetailsLayout, ThunderSymbolId } from '../reading-layout.d.mts';
|
|
4
4
|
|
|
5
|
-
export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
|
|
6
|
-
export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, ThunderSymbolId } from '../reading-layout.d.mts';
|
|
5
|
+
export { readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, READING_LABELS } from '../reading-layout.mjs';
|
|
6
|
+
export type { ReadingLayout, ThingCardLayout, DataCardLayout, IOBoxesLayout, DetailsLayout, When, ThunderSymbolId } from '../reading-layout.d.mts';
|
|
7
7
|
|
|
8
8
|
/** A Thunder symbol; its color is the CSS variable for its grammar color (--tl-c-*). */
|
|
9
9
|
export function ThunderSymbol(props: { id: ThunderSymbolId; size?: number; label?: string }): ReactElement | null;
|
|
@@ -11,5 +11,15 @@ export function ThunderSymbol(props: { id: ThunderSymbolId; size?: number; label
|
|
|
11
11
|
export function ThingCard(props: { card?: ThingCardLayout; model?: ThunderModel; thing?: Thing; onOpen?: (memberId: string) => void; selected?: boolean; headingLevel?: 2 | 3 | 4 }): ReactElement;
|
|
12
12
|
/** A Data card: a record or choices. Pass `card` or `thing`. */
|
|
13
13
|
export function DataCard(props: { card?: DataCardLayout; thing?: Thing; headingLevel?: 2 | 3 | 4 }): ReactElement;
|
|
14
|
-
/**
|
|
15
|
-
export function
|
|
14
|
+
/** You give it / You get back / It can stop with, and "Part of <Thing>". Pass `card` or `model` and `member`. */
|
|
15
|
+
export function IOBoxes(props: { card?: IOBoxesLayout; model?: ThunderModel; member?: Member; onLine?: (line: number) => void; onThing?: (thingId: string) => void; headingLevel?: 2 | 3 | 4; children?: ReactNode }): ReactElement;
|
|
16
|
+
/** The Big Picture, zoomed by focus: Things then Data, or an action's or rule's IO boxes (children go under them). */
|
|
17
|
+
export function BigPicture(props: { model?: ThunderModel; layout?: ReadingLayout; focus?: string | null; onOpen?: (memberId: string) => void; onLine?: (line: number) => void; onThing?: (thingId: string) => void; selectedId?: string; headingLevel?: 2 | 3; children?: ReactNode }): ReactElement;
|
|
18
|
+
export interface FlowGraph {
|
|
19
|
+
nodes: { id: string; kind: string; text: string; lane: number; row: number; line?: number | null; does?: string; uses?: string; code?: boolean }[];
|
|
20
|
+
edges: { from: string; to: string; label?: string | null; text?: string }[];
|
|
21
|
+
}
|
|
22
|
+
/** Flow: every step at the compiler's lane and row, with its edges. */
|
|
23
|
+
export function Flow(props: { flow: FlowGraph; onLine?: (line: number) => void; onUse?: (memberId: string) => void; useLabel?: (memberId: string) => string | undefined; marks?: Set<string>; markAs?: 'added' | 'removed' }): ReactElement;
|
|
24
|
+
/** Details: the same action sorted into facts, each with its line. Pass `view` (readLevel details) or `layout`. */
|
|
25
|
+
export function Details(props: { view?: Record<string, any>; layout?: DetailsLayout; onLine?: (line: number) => void; rules?: ReactNode; headingLevel?: 2 | 3 | 4 }): ReactElement;
|
package/src/react/reading.mjs
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// Styling: plain `tl-` class names and one stylesheet (@skillstech/thunderlang/react/reading.css) whose colors are
|
|
5
5
|
// CSS variables, so each app sets its own (STT's --language-accent is honored). No JSX, no build step, no Tailwind:
|
|
6
6
|
// React is the only dependency, and it is the app's own (a peer dependency).
|
|
7
|
-
import { createElement as h, Fragment } from 'react';
|
|
7
|
+
import { createElement as h, Fragment, useLayoutEffect, useRef, useState } from 'react';
|
|
8
8
|
import { THUNDER_VISUAL } from '../visual.mjs';
|
|
9
|
-
import { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
|
|
9
|
+
import { readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, READING_LABELS } from '../reading-layout.mjs';
|
|
10
10
|
|
|
11
|
-
export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS };
|
|
11
|
+
export { readingLayout, thingCard, dataCard, ioBoxes, detailsLayout, flowEdgeLabel, READING_LABELS };
|
|
12
12
|
|
|
13
13
|
/** A Thunder symbol, from the grammar's own path data. Its color is the CSS variable for its grammar color. */
|
|
14
14
|
export function ThunderSymbol({ id, size = 28, label }) {
|
|
@@ -74,14 +74,176 @@ export function DataCard({ card, thing, headingLevel = 3 }) {
|
|
|
74
74
|
c.knows.length ? h('ul', { className: 'tl-knows tl-knows-small' }, c.knows.map(knowsItem)) : null);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** A "line N" button that opens the original code there, or nothing without onLine or a line. */
|
|
78
|
+
const LineButton = ({ line, onLine, className = 'tl-line' }) => (line == null || !onLine ? null
|
|
79
|
+
: h('button', { type: 'button', className, onClick: () => onLine(line), title: 'See the original code at this line' }, READING_LABELS.openLine(line)));
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* What goes in and out of one action or rule: You give it, You get back, It can stop with, and "Part of <Thing>".
|
|
83
|
+
* card: ioBoxes(model, member), or pass `model` and `member`.
|
|
84
|
+
* onLine(line) makes each stop's line a button; onThing(thingId) makes "Part of …" a button back to its card.
|
|
85
|
+
* children: anything the app adds under the boxes (an AI summary, nearby rules).
|
|
86
|
+
*/
|
|
87
|
+
export function IOBoxes({ card, model, member, onLine, onThing, headingLevel = 3, children }) {
|
|
88
|
+
const c = card ?? ioBoxes(model, member);
|
|
89
|
+
const H = `h${headingLevel}`;
|
|
90
|
+
return h('section', { className: 'tl-card tl-io-card', 'aria-label': READING_LABELS.io },
|
|
91
|
+
c.doc ? h('p', { className: 'tl-doc tl-io-doc' }, c.doc) : null,
|
|
92
|
+
h('div', { className: 'tl-io' },
|
|
93
|
+
h('section', { className: 'tl-io-box tl-io-give' },
|
|
94
|
+
h(H, { className: 'tl-io-label' }, h('span', { 'aria-hidden': true }, '→ '), c.give.heading),
|
|
95
|
+
c.give.items.length
|
|
96
|
+
? h('ul', { className: 'tl-pills' }, c.give.items.map((g) => h('li', { key: g.label, className: 'tl-pill tl-pill-fact' }, g.label, g.kind ? h('span', { className: 'tl-pill-kind' }, `: ${g.kind}`) : null)))
|
|
97
|
+
: h('p', { className: 'tl-quiet' }, c.give.empty)),
|
|
98
|
+
h('section', { className: 'tl-io-box tl-io-back' },
|
|
99
|
+
h(H, { className: 'tl-io-label' }, h('span', { 'aria-hidden': true }, '⇥ '), c.getBack.heading),
|
|
100
|
+
c.getBack.items.length ? h('ul', { className: 'tl-pills' }, c.getBack.items.map((t) => h('li', { key: t, className: 'tl-pill tl-pill-outcome' }, t))) : h('p', { className: 'tl-quiet' }, c.getBack.empty))),
|
|
101
|
+
c.stops.items.length ? h('section', { className: 'tl-io-box tl-io-stops' },
|
|
102
|
+
h(H, { className: 'tl-io-label' }, h(ThunderSymbol, { id: 'stop', size: 14 }), ' ', c.stops.heading),
|
|
103
|
+
h('ul', { className: 'tl-stop-list' }, c.stops.items.map((x, i) => h('li', { key: i, className: 'tl-stop-row' },
|
|
104
|
+
h(ThunderSymbol, { id: 'stop', size: 14 }), h('span', { className: 'tl-stop-text' }, x.text), h(LineButton, { line: x.line, onLine }))))) : null,
|
|
105
|
+
children ?? null,
|
|
106
|
+
c.partOf ? (onThing
|
|
107
|
+
? h('button', { type: 'button', className: 'tl-part-of tl-part-of-button', onClick: () => onThing(c.partOf.id) }, h(ThunderSymbol, { id: 'thing', size: 18 }), c.partOf.text)
|
|
108
|
+
: h('p', { className: 'tl-part-of' }, h(ThunderSymbol, { id: 'thing', size: 18 }), c.partOf.text)) : null);
|
|
109
|
+
}
|
|
110
|
+
|
|
77
111
|
/**
|
|
78
|
-
* The Big Picture, zoomed by `focus` (see readingLayout)
|
|
79
|
-
* which joins the kit next; until then that section is left to the app.
|
|
112
|
+
* The Big Picture, zoomed by `focus` (see readingLayout): Things and Data, or, for an action or rule, its IO boxes.
|
|
80
113
|
*/
|
|
81
|
-
export function BigPicture({ model, layout, focus = null, onOpen, selectedId, headingLevel = 2 }) {
|
|
114
|
+
export function BigPicture({ model, layout, focus = null, onOpen, onLine, onThing, selectedId, headingLevel = 2, children }) {
|
|
82
115
|
const l = layout ?? readingLayout(model, { focus });
|
|
83
|
-
return h('div', { className: 'tl-reading tl-big-picture' }, l.sections.
|
|
84
|
-
|
|
85
|
-
? h(
|
|
86
|
-
: h(
|
|
116
|
+
return h('div', { className: 'tl-reading tl-big-picture' }, l.sections.map((s) => h('section', { key: s.id, className: `tl-bp-section tl-bp-${s.id}`, 'aria-label': s.heading },
|
|
117
|
+
s.id === 'io'
|
|
118
|
+
? s.cards.map((c) => h(IOBoxes, { key: c.id, card: c, onLine, onThing, headingLevel: headingLevel + 1 }, children))
|
|
119
|
+
: h('div', { className: s.id === 'things' ? 'tl-bp-things' : 'tl-bp-data' }, s.cards.map((c) => (c.kind === 'thing'
|
|
120
|
+
? h(ThingCard, { key: c.id, card: c, onOpen, selected: c.id === selectedId, headingLevel })
|
|
121
|
+
: h(DataCard, { key: c.id, card: c, headingLevel: headingLevel + 1 })))))));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const doesOf = (does) => THUNDER_VISUAL.does[does ?? ''] ?? { mark: '·', label: 'Does', color: 'structure' };
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Flow: one action or rule, step by step. Every node sits at the lane and row the compiler gives it, every edge is
|
|
128
|
+
* the compiler's (Yes / No / For each / Done / If it fails), each node's mark and color come from DOES. Steps Thunder
|
|
129
|
+
* could only show as code are dashed. The app adds only the interaction:
|
|
130
|
+
* flow: member.flow (or readLevel(model, 'flow', id).flow)
|
|
131
|
+
* onLine(line): each node's line opens the original code. onUse(memberId): a step that uses a rule opens it.
|
|
132
|
+
* marks + markAs: Thunder Diff highlights nodes as 'added' (New) or 'removed' (Gone).
|
|
133
|
+
* Edges are measured from the drawn nodes, so they appear after the first paint (none in server rendering).
|
|
134
|
+
*/
|
|
135
|
+
export function Flow({ flow, onLine, onUse, useLabel, marks, markAs }) {
|
|
136
|
+
const box = useRef(null);
|
|
137
|
+
const refs = useRef(new Map());
|
|
138
|
+
const [pos, setPos] = useState(() => new Map());
|
|
139
|
+
const [size, setSize] = useState({ w: 0, h: 0 });
|
|
140
|
+
const lanes = Math.max(1, ...flow.nodes.map((n) => n.lane + 1));
|
|
141
|
+
useLayoutEffect(() => {
|
|
142
|
+
const measure = () => {
|
|
143
|
+
const root = box.current?.getBoundingClientRect();
|
|
144
|
+
if (!root) return;
|
|
145
|
+
const next = new Map();
|
|
146
|
+
for (const [id, el] of refs.current) { const r = el.getBoundingClientRect(); next.set(id, { x: r.left - root.left, y: r.top - root.top, w: r.width, h: r.height }); }
|
|
147
|
+
setPos(next);
|
|
148
|
+
setSize({ w: box.current.clientWidth, h: box.current.scrollHeight });
|
|
149
|
+
};
|
|
150
|
+
measure();
|
|
151
|
+
const ro = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : null;
|
|
152
|
+
if (ro && box.current) ro.observe(box.current);
|
|
153
|
+
return () => ro?.disconnect();
|
|
154
|
+
}, [flow]);
|
|
155
|
+
const edges = flow.edges.map((e, i) => {
|
|
156
|
+
const a = pos.get(e.from), b = pos.get(e.to);
|
|
157
|
+
if (!a || !b) return null;
|
|
158
|
+
const same = Math.abs(a.x - b.x) < 4;
|
|
159
|
+
const x1 = same ? a.x + a.w / 2 : a.x + a.w, y1 = same ? a.y + a.h : a.y + a.h / 2;
|
|
160
|
+
const x2 = same ? b.x + b.w / 2 : b.x + (b.x > a.x ? 0 : b.w), y2 = same ? b.y : b.y + b.h / 2;
|
|
161
|
+
const d = same ? `M${x1} ${y1} L${x2} ${y2 - 2}` : `M${x1} ${y1} C${(x1 + x2) / 2} ${y1}, ${(x1 + x2) / 2} ${y2}, ${x2 + (b.x > a.x ? -2 : 2)} ${y2}`;
|
|
162
|
+
const label = flowEdgeLabel(e);
|
|
163
|
+
const lx = same ? x1 + 8 : (x1 + x2) / 2, ly = same ? (y1 + y2) / 2 + 4 : Math.min(y1, y2) - 6 + Math.abs(y2 - y1) / 2;
|
|
164
|
+
return h('g', { key: i, className: `tl-edge tl-edge-${e.label ?? 'next'}` }, h('path', { d, markerEnd: 'url(#tl-arrow)' }), label ? h('text', { x: lx, y: ly }, label) : null);
|
|
165
|
+
});
|
|
166
|
+
return h('div', { className: 'tl-reading tl-flow', ref: box, style: { gridTemplateColumns: `repeat(${lanes}, minmax(200px, 1fr))` } },
|
|
167
|
+
h('svg', { className: 'tl-edges', width: size.w, height: size.h, 'aria-hidden': true },
|
|
168
|
+
h('defs', null, h('marker', { id: 'tl-arrow', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0 L10 5 L0 10 z' }))),
|
|
169
|
+
edges),
|
|
170
|
+
flow.nodes.map((n) => {
|
|
171
|
+
const does = doesOf(n.does);
|
|
172
|
+
const color = n.kind === 'stop' ? 'failure' : n.kind === 'decision' ? 'question' : does.color;
|
|
173
|
+
const symbol = n.kind === 'stop' ? 'stop' : n.kind === 'decision' ? 'rule' : n.kind === 'start' ? 'action' : null;
|
|
174
|
+
const mark = marks?.has(n.id) ? markAs : undefined;
|
|
175
|
+
return h('div', {
|
|
176
|
+
key: n.id, ref: (el) => { if (el) refs.current.set(n.id, el); else refs.current.delete(n.id); },
|
|
177
|
+
className: `tl-node tl-node-${n.kind} tl-tone-${color}${n.code || n.kind === 'code' ? ' tl-node-code' : ''}${mark ? ` tl-mark-${mark}` : ''}`,
|
|
178
|
+
style: { gridRow: n.row + 1, gridColumn: n.lane + 1 },
|
|
179
|
+
},
|
|
180
|
+
h('span', { className: 'tl-node-mark', 'aria-hidden': true, title: does.label }, symbol ? h(ThunderSymbol, { id: symbol, size: 15 }) : does.mark),
|
|
181
|
+
mark ? h('span', { className: `tl-badge tl-badge-${mark}` }, mark === 'added' ? 'New' : 'Gone') : null,
|
|
182
|
+
h('span', { className: 'tl-node-text', title: n.text }, n.kind === 'code' ? h('code', null, n.text) : n.text),
|
|
183
|
+
n.uses && onUse ? h('button', { type: 'button', className: 'tl-node-use', onClick: () => onUse(n.uses), title: 'Open the rule this step uses, and try it' }, `${useLabel?.(n.uses) ?? READING_LABELS.openRule} →`) : null,
|
|
184
|
+
h(LineButton, { line: n.line, onLine }));
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function Whens({ when }) {
|
|
189
|
+
if (!when.length) return h('span', { className: 'tl-quiet' }, READING_LABELS.details.always);
|
|
190
|
+
return h(Fragment, null, when.map((w, k) => h('span', { key: k, className: 'tl-cond' },
|
|
191
|
+
h('span', { className: 'tl-cond-q' }, w.question), ' ',
|
|
192
|
+
h('span', { className: `tl-ans tl-ans-${w.answer === 'Yes' ? 'yes' : w.answer === 'No' ? 'no' : 'each'}` }, w.answer),
|
|
193
|
+
k < when.length - 1 ? h('span', { className: 'tl-cond-and', 'aria-hidden': true }, '·') : null)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Details: the same action sorted into facts, each with its line. `view` is readLevel(model, 'details', memberId)
|
|
198
|
+
* (or pass `layout` from detailsLayout). Sections appear only when the compiler gives them.
|
|
199
|
+
* onLine(line) opens the original code. rules: the app's own cards for the rules it relies on, drawn in place of
|
|
200
|
+
* the plain "It relies on" list (OpenThunder's try-it cards).
|
|
201
|
+
*/
|
|
202
|
+
export function Details({ view, layout, onLine, rules, headingLevel = 3 }) {
|
|
203
|
+
const d = layout ?? detailsLayout(view);
|
|
204
|
+
const H = `h${headingLevel}`;
|
|
205
|
+
const card = (cls, heading, icon, ...body) => h('section', { className: `tl-card tl-details-card${cls ? ` ${cls}` : ''}` },
|
|
206
|
+
h(H, { className: 'tl-details-h' }, icon, heading), ...body);
|
|
207
|
+
const doesMark = (does, mark) => { const x = doesOf(does); return h('span', { className: `tl-does tl-c-${x.color}`, title: x.label }, mark || x.mark); };
|
|
208
|
+
return h('div', { className: 'tl-reading tl-details' },
|
|
209
|
+
h('div', { className: 'tl-stats', 'aria-label': d.heading }, d.stats.map((s) => h('span', { key: s.id, className: `tl-stat tl-stat-${s.id}` }, h('b', null, s.count), ` ${s.text}`))),
|
|
210
|
+
d.give ? h('div', { className: 'tl-io' },
|
|
211
|
+
card('tl-io-give', d.give.heading, h('span', { 'aria-hidden': true }, '→ '),
|
|
212
|
+
d.give.items.length ? h('ul', { className: 'tl-inputs' }, d.give.items.map((i) => h('li', { key: i.label },
|
|
213
|
+
h('span', { className: 'tl-pill tl-pill-fact' }, i.label),
|
|
214
|
+
i.lines.length && onLine ? h('span', { className: 'tl-used' }, `${READING_LABELS.details.usedOn} `, i.lines.map((l, k) => h(Fragment, { key: l }, k > 0 ? ', ' : null,
|
|
215
|
+
h('button', { type: 'button', className: 'tl-line tl-line-inline', onClick: () => onLine(l), title: 'See this line' }, l)))) : null)))
|
|
216
|
+
: h('p', { className: 'tl-quiet' }, d.give.empty)),
|
|
217
|
+
card('tl-io-back', d.getBack.heading, h('span', { 'aria-hidden': true }, '⇥ '),
|
|
218
|
+
d.getBack.items.length ? h('ul', { className: 'tl-rows' }, d.getBack.items.map((g, i) => h('li', { key: i },
|
|
219
|
+
h('div', { className: 'tl-row-top' }, h('span', { className: 'tl-strong' }, g.text), h(LineButton, { line: g.line, onLine })),
|
|
220
|
+
g.when ? h('div', { className: 'tl-when' }, h(Whens, { when: g.when })) : null)))
|
|
221
|
+
: h('p', { className: 'tl-quiet' }, d.getBack.empty))) : null,
|
|
222
|
+
d.stops ? card('tl-details-stops', d.stops.heading, h(ThunderSymbol, { id: 'stop', size: 15 }),
|
|
223
|
+
d.stops.items.length ? h('ul', { className: 'tl-rows' }, d.stops.items.map((s, i) => h('li', { key: i, className: 'tl-stop-row-detail' },
|
|
224
|
+
h('div', { className: 'tl-row-top' }, h('b', null, s.error), s.message ? h('span', { className: 'tl-message' }, `"${s.message}"`) : null, h(LineButton, { line: s.line, onLine })),
|
|
225
|
+
h('div', { className: 'tl-when' }, h(Whens, { when: s.when })))))
|
|
226
|
+
: h('p', { className: 'tl-quiet' }, d.stops.empty)) : null,
|
|
227
|
+
d.changes ? card(null, d.changes.heading, h('span', { 'aria-hidden': true }, '= '),
|
|
228
|
+
h('ul', { className: 'tl-rows' }, d.changes.items.map((c, i) => h('li', { key: i },
|
|
229
|
+
h('div', { className: 'tl-row-top' }, doesMark(c.does), h('span', { className: 'tl-strong' }, c.text), h(LineButton, { line: c.line, onLine })),
|
|
230
|
+
c.when.length ? h('div', { className: 'tl-when' }, h(Whens, { when: c.when })) : null)))) : null,
|
|
231
|
+
d.answers ? card(null, d.answers.heading, h(ThunderSymbol, { id: 'rule', size: 15 }),
|
|
232
|
+
h('ol', { className: 'tl-answers' }, d.answers.items.map((a, i) => h('li', { key: i }, h('b', null, a.answer), ' ', h('span', { className: 'tl-quiet' }, a.when))))) : null,
|
|
233
|
+
d.limits ? card(null, d.limits.heading, h(ThunderSymbol, { id: 'rule', size: 15 }),
|
|
234
|
+
h('p', { className: 'tl-quiet tl-limits-note' }, d.limits.note),
|
|
235
|
+
h('div', { className: 'tl-limits' }, d.limits.items.map((r, i) => h('div', { key: i, className: 'tl-limit' }, h('span', { className: 'tl-range' }, r.range), h('b', null, r.answer))))) : null,
|
|
236
|
+
d.steps ? card(null, d.steps.heading, h('span', { 'aria-hidden': true }, '≡ '),
|
|
237
|
+
h('ul', { className: 'tl-steps' }, d.steps.items.map((s) => h('li', { key: s.id, className: s.notExplained ? 'tl-step-code' : undefined, style: { paddingLeft: 4 + s.depth * 18 } },
|
|
238
|
+
doesMark(s.does, s.mark),
|
|
239
|
+
h('span', { className: 'tl-step-text' }, s.notExplained ? h('code', null, s.text) : s.text, s.via ? h('span', { className: 'tl-quiet' }, ` · ${s.via}`) : null),
|
|
240
|
+
h(LineButton, { line: s.line, onLine }))))) : null,
|
|
241
|
+
d.reliesOn && !rules ? card(null, d.reliesOn.heading, h(ThunderSymbol, { id: 'rule', size: 15 }),
|
|
242
|
+
h('ul', { className: 'tl-rows' }, d.reliesOn.items.map((r) => h('li', { key: r.id },
|
|
243
|
+
h('div', { className: 'tl-row-top' }, h(ThunderSymbol, { id: r.symbol, size: 14 }), h('b', null, r.label)),
|
|
244
|
+
r.says ? h('div', { className: 'tl-quiet' }, r.says) : null)))) : null,
|
|
245
|
+
rules ?? null,
|
|
246
|
+
d.usedBy ? h('p', { className: 'tl-quiet' }, `${d.usedBy.heading}: ${d.usedBy.items.map((u) => u.label).join(', ')}.`) : null,
|
|
247
|
+
d.openQuestions ? card('tl-details-open', d.openQuestions.heading, null, h('ul', { className: 'tl-rows' }, d.openQuestions.items.map((q) => h('li', { key: q }, q)))) : null,
|
|
248
|
+
d.source ? h('p', { className: 'tl-source' }, d.source) : null);
|
|
87
249
|
}
|
package/src/reading-layout.d.mts
CHANGED
|
@@ -5,6 +5,13 @@ export const READING_LABELS: Readonly<{
|
|
|
5
5
|
thing: string; knows: string; can: string; starts: (label: string) => string; startsWithKnows: (label: string) => string;
|
|
6
6
|
record: string; choices: string; recordSymbol: string; choicesSymbol: string; things: string; data: string;
|
|
7
7
|
give: string; getBack: string; stops: string; givesNothing: string; getsNothing: string; partOf: (label: string) => string; io: string;
|
|
8
|
+
edges: Readonly<Record<'yes' | 'no' | 'each' | 'done' | 'error' | 'nested' | 'case', string>>;
|
|
9
|
+
openLine: (line: number) => string; openRule: string;
|
|
10
|
+
details: Readonly<{
|
|
11
|
+
stops: string; noStops: string; noInputs: string; nothingBack: string; changes: string; answers: string; limits: (fact: string) => string;
|
|
12
|
+
limitsHow: string; steps: string; reliesOn: string; usedBy: string; openQuestions: string; always: string; otherwise: string;
|
|
13
|
+
when: (w: string) => string; usedOn: string; atAGlance: string;
|
|
14
|
+
}>;
|
|
8
15
|
}>;
|
|
9
16
|
export type ThunderSymbolId = 'app' | 'area' | 'file' | 'thing' | 'data' | 'record' | 'choices' | 'action' | 'rule' | 'steps' | 'setup' | 'stop' | 'not-read' | 'resource' | 'permission';
|
|
10
17
|
export interface KnowsLine { name: string; label: string; detail: string | null; secret?: true; line: number | null }
|
|
@@ -22,7 +29,8 @@ export interface DataCardLayout {
|
|
|
22
29
|
export interface IOBoxesLayout {
|
|
23
30
|
kind: 'io'; id: string; label: string; doc: string | null; symbol: ThunderSymbolId;
|
|
24
31
|
give: { heading: string; items: { label: string; kind: string | null }[]; empty: string };
|
|
25
|
-
|
|
32
|
+
/** text: what the code declares; items: that, else the Flow's end steps (what to draw). */
|
|
33
|
+
getBack: { heading: string; text: string | null; items: string[]; empty: string };
|
|
26
34
|
stops: { heading: string; items: { text: string; line: number | null }[] };
|
|
27
35
|
/** The Thing it belongs to, to link back to its card. */
|
|
28
36
|
partOf: { id: string; text: string } | null;
|
|
@@ -32,6 +40,26 @@ export interface ReadingLayout {
|
|
|
32
40
|
focus: { kind: 'app' | 'file' | 'thing' | 'member' | 'unknown'; id: string | null };
|
|
33
41
|
sections: Array<{ id: 'things'; heading: string; cards: ThingCardLayout[] } | { id: 'data'; heading: string; cards: DataCardLayout[] } | { id: 'io'; heading: string; cards: IOBoxesLayout[] }>;
|
|
34
42
|
}
|
|
43
|
+
export interface When { question: string; answer: string }
|
|
44
|
+
export interface DetailsLayout {
|
|
45
|
+
id: string | null; title: string | null; heading: string;
|
|
46
|
+
stats: { id: 'inputs' | 'steps' | 'stops' | 'changes' | 'reliesOn' | 'notExplained'; count: number; text: string }[];
|
|
47
|
+
give: { heading: string; items: { label: string; lines: number[] }[]; empty: string } | null;
|
|
48
|
+
getBack: { heading: string; items: { text: string; line: number | null; when: When[] | null }[]; empty: string } | null;
|
|
49
|
+
stops: { heading: string; items: { error: string; message: string | null; line: number | null; when: When[] }[]; empty: string } | null;
|
|
50
|
+
changes: { heading: string; items: { text: string; does: string | null; line: number | null; when: When[] }[] } | null;
|
|
51
|
+
answers: { heading: string; items: { answer: string; when: string }[] } | null;
|
|
52
|
+
limits: { heading: string; note: string; items: { range: string; answer: string }[] } | null;
|
|
53
|
+
steps: { heading: string; items: { id: string; text: string; does: string | null; mark: string | null; depth: number; line: number | null; notExplained: boolean; via: string | null }[] } | null;
|
|
54
|
+
reliesOn: { heading: string; items: { id: string; label: string; symbol: ThunderSymbolId; says: string }[] } | null;
|
|
55
|
+
usedBy: { heading: string; items: { id: string; label: string }[] } | null;
|
|
56
|
+
openQuestions: { heading: string; items: string[] } | null;
|
|
57
|
+
source: string | null;
|
|
58
|
+
}
|
|
59
|
+
/** What a Flow edge says, or null for a plain next step. */
|
|
60
|
+
export function flowEdgeLabel(edge: { label?: string | null; text?: string }): string | null;
|
|
61
|
+
/** Details sorted for drawing; `view` is readLevel(model, 'details', memberId). */
|
|
62
|
+
export function detailsLayout(view: Record<string, any>): DetailsLayout;
|
|
35
63
|
export function memberSymbolId(member: { kind: string }): ThunderSymbolId;
|
|
36
64
|
export function thingCard(model: ThunderModel, thing: Thing): ThingCardLayout;
|
|
37
65
|
export function dataCard(thing: Thing): DataCardLayout;
|
package/src/reading-layout.mjs
CHANGED
|
@@ -25,6 +25,19 @@ export const READING_LABELS = Object.freeze({
|
|
|
25
25
|
getsNothing: 'Nothing it hands back',
|
|
26
26
|
partOf: (label) => `Part of ${label}`,
|
|
27
27
|
io: 'What goes in and out',
|
|
28
|
+
// Flow: the words on each kind of edge. An edge label not listed here is shown as the compiler wrote it.
|
|
29
|
+
edges: Object.freeze({ yes: 'Yes', no: 'No', each: 'For each', done: 'Done', error: 'If it fails', nested: 'Runs on its own', case: 'When' }),
|
|
30
|
+
openLine: (line) => `line ${line}`,
|
|
31
|
+
openRule: 'Open the rule',
|
|
32
|
+
// Details: what each section is called.
|
|
33
|
+
details: Object.freeze({
|
|
34
|
+
stops: 'When it stops', noStops: 'Thunder found no place where it stops early.',
|
|
35
|
+
noInputs: 'Thunder found no inputs. Check Original if it reads a request or a file.', nothingBack: 'Thunder found nothing it gives back.',
|
|
36
|
+
changes: 'What it changes, saves or sends', answers: 'Its answers', limits: (fact) => `Exact limits for ${fact}`,
|
|
37
|
+
limitsHow: 'Found by running the rule on every whole number around each limit.',
|
|
38
|
+
steps: 'Every step, with its line', reliesOn: 'It relies on', usedBy: 'Used by', openQuestions: 'Questions the code cannot answer',
|
|
39
|
+
always: 'Always', otherwise: 'otherwise', when: (w) => `when ${w}`, usedOn: 'used on', atAGlance: 'At a glance',
|
|
40
|
+
}),
|
|
28
41
|
});
|
|
29
42
|
|
|
30
43
|
/** The symbol (thunder-visual-v1) for a member, as every view draws it. */
|
|
@@ -62,6 +75,12 @@ export function dataCard(thing) {
|
|
|
62
75
|
};
|
|
63
76
|
}
|
|
64
77
|
|
|
78
|
+
/** What an action gives back: its declared result, else the end steps of its Flow, each once. */
|
|
79
|
+
const givesBackOf = (member) => {
|
|
80
|
+
const list = member.youGetBack ? [member.youGetBack] : (member.flow?.nodes ?? []).filter((n) => n.kind === 'end').map((n) => n.text.replace(/^Gives back\s+/i, ''));
|
|
81
|
+
return [...new Set(list.filter(Boolean))];
|
|
82
|
+
};
|
|
83
|
+
|
|
65
84
|
/**
|
|
66
85
|
* What goes in and out of one action or rule: "You give it" (each input, with its kind when the code says it), "You
|
|
67
86
|
* get back", "It can stop with" (every Stop in its flow, with its line), and "Part of <Thing>" back to its card.
|
|
@@ -73,12 +92,63 @@ export function ioBoxes(model, member) {
|
|
|
73
92
|
return {
|
|
74
93
|
kind: 'io', id: member.id, label: `${member.label}${member.yesNo ? '?' : ''}`, doc: member.doc ?? null, symbol: memberSymbolId(member),
|
|
75
94
|
give: { heading: READING_LABELS.give, items: member.youGive.map((label) => ({ label, kind: kinds[label] ?? null })), empty: READING_LABELS.givesNothing },
|
|
76
|
-
|
|
95
|
+
// What it gives back: what the code declares, else the Flow's end steps (the same facts Flow and Details show).
|
|
96
|
+
getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, items: givesBackOf(member), empty: READING_LABELS.getsNothing },
|
|
77
97
|
stops: { heading: READING_LABELS.stops, items: stops },
|
|
78
98
|
partOf: owner ? { id: owner.id, text: READING_LABELS.partOf(owner.label) } : null,
|
|
79
99
|
};
|
|
80
100
|
}
|
|
81
101
|
|
|
102
|
+
/** What a Flow edge says ("Yes", "For each", a case's own words), or null for a plain next step. */
|
|
103
|
+
export function flowEdgeLabel(edge) {
|
|
104
|
+
if (!edge.label || edge.label === 'next') return null;
|
|
105
|
+
if (edge.label === 'case') return edge.text ?? READING_LABELS.edges.case;
|
|
106
|
+
return READING_LABELS.edges[edge.label] ?? edge.text ?? edge.label;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const count = (n, one, many) => ({ count: n, text: n === 1 ? one : many });
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Details, sorted for drawing: the counts at a glance, then You give it / You get back, When it stops, What it
|
|
113
|
+
* changes, Its answers, Exact limits, Every step, It relies on, Used by, and Questions the code cannot answer.
|
|
114
|
+
* `view` is readLevel(model, 'details', memberId). A section is present only when the compiler gave it (null when
|
|
115
|
+
* not), so nothing is invented. What it gives back comes from the same facts as the Big Picture: givesBack, else
|
|
116
|
+
* youGetBack, else the Flow's end steps.
|
|
117
|
+
*/
|
|
118
|
+
export function detailsLayout(view) {
|
|
119
|
+
const L = READING_LABELS.details;
|
|
120
|
+
const inputs = view.inputs ?? (view.youGive ?? []).map((label) => ({ label, lines: [] }));
|
|
121
|
+
const givesBack = view.givesBack?.length ? view.givesBack.map((g) => ({ text: g.text, line: g.line ?? null, when: g.when ?? null }))
|
|
122
|
+
: view.youGetBack ? [{ text: view.youGetBack, line: null, when: null }]
|
|
123
|
+
: (view.flow?.nodes ?? []).filter((n) => n.kind === 'end').map((n) => ({ text: n.text, line: n.line ?? null, when: null }));
|
|
124
|
+
const steps = view.steps ?? [];
|
|
125
|
+
const stops = view.stops ?? null;
|
|
126
|
+
const changes = view.changes ?? null;
|
|
127
|
+
const reliesOn = view.reliesOn ?? (view.uses ?? []).map((u) => ({ id: u.id, label: u.label, symbol: 'rule', says: '' }));
|
|
128
|
+
const stats = [
|
|
129
|
+
...(inputs.length ? [{ id: 'inputs', ...count(inputs.length, 'thing you give it', 'things you give it') }] : []),
|
|
130
|
+
{ id: 'steps', ...count(steps.length, 'step', 'steps') },
|
|
131
|
+
...(stops ? [{ id: 'stops', ...count(stops.length, 'way to stop', 'ways to stop') }] : []),
|
|
132
|
+
...(changes ? [{ id: 'changes', ...count(changes.length, 'change', 'changes') }] : []),
|
|
133
|
+
...(reliesOn.length ? [{ id: 'reliesOn', count: reliesOn.length, text: 'relies on' }] : []),
|
|
134
|
+
...((view.notExplained ?? 0) > 0 ? [{ id: 'notExplained', count: view.notExplained, text: 'not explained yet' }] : []),
|
|
135
|
+
];
|
|
136
|
+
return {
|
|
137
|
+
id: view.id ?? null, title: view.title ?? null, heading: L.atAGlance, stats,
|
|
138
|
+
give: inputs.length || givesBack.length ? { heading: READING_LABELS.give, items: inputs.map((i) => ({ label: i.label, lines: i.lines ?? [] })), empty: L.noInputs } : null,
|
|
139
|
+
getBack: inputs.length || givesBack.length ? { heading: READING_LABELS.getBack, items: givesBack, empty: L.nothingBack } : null,
|
|
140
|
+
stops: stops ? { heading: L.stops, items: stops.map((s) => ({ error: s.error, message: s.message ?? null, line: s.line ?? null, when: s.when ?? [] })), empty: L.noStops } : null,
|
|
141
|
+
changes: changes?.length ? { heading: L.changes, items: changes.map((c) => ({ text: c.text, does: c.does ?? null, line: c.line ?? null, when: c.when ?? [] })) } : null,
|
|
142
|
+
answers: view.answers?.length ? { heading: L.answers, items: view.answers.map((a) => ({ answer: a.answer, when: a.when === 'otherwise' ? L.otherwise : L.when(a.when) })) } : null,
|
|
143
|
+
limits: view.limits ? { heading: L.limits(view.limits.fact), note: L.limitsHow, items: view.limits.ranges.map((r) => ({ range: r.from == null ? `${r.to} or less` : r.to == null ? `${r.from} or more` : r.from === r.to ? `${r.from}` : `${r.from} to ${r.to}`, answer: r.answer })) } : null,
|
|
144
|
+
steps: steps.length ? { heading: L.steps, items: steps.map((s) => ({ id: s.id, text: s.text, does: s.does ?? null, mark: s.mark ?? null, depth: s.depth ?? 0, line: s.line ?? null, notExplained: !!s.notExplained, via: s.via ?? null })) } : null,
|
|
145
|
+
reliesOn: reliesOn.length ? { heading: L.reliesOn, items: reliesOn.map((r) => ({ id: r.id, label: r.label, symbol: r.symbol ?? 'rule', says: r.says ?? '' })) } : null,
|
|
146
|
+
usedBy: view.usedBy?.length ? { heading: L.usedBy, items: view.usedBy.map((u) => ({ id: u.id, label: u.label })) } : null,
|
|
147
|
+
openQuestions: view.openQuestions?.length ? { heading: L.openQuestions, items: [...view.openQuestions] } : null,
|
|
148
|
+
source: view.source ?? null,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
82
152
|
const sectionsFor = (model, things) => {
|
|
83
153
|
const cards = things.filter((t) => t.kind === 'thing').map((t) => thingCard(model, t));
|
|
84
154
|
const data = [...things.filter((t) => t.kind === 'record'), ...things.filter((t) => t.kind === 'choices')].map(dataCard);
|