@zeyos/zx 5.6.0 → 5.7.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 +154 -0
- package/README.md +73 -7
- package/bin/zx-css.js +328 -0
- package/dist/types/components/account-menu/account-menu.d.ts +4 -2
- package/dist/types/components/activity-list/activity-list.d.ts +14 -8
- package/dist/types/components/agent-thread/ag-ui.d.ts +340 -0
- package/dist/types/components/agent-thread/agent-thread.d.ts +142 -14
- package/dist/types/components/agent-thread/ui-message-stream.d.ts +401 -0
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +14 -8
- package/dist/types/components/breadcrumb/breadcrumb.d.ts +3 -3
- package/dist/types/components/calendar/calendar-model.d.ts +9 -2
- package/dist/types/components/calendar/calendar.d.ts +12 -4
- package/dist/types/components/chart/chart.d.ts +25 -13
- package/dist/types/components/code-editor/code-editor.d.ts +7 -2
- package/dist/types/components/composer/composer.d.ts +206 -4
- package/dist/types/components/composer/queue.d.ts +76 -0
- package/dist/types/components/copy/copy-button.d.ts +6 -4
- package/dist/types/components/copy/copy-input.d.ts +10 -6
- package/dist/types/components/datebox/date-range-box.d.ts +33 -0
- package/dist/types/components/datebox/placeholder.d.ts +7 -0
- package/dist/types/components/dock/dock.d.ts +12 -3
- package/dist/types/components/entity-ref/entity-ref.d.ts +5 -3
- package/dist/types/components/field-upload/field-upload.d.ts +3 -2
- package/dist/types/components/file-item/file-item.d.ts +3 -2
- package/dist/types/components/file-list/file-list.d.ts +14 -8
- package/dist/types/components/filter/filter-model.d.ts +31 -1
- package/dist/types/components/filter/filter.d.ts +20 -2
- package/dist/types/components/finder/finder.d.ts +14 -6
- package/dist/types/components/flag/flag.d.ts +99 -0
- package/dist/types/components/grid/grid.d.ts +1 -1
- package/dist/types/components/kanban-view/kanban-view.d.ts +8 -66
- package/dist/types/components/launcher/launcher.d.ts +2 -0
- package/dist/types/components/multi-value-editor/multi-value-editor.d.ts +3 -2
- package/dist/types/components/number-field/number-field.d.ts +17 -6
- package/dist/types/components/prompt-starters/prompt-starters.d.ts +107 -0
- package/dist/types/components/prose/prose.d.ts +9 -6
- package/dist/types/components/questionnaire/conditions.d.ts +270 -0
- package/dist/types/components/questionnaire/items.d.ts +52 -30
- package/dist/types/components/questionnaire/questionnaire.d.ts +44 -4
- package/dist/types/components/rating/rating.d.ts +5 -3
- package/dist/types/components/select/country.d.ts +106 -0
- package/dist/types/components/select/field-adapter.d.ts +2 -1
- package/dist/types/components/select/locale.d.ts +102 -0
- package/dist/types/components/select/select.d.ts +41 -2
- package/dist/types/components/slider/slider.d.ts +1 -0
- package/dist/types/components/sort-control/sort-control.d.ts +7 -3
- package/dist/types/components/source-list/source-list.d.ts +7 -5
- package/dist/types/components/split-view/split-view.d.ts +5 -3
- package/dist/types/components/surface/catalog.d.ts +260 -0
- package/dist/types/components/surface/elicit.d.ts +81 -0
- package/dist/types/components/surface/mcp.d.ts +165 -0
- package/dist/types/components/surface/schema.d.ts +314 -0
- package/dist/types/components/surface/stream.d.ts +118 -0
- package/dist/types/components/surface/surface.d.ts +718 -0
- package/dist/types/components/surface/text.d.ts +277 -0
- package/dist/types/components/surface/validate.d.ts +339 -0
- package/dist/types/components/table/table.d.ts +55 -3
- package/dist/types/components/table/window.d.ts +203 -0
- package/dist/types/components/toolbar/toolbar.d.ts +10 -6
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/components/tree/tree.d.ts +20 -13
- package/dist/types/core/component.d.ts +10 -0
- package/dist/types/core/date.d.ts +8 -1
- package/dist/types/core/dom.d.ts +1 -0
- package/dist/types/core/http.d.ts +10 -0
- package/dist/types/core/i18n.d.ts +38 -0
- package/dist/types/core/messages.d.ts +344 -1
- package/dist/types/core/storage.d.ts +7 -2
- package/dist/types/elements/define.d.ts +21 -46
- package/dist/types/elements/definitions.d.ts +147 -0
- package/dist/types/elements/kit.d.ts +7 -0
- package/dist/types/elements/reflect.d.ts +6 -3
- package/dist/types/index.d.ts +10 -1
- package/dist/types/internal/date-locale.d.ts +7 -0
- package/dist/types/internal/json-patch.d.ts +146 -0
- package/dist/types/locales/de.d.ts +13 -0
- package/dist/types/locales/en.d.ts +2 -0
- package/dist/types/locales/index.d.ts +823 -0
- package/dist/types/zeyos/view.d.ts +8 -1
- package/dist/zx-zeyos.esm.js +16802 -15180
- package/dist/zx-zeyos.esm.min.js +5 -5
- package/dist/zx.core.css +1276 -0
- package/dist/zx.core.min.css +1 -0
- package/dist/zx.css +498 -134
- package/dist/zx.esm.js +40778 -29654
- package/dist/zx.esm.min.js +36 -23
- package/dist/zx.global.js +40778 -29654
- package/dist/zx.global.min.js +36 -23
- package/dist/zx.layered.css +17302 -0
- package/dist/zx.layered.min.css +1 -0
- package/dist/zx.min.css +1 -1
- package/docs/agent-catalog.json +12501 -0
- package/docs/agent-surfaces.md +340 -0
- package/docs/api.json +851 -121
- package/docs/llms.md +1018 -71
- package/docs/llms.txt +30 -9
- package/package.json +29 -6
- package/src/components/account-menu/account-menu.js +6 -3
- package/src/components/activity-item/activity-item.js +2 -1
- package/src/components/activity-list/activity-list.js +16 -10
- package/src/components/agent-thread/ag-ui.js +1439 -0
- package/src/components/agent-thread/agent-thread.js +359 -54
- package/src/components/agent-thread/ui-message-stream.js +1281 -0
- package/src/components/app-sidebar/app-sidebar.js +18 -8
- package/src/components/approval-card/approval-card.js +3 -2
- package/src/components/block-view/block-view.js +7 -6
- package/src/components/breadcrumb/breadcrumb.js +8 -5
- package/src/components/calendar/calendar-model.js +8 -2
- package/src/components/calendar/calendar.js +53 -18
- package/src/components/chart/chart.js +54 -23
- package/src/components/code-editor/code-editor.js +45 -8
- package/src/components/code-editor/field-adapter.js +1 -1
- package/src/components/composer/composer.css +80 -1
- package/src/components/composer/composer.js +390 -16
- package/src/components/composer/queue.js +78 -0
- package/src/components/context-menu/context-menu.js +12 -1
- package/src/components/copy/copy-button.js +9 -7
- package/src/components/copy/copy-input.js +10 -6
- package/src/components/date-picker/date-picker.js +2 -1
- package/src/components/date-picker/date-range-picker.js +8 -7
- package/src/components/datebox/date-range-box.js +3 -9
- package/src/components/datebox/datebox.js +18 -21
- package/src/components/datebox/placeholder.js +18 -0
- package/src/components/dialog/dialog.js +1 -1
- package/src/components/dock/dock.js +34 -13
- package/src/components/entity-ref/entity-ref.js +16 -5
- package/src/components/field-upload/field-upload.js +81 -38
- package/src/components/file-item/file-item.js +70 -40
- package/src/components/file-list/file-list.js +15 -9
- package/src/components/filter/filter-model.js +46 -8
- package/src/components/filter/filter.css +3 -3
- package/src/components/filter/filter.js +29 -10
- package/src/components/filter-panel/filter-panel.js +13 -5
- package/src/components/finder/finder.js +50 -26
- package/src/components/flag/flag.css +40 -0
- package/src/components/flag/flag.js +177 -0
- package/src/components/form/form.js +1 -1
- package/src/components/grid/grid.js +22 -8
- package/src/components/kanban-view/kanban-view.js +51 -81
- package/src/components/launcher/launcher.js +17 -2
- package/src/components/list-toolbar/list-toolbar.js +2 -1
- package/src/components/master-panel/master-panel.js +1 -1
- package/src/components/menu-button/menu-button.js +4 -0
- package/src/components/message/message.js +3 -0
- package/src/components/multi-value-editor/multi-value-editor.js +10 -9
- package/src/components/navigation-bar/navigation-bar.js +3 -3
- package/src/components/number-field/number-field.js +29 -13
- package/src/components/prompt-starters/prompt-starters.css +91 -0
- package/src/components/prompt-starters/prompt-starters.js +206 -0
- package/src/components/prose/prose.js +14 -10
- package/src/components/questionnaire/conditions.js +666 -0
- package/src/components/questionnaire/items.js +150 -41
- package/src/components/questionnaire/questionnaire.js +126 -32
- package/src/components/rating/rating.js +5 -4
- package/src/components/run-status/run-status.js +2 -2
- package/src/components/select/country.js +136 -0
- package/src/components/select/field-adapter.js +7 -2
- package/src/components/select/locale.js +219 -0
- package/src/components/select/select.css +20 -22
- package/src/components/select/select.js +94 -12
- package/src/components/sheet/sheet-stack.js +10 -1
- package/src/components/slider/slider.js +7 -2
- package/src/components/sort-control/sort-control.js +15 -5
- package/src/components/source-list/source-list.js +7 -4
- package/src/components/split-view/split-view.js +5 -3
- package/src/components/surface/catalog.js +1334 -0
- package/src/components/surface/elicit.js +107 -0
- package/src/components/surface/mcp.js +243 -0
- package/src/components/surface/schema.js +644 -0
- package/src/components/surface/stream.js +245 -0
- package/src/components/surface/surface.css +308 -0
- package/src/components/surface/surface.js +2291 -0
- package/src/components/surface/text.js +513 -0
- package/src/components/surface/validate.js +2218 -0
- package/src/components/tabbox/tabbox.js +9 -0
- package/src/components/table/table.css +63 -3
- package/src/components/table/table.js +167 -28
- package/src/components/table/window.js +317 -0
- package/src/components/toolbar/toolbar.js +12 -7
- package/src/components/tooltip/tooltip.css +2 -3
- package/src/components/tooltip/tooltip.js +32 -5
- package/src/components/tree/tree.js +53 -23
- package/src/core/component.js +25 -1
- package/src/core/date.js +62 -16
- package/src/core/dom.js +22 -2
- package/src/core/format.js +15 -13
- package/src/core/http.js +29 -20
- package/src/core/i18n.js +83 -10
- package/src/core/keyboard.js +79 -8
- package/src/core/messages.js +376 -2
- package/src/core/overlay-host.js +1 -0
- package/src/core/storage.js +59 -6
- package/src/elements/define.js +178 -130
- package/src/elements/definitions.js +229 -0
- package/src/elements/kit.js +444 -0
- package/src/elements/reflect.js +8 -3
- package/src/index.js +10 -1
- package/src/internal/date-locale.js +11 -0
- package/src/internal/json-patch.js +405 -0
- package/src/locales/de.js +911 -0
- package/src/locales/en.js +2 -0
- package/src/locales/index.js +7 -0
- package/src/zeyos/calendar.js +2 -1
- package/src/zeyos/form.js +2 -1
- package/src/zeyos/launcher.js +7 -6
- package/src/zeyos/module-bar.js +2 -1
- package/src/zeyos/schema.js +37 -23
- package/src/zeyos/select.js +4 -3
- package/src/zeyos/table.js +2 -13
- package/src/zeyos/view.js +57 -17
- package/styles/core.css +11 -0
- package/styles/tokens/semantic.css +1 -0
- package/styles/zeyos.css +2 -0
- package/styles/zx.css +4 -8
- package/styles/zx.layered.css +1 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* PromptStarters — the starting points of an empty conversation: a group of buttons on the surface
|
|
3
|
+
* tone, each a title with a muted line of two at most beneath it. The root is the container its
|
|
4
|
+
* own narrow form asks about, so it fills whatever it is placed in.
|
|
5
|
+
*/
|
|
6
|
+
.zx-prompt-starters {
|
|
7
|
+
container: zx-prompt-starters / inline-size;
|
|
8
|
+
display: grid;
|
|
9
|
+
gap: var(--zx-space-3);
|
|
10
|
+
inline-size: 100%;
|
|
11
|
+
min-inline-size: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.zx-prompt-starters[hidden] {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.zx-prompt-starters__heading {
|
|
19
|
+
margin: 0;
|
|
20
|
+
color: var(--zx-color-text-muted);
|
|
21
|
+
font-size: var(--zx-text-sm);
|
|
22
|
+
font-weight: var(--zx-weight-medium);
|
|
23
|
+
text-align: start;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.zx-prompt-starters__list {
|
|
27
|
+
display: grid;
|
|
28
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
29
|
+
gap: var(--zx-space-3);
|
|
30
|
+
min-inline-size: 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.zx-prompt-starters[data-columns="1"] > .zx-prompt-starters__list {
|
|
34
|
+
grid-template-columns: minmax(0, 1fr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@container zx-prompt-starters (inline-size < 32rem) {
|
|
38
|
+
.zx-prompt-starters[data-columns="auto"] > .zx-prompt-starters__list {
|
|
39
|
+
grid-template-columns: minmax(0, 1fr);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.zx-prompt-starters .zx-prompt-starters__item {
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: flex-start;
|
|
46
|
+
gap: var(--zx-space-2);
|
|
47
|
+
min-inline-size: 0;
|
|
48
|
+
padding: var(--zx-space-3) var(--zx-space-4);
|
|
49
|
+
border: 1px solid var(--zx-color-border-subtle);
|
|
50
|
+
border-radius: var(--zx-radius-lg);
|
|
51
|
+
background: var(--zx-color-bg-surface);
|
|
52
|
+
color: var(--zx-color-text);
|
|
53
|
+
text-align: start;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.zx-prompt-starters .zx-prompt-starters__item:hover {
|
|
57
|
+
border-color: var(--zx-color-border);
|
|
58
|
+
background: var(--zx-color-bg-hover);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.zx-prompt-starters .zx-prompt-starters__item:focus-visible {
|
|
62
|
+
outline-color: transparent;
|
|
63
|
+
box-shadow: var(--zx-focus-ring);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.zx-prompt-starters__item > .zx-icon {
|
|
67
|
+
flex: none;
|
|
68
|
+
margin-block-start: 2px;
|
|
69
|
+
color: var(--zx-color-text-subtle);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.zx-prompt-starters__copy {
|
|
73
|
+
display: grid;
|
|
74
|
+
gap: var(--zx-space-1);
|
|
75
|
+
min-inline-size: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.zx-prompt-starters__title {
|
|
79
|
+
font-weight: var(--zx-weight-medium);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.zx-prompt-starters__text {
|
|
83
|
+
display: -webkit-box;
|
|
84
|
+
overflow: hidden;
|
|
85
|
+
-webkit-box-orient: vertical;
|
|
86
|
+
-webkit-line-clamp: 2;
|
|
87
|
+
line-clamp: 2;
|
|
88
|
+
color: var(--zx-color-text-muted);
|
|
89
|
+
font-size: var(--zx-text-sm);
|
|
90
|
+
font-weight: 400;
|
|
91
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Component } from '../../core/component.js';
|
|
3
|
+
import { h, restoreTarget, snapshotTarget } from '../../core/dom.js';
|
|
4
|
+
import { ICON_SIZE, icon } from '../../core/icons.js';
|
|
5
|
+
import { uid } from '../../core/util.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One conversation starter.
|
|
9
|
+
* @typedef {Object} PromptStarter
|
|
10
|
+
* @property {string|number} id Stable identifier.
|
|
11
|
+
* @property {string} title What the starter is called: its visible title and accessible name.
|
|
12
|
+
* @property {string} text The prompt it stands for, handed back in `pick`. Shown beneath the title
|
|
13
|
+
* when there is no `description`.
|
|
14
|
+
* @property {string} [description] What is shown beneath the title in place of `text`.
|
|
15
|
+
* @property {string} [icon] Icon name drawn before the title.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} PromptStartersOptions
|
|
20
|
+
* @property {PromptStarter[]} [items=[]] The starters. An entry without `id`, `title` or `text` is
|
|
21
|
+
* left out, as is a repeated id; any other field on an item is handed back in `pick`.
|
|
22
|
+
* @property {string|null} [label=null] Accessible name of the group. Omitted resolves
|
|
23
|
+
* `promptStarters.label`, English `Suggestions`.
|
|
24
|
+
* @property {'auto'|1|2} [columns='auto'] Columns of starters. `'auto'` is two, and one in a
|
|
25
|
+
* container narrower than 32rem.
|
|
26
|
+
* @property {1|2|3|4|5|6|null} [headingLevel=null] Shows `label` above the starters as a heading of
|
|
27
|
+
* this level, which then names the group. Null keeps the label for assistive technology only.
|
|
28
|
+
* @property {Record<string, string>|Record<string, Record<string, string>>} [msg] Localized messages.
|
|
29
|
+
* @property {(event: CustomEvent<{item: PromptStarter}>) => void} [onpick] Listener for a starter
|
|
30
|
+
* being picked.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const MESSAGES = Object.freeze({
|
|
34
|
+
'promptStarters.label': 'Suggestions'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Starting points for an empty conversation: a labelled group of buttons, each with a title and a
|
|
39
|
+
* muted line beneath it. A pick is only reported. Whether it fills the composer or sends at once
|
|
40
|
+
* is the application's decision, and PromptStarters never sends anything itself.
|
|
41
|
+
*
|
|
42
|
+
* @fires PromptStarters#pick
|
|
43
|
+
* @extends {Component<PromptStartersOptions>}
|
|
44
|
+
*/
|
|
45
|
+
export class PromptStarters extends Component {
|
|
46
|
+
static cssName = 'prompt-starters';
|
|
47
|
+
|
|
48
|
+
/** @type {Readonly<PromptStartersOptions>} */
|
|
49
|
+
static defaults = {
|
|
50
|
+
items: [],
|
|
51
|
+
label: null,
|
|
52
|
+
columns: 'auto',
|
|
53
|
+
headingLevel: null,
|
|
54
|
+
msg: MESSAGES
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** @returns {HTMLElement} */
|
|
58
|
+
render() {
|
|
59
|
+
const created = !this.el;
|
|
60
|
+
const root = /** @type {HTMLElement} */ (this.el ?? h('div'));
|
|
61
|
+
this.el = root;
|
|
62
|
+
this._original = created ? null : snapshotTarget(root);
|
|
63
|
+
if (!created) root.replaceChildren();
|
|
64
|
+
this._destroyed = false;
|
|
65
|
+
/** @type {PromptStarter[]} */
|
|
66
|
+
this._items = [];
|
|
67
|
+
|
|
68
|
+
const options = this.options;
|
|
69
|
+
const label = String(options.label ?? this.msg('promptStarters.label'));
|
|
70
|
+
const level = headingLevel(options.headingLevel);
|
|
71
|
+
root.setAttribute('role', 'group');
|
|
72
|
+
root.dataset.columns = columnsOf(options.columns);
|
|
73
|
+
this._list = h('div', { class: 'zx-prompt-starters__list' });
|
|
74
|
+
if (level) {
|
|
75
|
+
const id = uid('zx-prompt-starters-heading');
|
|
76
|
+
root.setAttribute('aria-labelledby', id);
|
|
77
|
+
root.append(h(`h${level}`, { class: 'zx-prompt-starters__heading', id }, label));
|
|
78
|
+
} else {
|
|
79
|
+
root.setAttribute('aria-label', label);
|
|
80
|
+
}
|
|
81
|
+
root.append(this._list);
|
|
82
|
+
|
|
83
|
+
this.listen(root, 'click', (event) => this._onClick(/** @type {MouseEvent} */ (event)));
|
|
84
|
+
this._build(options.items);
|
|
85
|
+
return root;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Replaces the starters. The focus on a starter stays on the starter with the same `id`. Emits
|
|
90
|
+
* nothing.
|
|
91
|
+
* @param {PromptStarter[]} items
|
|
92
|
+
* @returns {this}
|
|
93
|
+
*/
|
|
94
|
+
setItems(items) {
|
|
95
|
+
if (!this._destroyed) this._build(items);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Removes what was drawn and stops listening. @returns {void} */
|
|
100
|
+
destroy() {
|
|
101
|
+
if (this._destroyed) return;
|
|
102
|
+
this._destroyed = true;
|
|
103
|
+
super.destroy();
|
|
104
|
+
if (this._original) restoreTarget(this.el, this._original);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @private
|
|
109
|
+
* @param {unknown} items
|
|
110
|
+
* @returns {void}
|
|
111
|
+
*/
|
|
112
|
+
_build(items) {
|
|
113
|
+
const list = /** @type {HTMLElement} */ (this._list);
|
|
114
|
+
const active = list.ownerDocument.activeElement;
|
|
115
|
+
const focused = active && list.contains(active)
|
|
116
|
+
? /** @type {HTMLElement|null} */ (active.closest('[data-starter]'))?.dataset.starter ?? null
|
|
117
|
+
: null;
|
|
118
|
+
this._items = normalizeStarters(items);
|
|
119
|
+
list.replaceChildren(...this._items.map((item) => this._button(item)));
|
|
120
|
+
/** @type {HTMLElement} */ (this.el).hidden = this._items.length === 0;
|
|
121
|
+
if (focused === null) return;
|
|
122
|
+
const buttons = /** @type {HTMLElement[]} */ (Array.from(list.children));
|
|
123
|
+
buttons.find((button) => button.dataset.starter === focused)?.focus();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A starter's button: named by its title, described by the line beneath it.
|
|
128
|
+
* @private
|
|
129
|
+
* @param {PromptStarter} item
|
|
130
|
+
* @returns {HTMLElement}
|
|
131
|
+
*/
|
|
132
|
+
_button(item) {
|
|
133
|
+
const id = uid('zx-prompt-starter');
|
|
134
|
+
return h('button', {
|
|
135
|
+
type: 'button',
|
|
136
|
+
class: 'zx-prompt-starters__item',
|
|
137
|
+
dataset: { starter: String(item.id) },
|
|
138
|
+
'aria-labelledby': `${id}-title`,
|
|
139
|
+
'aria-describedby': `${id}-text`
|
|
140
|
+
},
|
|
141
|
+
item.icon ? icon(item.icon, { size: ICON_SIZE.control }) : null,
|
|
142
|
+
h('span', { class: 'zx-prompt-starters__copy' },
|
|
143
|
+
h('span', { class: 'zx-prompt-starters__title', id: `${id}-title` }, item.title),
|
|
144
|
+
h('span', { class: 'zx-prompt-starters__text', id: `${id}-text` }, item.description || item.text)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @private
|
|
149
|
+
* @param {MouseEvent} event
|
|
150
|
+
* @returns {void}
|
|
151
|
+
* @fires PromptStarters#pick
|
|
152
|
+
*/
|
|
153
|
+
_onClick(event) {
|
|
154
|
+
const button = /** @type {HTMLElement|null} */ (/** @type {Element|null} */ (event.target)?.closest?.('[data-starter]'));
|
|
155
|
+
if (!button) return;
|
|
156
|
+
const item = this._items.find((entry) => String(entry.id) === button.dataset.starter);
|
|
157
|
+
if (item) this.emit('pick', { item: { ...item } });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The starters as they are drawn: an entry without an `id`, a `title` or a `text` that says
|
|
163
|
+
* something is left out, a repeated id keeps its first entry, and `title`, `text` and `description`
|
|
164
|
+
* become strings. `text` keeps its spaces and line breaks, for a prompt that ends where the person
|
|
165
|
+
* goes on writing. Any other field the application put on an item is kept.
|
|
166
|
+
* @param {unknown} items
|
|
167
|
+
* @returns {PromptStarter[]}
|
|
168
|
+
*/
|
|
169
|
+
function normalizeStarters(items) {
|
|
170
|
+
/** @type {PromptStarter[]} */
|
|
171
|
+
const list = [];
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
for (const entry of Array.isArray(items) ? items : []) {
|
|
174
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
175
|
+
const { description, ...item } = /** @type {Partial<PromptStarter>} */ (entry);
|
|
176
|
+
const key = item.id == null ? '' : String(item.id);
|
|
177
|
+
const title = String(item.title ?? '').trim();
|
|
178
|
+
const text = String(item.text ?? '');
|
|
179
|
+
if (!key || !title || !text.trim() || seen.has(key)) continue;
|
|
180
|
+
seen.add(key);
|
|
181
|
+
const note = String(description ?? '').trim();
|
|
182
|
+
list.push({ ...item, id: /** @type {string|number} */ (item.id), title, text, ...(note ? { description: note } : {}) });
|
|
183
|
+
}
|
|
184
|
+
return list;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The columns an option names; anything but `1` or `2` is `'auto'`.
|
|
189
|
+
* @param {unknown} value
|
|
190
|
+
* @returns {string}
|
|
191
|
+
*/
|
|
192
|
+
function columnsOf(value) {
|
|
193
|
+
return value === 1 || value === 2 ? String(value) : 'auto';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The heading level an option names, or null for none.
|
|
198
|
+
* @param {unknown} value
|
|
199
|
+
* @returns {number|null}
|
|
200
|
+
*/
|
|
201
|
+
function headingLevel(value) {
|
|
202
|
+
const level = Number(value);
|
|
203
|
+
return value != null && Number.isInteger(level) && level >= 1 && level <= 6 ? level : null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Fired when a starter is picked. Nothing is sent: the application decides what a pick does. @event PromptStarters#pick @type {CustomEvent<{item: PromptStarter}>} */
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { h } from '../../core/dom.js';
|
|
2
2
|
import { copyToClipboard } from '../../core/export.js';
|
|
3
|
+
import { translate } from '../../core/i18n.js';
|
|
3
4
|
import { icon } from '../../core/icons.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {Object} ProseAnchorsOptions
|
|
7
8
|
* @property {string} [selector='h2[id], h3[id], h4[id]'] The headings that get a link, inside a
|
|
8
9
|
* `.zx-prose` under the root. A heading without an `id` has nothing to link to and is skipped.
|
|
9
|
-
* @property {string} [label
|
|
10
|
-
*
|
|
11
|
-
* @property {string} [
|
|
10
|
+
* @property {string|null} [label] The link's accessible name; `%1` is the heading. By default the
|
|
11
|
+
* `prose.copyLinkTo` message ("Copy link to %1"). Null gives none.
|
|
12
|
+
* @property {string|null} [title] The link's tooltip, by default the `prose.copyLink` message
|
|
13
|
+
* ("Copy link"). Null gives none.
|
|
14
|
+
* @property {string|null} [feedback] What the live region says after a copy, by default the
|
|
15
|
+
* `prose.copied` message ("Link copied"). Null says nothing.
|
|
12
16
|
* @property {number} [feedbackDuration=2000] Milliseconds the tick and the message stay.
|
|
13
17
|
* @property {(id: string) => string} [href] The address copied for a heading id. Defaults to the
|
|
14
18
|
* current address with its hash replaced (`sectionHref(location.href, id)`).
|
|
@@ -23,12 +27,9 @@ import { icon } from '../../core/icons.js';
|
|
|
23
27
|
* @property {() => void} destroy Removes every link, the live region, and the listener.
|
|
24
28
|
*/
|
|
25
29
|
|
|
26
|
-
/** @type {Readonly<Required<Omit<ProseAnchorsOptions, 'href'|'oncopy'>>>} */
|
|
30
|
+
/** @type {Readonly<Required<Omit<ProseAnchorsOptions, 'href'|'oncopy'|'label'|'title'|'feedback'>>>} */
|
|
27
31
|
const defaults = Object.freeze({
|
|
28
32
|
selector: 'h2[id], h3[id], h4[id]',
|
|
29
|
-
label: 'Copy link to %1',
|
|
30
|
-
title: 'Copy link',
|
|
31
|
-
feedback: 'Link copied',
|
|
32
33
|
feedbackDuration: 2000
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -65,6 +66,9 @@ export function proseAnchors(root, options = {}) {
|
|
|
65
66
|
const target = typeof root === 'string' ? document.querySelector(root) : root;
|
|
66
67
|
if (!(target instanceof Element)) throw new TypeError('proseAnchors root could not be resolved');
|
|
67
68
|
const settings = { ...defaults, ...options };
|
|
69
|
+
const {
|
|
70
|
+
label = translate('prose.copyLinkTo'), title = translate('prose.copyLink'), feedback = translate('prose.copied')
|
|
71
|
+
} = settings;
|
|
68
72
|
const abort = new AbortController();
|
|
69
73
|
/** @type {Map<HTMLAnchorElement, HTMLElement>} Link → its heading. */
|
|
70
74
|
const anchors = new Map();
|
|
@@ -95,8 +99,8 @@ export function proseAnchors(root, options = {}) {
|
|
|
95
99
|
const anchor = /** @type {HTMLAnchorElement} */ (h('a', {
|
|
96
100
|
class: 'zx-prose__anchor',
|
|
97
101
|
href: `#${heading.id}`,
|
|
98
|
-
ariaLabel: String(
|
|
99
|
-
title: String(
|
|
102
|
+
ariaLabel: String(label ?? '').replace('%1', text),
|
|
103
|
+
title: String(title ?? ''),
|
|
100
104
|
'data-zx-reveal': ''
|
|
101
105
|
}, icon('link-2')));
|
|
102
106
|
if (!heading.hasAttribute('data-zx-reveal-host')) {
|
|
@@ -126,7 +130,7 @@ export function proseAnchors(root, options = {}) {
|
|
|
126
130
|
anchor.dataset.copied = 'true';
|
|
127
131
|
anchor.replaceChildren(icon('check'));
|
|
128
132
|
if (!status.isConnected) target.append(status);
|
|
129
|
-
status.textContent = String(
|
|
133
|
+
status.textContent = String(feedback ?? '');
|
|
130
134
|
timer = setTimeout(() => {
|
|
131
135
|
delete anchor.dataset.copied;
|
|
132
136
|
anchor.replaceChildren(icon('link-2'));
|