@zeyos/zx 5.7.1 → 5.8.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 +296 -0
- package/README.md +47 -9
- package/dist/types/components/activity-item/activity-item.d.ts +14 -3
- package/dist/types/components/agent-avatar/agent-avatar.d.ts +165 -0
- package/dist/types/components/agent-avatar/agent-face.d.ts +93 -0
- package/dist/types/components/agent-thread/ag-ui.d.ts +21 -9
- package/dist/types/components/agent-thread/agent-thread.d.ts +26 -0
- package/dist/types/components/agent-thread/ui-message-stream.d.ts +3 -1
- package/dist/types/components/approval-card/approval-card.d.ts +31 -2
- package/dist/types/components/aurora/aurora.d.ts +31 -5
- package/dist/types/components/calendar/calendar.d.ts +39 -26
- package/dist/types/components/chart/chart.d.ts +250 -20
- package/dist/types/components/chart/color.d.ts +66 -0
- package/dist/types/components/chart/svg-adapter.d.ts +103 -0
- package/dist/types/components/chart/svg-geometry.d.ts +203 -0
- package/dist/types/components/check-button/check-button.d.ts +1 -4
- package/dist/types/components/checklist/checklist.d.ts +19 -5
- package/dist/types/components/code-editor/code-editor.d.ts +55 -1
- package/dist/types/components/composer/composer.d.ts +41 -6
- package/dist/types/components/context-menu/context-menu.d.ts +36 -8
- package/dist/types/components/copy/copy-button.d.ts +6 -0
- package/dist/types/components/copy/copy-input.d.ts +1 -0
- package/dist/types/components/date-picker/date-picker.d.ts +14 -0
- package/dist/types/components/date-picker/time-picker.d.ts +26 -17
- package/dist/types/components/datebox/datebox.d.ts +8 -4
- package/dist/types/components/dialog/dialog.d.ts +13 -2
- package/dist/types/components/empty-state/empty-state.d.ts +10 -1
- package/dist/types/components/field/field.d.ts +4 -2
- package/dist/types/components/form/form.d.ts +2 -1
- package/dist/types/components/kanban-view/kanban-card.d.ts +7 -0
- package/dist/types/components/kanban-view/kanban-view.d.ts +15 -3
- package/dist/types/components/launcher/launcher.d.ts +26 -0
- package/dist/types/components/master-panel/master-panel.d.ts +9 -4
- package/dist/types/components/menu-button/menu-button.d.ts +29 -5
- package/dist/types/components/message/message.d.ts +308 -5
- package/dist/types/components/modal/modal.d.ts +11 -0
- package/dist/types/components/modal/native-dialog.d.ts +40 -0
- package/dist/types/components/module-bar/module-bar.d.ts +9 -2
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +5 -4
- package/dist/types/components/number-field/number-field.d.ts +7 -0
- package/dist/types/components/pagination/pagination.d.ts +341 -19
- package/dist/types/components/run-status/run-status.d.ts +26 -0
- package/dist/types/components/run-trace/run-trace.d.ts +10 -6
- package/dist/types/components/search/search.d.ts +16 -4
- package/dist/types/components/select/select.d.ts +19 -1
- package/dist/types/components/sheet/sheet.d.ts +18 -4
- package/dist/types/components/slider/slider.d.ts +2 -1
- package/dist/types/components/stat-tile/stat-tile.d.ts +20 -3
- package/dist/types/components/stepper/stepper.d.ts +17 -4
- package/dist/types/components/surface/catalog.d.ts +61 -17
- package/dist/types/components/surface/surface.d.ts +6 -4
- package/dist/types/components/table/table.d.ts +207 -5
- package/dist/types/components/table/window.d.ts +25 -1
- package/dist/types/components/toggle/toggle.d.ts +38 -6
- package/dist/types/components/tooltip/tooltip.d.ts +5 -4
- package/dist/types/components/tree/tree.d.ts +43 -6
- package/dist/types/components/truncate/truncate.d.ts +4 -2
- package/dist/types/components/value-list/value-list.d.ts +9 -2
- package/dist/types/core/date.d.ts +2 -1
- package/dist/types/core/drag-axis.d.ts +10 -5
- package/dist/types/core/export.d.ts +2 -2
- package/dist/types/core/format.d.ts +3 -1
- package/dist/types/core/icons.d.ts +36 -3
- package/dist/types/core/keyboard.d.ts +7 -3
- package/dist/types/core/messages.d.ts +3 -0
- package/dist/types/core/storage.d.ts +4 -3
- package/dist/types/core/util.d.ts +3 -1
- package/dist/types/elements/define.d.ts +5 -2
- package/dist/types/index.d.ts +6 -4
- package/dist/types/internal/agent-model.d.ts +99 -0
- package/dist/types/internal/app-rail.d.ts +37 -2
- package/dist/types/internal/collections.d.ts +18 -0
- package/dist/types/internal/menu-items.d.ts +27 -0
- package/dist/types/internal/overlay-content.d.ts +23 -0
- package/dist/types/internal/presence-loop.d.ts +5 -2
- package/dist/types/locales/index.d.ts +3 -0
- package/dist/types/zeyos/calendar.d.ts +43 -7
- package/dist/types/zeyos/connect.d.ts +4 -0
- package/dist/types/zeyos/form.d.ts +13 -5
- package/dist/types/zeyos/select.d.ts +5 -2
- package/dist/types/zeyos/table.d.ts +16 -8
- package/dist/types/zeyos/view.d.ts +2 -1
- package/dist/zx-zeyos.esm.js +2998 -451
- package/dist/zx-zeyos.esm.min.js +4 -4
- package/dist/zx.core.css +4 -0
- package/dist/zx.core.min.css +1 -1
- package/dist/zx.css +948 -48
- package/dist/zx.esm.js +7432 -3408
- package/dist/zx.esm.min.js +26 -26
- package/dist/zx.global.js +7432 -3408
- package/dist/zx.global.min.js +26 -26
- package/dist/zx.layered.css +950 -48
- package/dist/zx.layered.min.css +1 -1
- package/dist/zx.min.css +1 -1
- package/docs/agent-catalog.json +159 -1
- package/docs/agent-surfaces.md +21 -21
- package/docs/api.json +3122 -528
- package/docs/components/account-menu.md +24 -0
- package/docs/components/activity-item.md +23 -0
- package/docs/components/activity-list.md +28 -0
- package/docs/components/agent-avatar.md +59 -0
- package/docs/components/agent-thread.md +275 -0
- package/docs/components/app-icon.md +36 -0
- package/docs/components/app-sidebar.md +92 -0
- package/docs/components/approval-card.md +71 -0
- package/docs/components/aurora.md +34 -0
- package/docs/components/avatar.md +37 -0
- package/docs/components/badge.md +36 -0
- package/docs/components/block-view.md +34 -0
- package/docs/components/breadcrumb.md +20 -0
- package/docs/components/button.md +23 -0
- package/docs/components/calendar.md +68 -0
- package/docs/components/card-view.md +73 -0
- package/docs/components/card.md +25 -0
- package/docs/components/chart.md +109 -0
- package/docs/components/check-button.md +16 -0
- package/docs/components/checklist.md +19 -0
- package/docs/components/code-editor.md +38 -0
- package/docs/components/composer.md +107 -0
- package/docs/components/context-menu.md +32 -0
- package/docs/components/copy.md +37 -0
- package/docs/components/data-filter.md +16 -0
- package/docs/components/date-picker.md +31 -0
- package/docs/components/date-range.md +21 -0
- package/docs/components/datebox.md +31 -0
- package/docs/components/dialog.md +25 -0
- package/docs/components/dock.md +57 -0
- package/docs/components/dropdown.md +39 -0
- package/docs/components/elements.md +63 -0
- package/docs/components/empty-state.md +17 -0
- package/docs/components/entity-ref.md +26 -0
- package/docs/components/field-upload.md +18 -0
- package/docs/components/file-item.md +27 -0
- package/docs/components/file-list.md +23 -0
- package/docs/components/filter-panel.md +45 -0
- package/docs/components/filter.md +47 -0
- package/docs/components/finder.md +25 -0
- package/docs/components/form-widgets.md +42 -0
- package/docs/components/form.md +80 -0
- package/docs/components/grid.md +26 -0
- package/docs/components/groupbox.md +11 -0
- package/docs/components/helpers.md +359 -0
- package/docs/components/icons.md +87 -0
- package/docs/components/index.md +99 -0
- package/docs/components/kanban-view.md +42 -0
- package/docs/components/kbd.md +23 -0
- package/docs/components/kernel.md +41 -0
- package/docs/components/launcher.md +66 -0
- package/docs/components/layout.md +33 -0
- package/docs/components/list-toolbar.md +38 -0
- package/docs/components/loading.md +48 -0
- package/docs/components/menu-button.md +47 -0
- package/docs/components/message.md +76 -0
- package/docs/components/modal.md +27 -0
- package/docs/components/module-bar.md +71 -0
- package/docs/components/multi-value-editor.md +16 -0
- package/docs/components/navigation-bar.md +22 -0
- package/docs/components/number-field.md +34 -0
- package/docs/components/pagination.md +73 -0
- package/docs/components/panel.md +28 -0
- package/docs/components/prompt-starters.md +40 -0
- package/docs/components/prose.md +38 -0
- package/docs/components/questionnaire.md +115 -0
- package/docs/components/rating.md +19 -0
- package/docs/components/run-status.md +50 -0
- package/docs/components/run-trace.md +72 -0
- package/docs/components/search.md +11 -0
- package/docs/components/select.md +129 -0
- package/docs/components/sheet-stack.md +39 -0
- package/docs/components/sheet.md +77 -0
- package/docs/components/skeleton.md +27 -0
- package/docs/components/slider.md +29 -0
- package/docs/components/sort-control.md +21 -0
- package/docs/components/source-list.md +30 -0
- package/docs/components/split-view.md +12 -0
- package/docs/components/stat-tile.md +49 -0
- package/docs/components/stepper.md +27 -0
- package/docs/components/surface.md +152 -0
- package/docs/components/tabbox.md +33 -0
- package/docs/components/table-view.md +43 -0
- package/docs/components/table.md +232 -0
- package/docs/components/tag-picker.md +39 -0
- package/docs/components/timebox.md +16 -0
- package/docs/components/toggle.md +21 -0
- package/docs/components/tokens.md +82 -0
- package/docs/components/toolbar.md +26 -0
- package/docs/components/tooltip.md +16 -0
- package/docs/components/tree.md +48 -0
- package/docs/components/truncate.md +21 -0
- package/docs/components/value-list.md +14 -0
- package/docs/components/view-settings.md +56 -0
- package/docs/components/workspace-switcher.md +42 -0
- package/docs/components/zeyos.md +196 -0
- package/docs/llms-small.txt +299 -0
- package/docs/llms.md +697 -100
- package/docs/llms.txt +46 -19
- package/package.json +9 -4
- package/src/components/activity-item/activity-item.js +21 -2
- package/src/components/agent-avatar/agent-avatar.css +195 -0
- package/src/components/agent-avatar/agent-avatar.js +333 -0
- package/src/components/agent-avatar/agent-face.js +292 -0
- package/src/components/agent-thread/ag-ui.js +44 -11
- package/src/components/agent-thread/agent-thread.js +103 -11
- package/src/components/agent-thread/ui-message-stream.js +3 -1
- package/src/components/app-rail/app-rail.css +5 -0
- package/src/components/app-sidebar/app-sidebar.css +3 -0
- package/src/components/app-sidebar/app-sidebar.js +4 -3
- package/src/components/approval-card/approval-card.css +6 -0
- package/src/components/approval-card/approval-card.js +55 -7
- package/src/components/aurora/aurora.css +149 -14
- package/src/components/aurora/aurora.js +49 -6
- package/src/components/calendar/calendar.css +6 -2
- package/src/components/calendar/calendar.js +127 -47
- package/src/components/card-view/card-view.js +5 -6
- package/src/components/chart/chart.css +159 -1
- package/src/components/chart/chart.js +450 -62
- package/src/components/chart/color.js +297 -0
- package/src/components/chart/svg-adapter.js +576 -0
- package/src/components/chart/svg-geometry.js +323 -0
- package/src/components/check-button/check-button.js +3 -18
- package/src/components/checklist/checklist.js +46 -17
- package/src/components/checklist/field-adapter.js +4 -1
- package/src/components/code-editor/code-editor.css +33 -0
- package/src/components/code-editor/code-editor.js +97 -8
- package/src/components/code-editor/field-adapter.js +3 -0
- package/src/components/composer/composer.css +3 -0
- package/src/components/composer/composer.js +100 -22
- package/src/components/context-menu/context-menu.js +41 -5
- package/src/components/copy/copy-button.js +9 -1
- package/src/components/copy/copy-input.js +5 -0
- package/src/components/data-filter/filter-core.js +0 -1
- package/src/components/date-picker/date-picker.css +8 -0
- package/src/components/date-picker/date-picker.js +47 -8
- package/src/components/date-picker/date-range-picker.js +1 -1
- package/src/components/date-picker/month-picker.js +19 -3
- package/src/components/date-picker/time-picker.js +54 -19
- package/src/components/datebox/date-range-box.js +7 -3
- package/src/components/datebox/datebox.js +32 -6
- package/src/components/dialog/dialog.css +6 -0
- package/src/components/dialog/dialog.js +22 -30
- package/src/components/dropdown/dropdown.js +1 -18
- package/src/components/empty-state/empty-state.js +21 -2
- package/src/components/field/field.js +19 -3
- package/src/components/fieldset/fieldset.js +3 -1
- package/src/components/filter/filter.js +9 -0
- package/src/components/form/form.js +19 -2
- package/src/components/kanban-view/kanban-card.js +15 -2
- package/src/components/kanban-view/kanban-view.css +21 -0
- package/src/components/kanban-view/kanban-view.js +29 -16
- package/src/components/launcher/launcher.css +14 -0
- package/src/components/launcher/launcher.js +54 -9
- package/src/components/master-panel/master-panel.js +24 -22
- package/src/components/menu-button/menu-button.js +26 -4
- package/src/components/message/message.css +228 -29
- package/src/components/message/message.js +664 -30
- package/src/components/modal/modal.js +70 -25
- package/src/components/modal/native-dialog.js +91 -0
- package/src/components/module-bar/module-bar.css +3 -0
- package/src/components/module-bar/module-bar.js +17 -4
- package/src/components/multi-value-editor/multi-value-editor.css +7 -2
- package/src/components/multi-value-editor/multi-value-editor.js +3 -2
- package/src/components/navigation-bar/navigation-bar.js +13 -1
- package/src/components/number-field/field-adapter.js +3 -0
- package/src/components/number-field/number-field.js +2 -1
- package/src/components/pagination/pagination.css +26 -2
- package/src/components/pagination/pagination.js +551 -65
- package/src/components/prose/prose.js +7 -1
- package/src/components/rating/field-adapter.js +3 -0
- package/src/components/run-status/run-status.js +43 -3
- package/src/components/run-trace/run-trace.js +15 -7
- package/src/components/search/search.js +3 -18
- package/src/components/select/field-adapter.js +8 -1
- package/src/components/select/select.js +68 -13
- package/src/components/sheet/sheet.js +27 -8
- package/src/components/slider/field-adapter.js +3 -0
- package/src/components/slider/slider.js +4 -6
- package/src/components/stat-tile/stat-tile.js +24 -9
- package/src/components/stepper/stepper.css +15 -0
- package/src/components/stepper/stepper.js +34 -2
- package/src/components/surface/catalog.js +185 -28
- package/src/components/surface/surface.js +10 -5
- package/src/components/tabbox/tabbox.js +13 -1
- package/src/components/table/table.css +160 -2
- package/src/components/table/table.js +479 -52
- package/src/components/table/window.js +46 -4
- package/src/components/table-view/table-view.js +1 -10
- package/src/components/tag-picker/field-adapter.js +3 -0
- package/src/components/tag-picker/tag-picker.js +2 -0
- package/src/components/timebox/field-adapter.js +3 -0
- package/src/components/toggle/toggle.js +51 -27
- package/src/components/tooltip/tooltip.js +21 -14
- package/src/components/tree/tree.js +87 -14
- package/src/components/truncate/truncate.js +21 -5
- package/src/components/value-list/value-list.js +37 -9
- package/src/components/view-settings/view-settings.js +1 -5
- package/src/core/component.js +34 -2
- package/src/core/date.js +5 -4
- package/src/core/drag-axis.js +24 -7
- package/src/core/export.js +4 -4
- package/src/core/fontawesome.js +34 -3
- package/src/core/format.js +3 -1
- package/src/core/http.js +23 -11
- package/src/core/icons.js +51 -10
- package/src/core/keyboard.js +83 -9
- package/src/core/messages.js +3 -0
- package/src/core/position.js +2 -2
- package/src/core/storage.js +80 -31
- package/src/core/util.js +16 -5
- package/src/elements/define.js +82 -47
- package/src/elements/kit.js +46 -35
- package/src/index.js +8 -4
- package/src/internal/agent-model.js +152 -0
- package/src/internal/app-rail.js +53 -2
- package/src/internal/collections.js +25 -0
- package/src/internal/menu-items.js +59 -0
- package/src/internal/overlay-content.js +35 -0
- package/src/internal/presence-loop.js +61 -14
- package/src/locales/de.js +3 -0
- package/src/zeyos/calendar.js +81 -19
- package/src/zeyos/connect.js +5 -1
- package/src/zeyos/form.js +29 -10
- package/src/zeyos/select.js +36 -12
- package/src/zeyos/table.js +43 -11
- package/src/zeyos/view.js +2 -1
- package/styles/tokens/semantic.css +7 -1
- package/styles/zx.css +1 -0
|
@@ -234,11 +234,12 @@ export class DatePicker extends Component {
|
|
|
234
234
|
const rowStart = addDays(start, week * 7);
|
|
235
235
|
const row = h('tr');
|
|
236
236
|
if (this.options.showWeekNumbers) {
|
|
237
|
+
const weekNumber = rowWeekNumber(rowStart);
|
|
237
238
|
row.append(h('th', {
|
|
238
239
|
class: 'zx-date-picker__week',
|
|
239
240
|
scope: 'row',
|
|
240
|
-
ariaLabel: this._message('datePicker.week', 'Week %1',
|
|
241
|
-
}, String(
|
|
241
|
+
ariaLabel: this._message('datePicker.week', 'Week %1', weekNumber)
|
|
242
|
+
}, String(weekNumber)));
|
|
242
243
|
}
|
|
243
244
|
for (let column = 0; column < 7; column += 1) {
|
|
244
245
|
const date = addDays(rowStart, column);
|
|
@@ -262,7 +263,11 @@ export class DatePicker extends Component {
|
|
|
262
263
|
}
|
|
263
264
|
rows.push(row);
|
|
264
265
|
}
|
|
266
|
+
// Redrawing replaces the focused day's button; focus follows to its replacement so the arrow
|
|
267
|
+
// keys keep working after a selection (and before `change`, so a host can still move it on).
|
|
268
|
+
const hadFocus = hasFocusWithin(this.refs.days);
|
|
265
269
|
this.refs.days.replaceChildren(...rows);
|
|
270
|
+
if (hadFocus) this._buttonForDate(this._focused)?.focus();
|
|
266
271
|
if (this._quickOpen) this._renderQuickPick();
|
|
267
272
|
}
|
|
268
273
|
|
|
@@ -365,15 +370,25 @@ export class DatePicker extends Component {
|
|
|
365
370
|
this._quickOpen = false;
|
|
366
371
|
this.refs.quickPanel.hidden = true;
|
|
367
372
|
this.refs.heading.setAttribute('aria-expanded', 'false');
|
|
373
|
+
// Stepping the year in the panel already moved the view and announced it with `monthchange`:
|
|
374
|
+
// however the panel closes, the calendar shows that month, with the roving day inside it.
|
|
375
|
+
if (this._focused.getFullYear() !== this._viewYear || this._focused.getMonth() !== this._viewMonth) {
|
|
376
|
+
this._focused = new Date(this._viewYear, this._viewMonth, Math.min(
|
|
377
|
+
this._focused.getDate(), new Date(this._viewYear, this._viewMonth + 1, 0).getDate()
|
|
378
|
+
));
|
|
379
|
+
}
|
|
380
|
+
this._renderCalendar();
|
|
368
381
|
}
|
|
369
382
|
|
|
370
383
|
/** @returns {void} */
|
|
371
384
|
_renderQuickPick() {
|
|
372
385
|
this.refs.quickYear.textContent = String(this._viewYear);
|
|
373
|
-
const
|
|
386
|
+
const rows = [];
|
|
374
387
|
for (let month = 0; month < 12; month += 1) {
|
|
375
388
|
const date = new Date(this._viewYear, month, 1);
|
|
376
|
-
months
|
|
389
|
+
// Three months to a row, so the grid's cells sit in rows as the grid role requires.
|
|
390
|
+
if (month % 3 === 0) rows.push(h('div', { class: 'zx-date-picker__quick-row', role: 'row' }));
|
|
391
|
+
rows[rows.length - 1].append(h('button', {
|
|
377
392
|
class: 'zx-date-picker__quick-month',
|
|
378
393
|
type: 'button',
|
|
379
394
|
role: 'gridcell',
|
|
@@ -382,7 +397,7 @@ export class DatePicker extends Component {
|
|
|
382
397
|
dataset: { month }
|
|
383
398
|
}, formatDate(date, '%b')));
|
|
384
399
|
}
|
|
385
|
-
this.refs.quickGrid.replaceChildren(...
|
|
400
|
+
this.refs.quickGrid.replaceChildren(...rows);
|
|
386
401
|
}
|
|
387
402
|
|
|
388
403
|
/** @param {number} amount @returns {void} */
|
|
@@ -438,7 +453,6 @@ export class DatePicker extends Component {
|
|
|
438
453
|
this._focused = dayOnly(date);
|
|
439
454
|
this._viewMonth = month;
|
|
440
455
|
this._closeQuickPick();
|
|
441
|
-
this._renderCalendar();
|
|
442
456
|
this._emitMonthChange();
|
|
443
457
|
this.focus();
|
|
444
458
|
}
|
|
@@ -489,6 +503,16 @@ function dayOnly(date) {
|
|
|
489
503
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
490
504
|
}
|
|
491
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Whether focus is on `element` or inside it, judged in its own document or shadow root.
|
|
508
|
+
* @param {Element} element Container to test.
|
|
509
|
+
* @returns {boolean}
|
|
510
|
+
*/
|
|
511
|
+
function hasFocusWithin(element) {
|
|
512
|
+
const active = /** @type {Document|ShadowRoot|undefined} */ (element.getRootNode?.())?.activeElement;
|
|
513
|
+
return Boolean(active) && element.contains(active);
|
|
514
|
+
}
|
|
515
|
+
|
|
492
516
|
/** @param {Date|null} date @returns {Date|null} */
|
|
493
517
|
function cloneDate(date) {
|
|
494
518
|
return date ? new Date(date.getTime()) : null;
|
|
@@ -505,11 +529,26 @@ function normalizeWeekStart(value) {
|
|
|
505
529
|
return Number.isInteger(number) && number >= 0 && number <= 6 ? number : getWeekStart();
|
|
506
530
|
}
|
|
507
531
|
|
|
508
|
-
/**
|
|
509
|
-
|
|
532
|
+
/**
|
|
533
|
+
* ISO 8601 week number of a local calendar day.
|
|
534
|
+
* @param {Date} date Any time on the day.
|
|
535
|
+
* @returns {number}
|
|
536
|
+
*/
|
|
537
|
+
export function isoWeekNumber(date) {
|
|
510
538
|
const utc = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
511
539
|
const weekday = utc.getUTCDay() || 7;
|
|
512
540
|
utc.setUTCDate(utc.getUTCDate() + 4 - weekday);
|
|
513
541
|
const yearStart = new Date(Date.UTC(utc.getUTCFullYear(), 0, 1));
|
|
514
542
|
return Math.ceil((((utc.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
|
|
515
543
|
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* ISO week number for a calendar row of seven days starting on `rowStart`. A row that does not
|
|
547
|
+
* start on Monday straddles two ISO weeks; its Thursday always falls in the week that holds most of
|
|
548
|
+
* the row (for a Sunday start, Monday to Saturday), which is the week the row is labelled with.
|
|
549
|
+
* @param {Date} rowStart First day of the row.
|
|
550
|
+
* @returns {number}
|
|
551
|
+
*/
|
|
552
|
+
export function rowWeekNumber(rowStart) {
|
|
553
|
+
return isoWeekNumber(addDays(rowStart, (4 - rowStart.getDay() + 7) % 7));
|
|
554
|
+
}
|
|
@@ -152,7 +152,7 @@ export class DateRangePicker extends Component {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
// Every field below is initialized here rather than as a class field: render() runs inside the
|
|
155
|
-
// base constructor, before class-field initializers would overwrite it
|
|
155
|
+
// base constructor, before class-field initializers would overwrite it.
|
|
156
156
|
|
|
157
157
|
/** @returns {HTMLElement} */
|
|
158
158
|
render() {
|
|
@@ -122,11 +122,13 @@ export class MonthPicker extends DatePicker {
|
|
|
122
122
|
_renderMonths() {
|
|
123
123
|
if (!this.refs?.grid) return;
|
|
124
124
|
this.refs.year.textContent = String(this._year);
|
|
125
|
-
const
|
|
125
|
+
const rows = [];
|
|
126
126
|
for (let month = 0; month < 12; month += 1) {
|
|
127
127
|
const date = new Date(this._year, month, 1);
|
|
128
128
|
const selected = Boolean(this._value && sameMonth(date, this._value));
|
|
129
|
-
months
|
|
129
|
+
// Three months to a row, so the grid's cells sit in rows as the grid role requires.
|
|
130
|
+
if (month % 3 === 0) rows.push(h('div', { class: 'zx-month-picker__row', role: 'row' }));
|
|
131
|
+
rows[rows.length - 1].append(h('button', {
|
|
130
132
|
class: 'zx-month-picker__month',
|
|
131
133
|
type: 'button',
|
|
132
134
|
role: 'gridcell',
|
|
@@ -137,7 +139,11 @@ export class MonthPicker extends DatePicker {
|
|
|
137
139
|
dataset: { month }
|
|
138
140
|
}, formatDate(date, '%b')));
|
|
139
141
|
}
|
|
140
|
-
|
|
142
|
+
// Redrawing replaces the focused month's button; focus follows to its replacement so the arrow
|
|
143
|
+
// keys keep working after a selection (and before `change`, so a host can still move it on).
|
|
144
|
+
const hadFocus = hasFocusWithin(this.refs.grid);
|
|
145
|
+
this.refs.grid.replaceChildren(...rows);
|
|
146
|
+
if (hadFocus) this._button(this._focusedMonth)?.focus();
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
/** @param {number} amount @returns {void} */
|
|
@@ -226,6 +232,16 @@ function firstOfMonth(date) {
|
|
|
226
232
|
return date ? new Date(date.getFullYear(), date.getMonth(), 1) : null;
|
|
227
233
|
}
|
|
228
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Whether focus is on `element` or inside it, judged in its own document or shadow root.
|
|
237
|
+
* @param {Element} element Container to test.
|
|
238
|
+
* @returns {boolean}
|
|
239
|
+
*/
|
|
240
|
+
function hasFocusWithin(element) {
|
|
241
|
+
const active = /** @type {Document|ShadowRoot|undefined} */ (element.getRootNode?.())?.activeElement;
|
|
242
|
+
return Boolean(active) && element.contains(active);
|
|
243
|
+
}
|
|
244
|
+
|
|
229
245
|
/** @param {Date} a @param {Date} b @returns {boolean} */
|
|
230
246
|
function sameMonth(a, b) {
|
|
231
247
|
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
@@ -156,7 +156,13 @@ export class TimePicker extends Component {
|
|
|
156
156
|
this.listen(input, 'focus', () => input.select());
|
|
157
157
|
this.listen(input, 'keydown', (event) => this._onKeydown(event, segment, max));
|
|
158
158
|
this.listen(input, 'input', () => this._onInput(input, segment, max));
|
|
159
|
-
|
|
159
|
+
// Leaving a field the reader did not edit commits nothing: tabbing through an empty picker
|
|
160
|
+
// must not choose 00:00, nor round away the seconds of a value whose seconds are not shown.
|
|
161
|
+
this.listen(input, 'blur', () => {
|
|
162
|
+
if (this._inputs.some((field) => field.value !== pad(this._display[field.dataset.segment]))) {
|
|
163
|
+
this._commitFromInputs();
|
|
164
|
+
}
|
|
165
|
+
});
|
|
160
166
|
}
|
|
161
167
|
|
|
162
168
|
/** @param {KeyboardEvent} event @param {'h'|'m'|'s'} segment @param {number} max @returns {void} */
|
|
@@ -184,7 +190,8 @@ export class TimePicker extends Component {
|
|
|
184
190
|
|
|
185
191
|
/** @returns {void} */
|
|
186
192
|
_commitFromInputs() {
|
|
187
|
-
|
|
193
|
+
// Start from what is shown, so a segment that is not rendered (seconds) keeps its value.
|
|
194
|
+
const next = { ...this._display };
|
|
188
195
|
for (const input of this._inputs) {
|
|
189
196
|
const segment = input.dataset.segment;
|
|
190
197
|
const max = segment === 'h' ? 23 : 59;
|
|
@@ -249,16 +256,18 @@ export class TimePicker extends Component {
|
|
|
249
256
|
}
|
|
250
257
|
|
|
251
258
|
/**
|
|
252
|
-
* Applies a mark's value to the active unit
|
|
253
|
-
* be set with two clicks
|
|
259
|
+
* Applies a mark's value to the active unit. An explicit pick (click, Enter, Space) of an hour
|
|
260
|
+
* then moves on to the minutes so a whole time can be set with two clicks; arrowing through the
|
|
261
|
+
* radio group passes `advance: false` and stays on the dial it is in.
|
|
254
262
|
* @param {number} value Hour or minute the mark stands for.
|
|
263
|
+
* @param {{advance?: boolean}} [options={}] Whether an hour pick opens the minute dial.
|
|
255
264
|
* @returns {void}
|
|
256
265
|
*/
|
|
257
|
-
_pick(value) {
|
|
266
|
+
_pick(value, { advance = true } = {}) {
|
|
258
267
|
const next = { ...this._display, [this._clockUnit]: value };
|
|
259
|
-
const
|
|
268
|
+
const toMinutes = advance && this._clockUnit === 'h';
|
|
260
269
|
this.set(next);
|
|
261
|
-
if (
|
|
270
|
+
if (toMinutes) this.openClock('m');
|
|
262
271
|
}
|
|
263
272
|
|
|
264
273
|
/** @param {KeyboardEvent} event @returns {void} */
|
|
@@ -275,8 +284,8 @@ export class TimePicker extends Component {
|
|
|
275
284
|
else if (event.key === 'End') next = marks.length - 1;
|
|
276
285
|
if (next === null) return;
|
|
277
286
|
event.preventDefault();
|
|
278
|
-
// Selection follows focus, the APG behaviour for a radio group.
|
|
279
|
-
this._pick(Number(marks[next].dataset.value));
|
|
287
|
+
// Selection follows focus, the APG behaviour for a radio group — within this group only.
|
|
288
|
+
this._pick(Number(marks[next].dataset.value), { advance: false });
|
|
280
289
|
this.refs.dial.querySelector(`[data-value="${marks[next].dataset.value}"]`)?.focus();
|
|
281
290
|
}
|
|
282
291
|
|
|
@@ -296,14 +305,15 @@ export class TimePicker extends Component {
|
|
|
296
305
|
|
|
297
306
|
const selected = hours ? this._display.h : this._display.m;
|
|
298
307
|
const marks = hours ? hourMarks() : minuteMarks();
|
|
308
|
+
const stop = tabStop(marks, selected, hours ? 24 : 60);
|
|
299
309
|
const rendered = this.refs.dial.querySelectorAll('.zx-time-picker__mark');
|
|
300
310
|
// Rebuild only when the dial switches unit; otherwise just restate which mark is checked.
|
|
301
311
|
if (rendered.length !== marks.length || this.refs.dial.dataset.unit !== this._clockUnit) {
|
|
302
312
|
for (const mark of rendered) mark.remove();
|
|
303
313
|
this.refs.dial.dataset.unit = this._clockUnit;
|
|
304
|
-
this.refs.dial.append(...marks.map((mark) => this._buildMark(mark, selected)));
|
|
314
|
+
this.refs.dial.append(...marks.map((mark) => this._buildMark(mark, selected, stop)));
|
|
305
315
|
} else {
|
|
306
|
-
marks.forEach((mark, index) => this._syncMark(rendered[index], mark, selected));
|
|
316
|
+
marks.forEach((mark, index) => this._syncMark(rendered[index], mark, selected, stop));
|
|
307
317
|
}
|
|
308
318
|
|
|
309
319
|
const ring = hours && !isOuterHour(selected) ? 'inner' : 'outer';
|
|
@@ -312,8 +322,8 @@ export class TimePicker extends Component {
|
|
|
312
322
|
this.refs.hand.style.setProperty('--zx-clock-angle', `${angle}deg`);
|
|
313
323
|
}
|
|
314
324
|
|
|
315
|
-
/** @param {ClockMark} mark @param {number} selected @returns {HTMLElement} */
|
|
316
|
-
_buildMark(mark, selected) {
|
|
325
|
+
/** @param {ClockMark} mark @param {number} selected @param {number} stop @returns {HTMLElement} */
|
|
326
|
+
_buildMark(mark, selected, stop) {
|
|
317
327
|
const element = h('button', {
|
|
318
328
|
class: 'zx-time-picker__mark',
|
|
319
329
|
type: 'button',
|
|
@@ -321,15 +331,18 @@ export class TimePicker extends Component {
|
|
|
321
331
|
dataset: { value: String(mark.value), ring: mark.ring }
|
|
322
332
|
}, mark.label);
|
|
323
333
|
element.style.setProperty('--zx-clock-angle', `${mark.angle}deg`);
|
|
324
|
-
this._syncMark(element, mark, selected);
|
|
334
|
+
this._syncMark(element, mark, selected, stop);
|
|
325
335
|
return element;
|
|
326
336
|
}
|
|
327
337
|
|
|
328
|
-
/**
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
338
|
+
/**
|
|
339
|
+
* @param {HTMLElement} element @param {ClockMark} mark @param {number} selected
|
|
340
|
+
* @param {number} stop Value of the one mark in the Tab order.
|
|
341
|
+
* @returns {void}
|
|
342
|
+
*/
|
|
343
|
+
_syncMark(element, mark, selected, stop) {
|
|
344
|
+
element.setAttribute('aria-checked', String(mark.value === selected));
|
|
345
|
+
element.tabIndex = mark.value === stop ? 0 : -1;
|
|
333
346
|
}
|
|
334
347
|
|
|
335
348
|
/**
|
|
@@ -376,6 +389,28 @@ function minuteMarks() {
|
|
|
376
389
|
return marks;
|
|
377
390
|
}
|
|
378
391
|
|
|
392
|
+
/**
|
|
393
|
+
* The mark that takes the dial's Tab stop: the checked one, or — when the value falls between
|
|
394
|
+
* marks, as 12:07 does on a five-minute dial — the nearest, so the group is always reachable.
|
|
395
|
+
* @param {ClockMark[]} marks Marks on the dial.
|
|
396
|
+
* @param {number} selected Current hour or minute.
|
|
397
|
+
* @param {number} cycle Values around the dial (24 or 60).
|
|
398
|
+
* @returns {number}
|
|
399
|
+
*/
|
|
400
|
+
export function tabStop(marks, selected, cycle) {
|
|
401
|
+
let best = marks[0]?.value ?? 0;
|
|
402
|
+
let distance = Infinity;
|
|
403
|
+
for (const { value } of marks) {
|
|
404
|
+
const gap = Math.abs(value - selected);
|
|
405
|
+
const around = Math.min(gap, cycle - gap);
|
|
406
|
+
if (around < distance) {
|
|
407
|
+
best = value;
|
|
408
|
+
distance = around;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return best;
|
|
412
|
+
}
|
|
413
|
+
|
|
379
414
|
/** @param {number} hour @returns {boolean} */
|
|
380
415
|
function isOuterHour(hour) {
|
|
381
416
|
return hour >= 1 && hour <= 12;
|
|
@@ -123,7 +123,7 @@ export class DateRangeBox extends Component {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
// State used by render() is initialized inside it, never as class fields: render() runs from the
|
|
126
|
-
// base constructor, before field initializers would reset it
|
|
126
|
+
// base constructor, before field initializers would reset it.
|
|
127
127
|
|
|
128
128
|
/** @returns {HTMLElement} */
|
|
129
129
|
render() {
|
|
@@ -145,13 +145,15 @@ export class DateRangeBox extends Component {
|
|
|
145
145
|
|
|
146
146
|
const content = h('div', { class: 'zx-date-range-box__content' },
|
|
147
147
|
h('div', { ref: 'control', class: 'zx-date-range-box__control' },
|
|
148
|
+
// APG date picker combobox: the text field owns the expanded state of the calendar dialog.
|
|
148
149
|
h('input', {
|
|
149
150
|
ref: 'input',
|
|
150
151
|
class: 'zx-date-range-box__input',
|
|
151
152
|
type: 'text',
|
|
153
|
+
role: 'combobox',
|
|
152
154
|
autocomplete: 'off',
|
|
153
155
|
placeholder: this.options.placeholder ?? this._placeholder(),
|
|
154
|
-
'aria-haspopup': '
|
|
156
|
+
'aria-haspopup': 'dialog',
|
|
155
157
|
ariaControls: popoverId,
|
|
156
158
|
ariaExpanded: 'false'
|
|
157
159
|
}),
|
|
@@ -166,7 +168,7 @@ export class DateRangeBox extends Component {
|
|
|
166
168
|
class: 'zx-date-range-box__toggle',
|
|
167
169
|
type: 'button',
|
|
168
170
|
ariaLabel: text('daterange.choose', 'Choose date range'),
|
|
169
|
-
'aria-haspopup': '
|
|
171
|
+
'aria-haspopup': 'dialog',
|
|
170
172
|
ariaControls: popoverId,
|
|
171
173
|
ariaExpanded: 'false'
|
|
172
174
|
}, icon('calendar'))
|
|
@@ -175,6 +177,8 @@ export class DateRangeBox extends Component {
|
|
|
175
177
|
ref: 'popover',
|
|
176
178
|
id: popoverId,
|
|
177
179
|
class: 'zx-date-range-box__popover',
|
|
180
|
+
role: 'dialog',
|
|
181
|
+
ariaLabel: text('daterange.choose', 'Choose date range'),
|
|
178
182
|
popover: 'manual',
|
|
179
183
|
dataset: { state: 'closed' }
|
|
180
184
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component } from '../../core/component.js';
|
|
2
|
-
import {
|
|
2
|
+
import { formatDate, parseDate } from '../../core/date.js';
|
|
3
3
|
import { h } from '../../core/dom.js';
|
|
4
4
|
import { ICON_SIZE, icon } from '../../core/icons.js';
|
|
5
5
|
import { position } from '../../core/position.js';
|
|
@@ -16,8 +16,10 @@ import { placeholderTokens } from './placeholder.js';
|
|
|
16
16
|
* so a date reads as the rest of the screen writes dates. It is never parsed, so it may use any
|
|
17
17
|
* `formatDate()` token, month and weekday names included. Null shows `format`.
|
|
18
18
|
* @property {boolean} [time=false] Append `%H:%M` and show time controls.
|
|
19
|
-
* @property {Date|null} [min=null] Earliest selectable date.
|
|
20
|
-
*
|
|
19
|
+
* @property {Date|null} [min=null] Earliest selectable date. Bounds are whole local calendar days,
|
|
20
|
+
* as in the calendar: with `time`, any time on the `min` day is allowed.
|
|
21
|
+
* @property {Date|null} [max=null] Latest selectable date, the whole local calendar day: with
|
|
22
|
+
* `time`, any time on the `max` day is allowed.
|
|
21
23
|
* @property {string|null} [placeholder=null] Input placeholder; null derives one from the format.
|
|
22
24
|
* @property {boolean} [clearable=true] Show a clear button while a value is present and the box is
|
|
23
25
|
* enabled; without it the input keeps no room for one.
|
|
@@ -76,13 +78,15 @@ export class Datebox extends Component {
|
|
|
76
78
|
|
|
77
79
|
const content = h('div', { class: 'zx-datebox__content' },
|
|
78
80
|
h('div', { ref: 'control', class: 'zx-datebox__control' },
|
|
81
|
+
// APG date picker combobox: the text field owns the expanded state of the calendar dialog.
|
|
79
82
|
h('input', {
|
|
80
83
|
ref: 'input',
|
|
81
84
|
class: 'zx-datebox__input',
|
|
82
85
|
type: 'text',
|
|
86
|
+
role: 'combobox',
|
|
83
87
|
autocomplete: 'off',
|
|
84
88
|
placeholder: this.options.placeholder ?? placeholderFromFormat(this._format, (key) => this.msg(key)),
|
|
85
|
-
'aria-haspopup': '
|
|
89
|
+
'aria-haspopup': 'dialog',
|
|
86
90
|
ariaControls: popoverId,
|
|
87
91
|
ariaExpanded: 'false'
|
|
88
92
|
}),
|
|
@@ -97,7 +101,7 @@ export class Datebox extends Component {
|
|
|
97
101
|
class: 'zx-datebox__toggle',
|
|
98
102
|
type: 'button',
|
|
99
103
|
ariaLabel: this.msg('datebox.choose'),
|
|
100
|
-
'aria-haspopup': '
|
|
104
|
+
'aria-haspopup': 'dialog',
|
|
101
105
|
ariaControls: popoverId,
|
|
102
106
|
ariaExpanded: 'false'
|
|
103
107
|
}, icon('calendar'))
|
|
@@ -106,6 +110,8 @@ export class Datebox extends Component {
|
|
|
106
110
|
ref: 'popover',
|
|
107
111
|
id: popoverId,
|
|
108
112
|
class: 'zx-datebox__popover',
|
|
113
|
+
role: 'dialog',
|
|
114
|
+
ariaLabel: this.msg('datebox.choose'),
|
|
109
115
|
popover: 'manual',
|
|
110
116
|
dataset: { state: 'closed' }
|
|
111
117
|
})
|
|
@@ -298,7 +304,7 @@ export class Datebox extends Component {
|
|
|
298
304
|
else if (typeof value === 'number' && Number.isFinite(value)) date = new Date(value * 1000);
|
|
299
305
|
else if (typeof value === 'string') date = parseDate(value, this._format);
|
|
300
306
|
if (!date || Number.isNaN(date.getTime())) return null;
|
|
301
|
-
return
|
|
307
|
+
return clampDay(date, this._min, this._max);
|
|
302
308
|
}
|
|
303
309
|
|
|
304
310
|
/**
|
|
@@ -376,6 +382,26 @@ function validDate(value) {
|
|
|
376
382
|
return value instanceof Date && !Number.isNaN(value.getTime()) ? new Date(value.getTime()) : null;
|
|
377
383
|
}
|
|
378
384
|
|
|
385
|
+
/**
|
|
386
|
+
* Keeps a date inside the bounds by local calendar day, as the calendar does: a date on a day
|
|
387
|
+
* outside them moves to the nearest bound's day and keeps its time of day. Mutates `date`.
|
|
388
|
+
* @param {Date} date Date to clamp.
|
|
389
|
+
* @param {Date|null} min Earliest allowed day.
|
|
390
|
+
* @param {Date|null} max Latest allowed day.
|
|
391
|
+
* @returns {Date}
|
|
392
|
+
*/
|
|
393
|
+
function clampDay(date, min, max) {
|
|
394
|
+
const day = startOfDay(date);
|
|
395
|
+
const bound = min && day < startOfDay(min) ? min : max && day > startOfDay(max) ? max : null;
|
|
396
|
+
if (bound) date.setFullYear(bound.getFullYear(), bound.getMonth(), bound.getDate());
|
|
397
|
+
return date;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** @param {Date} date @returns {number} */
|
|
401
|
+
function startOfDay(date) {
|
|
402
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
403
|
+
}
|
|
404
|
+
|
|
379
405
|
/**
|
|
380
406
|
* Resolves the two formats a Datebox works with: `format`, which the reader types and the field
|
|
381
407
|
* shows while focused, and `display`, which the field shows at rest. A missing format is
|
|
@@ -35,6 +35,12 @@
|
|
|
35
35
|
padding-inline: 0;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/* `closable: false` (a sheet's `closeButton: false`) switches the header button off; the button's
|
|
39
|
+
own display rule must not show it. */
|
|
40
|
+
.zx-dialog .zx-dialog__close[hidden] {
|
|
41
|
+
display: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
38
44
|
.zx-dialog__body {
|
|
39
45
|
min-block-size: 0;
|
|
40
46
|
overflow: auto;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { h } from '../../core/dom.js';
|
|
2
2
|
import { ICON_SIZE, icon } from '../../core/icons.js';
|
|
3
3
|
import { uid } from '../../core/util.js';
|
|
4
|
+
import { appendContent, replaceContent } from '../../internal/overlay-content.js';
|
|
4
5
|
import { Modal } from '../modal/modal.js';
|
|
5
6
|
import { button } from '../button/button.js';
|
|
6
7
|
|
|
@@ -19,7 +20,7 @@ import { button } from '../button/button.js';
|
|
|
19
20
|
* @property {string} [title=''] Dialog title.
|
|
20
21
|
* @property {'sm'|'md'|'lg'|number} [size='md'] Preset or pixel width.
|
|
21
22
|
* @property {DialogButton[]} [buttons=[]] Footer buttons.
|
|
22
|
-
* @property {boolean} [closable=true] Whether Escape and the header button may close the dialog.
|
|
23
|
+
* @property {boolean} [closable=true] Whether Escape and the header button may close the dialog. When false the header button is not rendered as a control at all: it is not displayed, not focusable, and closes nothing.
|
|
23
24
|
* @property {Node|string|number|{toElement: () => Node|null}|null} [content=null] Body content.
|
|
24
25
|
* @property {Element|string|null} [scope=null] Element whose nearest Zx theme scope owns the overlay; defaults to the opener. Resolved on every open, so a scope connected after construction still owns it.
|
|
25
26
|
* @property {(event: CustomEvent<Record<string, never>>) => void} [onopen] Open event listener.
|
|
@@ -105,9 +106,13 @@ export class Dialog extends Modal {
|
|
|
105
106
|
this.#applyTitle(this.#baseTitle);
|
|
106
107
|
this.#baseButtons = normalizeDialogButtons(this.options.buttons);
|
|
107
108
|
this.#renderButtons(this.#baseButtons);
|
|
108
|
-
this.refs.close.hidden = !this.
|
|
109
|
+
this.refs.close.hidden = !this._hasCloseButton();
|
|
109
110
|
|
|
110
|
-
this.listen(this.refs.close, 'click', () =>
|
|
111
|
+
this.listen(this.refs.close, 'click', () => {
|
|
112
|
+
// Switched off, the button is not displayed; a click dispatched at it all the same — by a
|
|
113
|
+
// script, or by a stylesheet that shows it again — must not close what was made unclosable.
|
|
114
|
+
if (this._hasCloseButton()) this._requestDismiss('close-button');
|
|
115
|
+
});
|
|
111
116
|
this.listen(this.refs.footer, 'click', (event) => {
|
|
112
117
|
const button = event.target.closest?.('[data-dialog-button]');
|
|
113
118
|
if (!button || !this.refs.footer.contains(button)) return;
|
|
@@ -416,6 +421,20 @@ export class Dialog extends Modal {
|
|
|
416
421
|
});
|
|
417
422
|
}
|
|
418
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Whether the header close button is offered. Switched off, it is not displayed, not focusable,
|
|
426
|
+
* and does not dismiss the dialog. A dialog shows it while it is `closable`; a subclass with a
|
|
427
|
+
* setting of its own for the button overrides this.
|
|
428
|
+
*
|
|
429
|
+
* Called from the constructor before any subclass field initializers have run, so an override
|
|
430
|
+
* may read `this.options` but no instance state.
|
|
431
|
+
* @returns {boolean}
|
|
432
|
+
* @protected
|
|
433
|
+
*/
|
|
434
|
+
_hasCloseButton() {
|
|
435
|
+
return Boolean(this.options.closable);
|
|
436
|
+
}
|
|
437
|
+
|
|
419
438
|
/**
|
|
420
439
|
* Applies the dialog width. Subclasses that size themselves on a different axis override this.
|
|
421
440
|
*
|
|
@@ -533,30 +552,3 @@ export function normalizeDialogButtons(list) {
|
|
|
533
552
|
};
|
|
534
553
|
});
|
|
535
554
|
}
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* @param {Element} target
|
|
539
|
-
* @param {Node|string|number|{toElement: () => Node|null}|null|undefined} content
|
|
540
|
-
* @returns {void}
|
|
541
|
-
*/
|
|
542
|
-
function replaceContent(target, content) {
|
|
543
|
-
target.replaceChildren();
|
|
544
|
-
appendContent(target, content);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* @param {Element} target
|
|
549
|
-
* @param {Node|string|number|{toElement: () => Node|null}|null|undefined} content
|
|
550
|
-
* @returns {void}
|
|
551
|
-
*/
|
|
552
|
-
function appendContent(target, content) {
|
|
553
|
-
if (content == null) return;
|
|
554
|
-
if (typeof content === 'string' || typeof content === 'number') {
|
|
555
|
-
target.append(document.createTextNode(String(content)));
|
|
556
|
-
} else if (typeof content.toElement === 'function') {
|
|
557
|
-
const element = content.toElement();
|
|
558
|
-
if (element) target.append(element);
|
|
559
|
-
} else if (typeof content.nodeType === 'number') {
|
|
560
|
-
target.append(content);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
@@ -4,6 +4,7 @@ import { connectedOverlayHost, openDialogOf, overlayHost, overlayScope } from '.
|
|
|
4
4
|
import { pushOverlay } from '../../core/overlay-stack.js';
|
|
5
5
|
import { position } from '../../core/position.js';
|
|
6
6
|
import { uid } from '../../core/util.js';
|
|
7
|
+
import { replaceContent } from '../../internal/overlay-content.js';
|
|
7
8
|
|
|
8
9
|
/** What Tab may land on inside a panel: the controls a reader reaches in sequence. */
|
|
9
10
|
const TABBABLE_SELECTOR = [
|
|
@@ -305,24 +306,6 @@ export class Dropdown extends Component {
|
|
|
305
306
|
* @type {CustomEvent<Record<string, never>>}
|
|
306
307
|
*/
|
|
307
308
|
|
|
308
|
-
/**
|
|
309
|
-
* @param {Element} target
|
|
310
|
-
* @param {Node|string|number|{toElement: () => Node|null}|null|undefined} content
|
|
311
|
-
* @returns {void}
|
|
312
|
-
*/
|
|
313
|
-
function replaceContent(target, content) {
|
|
314
|
-
target.replaceChildren();
|
|
315
|
-
if (content == null) return;
|
|
316
|
-
if (typeof content === 'string' || typeof content === 'number') {
|
|
317
|
-
target.append(document.createTextNode(String(content)));
|
|
318
|
-
} else if (typeof content.toElement === 'function') {
|
|
319
|
-
const element = content.toElement();
|
|
320
|
-
if (element) target.append(element);
|
|
321
|
-
} else if (typeof content.nodeType === 'number') {
|
|
322
|
-
target.append(content);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
309
|
/**
|
|
327
310
|
* The controls inside a container Tab would visit, in document order.
|
|
328
311
|
* @param {Element} container
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { h } from '../../core/dom.js';
|
|
2
2
|
import { icon as createIcon } from '../../core/icons.js';
|
|
3
3
|
import { isElement } from '../../core/util.js';
|
|
4
|
+
import { agentAvatarOptions } from '../../internal/agent-model.js';
|
|
5
|
+
import { AgentAvatar } from '../agent-avatar/agent-avatar.js';
|
|
4
6
|
import { button } from '../button/button.js';
|
|
5
7
|
|
|
6
8
|
/** @typedef {import('../button/button.js').ButtonOptions} ButtonOptions */
|
|
9
|
+
/** @typedef {import('../../internal/agent-model.js').AgentFace} AgentFace */
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* @typedef {Object} EmptyStateOptions
|
|
10
13
|
* @property {string|null} [icon='folder-open'] Decorative icon name; null renders no icon.
|
|
14
|
+
* @property {AgentFace|true|null} [agent=null] Draws an agent's face in place of the icon — an empty
|
|
15
|
+
* conversation, an agent with nothing to do yet: its AgentAvatar traits and name, or `true` to
|
|
16
|
+
* derive the face from the title. The face is keyed by the agent's `seed`, else its `name`, else
|
|
17
|
+
* the title; give the agent's seed or name so its face matches the one drawn elsewhere.
|
|
18
|
+
* Decorative and at rest, so the text says whose it is.
|
|
11
19
|
* @property {string} [title=''] Headline text, rendered as a paragraph so page outlines stay intact.
|
|
12
20
|
* @property {string} [description=''] Supporting sentence below the headline.
|
|
13
21
|
* @property {Array<Element|ButtonOptions>} [actions=[]] Buttons or button descriptors below the text.
|
|
@@ -18,9 +26,13 @@ import { button } from '../button/button.js';
|
|
|
18
26
|
/** Icon sizes per `size` option. */
|
|
19
27
|
const ICON_SIZE = Object.freeze({ md: 40, sm: 28 });
|
|
20
28
|
|
|
29
|
+
/** Agent face sizes per `size` option: the `lg` preset and the smallest size a soft body keeps. */
|
|
30
|
+
const AGENT_SIZE = Object.freeze({ md: 'lg', sm: 28 });
|
|
31
|
+
|
|
21
32
|
/** @type {Readonly<EmptyStateOptions>} */
|
|
22
33
|
const defaults = Object.freeze({
|
|
23
34
|
icon: 'folder-open',
|
|
35
|
+
agent: null,
|
|
24
36
|
title: '',
|
|
25
37
|
description: '',
|
|
26
38
|
actions: [],
|
|
@@ -31,7 +43,7 @@ const defaults = Object.freeze({
|
|
|
31
43
|
/**
|
|
32
44
|
* Creates the placeholder shown where a list, table, or panel has no content yet.
|
|
33
45
|
*
|
|
34
|
-
* Purely presentational: the icon is decorative, the headline is a paragraph rather than a heading
|
|
46
|
+
* Purely presentational: the icon — or an agent's face — is decorative, the headline is a paragraph rather than a heading
|
|
35
47
|
* so dropping the element into a Table's empty slot or a Panel body never disturbs the page's
|
|
36
48
|
* heading outline.
|
|
37
49
|
*
|
|
@@ -46,7 +58,14 @@ export function emptyState(opts = {}) {
|
|
|
46
58
|
dataset: { size, align: normalizeAlign(options.align) }
|
|
47
59
|
}));
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
const face = agentAvatarOptions(options.agent, { size: AGENT_SIZE[size], label: null, activity: null, animate: false },
|
|
62
|
+
{ fallback: { name: String(options.title ?? '') } });
|
|
63
|
+
if (face) {
|
|
64
|
+
// At rest it holds no listener and no loop entry, so it goes with the element.
|
|
65
|
+
element.append(h('div', { class: 'zx-empty-state__icon', ariaHidden: 'true', dataset: { agent: '' } },
|
|
66
|
+
new AgentAvatar(null, face).toElement()
|
|
67
|
+
));
|
|
68
|
+
} else if (options.icon) {
|
|
50
69
|
element.append(h('div', { class: 'zx-empty-state__icon', ariaHidden: 'true' },
|
|
51
70
|
createIcon(options.icon, { size: ICON_SIZE[size] })
|
|
52
71
|
));
|