@skillstech/thunderlang 1.4.0 → 1.4.1
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 +28 -0
- package/dist/core.cjs +120 -4
- package/dist/index.cjs +1 -1
- package/dist/learn.cjs +3355 -1184
- package/package.json +15 -2
- package/src/core.d.ts +4 -0
- package/src/core.mjs +2 -0
- package/src/emit.mjs +1 -1
- package/src/learn-lessons.mjs +145 -0
- package/src/learn.mjs +17 -0
- package/src/react/reading.css +119 -0
- package/src/react/reading.d.mts +15 -0
- package/src/react/reading.mjs +87 -0
- package/src/reading-layout.d.mts +40 -0
- package/src/reading-layout.mjs +112 -0
- package/src/write-across.mjs +13 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skillstech/thunderlang",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "Thunder
|
|
3
|
+
"version": "1.4.1",
|
|
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",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"types": "./src/program.d.mts",
|
|
38
38
|
"import": "./src/program.mjs"
|
|
39
39
|
},
|
|
40
|
+
"./react": {
|
|
41
|
+
"types": "./src/react/reading.d.mts",
|
|
42
|
+
"import": "./src/react/reading.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./react/reading.css": "./src/react/reading.css",
|
|
40
45
|
"./package.json": "./package.json"
|
|
41
46
|
},
|
|
42
47
|
"bin": {
|
|
@@ -68,6 +73,14 @@
|
|
|
68
73
|
"devDependencies": {
|
|
69
74
|
"esbuild": "^0.28.1"
|
|
70
75
|
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"react": ">=18"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"react": {
|
|
81
|
+
"optional": true
|
|
82
|
+
}
|
|
83
|
+
},
|
|
71
84
|
"keywords": [
|
|
72
85
|
"thunder",
|
|
73
86
|
"thunder-programming-language",
|
package/src/core.d.ts
CHANGED
|
@@ -200,3 +200,7 @@ export interface WriteAcrossResult {
|
|
|
200
200
|
}
|
|
201
201
|
export function writeRuleAcross(files: WriteAcrossFile[], options: { decision: string; rule: number | string; when: string }): WriteAcrossResult;
|
|
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
|
+
|
|
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';
|
package/src/core.mjs
CHANGED
|
@@ -138,3 +138,5 @@ export { stepShape } from './write-steps.mjs';
|
|
|
138
138
|
// The Thunder Software Passport, pure half (assemble, check, render). buildPassport (folders, git, runs) is in the root entry.
|
|
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
|
+
// 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';
|
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.1';
|
|
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/learn-lessons.mjs
CHANGED
|
@@ -544,6 +544,69 @@ const AGENT_RUN = (() => {
|
|
|
544
544
|
] }] }] }, null, 2);
|
|
545
545
|
})();
|
|
546
546
|
|
|
547
|
+
// ── Changing real code safely ──────────────────────────────────────────────────────────────────────────────────
|
|
548
|
+
// Three tools for code that already runs in several services: is every record limited to its caller, one rule
|
|
549
|
+
// changed everywhere it is written, and a record of the evidence for a change. Every answer is worked out by the
|
|
550
|
+
// tool itself on the lesson's files (accessFlow, writeRuleAcross, assemblePassport and checkPassport in ./core).
|
|
551
|
+
|
|
552
|
+
const INVOICES_API = `import express from "express";
|
|
553
|
+
import { db } from "./db";
|
|
554
|
+
|
|
555
|
+
const app = express();
|
|
556
|
+
|
|
557
|
+
app.get("/invoices/:id", async (req, res) => {
|
|
558
|
+
const invoice = await db.invoice.findFirst({
|
|
559
|
+
where: { id: req.params.id, tenantId: req.user.tenantId },
|
|
560
|
+
});
|
|
561
|
+
res.json(invoice);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
app.get("/receipts/:id", async (req, res) => {
|
|
565
|
+
const receipt = await db.receipt.findUnique({ where: { id: req.params.id } });
|
|
566
|
+
res.json(receipt);
|
|
567
|
+
});
|
|
568
|
+
`;
|
|
569
|
+
|
|
570
|
+
const INVOICES_DB = `import { PrismaClient } from "@prisma/client";
|
|
571
|
+
|
|
572
|
+
export const db = new PrismaClient();
|
|
573
|
+
`;
|
|
574
|
+
|
|
575
|
+
const SHIP_WEB = `export function shippingFee(subtotal: number): number {
|
|
576
|
+
if (subtotal >= 50) return 0;
|
|
577
|
+
return 5.99;
|
|
578
|
+
}
|
|
579
|
+
`;
|
|
580
|
+
|
|
581
|
+
const SHIP_ORDERS = `public static class Shipping
|
|
582
|
+
{
|
|
583
|
+
public static decimal ShippingFee(decimal subtotal)
|
|
584
|
+
{
|
|
585
|
+
if (subtotal >= 50m) return 0m;
|
|
586
|
+
return 5.99m;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
`;
|
|
590
|
+
|
|
591
|
+
const SHIP_BILLING = `def shipping_fee(subtotal):
|
|
592
|
+
if subtotal >= 50:
|
|
593
|
+
return 0
|
|
594
|
+
return 5.99
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def coupon_allowed(subtotal):
|
|
598
|
+
if subtotal >= 50:
|
|
599
|
+
return True
|
|
600
|
+
return False
|
|
601
|
+
`;
|
|
602
|
+
|
|
603
|
+
const SHIP_TEST = `from receipt import shipping_fee
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def test_a_45_dollar_order_pays_shipping():
|
|
607
|
+
assert shipping_fee(45) == 5.99
|
|
608
|
+
`;
|
|
609
|
+
|
|
547
610
|
export const WRITE_LESSONS = [
|
|
548
611
|
{
|
|
549
612
|
slug: "first-program",
|
|
@@ -699,4 +762,86 @@ export const WRITE_LESSONS = [
|
|
|
699
762
|
{ q: "The refund did not go through. Was the customer refunded?", a: "Thunder can't know: the record shows the requests failed, not what the payment service did. It says the step may have partly happened, so a person checks." },
|
|
700
763
|
],
|
|
701
764
|
},
|
|
765
|
+
{
|
|
766
|
+
slug: "access-check",
|
|
767
|
+
part: "write",
|
|
768
|
+
concept: "Ownership: every record a request asks for must belong to the person asking",
|
|
769
|
+
title: "Does every route keep each customer's records to them?",
|
|
770
|
+
idea: "A web route that looks up a record by the id in the address must also check that the record belongs to the caller, or anyone can read anyone's invoice by changing a number. thunder read ./api --access follows each request through the code into the database and gives every route one verdict: guarded, unguarded, or cannot tell. Each verdict points to its lines. Thunder says unguarded only when it followed every step; when something is out of reach (a file it was not given), it says cannot tell and names what stopped it.",
|
|
771
|
+
picture: "A hotel desk. One clerk checks that the room key belongs to the guest before handing it over; the other hands any key to whoever names a room number.",
|
|
772
|
+
commands: ["thunder read ./api --access"],
|
|
773
|
+
files: [{ language: "typescript", label: "api/routes.ts", code: INVOICES_API }, { language: "typescript", label: "api/db.ts", code: INVOICES_DB }],
|
|
774
|
+
access: true,
|
|
775
|
+
show: "run",
|
|
776
|
+
quiz: [
|
|
777
|
+
{ prompt: "Which route lets one customer read another customer's record?", choices: ["GET /receipts/:id", "GET /invoices/:id", "Neither"], expect: "GET /receipts/:id",
|
|
778
|
+
explain: "The receipts lookup uses only the id from the address. The invoices lookup also requires tenantId to be the caller's own, so a different customer's id finds nothing.",
|
|
779
|
+
check: ({ access }) => { const u = access.routes.filter((r) => r.verdict === 'unguarded'); return u.length === 1 ? `${u[0].method} ${u[0].path}` : u.length ? 'Both' : 'Neither'; } },
|
|
780
|
+
{ prompt: "Thunder is given routes.ts but not db.ts. What does it say about GET /receipts/:id?", choices: ["Cannot tell: db comes from a file it was not given", "Unguarded", "Guarded"], expect: "Cannot tell: db comes from a file it was not given",
|
|
781
|
+
explain: "Without db.ts, Thunder cannot see that db is the database, so it cannot follow the lookup. It names what stopped it instead of guessing either way.",
|
|
782
|
+
check: ({ accessOf }) => { const r = accessOf([0]).routes.find((x) => x.path === '/receipts/:id'); return r.verdict === 'cannot tell' && /outside these files/.test(r.why) ? 'Cannot tell: db comes from a file it was not given' : r.verdict === 'unguarded' ? 'Unguarded' : 'Guarded'; } },
|
|
783
|
+
],
|
|
784
|
+
questions: [
|
|
785
|
+
{ q: "Every route says guarded. Is the app safe?", a: "Each route limits the record it hands back to the caller, on the paths Thunder followed. That is one important check, not all of security: sign-in itself, what a role may do, and data that leaks through other means are separate questions." },
|
|
786
|
+
{ q: "Why is cannot tell better than a guess?", a: "A wrong guarded hides a leak; a wrong unguarded wastes your time and teaches you to ignore warnings. Cannot tell, with what stopped it, tells you exactly where to look." },
|
|
787
|
+
],
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
slug: "change-everywhere",
|
|
791
|
+
part: "write",
|
|
792
|
+
concept: "One business rule, written in several services, changed together",
|
|
793
|
+
title: "Change one rule in every service at once",
|
|
794
|
+
idea: "Free shipping from $50 is often written three times: the cart page (TypeScript), the orders service (C#), and billing's receipt (Python). Change one and forget another, and customers see one price and pay another. thunder write web orders billing finds every copy of the rule, shows the plan, and with --write changes all of them or none, touching only the rule's characters. A rule that only looks the same is listed for you to check by hand, never changed, and tests are never edited.",
|
|
795
|
+
picture: "Changing a price on the shelf tag, the till, and the receipt printer together, instead of hoping someone remembers the other two.",
|
|
796
|
+
commands: ["thunder write web orders billing --decision shippingFee --rule 1 --when \"subtotal >= 40\"", "thunder write web orders billing --decision shippingFee --rule 1 --when \"subtotal >= 40\" --write"],
|
|
797
|
+
files: [
|
|
798
|
+
{ language: "typescript", label: "web/shipping.ts", code: SHIP_WEB },
|
|
799
|
+
{ language: "csharp", label: "orders/Shipping.cs", code: SHIP_ORDERS },
|
|
800
|
+
{ language: "python", label: "billing/receipt.py", code: SHIP_BILLING },
|
|
801
|
+
{ language: "python", label: "billing/test_receipt.py", code: SHIP_TEST },
|
|
802
|
+
],
|
|
803
|
+
across: { decision: "shippingFee", rule: 1, when: "subtotal >= 40" },
|
|
804
|
+
show: "run",
|
|
805
|
+
quiz: [
|
|
806
|
+
{ prompt: "Free shipping moves from $50 to $40. How many files does Thunder change?", choices: ["3", "4", "1"], expect: "3",
|
|
807
|
+
explain: "The shipping rule in each service: shipping.ts, Shipping.cs, and receipt.py. The test file is never edited.",
|
|
808
|
+
check: ({ across }) => String(new Set(across.plan.map((p) => `${p.part}/${p.file}`)).size) },
|
|
809
|
+
{ prompt: "coupon_allowed also says subtotal >= 50. What does Thunder do with it?", choices: ["Lists it to check by hand", "Changes it to 40 too"], expect: "Lists it to check by hand",
|
|
810
|
+
explain: "It has the same limit, but its name shares no word with shippingFee, so it is probably a different rule (the coupon minimum) that happens to use $50. Thunder lists it and leaves it alone.",
|
|
811
|
+
check: ({ across }) => (across.notIncluded.some((n) => n.decision === 'coupon_allowed') ? 'Lists it to check by hand' : 'Changes it to 40 too') },
|
|
812
|
+
{ prompt: "The test expects a $45 order to pay $5.99. After the change, what is true?", choices: ["The test will fail and needs a person to update it", "Thunder updates the test"], expect: "The test will fail and needs a person to update it",
|
|
813
|
+
explain: "At $40, a $45 order ships free, so the test's expectation is now wrong. Thunder never edits tests: a test that disagrees is how you find out what the change means.",
|
|
814
|
+
check: ({ across }) => (across.files['billing/test_receipt.py'] === undefined && across.ok ? 'The test will fail and needs a person to update it' : 'Thunder updates the test') },
|
|
815
|
+
],
|
|
816
|
+
questions: [
|
|
817
|
+
{ q: "Why all or nothing?", a: "Half a change is the problem you started with: two services disagreeing. If any copy cannot be changed exactly, no file changes and Thunder says which one and why." },
|
|
818
|
+
{ q: "The C# copy says 50m and the Python copy says 50. Why are they the same rule?", a: "Numbers are compared by value, and names as words (shippingFee, ShippingFee, and shipping_fee are the same name). Each copy keeps its own spelling: the C# becomes 40m." },
|
|
819
|
+
],
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
slug: "passport",
|
|
823
|
+
part: "write",
|
|
824
|
+
concept: "Evidence: what was checked, how, and what it does not cover",
|
|
825
|
+
title: "Keep the evidence for a change",
|
|
826
|
+
idea: "When you change code, a reviewer asks: what changed, how do you know it works, and what did you not check? thunder passport writes that down as a Software Passport. Each claim has its basis (a command and its exit code, or the source lines) and the files it depended on, by fingerprint. A failed test is recorded as failed, never as passed, and deployment, real outside services, several machines, and load are always listed as not verified. Later, thunder passport check marks each claim current, or stale when a file it depended on has changed since.",
|
|
827
|
+
picture: "A building inspection certificate: what was inspected, by what test, on which date, and a note that it no longer counts once someone moves a wall.",
|
|
828
|
+
commands: ["thunder passport web billing --run \"web: node --test\" --run \"billing: python3 -m pytest\"", "thunder passport check"],
|
|
829
|
+
files: [{ language: "typescript", label: "web/shipping.ts", code: SHIP_WEB }, { language: "python", label: "billing/receipt.py", code: SHIP_BILLING }],
|
|
830
|
+
passport: [
|
|
831
|
+
{ command: "node --test", part: "web", exitCode: 0, output: "1 passed" },
|
|
832
|
+
{ command: "python3 -m pytest", part: "billing", exitCode: 0, output: "1 passed" },
|
|
833
|
+
],
|
|
834
|
+
show: "run",
|
|
835
|
+
quiz: [
|
|
836
|
+
{ prompt: "After the passport is made, someone edits web/shipping.ts. Which claim turns stale?", choices: ["The web test run", "The billing test run", "Both"], expect: "The web test run",
|
|
837
|
+
explain: "Only the web tests depended on shipping.ts. Billing's claim depended on receipt.py, which did not change, so it stays current. Nothing is re-run: check compares fingerprints.",
|
|
838
|
+
check: ({ passportCheck }) => { const c = passportCheck({ 'web/shipping.ts': SHIP_WEB.replace('50', '45') }); const stale = c.items.filter((i) => i.freshness === 'stale'); return stale.length === 2 ? 'Both' : /in web/.test(stale[0]?.claim) ? 'The web test run' : 'The billing test run'; } },
|
|
839
|
+
{ prompt: "Every test passed. Does the passport say the change works in production?", choices: ["No: deployment is always listed as not verified", "Yes"], expect: "No: deployment is always listed as not verified",
|
|
840
|
+
explain: "Tests prove what they ran, on the machine they ran on. How it is deployed, real outside services, more than one machine, and heavy load are listed as not verified unless a claim covers them.",
|
|
841
|
+
check: ({ passport }) => (passport.unknowns.notVerified.some((x) => /^Deployment/.test(x)) ? 'No: deployment is always listed as not verified' : 'Yes') },
|
|
842
|
+
],
|
|
843
|
+
questions: [
|
|
844
|
+
{ q: "Why record a failed test instead of leaving it out?", a: "Leaving it out makes the passport look better than the truth. A reviewer needs to see the failure, and the passport says what it means: what that test covers is not verified." },
|
|
845
|
+
],
|
|
846
|
+
},
|
|
702
847
|
];
|
package/src/learn.mjs
CHANGED
|
@@ -13,6 +13,9 @@ import { compileCore } from './core/index.mjs';
|
|
|
13
13
|
import { runInProcess, testInProcess } from './core/engine-core.mjs';
|
|
14
14
|
import { pythonToCore } from './core/from-python.mjs';
|
|
15
15
|
import { explainRun } from './why.mjs';
|
|
16
|
+
import { accessFlow } from './flow/access.mjs';
|
|
17
|
+
import { writeRuleAcross } from './write-across.mjs';
|
|
18
|
+
import { assemblePassport, checkPassport } from './passport.mjs';
|
|
16
19
|
|
|
17
20
|
export const LEARN_SCHEMA = 'thunder-learn-v1';
|
|
18
21
|
export { READ_LESSONS, WRITE_LESSONS };
|
|
@@ -76,6 +79,20 @@ function writeContext(lesson) {
|
|
|
76
79
|
}
|
|
77
80
|
if (lesson.asCore) ctx.asCore = pythonToCore(file.code);
|
|
78
81
|
if (lesson.why) ctx.why = explainRun(file.code);
|
|
82
|
+
// Changing real code: each tool run on the lesson's files, labeled "part/file".
|
|
83
|
+
const parted = lesson.files.map((f) => { const i = f.label.indexOf('/'); return { part: f.label.slice(0, i), path: f.label.slice(i + 1), source: f.code }; });
|
|
84
|
+
if (lesson.access) {
|
|
85
|
+
ctx.accessOf = (which) => accessFlow((which ?? lesson.files.map((_, i) => i)).map((i) => ({ path: lesson.files[i].label, source: lesson.files[i].code })));
|
|
86
|
+
ctx.access = ctx.accessOf();
|
|
87
|
+
}
|
|
88
|
+
if (lesson.across) ctx.across = writeRuleAcross(parted, lesson.across);
|
|
89
|
+
if (lesson.passport) {
|
|
90
|
+
const parts = [...new Set(parted.map((f) => f.part))].map((name) => ({ name, files: parted.filter((f) => f.part === name).map(({ path, source }) => ({ path, source })) }));
|
|
91
|
+
const runs = lesson.passport.map((r) => ({ cwd: r.part, ...r }));
|
|
92
|
+
ctx.passport = assemblePassport({ parts, runs, builtAt: '2026-01-01T00:00:00.000Z', thunder: COMPILER_VERSION });
|
|
93
|
+
/** Check the passport after some files changed: { "part/file": new source }. */
|
|
94
|
+
ctx.passportCheck = (changed) => checkPassport(ctx.passport, { read: (part, file) => changed[`${part}/${file}`] ?? parted.find((f) => f.part === part && f.path === file)?.source });
|
|
95
|
+
}
|
|
79
96
|
return ctx;
|
|
80
97
|
}
|
|
81
98
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* @skillstech/thunderlang/react/reading.css: the Thunder drawing kit's one stylesheet.
|
|
2
|
+
Every color is a CSS variable: set them on any ancestor (or :root) to fit your app. The defaults are the dark
|
|
3
|
+
Thunder look; add class "tl-light" to an ancestor for the light set. --tl-accent (a Thing's color) follows
|
|
4
|
+
--language-accent when the page sets it. Works from 320px wide up; the "It can" grid is one column below 560px. */
|
|
5
|
+
|
|
6
|
+
.tl-reading, .tl-card {
|
|
7
|
+
--tl-surface: rgba(14, 18, 30, 0.6);
|
|
8
|
+
--tl-surface-raised: rgba(20, 26, 42, 0.7);
|
|
9
|
+
--tl-border: rgba(255, 255, 255, 0.12);
|
|
10
|
+
--tl-border-strong: rgba(255, 255, 255, 0.3);
|
|
11
|
+
--tl-text: #ffffff;
|
|
12
|
+
--tl-text-body: #e7eaf2;
|
|
13
|
+
--tl-text-muted: #aab2c5;
|
|
14
|
+
--tl-text-quiet: #8a93a8;
|
|
15
|
+
--tl-focus: #fcd34d;
|
|
16
|
+
--tl-radius: 24px;
|
|
17
|
+
--tl-radius-small: 12px;
|
|
18
|
+
/* The grammar's colors (thunder-visual-v1). */
|
|
19
|
+
--tl-c-structure: #c4b5fd;
|
|
20
|
+
--tl-c-question: #7fb2ff;
|
|
21
|
+
--tl-c-fact: #fcd34d;
|
|
22
|
+
--tl-c-comparison: #f472b6;
|
|
23
|
+
--tl-c-amount: #fdba74;
|
|
24
|
+
--tl-c-outcome: #67e8f9;
|
|
25
|
+
--tl-c-name: #bef264;
|
|
26
|
+
--tl-c-failure: #fdba74;
|
|
27
|
+
--tl-c-pass: #34d399;
|
|
28
|
+
--tl-c-fail: #f87171;
|
|
29
|
+
--tl-c-unread: #9ca3af;
|
|
30
|
+
--tl-accent: var(--language-accent, var(--tl-c-outcome));
|
|
31
|
+
--tl-knows: var(--tl-c-fact);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.tl-light .tl-reading, .tl-light .tl-card, .tl-reading.tl-light, .tl-card.tl-light {
|
|
35
|
+
--tl-surface: #ffffff;
|
|
36
|
+
--tl-surface-raised: #f6f7fb;
|
|
37
|
+
--tl-border: #dde1ea;
|
|
38
|
+
--tl-border-strong: #9aa3b5;
|
|
39
|
+
--tl-text: #111827;
|
|
40
|
+
--tl-text-body: #1f2937;
|
|
41
|
+
--tl-text-muted: #4b5563;
|
|
42
|
+
--tl-text-quiet: #6b7280;
|
|
43
|
+
--tl-focus: #b45309;
|
|
44
|
+
--tl-c-structure: #6d28d9;
|
|
45
|
+
--tl-c-question: #1d4ed8;
|
|
46
|
+
--tl-c-fact: #92400e;
|
|
47
|
+
--tl-c-comparison: #be185d;
|
|
48
|
+
--tl-c-amount: #c2410c;
|
|
49
|
+
--tl-c-outcome: #0e7490;
|
|
50
|
+
--tl-c-name: #4d7c0f;
|
|
51
|
+
--tl-c-failure: #c2410c;
|
|
52
|
+
--tl-c-pass: #047857;
|
|
53
|
+
--tl-c-fail: #b91c1c;
|
|
54
|
+
--tl-c-unread: #6b7280;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.tl-reading, .tl-card { box-sizing: border-box; color: var(--tl-text-body); font: inherit; min-width: 0; }
|
|
58
|
+
.tl-reading *, .tl-card * { box-sizing: border-box; }
|
|
59
|
+
.tl-reading :is(h2, h3, h4, h5, p, ul), .tl-card :is(h2, h3, h4, h5, p, ul) { margin: 0; }
|
|
60
|
+
.tl-reading ul, .tl-card ul { list-style: none; padding: 0; }
|
|
61
|
+
|
|
62
|
+
.tl-symbol { flex-shrink: 0; }
|
|
63
|
+
.tl-c-structure { color: var(--tl-c-structure); }
|
|
64
|
+
.tl-c-question { color: var(--tl-c-question); }
|
|
65
|
+
.tl-c-fact { color: var(--tl-c-fact); }
|
|
66
|
+
.tl-c-comparison { color: var(--tl-c-comparison); }
|
|
67
|
+
.tl-c-amount { color: var(--tl-c-amount); }
|
|
68
|
+
.tl-c-outcome { color: var(--tl-c-outcome); }
|
|
69
|
+
.tl-c-name { color: var(--tl-c-name); }
|
|
70
|
+
.tl-c-failure { color: var(--tl-c-failure); }
|
|
71
|
+
.tl-c-pass { color: var(--tl-c-pass); }
|
|
72
|
+
.tl-c-fail { color: var(--tl-c-fail); }
|
|
73
|
+
.tl-c-unread { color: var(--tl-c-unread); }
|
|
74
|
+
|
|
75
|
+
/* Cards */
|
|
76
|
+
.tl-card { border: 1px solid var(--tl-border); border-radius: calc(var(--tl-radius) - 4px); background: var(--tl-surface); padding: 20px; overflow-wrap: anywhere; }
|
|
77
|
+
.tl-card-head { display: flex; align-items: center; gap: 14px; }
|
|
78
|
+
.tl-kicker { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tl-accent); }
|
|
79
|
+
.tl-kicker-quiet { font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--tl-text-quiet); }
|
|
80
|
+
.tl-card-title { font-size: 24px; line-height: 1.25; font-weight: 700; color: var(--tl-text); }
|
|
81
|
+
.tl-card-title-small { font-size: 18px; font-weight: 600; }
|
|
82
|
+
.tl-doc { margin-top: 12px !important; font-size: 17px; line-height: 1.55; color: var(--tl-text-body); }
|
|
83
|
+
.tl-doc-small { margin-top: 8px !important; font-size: 14px; color: var(--tl-text-muted); }
|
|
84
|
+
.tl-section-label { margin-top: 20px !important; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tl-text-quiet); }
|
|
85
|
+
|
|
86
|
+
/* A Thing */
|
|
87
|
+
.tl-thing { border: 2px solid color-mix(in srgb, var(--tl-accent) 50%, transparent); border-radius: var(--tl-radius); background: color-mix(in srgb, var(--tl-accent) 4%, transparent); padding: 24px; }
|
|
88
|
+
.tl-thing.tl-selected { border-color: var(--tl-accent); }
|
|
89
|
+
.tl-knows { margin-top: 8px !important; display: grid; gap: 4px; font-size: 16px; }
|
|
90
|
+
.tl-knows-small { margin-top: 12px !important; font-size: 14px; }
|
|
91
|
+
.tl-knows-name { color: var(--tl-knows); }
|
|
92
|
+
.tl-knows-detail { color: var(--tl-text-muted); }
|
|
93
|
+
.tl-abilities { margin-top: 8px !important; display: grid; gap: 8px; grid-template-columns: 1fr; }
|
|
94
|
+
@media (min-width: 560px) { .tl-abilities { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
95
|
+
.tl-ability { display: flex; width: 100%; min-height: 44px; align-items: center; gap: 12px; border: 1px solid var(--tl-border); border-radius: var(--tl-radius-small); background: var(--tl-surface-raised); padding: 10px 12px; text-align: left; font: inherit; color: inherit; }
|
|
96
|
+
.tl-ability-button { cursor: pointer; }
|
|
97
|
+
.tl-ability-button:hover { border-color: var(--tl-border-strong); }
|
|
98
|
+
.tl-ability-label { font-size: 15px; font-weight: 500; color: var(--tl-text); }
|
|
99
|
+
.tl-ability-go { margin-left: auto; color: var(--tl-text-quiet); }
|
|
100
|
+
.tl-starts { margin-top: 12px !important; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--tl-text-muted); }
|
|
101
|
+
.tl-starts-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; }
|
|
102
|
+
.tl-starts-button:hover { color: var(--tl-text); }
|
|
103
|
+
.tl-ability-button:focus-visible, .tl-starts-button:focus-visible { outline: 2px solid var(--tl-focus); outline-offset: 2px; }
|
|
104
|
+
|
|
105
|
+
/* Data */
|
|
106
|
+
.tl-choices { margin-top: 12px !important; display: flex; flex-wrap: wrap; gap: 8px; }
|
|
107
|
+
.tl-choice { border: 1px solid color-mix(in srgb, var(--tl-c-outcome) 50%, transparent); border-radius: 999px; padding: 4px 12px; font-size: 14px; color: var(--tl-c-outcome); }
|
|
108
|
+
|
|
109
|
+
/* The Big Picture */
|
|
110
|
+
.tl-big-picture { display: grid; gap: 24px; }
|
|
111
|
+
.tl-bp-things { display: grid; gap: 20px; }
|
|
112
|
+
.tl-bp-data { display: grid; gap: 16px; grid-template-columns: 1fr; }
|
|
113
|
+
@media (min-width: 760px) { .tl-bp-data { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
114
|
+
@media (max-width: 420px) {
|
|
115
|
+
.tl-thing { padding: 18px; }
|
|
116
|
+
.tl-card { padding: 16px; }
|
|
117
|
+
.tl-card-title { font-size: 21px; }
|
|
118
|
+
}
|
|
119
|
+
@media (prefers-reduced-motion: no-preference) { .tl-ability-button, .tl-starts-button { transition: border-color 120ms, color 120ms; } }
|
|
@@ -0,0 +1,15 @@
|
|
|
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';
|
|
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';
|
|
7
|
+
|
|
8
|
+
/** A Thunder symbol; its color is the CSS variable for its grammar color (--tl-c-*). */
|
|
9
|
+
export function ThunderSymbol(props: { id: ThunderSymbolId; size?: number; label?: string }): ReactElement | null;
|
|
10
|
+
/** A Thing card. Pass `card` (from thingCard/readingLayout) or `model` and `thing`. onOpen(memberId) makes abilities buttons. */
|
|
11
|
+
export function ThingCard(props: { card?: ThingCardLayout; model?: ThunderModel; thing?: Thing; onOpen?: (memberId: string) => void; selected?: boolean; headingLevel?: 2 | 3 | 4 }): ReactElement;
|
|
12
|
+
/** A Data card: a record or choices. Pass `card` or `thing`. */
|
|
13
|
+
export function DataCard(props: { card?: DataCardLayout; thing?: Thing; headingLevel?: 2 | 3 | 4 }): ReactElement;
|
|
14
|
+
/** The Big Picture: every Thing, then records and choices. */
|
|
15
|
+
export function BigPicture(props: { model?: ThunderModel; layout?: ReadingLayout; focus?: string | null; onOpen?: (memberId: string) => void; selectedId?: string; headingLevel?: 2 | 3 }): ReactElement;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @skillstech/thunderlang/react: the Thunder drawing kit. One set of components that OpenThunder, thunderlang.dev,
|
|
2
|
+
// and the Skills Tech Talk course all use, so a reading looks and reads the same everywhere. Every word and its
|
|
3
|
+
// order come from readingLayout (../reading-layout.mjs); these components only turn that data into elements.
|
|
4
|
+
// Styling: plain `tl-` class names and one stylesheet (@skillstech/thunderlang/react/reading.css) whose colors are
|
|
5
|
+
// CSS variables, so each app sets its own (STT's --language-accent is honored). No JSX, no build step, no Tailwind:
|
|
6
|
+
// React is the only dependency, and it is the app's own (a peer dependency).
|
|
7
|
+
import { createElement as h, Fragment } from 'react';
|
|
8
|
+
import { THUNDER_VISUAL } from '../visual.mjs';
|
|
9
|
+
import { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS } from '../reading-layout.mjs';
|
|
10
|
+
|
|
11
|
+
export { readingLayout, thingCard, dataCard, ioBoxes, READING_LABELS };
|
|
12
|
+
|
|
13
|
+
/** A Thunder symbol, from the grammar's own path data. Its color is the CSS variable for its grammar color. */
|
|
14
|
+
export function ThunderSymbol({ id, size = 28, label }) {
|
|
15
|
+
const s = THUNDER_VISUAL.symbols[id];
|
|
16
|
+
if (!s) return null;
|
|
17
|
+
return h('svg', {
|
|
18
|
+
width: size, height: size, viewBox: '0 0 44 44', fill: 'none', stroke: 'currentColor', strokeWidth: 2.6, strokeLinejoin: 'round', strokeLinecap: 'round',
|
|
19
|
+
strokeDasharray: s.dashed ? '4 4' : undefined, className: `tl-symbol tl-c-${s.color}`,
|
|
20
|
+
role: label ? 'img' : undefined, 'aria-label': label, 'aria-hidden': label ? undefined : true, focusable: 'false',
|
|
21
|
+
},
|
|
22
|
+
...s.paths.map((d, i) => h('path', { key: `p${i}`, d })),
|
|
23
|
+
...(s.circles ?? []).map(([cx, cy, r], i) => h('circle', { key: `c${i}`, cx, cy, r, fill: s.fill ? 'currentColor' : 'none' })));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const knowsItem = (k) => h('li', { key: k.name, className: 'tl-knows-item' },
|
|
27
|
+
h('span', { className: 'tl-knows-name' }, k.label),
|
|
28
|
+
k.detail ? h('span', { className: 'tl-knows-detail' }, `: ${k.detail}`) : null);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A Thing (a class): what it knows and what it can do. With `onOpen`, each ability and "How a new … starts" is a
|
|
32
|
+
* button that calls onOpen(memberId); without it they are plain text.
|
|
33
|
+
* card: thingCard(model, thing), or pass `model` and `thing` and it is worked out here.
|
|
34
|
+
*/
|
|
35
|
+
export function ThingCard({ card, model, thing, onOpen, selected = false, headingLevel = 2 }) {
|
|
36
|
+
const c = card ?? thingCard(model, thing);
|
|
37
|
+
const hid = `tl-thing-${c.id}`;
|
|
38
|
+
const ability = (m) => h(Fragment, null,
|
|
39
|
+
h(ThunderSymbol, { id: m.symbol, size: 24 }),
|
|
40
|
+
h('span', { className: 'tl-ability-label' }, m.label),
|
|
41
|
+
onOpen ? h('span', { className: 'tl-ability-go', 'aria-hidden': true }, '→') : null);
|
|
42
|
+
return h('section', { 'aria-labelledby': hid, className: `tl-card tl-thing${selected ? ' tl-selected' : ''}` },
|
|
43
|
+
h('div', { className: 'tl-card-head' },
|
|
44
|
+
h(ThunderSymbol, { id: 'thing', size: 44, label: 'Thing' }),
|
|
45
|
+
h('div', null,
|
|
46
|
+
h('p', { className: 'tl-kicker' }, c.heading),
|
|
47
|
+
h(`h${headingLevel}`, { id: hid, className: 'tl-card-title' }, c.label))),
|
|
48
|
+
c.doc ? h('p', { className: 'tl-doc' }, c.doc) : null,
|
|
49
|
+
c.knows.items.length ? h(Fragment, null,
|
|
50
|
+
h(`h${headingLevel + 1}`, { className: 'tl-section-label' }, c.knows.heading),
|
|
51
|
+
h('ul', { className: 'tl-knows' }, c.knows.items.map(knowsItem))) : null,
|
|
52
|
+
c.can.items.length ? h(Fragment, null,
|
|
53
|
+
h(`h${headingLevel + 1}`, { className: 'tl-section-label' }, c.can.heading),
|
|
54
|
+
h('ul', { className: 'tl-abilities' }, c.can.items.map((m) => h('li', { key: m.id },
|
|
55
|
+
onOpen
|
|
56
|
+
? h('button', { type: 'button', className: 'tl-ability tl-ability-button', onClick: () => onOpen(m.id) }, ability(m))
|
|
57
|
+
: h('div', { className: 'tl-ability' }, ability(m)))))) : null,
|
|
58
|
+
c.starts.id && onOpen
|
|
59
|
+
? h('button', { type: 'button', className: 'tl-starts tl-starts-button', onClick: () => onOpen(c.starts.id) }, h(ThunderSymbol, { id: 'setup', size: 18 }), c.starts.text)
|
|
60
|
+
: h('p', { className: 'tl-starts' }, h(ThunderSymbol, { id: 'setup', size: 18 }), c.starts.text));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Data: a record (facts, like an ID card) or choices (one allowed value). */
|
|
64
|
+
export function DataCard({ card, thing, headingLevel = 3 }) {
|
|
65
|
+
const c = card ?? dataCard(thing);
|
|
66
|
+
return h('section', { className: `tl-card tl-data tl-data-${c.kind}` },
|
|
67
|
+
h('div', { className: 'tl-card-head' },
|
|
68
|
+
h(ThunderSymbol, { id: c.symbol, size: 30, label: c.symbolLabel }),
|
|
69
|
+
h('div', null,
|
|
70
|
+
h('p', { className: 'tl-kicker tl-kicker-quiet' }, c.heading),
|
|
71
|
+
h(`h${headingLevel}`, { className: 'tl-card-title tl-card-title-small' }, c.label))),
|
|
72
|
+
c.doc ? h('p', { className: 'tl-doc tl-doc-small' }, c.doc) : null,
|
|
73
|
+
c.choices.length ? h('ul', { className: 'tl-choices' }, c.choices.map((x) => h('li', { key: x, className: 'tl-choice' }, x))) : null,
|
|
74
|
+
c.knows.length ? h('ul', { className: 'tl-knows tl-knows-small' }, c.knows.map(knowsItem)) : null);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The Big Picture, zoomed by `focus` (see readingLayout). The IO boxes for an action or rule are drawn by IOBoxes,
|
|
79
|
+
* which joins the kit next; until then that section is left to the app.
|
|
80
|
+
*/
|
|
81
|
+
export function BigPicture({ model, layout, focus = null, onOpen, selectedId, headingLevel = 2 }) {
|
|
82
|
+
const l = layout ?? readingLayout(model, { focus });
|
|
83
|
+
return h('div', { className: 'tl-reading tl-big-picture' }, l.sections.filter((s) => s.id !== 'io').map((s) => h('section', { key: s.id, className: `tl-bp-section tl-bp-${s.id}`, 'aria-label': s.heading },
|
|
84
|
+
h('div', { className: s.id === 'things' ? 'tl-bp-things' : 'tl-bp-data' }, s.cards.map((c) => (c.kind === 'thing'
|
|
85
|
+
? h(ThingCard, { key: c.id, card: c, onOpen, selected: c.id === selectedId, headingLevel })
|
|
86
|
+
: h(DataCard, { key: c.id, card: c, headingLevel: headingLevel + 1 })))))));
|
|
87
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ThunderModel, Thing, Member } from './model.d.mts';
|
|
2
|
+
|
|
3
|
+
export const READING_LAYOUT_SCHEMA: 'thunder-reading-layout-v1';
|
|
4
|
+
export const READING_LABELS: Readonly<{
|
|
5
|
+
thing: string; knows: string; can: string; starts: (label: string) => string; startsWithKnows: (label: string) => string;
|
|
6
|
+
record: string; choices: string; recordSymbol: string; choicesSymbol: string; things: string; data: string;
|
|
7
|
+
give: string; getBack: string; stops: string; givesNothing: string; getsNothing: string; partOf: (label: string) => string; io: string;
|
|
8
|
+
}>;
|
|
9
|
+
export type ThunderSymbolId = 'app' | 'area' | 'file' | 'thing' | 'data' | 'record' | 'choices' | 'action' | 'rule' | 'steps' | 'setup' | 'stop' | 'not-read' | 'resource' | 'permission';
|
|
10
|
+
export interface KnowsLine { name: string; label: string; detail: string | null; secret?: true; line: number | null }
|
|
11
|
+
export interface ThingCardLayout {
|
|
12
|
+
kind: 'thing'; id: string; label: string; doc: string | null; heading: string; symbol: 'thing';
|
|
13
|
+
knows: { heading: string; items: KnowsLine[] };
|
|
14
|
+
can: { heading: string; items: { id: string; label: string; symbol: ThunderSymbolId }[] };
|
|
15
|
+
/** id: the setup member to open, or null when a new one starts with what it knows. */
|
|
16
|
+
starts: { id: string | null; text: string };
|
|
17
|
+
}
|
|
18
|
+
export interface DataCardLayout {
|
|
19
|
+
kind: 'record' | 'choices'; id: string; label: string; doc: string | null; heading: string;
|
|
20
|
+
symbol: 'record' | 'choices'; symbolLabel: string; choices: string[]; knows: KnowsLine[];
|
|
21
|
+
}
|
|
22
|
+
export interface IOBoxesLayout {
|
|
23
|
+
kind: 'io'; id: string; label: string; doc: string | null; symbol: ThunderSymbolId;
|
|
24
|
+
give: { heading: string; items: { label: string; kind: string | null }[]; empty: string };
|
|
25
|
+
getBack: { heading: string; text: string | null; empty: string };
|
|
26
|
+
stops: { heading: string; items: { text: string; line: number | null }[] };
|
|
27
|
+
/** The Thing it belongs to, to link back to its card. */
|
|
28
|
+
partOf: { id: string; text: string } | null;
|
|
29
|
+
}
|
|
30
|
+
export interface ReadingLayout {
|
|
31
|
+
schema: 'thunder-reading-layout-v1';
|
|
32
|
+
focus: { kind: 'app' | 'file' | 'thing' | 'member' | 'unknown'; id: string | null };
|
|
33
|
+
sections: Array<{ id: 'things'; heading: string; cards: ThingCardLayout[] } | { id: 'data'; heading: string; cards: DataCardLayout[] } | { id: 'io'; heading: string; cards: IOBoxesLayout[] }>;
|
|
34
|
+
}
|
|
35
|
+
export function memberSymbolId(member: { kind: string }): ThunderSymbolId;
|
|
36
|
+
export function thingCard(model: ThunderModel, thing: Thing): ThingCardLayout;
|
|
37
|
+
export function dataCard(thing: Thing): DataCardLayout;
|
|
38
|
+
export function ioBoxes(model: ThunderModel, member: Member): IOBoxesLayout;
|
|
39
|
+
/** The Big Picture, zoomed by focus: none or a file (Things, then records, then choices), a Thing (its card, then its file's Data), or an action/rule (its IO boxes). */
|
|
40
|
+
export function readingLayout(model: ThunderModel, options?: { focus?: string | null }): ReadingLayout;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// What a Thunder reading shows, and in what order, as plain data: the words on every card, which list comes first,
|
|
2
|
+
// and what each entry opens. Every app that draws a reading (OpenThunder, thunderlang.dev, the Skills Tech Talk
|
|
3
|
+
// course) draws from this, so the three say the same thing in the same order; the drawing kit
|
|
4
|
+
// (@skillstech/thunderlang/react) only turns it into elements. Pure, deterministic, browser-safe, no React.
|
|
5
|
+
|
|
6
|
+
export const READING_LAYOUT_SCHEMA = 'thunder-reading-layout-v1';
|
|
7
|
+
|
|
8
|
+
/** Every fixed word a reading shows. Change a label here and every app changes with it. */
|
|
9
|
+
export const READING_LABELS = Object.freeze({
|
|
10
|
+
thing: 'A Thing',
|
|
11
|
+
knows: 'It knows',
|
|
12
|
+
can: 'It can',
|
|
13
|
+
starts: (label) => `How a new ${label} starts`,
|
|
14
|
+
startsWithKnows: (label) => `A new ${label} starts with what it knows above`,
|
|
15
|
+
record: 'Data: a record',
|
|
16
|
+
choices: 'Data: choices',
|
|
17
|
+
recordSymbol: 'Record',
|
|
18
|
+
choicesSymbol: 'Choices',
|
|
19
|
+
things: 'Things',
|
|
20
|
+
data: 'Data',
|
|
21
|
+
give: 'You give it',
|
|
22
|
+
getBack: 'You get back',
|
|
23
|
+
stops: 'It can stop with',
|
|
24
|
+
givesNothing: 'Nothing',
|
|
25
|
+
getsNothing: 'Nothing it hands back',
|
|
26
|
+
partOf: (label) => `Part of ${label}`,
|
|
27
|
+
io: 'What goes in and out',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/** The symbol (thunder-visual-v1) for a member, as every view draws it. */
|
|
31
|
+
export const memberSymbolId = (m) => (m.kind === 'action' || m.kind === 'pipeline' ? 'action' : m.kind === 'rule' ? 'rule' : m.kind === 'setup' ? 'setup' : m.kind === 'not-read' ? 'not-read' : 'steps');
|
|
32
|
+
|
|
33
|
+
/** One "It knows" line: the name, and its kind and starting value in words when the code says them. */
|
|
34
|
+
const knowsLine = (k) => {
|
|
35
|
+
const detail = [k.kind, k.start].filter(Boolean).join(', ');
|
|
36
|
+
return { name: k.name, label: k.label, detail: detail || null, ...(k.secret ? { secret: true } : {}), line: k.line ?? null };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** A Thing card: what it knows, what it can do (each a door to open), and how a new one starts. */
|
|
40
|
+
export function thingCard(model, thing) {
|
|
41
|
+
const members = new Map(model.members.map((m) => [m.id, m]));
|
|
42
|
+
const can = thing.can.map((id) => members.get(id)).filter(Boolean);
|
|
43
|
+
const setup = can.find((m) => m.kind === 'setup') ?? null;
|
|
44
|
+
return {
|
|
45
|
+
kind: 'thing', id: thing.id, label: thing.label, doc: thing.doc ?? null,
|
|
46
|
+
heading: READING_LABELS.thing, symbol: 'thing',
|
|
47
|
+
knows: { heading: READING_LABELS.knows, items: thing.knows.map(knowsLine) },
|
|
48
|
+
can: { heading: READING_LABELS.can, items: can.filter((m) => m !== setup).map((m) => ({ id: m.id, label: `${m.label}${m.yesNo ? '?' : ''}`, symbol: memberSymbolId(m) })) },
|
|
49
|
+
starts: setup ? { id: setup.id, text: READING_LABELS.starts(thing.label) } : { id: null, text: READING_LABELS.startsWithKnows(thing.label) },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A Data card: a record (facts, like an ID card) or choices (one allowed value). */
|
|
54
|
+
export function dataCard(thing) {
|
|
55
|
+
const record = thing.kind === 'record';
|
|
56
|
+
return {
|
|
57
|
+
kind: record ? 'record' : 'choices', id: thing.id, label: thing.label, doc: thing.doc ?? null,
|
|
58
|
+
heading: record ? READING_LABELS.record : READING_LABELS.choices,
|
|
59
|
+
symbol: record ? 'record' : 'choices', symbolLabel: record ? READING_LABELS.recordSymbol : READING_LABELS.choicesSymbol,
|
|
60
|
+
choices: [...thing.choices],
|
|
61
|
+
knows: thing.knows.map(knowsLine),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 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
|
+
* get back", "It can stop with" (every Stop in its flow, with its line), and "Part of <Thing>" back to its card.
|
|
68
|
+
*/
|
|
69
|
+
export function ioBoxes(model, member) {
|
|
70
|
+
const owner = member.owner ? model.things.find((t) => t.id === member.owner) : null;
|
|
71
|
+
const kinds = member.inputKinds ?? {};
|
|
72
|
+
const stops = (member.flow?.nodes ?? []).filter((n) => n.kind === 'stop').map((n) => ({ text: n.text.replace(/^Stop:\s*/, ''), line: n.line ?? null }));
|
|
73
|
+
return {
|
|
74
|
+
kind: 'io', id: member.id, label: `${member.label}${member.yesNo ? '?' : ''}`, doc: member.doc ?? null, symbol: memberSymbolId(member),
|
|
75
|
+
give: { heading: READING_LABELS.give, items: member.youGive.map((label) => ({ label, kind: kinds[label] ?? null })), empty: READING_LABELS.givesNothing },
|
|
76
|
+
getBack: { heading: READING_LABELS.getBack, text: member.youGetBack ?? null, empty: READING_LABELS.getsNothing },
|
|
77
|
+
stops: { heading: READING_LABELS.stops, items: stops },
|
|
78
|
+
partOf: owner ? { id: owner.id, text: READING_LABELS.partOf(owner.label) } : null,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const sectionsFor = (model, things) => {
|
|
83
|
+
const cards = things.filter((t) => t.kind === 'thing').map((t) => thingCard(model, t));
|
|
84
|
+
const data = [...things.filter((t) => t.kind === 'record'), ...things.filter((t) => t.kind === 'choices')].map(dataCard);
|
|
85
|
+
return [
|
|
86
|
+
...(cards.length ? [{ id: 'things', heading: READING_LABELS.things, cards }] : []),
|
|
87
|
+
...(data.length ? [{ id: 'data', heading: READING_LABELS.data, cards: data }] : []),
|
|
88
|
+
];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The Big Picture, which zooms with what is in focus (the tabs stay Big Picture / Flow / Details / Text / Original):
|
|
93
|
+
* no focus: every Thing, then every record, then every set of choices
|
|
94
|
+
* a file's path: the same, for that file
|
|
95
|
+
* a Thing's id: its card, then the Data in its file
|
|
96
|
+
* an action or rule: its "You give it / You get back / It can stop with" boxes, with "Part of <Thing>"
|
|
97
|
+
* Resources are infrastructure and have their own view. `focus.kind` says which one it was ('unknown' when the id is
|
|
98
|
+
* not in the model: nothing is drawn rather than something else).
|
|
99
|
+
*/
|
|
100
|
+
export function readingLayout(model, { focus = null } = {}) {
|
|
101
|
+
const base = { schema: READING_LAYOUT_SCHEMA };
|
|
102
|
+
if (focus == null) return { ...base, focus: { kind: 'app', id: null }, sections: sectionsFor(model, model.things) };
|
|
103
|
+
const member = model.members.find((m) => m.id === focus);
|
|
104
|
+
if (member) return { ...base, focus: { kind: 'member', id: focus }, sections: [{ id: 'io', heading: READING_LABELS.io, cards: [ioBoxes(model, member)] }] };
|
|
105
|
+
const thing = model.things.find((t) => t.id === focus);
|
|
106
|
+
if (thing) {
|
|
107
|
+
const rest = model.things.filter((t) => t !== thing && t.file === thing.file && t.kind !== 'thing');
|
|
108
|
+
return { ...base, focus: { kind: 'thing', id: focus }, sections: sectionsFor(model, [thing, ...rest]) };
|
|
109
|
+
}
|
|
110
|
+
if (model.files.some((f) => f.path === focus)) return { ...base, focus: { kind: 'file', id: focus }, sections: sectionsFor(model, model.things.filter((t) => t.file === focus)) };
|
|
111
|
+
return { ...base, focus: { kind: 'unknown', id: focus }, sections: [] };
|
|
112
|
+
}
|