@haiyue/ui 0.2.2 → 0.3.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 (119) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +506 -2
  3. package/dist/adapters/web/renderer.js +1 -8
  4. package/dist/adapters/web/styles.d.ts +2 -3
  5. package/dist/adapters/web/styles.js +26 -23
  6. package/dist/alert.d.ts +39 -0
  7. package/dist/alert.js +144 -0
  8. package/dist/anchor.d.ts +60 -0
  9. package/dist/anchor.js +274 -0
  10. package/dist/auto-complete.d.ts +83 -0
  11. package/dist/auto-complete.js +267 -0
  12. package/dist/avatar.d.ts +45 -0
  13. package/dist/avatar.js +135 -0
  14. package/dist/badge.js +5 -5
  15. package/dist/border-beam.js +1 -1
  16. package/dist/breadcrumb.js +5 -5
  17. package/dist/button-group.js +8 -8
  18. package/dist/button.js +10 -10
  19. package/dist/card.d.ts +29 -0
  20. package/dist/card.js +101 -0
  21. package/dist/carousel.js +6 -6
  22. package/dist/cascader.js +12 -12
  23. package/dist/checkbox.d.ts +12 -0
  24. package/dist/checkbox.js +22 -6
  25. package/dist/collapse.js +6 -6
  26. package/dist/context-menu.js +3 -3
  27. package/dist/date-picker.js +13 -13
  28. package/dist/descriptions.d.ts +44 -0
  29. package/dist/descriptions.js +169 -0
  30. package/dist/dialog.js +11 -11
  31. package/dist/divider.js +2 -2
  32. package/dist/draggable.js +1 -1
  33. package/dist/drawer.js +12 -12
  34. package/dist/dropdown.js +3 -3
  35. package/dist/empty.d.ts +20 -0
  36. package/dist/empty.js +58 -0
  37. package/dist/expandable.js +4 -4
  38. package/dist/form-item.d.ts +60 -0
  39. package/dist/form-item.js +212 -0
  40. package/dist/form.d.ts +41 -0
  41. package/dist/form.js +154 -0
  42. package/dist/history-controls.js +5 -5
  43. package/dist/image-preview.d.ts +22 -0
  44. package/dist/image-preview.js +38 -0
  45. package/dist/image.d.ts +52 -0
  46. package/dist/image.js +152 -0
  47. package/dist/index.d.ts +48 -0
  48. package/dist/index.js +72 -0
  49. package/dist/input.d.ts +11 -0
  50. package/dist/input.js +29 -15
  51. package/dist/internal/anchored-popup.d.ts +19 -0
  52. package/dist/internal/anchored-popup.js +89 -0
  53. package/dist/internal/form-control.d.ts +22 -0
  54. package/dist/internal/form-control.js +52 -0
  55. package/dist/internal/image-viewer.d.ts +51 -0
  56. package/dist/internal/image-viewer.js +210 -0
  57. package/dist/internal/pagination.d.ts +35 -0
  58. package/dist/internal/pagination.js +169 -0
  59. package/dist/internal/popover-base.d.ts +87 -0
  60. package/dist/internal/popover-base.js +365 -0
  61. package/dist/internal/presentation.d.ts +2 -0
  62. package/dist/internal/presentation.js +28 -0
  63. package/dist/mentions.d.ts +115 -0
  64. package/dist/mentions.js +485 -0
  65. package/dist/menu-shared.d.ts +1 -1
  66. package/dist/menu-shared.js +3 -3
  67. package/dist/menu.d.ts +63 -0
  68. package/dist/menu.js +339 -0
  69. package/dist/modal.js +10 -10
  70. package/dist/notification.js +9 -9
  71. package/dist/pagination.d.ts +34 -0
  72. package/dist/pagination.js +73 -0
  73. package/dist/popconfirm.d.ts +6 -0
  74. package/dist/popconfirm.js +7 -0
  75. package/dist/popover.d.ts +6 -0
  76. package/dist/popover.js +7 -0
  77. package/dist/progress.d.ts +30 -0
  78. package/dist/progress.js +102 -0
  79. package/dist/qr-code.js +3 -3
  80. package/dist/radio.d.ts +10 -0
  81. package/dist/radio.js +18 -5
  82. package/dist/range.js +7 -7
  83. package/dist/rate.js +3 -3
  84. package/dist/resizable.js +4 -4
  85. package/dist/result.d.ts +22 -0
  86. package/dist/result.js +88 -0
  87. package/dist/ribbon.d.ts +19 -0
  88. package/dist/ribbon.js +106 -0
  89. package/dist/segmented.d.ts +39 -0
  90. package/dist/segmented.js +192 -0
  91. package/dist/select.d.ts +12 -0
  92. package/dist/select.js +31 -13
  93. package/dist/skeleton.js +10 -10
  94. package/dist/spin.d.ts +26 -0
  95. package/dist/spin.js +80 -0
  96. package/dist/steps.js +13 -13
  97. package/dist/switch.d.ts +44 -0
  98. package/dist/switch.js +104 -0
  99. package/dist/table.d.ts +0 -2
  100. package/dist/table.js +46 -87
  101. package/dist/tabs.js +7 -7
  102. package/dist/tag.js +8 -8
  103. package/dist/time-picker.js +10 -10
  104. package/dist/timeline.js +12 -12
  105. package/dist/toast.js +9 -9
  106. package/dist/tooltip.js +4 -4
  107. package/dist/tour.js +11 -11
  108. package/dist/tree-node.js +2 -2
  109. package/dist/tree-select.d.ts +94 -0
  110. package/dist/tree-select.js +398 -0
  111. package/dist/tree.js +6 -5
  112. package/dist/upload.d.ts +107 -0
  113. package/dist/upload.js +353 -0
  114. package/dist/virtual-keyboard.js +5 -5
  115. package/dist/virtual-list.js +4 -4
  116. package/dist/virtual-mouse.js +5 -5
  117. package/package.json +82 -1
  118. package/themes/haiyue-dark.css +51 -0
  119. package/themes/haiyue-light.css +51 -0
