@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
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The inspector's own state, as it lives in the page's own graph
3
+ * (./front.json): read through `io.state`, changed by the patches built here
4
+ * and written through `io.set`. One entity, `inspect`, holds the page's
5
+ * (`inspector`: the page being edited, a note open, a delete armed, where a
6
+ * write was refused, the slice of the schema the map shows); each table holds
7
+ * its own (`table`: its order, its page and its open rows).
8
+ *
9
+ * @module
10
+ */ import { type Host as Ux } from "@yaks/ux";
11
+ import type { Host, Io } from "./host.js";
12
+ /** The entity the page's state is on. */ export declare let INSPECT: string;
13
+ /** Whether the page of the entity `eid` shows its controls: where the host's
14
+ * take input, once the reader asked to edit it. */ export declare let edited: (io: Pick<Io, 'state' | 'edits'>, eid: string) => boolean;
15
+ /** The UX components' host (@yaks/ux) over the inspector's: a value changed
16
+ * where it stands is written like any write here, a refusal said in the head
17
+ * of the entity it was about until a write lands, and so is input its `Edit`
18
+ * could not read (a `Refused` event). The page's graph is the inspector's
19
+ * own; `find` is the server search a picker's candidates come from, `fields`
20
+ * the page's query fields, `drafts` where what is typed waits, and `Float`
21
+ * where a picker floats. */ export declare let editing: (host: Host, more: Pick<Ux, 'find' | 'fields' | 'drafts' | 'Float'>) => Ux;
22
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sources":["../state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GAED,SAAS,KAAK,QAAQ,EAAE,wBAA6B;AACrD,cAAsB,IAAI,EAAE,EAAE,oBAAmB;AAGjD,uCAAuC,GACvC,OAAO,YAAI,gBAAmB;AAsC9B;iDACiD,GACjD,OAAO,YAAI,SAAU,IAAI,KAAK,IAAI,UAAU,UAAU,KAAK,MAAM,KAAG,OAAO,CACxC;AA0CnC;;;;;;0BAM0B,GAC1B,OAAO,YAAI,UACT,MAAM,MACN,MAAM,KAAK,IAAI,SAAS,WAAW,WAAW,aAC7C,GAkBF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A stored value on a page. Read, it is said the way a person reads it (`reads`):
3
+ * a reference as the name of what it names, linked; a moment in words; a hash
4
+ * as far as it tells one from another; a JSON value, a text cut to a line.
5
+ * Edited, it is a @yaks/ux `Edit` showing the value as it was stored (`shown`):
6
+ * pressed, it is typed over where it stands, in the shape's own type so nothing
7
+ * moves, or its choices float beside it; a reference's picker opens from a
8
+ * handle beside its link. A value the vocabulary keeps from clients is only
9
+ * shown.
10
+ *
11
+ * @module
12
+ */ import { type JSX } from "@types/react";
13
+ import type { Prop as Declared } from "@yaks/vocab";
14
+ import type { Io } from "./host.js";
15
+ /** An entity a value names: what it is called, linked to its page, the id a
16
+ * person types where the pointer rests on it. */ export declare let mention: (io: Io, eid: string) => JSX.Element;
17
+ /** A stored value as a person reads it; nothing where it holds nothing. A text
18
+ * kept as a blob (@yaks/blob's `store: 'blob'`), where a journal holds its
19
+ * address rather than its words, links to the words. */ export declare let reads: (io: Io, v: unknown, p?: Declared) => JSX.Element;
20
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sources":["../value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GAEyC,SAA6B,KAAK,GAAG,uBAA0B;AAGzG,cAAc,QAAQ,QAAQ,2BAAgC;AAC9D,cAAsB,EAAE,oBAAmB;AAG3C;+CAC+C,GAC/C,OAAO,YAAI,UAAW,IAAI,IAAI,KAAK,MAAM,KAAG,IAAI,QAK/C;AASD;;sDAEsD,GACtD,OAAO,YAAI,QAAS,IAAI,IAAI,GAAG,OAAO,EAAE,IAAI,aAAW,IAAI,QAe1D"}
@@ -0,0 +1,3 @@
1
+ import type { View } from "./host.js";
2
+ export declare let inspectViews: () => Promise<View[]>;
3
+ //# sourceMappingURL=views.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAEA,cAAc,IAAI,oBAAmB;AAErC,OAAO,YAAI,oBAAmB,QAAQ,QACM"}
package/census.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The census every map of the data is read off: each set of components
3
+ * entities are made of (@yaks/archetype), and how many entities are made of
4
+ * each. From it, how many entities carry each component, which sets a
5
+ * component is found in, and how many edges state each relation: no page asks
6
+ * the graph to count those again. The storage adapters answer this unfiltered
7
+ * tally from maintained archetype populations, not by reading their owners.
8
+ * It is asked once, and shared by the map and every page that reads it.
9
+ *
10
+ * @module
11
+ */ import { census as carrying, tables } from "./read.js";
12
+ /** The two lines a census is read from. */ export let CENSUS = {
13
+ sets: '.archetype&.fields=archetype.tables',
14
+ tally: '.tally=entity.archetype'
15
+ };
16
+ /** The census: a hook, asked once and kept while the page is open. */ export let useCensus = (io)=>{
17
+ let got = io.ask({
18
+ sets: {
19
+ query: CENSUS.sets,
20
+ once: true
21
+ },
22
+ tally: {
23
+ query: CENSUS.tally,
24
+ once: true
25
+ }
26
+ });
27
+ let tally = got.tally?.tally ?? {};
28
+ let sets = (got.sets?.rows ?? []).toSorted((a, b)=>(tally[b.entity.eid] ?? 0) - (tally[a.entity.eid] ?? 0));
29
+ let ready = !!got.tally?.ready && !!got.sets?.ready;
30
+ return {
31
+ sets,
32
+ tally,
33
+ carried: carrying(sets, tally, io.vocab),
34
+ ready,
35
+ error: got.sets?.error ?? got.tally?.error
36
+ };
37
+ };
38
+ /**
39
+ * The sets a component is found in, most populous first.
40
+ *
41
+ * ```ts
42
+ * import { within } from './census.ts'
43
+ * let s = (eid: string, t: string[]) =>
44
+ * ({ entity: { eid }, archetype: { tables: JSON.stringify(t) } })
45
+ * within([s('a', ['doc', 'task']), s('b', ['doc'])], 'task')
46
+ * .map((b) => b.entity.eid) // ['a']
47
+ * ```
48
+ */ export let within = (sets, name, vocab)=>sets.filter((s)=>tables(s, vocab).includes(name));
49
+ /** How many entities are made of the sets `of`. */ export let counted = (c, of)=>of.reduce((n, s)=>n + (c.tally[s.entity.eid] ?? 0), 0);
50
+ //# sourceMappingURL=census.js.map
package/census.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"census.js","sources":["./census.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;CAUC,GAID,SAAS,UAAU,QAAQ,EAAE,MAAM,oBAAmB;AAEtD,yCAAyC,GACzC,OAAO,IAAI,SAAS;EAClB,MAAM;EACN,OAAO;AACT,EAAC;AAgBD,oEAAoE,GACpE,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI,MAAM,GAAG,GAAG,CAAC;IACf,MAAM;MAAE,OAAO,OAAO,IAAI;MAAE,MAAM;IAAK;IACvC,OAAO;MAAE,OAAO,OAAO,KAAK;MAAE,MAAM;IAAK;EAC3C;EACA,IAAI,QAAQ,IAAI,KAAK,EAAE,SAAS,CAAC;EACjC,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC,GAAG,IAC7C,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;EAExD,IAAI,QAAQ,CAAC,CAAC,IAAI,KAAK,EAAE,SAAS,CAAC,CAAC,IAAI,IAAI,EAAE;EAC9C,OAAO;IACL;IACA;IACA,SAAS,SAAS,MAAM,OAAO,GAAG,KAAK;IACvC;IACA,OAAO,IAAI,IAAI,EAAE,SAAS,IAAI,KAAK,EAAE;EACvC;AACF,EAAC;AAED;;;;;;;;;;CAUC,GACD,OAAO,IAAI,SAAS,CAClB,MACA,MACA,QACa,KAAK,MAAM,CAAC,CAAC,IAAM,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAM;AAElE,iDAAiD,GACjD,OAAO,IAAI,UAAU,CAAC,GAAW,KAC/B,GAAG,MAAM,CAAC,CAAC,GAAG,IAAM,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAE"}
package/census.ts ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The census every map of the data is read off: each set of components
3
+ * entities are made of (@yaks/archetype), and how many entities are made of
4
+ * each. From it, how many entities carry each component, which sets a
5
+ * component is found in, and how many edges state each relation: no page asks
6
+ * the graph to count those again. The storage adapters answer this unfiltered
7
+ * tally from maintained archetype populations, not by reading their owners.
8
+ * It is asked once, and shared by the map and every page that reads it.
9
+ *
10
+ * @module
11
+ */
12
+
13
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
14
+ import type { Bundle, Io } from './host.ts'
15
+ import { census as carrying, tables } from './read.js'
16
+
17
+ /** The two lines a census is read from. */
18
+ export let CENSUS = {
19
+ sets: '.archetype&.fields=archetype.tables',
20
+ tally: '.tally=entity.archetype',
21
+ }
22
+
23
+ /** The census, as a page reads it. */
24
+ export type Census = {
25
+ /** every set of components that occurs, most populous first */
26
+ sets: Bundle[]
27
+ /** how many entities are made of each set, by its eid */
28
+ tally: Record<string, number>
29
+ /** how many entities carry each component, by its name */
30
+ carried: Record<string, number>
31
+ /** the counts are in */
32
+ ready: boolean
33
+ /** why the graph could not answer */
34
+ error?: string
35
+ }
36
+
37
+ /** The census: a hook, asked once and kept while the page is open. */
38
+ export let useCensus = (io: Io): Census => {
39
+ let got = io.ask({
40
+ sets: { query: CENSUS.sets, once: true },
41
+ tally: { query: CENSUS.tally, once: true },
42
+ })
43
+ let tally = got.tally?.tally ?? {}
44
+ let sets = (got.sets?.rows ?? []).toSorted((a, b) =>
45
+ (tally[b.entity.eid] ?? 0) - (tally[a.entity.eid] ?? 0)
46
+ )
47
+ let ready = !!got.tally?.ready && !!got.sets?.ready
48
+ return {
49
+ sets,
50
+ tally,
51
+ carried: carrying(sets, tally, io.vocab),
52
+ ready,
53
+ error: got.sets?.error ?? got.tally?.error,
54
+ }
55
+ }
56
+
57
+ /**
58
+ * The sets a component is found in, most populous first.
59
+ *
60
+ * ```ts
61
+ * import { within } from './census.ts'
62
+ * let s = (eid: string, t: string[]) =>
63
+ * ({ entity: { eid }, archetype: { tables: JSON.stringify(t) } })
64
+ * within([s('a', ['doc', 'task']), s('b', ['doc'])], 'task')
65
+ * .map((b) => b.entity.eid) // ['a']
66
+ * ```
67
+ */
68
+ export let within = (
69
+ sets: Bundle[],
70
+ name: string,
71
+ vocab?: Pick<Vocab, 'word'>,
72
+ ): Bundle[] => sets.filter((s) => tables(s, vocab).includes(name))
73
+
74
+ /** How many entities are made of the sets `of`. */
75
+ export let counted = (c: Census, of: Bundle[]): number =>
76
+ of.reduce((n, s) => n + (c.tally[s.entity.eid] ?? 0), 0)
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts","./testing.ts"]},"name":"@yaks/inspect","version":"0.2.36","license":"Apache-2.0","description":"Inspect views: graph entities, vocabulary components, packages, properties, query rows and the map, drawn through the host’s shared renderer registry.","exports":{".":"./mod.ts","./views":"./views.ts","./front":"./front.ts"},"imports":{"@yaks/inspect":"./mod.ts","@yaks/inspect/views":"./views.ts","@yaks/inspect/front":"./front.ts"}}
package/door.js ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The door every inspector view is drawn through. `inspector(registry, host)`
3
+ * binds a registry of views ({@link View}) to what a host supplies, and gives
4
+ * `Door`: `<Door e={bundle} view='Inspect.Page' />` selects the view for the
5
+ * bundle (@yaks/render `resolve`), asks the host for what that view asks,
6
+ * and draws its component with the bundle, the answers and `io`.
7
+ *
8
+ * `io.state` reads the inspector's own entities in the page's own graph, and a
9
+ * render that reads one is woken when that graph changes; `io.set` writes
10
+ * them. `io.ask` is the host's hook, for a component's own asks. Everything
11
+ * else on `io` is the host's, passed through.
12
+ *
13
+ * @module
14
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
15
+ import { useObserved } from "@yaks/ux";
16
+ import { signal } from "@preact/signals-core";
17
+ import { resolve } from "@yaks/render";
18
+ /** Bind a registry of views to a host. */ export let inspector = (registry, host)=>{
19
+ let { useAnswers, front, ...doors } = host;
20
+ // A change to the inspector's graph wakes the doors mounted over it.
21
+ let turn = signal(0);
22
+ for (let comp of front.vocab.comps.filter((c)=>c != 'entity')){
23
+ front.watch(`.${comp}`).subscribe(()=>turn.value++);
24
+ }
25
+ let io = {
26
+ ...doors,
27
+ show: (b, view, ctx)=>/*#__PURE__*/ h(Door, {
28
+ key: `${b.entity.eid} ${view}`,
29
+ e: b,
30
+ view,
31
+ ctx
32
+ }),
33
+ can: (b, view)=>!!resolve(registry, b, view, host.vocab),
34
+ ask: useAnswers,
35
+ state: front.ent,
36
+ set: (bundles)=>void front.mutate(bundles)
37
+ };
38
+ let Door = ({ e, view, ctx = {} })=>{
39
+ useObserved(turn);
40
+ let r = resolve(registry, e, view, host.vocab);
41
+ let got = useAnswers(r?.asks?.(e, io, ctx) ?? {});
42
+ return r ? /*#__PURE__*/ h(r.Render, {
43
+ e,
44
+ got,
45
+ io,
46
+ ctx
47
+ }) : null;
48
+ };
49
+ return {
50
+ Door,
51
+ io
52
+ };
53
+ };
54
+ //# sourceMappingURL=door.js.map
package/door.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"door.js","sources":["./door.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAkD;AACvH,SAAS,WAAW,wBAA6B;AACjD,SAAS,MAAM,+BAAyC;AACxD,SAAuB,OAAO,4BAAiD;AAa/E,wCAAwC,GACxC,OAAO,IAAI,YAAY,CACrB,UACA;EAEA,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,OAAO,GAAG;EACtC,qEAAqE;EACrE,IAAI,OAAO,OAAO;EAClB,KAAK,IAAI,QAAQ,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAM,KAAK,UAAW;IAC/D,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,IAAM,KAAK,KAAK;EACpD;EACA,IAAI,KAAS;IACX,GAAG,KAAK;IACR,MAAM,CAAC,GAAG,MAAM,oBACd,EAAE,MAAM;QAAE,KAAK,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM;QAAE,GAAG;QAAG;QAAM;MAAI;IAC5D,KAAK,CAAC,GAAG,OAAS,CAAC,CAAC,QAAQ,UAAU,GAAG,MAAM,KAAK,KAAK;IACzD,KAAK;IACL,OAAO,MAAM,GAAG;IAChB,KAAK,CAAC,UAAY,KAAK,MAAM,MAAM,CAAC;EACtC;EACA,IAAI,OAAqC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE;IAC7D,YAAY;IACZ,IAAI,IAAI,QAAQ,UAAU,GAAG,MAAM,KAAK,KAAK;IAC7C,IAAI,MAAM,WAAW,GAAG,OAAO,GAAG,IAAI,QAAQ,CAAC;IAC/C,OAAO,kBAAI,EAAE,EAAE,MAAM,EAAE;MAAE;MAAG;MAAK;MAAI;IAAI,KAAK;EAChD;EACA,OAAO;IAAE;IAAM;EAAG;AACpB,EAAC"}
package/door.ts ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The door every inspector view is drawn through. `inspector(registry, host)`
3
+ * binds a registry of views ({@link View}) to what a host supplies, and gives
4
+ * `Door`: `<Door e={bundle} view='Inspect.Page' />` selects the view for the
5
+ * bundle (@yaks/render `resolve`), asks the host for what that view asks,
6
+ * and draws its component with the bundle, the answers and `io`.
7
+ *
8
+ * `io.state` reads the inspector's own entities in the page's own graph, and a
9
+ * render that reads one is woken when that graph changes; `io.set` writes
10
+ * them. `io.ask` is the host's hook, for a component's own asks. Everything
11
+ * else on `io` is the host's, passed through.
12
+ *
13
+ * @module
14
+ */
15
+
16
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type FunctionComponent } from 'react'
17
+ import { useObserved } from '@yaks/ux'
18
+ import { signal } from '@preact/signals-core'
19
+ import { type Context, resolve, type Selection } from '@yaks/render'
20
+ import type { Bundle, Host, Io, View } from './host.ts'
21
+
22
+ /** What `Door` takes: the bundle, the view it is drawn as, and the context
23
+ * the view is drawn with. */
24
+ export type DoorProps = { e: Bundle; view: string; ctx?: Context }
25
+
26
+ /** A host's inspector: the door views are drawn through, and their `io`. */
27
+ export type Inspector = {
28
+ Door: FunctionComponent<DoorProps>
29
+ io: Io
30
+ }
31
+
32
+ /** Bind a registry of views to a host. */
33
+ export let inspector = (
34
+ registry: Selection<View>,
35
+ host: Host,
36
+ ): Inspector => {
37
+ let { useAnswers, front, ...doors } = host
38
+ // A change to the inspector's graph wakes the doors mounted over it.
39
+ let turn = signal(0)
40
+ for (let comp of front.vocab.comps.filter((c) => c != 'entity')) {
41
+ front.watch(`.${comp}`).subscribe(() => turn.value++)
42
+ }
43
+ let io: Io = {
44
+ ...doors,
45
+ show: (b, view, ctx) =>
46
+ h(Door, { key: `${b.entity.eid} ${view}`, e: b, view, ctx }),
47
+ can: (b, view) => !!resolve(registry, b, view, host.vocab),
48
+ ask: useAnswers,
49
+ state: front.ent,
50
+ set: (bundles) => void front.mutate(bundles),
51
+ }
52
+ let Door: FunctionComponent<DoorProps> = ({ e, view, ctx = {} }) => {
53
+ useObserved(turn)
54
+ let r = resolve(registry, e, view, host.vocab)
55
+ let got = useAnswers(r?.asks?.(e, io, ctx) ?? {})
56
+ return r ? h(r.Render, { e, got, io, ctx }) : null
57
+ }
58
+ return { Door, io }
59
+ }
package/front.js ADDED
@@ -0,0 +1,12 @@
1
+ // The inspector's own components, and nothing else: the module a page's own
2
+ // graph loads at `@yaks/inspect/front`. They are the page's, never the graph's
3
+ // it inspects, so this is not a `./vocab` facet a host composes. It reaches no
4
+ // storage and no runtime.
5
+ import doc from './front.json' with {
6
+ type: 'json'
7
+ };
8
+ /** The inspector's vocabulary, in the form `loadVocab` accepts. */ export let inspectDoc = doc;
9
+ /** Every document this package declares. */ export let docs = [
10
+ inspectDoc
11
+ ];
12
+ //# sourceMappingURL=front.js.map
package/front.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"front.js","sources":["./front.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,0BAA0B;AAG1B,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,iEAAiE,GACjE,OAAO,IAAI,aAAuB,IAAe;AAEjD,0CAA0C,GAC1C,OAAO,IAAI,OAAmB;EAAC;CAAW,CAAA"}
package/front.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "$vocabulary": {
3
+ "https://yak.sh/vocab/core": true
4
+ },
5
+ "title": "inspect",
6
+ "description": "The inspector's own state, in a page's own graph: never synced, gone with the page.",
7
+ "$defs": {
8
+ "inspector": {
9
+ "component": true,
10
+ "type": "object",
11
+ "sync": "none",
12
+ "durable": "connection",
13
+ "description": "the inspector's page, on the entity `inspect`: the page being edited, a note open, a delete armed, a refused write and the slice of the schema its map shows; what the index's field holds is the same entity's `filter` (@yaks/filter)",
14
+ "properties": {
15
+ "editing": {
16
+ "type": "string",
17
+ "description": "the eid of the entity whose page shows its controls: a page is read until the reader asks to edit it"
18
+ },
19
+ "note": {
20
+ "type": "string",
21
+ "description": "the heading whose note line is open, `<eid> <heading>`"
22
+ },
23
+ "armed": {
24
+ "type": "string",
25
+ "description": "the eid of the entity whose delete was pressed once; a second press deletes it"
26
+ },
27
+ "said": {
28
+ "type": "string",
29
+ "description": "why the graph refused the last write, until the next one lands"
30
+ },
31
+ "at": {
32
+ "type": "string",
33
+ "description": "where the refused write came from: a note's key, or the eid of the entity it was about"
34
+ },
35
+ "slice": {
36
+ "type": "string",
37
+ "enum": [
38
+ "packages",
39
+ "components",
40
+ "kinds",
41
+ "relations",
42
+ "archetypes"
43
+ ],
44
+ "description": "the slice of the schema the map shows; packages when none is chosen"
45
+ }
46
+ }
47
+ },
48
+ "table": {
49
+ "component": true,
50
+ "type": "object",
51
+ "sync": "none",
52
+ "durable": "connection",
53
+ "description": "one table on an inspector page, how its rows run, which page of them shows and which of its rows are open; its id is `<eid> <heading>`",
54
+ "properties": {
55
+ "order": {
56
+ "type": "string",
57
+ "description": "the property its rows run by, `-` before it when they run down"
58
+ },
59
+ "after": {
60
+ "type": "array",
61
+ "items": { "type": "string" },
62
+ "description": "the last row of each page before the one shown, the way back"
63
+ },
64
+ "open": {
65
+ "type": "array",
66
+ "items": { "type": "string" },
67
+ "description": "the eids of the rows showing the rows they hold, in a table that is a tree"
68
+ },
69
+ "rank": {
70
+ "type": "boolean",
71
+ "description": "its values are ranked though ranking them reads every entity carrying them"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
package/front.ts ADDED
@@ -0,0 +1,13 @@
1
+ // The inspector's own components, and nothing else: the module a page's own
2
+ // graph loads at `@yaks/inspect/front`. They are the page's, never the graph's
3
+ // it inspects, so this is not a `./vocab` facet a host composes. It reaches no
4
+ // storage and no runtime.
5
+
6
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
7
+ import doc from './front.json' with { type: 'json' }
8
+
9
+ /** The inspector's vocabulary, in the form `loadVocab` accepts. */
10
+ export let inspectDoc: VocabDoc = doc as VocabDoc
11
+
12
+ /** Every document this package declares. */
13
+ export let docs: VocabDoc[] = [inspectDoc]