@yaks/inspect 0.0.0-stage → 0.2.36

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.
Files changed (133) hide show
  1. package/Comp.js +469 -0
  2. package/Comp.js.map +1 -0
  3. package/Comp.ts +471 -0
  4. package/Effect.js +136 -0
  5. package/Effect.js.map +1 -0
  6. package/Effect.ts +142 -0
  7. package/Entity.js +112 -0
  8. package/Entity.js.map +1 -0
  9. package/Entity.ts +137 -0
  10. package/Facts.js +143 -0
  11. package/Facts.js.map +1 -0
  12. package/Facts.ts +150 -0
  13. package/Head.js +196 -0
  14. package/Head.js.map +1 -0
  15. package/Head.ts +195 -0
  16. package/Held.js +144 -0
  17. package/Held.js.map +1 -0
  18. package/Held.ts +172 -0
  19. package/History.js +157 -0
  20. package/History.js.map +1 -0
  21. package/History.ts +215 -0
  22. package/Home.js +482 -0
  23. package/Home.js.map +1 -0
  24. package/Home.ts +550 -0
  25. package/LICENSE +202 -0
  26. package/Links.js +197 -0
  27. package/Links.js.map +1 -0
  28. package/Links.ts +212 -0
  29. package/Package.js +195 -0
  30. package/Package.js.map +1 -0
  31. package/Package.ts +191 -0
  32. package/Past.js +163 -0
  33. package/Past.js.map +1 -0
  34. package/Past.ts +181 -0
  35. package/Prop.js +225 -0
  36. package/Prop.js.map +1 -0
  37. package/Prop.ts +208 -0
  38. package/Query.js +207 -0
  39. package/Query.js.map +1 -0
  40. package/Query.ts +229 -0
  41. package/README.md +141 -2
  42. package/Words.js +43 -0
  43. package/Words.js.map +1 -0
  44. package/Words.ts +70 -0
  45. package/_dist/Entity.d.ts +7 -0
  46. package/_dist/Entity.d.ts.map +1 -0
  47. package/_dist/Facts.d.ts +7 -0
  48. package/_dist/Facts.d.ts.map +1 -0
  49. package/_dist/Head.d.ts +22 -0
  50. package/_dist/Head.d.ts.map +1 -0
  51. package/_dist/Held.d.ts +37 -0
  52. package/_dist/Held.d.ts.map +1 -0
  53. package/_dist/Links.d.ts +9 -0
  54. package/_dist/Links.d.ts.map +1 -0
  55. package/_dist/Past.d.ts +65 -0
  56. package/_dist/Past.d.ts.map +1 -0
  57. package/_dist/Words.d.ts +27 -0
  58. package/_dist/Words.d.ts.map +1 -0
  59. package/_dist/census.d.ts +10 -0
  60. package/_dist/census.d.ts.map +1 -0
  61. package/_dist/door.d.ts +28 -0
  62. package/_dist/door.d.ts.map +1 -0
  63. package/_dist/front.d.ts +4 -0
  64. package/_dist/front.d.ts.map +1 -0
  65. package/_dist/host.d.ts +94 -0
  66. package/_dist/host.d.ts.map +1 -0
  67. package/_dist/mod.d.ts +24 -0
  68. package/_dist/mod.d.ts.map +1 -0
  69. package/_dist/notes.d.ts +38 -0
  70. package/_dist/notes.d.ts.map +1 -0
  71. package/_dist/read.d.ts +59 -0
  72. package/_dist/read.d.ts.map +1 -0
  73. package/_dist/reading.d.ts +21 -0
  74. package/_dist/reading.d.ts.map +1 -0
  75. package/_dist/registry.d.ts +12 -0
  76. package/_dist/registry.d.ts.map +1 -0
  77. package/_dist/schema.d.ts +4 -0
  78. package/_dist/schema.d.ts.map +1 -0
  79. package/_dist/state.d.ts +22 -0
  80. package/_dist/state.d.ts.map +1 -0
  81. package/_dist/value.d.ts +20 -0
  82. package/_dist/value.d.ts.map +1 -0
  83. package/_dist/views.d.ts +3 -0
  84. package/_dist/views.d.ts.map +1 -0
  85. package/census.js +50 -0
  86. package/census.js.map +1 -0
  87. package/census.ts +76 -0
  88. package/deno.json +1 -0
  89. package/door.js +54 -0
  90. package/door.js.map +1 -0
  91. package/door.ts +59 -0
  92. package/front.js +12 -0
  93. package/front.js.map +1 -0
  94. package/front.json +76 -0
  95. package/front.ts +13 -0
  96. package/grid.js +249 -0
  97. package/grid.js.map +1 -0
  98. package/grid.ts +395 -0
  99. package/host.js +20 -0
  100. package/host.js.map +1 -0
  101. package/host.ts +134 -0
  102. package/mod.js +20 -0
  103. package/mod.js.map +1 -0
  104. package/mod.ts +45 -0
  105. package/notes.js +184 -0
  106. package/notes.js.map +1 -0
  107. package/notes.ts +288 -0
  108. package/package.json +35 -4
  109. package/read.js +300 -0
  110. package/read.js.map +1 -0
  111. package/read.ts +386 -0
  112. package/reading.js +64 -0
  113. package/reading.js.map +1 -0
  114. package/reading.ts +73 -0
  115. package/registry.js +89 -0
  116. package/registry.js.map +1 -0
  117. package/registry.ts +89 -0
  118. package/rows.js +12 -0
  119. package/rows.js.map +1 -0
  120. package/rows.ts +26 -0
  121. package/schema.js +47 -0
  122. package/schema.js.map +1 -0
  123. package/schema.ts +70 -0
  124. package/state.js +85 -0
  125. package/state.js.map +1 -0
  126. package/state.ts +128 -0
  127. package/terminal-links.ts +16 -0
  128. package/value.js +67 -0
  129. package/value.js.map +1 -0
  130. package/value.ts +79 -0
  131. package/views.js +4 -0
  132. package/views.js.map +1 -0
  133. package/views.ts +6 -0
