@vobs/ui 0.3.0 → 1.1.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/LICENSE +1 -1
- package/README.md +60 -0
- package/package.json +52 -110
- package/src/activity-rail.ts +125 -0
- package/src/alert.ts +65 -0
- package/src/assets/icons/alert-circle.svg +1 -0
- package/src/assets/icons/alert-triangle.svg +1 -0
- package/src/assets/icons/alert.d27e24.svg +1 -0
- package/src/assets/icons/alert.svg +1 -0
- package/src/assets/icons/apple.svg +1 -0
- package/src/assets/icons/arrow-down.svg +1 -0
- package/src/assets/icons/arrow-expand.svg +1 -0
- package/src/assets/icons/arrow-left.svg +1 -0
- package/src/assets/icons/arrow-minimize.svg +1 -0
- package/src/assets/icons/arrow-right-to-line.svg +1 -0
- package/src/assets/icons/arrow-right.svg +1 -0
- package/src/assets/icons/arrow-up-right.svg +1 -0
- package/src/assets/icons/arrow-up.0c0c0d.svg +1 -0
- package/src/assets/icons/arrow-up.svg +1 -0
- package/src/assets/icons/at.svg +1 -0
- package/src/assets/icons/atom.0c0c0d.svg +1 -0
- package/src/assets/icons/atom.svg +1 -0
- package/src/assets/icons/bar.svg +1 -0
- package/src/assets/icons/bell.svg +1 -0
- package/src/assets/icons/box.svg +1 -0
- package/src/assets/icons/bug.svg +1 -0
- package/src/assets/icons/calendar.svg +1 -0
- package/src/assets/icons/check-circle.33c192.svg +1 -0
- package/src/assets/icons/check-circle.svg +1 -0
- package/src/assets/icons/check.d1d3db.svg +1 -0
- package/src/assets/icons/check.svg +1 -0
- package/src/assets/icons/chevron-down.svg +1 -0
- package/src/assets/icons/chevron-right.svg +1 -0
- package/src/assets/icons/chevron-up.svg +1 -0
- package/src/assets/icons/circle.svg +1 -0
- package/src/assets/icons/clock.svg +1 -0
- package/src/assets/icons/cmd.svg +1 -0
- package/src/assets/icons/code.svg +1 -0
- package/src/assets/icons/columns.svg +1 -0
- package/src/assets/icons/copy.svg +1 -0
- package/src/assets/icons/cpu.svg +1 -0
- package/src/assets/icons/dashboard.0c0c0d.svg +1 -0
- package/src/assets/icons/dashboard.svg +1 -0
- package/src/assets/icons/dollar.svg +1 -0
- package/src/assets/icons/download.svg +1 -0
- package/src/assets/icons/edit.svg +1 -0
- package/src/assets/icons/extensions.svg +1 -0
- package/src/assets/icons/external.svg +1 -0
- package/src/assets/icons/eye.svg +1 -0
- package/src/assets/icons/file-text.svg +1 -0
- package/src/assets/icons/file.svg +1 -0
- package/src/assets/icons/files.svg +1 -0
- package/src/assets/icons/filter.svg +1 -0
- package/src/assets/icons/folder.svg +1 -0
- package/src/assets/icons/gear.svg +1 -0
- package/src/assets/icons/git.svg +1 -0
- package/src/assets/icons/github.svg +1 -0
- package/src/assets/icons/globe.svg +1 -0
- package/src/assets/icons/grid-2x2.svg +1 -0
- package/src/assets/icons/hash.svg +1 -0
- package/src/assets/icons/heart.svg +1 -0
- package/src/assets/icons/help.svg +1 -0
- package/src/assets/icons/home.svg +1 -0
- package/src/assets/icons/image.svg +1 -0
- package/src/assets/icons/info-circle.svg +1 -0
- package/src/assets/icons/info-square.svg +1 -0
- package/src/assets/icons/info.387bff.svg +1 -0
- package/src/assets/icons/info.svg +1 -0
- package/src/assets/icons/key.svg +1 -0
- package/src/assets/icons/layers.svg +1 -0
- package/src/assets/icons/layout.svg +1 -0
- package/src/assets/icons/link.svg +1 -0
- package/src/assets/icons/list.svg +1 -0
- package/src/assets/icons/lock.svg +1 -0
- package/src/assets/icons/log-out.svg +1 -0
- package/src/assets/icons/logo.svg +1 -0
- package/src/assets/icons/mail.svg +1 -0
- package/src/assets/icons/menu.svg +1 -0
- package/src/assets/icons/message-circle.svg +1 -0
- package/src/assets/icons/message-plus.svg +1 -0
- package/src/assets/icons/message-square.svg +1 -0
- package/src/assets/icons/mic.svg +1 -0
- package/src/assets/icons/minus.svg +1 -0
- package/src/assets/icons/moon.svg +1 -0
- package/src/assets/icons/more-h.svg +1 -0
- package/src/assets/icons/mouse.svg +1 -0
- package/src/assets/icons/palette.svg +1 -0
- package/src/assets/icons/panel-bottom.svg +1 -0
- package/src/assets/icons/pause.svg +1 -0
- package/src/assets/icons/play.svg +1 -0
- package/src/assets/icons/plug.svg +1 -0
- package/src/assets/icons/plus.0c0c0d.svg +1 -0
- package/src/assets/icons/plus.svg +1 -0
- package/src/assets/icons/refresh.svg +1 -0
- package/src/assets/icons/ruler.svg +1 -0
- package/src/assets/icons/scroll-text.svg +1 -0
- package/src/assets/icons/search-menu.svg +1 -0
- package/src/assets/icons/search.svg +1 -0
- package/src/assets/icons/send.0c0c0d.svg +1 -0
- package/src/assets/icons/send.svg +1 -0
- package/src/assets/icons/settings.0c0c0d.svg +1 -0
- package/src/assets/icons/settings.svg +1 -0
- package/src/assets/icons/shield.svg +1 -0
- package/src/assets/icons/sidebar-left.svg +1 -0
- package/src/assets/icons/sidebar-right.svg +1 -0
- package/src/assets/icons/sliders.svg +1 -0
- package/src/assets/icons/sparkles.32f08c.svg +1 -0
- package/src/assets/icons/sparkles.svg +1 -0
- package/src/assets/icons/square.svg +1 -0
- package/src/assets/icons/star.svg +1 -0
- package/src/assets/icons/sun.svg +1 -0
- package/src/assets/icons/terminal.svg +1 -0
- package/src/assets/icons/trash.svg +1 -0
- package/src/assets/icons/trending-down.svg +1 -0
- package/src/assets/icons/trending-up.svg +1 -0
- package/src/assets/icons/type.svg +1 -0
- package/src/assets/icons/upload.svg +1 -0
- package/src/assets/icons/user-circle.svg +1 -0
- package/src/assets/icons/user.svg +1 -0
- package/src/assets/icons/users.svg +1 -0
- package/src/assets/icons/wrench.svg +1 -0
- package/src/assets/icons/x-circle.svg +1 -0
- package/src/assets/icons/x.svg +1 -0
- package/src/assets/icons/zap.0c0c0d.svg +1 -0
- package/src/assets/icons/zap.svg +1 -0
- package/src/avatar.ts +64 -0
- package/src/button.ts +88 -0
- package/src/card.ts +59 -0
- package/src/chat-composer.ts +156 -0
- package/src/dialog.ts +127 -0
- package/src/drawer.ts +131 -0
- package/src/editor-tabs.ts +184 -0
- package/src/file-tree.ts +214 -0
- package/src/forms.ts +270 -0
- package/src/icon.ts +118 -0
- package/src/icons.js +165 -0
- package/src/index.test.ts +213 -0
- package/src/index.ts +94 -0
- package/src/kbd.ts +72 -0
- package/src/menu.ts +119 -0
- package/src/nav-list.ts +157 -0
- package/src/overlay.test.ts +66 -0
- package/src/overlay.ts +205 -0
- package/src/page-header.ts +97 -0
- package/src/pagination.ts +163 -0
- package/src/second-batch.test.ts +205 -0
- package/src/stat-card.ts +92 -0
- package/src/status-bar.ts +108 -0
- package/src/styles/base.css +240 -0
- package/src/styles/components.css +1234 -0
- package/{dist → src/styles}/styles.css +2 -0
- package/src/styles/toast.css +57 -0
- package/src/styles/tokens.css +438 -0
- package/src/styles/vui.css +47 -0
- package/src/table.ts +191 -0
- package/src/tabs.ts +100 -0
- package/src/tag.ts +33 -0
- package/src/third-batch.test.ts +137 -0
- package/src/toast.test.ts +55 -0
- package/src/toast.ts +79 -0
- package/src/types.ts +25 -0
- package/src/utils.ts +221 -0
- package/src/workbench-titlebar.ts +137 -0
- package/dist/app-shell-dom.d.ts +0 -30
- package/dist/app-shell-dom.js +0 -913
- package/dist/app-shell.d.ts +0 -235
- package/dist/app-shell.js +0 -415
- package/dist/base.css +0 -51
- package/dist/calendar-picker.d.ts +0 -45
- package/dist/calendar-picker.js +0 -217
- package/dist/calendar.d.ts +0 -95
- package/dist/calendar.js +0 -194
- package/dist/complex-inputs.d.ts +0 -300
- package/dist/complex-inputs.js +0 -866
- package/dist/components.css +0 -4756
- package/dist/data-display.d.ts +0 -1094
- package/dist/data-display.js +0 -2341
- package/dist/dialog.d.ts +0 -26
- package/dist/dialog.js +0 -94
- package/dist/feedback.d.ts +0 -88
- package/dist/feedback.js +0 -281
- package/dist/forms.d.ts +0 -378
- package/dist/forms.js +0 -1019
- package/dist/icons-config.d.ts +0 -25
- package/dist/icons-config.js +0 -14
- package/dist/icons.d.ts +0 -41
- package/dist/icons.js +0 -185
- package/dist/index.d.ts +0 -31
- package/dist/index.js +0 -40
- package/dist/locale/en-US.d.ts +0 -31
- package/dist/locale/en-US.js +0 -20
- package/dist/locale/zh-CN.d.ts +0 -31
- package/dist/locale/zh-CN.js +0 -20
- package/dist/navigation.d.ts +0 -609
- package/dist/navigation.js +0 -1707
- package/dist/overlay.d.ts +0 -308
- package/dist/overlay.js +0 -974
- package/dist/page-state.d.ts +0 -23
- package/dist/page-state.js +0 -96
- package/dist/primitives.d.ts +0 -268
- package/dist/primitives.js +0 -764
- package/dist/theme-data.d.ts +0 -394
- package/dist/theme-data.js +0 -417
- package/dist/theme.d.ts +0 -97
- package/dist/theme.js +0 -301
- package/dist/tokens.css +0 -570
- package/dist/tree.d.ts +0 -144
- package/dist/tree.js +0 -475
- package/dist/virtual-list.d.ts +0 -190
- package/dist/virtual-list.js +0 -538
- package/dist/workbench.d.ts +0 -136
- package/dist/workbench.js +0 -156
package/dist/data-display.js
DELETED
|
@@ -1,2341 +0,0 @@
|
|
|
1
|
-
/** @license MIT
|
|
2
|
-
* Copyright (c) 2026 vobsjs
|
|
3
|
-
* @vobs/ui
|
|
4
|
-
*/
|
|
5
|
-
import { classNames, createButtonPrimitive, createSkeletonPrimitive, createSpinPrimitive, createUiDomPlan, } from './primitives.js';
|
|
6
|
-
export function createTablePlans(options) {
|
|
7
|
-
const columns = options.columns.filter((column) => column.hidden !== true);
|
|
8
|
-
const sortColumn = columns.find((column) => column.sortDirection !== undefined);
|
|
9
|
-
return {
|
|
10
|
-
root: createUiDomPlan('table', 'table', {
|
|
11
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
12
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
13
|
-
attrs: {
|
|
14
|
-
id: options.id,
|
|
15
|
-
'aria-labelledby': options.captionId,
|
|
16
|
-
...options.attrs,
|
|
17
|
-
'data-columns': columns.length,
|
|
18
|
-
'data-rows': options.rows.length,
|
|
19
|
-
'data-selectable': options.selectable === true ? 'true' : undefined,
|
|
20
|
-
'data-sticky-header': options.stickyHeader === true ? 'true' : undefined,
|
|
21
|
-
'data-sort-column': sortColumn?.id,
|
|
22
|
-
'data-sort-direction': sortColumn?.sortDirection,
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
caption: options.captionId === undefined
|
|
26
|
-
? undefined
|
|
27
|
-
: createUiDomPlan('caption', 'table-caption', { attrs: { id: options.captionId } }),
|
|
28
|
-
selectionHeader: options.selectable === true
|
|
29
|
-
? createUiDomPlan('th', 'table-selection-header', {
|
|
30
|
-
attrs: {
|
|
31
|
-
scope: 'col',
|
|
32
|
-
'aria-label': 'Select rows',
|
|
33
|
-
'data-sticky': 'start',
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
: undefined,
|
|
37
|
-
headers: columns.map((column) => createUiDomPlan('th', 'table-header', {
|
|
38
|
-
attrs: {
|
|
39
|
-
scope: 'col',
|
|
40
|
-
role: column.sortable === true ? 'columnheader' : undefined,
|
|
41
|
-
'aria-sort': ariaSort(column),
|
|
42
|
-
'data-column-id': column.id,
|
|
43
|
-
'data-align': column.align,
|
|
44
|
-
'data-sortable': column.sortable === true ? 'true' : undefined,
|
|
45
|
-
'data-sort-direction': column.sortDirection,
|
|
46
|
-
'data-sticky': column.sticky,
|
|
47
|
-
style: tableColumnStyle(column),
|
|
48
|
-
},
|
|
49
|
-
})),
|
|
50
|
-
rows: options.rows.map((row) => createUiDomPlan('tr', 'table-row', {
|
|
51
|
-
state: row.selected === true ? 'selected' : row.disabled === true ? 'disabled' : 'idle',
|
|
52
|
-
attrs: {
|
|
53
|
-
'data-row-id': row.id,
|
|
54
|
-
'aria-selected': row.selected === true ? 'true' : undefined,
|
|
55
|
-
'aria-checked': row.checked === true ? 'true' : undefined,
|
|
56
|
-
'aria-disabled': row.disabled === true ? 'true' : undefined,
|
|
57
|
-
'aria-expanded': row.expanded === undefined ? undefined : row.expanded ? 'true' : 'false',
|
|
58
|
-
},
|
|
59
|
-
})),
|
|
60
|
-
selectionCells: options.selectable === true
|
|
61
|
-
? options.rows.map((row) => createUiDomPlan('td', 'table-selection-cell', {
|
|
62
|
-
attrs: {
|
|
63
|
-
'data-row-id': row.id,
|
|
64
|
-
'data-sticky': 'start',
|
|
65
|
-
'data-checked': row.checked === true ? 'true' : 'false',
|
|
66
|
-
},
|
|
67
|
-
}))
|
|
68
|
-
: [],
|
|
69
|
-
cells: options.rows.flatMap((row) => columns.map((column) => createUiDomPlan('td', 'table-cell', {
|
|
70
|
-
attrs: {
|
|
71
|
-
'data-row-id': row.id,
|
|
72
|
-
'data-column-id': column.id,
|
|
73
|
-
'data-align': column.align,
|
|
74
|
-
'data-sticky': column.sticky,
|
|
75
|
-
style: tableColumnStyle(column),
|
|
76
|
-
},
|
|
77
|
-
}))),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export function getNextTableSortDirection(current, cycle = 'tri-state') {
|
|
81
|
-
if (current === undefined || current === 'none')
|
|
82
|
-
return 'ascending';
|
|
83
|
-
if (current === 'ascending')
|
|
84
|
-
return 'descending';
|
|
85
|
-
return cycle === 'binary' ? 'ascending' : 'none';
|
|
86
|
-
}
|
|
87
|
-
export function toggleTableRowSelection(selectedIds, rowId, multiselect = true) {
|
|
88
|
-
if (selectedIds.has(rowId)) {
|
|
89
|
-
const next = new Set(selectedIds);
|
|
90
|
-
next.delete(rowId);
|
|
91
|
-
return next;
|
|
92
|
-
}
|
|
93
|
-
if (!multiselect)
|
|
94
|
-
return new Set([rowId]);
|
|
95
|
-
return new Set([...selectedIds, rowId]);
|
|
96
|
-
}
|
|
97
|
-
export function createTableToolbarStateContract(options = {}) {
|
|
98
|
-
const mode = options.mode ?? 'local';
|
|
99
|
-
const query = (options.query ?? '').trim();
|
|
100
|
-
const activeFilterIds = (options.filters ?? [])
|
|
101
|
-
.filter((filter) => filter.active === true)
|
|
102
|
-
.map((filter) => filter.id);
|
|
103
|
-
const selectedIds = normalizeSelectedIds(options.selectedIds);
|
|
104
|
-
const selectedCount = selectedIds.length;
|
|
105
|
-
const totalCount = normalizeCount(options.totalCount);
|
|
106
|
-
const filteredCount = normalizeCount(options.filteredCount);
|
|
107
|
-
const sortColumnId = options.sortColumnId ?? '';
|
|
108
|
-
const sortDirection = options.sortDirection ?? 'none';
|
|
109
|
-
const summary = formatDataToolbarSummary({
|
|
110
|
-
...(totalCount === undefined ? {} : { totalCount }),
|
|
111
|
-
...(filteredCount === undefined ? {} : { filteredCount }),
|
|
112
|
-
selectedCount,
|
|
113
|
-
});
|
|
114
|
-
const state = tableToolbarState({
|
|
115
|
-
activeFilterCount: activeFilterIds.length,
|
|
116
|
-
filteredCount,
|
|
117
|
-
loading: options.loading === true,
|
|
118
|
-
query,
|
|
119
|
-
selectedCount,
|
|
120
|
-
sortDirection,
|
|
121
|
-
totalCount,
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
mode,
|
|
125
|
-
state,
|
|
126
|
-
query,
|
|
127
|
-
activeFilterIds,
|
|
128
|
-
activeFilterCount: activeFilterIds.length,
|
|
129
|
-
sortColumnId,
|
|
130
|
-
sortDirection,
|
|
131
|
-
selectedIds,
|
|
132
|
-
selectedCount,
|
|
133
|
-
totalCount,
|
|
134
|
-
filteredCount,
|
|
135
|
-
summary,
|
|
136
|
-
attrs: {
|
|
137
|
-
'data-source': mode,
|
|
138
|
-
'data-state': state,
|
|
139
|
-
'data-query': query,
|
|
140
|
-
'data-active-filter-ids': activeFilterIds.join(','),
|
|
141
|
-
'data-active-filter-count': activeFilterIds.length,
|
|
142
|
-
'data-sort-column': sortColumnId,
|
|
143
|
-
'data-sort-direction': sortDirection,
|
|
144
|
-
'data-selected-ids': selectedIds.join(','),
|
|
145
|
-
'data-selected-count': selectedCount,
|
|
146
|
-
'data-total-count': totalCount,
|
|
147
|
-
'data-filtered-count': filteredCount,
|
|
148
|
-
'data-summary': summary,
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
export function createTableColumnPreferenceStateContract(options) {
|
|
153
|
-
const knownIds = new Set(options.columns.map((column) => column.id));
|
|
154
|
-
const density = options.density ?? options.defaultDensity ?? 'comfortable';
|
|
155
|
-
const orderedIds = normalizeColumnPreferenceIds(options.orderIds, knownIds);
|
|
156
|
-
const visibleSet = options.visibleIds === undefined
|
|
157
|
-
? undefined
|
|
158
|
-
: new Set(normalizeColumnPreferenceIds(options.visibleIds, knownIds));
|
|
159
|
-
const hiddenSet = new Set(normalizeColumnPreferenceIds(options.hiddenIds, knownIds));
|
|
160
|
-
const stickyStartSet = options.stickyStartIds === undefined
|
|
161
|
-
? undefined
|
|
162
|
-
: new Set(normalizeColumnPreferenceIds(options.stickyStartIds, knownIds));
|
|
163
|
-
const stickyEndSet = options.stickyEndIds === undefined
|
|
164
|
-
? undefined
|
|
165
|
-
: new Set(normalizeColumnPreferenceIds(options.stickyEndIds, knownIds));
|
|
166
|
-
const orderedColumns = orderTableColumns(options.columns, orderedIds);
|
|
167
|
-
const columns = orderedColumns.map((column) => {
|
|
168
|
-
const visible = (visibleSet === undefined || visibleSet.has(column.id)) && !hiddenSet.has(column.id);
|
|
169
|
-
const sticky = tableColumnPreferenceSticky(column, stickyStartSet, stickyEndSet);
|
|
170
|
-
const { hidden: _hidden, sticky: _sticky, ...baseColumn } = column;
|
|
171
|
-
void _hidden;
|
|
172
|
-
void _sticky;
|
|
173
|
-
return sticky === undefined
|
|
174
|
-
? { ...baseColumn, hidden: !visible }
|
|
175
|
-
: { ...baseColumn, hidden: !visible, sticky };
|
|
176
|
-
});
|
|
177
|
-
const columnContracts = columns.map((column, index) => {
|
|
178
|
-
const visible = column.hidden !== true;
|
|
179
|
-
return {
|
|
180
|
-
id: column.id,
|
|
181
|
-
label: column.label ?? column.id,
|
|
182
|
-
visible,
|
|
183
|
-
order: index,
|
|
184
|
-
sticky: column.sticky,
|
|
185
|
-
attrs: {
|
|
186
|
-
'data-column-id': column.id,
|
|
187
|
-
'data-column-order': index,
|
|
188
|
-
'data-visible': visible ? 'true' : 'false',
|
|
189
|
-
'data-hidden': visible ? undefined : 'true',
|
|
190
|
-
'data-sticky': column.sticky,
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
const visibleIds = columnContracts.filter((column) => column.visible).map((column) => column.id);
|
|
195
|
-
const hiddenIds = columnContracts.filter((column) => !column.visible).map((column) => column.id);
|
|
196
|
-
const stickyStartIds = columnContracts
|
|
197
|
-
.filter((column) => column.sticky === 'start' && column.visible)
|
|
198
|
-
.map((column) => column.id);
|
|
199
|
-
const stickyEndIds = columnContracts
|
|
200
|
-
.filter((column) => column.sticky === 'end' && column.visible)
|
|
201
|
-
.map((column) => column.id);
|
|
202
|
-
const state = tableColumnPreferenceState({
|
|
203
|
-
columns,
|
|
204
|
-
density,
|
|
205
|
-
defaultDensity: options.defaultDensity,
|
|
206
|
-
hiddenIds,
|
|
207
|
-
orderIds: orderedIds,
|
|
208
|
-
sourceColumns: options.columns,
|
|
209
|
-
stickyEndIds: options.stickyEndIds,
|
|
210
|
-
stickyStartIds: options.stickyStartIds,
|
|
211
|
-
visibleIds: options.visibleIds,
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
state,
|
|
215
|
-
density,
|
|
216
|
-
columnCount: options.columns.length,
|
|
217
|
-
visibleCount: visibleIds.length,
|
|
218
|
-
hiddenCount: hiddenIds.length,
|
|
219
|
-
orderedIds: columns.map((column) => column.id),
|
|
220
|
-
visibleIds,
|
|
221
|
-
hiddenIds,
|
|
222
|
-
stickyStartIds,
|
|
223
|
-
stickyEndIds,
|
|
224
|
-
columns,
|
|
225
|
-
columnContracts,
|
|
226
|
-
attrs: {
|
|
227
|
-
'data-table-column-preference-contract': 'true',
|
|
228
|
-
'data-state': state,
|
|
229
|
-
'data-density': density,
|
|
230
|
-
'data-column-count': options.columns.length,
|
|
231
|
-
'data-visible-column-count': visibleIds.length,
|
|
232
|
-
'data-hidden-column-count': hiddenIds.length,
|
|
233
|
-
'data-column-order': columns.map((column) => column.id).join(','),
|
|
234
|
-
'data-visible-column-ids': visibleIds.join(','),
|
|
235
|
-
'data-hidden-column-ids': hiddenIds.join(','),
|
|
236
|
-
'data-sticky-start-ids': stickyStartIds.join(','),
|
|
237
|
-
'data-sticky-end-ids': stickyEndIds.join(','),
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
export function createTableCellStateContract(options) {
|
|
242
|
-
const kind = options.kind ?? 'text';
|
|
243
|
-
const intent = options.intent ?? '';
|
|
244
|
-
const state = tableCellState(options);
|
|
245
|
-
return {
|
|
246
|
-
rowId: options.rowId,
|
|
247
|
-
columnId: options.columnId,
|
|
248
|
-
kind,
|
|
249
|
-
state,
|
|
250
|
-
intent,
|
|
251
|
-
attrs: {
|
|
252
|
-
'data-table-cell-contract': 'true',
|
|
253
|
-
'data-row-id': options.rowId,
|
|
254
|
-
'data-column-id': options.columnId,
|
|
255
|
-
'data-cell-kind': kind,
|
|
256
|
-
'data-cell-state': state,
|
|
257
|
-
'data-cell-intent': intent,
|
|
258
|
-
'data-value': options.value,
|
|
259
|
-
'data-tone': options.tone,
|
|
260
|
-
'data-interactive': options.interactive === true ? 'true' : undefined,
|
|
261
|
-
'data-truncate': options.truncate === true ? 'true' : undefined,
|
|
262
|
-
'aria-label': options.label,
|
|
263
|
-
'aria-describedby': options.describedBy,
|
|
264
|
-
'aria-disabled': options.disabled === true ? 'true' : undefined,
|
|
265
|
-
'aria-busy': options.loading === true ? 'true' : undefined,
|
|
266
|
-
...options.attrs,
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
export function createTableBatchActionStateContract(options = {}) {
|
|
271
|
-
const selectedIds = normalizeSelectedIds(options.selectedIds);
|
|
272
|
-
const selectedCount = selectedIds.length;
|
|
273
|
-
const totalCount = normalizeCount(options.totalCount);
|
|
274
|
-
const eligibleCount = normalizeCount(options.eligibleCount) ?? totalCount;
|
|
275
|
-
const selectionState = tableSelectionSummaryState(selectedCount, eligibleCount);
|
|
276
|
-
const selectionSummary = formatTableSelectionSummary({
|
|
277
|
-
eligibleCount,
|
|
278
|
-
selectedCount,
|
|
279
|
-
totalCount,
|
|
280
|
-
});
|
|
281
|
-
const actionContracts = (options.actions ?? []).map((action) => tableBatchActionContract(action, selectedCount));
|
|
282
|
-
const availableActionIds = actionContracts
|
|
283
|
-
.filter((action) => action.state === 'available')
|
|
284
|
-
.map((action) => action.id);
|
|
285
|
-
const disabledActionIds = actionContracts
|
|
286
|
-
.filter((action) => action.state === 'disabled')
|
|
287
|
-
.map((action) => action.id);
|
|
288
|
-
const pendingActionIds = actionContracts
|
|
289
|
-
.filter((action) => action.state === 'pending')
|
|
290
|
-
.map((action) => action.id);
|
|
291
|
-
const hiddenActionIds = actionContracts
|
|
292
|
-
.filter((action) => action.state === 'hidden')
|
|
293
|
-
.map((action) => action.id);
|
|
294
|
-
return {
|
|
295
|
-
selectionState,
|
|
296
|
-
selectedIds,
|
|
297
|
-
selectedCount,
|
|
298
|
-
totalCount,
|
|
299
|
-
eligibleCount,
|
|
300
|
-
selectionSummary,
|
|
301
|
-
actionContracts,
|
|
302
|
-
availableActionIds,
|
|
303
|
-
disabledActionIds,
|
|
304
|
-
pendingActionIds,
|
|
305
|
-
hiddenActionIds,
|
|
306
|
-
attrs: {
|
|
307
|
-
'data-table-batch-action-contract': 'true',
|
|
308
|
-
'data-selection-state': selectionState,
|
|
309
|
-
'data-selected-ids': selectedIds.join(','),
|
|
310
|
-
'data-selected-count': selectedCount,
|
|
311
|
-
'data-total-count': totalCount,
|
|
312
|
-
'data-eligible-count': eligibleCount,
|
|
313
|
-
'data-selection-summary': selectionSummary,
|
|
314
|
-
'data-action-count': actionContracts.length,
|
|
315
|
-
'data-available-action-ids': availableActionIds.join(','),
|
|
316
|
-
'data-disabled-action-ids': disabledActionIds.join(','),
|
|
317
|
-
'data-pending-action-ids': pendingActionIds.join(','),
|
|
318
|
-
'data-hidden-action-ids': hiddenActionIds.join(','),
|
|
319
|
-
},
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
export function createFilterBarPlans(options) {
|
|
323
|
-
const activeCount = options.filters.filter((filter) => filter.active === true).length;
|
|
324
|
-
return {
|
|
325
|
-
root: createUiDomPlan('div', 'filter-bar', {
|
|
326
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
327
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
328
|
-
state: activeCount === 0 ? 'empty' : 'filtered',
|
|
329
|
-
attrs: {
|
|
330
|
-
id: options.id,
|
|
331
|
-
role: 'list',
|
|
332
|
-
'aria-label': options.label ?? 'Filters',
|
|
333
|
-
...options.attrs,
|
|
334
|
-
'data-filter-count': options.filters.length,
|
|
335
|
-
'data-active-filter-count': activeCount,
|
|
336
|
-
},
|
|
337
|
-
}),
|
|
338
|
-
chips: options.filters.map((filter) => createUiDomPlan('button', 'filter-chip', {
|
|
339
|
-
...(filter.disabled === undefined ? {} : { disabled: filter.disabled }),
|
|
340
|
-
state: filter.disabled === true ? 'disabled' : filter.active === true ? 'active' : 'idle',
|
|
341
|
-
attrs: {
|
|
342
|
-
type: 'button',
|
|
343
|
-
role: 'listitem',
|
|
344
|
-
'aria-pressed': filter.active === true ? 'true' : 'false',
|
|
345
|
-
'aria-label': filterChipLabel(filter),
|
|
346
|
-
'data-filter-id': filter.id,
|
|
347
|
-
'data-tone': filter.tone ?? 'neutral',
|
|
348
|
-
'data-removable': filter.removable === true ? 'true' : undefined,
|
|
349
|
-
'data-label': filter.label,
|
|
350
|
-
'data-value': filter.value,
|
|
351
|
-
},
|
|
352
|
-
})),
|
|
353
|
-
clear: activeCount === 0
|
|
354
|
-
? undefined
|
|
355
|
-
: createUiDomPlan('button', 'filter-clear', {
|
|
356
|
-
attrs: {
|
|
357
|
-
type: 'button',
|
|
358
|
-
'aria-label': options.clearLabel ?? 'Clear filters',
|
|
359
|
-
'data-count': activeCount,
|
|
360
|
-
},
|
|
361
|
-
}),
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
export function createDataToolbarPlans(options = {}) {
|
|
365
|
-
const filters = options.filters ?? [];
|
|
366
|
-
const filterBar = createFilterBarPlans({
|
|
367
|
-
filters,
|
|
368
|
-
label: 'Active filters',
|
|
369
|
-
...(options.id === undefined ? {} : { id: `${options.id}-filters` }),
|
|
370
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
371
|
-
});
|
|
372
|
-
return {
|
|
373
|
-
root: createUiDomPlan('div', 'data-toolbar', {
|
|
374
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
375
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
376
|
-
state: filters.some((filter) => filter.active === true) ? 'filtered' : 'idle',
|
|
377
|
-
attrs: {
|
|
378
|
-
id: options.id,
|
|
379
|
-
role: 'toolbar',
|
|
380
|
-
...options.attrs,
|
|
381
|
-
'data-action-count': options.actions?.length ?? 0,
|
|
382
|
-
'data-filter-count': filters.length,
|
|
383
|
-
'data-selected-count': options.selectedCount,
|
|
384
|
-
},
|
|
385
|
-
}),
|
|
386
|
-
search: options.searchValue === undefined && options.searchPlaceholder === undefined
|
|
387
|
-
? undefined
|
|
388
|
-
: createUiDomPlan('input', 'data-toolbar-search', {
|
|
389
|
-
attrs: {
|
|
390
|
-
type: 'search',
|
|
391
|
-
role: 'searchbox',
|
|
392
|
-
value: options.searchValue,
|
|
393
|
-
placeholder: options.searchPlaceholder,
|
|
394
|
-
'aria-label': options.searchLabel ?? 'Search data',
|
|
395
|
-
},
|
|
396
|
-
}),
|
|
397
|
-
filterBar,
|
|
398
|
-
summary: createUiDomPlan('output', 'data-toolbar-summary', {
|
|
399
|
-
attrs: {
|
|
400
|
-
'aria-live': 'polite',
|
|
401
|
-
'data-summary': formatDataToolbarSummary(options),
|
|
402
|
-
},
|
|
403
|
-
}),
|
|
404
|
-
actions: (options.actions ?? []).map((action) => createUiDomPlan('button', 'data-toolbar-action', {
|
|
405
|
-
...(action.disabled === undefined ? {} : { disabled: action.disabled }),
|
|
406
|
-
state: action.disabled === true ? 'disabled' : action.pressed === true ? 'pressed' : 'idle',
|
|
407
|
-
attrs: {
|
|
408
|
-
type: 'button',
|
|
409
|
-
'aria-label': action.label,
|
|
410
|
-
'aria-pressed': action.pressed === undefined ? undefined : action.pressed ? 'true' : 'false',
|
|
411
|
-
'data-action-id': action.id,
|
|
412
|
-
'data-tone': action.tone ?? 'secondary',
|
|
413
|
-
'data-label': action.label,
|
|
414
|
-
},
|
|
415
|
-
})),
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
export function formatDataToolbarSummary(options) {
|
|
419
|
-
const total = normalizeCount(options.totalCount);
|
|
420
|
-
const filtered = normalizeCount(options.filteredCount);
|
|
421
|
-
const selected = normalizeCount(options.selectedCount);
|
|
422
|
-
const visible = filtered ?? total;
|
|
423
|
-
const parts = [];
|
|
424
|
-
if (visible !== undefined &&
|
|
425
|
-
total !== undefined &&
|
|
426
|
-
filtered !== undefined &&
|
|
427
|
-
filtered !== total) {
|
|
428
|
-
parts.push(`${visible} of ${total}`);
|
|
429
|
-
}
|
|
430
|
-
else if (visible !== undefined) {
|
|
431
|
-
parts.push(`${visible} rows`);
|
|
432
|
-
}
|
|
433
|
-
if (selected !== undefined && selected > 0)
|
|
434
|
-
parts.push(`${selected} selected`);
|
|
435
|
-
return parts.length === 0 ? 'No summary' : parts.join(' · ');
|
|
436
|
-
}
|
|
437
|
-
export function createEmptyPlan(options = {}) {
|
|
438
|
-
const status = options.status ?? 'empty';
|
|
439
|
-
return createUiDomPlan('div', 'empty', {
|
|
440
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
441
|
-
state: status,
|
|
442
|
-
attrs: {
|
|
443
|
-
id: options.id,
|
|
444
|
-
role: 'status',
|
|
445
|
-
'aria-label': options.label ?? 'No data',
|
|
446
|
-
'aria-labelledby': options.titleId,
|
|
447
|
-
'aria-describedby': options.descriptionId,
|
|
448
|
-
...options.attrs,
|
|
449
|
-
'data-status': status,
|
|
450
|
-
'data-icon-ready': options.icon === false ? 'false' : 'true',
|
|
451
|
-
'data-actionable': options.action === undefined ? undefined : '',
|
|
452
|
-
},
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
export function createEmptyPlans(options = {}) {
|
|
456
|
-
return {
|
|
457
|
-
root: createEmptyPlan(options),
|
|
458
|
-
...(options.icon === false
|
|
459
|
-
? {}
|
|
460
|
-
: {
|
|
461
|
-
icon: createUiDomPlan('span', 'empty-icon', {
|
|
462
|
-
attrs: { 'aria-hidden': 'true', 'data-status': options.status ?? 'empty' },
|
|
463
|
-
}),
|
|
464
|
-
}),
|
|
465
|
-
...(options.titleId === undefined
|
|
466
|
-
? {}
|
|
467
|
-
: {
|
|
468
|
-
title: createUiDomPlan('strong', 'empty-title', {
|
|
469
|
-
attrs: { id: options.titleId },
|
|
470
|
-
}),
|
|
471
|
-
}),
|
|
472
|
-
...(options.descriptionId === undefined
|
|
473
|
-
? {}
|
|
474
|
-
: {
|
|
475
|
-
description: createUiDomPlan('p', 'empty-description', {
|
|
476
|
-
attrs: { id: options.descriptionId },
|
|
477
|
-
}),
|
|
478
|
-
}),
|
|
479
|
-
...(options.action === undefined
|
|
480
|
-
? {}
|
|
481
|
-
: { actionButton: createDataDisplayActionButton('empty', options.action) }),
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
export function createResultPlans(options = {}) {
|
|
485
|
-
const status = options.status ?? 'info';
|
|
486
|
-
return {
|
|
487
|
-
root: createUiDomPlan('section', 'result', {
|
|
488
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
489
|
-
state: status,
|
|
490
|
-
attrs: {
|
|
491
|
-
id: options.id,
|
|
492
|
-
role: status === 'error' || status === 'warning' ? 'alert' : 'status',
|
|
493
|
-
'aria-labelledby': options.titleId,
|
|
494
|
-
'aria-describedby': options.descriptionId,
|
|
495
|
-
...options.attrs,
|
|
496
|
-
'data-status': status,
|
|
497
|
-
'data-icon-ready': options.icon === false ? 'false' : 'true',
|
|
498
|
-
'data-actionable': options.action === undefined ? undefined : '',
|
|
499
|
-
'data-dismissible': options.closeLabel === undefined ? undefined : '',
|
|
500
|
-
},
|
|
501
|
-
}),
|
|
502
|
-
...(options.icon === false
|
|
503
|
-
? {}
|
|
504
|
-
: {
|
|
505
|
-
icon: createUiDomPlan('span', 'result-icon', {
|
|
506
|
-
attrs: { 'aria-hidden': 'true', 'data-status': status },
|
|
507
|
-
}),
|
|
508
|
-
}),
|
|
509
|
-
...(options.titleId === undefined
|
|
510
|
-
? {}
|
|
511
|
-
: { title: createUiDomPlan('h3', 'result-title', { attrs: { id: options.titleId } }) }),
|
|
512
|
-
...(options.descriptionId === undefined
|
|
513
|
-
? {}
|
|
514
|
-
: {
|
|
515
|
-
description: createUiDomPlan('p', 'result-description', {
|
|
516
|
-
attrs: { id: options.descriptionId },
|
|
517
|
-
}),
|
|
518
|
-
}),
|
|
519
|
-
...(options.action === undefined
|
|
520
|
-
? {}
|
|
521
|
-
: { actionButton: createDataDisplayActionButton('result', options.action) }),
|
|
522
|
-
...(options.closeLabel === undefined
|
|
523
|
-
? {}
|
|
524
|
-
: {
|
|
525
|
-
closeButton: createUiDomPlan('button', 'result-close', {
|
|
526
|
-
attrs: {
|
|
527
|
-
type: 'button',
|
|
528
|
-
'aria-label': options.closeLabel,
|
|
529
|
-
'data-display-close': '',
|
|
530
|
-
},
|
|
531
|
-
}),
|
|
532
|
-
}),
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
export function createBadgePlan(options = {}) {
|
|
536
|
-
const tone = options.tone ?? 'neutral';
|
|
537
|
-
return createUiDomPlan('span', 'badge', {
|
|
538
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
539
|
-
state: tone,
|
|
540
|
-
attrs: {
|
|
541
|
-
'aria-label': options.label,
|
|
542
|
-
...options.attrs,
|
|
543
|
-
'data-tone': tone,
|
|
544
|
-
},
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
export function createBadgeCountOverflowContract(options = {}) {
|
|
548
|
-
const count = normalizeCount(options.count) ?? 0;
|
|
549
|
-
const max = Math.max(1, normalizeCount(options.max) ?? 99);
|
|
550
|
-
const dot = options.dot === true;
|
|
551
|
-
const overflow = !dot && count > max;
|
|
552
|
-
const state = dot
|
|
553
|
-
? 'dot'
|
|
554
|
-
: count <= 0
|
|
555
|
-
? 'empty'
|
|
556
|
-
: overflow
|
|
557
|
-
? 'overflow'
|
|
558
|
-
: 'count';
|
|
559
|
-
const displayValue = dot || count <= 0 ? '' : overflow ? `${max}+` : String(count);
|
|
560
|
-
return {
|
|
561
|
-
state,
|
|
562
|
-
count,
|
|
563
|
-
max,
|
|
564
|
-
displayValue,
|
|
565
|
-
overflow,
|
|
566
|
-
dot,
|
|
567
|
-
attrs: {
|
|
568
|
-
'data-badge-count-overflow-contract': 'true',
|
|
569
|
-
'data-badge-state': state,
|
|
570
|
-
'data-count': count,
|
|
571
|
-
'data-max': max,
|
|
572
|
-
'data-display-value': displayValue,
|
|
573
|
-
'data-overflow': overflow ? 'true' : undefined,
|
|
574
|
-
'data-dot': dot ? 'true' : undefined,
|
|
575
|
-
'aria-label': options.label ?? badgeCountOverflowLabel({ count, displayValue, dot, overflow }),
|
|
576
|
-
},
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
export function createTagPlans(options) {
|
|
580
|
-
const variant = options.variant ?? 'tag';
|
|
581
|
-
const interactive = options.selected !== undefined || options.disabled === true;
|
|
582
|
-
const tag = createUiDomPlan(interactive ? 'button' : 'span', variant, {
|
|
583
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
584
|
-
...(options.disabled === undefined ? {} : { disabled: options.disabled }),
|
|
585
|
-
state: options.disabled === true ? 'disabled' : options.selected === true ? 'selected' : 'idle',
|
|
586
|
-
attrs: {
|
|
587
|
-
id: options.id,
|
|
588
|
-
type: interactive ? 'button' : undefined,
|
|
589
|
-
role: interactive ? 'option' : undefined,
|
|
590
|
-
'aria-selected': options.selected === undefined ? undefined : String(options.selected),
|
|
591
|
-
'aria-label': tagLabel(options),
|
|
592
|
-
...options.attrs,
|
|
593
|
-
'data-tone': options.tone ?? 'neutral',
|
|
594
|
-
'data-variant': variant,
|
|
595
|
-
'data-label': options.label,
|
|
596
|
-
'data-value': options.value,
|
|
597
|
-
'data-removable': options.removable === true ? 'true' : undefined,
|
|
598
|
-
'data-count': options.count,
|
|
599
|
-
},
|
|
600
|
-
});
|
|
601
|
-
return {
|
|
602
|
-
root: tag,
|
|
603
|
-
...(options.icon === true
|
|
604
|
-
? {
|
|
605
|
-
icon: createUiDomPlan('span', `${variant}-icon`, {
|
|
606
|
-
attrs: {
|
|
607
|
-
'aria-hidden': 'true',
|
|
608
|
-
'data-tone': options.tone ?? 'neutral',
|
|
609
|
-
},
|
|
610
|
-
}),
|
|
611
|
-
}
|
|
612
|
-
: {}),
|
|
613
|
-
label: createUiDomPlan('span', `${variant}-label`, {
|
|
614
|
-
attrs: { 'data-label': options.label },
|
|
615
|
-
}),
|
|
616
|
-
...(options.value === undefined
|
|
617
|
-
? {}
|
|
618
|
-
: {
|
|
619
|
-
value: createUiDomPlan('span', `${variant}-value`, {
|
|
620
|
-
attrs: { 'data-value': options.value },
|
|
621
|
-
}),
|
|
622
|
-
}),
|
|
623
|
-
...(options.count === undefined
|
|
624
|
-
? {}
|
|
625
|
-
: {
|
|
626
|
-
count: createUiDomPlan('span', `${variant}-count`, {
|
|
627
|
-
attrs: { 'aria-label': `${options.count} items`, 'data-count': options.count },
|
|
628
|
-
}),
|
|
629
|
-
}),
|
|
630
|
-
...(options.removable === true
|
|
631
|
-
? {
|
|
632
|
-
removeButton: createUiDomPlan('button', `${variant}-remove`, {
|
|
633
|
-
attrs: {
|
|
634
|
-
type: 'button',
|
|
635
|
-
'aria-label': `Remove ${options.label}`,
|
|
636
|
-
'data-remove-id': options.id,
|
|
637
|
-
},
|
|
638
|
-
}),
|
|
639
|
-
}
|
|
640
|
-
: {}),
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
export function createChipPlans(options) {
|
|
644
|
-
return createTagPlans({ ...options, variant: 'chip' });
|
|
645
|
-
}
|
|
646
|
-
export function createNotePlans(options = {}) {
|
|
647
|
-
return createNoteLikePlans('note', options);
|
|
648
|
-
}
|
|
649
|
-
export function createCalloutPlans(options = {}) {
|
|
650
|
-
return createNoteLikePlans('callout', options);
|
|
651
|
-
}
|
|
652
|
-
export function createNoteRichContentStateContract(options) {
|
|
653
|
-
const density = options.density ?? 'comfortable';
|
|
654
|
-
const blocks = (options.blocks ?? []).map((block) => ({
|
|
655
|
-
...block,
|
|
656
|
-
attrs: {
|
|
657
|
-
'data-note-rich-content-block': 'true',
|
|
658
|
-
'data-block-id': block.id,
|
|
659
|
-
'data-block-kind': block.kind,
|
|
660
|
-
},
|
|
661
|
-
}));
|
|
662
|
-
const blockIds = blocks.map((block) => block.id);
|
|
663
|
-
const state = blocks.length === 0 ? 'empty' : 'ready';
|
|
664
|
-
const actionState = options.actionId === undefined
|
|
665
|
-
? 'hidden'
|
|
666
|
-
: options.actionDisabled === true
|
|
667
|
-
? 'disabled'
|
|
668
|
-
: 'ready';
|
|
669
|
-
const closeState = options.closeAvailable !== true
|
|
670
|
-
? 'hidden'
|
|
671
|
-
: options.closeDisabled === true
|
|
672
|
-
? 'disabled'
|
|
673
|
-
: 'ready';
|
|
674
|
-
return {
|
|
675
|
-
kind: options.kind,
|
|
676
|
-
density,
|
|
677
|
-
state,
|
|
678
|
-
actionState,
|
|
679
|
-
closeState,
|
|
680
|
-
blockCount: blocks.length,
|
|
681
|
-
blockIds,
|
|
682
|
-
blocks,
|
|
683
|
-
attrs: {
|
|
684
|
-
'data-note-rich-content-contract': 'true',
|
|
685
|
-
'data-note-kind': options.kind,
|
|
686
|
-
'data-content-density': density,
|
|
687
|
-
'data-content-state': state,
|
|
688
|
-
'data-block-count': blocks.length,
|
|
689
|
-
'data-block-ids': blockIds.join(','),
|
|
690
|
-
'data-action-state': actionState,
|
|
691
|
-
'data-close-state': closeState,
|
|
692
|
-
},
|
|
693
|
-
contentAttrs: {
|
|
694
|
-
'data-note-rich-content': 'true',
|
|
695
|
-
'data-content-density': density,
|
|
696
|
-
'data-content-state': state,
|
|
697
|
-
},
|
|
698
|
-
actionAttrs: {
|
|
699
|
-
type: 'button',
|
|
700
|
-
'data-action-id': options.actionId,
|
|
701
|
-
'data-action-state': actionState,
|
|
702
|
-
hidden: actionState === 'hidden' ? true : undefined,
|
|
703
|
-
disabled: actionState === 'disabled' ? true : undefined,
|
|
704
|
-
'aria-disabled': actionState === 'disabled' ? 'true' : undefined,
|
|
705
|
-
},
|
|
706
|
-
closeAttrs: {
|
|
707
|
-
type: 'button',
|
|
708
|
-
'data-close-state': closeState,
|
|
709
|
-
hidden: closeState === 'hidden' ? true : undefined,
|
|
710
|
-
disabled: closeState === 'disabled' ? true : undefined,
|
|
711
|
-
'aria-disabled': closeState === 'disabled' ? 'true' : undefined,
|
|
712
|
-
},
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
export function createPanelPlans(options = {}) {
|
|
716
|
-
return createPanelLikePlans('panel', options);
|
|
717
|
-
}
|
|
718
|
-
export function createCardPlans(options = {}) {
|
|
719
|
-
return createPanelLikePlans('card', options);
|
|
720
|
-
}
|
|
721
|
-
export function createPanelCardMediaActionStateContract(options) {
|
|
722
|
-
const mediaState = options.mediaId === undefined ? 'empty' : 'ready';
|
|
723
|
-
const mediaPlacement = options.mediaPlacement ?? 'top';
|
|
724
|
-
const selectionState = options.selected === true ? 'selected' : 'idle';
|
|
725
|
-
const selectedEmphasis = selectionState === 'selected' && options.selectedEmphasis === true;
|
|
726
|
-
const hiddenActionIds = new Set(options.hiddenActionIds ?? []);
|
|
727
|
-
const actionContracts = (options.actions ?? []).map((action) => {
|
|
728
|
-
const state = hiddenActionIds.has(action.id)
|
|
729
|
-
? 'hidden'
|
|
730
|
-
: action.disabled === true
|
|
731
|
-
? 'disabled'
|
|
732
|
-
: 'ready';
|
|
733
|
-
return {
|
|
734
|
-
id: action.id,
|
|
735
|
-
state,
|
|
736
|
-
attrs: {
|
|
737
|
-
type: 'button',
|
|
738
|
-
'data-action-id': action.id,
|
|
739
|
-
'data-action-state': state,
|
|
740
|
-
hidden: state === 'hidden' ? true : undefined,
|
|
741
|
-
disabled: state === 'disabled' ? true : undefined,
|
|
742
|
-
'aria-disabled': state === 'disabled' ? 'true' : undefined,
|
|
743
|
-
},
|
|
744
|
-
};
|
|
745
|
-
});
|
|
746
|
-
const readyActionIds = actionContracts
|
|
747
|
-
.filter((action) => action.state === 'ready')
|
|
748
|
-
.map((action) => action.id);
|
|
749
|
-
const disabledActionIds = actionContracts
|
|
750
|
-
.filter((action) => action.state === 'disabled')
|
|
751
|
-
.map((action) => action.id);
|
|
752
|
-
const resolvedHiddenActionIds = actionContracts
|
|
753
|
-
.filter((action) => action.state === 'hidden')
|
|
754
|
-
.map((action) => action.id);
|
|
755
|
-
return {
|
|
756
|
-
kind: options.kind,
|
|
757
|
-
mediaState,
|
|
758
|
-
mediaPlacement,
|
|
759
|
-
selectionState,
|
|
760
|
-
selectedEmphasis,
|
|
761
|
-
actionCount: actionContracts.length,
|
|
762
|
-
readyActionIds,
|
|
763
|
-
disabledActionIds,
|
|
764
|
-
hiddenActionIds: resolvedHiddenActionIds,
|
|
765
|
-
attrs: {
|
|
766
|
-
'data-panel-card-media-action-contract': 'true',
|
|
767
|
-
'data-panel-card-kind': options.kind,
|
|
768
|
-
'data-media-state': mediaState,
|
|
769
|
-
'data-media-placement': mediaPlacement,
|
|
770
|
-
'data-selection-state': selectionState,
|
|
771
|
-
'data-selected-emphasis': selectedEmphasis ? 'true' : undefined,
|
|
772
|
-
'data-action-count': actionContracts.length,
|
|
773
|
-
'data-ready-action-ids': readyActionIds.join(','),
|
|
774
|
-
'data-disabled-action-ids': disabledActionIds.join(','),
|
|
775
|
-
'data-hidden-action-ids': resolvedHiddenActionIds.join(','),
|
|
776
|
-
},
|
|
777
|
-
mediaAttrs: {
|
|
778
|
-
id: options.mediaId,
|
|
779
|
-
role: mediaState === 'ready' ? 'img' : undefined,
|
|
780
|
-
'aria-label': mediaState === 'ready' ? options.mediaLabel : undefined,
|
|
781
|
-
'aria-hidden': mediaState === 'empty' ? 'true' : undefined,
|
|
782
|
-
hidden: mediaState === 'empty' ? true : undefined,
|
|
783
|
-
'data-media-state': mediaState,
|
|
784
|
-
'data-media-placement': mediaPlacement,
|
|
785
|
-
},
|
|
786
|
-
actionContracts,
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
export function createPageHeaderPlans(options) {
|
|
790
|
-
const actions = (options.actions ?? []).map((action) => createDataDisplayActionButton('page-header', action));
|
|
791
|
-
return {
|
|
792
|
-
root: createUiDomPlan('header', 'product-page-header', {
|
|
793
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
794
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
795
|
-
attrs: {
|
|
796
|
-
id: options.id,
|
|
797
|
-
'aria-labelledby': options.titleId,
|
|
798
|
-
'aria-describedby': options.subtitleId,
|
|
799
|
-
...options.attrs,
|
|
800
|
-
'data-has-breadcrumb': options.breadcrumbLabel === undefined ? undefined : 'true',
|
|
801
|
-
'data-action-count': actions.length,
|
|
802
|
-
'data-tabs-ready': options.tabsId === undefined ? undefined : 'true',
|
|
803
|
-
},
|
|
804
|
-
}),
|
|
805
|
-
...(options.breadcrumbLabel === undefined
|
|
806
|
-
? {}
|
|
807
|
-
: {
|
|
808
|
-
breadcrumbSlot: createUiDomPlan('nav', 'page-header-breadcrumb', {
|
|
809
|
-
attrs: { 'aria-label': options.breadcrumbLabel, 'data-slot': 'breadcrumb' },
|
|
810
|
-
}),
|
|
811
|
-
}),
|
|
812
|
-
content: createUiDomPlan('div', 'page-header-content'),
|
|
813
|
-
title: createUiDomPlan('h1', 'page-header-title', { attrs: { id: options.titleId } }),
|
|
814
|
-
...(options.subtitleId === undefined
|
|
815
|
-
? {}
|
|
816
|
-
: {
|
|
817
|
-
subtitle: createUiDomPlan('p', 'page-header-subtitle', {
|
|
818
|
-
attrs: { id: options.subtitleId },
|
|
819
|
-
}),
|
|
820
|
-
}),
|
|
821
|
-
...(actions.length === 0
|
|
822
|
-
? {}
|
|
823
|
-
: {
|
|
824
|
-
actionsSlot: createUiDomPlan('div', 'page-header-actions', {
|
|
825
|
-
attrs: { role: 'toolbar', 'data-slot': 'actions', 'data-action-count': actions.length },
|
|
826
|
-
}),
|
|
827
|
-
}),
|
|
828
|
-
actions,
|
|
829
|
-
...(options.tabsId === undefined
|
|
830
|
-
? {}
|
|
831
|
-
: {
|
|
832
|
-
tabsSlot: createUiDomPlan('div', 'page-header-tabs', {
|
|
833
|
-
attrs: { id: `${options.tabsId}-slot`, 'data-slot': 'tabs' },
|
|
834
|
-
}),
|
|
835
|
-
}),
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
export function createStatCardPlans(options) {
|
|
839
|
-
const tone = options.tone ?? 'neutral';
|
|
840
|
-
const loading = options.loading === true;
|
|
841
|
-
return {
|
|
842
|
-
root: createUiDomPlan('article', 'stat-card', {
|
|
843
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
844
|
-
loading,
|
|
845
|
-
attrs: {
|
|
846
|
-
id: options.id,
|
|
847
|
-
'aria-labelledby': options.titleId,
|
|
848
|
-
'aria-describedby': options.descriptionId,
|
|
849
|
-
...options.attrs,
|
|
850
|
-
'data-tone': tone,
|
|
851
|
-
'data-value': options.value,
|
|
852
|
-
'data-unit': options.unit,
|
|
853
|
-
'data-trend-direction': options.trendDirection,
|
|
854
|
-
'data-actionable': options.action === undefined ? undefined : '',
|
|
855
|
-
},
|
|
856
|
-
}),
|
|
857
|
-
header: createUiDomPlan('header', 'stat-card-header'),
|
|
858
|
-
title: createUiDomPlan('h3', 'stat-card-title', { attrs: { id: options.titleId } }),
|
|
859
|
-
value: createUiDomPlan('output', 'stat-card-value', {
|
|
860
|
-
attrs: {
|
|
861
|
-
'aria-live': 'polite',
|
|
862
|
-
'data-value': loading ? undefined : options.value,
|
|
863
|
-
},
|
|
864
|
-
}),
|
|
865
|
-
...(options.unit === undefined
|
|
866
|
-
? {}
|
|
867
|
-
: {
|
|
868
|
-
unit: createUiDomPlan('span', 'stat-card-unit', { attrs: { 'data-unit': options.unit } }),
|
|
869
|
-
}),
|
|
870
|
-
...(options.trend === undefined
|
|
871
|
-
? {}
|
|
872
|
-
: {
|
|
873
|
-
trend: createUiDomPlan('span', 'stat-card-trend', {
|
|
874
|
-
attrs: {
|
|
875
|
-
'aria-label': options.trend,
|
|
876
|
-
'data-trend': options.trend,
|
|
877
|
-
'data-direction': options.trendDirection ?? 'flat',
|
|
878
|
-
},
|
|
879
|
-
}),
|
|
880
|
-
}),
|
|
881
|
-
...(options.descriptionId === undefined
|
|
882
|
-
? {}
|
|
883
|
-
: {
|
|
884
|
-
description: createUiDomPlan('p', 'stat-card-description', {
|
|
885
|
-
attrs: { id: options.descriptionId },
|
|
886
|
-
}),
|
|
887
|
-
}),
|
|
888
|
-
...(options.action === undefined
|
|
889
|
-
? {}
|
|
890
|
-
: { actionButton: createDataDisplayActionButton('stat-card', options.action) }),
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
export function createTablePanelPlans(options) {
|
|
894
|
-
const actions = (options.actions ?? []).map((action) => createDataDisplayActionButton('table-panel', action));
|
|
895
|
-
const emptyOptions = normalizeEmptyOptions(options.empty);
|
|
896
|
-
const table = createTablePlans({
|
|
897
|
-
...(options.id === undefined ? {} : { id: `${options.id}-table` }),
|
|
898
|
-
columns: options.columns,
|
|
899
|
-
rows: options.rows,
|
|
900
|
-
...(options.captionId === undefined ? {} : { captionId: options.captionId }),
|
|
901
|
-
...(options.selectable === undefined ? {} : { selectable: options.selectable }),
|
|
902
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
903
|
-
...(options.stickyHeader === undefined ? {} : { stickyHeader: options.stickyHeader }),
|
|
904
|
-
...(options.tableAttrs === undefined ? {} : { attrs: options.tableAttrs }),
|
|
905
|
-
});
|
|
906
|
-
return {
|
|
907
|
-
root: createUiDomPlan('section', 'table-panel', {
|
|
908
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
909
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
910
|
-
...(options.loading === undefined ? {} : { loading: options.loading }),
|
|
911
|
-
attrs: {
|
|
912
|
-
id: options.id,
|
|
913
|
-
'aria-labelledby': options.titleId,
|
|
914
|
-
'aria-describedby': options.descriptionId,
|
|
915
|
-
...options.attrs,
|
|
916
|
-
'data-row-count': options.rows.length,
|
|
917
|
-
'data-column-count': options.columns.filter((column) => column.hidden !== true).length,
|
|
918
|
-
'data-action-count': actions.length,
|
|
919
|
-
'data-has-toolbar': options.toolbarLabel === undefined ? undefined : 'true',
|
|
920
|
-
'data-empty': emptyOptions === undefined ? undefined : 'true',
|
|
921
|
-
},
|
|
922
|
-
}),
|
|
923
|
-
...(options.titleId === undefined && options.descriptionId === undefined && actions.length === 0
|
|
924
|
-
? {}
|
|
925
|
-
: { header: createUiDomPlan('header', 'table-panel-header') }),
|
|
926
|
-
...(options.titleId === undefined
|
|
927
|
-
? {}
|
|
928
|
-
: { title: createUiDomPlan('h3', 'table-panel-title', { attrs: { id: options.titleId } }) }),
|
|
929
|
-
...(options.descriptionId === undefined
|
|
930
|
-
? {}
|
|
931
|
-
: {
|
|
932
|
-
description: createUiDomPlan('p', 'table-panel-description', {
|
|
933
|
-
attrs: { id: options.descriptionId },
|
|
934
|
-
}),
|
|
935
|
-
}),
|
|
936
|
-
...(options.toolbarLabel === undefined
|
|
937
|
-
? {}
|
|
938
|
-
: {
|
|
939
|
-
toolbarSlot: createUiDomPlan('div', 'table-panel-toolbar', {
|
|
940
|
-
attrs: {
|
|
941
|
-
role: 'toolbar',
|
|
942
|
-
'aria-label': options.toolbarLabel,
|
|
943
|
-
'data-slot': 'toolbar',
|
|
944
|
-
},
|
|
945
|
-
}),
|
|
946
|
-
}),
|
|
947
|
-
actions,
|
|
948
|
-
body: createUiDomPlan('div', 'table-panel-body'),
|
|
949
|
-
scroller: createUiDomPlan('div', 'table-panel-scroller'),
|
|
950
|
-
table,
|
|
951
|
-
...(emptyOptions === undefined ? {} : { empty: createEmptyPlan(emptyOptions) }),
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
export function createProgressPlan(options) {
|
|
955
|
-
const max = options.max ?? 100;
|
|
956
|
-
const value = Math.min(Math.max(options.value, 0), max);
|
|
957
|
-
return createUiDomPlan('div', 'progress', {
|
|
958
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
959
|
-
state: options.status ?? 'idle',
|
|
960
|
-
attrs: {
|
|
961
|
-
role: 'progressbar',
|
|
962
|
-
'aria-label': options.label,
|
|
963
|
-
'aria-valuemin': 0,
|
|
964
|
-
'aria-valuemax': max,
|
|
965
|
-
'aria-valuenow': value,
|
|
966
|
-
...options.attrs,
|
|
967
|
-
'data-status': options.status,
|
|
968
|
-
style: `--kui-progress-value: ${(value / max) * 100}%;${styleSuffix(options.attrs?.style)}`,
|
|
969
|
-
},
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
export function createTypographyPlan(options = {}) {
|
|
973
|
-
const variant = options.variant ?? 'body';
|
|
974
|
-
const tag = options.as ?? typographyTag(variant);
|
|
975
|
-
return createUiDomPlan(tag, 'typography', {
|
|
976
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
977
|
-
state: variant,
|
|
978
|
-
attrs: {
|
|
979
|
-
id: options.id,
|
|
980
|
-
href: tag === 'a' ? options.href : undefined,
|
|
981
|
-
'aria-label': options.label,
|
|
982
|
-
...options.attrs,
|
|
983
|
-
'data-variant': variant,
|
|
984
|
-
'data-truncate': options.truncate === true ? 'true' : undefined,
|
|
985
|
-
},
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
export function createTypographyRichContentStateContract(options = {}) {
|
|
989
|
-
const source = options.source ?? 'rich-text';
|
|
990
|
-
const density = options.density ?? 'comfortable';
|
|
991
|
-
const blocks = (options.blocks ?? []).map((block) => ({
|
|
992
|
-
...block,
|
|
993
|
-
attrs: {
|
|
994
|
-
'data-rich-content-block': 'true',
|
|
995
|
-
'data-block-id': block.id,
|
|
996
|
-
'data-block-kind': block.kind,
|
|
997
|
-
},
|
|
998
|
-
}));
|
|
999
|
-
const blockIds = blocks.map((block) => block.id);
|
|
1000
|
-
const headingCount = blocks.filter((block) => block.kind === 'heading').length;
|
|
1001
|
-
const state = blocks.length === 0 ? 'empty' : 'ready';
|
|
1002
|
-
return {
|
|
1003
|
-
source,
|
|
1004
|
-
density,
|
|
1005
|
-
state,
|
|
1006
|
-
blockCount: blocks.length,
|
|
1007
|
-
headingCount,
|
|
1008
|
-
blockIds,
|
|
1009
|
-
blocks,
|
|
1010
|
-
attrs: {
|
|
1011
|
-
'data-typography-rich-content-contract': 'true',
|
|
1012
|
-
'data-content-source': source,
|
|
1013
|
-
'data-content-density': density,
|
|
1014
|
-
'data-content-state': state,
|
|
1015
|
-
'data-block-count': blocks.length,
|
|
1016
|
-
'data-heading-count': headingCount,
|
|
1017
|
-
'data-block-ids': blockIds.join(','),
|
|
1018
|
-
'aria-label': options.label,
|
|
1019
|
-
},
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
export function createDividerPlans(options = {}) {
|
|
1023
|
-
const orientation = options.orientation ?? 'horizontal';
|
|
1024
|
-
return {
|
|
1025
|
-
root: createUiDomPlan('div', 'divider', {
|
|
1026
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1027
|
-
state: options.label === undefined ? 'line' : 'labelled',
|
|
1028
|
-
attrs: {
|
|
1029
|
-
id: options.id,
|
|
1030
|
-
role: 'separator',
|
|
1031
|
-
'aria-orientation': orientation,
|
|
1032
|
-
'aria-labelledby': options.labelId,
|
|
1033
|
-
...options.attrs,
|
|
1034
|
-
'data-orientation': orientation,
|
|
1035
|
-
'data-inset': dividerInset(options.inset),
|
|
1036
|
-
'data-label': options.label,
|
|
1037
|
-
},
|
|
1038
|
-
}),
|
|
1039
|
-
...(options.label === undefined
|
|
1040
|
-
? {}
|
|
1041
|
-
: {
|
|
1042
|
-
label: createUiDomPlan('span', 'divider-label', {
|
|
1043
|
-
attrs: {
|
|
1044
|
-
id: options.labelId,
|
|
1045
|
-
'data-label': options.label,
|
|
1046
|
-
},
|
|
1047
|
-
}),
|
|
1048
|
-
}),
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
export function createDividerSectionHeadingStateContract(options) {
|
|
1052
|
-
const state = options.current === true ? 'current' : 'idle';
|
|
1053
|
-
const level = options.level ?? 2;
|
|
1054
|
-
return {
|
|
1055
|
-
state,
|
|
1056
|
-
headingId: options.headingId,
|
|
1057
|
-
sectionId: options.sectionId,
|
|
1058
|
-
level,
|
|
1059
|
-
attrs: {
|
|
1060
|
-
'data-divider-section-heading-contract': 'true',
|
|
1061
|
-
'data-section-heading-state': state,
|
|
1062
|
-
'data-section-id': options.sectionId,
|
|
1063
|
-
'data-heading-id': options.headingId,
|
|
1064
|
-
'data-heading-level': level,
|
|
1065
|
-
'aria-labelledby': options.headingId,
|
|
1066
|
-
'aria-describedby': options.descriptionId,
|
|
1067
|
-
},
|
|
1068
|
-
headingAttrs: {
|
|
1069
|
-
id: options.headingId,
|
|
1070
|
-
role: 'heading',
|
|
1071
|
-
'aria-level': level,
|
|
1072
|
-
'aria-describedby': options.descriptionId,
|
|
1073
|
-
'data-section-heading-state': state,
|
|
1074
|
-
},
|
|
1075
|
-
sectionAttrs: {
|
|
1076
|
-
id: options.sectionId,
|
|
1077
|
-
'aria-labelledby': options.headingId,
|
|
1078
|
-
'aria-describedby': options.descriptionId,
|
|
1079
|
-
'data-section-heading-state': state,
|
|
1080
|
-
},
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
export function createAvatarPlans(options) {
|
|
1084
|
-
const size = options.size ?? 'md';
|
|
1085
|
-
const initials = normalizeInitials(options.initials ?? initialsFromName(options.name));
|
|
1086
|
-
return {
|
|
1087
|
-
root: createUiDomPlan('span', 'avatar', {
|
|
1088
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1089
|
-
state: options.src === undefined ? 'fallback' : 'image',
|
|
1090
|
-
attrs: {
|
|
1091
|
-
id: options.id,
|
|
1092
|
-
role: 'img',
|
|
1093
|
-
'aria-label': options.name,
|
|
1094
|
-
...options.attrs,
|
|
1095
|
-
'data-size': size,
|
|
1096
|
-
'data-name': options.name,
|
|
1097
|
-
'data-initials': initials,
|
|
1098
|
-
'data-status': options.status,
|
|
1099
|
-
},
|
|
1100
|
-
}),
|
|
1101
|
-
...(options.src === undefined
|
|
1102
|
-
? {}
|
|
1103
|
-
: {
|
|
1104
|
-
image: createUiDomPlan('img', 'avatar-image', {
|
|
1105
|
-
attrs: {
|
|
1106
|
-
src: options.src,
|
|
1107
|
-
alt: options.alt ?? '',
|
|
1108
|
-
},
|
|
1109
|
-
}),
|
|
1110
|
-
}),
|
|
1111
|
-
fallback: createUiDomPlan('span', 'avatar-fallback', {
|
|
1112
|
-
attrs: {
|
|
1113
|
-
'aria-hidden': options.src === undefined ? undefined : 'true',
|
|
1114
|
-
'data-initials': initials,
|
|
1115
|
-
},
|
|
1116
|
-
}),
|
|
1117
|
-
...(options.status === undefined
|
|
1118
|
-
? {}
|
|
1119
|
-
: {
|
|
1120
|
-
status: createUiDomPlan('span', 'avatar-status', {
|
|
1121
|
-
attrs: {
|
|
1122
|
-
'aria-label': `${options.name} is ${options.status}`,
|
|
1123
|
-
'data-status': options.status,
|
|
1124
|
-
},
|
|
1125
|
-
}),
|
|
1126
|
-
}),
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
export function createAvatarGroupPlans(options) {
|
|
1130
|
-
const maxVisible = Math.max(0, Math.trunc(options.maxVisible ?? options.avatars.length));
|
|
1131
|
-
const visible = options.avatars.slice(0, maxVisible);
|
|
1132
|
-
const overflowCount = Math.max(0, options.avatars.length - visible.length);
|
|
1133
|
-
return {
|
|
1134
|
-
root: createUiDomPlan('div', 'avatar-group', {
|
|
1135
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1136
|
-
attrs: {
|
|
1137
|
-
id: options.id,
|
|
1138
|
-
role: 'group',
|
|
1139
|
-
'aria-label': options.label ?? `${options.avatars.length} people`,
|
|
1140
|
-
...options.attrs,
|
|
1141
|
-
'data-count': options.avatars.length,
|
|
1142
|
-
'data-visible-count': visible.length,
|
|
1143
|
-
'data-overflow-count': overflowCount,
|
|
1144
|
-
'data-size': options.size ?? 'md',
|
|
1145
|
-
},
|
|
1146
|
-
}),
|
|
1147
|
-
avatars: visible.map((avatar) => createAvatarPlans({ ...avatar, size: avatar.size ?? options.size ?? 'md' })),
|
|
1148
|
-
...(overflowCount === 0
|
|
1149
|
-
? {}
|
|
1150
|
-
: {
|
|
1151
|
-
overflow: createUiDomPlan('span', 'avatar-overflow', {
|
|
1152
|
-
attrs: {
|
|
1153
|
-
role: 'img',
|
|
1154
|
-
'aria-label': `${overflowCount} more`,
|
|
1155
|
-
'data-overflow-count': overflowCount,
|
|
1156
|
-
},
|
|
1157
|
-
}),
|
|
1158
|
-
}),
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
export function createAvatarImagePresenceStateContract(options) {
|
|
1162
|
-
const imageState = options.imageState ?? avatarImageState(options);
|
|
1163
|
-
const presenceSource = options.presenceSource ?? 'unknown';
|
|
1164
|
-
const cacheState = options.cacheState ?? (options.cacheKey === undefined ? 'unbound' : 'miss');
|
|
1165
|
-
const fallbackInitials = normalizeInitials(options.fallbackInitials ?? initialsFromName(options.name));
|
|
1166
|
-
return {
|
|
1167
|
-
imageState,
|
|
1168
|
-
presenceSource,
|
|
1169
|
-
cacheState,
|
|
1170
|
-
fallbackInitials,
|
|
1171
|
-
attrs: {
|
|
1172
|
-
'data-avatar-image-presence-contract': 'true',
|
|
1173
|
-
'data-image-state': imageState,
|
|
1174
|
-
'data-image-src': options.src,
|
|
1175
|
-
'data-image-error': options.imageError,
|
|
1176
|
-
'data-presence-status': options.status,
|
|
1177
|
-
'data-presence-source': presenceSource,
|
|
1178
|
-
'data-presence-updated-at': options.presenceUpdatedAt,
|
|
1179
|
-
'data-cache-state': cacheState,
|
|
1180
|
-
'data-cache-key': options.cacheKey,
|
|
1181
|
-
'data-cached-at': options.cachedAt,
|
|
1182
|
-
'data-fallback-initials': fallbackInitials,
|
|
1183
|
-
'aria-busy': imageState === 'loading' ? 'true' : undefined,
|
|
1184
|
-
},
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
export function createKbdPlan(options) {
|
|
1188
|
-
return createUiDomPlan('kbd', 'kbd', {
|
|
1189
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1190
|
-
attrs: {
|
|
1191
|
-
'aria-label': options.label ?? options.key,
|
|
1192
|
-
...options.attrs,
|
|
1193
|
-
'data-key': options.key,
|
|
1194
|
-
},
|
|
1195
|
-
});
|
|
1196
|
-
}
|
|
1197
|
-
export function createShortcutPlans(options) {
|
|
1198
|
-
const label = options.label ?? formatShortcutLabel(options.keys);
|
|
1199
|
-
return {
|
|
1200
|
-
root: createUiDomPlan('span', 'shortcut', {
|
|
1201
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1202
|
-
attrs: {
|
|
1203
|
-
role: 'img',
|
|
1204
|
-
'aria-label': label,
|
|
1205
|
-
...options.attrs,
|
|
1206
|
-
'data-shortcut': label,
|
|
1207
|
-
'data-key-count': options.keys.length,
|
|
1208
|
-
},
|
|
1209
|
-
}),
|
|
1210
|
-
keys: options.keys.map((key) => createKbdPlan({ key })),
|
|
1211
|
-
separators: options.keys.slice(1).map((_, index) => createUiDomPlan('span', 'shortcut-separator', {
|
|
1212
|
-
attrs: {
|
|
1213
|
-
'aria-hidden': 'true',
|
|
1214
|
-
'data-index': index,
|
|
1215
|
-
},
|
|
1216
|
-
})),
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
export function createShortcutDisplayStateContract(options) {
|
|
1220
|
-
const platform = options.platform ?? 'generic';
|
|
1221
|
-
const keys = options.keys.map((key) => key.trim()).filter((key) => key !== '');
|
|
1222
|
-
const keyContracts = keys.map((key) => {
|
|
1223
|
-
const alias = options.modifierAliases?.[key]?.trim() ?? '';
|
|
1224
|
-
const displayKey = alias === '' ? key : alias;
|
|
1225
|
-
const aliased = displayKey !== key;
|
|
1226
|
-
return {
|
|
1227
|
-
key,
|
|
1228
|
-
displayKey,
|
|
1229
|
-
aliased,
|
|
1230
|
-
attrs: {
|
|
1231
|
-
'data-key': key,
|
|
1232
|
-
'data-display-key': displayKey,
|
|
1233
|
-
'data-modifier-alias': aliased ? 'true' : undefined,
|
|
1234
|
-
},
|
|
1235
|
-
};
|
|
1236
|
-
});
|
|
1237
|
-
const displayKeys = keyContracts.map((key) => key.displayKey);
|
|
1238
|
-
const aliasedKeys = keyContracts.filter((key) => key.aliased).map((key) => key.key);
|
|
1239
|
-
const state = keys.length === 0 ? 'empty' : aliasedKeys.length === 0 ? 'ready' : 'aliased';
|
|
1240
|
-
const label = options.label?.trim() || formatShortcutLabel(displayKeys);
|
|
1241
|
-
return {
|
|
1242
|
-
platform,
|
|
1243
|
-
state,
|
|
1244
|
-
keys,
|
|
1245
|
-
displayKeys,
|
|
1246
|
-
aliasedKeys,
|
|
1247
|
-
label,
|
|
1248
|
-
keyContracts,
|
|
1249
|
-
attrs: {
|
|
1250
|
-
'data-shortcut-display-contract': 'true',
|
|
1251
|
-
'data-shortcut-platform': platform,
|
|
1252
|
-
'data-shortcut-display-state': state,
|
|
1253
|
-
'data-shortcut-keys': keys.join(','),
|
|
1254
|
-
'data-shortcut-display-keys': displayKeys.join(','),
|
|
1255
|
-
'data-aliased-keys': aliasedKeys.join(','),
|
|
1256
|
-
'data-key-count': keys.length,
|
|
1257
|
-
'data-shortcut-label': label,
|
|
1258
|
-
'aria-label': label,
|
|
1259
|
-
},
|
|
1260
|
-
};
|
|
1261
|
-
}
|
|
1262
|
-
export function createPaginationPlans(options) {
|
|
1263
|
-
const pageCount = getPaginationPageCount(options);
|
|
1264
|
-
const page = clampPage(options.page, pageCount);
|
|
1265
|
-
const items = createPaginationItems({
|
|
1266
|
-
page,
|
|
1267
|
-
pageCount,
|
|
1268
|
-
...(options.siblingCount === undefined ? {} : { siblingCount: options.siblingCount }),
|
|
1269
|
-
...(options.boundaryCount === undefined ? {} : { boundaryCount: options.boundaryCount }),
|
|
1270
|
-
});
|
|
1271
|
-
const root = createUiDomPlan('nav', 'pagination', {
|
|
1272
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1273
|
-
attrs: {
|
|
1274
|
-
id: options.id,
|
|
1275
|
-
'aria-label': options.label ?? 'Pagination',
|
|
1276
|
-
...options.attrs,
|
|
1277
|
-
'data-page': page,
|
|
1278
|
-
'data-page-count': pageCount,
|
|
1279
|
-
'data-total-items': normalizeCount(options.totalItems),
|
|
1280
|
-
},
|
|
1281
|
-
});
|
|
1282
|
-
const list = createUiDomPlan('ol', 'pagination-list', { attrs: { role: 'list' } });
|
|
1283
|
-
const previous = createPaginationControl('previous', page <= 1 ? 1 : page - 1, page <= 1, options.previousLabel ?? 'Previous page');
|
|
1284
|
-
const pages = items.map((item, index) => createPaginationItemPlan(item, index, options.pageLabel));
|
|
1285
|
-
const next = createPaginationControl('next', page >= pageCount ? pageCount : page + 1, page >= pageCount, options.nextLabel ?? 'Next page');
|
|
1286
|
-
const summary = options.summary ??
|
|
1287
|
-
formatPaginationSummary({
|
|
1288
|
-
...options,
|
|
1289
|
-
page,
|
|
1290
|
-
pageCount,
|
|
1291
|
-
});
|
|
1292
|
-
const summaryPlan = createUiDomPlan('output', 'pagination-summary', {
|
|
1293
|
-
attrs: {
|
|
1294
|
-
'aria-live': 'polite',
|
|
1295
|
-
'data-summary': summary,
|
|
1296
|
-
},
|
|
1297
|
-
});
|
|
1298
|
-
return {
|
|
1299
|
-
root,
|
|
1300
|
-
list,
|
|
1301
|
-
previous,
|
|
1302
|
-
pages,
|
|
1303
|
-
next,
|
|
1304
|
-
summary: summaryPlan,
|
|
1305
|
-
model: {
|
|
1306
|
-
rootId: typeof root.attrs.id === 'string' ? root.attrs.id : '',
|
|
1307
|
-
rootClassName: root.className,
|
|
1308
|
-
page,
|
|
1309
|
-
pageCount,
|
|
1310
|
-
totalItems: normalizeCount(options.totalItems) ?? 0,
|
|
1311
|
-
previousClassName: previous.className,
|
|
1312
|
-
previousLabel: typeof previous.attrs['aria-label'] === 'string' ? previous.attrs['aria-label'] : '',
|
|
1313
|
-
previousPage: typeof previous.attrs['data-page'] === 'number' ? previous.attrs['data-page'] : 1,
|
|
1314
|
-
previousDisabled: previous.attrs.disabled === true || previous.attrs.disabled === '',
|
|
1315
|
-
listClassName: list.className,
|
|
1316
|
-
pages: items.map((item, index) => createPaginationItemModel(item, index, pages[index], options.pageLabel)),
|
|
1317
|
-
nextClassName: next.className,
|
|
1318
|
-
nextLabel: typeof next.attrs['aria-label'] === 'string' ? next.attrs['aria-label'] : '',
|
|
1319
|
-
nextPage: typeof next.attrs['data-page'] === 'number' ? next.attrs['data-page'] : pageCount,
|
|
1320
|
-
nextDisabled: next.attrs.disabled === true || next.attrs.disabled === '',
|
|
1321
|
-
summaryClassName: summaryPlan.className,
|
|
1322
|
-
summary,
|
|
1323
|
-
},
|
|
1324
|
-
};
|
|
1325
|
-
}
|
|
1326
|
-
export function createPaginationItems(options) {
|
|
1327
|
-
const pageCount = Math.max(1, Math.trunc(options.pageCount ?? 1));
|
|
1328
|
-
const page = clampPage(options.page, pageCount);
|
|
1329
|
-
const siblingCount = Math.max(0, Math.trunc(options.siblingCount ?? 1));
|
|
1330
|
-
const boundaryCount = Math.max(0, Math.trunc(options.boundaryCount ?? 1));
|
|
1331
|
-
const pages = new Set();
|
|
1332
|
-
for (let value = 1; value <= Math.min(boundaryCount, pageCount); value += 1)
|
|
1333
|
-
pages.add(value);
|
|
1334
|
-
for (let value = Math.max(1, pageCount - boundaryCount + 1); value <= pageCount; value += 1) {
|
|
1335
|
-
pages.add(value);
|
|
1336
|
-
}
|
|
1337
|
-
for (let value = Math.max(1, page - siblingCount); value <= Math.min(pageCount, page + siblingCount); value += 1) {
|
|
1338
|
-
pages.add(value);
|
|
1339
|
-
}
|
|
1340
|
-
const sorted = [...pages].sort((left, right) => left - right);
|
|
1341
|
-
const items = [];
|
|
1342
|
-
let previous = 0;
|
|
1343
|
-
for (const value of sorted) {
|
|
1344
|
-
if (previous > 0 && value - previous > 1)
|
|
1345
|
-
items.push({ kind: 'ellipsis' });
|
|
1346
|
-
items.push({ kind: 'page', page: value, current: value === page });
|
|
1347
|
-
previous = value;
|
|
1348
|
-
}
|
|
1349
|
-
return items;
|
|
1350
|
-
}
|
|
1351
|
-
export function formatPaginationSummary(options) {
|
|
1352
|
-
const pageCount = getPaginationPageCount(options);
|
|
1353
|
-
const page = clampPage(options.page, pageCount);
|
|
1354
|
-
const total = normalizeCount(options.totalItems);
|
|
1355
|
-
const pageSize = normalizeCount(options.pageSize);
|
|
1356
|
-
if (total !== undefined && pageSize !== undefined && total > 0) {
|
|
1357
|
-
const start = (page - 1) * pageSize + 1;
|
|
1358
|
-
const end = Math.min(total, page * pageSize);
|
|
1359
|
-
return `${start}-${end} of ${total}`;
|
|
1360
|
-
}
|
|
1361
|
-
return `Page ${page} of ${pageCount}`;
|
|
1362
|
-
}
|
|
1363
|
-
export function createListPlans(options) {
|
|
1364
|
-
const selectionMode = options.selectionMode ?? 'none';
|
|
1365
|
-
return {
|
|
1366
|
-
root: createUiDomPlan(options.ordered === true ? 'ol' : 'ul', 'list', {
|
|
1367
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1368
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
1369
|
-
attrs: {
|
|
1370
|
-
id: options.id,
|
|
1371
|
-
role: selectionMode === 'none' ? 'list' : 'listbox',
|
|
1372
|
-
'aria-label': options.label,
|
|
1373
|
-
'aria-multiselectable': selectionMode === 'multiple' ? 'true' : undefined,
|
|
1374
|
-
...options.attrs,
|
|
1375
|
-
'data-count': options.items.length,
|
|
1376
|
-
'data-selection-mode': selectionMode,
|
|
1377
|
-
},
|
|
1378
|
-
}),
|
|
1379
|
-
items: options.items.map((item) => createUiDomPlan('li', 'list-item', {
|
|
1380
|
-
...(item.disabled === undefined ? {} : { disabled: item.disabled }),
|
|
1381
|
-
state: item.disabled === true ? 'disabled' : item.selected === true ? 'selected' : 'idle',
|
|
1382
|
-
attrs: {
|
|
1383
|
-
role: selectionMode === 'none' ? 'listitem' : 'option',
|
|
1384
|
-
'aria-selected': selectionMode === 'none' ? undefined : String(item.selected === true),
|
|
1385
|
-
'data-item-id': item.id,
|
|
1386
|
-
'data-label': item.label,
|
|
1387
|
-
'data-description': item.description,
|
|
1388
|
-
'data-meta': item.meta,
|
|
1389
|
-
'data-actionable': item.actionLabel === undefined ? undefined : '',
|
|
1390
|
-
},
|
|
1391
|
-
})),
|
|
1392
|
-
icons: options.items.map((item) => item.icon === true
|
|
1393
|
-
? createUiDomPlan('span', 'list-item-icon', {
|
|
1394
|
-
attrs: { 'aria-hidden': 'true', 'data-item-id': item.id },
|
|
1395
|
-
})
|
|
1396
|
-
: undefined),
|
|
1397
|
-
labels: options.items.map((item) => createUiDomPlan('span', 'list-item-label', {
|
|
1398
|
-
attrs: { 'data-label': item.label ?? item.id },
|
|
1399
|
-
})),
|
|
1400
|
-
descriptions: options.items.map((item) => item.description === undefined
|
|
1401
|
-
? undefined
|
|
1402
|
-
: createUiDomPlan('p', 'list-item-description', {
|
|
1403
|
-
attrs: { 'data-description': item.description },
|
|
1404
|
-
})),
|
|
1405
|
-
metas: options.items.map((item) => item.meta === undefined
|
|
1406
|
-
? undefined
|
|
1407
|
-
: createUiDomPlan('span', 'list-item-meta', {
|
|
1408
|
-
attrs: { 'data-meta': item.meta },
|
|
1409
|
-
})),
|
|
1410
|
-
actions: options.items.map((item) => item.actionLabel === undefined
|
|
1411
|
-
? undefined
|
|
1412
|
-
: createUiDomPlan('button', 'list-item-action', {
|
|
1413
|
-
attrs: {
|
|
1414
|
-
type: 'button',
|
|
1415
|
-
'aria-label': item.actionLabel,
|
|
1416
|
-
'data-item-id': item.id,
|
|
1417
|
-
},
|
|
1418
|
-
})),
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
export function createListGroupedItemActionStateContract(options) {
|
|
1422
|
-
const itemById = new Map(options.items.map((item) => [item.id, item]));
|
|
1423
|
-
const groupedIds = new Set();
|
|
1424
|
-
const groups = (options.groups ?? []).map((group) => {
|
|
1425
|
-
const itemIds = group.itemIds.filter((id) => {
|
|
1426
|
-
if (!itemById.has(id) || groupedIds.has(id))
|
|
1427
|
-
return false;
|
|
1428
|
-
groupedIds.add(id);
|
|
1429
|
-
return true;
|
|
1430
|
-
});
|
|
1431
|
-
const selectedCount = itemIds.filter((id) => itemById.get(id)?.selected === true).length;
|
|
1432
|
-
const selectionState = itemIds.length === 0
|
|
1433
|
-
? 'empty'
|
|
1434
|
-
: selectedCount === 0
|
|
1435
|
-
? 'none'
|
|
1436
|
-
: selectedCount === itemIds.length
|
|
1437
|
-
? 'all'
|
|
1438
|
-
: 'partial';
|
|
1439
|
-
return {
|
|
1440
|
-
id: group.id,
|
|
1441
|
-
label: group.label,
|
|
1442
|
-
itemIds,
|
|
1443
|
-
itemCount: itemIds.length,
|
|
1444
|
-
selectedCount,
|
|
1445
|
-
selectionState,
|
|
1446
|
-
attrs: {
|
|
1447
|
-
role: 'group',
|
|
1448
|
-
'aria-labelledby': group.headingId,
|
|
1449
|
-
'data-group-id': group.id,
|
|
1450
|
-
'data-group-selection-state': selectionState,
|
|
1451
|
-
'data-group-item-count': itemIds.length,
|
|
1452
|
-
'data-group-selected-count': selectedCount,
|
|
1453
|
-
},
|
|
1454
|
-
headingAttrs: {
|
|
1455
|
-
id: group.headingId,
|
|
1456
|
-
role: 'heading',
|
|
1457
|
-
'aria-level': 3,
|
|
1458
|
-
'data-group-id': group.id,
|
|
1459
|
-
'data-group-label': group.label,
|
|
1460
|
-
},
|
|
1461
|
-
};
|
|
1462
|
-
});
|
|
1463
|
-
const groupByItemId = new Map(groups.flatMap((group) => group.itemIds.map((itemId) => [itemId, group.id])));
|
|
1464
|
-
const disabledSet = new Set(options.actionDisabledIds ?? []);
|
|
1465
|
-
const hiddenSet = new Set(options.actionHiddenIds ?? []);
|
|
1466
|
-
const items = options.items.map((item) => {
|
|
1467
|
-
const actionable = item.actionLabel !== undefined;
|
|
1468
|
-
const actionState = !actionable || hiddenSet.has(item.id)
|
|
1469
|
-
? 'hidden'
|
|
1470
|
-
: item.disabled === true || disabledSet.has(item.id)
|
|
1471
|
-
? 'disabled'
|
|
1472
|
-
: 'ready';
|
|
1473
|
-
return {
|
|
1474
|
-
id: item.id,
|
|
1475
|
-
groupId: groupByItemId.get(item.id) ?? '',
|
|
1476
|
-
actionState,
|
|
1477
|
-
attrs: {
|
|
1478
|
-
'data-item-id': item.id,
|
|
1479
|
-
'data-group-id': groupByItemId.get(item.id),
|
|
1480
|
-
'data-action-state': actionState,
|
|
1481
|
-
},
|
|
1482
|
-
actionAttrs: {
|
|
1483
|
-
type: 'button',
|
|
1484
|
-
'data-item-id': item.id,
|
|
1485
|
-
'data-action-state': actionState,
|
|
1486
|
-
hidden: actionState === 'hidden' ? true : undefined,
|
|
1487
|
-
disabled: actionState === 'disabled' ? true : undefined,
|
|
1488
|
-
'aria-disabled': actionState === 'disabled' ? 'true' : undefined,
|
|
1489
|
-
},
|
|
1490
|
-
};
|
|
1491
|
-
});
|
|
1492
|
-
const actionableItems = items.filter((item) => itemById.get(item.id)?.actionLabel !== undefined);
|
|
1493
|
-
const readyActionIds = actionableItems
|
|
1494
|
-
.filter((item) => item.actionState === 'ready')
|
|
1495
|
-
.map((item) => item.id);
|
|
1496
|
-
const disabledActionIds = actionableItems
|
|
1497
|
-
.filter((item) => item.actionState === 'disabled')
|
|
1498
|
-
.map((item) => item.id);
|
|
1499
|
-
const hiddenActionIds = actionableItems
|
|
1500
|
-
.filter((item) => item.actionState === 'hidden')
|
|
1501
|
-
.map((item) => item.id);
|
|
1502
|
-
const state = options.items.length === 0
|
|
1503
|
-
? 'empty'
|
|
1504
|
-
: groups.length === 0
|
|
1505
|
-
? 'plain'
|
|
1506
|
-
: groupedIds.size === options.items.length
|
|
1507
|
-
? 'grouped'
|
|
1508
|
-
: 'partial';
|
|
1509
|
-
return {
|
|
1510
|
-
state,
|
|
1511
|
-
itemCount: options.items.length,
|
|
1512
|
-
groupCount: groups.length,
|
|
1513
|
-
groupedItemCount: groupedIds.size,
|
|
1514
|
-
actionCount: actionableItems.length,
|
|
1515
|
-
groupIds: groups.map((group) => group.id),
|
|
1516
|
-
readyActionIds,
|
|
1517
|
-
disabledActionIds,
|
|
1518
|
-
hiddenActionIds,
|
|
1519
|
-
attrs: {
|
|
1520
|
-
'data-list-grouped-item-action-contract': 'true',
|
|
1521
|
-
'data-list-grouped-state': state,
|
|
1522
|
-
'data-group-count': groups.length,
|
|
1523
|
-
'data-grouped-item-count': groupedIds.size,
|
|
1524
|
-
'data-group-ids': groups.map((group) => group.id).join(','),
|
|
1525
|
-
'data-action-count': actionableItems.length,
|
|
1526
|
-
'data-ready-action-ids': readyActionIds.join(','),
|
|
1527
|
-
'data-disabled-action-ids': disabledActionIds.join(','),
|
|
1528
|
-
'data-hidden-action-ids': hiddenActionIds.join(','),
|
|
1529
|
-
},
|
|
1530
|
-
groups,
|
|
1531
|
-
items,
|
|
1532
|
-
};
|
|
1533
|
-
}
|
|
1534
|
-
export function createCarouselPlans(options) {
|
|
1535
|
-
const slideCount = options.slides.length;
|
|
1536
|
-
const currentIndex = Math.max(0, options.slides.findIndex((slide) => slide.id === options.currentSlideId));
|
|
1537
|
-
const currentSlide = options.slides[currentIndex];
|
|
1538
|
-
const currentSlideId = currentSlide?.id ?? '';
|
|
1539
|
-
const state = slideCount === 0 ? 'empty' : 'ready';
|
|
1540
|
-
const playbackState = slideCount > 1 && options.playback === 'playing' ? 'playing' : 'paused';
|
|
1541
|
-
const previousTarget = currentIndex > 0 ? options.slides[currentIndex - 1] : undefined;
|
|
1542
|
-
const nextTarget = currentIndex < slideCount - 1 ? options.slides[currentIndex + 1] : undefined;
|
|
1543
|
-
const previousState = previousTarget === undefined ? 'disabled' : 'ready';
|
|
1544
|
-
const nextState = nextTarget === undefined ? 'disabled' : 'ready';
|
|
1545
|
-
const playbackDisabled = slideCount < 2;
|
|
1546
|
-
const rootId = options.id;
|
|
1547
|
-
const viewportId = rootId === undefined ? undefined : `${rootId}-viewport`;
|
|
1548
|
-
const trackId = rootId === undefined ? undefined : `${rootId}-track`;
|
|
1549
|
-
return {
|
|
1550
|
-
state,
|
|
1551
|
-
playbackState,
|
|
1552
|
-
currentSlideId,
|
|
1553
|
-
currentSlidePosition: currentSlide === undefined ? 0 : currentIndex + 1,
|
|
1554
|
-
slideCount,
|
|
1555
|
-
root: createUiDomPlan('section', 'carousel', {
|
|
1556
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1557
|
-
attrs: {
|
|
1558
|
-
id: rootId,
|
|
1559
|
-
role: 'region',
|
|
1560
|
-
'aria-roledescription': 'carousel',
|
|
1561
|
-
'aria-label': options.label,
|
|
1562
|
-
...options.attrs,
|
|
1563
|
-
'data-carousel-structure-playback-contract': 'true',
|
|
1564
|
-
'data-carousel-state': state,
|
|
1565
|
-
'data-playback-state': playbackState,
|
|
1566
|
-
'data-slide-count': slideCount,
|
|
1567
|
-
'data-slide-ids': options.slides.map((slide) => slide.id).join(','),
|
|
1568
|
-
'data-current-slide-id': currentSlideId,
|
|
1569
|
-
'data-current-slide-position': currentSlide === undefined ? 0 : currentIndex + 1,
|
|
1570
|
-
},
|
|
1571
|
-
}),
|
|
1572
|
-
viewport: createUiDomPlan('div', 'carousel-viewport', {
|
|
1573
|
-
attrs: {
|
|
1574
|
-
id: viewportId,
|
|
1575
|
-
'aria-live': playbackState === 'playing' ? 'off' : 'polite',
|
|
1576
|
-
'aria-atomic': 'true',
|
|
1577
|
-
'data-current-slide-id': currentSlideId,
|
|
1578
|
-
},
|
|
1579
|
-
}),
|
|
1580
|
-
track: createUiDomPlan('div', 'carousel-track', { attrs: { id: trackId } }),
|
|
1581
|
-
slides: options.slides.map((slide, index) => {
|
|
1582
|
-
const current = index === currentIndex;
|
|
1583
|
-
return createUiDomPlan('article', 'carousel-slide', {
|
|
1584
|
-
attrs: {
|
|
1585
|
-
id: slide.id,
|
|
1586
|
-
role: 'group',
|
|
1587
|
-
'aria-roledescription': 'slide',
|
|
1588
|
-
'aria-label': `${index + 1} of ${slideCount}: ${slide.label}`,
|
|
1589
|
-
'aria-current': current ? 'true' : undefined,
|
|
1590
|
-
'aria-hidden': current ? undefined : 'true',
|
|
1591
|
-
hidden: current ? undefined : true,
|
|
1592
|
-
'data-slide-id': slide.id,
|
|
1593
|
-
'data-slide-label': slide.label,
|
|
1594
|
-
'data-slide-state': current ? 'current' : 'inactive',
|
|
1595
|
-
},
|
|
1596
|
-
});
|
|
1597
|
-
}),
|
|
1598
|
-
controls: createUiDomPlan('div', 'carousel-controls', {
|
|
1599
|
-
attrs: { role: 'group', 'aria-label': 'Carousel controls' },
|
|
1600
|
-
}),
|
|
1601
|
-
previous: createUiDomPlan('button', 'carousel-control', {
|
|
1602
|
-
disabled: previousState === 'disabled',
|
|
1603
|
-
attrs: {
|
|
1604
|
-
type: 'button',
|
|
1605
|
-
'aria-label': options.previousLabel ?? 'Previous slide',
|
|
1606
|
-
'aria-controls': trackId,
|
|
1607
|
-
'data-control': 'previous',
|
|
1608
|
-
'data-carousel-control-state': previousState,
|
|
1609
|
-
'data-target-slide-id': previousTarget?.id,
|
|
1610
|
-
},
|
|
1611
|
-
}),
|
|
1612
|
-
next: createUiDomPlan('button', 'carousel-control', {
|
|
1613
|
-
disabled: nextState === 'disabled',
|
|
1614
|
-
attrs: {
|
|
1615
|
-
type: 'button',
|
|
1616
|
-
'aria-label': options.nextLabel ?? 'Next slide',
|
|
1617
|
-
'aria-controls': trackId,
|
|
1618
|
-
'data-control': 'next',
|
|
1619
|
-
'data-carousel-control-state': nextState,
|
|
1620
|
-
'data-target-slide-id': nextTarget?.id,
|
|
1621
|
-
},
|
|
1622
|
-
}),
|
|
1623
|
-
playback: createUiDomPlan('button', 'carousel-playback', {
|
|
1624
|
-
disabled: playbackDisabled,
|
|
1625
|
-
attrs: {
|
|
1626
|
-
type: 'button',
|
|
1627
|
-
'aria-label': playbackState === 'playing'
|
|
1628
|
-
? (options.pauseLabel ?? 'Pause carousel')
|
|
1629
|
-
: (options.playLabel ?? 'Play carousel'),
|
|
1630
|
-
'aria-controls': trackId,
|
|
1631
|
-
'aria-pressed': playbackState === 'playing' ? 'true' : 'false',
|
|
1632
|
-
'data-carousel-control-state': playbackDisabled ? 'disabled' : 'ready',
|
|
1633
|
-
'data-playback-state': playbackState,
|
|
1634
|
-
'data-next-playback-state': playbackState === 'playing' ? 'paused' : 'playing',
|
|
1635
|
-
},
|
|
1636
|
-
}),
|
|
1637
|
-
indicators: createUiDomPlan('div', 'carousel-indicators', {
|
|
1638
|
-
attrs: { role: 'group', 'aria-label': 'Choose slide' },
|
|
1639
|
-
}),
|
|
1640
|
-
indicatorButtons: options.slides.map((slide, index) => {
|
|
1641
|
-
const current = index === currentIndex;
|
|
1642
|
-
return createUiDomPlan('button', 'carousel-indicator', {
|
|
1643
|
-
disabled: current,
|
|
1644
|
-
attrs: {
|
|
1645
|
-
type: 'button',
|
|
1646
|
-
'aria-label': `Go to slide ${index + 1}: ${slide.label}`,
|
|
1647
|
-
'aria-controls': slide.id,
|
|
1648
|
-
'aria-current': current ? 'true' : undefined,
|
|
1649
|
-
'data-slide-id': slide.id,
|
|
1650
|
-
'data-slide-state': current ? 'current' : 'idle',
|
|
1651
|
-
},
|
|
1652
|
-
});
|
|
1653
|
-
}),
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
export function createSplitWorkspacePlans(options) {
|
|
1657
|
-
const fallback = options.tabletFallback ?? 'stack';
|
|
1658
|
-
return {
|
|
1659
|
-
root: createUiDomPlan('section', 'split-workspace', {
|
|
1660
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1661
|
-
attrs: {
|
|
1662
|
-
id: options.id,
|
|
1663
|
-
...options.attrs,
|
|
1664
|
-
'data-tablet-fallback': fallback,
|
|
1665
|
-
'data-areas': options.areas.length,
|
|
1666
|
-
},
|
|
1667
|
-
}),
|
|
1668
|
-
areas: options.areas.map((area) => createUiDomPlan('section', 'split-workspace-area', {
|
|
1669
|
-
attrs: {
|
|
1670
|
-
id: area.id,
|
|
1671
|
-
'data-area-role': area.role,
|
|
1672
|
-
'data-fallback': area.fallback ?? fallback,
|
|
1673
|
-
style: area.minWidth === undefined ? undefined : `--kui-area-min: ${area.minWidth};`,
|
|
1674
|
-
},
|
|
1675
|
-
})),
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
export function createSkeletonScreenPlans(options = {}) {
|
|
1679
|
-
const rowCount = Math.max(1, Math.trunc(options.rows ?? 4));
|
|
1680
|
-
return {
|
|
1681
|
-
root: createUiDomPlan('section', 'skeleton-screen', {
|
|
1682
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1683
|
-
...(options.density === undefined ? {} : { density: options.density }),
|
|
1684
|
-
loading: true,
|
|
1685
|
-
attrs: {
|
|
1686
|
-
id: options.id,
|
|
1687
|
-
role: 'status',
|
|
1688
|
-
'aria-label': options.label ?? 'Loading content',
|
|
1689
|
-
...options.attrs,
|
|
1690
|
-
'data-row-count': rowCount,
|
|
1691
|
-
'data-animated': options.animated === false ? 'false' : 'true',
|
|
1692
|
-
},
|
|
1693
|
-
}),
|
|
1694
|
-
rows: Array.from({ length: rowCount }, (_, index) => createSkeletonPrimitive({
|
|
1695
|
-
className: 'kui-skeleton-screen-row',
|
|
1696
|
-
attrs: {
|
|
1697
|
-
'data-index': index,
|
|
1698
|
-
style: `--kui-skeleton-width: ${skeletonRowWidth(index)}%;`,
|
|
1699
|
-
},
|
|
1700
|
-
})),
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
export function createSpinOverlayPlans(options = {}) {
|
|
1704
|
-
const open = options.open !== false;
|
|
1705
|
-
const mode = options.mode ?? 'blocking';
|
|
1706
|
-
return {
|
|
1707
|
-
root: createUiDomPlan('div', 'spin-overlay', {
|
|
1708
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1709
|
-
loading: open,
|
|
1710
|
-
state: open ? 'open' : 'closed',
|
|
1711
|
-
attrs: {
|
|
1712
|
-
id: options.id,
|
|
1713
|
-
role: 'status',
|
|
1714
|
-
'aria-label': options.label ?? 'Loading',
|
|
1715
|
-
'aria-live': 'polite',
|
|
1716
|
-
'aria-controls': options.targetId,
|
|
1717
|
-
hidden: open ? undefined : true,
|
|
1718
|
-
...options.attrs,
|
|
1719
|
-
'data-mode': mode,
|
|
1720
|
-
'data-target-id': options.targetId,
|
|
1721
|
-
},
|
|
1722
|
-
}),
|
|
1723
|
-
spinner: createSpinPrimitive({
|
|
1724
|
-
label: options.label ?? 'Loading',
|
|
1725
|
-
className: 'kui-spin-overlay-spinner',
|
|
1726
|
-
}),
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
export function createButtonLoadingPlans(options) {
|
|
1730
|
-
const button = createButtonPrimitive({
|
|
1731
|
-
label: options.label,
|
|
1732
|
-
...(options.loading === undefined ? {} : { loading: options.loading }),
|
|
1733
|
-
...(options.disabled === undefined ? {} : { disabled: options.disabled }),
|
|
1734
|
-
...(options.variant === undefined ? {} : { variant: options.variant }),
|
|
1735
|
-
...(options.size === undefined ? {} : { size: options.size }),
|
|
1736
|
-
className: classNames('kui-button-loading', options.className),
|
|
1737
|
-
attrs: {
|
|
1738
|
-
...(options.id === undefined ? {} : { id: options.id }),
|
|
1739
|
-
...options.attrs,
|
|
1740
|
-
'data-label': options.label,
|
|
1741
|
-
},
|
|
1742
|
-
});
|
|
1743
|
-
return {
|
|
1744
|
-
root: button,
|
|
1745
|
-
...(options.loading === true
|
|
1746
|
-
? {
|
|
1747
|
-
indicator: createSpinPrimitive({
|
|
1748
|
-
label: `${options.label} loading`,
|
|
1749
|
-
className: 'kui-button-loading-indicator',
|
|
1750
|
-
attrs: {
|
|
1751
|
-
id: options.id === undefined ? undefined : `${options.id}-loading`,
|
|
1752
|
-
},
|
|
1753
|
-
}),
|
|
1754
|
-
}
|
|
1755
|
-
: {}),
|
|
1756
|
-
label: createUiDomPlan('span', 'button-loading-label', {
|
|
1757
|
-
attrs: { 'data-label': options.label },
|
|
1758
|
-
}),
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
function styleSuffix(value) {
|
|
1762
|
-
if (typeof value !== 'string' || value.trim() === '')
|
|
1763
|
-
return '';
|
|
1764
|
-
return value.trim().endsWith(';') ? value.trim() : `${value.trim()};`;
|
|
1765
|
-
}
|
|
1766
|
-
function ariaSort(column) {
|
|
1767
|
-
if (column.sortable !== true)
|
|
1768
|
-
return undefined;
|
|
1769
|
-
if (column.sortDirection === 'ascending')
|
|
1770
|
-
return 'ascending';
|
|
1771
|
-
if (column.sortDirection === 'descending')
|
|
1772
|
-
return 'descending';
|
|
1773
|
-
return 'none';
|
|
1774
|
-
}
|
|
1775
|
-
function tableColumnStyle(column) {
|
|
1776
|
-
const parts = [];
|
|
1777
|
-
if (column.width !== undefined)
|
|
1778
|
-
parts.push(`width: ${column.width};`);
|
|
1779
|
-
if (column.minWidth !== undefined)
|
|
1780
|
-
parts.push(`min-width: ${column.minWidth};`);
|
|
1781
|
-
return parts.length === 0 ? undefined : parts.join('');
|
|
1782
|
-
}
|
|
1783
|
-
function filterChipLabel(filter) {
|
|
1784
|
-
if (filter.value === undefined || filter.value === '')
|
|
1785
|
-
return filter.label;
|
|
1786
|
-
return `${filter.label}: ${filter.value}`;
|
|
1787
|
-
}
|
|
1788
|
-
function tagLabel(options) {
|
|
1789
|
-
const parts = [options.label];
|
|
1790
|
-
if (options.value !== undefined && options.value !== '')
|
|
1791
|
-
parts.push(options.value);
|
|
1792
|
-
if (options.count !== undefined)
|
|
1793
|
-
parts.push(`${options.count}`);
|
|
1794
|
-
return parts.join(': ');
|
|
1795
|
-
}
|
|
1796
|
-
function typographyTag(variant) {
|
|
1797
|
-
if (variant === 'heading-lg')
|
|
1798
|
-
return 'h1';
|
|
1799
|
-
if (variant === 'heading-md')
|
|
1800
|
-
return 'h2';
|
|
1801
|
-
if (variant === 'heading-sm')
|
|
1802
|
-
return 'h3';
|
|
1803
|
-
if (variant === 'code')
|
|
1804
|
-
return 'code';
|
|
1805
|
-
if (variant === 'link')
|
|
1806
|
-
return 'a';
|
|
1807
|
-
return 'p';
|
|
1808
|
-
}
|
|
1809
|
-
function dividerInset(value) {
|
|
1810
|
-
if (value === true)
|
|
1811
|
-
return 'both';
|
|
1812
|
-
if (value === false || value === undefined)
|
|
1813
|
-
return undefined;
|
|
1814
|
-
return value;
|
|
1815
|
-
}
|
|
1816
|
-
function initialsFromName(name) {
|
|
1817
|
-
const parts = name
|
|
1818
|
-
.trim()
|
|
1819
|
-
.split(/\s+/)
|
|
1820
|
-
.filter((part) => part.length > 0);
|
|
1821
|
-
if (parts.length === 0)
|
|
1822
|
-
return '?';
|
|
1823
|
-
if (parts.length === 1)
|
|
1824
|
-
return parts[0]?.slice(0, 2) ?? '?';
|
|
1825
|
-
return `${parts[0]?.[0] ?? ''}${parts[parts.length - 1]?.[0] ?? ''}`;
|
|
1826
|
-
}
|
|
1827
|
-
function normalizeInitials(value) {
|
|
1828
|
-
const normalized = value.replace(/\s+/g, '').slice(0, 2).toUpperCase();
|
|
1829
|
-
return normalized === '' ? '?' : normalized;
|
|
1830
|
-
}
|
|
1831
|
-
function avatarImageState(options) {
|
|
1832
|
-
if (options.imageError !== undefined && options.imageError.length > 0)
|
|
1833
|
-
return 'error';
|
|
1834
|
-
return options.src === undefined || options.src === '' ? 'fallback' : 'loaded';
|
|
1835
|
-
}
|
|
1836
|
-
function formatShortcutLabel(keys) {
|
|
1837
|
-
return keys.join(' + ');
|
|
1838
|
-
}
|
|
1839
|
-
function getPaginationPageCount(options) {
|
|
1840
|
-
const explicit = normalizeCount(options.pageCount);
|
|
1841
|
-
if (explicit !== undefined && explicit > 0)
|
|
1842
|
-
return explicit;
|
|
1843
|
-
const total = normalizeCount(options.totalItems);
|
|
1844
|
-
const pageSize = normalizeCount(options.pageSize);
|
|
1845
|
-
if (total !== undefined && pageSize !== undefined && pageSize > 0) {
|
|
1846
|
-
return Math.max(1, Math.ceil(total / pageSize));
|
|
1847
|
-
}
|
|
1848
|
-
return 1;
|
|
1849
|
-
}
|
|
1850
|
-
function clampPage(page, pageCount) {
|
|
1851
|
-
if (!Number.isFinite(page))
|
|
1852
|
-
return 1;
|
|
1853
|
-
return Math.min(Math.max(1, Math.trunc(page)), Math.max(1, pageCount));
|
|
1854
|
-
}
|
|
1855
|
-
function createPaginationControl(control, page, disabled, label) {
|
|
1856
|
-
return createUiDomPlan('button', `pagination-${control}`, {
|
|
1857
|
-
disabled,
|
|
1858
|
-
state: disabled ? 'disabled' : 'idle',
|
|
1859
|
-
attrs: {
|
|
1860
|
-
type: 'button',
|
|
1861
|
-
'aria-label': label,
|
|
1862
|
-
'data-page': page,
|
|
1863
|
-
'data-control': control,
|
|
1864
|
-
},
|
|
1865
|
-
});
|
|
1866
|
-
}
|
|
1867
|
-
function createPaginationItemPlan(item, index, pageLabel) {
|
|
1868
|
-
if (item.kind === 'ellipsis') {
|
|
1869
|
-
return createUiDomPlan('span', 'pagination-ellipsis', {
|
|
1870
|
-
attrs: {
|
|
1871
|
-
'aria-hidden': 'true',
|
|
1872
|
-
'data-kind': 'ellipsis',
|
|
1873
|
-
'data-index': index,
|
|
1874
|
-
},
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
1877
|
-
const page = item.page ?? 1;
|
|
1878
|
-
return createUiDomPlan('button', 'pagination-page', {
|
|
1879
|
-
state: item.current === true ? 'current' : 'idle',
|
|
1880
|
-
attrs: {
|
|
1881
|
-
type: 'button',
|
|
1882
|
-
'aria-label': pageLabel?.(page) ?? `Page ${page}`,
|
|
1883
|
-
'aria-current': item.current === true ? 'page' : undefined,
|
|
1884
|
-
'data-kind': 'page',
|
|
1885
|
-
'data-page': page,
|
|
1886
|
-
},
|
|
1887
|
-
});
|
|
1888
|
-
}
|
|
1889
|
-
function createPaginationItemModel(item, index, plan, pageLabel) {
|
|
1890
|
-
const page = item.page ?? 1;
|
|
1891
|
-
const isPage = item.kind === 'page';
|
|
1892
|
-
return {
|
|
1893
|
-
id: String(index),
|
|
1894
|
-
className: plan?.className ?? '',
|
|
1895
|
-
kind: item.kind,
|
|
1896
|
-
page,
|
|
1897
|
-
state: item.kind === 'ellipsis' ? 'ellipsis' : item.current === true ? 'current' : 'idle',
|
|
1898
|
-
current: item.current === true ? 'page' : undefined,
|
|
1899
|
-
label: isPage ? (pageLabel?.(page) ?? `Page ${page}`) : '',
|
|
1900
|
-
};
|
|
1901
|
-
}
|
|
1902
|
-
function createNoteLikePlans(kind, options) {
|
|
1903
|
-
const tone = options.tone ?? 'info';
|
|
1904
|
-
return {
|
|
1905
|
-
root: createUiDomPlan('aside', kind, {
|
|
1906
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1907
|
-
state: tone,
|
|
1908
|
-
attrs: {
|
|
1909
|
-
id: options.id,
|
|
1910
|
-
role: tone === 'error' || tone === 'warning' ? 'alert' : 'note',
|
|
1911
|
-
'aria-labelledby': options.titleId,
|
|
1912
|
-
'aria-describedby': options.descriptionId,
|
|
1913
|
-
...options.attrs,
|
|
1914
|
-
'data-tone': tone,
|
|
1915
|
-
'data-dismissible': options.closeLabel === undefined ? undefined : '',
|
|
1916
|
-
'data-actionable': options.action === undefined ? undefined : '',
|
|
1917
|
-
},
|
|
1918
|
-
}),
|
|
1919
|
-
...(options.icon === false
|
|
1920
|
-
? {}
|
|
1921
|
-
: {
|
|
1922
|
-
icon: createUiDomPlan('span', `${kind}-icon`, {
|
|
1923
|
-
attrs: { 'aria-hidden': 'true', 'data-tone': tone },
|
|
1924
|
-
}),
|
|
1925
|
-
}),
|
|
1926
|
-
content: createUiDomPlan('div', `${kind}-content`),
|
|
1927
|
-
...(options.titleId === undefined
|
|
1928
|
-
? {}
|
|
1929
|
-
: { title: createUiDomPlan('strong', `${kind}-title`, { attrs: { id: options.titleId } }) }),
|
|
1930
|
-
...(options.descriptionId === undefined
|
|
1931
|
-
? {}
|
|
1932
|
-
: {
|
|
1933
|
-
description: createUiDomPlan('p', `${kind}-description`, {
|
|
1934
|
-
attrs: { id: options.descriptionId },
|
|
1935
|
-
}),
|
|
1936
|
-
}),
|
|
1937
|
-
...(options.action === undefined
|
|
1938
|
-
? {}
|
|
1939
|
-
: { actionButton: createDataDisplayActionButton(kind, options.action) }),
|
|
1940
|
-
...(options.closeLabel === undefined
|
|
1941
|
-
? {}
|
|
1942
|
-
: {
|
|
1943
|
-
closeButton: createUiDomPlan('button', `${kind}-close`, {
|
|
1944
|
-
attrs: {
|
|
1945
|
-
type: 'button',
|
|
1946
|
-
'aria-label': options.closeLabel,
|
|
1947
|
-
'data-display-close': '',
|
|
1948
|
-
},
|
|
1949
|
-
}),
|
|
1950
|
-
}),
|
|
1951
|
-
};
|
|
1952
|
-
}
|
|
1953
|
-
function createPanelLikePlans(kind, options) {
|
|
1954
|
-
const tone = options.tone ?? 'default';
|
|
1955
|
-
const actions = (options.actions ?? []).map((action) => createDataDisplayActionButton(kind, action));
|
|
1956
|
-
return {
|
|
1957
|
-
root: createUiDomPlan(kind === 'card' ? 'article' : 'section', kind, {
|
|
1958
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
1959
|
-
state: options.selected === true ? 'selected' : 'idle',
|
|
1960
|
-
attrs: {
|
|
1961
|
-
id: options.id,
|
|
1962
|
-
role: options.interactive === true ? 'button' : undefined,
|
|
1963
|
-
tabindex: options.interactive === true ? 0 : undefined,
|
|
1964
|
-
'aria-labelledby': options.titleId,
|
|
1965
|
-
'aria-describedby': options.descriptionId,
|
|
1966
|
-
'aria-selected': options.selected === undefined ? undefined : String(options.selected),
|
|
1967
|
-
...options.attrs,
|
|
1968
|
-
'data-tone': tone,
|
|
1969
|
-
'data-interactive': options.interactive === true ? 'true' : undefined,
|
|
1970
|
-
'data-action-count': actions.length,
|
|
1971
|
-
},
|
|
1972
|
-
}),
|
|
1973
|
-
...(options.titleId === undefined && options.descriptionId === undefined && actions.length === 0
|
|
1974
|
-
? {}
|
|
1975
|
-
: { header: createUiDomPlan('header', `${kind}-header`) }),
|
|
1976
|
-
...(options.titleId === undefined
|
|
1977
|
-
? {}
|
|
1978
|
-
: { title: createUiDomPlan('h3', `${kind}-title`, { attrs: { id: options.titleId } }) }),
|
|
1979
|
-
...(options.descriptionId === undefined
|
|
1980
|
-
? {}
|
|
1981
|
-
: {
|
|
1982
|
-
description: createUiDomPlan('p', `${kind}-description`, {
|
|
1983
|
-
attrs: { id: options.descriptionId },
|
|
1984
|
-
}),
|
|
1985
|
-
}),
|
|
1986
|
-
body: createUiDomPlan('div', `${kind}-body`),
|
|
1987
|
-
...(actions.length === 0 ? {} : { footer: createUiDomPlan('footer', `${kind}-footer`) }),
|
|
1988
|
-
actions,
|
|
1989
|
-
};
|
|
1990
|
-
}
|
|
1991
|
-
function createDataDisplayActionButton(component, action) {
|
|
1992
|
-
return createUiDomPlan('button', `${component}-action`, {
|
|
1993
|
-
...(action.disabled === undefined ? {} : { disabled: action.disabled }),
|
|
1994
|
-
state: action.disabled === true ? 'disabled' : 'idle',
|
|
1995
|
-
className: classNames(action.tone === undefined ? undefined : `kui-${component}-action--${action.tone}`),
|
|
1996
|
-
attrs: {
|
|
1997
|
-
type: 'button',
|
|
1998
|
-
'aria-label': action.label,
|
|
1999
|
-
'data-action-id': action.id,
|
|
2000
|
-
'data-tone': action.tone ?? 'default',
|
|
2001
|
-
'data-label': action.label,
|
|
2002
|
-
},
|
|
2003
|
-
});
|
|
2004
|
-
}
|
|
2005
|
-
function tableCellState(options) {
|
|
2006
|
-
if (options.loading === true)
|
|
2007
|
-
return 'loading';
|
|
2008
|
-
if (options.error === true)
|
|
2009
|
-
return 'error';
|
|
2010
|
-
if (options.disabled === true)
|
|
2011
|
-
return 'disabled';
|
|
2012
|
-
if (options.interactive === true || options.intent !== undefined)
|
|
2013
|
-
return 'interactive';
|
|
2014
|
-
return 'readonly';
|
|
2015
|
-
}
|
|
2016
|
-
function tableSelectionSummaryState(selectedCount, eligibleCount) {
|
|
2017
|
-
if (selectedCount === 0)
|
|
2018
|
-
return 'empty';
|
|
2019
|
-
if (eligibleCount !== undefined && eligibleCount > 0 && selectedCount >= eligibleCount)
|
|
2020
|
-
return 'all';
|
|
2021
|
-
return 'partial';
|
|
2022
|
-
}
|
|
2023
|
-
function formatTableSelectionSummary(options) {
|
|
2024
|
-
const parts = [`${options.selectedCount} selected`];
|
|
2025
|
-
if (options.eligibleCount !== undefined)
|
|
2026
|
-
parts.push(`${options.eligibleCount} eligible`);
|
|
2027
|
-
if (options.totalCount !== undefined && options.totalCount !== options.eligibleCount) {
|
|
2028
|
-
parts.push(`${options.totalCount} rows`);
|
|
2029
|
-
}
|
|
2030
|
-
return parts.join(' · ');
|
|
2031
|
-
}
|
|
2032
|
-
function tableBatchActionContract(action, selectedCount) {
|
|
2033
|
-
const state = tableBatchActionState(action, selectedCount);
|
|
2034
|
-
const reason = action.reason ??
|
|
2035
|
-
(action.requiresSelection === true && selectedCount === 0 ? 'Select rows first' : '');
|
|
2036
|
-
return {
|
|
2037
|
-
id: action.id,
|
|
2038
|
-
label: action.label,
|
|
2039
|
-
state,
|
|
2040
|
-
reason,
|
|
2041
|
-
attrs: {
|
|
2042
|
-
'data-action-id': action.id,
|
|
2043
|
-
'data-label': action.label,
|
|
2044
|
-
'data-tone': action.tone ?? 'secondary',
|
|
2045
|
-
'data-action-state': state,
|
|
2046
|
-
'data-requires-selection': action.requiresSelection === true ? 'true' : undefined,
|
|
2047
|
-
'data-disabled-reason': reason === '' ? undefined : reason,
|
|
2048
|
-
'aria-label': action.label,
|
|
2049
|
-
'aria-disabled': state === 'disabled' ? 'true' : undefined,
|
|
2050
|
-
'aria-busy': state === 'pending' ? 'true' : undefined,
|
|
2051
|
-
hidden: state === 'hidden' ? true : undefined,
|
|
2052
|
-
},
|
|
2053
|
-
};
|
|
2054
|
-
}
|
|
2055
|
-
function tableBatchActionState(action, selectedCount) {
|
|
2056
|
-
if (action.hidden === true)
|
|
2057
|
-
return 'hidden';
|
|
2058
|
-
if (action.pending === true)
|
|
2059
|
-
return 'pending';
|
|
2060
|
-
if (action.disabled === true || action.reason !== undefined)
|
|
2061
|
-
return 'disabled';
|
|
2062
|
-
if (action.requiresSelection === true && selectedCount === 0)
|
|
2063
|
-
return 'disabled';
|
|
2064
|
-
return 'available';
|
|
2065
|
-
}
|
|
2066
|
-
function normalizeCount(value) {
|
|
2067
|
-
if (value === undefined || !Number.isFinite(value))
|
|
2068
|
-
return undefined;
|
|
2069
|
-
return Math.max(0, Math.trunc(value));
|
|
2070
|
-
}
|
|
2071
|
-
function badgeCountOverflowLabel(options) {
|
|
2072
|
-
if (options.dot)
|
|
2073
|
-
return 'Badge dot';
|
|
2074
|
-
if (options.count <= 0)
|
|
2075
|
-
return 'No badge count';
|
|
2076
|
-
return options.overflow ? `${options.displayValue} items` : `${options.count} items`;
|
|
2077
|
-
}
|
|
2078
|
-
function normalizeSelectedIds(ids) {
|
|
2079
|
-
if (ids === undefined)
|
|
2080
|
-
return [];
|
|
2081
|
-
const values = Array.isArray(ids) ? ids : [...ids];
|
|
2082
|
-
return [...new Set(values.filter((id) => id.length > 0))];
|
|
2083
|
-
}
|
|
2084
|
-
function normalizeColumnPreferenceIds(ids, knownIds) {
|
|
2085
|
-
if (ids === undefined)
|
|
2086
|
-
return [];
|
|
2087
|
-
const result = [];
|
|
2088
|
-
const seen = new Set();
|
|
2089
|
-
for (const id of ids) {
|
|
2090
|
-
if (!knownIds.has(id) || seen.has(id))
|
|
2091
|
-
continue;
|
|
2092
|
-
seen.add(id);
|
|
2093
|
-
result.push(id);
|
|
2094
|
-
}
|
|
2095
|
-
return result;
|
|
2096
|
-
}
|
|
2097
|
-
function orderTableColumns(columns, orderIds) {
|
|
2098
|
-
if (orderIds.length === 0)
|
|
2099
|
-
return [...columns];
|
|
2100
|
-
const columnById = new Map(columns.map((column) => [column.id, column]));
|
|
2101
|
-
const orderedIdSet = new Set(orderIds);
|
|
2102
|
-
const ordered = orderIds
|
|
2103
|
-
.map((id) => columnById.get(id))
|
|
2104
|
-
.filter((column) => column !== undefined);
|
|
2105
|
-
const remaining = columns.filter((column) => !orderedIdSet.has(column.id));
|
|
2106
|
-
return [...ordered, ...remaining];
|
|
2107
|
-
}
|
|
2108
|
-
function tableColumnPreferenceSticky(column, stickyStartIds, stickyEndIds) {
|
|
2109
|
-
if (stickyStartIds === undefined && stickyEndIds === undefined)
|
|
2110
|
-
return column.sticky;
|
|
2111
|
-
if (stickyStartIds?.has(column.id) === true)
|
|
2112
|
-
return 'start';
|
|
2113
|
-
if (stickyEndIds?.has(column.id) === true)
|
|
2114
|
-
return 'end';
|
|
2115
|
-
return undefined;
|
|
2116
|
-
}
|
|
2117
|
-
function tableColumnPreferenceState(options) {
|
|
2118
|
-
if (options.sourceColumns.length === 0)
|
|
2119
|
-
return 'empty';
|
|
2120
|
-
const sourceOrder = options.sourceColumns.map((column) => column.id).join(',');
|
|
2121
|
-
const nextOrder = options.columns.map((column) => column.id).join(',');
|
|
2122
|
-
const densityChanged = options.defaultDensity !== undefined && options.density !== options.defaultDensity;
|
|
2123
|
-
if (densityChanged ||
|
|
2124
|
-
options.hiddenIds.length > 0 ||
|
|
2125
|
-
options.visibleIds !== undefined ||
|
|
2126
|
-
options.orderIds.length > 0 ||
|
|
2127
|
-
sourceOrder !== nextOrder ||
|
|
2128
|
-
options.stickyStartIds !== undefined ||
|
|
2129
|
-
options.stickyEndIds !== undefined) {
|
|
2130
|
-
return 'customized';
|
|
2131
|
-
}
|
|
2132
|
-
return 'default';
|
|
2133
|
-
}
|
|
2134
|
-
function tableToolbarState(options) {
|
|
2135
|
-
const visibleCount = options.filteredCount ?? options.totalCount;
|
|
2136
|
-
if (options.loading)
|
|
2137
|
-
return 'loading';
|
|
2138
|
-
if (visibleCount === 0)
|
|
2139
|
-
return 'empty';
|
|
2140
|
-
if (options.selectedCount > 0)
|
|
2141
|
-
return 'selected';
|
|
2142
|
-
if (options.query !== '' || options.activeFilterCount > 0 || options.sortDirection !== 'none') {
|
|
2143
|
-
return 'filtered';
|
|
2144
|
-
}
|
|
2145
|
-
return 'ready';
|
|
2146
|
-
}
|
|
2147
|
-
function normalizeEmptyOptions(options) {
|
|
2148
|
-
if (options === undefined || options === false)
|
|
2149
|
-
return undefined;
|
|
2150
|
-
if (options === true)
|
|
2151
|
-
return {};
|
|
2152
|
-
return options;
|
|
2153
|
-
}
|
|
2154
|
-
function skeletonRowWidth(index) {
|
|
2155
|
-
const widths = [92, 84, 78, 88, 72, 80];
|
|
2156
|
-
return widths[index % widths.length] ?? 80;
|
|
2157
|
-
}
|
|
2158
|
-
export function createDescriptionsPlans(options) {
|
|
2159
|
-
const layout = options.layout ?? 'horizontal';
|
|
2160
|
-
const items = options.items.map((item) => ({
|
|
2161
|
-
itemId: item.id,
|
|
2162
|
-
label: createUiDomPlan('dt', 'descriptions-label', {
|
|
2163
|
-
attrs: { id: `${options.id}-${item.id}-label`, 'data-label': item.label },
|
|
2164
|
-
}),
|
|
2165
|
-
value: createUiDomPlan('dd', 'descriptions-value', {
|
|
2166
|
-
attrs: {
|
|
2167
|
-
...(item.span === undefined ? {} : { 'data-span': String(item.span) }),
|
|
2168
|
-
...(item.value === undefined ? {} : { 'data-value': item.value }),
|
|
2169
|
-
},
|
|
2170
|
-
}),
|
|
2171
|
-
}));
|
|
2172
|
-
return {
|
|
2173
|
-
root: createUiDomPlan('dl', 'descriptions', {
|
|
2174
|
-
state: layout === 'vertical' ? 'vertical' : 'horizontal',
|
|
2175
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
2176
|
-
attrs: {
|
|
2177
|
-
id: `${options.id}-descriptions`,
|
|
2178
|
-
...(options.bordered === undefined
|
|
2179
|
-
? {}
|
|
2180
|
-
: { 'data-bordered': options.bordered ? 'true' : 'false' }),
|
|
2181
|
-
...(options.column === undefined ? {} : { 'data-column': String(options.column) }),
|
|
2182
|
-
...options.attrs,
|
|
2183
|
-
},
|
|
2184
|
-
}),
|
|
2185
|
-
items,
|
|
2186
|
-
};
|
|
2187
|
-
}
|
|
2188
|
-
export function createTimelinePlans(options) {
|
|
2189
|
-
const items = options.items.map((item) => {
|
|
2190
|
-
const state = item.state ?? 'default';
|
|
2191
|
-
return {
|
|
2192
|
-
itemId: item.id,
|
|
2193
|
-
state,
|
|
2194
|
-
title: createUiDomPlan('div', 'timeline-title', {
|
|
2195
|
-
attrs: { id: `${options.id}-${item.id}-title`, 'data-label': item.title },
|
|
2196
|
-
}),
|
|
2197
|
-
description: createUiDomPlan('div', 'timeline-description', {
|
|
2198
|
-
attrs: {
|
|
2199
|
-
id: `${options.id}-${item.id}-desc`,
|
|
2200
|
-
...(item.description === undefined ? {} : { 'data-label': item.description }),
|
|
2201
|
-
},
|
|
2202
|
-
}),
|
|
2203
|
-
time: createUiDomPlan('div', 'timeline-time', {
|
|
2204
|
-
attrs: {
|
|
2205
|
-
id: `${options.id}-${item.id}-time`,
|
|
2206
|
-
...(item.time === undefined ? {} : { 'data-label': item.time }),
|
|
2207
|
-
},
|
|
2208
|
-
}),
|
|
2209
|
-
};
|
|
2210
|
-
});
|
|
2211
|
-
// Timeline items carry state metadata (the root <li> elements are rendered by the app from items)
|
|
2212
|
-
return {
|
|
2213
|
-
root: createUiDomPlan('ul', 'timeline', {
|
|
2214
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
2215
|
-
attrs: { id: `${options.id}-timeline`, ...options.attrs },
|
|
2216
|
-
}),
|
|
2217
|
-
items,
|
|
2218
|
-
};
|
|
2219
|
-
}
|
|
2220
|
-
export function createImagePlans(options) {
|
|
2221
|
-
return {
|
|
2222
|
-
root: createUiDomPlan('figure', 'image', {
|
|
2223
|
-
state: options.preview === true ? 'preview' : 'plain',
|
|
2224
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
2225
|
-
attrs: { id: `${options.id}-image`, ...options.attrs },
|
|
2226
|
-
}),
|
|
2227
|
-
image: createUiDomPlan('img', 'image-figure', {
|
|
2228
|
-
attrs: {
|
|
2229
|
-
id: `${options.id}-img`,
|
|
2230
|
-
...(options.src === undefined ? {} : { src: options.src }),
|
|
2231
|
-
...(options.alt === undefined ? {} : { alt: options.alt }),
|
|
2232
|
-
...(options.preview === true ? { 'data-preview': 'true' } : {}),
|
|
2233
|
-
},
|
|
2234
|
-
}),
|
|
2235
|
-
overlay: createUiDomPlan('div', 'image-overlay', {
|
|
2236
|
-
state: 'hidden',
|
|
2237
|
-
attrs: { id: `${options.id}-overlay`, role: 'dialog', 'aria-hidden': 'true' },
|
|
2238
|
-
}),
|
|
2239
|
-
close: createUiDomPlan('button', 'image-overlay-close', {
|
|
2240
|
-
attrs: { id: `${options.id}-close`, type: 'button', 'aria-label': 'Close preview' },
|
|
2241
|
-
}),
|
|
2242
|
-
caption: createUiDomPlan('figcaption', 'image-caption', {
|
|
2243
|
-
attrs: {
|
|
2244
|
-
id: `${options.id}-caption`,
|
|
2245
|
-
...(options.caption === undefined ? {} : { 'data-label': options.caption }),
|
|
2246
|
-
},
|
|
2247
|
-
}),
|
|
2248
|
-
};
|
|
2249
|
-
}
|
|
2250
|
-
export function createBackTopPlans(options) {
|
|
2251
|
-
return {
|
|
2252
|
-
root: createUiDomPlan('button', 'back-top', {
|
|
2253
|
-
state: options.visible === true ? 'visible' : 'hidden',
|
|
2254
|
-
...(options.disabled === undefined ? {} : { disabled: options.disabled }),
|
|
2255
|
-
attrs: {
|
|
2256
|
-
id: `${options.id}-backtop`,
|
|
2257
|
-
type: 'button',
|
|
2258
|
-
'aria-label': 'Back to top',
|
|
2259
|
-
...(options.visible === true ? {} : { hidden: 'true' }),
|
|
2260
|
-
...options.attrs,
|
|
2261
|
-
},
|
|
2262
|
-
}),
|
|
2263
|
-
};
|
|
2264
|
-
}
|
|
2265
|
-
function escapeRegex(value) {
|
|
2266
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2267
|
-
}
|
|
2268
|
-
/**
|
|
2269
|
-
* Splits text into highlight/plain segments by query.
|
|
2270
|
-
* - Case-insensitive; supports multiple keywords (array); empty query/text returns a single plain segment.
|
|
2271
|
-
* - Overlapping hits are resolved by the earliest position (no nesting).
|
|
2272
|
-
*/
|
|
2273
|
-
export function splitHighlightSegments(text, query) {
|
|
2274
|
-
const keywords = (Array.isArray(query) ? query : [query])
|
|
2275
|
-
.map((value) => value.trim())
|
|
2276
|
-
.filter((value) => value !== '');
|
|
2277
|
-
if (text === '' || keywords.length === 0)
|
|
2278
|
-
return [{ text, highlighted: false }];
|
|
2279
|
-
const pattern = new RegExp(`(${keywords.map(escapeRegex).join('|')})`, 'gi');
|
|
2280
|
-
const segments = [];
|
|
2281
|
-
let lastIndex = 0;
|
|
2282
|
-
for (const match of text.matchAll(pattern)) {
|
|
2283
|
-
const index = match.index ?? 0;
|
|
2284
|
-
if (index > lastIndex) {
|
|
2285
|
-
segments.push({ text: text.slice(lastIndex, index), highlighted: false });
|
|
2286
|
-
}
|
|
2287
|
-
segments.push({ text: match[0], highlighted: true });
|
|
2288
|
-
lastIndex = index + match[0].length;
|
|
2289
|
-
}
|
|
2290
|
-
if (lastIndex < text.length) {
|
|
2291
|
-
segments.push({ text: text.slice(lastIndex), highlighted: false });
|
|
2292
|
-
}
|
|
2293
|
-
return segments.length === 0 ? [{ text, highlighted: false }] : segments;
|
|
2294
|
-
}
|
|
2295
|
-
/** Highlight-mark plan (used by the app for highlighted segments at render time). */
|
|
2296
|
-
export function createHighlightMark(text, id) {
|
|
2297
|
-
return createUiDomPlan('mark', 'highlight', {
|
|
2298
|
-
attrs: { ...(id === undefined ? {} : { id }), 'data-label': text },
|
|
2299
|
-
});
|
|
2300
|
-
}
|
|
2301
|
-
export function createCodeBlockPlans(options) {
|
|
2302
|
-
const code = createUiDomPlan('pre', 'code-block-code', {
|
|
2303
|
-
attrs: {
|
|
2304
|
-
id: `${options.id}-code`,
|
|
2305
|
-
...(options.code === undefined ? {} : { 'data-code': options.code }),
|
|
2306
|
-
},
|
|
2307
|
-
});
|
|
2308
|
-
return {
|
|
2309
|
-
root: createUiDomPlan('figure', 'code-block', {
|
|
2310
|
-
...(options.className === undefined ? {} : { className: options.className }),
|
|
2311
|
-
attrs: { id: `${options.id}-codeblock`, ...options.attrs },
|
|
2312
|
-
}),
|
|
2313
|
-
header: createUiDomPlan('div', 'code-block-header', {
|
|
2314
|
-
attrs: { id: `${options.id}-header` },
|
|
2315
|
-
}),
|
|
2316
|
-
language: createUiDomPlan('span', 'code-block-language', {
|
|
2317
|
-
attrs: {
|
|
2318
|
-
id: `${options.id}-lang`,
|
|
2319
|
-
...(options.language === undefined
|
|
2320
|
-
? {}
|
|
2321
|
-
: { 'data-label': options.language, 'data-language': options.language }),
|
|
2322
|
-
},
|
|
2323
|
-
}),
|
|
2324
|
-
copy: createUiDomPlan('button', 'code-block-copy', {
|
|
2325
|
-
attrs: {
|
|
2326
|
-
id: `${options.id}-copy`,
|
|
2327
|
-
type: 'button',
|
|
2328
|
-
'aria-label': 'Copy code',
|
|
2329
|
-
...(options.copyable === false ? { hidden: 'true' } : {}),
|
|
2330
|
-
},
|
|
2331
|
-
}),
|
|
2332
|
-
code,
|
|
2333
|
-
...(options.showLineNumbers === true
|
|
2334
|
-
? {
|
|
2335
|
-
lineNumbers: createUiDomPlan('div', 'code-block-line-numbers', {
|
|
2336
|
-
attrs: { id: `${options.id}-lines` },
|
|
2337
|
-
}),
|
|
2338
|
-
}
|
|
2339
|
-
: {}),
|
|
2340
|
-
};
|
|
2341
|
-
}
|