@haiyue/ui 0.3.0 → 0.4.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +84 -2
  3. package/dist/adapters/web/controls.js +48 -8
  4. package/dist/adapters/web/renderer.js +8 -3
  5. package/dist/anchor.d.ts +2 -0
  6. package/dist/anchor.js +23 -4
  7. package/dist/border-beam.js +2 -1
  8. package/dist/cascader.js +7 -1
  9. package/dist/context-menu.js +0 -1
  10. package/dist/core/actions.js +7 -8
  11. package/dist/core/data.d.ts +1 -1
  12. package/dist/core/data.js +44 -10
  13. package/dist/core/platform-view.js +8 -2
  14. package/dist/core/selection.js +4 -4
  15. package/dist/core/semantics.d.ts +26 -0
  16. package/dist/core/semantics.js +8 -0
  17. package/dist/core/text.js +3 -3
  18. package/dist/core/validation.d.ts +3 -1
  19. package/dist/core/validation.js +23 -5
  20. package/dist/date-picker.js +6 -0
  21. package/dist/dialog.d.ts +4 -0
  22. package/dist/dialog.js +37 -16
  23. package/dist/drag-source.d.ts +27 -0
  24. package/dist/drag-source.js +114 -0
  25. package/dist/draggable.d.ts +1 -2
  26. package/dist/draggable.js +25 -31
  27. package/dist/drawer.js +4 -12
  28. package/dist/dropdown.js +0 -1
  29. package/dist/dropzone.d.ts +29 -0
  30. package/dist/dropzone.js +89 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +9 -0
  33. package/dist/input.js +3 -3
  34. package/dist/internal/drag-drop.d.ts +29 -0
  35. package/dist/internal/drag-drop.js +171 -0
  36. package/dist/internal/focus.d.ts +2 -0
  37. package/dist/internal/focus.js +31 -0
  38. package/dist/internal/keyboard.d.ts +2 -0
  39. package/dist/internal/keyboard.js +12 -0
  40. package/dist/internal/native-drop.d.ts +17 -0
  41. package/dist/internal/native-drop.js +62 -0
  42. package/dist/internal/numbers.d.ts +2 -0
  43. package/dist/internal/numbers.js +8 -0
  44. package/dist/internal/pointer-drag.d.ts +15 -0
  45. package/dist/internal/pointer-drag.js +100 -0
  46. package/dist/modal.js +1 -30
  47. package/dist/notification.js +2 -1
  48. package/dist/portable/page.js +25 -14
  49. package/dist/radio.js +1 -1
  50. package/dist/resizable.d.ts +1 -1
  51. package/dist/resizable.js +26 -27
  52. package/dist/sortable.d.ts +62 -0
  53. package/dist/sortable.js +363 -0
  54. package/dist/table.d.ts +3 -1
  55. package/dist/table.js +65 -42
  56. package/dist/time-picker.js +6 -0
  57. package/dist/toast.js +3 -2
  58. package/dist/tooltip.d.ts +6 -0
  59. package/dist/tooltip.js +103 -2
  60. package/dist/tour.js +15 -6
  61. package/dist/tree-model.d.ts +2 -0
  62. package/dist/tree-model.js +32 -11
  63. package/dist/tree.d.ts +0 -2
  64. package/dist/tree.js +8 -24
  65. package/dist/upload.d.ts +2 -5
  66. package/dist/upload.js +19 -25
  67. package/dist/virtual-keyboard.d.ts +1 -0
  68. package/dist/virtual-keyboard.js +67 -36
  69. package/dist/virtual-list.d.ts +1 -0
  70. package/dist/virtual-list.js +21 -4
  71. package/dist/virtual-mouse.js +2 -1
  72. package/dist/watermark.js +2 -1
  73. package/package.json +33 -6
package/dist/table.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { finiteNumber } from './internal/numbers.js';
1
2
  import { HYPaginationControls, HY_PAGINATION_STYLES } from './internal/pagination.js';
2
3
  const DEFAULT_PAGE_SIZE = 10;
3
4
  const DEFAULT_PAGE_SIZE_OPTIONS = [5, 10, 20, 50];
4
5
  const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
5
6
  function finiteInteger(value, fallback, minimum = 1) {
6
- const number = Number(value);
7
+ const number = finiteNumber(value, fallback);
7
8
  return Number.isFinite(number) ? Math.max(minimum, Math.floor(number)) : fallback;
8
9
  }
