@yaks/topic 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 (62) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +256 -2
  3. package/_dist/context.d.ts +74 -0
  4. package/_dist/context.d.ts.map +1 -0
  5. package/_dist/graph.d.ts +5 -0
  6. package/_dist/graph.d.ts.map +1 -0
  7. package/_dist/mod.d.ts +33 -0
  8. package/_dist/mod.d.ts.map +1 -0
  9. package/_dist/share.d.ts +61 -0
  10. package/_dist/share.d.ts.map +1 -0
  11. package/_dist/shelves.d.ts +24 -0
  12. package/_dist/shelves.d.ts.map +1 -0
  13. package/_dist/tools.d.ts +5 -0
  14. package/_dist/tools.d.ts.map +1 -0
  15. package/_dist/topic.d.ts +50 -0
  16. package/_dist/topic.d.ts.map +1 -0
  17. package/_dist/views.d.ts +23 -0
  18. package/_dist/views.d.ts.map +1 -0
  19. package/_dist/vocab.d.ts +6 -0
  20. package/_dist/vocab.d.ts.map +1 -0
  21. package/catalogue.js +155 -0
  22. package/catalogue.js.map +1 -0
  23. package/catalogue.ts +218 -0
  24. package/context.js +289 -0
  25. package/context.js.map +1 -0
  26. package/context.ts +318 -0
  27. package/deno.json +1 -0
  28. package/graph.js +32 -0
  29. package/graph.js.map +1 -0
  30. package/graph.ts +26 -0
  31. package/inspect.js +48 -0
  32. package/inspect.js.map +1 -0
  33. package/inspect.ts +25 -0
  34. package/mod.js +33 -0
  35. package/mod.js.map +1 -0
  36. package/mod.ts +56 -0
  37. package/package.json +50 -4
  38. package/page.js +247 -0
  39. package/page.js.map +1 -0
  40. package/page.ts +297 -0
  41. package/share.js +104 -0
  42. package/share.js.map +1 -0
  43. package/share.ts +115 -0
  44. package/shelves.js +99 -0
  45. package/shelves.js.map +1 -0
  46. package/shelves.ts +93 -0
  47. package/tools.js +114 -0
  48. package/tools.js.map +1 -0
  49. package/tools.ts +122 -0
  50. package/topic.js +97 -0
  51. package/topic.js.map +1 -0
  52. package/topic.ts +128 -0
  53. package/tree.js +77 -0
  54. package/tree.js.map +1 -0
  55. package/tree.ts +93 -0
  56. package/views.js +30 -0
  57. package/views.js.map +1 -0
  58. package/views.ts +26 -0
  59. package/vocab.js +16 -0
  60. package/vocab.js.map +1 -0
  61. package/vocab.json +186 -0
  62. package/vocab.ts +17 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The shelves: every topic laid out as a catalogue's tree. A shelf is a topic
