@haiyue/ui 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +523 -4
- package/dist/adapters/web/controls.js +48 -8
- package/dist/adapters/web/renderer.js +9 -11
- package/dist/adapters/web/styles.d.ts +2 -3
- package/dist/adapters/web/styles.js +26 -23
- package/dist/alert.d.ts +39 -0
- package/dist/alert.js +144 -0
- package/dist/anchor.d.ts +62 -0
- package/dist/anchor.js +293 -0
- package/dist/auto-complete.d.ts +83 -0
- package/dist/auto-complete.js +267 -0
- package/dist/avatar.d.ts +45 -0
- package/dist/avatar.js +135 -0
- package/dist/badge.js +5 -5
- package/dist/border-beam.js +3 -2
- package/dist/breadcrumb.js +5 -5
- package/dist/button-group.js +8 -8
- package/dist/button.js +10 -10
- package/dist/card.d.ts +29 -0
- package/dist/card.js +101 -0
- package/dist/carousel.js +6 -6
- package/dist/cascader.js +19 -13
- package/dist/checkbox.d.ts +12 -0
- package/dist/checkbox.js +22 -6
- package/dist/collapse.js +6 -6
- package/dist/context-menu.js +3 -4
- package/dist/core/actions.js +7 -8
- package/dist/core/data.d.ts +1 -1
- package/dist/core/data.js +44 -10
- package/dist/core/platform-view.js +8 -2
- package/dist/core/selection.js +4 -4
- package/dist/core/semantics.d.ts +26 -0
- package/dist/core/semantics.js +8 -0
- package/dist/core/text.js +3 -3
- package/dist/core/validation.d.ts +3 -1
- package/dist/core/validation.js +23 -5
- package/dist/date-picker.js +19 -13
- package/dist/descriptions.d.ts +44 -0
- package/dist/descriptions.js +169 -0
- package/dist/dialog.d.ts +4 -0
- package/dist/dialog.js +48 -27
- package/dist/divider.js +2 -2
- package/dist/draggable.js +5 -3
- package/dist/drawer.js +16 -24
- package/dist/dropdown.js +3 -4
- package/dist/empty.d.ts +20 -0
- package/dist/empty.js +58 -0
- package/dist/expandable.js +4 -4
- package/dist/form-item.d.ts +60 -0
- package/dist/form-item.js +212 -0
- package/dist/form.d.ts +41 -0
- package/dist/form.js +154 -0
- package/dist/history-controls.js +5 -5
- package/dist/image-preview.d.ts +22 -0
- package/dist/image-preview.js +38 -0
- package/dist/image.d.ts +52 -0
- package/dist/image.js +152 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +72 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +32 -18
- package/dist/internal/anchored-popup.d.ts +19 -0
- package/dist/internal/anchored-popup.js +89 -0
- package/dist/internal/focus.d.ts +2 -0
- package/dist/internal/focus.js +31 -0
- package/dist/internal/form-control.d.ts +22 -0
- package/dist/internal/form-control.js +52 -0
- package/dist/internal/image-viewer.d.ts +51 -0
- package/dist/internal/image-viewer.js +210 -0
- package/dist/internal/keyboard.d.ts +2 -0
- package/dist/internal/keyboard.js +12 -0
- package/dist/internal/numbers.d.ts +2 -0
- package/dist/internal/numbers.js +8 -0
- package/dist/internal/pagination.d.ts +35 -0
- package/dist/internal/pagination.js +169 -0
- package/dist/internal/popover-base.d.ts +87 -0
- package/dist/internal/popover-base.js +365 -0
- package/dist/internal/presentation.d.ts +2 -0
- package/dist/internal/presentation.js +28 -0
- package/dist/mentions.d.ts +115 -0
- package/dist/mentions.js +485 -0
- package/dist/menu-shared.d.ts +1 -1
- package/dist/menu-shared.js +3 -3
- package/dist/menu.d.ts +63 -0
- package/dist/menu.js +339 -0
- package/dist/modal.js +11 -40
- package/dist/notification.js +11 -10
- package/dist/pagination.d.ts +34 -0
- package/dist/pagination.js +73 -0
- package/dist/popconfirm.d.ts +6 -0
- package/dist/popconfirm.js +7 -0
- package/dist/popover.d.ts +6 -0
- package/dist/popover.js +7 -0
- package/dist/portable/page.js +25 -14
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +102 -0
- package/dist/qr-code.js +3 -3
- package/dist/radio.d.ts +10 -0
- package/dist/radio.js +18 -5
- package/dist/range.js +7 -7
- package/dist/rate.js +3 -3
- package/dist/resizable.js +8 -5
- package/dist/result.d.ts +22 -0
- package/dist/result.js +88 -0
- package/dist/ribbon.d.ts +19 -0
- package/dist/ribbon.js +106 -0
- package/dist/segmented.d.ts +39 -0
- package/dist/segmented.js +192 -0
- package/dist/select.d.ts +12 -0
- package/dist/select.js +31 -13
- package/dist/skeleton.js +10 -10
- package/dist/spin.d.ts +26 -0
- package/dist/spin.js +80 -0
- package/dist/steps.js +13 -13
- package/dist/switch.d.ts +44 -0
- package/dist/switch.js +104 -0
- package/dist/table.d.ts +3 -3
- package/dist/table.js +110 -128
- package/dist/tabs.js +7 -7
- package/dist/tag.js +8 -8
- package/dist/time-picker.js +16 -10
- package/dist/timeline.js +12 -12
- package/dist/toast.js +12 -11
- package/dist/tooltip.d.ts +6 -0
- package/dist/tooltip.js +107 -6
- package/dist/tour.js +26 -17
- package/dist/tree-model.d.ts +2 -0
- package/dist/tree-model.js +32 -11
- package/dist/tree-node.js +2 -2
- package/dist/tree-select.d.ts +94 -0
- package/dist/tree-select.js +398 -0
- package/dist/tree.d.ts +0 -2
- package/dist/tree.js +14 -29
- package/dist/upload.d.ts +108 -0
- package/dist/upload.js +358 -0
- package/dist/virtual-keyboard.d.ts +1 -0
- package/dist/virtual-keyboard.js +72 -41
- package/dist/virtual-list.d.ts +1 -0
- package/dist/virtual-list.js +25 -8
- package/dist/virtual-mouse.js +7 -6
- package/dist/watermark.js +2 -1
- package/package.json +82 -1
- package/themes/haiyue-dark.css +51 -0
- package/themes/haiyue-light.css +51 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type HYFormItemStatus = '' | 'validating' | 'success' | 'error';
|
|
2
|
+
export interface HYFormRule {
|
|
3
|
+
required?: boolean;
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
pattern?: RegExp;
|
|
7
|
+
message?: string;
|
|
8
|
+
validator?: (value: unknown, signal: AbortSignal) => void | string | Promise<void | string>;
|
|
9
|
+
}
|
|
10
|
+
export interface HYFormItemValidateDetail {
|
|
11
|
+
name: string;
|
|
12
|
+
valid: boolean;
|
|
13
|
+
error: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class HYFormItem extends HTMLElement {
|
|
16
|
+
private readonly _label;
|
|
17
|
+
private readonly _slot;
|
|
18
|
+
private readonly _help;
|
|
19
|
+
private readonly _error;
|
|
20
|
+
private readonly _pending;
|
|
21
|
+
private _rules;
|
|
22
|
+
private _status;
|
|
23
|
+
private _validation;
|
|
24
|
+
private _listeners;
|
|
25
|
+
private _observer;
|
|
26
|
+
private _managed;
|
|
27
|
+
static get observedAttributes(): string[];
|
|
28
|
+
constructor();
|
|
29
|
+
connectedCallback(): void;
|
|
30
|
+
disconnectedCallback(): void;
|
|
31
|
+
attributeChangedCallback(): void;
|
|
32
|
+
get label(): string;
|
|
33
|
+
set label(value: string);
|
|
34
|
+
get name(): string;
|
|
35
|
+
set name(value: string);
|
|
36
|
+
get required(): boolean;
|
|
37
|
+
set required(value: boolean);
|
|
38
|
+
get help(): string;
|
|
39
|
+
set help(value: string);
|
|
40
|
+
get error(): string;
|
|
41
|
+
set error(value: string);
|
|
42
|
+
get status(): HYFormItemStatus;
|
|
43
|
+
get rules(): HYFormRule[];
|
|
44
|
+
set rules(value: HYFormRule[]);
|
|
45
|
+
get validateTrigger(): 'blur' | 'change' | 'submit';
|
|
46
|
+
set validateTrigger(value: 'blur' | 'change' | 'submit');
|
|
47
|
+
get value(): unknown;
|
|
48
|
+
focus(options?: FocusOptions): void;
|
|
49
|
+
clearValidation(): void;
|
|
50
|
+
validate(): Promise<boolean>;
|
|
51
|
+
private _field;
|
|
52
|
+
private _manage;
|
|
53
|
+
private _restoreManaged;
|
|
54
|
+
private _sync;
|
|
55
|
+
private _isOwnEvent;
|
|
56
|
+
private _onInput;
|
|
57
|
+
private _onChange;
|
|
58
|
+
private _onBlur;
|
|
59
|
+
}
|
|
60
|
+
export declare function defineFormItemComponents(): void;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
export class HYFormItem extends HTMLElement {
|
|
2
|
+
_label = document.createElement('label');
|
|
3
|
+
_slot = document.createElement('slot');
|
|
4
|
+
_help = document.createElement('div');
|
|
5
|
+
_error = document.createElement('div');
|
|
6
|
+
_pending = document.createElement('div');
|
|
7
|
+
_rules = [];
|
|
8
|
+
_status = '';
|
|
9
|
+
_validation = null;
|
|
10
|
+
_listeners = null;
|
|
11
|
+
_observer = null;
|
|
12
|
+
_managed = new Map();
|
|
13
|
+
static get observedAttributes() { return ['label', 'name', 'required', 'help', 'error', 'validate-trigger']; }
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
17
|
+
const style = document.createElement('style');
|
|
18
|
+
style.textContent = `
|
|
19
|
+
:host { display: block; min-width: 0; color: var(--hy-text-color, #d8e2f2); font: var(--hy-font-size-sm, 12px)/1.5 var(--hy-font-family, system-ui, sans-serif); }
|
|
20
|
+
.field { display: grid; grid-template-columns: var(--hy-form-item-columns, minmax(0,1fr)); gap: var(--hy-space-3, 6px) var(--hy-space-6, 12px); align-items: start; } label { font-weight: 500; cursor: pointer; }
|
|
21
|
+
.control, .help, .error, .pending { grid-column: var(--hy-form-control-column, 1); }
|
|
22
|
+
:host([required]) label::before { content: '* '; color: var(--hy-error-color, #d95d72); }
|
|
23
|
+
.help { color: var(--hy-secondary-text-color, #aebbd0); } .error { color: var(--hy-error-color, #d95d72); } .pending { color: var(--hy-muted-text-color, #8290a3); }
|
|
24
|
+
[hidden] { display: none !important; } ::slotted(*) { min-width: 0; }
|
|
25
|
+
`;
|
|
26
|
+
const field = document.createElement('div');
|
|
27
|
+
field.className = 'field';
|
|
28
|
+
field.part.add('field');
|
|
29
|
+
this._label.part.add('label');
|
|
30
|
+
this._help.className = 'help';
|
|
31
|
+
this._help.part.add('help');
|
|
32
|
+
this._error.className = 'error';
|
|
33
|
+
this._error.part.add('error');
|
|
34
|
+
this._error.setAttribute('role', 'alert');
|
|
35
|
+
this._pending.className = 'pending';
|
|
36
|
+
this._pending.part.add('pending');
|
|
37
|
+
this._pending.setAttribute('role', 'status');
|
|
38
|
+
this._pending.textContent = 'Validating…';
|
|
39
|
+
const control = document.createElement('div');
|
|
40
|
+
control.className = 'control';
|
|
41
|
+
control.part.add('control');
|
|
42
|
+
control.append(this._slot);
|
|
43
|
+
field.append(this._label, control, this._help, this._error, this._pending);
|
|
44
|
+
root.append(style, field);
|
|
45
|
+
}
|
|
46
|
+
connectedCallback() {
|
|
47
|
+
this._listeners?.abort();
|
|
48
|
+
this._listeners = new AbortController();
|
|
49
|
+
const { signal } = this._listeners;
|
|
50
|
+
this._label.addEventListener('click', () => this.focus(), { signal });
|
|
51
|
+
this.addEventListener('input', this._onInput, { signal });
|
|
52
|
+
this.addEventListener('change', this._onChange, { signal });
|
|
53
|
+
this.addEventListener('focusout', this._onBlur, { signal });
|
|
54
|
+
this._slot.addEventListener('slotchange', this._sync, { signal });
|
|
55
|
+
this._observer = new MutationObserver(this._sync);
|
|
56
|
+
this._observer.observe(this, { childList: true, subtree: true });
|
|
57
|
+
this._sync();
|
|
58
|
+
}
|
|
59
|
+
disconnectedCallback() { this._validation?.abort(); this._listeners?.abort(); this._observer?.disconnect(); this._observer = null; this._restoreManaged(); }
|
|
60
|
+
attributeChangedCallback() { this._sync(); }
|
|
61
|
+
get label() { return this.getAttribute('label') ?? ''; }
|
|
62
|
+
set label(value) { this.setAttribute('label', value); }
|
|
63
|
+
get name() { return this.getAttribute('name') ?? this._field()?.getAttribute('name') ?? ''; }
|
|
64
|
+
set name(value) { this.setAttribute('name', value); }
|
|
65
|
+
get required() { return this.hasAttribute('required'); }
|
|
66
|
+
set required(value) { this.toggleAttribute('required', value); }
|
|
67
|
+
get help() { return this.getAttribute('help') ?? ''; }
|
|
68
|
+
set help(value) { this.setAttribute('help', value); }
|
|
69
|
+
get error() { return this.getAttribute('error') ?? ''; }
|
|
70
|
+
set error(value) { if (value)
|
|
71
|
+
this.setAttribute('error', value);
|
|
72
|
+
else
|
|
73
|
+
this.removeAttribute('error'); }
|
|
74
|
+
get status() { return this.error ? 'error' : this._status; }
|
|
75
|
+
get rules() { return this._rules.map(rule => ({ ...rule })); }
|
|
76
|
+
set rules(value) { this._validation?.abort(); this._rules = Array.isArray(value) ? value.map(rule => ({ ...rule })) : []; this.clearValidation(); }
|
|
77
|
+
get validateTrigger() { const value = this.getAttribute('validate-trigger'); return value === 'change' || value === 'submit' ? value : 'blur'; }
|
|
78
|
+
set validateTrigger(value) { this.setAttribute('validate-trigger', value); }
|
|
79
|
+
get value() {
|
|
80
|
+
const field = this._field();
|
|
81
|
+
if (!field)
|
|
82
|
+
return undefined;
|
|
83
|
+
if (field.tagName === 'HY-UPLOAD')
|
|
84
|
+
return field.fileList;
|
|
85
|
+
if ('checked' in field && (field.tagName.startsWith('HY-') || field instanceof HTMLInputElement && ['checkbox', 'radio'].includes(field.type)))
|
|
86
|
+
return field.checked;
|
|
87
|
+
if (field instanceof HTMLInputElement && field.type === 'file')
|
|
88
|
+
return [...(field.files ?? [])];
|
|
89
|
+
return field.value;
|
|
90
|
+
}
|
|
91
|
+
focus(options) { this._field()?.focus(options); }
|
|
92
|
+
clearValidation() { this._validation?.abort(); this._validation = null; this._status = ''; this.error = ''; this._sync(); }
|
|
93
|
+
async validate() {
|
|
94
|
+
this._validation?.abort();
|
|
95
|
+
const validation = new AbortController();
|
|
96
|
+
this._validation = validation;
|
|
97
|
+
const field = this._field();
|
|
98
|
+
const value = this.value;
|
|
99
|
+
if (!field || field.disabled || field.matches(':disabled')) {
|
|
100
|
+
this.clearValidation();
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
this._status = 'validating';
|
|
104
|
+
this.error = '';
|
|
105
|
+
this._sync();
|
|
106
|
+
let error = '';
|
|
107
|
+
const rules = this.required ? [{ required: true, message: `${this.label || this.name || 'This field'} is required` }, ...this._rules] : this._rules;
|
|
108
|
+
try {
|
|
109
|
+
for (const rule of rules) {
|
|
110
|
+
const empty = value === undefined || value === null || value === false || typeof value === 'string' && !value.trim() || Array.isArray(value) && value.length === 0;
|
|
111
|
+
const length = typeof value === 'number' ? value : typeof value === 'string' || Array.isArray(value) ? value.length : 0;
|
|
112
|
+
if (rule.required && empty)
|
|
113
|
+
error = rule.message || 'This field is required';
|
|
114
|
+
else if (!empty && rule.min !== undefined && length < rule.min)
|
|
115
|
+
error = rule.message || `Minimum: ${rule.min}`;
|
|
116
|
+
else if (!empty && rule.max !== undefined && length > rule.max)
|
|
117
|
+
error = rule.message || `Maximum: ${rule.max}`;
|
|
118
|
+
else if (!empty && rule.pattern) {
|
|
119
|
+
rule.pattern.lastIndex = 0;
|
|
120
|
+
if (!rule.pattern.test(String(value)))
|
|
121
|
+
error = rule.message || 'Invalid format';
|
|
122
|
+
}
|
|
123
|
+
if (!error && rule.validator)
|
|
124
|
+
error = await rule.validator(value, validation.signal) || '';
|
|
125
|
+
if (validation.signal.aborted || !this.isConnected)
|
|
126
|
+
return false;
|
|
127
|
+
if (error)
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (!error && field.checkValidity && !field.checkValidity())
|
|
131
|
+
error = field.validationMessage || 'Invalid value';
|
|
132
|
+
}
|
|
133
|
+
catch (cause) {
|
|
134
|
+
if (!validation.signal.aborted)
|
|
135
|
+
error = cause instanceof Error ? cause.message : 'Validation failed';
|
|
136
|
+
}
|
|
137
|
+
if (validation.signal.aborted || !this.isConnected)
|
|
138
|
+
return false;
|
|
139
|
+
this._status = error ? 'error' : 'success';
|
|
140
|
+
this.error = error;
|
|
141
|
+
this._sync();
|
|
142
|
+
this.dispatchEvent(new CustomEvent('field-validate', { detail: { name: this.name, valid: !error, error }, bubbles: true, composed: true }));
|
|
143
|
+
return !error;
|
|
144
|
+
}
|
|
145
|
+
_field() {
|
|
146
|
+
return [...this.querySelectorAll('input,textarea,select,[name],hy-input,hy-select,hy-checkbox,hy-radio,hy-switch,hy-mentions,hy-upload,hy-auto-complete,hy-tree-select')]
|
|
147
|
+
.find(field => field.closest('hy-form-item') === this && field.tagName !== 'HY-FORM-ITEM') ?? null;
|
|
148
|
+
}
|
|
149
|
+
_manage(node, name, value) {
|
|
150
|
+
let attributes = this._managed.get(node);
|
|
151
|
+
if (!attributes) {
|
|
152
|
+
attributes = new Map();
|
|
153
|
+
this._managed.set(node, attributes);
|
|
154
|
+
}
|
|
155
|
+
if (!attributes.has(name))
|
|
156
|
+
attributes.set(name, node.getAttribute(name));
|
|
157
|
+
if (value === null) {
|
|
158
|
+
if (node.hasAttribute(name))
|
|
159
|
+
node.removeAttribute(name);
|
|
160
|
+
}
|
|
161
|
+
else if (node.getAttribute(name) !== value)
|
|
162
|
+
node.setAttribute(name, value);
|
|
163
|
+
}
|
|
164
|
+
_restoreManaged() { for (const [node, attributes] of this._managed)
|
|
165
|
+
for (const [name, value] of attributes) {
|
|
166
|
+
if (value === null)
|
|
167
|
+
node.removeAttribute(name);
|
|
168
|
+
else
|
|
169
|
+
node.setAttribute(name, value);
|
|
170
|
+
} this._managed.clear(); }
|
|
171
|
+
_sync = () => {
|
|
172
|
+
this._label.textContent = this.label;
|
|
173
|
+
this._label.hidden = !this.label;
|
|
174
|
+
this._help.textContent = this.help;
|
|
175
|
+
this._help.hidden = !this.help || Boolean(this.error);
|
|
176
|
+
this._error.textContent = this.error;
|
|
177
|
+
this._error.hidden = !this.error;
|
|
178
|
+
this._pending.hidden = this._status !== 'validating';
|
|
179
|
+
const field = this._field();
|
|
180
|
+
if (!field || !this.isConnected)
|
|
181
|
+
return;
|
|
182
|
+
if (this.hasAttribute('name') && (!field.hasAttribute('name') || this._managed.get(field)?.has('name')))
|
|
183
|
+
this._manage(field, 'name', this.getAttribute('name'));
|
|
184
|
+
if (this.label && (!field.hasAttribute('aria-label') || this._managed.get(field)?.has('aria-label')))
|
|
185
|
+
this._manage(field, 'aria-label', this.label);
|
|
186
|
+
const controls = field.shadowRoot ? [...field.shadowRoot.querySelectorAll('input:not([type="file"]),textarea,select,button')] : [field];
|
|
187
|
+
for (const native of controls) {
|
|
188
|
+
this._manage(native, 'aria-invalid', this.error ? 'true' : null);
|
|
189
|
+
this._manage(native, 'aria-description', this.error || this.help || null);
|
|
190
|
+
this._manage(native, 'aria-busy', this._status === 'validating' ? 'true' : null);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
_isOwnEvent(event) { return event.target instanceof Element && event.target.closest('hy-form-item') === this; }
|
|
194
|
+
_onInput = (event) => {
|
|
195
|
+
if (!this._isOwnEvent(event))
|
|
196
|
+
return;
|
|
197
|
+
this._validation?.abort();
|
|
198
|
+
this._validation = null;
|
|
199
|
+
if (this._status === 'validating') {
|
|
200
|
+
this._status = '';
|
|
201
|
+
this._sync();
|
|
202
|
+
}
|
|
203
|
+
if (this.validateTrigger === 'change' && !(event instanceof InputEvent && event.isComposing))
|
|
204
|
+
void this.validate();
|
|
205
|
+
};
|
|
206
|
+
_onChange = (event) => { this._onInput(event); };
|
|
207
|
+
_onBlur = (event) => { if (this._isOwnEvent(event) && this.validateTrigger === 'blur')
|
|
208
|
+
void this.validate(); };
|
|
209
|
+
}
|
|
210
|
+
export function defineFormItemComponents() { if (!customElements.get('hy-form-item'))
|
|
211
|
+
customElements.define('hy-form-item', HYFormItem); }
|
|
212
|
+
//# sourceMappingURL=form-item.js.map
|
package/dist/form.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type HYFormValue = FormDataEntryValue | FormDataEntryValue[];
|
|
2
|
+
export interface HYFormSubmitDetail {
|
|
3
|
+
values: Record<string, HYFormValue>;
|
|
4
|
+
formData: FormData;
|
|
5
|
+
}
|
|
6
|
+
export interface HYFormInvalidDetail {
|
|
7
|
+
errors: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export type HYFormLayout = 'vertical' | 'horizontal' | 'inline';
|
|
10
|
+
/** Owns a real light-DOM form so native and form-associated custom controls share one owner. */
|
|
11
|
+
export declare class HYForm extends HTMLElement {
|
|
12
|
+
private readonly _form;
|
|
13
|
+
private readonly _observer;
|
|
14
|
+
private _listeners;
|
|
15
|
+
private _revision;
|
|
16
|
+
private _submission;
|
|
17
|
+
static get observedAttributes(): string[];
|
|
18
|
+
constructor();
|
|
19
|
+
connectedCallback(): void;
|
|
20
|
+
disconnectedCallback(): void;
|
|
21
|
+
attributeChangedCallback(): void;
|
|
22
|
+
get layout(): HYFormLayout;
|
|
23
|
+
set layout(value: HYFormLayout);
|
|
24
|
+
get formElement(): HTMLFormElement;
|
|
25
|
+
get formData(): FormData;
|
|
26
|
+
get values(): Record<string, HYFormValue>;
|
|
27
|
+
setValues(values: Readonly<Record<string, string | number | boolean | readonly string[]>>): void;
|
|
28
|
+
validate(): Promise<boolean>;
|
|
29
|
+
submit(): Promise<boolean>;
|
|
30
|
+
reset(): void;
|
|
31
|
+
clearValidation(): void;
|
|
32
|
+
private _items;
|
|
33
|
+
private _adoptChildren;
|
|
34
|
+
private _sync;
|
|
35
|
+
private _onInput;
|
|
36
|
+
private _onSubmit;
|
|
37
|
+
private _onReset;
|
|
38
|
+
private _onButtonClick;
|
|
39
|
+
private _onKeydown;
|
|
40
|
+
}
|
|
41
|
+
export declare function defineFormComponents(): void;
|
package/dist/form.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** Owns a real light-DOM form so native and form-associated custom controls share one owner. */
|
|
2
|
+
export class HYForm extends HTMLElement {
|
|
3
|
+
_form = document.createElement('form');
|
|
4
|
+
_observer = new MutationObserver(() => this._adoptChildren());
|
|
5
|
+
_listeners = null;
|
|
6
|
+
_revision = 0;
|
|
7
|
+
_submission = 0;
|
|
8
|
+
static get observedAttributes() { return ['layout', 'aria-label', 'autocomplete']; }
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
12
|
+
const style = document.createElement('style');
|
|
13
|
+
style.textContent = `
|
|
14
|
+
:host { display: block; min-width: 0; color: var(--hy-text-color, #d8e2f2); font: var(--hy-font-size-sm, 12px)/1.5 var(--hy-font-family, system-ui, sans-serif); }
|
|
15
|
+
::slotted(form) { display: flex; flex-direction: column; gap: var(--hy-form-gap, var(--hy-space-8, 16px)); margin: 0; }
|
|
16
|
+
:host([layout="inline"]) ::slotted(form) { flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
|
|
17
|
+
`;
|
|
18
|
+
this._form.noValidate = true;
|
|
19
|
+
this._form.setAttribute('part', 'form');
|
|
20
|
+
root.append(style, document.createElement('slot'));
|
|
21
|
+
}
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
this._adoptChildren();
|
|
24
|
+
this._observer.observe(this, { childList: true });
|
|
25
|
+
this._listeners?.abort();
|
|
26
|
+
this._listeners = new AbortController();
|
|
27
|
+
const { signal } = this._listeners;
|
|
28
|
+
this._form.addEventListener('submit', this._onSubmit, { signal });
|
|
29
|
+
this._form.addEventListener('reset', this._onReset, { signal });
|
|
30
|
+
this._form.addEventListener('input', this._onInput, { signal });
|
|
31
|
+
this._form.addEventListener('change', this._onInput, { signal });
|
|
32
|
+
this._form.addEventListener('click', this._onButtonClick, { signal });
|
|
33
|
+
this._form.addEventListener('keydown', this._onKeydown, { signal });
|
|
34
|
+
this._sync();
|
|
35
|
+
}
|
|
36
|
+
disconnectedCallback() { this._observer.disconnect(); this._listeners?.abort(); this._listeners = null; this._submission++; this._revision++; }
|
|
37
|
+
attributeChangedCallback() { this._sync(); }
|
|
38
|
+
get layout() { const value = this.getAttribute('layout'); return value === 'horizontal' || value === 'inline' ? value : 'vertical'; }
|
|
39
|
+
set layout(value) { this.setAttribute('layout', value); }
|
|
40
|
+
get formElement() { return this._form; }
|
|
41
|
+
get formData() { return new FormData(this._form); }
|
|
42
|
+
get values() {
|
|
43
|
+
const values = Object.create(null);
|
|
44
|
+
for (const [name, value] of this.formData) {
|
|
45
|
+
const previous = values[name];
|
|
46
|
+
values[name] = previous === undefined ? value : Array.isArray(previous) ? [...previous, value] : [previous, value];
|
|
47
|
+
}
|
|
48
|
+
return values;
|
|
49
|
+
}
|
|
50
|
+
setValues(values) {
|
|
51
|
+
for (const element of this._form.elements) {
|
|
52
|
+
if (!(element instanceof HTMLElement))
|
|
53
|
+
continue;
|
|
54
|
+
const name = element.getAttribute('name');
|
|
55
|
+
if (!name || !Object.hasOwn(values, name))
|
|
56
|
+
continue;
|
|
57
|
+
const value = values[name];
|
|
58
|
+
const field = element;
|
|
59
|
+
if ('checked' in field)
|
|
60
|
+
field.checked = typeof value === 'boolean' ? value : Array.isArray(value) ? value.includes(field.value ?? '') : String(value) === field.value;
|
|
61
|
+
else if ('value' in field) {
|
|
62
|
+
if (Array.isArray(value) && Reflect.get(field, 'multiple') === true) {
|
|
63
|
+
if (field instanceof HTMLSelectElement)
|
|
64
|
+
for (const option of field.options)
|
|
65
|
+
option.selected = value.includes(option.value);
|
|
66
|
+
else
|
|
67
|
+
Reflect.set(field, 'value', [...value]);
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
field.value = String(value ?? '');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this._revision++;
|
|
74
|
+
}
|
|
75
|
+
async validate() {
|
|
76
|
+
const revision = this._revision;
|
|
77
|
+
const items = this._items();
|
|
78
|
+
const results = await Promise.all(items.map(item => item.validate()));
|
|
79
|
+
if (!this.isConnected || revision !== this._revision)
|
|
80
|
+
return false;
|
|
81
|
+
const nativeValid = this._form.checkValidity();
|
|
82
|
+
const valid = nativeValid && results.every(Boolean);
|
|
83
|
+
if (!valid) {
|
|
84
|
+
const invalid = items.find(item => item.error);
|
|
85
|
+
if (invalid)
|
|
86
|
+
invalid.focus();
|
|
87
|
+
else
|
|
88
|
+
this._form.reportValidity();
|
|
89
|
+
const errors = Object.create(null);
|
|
90
|
+
for (const item of items)
|
|
91
|
+
if (item.error)
|
|
92
|
+
errors[item.name] = item.error;
|
|
93
|
+
this.dispatchEvent(new CustomEvent('form-invalid', { detail: { errors }, bubbles: true, composed: true }));
|
|
94
|
+
}
|
|
95
|
+
return valid;
|
|
96
|
+
}
|
|
97
|
+
async submit() {
|
|
98
|
+
const submission = ++this._submission;
|
|
99
|
+
const revision = this._revision;
|
|
100
|
+
if (!await this.validate() || submission !== this._submission || revision !== this._revision || !this.isConnected)
|
|
101
|
+
return false;
|
|
102
|
+
return this.dispatchEvent(new CustomEvent('form-submit', { detail: { values: this.values, formData: this.formData }, bubbles: true, composed: true, cancelable: true }));
|
|
103
|
+
}
|
|
104
|
+
reset() { this._form.reset(); }
|
|
105
|
+
clearValidation() { for (const item of this._items())
|
|
106
|
+
item.clearValidation(); }
|
|
107
|
+
_items() { return [...this._form.querySelectorAll('hy-form-item')].filter(item => item.closest('hy-form') === this && typeof item.validate === 'function'); }
|
|
108
|
+
_adoptChildren() {
|
|
109
|
+
const nodes = [...this.childNodes].filter(node => node !== this._form);
|
|
110
|
+
if (nodes.length)
|
|
111
|
+
this._form.append(...nodes);
|
|
112
|
+
if (this._form.parentNode !== this)
|
|
113
|
+
this.append(this._form);
|
|
114
|
+
}
|
|
115
|
+
_sync() {
|
|
116
|
+
this._form.setAttribute('aria-label', this.getAttribute('aria-label') || 'Form');
|
|
117
|
+
this._form.autocomplete = this.getAttribute('autocomplete') === 'off' ? 'off' : 'on';
|
|
118
|
+
this._form.style.setProperty('--hy-form-item-columns', this.layout === 'horizontal' ? 'var(--hy-form-label-width, 120px) minmax(0,1fr)' : 'minmax(0,1fr)');
|
|
119
|
+
this._form.style.setProperty('--hy-form-control-column', this.layout === 'horizontal' ? '2' : '1');
|
|
120
|
+
}
|
|
121
|
+
_onInput = () => { this._revision++; };
|
|
122
|
+
_onSubmit = (event) => { event.preventDefault(); void this.submit(); };
|
|
123
|
+
_onReset = (event) => { queueMicrotask(() => { if (!event.defaultPrevented && this.isConnected) {
|
|
124
|
+
this._revision++;
|
|
125
|
+
this._submission++;
|
|
126
|
+
this.clearValidation();
|
|
127
|
+
this.dispatchEvent(new Event('form-reset', { bubbles: true, composed: true }));
|
|
128
|
+
} }); };
|
|
129
|
+
_onButtonClick = (event) => {
|
|
130
|
+
const button = event.composedPath().find(node => node instanceof HTMLElement && node.tagName === 'HY-BUTTON');
|
|
131
|
+
if (!button || event.defaultPrevented || button.hasAttribute('disabled') || button.hasAttribute('loading'))
|
|
132
|
+
return;
|
|
133
|
+
if (button.getAttribute('type') === 'submit') {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
this._form.requestSubmit();
|
|
136
|
+
}
|
|
137
|
+
else if (button.getAttribute('type') === 'reset') {
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
this.reset();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
_onKeydown = (event) => {
|
|
143
|
+
if (event.key !== 'Enter' || event.isComposing || event.defaultPrevented || event.ctrlKey || event.shiftKey || event.metaKey || event.altKey)
|
|
144
|
+
return;
|
|
145
|
+
const target = event.composedPath()[0];
|
|
146
|
+
if (target instanceof HTMLInputElement && !['button', 'submit', 'reset', 'checkbox', 'radio', 'file'].includes(target.type) && target.getRootNode() !== this._form.getRootNode()) {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
this._form.requestSubmit();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export function defineFormComponents() { if (!customElements.get('hy-form'))
|
|
153
|
+
customElements.define('hy-form', HYForm); }
|
|
154
|
+
//# sourceMappingURL=form.js.map
|
package/dist/history-controls.js
CHANGED
|
@@ -19,18 +19,18 @@ export class HYHistoryControls extends HTMLElement {
|
|
|
19
19
|
const style = document.createElement('style');
|
|
20
20
|
style.textContent = `
|
|
21
21
|
:host { display: inline-flex; }
|
|
22
|
-
[role="toolbar"] { display: inline-flex; gap: 2px; }
|
|
22
|
+
[role="toolbar"] { display: inline-flex; gap: var(--hy-space-1, 2px); }
|
|
23
23
|
button {
|
|
24
24
|
width: 30px;
|
|
25
|
-
min-height: 28px;
|
|
25
|
+
min-height: var(--hy-control-height-sm, 28px);
|
|
26
26
|
border: 1px solid var(--hy-border-color, #3d4654);
|
|
27
27
|
background: var(--hy-surface-elevated-color, #202733);
|
|
28
28
|
color: var(--hy-text-color, #eef3ff);
|
|
29
|
-
font: 600
|
|
29
|
+
font: var(--hy-font-weight-semibold, 600) calc(var(--hy-font-size-md, 14px) + 1px) var(--hy-font-family, system-ui, sans-serif);
|
|
30
30
|
cursor: pointer;
|
|
31
31
|
}
|
|
32
|
-
button:first-child { border-radius: 4px 0 0 4px; }
|
|
33
|
-
button:last-child { border-radius: 0 4px 4px 0; }
|
|
32
|
+
button:first-child { border-radius: var(--hy-radius-sm, 4px) 0 0 var(--hy-radius-sm, 4px); }
|
|
33
|
+
button:last-child { border-radius: 0 var(--hy-radius-sm, 4px) var(--hy-radius-sm, 4px) 0; }
|
|
34
34
|
button:hover:not(:disabled) { background: var(--hy-hover-bg-color, #273241); }
|
|
35
35
|
button:focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 1px; }
|
|
36
36
|
button:disabled { opacity: 0.45; cursor: default; }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HYImagePreviewItem } from './internal/image-viewer.js';
|
|
2
|
+
export type { HYImagePreviewItem, HYImagePreviewOpenDetail, HYImagePreviewChangeDetail } from './internal/image-viewer.js';
|
|
3
|
+
export declare class HYImagePreview extends HTMLElement {
|
|
4
|
+
private readonly _viewer;
|
|
5
|
+
private _images;
|
|
6
|
+
private _reflecting;
|
|
7
|
+
static get observedAttributes(): string[];
|
|
8
|
+
constructor();
|
|
9
|
+
connectedCallback(): void;
|
|
10
|
+
disconnectedCallback(): void;
|
|
11
|
+
attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
|
|
12
|
+
get images(): HYImagePreviewItem[];
|
|
13
|
+
set images(value: (HYImagePreviewItem | string)[]);
|
|
14
|
+
get current(): number;
|
|
15
|
+
set current(value: number);
|
|
16
|
+
get open(): boolean;
|
|
17
|
+
set open(value: boolean);
|
|
18
|
+
show(index?: number): void;
|
|
19
|
+
hide(): void;
|
|
20
|
+
private _sync;
|
|
21
|
+
}
|
|
22
|
+
export declare function defineImagePreviewComponents(): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HYImageViewer, normalizePreviewItems } from './internal/image-viewer.js';
|
|
2
|
+
export class HYImagePreview extends HTMLElement {
|
|
3
|
+
_viewer;
|
|
4
|
+
_images = [];
|
|
5
|
+
_reflecting = false;
|
|
6
|
+
static get observedAttributes() { return ['images', 'open', 'current', 'aria-label']; }
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
10
|
+
this._viewer = new HYImageViewer(this, root, detail => { this._reflecting = true; this.toggleAttribute('open', detail.open); this._reflecting = false; this.dispatchEvent(new CustomEvent('open-change', { detail, bubbles: true, composed: true })); }, detail => { this._reflecting = true; this.setAttribute('current', String(detail.index)); this._reflecting = false; this.dispatchEvent(new CustomEvent('preview-change', { detail, bubbles: true, composed: true })); });
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() { this._sync(); }
|
|
13
|
+
disconnectedCallback() { this._viewer.dispose(); }
|
|
14
|
+
attributeChangedCallback(name, previous, next) { if (this._reflecting || previous === next)
|
|
15
|
+
return; if (name === 'images') {
|
|
16
|
+
let value = [];
|
|
17
|
+
try {
|
|
18
|
+
value = JSON.parse(next ?? '[]');
|
|
19
|
+
}
|
|
20
|
+
catch { /* Invalid lists are empty. */ }
|
|
21
|
+
this._images = normalizePreviewItems(value);
|
|
22
|
+
} this._sync(); }
|
|
23
|
+
get images() { return this._images.map(item => ({ ...item })); }
|
|
24
|
+
set images(value) { this._images = normalizePreviewItems(value); this._sync(); }
|
|
25
|
+
get current() { const value = Number(this.getAttribute('current')); return Number.isFinite(value) ? Math.max(0, Math.min(this._images.length - 1, Math.floor(value))) : 0; }
|
|
26
|
+
set current(value) { this.setAttribute('current', String(value)); }
|
|
27
|
+
get open() { return this.hasAttribute('open'); }
|
|
28
|
+
set open(value) { this.toggleAttribute('open', value); }
|
|
29
|
+
show(index = this.current) { this.current = index; this.open = true; }
|
|
30
|
+
hide() { this.open = false; }
|
|
31
|
+
_sync() { this._viewer.setItems(this._images, this.current); this._viewer.dialog.setAttribute('aria-label', this.getAttribute('aria-label') || 'Image preview'); if (this.isConnected && this.open && this._images.length)
|
|
32
|
+
this._viewer.show();
|
|
33
|
+
else
|
|
34
|
+
this._viewer.close(); }
|
|
35
|
+
}
|
|
36
|
+
export function defineImagePreviewComponents() { if (!customElements.get('hy-image-preview'))
|
|
37
|
+
customElements.define('hy-image-preview', HYImagePreview); }
|
|
38
|
+
//# sourceMappingURL=image-preview.js.map
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type HYImageStatus = 'empty' | 'loading' | 'loaded' | 'error';
|
|
2
|
+
export interface HYImageLoadDetail {
|
|
3
|
+
src: string;
|
|
4
|
+
naturalWidth: number;
|
|
5
|
+
naturalHeight: number;
|
|
6
|
+
}
|
|
7
|
+
export interface HYImageErrorDetail {
|
|
8
|
+
src: string;
|
|
9
|
+
fallback: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class HYImage extends HTMLElement {
|
|
12
|
+
private readonly _frame;
|
|
13
|
+
private readonly _imageHost;
|
|
14
|
+
private readonly _placeholder;
|
|
15
|
+
private readonly _error;
|
|
16
|
+
private readonly _preview;
|
|
17
|
+
private readonly _viewer;
|
|
18
|
+
private _image;
|
|
19
|
+
private _loadListeners;
|
|
20
|
+
private _status;
|
|
21
|
+
private _sourceKey;
|
|
22
|
+
private _usedFallback;
|
|
23
|
+
static get observedAttributes(): string[];
|
|
24
|
+
constructor();
|
|
25
|
+
connectedCallback(): void;
|
|
26
|
+
disconnectedCallback(): void;
|
|
27
|
+
attributeChangedCallback(): void;
|
|
28
|
+
get src(): string;
|
|
29
|
+
set src(value: string);
|
|
30
|
+
get alt(): string;
|
|
31
|
+
set alt(value: string);
|
|
32
|
+
get fallback(): string;
|
|
33
|
+
set fallback(value: string);
|
|
34
|
+
get preview(): boolean;
|
|
35
|
+
set preview(value: boolean);
|
|
36
|
+
get previewSrc(): string;
|
|
37
|
+
set previewSrc(value: string);
|
|
38
|
+
get width(): string;
|
|
39
|
+
set width(value: string | number);
|
|
40
|
+
get height(): string;
|
|
41
|
+
set height(value: string | number);
|
|
42
|
+
get fit(): string;
|
|
43
|
+
set fit(value: string);
|
|
44
|
+
get loading(): 'lazy' | 'eager';
|
|
45
|
+
set loading(value: 'lazy' | 'eager');
|
|
46
|
+
get status(): HYImageStatus;
|
|
47
|
+
showPreview(): void;
|
|
48
|
+
hidePreview(): void;
|
|
49
|
+
private _sync;
|
|
50
|
+
private _load;
|
|
51
|
+
}
|
|
52
|
+
export declare function defineImageComponents(): void;
|