@haiyue/ui 0.2.2 → 0.3.1

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.
Files changed (145) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +523 -4
  3. package/dist/adapters/web/controls.js +48 -8
  4. package/dist/adapters/web/renderer.js +9 -11
  5. package/dist/adapters/web/styles.d.ts +2 -3
  6. package/dist/adapters/web/styles.js +26 -23
  7. package/dist/alert.d.ts +39 -0
  8. package/dist/alert.js +144 -0
  9. package/dist/anchor.d.ts +62 -0
  10. package/dist/anchor.js +293 -0
  11. package/dist/auto-complete.d.ts +83 -0
  12. package/dist/auto-complete.js +267 -0
  13. package/dist/avatar.d.ts +45 -0
  14. package/dist/avatar.js +135 -0
  15. package/dist/badge.js +5 -5
  16. package/dist/border-beam.js +3 -2
  17. package/dist/breadcrumb.js +5 -5
  18. package/dist/button-group.js +8 -8
  19. package/dist/button.js +10 -10
  20. package/dist/card.d.ts +29 -0
  21. package/dist/card.js +101 -0
  22. package/dist/carousel.js +6 -6
  23. package/dist/cascader.js +19 -13
  24. package/dist/checkbox.d.ts +12 -0
  25. package/dist/checkbox.js +22 -6
  26. package/dist/collapse.js +6 -6
  27. package/dist/context-menu.js +3 -4
  28. package/dist/core/actions.js +7 -8
  29. package/dist/core/data.d.ts +1 -1
  30. package/dist/core/data.js +44 -10
  31. package/dist/core/platform-view.js +8 -2
  32. package/dist/core/selection.js +4 -4
  33. package/dist/core/semantics.d.ts +26 -0
  34. package/dist/core/semantics.js +8 -0
  35. package/dist/core/text.js +3 -3
  36. package/dist/core/validation.d.ts +3 -1
  37. package/dist/core/validation.js +23 -5
  38. package/dist/date-picker.js +19 -13
  39. package/dist/descriptions.d.ts +44 -0
  40. package/dist/descriptions.js +169 -0
  41. package/dist/dialog.d.ts +4 -0
  42. package/dist/dialog.js +48 -27
  43. package/dist/divider.js +2 -2
  44. package/dist/draggable.js +5 -3
  45. package/dist/drawer.js +16 -24
  46. package/dist/dropdown.js +3 -4
  47. package/dist/empty.d.ts +20 -0
  48. package/dist/empty.js +58 -0
  49. package/dist/expandable.js +4 -4
  50. package/dist/form-item.d.ts +60 -0
  51. package/dist/form-item.js +212 -0
  52. package/dist/form.d.ts +41 -0
  53. package/dist/form.js +154 -0
  54. package/dist/history-controls.js +5 -5
  55. package/dist/image-preview.d.ts +22 -0
  56. package/dist/image-preview.js +38 -0
  57. package/dist/image.d.ts +52 -0
  58. package/dist/image.js +152 -0
  59. package/dist/index.d.ts +48 -0
  60. package/dist/index.js +72 -0
  61. package/dist/input.d.ts +11 -0
  62. package/dist/input.js +32 -18
  63. package/dist/internal/anchored-popup.d.ts +19 -0
  64. package/dist/internal/anchored-popup.js +89 -0
  65. package/dist/internal/focus.d.ts +2 -0
  66. package/dist/internal/focus.js +31 -0
  67. package/dist/internal/form-control.d.ts +22 -0
  68. package/dist/internal/form-control.js +52 -0
  69. package/dist/internal/image-viewer.d.ts +51 -0
  70. package/dist/internal/image-viewer.js +210 -0
  71. package/dist/internal/keyboard.d.ts +2 -0
  72. package/dist/internal/keyboard.js +12 -0
  73. package/dist/internal/numbers.d.ts +2 -0
  74. package/dist/internal/numbers.js +8 -0
  75. package/dist/internal/pagination.d.ts +35 -0
  76. package/dist/internal/pagination.js +169 -0
  77. package/dist/internal/popover-base.d.ts +87 -0
  78. package/dist/internal/popover-base.js +365 -0
  79. package/dist/internal/presentation.d.ts +2 -0
  80. package/dist/internal/presentation.js +28 -0
  81. package/dist/mentions.d.ts +115 -0
  82. package/dist/mentions.js +485 -0
  83. package/dist/menu-shared.d.ts +1 -1
  84. package/dist/menu-shared.js +3 -3
  85. package/dist/menu.d.ts +63 -0
  86. package/dist/menu.js +339 -0
  87. package/dist/modal.js +11 -40
  88. package/dist/notification.js +11 -10
  89. package/dist/pagination.d.ts +34 -0
  90. package/dist/pagination.js +73 -0
  91. package/dist/popconfirm.d.ts +6 -0
  92. package/dist/popconfirm.js +7 -0
  93. package/dist/popover.d.ts +6 -0
  94. package/dist/popover.js +7 -0
  95. package/dist/portable/page.js +25 -14
  96. package/dist/progress.d.ts +30 -0
  97. package/dist/progress.js +102 -0
  98. package/dist/qr-code.js +3 -3
  99. package/dist/radio.d.ts +10 -0
  100. package/dist/radio.js +18 -5
  101. package/dist/range.js +7 -7
  102. package/dist/rate.js +3 -3
  103. package/dist/resizable.js +8 -5
  104. package/dist/result.d.ts +22 -0
  105. package/dist/result.js +88 -0
  106. package/dist/ribbon.d.ts +19 -0
  107. package/dist/ribbon.js +106 -0
  108. package/dist/segmented.d.ts +39 -0
  109. package/dist/segmented.js +192 -0
  110. package/dist/select.d.ts +12 -0
  111. package/dist/select.js +31 -13
  112. package/dist/skeleton.js +10 -10
  113. package/dist/spin.d.ts +26 -0
  114. package/dist/spin.js +80 -0
  115. package/dist/steps.js +13 -13
  116. package/dist/switch.d.ts +44 -0
  117. package/dist/switch.js +104 -0
  118. package/dist/table.d.ts +3 -3
  119. package/dist/table.js +110 -128
  120. package/dist/tabs.js +7 -7
  121. package/dist/tag.js +8 -8
  122. package/dist/time-picker.js +16 -10
  123. package/dist/timeline.js +12 -12
  124. package/dist/toast.js +12 -11
  125. package/dist/tooltip.d.ts +6 -0
  126. package/dist/tooltip.js +107 -6
  127. package/dist/tour.js +26 -17
  128. package/dist/tree-model.d.ts +2 -0
  129. package/dist/tree-model.js +32 -11
  130. package/dist/tree-node.js +2 -2
  131. package/dist/tree-select.d.ts +94 -0
  132. package/dist/tree-select.js +398 -0
  133. package/dist/tree.d.ts +0 -2
  134. package/dist/tree.js +14 -29
  135. package/dist/upload.d.ts +108 -0
  136. package/dist/upload.js +358 -0
  137. package/dist/virtual-keyboard.d.ts +1 -0
  138. package/dist/virtual-keyboard.js +72 -41
  139. package/dist/virtual-list.d.ts +1 -0
  140. package/dist/virtual-list.js +25 -8
  141. package/dist/virtual-mouse.js +7 -6
  142. package/dist/watermark.js +2 -1
  143. package/package.json +82 -1
  144. package/themes/haiyue-dark.css +51 -0
  145. package/themes/haiyue-light.css +51 -0