9
10
  function positiveIntegerOptions(value) {
@@ -230,13 +231,13 @@ export class HYTable extends HTMLElement {
230
231
  }
231
232
  connectedCallback() {
232
233
  this._syncAttributes();
233
- this._render();
234
+ this._render(true);
234
235
  }
235
- attributeChangedCallback() {
236
+ attributeChangedCallback(name) {
236
237
  if (this._reflecting)
237
238
  return;
238
239
  this._syncAttributes();
239
- this._render();
240
+ this._render(name === undefined || name === 'show-filters');
240
241
  }
241
242
  get columns() { return this._columns; }
242
243
  set columns(value) {
@@ -245,13 +246,11 @@ export class HYTable extends HTMLElement {
245
246
  this._filters = Object.fromEntries(Object.entries(this._filters).filter(([key]) => keys.has(key)));
246
247
  if (this._sort && !keys.has(this._sort.key))
247
248
  this._sort = null;
248
- this._clampPage();
249
- this._render();
249
+ this._render(true);
250
250
  }
251
251
  get dataSource() { return this._dataSource; }
252
252
  set dataSource(value) {
253
253
  this._dataSource = Array.isArray(value) ? [...value] : [];
254
- this._clampPage();
255
254
  this._renderBodyAndPagination();
256
255
  }
257
256
  get page() { return this._page; }
@@ -265,15 +264,13 @@ export class HYTable extends HTMLElement {
265
264
  this._page = 1;
266
265
  this._reflectNumber('page-size', next);
267
266
  this._reflectNumber('page', 1);
268
- this._renderBodyAndPagination();
269
- this._dispatchChange('paginate');
267
+ this._update('paginate');
270
268
  }
271
269
  get pageSizeOptions() { return this._pageSizeOptions; }
272
270
  set pageSizeOptions(value) {
273
271
  const options = positiveIntegerOptions(Array.isArray(value) ? value : []);
274
272
  this._pageSizeOptions = options.length ? options : DEFAULT_PAGE_SIZE_OPTIONS;
275
273
  this.setAttribute('page-size-options', this._pageSizeOptions.join(','));
276
- this._renderPagination();
277
274
  }
278
275
  get pagination() { return this.getAttribute('pagination') !== 'false'; }
279
276
  set pagination(value) { this.setAttribute('pagination', String(Boolean(value))); }
@@ -291,8 +288,7 @@ export class HYTable extends HTMLElement {
291
288
  }
292
289
  this._page = 1;
293
290
  this._reflectNumber('page', 1);
294
- this._render();
295
- this._dispatchChange('sort');
291
+ this._update('sort');
296
292
  }
297
293
  get filters() { return { ...this._filters }; }
298
294
  set filters(value) {
@@ -300,19 +296,20 @@ export class HYTable extends HTMLElement {
300
296
  this._filters = Object.fromEntries(Object.entries(value ?? {}).filter(([key, filter]) => allowed.has(key) && String(filter).length > 0).map(([key, filter]) => [key, String(filter)]));
301
297
  this._page = 1;
302
298
  this._reflectNumber('page', 1);
303
- this._render();
304
- this._dispatchChange('filter');
299
+ this._update('filter');
305
300
  }
306
301
  get filteredData() { return this._processedRecords().map(item => item.record); }
307
302
  get visibleData() { return this._visibleRecords().map(item => item.record); }
308
303
  goToPage(value) {
309
- const next = Math.min(this.pageCount, finiteInteger(value, 1));
304
+ const processed = this._processedRecords();
305
+ const count = this.pagination ? Math.max(1, Math.ceil(processed.length / this._pageSize)) : 1;
306
+ const next = Math.min(count, finiteInteger(value, 1));
310
307
  if (next === this._page)
311
308
  return;
312
309
  this._page = next;
313
310
  this._reflectNumber('page', next);
314
- this._renderBodyAndPagination();
315
- this._dispatchChange('paginate');
311
+ this._renderBodyAndPagination(processed);
312
+ this._dispatchChange('paginate', processed);
316
313
  }
317
314
  get pageCount() {
318
315
  if (!this.pagination)
@@ -348,8 +345,7 @@ export class HYTable extends HTMLElement {
348
345
  delete this._filters[key];
349
346
  this._page = 1;
350
347
  this._reflectNumber('page', 1);
351
- this._render();
352
- this._dispatchChange('filter');
348
+ this._update('filter');
353
349
  }
354
350
  clearFilters() {
355
351
  if (Object.keys(this._filters).length === 0)
@@ -357,12 +353,11 @@ export class HYTable extends HTMLElement {
357
353
  this._filters = {};
358
354
  this._page = 1;
359
355
  this._reflectNumber('page', 1);
360
- this._render();
361
- this._dispatchChange('filter');
356
+ this._update('filter');
362
357
  }
363
358
  _syncAttributes() {
364
- this._pageSize = finiteInteger(this.getAttribute('page-size'), this._pageSize);
365
- this._page = finiteInteger(this.getAttribute('page'), this._page);
359
+ this._pageSize = finiteInteger(this.getAttribute('page-size'), DEFAULT_PAGE_SIZE);
360
+ this._page = finiteInteger(this.getAttribute('page'), 1);
366
361
  if (this.hasAttribute('page-size-options')) {
367
362
  const options = positiveIntegerOptions((this.getAttribute('page-size-options') ?? '').split(','));
368
363
  if (options.length)
@@ -373,11 +368,42 @@ export class HYTable extends HTMLElement {
373
368
  this._table.setAttribute('aria-label', label);
374
369
  else
375
370
  this._table.removeAttribute('aria-label');
376
- this._clampPage();
377
371
  }
378
- _render() {
379
- this._renderHeader();
380
- this._renderBodyAndPagination();
372
+ _update(reason) {
373
+ const processed = this._processedRecords();
374
+ this._render(false, processed);
375
+ this._dispatchChange(reason, processed);
376
+ }
377
+ _render(rebuildHeader = false, processed = this._processedRecords()) {
378
+ if (rebuildHeader)
379
+ this._renderHeader();
380
+ this._syncHeaderState();
381
+ this._renderBodyAndPagination(processed);
382
+ }
383
+ _syncHeaderState() {
384
+ // Index alignment preserves duplicate column keys and each control's DOM identity.
385
+ const headers = this._head.querySelectorAll('th');
386
+ this._columns.forEach((column, index) => {
387
+ const header = headers[index];
388
+ if (!header)
389
+ return;
390
+ const indicator = header.querySelector('.sort-indicator');
391
+ if (indicator) {
392
+ const direction = this._sort?.key === column.key ? this._sort.direction : null;
393
+ indicator.textContent = direction === 'asc' ? '▲' : direction === 'desc' ? '▼' : '◆';
394
+ header.setAttribute('aria-sort', direction === 'asc' ? 'ascending' : direction === 'desc' ? 'descending' : 'none');
395
+ }
396
+ const value = this._filters[column.key] ?? '';
397
+ const control = header.querySelector('.filter');
398
+ if (control && control.value !== value)
399
+ control.value = value;
400
+ const trigger = header.querySelector('.filter-trigger');
401
+ if (trigger)
402
+ trigger.dataset.active = String(Boolean(value));
403
+ const clear = header.querySelector('.filter-clear');
404
+ if (clear)
405
+ clear.disabled = !value;
406
+ });
381
407
  }
382
408
  _renderHeader() {
383
409
  const titleRow = document.createElement('tr');
@@ -507,12 +533,11 @@ export class HYTable extends HTMLElement {
507
533
  delete this._filters[key];
508
534
  this._page = 1;
509
535
  this._reflectNumber('page', 1);
510
- this._renderBodyAndPagination();
511
- this._dispatchChange('filter');
536
+ this._update('filter');
512
537
  }
513
- _renderBodyAndPagination() {
514
- this._clampPage();
515
- const rows = this._visibleRecords();
538
+ _renderBodyAndPagination(processed = this._processedRecords()) {
539
+ this._clampPage(processed);
540
+ const rows = this._visibleRecords(processed);
516
541
  if (rows.length === 0) {
517
542
  const row = document.createElement('tr');
518
543
  row.part.add('empty-row');
@@ -530,7 +555,7 @@ export class HYTable extends HTMLElement {
530
555
  else {
531
556
  this._body.replaceChildren(...rows.map(item => this._createRow(item)));
532
557
  }
533
- this._renderPagination();
558
+ this._renderPagination(processed);
534
559
  }
535
560
  _createRow(item) {
536
561
  const row = document.createElement('tr');
@@ -555,9 +580,9 @@ export class HYTable extends HTMLElement {
555
580
  }
556
581
  return row;
557
582
  }
558
- _renderPagination() {
583
+ _renderPagination(processed = this._processedRecords()) {
559
584
  this._pagination.update({
560
- page: this._page, pageSize: this._pageSize, total: this._processedRecords().length,
585
+ page: this._page, pageSize: this._pageSize, total: processed.length,
561
586
  pageSizeOptions: this._pageSizeOptions, label: 'Table pagination',
562
587
  hidden: !this.pagination, showSizeChanger: true,
563
588
  });
@@ -592,15 +617,14 @@ export class HYTable extends HTMLElement {
592
617
  }
593
618
  return records;
594
619
  }
595
- _visibleRecords() {
596
- const records = this._processedRecords();
620
+ _visibleRecords(records = this._processedRecords()) {
597
621
  if (!this.pagination)
598
622
  return records;
599
623
  const start = (this._page - 1) * this._pageSize;
600
624
  return records.slice(start, start + this._pageSize);
601
625
  }
602
- _clampPage() {
603
- const total = this._processedRecords().length;
626
+ _clampPage(processed) {
627
+ const total = processed.length;
604
628
  const pageCount = this.pagination ? Math.max(1, Math.ceil(total / this._pageSize)) : 1;
605
629
  const next = Math.min(pageCount, Math.max(1, this._page));
606
630
  if (next !== this._page) {
@@ -623,8 +647,7 @@ export class HYTable extends HTMLElement {
623
647
  this.setAttribute(name, text);
624
648
  this._reflecting = false;
625
649
  }
626
- _dispatchChange(reason) {
627
- const processed = this._processedRecords();
650
+ _dispatchChange(reason, processed) {
628
651
  const detail = {
629
652
  reason,
630
653
  page: this._page,
@@ -634,7 +657,7 @@ export class HYTable extends HTMLElement {
634
657
  filteredTotal: processed.length,
635
658
  sort: this.sort,
636
659
  filters: this.filters,
637
- visibleData: this.visibleData,
660
+ visibleData: this._visibleRecords(processed).map(item => item.record),
638
661
  };
639
662
  this.dispatchEvent(new CustomEvent('table-change', {
640
663
  bubbles: true, composed: true, detail,
@@ -169,6 +169,10 @@ export class HYTimePicker extends HTMLElement {
169
169
  this._draft = { hour: now.getHours(), minute: Math.floor(now.getMinutes() / this.minuteStep) * this.minuteStep, second: Math.floor(now.getSeconds() / this.secondStep) * this.secondStep };
170
170
  }
171
171
  _render() {
172
+ if (this.disabled && this.open) {
173
+ this.open = false;
174
+ return;
175
+ }
172
176
  this._label.textContent = this._value || this.placeholder;
173
177
  this._label.classList.toggle('placeholder', !this._value);
174
178
  this._trigger.disabled = this.disabled;
@@ -276,6 +280,8 @@ export class HYTimePicker extends HTMLElement {
276
280
  }
277
281
  _focusSelected(columnIndex) { this._panel.querySelectorAll('.column')[columnIndex]?.querySelector('[aria-selected="true"]')?.focus(); }
278
282
  _commit(value) {
283
+ if (this.disabled)
284
+ return;
279
285
  this._value = this._normalizeValue(value);
280
286
  this._reflectValue();
281
287
  if (this.open)
package/dist/toast.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { finiteNumber } from './internal/numbers.js';
1
2
  const TYPES = ['success', 'info', 'warning', 'error', 'loading'];
2
3
  const PLACEMENTS = ['top', 'center', 'bottom'];
3
4
  const DEFAULT_DURATION = 3;
@@ -9,7 +10,7 @@ function isPlacement(value) {
9
10
  return typeof value === 'string' && PLACEMENTS.includes(value);
10
11
  }
11
12
  function finiteNonNegative(value, fallback) {
12
- const number = Number(value);
13
+ const number = finiteNumber(value, fallback);
13
14
  return Number.isFinite(number) && number >= 0 ? number : fallback;
14
15
  }
15
16
  /** Lightweight imperative feedback center for short, transient messages. */
@@ -87,7 +88,7 @@ export class HYToast extends HTMLElement {
87
88
  get duration() { return finiteNonNegative(this.getAttribute('duration'), DEFAULT_DURATION); }
88
89
  set duration(value) { this.setAttribute('duration', String(finiteNonNegative(value, DEFAULT_DURATION))); }
89
90
  get maxCount() {
90
- const value = Math.floor(Number(this.getAttribute('max-count')));
91
+ const value = Math.floor(finiteNumber(this.getAttribute('max-count'), 5));
91
92
  return Number.isFinite(value) ? Math.min(20, Math.max(1, value)) : 5;
92
93
  }
93
94
  set maxCount(value) {
package/dist/tooltip.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type HYTooltipPlacement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight' | 'left' | 'leftTop' | 'leftBottom' | 'right' | 'rightTop' | 'rightBottom';
2
2
  export declare class HYTooltip extends HTMLElement {
3
+ private static _descriptionSequence;
3
4
  private readonly _root;
4
5
  private readonly _style;
5
6
  private readonly _slot;
@@ -8,6 +9,8 @@ export declare class HYTooltip extends HTMLElement {
8
9
  private readonly _arrow;
9
10
  private _showTimer;
10
11
  private _visible;
12
+ private readonly _descriptions;
13
+ private readonly _observer;
11
14
  static get observedAttributes(): string[];
12
15
  constructor();
13
16
  connectedCallback(): void;
@@ -28,6 +31,9 @@ export declare class HYTooltip extends HTMLElement {
28
31
  private _hide;
29
32
  private _onViewportChange;
30
33
  private _syncLabel;
34
+ private _removeDescription;
35
+ private _clearDescriptions;
36
+ private _syncDescriptions;
31
37
  private _syncArrow;
32
38
  private _syncPosition;
33
39
  private _syncArrowPosition;
package/dist/tooltip.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { finiteNumber } from './internal/numbers.js';
1
2
  const DEFAULT_DELAY = 1000;
2
3
  const VIEWPORT_PADDING = 8;
3
4
  const TRIGGER_GAP = 8;
@@ -18,6 +19,7 @@ const TOOLTIP_PLACEMENTS = new Set([
18
19
  'rightBottom',
19
20
  ]);
20
21
  export class HYTooltip extends HTMLElement {
22
+ static _descriptionSequence = 0;
21
23
  _root;
22
24
  _style = document.createElement('style');
23
25
  _slot = document.createElement('slot');
@@ -26,6 +28,8 @@ export class HYTooltip extends HTMLElement {
26
28
  _arrow = document.createElement('span');
27
29
  _showTimer = null;
28
30
  _visible = false;
31
+ _descriptions = new Map();
32
+ _observer = new MutationObserver(() => this._syncDescriptions());
29
33
  static get observedAttributes() {
30
34
  return ['label', 'placement', 'delay', 'disabled', 'arrow', 'no-arrow'];
31
35
  }
@@ -56,6 +60,7 @@ export class HYTooltip extends HTMLElement {
56
60
  overflow-wrap: anywhere;
57
61
  pointer-events: none;
58
62
  opacity: 0;
63
+ visibility: hidden;
59
64
  transform: translate3d(0, -2px, 0);
60
65
  transition: opacity 0.12s ease, transform 0.12s ease;
61
66
  }
@@ -73,15 +78,18 @@ export class HYTooltip extends HTMLElement {
73
78
  }
74
79
  .tooltip.visible {
75
80
  opacity: 1;
81
+ visibility: visible;
76
82
  transform: translate3d(0, 0, 0);
77
83
  }
78
84
  `;
79
85
  this._tooltip.className = 'tooltip';
80
86
  this._tooltip.setAttribute('role', 'tooltip');
87
+ this._tooltip.setAttribute('aria-hidden', 'true');
81
88
  this._content.className = 'content';
82
89
  this._arrow.className = 'arrow';
83
90
  this._tooltip.append(this._content, this._arrow);
84
91
  this._root.append(this._style, this._slot, this._tooltip);
92
+ this._slot.addEventListener('slotchange', () => this._syncDescriptions());
85
93
  }
86
94
  connectedCallback() {
87
95
  this.addEventListener('pointerenter', this._onEnter);
@@ -89,6 +97,7 @@ export class HYTooltip extends HTMLElement {
89
97
  this.addEventListener('focusin', this._onEnter);
90
98
  this.addEventListener('focusout', this._onLeave);
91
99
  this.addEventListener('keydown', this._onKeyDown);
100
+ this._observer.observe(this, { childList: true, subtree: true });
92
101
  this._syncLabel();
93
102
  }
94
103
  disconnectedCallback() {
@@ -99,10 +108,17 @@ export class HYTooltip extends HTMLElement {
99
108
  this.removeEventListener('keydown', this._onKeyDown);
100
109
  this._clearShowTimer();
101
110
  this._hide();
111
+ this._observer.disconnect();
112
+ this._clearDescriptions();
102
113
  }
103
114
  attributeChangedCallback(name) {
104
115
  if (name === 'label')
105
116
  this._syncLabel();
117
+ if (name === 'disabled') {
118
+ this._clearShowTimer();
119
+ this._hide();
120
+ this._syncDescriptions();
121
+ }
106
122
  if (name === 'arrow' || name === 'no-arrow')
107
123
  this._syncArrow();
108
124
  if ((name === 'placement' || name === 'disabled' || name === 'arrow' || name === 'no-arrow') && this._visible) {
@@ -125,7 +141,7 @@ export class HYTooltip extends HTMLElement {
125
141
  this.setAttribute('placement', value);
126
142
  }
127
143
  get delay() {
128
- const value = Number(this.getAttribute('delay'));
144
+ const value = finiteNumber(this.getAttribute('delay'), DEFAULT_DELAY);
129
145
  return Number.isFinite(value) && value >= 0 ? value : DEFAULT_DELAY;
130
146
  }
131
147
  set delay(value) {
@@ -149,6 +165,7 @@ export class HYTooltip extends HTMLElement {
149
165
  _onEnter = () => {
150
166
  if (this.hasAttribute('disabled') || !this.label)
151
167
  return;
168
+ this._syncDescriptions();
152
169
  this._clearShowTimer();
153
170
  this._showTimer = window.setTimeout(() => this._show(), this.delay);
154
171
  };
@@ -157,14 +174,17 @@ export class HYTooltip extends HTMLElement {
157
174
  this._hide();
158
175
  };
159
176
  _onKeyDown = (event) => {
160
- if (event.key === 'Escape')
177
+ if (event.key === 'Escape') {
178
+ this._clearShowTimer();
161
179
  this._hide();
180
+ }
162
181
  };
163
182
  _show() {
164
183
  this._showTimer = null;
165
184
  if (!this.isConnected || this.hasAttribute('disabled') || !this.label)
166
185
  return;
167
186
  this._visible = true;
187
+ this._tooltip.setAttribute('aria-hidden', 'false');
168
188
  this._syncArrow();
169
189
  this._syncPosition();
170
190
  this._tooltip.classList.add('visible');
@@ -172,6 +192,7 @@ export class HYTooltip extends HTMLElement {
172
192
  window.addEventListener('resize', this._onViewportChange);
173
193
  }
174
194
  _hide() {
195
+ this._tooltip.setAttribute('aria-hidden', 'true');
175
196
  if (!this._visible)
176
197
  return;
177
198
  this._visible = false;
@@ -185,6 +206,86 @@ export class HYTooltip extends HTMLElement {
185
206
  };
186
207
  _syncLabel() {
187
208
  this._content.textContent = this.label;
209
+ if (!this.label) {
210
+ this._clearShowTimer();
211
+ this._hide();
212
+ }
213
+ this._syncDescriptions();
214
+ }
215
+ _removeDescription(target) {
216
+ const record = this._descriptions.get(target);
217
+ if (!record)
218
+ return;
219
+ const ids = (target.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(id => id && id !== record.id);
220
+ if (ids.length)
221
+ target.setAttribute('aria-describedby', ids.join(' '));
222
+ else
223
+ target.removeAttribute('aria-describedby');
224
+ record.node.remove();
225
+ this._descriptions.delete(target);
226
+ }
227
+ _clearDescriptions() {
228
+ for (const target of [...this._descriptions.keys()])
229
+ this._removeDescription(target);
230
+ }
231
+ _syncDescriptions() {
232
+ if (!this.isConnected || this.hasAttribute('disabled') || !this.label) {
233
+ this._clearDescriptions();
234
+ return;
235
+ }
236
+ const targets = new Set();
237
+ const visit = (element) => {
238
+ if (element instanceof HTMLElement && (element.hidden || element.inert || element.getAttribute('aria-hidden') === 'true'))
239
+ return;
240
+ if (element instanceof HTMLSlotElement) {
241
+ for (const child of element.assignedElements({ flatten: true }))
242
+ visit(child);
243
+ }
244
+ else if (element.shadowRoot) {
245
+ for (const child of element.shadowRoot.children)
246
+ visit(child);
247
+ }
248
+ else {
249
+ if (element instanceof HTMLElement && (element.isContentEditable || element.matches('button,input,select,textarea,a[href],[tabindex],[role="button"],[role="textbox"],[role="slider"]')))
250
+ targets.add(element);
251
+ for (const child of element.children)
252
+ visit(child);
253
+ }
254
+ };
255
+ for (const element of this._slot.assignedElements({ flatten: true })) {
256
+ const before = targets.size;
257
+ visit(element);
258
+ if (targets.size === before && element instanceof HTMLElement && !element.hidden && !element.inert)
259
+ targets.add(element);
260
+ }
261
+ for (const target of [...this._descriptions.keys()]) {
262
+ const record = this._descriptions.get(target);
263
+ if (!targets.has(target) || record.node.getRootNode() !== target.getRootNode())
264
+ this._removeDescription(target);
265
+ }
266
+ for (const target of targets) {
267
+ let record = this._descriptions.get(target);
268
+ if (!record) {
269
+ const node = document.createElement('span');
270
+ node.hidden = true;
271
+ const id = `hy-tooltip-description-${++HYTooltip._descriptionSequence}`;
272
+ node.id = id;
273
+ const scope = target.getRootNode();
274
+ if (scope instanceof ShadowRoot)
275
+ scope.append(node);
276
+ else
277
+ (target.ownerDocument.body ?? target.ownerDocument.documentElement).append(node);
278
+ record = { node, id };
279
+ this._descriptions.set(target, record);
280
+ }
281
+ if (record.node.textContent !== this.label)
282
+ record.node.textContent = this.label;
283
+ const ids = new Set((target.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean));
284
+ ids.add(record.id);
285
+ const description = [...ids].join(' ');
286
+ if (target.getAttribute('aria-describedby') !== description)
287
+ target.setAttribute('aria-describedby', description);
288
+ }
188
289
  }
189
290
  _syncArrow() {
190
291
  this._tooltip.classList.toggle('no-arrow', !this.arrow);
package/dist/tour.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { finiteNumber } from './internal/numbers.js';
1
2
  function normalizeSteps(value) {
2
3
  if (!Array.isArray(value))
3
4
  return [];
@@ -129,10 +130,10 @@ export class HYTour extends HTMLElement {
129
130
  set closeOnEscape(value) { this.setAttribute('close-on-escape', String(Boolean(value))); }
130
131
  get autoScroll() { return this.getAttribute('scroll-into-view') !== 'false'; }
131
132
  set autoScroll(value) { this.setAttribute('scroll-into-view', String(Boolean(value))); }
132
- get gap() { const number = Number(this.getAttribute('gap')); return Number.isFinite(number) ? Math.min(80, Math.max(0, number)) : 8; }
133
+ get gap() { const number = finiteNumber(this.getAttribute('gap'), 8); return Number.isFinite(number) ? Math.min(80, Math.max(0, number)) : 8; }
133
134
  set gap(value) { const number = Number(value); this.setAttribute('gap', String(Number.isFinite(number) ? Math.min(80, Math.max(0, number)) : 8)); }
134
- get zIndex() { const number = Number(this.getAttribute('z-index')); return Number.isFinite(number) ? Math.round(number) : 1000; }
135
- set zIndex(value) { this.setAttribute('z-index', String(Math.round(Number(value) || 1000))); }
135
+ get zIndex() { const number = finiteNumber(this.getAttribute('z-index'), 1000); return Number.isFinite(number) ? Math.round(number) : 1000; }
136
+ set zIndex(value) { this.setAttribute('z-index', String(Math.round(finiteNumber(value, 1000)))); }
136
137
  start(current = 0) { if (!this._steps.length)
137
138
  return; this.current = current; this.open = true; }
138
139
  next() {
@@ -163,6 +164,10 @@ export class HYTour extends HTMLElement {
163
164
  if (!this.isConnected)
164
165
  return;
165
166
  this.style.setProperty('--_hy-tour-z-index', String(this.zIndex));
167
+ if (this.open && !this._steps.length) {
168
+ this.close('programmatic');
169
+ return;
170
+ }
166
171
  if (!this.open || !this._steps.length) {
167
172
  this._teardown();
168
173
  this._returnFocus?.focus({ preventScroll: true });
@@ -187,8 +192,11 @@ export class HYTour extends HTMLElement {
187
192
  _teardown() { this._documentAbort?.abort(); this._documentAbort = null; this._resizeObserver?.disconnect(); this._resizeObserver = null; cancelAnimationFrame(this._frame); this._frame = 0; this._target = null; this._scrolledStep = -1; }
188
193
  _renderStep() {
189
194
  const step = this._steps[this.current];
190
- if (!step)
195
+ if (!step) {
196
+ if (this.open)
197
+ this.close('programmatic');
191
198
  return;
199
+ }
192
200
  this._title.textContent = step.title;
193
201
  this._description.textContent = step.description ?? '';
194
202
  this._description.hidden = !step.description;
@@ -211,7 +219,8 @@ export class HYTour extends HTMLElement {
211
219
  this._resizeObserver.observe(this._target);
212
220
  }
213
221
  this._schedulePosition();
214
- queueMicrotask(() => this._popover.focus({ preventScroll: true }));
222
+ queueMicrotask(() => { if (this.open && this.isConnected)
223
+ this._popover.focus({ preventScroll: true }); });
215
224
  }
216
225
  _resolveTarget(target) { if (typeof target === 'function')
217
226
  return target(); if (typeof target === 'string') {
@@ -234,7 +243,7 @@ export class HYTour extends HTMLElement {
234
243
  const margin = 12;
235
244
  const gap = this.gap;
236
245
  const mask = step.mask ?? this.mask;
237
- this._popover.setAttribute('aria-modal', String(mask));
246
+ this._popover.removeAttribute('aria-modal');
238
247
  if (!this._target) {
239
248
  this._masks.forEach(piece => { piece.hidden = !mask; piece.style.cssText = mask ? 'inset:0' : ''; });
240
249
  this._highlight.hidden = true;
@@ -24,6 +24,7 @@ export declare class HYTreeModel {
24
24
  } | null;
25
25
  topLevelSelection(ids: Iterable<string>): string[];
26
26
  removeNode(id: string): boolean;
27
+ removeNodes(ids: Iterable<string>): string[];
27
28
  moveNode(sourceId: string, targetId: string, position: HYTreeDropPosition): boolean;
28
29
  private _createMovePlan;
29
30
  private _visibleRange;
@@ -37,6 +38,7 @@ export declare class HYTreeModel {
37
38
  private _resolveVisibleInsertAt;
38
39
  private _insertVisibleSubtrees;
39
40
  private _collectVisibleSubtree;
41
+ private _insertMany;
40
42
  private _visibleSubtreeEnd;
41
43
  private _refreshVisibleIndexes;
42
44
  private _ensureIndex;
@@ -73,16 +73,29 @@ export class HYTreeModel {
73
73
  });
74
74
  }
75
75
  removeNode(id) {
76
- const found = this.findNode(id);
77
- if (!found)
78
- return false;
79
- const list = found.parent?.children ?? this._data;
80
- const index = this._nodeIndex.get(id)?.index ?? -1;
81
- if (index < 0)
82
- return false;
83
- list.splice(index, 1);
76
+ return this.removeNodes([id]).length !== 0;
77
+ }
78
+ removeNodes(ids) {
79
+ const selected = this.topLevelSelection(ids);
80
+ if (!selected.length)
81
+ return [];
82
+ const groups = new Map();
83
+ for (const id of selected) {
84
+ const indexed = this._nodeIndex.get(id);
85
+ const list = indexed.parent?.children ?? this._data;
86
+ if (!groups.has(list))
87
+ groups.set(list, new Set());
88
+ groups.get(list).add(indexed.index);
89
+ }
90
+ for (const [list, removed] of groups) {
91
+ let write = 0;
92
+ for (let read = 0; read < list.length; read++)
93
+ if (!removed.has(read))
94
+ list[write++] = list[read];
95
+ list.length = write;
96
+ }
84
97
  this.setData(this._data);
85
- return true;
98
+ return selected;
86
99
  }
87
100
  moveNode(sourceId, targetId, position) {
88
101
  this._ensureIndex();
@@ -225,8 +238,8 @@ export class HYTreeModel {
225
238
  this._collectVisibleSubtree(root, moved);
226
239
  if (moved.length === 0)
227
240
  return;
228
- this._visibleNodes.splice(insertAt, 0, ...moved);
229
- this._visibleIds.splice(insertAt, 0, ...moved.map(item => item.node.id));
241
+ this._insertMany(this._visibleNodes, insertAt, moved);
242
+ this._insertMany(this._visibleIds, insertAt, moved.map(item => item.node.id));
230
243
  this._refreshVisibleIndexes(insertAt);
231
244
  }
232
245
  _collectVisibleSubtree(node, result) {
@@ -239,6 +252,14 @@ export class HYTreeModel {
239
252
  for (const child of node.children ?? [])
240
253
  this._collectVisibleSubtree(child, result);
241
254
  }
255
+ _insertMany(list, index, items) {
256
+ const length = list.length;
257
+ list.length += items.length;
258
+ for (let i = length - 1; i >= index; i--)
259
+ list[i + items.length] = list[i];
260
+ for (let i = 0; i < items.length; i++)
261
+ list[index + i] = items[i];
262
+ }
242
263
  _visibleSubtreeEnd(id) {
243
264
  if (!id)
244
265
  return -1;
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;