@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/grid.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A table of things, the way every inspector page draws one: @yaks/ui's
|
|
3
|
+
* `Table`, a column per heading and a row per thing. A press on a row opens
|
|
4
|
+
* the entity it stands for (`io.go` to its `link`), unless the press was on
|
|
5
|
+
* a link or a value inside it; the keyboard can rest on a row, for Enter to
|
|
6
|
+
* open it (./main.ts). A press on a heading whose column can sort runs the
|
|
7
|
+
* rows by it, then back the other way, then as they came.
|
|
8
|
+
* A long table shows a page of rows at a time, with a `Pager` under it. How
|
|
9
|
+
* the rows run and which page shows are the table's state in the page's own
|
|
10
|
+
* graph (./state.ts `grid`), so a page shown again shows as it was left; a
|
|
11
|
+
* page that keeps its order elsewhere (a query's page, in its line and so its
|
|
12
|
+
* address) hands it in as `sorts`.
|
|
13
|
+
*
|
|
14
|
+
* A table paged by the graph asks for one page at a time (`paged`), and the
|
|
15
|
+
* graph sorts it; one whose rows are all in hand (a tally, a component's
|
|
16
|
+
* properties) pages them itself (`local`), and sorts them by a column's
|
|
17
|
+
* `value` (`run`, @yaks/ux `sortRows`): numbers as numbers, an empty value
|
|
18
|
+
* last either way.
|
|
19
|
+
*
|
|
20
|
+
* A table whose rows hold rows is a tree (`holds`): a row holding some wears a
|
|
21
|
+
* toggle, and once opened the rows it holds show under it, a step in, run by
|
|
22
|
+
* the same column as their parent's; which rows are open is the table's state
|
|
23
|
+
* too. A long tree pages the rows it shows.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, Fragment } from "react";
|
|
27
|
+
import { conjoin, order as ordered, stringify } from "@yaks/query";
|
|
28
|
+
import { Pager, Table } from "@yaks/ui";
|
|
29
|
+
import { sortRows } from "@yaks/ux";
|
|
30
|
+
import { count } from "./read.js";
|
|
31
|
+
import { none } from "./rows.js";
|
|
32
|
+
import { grid, turned } from "./state.js";
|
|
33
|
+
/** How many rows a page of a table holds. */ export let SIZE = 50;
|
|
34
|
+
// What a column sorts by in a table's state: the property the graph runs by,
|
|
35
|
+
// or, where the table holds its rows, the column's name.
|
|
36
|
+
let sorted = (c)=>c.sort ?? (c.value ? c.name : undefined);
|
|
37
|
+
/**
|
|
38
|
+
* Rows a table holds, run by the column its order names (`-` before it when
|
|
39
|
+
* they run down), or as they came.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { type Column, run } from './grid.ts'
|
|
43
|
+
* let rows = [2, 3, 1].map((n) => ({ entity: { eid: `${n}` } }))
|
|
44
|
+
* let cols: Column[] = [
|
|
45
|
+
* { name: 'n', value: (b) => Number(b.entity.eid), cell: () => '' },
|
|
46
|
+
* ]
|
|
47
|
+
* run(rows, cols, '-n').map((b) => b.entity.eid) // ['3', '2', '1']
|
|
48
|
+
* run(rows, cols, null).map((b) => b.entity.eid) // ['2', '3', '1']
|
|
49
|
+
* ```
|
|
50
|
+
*/ export let run = (rows, columns, order)=>{
|
|
51
|
+
let c = columns.find((c)=>c.value && c.name == order?.replace(/^-/, ''));
|
|
52
|
+
if (!c?.value) return rows;
|
|
53
|
+
let v = c.value;
|
|
54
|
+
return sortRows(rows, (b)=>[
|
|
55
|
+
v(b)
|
|
56
|
+
], {
|
|
57
|
+
column: 0,
|
|
58
|
+
direction: order.startsWith('-') ? 'desc' : 'asc'
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The rows a tree shows, in order: each level run by `order` (`run`), and
|
|
63
|
+
* under each row `open` names the rows it `holds`, a step deeper.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { type Column, unfold } from './grid.ts'
|
|
67
|
+
* let b = (eid: string) => ({ entity: { eid } })
|
|
68
|
+
* let kids: Record<string, string[]> = { p: ['c2', 'c1'], c1: ['x'] }
|
|
69
|
+
* let holds = (r: { entity: { eid: string } }) =>
|
|
70
|
+
* (kids[r.entity.eid] ?? []).map(b)
|
|
71
|
+
* let cols: Column[] = [{ name: 'n', value: (r) => r.entity.eid, cell: () => '' }]
|
|
72
|
+
* unfold([b('q'), b('p')], cols, 'n', ['p', 'c1'], holds)
|
|
73
|
+
* .map((r) => `${r.depth}${r.b.entity.eid}${r.holds ? '+' : ''}`)
|
|
74
|
+
* // ['0p+', '1c1+', '2x', '1c2', '0q']
|
|
75
|
+
* ```
|
|
76
|
+
*/ export let unfold = (rows, columns, order, open, holds, depth = 0)=>run(rows, columns, order).flatMap((b)=>{
|
|
77
|
+
let kids = holds(b);
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
b,
|
|
81
|
+
depth,
|
|
82
|
+
holds: kids.length > 0
|
|
83
|
+
},
|
|
84
|
+
...kids.length && open.includes(b.entity.eid) ? unfold(kids, columns, order, open, holds, depth + 1) : []
|
|
85
|
+
];
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* The line for the page of `base`'s rows the table `id` shows: run by its
|
|
89
|
+
* order (or `order`, when the table names none, with no value `last` when
|
|
90
|
+
* asked), after the last row of the page before, `size` of them.
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { paged } from './grid.ts'
|
|
94
|
+
* let io = { state: () => ({ entity: { eid: 't' }, table: { order: '-task.status', after: ['e9'] } }) }
|
|
95
|
+
* paged(io, 't', '.task') // '.task&.order=-task.status&.after=e9&.limit=50'
|
|
96
|
+
* paged({ state: () => undefined }, 't', '.task', { order: 'doc.title', last: true })
|
|
97
|
+
* // '.task&.order[last]=doc.title&.limit=50'
|
|
98
|
+
* ```
|
|
99
|
+
*/ export let paged = (io, id, base, { order, last, size = SIZE } = {})=>{
|
|
100
|
+
let g = grid(io, id);
|
|
101
|
+
let by = g.order || order;
|
|
102
|
+
return conjoin(base, by ? stringify(ordered(by, !g.order && !!last)) : '', g.after?.length ? `.after=${g.after.at(-1)}` : '', `.limit=${size}`);
|
|
103
|
+
};
|
|
104
|
+
/** Whether a press landed on something of its own inside the row: a link, a
|
|
105
|
+
* control, a value that can be changed (@yaks/ux). */ let own = (target)=>{
|
|
106
|
+
for(let n = target; n && !/\bTable_Row\b/.test(n.className ?? ''); n = n.parentNode){
|
|
107
|
+
if ([
|
|
108
|
+
'a',
|
|
109
|
+
'button',
|
|
110
|
+
'input',
|
|
111
|
+
'select',
|
|
112
|
+
'textarea'
|
|
113
|
+
].includes(n.localName)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (/\b(Prop-live|Edit)\b/.test(n.className ?? '')) return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
120
|
+
/** Where a page of rows sits, and a step to the page either side of it: the
|
|
121
|
+
* way back is the last row of each page before, kept in the table's state.
|
|
122
|
+
* Nothing, for a table that fits on one page. */ export let Paging = (p)=>{
|
|
123
|
+
let { io, id, shown, size, total } = p;
|
|
124
|
+
let after = grid(io, id).after ?? [];
|
|
125
|
+
let page = after.length;
|
|
126
|
+
let to = page * size + shown;
|
|
127
|
+
let more = total != null ? to < total : shown == size;
|
|
128
|
+
let [back, next] = p.steps ?? [
|
|
129
|
+
'‹ back',
|
|
130
|
+
'next ›'
|
|
131
|
+
];
|
|
132
|
+
let step = (d)=>io.set(turned(id, {
|
|
133
|
+
after: d < 0 ? after.slice(0, -1) : [
|
|
134
|
+
...after,
|
|
135
|
+
p.last ?? String(page)
|
|
136
|
+
]
|
|
137
|
+
}));
|
|
138
|
+
return page || more ? /*#__PURE__*/ h(Pager, {}, /*#__PURE__*/ h(Pager.Span, {}, `${count(page * size + 1)}–${count(to)}`, total != null ? ` of ${count(total)}` : ''), /*#__PURE__*/ h(Pager.Step, {
|
|
139
|
+
type: 'button',
|
|
140
|
+
disabled: !page,
|
|
141
|
+
onClick: ()=>step(-1)
|
|
142
|
+
}, back), /*#__PURE__*/ h(Pager.Step, {
|
|
143
|
+
type: 'button',
|
|
144
|
+
disabled: !more,
|
|
145
|
+
onClick: ()=>step(1)
|
|
146
|
+
}, next)) : null;
|
|
147
|
+
};
|
|
148
|
+
// Which way a column runs: its heading's variant.
|
|
149
|
+
let way = (order, c)=>!sorted(c) ? undefined : order == sorted(c) ? 'asc' : order == `-${sorted(c)}` ? 'desc' : undefined;
|
|
150
|
+
// What a tree row's first cell starts with: an indent for each row it is
|
|
151
|
+
// under, then its toggle, or an indent where it holds none.
|
|
152
|
+
let Stem = ({ io, id, at, open })=>{
|
|
153
|
+
let eid = at.b.entity.eid;
|
|
154
|
+
let shown = open.includes(eid);
|
|
155
|
+
return /*#__PURE__*/ h(Fragment, null, Array.from({
|
|
156
|
+
length: at.depth
|
|
157
|
+
}, (_, i)=>/*#__PURE__*/ h(Table.Indent, {
|
|
158
|
+
key: i
|
|
159
|
+
})), at.holds ? /*#__PURE__*/ h(Table.Toggle, {
|
|
160
|
+
type: 'button',
|
|
161
|
+
mod: shown && 'open',
|
|
162
|
+
'aria-expanded': shown,
|
|
163
|
+
'aria-label': 'what it holds',
|
|
164
|
+
onClick: ()=>io.set(turned(id, {
|
|
165
|
+
open: shown ? open.filter((o)=>o != eid) : [
|
|
166
|
+
...open,
|
|
167
|
+
eid
|
|
168
|
+
]
|
|
169
|
+
}))
|
|
170
|
+
}) : /*#__PURE__*/ h(Table.Indent, {}));
|
|
171
|
+
};
|
|
172
|
+
/** A table of things, paged, its rows opened and its columns sorted. */ export let Grid = (p)=>{
|
|
173
|
+
let { io, id, columns, local, holds } = p;
|
|
174
|
+
let size = p.size ?? SIZE;
|
|
175
|
+
let g = grid(io, id);
|
|
176
|
+
let order = p.sorts ? p.sorts.order : g.order;
|
|
177
|
+
let open = g.open ?? [];
|
|
178
|
+
let tree = holds ? unfold(p.rows, columns, order, open, holds) : (local ? run(p.rows, columns, order) : p.rows).map((b)=>({
|
|
179
|
+
b,
|
|
180
|
+
depth: 0,
|
|
181
|
+
holds: false
|
|
182
|
+
}));
|
|
183
|
+
let rows = tree.map((t)=>t.b);
|
|
184
|
+
let after = g.after ?? [];
|
|
185
|
+
let page = after.length;
|
|
186
|
+
let shown = local || holds ? tree.slice(page * size, (page + 1) * size) : tree;
|
|
187
|
+
let pick = p.pick === false ? ()=>undefined : p.pick ?? ((b)=>b.entity.eid);
|
|
188
|
+
let sort = (c)=>{
|
|
189
|
+
let by = sorted(c);
|
|
190
|
+
let next = order == by ? `-${by}` : order == `-${by}` ? null : by;
|
|
191
|
+
if (p.sorts) p.sorts.to(next ?? undefined);
|
|
192
|
+
else io.set(turned(id, {
|
|
193
|
+
order: next,
|
|
194
|
+
after: []
|
|
195
|
+
}));
|
|
196
|
+
};
|
|
197
|
+
if (!rows.length && !page) return none();
|
|
198
|
+
return /*#__PURE__*/ h(Fragment, null, /*#__PURE__*/ h(Table, {
|
|
199
|
+
'data-table': id,
|
|
200
|
+
...holds ? {
|
|
201
|
+
role: 'treegrid'
|
|
202
|
+
} : {},
|
|
203
|
+
cols: columns.map((c)=>c.mod)
|
|
204
|
+
}, /*#__PURE__*/ h(Table.Head, {}, /*#__PURE__*/ h(Table.Row, {}, columns.map((c)=>{
|
|
205
|
+
let dir = way(order, c);
|
|
206
|
+
return /*#__PURE__*/ h(Table.Heading, {
|
|
207
|
+
key: c.name,
|
|
208
|
+
mod: [
|
|
209
|
+
sorted(c) && 'sorts',
|
|
210
|
+
dir,
|
|
211
|
+
c.mod == 'num' && 'num'
|
|
212
|
+
],
|
|
213
|
+
'aria-sort': sorted(c) ? dir == 'asc' ? 'ascending' : dir == 'desc' ? 'descending' : 'none' : undefined
|
|
214
|
+
}, sorted(c) ? /*#__PURE__*/ h(Table.Sort, {
|
|
215
|
+
type: 'button',
|
|
216
|
+
onClick: ()=>sort(c)
|
|
217
|
+
}, c.name) : c.name);
|
|
218
|
+
}))), /*#__PURE__*/ h(Table.Body, {}, shown.map((t)=>{
|
|
219
|
+
let { b } = t;
|
|
220
|
+
let at = pick(b);
|
|
221
|
+
return /*#__PURE__*/ h(Table.Row, {
|
|
222
|
+
key: b.entity.eid,
|
|
223
|
+
mod: at && 'picks',
|
|
224
|
+
'data-pick': at,
|
|
225
|
+
'aria-level': holds ? t.depth + 1 : undefined,
|
|
226
|
+
tabIndex: at ? -1 : undefined,
|
|
227
|
+
onClick: at ? (ev)=>{
|
|
228
|
+
// Step aside without consuming the bubbled link click.
|
|
229
|
+
if (!own(ev.target)) io.go(io.link(at));
|
|
230
|
+
} : undefined
|
|
231
|
+
}, columns.map((c, i)=>/*#__PURE__*/ h(Table.Cell, {
|
|
232
|
+
key: c.name,
|
|
233
|
+
mod: c.mod
|
|
234
|
+
}, holds && !i ? /*#__PURE__*/ h(Stem, {
|
|
235
|
+
io,
|
|
236
|
+
id,
|
|
237
|
+
at: t,
|
|
238
|
+
open
|
|
239
|
+
}) : null, c.cell(b))));
|
|
240
|
+
}))), /*#__PURE__*/ h(Paging, {
|
|
241
|
+
io,
|
|
242
|
+
id,
|
|
243
|
+
shown: shown.length,
|
|
244
|
+
last: shown.at(-1)?.b.entity.eid,
|
|
245
|
+
size,
|
|
246
|
+
total: local || holds ? rows.length : p.total
|
|
247
|
+
}));
|
|
248
|
+
};
|
|
249
|
+
//# sourceMappingURL=grid.js.map
|
package/grid.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.js","sources":["./grid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GAED,uCAAuC,GAAG,SAAS,iBAAiB,CAAC,EAAE,QAAQ,gBAAoD;AACnI,SAAS,OAAO,EAAE,SAAS,OAAO,EAAE,SAAS,2BAAgC;AAC7E,SAAS,KAAK,EAAE,KAAK,wBAA6B;AAClD,SAAS,QAAQ,wBAA6C;AAE9D,SAAS,KAAK,oBAAmB;AACjC,SA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 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A table of things, the way every inspector page draws one: @yaks/ui's
|
|
3
|
+
* `Table`, a column per heading and a row per thing. A press on a row opens
|
|
4
|
+
* the entity it stands for (`io.go` to its `link`), unless the press was on
|
|
5
|
+
* a link or a value inside it; the keyboard can rest on a row, for Enter to
|
|
6
|
+
* open it (./main.ts). A press on a heading whose column can sort runs the
|
|
7
|
+
* rows by it, then back the other way, then as they came.
|
|
8
|
+
* A long table shows a page of rows at a time, with a `Pager` under it. How
|
|
9
|
+
* the rows run and which page shows are the table's state in the page's own
|
|
10
|
+
* graph (./state.ts `grid`), so a page shown again shows as it was left; a
|
|
11
|
+
* page that keeps its order elsewhere (a query's page, in its line and so its
|
|
12
|
+
* address) hands it in as `sorts`.
|
|
13
|
+
*
|
|
14
|
+
* A table paged by the graph asks for one page at a time (`paged`), and the
|
|
15
|
+
* graph sorts it; one whose rows are all in hand (a tally, a component's
|
|
16
|
+
* properties) pages them itself (`local`), and sorts them by a column's
|
|
17
|
+
* `value` (`run`, @yaks/ux `sortRows`): numbers as numbers, an empty value
|
|
18
|
+
* last either way.
|
|
19
|
+
*
|
|
20
|
+
* A table whose rows hold rows is a tree (`holds`): a row holding some wears a
|
|
21
|
+
* toggle, and once opened the rows it holds show under it, a step in, run by
|
|
22
|
+
* the same column as their parent's; which rows are open is the table's state
|
|
23
|
+
* too. A long tree pages the rows it shows.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, Fragment, type JSX, type ReactNode } from 'react'
|
|
29
|
+
import { conjoin, order as ordered, stringify } from '@yaks/query'
|
|
30
|
+
import { Pager, Table } from '@yaks/ui'
|
|
31
|
+
import { sortRows, type SortValue } from '@yaks/ux'
|
|
32
|
+
import type { Bundle, Io } from './host.ts'
|
|
33
|
+
import { count } from './read.js'
|
|
34
|
+
import { none } from './rows.js'
|
|
35
|
+
import { grid, turned } from './state.js'
|
|
36
|
+
|
|
37
|
+
/** How many rows a page of a table holds. */
|
|
38
|
+
export let SIZE = 50
|
|
39
|
+
|
|
40
|
+
/** One column: its heading, what its cells hold, and what it sorts by. */
|
|
41
|
+
export type Column = {
|
|
42
|
+
name: string
|
|
43
|
+
/** the property the graph runs its rows by when its heading is pressed */
|
|
44
|
+
sort?: string
|
|
45
|
+
/** what a table holding every row runs them by when its heading is
|
|
46
|
+
* pressed: a number, text, or null for none */
|
|
47
|
+
value?: (b: Bundle) => SortValue
|
|
48
|
+
mod?: 'num' | 'key' | 'prose'
|
|
49
|
+
cell: (b: Bundle) => ReactNode
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// What a column sorts by in a table's state: the property the graph runs by,
|
|
53
|
+
// or, where the table holds its rows, the column's name.
|
|
54
|
+
let sorted = (c: Column) => c.sort ?? (c.value ? c.name : undefined)
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Rows a table holds, run by the column its order names (`-` before it when
|
|
58
|
+
* they run down), or as they came.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { type Column, run } from './grid.ts'
|
|
62
|
+
* let rows = [2, 3, 1].map((n) => ({ entity: { eid: `${n}` } }))
|
|
63
|
+
* let cols: Column[] = [
|
|
64
|
+
* { name: 'n', value: (b) => Number(b.entity.eid), cell: () => '' },
|
|
65
|
+
* ]
|
|
66
|
+
* run(rows, cols, '-n').map((b) => b.entity.eid) // ['3', '2', '1']
|
|
67
|
+
* run(rows, cols, null).map((b) => b.entity.eid) // ['2', '3', '1']
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export let run = (
|
|
71
|
+
rows: Bundle[],
|
|
72
|
+
columns: Column[],
|
|
73
|
+
order?: string | null,
|
|
74
|
+
): Bundle[] => {
|
|
75
|
+
let c = columns.find((c) => c.value && c.name == order?.replace(/^-/, ''))
|
|
76
|
+
if (!c?.value) return rows
|
|
77
|
+
let v = c.value
|
|
78
|
+
return sortRows(rows, (b) => [v(b)], {
|
|
79
|
+
column: 0,
|
|
80
|
+
direction: order!.startsWith('-') ? 'desc' : 'asc',
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A row a tree shows: how deep it is, and whether it holds rows (and so
|
|
85
|
+
* wears a toggle). */
|
|
86
|
+
export type Branch = { b: Bundle; depth: number; holds: boolean }
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The rows a tree shows, in order: each level run by `order` (`run`), and
|
|
90
|
+
* under each row `open` names the rows it `holds`, a step deeper.
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { type Column, unfold } from './grid.ts'
|
|
94
|
+
* let b = (eid: string) => ({ entity: { eid } })
|
|
95
|
+
* let kids: Record<string, string[]> = { p: ['c2', 'c1'], c1: ['x'] }
|
|
96
|
+
* let holds = (r: { entity: { eid: string } }) =>
|
|
97
|
+
* (kids[r.entity.eid] ?? []).map(b)
|
|
98
|
+
* let cols: Column[] = [{ name: 'n', value: (r) => r.entity.eid, cell: () => '' }]
|
|
99
|
+
* unfold([b('q'), b('p')], cols, 'n', ['p', 'c1'], holds)
|
|
100
|
+
* .map((r) => `${r.depth}${r.b.entity.eid}${r.holds ? '+' : ''}`)
|
|
101
|
+
* // ['0p+', '1c1+', '2x', '1c2', '0q']
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export let unfold = (
|
|
105
|
+
rows: Bundle[],
|
|
106
|
+
columns: Column[],
|
|
107
|
+
order: string | null | undefined,
|
|
108
|
+
open: string[],
|
|
109
|
+
holds: (b: Bundle) => Bundle[],
|
|
110
|
+
depth = 0,
|
|
111
|
+
): Branch[] =>
|
|
112
|
+
run(rows, columns, order).flatMap((b) => {
|
|
113
|
+
let kids = holds(b)
|
|
114
|
+
return [
|
|
115
|
+
{ b, depth, holds: kids.length > 0 },
|
|
116
|
+
...kids.length && open.includes(b.entity.eid)
|
|
117
|
+
? unfold(kids, columns, order, open, holds, depth + 1)
|
|
118
|
+
: [],
|
|
119
|
+
]
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The line for the page of `base`'s rows the table `id` shows: run by its
|
|
124
|
+
* order (or `order`, when the table names none, with no value `last` when
|
|
125
|
+
* asked), after the last row of the page before, `size` of them.
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { paged } from './grid.ts'
|
|
129
|
+
* let io = { state: () => ({ entity: { eid: 't' }, table: { order: '-task.status', after: ['e9'] } }) }
|
|
130
|
+
* paged(io, 't', '.task') // '.task&.order=-task.status&.after=e9&.limit=50'
|
|
131
|
+
* paged({ state: () => undefined }, 't', '.task', { order: 'doc.title', last: true })
|
|
132
|
+
* // '.task&.order[last]=doc.title&.limit=50'
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export let paged = (
|
|
136
|
+
io: Pick<Io, 'state'>,
|
|
137
|
+
id: string,
|
|
138
|
+
base: string,
|
|
139
|
+
{ order, last, size = SIZE }: {
|
|
140
|
+
order?: string
|
|
141
|
+
last?: boolean
|
|
142
|
+
size?: number
|
|
143
|
+
} = {},
|
|
144
|
+
): string => {
|
|
145
|
+
let g = grid(io, id)
|
|
146
|
+
let by = g.order || order
|
|
147
|
+
return conjoin(
|
|
148
|
+
base,
|
|
149
|
+
by ? stringify(ordered(by, !g.order && !!last)) : '',
|
|
150
|
+
g.after?.length ? `.after=${g.after.at(-1)}` : '',
|
|
151
|
+
`.limit=${size}`,
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Whether a press landed on something of its own inside the row: a link, a
|
|
156
|
+
* control, a value that can be changed (@yaks/ux). */
|
|
157
|
+
let own = (target: unknown): boolean => {
|
|
158
|
+
for (
|
|
159
|
+
let n = target as {
|
|
160
|
+
localName?: string
|
|
161
|
+
className?: string
|
|
162
|
+
parentNode?: unknown
|
|
163
|
+
} | null;
|
|
164
|
+
n && !/\bTable_Row\b/.test(n.className ?? '');
|
|
165
|
+
n = n.parentNode as typeof n
|
|
166
|
+
) {
|
|
167
|
+
if (['a', 'button', 'input', 'select', 'textarea'].includes(n.localName!)) {
|
|
168
|
+
return true
|
|
169
|
+
}
|
|
170
|
+
if (/\b(Prop-live|Edit)\b/.test(n.className ?? '')) return true
|
|
171
|
+
}
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** What a grid is drawn with. */
|
|
176
|
+
export type GridProps = {
|
|
177
|
+
io: Io
|
|
178
|
+
/** the table's state entity in the page's own graph */
|
|
179
|
+
id: string
|
|
180
|
+
columns: Column[]
|
|
181
|
+
/** the page of rows the graph answered, or every row when `local` */
|
|
182
|
+
rows: Bundle[]
|
|
183
|
+
/** how many rows there are in all, when that is known */
|
|
184
|
+
total?: number
|
|
185
|
+
/** every row is in hand: the table pages them itself */
|
|
186
|
+
local?: boolean
|
|
187
|
+
size?: number
|
|
188
|
+
/** the entity a press on a row opens (its own, unless this says
|
|
189
|
+
* another); undefined opens nothing */
|
|
190
|
+
pick?: ((b: Bundle) => string | undefined) | false
|
|
191
|
+
/** the rows a row holds, which make the table a tree: shown under it once
|
|
192
|
+
* its toggle opens it. A tree holds all its rows, as a `local` table does */
|
|
193
|
+
holds?: (b: Bundle) => Bundle[]
|
|
194
|
+
/** the order the page keeps for the table, and where a pressed heading
|
|
195
|
+
* sends the next one; without it the order is the table's state */
|
|
196
|
+
sorts?: { order?: string; to: (order?: string) => void }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** What a pager is drawn with: the table it pages, how many rows this page
|
|
200
|
+
* shows and the last of them, how many a page holds, how many there are in
|
|
201
|
+
* all when that is known, and what its steps say. */
|
|
202
|
+
export type PagingProps = {
|
|
203
|
+
io: Io
|
|
204
|
+
id: string
|
|
205
|
+
shown: number
|
|
206
|
+
last?: string
|
|
207
|
+
size: number
|
|
208
|
+
total?: number
|
|
209
|
+
steps?: [back: string, next: string]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Where a page of rows sits, and a step to the page either side of it: the
|
|
213
|
+
* way back is the last row of each page before, kept in the table's state.
|
|
214
|
+
* Nothing, for a table that fits on one page. */
|
|
215
|
+
export let Paging = (p: PagingProps): JSX.Element | null => {
|
|
216
|
+
let { io, id, shown, size, total } = p
|
|
217
|
+
let after = grid(io, id).after ?? []
|
|
218
|
+
let page = after.length
|
|
219
|
+
let to = page * size + shown
|
|
220
|
+
let more = total != null ? to < total : shown == size
|
|
221
|
+
let [back, next] = p.steps ?? ['‹ back', 'next ›']
|
|
222
|
+
let step = (d: number) =>
|
|
223
|
+
io.set(turned(id, {
|
|
224
|
+
after: d < 0 ? after.slice(0, -1) : [...after, p.last ?? String(page)],
|
|
225
|
+
}))
|
|
226
|
+
return page || more
|
|
227
|
+
? h(
|
|
228
|
+
Pager,
|
|
229
|
+
{},
|
|
230
|
+
h(
|
|
231
|
+
Pager.Span,
|
|
232
|
+
{},
|
|
233
|
+
`${count(page * size + 1)}–${count(to)}`,
|
|
234
|
+
total != null ? ` of ${count(total)}` : '',
|
|
235
|
+
),
|
|
236
|
+
h(Pager.Step, {
|
|
237
|
+
type: 'button',
|
|
238
|
+
disabled: !page,
|
|
239
|
+
onClick: () => step(-1),
|
|
240
|
+
}, back),
|
|
241
|
+
h(Pager.Step, {
|
|
242
|
+
type: 'button',
|
|
243
|
+
disabled: !more,
|
|
244
|
+
onClick: () => step(1),
|
|
245
|
+
}, next),
|
|
246
|
+
)
|
|
247
|
+
: null
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Which way a column runs: its heading's variant.
|
|
251
|
+
let way = (order: string | null | undefined, c: Column) =>
|
|
252
|
+
!sorted(c)
|
|
253
|
+
? undefined
|
|
254
|
+
: order == sorted(c)
|
|
255
|
+
? 'asc'
|
|
256
|
+
: order == `-${sorted(c)}`
|
|
257
|
+
? 'desc'
|
|
258
|
+
: undefined
|
|
259
|
+
|
|
260
|
+
// What a tree row's first cell starts with: an indent for each row it is
|
|
261
|
+
// under, then its toggle, or an indent where it holds none.
|
|
262
|
+
let Stem = (
|
|
263
|
+
{ io, id, at, open }: { io: Io; id: string; at: Branch; open: string[] },
|
|
264
|
+
) => {
|
|
265
|
+
let eid = at.b.entity.eid
|
|
266
|
+
let shown = open.includes(eid)
|
|
267
|
+
return h(
|
|
268
|
+
Fragment,
|
|
269
|
+
null,
|
|
270
|
+
Array.from({ length: at.depth }, (_, i) => h(Table.Indent, { key: i })),
|
|
271
|
+
at.holds
|
|
272
|
+
? h(Table.Toggle, {
|
|
273
|
+
type: 'button',
|
|
274
|
+
mod: shown && 'open',
|
|
275
|
+
'aria-expanded': shown,
|
|
276
|
+
'aria-label': 'what it holds',
|
|
277
|
+
onClick: () =>
|
|
278
|
+
io.set(turned(id, {
|
|
279
|
+
open: shown ? open.filter((o) => o != eid) : [...open, eid],
|
|
280
|
+
})),
|
|
281
|
+
})
|
|
282
|
+
: h(Table.Indent, {}),
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** A table of things, paged, its rows opened and its columns sorted. */
|
|
287
|
+
export let Grid = (p: GridProps): JSX.Element => {
|
|
288
|
+
let { io, id, columns, local, holds } = p
|
|
289
|
+
let size = p.size ?? SIZE
|
|
290
|
+
let g = grid(io, id)
|
|
291
|
+
let order = p.sorts ? p.sorts.order : g.order
|
|
292
|
+
let open = g.open ?? []
|
|
293
|
+
let tree: Branch[] = holds
|
|
294
|
+
? unfold(p.rows, columns, order, open, holds)
|
|
295
|
+
: (local ? run(p.rows, columns, order) : p.rows)
|
|
296
|
+
.map((b) => ({ b, depth: 0, holds: false }))
|
|
297
|
+
let rows = tree.map((t) => t.b)
|
|
298
|
+
let after = g.after ?? []
|
|
299
|
+
let page = after.length
|
|
300
|
+
let shown = local || holds ? tree.slice(page * size, (page + 1) * size) : tree
|
|
301
|
+
let pick = p.pick === false
|
|
302
|
+
? () => undefined
|
|
303
|
+
: p.pick ?? ((b: Bundle) => b.entity.eid)
|
|
304
|
+
let sort = (c: Column) => {
|
|
305
|
+
let by = sorted(c)!
|
|
306
|
+
let next = order == by ? `-${by}` : order == `-${by}` ? null : by
|
|
307
|
+
if (p.sorts) p.sorts.to(next ?? undefined)
|
|
308
|
+
else io.set(turned(id, { order: next, after: [] }))
|
|
309
|
+
}
|
|
310
|
+
if (!rows.length && !page) return none()
|
|
311
|
+
return h(
|
|
312
|
+
Fragment,
|
|
313
|
+
null,
|
|
314
|
+
h(
|
|
315
|
+
Table,
|
|
316
|
+
{
|
|
317
|
+
'data-table': id,
|
|
318
|
+
...holds ? { role: 'treegrid' } : {},
|
|
319
|
+
cols: columns.map((c) => c.mod),
|
|
320
|
+
},
|
|
321
|
+
h(
|
|
322
|
+
Table.Head,
|
|
323
|
+
{},
|
|
324
|
+
h(
|
|
325
|
+
Table.Row,
|
|
326
|
+
{},
|
|
327
|
+
columns.map((c) => {
|
|
328
|
+
let dir = way(order, c)
|
|
329
|
+
return h(
|
|
330
|
+
Table.Heading,
|
|
331
|
+
{
|
|
332
|
+
key: c.name,
|
|
333
|
+
mod: [sorted(c) && 'sorts', dir, c.mod == 'num' && 'num'],
|
|
334
|
+
'aria-sort': sorted(c)
|
|
335
|
+
? dir == 'asc'
|
|
336
|
+
? 'ascending'
|
|
337
|
+
: dir == 'desc'
|
|
338
|
+
? 'descending'
|
|
339
|
+
: 'none'
|
|
340
|
+
: undefined,
|
|
341
|
+
},
|
|
342
|
+
sorted(c)
|
|
343
|
+
? h(
|
|
344
|
+
Table.Sort,
|
|
345
|
+
{ type: 'button', onClick: () => sort(c) },
|
|
346
|
+
c.name,
|
|
347
|
+
)
|
|
348
|
+
: c.name,
|
|
349
|
+
)
|
|
350
|
+
}),
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
h(
|
|
354
|
+
Table.Body,
|
|
355
|
+
{},
|
|
356
|
+
shown.map((t) => {
|
|
357
|
+
let { b } = t
|
|
358
|
+
let at = pick(b)
|
|
359
|
+
return h(
|
|
360
|
+
Table.Row,
|
|
361
|
+
{
|
|
362
|
+
key: b.entity.eid,
|
|
363
|
+
mod: at && 'picks',
|
|
364
|
+
'data-pick': at,
|
|
365
|
+
'aria-level': holds ? t.depth + 1 : undefined,
|
|
366
|
+
tabIndex: at ? -1 : undefined,
|
|
367
|
+
onClick: at
|
|
368
|
+
? (ev: { target: unknown }) => {
|
|
369
|
+
// Step aside without consuming the bubbled link click.
|
|
370
|
+
if (!own(ev.target)) io.go(io.link(at))
|
|
371
|
+
}
|
|
372
|
+
: undefined,
|
|
373
|
+
},
|
|
374
|
+
columns.map((c, i) =>
|
|
375
|
+
h(
|
|
376
|
+
Table.Cell,
|
|
377
|
+
{ key: c.name, mod: c.mod },
|
|
378
|
+
holds && !i ? h(Stem, { io, id, at: t, open }) : null,
|
|
379
|
+
c.cell(b),
|
|
380
|
+
)
|
|
381
|
+
),
|
|
382
|
+
)
|
|
383
|
+
}),
|
|
384
|
+
),
|
|
385
|
+
),
|
|
386
|
+
h(Paging, {
|
|
387
|
+
io,
|
|
388
|
+
id,
|
|
389
|
+
shown: shown.length,
|
|
390
|
+
last: shown.at(-1)?.b.entity.eid,
|
|
391
|
+
size,
|
|
392
|
+
total: local || holds ? rows.length : p.total,
|
|
393
|
+
}),
|
|
394
|
+
)
|
|
395
|
+
}
|
package/host.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an inspector view is, and what it asks of the host that draws it.
|
|
3
|
+
*
|
|
4
|
+
* A view is a domain component in the sense of https://yak.sh/composable-ui.md:
|
|
5
|
+
* it knows no store. It says which bundles it draws (`match`, a @yaks/render
|
|
6
|
+
* registration), the queries it needs as data (`asks`, a query line by the
|
|
7
|
+
* name it reads the answer under, and `io.ask` for a query that depends on
|
|
8
|
+
* another's answer), and draws what it is handed: the bundle, each answer
|
|
9
|
+
* (`got`), and `io`, its doors to the world outside it. An edit goes out
|
|
10
|
+
* through `io.apply` as bundles; the inspector's own state (./state.ts) is
|
|
11
|
+
* read and written in the page's own graph through `io.state` and `io.set`.
|
|
12
|
+
*
|
|
13
|
+
* The host is what a browser or a terminal supplies once ({@link Host}): the
|
|
14
|
+
* vocabulary, a hook answering asks while the view asking is mounted, where
|
|
15
|
+
* links go, how an entity is named, and the doors that write. `inspector()`
|
|
16
|
+
* (./door.ts) turns a host into the `Door` every view is drawn through.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/ /* @ts-types="npm:@types/react@19.3.0" */
|
|
20
|
+
//# sourceMappingURL=host.js.map
|
package/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sources":["./host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;CAkBC,GAED,uCAAuC,GAAG"}
|