@@ -0,0 +1,398 @@
1
+ import { HYAnchoredPopup, HY_COMBOBOX_STYLES } from './internal/anchored-popup.js';
2
+ let treeSelectId = 0;
3
+ export class HYTreeSelect extends HTMLElement {
4
+ static formAssociated = true;
5
+ _internals = this.attachInternals();
6
+ _control = document.createElement('div');
7
+ _tags = document.createElement('span');
8
+ _input = document.createElement('input');
9
+ _clear = document.createElement('button');
10
+ _panel = document.createElement('div');
11
+ _tree = document.createElement('div');
12
+ _status = document.createElement('div');
13
+ _id = `hy-tree-select-${++treeSelectId}`;
14
+ _popup = new HYAnchoredPopup(this, this._control, this._panel, () => this._setOpen(false));
15
+ _options = [];
16
+ _entries = new Map();
17
+ _expanded = new Set();
18
+ _visible = [];
19
+ _active = '';
20
+ _query = '';
21
+ _composing = false;
22
+ _formDisabled = false;
23
+ _initialValues = null;
24
+ _listeners = null;
25
+ _customError = '';
26
+ static get observedAttributes() { return ['options', 'value', 'multiple', 'expanded-keys', 'open', 'disabled', 'readonly', 'searchable', 'clearable', 'required', 'loading', 'name', 'placeholder', 'aria-label', 'not-found-content']; }
27
+ constructor() {
28
+ super();
29
+ const root = this.attachShadow({ mode: 'open' });
30
+ const style = document.createElement('style');
31
+ style.textContent = HY_COMBOBOX_STYLES + `
32
+ .control { flex-wrap: wrap; cursor: text; } .tags { display: contents; } .tag { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; margin-block: 3px; padding-inline: 5px; border-radius: var(--hy-radius-xs, 2px); background: var(--hy-hover-bg-color, #273241); }
33
+ .tag-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .tag button { border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; }
34
+ .option { display: flex; align-items: center; gap: 4px; padding-inline-start: calc(var(--_depth, 0) * 16px + 4px); }
35
+ .toggle { width: 22px; flex: 0 0 22px; height: 24px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
36
+ .check { flex: 0 0 14px; width: 14px; height: 14px; display: grid; place-items: center; border: 1px solid var(--hy-border-color, #303746); border-radius: 2px; }
37
+ [aria-checked="true"] .check { background: var(--hy-accent-strong-color, #554cc6); color: var(--hy-selected-text-color, #fff); } .label { min-width: 0; overflow-wrap: anywhere; }
38
+ `;
39
+ this._control.className = 'control';
40
+ this._control.part.add('control');
41
+ this._tags.className = 'tags';
42
+ this._tags.part.add('tags');
43
+ this._input.type = 'text';
44
+ this._input.autocomplete = 'off';
45
+ this._input.part.add('input');
46
+ this._input.setAttribute('role', 'combobox');
47
+ this._input.setAttribute('aria-haspopup', 'tree');
48
+ this._input.setAttribute('aria-controls', this._id);
49
+ this._input.setAttribute('aria-autocomplete', 'list');
50
+ this._clear.type = 'button';
51
+ this._clear.className = 'clear';
52
+ this._clear.textContent = '×';
53
+ this._clear.part.add('clear');
54
+ this._clear.setAttribute('aria-label', 'Clear selection');
55
+ this._panel.className = 'panel';
56
+ this._panel.part.add('panel');
57
+ this._tree.id = this._id;
58
+ this._tree.setAttribute('role', 'tree');
59
+ this._tree.part.add('tree');
60
+ this._status.className = 'status';
61
+ this._status.part.add('status');
62
+ this._status.setAttribute('role', 'status');
63
+ this._panel.append(this._tree, this._status);
64
+ this._control.append(this._tags, this._input, this._clear);
65
+ root.append(style, this._control, this._panel);
66
+ }
67
+ connectedCallback() {
68
+ this._initialValues ??= this.values;
69
+ this._listeners?.abort();
70
+ this._listeners = new AbortController();
71
+ const { signal } = this._listeners;
72
+ this._input.addEventListener('focus', () => this._setOpen(true), { signal });
73
+ this._input.addEventListener('click', () => this._setOpen(true), { signal });
74
+ this._input.addEventListener('blur', () => this._setOpen(false), { signal });
75
+ this._input.addEventListener('keydown', this._onKeydown, { signal });
76
+ this._input.addEventListener('input', () => { this._query = this._input.value; this._active = ''; this._setOpen(true); this._render(); if (!this._composing)
77
+ this._emitSearch(); }, { signal });
78
+ this._input.addEventListener('compositionstart', () => { this._composing = true; }, { signal });
79
+ this._input.addEventListener('compositionend', () => { this._composing = false; this._query = this._input.value; this._render(); this._emitSearch(); }, { signal });
80
+ this._panel.addEventListener('pointerdown', event => event.preventDefault(), { signal });
81
+ this._panel.addEventListener('click', this._onTreeClick, { signal });
82
+ this._clear.addEventListener('click', () => { if (this._disabled || this.readOnly)
83
+ return; this._query = ''; this._commit([]); this._input.focus(); this._setOpen(false); this.dispatchEvent(new Event('clear', { bubbles: true, composed: true })); }, { signal });
84
+ this._tags.addEventListener('click', event => { const button = event.target instanceof Element ? event.target.closest('button[data-remove]') : null; if (button && !this._disabled && !this.readOnly)
85
+ this._commit(this.values.filter(value => value !== button.dataset.remove)); }, { signal });
86
+ this._popup.connect();
87
+ this._sync();
88
+ }
89
+ disconnectedCallback() { this._listeners?.abort(); this._listeners = null; this._popup.dispose(); this._composing = false; }
90
+ attributeChangedCallback(name, previous, next) {
91
+ if (previous === next)
92
+ return;
93
+ if (name === 'options') {
94
+ let value = [];
95
+ try {
96
+ value = JSON.parse(next ?? '[]');
97
+ }
98
+ catch { /* Invalid options are empty. */ }
99
+ this._setOptions(value);
100
+ }
101
+ if (name === 'expanded-keys') {
102
+ try {
103
+ const value = JSON.parse(next ?? '[]');
104
+ this._expanded = new Set(Array.isArray(value) ? value.filter((key) => typeof key === 'string') : []);
105
+ }
106
+ catch {
107
+ this._expanded.clear();
108
+ }
109
+ }
110
+ this._sync();
111
+ if (this._disabled || this.readOnly)
112
+ this._setOpen(false);
113
+ }
114
+ get options() { return this._options.map(cloneOption); }
115
+ set options(value) { this._setOptions(value); this._sync(); }
116
+ get values() { const raw = this.getAttribute('value') ?? ''; if (!this.multiple)
117
+ return raw ? [raw] : []; try {
118
+ const value = JSON.parse(raw || '[]');
119
+ return Array.isArray(value) ? [...new Set(value.filter((item) => typeof item === 'string' && item.length > 0))] : raw ? [raw] : [];
120
+ }
121
+ catch {
122
+ return raw ? [raw] : [];
123
+ } }
124
+ set values(value) { this.value = this.multiple ? value : value[0] ?? ''; }
125
+ get value() { return this.multiple ? this.values : this.values[0] ?? ''; }
126
+ set value(value) { const values = Array.isArray(value) ? value : value ? [String(value)] : []; this.setAttribute('value', this.multiple ? JSON.stringify([...new Set(values)]) : values[0] ?? ''); }
127
+ get multiple() { return this.hasAttribute('multiple'); }
128
+ set multiple(value) { const values = this.values; this.toggleAttribute('multiple', value); this.values = values; }
129
+ get disabled() { return this.hasAttribute('disabled'); }
130
+ set disabled(value) { this.toggleAttribute('disabled', value); }
131
+ get readOnly() { return this.hasAttribute('readonly'); }
132
+ set readOnly(value) { this.toggleAttribute('readonly', value); }
133
+ get searchable() { return this.getAttribute('searchable') !== 'false'; }
134
+ set searchable(value) { this.setAttribute('searchable', String(value)); }
135
+ get clearable() { return this.getAttribute('clearable') !== 'false'; }
136
+ set clearable(value) { this.setAttribute('clearable', String(value)); }
137
+ get loading() { return this.hasAttribute('loading'); }
138
+ set loading(value) { this.toggleAttribute('loading', value); }
139
+ get open() { return this.hasAttribute('open'); }
140
+ set open(value) { this._setOpen(value); }
141
+ get expandedKeys() { return [...this._expanded]; }
142
+ set expandedKeys(value) { this.setAttribute('expanded-keys', JSON.stringify(value)); }
143
+ get placeholder() { return this.getAttribute('placeholder') ?? 'Select an item'; }
144
+ set placeholder(value) { this.setAttribute('placeholder', value); }
145
+ get form() { return this._internals.form; }
146
+ get validity() { return this._internals.validity; }
147
+ get validationMessage() { return this._internals.validationMessage; }
148
+ checkValidity() { return this._internals.checkValidity(); }
149
+ reportValidity() { return this._internals.reportValidity(); }
150
+ setCustomValidity(message) { this._customError = message; this._syncForm(); }
151
+ formDisabledCallback(disabled) { this._formDisabled = disabled; this._sync(); if (disabled)
152
+ this._setOpen(false); }
153
+ formResetCallback() { this.values = this._initialValues ?? []; this._query = ''; this._customError = ''; this._setOpen(false); this._sync(); }
154
+ formStateRestoreCallback(state) { if (typeof state === 'string') {
155
+ try {
156
+ const values = JSON.parse(state);
157
+ if (Array.isArray(values))
158
+ this.values = values.filter((value) => typeof value === 'string');
159
+ }
160
+ catch {
161
+ this.value = state;
162
+ }
163
+ } }
164
+ focus(options) { this._input.focus(options); }
165
+ blur() { this._input.blur(); }
166
+ get _disabled() { return this.disabled || this._formDisabled; }
167
+ _setOptions(value) {
168
+ this._options = normalizeTree(value);
169
+ this._entries.clear();
170
+ const build = (options, parent, depth, disabled) => options.flatMap((option, position) => {
171
+ const row = document.createElement('div');
172
+ row.className = 'option';
173
+ row.part.add('option');
174
+ row.id = `${this._id}-${this._entries.size}`;
175
+ row.dataset.value = option.value;
176
+ row.setAttribute('role', 'treeitem');
177
+ row.style.setProperty('--_depth', String(depth));
178
+ row.setAttribute('aria-level', String(depth + 1));
179
+ row.setAttribute('aria-posinset', String(position + 1));
180
+ row.setAttribute('aria-setsize', String(options.length));
181
+ const toggle = document.createElement('button');
182
+ toggle.type = 'button';
183
+ toggle.className = 'toggle';
184
+ toggle.part.add('toggle');
185
+ toggle.tabIndex = -1;
186
+ toggle.dataset.toggle = option.value;
187
+ toggle.textContent = option.children?.length ? '›' : '';
188
+ toggle.setAttribute('aria-label', `Expand ${option.label}`);
189
+ toggle.disabled = !option.children?.length || disabled || Boolean(option.disabled);
190
+ const check = document.createElement('span');
191
+ check.className = 'check';
192
+ check.setAttribute('aria-hidden', 'true');
193
+ const label = document.createElement('span');
194
+ label.className = 'label';
195
+ label.textContent = option.label;
196
+ row.append(toggle, check, label);
197
+ const entry = { option, parent, depth, disabled: disabled || Boolean(option.disabled), row, toggle };
198
+ this._entries.set(option.value, entry);
199
+ if (option.expanded)
200
+ this._expanded.add(option.value);
201
+ return [row, ...build(option.children ?? [], option.value, depth + 1, entry.disabled)];
202
+ });
203
+ this._tree.replaceChildren(...build(this._options, null, 0, false));
204
+ }
205
+ _sync() {
206
+ if (this._input.disabled !== this._disabled)
207
+ this._input.disabled = this._disabled;
208
+ this._input.readOnly = !this.searchable || this.readOnly;
209
+ this._control.classList.toggle('disabled', this._disabled);
210
+ const text = this.open ? this._query : this.multiple ? '' : this._entries.get(this.values[0] ?? '')?.option.label ?? this.values[0] ?? '';
211
+ if (this._input.value !== text)
212
+ this._input.value = text;
213
+ if (this._input.placeholder !== this.placeholder)
214
+ this._input.placeholder = this.placeholder;
215
+ this._input.setAttribute('aria-label', this.getAttribute('aria-label') || 'Tree selection');
216
+ this._clear.hidden = !this.clearable || !this.values.length || this.readOnly;
217
+ this._clear.disabled = this._disabled;
218
+ const tagKey = JSON.stringify(this.multiple ? this.values.map(value => [value, this._entries.get(value)?.option.label ?? value]) : []);
219
+ if (this._tags.dataset.values !== tagKey) {
220
+ this._tags.dataset.values = tagKey;
221
+ this._tags.replaceChildren(...(this.multiple ? this.values : []).map(value => { const tag = document.createElement('span'); tag.className = 'tag'; tag.part.add('tag'); const label = document.createElement('span'); label.className = 'tag-label'; label.textContent = this._entries.get(value)?.option.label ?? value; const remove = document.createElement('button'); remove.type = 'button'; remove.textContent = '×'; remove.dataset.remove = value; remove.setAttribute('aria-label', `Remove ${label.textContent}`); tag.append(label, remove); return tag; }));
222
+ }
223
+ for (const button of this._tags.querySelectorAll('button'))
224
+ button.disabled = this._disabled || this.readOnly;
225
+ this._syncForm();
226
+ this._render();
227
+ }
228
+ _syncForm() {
229
+ const name = this.getAttribute('name') ?? '';
230
+ const values = this.values;
231
+ if (this._disabled)
232
+ this._internals.setFormValue(null, JSON.stringify(values));
233
+ else if (this.multiple) {
234
+ const data = new FormData();
235
+ for (const value of values)
236
+ if (name)
237
+ data.append(name, value);
238
+ this._internals.setFormValue(data, JSON.stringify(values));
239
+ }
240
+ else
241
+ this._internals.setFormValue(values[0] ?? '', JSON.stringify(values));
242
+ const missing = !this._disabled && this.hasAttribute('required') && !values.length;
243
+ this._internals.setValidity(this._disabled ? {} : this._customError ? { customError: true } : missing ? { valueMissing: true } : {}, this._disabled ? '' : this._customError || (missing ? 'Select an item' : ''), this._input);
244
+ }
245
+ _render() {
246
+ const query = this._query.toLocaleLowerCase();
247
+ const matches = new Set();
248
+ if (query)
249
+ for (const entry of this._entries.values())
250
+ if (entry.option.label.toLocaleLowerCase().includes(query) || entry.option.value.toLocaleLowerCase().includes(query)) {
251
+ let key = entry.option.value;
252
+ while (key) {
253
+ matches.add(key);
254
+ key = this._entries.get(key)?.parent ?? null;
255
+ }
256
+ }
257
+ const visible = new Set();
258
+ this._visible = [];
259
+ for (const entry of this._entries.values()) {
260
+ const show = !this.loading && (query ? matches.has(entry.option.value) : !entry.parent || visible.has(entry.parent) && this._expanded.has(entry.parent));
261
+ entry.row.hidden = !show;
262
+ if (show) {
263
+ visible.add(entry.option.value);
264
+ this._visible.push(entry);
265
+ }
266
+ entry.row.setAttribute('aria-disabled', String(entry.disabled || entry.option.selectable === false && !entry.option.children?.length));
267
+ const selected = this.values.includes(entry.option.value);
268
+ entry.row.setAttribute(this.multiple ? 'aria-checked' : 'aria-selected', String(selected));
269
+ entry.row.removeAttribute(this.multiple ? 'aria-selected' : 'aria-checked');
270
+ const check = entry.row.querySelector('.check');
271
+ check.hidden = !this.multiple;
272
+ if (check.textContent !== (selected ? '✓' : ''))
273
+ check.textContent = selected ? '✓' : '';
274
+ const expanded = Boolean(query) || this._expanded.has(entry.option.value);
275
+ if (entry.option.children?.length)
276
+ entry.row.setAttribute('aria-expanded', String(expanded));
277
+ else
278
+ entry.row.removeAttribute('aria-expanded');
279
+ const symbol = entry.option.children?.length ? expanded ? '⌄' : '›' : '';
280
+ if (entry.toggle.textContent !== symbol)
281
+ entry.toggle.textContent = symbol;
282
+ entry.toggle.setAttribute('aria-label', `${expanded ? 'Collapse' : 'Expand'} ${entry.option.label}`);
283
+ }
284
+ if (!this._visible.some(entry => entry.option.value === this._active && !entry.disabled))
285
+ this._active = this._visible.find(entry => !entry.disabled)?.option.value ?? '';
286
+ const message = this.loading ? 'Loading…' : this.getAttribute('not-found-content') ?? 'No results';
287
+ if (this._status.textContent !== message)
288
+ this._status.textContent = message;
289
+ this._status.hidden = this._visible.length > 0;
290
+ this._tree.setAttribute('aria-label', this.getAttribute('aria-label') || 'Options');
291
+ this._tree.setAttribute('aria-multiselectable', String(this.multiple));
292
+ this._tree.setAttribute('aria-busy', String(this.loading));
293
+ const show = this.open && !this._disabled && !this.readOnly && this.isConnected;
294
+ this._input.setAttribute('aria-expanded', String(show));
295
+ if (show)
296
+ this._popup.show();
297
+ else
298
+ this._popup.hide();
299
+ this._syncActive();
300
+ }
301
+ _syncActive() { for (const entry of this._entries.values())
302
+ entry.row.classList.toggle('active', entry.option.value === this._active); const active = this._entries.get(this._active); if (this.open && active && !active.row.hidden)
303
+ this._input.setAttribute('aria-activedescendant', active.row.id);
304
+ else
305
+ this._input.removeAttribute('aria-activedescendant'); }
306
+ _setOpen(open) { if (open && (this._disabled || this.readOnly))
307
+ return; if (this.open === open)
308
+ return; if (!open)
309
+ this._query = ''; this.toggleAttribute('open', open); this.dispatchEvent(new CustomEvent('open-change', { detail: { open }, bubbles: true, composed: true })); }
310
+ _emitSearch() { this.dispatchEvent(new CustomEvent('search', { detail: { text: this._query }, bubbles: true, composed: true })); }
311
+ _commit(values) { if (this._disabled || this.readOnly)
312
+ return; this.values = values; this.dispatchEvent(new CustomEvent('value-change', { detail: { value: this.value, values: this.values, options: this.values.flatMap(value => { const option = this._entries.get(value)?.option; return option ? [cloneOption(option)] : []; }) }, bubbles: true, composed: true })); this.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }
313
+ _select(key) { const entry = this._entries.get(key); if (!entry || entry.disabled || this.loading || entry.option.selectable === false)
314
+ return; this._commit(this.multiple ? this.values.includes(key) ? this.values.filter(value => value !== key) : [...this.values, key] : [key]); if (!this.multiple)
315
+ this._setOpen(false); }
316
+ _toggle(key, open) { const entry = this._entries.get(key); if (!entry?.option.children?.length || entry.disabled)
317
+ return; const keys = new Set(this._expanded); if (open ?? !keys.has(key))
318
+ keys.add(key);
319
+ else
320
+ keys.delete(key); this.expandedKeys = [...keys]; this.dispatchEvent(new CustomEvent('expand-change', { detail: { expandedKeys: this.expandedKeys }, bubbles: true, composed: true })); }
321
+ _onTreeClick = (event) => { const target = event.target instanceof Element ? event.target : null; const toggle = target?.closest('[data-toggle]'); if (toggle)
322
+ this._toggle(toggle.dataset.toggle);
323
+ else {
324
+ const row = target?.closest('[data-value]');
325
+ if (row) {
326
+ this._active = row.dataset.value;
327
+ this._select(this._active);
328
+ }
329
+ } };
330
+ _onKeydown = (event) => {
331
+ if (event.isComposing || this._composing || event.keyCode === 229 || this._disabled || this.readOnly)
332
+ return;
333
+ if (event.key === 'Escape' || event.key === 'Tab') {
334
+ if (this.open && event.key === 'Escape') {
335
+ event.preventDefault();
336
+ event.stopPropagation();
337
+ }
338
+ this._setOpen(false);
339
+ return;
340
+ }
341
+ const wasOpen = this.open;
342
+ if (['ArrowDown', 'ArrowUp'].includes(event.key))
343
+ this._setOpen(true);
344
+ if (!this.open)
345
+ return;
346
+ const entries = this._visible.filter(entry => !entry.disabled);
347
+ const index = entries.findIndex(entry => entry.option.value === this._active);
348
+ const current = this._entries.get(this._active);
349
+ let target;
350
+ if (event.key === 'ArrowDown')
351
+ target = entries[wasOpen ? (index + 1) % entries.length : 0];
352
+ else if (event.key === 'ArrowUp')
353
+ target = entries[wasOpen ? (index - 1 + entries.length) % entries.length : entries.length - 1];
354
+ else if (event.key === 'Home' && !this._query)
355
+ target = entries[0];
356
+ else if (event.key === 'End' && !this._query)
357
+ target = entries.at(-1);
358
+ else if (event.key === 'ArrowRight' && !this._query && current?.option.children?.length) {
359
+ event.preventDefault();
360
+ if (!this._expanded.has(current.option.value))
361
+ this._toggle(current.option.value, true);
362
+ else
363
+ target = entries.find(entry => entry.parent === current.option.value);
364
+ }
365
+ else if (event.key === 'ArrowLeft' && !this._query && current) {
366
+ event.preventDefault();
367
+ if (this._expanded.has(current.option.value))
368
+ this._toggle(current.option.value, false);
369
+ else if (current.parent)
370
+ target = this._entries.get(current.parent);
371
+ }
372
+ else if (event.key === 'Enter' && current && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
373
+ event.preventDefault();
374
+ event.stopPropagation();
375
+ if (current.option.selectable === false)
376
+ this._toggle(current.option.value);
377
+ else
378
+ this._select(current.option.value);
379
+ }
380
+ if (target) {
381
+ event.preventDefault();
382
+ this._active = target.option.value;
383
+ this._syncActive();
384
+ target.row.scrollIntoView({ block: 'nearest' });
385
+ }
386
+ };
387
+ }
388
+ function cloneOption(option) { return { ...option, ...(option.children ? { children: option.children.map(cloneOption) } : {}) }; }
389
+ function normalizeTree(value) {
390
+ const keys = new Set();
391
+ const visiting = new Set();
392
+ const visit = (items, depth) => !Array.isArray(items) || depth > 64 ? [] : items.flatMap(item => { if (!item || typeof item !== 'object' || typeof item.value !== 'string' || !item.value || keys.has(item.value) || visiting.has(item))
393
+ return []; keys.add(item.value); visiting.add(item); const children = visit(item.children, depth + 1); visiting.delete(item); return [{ value: item.value, label: typeof item.label === 'string' ? item.label : item.value, ...(item.disabled ? { disabled: true } : {}), ...(item.selectable === false ? { selectable: false } : {}), ...(item.expanded ? { expanded: true } : {}), ...(children.length ? { children } : {}) }]; });
394
+ return visit(value, 0);
395
+ }
396
+ export function defineTreeSelectComponents() { if (!customElements.get('hy-tree-select'))
397
+ customElements.define('hy-tree-select', HYTreeSelect); }
398
+ //# sourceMappingURL=tree-select.js.map
package/dist/tree.d.ts CHANGED
@@ -42,7 +42,6 @@ export declare class HYTree extends HTMLElement {
42
42
  pasteClipboard(): boolean;
43
43
  deleteSelection(): boolean;
44
44
  cutSelection(): boolean;
45
- private _syncFromAttributes;
46
45
  private _readDataAttribute;
47
46
  private _seedExpanded;
48
47
  private _render;
@@ -87,7 +86,6 @@ export declare class HYTree extends HTMLElement {
87
86
  private _getTreeItemElementId;
88
87
  private _scrollActiveIntoView;
89
88
  private _onScroll;
90
- private _isEditableTarget;
91
89
  private _copySelection;
92
90
  private _pasteClipboard;
93
91
  private _deleteSelection;
package/dist/tree.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HYTreeModel } from './tree-model.js';
2
2
  import { HYTreeNode } from './tree-node.js';
3
+ import { isKeyboardControlEvent } from './internal/keyboard.js';
3
4
  export { HYTreeNode } from './tree-node.js';
4
5
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
5
6
  const TREE_TOGGLE_ICON_PATHS = [
@@ -68,7 +69,7 @@ export class HYTree extends HTMLElement {
68
69
  min-height: 0;
69
70
  color: var(--hy-tree-text-color, var(--hy-text-color, #c8d3e4));
70
71
  background: var(--hy-panel-bg-color, #171d28);
71
- font: 12px system-ui, sans-serif;
72
+ font: var(--hy-font-size-sm, 12px) var(--hy-font-family, system-ui, sans-serif);
72
73
  text-align: left;
73
74
  user-select: none;
74
75
  overflow: auto;
@@ -77,14 +78,15 @@ export class HYTree extends HTMLElement {
77
78
  box-sizing: border-box;
78
79
  width: 100%;
79
80
  flex: 0 0 auto;
80
- padding: 4px;
81
+ padding: var(--hy-space-2, 4px);
81
82
  }
82
83
  .row {
83
84
  height: 28px;
84
85
  display: flex;
85
86
  align-items: center;
86
- gap: 4px;
87
- border-radius: 4px;
87
+ gap: var(--hy-space-2, 4px);
88
+ padding-left: calc(var(--hy-space-2, 4px) + var(--_hy-tree-depth, 0) * var(--hy-space-8, 16px));
89
+ border-radius: var(--hy-radius-sm, 4px);
88
90
  color: var(--hy-tree-text-color, var(--hy-text-color, #c8d3e4));
89
91
  cursor: default;
90
92
  }
@@ -159,7 +161,11 @@ export class HYTree extends HTMLElement {
159
161
  this.tabIndex = 0;
160
162
  if (!this.hasAttribute('role'))
161
163
  this.setAttribute('role', 'tree');
162
- this._syncFromAttributes();
164
+ // Attribute callbacks initialize declarative data; reconnect with the current state.
165
+ if (this.hasAttribute('selected-ids'))
166
+ this._setSelectionFromSelectedIdsAttribute();
167
+ else
168
+ this._setSelectionFromSelectedIdAttribute();
163
169
  this.addEventListener('keydown', this._onKeyDown);
164
170
  this._list.addEventListener('click', this._onListClick);
165
171
  this._list.addEventListener('contextmenu', this._onListContextMenu);
@@ -278,13 +284,6 @@ export class HYTree extends HTMLElement {
278
284
  return false;
279
285
  return this._deleteSelection();
280
286
  }
281
- _syncFromAttributes() {
282
- this._readDataAttribute();
283
- if (this.hasAttribute('selected-ids'))
284
- this._setSelectionFromSelectedIdsAttribute();
285
- else
286
- this._setSelectionFromSelectedIdAttribute();
287
- }
288
287
  _readDataAttribute() {
289
288
  const raw = this.getAttribute('data');
290
289
  if (!raw) {
@@ -394,7 +393,7 @@ export class HYTree extends HTMLElement {
394
393
  const { row, toggle, content } = rendered;
395
394
  row.className = `row${selected ? ' selected' : ''}${active ? ' active' : ''}`;
396
395
  row.dataset.id = node.id;
397
- row.style.paddingLeft = `${depth * 16 + 4}px`;
396
+ row.style.setProperty('--_hy-tree-depth', String(depth));
398
397
  row.draggable = this.allowDrag;
399
398
  toggle.className = `${hasChildren ? 'toggle' : 'toggle empty'}${expanded ? ' expanded' : ''}`;
400
399
  toggle.disabled = !hasChildren;
@@ -666,7 +665,7 @@ export class HYTree extends HTMLElement {
666
665
  }
667
666
  }
668
667
  _onKeyDown = (event) => {
669
- if (event.defaultPrevented || this._isEditableTarget(event.target))
668
+ if (event.defaultPrevented || isKeyboardControlEvent(event, this))
670
669
  return;
671
670
  const key = event.key.toLowerCase();
672
671
  const command = event.metaKey || event.ctrlKey;
@@ -825,12 +824,6 @@ export class HYTree extends HTMLElement {
825
824
  if (this._getVisibleFlatNodes().length >= HYTree.VIRTUALIZATION_THRESHOLD)
826
825
  this._render();
827
826
  };
828
- _isEditableTarget(target) {
829
- if (!(target instanceof HTMLElement))
830
- return false;
831
- const tag = target.tagName.toLowerCase();
832
- return tag === 'input' || tag === 'textarea' || tag === 'select' || target.isContentEditable;
833
- }
834
827
  _copySelection() {
835
828
  const nodes = this._getSelectedTopLevelNodes();
836
829
  if (nodes.length === 0)
@@ -862,17 +855,9 @@ export class HYTree extends HTMLElement {
862
855
  return true;
863
856
  }
864
857
  _deleteSelection() {
865
- const ids = this._getTopLevelSelectedIds();
866
- if (ids.length === 0)
867
- return false;
868
- const deletedIds = [];
869
- for (const id of ids) {
870
- if (this._model.removeNode(id))
871
- deletedIds.push(id);
872
- }
858
+ const deletedIds = this._model.removeNodes(this._selectedIds);
873
859
  if (deletedIds.length === 0)
874
860
  return false;
875
- this._model.setData(this._data);
876
861
  this._setSelection([], null, true);
877
862
  this.dispatchEvent(new CustomEvent('data-change', {
878
863
  detail: { data: this._data, action: 'delete', deletedIds },
@@ -0,0 +1,108 @@
1
+ export type HYUploadStatus = 'ready' | 'uploading' | 'done' | 'error';
2
+ export type HYUploadChangeReason = 'select' | 'remove' | 'start' | 'progress' | 'success' | 'error' | 'abort';
3
+ export type HYUploadRejectReason = 'type' | 'size' | 'count' | 'before-upload' | 'error';
4
+ export interface HYUploadFile {
5
+ uid: string;
6
+ name: string;
7
+ status: HYUploadStatus;
8
+ percent?: number;
9
+ size?: number;
10
+ type?: string;
11
+ file?: File;
12
+ response?: unknown;
13
+ error?: string;
14
+ }
15
+ export interface HYUploadChangeDetail {
16
+ file: HYUploadFile;
17
+ fileList: HYUploadFile[];
18
+ reason: HYUploadChangeReason;
19
+ }
20
+ export interface HYUploadRejectDetail {
21
+ file: File;
22
+ reason: HYUploadRejectReason;
23
+ message: string;
24
+ }
25
+ export interface HYUploadRemoveDetail {
26
+ file: HYUploadFile;
27
+ }
28
+ export interface HYUploadRequestOptions {
29
+ file: File;
30
+ signal: AbortSignal;
31
+ onProgress: (percent: number) => void;
32
+ }
33
+ export type HYUploadRequest = (options: HYUploadRequestOptions) => Promise<unknown>;
34
+ export type HYUploadBeforeUpload = (file: File, files: readonly File[]) => boolean | Promise<boolean>;
35
+ export declare class HYUpload extends HTMLElement {
36
+ static readonly formAssociated = true;
37
+ private readonly _internals;
38
+ private readonly _input;
39
+ private readonly _zone;
40
+ private readonly _button;
41
+ private readonly _slot;
42
+ private readonly _list;
43
+ private readonly _message;
44
+ private _files;
45
+ private _initialFiles;
46
+ private _request;
47
+ private _beforeUpload;
48
+ private _requests;
49
+ private _rows;
50
+ private _listeners;
51
+ private _formDisabled;
52
+ private _selection;
53
+ private _dragDepth;
54
+ static get observedAttributes(): string[];
55
+ constructor();
56
+ connectedCallback(): void;
57
+ disconnectedCallback(): void;
58
+ attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
59
+ get fileList(): HYUploadFile[];
60
+ set fileList(value: HYUploadFile[]);
61
+ get files(): File[];
62
+ get request(): HYUploadRequest | null;
63
+ set request(value: HYUploadRequest | null);
64
+ get beforeUpload(): HYUploadBeforeUpload | null;
65
+ set beforeUpload(value: HYUploadBeforeUpload | null);
66
+ get name(): string;
67
+ set name(value: string);
68
+ get accept(): string;
69
+ set accept(value: string);
70
+ get multiple(): boolean;
71
+ set multiple(value: boolean);
72
+ get disabled(): boolean;
73
+ set disabled(value: boolean);
74
+ get drag(): boolean;
75
+ set drag(value: boolean);
76
+ get maxCount(): number;
77
+ set maxCount(value: number);
78
+ get maxSize(): number;
79
+ set maxSize(value: number);
80
+ get autoUpload(): boolean;
81
+ set autoUpload(value: boolean);
82
+ get showFileList(): boolean;
83
+ set showFileList(value: boolean);
84
+ get form(): HTMLFormElement | null;
85
+ get validity(): ValidityState;
86
+ get validationMessage(): string;
87
+ checkValidity(): boolean;
88
+ reportValidity(): boolean;
89
+ formDisabledCallback(disabled: boolean): void;
90
+ formResetCallback(): void;
91
+ focus(options?: FocusOptions): void;
92
+ openFileDialog(): void;
93
+ selectFiles(value: readonly File[] | FileList): Promise<void>;
94
+ upload(uid?: string): Promise<void>;
95
+ abort(uid?: string): void;
96
+ removeFile(uid: string): boolean;
97
+ private _upload;
98
+ private _notifyValueChange;
99
+ private _emit;
100
+ private _reject;
101
+ private _sync;
102
+ private _onListClick;
103
+ private _onDragEnter;
104
+ private _onDragLeave;
105
+ private _onDragOver;
106
+ private _onDrop;
107
+ }
108
+ export declare function defineUploadComponents(): void;