trebol 0.1.2 → 0.2.0
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/README.md +2 -0
- package/dist/cli.js +10040 -7519
- package/dist/lib/core/boot.js +10 -7
- package/dist/lib/core/eval.js +2 -2
- package/dist/lib/core/machine/checks.d.ts +1 -0
- package/dist/lib/core/machine/checks.js +250 -0
- package/dist/lib/core/machine/events.d.ts +1 -0
- package/dist/lib/core/machine/events.js +365 -0
- package/dist/lib/core/machine/running.d.ts +1 -0
- package/dist/lib/core/machine/running.js +180 -0
- package/dist/lib/core/machine/shared.d.ts +1 -0
- package/dist/lib/core/machine/shared.js +123 -0
- package/dist/lib/core/machine/snapshot.d.ts +1 -0
- package/dist/lib/core/machine/snapshot.js +244 -0
- package/dist/lib/core/machine/spec.d.ts +1 -0
- package/dist/lib/core/machine/spec.js +274 -0
- package/dist/lib/core/machine/words.d.ts +1 -0
- package/dist/lib/core/machine/words.js +98 -0
- package/dist/lib/core/machine.d.ts +1 -0
- package/dist/lib/core/machine.js +17 -0
- package/dist/lib/core/mezz.js +31 -0
- package/dist/lib/core/natives/control.js +1 -1
- package/dist/lib/core/natives/data.js +6 -1
- package/dist/lib/core/natives/series.js +49 -9
- package/dist/lib/core/natives/text.js +0 -1
- package/dist/lib/host/browser/calendar.d.ts +34 -0
- package/dist/lib/host/browser/calendar.js +268 -0
- package/dist/lib/host/browser/count.d.ts +15 -0
- package/dist/lib/host/browser/count.js +48 -0
- package/dist/lib/host/browser/dialogs.d.ts +39 -0
- package/dist/lib/host/browser/dialogs.js +443 -0
- package/dist/lib/host/browser/drag.d.ts +70 -0
- package/dist/lib/host/browser/drag.js +268 -0
- package/dist/lib/host/browser/drawings.d.ts +30 -0
- package/dist/lib/host/browser/drawings.js +176 -0
- package/dist/lib/host/browser/events.d.ts +16 -0
- package/dist/lib/host/browser/events.js +125 -0
- package/dist/lib/host/browser/faces.d.ts +35 -0
- package/dist/lib/host/browser/faces.js +131 -0
- package/dist/lib/host/browser/fields.d.ts +16 -0
- package/dist/lib/host/browser/fields.js +322 -0
- package/dist/lib/host/browser/keys.d.ts +29 -0
- package/dist/lib/host/browser/keys.js +151 -0
- package/dist/lib/host/browser/lookup.d.ts +25 -0
- package/dist/lib/host/browser/lookup.js +275 -0
- package/dist/lib/host/browser/menus.d.ts +20 -0
- package/dist/lib/host/browser/menus.js +149 -0
- package/dist/lib/host/browser/mount.d.ts +92 -0
- package/dist/lib/host/browser/mount.js +448 -0
- package/dist/lib/host/browser/orbits.d.ts +90 -0
- package/dist/lib/host/browser/orbits.js +379 -0
- package/dist/lib/host/browser/page.d.ts +13 -0
- package/dist/lib/host/browser/page.js +35 -0
- package/dist/lib/host/browser/richtext.d.ts +19 -0
- package/dist/lib/host/browser/richtext.js +379 -0
- package/dist/lib/host/browser/row-faces.d.ts +5 -0
- package/dist/lib/host/browser/row-faces.js +74 -0
- package/dist/lib/host/browser/screens.d.ts +37 -0
- package/dist/lib/host/browser/screens.js +140 -0
- package/dist/lib/host/browser/swipe.d.ts +31 -0
- package/dist/lib/host/browser/swipe.js +178 -0
- package/dist/lib/host/browser/sync.d.ts +24 -0
- package/dist/lib/host/browser/sync.js +450 -0
- package/dist/lib/host/browser/tables.d.ts +65 -0
- package/dist/lib/host/browser/tables.js +505 -0
- package/dist/lib/host/browser/times.d.ts +14 -0
- package/dist/lib/host/browser/times.js +114 -0
- package/dist/lib/host/browser/toolbars.d.ts +17 -0
- package/dist/lib/host/browser/toolbars.js +129 -0
- package/dist/lib/host/browser/trees.d.ts +20 -0
- package/dist/lib/host/browser/trees.js +235 -0
- package/dist/lib/host/browser/uploads.d.ts +29 -0
- package/dist/lib/host/browser/uploads.js +370 -0
- package/dist/lib/host/browser/widget.d.ts +13 -0
- package/dist/lib/host/browser/widget.js +105 -0
- package/dist/lib/host/browser.d.ts +25 -0
- package/dist/lib/host/browser.js +84 -4812
- package/dist/lib/host/devtools/console.d.ts +9 -0
- package/dist/lib/host/devtools/console.js +104 -0
- package/dist/lib/host/devtools/faces.d.ts +25 -0
- package/dist/lib/host/devtools/faces.js +169 -0
- package/dist/lib/host/devtools/log.d.ts +3 -0
- package/dist/lib/host/devtools/log.js +32 -0
- package/dist/lib/host/devtools/machines.d.ts +34 -0
- package/dist/lib/host/devtools/machines.js +212 -0
- package/dist/lib/host/devtools/read.d.ts +13 -0
- package/dist/lib/host/devtools/read.js +52 -0
- package/dist/lib/host/devtools/state.d.ts +90 -0
- package/dist/lib/host/devtools/state.js +123 -0
- package/dist/lib/host/devtools.d.ts +15 -19
- package/dist/lib/host/devtools.js +39 -427
- package/dist/lib/host/fonts.js +4 -3
- package/dist/lib/host/icons.js +4 -0
- package/dist/lib/host/index.d.ts +3 -1
- package/dist/lib/host/index.js +107 -4
- package/dist/lib/host/locale.d.ts +18 -0
- package/dist/lib/host/locale.js +75 -5
- package/dist/lib/host/markdown.d.ts +4 -0
- package/dist/lib/host/markdown.js +8 -0
- package/dist/lib/host/modules.js +118 -19
- package/dist/lib/host/motion.d.ts +32 -0
- package/dist/lib/host/motion.js +190 -0
- package/dist/lib/host/net.js +5 -2
- package/dist/lib/host/palette.d.ts +17 -0
- package/dist/lib/host/palette.js +131 -0
- package/dist/lib/host/scheduler.d.ts +2 -0
- package/dist/lib/host/scheduler.js +4 -0
- package/dist/lib/host/share.d.ts +31 -0
- package/dist/lib/host/share.js +134 -0
- package/dist/lib/host/theme/classic.d.ts +1 -0
- package/dist/lib/host/theme/classic.js +120 -0
- package/dist/lib/host/theme/cupertino.d.ts +1 -0
- package/dist/lib/host/theme/cupertino.js +65 -0
- package/dist/lib/host/theme/data.d.ts +1 -0
- package/dist/lib/host/theme/data.js +109 -0
- package/dist/lib/host/theme/devtools.d.ts +1 -0
- package/dist/lib/host/theme/devtools.js +166 -0
- package/dist/lib/host/theme/dialogs.d.ts +1 -0
- package/dist/lib/host/theme/dialogs.js +63 -0
- package/dist/lib/host/theme/fluent.d.ts +1 -0
- package/dist/lib/host/theme/fluent.js +64 -0
- package/dist/lib/host/theme/forms.d.ts +1 -0
- package/dist/lib/host/theme/forms.js +239 -0
- package/dist/lib/host/theme/fusion.d.ts +1 -0
- package/dist/lib/host/theme/fusion.js +66 -0
- package/dist/lib/host/theme/layout.d.ts +1 -0
- package/dist/lib/host/theme/layout.js +166 -0
- package/dist/lib/host/theme/media.d.ts +1 -0
- package/dist/lib/host/theme/media.js +106 -0
- package/dist/lib/host/theme/navigation.d.ts +1 -0
- package/dist/lib/host/theme/navigation.js +36 -0
- package/dist/lib/host/theme/panes.d.ts +1 -0
- package/dist/lib/host/theme/panes.js +99 -0
- package/dist/lib/host/theme/popups.d.ts +1 -0
- package/dist/lib/host/theme/popups.js +149 -0
- package/dist/lib/host/theme/responsive.d.ts +1 -0
- package/dist/lib/host/theme/responsive.js +103 -0
- package/dist/lib/host/theme/toasts.d.ts +1 -0
- package/dist/lib/host/theme/toasts.js +62 -0
- package/dist/lib/host/theme.js +19 -1384
- package/dist/lib/ui/dialect/events.trb +276 -0
- package/dist/lib/ui/dialect/faces.trb +135 -0
- package/dist/lib/ui/dialect/layout.trb +283 -0
- package/dist/lib/ui/dialect/palette.trb +87 -0
- package/dist/lib/ui/dialect/problems.trb +174 -0
- package/dist/lib/ui/dialect/reactions.trb +198 -0
- package/dist/lib/ui/dialect/rows.trb +208 -0
- package/dist/lib/ui/dialect/screens.trb +293 -0
- package/dist/lib/ui/dialect/steps.trb +203 -0
- package/dist/lib/ui/dialect/validation.trb +137 -0
- package/dist/lib/ui/dialect/view.trb +110 -0
- package/dist/lib/ui/dialect/walking.trb +98 -0
- package/dist/lib/ui/dialect/words.trb +70 -0
- package/dist/lib/ui/i18n.trb +17 -0
- package/dist/lib/ui/test.trb +3 -556
- package/dist/lib/ui/testing/actions.trb +421 -0
- package/dist/lib/ui/testing/faces.trb +148 -0
- package/dist/lib/ui/testing/server.trb +73 -0
- package/dist/lib/ui/ui.trb +25 -1675
- package/dist/trebol.js +4463 -1891
- package/package.json +1 -1
- package/src/core/boot.ts +9 -6
- package/src/core/eval.ts +2 -2
- package/src/core/machine/checks.ts +251 -0
- package/src/core/machine/events.ts +366 -0
- package/src/core/machine/running.ts +181 -0
- package/src/core/machine/shared.ts +124 -0
- package/src/core/machine/snapshot.ts +245 -0
- package/src/core/machine/spec.ts +275 -0
- package/src/core/machine/words.ts +99 -0
- package/src/core/machine.ts +20 -0
- package/src/core/mezz.ts +31 -0
- package/src/core/natives/control.ts +1 -1
- package/src/core/natives/data.ts +6 -1
- package/src/core/natives/parse.ts +1 -1
- package/src/core/natives/series.ts +47 -11
- package/src/core/natives/text.ts +0 -1
- package/src/host/browser/calendar.ts +264 -0
- package/src/host/browser/count.ts +48 -0
- package/src/host/browser/dialogs.ts +439 -0
- package/src/host/browser/drag.ts +278 -0
- package/src/host/browser/drawings.ts +178 -0
- package/src/host/browser/events.ts +117 -0
- package/src/host/browser/faces.ts +143 -0
- package/src/host/browser/fields.ts +315 -0
- package/src/host/browser/keys.ts +145 -0
- package/src/host/browser/lookup.ts +262 -0
- package/src/host/browser/menus.ts +146 -0
- package/src/host/browser/mount.ts +420 -0
- package/src/host/browser/orbits.ts +418 -0
- package/src/host/browser/page.ts +43 -0
- package/src/host/browser/richtext.ts +346 -0
- package/src/host/browser/row-faces.ts +75 -0
- package/src/host/browser/screens.ts +142 -0
- package/src/host/browser/swipe.ts +168 -0
- package/src/host/browser/sync.ts +354 -0
- package/src/host/browser/tables.ts +461 -0
- package/src/host/browser/times.ts +115 -0
- package/src/host/browser/toolbars.ts +126 -0
- package/src/host/browser/trees.ts +205 -0
- package/src/host/browser/uploads.ts +367 -0
- package/src/host/browser/widget.ts +103 -0
- package/src/host/browser.ts +82 -4612
- package/src/host/devtools/console.ts +102 -0
- package/src/host/devtools/faces.ts +160 -0
- package/src/host/devtools/log.ts +34 -0
- package/src/host/devtools/machines.ts +208 -0
- package/src/host/devtools/read.ts +58 -0
- package/src/host/devtools/state.ts +148 -0
- package/src/host/devtools.ts +39 -442
- package/src/host/fonts.ts +4 -3
- package/src/host/icons.ts +4 -0
- package/src/host/index.ts +107 -4
- package/src/host/locale.ts +71 -5
- package/src/host/markdown.ts +9 -0
- package/src/host/modules.ts +117 -21
- package/src/host/motion.ts +204 -0
- package/src/host/net.ts +4 -2
- package/src/host/palette.ts +139 -0
- package/src/host/scheduler.ts +5 -0
- package/src/host/share.ts +168 -0
- package/src/host/theme/classic.ts +121 -0
- package/src/host/theme/cupertino.ts +66 -0
- package/src/host/theme/data.ts +110 -0
- package/src/host/theme/devtools.ts +167 -0
- package/src/host/theme/dialogs.ts +64 -0
- package/src/host/theme/fluent.ts +65 -0
- package/src/host/theme/forms.ts +240 -0
- package/src/host/theme/fusion.ts +67 -0
- package/src/host/theme/layout.ts +167 -0
- package/src/host/theme/media.ts +107 -0
- package/src/host/theme/navigation.ts +37 -0
- package/src/host/theme/panes.ts +100 -0
- package/src/host/theme/popups.ts +150 -0
- package/src/host/theme/responsive.ts +104 -0
- package/src/host/theme/toasts.ts +63 -0
- package/src/host/theme.ts +19 -1384
- package/src/ui/dialect/events.trb +276 -0
- package/src/ui/dialect/faces.trb +135 -0
- package/src/ui/dialect/layout.trb +283 -0
- package/src/ui/dialect/palette.trb +87 -0
- package/src/ui/dialect/problems.trb +174 -0
- package/src/ui/dialect/reactions.trb +198 -0
- package/src/ui/dialect/rows.trb +208 -0
- package/src/ui/dialect/screens.trb +293 -0
- package/src/ui/dialect/steps.trb +203 -0
- package/src/ui/dialect/validation.trb +137 -0
- package/src/ui/dialect/view.trb +110 -0
- package/src/ui/dialect/walking.trb +98 -0
- package/src/ui/dialect/words.trb +70 -0
- package/src/ui/i18n.trb +17 -0
- package/src/ui/test.trb +3 -556
- package/src/ui/testing/actions.trb +421 -0
- package/src/ui/testing/faces.trb +148 -0
- package/src/ui/testing/server.trb +73 -0
- package/src/ui/ui.trb +25 -1675
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type Cell, type ObjectCell, type Sym } from '../../core/index.ts';
|
|
2
|
+
import { type Mounted } from './mount.ts';
|
|
3
|
+
/** A column; `image` when it shows each row's picture, `round` when cut to a circle. */
|
|
4
|
+
export interface Column {
|
|
5
|
+
sym: Sym;
|
|
6
|
+
word: Cell;
|
|
7
|
+
label: string;
|
|
8
|
+
image: boolean;
|
|
9
|
+
round: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function columns(face: ObjectCell): Column[];
|
|
12
|
+
/** The picture of a row in a column of images, from an address or a file; without one, an empty place for it. */
|
|
13
|
+
export declare function thumb(box: Element, v: Cell, round: boolean): void;
|
|
14
|
+
export declare function sameRow(a: Cell, b: Cell): boolean;
|
|
15
|
+
export declare function cellText(v: Cell): string;
|
|
16
|
+
export declare const NUMERIC: ReadonlySet<number>;
|
|
17
|
+
export declare function buildRows(face: ObjectCell, style: string, m: Mounted): HTMLElement;
|
|
18
|
+
/** The rows of a table or list in the order shown, with their keys; then draws them. */
|
|
19
|
+
export declare function syncRows(m: Mounted): void;
|
|
20
|
+
/** Tables and lists with too many rows to draw them all. */
|
|
21
|
+
export declare const longRows: Set<Mounted>;
|
|
22
|
+
/** While printing, every row is drawn. */
|
|
23
|
+
export declare let printing: boolean;
|
|
24
|
+
/** The rows to draw: all of them, or those near the screen. */
|
|
25
|
+
export declare function rowsToDraw(m: Mounted): {
|
|
26
|
+
first: number;
|
|
27
|
+
end: number;
|
|
28
|
+
};
|
|
29
|
+
/** Creates, updates, moves or removes only the rows drawn whose key changed. */
|
|
30
|
+
export declare function drawRows(m: Mounted, again?: boolean): void;
|
|
31
|
+
/** A morph name, 'logo or [client 7], as text: "logo", "client 7"; null for none. */
|
|
32
|
+
export declare function morphName(v: Cell): string | null;
|
|
33
|
+
/** Whether the rows drawn are the rows to draw, in the same order. */
|
|
34
|
+
export declare function sameKeys(old: Map<string, HTMLElement>, items: {
|
|
35
|
+
k: string;
|
|
36
|
+
}[]): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A long table keeps the widths its columns first took, as shares of its width,
|
|
39
|
+
* so they do not change with the rows drawn while it scrolls.
|
|
40
|
+
*/
|
|
41
|
+
export declare function keepColumns(table: HTMLTableElement, keep: boolean): void;
|
|
42
|
+
/** Sets the room of the rows not drawn above and below those drawn. */
|
|
43
|
+
export declare function room(m: Mounted, above: number, below: number): void;
|
|
44
|
+
export declare let rowsFrame: number;
|
|
45
|
+
/** On a scroll or a resize, the long tables and lists draw the rows now near the screen. */
|
|
46
|
+
export declare function onRowsMoved(): void;
|
|
47
|
+
/** Printing draws every row, and the screen goes back to drawing some after. */
|
|
48
|
+
export declare function onPrint(on: boolean): void;
|
|
49
|
+
/** Headers in the active language; in a sortable table each is a button, with an arrow on the sorted one. */
|
|
50
|
+
export declare function syncHead(f: ObjectCell, table: HTMLTableElement, cols: Column[]): void;
|
|
51
|
+
/** A table's sorted facet: [column asc] or [column desc]. */
|
|
52
|
+
export declare function sortedBy(f: ObjectCell): {
|
|
53
|
+
sym: Sym;
|
|
54
|
+
desc: boolean;
|
|
55
|
+
} | null;
|
|
56
|
+
/** The order the host applies itself: a sortable table without on-sort, which sorts for itself. */
|
|
57
|
+
export declare function hostSorted(f: ObjectCell): {
|
|
58
|
+
sym: Sym;
|
|
59
|
+
desc: boolean;
|
|
60
|
+
} | null;
|
|
61
|
+
/** A group's title, the width of the whole row. */
|
|
62
|
+
export declare function newGroupHead(cols: Column[], table: boolean): HTMLElement;
|
|
63
|
+
export declare function newTableRow(cols: Column[]): HTMLElement;
|
|
64
|
+
export declare function newListItem(): HTMLElement;
|
|
65
|
+
export declare function fillRow(item: HTMLElement, row: Cell, cols: Column[], table: boolean): void;
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// --- tables and lists ---------------------------------------------------------------
|
|
2
|
+
import { K, NONE, form, intern, spell, canon } from "../../core/index.js";
|
|
3
|
+
import { translate, activeLanguage } from "../index.js";
|
|
4
|
+
import { rowField, groupRow, sortGroups, rowWindow, DRAW_ALL_UP_TO } from "../rows.js";
|
|
5
|
+
import { mayMove, rowPlaces, moveRows, leaveRow } from "../motion.js";
|
|
6
|
+
import { get, str, own, display, flag, icon } from "./faces.js";
|
|
7
|
+
import { host, rowOf, fire, el } from "./mount.js";
|
|
8
|
+
import { handlerFor } from "./events.js";
|
|
9
|
+
export function columns(face) {
|
|
10
|
+
const c = get(face, 'columns');
|
|
11
|
+
if (c.t !== K.Block)
|
|
12
|
+
return [];
|
|
13
|
+
const out = [];
|
|
14
|
+
const d = c.s.data;
|
|
15
|
+
for (let i = c.i; i + 1 < d.length; i += 2) {
|
|
16
|
+
const w = d[i];
|
|
17
|
+
if (w.t !== K.Word)
|
|
18
|
+
continue;
|
|
19
|
+
// a column of images keeps its label in a block with what it is: ["Photo" image round]
|
|
20
|
+
const spec = d[i + 1];
|
|
21
|
+
const parts = spec.t === K.Block ? spec.s.data.slice(spec.i) : [spec];
|
|
22
|
+
const has = (name) => parts.some(p => p.t === K.Word && canon(p.sym) === canon(intern(name)));
|
|
23
|
+
out.push({ sym: w.sym, word: w, label: translate(parts[0] ?? NONE, host.rt), image: has('image'), round: has('round') });
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** The picture of a row in a column of images, from an address or a file; without one, an empty place for it. */
|
|
28
|
+
export function thumb(box, v, round) {
|
|
29
|
+
const src = v.t === K.String || v.t === K.Url || v.t === K.File ? form(v) : '';
|
|
30
|
+
const old = box.querySelector(':scope > .tb-thumb');
|
|
31
|
+
let pic = old;
|
|
32
|
+
if (src === '' ? pic?.tagName !== 'SPAN' : pic?.tagName !== 'IMG') {
|
|
33
|
+
// decoration: the row's text says who or what it is
|
|
34
|
+
pic = el(src === '' ? 'span' : 'img', 'tb-thumb');
|
|
35
|
+
if (src !== '')
|
|
36
|
+
pic.alt = '';
|
|
37
|
+
if (old !== null)
|
|
38
|
+
old.replaceWith(pic);
|
|
39
|
+
else
|
|
40
|
+
box.prepend(pic);
|
|
41
|
+
}
|
|
42
|
+
if (src !== '' && pic.getAttribute('src') !== src)
|
|
43
|
+
pic.src = src;
|
|
44
|
+
pic.classList.toggle('tb-round', round);
|
|
45
|
+
}
|
|
46
|
+
export function sameRow(a, b) {
|
|
47
|
+
if (a.t === K.Map && b.t === K.Map)
|
|
48
|
+
return a.s === b.s;
|
|
49
|
+
if (a.t === K.Object && b.t === K.Object)
|
|
50
|
+
return a.ctx === b.ctx;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export function cellText(v) {
|
|
54
|
+
if (v.t === K.None)
|
|
55
|
+
return '';
|
|
56
|
+
if (v.t === K.Logic)
|
|
57
|
+
return own(v.v ? 'yes' : 'no');
|
|
58
|
+
return display(v);
|
|
59
|
+
}
|
|
60
|
+
export const NUMERIC = new Set([K.Integer, K.Decimal, K.Money, K.Percent]);
|
|
61
|
+
export function buildRows(face, style, m) {
|
|
62
|
+
const wrap = el('div', style === 'table' ? 'tb-table-wrap' : 'tb-list-wrap');
|
|
63
|
+
let box;
|
|
64
|
+
if (style === 'table') {
|
|
65
|
+
// explicit roles keep the table semantics when narrow screens restyle it as cards
|
|
66
|
+
const table = el('table', 'tb-table');
|
|
67
|
+
table.setAttribute('role', 'table');
|
|
68
|
+
const head = el('thead');
|
|
69
|
+
const tr = el('tr');
|
|
70
|
+
tr.setAttribute('role', 'row');
|
|
71
|
+
const cols = columns(face);
|
|
72
|
+
for (const _ of cols) {
|
|
73
|
+
const th = el('th');
|
|
74
|
+
th.scope = 'col';
|
|
75
|
+
th.setAttribute('role', 'columnheader');
|
|
76
|
+
tr.append(th);
|
|
77
|
+
}
|
|
78
|
+
head.append(tr);
|
|
79
|
+
head.addEventListener('click', ev => {
|
|
80
|
+
const th = ev.target.closest('th');
|
|
81
|
+
const c = th !== null && th.querySelector('.tb-sort') !== null ? cols[th.cellIndex] : undefined;
|
|
82
|
+
if (c !== undefined)
|
|
83
|
+
void fire('ui-sort', face, c.word);
|
|
84
|
+
});
|
|
85
|
+
box = el('tbody');
|
|
86
|
+
// the totals row sits outside tbody, so it is never chosen, sorted or moved
|
|
87
|
+
const foot = el('tfoot');
|
|
88
|
+
const totals = newTableRow(cols);
|
|
89
|
+
totals.className = 'tb-totals';
|
|
90
|
+
foot.append(totals);
|
|
91
|
+
// the room of the rows not drawn, above and below the ones drawn
|
|
92
|
+
const room = () => {
|
|
93
|
+
const b = el('tbody', 'tb-room');
|
|
94
|
+
b.setAttribute('aria-hidden', 'true');
|
|
95
|
+
const r = el('tr');
|
|
96
|
+
r.append(el('td'));
|
|
97
|
+
b.append(r);
|
|
98
|
+
return b;
|
|
99
|
+
};
|
|
100
|
+
table.append(head, room(), box, room(), foot);
|
|
101
|
+
wrap.append(table);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
box = el('ul', 'tb-list');
|
|
105
|
+
wrap.append(box);
|
|
106
|
+
}
|
|
107
|
+
const empty = el('p', 'tb-empty');
|
|
108
|
+
wrap.append(empty);
|
|
109
|
+
const choose = (target) => {
|
|
110
|
+
const item = target?.closest(style === 'table' ? 'tr' : 'li');
|
|
111
|
+
const row = item ? rowOf.get(item) : undefined;
|
|
112
|
+
if (row !== undefined)
|
|
113
|
+
void fire('ui-select', face, row);
|
|
114
|
+
};
|
|
115
|
+
box.addEventListener('click', ev => choose(ev.target));
|
|
116
|
+
box.addEventListener('keydown', ev => {
|
|
117
|
+
if (ev.key === 'Enter' || ev.key === ' ') {
|
|
118
|
+
ev.preventDefault();
|
|
119
|
+
choose(ev.target);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
m.box = box;
|
|
123
|
+
m.rows = new Map();
|
|
124
|
+
m.empty = empty;
|
|
125
|
+
return wrap;
|
|
126
|
+
}
|
|
127
|
+
/** The rows of a table or list in the order shown, with their keys; then draws them. */
|
|
128
|
+
export function syncRows(m) {
|
|
129
|
+
const f = m.face;
|
|
130
|
+
const data = get(f, 'data');
|
|
131
|
+
let rows = data.t === K.Block ? data.s.data.slice(data.i) : [];
|
|
132
|
+
if (m.box.tagName === 'TBODY') {
|
|
133
|
+
syncHead(f, m.box.parentElement, columns(f));
|
|
134
|
+
const order = hostSorted(f);
|
|
135
|
+
if (order !== null)
|
|
136
|
+
rows = sortGroups(rows, order.sym, order.desc, activeLanguage(host.rt), cellText);
|
|
137
|
+
}
|
|
138
|
+
const keyWord = get(f, 'key');
|
|
139
|
+
const key = keyWord.t === K.Word || keyWord.t === K.LitWord ? keyWord.sym : intern('id');
|
|
140
|
+
const seen = new Set();
|
|
141
|
+
m.items = rows.map((row, i) => {
|
|
142
|
+
const group = groupRow(row);
|
|
143
|
+
let k;
|
|
144
|
+
if (group !== null)
|
|
145
|
+
k = `${group.kind}#${i}`;
|
|
146
|
+
else {
|
|
147
|
+
const id = rowField(row, key);
|
|
148
|
+
k = id.t === K.None ? `#${i}` : `${id.t}:${form(id)}`;
|
|
149
|
+
if (seen.has(k))
|
|
150
|
+
k = `${k}#${i}`;
|
|
151
|
+
}
|
|
152
|
+
seen.add(k);
|
|
153
|
+
return { row, k };
|
|
154
|
+
});
|
|
155
|
+
drawRows(m);
|
|
156
|
+
m.empty.textContent = str(f, 'text') ?? own('empty');
|
|
157
|
+
m.empty.hidden = rows.length > 0;
|
|
158
|
+
}
|
|
159
|
+
/** Tables and lists with too many rows to draw them all. */
|
|
160
|
+
export const longRows = new Set();
|
|
161
|
+
/** While printing, every row is drawn. */
|
|
162
|
+
export let printing = false;
|
|
163
|
+
/** The rows to draw: all of them, or those near the screen. */
|
|
164
|
+
export function rowsToDraw(m) {
|
|
165
|
+
const count = m.items.length;
|
|
166
|
+
if (count <= DRAW_ALL_UP_TO || printing)
|
|
167
|
+
return { first: 0, end: count };
|
|
168
|
+
// where the first row would be: the rows drawn start below the room of those that are not
|
|
169
|
+
const top = m.box.getBoundingClientRect().top - m.first * m.rowHeight;
|
|
170
|
+
const now = m.end > m.first ? { first: m.first, end: m.end } : undefined;
|
|
171
|
+
return rowWindow(count, m.rowHeight || 48, -top, innerHeight, now);
|
|
172
|
+
}
|
|
173
|
+
/** Creates, updates, moves or removes only the rows drawn whose key changed. */
|
|
174
|
+
export function drawRows(m, again = true) {
|
|
175
|
+
const f = m.face;
|
|
176
|
+
const box = m.box;
|
|
177
|
+
const table = box.tagName === 'TBODY';
|
|
178
|
+
const cols = columns(f);
|
|
179
|
+
const selected = get(f, 'selected');
|
|
180
|
+
const selectable = handlerFor(f, 'on-select');
|
|
181
|
+
box.parentElement.classList.toggle('tb-selectable', selectable);
|
|
182
|
+
const { first, end } = rowsToDraw(m);
|
|
183
|
+
const count = m.items.length;
|
|
184
|
+
const old = m.rows;
|
|
185
|
+
const next = new Map();
|
|
186
|
+
const morph = morphName(get(f, 'morph'));
|
|
187
|
+
const keyWord = get(f, 'key');
|
|
188
|
+
const keySym = keyWord.t === K.Word || keyWord.t === K.LitWord ? keyWord.sym : intern('id');
|
|
189
|
+
// rows added, taken away or in another order move to their places, when all of them are drawn
|
|
190
|
+
const moved = old.size > 0 && count <= DRAW_ALL_UP_TO && !printing && box.isConnected && mayMove()
|
|
191
|
+
&& !sameKeys(old, m.items) && m.items.some(it => old.has(it.k));
|
|
192
|
+
const was = moved ? rowPlaces(old.values()) : null;
|
|
193
|
+
let cursor = box.firstChild;
|
|
194
|
+
for (let i = first; i < end; i++) {
|
|
195
|
+
const { row, k } = m.items[i];
|
|
196
|
+
const group = groupRow(row);
|
|
197
|
+
let item = old.get(k);
|
|
198
|
+
if (group !== null) {
|
|
199
|
+
// a group's head or foot: kept by its place, never chosen, dragged or sorted
|
|
200
|
+
if (item === undefined)
|
|
201
|
+
item = group.kind === 'head' ? newGroupHead(cols, table) : table ? newTableRow(cols) : newListItem();
|
|
202
|
+
item.className = `tb-group-${group.kind} tb-level-${group.level}`;
|
|
203
|
+
if (group.kind === 'head') {
|
|
204
|
+
const t = translate(group.value, host.rt);
|
|
205
|
+
const cell = item.firstElementChild;
|
|
206
|
+
if (cell.textContent !== t)
|
|
207
|
+
cell.textContent = t;
|
|
208
|
+
if (table)
|
|
209
|
+
cell.colSpan = Math.max(1, cols.length);
|
|
210
|
+
}
|
|
211
|
+
else
|
|
212
|
+
fillRow(item, group.value, cols, table);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (item === undefined)
|
|
216
|
+
item = table ? newTableRow(cols) : newListItem();
|
|
217
|
+
rowOf.set(item, row);
|
|
218
|
+
// morph 'client: the row is "client <its key>", for a face of the next screen to become
|
|
219
|
+
if (morph !== null)
|
|
220
|
+
item.dataset['tbMorph'] = `${morph} ${form(rowField(row, keySym))}`;
|
|
221
|
+
else
|
|
222
|
+
delete item.dataset['tbMorph'];
|
|
223
|
+
fillRow(item, row, cols, table);
|
|
224
|
+
if (selectable)
|
|
225
|
+
item.tabIndex = 0;
|
|
226
|
+
else
|
|
227
|
+
item.removeAttribute('tabindex');
|
|
228
|
+
const on = selected.t !== K.None && sameRow(selected, row);
|
|
229
|
+
item.classList.toggle('tb-selected', on);
|
|
230
|
+
if (selectable)
|
|
231
|
+
item.setAttribute('aria-selected', on ? 'true' : 'false');
|
|
232
|
+
else
|
|
233
|
+
item.removeAttribute('aria-selected');
|
|
234
|
+
}
|
|
235
|
+
next.set(k, item);
|
|
236
|
+
// with rows left undrawn, each says where it is among all of them
|
|
237
|
+
if (count > end - first) {
|
|
238
|
+
item.setAttribute(table ? 'aria-rowindex' : 'aria-posinset', String(table ? i + 2 : i + 1));
|
|
239
|
+
if (!table)
|
|
240
|
+
item.setAttribute('aria-setsize', String(count));
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
item.removeAttribute(table ? 'aria-rowindex' : 'aria-posinset');
|
|
244
|
+
item.removeAttribute('aria-setsize');
|
|
245
|
+
}
|
|
246
|
+
if (item !== cursor)
|
|
247
|
+
box.insertBefore(item, cursor);
|
|
248
|
+
else
|
|
249
|
+
cursor = cursor.nextSibling;
|
|
250
|
+
}
|
|
251
|
+
for (const [k, item] of old) {
|
|
252
|
+
if (next.get(k) === item)
|
|
253
|
+
continue;
|
|
254
|
+
if (was !== null)
|
|
255
|
+
leaveRow(item, was.get(item));
|
|
256
|
+
else
|
|
257
|
+
item.remove();
|
|
258
|
+
}
|
|
259
|
+
m.rows = next;
|
|
260
|
+
if (was !== null)
|
|
261
|
+
moveRows(next.values(), was);
|
|
262
|
+
m.first = first;
|
|
263
|
+
m.end = end;
|
|
264
|
+
if (table) {
|
|
265
|
+
if (count > end - first)
|
|
266
|
+
box.parentElement.setAttribute('aria-rowcount', String(count + 1));
|
|
267
|
+
else
|
|
268
|
+
box.parentElement.removeAttribute('aria-rowcount');
|
|
269
|
+
}
|
|
270
|
+
if (count <= DRAW_ALL_UP_TO) {
|
|
271
|
+
longRows.delete(m);
|
|
272
|
+
room(m, 0, 0);
|
|
273
|
+
if (table)
|
|
274
|
+
keepColumns(box.parentElement, false);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
longRows.add(m);
|
|
278
|
+
if (table)
|
|
279
|
+
keepColumns(box.parentElement, true);
|
|
280
|
+
// how tall a row is, from those drawn; the room of the others follows it
|
|
281
|
+
const drawn = end - first;
|
|
282
|
+
const h = box.getBoundingClientRect().height - (table ? 0 : parseFloat(box.style.paddingTop || '0') + parseFloat(box.style.paddingBottom || '0'));
|
|
283
|
+
if (drawn > 0 && h > 0)
|
|
284
|
+
m.rowHeight = h / drawn;
|
|
285
|
+
room(m, first * m.rowHeight, (count - end) * m.rowHeight);
|
|
286
|
+
// a first guess of the height may have drawn the wrong rows
|
|
287
|
+
if (again) {
|
|
288
|
+
const want = rowsToDraw(m);
|
|
289
|
+
if (want.first !== first || want.end !== end)
|
|
290
|
+
drawRows(m, false);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/** A morph name, 'logo or [client 7], as text: "logo", "client 7"; null for none. */
|
|
294
|
+
export function morphName(v) {
|
|
295
|
+
if (v.t === K.Word || v.t === K.LitWord)
|
|
296
|
+
return spell(v.sym);
|
|
297
|
+
if (v.t === K.Block)
|
|
298
|
+
return v.s.data.slice(v.i).map(c => form(c)).join(' ');
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
/** Whether the rows drawn are the rows to draw, in the same order. */
|
|
302
|
+
export function sameKeys(old, items) {
|
|
303
|
+
if (old.size !== items.length)
|
|
304
|
+
return false;
|
|
305
|
+
let i = 0;
|
|
306
|
+
for (const k of old.keys())
|
|
307
|
+
if (items[i++].k !== k)
|
|
308
|
+
return false;
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* A long table keeps the widths its columns first took, as shares of its width,
|
|
313
|
+
* so they do not change with the rows drawn while it scrolls.
|
|
314
|
+
*/
|
|
315
|
+
export function keepColumns(table, keep) {
|
|
316
|
+
const ths = Array.from(table.tHead.rows[0].cells);
|
|
317
|
+
if (!keep) {
|
|
318
|
+
table.classList.remove('tb-fixed');
|
|
319
|
+
for (const th of ths)
|
|
320
|
+
th.style.width = '';
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (table.classList.contains('tb-fixed'))
|
|
324
|
+
return;
|
|
325
|
+
const widths = ths.map(th => th.getBoundingClientRect().width);
|
|
326
|
+
const all = widths.reduce((a, b) => a + b, 0);
|
|
327
|
+
// on a narrow screen the rows are cards and the headers take no room: later
|
|
328
|
+
if (all === 0)
|
|
329
|
+
return;
|
|
330
|
+
ths.forEach((th, i) => { th.style.width = `${(widths[i] / all) * 100}%`; });
|
|
331
|
+
table.classList.add('tb-fixed');
|
|
332
|
+
}
|
|
333
|
+
/** Sets the room of the rows not drawn above and below those drawn. */
|
|
334
|
+
export function room(m, above, below) {
|
|
335
|
+
const box = m.box;
|
|
336
|
+
if (box.tagName === 'TBODY') {
|
|
337
|
+
for (const [b, px] of [[box.previousElementSibling, above], [box.nextElementSibling, below]]) {
|
|
338
|
+
const td = b.querySelector('td');
|
|
339
|
+
td.style.height = `${px}px`;
|
|
340
|
+
b.hidden = px === 0;
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
box.style.paddingTop = above > 0 ? `${above}px` : '';
|
|
345
|
+
box.style.paddingBottom = below > 0 ? `${below}px` : '';
|
|
346
|
+
}
|
|
347
|
+
export let rowsFrame = 0;
|
|
348
|
+
/** On a scroll or a resize, the long tables and lists draw the rows now near the screen. */
|
|
349
|
+
export function onRowsMoved() {
|
|
350
|
+
if (rowsFrame !== 0 || longRows.size === 0)
|
|
351
|
+
return;
|
|
352
|
+
rowsFrame = requestAnimationFrame(() => {
|
|
353
|
+
rowsFrame = 0;
|
|
354
|
+
for (const m of longRows) {
|
|
355
|
+
if (!m.box.isConnected) {
|
|
356
|
+
longRows.delete(m);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
const want = rowsToDraw(m);
|
|
360
|
+
if (want.first !== m.first || want.end !== m.end)
|
|
361
|
+
drawRows(m);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/** Printing draws every row, and the screen goes back to drawing some after. */
|
|
366
|
+
export function onPrint(on) {
|
|
367
|
+
printing = on;
|
|
368
|
+
for (const m of longRows) {
|
|
369
|
+
if (!m.box.isConnected)
|
|
370
|
+
continue;
|
|
371
|
+
// all the rows cover the screen, but are not to be kept
|
|
372
|
+
if (!on)
|
|
373
|
+
m.end = m.first;
|
|
374
|
+
drawRows(m);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/** Headers in the active language; in a sortable table each is a button, with an arrow on the sorted one. */
|
|
378
|
+
export function syncHead(f, table, cols) {
|
|
379
|
+
const sortable = flag(f, 'sortable') || handlerFor(f, 'on-sort');
|
|
380
|
+
const order = sortedBy(f);
|
|
381
|
+
const ths = table.tHead.rows[0].cells;
|
|
382
|
+
cols.forEach((c, i) => {
|
|
383
|
+
const th = ths[i];
|
|
384
|
+
if (th === undefined)
|
|
385
|
+
return;
|
|
386
|
+
const on = order !== null && canon(order.sym) === canon(c.sym);
|
|
387
|
+
let button = th.querySelector('.tb-sort');
|
|
388
|
+
if (sortable && button === null) {
|
|
389
|
+
button = el('button', 'tb-sort');
|
|
390
|
+
button.type = 'button';
|
|
391
|
+
button.append(el('span'));
|
|
392
|
+
th.replaceChildren(button);
|
|
393
|
+
}
|
|
394
|
+
else if (!sortable && button !== null) {
|
|
395
|
+
th.replaceChildren();
|
|
396
|
+
button = null;
|
|
397
|
+
}
|
|
398
|
+
const label = button !== null ? button.firstChild : th;
|
|
399
|
+
if (label.textContent !== c.label)
|
|
400
|
+
label.textContent = c.label;
|
|
401
|
+
if (button !== null) {
|
|
402
|
+
// the button stays, so a header chosen from the keyboard keeps the focus
|
|
403
|
+
const arrow = on && order.desc ? 'arrow-down' : 'arrow-up';
|
|
404
|
+
const svg = button.querySelector('svg');
|
|
405
|
+
if (svg?.dataset['icon'] !== arrow) {
|
|
406
|
+
const next = icon(arrow);
|
|
407
|
+
if (next !== null) {
|
|
408
|
+
next.dataset['icon'] = arrow;
|
|
409
|
+
if (svg)
|
|
410
|
+
svg.replaceWith(next);
|
|
411
|
+
else
|
|
412
|
+
button.append(next);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
button.querySelector('svg')?.classList.toggle('tb-sort-idle', !on);
|
|
416
|
+
}
|
|
417
|
+
if (on)
|
|
418
|
+
th.setAttribute('aria-sort', order.desc ? 'descending' : 'ascending');
|
|
419
|
+
else
|
|
420
|
+
th.removeAttribute('aria-sort');
|
|
421
|
+
});
|
|
422
|
+
const totals = get(f, 'totals');
|
|
423
|
+
const foot = table.tFoot;
|
|
424
|
+
foot.hidden = totals.t === K.None;
|
|
425
|
+
if (totals.t !== K.None)
|
|
426
|
+
fillRow(foot.rows[0], totals, cols, true);
|
|
427
|
+
}
|
|
428
|
+
/** A table's sorted facet: [column asc] or [column desc]. */
|
|
429
|
+
export function sortedBy(f) {
|
|
430
|
+
const v = get(f, 'sorted');
|
|
431
|
+
if (v.t !== K.Block || v.s.data.length - v.i < 2)
|
|
432
|
+
return null;
|
|
433
|
+
const c = v.s.data[v.i];
|
|
434
|
+
const o = v.s.data[v.i + 1];
|
|
435
|
+
if ((c.t !== K.Word && c.t !== K.LitWord) || (o.t !== K.Word && o.t !== K.LitWord))
|
|
436
|
+
return null;
|
|
437
|
+
return { sym: c.sym, desc: canon(o.sym) === canon(intern('desc')) };
|
|
438
|
+
}
|
|
439
|
+
/** The order the host applies itself: a sortable table without on-sort, which sorts for itself. */
|
|
440
|
+
export function hostSorted(f) {
|
|
441
|
+
return flag(f, 'sortable') && !handlerFor(f, 'on-sort') ? sortedBy(f) : null;
|
|
442
|
+
}
|
|
443
|
+
/** A group's title, the width of the whole row. */
|
|
444
|
+
export function newGroupHead(cols, table) {
|
|
445
|
+
if (!table) {
|
|
446
|
+
const li = el('li');
|
|
447
|
+
li.append(el('span'));
|
|
448
|
+
return li;
|
|
449
|
+
}
|
|
450
|
+
const tr = el('tr');
|
|
451
|
+
tr.setAttribute('role', 'row');
|
|
452
|
+
const th = el('th');
|
|
453
|
+
th.scope = 'rowgroup';
|
|
454
|
+
th.setAttribute('role', 'rowheader');
|
|
455
|
+
th.colSpan = Math.max(1, cols.length);
|
|
456
|
+
tr.append(th);
|
|
457
|
+
return tr;
|
|
458
|
+
}
|
|
459
|
+
export function newTableRow(cols) {
|
|
460
|
+
const tr = el('tr');
|
|
461
|
+
tr.setAttribute('role', 'row');
|
|
462
|
+
for (const c of cols) {
|
|
463
|
+
const td = el('td');
|
|
464
|
+
td.setAttribute('role', 'cell');
|
|
465
|
+
td.dataset['label'] = c.label;
|
|
466
|
+
tr.append(td);
|
|
467
|
+
}
|
|
468
|
+
return tr;
|
|
469
|
+
}
|
|
470
|
+
export function newListItem() {
|
|
471
|
+
const li = el('li');
|
|
472
|
+
const texts = el('span', 'tb-list-texts');
|
|
473
|
+
texts.append(el('span', 'tb-list-primary'), el('span', 'tb-list-secondary'));
|
|
474
|
+
li.append(texts);
|
|
475
|
+
return li;
|
|
476
|
+
}
|
|
477
|
+
export function fillRow(item, row, cols, table) {
|
|
478
|
+
const set = (e, t) => {
|
|
479
|
+
if (e.textContent !== t)
|
|
480
|
+
e.textContent = t;
|
|
481
|
+
};
|
|
482
|
+
if (table) {
|
|
483
|
+
cols.forEach((c, i) => {
|
|
484
|
+
const v = rowField(row, c.sym);
|
|
485
|
+
const td = item.children[i];
|
|
486
|
+
if (c.image) {
|
|
487
|
+
td.classList.add('tb-thumb-cell');
|
|
488
|
+
return thumb(td, v, c.round);
|
|
489
|
+
}
|
|
490
|
+
set(td, cellText(v));
|
|
491
|
+
td.classList.toggle('tb-num', NUMERIC.has(v.t));
|
|
492
|
+
});
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
// a list shows its picture first, then its first column, and the others on a quieter line
|
|
496
|
+
const pic = cols.find(c => c.image);
|
|
497
|
+
if (pic !== undefined)
|
|
498
|
+
thumb(item, rowField(row, pic.sym), pic.round);
|
|
499
|
+
else
|
|
500
|
+
item.querySelector(':scope > .tb-thumb')?.remove();
|
|
501
|
+
const [first, ...rest] = cols.filter(c => !c.image).map(c => cellText(rowField(row, c.sym)));
|
|
502
|
+
const texts = item.querySelector(':scope > .tb-list-texts');
|
|
503
|
+
set(texts.children[0], first ?? '');
|
|
504
|
+
set(texts.children[1], rest.filter(Boolean).join(' · '));
|
|
505
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Cell, type ObjectCell } from '../../core/index.ts';
|
|
2
|
+
export interface Times {
|
|
3
|
+
face: ObjectCell;
|
|
4
|
+
opener: HTMLButtonElement;
|
|
5
|
+
list: HTMLElement;
|
|
6
|
+
}
|
|
7
|
+
export declare let times: Times | null;
|
|
8
|
+
/** The minutes of a time! cell since midnight, or null. */
|
|
9
|
+
export declare function minutesOf(v: Cell): number | null;
|
|
10
|
+
export declare function openTimes(face: ObjectCell, opener: HTMLButtonElement): void;
|
|
11
|
+
export declare function closeTimes(refocus?: boolean): void;
|
|
12
|
+
export declare function outsideTimes(ev: PointerEvent): void;
|
|
13
|
+
export declare function pickTime(at: string): void;
|
|
14
|
+
export declare function timesKey(ev: KeyboardEvent): void;
|