@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.
- package/LICENSE +202 -0
- package/README.md +256 -2
- package/_dist/context.d.ts +74 -0
- package/_dist/context.d.ts.map +1 -0
- package/_dist/graph.d.ts +5 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +33 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/share.d.ts +61 -0
- package/_dist/share.d.ts.map +1 -0
- package/_dist/shelves.d.ts +24 -0
- package/_dist/shelves.d.ts.map +1 -0
- package/_dist/tools.d.ts +5 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/topic.d.ts +50 -0
- package/_dist/topic.d.ts.map +1 -0
- package/_dist/views.d.ts +23 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/catalogue.js +155 -0
- package/catalogue.js.map +1 -0
- package/catalogue.ts +218 -0
- package/context.js +289 -0
- package/context.js.map +1 -0
- package/context.ts +318 -0
- package/deno.json +1 -0
- package/graph.js +32 -0
- package/graph.js.map +1 -0
- package/graph.ts +26 -0
- package/inspect.js +48 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +25 -0
- package/mod.js +33 -0
- package/mod.js.map +1 -0
- package/mod.ts +56 -0
- package/package.json +50 -4
- package/page.js +247 -0
- package/page.js.map +1 -0
- package/page.ts +297 -0
- package/share.js +104 -0
- package/share.js.map +1 -0
- package/share.ts +115 -0
- package/shelves.js +99 -0
- package/shelves.js.map +1 -0
- package/shelves.ts +93 -0
- package/tools.js +114 -0
- package/tools.js.map +1 -0
- package/tools.ts +122 -0
- package/topic.js +97 -0
- package/topic.js.map +1 -0
- package/topic.ts +128 -0
- package/tree.js +77 -0
- package/tree.js.map +1 -0
- package/tree.ts +93 -0
- package/views.js +30 -0
- package/views.js.map +1 -0
- package/views.ts +26 -0
- package/vocab.js +16 -0
- package/vocab.js.map +1 -0
- package/vocab.json +186 -0
- package/vocab.ts +17 -0
package/page.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A topic's page, read the way a book is: its cover (`doc{title, body}`, the
|
|
3
|
+
* title and a line or two saying what belongs under it, its body drawn as
|
|
4
|
+
* every doc's is, through `Inspect.Body`), a line to ask about it where the
|
|
5
|
+
* host draws a conversation (`Conversation`: a session opened on the topic,
|
|
6
|
+
* wearing the oracle), its contents (`content.body`, what is
|
|
7
|
+
* understood about it), then what it holds (`contains`), what to understand
|
|
8
|
+
* first (`requires`), what is related (`reads`, `references`) and its sources
|
|
9
|
+
* (`cites`), the beliefs about it (`belief.about`), and the comments on it,
|
|
10
|
+
* with a line to write one, where the host draws a thread (`Comments`); last,
|
|
11
|
+
* the parts any page has (`io.show`: the facts, the links, the history). Its
|
|
12
|
+
* head says what holds it: a topic belongs to whatever contains it.
|
|
13
|
+
*
|
|
14
|
+
* Whatever a topic holds or cites is drawn by its own renderer, asked for as
|
|
15
|
+
* `Topic.List.Tile`: a subtopic as its cover (`TopicTile`), a belief as what
|
|
16
|
+
* it states (@yaks/memory), anything else as it reads in any list. Each part
|
|
17
|
+
* is an ordered list edited in place: a row dragged between two others is
|
|
18
|
+
* put there, and opens where it stands on its title and body.
|
|
19
|
+
*
|
|
20
|
+
* An archived belief is kept, not live, so the beliefs part lists the live
|
|
21
|
+
* ones and opens the archived ones on a press, muted.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
|
|
27
|
+
import { Markdown } from '@yaks/markdown'
|
|
28
|
+
import * as ui from '@yaks/ui'
|
|
29
|
+
import { Disclosure, disclosureAt } from '@yaks/ux'
|
|
30
|
+
import {
|
|
31
|
+
type Answer,
|
|
32
|
+
type Asks,
|
|
33
|
+
type Bundle,
|
|
34
|
+
edited,
|
|
35
|
+
Held,
|
|
36
|
+
type Io,
|
|
37
|
+
Part,
|
|
38
|
+
type Props,
|
|
39
|
+
usePageNotes,
|
|
40
|
+
} from '@yaks/inspect'
|
|
41
|
+
import { title, TOPIC } from './topic.js'
|
|
42
|
+
|
|
43
|
+
/** How many edges from a topic its page reads. */
|
|
44
|
+
export let EDGES = 500
|
|
45
|
+
|
|
46
|
+
/** How many beliefs about a topic its page lists, live or archived. */
|
|
47
|
+
export let BELIEFS = 200
|
|
48
|
+
|
|
49
|
+
/** The relations a topic's page draws in parts of their own, in order, each
|
|
50
|
+
* under its heading. */
|
|
51
|
+
export let PARTS: [string, string[]][] = [
|
|
52
|
+
['Contains', ['contains']],
|
|
53
|
+
['Understand first', ['requires']],
|
|
54
|
+
['Related', ['reads', 'references']],
|
|
55
|
+
['Sources', ['cites']],
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
// What the links part leaves to the parts above: each relation read from the
|
|
59
|
+
// topic's end, the topic holding it, and the beliefs about it.
|
|
60
|
+
let DRAWN = [
|
|
61
|
+
...PARTS.flatMap(([, rels]) => rels),
|
|
62
|
+
'contained by',
|
|
63
|
+
'belief.about',
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
type Comp = Record<string, unknown>
|
|
67
|
+
let comp = (b: Bundle | undefined, name: string): Comp =>
|
|
68
|
+
(b?.[name] ?? {}) as Comp
|
|
69
|
+
let str = (b: Bundle | undefined, name: string, prop: string): string => {
|
|
70
|
+
let v = comp(b, name)[prop]
|
|
71
|
+
return typeof v == 'string' ? v : ''
|
|
72
|
+
}
|
|
73
|
+
let rows = (a?: Answer): Bundle[] => a?.rows ?? []
|
|
74
|
+
|
|
75
|
+
/** What a topic's page asks: its edges, what holds it, and the beliefs about
|
|
76
|
+
* it where the graph keeps beliefs. What holds it comes whole, so the head
|
|
77
|
+
* names it as it first paints. */
|
|
78
|
+
export let asks = (e: Bundle, io: Io): Asks => {
|
|
79
|
+
let eid = e.entity.eid
|
|
80
|
+
return {
|
|
81
|
+
out: `.edge.from=${eid}&*&.order=edge.ord&.limit=${EDGES}`,
|
|
82
|
+
within: `.contains[<=1]->${eid}&?doc&?${TOPIC}&.limit=${EDGES}`,
|
|
83
|
+
...io.vocab.comp('belief')
|
|
84
|
+
? {
|
|
85
|
+
beliefs: `.belief.about=${eid}&!archived&*` +
|
|
86
|
+
`&.order=-created.at&.limit=${BELIEFS}`,
|
|
87
|
+
archived: `.belief.about=${eid}&.archived&.count`,
|
|
88
|
+
}
|
|
89
|
+
: {},
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let byTitle = (a: Bundle, b: Bundle) =>
|
|
94
|
+
title(a).localeCompare(title(b), undefined, { sensitivity: 'base' })
|
|
95
|
+
|
|
96
|
+
// An entity by name, drawn from the answer that brought it, so no id shows
|
|
97
|
+
// while its name is on the way.
|
|
98
|
+
let named = (io: Io, b: Bundle) => io.show(b, 'Inspect.Reference.Inline')
|
|
99
|
+
|
|
100
|
+
// Each of some entities by name, a comma between them.
|
|
101
|
+
let listed = (io: Io, said: string, all: Bundle[]): ReactNode =>
|
|
102
|
+
all.length
|
|
103
|
+
? [said, ...all.flatMap((b, i) => [i ? ', ' : null, named(io, b)])]
|
|
104
|
+
: null
|
|
105
|
+
|
|
106
|
+
type Of = { e: Bundle; io: Io; notes: Map<string, Bundle[]> }
|
|
107
|
+
|
|
108
|
+
/** What is understood about it, as one document. */
|
|
109
|
+
let Contents = ({ e, io, notes }: Of): JSX.Element => {
|
|
110
|
+
let text = str(e, 'content', 'body')
|
|
111
|
+
let eid = e.entity.eid
|
|
112
|
+
return h(
|
|
113
|
+
Part,
|
|
114
|
+
{ io, eid, subject: io.id(e), heading: 'Contents', notes },
|
|
115
|
+
edited(io, eid)
|
|
116
|
+
? null
|
|
117
|
+
: text
|
|
118
|
+
? h(ui.Body, {}, h(Markdown, { source: text }))
|
|
119
|
+
: h(ui.Rows.More, {}, 'nothing is written here yet'),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** One part's far ends, each drawn by its own renderer, in edge order: an
|
|
124
|
+
* ordered list edited in place (@yaks/inspect `Held`), which an entity
|
|
125
|
+
* dragged from elsewhere joins where a part names one relation. */
|
|
126
|
+
let Relation = (
|
|
127
|
+
{ e, io, notes, heading, rels, edges, ends }: Of & {
|
|
128
|
+
heading: string
|
|
129
|
+
rels: string[]
|
|
130
|
+
edges: Bundle[]
|
|
131
|
+
ends?: Answer
|
|
132
|
+
},
|
|
133
|
+
): JSX.Element | null =>
|
|
134
|
+
edges.length
|
|
135
|
+
? h(
|
|
136
|
+
Part,
|
|
137
|
+
{
|
|
138
|
+
io,
|
|
139
|
+
eid: e.entity.eid,
|
|
140
|
+
subject: io.id(e),
|
|
141
|
+
heading,
|
|
142
|
+
count: edges.length,
|
|
143
|
+
notes,
|
|
144
|
+
},
|
|
145
|
+
h(Held, {
|
|
146
|
+
io,
|
|
147
|
+
from: e.entity.eid,
|
|
148
|
+
links: edges,
|
|
149
|
+
ends,
|
|
150
|
+
tile: 'Topic.List.Tile',
|
|
151
|
+
empty: '',
|
|
152
|
+
tag: rels.length == 1 ? rels[0] : undefined,
|
|
153
|
+
}),
|
|
154
|
+
)
|
|
155
|
+
: null
|
|
156
|
+
|
|
157
|
+
/** The archived beliefs, asked for only once they are opened. */
|
|
158
|
+
let Archived = ({ e, io }: { e: Bundle; io: Io }): JSX.Element => {
|
|
159
|
+
let got = io.ask({
|
|
160
|
+
beliefs: `.belief.about=${e.entity.eid}&.archived&*` +
|
|
161
|
+
`&.order=-created.at&.limit=${BELIEFS}`,
|
|
162
|
+
}).beliefs
|
|
163
|
+
return got?.error
|
|
164
|
+
? h(ui.Rows.More, {}, got.error)
|
|
165
|
+
: !got?.ready && !rows(got).length
|
|
166
|
+
? h(ui.Loading, {})
|
|
167
|
+
: h(
|
|
168
|
+
ui.Rows,
|
|
169
|
+
{ mod: 'quiet' },
|
|
170
|
+
rows(got).map((b) => io.show(b, 'Topic.List.Tile', {})),
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The beliefs about it: the live ones, newest first, and the archived ones
|
|
175
|
+
* on a press. */
|
|
176
|
+
let Beliefs = (
|
|
177
|
+
{ e, io, notes, got }: Of & { got: Record<string, Answer> },
|
|
178
|
+
): JSX.Element | null => {
|
|
179
|
+
if (!io.vocab.comp('belief')) return null
|
|
180
|
+
let live = rows(got.beliefs)
|
|
181
|
+
let kept = got.archived?.count ?? 0
|
|
182
|
+
let at = disclosureAt(`${e.entity.eid}/archived beliefs`)
|
|
183
|
+
let open = io.state(at) ?? { entity: { eid: at } }
|
|
184
|
+
return h(
|
|
185
|
+
Part,
|
|
186
|
+
{
|
|
187
|
+
io,
|
|
188
|
+
eid: e.entity.eid,
|
|
189
|
+
subject: io.id(e),
|
|
190
|
+
heading: 'Beliefs',
|
|
191
|
+
count: got.beliefs?.ready ? live.length : undefined,
|
|
192
|
+
notes,
|
|
193
|
+
},
|
|
194
|
+
got.beliefs?.error
|
|
195
|
+
? h(ui.Rows.More, {}, got.beliefs.error)
|
|
196
|
+
: !got.beliefs?.ready && !live.length
|
|
197
|
+
? h(ui.Loading, {})
|
|
198
|
+
: live.length
|
|
199
|
+
? h(ui.Rows, {}, live.map((b) => io.show(b, 'Topic.List.Tile', {})))
|
|
200
|
+
: h(
|
|
201
|
+
ui.Rows.More,
|
|
202
|
+
{},
|
|
203
|
+
kept ? 'none live' : 'nothing is believed about it yet',
|
|
204
|
+
),
|
|
205
|
+
kept
|
|
206
|
+
? h(Disclosure, {
|
|
207
|
+
e: open,
|
|
208
|
+
onChange: (b: Bundle) => io.set([b]),
|
|
209
|
+
summary: `${kept} archived`,
|
|
210
|
+
lazy: true,
|
|
211
|
+
}, h(Archived, { e, io }))
|
|
212
|
+
: null,
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** A line to ask about it: a session opened on the topic, wearing the oracle,
|
|
217
|
+
* wherever the host draws a conversation (`Conversation`); a host without one
|
|
218
|
+
* has no part. */
|
|
219
|
+
let Ask = ({ e, io }: { e: Bundle; io: Io }): JSX.Element | null =>
|
|
220
|
+
io.can(e, 'Conversation')
|
|
221
|
+
? h(
|
|
222
|
+
ui.Section,
|
|
223
|
+
{ 'data-section': 'Ask' },
|
|
224
|
+
h(ui.Section.Title, {}, 'Ask'),
|
|
225
|
+
io.show(e, 'Conversation', {}),
|
|
226
|
+
)
|
|
227
|
+
: null
|
|
228
|
+
|
|
229
|
+
/** What people said about it: the comment thread, with a line to say more,
|
|
230
|
+
* wherever the host draws one (`Comments`); a host without one has no part. */
|
|
231
|
+
let Comments = ({ e, io }: { e: Bundle; io: Io }): JSX.Element | null =>
|
|
232
|
+
io.can(e, 'Comments')
|
|
233
|
+
? h(
|
|
234
|
+
ui.Section,
|
|
235
|
+
{ 'data-section': 'Comments' },
|
|
236
|
+
h(ui.Section.Title, {}, 'Comments'),
|
|
237
|
+
io.show(e, 'Comments', {}),
|
|
238
|
+
)
|
|
239
|
+
: null
|
|
240
|
+
|
|
241
|
+
/** A topic's page. */
|
|
242
|
+
export let TopicPage = ({ e, io, got }: Props): JSX.Element => {
|
|
243
|
+
let eid = e.entity.eid
|
|
244
|
+
let notes = usePageNotes(io, e, [
|
|
245
|
+
'Contents',
|
|
246
|
+
...PARTS.map(([heading]) => heading),
|
|
247
|
+
'Beliefs',
|
|
248
|
+
])
|
|
249
|
+
let out = rows(got.out)
|
|
250
|
+
let ids = [...new Set(out.map((b) => str(b, 'edge', 'to')).filter(Boolean))]
|
|
251
|
+
let ends = io.ask(
|
|
252
|
+
ids.length ? { ends: `.entity.eid=${ids.join(',')}&*` } : {},
|
|
253
|
+
).ends
|
|
254
|
+
return h(
|
|
255
|
+
'div',
|
|
256
|
+
{ 'data-inspect': eid },
|
|
257
|
+
io.show(e, 'Inspect.Head', {
|
|
258
|
+
sub: listed(io, 'in ', rows(got.within).toSorted(byTitle)),
|
|
259
|
+
notes: notes.get(''),
|
|
260
|
+
}),
|
|
261
|
+
// Its cover's words, what belongs under it, as any page says what an
|
|
262
|
+
// entity says; a topic with no cover has its contents said below alone.
|
|
263
|
+
str(e, 'doc', 'body') ? io.show(e, 'Inspect.Body') : null,
|
|
264
|
+
h(Ask, { e, io }),
|
|
265
|
+
h(Contents, { e, io, notes }),
|
|
266
|
+
...PARTS.map(([heading, rels]) =>
|
|
267
|
+
h(Relation, {
|
|
268
|
+
key: heading,
|
|
269
|
+
e,
|
|
270
|
+
io,
|
|
271
|
+
notes,
|
|
272
|
+
heading,
|
|
273
|
+
rels,
|
|
274
|
+
edges: out.filter((b) => rels.some((r) => b[r])),
|
|
275
|
+
ends,
|
|
276
|
+
})
|
|
277
|
+
),
|
|
278
|
+
h(Beliefs, { e, io, notes, got }),
|
|
279
|
+
h(Comments, { e, io }),
|
|
280
|
+
io.show(e, 'Inspect.Facts', { notes, skip: [TOPIC] }),
|
|
281
|
+
io.show(e, 'Inspect.Links', { notes, skip: DRAWN }),
|
|
282
|
+
io.show(e, 'Inspect.History', { notes }),
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** A topic in a list: its cover, the title and what belongs under it, so a
|
|
287
|
+
* reader decides by it. */
|
|
288
|
+
export let TopicTile = ({ e, io }: Props): JSX.Element => {
|
|
289
|
+
let cover = str(e, 'doc', 'body')
|
|
290
|
+
return h(
|
|
291
|
+
ui.Tile,
|
|
292
|
+
{ href: io.link(e.entity.eid), 'data-topic': e.entity.eid },
|
|
293
|
+
h(ui.Tile.Kind, {}, 'topic'),
|
|
294
|
+
h(ui.Tile.Title, { mod: 'wrap' }, title(e)),
|
|
295
|
+
cover ? h(ui.Tile.Sub, { mod: 'wrap' }, cover) : null,
|
|
296
|
+
)
|
|
297
|
+
}
|
package/share.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A topic's share of the week: `attended{share}`, the part of each plan's
|
|
3
|
+
* week that work for the topic may use. Topics nest, and a subtopic's share
|
|
4
|
+
* is part of its parent's, so what a topic keeps is its share less the shares
|
|
5
|
+
* below it, computed here and never stored. Work for a topic with no share is
|
|
6
|
+
* charged to the nearest topic above it that has one. How much of a share is
|
|
7
|
+
* used is @yaks/spend's to say (`shared`).
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/ import { line } from "@yaks/query";
|
|
11
|
+
import { HOLDS, TOPIC, TOPICS } from "./topic.js";
|
|
12
|
+
/** The component that gives a topic its share. */ export let SHARE = 'attended';
|
|
13
|
+
/**
|
|
14
|
+
* The nearest topic above `topic` that has a share: of its containers, then
|
|
15
|
+
* of theirs, and of two as near the first by eid.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { above } from './share.ts'
|
|
19
|
+
* import { equal } from '@yaks/testing'
|
|
20
|
+
*
|
|
21
|
+
* let s = {
|
|
22
|
+
* share: new Map([['pilots', 0.4], ['grove', 0.1]]),
|
|
23
|
+
* up: new Map([['grove', ['pilots']], ['site', ['grove']], ['copy', ['site']]]),
|
|
24
|
+
* }
|
|
25
|
+
* equal([above(s, 'copy'), above(s, 'grove'), above(s, 'pilots')], ['grove', 'pilots', undefined])
|
|
26
|
+
* ```
|
|
27
|
+
*/ export let above = (s, topic)=>{
|
|
28
|
+
let seen = new Set([
|
|
29
|
+
topic
|
|
30
|
+
]);
|
|
31
|
+
for(let level = [
|
|
32
|
+
topic
|
|
33
|
+
]; level.length;){
|
|
34
|
+
level = [
|
|
35
|
+
...new Set(level.flatMap((t)=>s.up.get(t) ?? []))
|
|
36
|
+
].filter((t)=>!seen.has(t)).sort();
|
|
37
|
+
let found = level.find((t)=>s.share.has(t));
|
|
38
|
+
if (found) return found;
|
|
39
|
+
for (let t of level)seen.add(t);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The topic work for `topic` is charged to: itself where it has a share,
|
|
44
|
+
* else the nearest topic above it that has one. With none above, nothing
|
|
45
|
+
* was allotted for it.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { holder } from './share.ts'
|
|
49
|
+
* import { equal } from '@yaks/testing'
|
|
50
|
+
*
|
|
51
|
+
* let s = { share: new Map([['pilots', 0.4]]), up: new Map([['grove', ['pilots']]]) }
|
|
52
|
+
* equal([holder(s, 'pilots'), holder(s, 'grove'), holder(s, 'funnel')], ['pilots', 'pilots', undefined])
|
|
53
|
+
* ```
|
|
54
|
+
*/ export let holder = (s, topic)=>s.share.has(topic) ? topic : above(s, topic);
|
|
55
|
+
/**
|
|
56
|
+
* What each topic with a share keeps: its share less the shares of the
|
|
57
|
+
* nearest topics below it that have one.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { kept } from './share.ts'
|
|
61
|
+
* import { equal } from '@yaks/testing'
|
|
62
|
+
*
|
|
63
|
+
* let s = {
|
|
64
|
+
* share: new Map([['pilots', 0.5], ['grove', 0.25], ['funnel', 0.125]]),
|
|
65
|
+
* up: new Map([['grove', ['pilots']]]),
|
|
66
|
+
* }
|
|
67
|
+
* equal([...kept(s)], [['pilots', 0.25], ['grove', 0.25], ['funnel', 0.125]])
|
|
68
|
+
* ```
|
|
69
|
+
*/ export let kept = (s)=>{
|
|
70
|
+
let out = new Map(s.share);
|
|
71
|
+
for (let [topic, share] of s.share){
|
|
72
|
+
let up = above(s, topic);
|
|
73
|
+
if (up) out.set(up, out.get(up) - share);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
};
|
|
77
|
+
/** The shares a graph's topics have, and the topics that contain each
|
|
78
|
+
* topic. A graph with no share reads no nesting. */ export let shares = async (g)=>{
|
|
79
|
+
let out = {
|
|
80
|
+
share: new Map(),
|
|
81
|
+
up: new Map()
|
|
82
|
+
};
|
|
83
|
+
if (!g.vocab.comp(SHARE)) return out;
|
|
84
|
+
for (let b of (await g.read(line`.${TOPIC}&.${SHARE}&.limit=${TOPICS}`))){
|
|
85
|
+
let share = Number(b[SHARE].share);
|
|
86
|
+
if (share >= 0) out.share.set(b.entity.eid, share);
|
|
87
|
+
}
|
|
88
|
+
if (!out.share.size) return out;
|
|
89
|
+
let topics = new Set((await g.read(line`.${TOPIC}&.limit=${TOPICS}`)).map((b)=>b.entity.eid));
|
|
90
|
+
if (!topics.size) return out;
|
|
91
|
+
let edges = await g.read(line`.${HOLDS}&.edge.to=${[
|
|
92
|
+
...topics
|
|
93
|
+
]}&?edge&.limit=${TOPICS}`);
|
|
94
|
+
for (let b of edges){
|
|
95
|
+
let { from, to } = b.edge;
|
|
96
|
+
if (!topics.has(from)) continue;
|
|
97
|
+
out.up.set(to, [
|
|
98
|
+
...out.up.get(to) ?? [],
|
|
99
|
+
from
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=share.js.map
|
package/share.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share.js","sources":["./share.ts"],"names":[],"mappings":"AAAA;;;;;;;;;CASC,GAED,SAAS,IAAI,2BAAgC;AAC7C,SAAS,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAoB;AAEjD,gDAAgD,GAChD,OAAO,IAAI,QAAQ,WAAU;AAU7B;;;;;;;;;;;;;;CAcC,GACD,OAAO,IAAI,QAAQ,CAAC,GAAW;EAC7B,IAAI,OAAO,IAAI,IAAI;IAAC;GAAM;EAC1B,IAAK,IAAI,QAAQ;IAAC;GAAM,EAAE,MAAM,MAAM,EAAG;IACvC,QAAQ;SAAI,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC,IAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE;KAAG,CAC1D,MAAM,CAAC,CAAC,IAAM,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI;IACnC,IAAI,QAAQ,MAAM,IAAI,CAAC,CAAC,IAAM,EAAE,KAAK,CAAC,GAAG,CAAC;IA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zB,IAAI,QAAQ,MAAM,EAAE,IAAI,CACtB,IAAI,CAAC,CAAC,EAAE,MAAM,UAAU,EAAE;OAAI;GAAO,CAAC,cAAc,EAAE,OAAO,CAAC;EAEhE,KAAK,IAAI,KAAK,MAAO;IACnB,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI;IACzB,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO;IACvB,IAAI,EAAE,CAAC,GAAG,CAAC,IAAI;SAAI,IAAI,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE;MAAE;KAAK;EAChD;EACA,OAAO;AACT,EAAC"}
|
package/share.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A topic's share of the week: `attended{share}`, the part of each plan's
|
|
3
|
+
* week that work for the topic may use. Topics nest, and a subtopic's share
|
|
4
|
+
* is part of its parent's, so what a topic keeps is its share less the shares
|
|
5
|
+
* below it, computed here and never stored. Work for a topic with no share is
|
|
6
|
+
* charged to the nearest topic above it that has one. How much of a share is
|
|
7
|
+
* used is @yaks/spend's to say (`shared`).
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import type { Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
12
|
+
import { line } from '@yaks/query'
|
|
13
|
+
import { HOLDS, TOPIC, TOPICS } from './topic.js'
|
|
14
|
+
|
|
15
|
+
/** The component that gives a topic its share. */
|
|
16
|
+
export let SHARE = 'attended'
|
|
17
|
+
|
|
18
|
+
/** The shares topics have, and how the topics nest. */
|
|
19
|
+
export type Shares = {
|
|
20
|
+
/** each topic's share, 0 to 1, where it has one */
|
|
21
|
+
share: Map<Eid, number>
|
|
22
|
+
/** the topics that contain each topic */
|
|
23
|
+
up: Map<Eid, Eid[]>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The nearest topic above `topic` that has a share: of its containers, then
|
|
28
|
+
* of theirs, and of two as near the first by eid.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { above } from './share.ts'
|
|
32
|
+
* import { equal } from '@yaks/testing'
|
|
33
|
+
*
|
|
34
|
+
* let s = {
|
|
35
|
+
* share: new Map([['pilots', 0.4], ['grove', 0.1]]),
|
|
36
|
+
* up: new Map([['grove', ['pilots']], ['site', ['grove']], ['copy', ['site']]]),
|
|
37
|
+
* }
|
|
38
|
+
* equal([above(s, 'copy'), above(s, 'grove'), above(s, 'pilots')], ['grove', 'pilots', undefined])
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export let above = (s: Shares, topic: Eid): Eid | undefined => {
|
|
42
|
+
let seen = new Set([topic])
|
|
43
|
+
for (let level = [topic]; level.length;) {
|
|
44
|
+
level = [...new Set(level.flatMap((t) => s.up.get(t) ?? []))]
|
|
45
|
+
.filter((t) => !seen.has(t)).sort()
|
|
46
|
+
let found = level.find((t) => s.share.has(t))
|
|
47
|
+
if (found) return found
|
|
48
|
+
for (let t of level) seen.add(t)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The topic work for `topic` is charged to: itself where it has a share,
|
|
54
|
+
* else the nearest topic above it that has one. With none above, nothing
|
|
55
|
+
* was allotted for it.
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { holder } from './share.ts'
|
|
59
|
+
* import { equal } from '@yaks/testing'
|
|
60
|
+
*
|
|
61
|
+
* let s = { share: new Map([['pilots', 0.4]]), up: new Map([['grove', ['pilots']]]) }
|
|
62
|
+
* equal([holder(s, 'pilots'), holder(s, 'grove'), holder(s, 'funnel')], ['pilots', 'pilots', undefined])
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export let holder = (s: Shares, topic: Eid): Eid | undefined =>
|
|
66
|
+
s.share.has(topic) ? topic : above(s, topic)
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* What each topic with a share keeps: its share less the shares of the
|
|
70
|
+
* nearest topics below it that have one.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { kept } from './share.ts'
|
|
74
|
+
* import { equal } from '@yaks/testing'
|
|
75
|
+
*
|
|
76
|
+
* let s = {
|
|
77
|
+
* share: new Map([['pilots', 0.5], ['grove', 0.25], ['funnel', 0.125]]),
|
|
78
|
+
* up: new Map([['grove', ['pilots']]]),
|
|
79
|
+
* }
|
|
80
|
+
* equal([...kept(s)], [['pilots', 0.25], ['grove', 0.25], ['funnel', 0.125]])
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export let kept = (s: Shares): Map<Eid, number> => {
|
|
84
|
+
let out = new Map(s.share)
|
|
85
|
+
for (let [topic, share] of s.share) {
|
|
86
|
+
let up = above(s, topic)
|
|
87
|
+
if (up) out.set(up, out.get(up)! - share)
|
|
88
|
+
}
|
|
89
|
+
return out
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The shares a graph's topics have, and the topics that contain each
|
|
93
|
+
* topic. A graph with no share reads no nesting. */
|
|
94
|
+
export let shares = async (g: Graph): Promise<Shares> => {
|
|
95
|
+
let out: Shares = { share: new Map(), up: new Map() }
|
|
96
|
+
if (!g.vocab.comp(SHARE)) return out
|
|
97
|
+
for (let b of await g.read(line`.${TOPIC}&.${SHARE}&.limit=${TOPICS}`)) {
|
|
98
|
+
let share = Number((b[SHARE] as { share?: unknown }).share)
|
|
99
|
+
if (share >= 0) out.share.set(b.entity.eid, share)
|
|
100
|
+
}
|
|
101
|
+
if (!out.share.size) return out
|
|
102
|
+
let topics = new Set(
|
|
103
|
+
(await g.read(line`.${TOPIC}&.limit=${TOPICS}`)).map((b) => b.entity.eid),
|
|
104
|
+
)
|
|
105
|
+
if (!topics.size) return out
|
|
106
|
+
let edges = await g.read(
|
|
107
|
+
line`.${HOLDS}&.edge.to=${[...topics]}&?edge&.limit=${TOPICS}`,
|
|
108
|
+
)
|
|
109
|
+
for (let b of edges) {
|
|
110
|
+
let { from, to } = b.edge as { from: Eid; to: Eid }
|
|
111
|
+
if (!topics.has(from)) continue
|
|
112
|
+
out.up.set(to, [...out.up.get(to) ?? [], from])
|
|
113
|
+
}
|
|
114
|
+
return out
|
|
115
|
+
}
|
package/shelves.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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 { about, fits, title } from "./topic.js";
|
|
12
|
+
let by = (a, b)=>title(a).localeCompare(title(b), undefined, {
|
|
13
|
+
sensitivity: 'base'
|
|
14
|
+
});
|
|
15
|
+
let eidOf = (b)=>b.entity.eid;
|
|
16
|
+
let end = (e, side)=>{
|
|
17
|
+
let v = e.edge?.[side];
|
|
18
|
+
return typeof v == 'string' ? v : '';
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The topics as shelves, from the topics and the `contains` edges among them;
|
|
22
|
+
* an edge to or from anything else is left out.
|
|
23
|
+
*/ /// let t = (eid: string, body = '') => ({ entity: { eid }, doc: { title: eid, body } })
|
|
24
|
+
/// let held = (from: string, to: string) => ({ entity: { eid: from + to }, edge: { from, to }, contains: {} })
|
|
25
|
+
/// let names = (s: Shelf[]): unknown[] => s.map((x) => x.under.length ? [x.topic.entity.eid, names(x.under)] : x.topic.entity.eid)
|
|
26
|
+
/// names(shelves([t('b'), t('a'), t('c')], [held('a', 'c')])) -> [['a', ['c']], 'b']
|
|
27
|
+
/// names(shelves([t('a'), t('b')], [held('a', 'b'), held('b', 'a')])) -> [['a', [['b', ['a']]]]]
|
|
28
|
+
/// names(shelves([t('a')], [held('a', 'x')])) -> ['a']
|
|
29
|
+
export let shelves = (topics, edges)=>{
|
|
30
|
+
let all = new Map(topics.map((t)=>[
|
|
31
|
+
eidOf(t),
|
|
32
|
+
t
|
|
33
|
+
]));
|
|
34
|
+
let inside = new Map();
|
|
35
|
+
for (let e of edges){
|
|
36
|
+
let [from, to] = [
|
|
37
|
+
all.get(end(e, 'from')),
|
|
38
|
+
all.get(end(e, 'to'))
|
|
39
|
+
];
|
|
40
|
+
if (from && to) {
|
|
41
|
+
inside.set(eidOf(from), [
|
|
42
|
+
...inside.get(eidOf(from)) ?? [],
|
|
43
|
+
to
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
let kept = new Set([
|
|
48
|
+
...inside.values()
|
|
49
|
+
].flat().map(eidOf));
|
|
50
|
+
let seen = new Set();
|
|
51
|
+
let shelf = (t, path)=>{
|
|
52
|
+
let eid = eidOf(t);
|
|
53
|
+
seen.add(eid);
|
|
54
|
+
return {
|
|
55
|
+
topic: t,
|
|
56
|
+
under: path.includes(eid) ? [] : [
|
|
57
|
+
...new Set(inside.get(eid) ?? [])
|
|
58
|
+
].sort(by).map((u)=>shelf(u, [
|
|
59
|
+
...path,
|
|
60
|
+
eid
|
|
61
|
+
]))
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
let top = [
|
|
65
|
+
...all.values()
|
|
66
|
+
].filter((t)=>!kept.has(eidOf(t))).sort(by).map((t)=>shelf(t, []));
|
|
67
|
+
// What only a cycle holds is shelved at the top, from its first by title.
|
|
68
|
+
for (let t of [
|
|
69
|
+
...all.values()
|
|
70
|
+
].sort(by)){
|
|
71
|
+
if (!seen.has(eidOf(t))) top.push(shelf(t, []));
|
|
72
|
+
}
|
|
73
|
+
return top;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The shelves narrowed to what was said: each topic whose words fit it
|
|
77
|
+
* (`fits`), under the topics that hold it. Nothing said narrows nothing.
|
|
78
|
+
*/ /// let s = shelves([t('data', 'how data is shaped'), t('ids', 'what names a thing'), t('git', 'commits')], [held('data', 'ids')])
|
|
79
|
+
/// names(within(s, 'names')) -> [['data', ['ids']]]
|
|
80
|
+
/// names(within(s, 'commit')) -> ['git']
|
|
81
|
+
/// names(within(s, '')) -> [['data', ['ids']], 'git']
|
|
82
|
+
export let within = (all, said)=>all.flatMap((s)=>{
|
|
83
|
+
let under = within(s.under, said);
|
|
84
|
+
return under.length || fits(said, about(s.topic)) ? [
|
|
85
|
+
{
|
|
86
|
+
...s,
|
|
87
|
+
under
|
|
88
|
+
}
|
|
89
|
+
] : [];
|
|
90
|
+
});
|
|
91
|
+
/** Every topic on the shelves, top to bottom, as they are drawn. */ /// every(s).map((b) => b.entity.eid) -> ['data', 'ids', 'git']
|
|
92
|
+
export let every = (all)=>all.flatMap((s)=>[
|
|
93
|
+
s.topic,
|
|
94
|
+
...every(s.under)
|
|
95
|
+
]);
|
|
96
|
+
/** Whether a shelf holds a topic somewhere under it. */ /// holds(s[0], 'ids') -> true
|
|
97
|
+
/// holds(s[0], 'data') -> false
|
|
98
|
+
export let holds = (s, eid)=>s.under.some((u)=>eidOf(u.topic) == eid || holds(u, eid));
|
|
99
|
+
//# sourceMappingURL=shelves.js.map
|
package/shelves.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shelves.js","sources":["./shelves.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;CAUC,GAGD,SAAS,KAAK,EAAE,IAAI,EAAE,KAAK,qBAAoB;AAK/C,IAAI,KAAK,CAAC,GAAW,IACnB,MAAM,GAAG,aAAa,CAAC,MAAM,IAAI,WAAW;IAAE,aAAa;EAAO;AAEpE,IAAI,QAAQ,CAAC,IAAc,EAAE,MAAM,CAAC,GAAG;AAEvC,IAAI,MAAM,CAAC,GAAW;EACpB,IAAI,IAAK,EAAE,IAA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