@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.
- package/Comp.js +469 -0
- package/Comp.js.map +1 -0
- package/Comp.ts +471 -0
- package/Effect.js +136 -0
- package/Effect.js.map +1 -0
- package/Effect.ts +142 -0
- package/Entity.js +112 -0
- package/Entity.js.map +1 -0
- package/Entity.ts +137 -0
- package/Facts.js +143 -0
- package/Facts.js.map +1 -0
- package/Facts.ts +150 -0
- package/Head.js +196 -0
- package/Head.js.map +1 -0
- package/Head.ts +195 -0
- package/Held.js +144 -0
- package/Held.js.map +1 -0
- package/Held.ts +172 -0
- package/History.js +157 -0
- package/History.js.map +1 -0
- package/History.ts +215 -0
- package/Home.js +482 -0
- package/Home.js.map +1 -0
- package/Home.ts +550 -0
- package/LICENSE +202 -0
- package/Links.js +197 -0
- package/Links.js.map +1 -0
- package/Links.ts +212 -0
- package/Package.js +195 -0
- package/Package.js.map +1 -0
- package/Package.ts +191 -0
- package/Past.js +163 -0
- package/Past.js.map +1 -0
- package/Past.ts +181 -0
- package/Prop.js +225 -0
- package/Prop.js.map +1 -0
- package/Prop.ts +208 -0
- package/Query.js +207 -0
- package/Query.js.map +1 -0
- package/Query.ts +229 -0
- package/README.md +141 -2
- package/Words.js +43 -0
- package/Words.js.map +1 -0
- package/Words.ts +70 -0
- package/_dist/Entity.d.ts +7 -0
- package/_dist/Entity.d.ts.map +1 -0
- package/_dist/Facts.d.ts +7 -0
- package/_dist/Facts.d.ts.map +1 -0
- package/_dist/Head.d.ts +22 -0
- package/_dist/Head.d.ts.map +1 -0
- package/_dist/Held.d.ts +37 -0
- package/_dist/Held.d.ts.map +1 -0
- package/_dist/Links.d.ts +9 -0
- package/_dist/Links.d.ts.map +1 -0
- package/_dist/Past.d.ts +65 -0
- package/_dist/Past.d.ts.map +1 -0
- package/_dist/Words.d.ts +27 -0
- package/_dist/Words.d.ts.map +1 -0
- package/_dist/census.d.ts +10 -0
- package/_dist/census.d.ts.map +1 -0
- package/_dist/door.d.ts +28 -0
- package/_dist/door.d.ts.map +1 -0
- package/_dist/front.d.ts +4 -0
- package/_dist/front.d.ts.map +1 -0
- package/_dist/host.d.ts +94 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/mod.d.ts +24 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/notes.d.ts +38 -0
- package/_dist/notes.d.ts.map +1 -0
- package/_dist/read.d.ts +59 -0
- package/_dist/read.d.ts.map +1 -0
- package/_dist/reading.d.ts +21 -0
- package/_dist/reading.d.ts.map +1 -0
- package/_dist/registry.d.ts +12 -0
- package/_dist/registry.d.ts.map +1 -0
- package/_dist/schema.d.ts +4 -0
- package/_dist/schema.d.ts.map +1 -0
- package/_dist/state.d.ts +22 -0
- package/_dist/state.d.ts.map +1 -0
- package/_dist/value.d.ts +20 -0
- package/_dist/value.d.ts.map +1 -0
- package/_dist/views.d.ts +3 -0
- package/_dist/views.d.ts.map +1 -0
- package/census.js +50 -0
- package/census.js.map +1 -0
- package/census.ts +76 -0
- package/deno.json +1 -0
- package/door.js +54 -0
- package/door.js.map +1 -0
- package/door.ts +59 -0
- package/front.js +12 -0
- package/front.js.map +1 -0
- package/front.json +76 -0
- package/front.ts +13 -0
- package/grid.js +249 -0
- package/grid.js.map +1 -0
- package/grid.ts +395 -0
- package/host.js +20 -0
- package/host.js.map +1 -0
- package/host.ts +134 -0
- package/mod.js +20 -0
- package/mod.js.map +1 -0
- package/mod.ts +45 -0
- package/notes.js +184 -0
- package/notes.js.map +1 -0
- package/notes.ts +288 -0
- package/package.json +35 -4
- package/read.js +300 -0
- package/read.js.map +1 -0
- package/read.ts +386 -0
- package/reading.js +64 -0
- package/reading.js.map +1 -0
- package/reading.ts +73 -0
- package/registry.js +89 -0
- package/registry.js.map +1 -0
- package/registry.ts +89 -0
- package/rows.js +12 -0
- package/rows.js.map +1 -0
- package/rows.ts +26 -0
- package/schema.js +47 -0
- package/schema.js.map +1 -0
- package/schema.ts +70 -0
- package/state.js +85 -0
- package/state.js.map +1 -0
- package/state.ts +128 -0
- package/terminal-links.ts +16 -0
- package/value.js +67 -0
- package/value.js.map +1 -0
- package/value.ts +79 -0
- package/views.js +4 -0
- package/views.js.map +1 -0
- package/views.ts +6 -0
package/Held.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Held.js","sources":["./Held.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;CAqBC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoC;AACzG,YAAY,wBAA6B;AACzC,SACE,MAAM,MAAM,EACZ,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,MAAM,EACN,KAAK,EACL,OAAO,wBACmB;AAC5B,SAAS,IAAI,EAAE,MAAM,0BAA+B;AAEpD,SAAS,QAAQ,EAAE,GAAG,oBAAmB;AACzC,SAAS,SAAS,sBAAqB;AACvC,SAAS,OAAO,EAAE,KAAK,qBAAoB;AAC3C,SAAS,OAAO,qBAAoB;AACpC,SAAS,KAAK,qBAAoB;AAuBlC,IAAI,MAAM,CAAC,IAAc,IAAI,GAAG,QAAQ;AAExC,mEAAmE,GACnE,IAAI,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAA0C;EACtE,IAAI,MAAM,IAAI,MAAM,CAAC,GAAG;EACxB,IAAI,OAAO,CAAC,MAAc,qBACxB,EAAE,KAAK,IAAI,EAAE;MACX,GAAG;MACH,MAAM;MACN;MACA,IAAI,OAAO,OAAO,KAAK,OAAO;MAC9B,UAAU,CAAC,GAAG,KAAK;MACnB,GAAG,IAAI;IACT;EACF,IAAI,KAAK,QAAQ,IAAI;EACrB,qBAAO,EACL,GAAG,IAAI,CAAC,MAAM,EACd;IAAE,eAAe;EAAI,iBACrB,EAAE,UAAU,CAAC,GAAG,KAAK,SAAS;IAAE,QAAQ;EAAK,mBAC7C,EAAE,OAAO;IACP;IACA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;MAAE,QAAQ;QAAE,KAAK;MAAM;IAAE;IAC/C,UAAU,CAAC,IAAc,GAAG,GAAG,CAAC;QAAC;OAAE;IACnC,KAAK,KAAK,GAAG,CAAC;IACd;IACA,SAAS,GAAG,KAAK,GAAG,QAAQ;IAC5B,MAAM,CAAC,KAAO,OAAO,IAAI,IAAI;IAC7B;EACF;AACF,EAAC"}
|
package/Held.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an entity holds by its links, in the order they are read, put in
|
|
3
|
+
* order where it stands: `Held`. Each row is the entity a link leads to,
|
|
4
|
+
* drawn by its own renderer (the view `tile` names). Where the host takes
|
|
5
|
+
* edits, a row is picked up and dropped between two others, which writes the
|
|
6
|
+
* links' positions (`edge.ord`, @yaks/edge `placed`), and an entity dragged
|
|
7
|
+
* from elsewhere (@yaks/ux `drag`: a row of another list, of a desk) joins
|
|
8
|
+
* the list where it is dropped, linked by `tag`. Each row opens in place on
|
|
9
|
+
* the title and body of what it leads to, typed over where they stand
|
|
10
|
+
* (@yaks/ux `Edit.Text`), and read only where the host takes no edits. An
|
|
11
|
+
* open row is no drag handle: selecting its text, clicking into it and typing
|
|
12
|
+
* never pick it up.
|
|
13
|
+
*
|
|
14
|
+
* Its caller names the links and their order (the order its reader reads
|
|
15
|
+
* them in) and draws the heading around it.
|
|
16
|
+
*
|
|
17
|
+
* ```ts ignore
|
|
18
|
+
* h(Held, { io, from: eid, links, ends, tile: 'Topic.List.Tile', tag: 'contains', empty: 'nothing yet' })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX } from 'react'
|
|
25
|
+
import * as ui from '@yaks/ui'
|
|
26
|
+
import {
|
|
27
|
+
at as editAt,
|
|
28
|
+
disclosed,
|
|
29
|
+
disclosureAt,
|
|
30
|
+
Edit,
|
|
31
|
+
isOpen,
|
|
32
|
+
Order,
|
|
33
|
+
orderAt,
|
|
34
|
+
} from '@yaks/ux'
|
|
35
|
+
import { link, placed } from '@yaks/edge'
|
|
36
|
+
import type { Answer, Bundle, Io } from './host.ts'
|
|
37
|
+
import { relation, str } from './read.js'
|
|
38
|
+
import { relations } from './schema.js'
|
|
39
|
+
import { refusal, write } from './state.js'
|
|
40
|
+
import { mention } from './value.js'
|
|
41
|
+
import { Words } from './Words.js'
|
|
42
|
+
|
|
43
|
+
/** What a list of what an entity holds is drawn with. */
|
|
44
|
+
export type HeldProps = {
|
|
45
|
+
io: Io
|
|
46
|
+
/** the entity whose links these are */
|
|
47
|
+
from: string
|
|
48
|
+
/** its links, in the order they are read */
|
|
49
|
+
links: Bundle[]
|
|
50
|
+
/** the entities they lead to, whole */
|
|
51
|
+
ends?: Answer
|
|
52
|
+
/** the view each is drawn by */
|
|
53
|
+
tile: string
|
|
54
|
+
/** what a list with nothing on it says */
|
|
55
|
+
empty: string
|
|
56
|
+
/** the relation an entity joining from elsewhere is linked by; without
|
|
57
|
+
* one, none joins */
|
|
58
|
+
tag?: string
|
|
59
|
+
/** what else an entity joining from elsewhere writes, or `undefined` when
|
|
60
|
+
* it may not join */
|
|
61
|
+
join?: (to: string) => Bundle[] | undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let far = (b: Bundle) => str(b, 'edge', 'to')
|
|
65
|
+
|
|
66
|
+
/** A row opened in place: the title and body of what it leads to. */
|
|
67
|
+
let Detail = ({ io, end, owner }: { io: Io; end: Bundle; owner: string }) => {
|
|
68
|
+
let eid = end.entity.eid
|
|
69
|
+
let text = (prop: string, more: Record<string, unknown>) =>
|
|
70
|
+
h(Edit.Text, {
|
|
71
|
+
e: end,
|
|
72
|
+
comp: 'doc',
|
|
73
|
+
prop,
|
|
74
|
+
at: editAt(owner, eid, 'doc', prop),
|
|
75
|
+
readOnly: !io.edits,
|
|
76
|
+
...more,
|
|
77
|
+
})
|
|
78
|
+
let no = refusal(io, eid)
|
|
79
|
+
return h(
|
|
80
|
+
ui.Rows.Detail,
|
|
81
|
+
{ 'data-detail': eid },
|
|
82
|
+
h('strong', {}, text('title', { inline: true })),
|
|
83
|
+
h(Words, {
|
|
84
|
+
io,
|
|
85
|
+
e: end,
|
|
86
|
+
comp: 'doc',
|
|
87
|
+
prop: 'body',
|
|
88
|
+
at: editAt(owner, eid, 'doc', 'body'),
|
|
89
|
+
}),
|
|
90
|
+
no ? h(ui.Rows.More, { role: 'alert' }, no) : io.edits
|
|
91
|
+
? h(
|
|
92
|
+
ui.Rows.More,
|
|
93
|
+
{},
|
|
94
|
+
'double-click the title or the text to type over it',
|
|
95
|
+
)
|
|
96
|
+
: null,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** What an entity holds by its links, in order, each opened in place. */
|
|
101
|
+
export let Held = (
|
|
102
|
+
{ io, from, links, ends, tile, empty, tag, join }: HeldProps,
|
|
103
|
+
): JSX.Element => {
|
|
104
|
+
let held = new Map((ends?.rows ?? []).map((b) => [b.entity.eid, b]))
|
|
105
|
+
let rels = relations(io)
|
|
106
|
+
let seen = new Set<string>()
|
|
107
|
+
let rows = links.filter((b) => {
|
|
108
|
+
let to = far(b)
|
|
109
|
+
return to && !seen.has(to) && seen.add(to)
|
|
110
|
+
})
|
|
111
|
+
let named = [...new Set(rows.map((b) => relation(b, rels) ?? ''))]
|
|
112
|
+
let kinds = named.length > 1
|
|
113
|
+
let by = new Map(rows.map((b) => [far(b), b]))
|
|
114
|
+
let order = orderAt(`held/${from}/${tag ?? named.sort().join(' ')}`)
|
|
115
|
+
|
|
116
|
+
// A row put between two others, or an entity from elsewhere joining.
|
|
117
|
+
let place = (to: string, at: number) => {
|
|
118
|
+
let had = by.get(to)
|
|
119
|
+
if (had) return void write(io, from, placed(rows, had, at))
|
|
120
|
+
let more = tag && to != from ? join ? join(to) : [] : undefined
|
|
121
|
+
if (more) {
|
|
122
|
+
void write(io, from, [...more, ...placed(rows, link(from, tag!, to), at)])
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Whether the row leading to `to` is open, and what says so.
|
|
127
|
+
let opened = (to: string) => {
|
|
128
|
+
let at = disclosureAt(`held/${by.get(to)!.entity.eid}`)
|
|
129
|
+
let state = io.state(at) ?? { entity: { eid: at } }
|
|
130
|
+
return { state, open: isOpen(state) && !!held.get(to)?.doc }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let row = (to: string) => {
|
|
134
|
+
let b = by.get(to)!
|
|
135
|
+
let end = held.get(to)
|
|
136
|
+
let { state, open } = opened(to)
|
|
137
|
+
return [
|
|
138
|
+
h(
|
|
139
|
+
ui.Rows.Line,
|
|
140
|
+
{ 'data-held': to },
|
|
141
|
+
h(ui.Rows.Toggle, {
|
|
142
|
+
type: 'button',
|
|
143
|
+
disabled: !end?.doc,
|
|
144
|
+
'aria-expanded': open,
|
|
145
|
+
'aria-label': open ? 'close it' : 'open it here',
|
|
146
|
+
onClick: () => io.set([disclosed(state, !open)]),
|
|
147
|
+
}, open ? '▾' : '▸'),
|
|
148
|
+
h(
|
|
149
|
+
'div',
|
|
150
|
+
{},
|
|
151
|
+
kinds ? h(ui.Rows.Kind, {}, relation(b, rels)) : null,
|
|
152
|
+
end
|
|
153
|
+
? io.show(end, tile, {})
|
|
154
|
+
: ends?.ready
|
|
155
|
+
? [mention(io, to), ' is gone']
|
|
156
|
+
: h(ui.Loading, {}),
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
open && end ? h(Detail, { io, end, owner: b.entity.eid }) : null,
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return h(Order, {
|
|
164
|
+
e: io.state(order) ?? { entity: { eid: order } },
|
|
165
|
+
onChange: (b: Bundle) => io.set([b]),
|
|
166
|
+
ids: rows.map(far),
|
|
167
|
+
row,
|
|
168
|
+
onPlace: io.edits ? place : undefined,
|
|
169
|
+
open: (to) => opened(to).open,
|
|
170
|
+
empty,
|
|
171
|
+
})
|
|
172
|
+
}
|
package/History.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A history, newest first, off the journal (@yaks/journal): each transaction
|
|
3
|
+
* a moment on a timeline, when and by whom and through which session, and
|
|
4
|
+
* under it what each change made of a component, property by property: what
|
|
5
|
+
* it was before and what it became.
|
|
6
|
+
*
|
|
7
|
+
* An entity's history is the changes aimed at it; a transaction's is
|
|
8
|
+
* everything it wrote; a property's page shows the recent writes of its
|
|
9
|
+
* component that touched it. Wherever the changes are not all about one
|
|
10
|
+
* entity, each says which it was about.
|
|
11
|
+
*
|
|
12
|
+
* The changes are asked a page at a time (`_change` rows, by one column),
|
|
13
|
+
* and beside them, once they are in, the transactions that made them, the
|
|
14
|
+
* components they wrote and the people and sessions who wrote them, each by
|
|
15
|
+
* its eid. What a property was before is the value the next older change on
|
|
16
|
+
* the page gave it; the oldest change on a page says only what it wrote.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/ import { groupBy } from "@yaks/fp";
|
|
20
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
|
|
21
|
+
import { Timeline, Value } from "@yaks/ui";
|
|
22
|
+
import { paged, Paging } from "./grid.js";
|
|
23
|
+
import { chip } from "./schema.js";
|
|
24
|
+
import { about, Part, useNamed } from "./notes.js";
|
|
25
|
+
import { comp, named, str, unique } from "./read.js";
|
|
26
|
+
import { none, rows, waiting } from "./rows.js";
|
|
27
|
+
import { key } from "./state.js";
|
|
28
|
+
import { mention, reads } from "./value.js";
|
|
29
|
+
/** How many changes a page of history holds. */ export let CHANGES = 40;
|
|
30
|
+
// A change's value: the component as it was written, or null where it went.
|
|
31
|
+
let value = (b)=>comp(b, '_change').value;
|
|
32
|
+
// One property's change: what it was, and what it became, each as a person
|
|
33
|
+
// reads it (a reference by name, a moment in words, a hash cut short).
|
|
34
|
+
let moved = (io, name, prop, was, now, known)=>{
|
|
35
|
+
let p = io.vocab.prop(name, prop);
|
|
36
|
+
return /*#__PURE__*/ h('span', {
|
|
37
|
+
key: prop
|
|
38
|
+
}, /*#__PURE__*/ h(Value, {
|
|
39
|
+
mod: 'id'
|
|
40
|
+
}, prop), ' ', known ? [
|
|
41
|
+
reads(io, was, p),
|
|
42
|
+
' → '
|
|
43
|
+
] : null, reads(io, now, p));
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* What one change did to the component `name`, property by property, given
|
|
47
|
+
* the change before it (the next older one of the same component on the same
|
|
48
|
+
* entity) where the page holds it: each property that moved, or every one it
|
|
49
|
+
* wrote a value to when what came before is not known; only `prop`, where one
|
|
50
|
+
* is named.
|
|
51
|
+
*/ let did = (io, name, b, older, prop)=>{
|
|
52
|
+
let now = value(b);
|
|
53
|
+
if (now == null) return [
|
|
54
|
+
name == 'entity' ? 'deleted' : 'removed'
|
|
55
|
+
];
|
|
56
|
+
let was = older ? value(older) ?? {} : undefined;
|
|
57
|
+
let props = Object.keys(now).filter((p)=>(!prop || p == prop) && (was ? JSON.stringify(was[p]) != JSON.stringify(now[p]) : now[p] != null));
|
|
58
|
+
return props.length ? props.map((p)=>moved(io, name, p, was?.[p], now[p], !!was)) : [
|
|
59
|
+
'wrote what it held'
|
|
60
|
+
];
|
|
61
|
+
};
|
|
62
|
+
// Every entity the values of these changes name, so each reads by name.
|
|
63
|
+
let mentioned = (all)=>all.flatMap((b)=>Object.values(value(b) ?? {}).filter(named)).slice(0, 60);
|
|
64
|
+
/** A history: an entity's, a transaction's, or a component's writes. */ export let History = (p)=>{
|
|
65
|
+
let { e, io } = p;
|
|
66
|
+
let eid = e.entity.eid;
|
|
67
|
+
let where = p.where ?? `${e._tx ? 'tx' : 'target'}=${eid}`;
|
|
68
|
+
let about1 = !where.startsWith('target=');
|
|
69
|
+
let base = `._change&._change.${where}`;
|
|
70
|
+
let heading = p.heading ?? 'History';
|
|
71
|
+
let id = key(eid, heading);
|
|
72
|
+
// Newest first: a window runs newest first by the changes' own ids, which
|
|
73
|
+
// rise with their transactions, and an index answers it (an order by `tx`
|
|
74
|
+
// would sort every change of a component).
|
|
75
|
+
let page = paged(io, id, base, {
|
|
76
|
+
size: CHANGES
|
|
77
|
+
});
|
|
78
|
+
let got = io.ask({
|
|
79
|
+
rows: p.once ? {
|
|
80
|
+
query: page,
|
|
81
|
+
once: true
|
|
82
|
+
} : page,
|
|
83
|
+
...p.once ? {} : {
|
|
84
|
+
total: `${base}&.count`
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
let all = rows(got.rows).toSorted((a, b)=>str(b, '_change', 'tx').localeCompare(str(a, '_change', 'tx')));
|
|
88
|
+
let txs = unique(all.map((b)=>str(b, '_change', 'tx')));
|
|
89
|
+
let comps = unique(all.map((b)=>str(b, '_change', 'comp')));
|
|
90
|
+
io.ask(all.length ? {
|
|
91
|
+
txs: `._tx&.entity.eid=${txs.join(',')}`,
|
|
92
|
+
comps: `._comp&.entity.eid=${comps.join(',')}&.fields=_comp.name`
|
|
93
|
+
} : {});
|
|
94
|
+
let t = (tx)=>comp(io.get(tx), '_tx');
|
|
95
|
+
useNamed(io, [
|
|
96
|
+
...txs.flatMap((x)=>[
|
|
97
|
+
t(x).by,
|
|
98
|
+
t(x).via
|
|
99
|
+
]),
|
|
100
|
+
...about1 ? all.map((b)=>str(b, '_change', 'target')) : []
|
|
101
|
+
]);
|
|
102
|
+
useNamed(io, mentioned(all));
|
|
103
|
+
let name = (b)=>str(io.get(str(b, '_change', 'comp')), '_comp', 'name') || '…';
|
|
104
|
+
// The next older change of the same component on the same entity.
|
|
105
|
+
let older = (b)=>all.slice(all.indexOf(b) + 1).find((o)=>str(o, '_change', 'comp') == str(b, '_change', 'comp') && str(o, '_change', 'target') == str(b, '_change', 'target'));
|
|
106
|
+
let told = p.prop ? all.filter((b)=>p.prop in (value(b) ?? {})) : all;
|
|
107
|
+
let moments = [
|
|
108
|
+
...groupBy(told, (b)=>str(b, '_change', 'tx'))
|
|
109
|
+
];
|
|
110
|
+
let total = got.total?.count;
|
|
111
|
+
let target = (b)=>str(b, '_change', 'target');
|
|
112
|
+
// An entity's own history opens each moment's version, but the one that
|
|
113
|
+
// deleted it, which left nothing to read.
|
|
114
|
+
let opens = (cs)=>!about1 && io.past && !cs.some((b)=>name(b) == 'entity' && value(b) == null);
|
|
115
|
+
return /*#__PURE__*/ h(Part, {
|
|
116
|
+
io,
|
|
117
|
+
eid,
|
|
118
|
+
subject: about(io, e),
|
|
119
|
+
heading,
|
|
120
|
+
count: total,
|
|
121
|
+
notes: p.notes
|
|
122
|
+
}, waiting(got.rows && {
|
|
123
|
+
...got.rows,
|
|
124
|
+
rows: told
|
|
125
|
+
}) ?? /*#__PURE__*/ h('div', {}, !told.length ? none() : /*#__PURE__*/ h(Timeline, {}, moments.map(([x, cs])=>{
|
|
126
|
+
let w = t(x);
|
|
127
|
+
let by = typeof w.by == 'string' ? w.by : '';
|
|
128
|
+
let via = typeof w.via == 'string' && w.via != by ? w.via : '';
|
|
129
|
+
return /*#__PURE__*/ h(Timeline.Item, {
|
|
130
|
+
key: x
|
|
131
|
+
}, /*#__PURE__*/ h(Timeline.When, {}, /*#__PURE__*/ h('a', {
|
|
132
|
+
href: io.link(x)
|
|
133
|
+
}, w.at ? io.when(String(w.at)) : `#${w.seq ?? '…'}`), opens(cs) ? [
|
|
134
|
+
' · ',
|
|
135
|
+
/*#__PURE__*/ h('a', {
|
|
136
|
+
href: io.past(eid, x)
|
|
137
|
+
}, 'as it was')
|
|
138
|
+
] : null), /*#__PURE__*/ h(Timeline.Who, {}, by ? mention(io, by) : ''), via ? [
|
|
139
|
+
'via',
|
|
140
|
+
/*#__PURE__*/ h(Timeline.Who, {}, mention(io, via))
|
|
141
|
+
] : null, cs.map((b)=>/*#__PURE__*/ h(Timeline.What, {
|
|
142
|
+
key: b.entity.eid
|
|
143
|
+
}, about1 ? mention(io, target(b)) : null, chip(io, name(b)), ...did(io, name(b), b, older(b), p.prop))));
|
|
144
|
+
})), /*#__PURE__*/ h(Paging, {
|
|
145
|
+
io,
|
|
146
|
+
id,
|
|
147
|
+
shown: all.length,
|
|
148
|
+
last: all.at(-1)?.entity.eid,
|
|
149
|
+
size: CHANGES,
|
|
150
|
+
total,
|
|
151
|
+
steps: [
|
|
152
|
+
'‹ newer',
|
|
153
|
+
'older ›'
|
|
154
|
+
]
|
|
155
|
+
})));
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=History.js.map
|
package/History.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"History.js","sources":["./History.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;CAkBC,GAED,SAAS,OAAO,wBAA6B;AAC7C,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,gBAAoD;AACzH,SAAS,QAAQ,EAAE,KAAK,wBAA6B;AAErD,SAAS,KAAK,EAAE,MAAM,oBAAmB;AACzC,SAAS,IAAI,sBAAqB;AAClC,SAAS,KAAK,EAAE,IAAI,EAAE,QAAQ,qBAAoB;AAClD,SAAS,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAmB;AACpD,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,oBAAmB;AAC/C,SAAS,GAAG,qBAAoB;AAChC,SAAS,OAAO,EAAE,KAAK,qBAAoB;AAE3C,8CAA8C,GAC9C,OAAO,IAAI,UAAU,GAAE;AAIvB,4EAA4E;AAC5E,IAAI,QAAQ,CAAC,IAAc,KAAK,GAAG,WAAW,KAAK;AAEnD,2EAA2E;AAC3E,uEAAuE;AACvE,IAAI,QAAQ,CACV,IACA,MACA,MACA,KACA,KACA;EAEA,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM;EAC5B,qBAAO,EACL,QACA;IAAE,KAAK;EAAK,iBACZ,EAAE,OAAO;IAAE,KAAK;EAAK,GAAG,OACxB,KACA,QAAQ;IAAC,MAAM,IAAI,KAAK;IAAI;GAAM,GAAG,MACrC,MA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AE,KAAK;QAAE,MAAM,GAAG,IAAI,CAAE,KAAK;MAAG,GAAG;KAAa,GACxD,qBAEN,EAAE,SAAS,GAAG,EAAE,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,KAC3C,MAAM;MAAC;oBAAO,EAAE,SAAS,GAAG,EAAE,CAAC,GAAG,QAAQ,IAAI;KAAM,GAAG,MACvD,GAAG,GAAG,CAAC,CAAC,kBACN,EACE,SAAS,IAAI,EACb;QAAE,KAAK,EAAE,MAAM,CAAC,GAAG;MAAC,GACpB,SAAS,QAAQ,IAAI,OAAO,MAAM,MAClC,KAAK,IAAI,KAAK,QACX,IAAI,IAAI,KAAK,IAAI,GAAG,MAAM,IAAI,EAAE,IAAI;EAI/C,mBAEF,EAAE,QAAQ;IACR;IACA;IACA,OAAO,IAAI,MAAM;IACjB,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,OAAO;IACzB,MAAM;IACN;IACA,OAAO;MAAC;MAAW;KAAU;EAC/B;AAGN,EAAC"}
|
package/History.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A history, newest first, off the journal (@yaks/journal): each transaction
|
|
3
|
+
* a moment on a timeline, when and by whom and through which session, and
|
|
4
|
+
* under it what each change made of a component, property by property: what
|
|
5
|
+
* it was before and what it became.
|
|
6
|
+
*
|
|
7
|
+
* An entity's history is the changes aimed at it; a transaction's is
|
|
8
|
+
* everything it wrote; a property's page shows the recent writes of its
|
|
9
|
+
* component that touched it. Wherever the changes are not all about one
|
|
10
|
+
* entity, each says which it was about.
|
|
11
|
+
*
|
|
12
|
+
* The changes are asked a page at a time (`_change` rows, by one column),
|
|
13
|
+
* and beside them, once they are in, the transactions that made them, the
|
|
14
|
+
* components they wrote and the people and sessions who wrote them, each by
|
|
15
|
+
* its eid. What a property was before is the value the next older change on
|
|
16
|
+
* the page gave it; the oldest change on a page says only what it wrote.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { groupBy } from '@yaks/fp'
|
|
22
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
|
|
23
|
+
import { Timeline, Value } from '@yaks/ui'
|
|
24
|
+
import type { Bundle, Io } from './host.ts'
|
|
25
|
+
import { paged, Paging } from './grid.js'
|
|
26
|
+
import { chip } from './schema.js'
|
|
27
|
+
import { about, Part, useNamed } from './notes.js'
|
|
28
|
+
import { comp, named, str, unique } from './read.js'
|
|
29
|
+
import { none, rows, waiting } from './rows.js'
|
|
30
|
+
import { key } from './state.js'
|
|
31
|
+
import { mention, reads } from './value.js'
|
|
32
|
+
|
|
33
|
+
/** How many changes a page of history holds. */
|
|
34
|
+
export let CHANGES = 40
|
|
35
|
+
|
|
36
|
+
type Row = Record<string, unknown>
|
|
37
|
+
|
|
38
|
+
// A change's value: the component as it was written, or null where it went.
|
|
39
|
+
let value = (b: Bundle) => comp(b, '_change').value as Row | null | undefined
|
|
40
|
+
|
|
41
|
+
// One property's change: what it was, and what it became, each as a person
|
|
42
|
+
// reads it (a reference by name, a moment in words, a hash cut short).
|
|
43
|
+
let moved = (
|
|
44
|
+
io: Io,
|
|
45
|
+
name: string,
|
|
46
|
+
prop: string,
|
|
47
|
+
was: unknown,
|
|
48
|
+
now: unknown,
|
|
49
|
+
known: boolean,
|
|
50
|
+
) => {
|
|
51
|
+
let p = io.vocab.prop(name, prop)
|
|
52
|
+
return h(
|
|
53
|
+
'span',
|
|
54
|
+
{ key: prop },
|
|
55
|
+
h(Value, { mod: 'id' }, prop),
|
|
56
|
+
' ',
|
|
57
|
+
known ? [reads(io, was, p), ' → '] : null,
|
|
58
|
+
reads(io, now, p),
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* What one change did to the component `name`, property by property, given
|
|
64
|
+
* the change before it (the next older one of the same component on the same
|
|
65
|
+
* entity) where the page holds it: each property that moved, or every one it
|
|
66
|
+
* wrote a value to when what came before is not known; only `prop`, where one
|
|
67
|
+
* is named.
|
|
68
|
+
*/
|
|
69
|
+
let did = (
|
|
70
|
+
io: Io,
|
|
71
|
+
name: string,
|
|
72
|
+
b: Bundle,
|
|
73
|
+
older?: Bundle,
|
|
74
|
+
prop?: string,
|
|
75
|
+
): ReactNode[] => {
|
|
76
|
+
let now = value(b)
|
|
77
|
+
if (now == null) return [name == 'entity' ? 'deleted' : 'removed']
|
|
78
|
+
let was = older ? value(older) ?? {} : undefined
|
|
79
|
+
let props = Object.keys(now).filter((p) =>
|
|
80
|
+
(!prop || p == prop) &&
|
|
81
|
+
(was ? JSON.stringify(was[p]) != JSON.stringify(now[p]) : now[p] != null)
|
|
82
|
+
)
|
|
83
|
+
return props.length
|
|
84
|
+
? props.map((p) => moved(io, name, p, was?.[p], now[p], !!was))
|
|
85
|
+
: ['wrote what it held']
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Every entity the values of these changes name, so each reads by name.
|
|
89
|
+
let mentioned = (all: Bundle[]): string[] =>
|
|
90
|
+
all.flatMap((b) => Object.values(value(b) ?? {}).filter(named)).slice(0, 60)
|
|
91
|
+
|
|
92
|
+
/** What a history is drawn with. */
|
|
93
|
+
export type HistoryProps = {
|
|
94
|
+
e: Bundle
|
|
95
|
+
io: Io
|
|
96
|
+
notes: Map<string, Bundle[]>
|
|
97
|
+
/** its heading (default `History`) */
|
|
98
|
+
heading?: string
|
|
99
|
+
/** the changes it tells, as a test on one `_change` column (default: those
|
|
100
|
+
* aimed at `e`, or those `e` wrote when it is a transaction) */
|
|
101
|
+
where?: string
|
|
102
|
+
/** only the changes that wrote this property, and only it */
|
|
103
|
+
prop?: string
|
|
104
|
+
/** asked once, not kept live: for changes no index finds quickly (README,
|
|
105
|
+
* Limits); nor counted, for the same reason */
|
|
106
|
+
once?: boolean
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A history: an entity's, a transaction's, or a component's writes. */
|
|
110
|
+
export let History = (p: HistoryProps): JSX.Element => {
|
|
111
|
+
let { e, io } = p
|
|
112
|
+
let eid = e.entity.eid
|
|
113
|
+
let where = p.where ?? `${e._tx ? 'tx' : 'target'}=${eid}`
|
|
114
|
+
let about1 = !where.startsWith('target=')
|
|
115
|
+
let base = `._change&._change.${where}`
|
|
116
|
+
let heading = p.heading ?? 'History'
|
|
117
|
+
let id = key(eid, heading)
|
|
118
|
+
// Newest first: a window runs newest first by the changes' own ids, which
|
|
119
|
+
// rise with their transactions, and an index answers it (an order by `tx`
|
|
120
|
+
// would sort every change of a component).
|
|
121
|
+
let page = paged(io, id, base, { size: CHANGES })
|
|
122
|
+
let got = io.ask({
|
|
123
|
+
rows: p.once ? { query: page, once: true } : page,
|
|
124
|
+
...p.once ? {} : { total: `${base}&.count` },
|
|
125
|
+
})
|
|
126
|
+
let all = rows(got.rows).toSorted((a, b) =>
|
|
127
|
+
str(b, '_change', 'tx').localeCompare(str(a, '_change', 'tx'))
|
|
128
|
+
)
|
|
129
|
+
let txs = unique(all.map((b) => str(b, '_change', 'tx')))
|
|
130
|
+
let comps = unique(all.map((b) => str(b, '_change', 'comp')))
|
|
131
|
+
io.ask(
|
|
132
|
+
all.length
|
|
133
|
+
? {
|
|
134
|
+
txs: `._tx&.entity.eid=${txs.join(',')}`,
|
|
135
|
+
comps: `._comp&.entity.eid=${comps.join(',')}&.fields=_comp.name`,
|
|
136
|
+
}
|
|
137
|
+
: {},
|
|
138
|
+
)
|
|
139
|
+
let t = (tx: string) => comp(io.get(tx), '_tx')
|
|
140
|
+
useNamed(io, [
|
|
141
|
+
...txs.flatMap((x) => [t(x).by as string, t(x).via as string]),
|
|
142
|
+
...about1 ? all.map((b) => str(b, '_change', 'target')) : [],
|
|
143
|
+
])
|
|
144
|
+
useNamed(io, mentioned(all))
|
|
145
|
+
let name = (b: Bundle) =>
|
|
146
|
+
str(io.get(str(b, '_change', 'comp')), '_comp', 'name') || '…'
|
|
147
|
+
// The next older change of the same component on the same entity.
|
|
148
|
+
let older = (b: Bundle) =>
|
|
149
|
+
all.slice(all.indexOf(b) + 1).find((o) =>
|
|
150
|
+
str(o, '_change', 'comp') == str(b, '_change', 'comp') &&
|
|
151
|
+
str(o, '_change', 'target') == str(b, '_change', 'target')
|
|
152
|
+
)
|
|
153
|
+
let told = p.prop ? all.filter((b) => p.prop! in (value(b) ?? {})) : all
|
|
154
|
+
let moments = [...groupBy(told, (b) => str(b, '_change', 'tx'))]
|
|
155
|
+
let total = got.total?.count
|
|
156
|
+
let target = (b: Bundle) => str(b, '_change', 'target')
|
|
157
|
+
// An entity's own history opens each moment's version, but the one that
|
|
158
|
+
// deleted it, which left nothing to read.
|
|
159
|
+
let opens = (cs: Bundle[]) =>
|
|
160
|
+
!about1 && io.past &&
|
|
161
|
+
!cs.some((b) => name(b) == 'entity' && value(b) == null)
|
|
162
|
+
return h(
|
|
163
|
+
Part,
|
|
164
|
+
{ io, eid, subject: about(io, e), heading, count: total, notes: p.notes },
|
|
165
|
+
waiting(got.rows && { ...got.rows, rows: told }) ?? h(
|
|
166
|
+
'div',
|
|
167
|
+
{},
|
|
168
|
+
!told.length ? none() : h(
|
|
169
|
+
Timeline,
|
|
170
|
+
{},
|
|
171
|
+
moments.map(([x, cs]) => {
|
|
172
|
+
let w = t(x)
|
|
173
|
+
let by = typeof w.by == 'string' ? w.by : ''
|
|
174
|
+
let via = typeof w.via == 'string' && w.via != by ? w.via : ''
|
|
175
|
+
return h(
|
|
176
|
+
Timeline.Item,
|
|
177
|
+
{ key: x },
|
|
178
|
+
h(
|
|
179
|
+
Timeline.When,
|
|
180
|
+
{},
|
|
181
|
+
h(
|
|
182
|
+
'a',
|
|
183
|
+
{ href: io.link(x) },
|
|
184
|
+
w.at ? io.when(String(w.at)) : `#${w.seq ?? '…'}`,
|
|
185
|
+
),
|
|
186
|
+
opens(cs)
|
|
187
|
+
? [' · ', h('a', { href: io.past!(eid, x) }, 'as it was')]
|
|
188
|
+
: null,
|
|
189
|
+
),
|
|
190
|
+
h(Timeline.Who, {}, by ? mention(io, by) : ''),
|
|
191
|
+
via ? ['via', h(Timeline.Who, {}, mention(io, via))] : null,
|
|
192
|
+
cs.map((b) =>
|
|
193
|
+
h(
|
|
194
|
+
Timeline.What,
|
|
195
|
+
{ key: b.entity.eid },
|
|
196
|
+
about1 ? mention(io, target(b)) : null,
|
|
197
|
+
chip(io, name(b)),
|
|
198
|
+
...did(io, name(b), b, older(b), p.prop),
|
|
199
|
+
)
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
}),
|
|
203
|
+
),
|
|
204
|
+
h(Paging, {
|
|
205
|
+
io,
|
|
206
|
+
id,
|
|
207
|
+
shown: all.length,
|
|
208
|
+
last: all.at(-1)?.entity.eid,
|
|
209
|
+
size: CHANGES,
|
|
210
|
+
total,
|
|
211
|
+
steps: ['‹ newer', 'older ›'],
|
|
212
|
+
}),
|
|
213
|
+
),
|
|
214
|
+
)
|
|
215
|
+
}
|