@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.
- package/CHANGELOG.md +30 -0
- package/README.md +506 -2
- package/dist/adapters/web/renderer.js +1 -8
- 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 +60 -0
- package/dist/anchor.js +274 -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 +1 -1
- 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 +12 -12
- 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 -3
- package/dist/date-picker.js +13 -13
- package/dist/descriptions.d.ts +44 -0
- package/dist/descriptions.js +169 -0
- package/dist/dialog.js +11 -11
- package/dist/divider.js +2 -2
- package/dist/draggable.js +1 -1
- package/dist/drawer.js +12 -12
- package/dist/dropdown.js +3 -3
- 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 +29 -15
- package/dist/internal/anchored-popup.d.ts +19 -0
- package/dist/internal/anchored-popup.js +89 -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/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 +10 -10
- package/dist/notification.js +9 -9
- 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/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 +4 -4
- 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 +0 -2
- package/dist/table.js +46 -87
- package/dist/tabs.js +7 -7
- package/dist/tag.js +8 -8
- package/dist/time-picker.js +10 -10
- package/dist/timeline.js +12 -12
- package/dist/toast.js +9 -9
- package/dist/tooltip.js +4 -4
- package/dist/tour.js +11 -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.js +6 -5
- package/dist/upload.d.ts +107 -0
- package/dist/upload.js +353 -0
- package/dist/virtual-keyboard.js +5 -5
- package/dist/virtual-list.js +4 -4
- package/dist/virtual-mouse.js +5 -5
- package/package.json +82 -1
- package/themes/haiyue-dark.css +51 -0
- package/themes/haiyue-light.css +51 -0
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export type HYUploadStatus = 'ready' | 'uploading' | 'done' | 'error';
|
|
2
|
+
export type HYUploadChangeReason = 'select' | 'remove' | 'start' | 'progress' | 'success' | 'error' | 'abort';
|
|
3
|
+
export type HYUploadRejectReason = 'type' | 'size' | 'count' | 'before-upload' | 'error';
|
|
4
|
+
export interface HYUploadFile {
|
|
5
|
+
uid: string;
|
|
6
|
+
name: string;
|
|
7
|
+
status: HYUploadStatus;
|
|
8
|
+
percent?: number;
|
|
9
|
+
size?: number;
|
|
10
|
+
type?: string;
|
|
11
|
+
file?: File;
|
|
12
|
+
response?: unknown;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface HYUploadChangeDetail {
|
|
16
|
+
file: HYUploadFile;
|
|
17
|
+
fileList: HYUploadFile[];
|
|
18
|
+
reason: HYUploadChangeReason;
|
|
19
|
+
}
|
|
20
|
+
export interface HYUploadRejectDetail {
|
|
21
|
+
file: File;
|
|
22
|
+
reason: HYUploadRejectReason;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
export interface HYUploadRemoveDetail {
|
|
26
|
+
file: HYUploadFile;
|
|
27
|
+
}
|
|
28
|
+
export interface HYUploadRequestOptions {
|
|
29
|
+
file: File;
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
onProgress: (percent: number) => void;
|
|
32
|
+
}
|
|
33
|
+
export type HYUploadRequest = (options: HYUploadRequestOptions) => Promise<unknown>;
|
|
34
|
+
export type HYUploadBeforeUpload = (file: File, files: readonly File[]) => boolean | Promise<boolean>;
|
|
35
|
+
export declare class HYUpload extends HTMLElement {
|
|
36
|
+
static readonly formAssociated = true;
|
|
37
|
+
private readonly _internals;
|
|
38
|
+
private readonly _input;
|
|
39
|
+
private readonly _zone;
|
|
40
|
+
private readonly _button;
|
|
41
|
+
private readonly _slot;
|
|
42
|
+
private readonly _list;
|
|
43
|
+
private readonly _message;
|
|
44
|
+
private _files;
|
|
45
|
+
private _initialFiles;
|
|
46
|
+
private _request;
|
|
47
|
+
private _beforeUpload;
|
|
48
|
+
private _requests;
|
|
49
|
+
private _rows;
|
|
50
|
+
private _listeners;
|
|
51
|
+
private _formDisabled;
|
|
52
|
+
private _selection;
|
|
53
|
+
private _dragDepth;
|
|
54
|
+
static get observedAttributes(): string[];
|
|
55
|
+
constructor();
|
|
56
|
+
connectedCallback(): void;
|
|
57
|
+
disconnectedCallback(): void;
|
|
58
|
+
attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
|
|
59
|
+
get fileList(): HYUploadFile[];
|
|
60
|
+
set fileList(value: HYUploadFile[]);
|
|
61
|
+
get files(): File[];
|
|
62
|
+
get request(): HYUploadRequest | null;
|
|
63
|
+
set request(value: HYUploadRequest | null);
|
|
64
|
+
get beforeUpload(): HYUploadBeforeUpload | null;
|
|
65
|
+
set beforeUpload(value: HYUploadBeforeUpload | null);
|
|
66
|
+
get name(): string;
|
|
67
|
+
set name(value: string);
|
|
68
|
+
get accept(): string;
|
|
69
|
+
set accept(value: string);
|
|
70
|
+
get multiple(): boolean;
|
|
71
|
+
set multiple(value: boolean);
|
|
72
|
+
get disabled(): boolean;
|
|
73
|
+
set disabled(value: boolean);
|
|
74
|
+
get drag(): boolean;
|
|
75
|
+
set drag(value: boolean);
|
|
76
|
+
get maxCount(): number;
|
|
77
|
+
set maxCount(value: number);
|
|
78
|
+
get maxSize(): number;
|
|
79
|
+
set maxSize(value: number);
|
|
80
|
+
get autoUpload(): boolean;
|
|
81
|
+
set autoUpload(value: boolean);
|
|
82
|
+
get showFileList(): boolean;
|
|
83
|
+
set showFileList(value: boolean);
|
|
84
|
+
get form(): HTMLFormElement | null;
|
|
85
|
+
get validity(): ValidityState;
|
|
86
|
+
get validationMessage(): string;
|
|
87
|
+
checkValidity(): boolean;
|
|
88
|
+
reportValidity(): boolean;
|
|
89
|
+
formDisabledCallback(disabled: boolean): void;
|
|
90
|
+
formResetCallback(): void;
|
|
91
|
+
focus(options?: FocusOptions): void;
|
|
92
|
+
openFileDialog(): void;
|
|
93
|
+
selectFiles(value: readonly File[] | FileList): Promise<void>;
|
|
94
|
+
upload(uid?: string): Promise<void>;
|
|
95
|
+
abort(uid?: string): void;
|
|
96
|
+
removeFile(uid: string): boolean;
|
|
97
|
+
private _upload;
|
|
98
|
+
private _emit;
|
|
99
|
+
private _reject;
|
|
100
|
+
private _sync;
|
|
101
|
+
private _onListClick;
|
|
102
|
+
private _onDragEnter;
|
|
103
|
+
private _onDragLeave;
|
|
104
|
+
private _onDragOver;
|
|
105
|
+
private _onDrop;
|
|
106
|
+
}
|
|
107
|
+
export declare function defineUploadComponents(): void;
|
package/dist/upload.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
let uploadFileId = 0;
|
|
2
|
+
export class HYUpload extends HTMLElement {
|
|
3
|
+
static formAssociated = true;
|
|
4
|
+
_internals = this.attachInternals();
|
|
5
|
+
_input = document.createElement('input');
|
|
6
|
+
_zone = document.createElement('div');
|
|
7
|
+
_button = document.createElement('button');
|
|
8
|
+
_slot = document.createElement('slot');
|
|
9
|
+
_list = document.createElement('ul');
|
|
10
|
+
_message = document.createElement('div');
|
|
11
|
+
_files = [];
|
|
12
|
+
_initialFiles = null;
|
|
13
|
+
_request = null;
|
|
14
|
+
_beforeUpload = null;
|
|
15
|
+
_requests = new Map();
|
|
16
|
+
_rows = new Map();
|
|
17
|
+
_listeners = null;
|
|
18
|
+
_formDisabled = false;
|
|
19
|
+
_selection = 0;
|
|
20
|
+
_dragDepth = 0;
|
|
21
|
+
static get observedAttributes() { return ['name', 'accept', 'multiple', 'disabled', 'drag', 'required', 'max-count', 'max-size', 'auto-upload', 'label', 'aria-label', 'show-file-list']; }
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
25
|
+
const style = document.createElement('style');
|
|
26
|
+
style.textContent = `
|
|
27
|
+
: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); }
|
|
28
|
+
input { display: none; } .zone { display: flex; align-items: center; gap: var(--hy-space-4, 8px); }
|
|
29
|
+
:host([drag]) .zone { flex-direction: column; padding: var(--hy-space-12, 24px); border: 1px dashed var(--hy-border-color, #303746); border-radius: var(--hy-radius-md, 6px); background: var(--hy-surface-color, #121822); }
|
|
30
|
+
:host([drag]) .zone.dragover { border-color: var(--hy-accent-color, #8177f2); background: var(--hy-hover-bg-color, #273241); }
|
|
31
|
+
button { min-height: var(--hy-control-height-sm, 28px); padding: 0 var(--hy-space-5, 10px); border: 1px solid var(--hy-border-color, #303746); border-radius: var(--hy-radius-sm, 4px); color: inherit; background: var(--hy-surface-elevated-color, #202733); font: inherit; cursor: pointer; }
|
|
32
|
+
button:hover:not(:disabled) { background: var(--hy-hover-bg-color, #273241); } button:focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 2px; }
|
|
33
|
+
button:disabled { opacity: .55; cursor: not-allowed; } ul { list-style: none; margin: var(--hy-space-4, 8px) 0 0; padding: 0; }
|
|
34
|
+
li { display: grid; grid-template-columns: minmax(0,1fr) auto auto auto; align-items: center; gap: var(--hy-space-3, 6px); padding: var(--hy-space-3, 6px) 0; border-bottom: 1px solid var(--hy-border-color, #303746); }
|
|
35
|
+
.name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .status { color: var(--hy-muted-text-color, #8290a3); } li.error .status { color: var(--hy-error-color, #d95d72); }
|
|
36
|
+
progress { grid-column: 1 / -1; width: 100%; height: 5px; accent-color: var(--hy-accent-color, #8177f2); }
|
|
37
|
+
.message { margin-top: var(--hy-space-3, 6px); color: var(--hy-error-color, #d95d72); } [hidden] { display: none !important; }
|
|
38
|
+
`;
|
|
39
|
+
this._input.type = 'file';
|
|
40
|
+
this._input.tabIndex = -1;
|
|
41
|
+
this._input.part.add('input');
|
|
42
|
+
this._zone.className = 'zone';
|
|
43
|
+
this._zone.part.add('dropzone');
|
|
44
|
+
this._button.type = 'button';
|
|
45
|
+
this._button.part.add('trigger');
|
|
46
|
+
this._list.part.add('list');
|
|
47
|
+
this._list.setAttribute('aria-label', 'Selected files');
|
|
48
|
+
this._message.className = 'message';
|
|
49
|
+
this._message.part.add('message');
|
|
50
|
+
this._message.setAttribute('role', 'status');
|
|
51
|
+
this._zone.append(this._button, this._slot);
|
|
52
|
+
root.append(style, this._input, this._zone, this._list, this._message);
|
|
53
|
+
}
|
|
54
|
+
connectedCallback() {
|
|
55
|
+
this._initialFiles ??= this.fileList;
|
|
56
|
+
this._listeners?.abort();
|
|
57
|
+
this._listeners = new AbortController();
|
|
58
|
+
const { signal } = this._listeners;
|
|
59
|
+
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 });
|
|
65
|
+
this._list.addEventListener('click', this._onListClick, { signal });
|
|
66
|
+
this._sync();
|
|
67
|
+
}
|
|
68
|
+
disconnectedCallback() { this._listeners?.abort(); this._listeners = null; this._selection++; this.abort(); this._dragDepth = 0; this._zone.classList.remove('dragover'); }
|
|
69
|
+
attributeChangedCallback(name, previous, next) {
|
|
70
|
+
if (previous === next)
|
|
71
|
+
return;
|
|
72
|
+
if (name === 'disabled' && this.disabled) {
|
|
73
|
+
this._selection++;
|
|
74
|
+
this.abort();
|
|
75
|
+
}
|
|
76
|
+
this._sync();
|
|
77
|
+
}
|
|
78
|
+
get fileList() { return this._files.map(file => ({ ...file })); }
|
|
79
|
+
set fileList(value) {
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
const files = (Array.isArray(value) ? value : []).filter(file => file && typeof file.uid === 'string' && file.uid && typeof file.name === 'string' && !seen.has(file.uid) && Boolean(seen.add(file.uid)))
|
|
82
|
+
.map(file => ({ ...file, status: file.status === 'uploading' || file.status === 'done' || file.status === 'error' ? file.status : 'ready' }));
|
|
83
|
+
this.abort();
|
|
84
|
+
this._selection++;
|
|
85
|
+
this._files = files;
|
|
86
|
+
this._sync();
|
|
87
|
+
}
|
|
88
|
+
get files() { return this._files.flatMap(file => file.file ? [file.file] : []); }
|
|
89
|
+
get request() { return this._request; }
|
|
90
|
+
set request(value) { this.abort(); this._request = typeof value === 'function' ? value : null; }
|
|
91
|
+
get beforeUpload() { return this._beforeUpload; }
|
|
92
|
+
set beforeUpload(value) { this._selection++; this._beforeUpload = typeof value === 'function' ? value : null; }
|
|
93
|
+
get name() { return this.getAttribute('name') ?? ''; }
|
|
94
|
+
set name(value) { this.setAttribute('name', value); }
|
|
95
|
+
get accept() { return this.getAttribute('accept') ?? ''; }
|
|
96
|
+
set accept(value) { this.setAttribute('accept', value); }
|
|
97
|
+
get multiple() { return this.hasAttribute('multiple'); }
|
|
98
|
+
set multiple(value) { this.toggleAttribute('multiple', value); }
|
|
99
|
+
get disabled() { return this.hasAttribute('disabled'); }
|
|
100
|
+
set disabled(value) { this.toggleAttribute('disabled', value); }
|
|
101
|
+
get drag() { return this.hasAttribute('drag'); }
|
|
102
|
+
set drag(value) { this.toggleAttribute('drag', value); }
|
|
103
|
+
get maxCount() { return nonnegative(this.getAttribute('max-count')); }
|
|
104
|
+
set maxCount(value) { this.setAttribute('max-count', String(value)); }
|
|
105
|
+
get maxSize() { return nonnegative(this.getAttribute('max-size')); }
|
|
106
|
+
set maxSize(value) { this.setAttribute('max-size', String(value)); }
|
|
107
|
+
get autoUpload() { return this.getAttribute('auto-upload') !== 'false'; }
|
|
108
|
+
set autoUpload(value) { this.setAttribute('auto-upload', String(value)); }
|
|
109
|
+
get showFileList() { return this.getAttribute('show-file-list') !== 'false'; }
|
|
110
|
+
set showFileList(value) { this.setAttribute('show-file-list', String(value)); }
|
|
111
|
+
get form() { return this._internals.form; }
|
|
112
|
+
get validity() { return this._internals.validity; }
|
|
113
|
+
get validationMessage() { return this._internals.validationMessage; }
|
|
114
|
+
checkValidity() { return this._internals.checkValidity(); }
|
|
115
|
+
reportValidity() { return this._internals.reportValidity(); }
|
|
116
|
+
formDisabledCallback(disabled) { this._formDisabled = disabled; if (disabled) {
|
|
117
|
+
this._selection++;
|
|
118
|
+
this.abort();
|
|
119
|
+
} this._sync(); }
|
|
120
|
+
formResetCallback() { this.fileList = this._initialFiles ?? []; this._message.textContent = ''; }
|
|
121
|
+
focus(options) { this._button.focus(options); }
|
|
122
|
+
openFileDialog() { if (!this.disabled && !this._formDisabled)
|
|
123
|
+
this._input.click(); }
|
|
124
|
+
async selectFiles(value) {
|
|
125
|
+
if (this.disabled || this._formDisabled || !this.isConnected)
|
|
126
|
+
return;
|
|
127
|
+
const selection = ++this._selection;
|
|
128
|
+
const files = [...value].filter(file => file instanceof File);
|
|
129
|
+
const accepted = [];
|
|
130
|
+
this._message.textContent = '';
|
|
131
|
+
for (const file of files) {
|
|
132
|
+
if (this.maxSize && file.size > this.maxSize) {
|
|
133
|
+
this._reject(file, 'size', 'File exceeds the size limit');
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (!matchesAccept(file, this.accept)) {
|
|
137
|
+
this._reject(file, 'type', 'File type is not accepted');
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const limit = this.multiple ? this.maxCount : 1;
|
|
141
|
+
if (limit && (this.multiple ? this._files.length : 0) + accepted.length >= limit) {
|
|
142
|
+
this._reject(file, 'count', 'Too many files');
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
if (this._beforeUpload && !await this._beforeUpload(file, files)) {
|
|
147
|
+
if (selection !== this._selection)
|
|
148
|
+
return;
|
|
149
|
+
this._reject(file, 'before-upload', 'File was rejected');
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (cause) {
|
|
154
|
+
if (selection !== this._selection)
|
|
155
|
+
return;
|
|
156
|
+
this._reject(file, 'error', cause instanceof Error ? cause.message : 'File validation failed');
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (selection !== this._selection || !this.isConnected || this.disabled || this._formDisabled)
|
|
160
|
+
return;
|
|
161
|
+
accepted.push({ uid: `hy-upload-${++uploadFileId}`, name: file.name, size: file.size, type: file.type, file, status: 'ready', percent: 0 });
|
|
162
|
+
}
|
|
163
|
+
if (selection !== this._selection || !this.isConnected || !accepted.length)
|
|
164
|
+
return;
|
|
165
|
+
if (!this.multiple) {
|
|
166
|
+
this.abort();
|
|
167
|
+
this._files = [];
|
|
168
|
+
}
|
|
169
|
+
this._files.push(...accepted);
|
|
170
|
+
this._sync();
|
|
171
|
+
for (const file of accepted)
|
|
172
|
+
this._emit(file, 'select');
|
|
173
|
+
if (this.autoUpload && this._request)
|
|
174
|
+
await Promise.all(accepted.map(file => this._upload(file.uid)));
|
|
175
|
+
}
|
|
176
|
+
async upload(uid) {
|
|
177
|
+
if (!this._request || this.disabled || this._formDisabled || !this.isConnected)
|
|
178
|
+
return;
|
|
179
|
+
await Promise.all(this._files.filter(file => (!uid || file.uid === uid) && file.status !== 'done').map(file => this._upload(file.uid)));
|
|
180
|
+
}
|
|
181
|
+
abort(uid) {
|
|
182
|
+
for (const [id, controller] of this._requests) {
|
|
183
|
+
if (uid && id !== uid)
|
|
184
|
+
continue;
|
|
185
|
+
controller.abort();
|
|
186
|
+
this._requests.delete(id);
|
|
187
|
+
const file = this._files.find(file => file.uid === id);
|
|
188
|
+
if (file) {
|
|
189
|
+
file.status = 'ready';
|
|
190
|
+
file.percent = 0;
|
|
191
|
+
this._emit(file, 'abort');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
this._sync();
|
|
195
|
+
}
|
|
196
|
+
removeFile(uid) {
|
|
197
|
+
if (this.disabled || this._formDisabled)
|
|
198
|
+
return false;
|
|
199
|
+
const file = this._files.find(file => file.uid === uid);
|
|
200
|
+
if (!file)
|
|
201
|
+
return false;
|
|
202
|
+
if (!this.dispatchEvent(new CustomEvent('file-remove', { detail: { file: { ...file } }, bubbles: true, composed: true, cancelable: true })))
|
|
203
|
+
return false;
|
|
204
|
+
this.abort(uid);
|
|
205
|
+
this._files = this._files.filter(file => file.uid !== uid);
|
|
206
|
+
this._sync();
|
|
207
|
+
this._emit(file, 'remove');
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
async _upload(uid) {
|
|
211
|
+
const request = this._request;
|
|
212
|
+
const file = this._files.find(file => file.uid === uid);
|
|
213
|
+
if (!request || !file?.file || this._requests.has(uid) || !this.isConnected || this.disabled || this._formDisabled)
|
|
214
|
+
return;
|
|
215
|
+
const controller = new AbortController();
|
|
216
|
+
this._requests.set(uid, controller);
|
|
217
|
+
file.status = 'uploading';
|
|
218
|
+
file.percent = 0;
|
|
219
|
+
delete file.error;
|
|
220
|
+
this._sync();
|
|
221
|
+
this._emit(file, 'start');
|
|
222
|
+
if (controller.signal.aborted)
|
|
223
|
+
return;
|
|
224
|
+
try {
|
|
225
|
+
const response = await request({ file: file.file, signal: controller.signal, onProgress: percent => {
|
|
226
|
+
if (!controller.signal.aborted && this._requests.get(uid) === controller && Number.isFinite(percent)) {
|
|
227
|
+
file.percent = Math.max(0, Math.min(100, percent));
|
|
228
|
+
this._sync();
|
|
229
|
+
this._emit(file, 'progress');
|
|
230
|
+
}
|
|
231
|
+
} });
|
|
232
|
+
if (controller.signal.aborted || this._requests.get(uid) !== controller)
|
|
233
|
+
return;
|
|
234
|
+
file.status = 'done';
|
|
235
|
+
file.percent = 100;
|
|
236
|
+
file.response = response;
|
|
237
|
+
this._sync();
|
|
238
|
+
this._emit(file, 'success');
|
|
239
|
+
}
|
|
240
|
+
catch (cause) {
|
|
241
|
+
if (controller.signal.aborted || this._requests.get(uid) !== controller)
|
|
242
|
+
return;
|
|
243
|
+
file.status = 'error';
|
|
244
|
+
file.error = cause instanceof Error ? cause.message : 'Upload failed';
|
|
245
|
+
this._sync();
|
|
246
|
+
this._emit(file, 'error');
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
if (this._requests.get(uid) === controller)
|
|
250
|
+
this._requests.delete(uid);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
_emit(file, reason) { this.dispatchEvent(new CustomEvent('upload-change', { detail: { file: { ...file }, fileList: this.fileList, reason }, bubbles: true, composed: true })); }
|
|
254
|
+
_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
|
+
_sync() {
|
|
256
|
+
const disabled = this.disabled || this._formDisabled;
|
|
257
|
+
this._input.disabled = this._button.disabled = disabled;
|
|
258
|
+
this._input.accept = this.accept;
|
|
259
|
+
this._input.multiple = this.multiple;
|
|
260
|
+
this._button.textContent = this.getAttribute('label') || 'Choose files';
|
|
261
|
+
this._button.setAttribute('aria-label', this.getAttribute('aria-label') || this.getAttribute('label') || 'Choose files');
|
|
262
|
+
this._zone.setAttribute('aria-disabled', String(disabled));
|
|
263
|
+
this._list.hidden = !this.showFileList || !this._files.length;
|
|
264
|
+
for (const [uid, row] of this._rows)
|
|
265
|
+
if (!this._files.some(file => file.uid === uid)) {
|
|
266
|
+
row.row.remove();
|
|
267
|
+
this._rows.delete(uid);
|
|
268
|
+
}
|
|
269
|
+
this._files.forEach((file, index) => {
|
|
270
|
+
let record = this._rows.get(file.uid);
|
|
271
|
+
if (!record) {
|
|
272
|
+
const row = document.createElement('li');
|
|
273
|
+
row.part.add('file');
|
|
274
|
+
const name = document.createElement('span');
|
|
275
|
+
name.className = 'name';
|
|
276
|
+
name.part.add('file-name');
|
|
277
|
+
const status = document.createElement('span');
|
|
278
|
+
status.className = 'status';
|
|
279
|
+
status.part.add('file-status');
|
|
280
|
+
const progress = document.createElement('progress');
|
|
281
|
+
progress.max = 100;
|
|
282
|
+
progress.part.add('progress');
|
|
283
|
+
const remove = document.createElement('button');
|
|
284
|
+
remove.type = 'button';
|
|
285
|
+
remove.dataset.remove = file.uid;
|
|
286
|
+
remove.textContent = '×';
|
|
287
|
+
remove.part.add('remove');
|
|
288
|
+
const retry = document.createElement('button');
|
|
289
|
+
retry.type = 'button';
|
|
290
|
+
retry.dataset.retry = file.uid;
|
|
291
|
+
retry.textContent = 'Retry';
|
|
292
|
+
retry.part.add('retry');
|
|
293
|
+
row.append(name, status, retry, remove, progress);
|
|
294
|
+
record = { row, name, status, progress, remove, retry };
|
|
295
|
+
this._rows.set(file.uid, record);
|
|
296
|
+
}
|
|
297
|
+
record.row.className = file.status;
|
|
298
|
+
if (record.name.textContent !== file.name)
|
|
299
|
+
record.name.textContent = file.name;
|
|
300
|
+
record.name.title = file.name;
|
|
301
|
+
record.status.textContent = file.status === 'uploading' ? `${Math.round(file.percent ?? 0)}%` : file.error || file.status;
|
|
302
|
+
record.progress.hidden = file.status !== 'uploading';
|
|
303
|
+
record.progress.value = file.percent ?? 0;
|
|
304
|
+
record.progress.setAttribute('aria-label', `Upload ${file.name}`);
|
|
305
|
+
record.remove.disabled = disabled;
|
|
306
|
+
record.remove.setAttribute('aria-label', `Remove ${file.name}`);
|
|
307
|
+
record.retry.hidden = file.status !== 'error' || !this._request;
|
|
308
|
+
record.retry.disabled = disabled;
|
|
309
|
+
record.retry.setAttribute('aria-label', `Retry ${file.name}`);
|
|
310
|
+
if (this._list.children[index] !== record.row)
|
|
311
|
+
this._list.insertBefore(record.row, this._list.children[index] ?? null);
|
|
312
|
+
});
|
|
313
|
+
const data = new FormData();
|
|
314
|
+
for (const file of this.files)
|
|
315
|
+
data.append(this.name, file);
|
|
316
|
+
this._internals.setFormValue(disabled || !this.name ? null : data);
|
|
317
|
+
const missing = !disabled && this.hasAttribute('required') && !this._files.length;
|
|
318
|
+
this._internals.setValidity(missing ? { valueMissing: true } : {}, missing ? 'Choose a file' : '', this._button);
|
|
319
|
+
}
|
|
320
|
+
_onListClick = (event) => {
|
|
321
|
+
const button = event.target instanceof Element ? event.target.closest('button') : null;
|
|
322
|
+
if (button?.dataset.remove)
|
|
323
|
+
this.removeFile(button.dataset.remove);
|
|
324
|
+
else if (button?.dataset.retry)
|
|
325
|
+
void this.upload(button.dataset.retry);
|
|
326
|
+
};
|
|
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
|
+
}
|
|
346
|
+
function nonnegative(value) { const number = Number(value); return Number.isFinite(number) ? Math.max(0, number) : 0; }
|
|
347
|
+
function matchesAccept(file, accept) {
|
|
348
|
+
const tokens = accept.toLowerCase().split(',').map(token => token.trim()).filter(Boolean);
|
|
349
|
+
return !tokens.length || tokens.some(token => token === '*' || token === '*/*' || (token.startsWith('.') ? file.name.toLowerCase().endsWith(token) : token.endsWith('/*') ? file.type.toLowerCase().startsWith(token.slice(0, -1)) : file.type.toLowerCase() === token));
|
|
350
|
+
}
|
|
351
|
+
export function defineUploadComponents() { if (!customElements.get('hy-upload'))
|
|
352
|
+
customElements.define('hy-upload', HYUpload); }
|
|
353
|
+
//# sourceMappingURL=upload.js.map
|
package/dist/virtual-keyboard.js
CHANGED
|
@@ -70,16 +70,16 @@ export class HYVirtualKeyboard extends HTMLElement {
|
|
|
70
70
|
const root = this.attachShadow({ mode: 'open' });
|
|
71
71
|
const style = document.createElement('style');
|
|
72
72
|
style.textContent = `
|
|
73
|
-
:host { display: block; min-width: 0; color: var(--hy-text-color, #eef3ff); font: 12px/1 system-ui, sans-serif; }
|
|
74
|
-
.keyboard { display: grid; gap: var(--hy-virtual-keyboard-row-gap,
|
|
75
|
-
.row { display: flex; gap: var(--hy-virtual-keyboard-key-gap, 6px); min-width: 0; }
|
|
76
|
-
.key { position: relative; min-width: 0; height: var(--hy-virtual-keyboard-key-height,
|
|
73
|
+
:host { display: block; min-width: 0; color: var(--hy-text-color, #eef3ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-tight, 1) var(--hy-font-family, system-ui, sans-serif); }
|
|
74
|
+
.keyboard { display: grid; gap: var(--hy-virtual-keyboard-row-gap, calc(var(--hy-space-3, 6px) + 1px)); box-sizing: border-box; padding: var(--hy-virtual-keyboard-padding, var(--hy-space-6, 12px)); border: 1px solid var(--hy-border-color, #3d4654); border-radius: var(--hy-virtual-keyboard-radius, calc(var(--hy-radius-xl, 12px) - 1px)); background: var(--hy-virtual-keyboard-bg, var(--hy-surface-color, #111722)); box-shadow: var(--hy-virtual-keyboard-shadow, 0 16px 40px var(--hy-shadow-color, rgba(0, 0, 0, .22))); user-select: none; touch-action: manipulation; }
|
|
75
|
+
.row { display: flex; gap: var(--hy-virtual-keyboard-key-gap, var(--hy-space-3, 6px)); min-width: 0; }
|
|
76
|
+
.key { position: relative; min-width: 0; height: var(--hy-virtual-keyboard-key-height, calc(var(--hy-control-height-lg, 44px) - 2px)); flex: var(--_key-width, 1) 1 0; overflow: hidden; padding: 0 calc(var(--hy-space-2, 4px) + 1px); border: 1px solid var(--hy-virtual-keyboard-key-border, var(--hy-border-color, #3d4654)); border-radius: var(--hy-virtual-keyboard-key-radius, calc(var(--hy-radius-md, 6px) + 1px)); color: var(--hy-virtual-keyboard-key-color, var(--hy-text-color, #eef3ff)); background: var(--hy-virtual-keyboard-key-bg, var(--hy-surface-elevated-color, #171d27)); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--hy-border-color, #3d4654) 65%, transparent); cursor: pointer; font: inherit; text-overflow: ellipsis; white-space: nowrap; transition: translate 70ms ease, background-color 70ms ease, box-shadow 70ms ease; }
|
|
77
77
|
.key:hover:not(:disabled) { border-color: var(--hy-hover-border-color, #596779); background: var(--hy-hover-bg-color, #273241); }
|
|
78
78
|
.key:focus-visible { z-index: 1; outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 1px; }
|
|
79
79
|
.key.pressed, .key[aria-pressed="true"] { translate: 0 1px; border-color: var(--hy-selected-bg-color, #554cc6); background: var(--hy-virtual-keyboard-active-bg, color-mix(in srgb, var(--hy-selected-bg-color, #554cc6) 50%, var(--hy-surface-elevated-color, #171d27))); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hy-focus-border-color, #79a8ff) 24%, transparent); }
|
|
80
80
|
.key:disabled { opacity: .42; cursor: not-allowed; }
|
|
81
81
|
:host([disabled]) .keyboard { opacity: .62; }
|
|
82
|
-
@media (max-width: 620px) { .keyboard { --hy-virtual-keyboard-padding:
|
|
82
|
+
@media (max-width: 620px) { .keyboard { --hy-virtual-keyboard-padding: calc(var(--hy-space-3, 6px) + 1px); --hy-virtual-keyboard-row-gap: calc(var(--hy-space-2, 4px) + 1px); --hy-virtual-keyboard-key-gap: calc(var(--hy-space-1, 2px) + 1px); --hy-virtual-keyboard-key-height: calc(var(--hy-control-height-md, 34px) + 2px); font-size: calc(var(--hy-font-size-xs, 10px) - 1px); } }
|
|
83
83
|
@media (prefers-reduced-motion: reduce) { .key { transition: none; } }
|
|
84
84
|
`;
|
|
85
85
|
this._keyboard.className = 'keyboard';
|
package/dist/virtual-list.js
CHANGED
|
@@ -51,7 +51,7 @@ export class HYVirtualList extends HTMLElement {
|
|
|
51
51
|
display: block;
|
|
52
52
|
min-width: 0;
|
|
53
53
|
color: var(--hy-text-color, #eef3ff);
|
|
54
|
-
font:
|
|
54
|
+
font: calc(var(--hy-font-size-sm, 12px) + 1px)/var(--hy-line-height-snug, 1.4) var(--hy-font-family, system-ui, sans-serif);
|
|
55
55
|
}
|
|
56
56
|
.viewport {
|
|
57
57
|
position: relative;
|
|
@@ -60,7 +60,7 @@ export class HYVirtualList extends HTMLElement {
|
|
|
60
60
|
overflow-y: auto;
|
|
61
61
|
overscroll-behavior: contain;
|
|
62
62
|
border: 1px solid var(--hy-border-color, #3d4654);
|
|
63
|
-
border-radius: var(--hy-virtual-list-border-radius, 6px);
|
|
63
|
+
border-radius: var(--hy-virtual-list-border-radius, var(--hy-radius-md, 6px));
|
|
64
64
|
outline: none;
|
|
65
65
|
background: var(--hy-surface-color, #171d27);
|
|
66
66
|
scrollbar-color: var(--hy-border-strong-color, #596779) var(--hy-input-bg-color, #111722);
|
|
@@ -75,7 +75,7 @@ export class HYVirtualList extends HTMLElement {
|
|
|
75
75
|
.viewport::-webkit-scrollbar-thumb {
|
|
76
76
|
min-height: 28px;
|
|
77
77
|
border: 2px solid var(--hy-input-bg-color, #111722);
|
|
78
|
-
border-radius: 999px;
|
|
78
|
+
border-radius: var(--hy-radius-full, 999px);
|
|
79
79
|
background: var(--hy-border-strong-color, #596779);
|
|
80
80
|
}
|
|
81
81
|
.viewport::-webkit-scrollbar-thumb:hover { background: var(--hy-accent-color, #79a8ff); }
|
|
@@ -95,7 +95,7 @@ export class HYVirtualList extends HTMLElement {
|
|
|
95
95
|
display: grid;
|
|
96
96
|
height: 100%;
|
|
97
97
|
place-items: center;
|
|
98
|
-
padding: 24px;
|
|
98
|
+
padding: var(--hy-space-12, 24px);
|
|
99
99
|
color: var(--hy-secondary-text-color, #9aa8ba);
|
|
100
100
|
box-sizing: border-box;
|
|
101
101
|
}
|
package/dist/virtual-mouse.js
CHANGED
|
@@ -72,17 +72,17 @@ export class HYVirtualMouse extends HTMLElement {
|
|
|
72
72
|
box-sizing: border-box;
|
|
73
73
|
border: var(--hy-virtual-mouse-border-width, 1.5px) solid var(--hy-virtual-mouse-border-color, #f5fbff);
|
|
74
74
|
clip-path: polygon(5% 0, 88% 70%, 55% 74%, 72% 100%, 51% 100%, 36% 76%, 10% 96%);
|
|
75
|
-
background: var(--hy-virtual-mouse-idle-background, linear-gradient(145deg, #78d7ff, #5265e8));
|
|
75
|
+
background: var(--hy-virtual-mouse-idle-background, linear-gradient(145deg, var(--hy-accent-color, #78d7ff), var(--hy-accent-strong-color, #5265e8)));
|
|
76
76
|
filter: drop-shadow(var(--hy-virtual-mouse-shadow, 0 3px 5px rgba(4, 9, 28, 0.5)));
|
|
77
77
|
}
|
|
78
78
|
:host([data-state="left-down"]) .shape {
|
|
79
|
-
background: var(--hy-virtual-mouse-left-down-background, linear-gradient(145deg, #b5f1ff, #6d74ff));
|
|
79
|
+
background: var(--hy-virtual-mouse-left-down-background, linear-gradient(145deg, var(--hy-focus-border-color, #b5f1ff), var(--hy-accent-color, #6d74ff)));
|
|
80
80
|
}
|
|
81
81
|
:host([data-state="middle-down"]) .shape {
|
|
82
|
-
background: var(--hy-virtual-mouse-middle-down-background, linear-gradient(145deg, #d6c4ff, #7654e8));
|
|
82
|
+
background: var(--hy-virtual-mouse-middle-down-background, linear-gradient(145deg, var(--hy-theme-highlight-color, #d6c4ff), #7654e8));
|
|
83
83
|
}
|
|
84
84
|
:host([data-state="right-down"]) .shape {
|
|
85
|
-
background: var(--hy-virtual-mouse-right-down-background, linear-gradient(145deg, #f4c8ff, #9156dc));
|
|
85
|
+
background: var(--hy-virtual-mouse-right-down-background, linear-gradient(145deg, #f4c8ff, var(--hy-accent-strong-color, #9156dc)));
|
|
86
86
|
}
|
|
87
87
|
.image {
|
|
88
88
|
position: absolute;
|
|
@@ -103,7 +103,7 @@ export class HYVirtualMouse extends HTMLElement {
|
|
|
103
103
|
left: var(--hy-virtual-mouse-hotspot-x, 2px);
|
|
104
104
|
width: var(--hy-virtual-mouse-click-size, 28px);
|
|
105
105
|
height: var(--hy-virtual-mouse-click-size, 28px);
|
|
106
|
-
border: 2px solid var(--hy-virtual-mouse-click-color, #83dcff);
|
|
106
|
+
border: 2px solid var(--hy-virtual-mouse-click-color, var(--hy-accent-color, #83dcff));
|
|
107
107
|
border-radius: 50%;
|
|
108
108
|
opacity: 0;
|
|
109
109
|
translate: -50% -50%;
|