@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/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 = [
@@ -160,7 +161,11 @@ export class HYTree extends HTMLElement {
160
161
  this.tabIndex = 0;
161
162
  if (!this.hasAttribute('role'))
162
163
  this.setAttribute('role', 'tree');
163
- 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();
164
169
  this.addEventListener('keydown', this._onKeyDown);
165
170
  this._list.addEventListener('click', this._onListClick);
166
171
  this._list.addEventListener('contextmenu', this._onListContextMenu);
@@ -279,13 +284,6 @@ export class HYTree extends HTMLElement {
279
284
  return false;
280
285
  return this._deleteSelection();
281
286
  }
282
- _syncFromAttributes() {
283
- this._readDataAttribute();
284
- if (this.hasAttribute('selected-ids'))
285
- this._setSelectionFromSelectedIdsAttribute();
286
- else
287
- this._setSelectionFromSelectedIdAttribute();
288
- }
289
287
  _readDataAttribute() {
290
288
  const raw = this.getAttribute('data');
291
289
  if (!raw) {
@@ -667,7 +665,7 @@ export class HYTree extends HTMLElement {
667
665
  }
668
666
  }
669
667
  _onKeyDown = (event) => {
670
- if (event.defaultPrevented || this._isEditableTarget(event.target))
668
+ if (event.defaultPrevented || isKeyboardControlEvent(event, this))
671
669
  return;
672
670
  const key = event.key.toLowerCase();
673
671
  const command = event.metaKey || event.ctrlKey;
@@ -826,12 +824,6 @@ export class HYTree extends HTMLElement {
826
824
  if (this._getVisibleFlatNodes().length >= HYTree.VIRTUALIZATION_THRESHOLD)
827
825
  this._render();
828
826
  };
829
- _isEditableTarget(target) {
830
- if (!(target instanceof HTMLElement))
831
- return false;
832
- const tag = target.tagName.toLowerCase();
833
- return tag === 'input' || tag === 'textarea' || tag === 'select' || target.isContentEditable;
834
- }
835
827
  _copySelection() {
836
828
  const nodes = this._getSelectedTopLevelNodes();
837
829
  if (nodes.length === 0)
@@ -863,17 +855,9 @@ export class HYTree extends HTMLElement {
863
855
  return true;
864
856
  }
865
857
  _deleteSelection() {
866
- const ids = this._getTopLevelSelectedIds();
867
- if (ids.length === 0)
868
- return false;
869
- const deletedIds = [];
870
- for (const id of ids) {
871
- if (this._model.removeNode(id))
872
- deletedIds.push(id);
873
- }
858
+ const deletedIds = this._model.removeNodes(this._selectedIds);
874
859
  if (deletedIds.length === 0)
875
860
  return false;
876
- this._model.setData(this._data);
877
861
  this._setSelection([], null, true);
878
862
  this.dispatchEvent(new CustomEvent('data-change', {
879
863
  detail: { data: this._data, action: 'delete', deletedIds },
package/dist/upload.d.ts CHANGED
@@ -50,7 +50,7 @@ export declare class HYUpload extends HTMLElement {
50
50
  private _listeners;
51
51
  private _formDisabled;
52
52
  private _selection;
53
- private _dragDepth;
53
+ private readonly _drop;
54
54
  static get observedAttributes(): string[];
55
55
  constructor();
56
56
  connectedCallback(): void;
@@ -95,13 +95,10 @@ export declare class HYUpload extends HTMLElement {
95
95
  abort(uid?: string): void;
96
96
  removeFile(uid: string): boolean;
97
97
  private _upload;
98
+ private _notifyValueChange;
98
99
  private _emit;
99
100
  private _reject;
100
101
  private _sync;
101
102
  private _onListClick;
102
- private _onDragEnter;
103
- private _onDragLeave;
104
- private _onDragOver;
105
- private _onDrop;
106
103
  }
107
104
  export declare function defineUploadComponents(): void;
package/dist/upload.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { HYNativeDrop, hasFiles } from './internal/native-drop.js';
1
2
  let uploadFileId = 0;
2
3
  export class HYUpload extends HTMLElement {
3
4
  static formAssociated = true;
@@ -17,7 +18,13 @@ export class HYUpload extends HTMLElement {
17
18
  _listeners = null;
18
19
  _formDisabled = false;
19
20
  _selection = 0;
20
- _dragDepth = 0;
21
+ _drop = new HYNativeDrop(this._zone, {
22
+ enabled: () => this.drag,
23
+ accepts: transfer => !this.disabled && !this._formDisabled && hasFiles(transfer),
24
+ active: value => this._zone.classList.toggle('dragover', value),
25
+ drop: event => { if (event.dataTransfer)
26
+ void this.selectFiles(event.dataTransfer.files); },
27
+ });
21
28
  static get observedAttributes() { return ['name', 'accept', 'multiple', 'disabled', 'drag', 'required', 'max-count', 'max-size', 'auto-upload', 'label', 'aria-label', 'show-file-list']; }
22
29
  constructor() {
23
30
  super();
@@ -57,18 +64,19 @@ export class HYUpload extends HTMLElement {
57
64
  this._listeners = new AbortController();
58
65
  const { signal } = this._listeners;
59
66
  this._button.addEventListener('click', () => this.openFileDialog(), { signal });
60
- this._input.addEventListener('change', () => { const files = [...(this._input.files ?? [])]; this._input.value = ''; void this.selectFiles(files); }, { signal });
61
- this._zone.addEventListener('dragenter', this._onDragEnter, { signal });
62
- this._zone.addEventListener('dragleave', this._onDragLeave, { signal });
63
- this._zone.addEventListener('dragover', this._onDragOver, { signal });
64
- this._zone.addEventListener('drop', this._onDrop, { signal });
67
+ // Native picker input precedes asynchronous acceptance; notify only after committing files.
68
+ this._input.addEventListener('input', event => event.stopPropagation(), { signal });
69
+ this._input.addEventListener('change', event => { event.stopPropagation(); const files = [...(this._input.files ?? [])]; this._input.value = ''; void this.selectFiles(files); }, { signal });
70
+ this._drop.connect(signal);
65
71
  this._list.addEventListener('click', this._onListClick, { signal });
66
72
  this._sync();
67
73
  }
68
- disconnectedCallback() { this._listeners?.abort(); this._listeners = null; this._selection++; this.abort(); this._dragDepth = 0; this._zone.classList.remove('dragover'); }
74
+ disconnectedCallback() { this._listeners?.abort(); this._listeners = null; this._selection++; this.abort(); this._drop.reset(); }
69
75
  attributeChangedCallback(name, previous, next) {
70
76
  if (previous === next)
71
77
  return;
78
+ if (name === 'disabled' || name === 'drag')
79
+ this._drop.reset();
72
80
  if (name === 'disabled' && this.disabled) {
73
81
  this._selection++;
74
82
  this.abort();
@@ -116,6 +124,7 @@ export class HYUpload extends HTMLElement {
116
124
  formDisabledCallback(disabled) { this._formDisabled = disabled; if (disabled) {
117
125
  this._selection++;
118
126
  this.abort();
127
+ this._drop.reset();
119
128
  } this._sync(); }
120
129
  formResetCallback() { this.fileList = this._initialFiles ?? []; this._message.textContent = ''; }
121
130
  focus(options) { this._button.focus(options); }
@@ -168,6 +177,7 @@ export class HYUpload extends HTMLElement {
168
177
  }
169
178
  this._files.push(...accepted);
170
179
  this._sync();
180
+ this._notifyValueChange();
171
181
  for (const file of accepted)
172
182
  this._emit(file, 'select');
173
183
  if (this.autoUpload && this._request)
@@ -204,6 +214,7 @@ export class HYUpload extends HTMLElement {
204
214
  this.abort(uid);
205
215
  this._files = this._files.filter(file => file.uid !== uid);
206
216
  this._sync();
217
+ this._notifyValueChange();
207
218
  this._emit(file, 'remove');
208
219
  return true;
209
220
  }
@@ -250,6 +261,7 @@ export class HYUpload extends HTMLElement {
250
261
  this._requests.delete(uid);
251
262
  }
252
263
  }
264
+ _notifyValueChange() { this.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }
253
265
  _emit(file, reason) { this.dispatchEvent(new CustomEvent('upload-change', { detail: { file: { ...file }, fileList: this.fileList, reason }, bubbles: true, composed: true })); }
254
266
  _reject(file, reason, message) { this._message.textContent = `${file.name}: ${message}`; this.dispatchEvent(new CustomEvent('file-reject', { detail: { file, reason, message }, bubbles: true, composed: true })); }
255
267
  _sync() {
@@ -324,24 +336,6 @@ export class HYUpload extends HTMLElement {
324
336
  else if (button?.dataset.retry)
325
337
  void this.upload(button.dataset.retry);
326
338
  };
327
- _onDragEnter = (event) => { if (!this.drag)
328
- return; event.preventDefault(); if (!this.disabled && !this._formDisabled) {
329
- this._dragDepth++;
330
- this._zone.classList.add('dragover');
331
- } };
332
- _onDragLeave = (event) => { if (!this.drag)
333
- return; event.preventDefault(); if (--this._dragDepth <= 0) {
334
- this._dragDepth = 0;
335
- this._zone.classList.remove('dragover');
336
- } };
337
- _onDragOver = (event) => { if (this.drag) {
338
- event.preventDefault();
339
- if (event.dataTransfer)
340
- event.dataTransfer.dropEffect = this.disabled || this._formDisabled ? 'none' : 'copy';
341
- } };
342
- _onDrop = (event) => { if (!this.drag)
343
- return; event.preventDefault(); this._dragDepth = 0; this._zone.classList.remove('dragover'); if (event.dataTransfer)
344
- void this.selectFiles(event.dataTransfer.files); };
345
339
  }
346
340
  function nonnegative(value) { const number = Number(value); return Number.isFinite(number) ? Math.max(0, number) : 0; }
347
341
  function matchesAccept(file, accept) {
@@ -77,6 +77,7 @@ export declare class HYVirtualKeyboard extends HTMLElement {
77
77
  private _press;
78
78
  private _release;
79
79
  private _applyKey;
80
+ private _editableTarget;
80
81
  private _insertText;
81
82
  private _deleteBackward;
82
83
  private _deleteForward;
@@ -1,3 +1,10 @@
1
+ const textSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
2
+ function textBoundaries(value) {
3
+ return [0, ...Array.from(textSegmenter.segment(value), part => part.index + part.segment.length)];
4
+ }
5
+ function boundaryBefore(edges, position) { return edges.filter(edge => edge < position).at(-1) ?? 0; }
6
+ function boundaryFloor(edges, position) { return edges.filter(edge => edge <= position).at(-1) ?? 0; }
7
+ function boundaryCeil(edges, position) { return edges.find(edge => edge >= position) ?? edges.at(-1); }
1
8
  const LETTERS = 'QWERTYUIOPASDFGHJKLZXCVBNM';
2
9
  const DIGITS = [
3
10
  ['Digit1', '1', '!'], ['Digit2', '2', '@'], ['Digit3', '3', '#'], ['Digit4', '4', '$'], ['Digit5', '5', '%'],
@@ -152,7 +159,8 @@ export class HYVirtualKeyboard extends HTMLElement {
152
159
  const operation = ++this._operation;
153
160
  const requested = options.interval == null ? 45 : Number(options.interval);
154
161
  const interval = Number.isFinite(requested) ? Math.min(10_000, Math.max(0, requested)) : 45;
155
- for (const character of String(text)) {
162
+ for (const part of textSegmenter.segment(String(text))) {
163
+ const character = part.segment;
156
164
  if (operation !== this._operation || !this.isConnected)
157
165
  return;
158
166
  const match = this._findCharacterKey(character);
@@ -169,10 +177,11 @@ export class HYVirtualKeyboard extends HTMLElement {
169
177
  }
170
178
  }
171
179
  clear() {
172
- if (!this._target || this.disabled || this._target.disabled || this._target.readOnly)
180
+ const target = this._editableTarget();
181
+ if (!target)
173
182
  return;
174
- this._target.value = '';
175
- this._target.setSelectionRange(0, 0);
183
+ target.value = '';
184
+ target.setSelectionRange(0, 0);
176
185
  this._dispatchTargetInput('deleteContent', null);
177
186
  this._emitInput({ code: 'Clear', key: '', action: 'delete', source: 'api' }, 'deleteContent');
178
187
  }
@@ -279,6 +288,8 @@ export class HYVirtualKeyboard extends HTMLElement {
279
288
  this._dispatchKeyEvent('virtual-keyboard-up', key, resolvedValue, source);
280
289
  }
281
290
  _applyKey(key, resolvedValue, source) {
291
+ if (!this._editableTarget(false))
292
+ return;
282
293
  const descriptor = { code: key.code, key: resolvedValue, action: key.action ?? 'character', source };
283
294
  if (key.action === 'shift' || key.action === 'caps-lock')
284
295
  return;
@@ -313,69 +324,89 @@ export class HYVirtualKeyboard extends HTMLElement {
313
324
  else
314
325
  this._insertText(key.action === 'space' ? ' ' : resolvedValue, 'insertText', descriptor);
315
326
  }
316
- _insertText(text, inputType, descriptor) {
327
+ _editableTarget(edit = true) {
317
328
  const target = this._target;
318
- if (!target || target.disabled || target.readOnly)
329
+ if (!target || this.disabled || target.disabled || edit && target.readOnly)
330
+ return null;
331
+ if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target.type))
332
+ return null;
333
+ return target;
334
+ }
335
+ _insertText(text, inputType, descriptor) {
336
+ const target = this._editableTarget();
337
+ if (!target)
319
338
  return;
320
- const start = target.selectionStart ?? target.value.length;
321
- const end = target.selectionEnd ?? start;
339
+ const edges = textBoundaries(target.value), rawStart = target.selectionStart ?? target.value.length, rawEnd = target.selectionEnd ?? rawStart;
340
+ const start = boundaryFloor(edges, rawStart), end = rawStart === rawEnd ? start : boundaryCeil(edges, rawEnd);
322
341
  target.setRangeText(text, start, end, 'end');
323
342
  this._dispatchTargetInput(inputType, text);
324
343
  this._emitInput(descriptor, inputType);
325
344
  }
326
345
  _deleteBackward(descriptor) {
327
- const target = this._target;
328
- if (!target || target.disabled || target.readOnly)
346
+ const target = this._editableTarget();
347
+ if (!target)
329
348
  return;
330
- const start = target.selectionStart ?? 0;
331
- const end = target.selectionEnd ?? start;
332
- if (start === end && start === 0)
349
+ const edges = textBoundaries(target.value), rawStart = target.selectionStart ?? 0, rawEnd = target.selectionEnd ?? rawStart;
350
+ if (rawStart === 0 && rawEnd === 0)
333
351
  return;
334
- target.setRangeText('', start === end ? start - 1 : start, end, 'end');
352
+ const end = boundaryCeil(edges, rawEnd), start = rawStart === rawEnd ? boundaryBefore(edges, end) : boundaryFloor(edges, rawStart);
353
+ target.setRangeText('', start, end, 'end');
335
354
  this._dispatchTargetInput('deleteContentBackward', null);
336
355
  this._emitInput(descriptor, 'deleteContentBackward');
337
356
  }
338
357
  _deleteForward(descriptor) {
339
- const target = this._target;
340
- if (!target || target.disabled || target.readOnly)
358
+ const target = this._editableTarget();
359
+ if (!target)
341
360
  return;
342
- const start = target.selectionStart ?? 0;
343
- const end = target.selectionEnd ?? start;
344
- if (start === end && end >= target.value.length)
361
+ const edges = textBoundaries(target.value), rawStart = target.selectionStart ?? 0, rawEnd = target.selectionEnd ?? rawStart;
362
+ if (rawStart === rawEnd && rawEnd >= target.value.length)
345
363
  return;
346
- target.setRangeText('', start, start === end ? end + 1 : end, 'end');
364
+ const start = boundaryFloor(edges, rawStart), end = rawStart === rawEnd ? edges.find(edge => edge > start) : boundaryCeil(edges, rawEnd);
365
+ target.setRangeText('', start, end, 'end');
347
366
  this._dispatchTargetInput('deleteContentForward', null);
348
367
  this._emitInput(descriptor, 'deleteContentForward');
349
368
  }
350
- _moveCaret(delta) { const target = this._target; if (!target)
351
- return; const position = Math.max(0, Math.min(target.value.length, (target.selectionStart ?? 0) + delta)); this._setCaret(position); }
369
+ _moveCaret(delta) {
370
+ const target = this._editableTarget(false);
371
+ if (!target)
372
+ return;
373
+ const edges = textBoundaries(target.value), start = target.selectionStart ?? 0, end = target.selectionEnd ?? start;
374
+ const position = start !== end ? (delta < 0 ? boundaryFloor(edges, start) : boundaryCeil(edges, end))
375
+ : delta < 0 ? boundaryBefore(edges, start) : edges.find(edge => edge > start) ?? target.value.length;
376
+ this._setCaret(position);
377
+ }
352
378
  _moveCaretVertical(direction) {
353
- const target = this._target;
379
+ const target = this._editableTarget(false);
354
380
  if (!(target instanceof HTMLTextAreaElement))
355
381
  return;
356
- const value = target.value;
357
- const position = target.selectionStart ?? 0;
358
- const lineStart = value.lastIndexOf('\n', position - 1) + 1;
359
- const column = position - lineStart;
382
+ const value = target.value, position = target.selectionStart ?? 0, lineStart = value.lastIndexOf('\n', position - 1) + 1;
383
+ const column = Array.from(textSegmenter.segment(value.slice(lineStart, position))).length;
384
+ let start, end;
360
385
  if (direction < 0) {
361
386
  if (lineStart === 0)
362
387
  return;
363
- const previousEnd = lineStart - 1;
364
- const previousStart = value.lastIndexOf('\n', previousEnd - 1) + 1;
365
- this._setCaret(previousStart + Math.min(column, previousEnd - previousStart));
388
+ end = lineStart - 1;
389
+ start = value.lastIndexOf('\n', end - 1) + 1;
366
390
  }
367
391
  else {
368
392
  const currentEnd = value.indexOf('\n', position);
369
393
  if (currentEnd < 0)
370
394
  return;
371
- const nextStart = currentEnd + 1;
372
- const nextEnd = value.indexOf('\n', nextStart);
373
- const length = (nextEnd < 0 ? value.length : nextEnd) - nextStart;
374
- this._setCaret(nextStart + Math.min(column, length));
395
+ start = currentEnd + 1;
396
+ const nextEnd = value.indexOf('\n', start);
397
+ end = nextEnd < 0 ? value.length : nextEnd;
375
398
  }
399
+ const edges = textBoundaries(value.slice(start, end));
400
+ this._setCaret(start + edges[Math.min(column, edges.length - 1)]);
401
+ }
402
+ _setCaret(position) {
403
+ const target = this._editableTarget(false);
404
+ if (!target)
405
+ return;
406
+ const next = boundaryFloor(textBoundaries(target.value), Math.max(0, Math.min(target.value.length, position)));
407
+ target.focus({ preventScroll: true });
408
+ target.setSelectionRange(next, next);
376
409
  }
377
- _setCaret(position) { const target = this._target; if (!target)
378
- return; target.focus({ preventScroll: true }); target.setSelectionRange(position, position); }
379
410
  _dispatchTargetInput(inputType, data) {
380
411
  if (!this._target)
381
412
  return;
@@ -27,6 +27,7 @@ export declare class HYVirtualList<T = unknown> extends HTMLElement {
27
27
  private _height;
28
28
  private _overscan;
29
29
  private _range;
30
+ private readonly _rows;
30
31
  private _resizeObserver;
31
32
  private _connected;
32
33
  private readonly _onScroll;
@@ -35,6 +35,7 @@ export class HYVirtualList extends HTMLElement {
35
35
  _height = DEFAULT_HEIGHT;
36
36
  _overscan = DEFAULT_OVERSCAN;
37
37
  _range = null;
38
+ _rows = new Map();
38
39
  _resizeObserver = null;
39
40
  _connected = false;
40
41
  _onScroll = () => this._renderWindow();
@@ -270,6 +271,11 @@ export class HYVirtualList extends HTMLElement {
270
271
  const rows = [];
271
272
  for (let index = range.startIndex; index < range.endIndex; index += 1) {
272
273
  const item = this._items[index];
274
+ const retained = !force ? this._rows.get(index) : undefined;
275
+ if (retained) {
276
+ rows.push(retained);
277
+ continue;
278
+ }
273
279
  const row = document.createElement('div');
274
280
  row.className = 'hy-virtual-list-item';
275
281
  row.dataset.hyVirtualListGenerated = '';
@@ -311,10 +317,21 @@ export class HYVirtualList extends HTMLElement {
311
317
  }));
312
318
  }
313
319
  _replaceRows(rows) {
314
- // Keep the recycled window entirely inside the shadow tree. Slotted light
315
- // DOM rows can be redistributed asynchronously while a host application is
316
- // also updating, which may briefly paint rows from the previous range.
317
- this._window.replaceChildren(...rows);
320
+ const retained = new Set(rows), active = this.shadowRoot?.activeElement;
321
+ for (const row of this._rows.values())
322
+ if (!retained.has(row)) {
323
+ if (this.isConnected && active && row.contains(active))
324
+ this._viewport.focus({ preventScroll: true });
325
+ row.remove();
326
+ }
327
+ this._rows.clear();
328
+ let cursor = this._window.firstElementChild;
329
+ for (const row of rows) {
330
+ this._rows.set(Number(row.dataset.index), row);
331
+ if (row !== cursor)
332
+ this._window.insertBefore(row, cursor);
333
+ cursor = row.nextElementSibling;
334
+ }
318
335
  }
319
336
  }
320
337
  export function defineVirtualListComponents() {
@@ -1,9 +1,10 @@
1
+ import { finiteNumber as readFiniteNumber } from './internal/numbers.js';
1
2
  const DEFAULT_DURATION = 320;
2
3
  const DEFAULT_EASING = 'cubic-bezier(0.22, 1, 0.36, 1)';
3
4
  const BUTTONS = ['left', 'middle', 'right'];
4
5
  const STATES = ['idle', 'left-down', 'middle-down', 'right-down'];
5
6
  function finiteNumber(value, fallback) {
6
- const number = Number(value);
7
+ const number = readFiniteNumber(value, fallback);
7
8
  return Number.isFinite(number) ? number : fallback;
8
9
  }
9
10
  function normalizeButton(button) {
package/dist/watermark.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { finiteNumber as readFiniteNumber } from './internal/numbers.js';
1
2
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
2
3
  function finiteNumber(value, fallback, min, max) {
3
- const number = Number(value);
4
+ const number = readFiniteNumber(value, fallback);
4
5
  return Number.isFinite(number) ? Math.min(max, Math.max(min, number)) : fallback;
5
6
  }
6
7
  function svgElement(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haiyue/ui",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "Dependency-free Web Components for HaiyueStudio tools and products.",
6
6
  "license": "MIT",
@@ -101,6 +101,18 @@
101
101
  "types": "./dist/draggable.d.ts",
102
102
  "import": "./dist/draggable.js"
103
103
  },
104
+ "./drag-source": {
105
+ "types": "./dist/drag-source.d.ts",
106
+ "import": "./dist/drag-source.js"
107
+ },
108
+ "./dropzone": {
109
+ "types": "./dist/dropzone.d.ts",
110
+ "import": "./dist/dropzone.js"
111
+ },
112
+ "./sortable": {
113
+ "types": "./dist/sortable.d.ts",
114
+ "import": "./dist/sortable.js"
115
+ },
104
116
  "./dropdown": {
105
117
  "types": "./dist/dropdown.d.ts",
106
118
  "import": "./dist/dropdown.js"
@@ -273,11 +285,26 @@
273
285
  "types": "./dist/tree.d.ts",
274
286
  "import": "./dist/tree.js"
275
287
  },
276
- "./empty": { "types": "./dist/empty.d.ts", "import": "./dist/empty.js" },
277
- "./result": { "types": "./dist/result.d.ts", "import": "./dist/result.js" },
278
- "./avatar": { "types": "./dist/avatar.d.ts", "import": "./dist/avatar.js" },
279
- "./card": { "types": "./dist/card.d.ts", "import": "./dist/card.js" },
280
- "./descriptions": { "types": "./dist/descriptions.d.ts", "import": "./dist/descriptions.js" },
288
+ "./empty": {
289
+ "types": "./dist/empty.d.ts",
290
+ "import": "./dist/empty.js"
291
+ },
292
+ "./result": {
293
+ "types": "./dist/result.d.ts",
294
+ "import": "./dist/result.js"
295
+ },
296
+ "./avatar": {
297
+ "types": "./dist/avatar.d.ts",
298
+ "import": "./dist/avatar.js"
299
+ },
300
+ "./card": {
301
+ "types": "./dist/card.d.ts",
302
+ "import": "./dist/card.js"
303
+ },
304
+ "./descriptions": {
305
+ "types": "./dist/descriptions.d.ts",
306
+ "import": "./dist/descriptions.js"
307
+ },
281
308
  "./themes/light.css": "./themes/haiyue-light.css",
282
309
  "./themes/dark.css": "./themes/haiyue-dark.css",
283
310
  "./package.json": "./package.json",