@telperion/elements 1.0.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/LICENSE +21 -0
- package/README.md +102 -0
- package/bundle.js +164 -0
- package/bundle.mjs +2630 -0
- package/drag-drop/drag-element.cjs +438 -0
- package/drag-drop/drag-element.d.ts +120 -0
- package/drag-drop/drag-element.js +437 -0
- package/drag-drop/drag-element.js.map +1 -0
- package/drag-drop/drag-handle-element.cjs +35 -0
- package/drag-drop/drag-handle-element.d.ts +12 -0
- package/drag-drop/drag-handle-element.js +34 -0
- package/drag-drop/drag-handle-element.js.map +1 -0
- package/drag-drop/dropzone-element.cjs +117 -0
- package/drag-drop/dropzone-element.d.ts +17 -0
- package/drag-drop/dropzone-element.js +116 -0
- package/drag-drop/dropzone-element.js.map +1 -0
- package/drag-drop/index.cjs +11 -0
- package/drag-drop/index.d.ts +22 -0
- package/drag-drop/index.js +6 -0
- package/drag-drop/index.js.map +1 -0
- package/drag-drop/private-props.cjs +6 -0
- package/drag-drop/private-props.d.ts +3 -0
- package/drag-drop/private-props.js +5 -0
- package/drag-drop/private-props.js.map +1 -0
- package/drag-drop/tha-drag-event.cjs +34 -0
- package/drag-drop/tha-drag-event.d.ts +19 -0
- package/drag-drop/tha-drag-event.js +32 -0
- package/drag-drop/tha-drag-event.js.map +1 -0
- package/icon/icon-element.cjs +114 -0
- package/icon/icon-element.d.ts +40 -0
- package/icon/icon-element.js +113 -0
- package/icon/icon-element.js.map +1 -0
- package/icon/index.cjs +5 -0
- package/icon/index.d.ts +1 -0
- package/icon/index.js +3 -0
- package/icon/index.js.map +1 -0
- package/icon/material-symbols.css +22 -0
- package/index.cjs +11 -0
- package/index.d.ts +6 -0
- package/index.js +10 -0
- package/index.js.map +1 -0
- package/package.json +127 -0
- package/router/history-managed.cjs +97 -0
- package/router/history-managed.d.ts +76 -0
- package/router/history-managed.js +95 -0
- package/router/history-managed.js.map +1 -0
- package/router/history.cjs +65 -0
- package/router/history.d.ts +48 -0
- package/router/history.js +63 -0
- package/router/history.js.map +1 -0
- package/router/index.cjs +15 -0
- package/router/index.d.ts +6 -0
- package/router/index.js +8 -0
- package/router/index.js.map +1 -0
- package/router/signal-watcher-lit-element.cjs +11 -0
- package/router/signal-watcher-lit-element.d.ts +25 -0
- package/router/signal-watcher-lit-element.js +10 -0
- package/router/signal-watcher-lit-element.js.map +1 -0
- package/router/tha-route.cjs +125 -0
- package/router/tha-route.d.ts +90 -0
- package/router/tha-route.js +124 -0
- package/router/tha-route.js.map +1 -0
- package/router/tha-router-config.cjs +241 -0
- package/router/tha-router-config.d.ts +223 -0
- package/router/tha-router-config.js +240 -0
- package/router/tha-router-config.js.map +1 -0
- package/router/tha-router-link.cjs +209 -0
- package/router/tha-router-link.d.ts +95 -0
- package/router/tha-router-link.js +208 -0
- package/router/tha-router-link.js.map +1 -0
- package/router/tha-router-outlet.cjs +215 -0
- package/router/tha-router-outlet.d.ts +112 -0
- package/router/tha-router-outlet.js +214 -0
- package/router/tha-router-outlet.js.map +1 -0
- package/router/tha-router-param.cjs +278 -0
- package/router/tha-router-param.d.ts +226 -0
- package/router/tha-router-param.js +277 -0
- package/router/tha-router-param.js.map +1 -0
- package/router/tha-router.cjs +163 -0
- package/router/tha-router.d.ts +69 -0
- package/router/tha-router.js +162 -0
- package/router/tha-router.js.map +1 -0
- package/tha-url-output.cjs +79 -0
- package/tha-url-output.d.ts +41 -0
- package/tha-url-output.js +78 -0
- package/tha-url-output.js.map +1 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
var DragElement_1;
|
|
3
|
+
import { __decorate, __metadata } from "tslib";
|
|
4
|
+
import { defer } from "@telperion/js-utils/function/defer";
|
|
5
|
+
import { LitElement, css, html } from "lit";
|
|
6
|
+
import { customElement, property } from "lit/decorators.js";
|
|
7
|
+
import { ACCEPT_DROP_PROP, REGISTER_HANDLE_PROP, UNREGISTER_HANDLE_PROP } from "./private-props";
|
|
8
|
+
import { ThaDragEvent } from "./tha-drag-event";
|
|
9
|
+
let DragElement = class DragElement extends LitElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/**
|
|
13
|
+
* A record of drag-related data attributes.
|
|
14
|
+
*/
|
|
15
|
+
this.dragData = {};
|
|
16
|
+
/**
|
|
17
|
+
* Pre-drag data used to store the initial state of the element before dragging starts.
|
|
18
|
+
*/
|
|
19
|
+
this.preDragData = {
|
|
20
|
+
boundingRect: null,
|
|
21
|
+
dragStartEvent: null,
|
|
22
|
+
styles: {
|
|
23
|
+
pointerEvents: ''
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A weak reference to the currently accepted drop zone.
|
|
28
|
+
* This is used to track which drop zone the element is currently accepted in.
|
|
29
|
+
*/
|
|
30
|
+
this.#acceptedDropzone = null;
|
|
31
|
+
/**
|
|
32
|
+
* A weak reference to the clone of the element created during dragging.
|
|
33
|
+
* This is used to manage the clone's lifecycle and properties.
|
|
34
|
+
*/
|
|
35
|
+
this.#clone = null;
|
|
36
|
+
/**
|
|
37
|
+
* A set of drag handles associated with the element.
|
|
38
|
+
*/
|
|
39
|
+
this.#handles = new Set();
|
|
40
|
+
/**
|
|
41
|
+
* The dragging strategy to use for the element.
|
|
42
|
+
* This determines how the element is dragged (e.g., move or copy).
|
|
43
|
+
*/
|
|
44
|
+
this.draggingStrategy = 'move';
|
|
45
|
+
/**
|
|
46
|
+
* Indicates whether the element is currently being dragged.
|
|
47
|
+
*/
|
|
48
|
+
this.dragging = false;
|
|
49
|
+
/**
|
|
50
|
+
* Indicates whether the drag operation has ended.
|
|
51
|
+
* This is used to manage the state of the element after dragging.
|
|
52
|
+
*/
|
|
53
|
+
this.dragend = false;
|
|
54
|
+
/**
|
|
55
|
+
* The ID of the drop zone the element is currently over.
|
|
56
|
+
*/
|
|
57
|
+
this.draggedOver = null;
|
|
58
|
+
/**
|
|
59
|
+
* Indicates whether the element has been accepted by a drop zone.
|
|
60
|
+
* This is used to manage the state of the element during drag-and-drop operations.
|
|
61
|
+
*/
|
|
62
|
+
this.dropAccepted = false;
|
|
63
|
+
/**
|
|
64
|
+
* Handles the drag start event.
|
|
65
|
+
* @param event The drag event.
|
|
66
|
+
*/
|
|
67
|
+
this.#handleDragStart = (event) => {
|
|
68
|
+
if (!this.#shouldHandleEvent(event))
|
|
69
|
+
return event.preventDefault();
|
|
70
|
+
// Stop propagation to prevent parent draggable elements from interfering.
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
// Modify base event properties to prevent default behavior and set up drag image.
|
|
73
|
+
event.dataTransfer?.setDragImage(DragElement_1.TRANSPARENT_IMAGE, 0, 0);
|
|
74
|
+
event.dataTransfer.effectAllowed = this.draggingStrategy;
|
|
75
|
+
document.addEventListener('dragover', this.#preventDragOver);
|
|
76
|
+
// Prepare pre-drag data and styles.
|
|
77
|
+
this.#preparePreDragData(event);
|
|
78
|
+
this.#prepareDraggingStyles();
|
|
79
|
+
defer().then(() => {
|
|
80
|
+
this.style.pointerEvents = 'none';
|
|
81
|
+
this.dragging = true;
|
|
82
|
+
if (this.replaceClone) {
|
|
83
|
+
const clone = this.#createClone();
|
|
84
|
+
this.#clone = new WeakRef(clone);
|
|
85
|
+
this.parentElement.insertBefore(clone, this.nextSibling);
|
|
86
|
+
}
|
|
87
|
+
this.dispatchEvent(new ThaDragEvent('thadragstart', { dragTarget: new WeakRef(this) }, event));
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Handles the drag end event.
|
|
92
|
+
* @param event The drag event.
|
|
93
|
+
*/
|
|
94
|
+
this.#handleDragEnd = (event) => {
|
|
95
|
+
document.removeEventListener('dragover', this.#preventDragOver);
|
|
96
|
+
this.dragend = true;
|
|
97
|
+
const hasTransition = getComputedStyle(this).transitionDuration.match(/\d*\.?\d+/g)?.map(Number).some(num => num > 0);
|
|
98
|
+
const clear = () => {
|
|
99
|
+
if (this.replaceClone)
|
|
100
|
+
this.clone?.remove();
|
|
101
|
+
this.style.pointerEvents = this.preDragData.styles.pointerEvents;
|
|
102
|
+
['--tha-width', '--tha-height', '--tha-left', '--tha-top', '--tha-x', '--tha-y', '--tha-cx', '--tha-cy'].forEach(prop => {
|
|
103
|
+
this.style.removeProperty(prop);
|
|
104
|
+
});
|
|
105
|
+
['width', 'height', 'left', 'right', 'top', 'bottom'].forEach(prop => {
|
|
106
|
+
this.style.removeProperty(`--tha-target-${prop}`);
|
|
107
|
+
});
|
|
108
|
+
const acceptedDropzone = this.#acceptedDropzone;
|
|
109
|
+
const dropAccepted = this.dropAccepted;
|
|
110
|
+
this.dragging = false;
|
|
111
|
+
this.dragend = false;
|
|
112
|
+
this.draggedOver = null;
|
|
113
|
+
this.dropAccepted = false;
|
|
114
|
+
this.#acceptedDropzone = null;
|
|
115
|
+
if (dropAccepted && acceptedDropzone) {
|
|
116
|
+
acceptedDropzone.deref()?.dispatchEvent(new ThaDragEvent('thadropend', { dragTarget: new WeakRef(this), dropzoneTarget: acceptedDropzone }, event));
|
|
117
|
+
}
|
|
118
|
+
this.dispatchEvent(new ThaDragEvent('thadragend', { dragTarget: new WeakRef(this) }, event));
|
|
119
|
+
};
|
|
120
|
+
if (hasTransition)
|
|
121
|
+
this.addEventListener('transitionend', clear, { once: true });
|
|
122
|
+
else
|
|
123
|
+
clear();
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Handles the drag event.
|
|
127
|
+
* This updates the position of the element during dragging.
|
|
128
|
+
* @param event The drag event.
|
|
129
|
+
*/
|
|
130
|
+
this.#handleDrag = (event) => {
|
|
131
|
+
const { x, y } = event;
|
|
132
|
+
this.style.setProperty('--tha-cx', `${x}px`);
|
|
133
|
+
this.style.setProperty('--tha-cy', `${y}px`);
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Handles the drop zone enter event.
|
|
137
|
+
* This updates the draggedOver property to indicate which drop zone the element is currently over.
|
|
138
|
+
* @param event The ThaDragEvent for the drop zone enter.
|
|
139
|
+
*/
|
|
140
|
+
this.#handleDropZoneEnter = (event) => {
|
|
141
|
+
this.draggedOver = event.dropzoneTarget?.deref()?.name ?? '';
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Handles the drop zone leave event.
|
|
145
|
+
* This clears the draggedOver property when the element leaves a drop zone.
|
|
146
|
+
* @param event The ThaDragEvent for the drop zone leave.
|
|
147
|
+
*/
|
|
148
|
+
this.#handleDropZoneLeave = () => {
|
|
149
|
+
this.draggedOver = null;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
static { DragElement_1 = this; }
|
|
153
|
+
/**
|
|
154
|
+
* An observer for monitoring changes to drag-related attributes.
|
|
155
|
+
*/
|
|
156
|
+
static { this.DRAG_DATA_OBSERVER = new MutationObserver(records => {
|
|
157
|
+
for (const { attributeName, target } of records) {
|
|
158
|
+
if (!attributeName?.startsWith('data-drag-'))
|
|
159
|
+
continue;
|
|
160
|
+
const element = target;
|
|
161
|
+
element.dragData[attributeName.replace('data-drag-', '')] = element.getAttribute(attributeName);
|
|
162
|
+
}
|
|
163
|
+
}); }
|
|
164
|
+
static { this.styles = css `
|
|
165
|
+
:host {
|
|
166
|
+
--tha-diff-x: calc(var(--tha-cx) - var(--tha-x));
|
|
167
|
+
--tha-diff-y: calc(var(--tha-cy) - var(--tha-y));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
:host([draggingstrategy="move"]),
|
|
171
|
+
:host([draggingstrategy="copyMove"]) {
|
|
172
|
+
transition-duration: .2s;
|
|
173
|
+
transition-timing-function: ease-out;
|
|
174
|
+
transition-property: none;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
:host([draggingstrategy="move"][dragging]),
|
|
178
|
+
:host([draggingstrategy="copyMove"][dragging]) {
|
|
179
|
+
position: fixed;
|
|
180
|
+
width: var(--tha-width);
|
|
181
|
+
height: var(--tha-height);
|
|
182
|
+
left: calc(var(--tha-left) + var(--tha-diff-x) + var(--tha-offset-x));
|
|
183
|
+
top: calc(var(--tha-top) + var(--tha-diff-y) + var(--tha-offset-y));
|
|
184
|
+
transform-origin: calc(var(--tha-x) - var(--tha-left)) calc(var(--tha-y) - var(--tha-top));
|
|
185
|
+
z-index: 100;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
:host([draggingstrategy="move"][dragend]),
|
|
189
|
+
:host([draggingstrategy="copyMove"][dragend]) {
|
|
190
|
+
left: var(--tha-left);
|
|
191
|
+
top: var(--tha-top);
|
|
192
|
+
transition-property: all;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
:host([draggingstrategy="move"][dragend][dropaccepted]),
|
|
196
|
+
:host([draggingstrategy="copyMove"][dragend][dropaccepted]) {
|
|
197
|
+
left: var(--tha-target-left);
|
|
198
|
+
top: var(--tha-target-top);
|
|
199
|
+
width: var(--tha-target-width);
|
|
200
|
+
height: var(--tha-target-height);
|
|
201
|
+
}
|
|
202
|
+
`; }
|
|
203
|
+
static {
|
|
204
|
+
this.TRANSPARENT_IMAGE = new Image(1, 1);
|
|
205
|
+
this.TRANSPARENT_IMAGE.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==';
|
|
206
|
+
const style = this.GLOBAL_STYLE = document.createElement('style');
|
|
207
|
+
style.innerHTML = `
|
|
208
|
+
@property --tha-offset-x {
|
|
209
|
+
syntax: '<length>';
|
|
210
|
+
initial-value: 0px;
|
|
211
|
+
inherits: true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@property --tha-offset-y {
|
|
215
|
+
syntax: '<length>';
|
|
216
|
+
initial-value: 0px;
|
|
217
|
+
inherits: true;
|
|
218
|
+
}
|
|
219
|
+
`;
|
|
220
|
+
document.head.appendChild(style);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A weak reference to the currently accepted drop zone.
|
|
224
|
+
* This is used to track which drop zone the element is currently accepted in.
|
|
225
|
+
*/
|
|
226
|
+
#acceptedDropzone;
|
|
227
|
+
/**
|
|
228
|
+
* A weak reference to the clone of the element created during dragging.
|
|
229
|
+
* This is used to manage the clone's lifecycle and properties.
|
|
230
|
+
*/
|
|
231
|
+
#clone;
|
|
232
|
+
/**
|
|
233
|
+
* A set of drag handles associated with the element.
|
|
234
|
+
*/
|
|
235
|
+
#handles;
|
|
236
|
+
/**
|
|
237
|
+
* Returns the clone of the element if it exists.
|
|
238
|
+
* This is used to access the clone during drag operations.
|
|
239
|
+
*/
|
|
240
|
+
get clone() { return this.#clone.deref(); }
|
|
241
|
+
connectedCallback() {
|
|
242
|
+
super.connectedCallback();
|
|
243
|
+
// Set the draggable attribute to true to enable dragging.
|
|
244
|
+
this.draggable = true;
|
|
245
|
+
// Set up the drag data attributes observer to monitor changes to drag-related attributes.
|
|
246
|
+
this.#setUpDragDataAttrs();
|
|
247
|
+
// Add event listeners for drag events.
|
|
248
|
+
this.addEventListener('dragstart', this.#handleDragStart);
|
|
249
|
+
this.addEventListener('dragend', this.#handleDragEnd);
|
|
250
|
+
this.addEventListener('drag', this.#handleDrag);
|
|
251
|
+
this.addEventListener('thadropzoneenter', this.#handleDropZoneEnter);
|
|
252
|
+
this.addEventListener('thadropzoneleave', this.#handleDropZoneLeave);
|
|
253
|
+
}
|
|
254
|
+
disconnectedCallback() {
|
|
255
|
+
super.disconnectedCallback();
|
|
256
|
+
// Clean up the drag data attributes observer.
|
|
257
|
+
this.removeEventListener('dragstart', this.#handleDragStart);
|
|
258
|
+
this.removeEventListener('dragend', this.#handleDragEnd);
|
|
259
|
+
this.removeEventListener('drag', this.#handleDrag);
|
|
260
|
+
this.removeEventListener('thadropzoneenter', this.#handleDropZoneEnter);
|
|
261
|
+
this.removeEventListener('thadropzoneleave', this.#handleDropZoneLeave);
|
|
262
|
+
}
|
|
263
|
+
render() {
|
|
264
|
+
return html `<slot></slot>`;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Accepts a drop zone and an optional rectangle for the drop area.
|
|
268
|
+
* @param dropzone The drop zone element being accepted.
|
|
269
|
+
* @param rect The bounding rectangle of the drop area.
|
|
270
|
+
* @returns
|
|
271
|
+
*/
|
|
272
|
+
[ACCEPT_DROP_PROP](dropzone, rect) {
|
|
273
|
+
this.dropAccepted = true;
|
|
274
|
+
this.#acceptedDropzone = dropzone;
|
|
275
|
+
if (!rect)
|
|
276
|
+
return;
|
|
277
|
+
const { width, height, left, right, top, bottom } = rect;
|
|
278
|
+
for (const prop in { width, height, left, right, top, bottom }) {
|
|
279
|
+
this.style.setProperty(`--tha-target-${prop}`, `${rect[prop]}px`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Registers a drag handle element.
|
|
284
|
+
* @param handle The drag handle element to register.
|
|
285
|
+
*/
|
|
286
|
+
[REGISTER_HANDLE_PROP](handle) {
|
|
287
|
+
this.#handles.add(handle);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Unregisters a drag handle element.
|
|
291
|
+
* @param handle The drag handle element to unregister.
|
|
292
|
+
*/
|
|
293
|
+
[UNREGISTER_HANDLE_PROP](handle) {
|
|
294
|
+
this.#handles.delete(handle);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Sets up the drag data attributes observer to monitor changes to drag-related attributes.
|
|
298
|
+
* This allows the element to transfer custom data during drag-and-drop operations.
|
|
299
|
+
*/
|
|
300
|
+
#setUpDragDataAttrs() {
|
|
301
|
+
DragElement_1.DRAG_DATA_OBSERVER.observe(this, { attributes: true });
|
|
302
|
+
for (const { name, value } of Object.values(this.attributes).filter(attr => attr.name.startsWith('data-drag-'))) {
|
|
303
|
+
this.dragData[name.replace('data-drag-', '')] = value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Handles the drag start event.
|
|
308
|
+
* @param event The drag event.
|
|
309
|
+
*/
|
|
310
|
+
#handleDragStart;
|
|
311
|
+
/**
|
|
312
|
+
* Handles the drag end event.
|
|
313
|
+
* @param event The drag event.
|
|
314
|
+
*/
|
|
315
|
+
#handleDragEnd;
|
|
316
|
+
/**
|
|
317
|
+
* Handles the drag event.
|
|
318
|
+
* This updates the position of the element during dragging.
|
|
319
|
+
* @param event The drag event.
|
|
320
|
+
*/
|
|
321
|
+
#handleDrag;
|
|
322
|
+
/**
|
|
323
|
+
* Handles the drop zone enter event.
|
|
324
|
+
* This updates the draggedOver property to indicate which drop zone the element is currently over.
|
|
325
|
+
* @param event The ThaDragEvent for the drop zone enter.
|
|
326
|
+
*/
|
|
327
|
+
#handleDropZoneEnter;
|
|
328
|
+
/**
|
|
329
|
+
* Handles the drop zone leave event.
|
|
330
|
+
* This clears the draggedOver property when the element leaves a drop zone.
|
|
331
|
+
* @param event The ThaDragEvent for the drop zone leave.
|
|
332
|
+
*/
|
|
333
|
+
#handleDropZoneLeave;
|
|
334
|
+
/**
|
|
335
|
+
* Creates a clone of the element for dragging.
|
|
336
|
+
* This clone is used to visually represent the element during drag operations.
|
|
337
|
+
* @returns The cloned element.
|
|
338
|
+
*/
|
|
339
|
+
#createClone() {
|
|
340
|
+
const container = document.createElement('tha-drag-clone');
|
|
341
|
+
Object.values(this.attributes)
|
|
342
|
+
.filter(attr => !['dragging', 'replaceclone', 'draggable'].includes(attr.name))
|
|
343
|
+
.forEach(attr => {
|
|
344
|
+
container.attributes.setNamedItem(attr.cloneNode());
|
|
345
|
+
});
|
|
346
|
+
this.childNodes.forEach(node => {
|
|
347
|
+
container.appendChild(node.cloneNode(true));
|
|
348
|
+
});
|
|
349
|
+
return container;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Prepares the pre-drag data, including the bounding rectangle and styles.
|
|
353
|
+
* This data is used to restore the element's state after dragging.
|
|
354
|
+
* @param event The drag event.
|
|
355
|
+
*/
|
|
356
|
+
#preparePreDragData(event) {
|
|
357
|
+
this.preDragData.boundingRect = this.getBoundingClientRect();
|
|
358
|
+
this.preDragData.dragStartEvent = event;
|
|
359
|
+
this.preDragData.styles.pointerEvents = this.style.pointerEvents;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Prepares the styles for dragging, including the position and size of the element.
|
|
363
|
+
* This is used to update the element's position during drag operations.
|
|
364
|
+
*/
|
|
365
|
+
#prepareDraggingStyles() {
|
|
366
|
+
const { boundingRect: { width, height, left, top }, dragStartEvent: { x, y } } = this.preDragData;
|
|
367
|
+
const props = { width, height, left, top, x, y };
|
|
368
|
+
for (const prop in props) {
|
|
369
|
+
this.style.setProperty(`--tha-${prop}`, `${props[prop]}px`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Prevents the default dragover behavior to allow custom drag-and-drop handling.
|
|
374
|
+
* @param event The drag event.
|
|
375
|
+
*/
|
|
376
|
+
#preventDragOver(event) {
|
|
377
|
+
event.preventDefault();
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Checks if the element should handle the drag event based on the target.
|
|
381
|
+
* If there are no handles, it returns true to allow the event.
|
|
382
|
+
* If there are handles, it checks if the event target is one of the handles.
|
|
383
|
+
* @param event The drag event.
|
|
384
|
+
* @returns True if the element should handle the event, false otherwise.
|
|
385
|
+
*/
|
|
386
|
+
#shouldHandleEvent(event) {
|
|
387
|
+
if (this.disabled)
|
|
388
|
+
return false;
|
|
389
|
+
if (!this.#handles.size)
|
|
390
|
+
return true;
|
|
391
|
+
if (this.#handles.has(event.target))
|
|
392
|
+
return true;
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
__decorate([
|
|
397
|
+
property({ type: String }),
|
|
398
|
+
__metadata("design:type", String)
|
|
399
|
+
], DragElement.prototype, "name", void 0);
|
|
400
|
+
__decorate([
|
|
401
|
+
property({ type: String, reflect: true }),
|
|
402
|
+
__metadata("design:type", String)
|
|
403
|
+
], DragElement.prototype, "draggingStrategy", void 0);
|
|
404
|
+
__decorate([
|
|
405
|
+
property({ type: String }),
|
|
406
|
+
__metadata("design:type", String)
|
|
407
|
+
], DragElement.prototype, "dragGroup", void 0);
|
|
408
|
+
__decorate([
|
|
409
|
+
property({ type: Boolean }),
|
|
410
|
+
__metadata("design:type", Boolean)
|
|
411
|
+
], DragElement.prototype, "replaceClone", void 0);
|
|
412
|
+
__decorate([
|
|
413
|
+
property({ type: Boolean, reflect: true }),
|
|
414
|
+
__metadata("design:type", Object)
|
|
415
|
+
], DragElement.prototype, "dragging", void 0);
|
|
416
|
+
__decorate([
|
|
417
|
+
property({ type: Boolean, reflect: true }),
|
|
418
|
+
__metadata("design:type", Object)
|
|
419
|
+
], DragElement.prototype, "dragend", void 0);
|
|
420
|
+
__decorate([
|
|
421
|
+
property({ type: String, reflect: true }),
|
|
422
|
+
__metadata("design:type", Object)
|
|
423
|
+
], DragElement.prototype, "draggedOver", void 0);
|
|
424
|
+
__decorate([
|
|
425
|
+
property({ type: Boolean, reflect: true }),
|
|
426
|
+
__metadata("design:type", Object)
|
|
427
|
+
], DragElement.prototype, "dropAccepted", void 0);
|
|
428
|
+
__decorate([
|
|
429
|
+
property({ type: Boolean, reflect: true }),
|
|
430
|
+
__metadata("design:type", Boolean)
|
|
431
|
+
], DragElement.prototype, "disabled", void 0);
|
|
432
|
+
DragElement = DragElement_1 = __decorate([
|
|
433
|
+
customElement('tha-drag')
|
|
434
|
+
], DragElement);
|
|
435
|
+
export { DragElement };
|
|
436
|
+
|
|
437
|
+
//# sourceMappingURL=drag-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/elements/src/drag-drop/drag-element.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAA4C,MAAM,KAAK,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,QAAQ,EAA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,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,MAA2B,CAAC;YAAE,OAAO,IAAI,CAAC;QAEtE,OAAO,KAAK,CAAC;IACf,CAAC;;AA7TO;IADP,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCACN;AAOrB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;qDACK;AAUvC;IADP,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACD;AAOlB;IADP,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;iDACE;AAM9B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;6CAC1B;AAOjB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;4CAC3B;AAMhB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;gDACR;AAOlC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;iDACtB;AAOb;IADP,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;6CACjB;AA7Lf,WAAW;IADvB,aAAa,CAAC,UAAU,CAAC;GACb,WAAW,CAkcvB","file":"drag-element.js","sourcesContent":["import { defer } from \"@telperion/js-utils/function/defer\";\r\nimport { LitElement, css, html, type CSSResultGroup, type TemplateResult } from \"lit\";\r\nimport { customElement, property } from \"lit/decorators.js\";\r\n\r\nimport type { DropZoneElement } from \"./dropzone-element\";\r\nimport { ACCEPT_DROP_PROP, REGISTER_HANDLE_PROP, UNREGISTER_HANDLE_PROP } from \"./private-props\";\r\nimport { ThaDragEvent } from \"./tha-drag-event\";\r\nimport type { DragHandleElement } from \"./drag-handle-element\";\r\n\r\ndeclare global {\r\n interface HTMLElementTagNameMap {\r\n /**\r\n * A draggable element that can be used to initiate drag-and-drop operations.\r\n * It can contain child elements and supports drag handles.\r\n * The `replaceclone` attribute indicates whether the element should be replaced with a clone during\r\n * the drag operation.\r\n * The `draggingstrategy` attribute defines the drag behavior, such as 'move' or 'copyMove'.\r\n *\r\n */\r\n \"tha-drag\": DragElement;\r\n }\r\n}\r\n\r\n@customElement('tha-drag')\r\nexport class DragElement extends LitElement {\r\n /**\r\n * A transparent image used as a drag image to prevent flickering during drag operations.\r\n * This image is used when the drag image is not set explicitly.\r\n * It is a 1x1 pixel transparent PNG.\r\n */\r\n declare private static TRANSPARENT_IMAGE: HTMLImageElement;\r\n\r\n /**\r\n * A global style element used to define custom properties for drag-and-drop.\r\n */\r\n declare private static GLOBAL_STYLE: HTMLStyleElement;\r\n\r\n /**\r\n * An observer for monitoring changes to drag-related attributes.\r\n */\r\n private static DRAG_DATA_OBSERVER = new MutationObserver(records => {\r\n for (const { attributeName, target } of records) {\r\n if (!attributeName?.startsWith('data-drag-')) continue;\r\n\r\n const element = <DragElement>target;\r\n\r\n element.dragData[attributeName.replace('data-drag-', '')] = element.getAttribute(attributeName)!;\r\n }\r\n });\r\n\r\n static override styles: CSSResultGroup = css`\r\n :host {\r\n --tha-diff-x: calc(var(--tha-cx) - var(--tha-x));\r\n --tha-diff-y: calc(var(--tha-cy) - var(--tha-y));\r\n }\r\n\r\n :host([draggingstrategy=\"move\"]),\r\n :host([draggingstrategy=\"copyMove\"]) {\r\n transition-duration: .2s;\r\n transition-timing-function: ease-out;\r\n transition-property: none;\r\n }\r\n\r\n :host([draggingstrategy=\"move\"][dragging]),\r\n :host([draggingstrategy=\"copyMove\"][dragging]) {\r\n position: fixed;\r\n width: var(--tha-width);\r\n height: var(--tha-height);\r\n left: calc(var(--tha-left) + var(--tha-diff-x) + var(--tha-offset-x));\r\n top: calc(var(--tha-top) + var(--tha-diff-y) + var(--tha-offset-y));\r\n transform-origin: calc(var(--tha-x) - var(--tha-left)) calc(var(--tha-y) - var(--tha-top));\r\n z-index: 100;\r\n }\r\n\r\n :host([draggingstrategy=\"move\"][dragend]),\r\n :host([draggingstrategy=\"copyMove\"][dragend]) {\r\n left: var(--tha-left);\r\n top: var(--tha-top);\r\n transition-property: all;\r\n }\r\n\r\n :host([draggingstrategy=\"move\"][dragend][dropaccepted]),\r\n :host([draggingstrategy=\"copyMove\"][dragend][dropaccepted]) {\r\n left: var(--tha-target-left);\r\n top: var(--tha-target-top);\r\n width: var(--tha-target-width);\r\n height: var(--tha-target-height);\r\n }\r\n `;\r\n\r\n static {\r\n this.TRANSPARENT_IMAGE = new Image(1, 1);\r\n this.TRANSPARENT_IMAGE.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==';\r\n\r\n const style = this.GLOBAL_STYLE = document.createElement('style');\r\n\r\n style.innerHTML = `\r\n @property --tha-offset-x {\r\n syntax: '<length>';\r\n initial-value: 0px;\r\n inherits: true;\r\n }\r\n\r\n @property --tha-offset-y {\r\n syntax: '<length>';\r\n initial-value: 0px;\r\n inherits: true;\r\n }\r\n `;\r\n document.head.appendChild(style);\r\n }\r\n\r\n /**\r\n * A record of drag-related data attributes.\r\n */\r\n readonly dragData: Record<string, string> = {};\r\n\r\n /**\r\n * Pre-drag data used to store the initial state of the element before dragging starts.\r\n */\r\n readonly preDragData = {\r\n boundingRect: null! as DOMRect,\r\n dragStartEvent: null! as DragEvent,\r\n styles: {\r\n pointerEvents: ''\r\n }\r\n };\r\n\r\n /**\r\n * A weak reference to the currently accepted drop zone.\r\n * This is used to track which drop zone the element is currently accepted in.\r\n */\r\n #acceptedDropzone: WeakRef<DropZoneElement> | null = null;\r\n\r\n /**\r\n * A weak reference to the clone of the element created during dragging.\r\n * This is used to manage the clone's lifecycle and properties.\r\n */\r\n #clone: WeakRef<HTMLElement> = null!;\r\n\r\n /**\r\n * A set of drag handles associated with the element.\r\n */\r\n #handles = new Set<DragHandleElement>();\r\n\r\n /**\r\n * Returns the clone of the element if it exists.\r\n * This is used to access the clone during drag operations.\r\n */\r\n get clone() { return this.#clone.deref(); }\r\n\r\n /**\r\n * The name of the element, used for identification in drag-and-drop operations.\r\n * This helps the dropzones to accept or reject the drag based on the name.\r\n */\r\n @property({ type: String })\r\n declare name: string;\r\n\r\n /**\r\n * The dragging strategy to use for the element.\r\n * This determines how the element is dragged (e.g., move or copy).\r\n */\r\n @property({ type: String, reflect: true })\r\n draggingStrategy: 'move' | 'copyMove' = 'move';\r\n\r\n /**\r\n * The group name for the drag element.\r\n * This is used to group elements together for drag-and-drop operations.\r\n * Elements with the same group name can interact with each other during drag-and-drop.\r\n *\r\n * !!! Not implemented yet !!!\r\n */\r\n @property({ type: String })\r\n declare dragGroup: string;\r\n\r\n /**\r\n * Indicates whether the element should replace its clone during drag operations.\r\n * If true , the original element is replaced with a clone during dragging.\r\n */\r\n @property({ type: Boolean })\r\n declare replaceClone: boolean;\r\n\r\n /**\r\n * Indicates whether the element is currently being dragged.\r\n */\r\n @property({ type: Boolean, reflect: true })\r\n dragging = false;\r\n\r\n /**\r\n * Indicates whether the drag operation has ended.\r\n * This is used to manage the state of the element after dragging.\r\n */\r\n @property({ type: Boolean, reflect: true })\r\n dragend = false;\r\n\r\n /**\r\n * The ID of the drop zone the element is currently over.\r\n */\r\n @property({ type: String, reflect: true })\r\n draggedOver: string | null = null;\r\n\r\n /**\r\n * Indicates whether the element has been accepted by a drop zone.\r\n * This is used to manage the state of the element during drag-and-drop operations.\r\n */\r\n @property({ type: Boolean, reflect: true })\r\n dropAccepted = false;\r\n\r\n /**\r\n * Indicates whether the drag element is disabled.\r\n * When disabled, the element cannot be dragged.\r\n */\r\n @property({ type: Boolean, reflect: true })\r\n declare disabled: boolean;\r\n\r\n override connectedCallback(): void {\r\n super.connectedCallback();\r\n\r\n // Set the draggable attribute to true to enable dragging.\r\n this.draggable = true;\r\n\r\n // Set up the drag data attributes observer to monitor changes to drag-related attributes.\r\n this.#setUpDragDataAttrs();\r\n\r\n // Add event listeners for drag events.\r\n this.addEventListener('dragstart', this.#handleDragStart);\r\n this.addEventListener('dragend', this.#handleDragEnd);\r\n this.addEventListener('drag', this.#handleDrag);\r\n this.addEventListener('thadropzoneenter', this.#handleDropZoneEnter);\r\n this.addEventListener('thadropzoneleave', this.#handleDropZoneLeave);\r\n }\r\n\r\n override disconnectedCallback(): void {\r\n super.disconnectedCallback();\r\n\r\n // Clean up the drag data attributes observer.\r\n this.removeEventListener('dragstart', this.#handleDragStart);\r\n this.removeEventListener('dragend', this.#handleDragEnd);\r\n this.removeEventListener('drag', this.#handleDrag);\r\n this.removeEventListener('thadropzoneenter', this.#handleDropZoneEnter);\r\n this.removeEventListener('thadropzoneleave', this.#handleDropZoneLeave);\r\n }\r\n\r\n protected override render(): TemplateResult {\r\n return html`<slot></slot>`;\r\n }\r\n\r\n /**\r\n * Accepts a drop zone and an optional rectangle for the drop area.\r\n * @param dropzone The drop zone element being accepted.\r\n * @param rect The bounding rectangle of the drop area.\r\n * @returns\r\n */\r\n [ACCEPT_DROP_PROP](dropzone: WeakRef<DropZoneElement>, rect?: DOMRect) {\r\n this.dropAccepted = true;\r\n this.#acceptedDropzone = dropzone;\r\n\r\n if (!rect) return;\r\n\r\n const { width, height, left, right, top, bottom } = rect;\r\n\r\n for (const prop in { width, height, left, right, top, bottom }) {\r\n this.style.setProperty(`--tha-target-${prop}`, `${rect[prop as keyof DOMRect]}px`);\r\n }\r\n }\r\n\r\n /**\r\n * Registers a drag handle element.\r\n * @param handle The drag handle element to register.\r\n */\r\n [REGISTER_HANDLE_PROP](handle: DragHandleElement) {\r\n this.#handles.add(handle);\r\n }\r\n\r\n /**\r\n * Unregisters a drag handle element.\r\n * @param handle The drag handle element to unregister.\r\n */\r\n [UNREGISTER_HANDLE_PROP](handle: DragHandleElement) {\r\n this.#handles.delete(handle);\r\n }\r\n\r\n /**\r\n * Sets up the drag data attributes observer to monitor changes to drag-related attributes.\r\n * This allows the element to transfer custom data during drag-and-drop operations.\r\n */\r\n #setUpDragDataAttrs() {\r\n DragElement.DRAG_DATA_OBSERVER.observe(this, { attributes: true });\r\n\r\n for (const { name, value } of Object.values(this.attributes).filter(attr => attr.name.startsWith('data-drag-'))) {\r\n this.dragData[name.replace('data-drag-', '')] = value;\r\n }\r\n }\r\n\r\n /**\r\n * Handles the drag start event.\r\n * @param event The drag event.\r\n */\r\n #handleDragStart = (event: DragEvent) => {\r\n if (!this.#shouldHandleEvent(event)) return event.preventDefault();\r\n\r\n // Stop propagation to prevent parent draggable elements from interfering.\r\n event.stopPropagation();\r\n\r\n // Modify base event properties to prevent default behavior and set up drag image.\r\n event.dataTransfer?.setDragImage(DragElement.TRANSPARENT_IMAGE, 0, 0);\r\n event.dataTransfer!.effectAllowed = this.draggingStrategy;\r\n\r\n document.addEventListener('dragover', this.#preventDragOver);\r\n\r\n // Prepare pre-drag data and styles.\r\n this.#preparePreDragData(event);\r\n this.#prepareDraggingStyles();\r\n\r\n defer().then(() => {\r\n this.style.pointerEvents = 'none';\r\n this.dragging = true;\r\n\r\n if (this.replaceClone) {\r\n const clone = this.#createClone();\r\n\r\n this.#clone = new WeakRef(clone);\r\n this.parentElement!.insertBefore(clone, this.nextSibling);\r\n }\r\n\r\n this.dispatchEvent(new ThaDragEvent('thadragstart', { dragTarget: new WeakRef(this) }, event));\r\n });\r\n };\r\n\r\n /**\r\n * Handles the drag end event.\r\n * @param event The drag event.\r\n */\r\n #handleDragEnd = (event: DragEvent) => {\r\n document.removeEventListener('dragover', this.#preventDragOver);\r\n this.dragend = true;\r\n\r\n const hasTransition = getComputedStyle(this).transitionDuration.match(/\\d*\\.?\\d+/g)?.map(Number).some(num => num > 0);\r\n const clear = () => {\r\n if (this.replaceClone) this.clone?.remove();\r\n\r\n this.style.pointerEvents = this.preDragData.styles.pointerEvents;\r\n ['--tha-width', '--tha-height', '--tha-left', '--tha-top', '--tha-x', '--tha-y', '--tha-cx', '--tha-cy'].forEach(prop => {\r\n this.style.removeProperty(prop);\r\n });\r\n ['width', 'height', 'left', 'right', 'top', 'bottom'].forEach(prop => {\r\n this.style.removeProperty(`--tha-target-${prop}`);\r\n });\r\n\r\n const acceptedDropzone = this.#acceptedDropzone;\r\n const dropAccepted = this.dropAccepted;\r\n\r\n this.dragging = false;\r\n this.dragend = false;\r\n this.draggedOver = null;\r\n this.dropAccepted = false;\r\n this.#acceptedDropzone = null;\r\n\r\n if (dropAccepted && acceptedDropzone) {\r\n acceptedDropzone.deref()?.dispatchEvent(new ThaDragEvent(\r\n 'thadropend',\r\n { dragTarget: new WeakRef(this), dropzoneTarget: acceptedDropzone },\r\n event\r\n ));\r\n }\r\n\r\n this.dispatchEvent(new ThaDragEvent('thadragend', { dragTarget: new WeakRef(this) }, event));\r\n };\r\n\r\n if (hasTransition) this.addEventListener('transitionend', clear, { once: true });\r\n else clear();\r\n };\r\n\r\n /**\r\n * Handles the drag event.\r\n * This updates the position of the element during dragging.\r\n * @param event The drag event.\r\n */\r\n #handleDrag = (event: DragEvent) => {\r\n const { x, y } = event;\r\n\r\n this.style.setProperty('--tha-cx', `${x}px`);\r\n this.style.setProperty('--tha-cy', `${y}px`);\r\n };\r\n\r\n /**\r\n * Handles the drop zone enter event.\r\n * This updates the draggedOver property to indicate which drop zone the element is currently over.\r\n * @param event The ThaDragEvent for the drop zone enter.\r\n */\r\n #handleDropZoneEnter = (event: ThaDragEvent) => {\r\n this.draggedOver = event.dropzoneTarget?.deref()?.name ?? '';\r\n };\r\n\r\n /**\r\n * Handles the drop zone leave event.\r\n * This clears the draggedOver property when the element leaves a drop zone.\r\n * @param event The ThaDragEvent for the drop zone leave.\r\n */\r\n #handleDropZoneLeave = () => {\r\n this.draggedOver = null;\r\n };\r\n\r\n /**\r\n * Creates a clone of the element for dragging.\r\n * This clone is used to visually represent the element during drag operations.\r\n * @returns The cloned element.\r\n */\r\n #createClone() {\r\n const container = document.createElement('tha-drag-clone');\r\n\r\n Object.values(this.attributes)\r\n .filter(attr => !['dragging', 'replaceclone', 'draggable'].includes(attr.name))\r\n .forEach(attr => {\r\n container.attributes.setNamedItem(attr.cloneNode() as Attr);\r\n });\r\n\r\n this.childNodes.forEach(node => {\r\n container.appendChild(node.cloneNode(true));\r\n });\r\n\r\n return container;\r\n }\r\n\r\n /**\r\n * Prepares the pre-drag data, including the bounding rectangle and styles.\r\n * This data is used to restore the element's state after dragging.\r\n * @param event The drag event.\r\n */\r\n #preparePreDragData(event: DragEvent) {\r\n this.preDragData.boundingRect = this.getBoundingClientRect();\r\n this.preDragData.dragStartEvent = event;\r\n this.preDragData.styles.pointerEvents = this.style.pointerEvents;\r\n }\r\n\r\n /**\r\n * Prepares the styles for dragging, including the position and size of the element.\r\n * This is used to update the element's position during drag operations.\r\n */\r\n #prepareDraggingStyles() {\r\n const {\r\n boundingRect: { width, height, left, top },\r\n dragStartEvent: { x, y }\r\n } = this.preDragData;\r\n const props = { width, height, left, top, x, y };\r\n\r\n for (const prop in props) {\r\n this.style.setProperty(`--tha-${prop}`, `${props[prop as keyof typeof props]}px`);\r\n }\r\n }\r\n\r\n /**\r\n * Prevents the default dragover behavior to allow custom drag-and-drop handling.\r\n * @param event The drag event.\r\n */\r\n #preventDragOver(event: DragEvent) {\r\n event.preventDefault();\r\n }\r\n\r\n /**\r\n * Checks if the element should handle the drag event based on the target.\r\n * If there are no handles, it returns true to allow the event.\r\n * If there are handles, it checks if the event target is one of the handles.\r\n * @param event The drag event.\r\n * @returns True if the element should handle the event, false otherwise.\r\n */\r\n #shouldHandleEvent(event: DragEvent): boolean {\r\n if (this.disabled) return false;\r\n if (!this.#handles.size) return true;\r\n\r\n if (this.#handles.has(event.target as DragHandleElement)) return true;\r\n\r\n return false;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DragHandleElement = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const get_parents_1 = require("@thalesrc/dom-utils/get-parents");
|
|
6
|
+
const lit_1 = require("lit");
|
|
7
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
8
|
+
const drag_element_1 = require("./drag-element");
|
|
9
|
+
const private_props_1 = require("./private-props");
|
|
10
|
+
let DragHandleElement = class DragHandleElement extends lit_1.LitElement {
|
|
11
|
+
get #parent() {
|
|
12
|
+
for (const parent of (0, get_parents_1.getParents)(this)) {
|
|
13
|
+
if (parent instanceof drag_element_1.DragElement) {
|
|
14
|
+
return parent;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
connectedCallback() {
|
|
20
|
+
super.connectedCallback();
|
|
21
|
+
this.draggable = true;
|
|
22
|
+
this.#parent?.[private_props_1.REGISTER_HANDLE_PROP](this);
|
|
23
|
+
}
|
|
24
|
+
disconnectedCallback() {
|
|
25
|
+
super.disconnectedCallback();
|
|
26
|
+
this.#parent?.[private_props_1.UNREGISTER_HANDLE_PROP](this);
|
|
27
|
+
}
|
|
28
|
+
render() {
|
|
29
|
+
return (0, lit_1.html) `<slot></slot>`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.DragHandleElement = DragHandleElement;
|
|
33
|
+
exports.DragHandleElement = DragHandleElement = tslib_1.__decorate([
|
|
34
|
+
(0, decorators_js_1.customElement)("tha-drag-handle")
|
|
35
|
+
], DragHandleElement);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LitElement, type TemplateResult } from "lit";
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
"tha-drag-handle": DragHandleElement;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare class DragHandleElement extends LitElement {
|
|
8
|
+
#private;
|
|
9
|
+
connectedCallback(): void;
|
|
10
|
+
disconnectedCallback(): void;
|
|
11
|
+
protected render(): TemplateResult;
|
|
12
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { getParents } from "@thalesrc/dom-utils/get-parents";
|
|
3
|
+
import { html, LitElement } from "lit";
|
|
4
|
+
import { customElement } from "lit/decorators.js";
|
|
5
|
+
import { DragElement } from "./drag-element";
|
|
6
|
+
import { REGISTER_HANDLE_PROP, UNREGISTER_HANDLE_PROP } from "./private-props";
|
|
7
|
+
let DragHandleElement = class DragHandleElement extends LitElement {
|
|
8
|
+
get #parent() {
|
|
9
|
+
for (const parent of getParents(this)) {
|
|
10
|
+
if (parent instanceof DragElement) {
|
|
11
|
+
return parent;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
super.connectedCallback();
|
|
18
|
+
this.draggable = true;
|
|
19
|
+
this.#parent?.[REGISTER_HANDLE_PROP](this);
|
|
20
|
+
}
|
|
21
|
+
disconnectedCallback() {
|
|
22
|
+
super.disconnectedCallback();
|
|
23
|
+
this.#parent?.[UNREGISTER_HANDLE_PROP](this);
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
return html `<slot></slot>`;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
DragHandleElement = __decorate([
|
|
30
|
+
customElement("tha-drag-handle")
|
|
31
|
+
], DragHandleElement);
|
|
32
|
+
export { DragHandleElement };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=drag-handle-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/elements/src/drag-drop/drag-handle-element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAuB,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AASxE,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU;IAC/C,IAAI,OAAO;QACT,KAAK,MAAM,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,IAAI,MAAM,YAAY,WAAW,EAAE,CAAC;gBAClC,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEQ,iBAAiB;QACxB,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAE1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEQ,oBAAoB;QAC3B,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAE7B,IAAI,CAAC,OAAO,EAAE,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAEkB,MAAM;QACvB,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;CACF,CAAA;AA3BY,iBAAiB;IAD7B,aAAa,CAAC,iBAAiB,CAAC;GACpB,iBAAiB,CA2B7B","file":"drag-handle-element.js","sourcesContent":["import { getParents } from \"@thalesrc/dom-utils/get-parents\";\r\nimport { html, LitElement, type TemplateResult } from \"lit\";\r\nimport { customElement } from \"lit/decorators.js\";\r\n\r\nimport { DragElement } from \"./drag-element\";\r\nimport { REGISTER_HANDLE_PROP, UNREGISTER_HANDLE_PROP } from \"./private-props\";\r\n\r\ndeclare global {\r\n interface HTMLElementTagNameMap {\r\n \"tha-drag-handle\": DragHandleElement;\r\n }\r\n}\r\n\r\n@customElement(\"tha-drag-handle\")\r\nexport class DragHandleElement extends LitElement {\r\n get #parent(): DragElement | null {\r\n for (const parent of getParents(this)) {\r\n if (parent instanceof DragElement) {\r\n return parent;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n override connectedCallback(): void {\r\n super.connectedCallback();\r\n\r\n this.draggable = true;\r\n this.#parent?.[REGISTER_HANDLE_PROP](this);\r\n }\r\n\r\n override disconnectedCallback(): void {\r\n super.disconnectedCallback();\r\n\r\n this.#parent?.[UNREGISTER_HANDLE_PROP](this);\r\n }\r\n\r\n protected override render(): TemplateResult {\r\n return html`<slot></slot>`;\r\n }\r\n}\r\n"]}
|