@zeyos/zx 5.4.0 → 5.6.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/CHANGELOG.md +136 -0
- package/README.md +23 -16
- package/dist/types/components/agent-thread/agent-thread.d.ts +583 -0
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +33 -0
- package/dist/types/components/approval-card/approval-card.d.ts +596 -0
- package/dist/types/components/avatar/avatar.d.ts +91 -4
- package/dist/types/components/badge/badge.d.ts +5 -4
- package/dist/types/components/block-view/block-view.d.ts +205 -0
- package/dist/types/components/composer/composer.d.ts +736 -0
- package/dist/types/components/datebox/date-range-box.d.ts +15 -2
- package/dist/types/components/datebox/datebox.d.ts +37 -3
- package/dist/types/components/kbd/kbd.d.ts +41 -0
- package/dist/types/components/launcher/launcher.d.ts +4 -2
- package/dist/types/components/prose/prose.d.ts +69 -0
- package/dist/types/components/questionnaire/questionnaire.d.ts +0 -36
- package/dist/types/components/run-status/run-status.d.ts +393 -0
- package/dist/types/components/run-trace/run-trace.d.ts +624 -0
- package/dist/types/components/source-list/source-list.d.ts +177 -0
- package/dist/types/components/stat-tile/stat-tile.d.ts +20 -0
- package/dist/types/components/tag-picker/tag-picker.d.ts +11 -5
- package/dist/types/components/tree/tree.d.ts +44 -3
- package/dist/types/core/icons.d.ts +22 -1
- package/dist/types/core/messages.d.ts +135 -0
- package/dist/types/index.d.ts +12 -2
- package/dist/types/internal/agent-model.d.ts +587 -0
- package/dist/types/internal/app-rail.d.ts +10 -3
- package/dist/types/internal/highlight.d.ts +24 -0
- package/dist/types/internal/presence-loop.d.ts +148 -0
- package/dist/types/internal/row-actions.d.ts +151 -0
- package/dist/zx-zeyos.esm.js +4852 -4535
- package/dist/zx-zeyos.esm.min.js +4 -4
- package/dist/zx.css +3152 -434
- package/dist/zx.esm.js +13730 -6595
- package/dist/zx.esm.min.js +27 -8
- package/dist/zx.global.js +13730 -6595
- package/dist/zx.global.min.js +27 -8
- package/dist/zx.min.css +1 -1
- package/docs/api.json +1474 -205
- package/docs/llms.md +698 -39
- package/docs/llms.txt +12 -1
- package/package.json +1 -1
- package/src/components/account-menu/account-menu.js +2 -2
- package/src/components/agent-thread/agent-thread.css +417 -0
- package/src/components/agent-thread/agent-thread.js +1365 -0
- package/src/components/app-rail/app-rail.css +11 -11
- package/src/components/app-sidebar/app-sidebar.css +90 -17
- package/src/components/app-sidebar/app-sidebar.js +120 -12
- package/src/components/approval-card/approval-card.css +289 -0
- package/src/components/approval-card/approval-card.js +1377 -0
- package/src/components/avatar/avatar.css +56 -1
- package/src/components/avatar/avatar.js +148 -26
- package/src/components/badge/badge.css +33 -20
- package/src/components/badge/badge.js +5 -4
- package/src/components/block-view/block-view.css +300 -0
- package/src/components/block-view/block-view.js +523 -0
- package/src/components/breadcrumb/breadcrumb.css +28 -3
- package/src/components/breadcrumb/breadcrumb.js +2 -2
- package/src/components/button/button.css +24 -13
- package/src/components/button/button.js +20 -2
- package/src/components/calendar/calendar.css +14 -4
- package/src/components/card-view/card-view.js +2 -2
- package/src/components/chart/chart.js +20 -5
- package/src/components/check-button/check-button.css +11 -3
- package/src/components/check-button/check-button.js +3 -3
- package/src/components/composer/composer.css +403 -0
- package/src/components/composer/composer.js +1441 -0
- package/src/components/context-menu/context-menu.css +7 -1
- package/src/components/date-picker/date-picker.css +6 -0
- package/src/components/date-picker/date-picker.js +5 -5
- package/src/components/date-picker/date-range-picker.css +6 -0
- package/src/components/date-picker/date-range-picker.js +3 -3
- package/src/components/date-picker/month-picker.js +3 -3
- package/src/components/date-picker/time-picker.css +6 -0
- package/src/components/datebox/date-range-box.js +30 -6
- package/src/components/datebox/datebox.js +44 -7
- package/src/components/dialog/dialog.css +0 -1
- package/src/components/dialog/dialog.js +2 -1
- package/src/components/dock/dock.js +2 -2
- package/src/components/dropdown/dropdown.css +2 -1
- package/src/components/entity-ref/entity-ref.css +8 -1
- package/src/components/file-item/file-item.css +1 -1
- package/src/components/finder/finder.js +2 -2
- package/src/components/groupbox/groupbox.js +2 -2
- package/src/components/kanban-view/kanban-view.css +8 -4
- package/src/components/kanban-view/kanban-view.js +3 -3
- package/src/components/kbd/kbd.css +64 -0
- package/src/components/kbd/kbd.js +121 -0
- package/src/components/launcher/launcher.css +30 -25
- package/src/components/launcher/launcher.js +15 -21
- package/src/components/list-toolbar/list-toolbar.css +7 -1
- package/src/components/menu-button/menu-button.css +9 -2
- package/src/components/message/message.js +2 -2
- package/src/components/module-bar/module-bar.css +11 -1
- package/src/components/multi-value-editor/multi-value-editor.js +4 -4
- package/src/components/navigation-bar/navigation-bar.css +3 -2
- package/src/components/pagination/pagination.js +2 -2
- package/src/components/panel/panel.js +2 -2
- package/src/components/prose/prose.css +53 -0
- package/src/components/prose/prose.js +152 -0
- package/src/components/questionnaire/questionnaire.css +7 -17
- package/src/components/questionnaire/questionnaire.js +16 -1
- package/src/components/rating/rating.css +3 -1
- package/src/components/run-status/run-status.css +208 -0
- package/src/components/run-status/run-status.js +782 -0
- package/src/components/run-trace/run-trace.css +443 -0
- package/src/components/run-trace/run-trace.js +1209 -0
- package/src/components/search/search.js +2 -2
- package/src/components/select/glyphs.js +3 -3
- package/src/components/select/select.css +35 -7
- package/src/components/select/select.js +4 -4
- package/src/components/source-list/source-list.css +208 -0
- package/src/components/source-list/source-list.js +355 -0
- package/src/components/stat-tile/stat-tile.css +56 -2
- package/src/components/stat-tile/stat-tile.js +25 -2
- package/src/components/stepper/stepper.css +2 -1
- package/src/components/stepper/stepper.js +3 -3
- package/src/components/tabbox/tabbox.css +2 -2
- package/src/components/tabbox/tabbox.js +2 -2
- package/src/components/table/table.css +52 -16
- package/src/components/table/table.js +7 -5
- package/src/components/tag-picker/tag-picker.css +56 -43
- package/src/components/tag-picker/tag-picker.js +21 -16
- package/src/components/tree/tree.css +44 -0
- package/src/components/tree/tree.js +97 -9
- package/src/components/value-list/value-list.css +25 -4
- package/src/components/value-list/value-list.js +2 -1
- package/src/components/view/record-view.js +3 -3
- package/src/components/view-settings/view-settings.css +2 -1
- package/src/components/workspace-switcher/workspace-switcher.js +3 -3
- package/src/core/icons.js +34 -3
- package/src/core/messages.js +143 -0
- package/src/elements/define.js +1 -0
- package/src/index.js +12 -2
- package/src/internal/agent-model.js +488 -0
- package/src/internal/app-rail.js +5 -1
- package/src/internal/highlight.js +104 -0
- package/src/internal/presence-loop.js +343 -0
- package/src/internal/row-actions.js +203 -0
- package/styles/base.css +26 -1
- package/styles/prose.css +306 -0
- package/styles/tokens/dark.css +97 -120
- package/styles/tokens/global.css +24 -9
- package/styles/tokens/semantic.css +464 -184
- package/styles/tokens/themes.css +9 -0
- package/styles/zx.css +10 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* The one animation loop every moving agent avatar on a page shares.
|
|
4
|
+
*
|
|
5
|
+
* An avatar joins with `trackPresence(element, activity)` and leaves with `untrack()`. The loop
|
|
6
|
+
* lives on the avatar's document under a symbol-keyed property — never in module scope — and is
|
|
7
|
+
* created with the first tracked avatar and torn down with the last. It moves only avatars on
|
|
8
|
+
* screen (an `IntersectionObserver`), eases from one pose to the next when an activity changes,
|
|
9
|
+
* clamps its frame step so a long frame never makes an avatar jump, and sleeps while the page is
|
|
10
|
+
* hidden or nothing is moving. Under reduced motion — the system's, or a `data-zx-motion="reduced"`
|
|
11
|
+
* region around an avatar, followed through `watchMotion()` — every avatar returns to rest and the
|
|
12
|
+
* loop stops. It writes `transform` and nothing else.
|
|
13
|
+
*
|
|
14
|
+
* Motion is never the only signal: an avatar's activity is also its dot and its word.
|
|
15
|
+
*/
|
|
16
|
+
import { prefersReducedMotion, watchMotion } from '../core/motion.js';
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('./agent-model.js').AgentActivity} AgentActivity */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Where an avatar wants to be at one moment: a vertical offset in pixels, a rotation in degrees, a
|
|
22
|
+
* scale, how much a blink may squash it (`w`, eased like the rest), and the blink's depth now.
|
|
23
|
+
* @typedef {{y: number, r: number, s: number, w: number, blink: number}} PresencePose
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} PresenceHandle
|
|
28
|
+
* @property {(activity: AgentActivity|string|null, options?: TrackOptions) => void} set Changes
|
|
29
|
+
* what the avatar is doing, and its phase when `options.phase` is given; the loop eases it into
|
|
30
|
+
* the new pose.
|
|
31
|
+
* @property {() => void} untrack Leaves the loop and puts the avatar back at rest. Safe to call
|
|
32
|
+
* more than once.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {Object} TrackOptions
|
|
37
|
+
* @property {number} [phase=0] Where in its cycle this avatar moves, as a fraction of the cycle
|
|
38
|
+
* from 0 up to 1 (whole turns wrap; anything that is not a finite number is 0). Avatars in the same
|
|
39
|
+
* activity at different phases never move in step: 0.5 is half a cycle apart, whatever the
|
|
40
|
+
* activity. `presencePhase(key)` derives one from a stable key.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/** The longest step one frame may take, so a frame after a stall eases instead of jumping. */
|
|
44
|
+
export const MAX_FRAME_MS = 50;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* How long one cycle of each moving activity takes, in seconds. Needs-you counts its blink beat;
|
|
48
|
+
* its lean runs on a shorter period of its own.
|
|
49
|
+
*/
|
|
50
|
+
const PERIODS = Object.freeze({ idle: 4.8, thinking: 3.4, working: 1.1, 'needs-you': 3.6 });
|
|
51
|
+
|
|
52
|
+
/** How quickly a pose follows its target: the fraction left after one second is e^-8. */
|
|
53
|
+
const EASE_RATE = 8;
|
|
54
|
+
|
|
55
|
+
/** The pose at rest. */
|
|
56
|
+
const REST = Object.freeze({ y: 0, r: 0, s: 1, w: 0, blink: 0 });
|
|
57
|
+
|
|
58
|
+
/** Where the shared loop is kept on its document. */
|
|
59
|
+
const LOOP = Symbol('zx.presenceLoop');
|
|
60
|
+
|
|
61
|
+
/** A handle that does nothing, for an environment the loop cannot run in. */
|
|
62
|
+
const INERT = Object.freeze({ set() {}, untrack() {} });
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The pose of an avatar doing `activity` at time `t`. Pure: the same input always gives the same
|
|
66
|
+
* pose. Idle breathes, thinking sways, working bobs, and needs-you leans and blinks; blocked,
|
|
67
|
+
* offline, and anything unknown stay at rest.
|
|
68
|
+
* @param {AgentActivity|string|null|undefined} activity
|
|
69
|
+
* @param {number} t Seconds.
|
|
70
|
+
* @returns {PresencePose}
|
|
71
|
+
*/
|
|
72
|
+
export function presencePose(activity, t) {
|
|
73
|
+
const time = Number.isFinite(t) ? t : 0;
|
|
74
|
+
/** @param {number} period @returns {number} 0 → 1 → 0 over one period. */
|
|
75
|
+
const cycle = (period) => 0.5 - 0.5 * Math.cos((2 * Math.PI * time) / period);
|
|
76
|
+
switch (activity) {
|
|
77
|
+
case 'idle': return { y: 0, r: 0, s: 1 + 0.035 * cycle(4.8), w: 0, blink: 0 };
|
|
78
|
+
case 'thinking': return { y: 0, r: 4 * Math.sin((2 * Math.PI * time) / 3.4), s: 1, w: 0, blink: 0 };
|
|
79
|
+
case 'working': return { y: -1.6 * cycle(1.1), r: 0, s: 1, w: 0, blink: 0 };
|
|
80
|
+
case 'needs-you': {
|
|
81
|
+
const beat = ((time % 3.6) + 3.6) % 3.6;
|
|
82
|
+
const blink = beat < 0.18 ? Math.sin((Math.PI * beat) / 0.18) : 0;
|
|
83
|
+
return { y: 0, r: -8 + Math.sin((2 * Math.PI * time) / 2.6), s: 1, w: 1, blink: 0.28 * blink };
|
|
84
|
+
}
|
|
85
|
+
default: return { ...REST };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A stable phase for a key, as a fraction of the cycle from 0 up to 1, so two avatars never move in
|
|
91
|
+
* step and the same avatar always moves the same way.
|
|
92
|
+
* @param {unknown} key
|
|
93
|
+
* @returns {number}
|
|
94
|
+
*/
|
|
95
|
+
export function presencePhase(key) {
|
|
96
|
+
let hash = 0;
|
|
97
|
+
for (const char of String(key ?? '')) hash = (hash * 31 + (char.codePointAt(0) ?? 0)) % 997;
|
|
98
|
+
return hash / 997;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Reads a phase: a finite number wrapped into a fraction from 0 up to 1 (`1.25` is `0.25`, `-0.25`
|
|
103
|
+
* is `0.75`), or null for anything else.
|
|
104
|
+
* @param {unknown} phase
|
|
105
|
+
* @returns {number|null}
|
|
106
|
+
*/
|
|
107
|
+
export function normalizePhase(phase) {
|
|
108
|
+
if (typeof phase !== 'number' || !Number.isFinite(phase)) return null;
|
|
109
|
+
const turn = phase % 1;
|
|
110
|
+
return turn < 0 ? turn + 1 : turn;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* How long one cycle of an activity takes, in seconds; 0 for one that stays at rest.
|
|
115
|
+
* @param {AgentActivity|string|null|undefined} activity
|
|
116
|
+
* @returns {number}
|
|
117
|
+
*/
|
|
118
|
+
export function presencePeriod(activity) {
|
|
119
|
+
return typeof activity === 'string' && Object.hasOwn(PERIODS, activity) ? PERIODS[/** @type {keyof typeof PERIODS} */ (activity)] : 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The seconds a phase moves an avatar along its activity's cycle.
|
|
124
|
+
* @param {AgentActivity|string|null|undefined} activity
|
|
125
|
+
* @param {unknown} phase A fraction of the cycle; see `normalizePhase()`.
|
|
126
|
+
* @returns {number}
|
|
127
|
+
*/
|
|
128
|
+
export function presenceOffset(activity, phase) {
|
|
129
|
+
return (normalizePhase(phase) ?? 0) * presencePeriod(activity);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Whether a pose is at rest, to within what a screen can show.
|
|
134
|
+
* @param {{y: number, r: number, s: number, w: number}} pose
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
*/
|
|
137
|
+
function settled(pose) {
|
|
138
|
+
return Math.abs(pose.y) < 0.01 && Math.abs(pose.r) < 0.01 && Math.abs(pose.s - 1) < 0.0005 && Math.abs(pose.w) < 0.01;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @typedef {Object} Entry
|
|
143
|
+
* @property {string|null} activity
|
|
144
|
+
* @property {number} phase A fraction of the cycle.
|
|
145
|
+
* @property {{y: number, r: number, s: number, w: number}} pose
|
|
146
|
+
* @property {boolean} visible
|
|
147
|
+
* @property {boolean} reduced
|
|
148
|
+
* @property {boolean} moved Whether the loop has written a transform it has not cleared.
|
|
149
|
+
* @property {() => void} unwatch
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @typedef {Object} Loop
|
|
154
|
+
* @property {Document} document
|
|
155
|
+
* @property {Map<HTMLElement, Entry>} entries
|
|
156
|
+
* @property {IntersectionObserver} observer
|
|
157
|
+
* @property {AbortController} abort
|
|
158
|
+
* @property {number} frame
|
|
159
|
+
* @property {number} last
|
|
160
|
+
* @property {number} time
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Adds an element to its document's presence loop. The element's `transform` belongs to the loop
|
|
165
|
+
* while it is tracked; `untrack()` clears it. Where `requestAnimationFrame` or
|
|
166
|
+
* `IntersectionObserver` is missing the handle does nothing.
|
|
167
|
+
* @param {HTMLElement} element What moves: the avatar's root.
|
|
168
|
+
* @param {AgentActivity|string|null} activity What the avatar is doing.
|
|
169
|
+
* @param {TrackOptions} [options={}]
|
|
170
|
+
* @returns {PresenceHandle}
|
|
171
|
+
*/
|
|
172
|
+
export function trackPresence(element, activity, options = {}) {
|
|
173
|
+
const doc = element?.ownerDocument;
|
|
174
|
+
if (!doc || typeof globalThis.requestAnimationFrame !== 'function'
|
|
175
|
+
|| typeof globalThis.IntersectionObserver !== 'function') return INERT;
|
|
176
|
+
const loop = loopOf(doc);
|
|
177
|
+
const existing = loop.entries.get(element);
|
|
178
|
+
if (existing) {
|
|
179
|
+
existing.activity = activity ?? null;
|
|
180
|
+
if (options && Object.hasOwn(options, 'phase')) existing.phase = normalizePhase(options.phase) ?? 0;
|
|
181
|
+
schedule(loop);
|
|
182
|
+
return handleFor(loop, element);
|
|
183
|
+
}
|
|
184
|
+
/** @type {Entry} */
|
|
185
|
+
const entry = {
|
|
186
|
+
activity: activity ?? null,
|
|
187
|
+
phase: normalizePhase(options?.phase) ?? 0,
|
|
188
|
+
pose: { y: 0, r: 0, s: 1, w: 0 },
|
|
189
|
+
visible: false,
|
|
190
|
+
reduced: prefersReducedMotion(element),
|
|
191
|
+
moved: false,
|
|
192
|
+
unwatch: () => {}
|
|
193
|
+
};
|
|
194
|
+
loop.entries.set(element, entry);
|
|
195
|
+
entry.unwatch = watchMotion(element, (reduced) => {
|
|
196
|
+
entry.reduced = reduced;
|
|
197
|
+
if (reduced) rest(element, entry);
|
|
198
|
+
else schedule(loop);
|
|
199
|
+
});
|
|
200
|
+
loop.observer.observe(element);
|
|
201
|
+
return handleFor(loop, element);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {Loop} loop
|
|
206
|
+
* @param {HTMLElement} element
|
|
207
|
+
* @returns {PresenceHandle}
|
|
208
|
+
*/
|
|
209
|
+
function handleFor(loop, element) {
|
|
210
|
+
return {
|
|
211
|
+
set(activity, options) {
|
|
212
|
+
const entry = loop.entries.get(element);
|
|
213
|
+
if (!entry) return;
|
|
214
|
+
entry.activity = activity ?? null;
|
|
215
|
+
if (options && Object.hasOwn(options, 'phase')) entry.phase = normalizePhase(options.phase) ?? 0;
|
|
216
|
+
schedule(loop);
|
|
217
|
+
},
|
|
218
|
+
untrack() {
|
|
219
|
+
const entry = loop.entries.get(element);
|
|
220
|
+
if (!entry) return;
|
|
221
|
+
loop.entries.delete(element);
|
|
222
|
+
entry.unwatch();
|
|
223
|
+
loop.observer.unobserve(element);
|
|
224
|
+
rest(element, entry);
|
|
225
|
+
if (loop.entries.size === 0) teardown(loop);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The document's loop, created on first use.
|
|
232
|
+
* @param {Document} doc
|
|
233
|
+
* @returns {Loop}
|
|
234
|
+
*/
|
|
235
|
+
function loopOf(doc) {
|
|
236
|
+
const host = /** @type {Document & {[LOOP]?: Loop}} */ (doc);
|
|
237
|
+
const current = host[LOOP];
|
|
238
|
+
if (current) return current;
|
|
239
|
+
/** @type {Loop} */
|
|
240
|
+
const loop = {
|
|
241
|
+
document: doc,
|
|
242
|
+
entries: new Map(),
|
|
243
|
+
observer: new IntersectionObserver((records) => {
|
|
244
|
+
for (const record of records) {
|
|
245
|
+
const entry = loop.entries.get(/** @type {HTMLElement} */ (record.target));
|
|
246
|
+
if (!entry) continue;
|
|
247
|
+
entry.visible = record.isIntersecting;
|
|
248
|
+
// An avatar built before it was attached could not see the region it landed in.
|
|
249
|
+
if (entry.visible) entry.reduced = prefersReducedMotion(record.target);
|
|
250
|
+
if (entry.reduced) rest(/** @type {HTMLElement} */ (record.target), entry);
|
|
251
|
+
}
|
|
252
|
+
schedule(loop);
|
|
253
|
+
}),
|
|
254
|
+
abort: new AbortController(),
|
|
255
|
+
frame: 0,
|
|
256
|
+
last: 0,
|
|
257
|
+
time: 0
|
|
258
|
+
};
|
|
259
|
+
doc.addEventListener('visibilitychange', () => {
|
|
260
|
+
if (doc.hidden) cancel(loop);
|
|
261
|
+
else schedule(loop);
|
|
262
|
+
}, { signal: loop.abort.signal });
|
|
263
|
+
host[LOOP] = loop;
|
|
264
|
+
return loop;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** @param {Loop} loop @returns {void} */
|
|
268
|
+
function teardown(loop) {
|
|
269
|
+
cancel(loop);
|
|
270
|
+
loop.observer.disconnect();
|
|
271
|
+
loop.abort.abort();
|
|
272
|
+
const host = /** @type {Document & {[LOOP]?: Loop}} */ (loop.document);
|
|
273
|
+
if (host[LOOP] === loop) delete host[LOOP];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @param {Loop} loop @returns {boolean} Whether any avatar could move now. */
|
|
277
|
+
function runnable(loop) {
|
|
278
|
+
if (loop.document.hidden) return false;
|
|
279
|
+
for (const entry of loop.entries.values()) {
|
|
280
|
+
if (entry.visible && !entry.reduced) return true;
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Starts the loop unless it is running or has nothing to move. @param {Loop} loop @returns {void} */
|
|
286
|
+
function schedule(loop) {
|
|
287
|
+
if (loop.frame || !runnable(loop)) return;
|
|
288
|
+
loop.last = performance.now();
|
|
289
|
+
loop.frame = requestAnimationFrame((now) => step(loop, now));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** @param {Loop} loop @returns {void} */
|
|
293
|
+
function cancel(loop) {
|
|
294
|
+
if (loop.frame) cancelAnimationFrame(loop.frame);
|
|
295
|
+
loop.frame = 0;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Puts one avatar back at rest at once.
|
|
300
|
+
* @param {HTMLElement} element
|
|
301
|
+
* @param {Entry} entry
|
|
302
|
+
* @returns {void}
|
|
303
|
+
*/
|
|
304
|
+
function rest(element, entry) {
|
|
305
|
+
entry.pose = { y: 0, r: 0, s: 1, w: 0 };
|
|
306
|
+
if (entry.moved) element.style.removeProperty('transform');
|
|
307
|
+
entry.moved = false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* One frame: every visible avatar eases toward its pose; the loop goes on only while one moves.
|
|
312
|
+
* @param {Loop} loop
|
|
313
|
+
* @param {number} now
|
|
314
|
+
* @returns {void}
|
|
315
|
+
*/
|
|
316
|
+
function step(loop, now) {
|
|
317
|
+
loop.frame = 0;
|
|
318
|
+
if (loop.document.hidden) return;
|
|
319
|
+
const dt = Math.min(Math.max(now - loop.last, 0), MAX_FRAME_MS) / 1000;
|
|
320
|
+
loop.last = now;
|
|
321
|
+
loop.time += dt;
|
|
322
|
+
const ease = 1 - Math.exp(-dt * EASE_RATE);
|
|
323
|
+
let moving = false;
|
|
324
|
+
for (const [element, entry] of loop.entries) {
|
|
325
|
+
if (!entry.visible || entry.reduced) continue;
|
|
326
|
+
const target = presencePose(entry.activity, loop.time + presenceOffset(entry.activity, entry.phase));
|
|
327
|
+
const pose = entry.pose;
|
|
328
|
+
pose.y += (target.y - pose.y) * ease;
|
|
329
|
+
pose.r += (target.r - pose.r) * ease;
|
|
330
|
+
pose.s += (target.s - pose.s) * ease;
|
|
331
|
+
pose.w += (target.w - pose.w) * ease;
|
|
332
|
+
if (settled(target) && settled(pose)) {
|
|
333
|
+
rest(element, entry);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
moving = true;
|
|
337
|
+
entry.moved = true;
|
|
338
|
+
const squash = 1 - pose.w * target.blink;
|
|
339
|
+
element.style.transform = `translateY(${pose.y.toFixed(2)}px) rotate(${pose.r.toFixed(2)}deg) `
|
|
340
|
+
+ `scale(${pose.s.toFixed(4)}, ${(pose.s * squash).toFixed(4)})`;
|
|
341
|
+
}
|
|
342
|
+
if (moving) loop.frame = requestAnimationFrame((next) => step(loop, next));
|
|
343
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { h } from '../core/dom.js';
|
|
2
|
+
import { icon } from '../core/icons.js';
|
|
3
|
+
import { ContextMenu } from '../components/context-menu/context-menu.js';
|
|
4
|
+
import { MenuButton } from '../components/menu-button/menu-button.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One action a row offers: a repeated, secondary command such as "Add sub-page" or "Rename".
|
|
8
|
+
* @typedef {Object} RowAction
|
|
9
|
+
* @property {string} label What the action does; the tooltip, and with the row's name its
|
|
10
|
+
* accessible name.
|
|
11
|
+
* @property {string} [icon] Icon name. Inline actions show only the icon.
|
|
12
|
+
* @property {(subject: any) => void} onSelect Runs the action for the row's node or item.
|
|
13
|
+
* @property {boolean} [disabled=false] Whether the action is unavailable on this row.
|
|
14
|
+
* @property {boolean} [danger=false] Whether the action destroys something; menus colour it.
|
|
15
|
+
*/
|
|
16
|
+
/** @typedef {RowAction|Node} RowActionEntry */
|
|
17
|
+
/**
|
|
18
|
+
* The controls built for one row.
|
|
19
|
+
* @typedef {Object} RowActionStrip
|
|
20
|
+
* @property {HTMLElement} element The strip, marked `data-zx-reveal`.
|
|
21
|
+
* @property {RowAction[]} actions Every descriptor of the row, inline and folded, in order — what
|
|
22
|
+
* the row's context menu lists. Inline buttons and menu items carry indexes into it.
|
|
23
|
+
* @property {MenuButton|null} menu The overflow menu, when actions were folded.
|
|
24
|
+
* @property {() => void} destroy Destroys the overflow menu.
|
|
25
|
+
*/
|
|
26
|
+
/** A row never carries more controls than this before the rest fold into a menu. */
|
|
27
|
+
export const ROW_ACTION_LIMIT = 2;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether an entry is a control of the application's own, placed in the row as given.
|
|
31
|
+
* @param {unknown} entry Candidate entry.
|
|
32
|
+
* @returns {entry is Node}
|
|
33
|
+
*/
|
|
34
|
+
export function isRowActionNode(entry) {
|
|
35
|
+
return Boolean(entry) && typeof entry === 'object'
|
|
36
|
+
&& typeof /** @type {{nodeType?: unknown}} */ (entry).nodeType === 'number';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether an entry is a usable action descriptor: a label and something to run.
|
|
41
|
+
* @param {unknown} entry Candidate entry.
|
|
42
|
+
* @returns {entry is RowAction}
|
|
43
|
+
*/
|
|
44
|
+
export function isRowAction(entry) {
|
|
45
|
+
if (!entry || typeof entry !== 'object' || isRowActionNode(entry)) return false;
|
|
46
|
+
const action = /** @type {Record<string, unknown>} */ (entry);
|
|
47
|
+
return action.label != null && String(action.label) !== '' && typeof action.onSelect === 'function';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Decides which entries a row shows and which fold into its overflow menu. One or two entries all
|
|
52
|
+
* show; with more, the first shows and the descriptors after it fold, so a row carries at most two
|
|
53
|
+
* controls of its own. A node is the application's control and never folds.
|
|
54
|
+
* @param {unknown} entries What `rowActions` or `actions` returned.
|
|
55
|
+
* @returns {{inline: RowActionEntry[], overflow: RowAction[]}}
|
|
56
|
+
*/
|
|
57
|
+
export function planRowActions(entries) {
|
|
58
|
+
const valid = /** @type {RowActionEntry[]} */ ((Array.isArray(entries) ? entries : [])
|
|
59
|
+
.filter((entry) => isRowActionNode(entry) || isRowAction(entry)));
|
|
60
|
+
if (valid.length <= ROW_ACTION_LIMIT) return { inline: valid, overflow: [] };
|
|
61
|
+
const [first, ...rest] = valid;
|
|
62
|
+
return {
|
|
63
|
+
inline: [first, ...rest.filter(isRowActionNode)],
|
|
64
|
+
overflow: /** @type {RowAction[]} */ (rest.filter((entry) => !isRowActionNode(entry)))
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* An action control's accessible name, which says which row it acts on: on a list of rows every
|
|
70
|
+
* "Rename" button is otherwise the same button. The action comes first, so a screen reader's
|
|
71
|
+
* list of buttons still sorts by what they do.
|
|
72
|
+
* @param {string} action Action label.
|
|
73
|
+
* @param {string} name The row's name.
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
export function rowActionLabel(action, name) {
|
|
77
|
+
const row = String(name ?? '').trim();
|
|
78
|
+
return row ? `${String(action).trim()}: ${row}` : String(action).trim();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Menu items for descriptors, valued by their index in `actions`.
|
|
83
|
+
* @param {RowAction[]} actions The row's descriptors.
|
|
84
|
+
* @param {RowAction[]} [only=actions] The descriptors to list.
|
|
85
|
+
* @returns {Array<{label: string, icon?: string, value: number, danger: boolean, disabled: boolean}>}
|
|
86
|
+
*/
|
|
87
|
+
export function menuEntries(actions, only = actions) {
|
|
88
|
+
return only.map((action) => ({
|
|
89
|
+
label: String(action.label),
|
|
90
|
+
icon: action.icon ? String(action.icon) : undefined,
|
|
91
|
+
value: actions.indexOf(action),
|
|
92
|
+
danger: Boolean(action.danger),
|
|
93
|
+
disabled: Boolean(action.disabled)
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Builds a row's action strip: an icon button per inline descriptor, the given nodes, and the
|
|
99
|
+
* overflow menu. Every control starts outside the Tab order; the host component makes the strip
|
|
100
|
+
* of the row holding focus tabbable. Inline buttons carry `data-row-action`, an index into
|
|
101
|
+
* `actions`, so the host runs them from its own delegated click listener.
|
|
102
|
+
* @param {unknown} entries Row actions.
|
|
103
|
+
* @param {{block: string, name: string, moreLabel?: string, run: (action: RowAction) => void}} options
|
|
104
|
+
* `block` names the parts (`zx-<block>__actions`, `zx-<block>__action`); `name` is the row's
|
|
105
|
+
* name; `moreLabel` names the overflow menu ("More actions"); `run` is called with a descriptor
|
|
106
|
+
* chosen from the overflow menu.
|
|
107
|
+
* @returns {RowActionStrip|null} Null when nothing usable was given.
|
|
108
|
+
*/
|
|
109
|
+
export function renderRowActions(entries, { block, name, moreLabel = 'More actions', run }) {
|
|
110
|
+
const plan = planRowActions(entries);
|
|
111
|
+
if (plan.inline.length === 0) return null;
|
|
112
|
+
const actions = /** @type {RowAction[]} */ ((Array.isArray(entries) ? entries : []).filter(isRowAction));
|
|
113
|
+
const element = /** @type {HTMLElement} */ (h('span', { class: `zx-${block}__actions`, 'data-zx-reveal': '' }));
|
|
114
|
+
|
|
115
|
+
for (const entry of plan.inline) {
|
|
116
|
+
if (isRowActionNode(entry)) {
|
|
117
|
+
element.append(entry);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
element.append(h('button', {
|
|
121
|
+
type: 'button',
|
|
122
|
+
class: ['zx-icon-btn', `zx-${block}__action`],
|
|
123
|
+
ariaLabel: rowActionLabel(entry.label, name),
|
|
124
|
+
title: String(entry.label),
|
|
125
|
+
disabled: Boolean(entry.disabled),
|
|
126
|
+
dataset: { rowAction: String(actions.indexOf(entry)) }
|
|
127
|
+
}, icon(entry.icon ? String(entry.icon) : 'dots')));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let menu = null;
|
|
131
|
+
if (plan.overflow.length > 0) {
|
|
132
|
+
menu = new MenuButton(null, {
|
|
133
|
+
icon: 'dots',
|
|
134
|
+
label: '',
|
|
135
|
+
kind: 'ghost',
|
|
136
|
+
placement: 'bottom-end',
|
|
137
|
+
items: menuEntries(actions, plan.overflow)
|
|
138
|
+
});
|
|
139
|
+
const trigger = menu.getTrigger();
|
|
140
|
+
trigger.classList.add(`zx-${block}__action`, `zx-${block}__more`);
|
|
141
|
+
trigger.setAttribute('aria-label', rowActionLabel(moreLabel, name));
|
|
142
|
+
trigger.title = String(moreLabel);
|
|
143
|
+
menu.on('select', (event) => {
|
|
144
|
+
const action = actions[Number(/** @type {CustomEvent} */ (event).detail.value)];
|
|
145
|
+
if (action && !action.disabled) run(action);
|
|
146
|
+
});
|
|
147
|
+
// The menu's own bubbling events stop at the trigger: a listener for the row component's
|
|
148
|
+
// `zx-select` must never hear an action chosen from a row's menu.
|
|
149
|
+
for (const type of ['zx-select', 'zx-open', 'zx-close']) {
|
|
150
|
+
menu.listen(trigger, type, (event) => event.stopPropagation());
|
|
151
|
+
}
|
|
152
|
+
element.append(trigger);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setRowActionsTabbable(element, false);
|
|
156
|
+
return {
|
|
157
|
+
element,
|
|
158
|
+
actions,
|
|
159
|
+
menu,
|
|
160
|
+
destroy: () => menu?.destroy()
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Puts every control in a strip in or out of the Tab order.
|
|
166
|
+
* @param {Element|null|undefined} element A strip.
|
|
167
|
+
* @param {boolean} tabbable Whether its controls are Tab stops.
|
|
168
|
+
* @returns {void}
|
|
169
|
+
*/
|
|
170
|
+
export function setRowActionsTabbable(element, tabbable) {
|
|
171
|
+
if (!element) return;
|
|
172
|
+
const controls = element.querySelectorAll('button, a[href], input, select, textarea, [tabindex]');
|
|
173
|
+
for (const control of controls) /** @type {HTMLElement} */ (control).tabIndex = tabbable ? 0 : -1;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The context menu of a component's rows: every descriptor of the row it opens on. Choosing an
|
|
178
|
+
* item closes the menu, which returns focus to the row, and only then runs the action — so a
|
|
179
|
+
* dialog the action opens records the row as the place to return to.
|
|
180
|
+
* @param {Element} target The element holding the rows.
|
|
181
|
+
* @param {string} selector The rows.
|
|
182
|
+
* @param {(row: Element) => {actions: RowAction[], subject: unknown}|null} resolve The row's
|
|
183
|
+
* descriptors and what their `onSelect` receives.
|
|
184
|
+
* @returns {ContextMenu}
|
|
185
|
+
*/
|
|
186
|
+
export function rowActionMenu(target, selector, resolve) {
|
|
187
|
+
const menu = new ContextMenu(target, {
|
|
188
|
+
selector,
|
|
189
|
+
items: (context) => {
|
|
190
|
+
const found = context ? resolve(context) : null;
|
|
191
|
+
return found ? menuEntries(found.actions) : [];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
menu.on('select', (event) => {
|
|
195
|
+
const { value, context } = /** @type {CustomEvent} */ (event).detail;
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
const found = context ? resolve(context) : null;
|
|
198
|
+
const action = found?.actions[Number(value)];
|
|
199
|
+
menu.close();
|
|
200
|
+
if (action && !action.disabled) action.onSelect(found.subject);
|
|
201
|
+
});
|
|
202
|
+
return menu;
|
|
203
|
+
}
|
package/styles/base.css
CHANGED
|
@@ -82,8 +82,33 @@
|
|
|
82
82
|
cursor: pointer;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/* The hover fill is laid over the control fill rather than replacing it: in dark both are about 5%
|
|
86
|
+
white, and a swap would leave the pointer with nothing to show. */
|
|
85
87
|
:where(.zx-scope button:not(.zx-icon-btn)):hover {
|
|
86
|
-
background: var(--zx-color-bg-hover);
|
|
88
|
+
background: linear-gradient(var(--zx-color-bg-hover), var(--zx-color-bg-hover)), var(--zx-color-bg-control);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Revealed affordances. Inside a `[data-zx-reveal-host]` — a row, a section heading — an element
|
|
92
|
+
marked `[data-zx-reveal]` rests invisible and appears while the host is pointed at, holds focus,
|
|
93
|
+
is current or selected, or has a menu open. It keeps its space (opacity, never display), so
|
|
94
|
+
nothing shifts, and it stays in the tab order, so focusing it is enough to show it. Only
|
|
95
|
+
repeated, secondary per-row actions that are reachable another way belong here. Hosts do not
|
|
96
|
+
nest. Zero specificity, so a component can still decide for itself. */
|
|
97
|
+
:where(.zx-scope [data-zx-reveal-host]) :where([data-zx-reveal]) {
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transition: opacity var(--zx-dur-fast) var(--zx-ease);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
:where(.zx-scope [data-zx-reveal-host]):where(:hover, :focus-within, [aria-current]:not([aria-current="false"]),
|
|
103
|
+
[aria-selected="true"], :has([aria-expanded="true"])) :where([data-zx-reveal]) {
|
|
104
|
+
opacity: 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* No pointer to hover with, or a request for more contrast: nothing hides. */
|
|
108
|
+
@media (hover: none), (prefers-contrast: more), (forced-colors: active) {
|
|
109
|
+
:where(.zx-scope [data-zx-reveal-host]) :where([data-zx-reveal]) {
|
|
110
|
+
opacity: 1;
|
|
111
|
+
}
|
|
87
112
|
}
|
|
88
113
|
|
|
89
114
|
/* Quiet fields. Inside `[data-zx-fields="quiet"]` — a property panel, an inspector, an inline
|