3
+ * and the shelves under it, the topics it holds (`contains`); the top shelves
4
+ * are the topics no topic holds. Each level runs by title. A topic held by two
5
+ * stands under both, and one met again on its own path stands there without
6
+ * what it holds, so a cycle ends; topics held only by each other are still
7
+ * shelved, at the top. Pure: the topics and their `contains` edges in, the
8
+ * tree out, so the views draw it and a test reads it without a graph.
9
+ *
10
+ * @module
11
+ */ import type { Bundle } from "@yaks/graph";
12
+ /** A topic, and the shelves of the topics it holds. */ export type Shelf = {
13
+ topic: Bundle;
14
+ under: Shelf[];
15
+ };
16
+ /**
17
+ * The topics as shelves, from the topics and the `contains` edges among them;
18
+ * an edge to or from anything else is left out.
19
+ */ export declare let shelves: (topics: Bundle[], edges: Bundle[]) => Shelf[];
20
+ /**
21
+ * The shelves narrowed to what was said: each topic whose words fit it
22
+ * (`fits`), under the topics that hold it. Nothing said narrows nothing.
23
+ */ export declare let within: (all: Shelf[], said: string) => Shelf[];
24
+ //# sourceMappingURL=shelves.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shelves.d.ts","sources":["../shelves.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,cAAc,MAAM,2BAAgC;AAGpD,qDAAqD,GACrD,YAAY;EAAU,OAAO;EAAQ,OAAO;;AAY5C;;;CAGC,GAOD,OAAO,YAAI,UAAW,QAAQ,UAAU,OAAO,aAAW,QA6BzD;AAED;;;CAGC,GAKD,OAAO,YAAI,SAAU,KAAK,SAAS,MAAM,MAAM,KAAG,QAI9C"}
@@ -0,0 +1,5 @@
1
+ import type { Runs } from "@yaks/graph/tools";
2
+ /** The implementations of `topic_new`, `topic_find`, `topic_add` and
3
+ * `topic_read`. A factory, like every such module, although these need
4
+ * nothing from the server. */ export declare let runs: () => Runs;
5
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAYA,cAAc,IAAI,iCAAsC;AA0BxD;;4BAE4B,GAC5B,OAAO,YAAI,YAAW,KAgFpB"}
@@ -0,0 +1,50 @@
1
+ import type { Bundle } from "@yaks/graph";
2
+ import { type Built } from "@yaks/query";
3
+ /** The component this package is about. */ export declare let TOPIC: string;
4
+ /** The relation from a topic to what it holds (@yaks/task's word). */ export declare let HOLDS: string;
5
+ /** The oracle: the one persona a session opened on a topic wears where whoever
6
+ * opened it named none. Its eid is derived from a fixed sentence, as
7
+ * @yaks/harness's own row is, so every graph names it alike and no door looks
8
+ * it up; what it says is a row like any persona's. */ export declare let ORACLE: string;
9
+ /** How many topics a find returns when the caller gave no limit. */ export declare let FIND: number;
10
+ /** How many topics a reading of every one reads at most: they are few and
11
+ * broad, so a find reads them all and matches the words here. */ export declare let TOPICS: number;
12
+ /**
13
+ * A topic's name: its title in lowercase, the spaces single.
14
+ *
15
+ * ```ts
16
+ * named(' UI Components ') // 'ui components'
17
+ * ```
18
+ */ export declare let named: (title: string) => string;
19
+ /**
20
+ * Whether two names name one subject by their words: every word of one starts
21
+ * a word of the other, or is started by one.
22
+ *
23
+ * ```ts
24
+ * overlaps('economic market design', 'market design') // true
25
+ * overlaps('tests', 'testing and ci') // false
26
+ * overlaps('test', 'testing and ci') // true
27
+ * overlaps('ui design', 'cover design') // false
28
+ * ```
29
+ */ export declare let overlaps: (a: string, b: string) => boolean;
30
+ /**
31
+ * Whether what was said finds a topic's words: each word said starts one of
32
+ * them, as it is typed ("dat" finds "data"), or shares its stem ("data
33
+ * modeling" finds "data model", "tests" finds "testing"). Nothing said finds
34
+ * every topic.
35
+ */ export declare let fits: (said: string, text: string) => boolean;
36
+ /** The words a topic is found by: its name, its title and its cover. */ export declare let about: (t: Bundle) => string;
37
+ /**
38
+ * The query string that reads every topic with its name and cover, ranked by
39
+ * meaning to `near`, or else in order of name. A find keeps those whose words
40
+ * fit what was said (`fits`).
41
+ *
42
+ * ```ts
43
+ * found({}) // '.topic&?doc&.order=topic.name&.limit=100000'
44
+ * found({ near: 'T-9' })
45
+ * // '.near=T-9&.topic&?doc&.order=similar&.limit=100000'
46
+ * ```
47
+ */ export declare let found: (o: {
48
+ near?: string;
49
+ }) => Built;
50
+ //# sourceMappingURL=topic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic.d.ts","sources":["../topic.ts"],"names":[],"mappings":"AAiBA,cAAc,MAAM,2BAAgC;AACpD,SAAS,KAAK,KAAK,2BAAsC;AAKzD,yCAAyC,GACzC,OAAO,YAAI,cAAe;AAE1B,oEAAoE,GACpE,OAAO,YAAI,cAAkB;AAE7B;;;oDAGoD,GACpD,OAAO,YAAI,QAAQ,MAAM,CAAmC;AAE5D,kEAAkE,GAClE,OAAO,YAAI,aAAS;AAEpB;+DAC+D,GAC/D,OAAO,YAAI,eAAe;AAE1B;;;;;;CAMC,GACD,OAAO,YAAI,QAAS,OAAO,MAAM,KAAG,MAAM,CACO;AAmBjD;;;;;;;;;;CAUC,GACD,OAAO,YAAI,WAAY,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAAO,CAIpD;AAED;;;;;CAKC,GAMD,OAAO,YAAI,OAAQ,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,OAAO,CAOtD;AAED,sEAAsE,GAGtE,OAAO,YAAI,QAAS,GAAG,WAAS,MAAM,CAER;AAE9B;;;;;;;;;;CAUC,GACD,OAAO,YAAI,QAAS;EAAK,OAAO,MAAM;MAAK,MAGqB"}
@@ -0,0 +1,23 @@
1
+ import type { View } from "@yaks/inspect";
2
+ // @ts-types="@yaks/ui/lucide"
3
+ import Library from "lucide/dist/esm/icons/library-big.mjs";
4
+ /** The shelves, the page, the tree and a topic's tile, as the inspector
5
+ * draws them. */ export declare let inspectViews: () => Promise<View[]>;
6
+ /** The tabs a topic wears, its page first, so it opens on its page. */ export declare let tabs: readonly [{
7
+ readonly view: string;
8
+ readonly icon: string;
9
+ }, {
10
+ readonly view: string;
11
+ readonly icon: string;
12
+ }];
13
+ /** The page the sidebar offers: every topic on its shelf, and the field that
14
+ * finds one. */ export declare let destinations: readonly [{
15
+ readonly key: string;
16
+ readonly name: string;
17
+ readonly icon: string;
18
+ readonly view: string;
19
+ }];
20
+ /** The glyph it wears there. */ export declare let icons: {
21
+ readonly 'library-big': any;
22
+ };
23
+ //# sourceMappingURL=views.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAGA,cAAc,IAAI,6BAAkC;AACpD,8BAA8B;AAC9B,OAAO,qDAA+D;AAEtE;eACe,GACf,OAAO,YAAI,oBAAmB,QAAQ,QACc;AAEpD,qEAAqE,GACrE,OAAO,YAAI;aACP;aAAe;;aACf;aAAc;KACjB;AAED;cACc,GACd,OAAO,YAAI;aACP;aAAe;aAAgB;aAAqB;KACvD;AAED,8BAA8B,GAC9B,OAAO,YAAI;WAAU;EAAwB"}
@@ -0,0 +1,6 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** The topic vocabulary, in the form `loadVocab` accepts. */ export declare let topicDoc: VocabDoc;
3
+ /** What this package is: its manifest's description, the one place it is
4
+ * written, which a host stamps on each document here. */ export declare let description: string;
5
+ /** Every document this plugin declares. */ export declare let docs: VocabDoc[];
6
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AAItD,2DAA2D,GAC3D,OAAO,YAAI,UAAU,SAA0B;AAE/C;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAuB"}
package/catalogue.js ADDED
@@ -0,0 +1,155 @@
1
+ /**
2
+ * The catalogue: the shelves of topics (./shelves.ts) to find and walk them,
3
+ * and a topic opened beside them. `Topics.Page`, the page the sidebar offers
4
+ * as Topics, is the shelves alone, each topic with its cover. `Topic`, the tab
5
+ * a topic opens on, sets its page (./page.ts) beside the shelves, titles only,
6
+ * the topic open lit and the shelves holding it open; stacked, as on a phone,
7
+ * the page comes first.
8
+ *
9
+ * Over the shelves a field finds a topic by what is typed (`fits`: "data
10
+ * modeling" finds data model), narrowing them to the topics it fits, under the
11
+ * topics holding them; Enter opens the first and clears it, Escape clears it.
12
+ * What is typed there is the person's draft (the UX host's `drafts`,
13
+ * @yaks/ux), so it stays as they go from topic to topic among what it found,
14
+ * and in every interface they use.
15
+ *
16
+ * @module
17
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, useLayoutEffect, useRef } from "react";
18
+ import * as ui from "@yaks/ui";
19
+ import { useHost } from "@yaks/ux";
20
+ import { every, holds, shelves, within } from "./shelves.js";
21
+ import { about, cover, fits, title, TOPIC, TOPICS } from "./topic.js";
22
+ import { TopicPage } from "./page.js";
23
+ /** Where what is typed to find a topic is kept, as the person's draft. */ export let FINDING = 'topics:find';
24
+ let rows = (a)=>a?.rows ?? [];
25
+ /** What the shelves ask: every live topic with its cover, and every
26
+ * `contains` edge from one topic to another. */ let asking = (io)=>({
27
+ topics: `.${TOPIC}&?doc` + `${io.vocab.comp('archived') ? '&!archived' : ''}&.limit=${TOPICS}`,
28
+ ...io.vocab.comp('contains') ? {
29
+ edges: `.contains&.edge.from.${TOPIC}.name&.edge.to.${TOPIC}.name` + `&?edge&.limit=${TOPICS}`
30
+ } : {}
31
+ });
32
+ /** Every topic, shelved and narrowed to what was typed to find one: a hook. */ let useShelves = (io)=>{
33
+ let got = io.ask(asking(io));
34
+ let said = useHost().drafts.text(FINDING);
35
+ let all = shelves(rows(got.topics), rows(got.edges));
36
+ let shown = within(all, said);
37
+ let hits = said ? every(shown).filter((t)=>fits(said, about(t))) : [];
38
+ return {
39
+ got: got.topics,
40
+ said,
41
+ all,
42
+ shown,
43
+ hits
44
+ };
45
+ };
46
+ /** The field a topic is found from. */ let Find = ({ io, said, hits })=>{
47
+ let { drafts } = useHost();
48
+ let box = useRef(null);
49
+ useLayoutEffect(()=>{
50
+ let el = box.current;
51
+ if (el && el.value != said) el.value = said;
52
+ }, [
53
+ said
54
+ ]);
55
+ return /*#__PURE__*/ h(ui.Field, {
56
+ elRef: box,
57
+ type: 'search',
58
+ name: 'find',
59
+ 'aria-label': 'find a topic',
60
+ placeholder: 'find a topic…',
61
+ onInput: (ev)=>drafts.type(FINDING, ev.currentTarget.value),
62
+ onKeyDown: (ev)=>{
63
+ if (ev.key == 'Enter' && hits[0]) {
64
+ ev.preventDefault();
65
+ drafts.spend(FINDING);
66
+ io.go(io.link(hits[0].entity.eid));
67
+ } else if (ev.key == 'Escape' && said) {
68
+ ev.preventDefault();
69
+ drafts.spend(FINDING);
70
+ }
71
+ }
72
+ });
73
+ };
74
+ /** A topic on its shelf, and the shelves under it where they are open: under
75
+ * the topic open, on the way to it, wherever something was typed, and
76
+ * everywhere the covers show. A closed one counts what it holds. */ let Twig = ({ io, shelf, said, lit, covers })=>{
77
+ let t = shelf.topic;
78
+ let eid = t.entity.eid;
79
+ let under = shelf.under.length;
80
+ let open = !!(covers || said || eid == lit || lit && holds(shelf, lit));
81
+ let words = covers ? cover(t) : '';
82
+ return /*#__PURE__*/ h(ui.Rows.Item, {
83
+ role: 'listitem',
84
+ 'data-shelf': eid
85
+ }, /*#__PURE__*/ h(ui.Tile, {
86
+ href: io.link(eid),
87
+ mod: eid == lit ? 'on' : undefined,
88
+ 'aria-current': eid == lit ? 'page' : undefined
89
+ }, /*#__PURE__*/ h(ui.Tile.Title, {
90
+ mod: covers ? 'wrap' : undefined
91
+ }, title(t)), under && !open ? /*#__PURE__*/ h(ui.Tile.Count, {}, String(under)) : null, words ? /*#__PURE__*/ h(ui.Tile.Sub, {
92
+ mod: 'wrap'
93
+ }, words) : null), under && open ? /*#__PURE__*/ h(ui.Rows, {
94
+ mod: 'nested',
95
+ role: 'list'
96
+ }, shelf.under.map((s)=>/*#__PURE__*/ h(Twig, {
97
+ key: s.topic.entity.eid,
98
+ io,
99
+ shelf: s,
100
+ said,
101
+ lit,
102
+ covers
103
+ }))) : null);
104
+ };
105
+ /** The shelves, or why there are none to show. */ let List = ({ io, got, said, shown, lit, covers })=>got?.error ? /*#__PURE__*/ h(ui.Rows.More, {}, got.error) : !got?.ready && !shown.length ? /*#__PURE__*/ h(ui.Loading, {}) : !shown.length ? /*#__PURE__*/ h(ui.Rows.More, {}, said ? `no topic fits “${said}”` : 'there are no topics yet') : /*#__PURE__*/ h(ui.Rows, {
106
+ role: 'list',
107
+ mod: covers ? 'ruled' : undefined,
108
+ 'data-shelves': ''
109
+ }, shown.map((s)=>/*#__PURE__*/ h(Twig, {
110
+ key: s.topic.entity.eid,
111
+ io,
112
+ shelf: s,
113
+ said,
114
+ lit,
115
+ covers
116
+ })));
117
+ /** The page the sidebar offers as Topics: every topic with its cover, under
118
+ * the topics holding it, and the field that finds one. */ export let TopicsPage = ({ io })=>{
119
+ let s = useShelves(io);
120
+ let n = rows(s.got).length;
121
+ return /*#__PURE__*/ h('article', {
122
+ 'data-topics': ''
123
+ }, /*#__PURE__*/ h(ui.Head, {}, /*#__PURE__*/ h(ui.Head.Title, {}, 'The knowledge graph, by topic'), /*#__PURE__*/ h(ui.Head.Sub, {}, 'Each topic’s cover, and under it the topics it holds. Open one to read what is known about it, what it holds and where that came from, and to comment on it.'), s.got?.ready ? /*#__PURE__*/ h(ui.Head.Facts, {}, `${n} ${n == 1 ? 'topic' : 'topics'}`, ...s.said ? [
124
+ `${s.hits.length} fit “${s.said}”`
125
+ ] : []) : null), /*#__PURE__*/ h(ui.Section, {}, /*#__PURE__*/ h(Find, {
126
+ ...s,
127
+ io
128
+ })), /*#__PURE__*/ h(List, {
129
+ ...s,
130
+ io,
131
+ covers: true
132
+ }));
133
+ };
134
+ /** A topic's page beside the shelves: the tab a topic opens on. */ export let ShelvedPage = (p)=>{
135
+ let s = useShelves(p.io);
136
+ return /*#__PURE__*/ h(ui.Panes, {
137
+ 'data-catalogue': p.e.entity.eid
138
+ }, /*#__PURE__*/ h(ui.Panes.Pane, {
139
+ mod: [
140
+ 'nav',
141
+ 'aside'
142
+ ],
143
+ 'aria-label': 'Topics'
144
+ }, /*#__PURE__*/ h(ui.Panes.Top, {}, /*#__PURE__*/ h(Find, {
145
+ ...s,
146
+ io: p.io
147
+ })), /*#__PURE__*/ h(ui.Panes.Body, {}, /*#__PURE__*/ h(List, {
148
+ ...s,
149
+ io: p.io,
150
+ lit: p.e.entity.eid
151
+ }))), /*#__PURE__*/ h(ui.Panes.Pane, {
152
+ mod: 'main'
153
+ }, /*#__PURE__*/ h(ui.Panes.Body, {}, /*#__PURE__*/ h(TopicPage, p))));
154
+ };
155
+ //# sourceMappingURL=catalogue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogue.js","sources":["./catalogue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,EAAY,eAAe,EAAE,MAAM,gBAA0B;AAClI,YAAY,wBAA6B;AACzC,SAAS,OAAO,wBAA6B;AAE7C,SAAS,KAAK,EAAE,KAAK,EAAc,OAAO,EAAE,MAAM,uBAAsB;AACxE,SAAS,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAoB;AACrE,SAAS,SAAS,oBAAmB;AAErC,wEAAwE,GACxE,OAAO,IAAI,UAAU,cAAa;AAElC,IAAI,OAAO,CAAC,IAAyB,GAAG,QAAQ,EAAE;AAElD;8CAC8C,GAC9C,IAAI,SAAS,CAAC,KAAW,C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AE,GAAG,OAAO,EAAE,CAAC,iBAAG,EAAE,MAAM;IAAE,GAAG,CAAC;IAAE;EAAG,mBACrC,EAAE,MAAM;IAAE,GAAG,CAAC;IAAE;IAAI,QAAQ;EAAK;AAErC,EAAC;AAED,iEAAiE,GACjE,OAAO,IAAI,cAAc,CAAC;EACxB,IAAI,IAAI,WAAW,EAAE,EAAE;EACvB,qBAAO,EACL,GAAG,KAAK,EACR;IAAE,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG;EAAC,iBACnC,EACE,GAAG,KAAK,CAAC,IAAI,EACb;IAAE,KAAK;MAAC;MAAO;KAAQ;IAAE,cAAc;EAAS,iBAChD,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,iBAAG,EAAE,MAAM;IAAE,GAAG,CAAC;IAAE,IAAI,EAAE,EAAE;EAAC,mBAC7C,EACE,GAAG,KAAK,CAAC,IAAI,EACb,CAAC,iBACD,EAAE,MAAM;IAAE,GAAG,CAAC;IAAE,IAAI,EAAE,EAAE;IAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG;EAAC,oBAGlD,EACE,GAAG,KAAK,CAAC,IAAI,EACb;IAAE,KAAK;EAAO,iBACd,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,iBAAG,EAAE,WAAW;AAGxC,EAAC"}
package/catalogue.ts ADDED
@@ -0,0 +1,218 @@
1
+ /**
2
+ * The catalogue: the shelves of topics (./shelves.ts) to find and walk them,
3
+ * and a topic opened beside them. `Topics.Page`, the page the sidebar offers
4
+ * as Topics, is the shelves alone, each topic with its cover. `Topic`, the tab
5
+ * a topic opens on, sets its page (./page.ts) beside the shelves, titles only,
6
+ * the topic open lit and the shelves holding it open; stacked, as on a phone,
7
+ * the page comes first.
8
+ *
9
+ * Over the shelves a field finds a topic by what is typed (`fits`: "data
10
+ * modeling" finds data model), narrowing them to the topics it fits, under the
11
+ * topics holding them; Enter opens the first and clears it, Escape clears it.
12
+ * What is typed there is the person's draft (the UX host's `drafts`,
13
+ * @yaks/ux), so it stays as they go from topic to topic among what it found,
14
+ * and in every interface they use.
15
+ *
16
+ * @module
17
+ */
18
+
19
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, useLayoutEffect, useRef } from 'react'
20
+ import * as ui from '@yaks/ui'
21
+ import { useHost } from '@yaks/ux'
22
+ import type { Answer, Bundle, Io, Props } from 'jsr:@yaks/inspect@0.2.36'
23
+ import { every, holds, type Shelf, shelves, within } from './shelves.js'
24
+ import { about, cover, fits, title, TOPIC, TOPICS } from './topic.js'
25
+ import { TopicPage } from './page.js'
26
+
27
+ /** Where what is typed to find a topic is kept, as the person's draft. */
28
+ export let FINDING = 'topics:find'
29
+
30
+ let rows = (a?: Answer): Bundle[] => a?.rows ?? []
31
+
32
+ /** What the shelves ask: every live topic with its cover, and every
33
+ * `contains` edge from one topic to another. */
34
+ let asking = (io: Io) => ({
35
+ topics: `.${TOPIC}&?doc` +
36
+ `${io.vocab.comp('archived') ? '&!archived' : ''}&.limit=${TOPICS}`,
37
+ ...io.vocab.comp('contains')
38
+ ? {
39
+ edges: `.contains&.edge.from.${TOPIC}.name&.edge.to.${TOPIC}.name` +
40
+ `&?edge&.limit=${TOPICS}`,
41
+ }
42
+ : {},
43
+ })
44
+
45
+ type Shelved = {
46
+ /** the topics' answer, for whether it has come */
47
+ got: Answer | undefined
48
+ /** what was typed to find one */
49
+ said: string
50
+ /** every topic, shelved */
51
+ all: Shelf[]
52
+ /** the shelves what was typed narrows them to */
53
+ shown: Shelf[]
54
+ /** the topics what was typed fits, as they are drawn */
55
+ hits: Bundle[]
56
+ }
57
+
58
+ /** Every topic, shelved and narrowed to what was typed to find one: a hook. */
59
+ let useShelves = (io: Io): Shelved => {
60
+ let got = io.ask(asking(io))
61
+ let said = useHost().drafts.text(FINDING)
62
+ let all = shelves(rows(got.topics), rows(got.edges))
63
+ let shown = within(all, said)
64
+ let hits = said ? every(shown).filter((t) => fits(said, about(t))) : []
65
+ return { got: got.topics, said, all, shown, hits }
66
+ }
67
+
68
+ /** The field a topic is found from. */
69
+ let Find = ({ io, said, hits }: Shelved & { io: Io }): JSX.Element => {
70
+ let { drafts } = useHost()
71
+ let box = useRef<HTMLInputElement>(null)
72
+ useLayoutEffect(() => {
73
+ let el = box.current
74
+ if (el && el.value != said) el.value = said
75
+ }, [said])
76
+ return h(ui.Field, {
77
+ elRef: box,
78
+ type: 'search',
79
+ name: 'find',
80
+ 'aria-label': 'find a topic',
81
+ placeholder: 'find a topic…',
82
+ onInput: (ev: Event) =>
83
+ drafts.type(FINDING, (ev.currentTarget as HTMLInputElement).value),
84
+ onKeyDown: (ev: KeyboardEvent) => {
85
+ if (ev.key == 'Enter' && hits[0]) {
86
+ ev.preventDefault()
87
+ drafts.spend(FINDING)
88
+ io.go(io.link(hits[0].entity.eid))
89
+ } else if (ev.key == 'Escape' && said) {
90
+ ev.preventDefault()
91
+ drafts.spend(FINDING)
92
+ }
93
+ },
94
+ })
95
+ }
96
+
97
+ type Drawn = { io: Io; said: string; lit?: string; covers?: boolean }
98
+
99
+ /** A topic on its shelf, and the shelves under it where they are open: under
100
+ * the topic open, on the way to it, wherever something was typed, and
101
+ * everywhere the covers show. A closed one counts what it holds. */
102
+ let Twig = (
103
+ { io, shelf, said, lit, covers }: Drawn & { shelf: Shelf },
104
+ ): JSX.Element => {
105
+ let t = shelf.topic
106
+ let eid = t.entity.eid
107
+ let under = shelf.under.length
108
+ let open = !!(covers || said || eid == lit || (lit && holds(shelf, lit)))
109
+ let words = covers ? cover(t) : ''
110
+ return h(
111
+ ui.Rows.Item,
112
+ { role: 'listitem', 'data-shelf': eid },
113
+ h(
114
+ ui.Tile,
115
+ {
116
+ href: io.link(eid),
117
+ mod: eid == lit ? 'on' : undefined,
118
+ 'aria-current': eid == lit ? 'page' : undefined,
119
+ },
120
+ h(ui.Tile.Title, { mod: covers ? 'wrap' : undefined }, title(t)),
121
+ under && !open ? h(ui.Tile.Count, {}, String(under)) : null,
122
+ words ? h(ui.Tile.Sub, { mod: 'wrap' }, words) : null,
123
+ ),
124
+ under && open
125
+ ? h(
126
+ ui.Rows,
127
+ { mod: 'nested', role: 'list' },
128
+ shelf.under.map((s) =>
129
+ h(Twig, {
130
+ key: s.topic.entity.eid,
131
+ io,
132
+ shelf: s,
133
+ said,
134
+ lit,
135
+ covers,
136
+ })
137
+ ),
138
+ )
139
+ : null,
140
+ )
141
+ }
142
+
143
+ /** The shelves, or why there are none to show. */
144
+ let List = (
145
+ { io, got, said, shown, lit, covers }: Shelved & Drawn,
146
+ ): JSX.Element =>
147
+ got?.error
148
+ ? h(ui.Rows.More, {}, got.error)
149
+ : !got?.ready && !shown.length
150
+ ? h(ui.Loading, {})
151
+ : !shown.length
152
+ ? h(
153
+ ui.Rows.More,
154
+ {},
155
+ said ? `no topic fits “${said}”` : 'there are no topics yet',
156
+ )
157
+ : h(
158
+ ui.Rows,
159
+ { role: 'list', mod: covers ? 'ruled' : undefined, 'data-shelves': '' },
160
+ shown.map((s) =>
161
+ h(Twig, { key: s.topic.entity.eid, io, shelf: s, said, lit, covers })
162
+ ),
163
+ )
164
+
165
+ /** The page the sidebar offers as Topics: every topic with its cover, under
166
+ * the topics holding it, and the field that finds one. */
167
+ export let TopicsPage = ({ io }: Props): JSX.Element => {
168
+ let s = useShelves(io)
169
+ let n = rows(s.got).length
170
+ return h(
171
+ 'article',
172
+ { 'data-topics': '' },
173
+ h(
174
+ ui.Head,
175
+ {},
176
+ h(ui.Head.Title, {}, 'The knowledge graph, by topic'),
177
+ h(
178
+ ui.Head.Sub,
179
+ {},
180
+ 'Each topic’s cover, and under it the topics it holds. Open one to read what is known about it, what it holds and where that came from, and to comment on it.',
181
+ ),
182
+ s.got?.ready
183
+ ? h(
184
+ ui.Head.Facts,
185
+ {},
186
+ `${n} ${n == 1 ? 'topic' : 'topics'}`,
187
+ ...s.said ? [`${s.hits.length} fit “${s.said}”`] : [],
188
+ )
189
+ : null,
190
+ ),
191
+ h(ui.Section, {}, h(Find, { ...s, io })),
192
+ h(List, { ...s, io, covers: true }),
193
+ )
194
+ }
195
+
196
+ /** A topic's page beside the shelves: the tab a topic opens on. */
197
+ export let ShelvedPage = (p: Props): JSX.Element => {
198
+ let s = useShelves(p.io)
199
+ return h(
200
+ ui.Panes,
201
+ { 'data-catalogue': p.e.entity.eid },
202
+ h(
203
+ ui.Panes.Pane,
204
+ { mod: ['nav', 'aside'], 'aria-label': 'Topics' },
205
+ h(ui.Panes.Top, {}, h(Find, { ...s, io: p.io })),
206
+ h(
207
+ ui.Panes.Body,
208
+ {},
209
+ h(List, { ...s, io: p.io, lit: p.e.entity.eid }),
210
+ ),
211
+ ),
212
+ h(
213
+ ui.Panes.Pane,
214
+ { mod: 'main' },
215
+ h(ui.Panes.Body, {}, h(TopicPage, p)),
216
+ ),
217
+ )
218
+ }