@haiyue/ui 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +68 -1
- package/dist/drag-source.d.ts +27 -0
- package/dist/drag-source.js +114 -0
- package/dist/draggable.d.ts +1 -2
- package/dist/draggable.js +21 -29
- package/dist/dropzone.d.ts +29 -0
- package/dist/dropzone.js +89 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/internal/drag-drop.d.ts +29 -0
- package/dist/internal/drag-drop.js +171 -0
- package/dist/internal/native-drop.d.ts +17 -0
- package/dist/internal/native-drop.js +62 -0
- package/dist/internal/pointer-drag.d.ts +15 -0
- package/dist/internal/pointer-drag.js +100 -0
- package/dist/resizable.d.ts +1 -1
- package/dist/resizable.js +22 -26
- package/dist/sortable.d.ts +62 -0
- package/dist/sortable.js +363 -0
- package/dist/upload.d.ts +1 -5
- package/dist/upload.js +13 -24
- package/package.json +33 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.4.0 - 2026-11-28
|
|
6
|
+
|
|
7
|
+
- 新增 `HYSortable`、`HYDragSource`、`HYDropzone`,覆盖纵向/横向/网格排序、同组跨列表转移、应用数据和原生文件拖放;支持手柄、鼠标/触屏/键盘、类型限制、取消和主题化示例。
|
|
8
|
+
- 拖拽交互共享指针激活、捕获与取消、接收区深度跟踪和拖拽会话;现有 Draggable、Resizable、Upload 接入共享实现,排序保留原始内容节点并在放下时提交顺序。
|
|
9
|
+
|
|
5
10
|
## 0.3.1 - 2026-11-24
|
|
6
11
|
|
|
7
12
|
- 完成剩余审查项:统一缺省数值属性,修复 Drawer/Dialog/Tour/Tooltip 的焦点、无障碍与生命周期,以及选择器禁用和 Radio 组互斥行为。
|
package/README.md
CHANGED
|
@@ -1104,6 +1104,73 @@ the exported `HY_VIRTUAL_KEYBOARD_NUMERIC_LAYOUT` with digits, decimal, minus, d
|
|
|
1104
1104
|
`virtual-keyboard-up`, and `virtual-keyboard-input`, or style `keyboard`, `row`, `key`, and per-code key parts
|
|
1105
1105
|
with the `--hy-virtual-keyboard-*` tokens.
|
|
1106
1106
|
|
|
1107
|
+
## Drag-and-drop
|
|
1108
|
+
|
|
1109
|
+
`@haiyue/ui/sortable`, `@haiyue/ui/drag-source` and `@haiyue/ui/dropzone` provide independent entries
|
|
1110
|
+
and explicit `defineSortableComponents()`, `defineDragSourceComponents()` and `defineDropzoneComponents()`
|
|
1111
|
+
registration. They are also included in `defineHaiyueUI()`.
|
|
1112
|
+
|
|
1113
|
+
```html
|
|
1114
|
+
<hy-sortable group="tasks" aria-label="Backlog">
|
|
1115
|
+
<article data-id="a">Task A</article>
|
|
1116
|
+
<article data-id="b">Task B</article>
|
|
1117
|
+
</hy-sortable>
|
|
1118
|
+
<hy-sortable group="tasks" aria-label="Ready"></hy-sortable>
|
|
1119
|
+
|
|
1120
|
+
<hy-drag-source id="asset" type="asset" value="ocean" aria-label="Ocean material">
|
|
1121
|
+
Ocean material
|
|
1122
|
+
</hy-drag-source>
|
|
1123
|
+
<hy-dropzone id="target" accept="asset,Files" aria-label="Asset destination">
|
|
1124
|
+
Drop an asset or files here
|
|
1125
|
+
</hy-dropzone>
|
|
1126
|
+
```
|
|
1127
|
+
|
|
1128
|
+
```js
|
|
1129
|
+
const source = document.querySelector('#asset');
|
|
1130
|
+
source.data = { id: 'ocean', name: 'Ocean material' };
|
|
1131
|
+
document.querySelector('#target').addEventListener('data-drop', event => {
|
|
1132
|
+
const { data, files, type, source, effect, input } = event.detail;
|
|
1133
|
+
if (!canPlace(data, files)) event.preventDefault();
|
|
1134
|
+
else placeAsset(data, files);
|
|
1135
|
+
});
|
|
1136
|
+
document.addEventListener('sort-change', event => {
|
|
1137
|
+
const { from, to, item, oldIndex, newIndex, fromOrder, toOrder } = event.detail;
|
|
1138
|
+
saveListOrders(fromOrder, toOrder);
|
|
1139
|
+
});
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
Sortable uses the visible, unnamed direct children as items. `data-id` or `id` supplies a stable key in
|
|
1143
|
+
`order`, `fromOrder` and `toOrder`; items without either receive an internal stable key. `direction` accepts
|
|
1144
|
+
`vertical` (default), `horizontal` and `grid`; `columns` defaults to 3 for the grid. Lists with the same
|
|
1145
|
+
nonempty `group` accept transfers between them, including into empty lists. `handle` restricts pointer
|
|
1146
|
+
activation to a CSS selector, `data-sort-disabled` prevents picking up an individual item, and `disabled`
|
|
1147
|
+
prevents sorting. `keyboard="false"` disables keyboard sorting. `move(fromIndex, toIndex)` reorders through
|
|
1148
|
+
the API. `refresh()` synchronizes item accessibility after changing item-level attributes.
|
|
1149
|
+
|
|
1150
|
+
`sort-start` and `sort-before-change` are cancelable. Sortable commits the original DOM elements on a
|
|
1151
|
+
successful drop, then emits one composed `sort-change` from the destination. It retains editable content
|
|
1152
|
+
and restores focus. `sort-end` is emitted from the origin and includes `accepted` and `cancelled`.
|
|
1153
|
+
Press Space or Enter on an item to pick it up, arrows/Home/End to choose a position, and Enter to commit.
|
|
1154
|
+
Tab can focus another list; Escape cancels. Horizontal and grid navigation follow RTL. Drop indicators
|
|
1155
|
+
and polite announcements communicate the current operation. Pointer gestures activate after 6px and
|
|
1156
|
+
support edge scrolling. Touch gestures use `touch-action: none`; `--hy-sortable-touch-action` can override it.
|
|
1157
|
+
|
|
1158
|
+
Drag Source supplies a `type`, arbitrary JavaScript `data` (or a string `value` attribute), `effect`
|
|
1159
|
+
(`move` by default, or `copy`), optional `handle`, and `disabled`. Its composed `drag-start` is cancelable;
|
|
1160
|
+
`drag-end` includes the payload, `target`, `accepted` and `cancelled`. Keyboard users pick up with Space,
|
|
1161
|
+
Tab to a Dropzone and press Enter to drop. The receiving application handles content placement.
|
|
1162
|
+
|
|
1163
|
+
Dropzone accepts comma-separated payload or native transfer types through `accept` (default `*`).
|
|
1164
|
+
`Files` accepts operating-system file drags; native file drops expose real `File` objects in `files`.
|
|
1165
|
+
Application payloads retain their original `data` object. `data-drop` is cancelable, and `drag-enter` /
|
|
1166
|
+
`drag-leave` expose application payload hover changes. Nested targets choose the innermost accepting zone.
|
|
1167
|
+
For file selection, type/size/count validation, upload progress and retry, use `hy-upload drag`.
|
|
1168
|
+
|
|
1169
|
+
Sortable exposes `items`, `indicator` and `status` parts and `--hy-sortable-gap`, `--hy-sortable-min-height`,
|
|
1170
|
+
`--hy-sortable-drag-opacity`. Drag Source and Dropzone expose a `surface` part. Dropzone also accepts
|
|
1171
|
+
`--hy-dropzone-padding`, `--hy-dropzone-radius`, `--hy-dropzone-min-height` and `--hy-dropzone-bg-color`.
|
|
1172
|
+
Colors, typography, focus rings and drop feedback inherit the shared theme tokens.
|
|
1173
|
+
|
|
1107
1174
|
## Draggable container
|
|
1108
1175
|
|
|
1109
1176
|
Import the transform-based container independently, then use any slotted element as its handle:
|
|
@@ -1344,7 +1411,7 @@ npm run release:check
|
|
|
1344
1411
|
```
|
|
1345
1412
|
|
|
1346
1413
|
Candidates: `.artifacts/packages/`. Review API changes before `npm run api:update`.
|
|
1347
|
-
See [release
|
|
1414
|
+
See [release history](CHANGELOG.md).
|
|
1348
1415
|
|
|
1349
1416
|
### 共享组件目录(开发中)
|
|
1350
1417
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type { HYDragPayload, HYDragEndDetail } from './internal/drag-drop.js';
|
|
2
|
+
/** Application data source for pointer, touch and keyboard drag-and-drop. */
|
|
3
|
+
export declare class HYDragSource extends HTMLElement {
|
|
4
|
+
private readonly _surface;
|
|
5
|
+
private readonly _pointer;
|
|
6
|
+
private readonly _instructions;
|
|
7
|
+
private _data;
|
|
8
|
+
static get observedAttributes(): string[];
|
|
9
|
+
constructor();
|
|
10
|
+
connectedCallback(): void;
|
|
11
|
+
disconnectedCallback(): void;
|
|
12
|
+
attributeChangedCallback(): void;
|
|
13
|
+
get type(): string;
|
|
14
|
+
set type(value: string);
|
|
15
|
+
get data(): unknown;
|
|
16
|
+
set data(value: unknown);
|
|
17
|
+
get effect(): 'copy' | 'move';
|
|
18
|
+
set effect(value: 'copy' | 'move');
|
|
19
|
+
get disabled(): boolean;
|
|
20
|
+
set disabled(value: boolean);
|
|
21
|
+
get handle(): string;
|
|
22
|
+
set handle(value: string);
|
|
23
|
+
focus(options?: FocusOptions): void;
|
|
24
|
+
private _sync;
|
|
25
|
+
private _begin;
|
|
26
|
+
}
|
|
27
|
+
export declare function defineDragSourceComponents(): void;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { HYPointerDrag, dragTargetAllowed } from './internal/pointer-drag.js';
|
|
2
|
+
import { activeDrag, beginDrag, cancelDragSource, finishDrag, moveDrag } from './internal/drag-drop.js';
|
|
3
|
+
import { isKeyboardControlEvent } from './internal/keyboard.js';
|
|
4
|
+
let instructionSequence = 0;
|
|
5
|
+
/** Application data source for pointer, touch and keyboard drag-and-drop. */
|
|
6
|
+
export class HYDragSource extends HTMLElement {
|
|
7
|
+
_surface = document.createElement('div');
|
|
8
|
+
_pointer = new HYPointerDrag();
|
|
9
|
+
_instructions = document.createElement('div');
|
|
10
|
+
_data;
|
|
11
|
+
static get observedAttributes() { return ['type', 'value', 'effect', 'disabled', 'handle', 'aria-label']; }
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
15
|
+
const style = document.createElement('style');
|
|
16
|
+
style.textContent = `
|
|
17
|
+
:host { display: inline-block; min-width: 0; max-width: 100%; touch-action: none; }
|
|
18
|
+
:host([hidden]) { display: none !important; }
|
|
19
|
+
.surface { cursor: grab; touch-action: none; border-radius: var(--hy-radius-md, 6px); }
|
|
20
|
+
.surface:focus-visible { outline: 2px solid var(--hy-focus-border-color, #8177f2); outline-offset: 2px; }
|
|
21
|
+
:host([dragging]) .surface { opacity: .55; cursor: grabbing; }
|
|
22
|
+
:host([disabled]) .surface { cursor: default; }
|
|
23
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
24
|
+
`;
|
|
25
|
+
this._surface.className = 'surface';
|
|
26
|
+
this._surface.part.add('surface');
|
|
27
|
+
this._surface.setAttribute('role', 'group');
|
|
28
|
+
this._surface.append(document.createElement('slot'));
|
|
29
|
+
this._instructions.id = `hy-drag-instructions-${++instructionSequence}`;
|
|
30
|
+
this._instructions.className = 'sr';
|
|
31
|
+
this._instructions.setAttribute('role', 'status');
|
|
32
|
+
this._instructions.setAttribute('aria-live', 'polite');
|
|
33
|
+
this._instructions.textContent = 'Press Space to pick up, Tab to a drop zone, Enter to drop, and Escape to cancel.';
|
|
34
|
+
this._surface.setAttribute('aria-describedby', this._instructions.id);
|
|
35
|
+
root.append(style, this._surface, this._instructions);
|
|
36
|
+
this.addEventListener('pointerdown', event => {
|
|
37
|
+
if (this.disabled || !dragTargetAllowed(event, this, this.handle))
|
|
38
|
+
return;
|
|
39
|
+
if (this._pointer.start(event, this._surface, {
|
|
40
|
+
start: () => this._begin('pointer'),
|
|
41
|
+
move: move => moveDrag(this.ownerDocument, move.clientX, move.clientY),
|
|
42
|
+
end: (up, cancelled) => {
|
|
43
|
+
if (!cancelled)
|
|
44
|
+
moveDrag(this.ownerDocument, up.clientX, up.clientY);
|
|
45
|
+
finishDrag(this.ownerDocument, cancelled);
|
|
46
|
+
},
|
|
47
|
+
}, 6))
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
});
|
|
50
|
+
this._surface.addEventListener('dragstart', event => event.preventDefault());
|
|
51
|
+
this._surface.addEventListener('keydown', event => {
|
|
52
|
+
if (this.disabled || event.defaultPrevented || (isKeyboardControlEvent(event, this._surface) && !(this.handle && dragTargetAllowed(event, this, this.handle))))
|
|
53
|
+
return;
|
|
54
|
+
if (event.key !== ' ' && event.key !== 'Enter')
|
|
55
|
+
return;
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
if (activeDrag(this.ownerDocument)?.source === this)
|
|
58
|
+
finishDrag(this.ownerDocument);
|
|
59
|
+
else
|
|
60
|
+
this._begin('keyboard');
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
connectedCallback() { this._sync(); }
|
|
64
|
+
disconnectedCallback() { this._pointer.cancel(); cancelDragSource(this); this.removeAttribute('dragging'); }
|
|
65
|
+
attributeChangedCallback() {
|
|
66
|
+
if (this.disabled) {
|
|
67
|
+
this._pointer.cancel();
|
|
68
|
+
cancelDragSource(this);
|
|
69
|
+
}
|
|
70
|
+
this._sync();
|
|
71
|
+
}
|
|
72
|
+
get type() { return this.getAttribute('type')?.trim() || 'item'; }
|
|
73
|
+
set type(value) { this.setAttribute('type', value); }
|
|
74
|
+
get data() { return this._data === undefined ? this.getAttribute('value') : this._data; }
|
|
75
|
+
set data(value) { this._data = value; }
|
|
76
|
+
get effect() { return this.getAttribute('effect') === 'copy' ? 'copy' : 'move'; }
|
|
77
|
+
set effect(value) { this.setAttribute('effect', value); }
|
|
78
|
+
get disabled() { return this.hasAttribute('disabled'); }
|
|
79
|
+
set disabled(value) { this.toggleAttribute('disabled', value); }
|
|
80
|
+
get handle() { return this.getAttribute('handle') ?? ''; }
|
|
81
|
+
set handle(value) { this.setAttribute('handle', value); }
|
|
82
|
+
focus(options) { this._surface.focus(options); }
|
|
83
|
+
_sync() {
|
|
84
|
+
this._surface.tabIndex = this.disabled ? -1 : 0;
|
|
85
|
+
this._surface.setAttribute('aria-disabled', String(this.disabled));
|
|
86
|
+
this._surface.setAttribute('aria-label', this.getAttribute('aria-label') || 'Drag source. Press Space to pick up, Tab to a drop zone, and Enter to drop.');
|
|
87
|
+
}
|
|
88
|
+
_begin(input) {
|
|
89
|
+
if (this.disabled || !this.isConnected || activeDrag(this.ownerDocument))
|
|
90
|
+
return false;
|
|
91
|
+
const payload = { type: this.type, data: this.data, source: this, effect: this.effect, input };
|
|
92
|
+
if (!this.dispatchEvent(new CustomEvent('drag-start', { detail: payload, bubbles: true, composed: true, cancelable: true })) || this.disabled || !this.isConnected)
|
|
93
|
+
return false;
|
|
94
|
+
const started = beginDrag(payload, detail => {
|
|
95
|
+
this._pointer.cancel();
|
|
96
|
+
this.removeAttribute('dragging');
|
|
97
|
+
this._instructions.textContent = detail.accepted ? 'Item dropped.' : 'Drag ended without a drop. Press Space to pick up again.';
|
|
98
|
+
if (detail.cancelled && detail.input === 'keyboard' && this.isConnected)
|
|
99
|
+
this.focus({ preventScroll: true });
|
|
100
|
+
this.dispatchEvent(new CustomEvent('drag-end', { detail, bubbles: true, composed: true }));
|
|
101
|
+
});
|
|
102
|
+
if (started) {
|
|
103
|
+
this.setAttribute('dragging', '');
|
|
104
|
+
this._instructions.textContent = 'Picked up. Tab to a drop zone, Enter to drop, or Escape to cancel.';
|
|
105
|
+
this.focus({ preventScroll: true });
|
|
106
|
+
}
|
|
107
|
+
return started;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function defineDragSourceComponents() {
|
|
111
|
+
if (!customElements.get('hy-drag-source'))
|
|
112
|
+
customElements.define('hy-drag-source', HYDragSource);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=drag-source.js.map
|
package/dist/draggable.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare class HYDraggable extends HTMLElement {
|
|
|
24
24
|
private _y;
|
|
25
25
|
private _reflecting;
|
|
26
26
|
private _boundsTarget;
|
|
27
|
-
private
|
|
27
|
+
private readonly _pointer;
|
|
28
28
|
private _pointerId;
|
|
29
29
|
private _originX;
|
|
30
30
|
private _originY;
|
|
@@ -63,7 +63,6 @@ export declare class HYDraggable extends HTMLElement {
|
|
|
63
63
|
refresh(): HYDraggablePosition;
|
|
64
64
|
private _startPointerDrag;
|
|
65
65
|
private _handlePointerMove;
|
|
66
|
-
private _finishPointerDrag;
|
|
67
66
|
private _completePointerDrag;
|
|
68
67
|
private _cancelDrag;
|
|
69
68
|
private _handleKeydown;
|
package/dist/draggable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { finiteNumber as readFiniteNumber } from './internal/numbers.js';
|
|
2
2
|
import { isKeyboardControlEvent } from './internal/keyboard.js';
|
|
3
|
+
import { HYPointerDrag } from './internal/pointer-drag.js';
|
|
3
4
|
const DEFAULT_CANCEL = 'input, textarea, select, button, a, [contenteditable="true"], [data-no-drag]';
|
|
4
5
|
function finiteNumber(value, fallback = 0) {
|
|
5
6
|
const number = readFiniteNumber(value, fallback);
|
|
@@ -20,7 +21,7 @@ export class HYDraggable extends HTMLElement {
|
|
|
20
21
|
_y = 0;
|
|
21
22
|
_reflecting = false;
|
|
22
23
|
_boundsTarget = null;
|
|
23
|
-
|
|
24
|
+
_pointer = new HYPointerDrag();
|
|
24
25
|
_pointerId = null;
|
|
25
26
|
_originX = 0;
|
|
26
27
|
_originY = 0;
|
|
@@ -117,24 +118,23 @@ export class HYDraggable extends HTMLElement {
|
|
|
117
118
|
_startPointerDrag(event) {
|
|
118
119
|
if (this.disabled || event.button !== 0 || this._pointerId != null || !this._allowsTarget(event))
|
|
119
120
|
return;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this._surface.addEventListener('lostpointercapture', () => this._cancelDrag(true), { signal: abort.signal });
|
|
121
|
+
this._pointer.start(event, this._surface, {
|
|
122
|
+
start: () => {
|
|
123
|
+
const start = new CustomEvent('drag-start', { bubbles: true, composed: true, cancelable: true, detail: { x: this._x, y: this._y, pointerId: event.pointerId } });
|
|
124
|
+
if (!this.dispatchEvent(start) || this.disabled || !this.isConnected)
|
|
125
|
+
return false;
|
|
126
|
+
this._surface.focus({ preventScroll: true });
|
|
127
|
+
this._pointerId = event.pointerId;
|
|
128
|
+
this._originX = this._x;
|
|
129
|
+
this._originY = this._y;
|
|
130
|
+
this._pointerX = event.clientX;
|
|
131
|
+
this._pointerY = event.clientY;
|
|
132
|
+
this.toggleAttribute('dragging', true);
|
|
133
|
+
return true;
|
|
134
|
+
},
|
|
135
|
+
move: move => this._handlePointerMove(move),
|
|
136
|
+
end: (up, cancelled) => this._completePointerDrag(up.pointerId, cancelled),
|
|
137
|
+
});
|
|
138
138
|
}
|
|
139
139
|
_handlePointerMove(event) {
|
|
140
140
|
if (event.pointerId !== this._pointerId)
|
|
@@ -144,26 +144,18 @@ export class HYDraggable extends HTMLElement {
|
|
|
144
144
|
const y = this.axis === 'x' ? this._originY : this._originY + event.clientY - this._pointerY;
|
|
145
145
|
this._moveTo(x, y, 'pointer');
|
|
146
146
|
}
|
|
147
|
-
_finishPointerDrag(event, cancelled) {
|
|
148
|
-
this._completePointerDrag(event.pointerId, cancelled);
|
|
149
|
-
}
|
|
150
147
|
_completePointerDrag(pointerId, cancelled) {
|
|
151
148
|
if (pointerId !== this._pointerId)
|
|
152
149
|
return;
|
|
153
150
|
const originX = this._originX;
|
|
154
151
|
const originY = this._originY;
|
|
155
|
-
this._dragAbort?.abort();
|
|
156
|
-
this._dragAbort = null;
|
|
157
152
|
this._pointerId = null;
|
|
158
153
|
this.toggleAttribute('dragging', false);
|
|
159
|
-
if (this._surface.hasPointerCapture(pointerId))
|
|
160
|
-
this._surface.releasePointerCapture(pointerId);
|
|
161
154
|
this.dispatchEvent(new CustomEvent('drag-end', { bubbles: true, composed: true, detail: { x: this._x, y: this._y, deltaX: this._x - originX, deltaY: this._y - originY, source: 'pointer', cancelled } }));
|
|
162
155
|
}
|
|
163
156
|
_cancelDrag(cancelled) {
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
this._completePointerDrag(this._pointerId, cancelled);
|
|
157
|
+
if (cancelled)
|
|
158
|
+
this._pointer.cancel();
|
|
167
159
|
}
|
|
168
160
|
_handleKeydown(event) {
|
|
169
161
|
if (this.disabled || !this.keyboard || event.defaultPrevented || isKeyboardControlEvent(event, this._surface))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface HYDropzoneDropDetail {
|
|
2
|
+
readonly source: HTMLElement | null;
|
|
3
|
+
readonly type: string;
|
|
4
|
+
readonly data: unknown;
|
|
5
|
+
readonly files: readonly File[];
|
|
6
|
+
readonly effect: 'copy' | 'move';
|
|
7
|
+
readonly input: 'pointer' | 'keyboard' | 'native';
|
|
8
|
+
}
|
|
9
|
+
/** Drop target for typed application data and native files or text. */
|
|
10
|
+
export declare class HYDropzone extends HTMLElement {
|
|
11
|
+
private readonly _surface;
|
|
12
|
+
private readonly _native;
|
|
13
|
+
private _unregister;
|
|
14
|
+
private _listeners;
|
|
15
|
+
static get observedAttributes(): string[];
|
|
16
|
+
constructor();
|
|
17
|
+
connectedCallback(): void;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
attributeChangedCallback(name: string): void;
|
|
20
|
+
get accept(): string;
|
|
21
|
+
set accept(value: string);
|
|
22
|
+
get disabled(): boolean;
|
|
23
|
+
set disabled(value: boolean);
|
|
24
|
+
focus(options?: FocusOptions): void;
|
|
25
|
+
private _sync;
|
|
26
|
+
private _acceptsTypes;
|
|
27
|
+
private _drop;
|
|
28
|
+
}
|
|
29
|
+
export declare function defineDropzoneComponents(): void;
|
package/dist/dropzone.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { registerDropTarget } from './internal/drag-drop.js';
|
|
2
|
+
import { HYNativeDrop, hasFiles } from './internal/native-drop.js';
|
|
3
|
+
/** Drop target for typed application data and native files or text. */
|
|
4
|
+
export class HYDropzone extends HTMLElement {
|
|
5
|
+
_surface = document.createElement('div');
|
|
6
|
+
_native = new HYNativeDrop(this._surface, {
|
|
7
|
+
enabled: () => true,
|
|
8
|
+
accepts: transfer => !this.disabled && this._acceptsTypes(hasFiles(transfer) ? ['Files'] : [...transfer.types]),
|
|
9
|
+
active: active => this.toggleAttribute('dragover', active),
|
|
10
|
+
drop: event => {
|
|
11
|
+
const transfer = event.dataTransfer;
|
|
12
|
+
const files = [...transfer.files];
|
|
13
|
+
const type = files.length ? 'Files' : [...transfer.types].find(value => this._acceptsTypes([value])) || 'text/plain';
|
|
14
|
+
this._drop({ source: null, type, data: files.length ? null : transfer.getData(type), files, effect: 'copy', input: 'native' });
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
_unregister = null;
|
|
18
|
+
_listeners = null;
|
|
19
|
+
static get observedAttributes() { return ['accept', 'disabled', 'aria-label']; }
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
23
|
+
const style = document.createElement('style');
|
|
24
|
+
style.textContent = `
|
|
25
|
+
:host { display: block; min-width: 0; color: var(--hy-text-color, #eef0ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-relaxed, 1.5) var(--hy-font-family, system-ui, sans-serif); }
|
|
26
|
+
:host([hidden]) { display: none !important; }
|
|
27
|
+
.surface { box-sizing: border-box; min-height: var(--hy-dropzone-min-height, 120px); padding: var(--hy-dropzone-padding, var(--hy-space-8, 16px)); border: 1px dashed var(--hy-border-color, #343765); border-radius: var(--hy-dropzone-radius, var(--hy-radius-lg, 8px)); background: var(--hy-dropzone-bg-color, var(--hy-surface-color, #10132f)); }
|
|
28
|
+
:host([dragover]) .surface { border-color: var(--hy-drop-indicator-color, var(--hy-accent-color, #8177f2)); background: var(--hy-drop-target-bg-color, var(--hy-hover-bg-color, #242752)); }
|
|
29
|
+
.surface:focus-visible { outline: 2px solid var(--hy-focus-border-color, #8177f2); outline-offset: 2px; }
|
|
30
|
+
:host([disabled]) .surface { opacity: .5; }
|
|
31
|
+
`;
|
|
32
|
+
this._surface.className = 'surface';
|
|
33
|
+
this._surface.part.add('surface');
|
|
34
|
+
this._surface.setAttribute('role', 'group');
|
|
35
|
+
this._surface.append(document.createElement('slot'));
|
|
36
|
+
root.append(style, this._surface);
|
|
37
|
+
}
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
this._listeners?.abort();
|
|
40
|
+
this._unregister?.();
|
|
41
|
+
this._listeners = new AbortController();
|
|
42
|
+
this._native.connect(this._listeners.signal);
|
|
43
|
+
this._unregister = registerDropTarget({
|
|
44
|
+
element: this,
|
|
45
|
+
accepts: payload => !this.disabled && this._acceptsTypes([payload.type]),
|
|
46
|
+
over: payload => {
|
|
47
|
+
if (this.hasAttribute('dragover'))
|
|
48
|
+
return;
|
|
49
|
+
this.setAttribute('dragover', '');
|
|
50
|
+
this.dispatchEvent(new CustomEvent('drag-enter', { detail: payload, bubbles: true, composed: true }));
|
|
51
|
+
},
|
|
52
|
+
leave: payload => {
|
|
53
|
+
this.removeAttribute('dragover');
|
|
54
|
+
this.dispatchEvent(new CustomEvent('drag-leave', { detail: payload, bubbles: true, composed: true }));
|
|
55
|
+
},
|
|
56
|
+
drop: payload => this._drop({ ...payload, files: [] }),
|
|
57
|
+
});
|
|
58
|
+
this._sync();
|
|
59
|
+
}
|
|
60
|
+
disconnectedCallback() { this._listeners?.abort(); this._listeners = null; this._unregister?.(); this._unregister = null; this.removeAttribute('dragover'); }
|
|
61
|
+
attributeChangedCallback(name) { if (name === 'accept' || name === 'disabled') {
|
|
62
|
+
this._native.reset();
|
|
63
|
+
this.removeAttribute('dragover');
|
|
64
|
+
} this._sync(); }
|
|
65
|
+
get accept() { return this.getAttribute('accept') ?? '*'; }
|
|
66
|
+
set accept(value) { this.setAttribute('accept', value); }
|
|
67
|
+
get disabled() { return this.hasAttribute('disabled'); }
|
|
68
|
+
set disabled(value) { this.toggleAttribute('disabled', value); }
|
|
69
|
+
focus(options) { this._surface.focus(options); }
|
|
70
|
+
_sync() {
|
|
71
|
+
this._surface.tabIndex = this.disabled ? -1 : 0;
|
|
72
|
+
this._surface.setAttribute('aria-disabled', String(this.disabled));
|
|
73
|
+
this._surface.setAttribute('aria-label', this.getAttribute('aria-label') || 'Drop zone. Press Enter to drop a picked-up item.');
|
|
74
|
+
}
|
|
75
|
+
_acceptsTypes(types) {
|
|
76
|
+
const accepted = this.accept.split(',').map(value => value.trim().toLowerCase()).filter(Boolean);
|
|
77
|
+
return accepted.includes('*') || types.some(type => accepted.includes(type.toLowerCase()));
|
|
78
|
+
}
|
|
79
|
+
_drop(detail) {
|
|
80
|
+
if (this.disabled || !this.isConnected || !this._acceptsTypes([detail.type]))
|
|
81
|
+
return false;
|
|
82
|
+
return this.dispatchEvent(new CustomEvent('data-drop', { detail, bubbles: true, composed: true, cancelable: true }));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function defineDropzoneComponents() {
|
|
86
|
+
if (!customElements.get('hy-dropzone'))
|
|
87
|
+
customElements.define('hy-dropzone', HYDropzone);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=dropzone.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -132,6 +132,12 @@ export { HYCard, defineCardComponents } from './card.js';
|
|
|
132
132
|
export type { HYCardSize } from './card.js';
|
|
133
133
|
export { HYRibbon, defineRibbonComponents } from './ribbon.js';
|
|
134
134
|
export type { HYRibbonPlacement } from './ribbon.js';
|
|
135
|
+
export { HYDragSource, defineDragSourceComponents } from './drag-source.js';
|
|
136
|
+
export type { HYDragPayload, HYDragEndDetail } from './drag-source.js';
|
|
137
|
+
export { HYDropzone, defineDropzoneComponents } from './dropzone.js';
|
|
138
|
+
export type { HYDropzoneDropDetail } from './dropzone.js';
|
|
139
|
+
export { HYSortable, defineSortableComponents } from './sortable.js';
|
|
140
|
+
export type { HYSortableDirection, HYSortableChangeDetail, HYSortableEndDetail } from './sortable.js';
|
|
135
141
|
export { HYDescriptions, defineDescriptionsComponents } from './descriptions.js';
|
|
136
142
|
export type { HYDescriptionItem, HYDescriptionsLayout, HYDescriptionsSize } from './descriptions.js';
|
|
137
143
|
export declare function defineHaiyueUI(): void;
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,9 @@ import { defineResizableComponents } from './resizable.js';
|
|
|
25
25
|
import { defineDialogComponents } from './dialog.js';
|
|
26
26
|
import { defineDrawerComponents } from './drawer.js';
|
|
27
27
|
import { defineDraggableComponents } from './draggable.js';
|
|
28
|
+
import { defineDragSourceComponents } from './drag-source.js';
|
|
29
|
+
import { defineDropzoneComponents } from './dropzone.js';
|
|
30
|
+
import { defineSortableComponents } from './sortable.js';
|
|
28
31
|
import { defineInputComponents } from './input.js';
|
|
29
32
|
import { defineMentionsComponents } from './mentions.js';
|
|
30
33
|
import { defineSwitchComponents } from './switch.js';
|
|
@@ -135,6 +138,9 @@ export { HYResult, defineResultComponents } from './result.js';
|
|
|
135
138
|
export { HYAvatar, defineAvatarComponents } from './avatar.js';
|
|
136
139
|
export { HYCard, defineCardComponents } from './card.js';
|
|
137
140
|
export { HYRibbon, defineRibbonComponents } from './ribbon.js';
|
|
141
|
+
export { HYDragSource, defineDragSourceComponents } from './drag-source.js';
|
|
142
|
+
export { HYDropzone, defineDropzoneComponents } from './dropzone.js';
|
|
143
|
+
export { HYSortable, defineSortableComponents } from './sortable.js';
|
|
138
144
|
export { HYDescriptions, defineDescriptionsComponents } from './descriptions.js';
|
|
139
145
|
export function defineHaiyueUI() {
|
|
140
146
|
defineEmptyComponents();
|
|
@@ -181,6 +187,9 @@ export function defineHaiyueUI() {
|
|
|
181
187
|
defineDialogComponents();
|
|
182
188
|
defineDrawerComponents();
|
|
183
189
|
defineDraggableComponents();
|
|
190
|
+
defineDragSourceComponents();
|
|
191
|
+
defineDropzoneComponents();
|
|
192
|
+
defineSortableComponents();
|
|
184
193
|
defineInputComponents();
|
|
185
194
|
defineMentionsComponents();
|
|
186
195
|
defineNotificationComponents();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface HYDragPayload {
|
|
2
|
+
readonly type: string;
|
|
3
|
+
readonly data: unknown;
|
|
4
|
+
readonly source: HTMLElement;
|
|
5
|
+
readonly effect: 'copy' | 'move';
|
|
6
|
+
readonly input: 'pointer' | 'keyboard';
|
|
7
|
+
}
|
|
8
|
+
export interface HYDragEndDetail extends HYDragPayload {
|
|
9
|
+
readonly target: HTMLElement | null;
|
|
10
|
+
readonly accepted: boolean;
|
|
11
|
+
readonly cancelled: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface HYDropTarget {
|
|
14
|
+
element: HTMLElement;
|
|
15
|
+
accepts(payload: HYDragPayload): boolean;
|
|
16
|
+
over(payload: HYDragPayload, point: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
} | null): void;
|
|
20
|
+
leave(payload: HYDragPayload): void;
|
|
21
|
+
drop(payload: HYDragPayload): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function composedContains(parent: Element, child: Node | null): boolean;
|
|
24
|
+
export declare function registerDropTarget(target: HYDropTarget): () => void;
|
|
25
|
+
export declare function activeDrag(document: Document): HYDragPayload | null;
|
|
26
|
+
export declare function beginDrag(payload: HYDragPayload, end: (detail: HYDragEndDetail) => void): boolean;
|
|
27
|
+
export declare function moveDrag(document: Document, x: number, y: number): void;
|
|
28
|
+
export declare function finishDrag(document: Document, cancelled?: boolean): void;
|
|
29
|
+
export declare function cancelDragSource(source: HTMLElement): void;
|