package/Home.ts ADDED
@@ -0,0 +1,550 @@
1
+ /**
2
+ * The schema: how the graph's data is made, one slice at a time, each a
3
+ * listing to press into.
4
+ *
5
+ * - Packages: a tree of each package the vocabulary is served from, the
6
+ * components and effects it declares, and the properties of each
7
+ * component: what each is, what it holds and how many entities carry it.
8
+ * Opening a package shows its components and effects, opening a component
9
+ * its properties.
10
+ * - Components: every component, its package, what it is and how many
11
+ * entities carry it, the most carried first.
12
+ * - Kinds: every kind, from the `_kind` rows the graph describes them in
13
+ * (@yaks/vocab): the components that make one, what a whole one also
14
+ * carries, the prefix its ids are numbered in, and how many entities are
15
+ * one.
16
+ * - Relations: every component that is an edge relation (@yaks/edge), what it
17
+ * reads as from the far end, and how many edges state it.
18
+ * - Archetypes: every set of components entities are made of, the most
19
+ * populous first.
20
+ *
21
+ * Which slice shows, which rows are open and how each table runs are the
22
+ * page's own state (./state.ts), so the map shows as it was left. Names, what
23
+ * each is and what it holds come from the vocabulary the host was served, so
24
+ * the map paints at once; every count comes from one census (./census.ts),
25
+ * which the graph answers from the populations it keeps, and fills in when
26
+ * it does.
27
+ *
28
+ * @module
29
+ */
30
+
31
+ import { groupBy } from '@yaks/fp'
32
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
33
+ import { Head, Loading, Tabs, Value } from '@yaks/ui'
34
+ import { type EffectDecl, effectsIn, type Vocab } from '@yaks/vocab'
35
+ import type { Bundle, Io } from './host.ts'
36
+ import { type Census, useCensus } from './census.js'
37
+ import { Grid } from './grid.js'
38
+ import {
39
+ chip,
40
+ chips,
41
+ compEid,
42
+ effectEid,
43
+ packEid,
44
+ propEid,
45
+ relations,
46
+ } from './schema.js'
47
+ import { Part, under, useNotes } from './notes.js'
48
+ import { comp, count, line, str, tables } from './read.js'
49
+ import { rows, waiting } from './rows.js'
50
+ import { key, me, put } from './state.js'
51
+
52
+ /** The slices of the schema the map shows, the first when none is chosen. */
53
+ export let SLICES = [
54
+ 'packages',
55
+ 'components',
56
+ 'kinds',
57
+ 'relations',
58
+ 'archetypes',
59
+ ]
60
+
61
+ // Each slice's heading, and the component its notes are about: what its
62
+ // rows are made of.
63
+ let SLICE: Record<string, { heading: string; concept: string }> = {
64
+ packages: { heading: 'Packages', concept: '_namespace' },
65
+ components: { heading: 'Components', concept: '_comp' },
66
+ kinds: { heading: 'Kinds', concept: '_kind' },
67
+ relations: { heading: 'Relations', concept: 'edge' },
68
+ archetypes: { heading: 'Archetypes', concept: 'archetype' },
69
+ }
70
+
71
+ // Keep known counts visible during a refresh, not zeroes before the census.
72
+ let tallied = (ready: boolean, n: number) =>
73
+ ready || n ? count(n) : h(Loading, {})
74
+
75
+ let plural = (n: number, one: string, many: string) =>
76
+ `${count(n)} ${n == 1 ? one : many}`
77
+
78
+ // A property's type, in a word: what it points at, the values it takes, or
79
+ // its scalar.
80
+ let typeOf = (io: Io, comp: string, prop: string): string => {
81
+ let p = io.vocab.prop(comp, prop)
82
+ return p?.ref
83
+ ? `→ ${p.ref}`
84
+ : p?.values?.join(' | ') ?? p?.types?.join(' | ') ?? p?.scalar ?? ''
85
+ }
86
+
87
+ /** What every slice reads: the vocabulary's packages, the components and
88
+ * effects each declares, and the census. */
89
+ type Schema = {
90
+ io: Io
91
+ census: Census
92
+ packages: string[]
93
+ declared: Map<string, string[]>
94
+ effects: Map<string, EffectDecl[]>
95
+ }
96
+
97
+ // The rows of the package tree, each made of the vocabulary component it
98
+ // stands for: a property's row names its component as the graph does, by
99
+ // its eid.
100
+ let packRow = (vocab: Vocab) => (name: string): Bundle => ({
101
+ entity: { eid: packEid(vocab, name) },
102
+ _namespace: { name },
103
+ })
104
+ let compRow = (vocab: Vocab) => (name: string): Bundle => ({
105
+ entity: { eid: compEid(vocab, name) },
106
+ _comp: { name },
107
+ })
108
+ let propRow = (vocab: Vocab, comp: string, prop: string): Bundle => ({
109
+ entity: { eid: propEid(vocab, comp, prop) },
110
+ _prop: { name: prop, comp: compEid(vocab, comp) },
111
+ })
112
+ let effectRow = (vocab: Vocab) => ({ name }: EffectDecl): Bundle => ({
113
+ entity: { eid: effectEid(vocab, name) },
114
+ _effect: { name },
115
+ })
116
+
117
+ // What a row of the package tree says: its name and the link drawn for it,
118
+ // what it holds (a count of the rows under it, or a property's type, in
119
+ // words and to sort by), what it is, how many entities carry it (none for a
120
+ // property or an effect, which the census does not count), and the rows
121
+ // under it.
122
+ type Node = {
123
+ name: string
124
+ link: ReactNode
125
+ holds: number | string
126
+ said: string
127
+ about?: string
128
+ entities?: number
129
+ kids: Bundle[]
130
+ }
131
+
132
+ // The package tree: packages, then the components and effects each
133
+ // declares, then the properties of each component.
134
+ let PackageTree = ({ io, census, packages, declared, effects }: Schema) => {
135
+ let { carried, sets, tally, ready } = census
136
+ let vocab = io.vocab
137
+ let names = new Map(vocab.all.map((n) => [compEid(vocab, n), n]))
138
+ // How many entities carry any of a package's components.
139
+ let reach = new Map<string, number>()
140
+ for (let s of sets) {
141
+ let own = new Set(
142
+ tables(s, vocab).map((t) => vocab.comp(t)?.namespace?.label ?? ''),
143
+ )
144
+ for (let p of own) {
145
+ reach.set(p, (reach.get(p) ?? 0) + (tally[s.entity.eid] ?? 0))
146
+ }
147
+ }
148
+ let described = new Map(
149
+ [...effects.values()].flat().map((x) => [x.name, x.description]),
150
+ )
151
+ let read = (b: Bundle): Node => {
152
+ if (b._namespace) {
153
+ let name = str(b, '_namespace', 'name')
154
+ let comps = declared.get(name) ?? []
155
+ let acts = effects.get(name) ?? []
156
+ return {
157
+ name,
158
+ link: name
159
+ ? io.show(io.get(b.entity.eid) ?? b, 'Inspect.Reference.Inline')
160
+ : h(Value, { mod: 'nil' }, 'unpackaged'),
161
+ holds: comps.length + acts.length,
162
+ said: [
163
+ plural(comps.length, 'component', 'components'),
164
+ acts.length ? plural(acts.length, 'effect', 'effects') : '',
165
+ ].filter(Boolean).join(' · '),
166
+ about: vocab.docs.find((d) => d.label == name)?.description,
167
+ entities: reach.get(name) ?? 0,
168
+ kids: [...comps.map(compRow(vocab)), ...acts.map(effectRow(vocab))],
169
+ }
170
+ }
171
+ if (b._effect) {
172
+ let name = str(b, '_effect', 'name')
173
+ return {
174
+ name,
175
+ link: io.show(b, 'Inline'),
176
+ holds: 'an effect',
177
+ said: 'an effect',
178
+ about: described.get(name),
179
+ kids: [],
180
+ }
181
+ }
182
+ if (b._comp) {
183
+ let name = str(b, '_comp', 'name')
184
+ let kids = vocab.props(name).map((p) => propRow(vocab, name, p))
185
+ return {
186
+ name,
187
+ link: chip(io, name),
188
+ holds: kids.length,
189
+ said: kids.length
190
+ ? plural(kids.length, 'property', 'properties')
191
+ : 'a mark',
192
+ about: vocab.comp(name)?.description,
193
+ entities: carried[name] ?? 0,
194
+ kids,
195
+ }
196
+ }
197
+ let name = str(b, '_prop', 'name')
198
+ let comp = names.get(str(b, '_prop', 'comp')) ?? ''
199
+ let type = typeOf(io, comp, name)
200
+ return {
201
+ name,
202
+ link: io.show(b, 'Inline'),
203
+ holds: type,
204
+ said: type,
205
+ about: vocab.prop(comp, name)?.description,
206
+ kids: [],
207
+ }
208
+ }
209
+ let nodes = new Map<string, Node>()
210
+ let node = (b: Bundle) =>
211
+ nodes.get(b.entity.eid) ??
212
+ nodes.set(b.entity.eid, read(b)).get(b.entity.eid)!
213
+ return h(Grid, {
214
+ io,
215
+ id: key('schema', 'Packages'),
216
+ local: true,
217
+ rows: packages.map(packRow(io.vocab)),
218
+ columns: [
219
+ { name: 'name', value: (b) => node(b).name, cell: (b) => node(b).link },
220
+ { name: 'holds', value: (b) => node(b).holds, cell: (b) => node(b).said },
221
+ {
222
+ name: 'what it is',
223
+ mod: 'prose',
224
+ cell: (b) => line(node(b).about, 200),
225
+ },
226
+ {
227
+ name: 'entities',
228
+ mod: 'num',
229
+ value: (b) => node(b).entities ?? 0,
230
+ cell: (b) => {
231
+ let n = node(b).entities
232
+ return n == null ? '' : tallied(ready, n)
233
+ },
234
+ },
235
+ ],
236
+ pick: (b) => node(b).name ? b.entity.eid : undefined,
237
+ holds: (b) => node(b).kids,
238
+ })
239
+ }
240
+
241
+ // Every component, the most carried first.
242
+ let ComponentList = ({ io, census: { carried, ready } }: Schema) => {
243
+ let vocab = io.vocab
244
+ let comps = vocab.all.toSorted((a, b) =>
245
+ (carried[b] ?? 0) - (carried[a] ?? 0) || a.localeCompare(b)
246
+ )
247
+ return h(Grid, {
248
+ io,
249
+ id: key('schema', 'Components'),
250
+ local: true,
251
+ rows: comps.map(compRow(vocab)),
252
+ columns: [
253
+ {
254
+ name: 'component',
255
+ value: (b) => str(b, '_comp', 'name'),
256
+ cell: (b) => chip(io, str(b, '_comp', 'name')),
257
+ },
258
+ {
259
+ name: 'package',
260
+ value: (b) =>
261
+ vocab.comp(str(b, '_comp', 'name'))?.namespace?.label ?? '',
262
+ cell: (b) =>
263
+ vocab.comp(str(b, '_comp', 'name'))?.namespace?.label ?? '',
264
+ },
265
+ {
266
+ name: 'what it is',
267
+ mod: 'prose',
268
+ cell: (b) =>
269
+ line(vocab.comp(str(b, '_comp', 'name'))?.description, 160),
270
+ },
271
+ {
272
+ name: 'entities',
273
+ mod: 'num',
274
+ value: (b) => carried[str(b, '_comp', 'name')] ?? 0,
275
+ cell: (b) => tallied(ready, carried[str(b, '_comp', 'name')] ?? 0),
276
+ },
277
+ ],
278
+ })
279
+ }
280
+
281
+ // The query the kinds slice reads: every kind's row, by name.
282
+ export let KINDS = '._kind&?doc&.order=_kind.name'
283
+
284
+ // Every kind, from its `_kind` row: what makes one, what a whole one also
285
+ // carries, its ids' prefix, what it is, and how many entities are one (each
286
+ // set of components counted as the kind it names).
287
+ let KindList = ({ io, census: { sets, tally, ready } }: Schema) => {
288
+ let { kinds } = io.ask({ kinds: KINDS })
289
+ let are = new Map<string, number>()
290
+ for (let s of sets) {
291
+ let k = io.vocab.kindOf(
292
+ Object.fromEntries(tables(s, io.vocab).map((t) => [t, {}])),
293
+ )
294
+ if (k) are.set(k, (are.get(k) ?? 0) + (tally[s.entity.eid] ?? 0))
295
+ }
296
+ let name = (b: Bundle) => str(b, '_kind', 'name')
297
+ let is = (b: Bundle) => (comp(b, '_kind').is ?? []) as string[]
298
+ let has = (b: Bundle) => Object.keys(comp(b, '_kind').with ?? {})
299
+ let prefix = (b: Bundle) => str(b, '_kind', 'prefix')
300
+ return waiting(kinds) ?? h(Grid, {
301
+ io,
302
+ id: key('schema', 'Kinds'),
303
+ local: true,
304
+ rows: rows(kinds),
305
+ columns: [
306
+ { name: 'kind', value: name, cell: (b) => io.show(b, 'Inline') },
307
+ { name: 'is', cell: (b) => chips(io, is(b)) },
308
+ {
309
+ name: 'with',
310
+ cell: (b) =>
311
+ has(b).length ? chips(io, has(b)) : h(Value, { mod: 'nil' }, '—'),
312
+ },
313
+ {
314
+ name: 'ids',
315
+ value: prefix,
316
+ cell: (b) => prefix(b) ? `${prefix(b)}-` : '',
317
+ },
318
+ {
319
+ name: 'what it is',
320
+ mod: 'prose',
321
+ cell: (b) => line(str(b, 'doc', 'body'), 160),
322
+ },
323
+ {
324
+ name: 'entities',
325
+ mod: 'num',
326
+ value: (b) => are.get(name(b)) ?? 0,
327
+ cell: (b) => tallied(ready, are.get(name(b)) ?? 0),
328
+ },
329
+ ],
330
+ })
331
+ }
332
+
333
+ // Every edge relation, what it reads as from the far end, and its edges.
334
+ let RelationList = ({ io, census: { carried, ready } }: Schema) => {
335
+ let vocab = io.vocab
336
+ return h(Grid, {
337
+ io,
338
+ id: key('schema', 'Relations'),
339
+ local: true,
340
+ rows: relations(io).toSorted().map(compRow(vocab)),
341
+ columns: [
342
+ {
343
+ name: 'relation',
344
+ value: (b) => str(b, '_comp', 'name'),
345
+ cell: (b) => chip(io, str(b, '_comp', 'name')),
346
+ },
347
+ {
348
+ name: 'from the far end',
349
+ cell: (b) => {
350
+ let back = vocab.comp(str(b, '_comp', 'name'))?.keywords.reversed
351
+ return typeof back == 'string'
352
+ ? back
353
+ : h(Value, { mod: 'nil' }, 'the same')
354
+ },
355
+ },
356
+ {
357
+ name: 'edges',
358
+ mod: 'num',
359
+ value: (b) => carried[str(b, '_comp', 'name')] ?? 0,
360
+ cell: (b) => tallied(ready, carried[str(b, '_comp', 'name')] ?? 0),
361
+ },
362
+ {
363
+ name: 'package',
364
+ value: (b) =>
365
+ vocab.comp(str(b, '_comp', 'name'))?.namespace?.label ?? '',
366
+ cell: (b) =>
367
+ vocab.comp(str(b, '_comp', 'name'))?.namespace?.label ?? '',
368
+ },
369
+ ],
370
+ })
371
+ }
372
+
373
+ // Every set of components entities are made of, the most populous first; a
374
+ // set's count lists its entities.
375
+ let ArchetypeList = ({ io, census }: Schema) =>
376
+ waiting({ rows: census.sets, ready: census.ready, error: census.error }) ??
377
+ h(Grid, {
378
+ io,
379
+ id: key('schema', 'Archetypes'),
380
+ local: true,
381
+ rows: census.sets,
382
+ columns: [
383
+ {
384
+ name: 'components',
385
+ cell: (b) =>
386
+ tables(b, io.vocab).length
387
+ ? chips(io, tables(b, io.vocab))
388
+ : h(Value, { mod: 'nil' }, 'no components'),
389
+ },
390
+ {
391
+ name: 'entities',
392
+ mod: 'num',
393
+ value: (b) => census.tally[b.entity.eid] ?? 0,
394
+ cell: (b) =>
395
+ h(
396
+ 'a',
397
+ { href: io.find(`.entity.archetype=${b.entity.eid}`) },
398
+ count(census.tally[b.entity.eid] ?? 0),
399
+ ),
400
+ },
401
+ ],
402
+ })
403
+
404
+ // What each slice says under its heading, and draws.
405
+ let BODY: Record<
406
+ string,
407
+ {
408
+ sub: string
409
+ Body: (m: Schema) => JSX.Element | null
410
+ size: (m: Schema) => number | undefined
411
+ }
412
+ > = {
413
+ packages: {
414
+ sub: 'Each package the vocabulary is served from. Open one for the ' +
415
+ 'components it declares, and a component for its properties; press a ' +
416
+ 'row to open its page.',
417
+ Body: PackageTree,
418
+ size: (m) => m.packages.length,
419
+ },
420
+ components: {
421
+ sub: 'Every component and how many entities carry it, the most carried ' +
422
+ 'first; a pressed heading runs them by it.',
423
+ Body: ComponentList,
424
+ size: (m) => m.io.vocab.all.length,
425
+ },
426
+ kinds: {
427
+ sub: 'Every kind an entity is named by: the components that make one, ' +
428
+ 'what a whole one also carries, and how many entities are one.',
429
+ Body: KindList,
430
+ size: (m) => m.io.vocab.kinds.length,
431
+ },
432
+ relations: {
433
+ sub: 'Every component that relates one entity to another, what it reads ' +
434
+ 'as from the far end, and how many edges state it.',
435
+ Body: RelationList,
436
+ size: (m) => relations(m.io).length,
437
+ },
438
+ archetypes: {
439
+ sub: 'Every set of components entities are made of, the most populous ' +
440
+ 'first; press a count to list them.',
441
+ Body: ArchetypeList,
442
+ size: (m) => m.census.ready ? m.census.sets.length : undefined,
443
+ },
444
+ }
445
+
446
+ // The slice showing, under its heading, with the notes left there; notes on
447
+ // a slice are about the component its rows are made of.
448
+ let Slice = ({ slice, ...m }: Schema & { slice: string }) => {
449
+ let { heading, concept } = SLICE[slice]
450
+ let eid = compEid(m.io.vocab, concept)
451
+ let { sub, Body, size } = BODY[slice]
452
+ return h(
453
+ Part,
454
+ {
455
+ io: m.io,
456
+ eid,
457
+ subject: concept,
458
+ heading,
459
+ notes: under(useNotes(m.io, eid), concept, [heading]),
460
+ count: size(m),
461
+ sub,
462
+ },
463
+ h(Body, m),
464
+ )
465
+ }
466
+
467
+ /** The map of the schema. */
468
+ export let HomePage = ({ io }: { io: Io }): JSX.Element => {
469
+ let census = useCensus(io)
470
+ let vocab = io.vocab
471
+ let declared = groupBy(
472
+ vocab.all.toSorted(),
473
+ (n) => vocab.comp(n)?.namespace?.label ?? '',
474
+ )
475
+ // Every package the vocabulary declares, even one declaring no component
476
+ // (it only extends another's), and the components no package declares.
477
+ let effects = groupBy(
478
+ vocab.docs.flatMap((d) =>
479
+ effectsIn(d).map((x) => ({ ...x, package: d.label ?? '' }))
480
+ ).toSorted((a, b) => a.name.localeCompare(b.name)),
481
+ (x) => x.package,
482
+ )
483
+ let named = [...new Set(vocab.docs.flatMap((d) => d.label ?? []))]
484
+ .toSorted()
485
+ let packages = declared.has('') || effects.has('') ? [...named, ''] : named
486
+ let slice = SLICES.includes(me(io).slice ?? '') ? me(io).slice! : SLICES[0]
487
+ let total = Object.values(census.tally).reduce((a, b) => a + b, 0)
488
+ return h(
489
+ 'div',
490
+ {},
491
+ h(
492
+ Head,
493
+ {},
494
+ h(Head.Title, {}, 'Schema'),
495
+ h(
496
+ Head.Sub,
497
+ {},
498
+ "The graph's data model: the packages it is declared in, the " +
499
+ 'components entities carry and their properties, the kinds they ' +
500
+ 'make, the relations ' +
501
+ 'between them, and the sets of components entities are made of.',
502
+ ),
503
+ h(
504
+ Head.Facts,
505
+ {},
506
+ h('span', {}, plural(named.length, 'package', 'packages')),
507
+ h('span', {}, plural(vocab.all.length, 'component', 'components')),
508
+ h('span', {}, plural(vocab.kinds.length, 'kind', 'kinds')),
509
+ h(
510
+ 'span',
511
+ {},
512
+ plural([...effects.values()].flat().length, 'effect', 'effects'),
513
+ ),
514
+ h(
515
+ 'span',
516
+ {},
517
+ plural(relations(io).length, 'relation', 'relations'),
518
+ ),
519
+ h(
520
+ 'span',
521
+ {},
522
+ census.ready || census.sets.length
523
+ ? plural(census.sets.length, 'archetype', 'archetypes')
524
+ : h(Loading, {}),
525
+ ),
526
+ h(
527
+ 'span',
528
+ {},
529
+ census.ready || total
530
+ ? plural(total, 'entity', 'entities')
531
+ : h(Loading, {}),
532
+ ),
533
+ ),
534
+ ),
535
+ h(
536
+ Tabs,
537
+ { role: 'group', 'aria-label': 'slice of the schema' },
538
+ SLICES.map((s) =>
539
+ h(Tabs.Tab, {
540
+ key: s,
541
+ type: 'button',
542
+ mod: s == slice && 'on',
543
+ 'aria-pressed': s == slice,
544
+ onClick: () => io.set(put({ slice: s })),
545
+ }, SLICE[s].heading)
546
+ ),
547
+ ),
548
+ h(Slice, { io, census, packages, declared, effects, slice }),
549
+ )
550
+ }