@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/Effect.ts ADDED
@@ -0,0 +1,142 @@
1
+ /**
2
+ * An effect's page (`_effect`, @yaks/vocab): what it does and the package
3
+ * declaring it; what owes it a run, as its declaration says: the components
4
+ * whose appearance, patch or removal on an entity does, the query a batch
5
+ * makes hold, a process starting, and the queries that narrow them; and how a
6
+ * run is tried. Its runs are the `effect` rows naming it (@yaks/effects), a
7
+ * query away.
8
+ *
9
+ * @module
10
+ */
11
+
12
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
13
+ import { parse } from '@yaks/query'
14
+ import { Pairs, Value } from '@yaks/ui'
15
+ import type { Bundle, Io, Props, View } from './host.ts'
16
+ import { usePageNotes } from './Entity.js'
17
+ import { chip, Described, described, propEid } from './schema.js'
18
+ import { Part, useNamed } from './notes.js'
19
+ import { comp, str } from './read.js'
20
+ import { none } from './rows.js'
21
+
22
+ let HEADINGS = ['Owed by']
23
+
24
+ // An effect's name, off its `_effect` bundle.
25
+ let nameOf = (e: Bundle): string => str(e, '_effect', 'name')
26
+
27
+ // A component, or one property of it (`comp.prop`), linked to its page.
28
+ let named = (io: Io, word: string) => {
29
+ let [name, ...prop] = word.split('.')
30
+ return prop.length
31
+ ? h('a', { href: io.link(propEid(io.vocab, name, prop.join('.'))) }, word)
32
+ : chip(io, name)
33
+ }
34
+
35
+ let list = (io: Io, words: string[]) =>
36
+ h('span', {}, words.flatMap((w, i) => [i ? ', ' : null, named(io, w)]))
37
+
38
+ // A query its declaration says, opened as a search where it is one.
39
+ let query = (io: Io, q: string) => {
40
+ try {
41
+ parse(q)
42
+ return h('a', { href: io.find(q) }, h(Value, {}, q))
43
+ } catch {
44
+ return h(Value, {}, q)
45
+ }
46
+ }
47
+
48
+ // What owes it a run: how each trigger its declaration can name is drawn.
49
+ let TRIGGERS: Record<string, (io: Io, v: unknown) => ReactNode> = {
50
+ created: (io, v) => list(io, v as string[]),
51
+ changed: (io, v) => list(io, v as string[]),
52
+ removed: (io, v) => list(io, v as string[]),
53
+ match: (io, v) => query(io, String(v)),
54
+ target: (io, v) => query(io, String(v)),
55
+ eligible: (io, v) => query(io, String(v)),
56
+ active: (io, v) => query(io, String(v)),
57
+ start: () => 'each time a process starts working the effects',
58
+ }
59
+
60
+ // The triggers its declaration names, each beside what it names.
61
+ let owed = (io: Io, e: Bundle): [string, ReactNode][] => {
62
+ let c = comp(e, '_effect')
63
+ return Object.entries(TRIGGERS)
64
+ .filter(([k]) => c[k] != null && c[k] !== false)
65
+ .map(([k, draw]) => [k, draw(io, c[k])])
66
+ }
67
+
68
+ // What an effect's page says, under whichever head tops it.
69
+ let useEffectPage = ({ e, io }: Props) => {
70
+ let name = nameOf(e)
71
+ let notes = usePageNotes(io, e, HEADINGS)
72
+ let c = comp(e, '_effect')
73
+ let pkg = str(e, '_effect', 'namespace')
74
+ useNamed(io, [pkg])
75
+ let triggers = owed(io, e)
76
+ return {
77
+ name,
78
+ notes,
79
+ text: str(e, 'doc', 'body'),
80
+ facts: [
81
+ pkg
82
+ ? ['from ', h('a', { href: io.link(pkg) }, io.name(pkg))]
83
+ : 'no package',
84
+ c.option ? ` · only with the option ${c.option}` : '',
85
+ c.tries ? ` · ${c.tries} tries` : '',
86
+ c.idempotent === false ? ' · not idempotent' : '',
87
+ ],
88
+ parts: [
89
+ h(
90
+ Part,
91
+ {
92
+ io,
93
+ eid: e.entity.eid,
94
+ subject: name,
95
+ heading: 'Owed by',
96
+ note: io.vocab.comp('effect')
97
+ ? h('a', { href: io.find(`.effect.handler=${name}`) }, 'its runs')
98
+ : undefined,
99
+ notes,
100
+ },
101
+ triggers.length
102
+ ? h(
103
+ Pairs,
104
+ {},
105
+ triggers.flatMap(([k, v]) => [
106
+ h(Pairs.Key, {}, k),
107
+ h(Pairs.Value, {}, v),
108
+ ]),
109
+ )
110
+ : none(),
111
+ ),
112
+ ],
113
+ }
114
+ }
115
+
116
+ /** An effect's own page. */
117
+ export let EffectPage = (p: Props): JSX.Element => {
118
+ let { name, notes, text, facts, parts } = useEffectPage(p)
119
+ return h(
120
+ 'div',
121
+ { 'data-inspect': p.e.entity.eid },
122
+ p.io.show(p.e, 'Inspect.Head', {
123
+ sub: described(text, facts),
124
+ notes: notes.get(''),
125
+ subject: name,
126
+ }),
127
+ ...parts,
128
+ )
129
+ }
130
+
131
+ /** An effect's page under another head: what it does, and what owes it a
132
+ * run (the body of its Full page). */
133
+ export let EffectBody = (p: Props): JSX.Element => {
134
+ let { text, facts, parts } = useEffectPage(p)
135
+ return h('div', {}, h(Described, { text, facts }), ...parts)
136
+ }
137
+
138
+ /** An effect's page, and its body under another head. */
139
+ export let effectViews: View[] = [
140
+ { view: 'Inspect.Page', match: parse('._effect'), Render: EffectPage },
141
+ { view: 'Full.Body', match: parse('.doc ._effect'), Render: EffectBody },
142
+ ]
package/Entity.js ADDED
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Any entity's page, read the way a person reads a page: what it is called,
3
+ * and where it came from (./Head.ts); what it says, in full (`Inspect.Body`);
4
+ * what else it states (./Facts.ts); what it is linked to (./Links.ts); and
5
+ * its history (./History.ts).
6
+ *
7
+ * Each part is a view of its own, registered here for anything
8
+ * (`Inspect.Head`, `Inspect.Body`, `Inspect.Facts`, `Inspect.Links`,
9
+ * `Inspect.History`), so a package's own page for its kind draws the parts it
10
+ * has no better way to say through the same registry (`io.show`), and a
11
+ * package can draw one part its own way for its kind: the most specific
12
+ * match wins. What each part is drawn with besides the entity (the notes left
13
+ * under its heading, what the page says elsewhere) is its context.
14
+ *
15
+ * @module
16
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
17
+ import { Markdown } from "@yaks/markdown";
18
+ import * as ui from "@yaks/ui";
19
+ import { factViews } from "./Facts.js";
20
+ import { headViews } from "./Head.js";
21
+ import { History } from "./History.js";
22
+ import { linkViews } from "./Links.js";
23
+ import { about, under, useNamed, useNotes } from "./notes.js";
24
+ import { bodyOf, comps, cut, str } from "./read.js";
25
+ import { edited } from "./state.js";
26
+ /** What an entity says, in full: a doc's body drawn by the host's `Body`, the
27
+ * view every doc's body is drawn by (@yaks/doc's, a document), or a message's
28
+ * words as markdown. Edited, it is typed over in the facts, so it is not said
29
+ * twice. */ export let Body = ({ e, io })=>{
30
+ let text = bodyOf(e);
31
+ return text && !edited(io, e.entity.eid) ? /*#__PURE__*/ h(ui.Section, {
32
+ 'data-body': ''
33
+ }, /*#__PURE__*/ h(ui.Body, {}, str(e, 'doc', 'body') && io.can(e, 'Body') ? io.show(e, 'Body') : /*#__PURE__*/ h(Markdown, {
34
+ source: text
35
+ }))) : null;
36
+ };
37
+ /** How much of a turn that is not the one a page is about reads before it is
38
+ * cut. */ export let TURN = 320;
39
+ /** An entity as one turn of a conversation (`Inspect.Turn`, a @yaks/ui
40
+ * `Turns.Turn`): who wrote it, linked to the turn's own page, and what it
41
+ * says, the one the page is about whole and lit, any other cut short; one
42
+ * that says nothing says its kind. A package whose entities are turns says
43
+ * better who speaks. */ export let Turn = ({ e, io, ctx })=>{
44
+ let { on, whole = on } = ctx;
45
+ let said = bodyOf(e) || str(e, 'doc', 'title');
46
+ let by = str(e, 'created', 'by');
47
+ useNamed(io, [
48
+ by
49
+ ]);
50
+ return /*#__PURE__*/ h(ui.Turns.Turn, {
51
+ mod: on ? 'on' : !said && 'quiet',
52
+ 'data-turn': e.entity.eid
53
+ }, /*#__PURE__*/ h(ui.Turns.Who, {
54
+ href: on ? undefined : io.link(e.entity.eid)
55
+ }, by ? io.name(by) : io.kind(e)), /*#__PURE__*/ h(ui.Turns.Text, {}, said ? /*#__PURE__*/ h(Markdown, {
56
+ source: whole ? said : cut(said, TURN)
57
+ }) : io.kind(e)));
58
+ };
59
+ /** Its history, as a part of a page. */ let Told = ({ e, io, ctx })=>io.vocab.comp('_change') ? /*#__PURE__*/ h(History, {
60
+ e,
61
+ io,
62
+ notes: ctx.notes ?? new Map()
63
+ }) : null;
64
+ /** The headings a page holds, for its notes: the components it carries, and
65
+ * the parts it draws. */ export let headings = (e, more = [])=>[
66
+ ...comps(e).map(([n])=>n),
67
+ 'Links',
68
+ 'History',
69
+ ...more
70
+ ];
71
+ /** The notes left on an entity, by the heading each was left under: a hook,
72
+ * for a page. */ export let usePageNotes = (io, e, more = [])=>under(useNotes(io, e.entity.eid), about(io, e), headings(e, more));
73
+ /** Any entity's page. */ export let EntityPage = ({ e, io })=>{
74
+ let notes = usePageNotes(io, e);
75
+ return /*#__PURE__*/ h('div', {
76
+ 'data-inspect': e.entity.eid
77
+ }, io.show(e, 'Inspect.Head', {
78
+ notes: notes.get('')
79
+ }), io.show(e, 'Inspect.Body'), io.show(e, 'Inspect.Facts', {
80
+ notes
81
+ }), io.show(e, 'Inspect.Links', {
82
+ notes
83
+ }), io.show(e, 'Inspect.History', {
84
+ notes
85
+ }));
86
+ };
87
+ /** Any entity's page, and every part of it. */ export let entityViews = [
88
+ ...headViews,
89
+ {
90
+ view: 'Inspect.Body',
91
+ match: true,
92
+ Render: Body
93
+ },
94
+ ...factViews,
95
+ ...linkViews,
96
+ {
97
+ view: 'Inspect.History',
98
+ match: true,
99
+ Render: Told
100
+ },
101
+ {
102
+ view: 'Inspect.Turn',
103
+ match: true,
104
+ Render: Turn
105
+ },
106
+ {
107
+ view: 'Inspect.Page',
108
+ match: true,
109
+ Render: EntityPage
110
+ }
111
+ ];
112
+ //# sourceMappingURL=Entity.js.map
package/Entity.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.js","sources":["./Entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoC;AACzG,SAAS,QAAQ,8BAAmC;AACpD,YAAY,wBAA6B;AAEzC,SAAS,SAAS,qBAAoB;AACtC,SAAS,SAAS,oBAAmB;AACrC,SAAS,OAAO,uBAAsB;AACtC,SAAS,SAAS,qBAAoB;AACtC,SAAS,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,qBAAoB;AAC7D,SAAS,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,oBAAmB;AACnD,SAAS,MAAM,qBAAoB;AAKnC;;;UAGU,GACV,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,EAAS;EACjC,IAAI,OAAO,OAAO;EAClB,OAAO,QAAQ,CAAC,OAAO,IAAI,EAAE,MAAM,CAAC,GAAG,kBACnC,EACA,GAAG,OAAO,EACV;IAAE,aAAa;EAAG,iBAClB,EACE,GAAG,IAAI,EACP,CAAC,GACD,IAAI,GAAG,OAAO,WAAW,GAAG,GAAG,CAAC,GAAG,UAC/B,GAAG,IAAI,CAAC,GAAG,wBACX,EAAE,UAAU;IAAE,QAAQ;EAAK,OAGjC;AACN,EAAC;AAED;QACQ,GACR,OAAO,IAAI,OAAO,IAAG;AAMrB;;;;sBAIsB,GACtB,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAS;EACtC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG;EACzB,IAAI,OAAO,OAAO,MAAM,IAAI,GAAG,OAAO;EACtC,IAAI,K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,OAAO,MAAM,GAAG,CAAC;EAAI,IAClD,GAAG,IAAI,CAAC,GAAG,iBACX,GAAG,IAAI,CAAC,GAAG,iBAAiB;IAAE;EAAM,IACpC,GAAG,IAAI,CAAC,GAAG,iBAAiB;IAAE;EAAM,IACpC,GAAG,IAAI,CAAC,GAAG,mBAAmB;IAAE;EAAM;AAE1C,EAAC;AAED,6CAA6C,GAC7C,OAAO,IAAI,cAAsB;KAC5B;EACH;IAAE,MAAM;IAAgB,OAAO;IAAM,QAAQ;EAAK;KAC/C;KACA;EACH;IAAE,MAAM;IAAmB,OAAO;IAAM,QAAQ;EAAK;EACrD;IAAE,MAAM;IAAgB,OAAO;IAAM,QAAQ;EAAK;EAClD;IAAE,MAAM;IAAgB,OAAO;IAAM,QAAQ;EAAW;CACzD,CAAA"}
package/Entity.ts ADDED
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Any entity's page, read the way a person reads a page: what it is called,
3
+ * and where it came from (./Head.ts); what it says, in full (`Inspect.Body`);
4
+ * what else it states (./Facts.ts); what it is linked to (./Links.ts); and
5
+ * its history (./History.ts).
6
+ *
7
+ * Each part is a view of its own, registered here for anything
8
+ * (`Inspect.Head`, `Inspect.Body`, `Inspect.Facts`, `Inspect.Links`,
9
+ * `Inspect.History`), so a package's own page for its kind draws the parts it
10
+ * has no better way to say through the same registry (`io.show`), and a
11
+ * package can draw one part its own way for its kind: the most specific
12
+ * match wins. What each part is drawn with besides the entity (the notes left
13
+ * under its heading, what the page says elsewhere) is its context.
14
+ *
15
+ * @module
16
+ */
17
+
18
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX } from 'react'
19
+ import { Markdown } from '@yaks/markdown'
20
+ import * as ui from '@yaks/ui'
21
+ import type { Bundle, Io, Props, View } from './host.ts'
22
+ import { factViews } from './Facts.js'
23
+ import { headViews } from './Head.js'
24
+ import { History } from './History.js'
25
+ import { linkViews } from './Links.js'
26
+ import { about, under, useNamed, useNotes } from './notes.js'
27
+ import { bodyOf, comps, cut, str } from './read.js'
28
+ import { edited } from './state.js'
29
+
30
+ /** What a page's parts are drawn with: the notes under each heading. */
31
+ export type PageCtx = { notes?: Map<string, Bundle[]> }
32
+
33
+ /** What an entity says, in full: a doc's body drawn by the host's `Body`, the
34
+ * view every doc's body is drawn by (@yaks/doc's, a document), or a message's
35
+ * words as markdown. Edited, it is typed over in the facts, so it is not said
36
+ * twice. */
37
+ export let Body = ({ e, io }: Props): JSX.Element | null => {
38
+ let text = bodyOf(e)
39
+ return text && !edited(io, e.entity.eid)
40
+ ? h(
41
+ ui.Section,
42
+ { 'data-body': '' },
43
+ h(
44
+ ui.Body,
45
+ {},
46
+ str(e, 'doc', 'body') && io.can(e, 'Body')
47
+ ? io.show(e, 'Body')
48
+ : h(Markdown, { source: text }),
49
+ ),
50
+ )
51
+ : null
52
+ }
53
+
54
+ /** How much of a turn that is not the one a page is about reads before it is
55
+ * cut. */
56
+ export let TURN = 320
57
+
58
+ /** What a turn is drawn with: whether it is the one the page is about, and
59
+ * whether it is said whole (by default, the one it is about). */
60
+ export type TurnCtx = { on?: boolean; whole?: boolean }
61
+
62
+ /** An entity as one turn of a conversation (`Inspect.Turn`, a @yaks/ui
63
+ * `Turns.Turn`): who wrote it, linked to the turn's own page, and what it
64
+ * says, the one the page is about whole and lit, any other cut short; one
65
+ * that says nothing says its kind. A package whose entities are turns says
66
+ * better who speaks. */
67
+ export let Turn = ({ e, io, ctx }: Props): JSX.Element => {
68
+ let { on, whole = on } = ctx as TurnCtx
69
+ let said = bodyOf(e) || str(e, 'doc', 'title')
70
+ let by = str(e, 'created', 'by')
71
+ useNamed(io, [by])
72
+ return h(
73
+ ui.Turns.Turn,
74
+ { mod: on ? 'on' : !said && 'quiet', 'data-turn': e.entity.eid },
75
+ h(
76
+ ui.Turns.Who,
77
+ { href: on ? undefined : io.link(e.entity.eid) },
78
+ by ? io.name(by) : io.kind(e),
79
+ ),
80
+ h(
81
+ ui.Turns.Text,
82
+ {},
83
+ said
84
+ ? h(Markdown, { source: whole ? said : cut(said, TURN) })
85
+ : io.kind(e),
86
+ ),
87
+ )
88
+ }
89
+
90
+ /** Its history, as a part of a page. */
91
+ let Told = ({ e, io, ctx }: Props): JSX.Element | null =>
92
+ io.vocab.comp('_change')
93
+ ? h(History, { e, io, notes: (ctx as PageCtx).notes ?? new Map() })
94
+ : null
95
+
96
+ /** The headings a page holds, for its notes: the components it carries, and
97
+ * the parts it draws. */
98
+ export let headings = (e: Bundle, more: string[] = []): string[] => [
99
+ ...comps(e).map(([n]) => n),
100
+ 'Links',
101
+ 'History',
102
+ ...more,
103
+ ]
104
+
105
+ /** The notes left on an entity, by the heading each was left under: a hook,
106
+ * for a page. */
107
+ export let usePageNotes = (
108
+ io: Io,
109
+ e: Bundle,
110
+ more: string[] = [],
111
+ ): Map<string, Bundle[]> =>
112
+ under(useNotes(io, e.entity.eid), about(io, e), headings(e, more))
113
+
114
+ /** Any entity's page. */
115
+ export let EntityPage = ({ e, io }: Props): JSX.Element => {
116
+ let notes = usePageNotes(io, e)
117
+ return h(
118
+ 'div',
119
+ { 'data-inspect': e.entity.eid },
120
+ io.show(e, 'Inspect.Head', { notes: notes.get('') }),
121
+ io.show(e, 'Inspect.Body'),
122
+ io.show(e, 'Inspect.Facts', { notes }),
123
+ io.show(e, 'Inspect.Links', { notes }),
124
+ io.show(e, 'Inspect.History', { notes }),
125
+ )
126
+ }
127
+
128
+ /** Any entity's page, and every part of it. */
129
+ export let entityViews: View[] = [
130
+ ...headViews,
131
+ { view: 'Inspect.Body', match: true, Render: Body },
132
+ ...factViews,
133
+ ...linkViews,
134
+ { view: 'Inspect.History', match: true, Render: Told },
135
+ { view: 'Inspect.Turn', match: true, Render: Turn },
136
+ { view: 'Inspect.Page', match: true, Render: EntityPage },
137
+ ]
package/Facts.js ADDED
@@ -0,0 +1,143 @@
1
+ /**
2
+ * What an entity states (`Inspect.Facts`): each component it carries that the
3
+ * head and the body do not already say, in the order they mean (./read.ts
4
+ * `facts`): the kinds it is, what else it carries, then what happened to it.
5
+ *
6
+ * Read, each component is a line: its name, linked to its page and telling
7
+ * what it is where the pointer rests, then the values it holds, each as a
8
+ * person reads it; one that holds nothing says what it means instead. Edited,
9
+ * each is a table of every property it stores or declares, each value typed
10
+ * over where it stands, and removed by its ×; the title and the body are
11
+ * among them, since editing is where they change.
12
+ *
13
+ * @module
14
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, Fragment } from "react";
15
+ import { Button, Pairs, Rows, Section, Value } from "@yaks/ui";
16
+ import { Cell, reads } from "./value.js";
17
+ import { Grid } from "./grid.js";
18
+ import { chip } from "./schema.js";
19
+ import { about, Part, Said, useNamed } from "./notes.js";
20
+ import { comp, comps, facts, line, named, writable } from "./read.js";
21
+ import { edited, key, write } from "./state.js";
22
+ /** One component of an entity, edited: a row per property it stores or
23
+ * declares, so a component just added shows what it can be given. */ export let CompTable = ({ e, io, name, notes })=>{
24
+ let eid = e.entity.eid;
25
+ let row = comp(e, name);
26
+ let props = [
27
+ ...new Set([
28
+ ...Object.keys(row),
29
+ ...io.vocab.props(name)
30
+ ])
31
+ ];
32
+ let refs = props.filter((p)=>io.vocab.prop(name, p)?.category == 'ref');
33
+ useNamed(io, refs.map((p)=>row[p]));
34
+ let remove = writable(io, name) ? /*#__PURE__*/ h(Button, {
35
+ type: 'button',
36
+ mod: [
37
+ 'quiet',
38
+ 'danger'
39
+ ],
40
+ 'aria-label': `remove ${name}`,
41
+ title: `remove ${name}`,
42
+ onClick: ()=>write(io, eid, [
43
+ {
44
+ entity: {
45
+ eid
46
+ },
47
+ [name]: null
48
+ }
49
+ ])
50
+ }, '×') : null;
51
+ return /*#__PURE__*/ h(Part, {
52
+ io,
53
+ eid,
54
+ subject: about(io, e),
55
+ heading: name,
56
+ title: chip(io, name),
57
+ act: remove,
58
+ sub: io.vocab.comp(name)?.description,
59
+ notes
60
+ }, props.length ? /*#__PURE__*/ h(Grid, {
61
+ io,
62
+ id: key(eid, name),
63
+ pick: false,
64
+ local: true,
65
+ rows: props.map((prop)=>({
66
+ entity: {
67
+ eid: prop
68
+ }
69
+ })),
70
+ columns: [
71
+ {
72
+ name: 'property',
73
+ mod: 'key',
74
+ cell: (p)=>p.entity.eid
75
+ },
76
+ {
77
+ name: 'value',
78
+ cell: (p)=>/*#__PURE__*/ h(Cell, {
79
+ io,
80
+ e,
81
+ name,
82
+ prop: p.entity.eid
83
+ })
84
+ }
85
+ ]
86
+ }) : /*#__PURE__*/ h(Rows.More, {}, 'no properties: it is there, or not'));
87
+ };
88
+ // One component, read: the values it holds, or what it means; and the notes
89
+ // left under it.
90
+ let stated = (io, e, name, notes)=>{
91
+ let held = Object.entries(comp(e, name)).filter(([, v])=>v != null && v !== '');
92
+ let what = io.vocab.comp(name)?.description;
93
+ let eid = e.entity.eid;
94
+ return [
95
+ /*#__PURE__*/ h(Pairs.Key, {
96
+ key: `${name} k`,
97
+ 'data-tip': what
98
+ }, chip(io, name)),
99
+ /*#__PURE__*/ h(Pairs.Value, {
100
+ key: `${name} v`
101
+ }, held.length ? held.flatMap(([p, v], i)=>[
102
+ i ? ' · ' : null,
103
+ /*#__PURE__*/ h(Value, {
104
+ key: p,
105
+ mod: 'id'
106
+ }, p),
107
+ ' ',
108
+ reads(io, v, io.vocab.prop(name, p))
109
+ ]) : /*#__PURE__*/ h(Value, {
110
+ mod: 'nil'
111
+ }, line(what ?? 'there', 120)), /*#__PURE__*/ h(Said, {
112
+ io,
113
+ eid,
114
+ subject: about(io, e),
115
+ heading: name,
116
+ notes: notes?.get(name)
117
+ }))
118
+ ];
119
+ };
120
+ /** What an entity states. */ export let Facts = ({ e, io, ctx })=>{
121
+ let { skip = [], notes } = ctx;
122
+ let editing = edited(io, e.entity.eid);
123
+ let names = editing ? comps(e).map(([n])=>n).filter((n)=>!skip.includes(n)) : facts(io.vocab, e, skip);
124
+ useNamed(io, names.flatMap((n)=>Object.values(comp(e, n)).filter(named)));
125
+ if (!names.length) return null;
126
+ return editing ? /*#__PURE__*/ h(Fragment, {}, names.map((name)=>/*#__PURE__*/ h(CompTable, {
127
+ key: name,
128
+ e,
129
+ io,
130
+ name,
131
+ notes
132
+ }))) : /*#__PURE__*/ h(Section, {
133
+ 'data-facts': ''
134
+ }, /*#__PURE__*/ h(Pairs, {}, names.flatMap((n)=>stated(io, e, n, notes))));
135
+ };
136
+ /** The facts of any entity. */ export let factViews = [
137
+ {
138
+ view: 'Inspect.Facts',
139
+ match: true,
140
+ Render: Facts
141
+ }
142
+ ];
143
+ //# sourceMappingURL=Facts.js.map
package/Facts.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Facts.js","sources":["./Facts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,EAAE,QAAQ,gBAAoC;AACnH,SAAS,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,wBAA6B;AAEzE,SAAS,IAAI,EAAE,KAAK,qBAAoB;AACxC,SAAS,IAAI,oBAAmB;AAChC,SAAS,IAAI,sBAAqB;AAClC,SAAS,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,qBAAoB;AACxD,SAAS,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,oBAAmB;AACrE,SAAS,MAAM,EAAE,GAAG,EAAE,KAAK,qBAAoB;AAM/C;mEACmE,GACnE,OAAO,IAAI,YAAY,CACrB,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAKnB;EAED,IAAI,MAAM,EAAE,MAAM,CAAC,GAAG;EACtB,IAAI,MAAM,KAAK,GAAG;EAClB,IAAI,QAAQ;OAAI,IAAI,IAAI;SAAI,OAAO,IAAI,CAAC;SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;KAAM;GAAE;EACxE,IAAI,OAAO,MAAM,MAAM,CAAC,CAAC,IAAM,GAAG,KAAK,CAAC,IAAI,CA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