package/dist/tour.js CHANGED
@@ -47,20 +47,20 @@ export class HYTour extends HTMLElement {
47
47
  const header = document.createElement('header');
48
48
  const footer = document.createElement('footer');
49
49
  style.textContent = `
50
- :host { position: fixed; z-index: var(--_hy-tour-z-index, 1000); inset: 0; display: block; visibility: hidden; pointer-events: none; color: var(--hy-text-color, #eef3ff); font: 12px/1.5 system-ui, sans-serif; }
50
+ :host { position: fixed; z-index: var(--_hy-tour-z-index, 1000); inset: 0; display: block; visibility: hidden; pointer-events: none; color: var(--hy-text-color, #eef3ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-relaxed, 1.5) var(--hy-font-family, system-ui, sans-serif); }
51
51
  :host([open]) { visibility: visible; }
52
- .mask { position: absolute; background: var(--hy-tour-mask-color, rgba(3, 7, 18, .68)); pointer-events: auto; }
52
+ .mask { position: absolute; background: var(--hy-tour-mask-color, var(--hy-dialog-backdrop-color, rgba(3, 7, 18, .68))); pointer-events: auto; }
53
53
  .mask[hidden], .highlight[hidden] { display: none; }
54
- .highlight { position: absolute; box-sizing: border-box; border: 1px solid var(--hy-tour-highlight-color, var(--hy-accent-color, #79a8ff)); border-radius: var(--hy-tour-highlight-radius, 8px); box-shadow: 0 0 0 3px var(--hy-focus-ring-color, rgba(121, 168, 255, .22)); pointer-events: none; }
55
- .popover { position: absolute; width: min(var(--hy-tour-width, 310px), calc(100vw - 24px)); box-sizing: border-box; padding: 15px; border: 1px solid var(--hy-border-color, #3d4654); border-radius: var(--hy-tour-radius, 10px); outline: none; background: var(--hy-surface-elevated-color, #171d27); box-shadow: 0 18px 48px var(--hy-menu-shadow-color, rgba(0, 0, 0, .4)); pointer-events: auto; }
56
- header { display: flex; align-items: flex-start; gap: 12px; }
57
- h2 { flex: 1; margin: 0; color: var(--hy-text-color, #eef3ff); font: 650 14px/1.4 system-ui, sans-serif; }
58
- .close { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 4px; color: var(--hy-muted-color, #788697); background: transparent; cursor: pointer; font: 17px/1 system-ui, sans-serif; }
54
+ .highlight { position: absolute; box-sizing: border-box; border: 1px solid var(--hy-tour-highlight-color, var(--hy-accent-color, #79a8ff)); border-radius: var(--hy-tour-highlight-radius, var(--hy-radius-lg, 8px)); box-shadow: 0 0 0 3px var(--hy-focus-ring-color, rgba(121, 168, 255, .22)); pointer-events: none; }
55
+ .popover { position: absolute; width: min(var(--hy-tour-width, 310px), calc(100vw - 24px)); box-sizing: border-box; padding: calc(var(--hy-space-7, 14px) + 1px); border: 1px solid var(--hy-border-color, #3d4654); border-radius: var(--hy-tour-radius, calc(var(--hy-radius-lg, 8px) + 2px)); outline: none; background: var(--hy-surface-elevated-color, #171d27); box-shadow: 0 18px 48px var(--hy-menu-shadow-color, rgba(0, 0, 0, .4)); pointer-events: auto; }
56
+ header { display: flex; align-items: flex-start; gap: var(--hy-space-6, 12px); }
57
+ h2 { flex: 1; margin: 0; color: var(--hy-text-color, #eef3ff); font: calc(var(--hy-font-weight-semibold, 600) + 50) var(--hy-font-size-md, 14px)/var(--hy-line-height-snug, 1.4) var(--hy-font-family, system-ui, sans-serif); }
58
+ .close { width: 24px; height: 24px; padding: 0; border: 0; border-radius: var(--hy-radius-sm, 4px); color: var(--hy-muted-color, #788697); background: transparent; cursor: pointer; font: calc(var(--hy-font-size-lg, 16px) + 1px)/var(--hy-line-height-tight, 1) var(--hy-font-family, system-ui, sans-serif); }
59
59
  .close:hover { color: var(--hy-text-color, #eef3ff); background: var(--hy-hover-bg-color, #273241); }
60
- .description { margin-top: 8px; color: var(--hy-secondary-text-color, #aebbd0); }
61
- footer { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
62
- .counter { flex: 1; color: var(--hy-muted-color, #788697); font: 10px/1 ui-monospace, monospace; }
63
- footer button { min-width: 58px; height: 29px; padding: 0 10px; border: 1px solid var(--hy-border-color, #3d4654); border-radius: 5px; color: var(--hy-secondary-text-color, #aebbd0); background: transparent; cursor: pointer; font: inherit; }
60
+ .description { margin-top: var(--hy-space-4, 8px); color: var(--hy-secondary-text-color, #aebbd0); }
61
+ footer { display: flex; align-items: center; gap: var(--hy-space-4, 8px); margin-top: var(--hy-space-8, 16px); }
62
+ .counter { flex: 1; color: var(--hy-muted-color, #788697); font: var(--hy-font-size-xs, 10px)/var(--hy-line-height-tight, 1) var(--hy-font-family-mono, ui-monospace, monospace); }
63
+ footer button { min-width: 58px; height: 29px; padding: 0 var(--hy-space-5, 10px); border: 1px solid var(--hy-border-color, #3d4654); border-radius: calc(var(--hy-radius-sm, 4px) + 1px); color: var(--hy-secondary-text-color, #aebbd0); background: transparent; cursor: pointer; font: inherit; }
64
64
  footer button:hover:not(:disabled) { color: var(--hy-text-color, #eef3ff); border-color: var(--hy-hover-border-color, #596779); background: var(--hy-hover-bg-color, #273241); }
65
65
  footer .next { color: var(--hy-selected-text-color, #fff); border-color: var(--hy-selected-bg-color, #554cc6); background: var(--hy-selected-bg-color, #554cc6); }
66
66
  footer button:disabled { visibility: hidden; }
package/dist/tree-node.js CHANGED
@@ -13,7 +13,7 @@ export class HYTreeNode extends HTMLElement {
13
13
  display: flex;
14
14
  align-items: center;
15
15
  min-width: 0;
16
- gap: 6px;
16
+ gap: var(--hy-space-3, 6px);
17
17
  color: inherit;
18
18
  font: inherit;
19
19
  }
@@ -23,7 +23,7 @@ export class HYTreeNode extends HTMLElement {
23
23
  display: inline-grid;
24
24
  place-items: center;
25
25
  color: var(--hy-tree-icon-color, var(--hy-secondary-text-color, #8fa7c8));
26
- font-size: 12px;
26
+ font-size: var(--hy-font-size-sm, 12px);
27
27
  }
28
28
  .label {
29
29
  min-width: 0;
@@ -0,0 +1,94 @@
1
+ export interface HYTreeSelectOption {
2
+ value: string;
3
+ label: string;
4
+ disabled?: boolean;
5
+ selectable?: boolean;
6
+ expanded?: boolean;
7
+ children?: HYTreeSelectOption[];
8
+ }
9
+ export interface HYTreeSelectChangeDetail {
10
+ value: string | string[];
11
+ values: string[];
12
+ options: HYTreeSelectOption[];
13
+ }
14
+ export interface HYTreeSelectExpandDetail {
15
+ expandedKeys: string[];
16
+ }
17
+ export declare class HYTreeSelect extends HTMLElement {
18
+ static readonly formAssociated = true;
19
+ private readonly _internals;
20
+ private readonly _control;
21
+ private readonly _tags;
22
+ private readonly _input;
23
+ private readonly _clear;
24
+ private readonly _panel;
25
+ private readonly _tree;
26
+ private readonly _status;
27
+ private readonly _id;
28
+ private readonly _popup;
29
+ private _options;
30
+ private _entries;
31
+ private _expanded;
32
+ private _visible;
33
+ private _active;
34
+ private _query;
35
+ private _composing;
36
+ private _formDisabled;
37
+ private _initialValues;
38
+ private _listeners;
39
+ private _customError;
40
+ static get observedAttributes(): string[];
41
+ constructor();
42
+ connectedCallback(): void;
43
+ disconnectedCallback(): void;
44
+ attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
45
+ get options(): HYTreeSelectOption[];
46
+ set options(value: HYTreeSelectOption[]);
47
+ get values(): string[];
48
+ set values(value: string[]);
49
+ get value(): string | string[];
50
+ set value(value: string | readonly string[]);
51
+ get multiple(): boolean;
52
+ set multiple(value: boolean);
53
+ get disabled(): boolean;
54
+ set disabled(value: boolean);
55
+ get readOnly(): boolean;
56
+ set readOnly(value: boolean);
57
+ get searchable(): boolean;
58
+ set searchable(value: boolean);
59
+ get clearable(): boolean;
60
+ set clearable(value: boolean);
61
+ get loading(): boolean;
62
+ set loading(value: boolean);
63
+ get open(): boolean;
64
+ set open(value: boolean);
65
+ get expandedKeys(): string[];
66
+ set expandedKeys(value: string[]);
67
+ get placeholder(): string;
68
+ set placeholder(value: string);
69
+ get form(): HTMLFormElement | null;
70
+ get validity(): ValidityState;
71
+ get validationMessage(): string;
72
+ checkValidity(): boolean;
73
+ reportValidity(): boolean;
74
+ setCustomValidity(message: string): void;
75
+ formDisabledCallback(disabled: boolean): void;
76
+ formResetCallback(): void;
77
+ formStateRestoreCallback(state: string | File | FormData | null): void;
78
+ focus(options?: FocusOptions): void;
79
+ blur(): void;
80
+ private get _disabled();
81
+ private _setOptions;
82
+ private _sync;
83
+ private _syncForm;
84
+ private _render;
85
+ private _syncActive;
86
+ private _setOpen;
87
+ private _emitSearch;
88
+ private _commit;
89
+ private _select;
90
+ private _toggle;
91
+ private _onTreeClick;
92
+ private _onKeydown;
93
+ }
94
+ export declare function defineTreeSelectComponents(): void;
@@ -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.js CHANGED
@@ -68,7 +68,7 @@ export class HYTree extends HTMLElement {
68
68
  min-height: 0;
69
69
  color: var(--hy-tree-text-color, var(--hy-text-color, #c8d3e4));
70
70
  background: var(--hy-panel-bg-color, #171d28);
71
- font: 12px system-ui, sans-serif;
71
+ font: var(--hy-font-size-sm, 12px) var(--hy-font-family, system-ui, sans-serif);
72
72
  text-align: left;
73
73
  user-select: none;
74
74
  overflow: auto;
@@ -77,14 +77,15 @@ export class HYTree extends HTMLElement {
77
77
  box-sizing: border-box;
78
78
  width: 100%;
79
79
  flex: 0 0 auto;
80
- padding: 4px;
80
+ padding: var(--hy-space-2, 4px);
81
81
  }
82
82
  .row {
83
83
  height: 28px;
84
84
  display: flex;
85
85
  align-items: center;
86
- gap: 4px;
87
- border-radius: 4px;
86
+ gap: var(--hy-space-2, 4px);
87
+ padding-left: calc(var(--hy-space-2, 4px) + var(--_hy-tree-depth, 0) * var(--hy-space-8, 16px));
88
+ border-radius: var(--hy-radius-sm, 4px);
88
89
  color: var(--hy-tree-text-color, var(--hy-text-color, #c8d3e4));
89
90
  cursor: default;
90
91
  }
@@ -394,7 +395,7 @@ export class HYTree extends HTMLElement {
394
395
  const { row, toggle, content } = rendered;
395
396
  row.className = `row${selected ? ' selected' : ''}${active ? ' active' : ''}`;
396
397
  row.dataset.id = node.id;
397
- row.style.paddingLeft = `${depth * 16 + 4}px`;
398
+ row.style.setProperty('--_hy-tree-depth', String(depth));
398
399
  row.draggable = this.allowDrag;
399
400
  toggle.className = `${hasChildren ? 'toggle' : 'toggle empty'}${expanded ? ' expanded' : ''}`;
400
401
  toggle.disabled = !hasChildren;