@sepveneto/free-dom 0.6.0 → 0.7.2
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/dist/index.css +105 -22
- package/dist/index.d.ts +567 -130
- package/dist/index.js +1536 -479
- package/dist/index.mjs +1527 -484
- package/package.json +11 -4
package/dist/index.mjs
CHANGED
|
@@ -1,465 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/components/freeDom.ts
|
|
9
|
-
import {
|
|
10
|
-
onMounted,
|
|
11
|
-
defineComponent,
|
|
12
|
-
h,
|
|
13
|
-
computed,
|
|
14
|
-
inject,
|
|
15
|
-
ref as ref2,
|
|
16
|
-
reactive,
|
|
17
|
-
isVue2,
|
|
18
|
-
shallowRef,
|
|
19
|
-
watch as watch2
|
|
20
|
-
} from "vue-demi";
|
|
21
|
-
|
|
22
|
-
// src/hooks/use-normalize-style.ts
|
|
23
|
-
import { ref, unref, watch } from "vue-demi";
|
|
24
|
-
function useNormalizeStyle(style) {
|
|
25
|
-
const _style = ref({
|
|
26
|
-
transition: "inherit"
|
|
27
|
-
});
|
|
28
|
-
watch(() => style, (data) => {
|
|
29
|
-
const res = Object.entries(unref(data)).reduce(
|
|
30
|
-
(obj, _style2) => {
|
|
31
|
-
const [key, value] = _style2;
|
|
32
|
-
if (typeof value === "number") {
|
|
33
|
-
obj[key] = `${value}px`;
|
|
34
|
-
} else {
|
|
35
|
-
obj[key] = value;
|
|
36
|
-
}
|
|
37
|
-
return obj;
|
|
38
|
-
},
|
|
39
|
-
{}
|
|
40
|
-
);
|
|
41
|
-
_style.value = {
|
|
42
|
-
..._style.value,
|
|
43
|
-
...res
|
|
44
|
-
};
|
|
45
|
-
}, { deep: true });
|
|
46
|
-
return _style;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/util/EventBus.ts
|
|
50
|
-
var _EventBus = class {
|
|
51
|
-
static on(name, callback) {
|
|
52
|
-
if (!Array.isArray(_EventBus._callbacks[name])) {
|
|
53
|
-
_EventBus._callbacks[name] = [];
|
|
54
|
-
}
|
|
55
|
-
_EventBus._callbacks[name].push(callback);
|
|
56
|
-
}
|
|
57
|
-
static emit(name, ...args) {
|
|
58
|
-
_EventBus._callbacks[name]?.forEach((item) => item.apply(this, args));
|
|
59
|
-
}
|
|
60
|
-
static off(name) {
|
|
61
|
-
_EventBus._callbacks[name].length = 0;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var EventBus = _EventBus;
|
|
65
|
-
__publicField(EventBus, "_callbacks", {});
|
|
1
|
+
// src/components/freeDomWrap.ts
|
|
2
|
+
import { computed as computed7, defineComponent as defineComponent5, onMounted as onMounted3, provide, reactive as reactive3, ref as ref10, shallowRef as shallowRef4, toRefs, watchEffect as watchEffect4 } from "vue-demi";
|
|
66
3
|
|
|
67
4
|
// src/util/tokens.ts
|
|
68
5
|
var SceneToken = Symbol("Scene");
|
|
69
6
|
|
|
70
|
-
// src/util/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let deltaY = clientY - startY;
|
|
93
|
-
if (Array.isArray(snapGrid)) {
|
|
94
|
-
[deltaX, deltaY] = snapToGrid(snapGrid, deltaX, deltaY);
|
|
95
|
-
}
|
|
96
|
-
const rate = cWidth / cHeight;
|
|
97
|
-
const newWidth = cWidth + (isL ? -deltaX : isR ? deltaX : 0);
|
|
98
|
-
const newHeight = cHeight + (isT ? -deltaY : isB ? deltaY : 0);
|
|
99
|
-
if (isDiagonal && diagonal) {
|
|
100
|
-
if (Math.abs(deltaX) >= Math.abs(deltaY)) {
|
|
101
|
-
rect.x = x + (isL ? deltaX : 0);
|
|
102
|
-
rect.width = clamp(newWidth, MIN_SIZE);
|
|
103
|
-
rect.height = clamp(newWidth / rate, MIN_SIZE);
|
|
7
|
+
// src/util/render.ts
|
|
8
|
+
import { merge } from "lodash";
|
|
9
|
+
import { h, isVue2 } from "vue-demi";
|
|
10
|
+
function createRender(comp, attrs = {}, props = {}, listeners = {}) {
|
|
11
|
+
if (!comp)
|
|
12
|
+
return () => null;
|
|
13
|
+
const options = isVue2 ? {
|
|
14
|
+
...attrs,
|
|
15
|
+
props,
|
|
16
|
+
on: listeners
|
|
17
|
+
} : {
|
|
18
|
+
...attrs,
|
|
19
|
+
...props
|
|
20
|
+
};
|
|
21
|
+
if (isVue2 && typeof comp === "object" && !("render" in comp)) {
|
|
22
|
+
merge(comp.data, options);
|
|
23
|
+
return comp;
|
|
24
|
+
}
|
|
25
|
+
return (slots) => {
|
|
26
|
+
if (isVue2) {
|
|
27
|
+
if (Object.prototype.toString.call(slots) === "[object Object]") {
|
|
28
|
+
return h(comp, { ...options, scopedSlots: slots });
|
|
104
29
|
} else {
|
|
105
|
-
|
|
106
|
-
rect.height = clamp(newHeight, MIN_SIZE);
|
|
107
|
-
rect.width = clamp(newHeight * rate, MIN_SIZE);
|
|
30
|
+
return h(comp, options, Array.isArray(slots) ? slots : [slots]);
|
|
108
31
|
}
|
|
109
32
|
} else {
|
|
110
|
-
|
|
111
|
-
rect.y = y + (isT ? deltaY : 0);
|
|
112
|
-
rect.width = clamp(newWidth, MIN_SIZE);
|
|
113
|
-
rect.height = clamp(newHeight, MIN_SIZE);
|
|
33
|
+
return h(comp, options, slots);
|
|
114
34
|
}
|
|
115
|
-
callbacks && callbacks.onMove && callbacks.onMove();
|
|
116
|
-
};
|
|
117
|
-
const up = () => {
|
|
118
|
-
document.removeEventListener("mousemove", move);
|
|
119
|
-
document.removeEventListener("mouseup", up);
|
|
120
|
-
callbacks && callbacks.onMove && callbacks.onUp();
|
|
121
35
|
};
|
|
122
|
-
document.addEventListener("mousemove", move);
|
|
123
|
-
document.addEventListener("mouseup", up);
|
|
124
36
|
}
|
|
125
37
|
|
|
126
|
-
// src/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
},
|
|
137
|
-
y: {
|
|
138
|
-
type: Number,
|
|
139
|
-
default: void 0
|
|
140
|
-
},
|
|
141
|
-
width: {
|
|
142
|
-
type: Number,
|
|
143
|
-
default: void 0
|
|
144
|
-
},
|
|
145
|
-
height: {
|
|
146
|
-
type: Number,
|
|
147
|
-
default: void 0
|
|
148
|
-
},
|
|
149
|
-
absolute: {
|
|
150
|
-
type: Boolean,
|
|
151
|
-
default: void 0
|
|
152
|
-
},
|
|
153
|
-
scale: {
|
|
154
|
-
type: [Boolean, Array],
|
|
155
|
-
default: void 0
|
|
156
|
-
},
|
|
157
|
-
move: Boolean,
|
|
158
|
-
preview: Boolean,
|
|
159
|
-
limitWidth: {
|
|
160
|
-
type: Number,
|
|
161
|
-
default: void 0
|
|
162
|
-
},
|
|
163
|
-
limitHeight: {
|
|
164
|
-
type: Number,
|
|
165
|
-
default: void 0
|
|
166
|
-
},
|
|
167
|
-
handler: {
|
|
168
|
-
type: String,
|
|
169
|
-
default: void 0
|
|
170
|
-
},
|
|
171
|
-
diagonal: {
|
|
172
|
-
type: Boolean,
|
|
173
|
-
default: void 0
|
|
174
|
-
},
|
|
175
|
-
grid: {
|
|
176
|
-
type: Object,
|
|
177
|
-
default: void 0
|
|
178
|
-
},
|
|
179
|
-
onDragStart: {
|
|
180
|
-
type: Function,
|
|
181
|
-
default: void 0
|
|
182
|
-
},
|
|
183
|
-
onDragEnd: {
|
|
184
|
-
type: Function,
|
|
185
|
-
default: void 0
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
emits: ["update:x", "update:y", "update:width", "update:height", "select"],
|
|
189
|
-
setup(props, { emit }) {
|
|
190
|
-
const active = ref2(false);
|
|
191
|
-
const SceneContext = inject(SceneToken, void 0);
|
|
192
|
-
const _preview = computed(() => SceneContext?.preview || props.preview);
|
|
193
|
-
const canScale = computed(() => !_preview.value && (SceneContext?.scale || props.scale));
|
|
194
|
-
const canMove = computed(() => !_preview.value && (SceneContext?.move || props.move));
|
|
195
|
-
const isAbsolute = computed(() => props.absolute ?? SceneContext?.absolute ?? true);
|
|
196
|
-
const handlerType = computed(() => props.handler ?? SceneContext?.handler ?? "dot");
|
|
197
|
-
const snapGrid = computed(() => props.grid ?? SceneContext?.grid);
|
|
198
|
-
const diagonal = computed(() => props.diagonal ?? SceneContext?.diagonal ?? true);
|
|
199
|
-
const widgetRef = shallowRef();
|
|
200
|
-
const _style = ref2({});
|
|
201
|
-
const wrapStyle = useNormalizeStyle(_style);
|
|
202
|
-
const uuid = uuidv4();
|
|
203
|
-
const isScale = ref2(false);
|
|
204
|
-
const isMove = ref2(false);
|
|
205
|
-
const _rect = reactive({});
|
|
206
|
-
const context = {
|
|
207
|
-
_rect,
|
|
208
|
-
trigger
|
|
209
|
-
};
|
|
210
|
-
onClickOutside(widgetRef, () => {
|
|
211
|
-
active.value = false;
|
|
212
|
-
});
|
|
213
|
-
let rectSize = reactive(useElementSize(widgetRef));
|
|
214
|
-
let autoWidth = true;
|
|
215
|
-
let autoHeight = true;
|
|
216
|
-
const unwatch = watch2(rectSize, ({ width, height }) => {
|
|
217
|
-
if (autoWidth && width) {
|
|
218
|
-
_rect.width = width;
|
|
219
|
-
}
|
|
220
|
-
if (autoHeight && height) {
|
|
221
|
-
_rect.height = height;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
watch2(
|
|
225
|
-
[
|
|
226
|
-
() => props.width,
|
|
227
|
-
() => props.height,
|
|
228
|
-
() => props.x,
|
|
229
|
-
() => props.y
|
|
230
|
-
],
|
|
231
|
-
([width, height, x, y]) => {
|
|
232
|
-
autoWidth = width === _rect.width;
|
|
233
|
-
autoHeight = height === _rect.height;
|
|
234
|
-
if (!autoHeight && !autoWidth) {
|
|
235
|
-
unwatch();
|
|
236
|
-
rectSize = null;
|
|
237
|
-
}
|
|
238
|
-
width && (_rect.width = width);
|
|
239
|
-
height && (_rect.height = height);
|
|
240
|
-
x != null && (_rect.x = x);
|
|
241
|
-
y != null && (_rect.y = y);
|
|
242
|
-
trigger();
|
|
243
|
-
},
|
|
244
|
-
{ immediate: true }
|
|
245
|
-
);
|
|
246
|
-
onMounted(async () => {
|
|
247
|
-
SceneContext?.register(uuid, context);
|
|
248
|
-
const { offsetTop, offsetLeft } = widgetRef.value;
|
|
249
|
-
_rect.x = _rect.x == null ? offsetLeft : _rect.x;
|
|
250
|
-
_rect.y = _rect.y == null ? offsetTop : _rect.y;
|
|
251
|
-
trigger();
|
|
252
|
-
});
|
|
253
|
-
function trigger() {
|
|
254
|
-
const { x, y, width, height } = _rect;
|
|
255
|
-
_style.value = {
|
|
256
|
-
transform: `translate(${x}px, ${y}px)`,
|
|
257
|
-
width,
|
|
258
|
-
height
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
const _dots = computed(() => {
|
|
262
|
-
return SceneContext && Array.isArray(SceneContext.scale) ? SceneContext.scale : props.scale;
|
|
263
|
-
});
|
|
264
|
-
const dots = computed(() => {
|
|
265
|
-
if (!isActive.value)
|
|
266
|
-
return [];
|
|
267
|
-
return Array.isArray(_dots.value) ? _dots.value : Dots;
|
|
268
|
-
});
|
|
269
|
-
const direct = {
|
|
270
|
-
l: "w",
|
|
271
|
-
r: "e",
|
|
272
|
-
t: "n",
|
|
273
|
-
b: "s"
|
|
274
|
-
};
|
|
275
|
-
const isActive = shallowRef(true);
|
|
276
|
-
function onMousedownDot(evt, dot) {
|
|
277
|
-
evt.stopPropagation();
|
|
278
|
-
evt.preventDefault();
|
|
279
|
-
if (isMove.value)
|
|
280
|
-
return;
|
|
281
|
-
isScale.value = true;
|
|
282
|
-
active.value = true;
|
|
283
|
-
const shouldUpdate = props.onDragStart?.();
|
|
284
|
-
if (shouldUpdate === false)
|
|
285
|
-
return;
|
|
286
|
-
const { clientX, clientY } = evt;
|
|
287
|
-
useResize(clientX, clientY, _rect, dot, diagonal.value, snapGrid.value, {
|
|
288
|
-
onMove() {
|
|
289
|
-
if (!checkValid(_rect))
|
|
290
|
-
return;
|
|
291
|
-
EventBus.emit("move", uuid);
|
|
292
|
-
trigger();
|
|
293
|
-
},
|
|
294
|
-
onUp() {
|
|
295
|
-
props.onDragEnd?.();
|
|
296
|
-
isScale.value = false;
|
|
297
|
-
EventBus.emit("moveup", uuid);
|
|
298
|
-
emitPos();
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
function emitPos() {
|
|
303
|
-
emit("update:x", _rect.x);
|
|
304
|
-
emit("update:y", _rect.y);
|
|
305
|
-
emit("update:width", _rect.width);
|
|
306
|
-
emit("update:height", _rect.height);
|
|
307
|
-
}
|
|
308
|
-
function getDotPos(dot) {
|
|
309
|
-
const { width, height } = _rect;
|
|
310
|
-
const isL = /l/.test(dot);
|
|
311
|
-
const isR = /r/.test(dot);
|
|
312
|
-
const isT = /t/.test(dot);
|
|
313
|
-
let left, top;
|
|
314
|
-
if (dot.length === 2) {
|
|
315
|
-
left = isL ? 0 : width;
|
|
316
|
-
top = isT ? 0 : height;
|
|
317
|
-
} else {
|
|
318
|
-
if (isL || isR) {
|
|
319
|
-
left = isL ? 0 : width;
|
|
320
|
-
top = Number(height) / 2;
|
|
321
|
-
} else {
|
|
322
|
-
left = Number(width) / 2;
|
|
323
|
-
top = isT ? 0 : height;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return {
|
|
327
|
-
top: `${handlerType.value === "dot" ? top : top - 3}px`,
|
|
328
|
-
left: `${handlerType.value === "dot" ? left : left - 3}px`,
|
|
329
|
-
cursor: dot.split("").reverse().map((item) => direct[item]).join("") + "-resize"
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
function onMousedown(evt) {
|
|
333
|
-
evt.stopPropagation();
|
|
334
|
-
if (isScale.value || !canMove.value)
|
|
335
|
-
return;
|
|
336
|
-
isMove.value = true;
|
|
337
|
-
active.value = true;
|
|
338
|
-
const shouldUpdate = props.onDragStart?.();
|
|
339
|
-
if (shouldUpdate === false)
|
|
340
|
-
return;
|
|
341
|
-
const pos = { ..._rect };
|
|
342
|
-
const move = (mouseEvt) => {
|
|
343
|
-
const { clientX, clientY } = mouseEvt;
|
|
344
|
-
const x = clientX - evt.clientX + pos.x;
|
|
345
|
-
const y = clientY - evt.clientY + pos.y;
|
|
346
|
-
_rect.x = x;
|
|
347
|
-
_rect.y = y;
|
|
348
|
-
_rect.width = pos.width;
|
|
349
|
-
_rect.height = pos.height;
|
|
350
|
-
if (!checkValid(_rect))
|
|
351
|
-
return;
|
|
352
|
-
EventBus.emit("move", uuid);
|
|
353
|
-
trigger();
|
|
354
|
-
};
|
|
355
|
-
const up = () => {
|
|
356
|
-
props.onDragEnd?.();
|
|
357
|
-
isMove.value = false;
|
|
358
|
-
EventBus.emit("moveup", uuid);
|
|
359
|
-
document.removeEventListener("mousemove", move);
|
|
360
|
-
document.removeEventListener("mouseup", up);
|
|
361
|
-
emitPos();
|
|
362
|
-
emit("select", _rect);
|
|
363
|
-
};
|
|
364
|
-
document.addEventListener("mousemove", move);
|
|
365
|
-
document.addEventListener("mouseup", up);
|
|
366
|
-
}
|
|
367
|
-
function checkValid(rect) {
|
|
368
|
-
if (SceneContext) {
|
|
369
|
-
return SceneContext.checkValid(rect);
|
|
370
|
-
} else if (props.limitWidth && props.limitHeight) {
|
|
371
|
-
const { x, y, width, height } = rect;
|
|
372
|
-
return x >= 0 && x + width <= props.limitWidth && y >= 0 && y + height <= props.limitHeight;
|
|
373
|
-
} else {
|
|
374
|
-
return true;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return {
|
|
378
|
-
widgetRef,
|
|
379
|
-
canMove,
|
|
380
|
-
wrapStyle,
|
|
381
|
-
canScale,
|
|
382
|
-
dots,
|
|
383
|
-
active,
|
|
384
|
-
isAbsolute,
|
|
385
|
-
isScale,
|
|
386
|
-
handlerType,
|
|
387
|
-
getDotPos,
|
|
388
|
-
onMousedown,
|
|
389
|
-
onMousedownDot
|
|
390
|
-
};
|
|
391
|
-
},
|
|
392
|
-
render() {
|
|
393
|
-
const dots = this.canScale ? this.dots.map((dot) => {
|
|
394
|
-
if (isVue2) {
|
|
395
|
-
return h("div", {
|
|
396
|
-
class: "free-dom__widget-dot",
|
|
397
|
-
style: this.getDotPos(dot),
|
|
398
|
-
on: {
|
|
399
|
-
mousedown: (evt) => this.onMousedownDot(evt, dot)
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
return h("div", {
|
|
404
|
-
class: this.handlerType === "dot" ? "free-dom__widget-dot" : "free-dom__resizable-handler",
|
|
405
|
-
style: this.getDotPos(dot),
|
|
406
|
-
onMousedown: (evt) => this.onMousedownDot(evt, dot)
|
|
407
|
-
});
|
|
408
|
-
}) : null;
|
|
409
|
-
const defaultSlot = typeof this.$slots.default === "function" ? this.$slots.default() : this.$slots.default;
|
|
410
|
-
if (isVue2) {
|
|
411
|
-
return h(
|
|
412
|
-
"section",
|
|
413
|
-
{
|
|
414
|
-
class: [
|
|
415
|
-
"free-dom__widget-wrapper",
|
|
416
|
-
{ "is-scale": this.isScale },
|
|
417
|
-
{ "is-absolute": this.isAbsolute },
|
|
418
|
-
{ "can-move": this.canMove },
|
|
419
|
-
{ "is-active": this.active }
|
|
420
|
-
],
|
|
421
|
-
style: this.wrapStyle,
|
|
422
|
-
ref: "widgetRef",
|
|
423
|
-
on: {
|
|
424
|
-
mousedown: this.onMousedown
|
|
425
|
-
}
|
|
426
|
-
},
|
|
427
|
-
[dots, defaultSlot]
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
return h(
|
|
431
|
-
"section",
|
|
432
|
-
{
|
|
433
|
-
ref: "widgetRef",
|
|
434
|
-
class: [
|
|
435
|
-
"free-dom__widget-wrapper",
|
|
436
|
-
{ "is-scale": this.isScale },
|
|
437
|
-
{ "is-absolute": this.isAbsolute },
|
|
438
|
-
{ "can-move": this.canMove },
|
|
439
|
-
{ "is-active": this.active }
|
|
440
|
-
],
|
|
441
|
-
style: this.wrapStyle,
|
|
442
|
-
onMousedown: this.onMousedown
|
|
443
|
-
},
|
|
444
|
-
[defaultSlot, dots]
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
// src/components/freeDomWrap.ts
|
|
450
|
-
import { defineComponent as defineComponent3, shallowRef as shallowRef3, h as h3, provide, reactive as reactive3, ref as ref4, toRefs } from "vue-demi";
|
|
451
|
-
import { useElementBounding } from "@vueuse/core";
|
|
38
|
+
// src/util/index.ts
|
|
39
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
40
|
+
function clamp(value, min, max = Infinity) {
|
|
41
|
+
return Math.max(Math.min(value, max), min);
|
|
42
|
+
}
|
|
43
|
+
function log(...args) {
|
|
44
|
+
if (isProduction)
|
|
45
|
+
return;
|
|
46
|
+
console.log("[grid-layout]", ...args);
|
|
47
|
+
}
|
|
452
48
|
|
|
453
49
|
// src/components/markLine.ts
|
|
454
|
-
import { h as h2,
|
|
50
|
+
import { defineComponent, h as h2, inject, onBeforeUnmount, reactive, ref, shallowRef } from "vue-demi";
|
|
455
51
|
var lineType = ["xt", "xc", "xb", "yl", "yc", "yr"];
|
|
456
|
-
var markLine_default =
|
|
52
|
+
var markLine_default = defineComponent({
|
|
53
|
+
props: {
|
|
54
|
+
showLine: Boolean
|
|
55
|
+
},
|
|
457
56
|
setup() {
|
|
458
|
-
const SceneContext =
|
|
459
|
-
const lines =
|
|
460
|
-
const diff =
|
|
57
|
+
const SceneContext = inject(SceneToken);
|
|
58
|
+
const lines = shallowRef(lineType);
|
|
59
|
+
const diff = ref(SceneContext.diff);
|
|
461
60
|
const nodes = SceneContext.nodes;
|
|
462
|
-
const lineStatus =
|
|
61
|
+
const lineStatus = reactive({
|
|
463
62
|
xt: {
|
|
464
63
|
show: false,
|
|
465
64
|
pos: 0
|
|
@@ -485,7 +84,7 @@ var markLine_default = defineComponent2({
|
|
|
485
84
|
pos: 0
|
|
486
85
|
}
|
|
487
86
|
});
|
|
488
|
-
|
|
87
|
+
const runConstraints = (uuid) => {
|
|
489
88
|
const current = nodes.find((node) => node.uuid === uuid)?.node ?? {};
|
|
490
89
|
clearStatus();
|
|
491
90
|
nodes.forEach((node) => {
|
|
@@ -564,11 +163,12 @@ var markLine_default = defineComponent2({
|
|
|
564
163
|
current._rect.x = _target.right - _current.width;
|
|
565
164
|
}
|
|
566
165
|
});
|
|
567
|
-
}
|
|
568
|
-
|
|
166
|
+
};
|
|
167
|
+
SceneContext?.on("move", runConstraints);
|
|
168
|
+
SceneContext?.on("moveup", clearStatus);
|
|
569
169
|
onBeforeUnmount(() => {
|
|
570
|
-
|
|
571
|
-
|
|
170
|
+
SceneContext?.off("move");
|
|
171
|
+
SceneContext?.off("moveup");
|
|
572
172
|
});
|
|
573
173
|
function clearStatus() {
|
|
574
174
|
lineStatus.xt.show = false;
|
|
@@ -580,6 +180,8 @@ var markLine_default = defineComponent2({
|
|
|
580
180
|
}
|
|
581
181
|
function normalize(rect) {
|
|
582
182
|
return {
|
|
183
|
+
deltaX: rect.deltaX,
|
|
184
|
+
deltaY: rect.deltaY,
|
|
583
185
|
top: rect.y,
|
|
584
186
|
bottom: rect.y + rect.height,
|
|
585
187
|
left: rect.x,
|
|
@@ -602,80 +204,1521 @@ var markLine_default = defineComponent2({
|
|
|
602
204
|
render() {
|
|
603
205
|
const _line = (line, info) => h2("div", {
|
|
604
206
|
style: { [line.includes("x") ? "top" : "left"]: info.pos + "px" },
|
|
605
|
-
class: [line.includes("x") ? "free-
|
|
207
|
+
class: [line.includes("x") ? "vv-free-dom--xline" : "vv-free-dom--yline", "vv-free-dom--line"]
|
|
606
208
|
});
|
|
607
|
-
const _lines = this.lines.filter((line) => this.lineStatus[line].show).map((line) => _line(line, this.lineStatus[line]));
|
|
209
|
+
const _lines = this.showLine ? this.lines.filter((line) => this.lineStatus[line].show).map((line) => _line(line, this.lineStatus[line])) : [];
|
|
608
210
|
return h2("div", {
|
|
609
|
-
class: "free-
|
|
211
|
+
class: "vv-free-dom--markline"
|
|
610
212
|
}, _lines);
|
|
611
213
|
}
|
|
612
214
|
});
|
|
613
215
|
|
|
614
|
-
// src/
|
|
615
|
-
|
|
616
|
-
|
|
216
|
+
// src/hooks/use-normalize-style.ts
|
|
217
|
+
import { ref as ref2, unref, watch } from "vue-demi";
|
|
218
|
+
|
|
219
|
+
// src/hooks/use-default-slot.ts
|
|
220
|
+
import { computed, useSlots } from "vue-demi";
|
|
221
|
+
function useDefaultSlot() {
|
|
222
|
+
const slots = useSlots();
|
|
223
|
+
const slotList = computed(() => {
|
|
224
|
+
return typeof slots.default === "function" ? slots.default() : slots.default;
|
|
225
|
+
});
|
|
226
|
+
const only = computed(() => slotList.value?.[0]);
|
|
227
|
+
return {
|
|
228
|
+
slots: slotList,
|
|
229
|
+
only
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/hooks/use-core-date.ts
|
|
234
|
+
import { ref as ref3, unref as unref2 } from "vue-demi";
|
|
235
|
+
function useCoreData(node) {
|
|
236
|
+
const lastX = ref3(NaN);
|
|
237
|
+
const lastY = ref3(NaN);
|
|
238
|
+
function create(x, y) {
|
|
239
|
+
const isStart = isNaN(lastX.value);
|
|
240
|
+
const _node = unref2(node);
|
|
241
|
+
if (!_node) {
|
|
242
|
+
throw new Error("drag node does not exist");
|
|
243
|
+
}
|
|
244
|
+
if (isStart) {
|
|
245
|
+
return {
|
|
246
|
+
node: _node,
|
|
247
|
+
deltaX: 0,
|
|
248
|
+
deltaY: 0,
|
|
249
|
+
lastX: x,
|
|
250
|
+
lastY: y,
|
|
251
|
+
x,
|
|
252
|
+
y
|
|
253
|
+
};
|
|
254
|
+
} else {
|
|
255
|
+
return {
|
|
256
|
+
node: _node,
|
|
257
|
+
deltaX: x - lastX.value,
|
|
258
|
+
deltaY: y - lastY.value,
|
|
259
|
+
lastX: lastX.value,
|
|
260
|
+
lastY: lastY.value,
|
|
261
|
+
x,
|
|
262
|
+
y
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
lastX,
|
|
268
|
+
lastY,
|
|
269
|
+
create
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/hooks/use-draggable-data.ts
|
|
274
|
+
import { ref as ref4, watchEffect } from "vue-demi";
|
|
275
|
+
function useDraggableData(props) {
|
|
276
|
+
const x = ref4(props.x || props.modelValue.x || 0);
|
|
277
|
+
const y = ref4(props.y || props.modelValue.y || 0);
|
|
278
|
+
const deltaX = ref4(0);
|
|
279
|
+
const deltaY = ref4(0);
|
|
280
|
+
const dragData = ref4();
|
|
281
|
+
watchEffect(() => {
|
|
282
|
+
x.value = props.x || props.modelValue.x || 0;
|
|
283
|
+
});
|
|
284
|
+
watchEffect(() => {
|
|
285
|
+
y.value = props.y || props.modelValue.y || 0;
|
|
286
|
+
});
|
|
287
|
+
const handleDrag = (evt, data) => {
|
|
288
|
+
x.value = data.x;
|
|
289
|
+
y.value = data.y;
|
|
290
|
+
deltaX.value = data.deltaX;
|
|
291
|
+
deltaY.value = data.deltaY;
|
|
292
|
+
props.dargFn(evt, data);
|
|
293
|
+
};
|
|
294
|
+
const handleDragStop = (evt, coreData) => {
|
|
295
|
+
const data = dragData.value = create(coreData);
|
|
296
|
+
props.dragStopFn(evt, data);
|
|
297
|
+
};
|
|
298
|
+
function create(coreData) {
|
|
299
|
+
return {
|
|
300
|
+
node: coreData.node,
|
|
301
|
+
x: x.value + coreData.deltaX,
|
|
302
|
+
y: y.value + coreData.deltaY,
|
|
303
|
+
deltaX: coreData.deltaX,
|
|
304
|
+
deltaY: coreData.deltaY,
|
|
305
|
+
lastX: x.value,
|
|
306
|
+
lastY: y.value
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
x,
|
|
311
|
+
y,
|
|
312
|
+
deltaX,
|
|
313
|
+
deltaY,
|
|
314
|
+
create,
|
|
315
|
+
handleDrag,
|
|
316
|
+
handleDragStop
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/hooks/use-scene-context.ts
|
|
321
|
+
import { computed as computed2, inject as inject2, onMounted } from "vue-demi";
|
|
322
|
+
var id = 0;
|
|
323
|
+
function useSceneContext(context, props) {
|
|
324
|
+
const SceneContext = inject2(SceneToken, void 0);
|
|
325
|
+
const uuid = id++;
|
|
326
|
+
const lockAspectRatio = computed2(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
|
|
327
|
+
const minWidth = computed2(() => SceneContext?.minWidth || props.minWidth);
|
|
328
|
+
const minHeight = computed2(() => SceneContext?.minHeight || props.minHeight);
|
|
329
|
+
const disabledDrag = computed2(() => SceneContext?.disabledDrag || props.disabledDrag);
|
|
330
|
+
const disabledResize = computed2(() => SceneContext?.disabledResize || props.disabledResize);
|
|
331
|
+
const scale = computed2(() => SceneContext?.scale || props.scale);
|
|
332
|
+
const fixNonMonospaced = computed2(() => {
|
|
333
|
+
return SceneContext?.fixNonMonospaced || props.fixNonMonospaced;
|
|
334
|
+
});
|
|
335
|
+
onMounted(() => {
|
|
336
|
+
SceneContext?.register(uuid, context);
|
|
337
|
+
});
|
|
338
|
+
function check(pos) {
|
|
339
|
+
if (!SceneContext)
|
|
340
|
+
return true;
|
|
341
|
+
return SceneContext.checkValid(pos);
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
emit: (name) => SceneContext?.emit(name, uuid),
|
|
345
|
+
check,
|
|
346
|
+
width: SceneContext?.width,
|
|
347
|
+
height: SceneContext?.height,
|
|
348
|
+
scale,
|
|
349
|
+
lockAspectRatio,
|
|
350
|
+
minWidth,
|
|
351
|
+
minHeight,
|
|
352
|
+
disabledDrag,
|
|
353
|
+
disabledResize,
|
|
354
|
+
fixNonMonospaced
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/hooks/use-event-bus.ts
|
|
359
|
+
import { ref as ref5 } from "vue-demi";
|
|
360
|
+
function useEventBus() {
|
|
361
|
+
const callbacks = ref5({});
|
|
362
|
+
const on = (name, cb) => {
|
|
363
|
+
if (!callbacks.value[name]) {
|
|
364
|
+
callbacks.value[name] = [cb];
|
|
365
|
+
} else {
|
|
366
|
+
callbacks.value[name].push(cb);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
const off = (name) => {
|
|
370
|
+
callbacks.value[name].length = 0;
|
|
371
|
+
};
|
|
372
|
+
const emit = (name, args) => {
|
|
373
|
+
const fns = callbacks.value[name] || [];
|
|
374
|
+
fns.forEach((fn) => fn(args));
|
|
375
|
+
};
|
|
376
|
+
return {
|
|
377
|
+
on,
|
|
378
|
+
off,
|
|
379
|
+
emit
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/hooks/use-resizable-data.ts
|
|
384
|
+
import { ref as ref6, watchEffect as watchEffect2 } from "vue-demi";
|
|
385
|
+
function useResizableData(props, domRef) {
|
|
386
|
+
const width = ref6(getWidth());
|
|
387
|
+
const height = ref6(getHeight());
|
|
388
|
+
watchEffect2(() => {
|
|
389
|
+
width.value = getWidth();
|
|
390
|
+
});
|
|
391
|
+
watchEffect2(() => {
|
|
392
|
+
height.value = getHeight();
|
|
393
|
+
});
|
|
394
|
+
function getWidth() {
|
|
395
|
+
return props.width || props.modelValue.w;
|
|
396
|
+
}
|
|
397
|
+
function getHeight() {
|
|
398
|
+
return props.height || props.modelValue.h;
|
|
399
|
+
}
|
|
400
|
+
async function syncSize(fixNonMonospaced, minWidth, minHeight) {
|
|
401
|
+
if (props.width && props.height || props.modelValue.w && props.modelValue.h)
|
|
402
|
+
return;
|
|
403
|
+
if (!domRef.value)
|
|
404
|
+
return [0, 0];
|
|
405
|
+
if (fixNonMonospaced) {
|
|
406
|
+
await document.fonts.ready;
|
|
407
|
+
}
|
|
408
|
+
const { width: w, height: h5 } = window.getComputedStyle(domRef.value.$el);
|
|
409
|
+
width.value = Math.max(Math.ceil(parseFloat(w)), minWidth);
|
|
410
|
+
height.value = Math.max(Math.ceil(parseFloat(h5)), minHeight);
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
width,
|
|
414
|
+
height,
|
|
415
|
+
syncSize
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/hooks/use-layout.ts
|
|
420
|
+
import { computed as computed3, ref as ref7, shallowRef as shallowRef2, watchEffect as watchEffect3 } from "vue-demi";
|
|
421
|
+
function useLayout(props) {
|
|
422
|
+
const layout = shallowRef2(props.modelValue);
|
|
423
|
+
watchEffect3(() => {
|
|
424
|
+
layout.value = props.modelValue;
|
|
425
|
+
});
|
|
426
|
+
const cellWidth = computed3(
|
|
427
|
+
() => (props.width - margin.value[0] * (cols.value - 1) - (containerPadding.value?.[0] || margin.value[0]) * 2) / props.cols
|
|
428
|
+
);
|
|
429
|
+
const cols = computed3(() => props.cols);
|
|
430
|
+
const rowHeight = computed3(() => props.rowHeight);
|
|
431
|
+
const margin = computed3(() => props.margin);
|
|
432
|
+
const maxRows = computed3(() => props.maxRows);
|
|
433
|
+
const containerPadding = computed3(() => props.containerPadding);
|
|
434
|
+
const minW = computed3(() => props.minW);
|
|
435
|
+
const minH = computed3(() => props.minH);
|
|
436
|
+
function getItem(key) {
|
|
437
|
+
return layout.value.find((item) => item.i === key);
|
|
438
|
+
}
|
|
439
|
+
function getFull() {
|
|
440
|
+
return layout.value;
|
|
441
|
+
}
|
|
442
|
+
function _moveElement(layout2, config, x, y, isUserAction, preventCollision) {
|
|
443
|
+
if (config.static)
|
|
444
|
+
return layout2;
|
|
445
|
+
if (config.y === y && config.x === x)
|
|
446
|
+
return layout2;
|
|
447
|
+
log(
|
|
448
|
+
`Moving element ${config.i} to [${String(x)},${String(y)}] from [${config.x},${config.y}]`
|
|
449
|
+
);
|
|
450
|
+
const oldX = config.x;
|
|
451
|
+
const oldY = config.y;
|
|
452
|
+
if (typeof x === "number")
|
|
453
|
+
config.x = x;
|
|
454
|
+
if (typeof y === "number")
|
|
455
|
+
config.y = y;
|
|
456
|
+
config.moved = true;
|
|
457
|
+
const sortable = _sortLayoutItems(layout2);
|
|
458
|
+
const collisions = sortable.filter((l) => _collides(l, config));
|
|
459
|
+
const hasCollsions = collisions.length > 0;
|
|
460
|
+
if (hasCollsions && preventCollision) {
|
|
461
|
+
config.x = oldX;
|
|
462
|
+
config.y = oldY;
|
|
463
|
+
config.moved = false;
|
|
464
|
+
return layout2;
|
|
465
|
+
}
|
|
466
|
+
collisions.forEach((collision) => {
|
|
467
|
+
log(
|
|
468
|
+
`Resolving collision between ${config.i} at [${config.x},${config.y}] and ${collision.i} at [${collision.x},${collision.y}]`,
|
|
469
|
+
collision.moved,
|
|
470
|
+
collision.i
|
|
471
|
+
);
|
|
472
|
+
if (collision.moved)
|
|
473
|
+
return;
|
|
474
|
+
if (collision.static) {
|
|
475
|
+
layout2 = _moveElementAwayFromCollision(
|
|
476
|
+
layout2,
|
|
477
|
+
collision,
|
|
478
|
+
config,
|
|
479
|
+
isUserAction
|
|
480
|
+
);
|
|
481
|
+
} else {
|
|
482
|
+
layout2 = _moveElementAwayFromCollision(
|
|
483
|
+
layout2,
|
|
484
|
+
config,
|
|
485
|
+
collision,
|
|
486
|
+
isUserAction
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
return layout2;
|
|
491
|
+
}
|
|
492
|
+
function _moveElementAwayFromCollision(layout2, collideWith, itemToMove, isUserAction) {
|
|
493
|
+
const preventCollision = collideWith.static;
|
|
494
|
+
if (isUserAction) {
|
|
495
|
+
isUserAction = false;
|
|
496
|
+
const fakeItem = {
|
|
497
|
+
x: itemToMove.x,
|
|
498
|
+
y: Math.max(collideWith.y - itemToMove.h, 0),
|
|
499
|
+
w: itemToMove.w,
|
|
500
|
+
h: itemToMove.h,
|
|
501
|
+
i: "-1"
|
|
502
|
+
};
|
|
503
|
+
if (!_getFirstCollision(layout2, fakeItem)) {
|
|
504
|
+
log(
|
|
505
|
+
`Doing reverse collision on ${itemToMove.i} up to [${fakeItem.x},${fakeItem.y}].`
|
|
506
|
+
);
|
|
507
|
+
return _moveElement(
|
|
508
|
+
layout2,
|
|
509
|
+
itemToMove,
|
|
510
|
+
void 0,
|
|
511
|
+
fakeItem.y,
|
|
512
|
+
isUserAction,
|
|
513
|
+
preventCollision
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return _moveElement(
|
|
518
|
+
layout2,
|
|
519
|
+
itemToMove,
|
|
520
|
+
void 0,
|
|
521
|
+
itemToMove.y + 1,
|
|
522
|
+
isUserAction,
|
|
523
|
+
preventCollision
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
function moveTo(item, x, y) {
|
|
527
|
+
const isUserAction = true;
|
|
528
|
+
const _layout = _moveElement(layout.value, item, x, y, isUserAction, !props.collision);
|
|
529
|
+
layout.value = _normalize(_layout);
|
|
530
|
+
return layout.value;
|
|
531
|
+
}
|
|
532
|
+
function resizeTo(item, w, h5) {
|
|
533
|
+
let hasCollisions = false;
|
|
534
|
+
if (!props.collision) {
|
|
535
|
+
const collisions = layout.value.filter((l) => _collides(l, { ...item, w, h: h5 }));
|
|
536
|
+
hasCollisions = collisions.length > 0;
|
|
537
|
+
if (hasCollisions) {
|
|
538
|
+
let leastX = Infinity;
|
|
539
|
+
let leastY = Infinity;
|
|
540
|
+
collisions.forEach((collision) => {
|
|
541
|
+
if (collision.x > item.x)
|
|
542
|
+
leastX = Math.min(collision.x, leastX);
|
|
543
|
+
if (collision.y > item.y)
|
|
544
|
+
leastY = Math.min(collision.y, leastY);
|
|
545
|
+
});
|
|
546
|
+
if (Number.isFinite(leastX))
|
|
547
|
+
item.w = leastX - item.x;
|
|
548
|
+
if (Number.isFinite(leastY))
|
|
549
|
+
item.h = leastY - item.y;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (!hasCollisions) {
|
|
553
|
+
item.w = w;
|
|
554
|
+
item.h = h5;
|
|
555
|
+
}
|
|
556
|
+
layout.value = _normalize([...layout.value]);
|
|
557
|
+
}
|
|
558
|
+
function _sortLayoutItems(layout2) {
|
|
559
|
+
return layout2.slice(0).sort((a, b) => {
|
|
560
|
+
if (a.y > b.y || a.y === b.y && a.x > b.x) {
|
|
561
|
+
return 1;
|
|
562
|
+
} else if (a.y === b.y && a.x === b.x) {
|
|
563
|
+
return 0;
|
|
564
|
+
} else {
|
|
565
|
+
return -1;
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
function _collides(l1, l2) {
|
|
570
|
+
if (l1.i === l2.i)
|
|
571
|
+
return false;
|
|
572
|
+
else if (l1.x + l1.w <= l2.x)
|
|
573
|
+
return false;
|
|
574
|
+
else if (l1.x >= l2.x + l2.w)
|
|
575
|
+
return false;
|
|
576
|
+
else if (l1.y + l1.h <= l2.y)
|
|
577
|
+
return false;
|
|
578
|
+
else if (l1.y >= l2.y + l2.h)
|
|
579
|
+
return false;
|
|
580
|
+
else
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
function _getFirstCollision(layout2, layoutItem) {
|
|
584
|
+
for (let i = 0; i < layout2.length; ++i) {
|
|
585
|
+
if (_collides(layout2[i], layoutItem))
|
|
586
|
+
return layout2[i];
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function _normalize(layout2) {
|
|
590
|
+
const compareWith = layout2.filter((item) => item.static);
|
|
591
|
+
const sorted = _sortLayoutItems(layout2);
|
|
592
|
+
const _layout = new Array(layout2.length);
|
|
593
|
+
sorted.forEach((item, index) => {
|
|
594
|
+
let l = JSON.parse(JSON.stringify(item));
|
|
595
|
+
if (!l.static) {
|
|
596
|
+
l = _normalizeItem(compareWith, l, sorted);
|
|
597
|
+
compareWith.push(l);
|
|
598
|
+
}
|
|
599
|
+
_layout[layout2.indexOf(sorted[index])] = l;
|
|
600
|
+
l.moved = false;
|
|
601
|
+
});
|
|
602
|
+
return _layout;
|
|
603
|
+
}
|
|
604
|
+
function _normalizeItem(compareWith, l, layout2) {
|
|
605
|
+
if (props.collision) {
|
|
606
|
+
l.y = Math.min(_calBottom(compareWith), l.y);
|
|
607
|
+
while (l.y > 0 && !_getFirstCollision(compareWith, l)) {
|
|
608
|
+
--l.y;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
let collides;
|
|
612
|
+
while ((collides = _getFirstCollision(compareWith, l)) && props.collision) {
|
|
613
|
+
resolveCompactionCollision(layout2, l, collides.y + collides.h, "y");
|
|
614
|
+
}
|
|
615
|
+
return l;
|
|
616
|
+
}
|
|
617
|
+
function _calBottom(layout2) {
|
|
618
|
+
let max = 0;
|
|
619
|
+
layout2.forEach((l) => {
|
|
620
|
+
const val = l.y + l.h;
|
|
621
|
+
if (val > max)
|
|
622
|
+
max = val;
|
|
623
|
+
});
|
|
624
|
+
return max;
|
|
625
|
+
}
|
|
626
|
+
function calContainerHeight() {
|
|
627
|
+
if (!props.autoHeight)
|
|
628
|
+
return;
|
|
629
|
+
const rows = _calBottom(layout.value);
|
|
630
|
+
return `${rows * props.rowHeight + margin.value[1] * (rows - 1) + (containerPadding.value?.[1] || margin.value[1]) * 2}px`;
|
|
631
|
+
}
|
|
632
|
+
const heightWidth = { x: "w", y: "h" };
|
|
633
|
+
function resolveCompactionCollision(layout2, item, position, axis) {
|
|
634
|
+
const sizeProp = heightWidth[axis];
|
|
635
|
+
item[axis] += 1;
|
|
636
|
+
const itemIndex = layout2.findIndex((each) => each === item);
|
|
637
|
+
for (let i = itemIndex + 1; i < layout2.length; ++i) {
|
|
638
|
+
const otherItem = layout2[i];
|
|
639
|
+
if (otherItem.y > item.y + item.h)
|
|
640
|
+
break;
|
|
641
|
+
if (_collides(item, otherItem)) {
|
|
642
|
+
resolveCompactionCollision(
|
|
643
|
+
layout2,
|
|
644
|
+
otherItem,
|
|
645
|
+
position + item[sizeProp],
|
|
646
|
+
axis
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
item[axis] = position;
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
cellWidth,
|
|
654
|
+
cols,
|
|
655
|
+
rowHeight,
|
|
656
|
+
margin,
|
|
657
|
+
maxRows,
|
|
658
|
+
containerPadding,
|
|
659
|
+
minW,
|
|
660
|
+
minH,
|
|
661
|
+
calContainerHeight,
|
|
662
|
+
moveTo,
|
|
663
|
+
resizeTo,
|
|
664
|
+
getItem,
|
|
665
|
+
getFull
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function useLayoutItem(props, layout) {
|
|
669
|
+
const { cellWidth, margin, rowHeight, cols, maxRows, containerPadding: cPadding } = layout;
|
|
670
|
+
const dragging = ref7();
|
|
671
|
+
const resizing = ref7();
|
|
672
|
+
const containerPadding = computed3(() => cPadding.value || margin.value);
|
|
673
|
+
const x = computed3(() => {
|
|
674
|
+
if (!dragging.value) {
|
|
675
|
+
return Math.round(props.x * (cellWidth.value + margin.value[0]) + containerPadding.value[0]);
|
|
676
|
+
} else {
|
|
677
|
+
return Math.round(dragging.value.x);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
const y = computed3(() => {
|
|
681
|
+
if (!dragging.value) {
|
|
682
|
+
return Math.round(props.y * (rowHeight.value + margin.value[1]) + containerPadding.value[1]);
|
|
683
|
+
} else {
|
|
684
|
+
return Math.round(dragging.value.y);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
const width = computed3(() => {
|
|
688
|
+
if (!resizing.value) {
|
|
689
|
+
return Math.round(cellWidth.value * props.width + Math.max(0, props.width - 1) * margin.value[0]);
|
|
690
|
+
} else {
|
|
691
|
+
return Math.round(resizing.value.width);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
const height = computed3(() => {
|
|
695
|
+
if (!resizing.value) {
|
|
696
|
+
return Math.round(rowHeight.value * props.height + Math.max(0, props.height - 1) * margin.value[1]);
|
|
697
|
+
} else {
|
|
698
|
+
return Math.round(resizing.value.height);
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
const minWidth = computed3(() => {
|
|
702
|
+
const minW = layout.minW.value;
|
|
703
|
+
return Math.round(cellWidth.value * minW + Math.max(0, minW - 1) * margin.value[0]);
|
|
704
|
+
});
|
|
705
|
+
const minHeight = computed3(() => {
|
|
706
|
+
const minH = layout.minH.value;
|
|
707
|
+
return Math.round(rowHeight.value * minH + Math.max(0, minH - 1) * margin.value[1]);
|
|
708
|
+
});
|
|
709
|
+
const style = computed3(() => {
|
|
710
|
+
return {
|
|
711
|
+
position: "absolute",
|
|
712
|
+
width: `${width.value}px`,
|
|
713
|
+
height: `${height.value}px`,
|
|
714
|
+
transform: `translate(${x.value}px, ${y.value}px)`
|
|
715
|
+
};
|
|
716
|
+
});
|
|
717
|
+
const onDragStart = (evt, { node }) => {
|
|
718
|
+
const parentRect = node.offsetParent.getBoundingClientRect();
|
|
719
|
+
const clientRect = node.getBoundingClientRect();
|
|
720
|
+
dragging.value = {
|
|
721
|
+
x: clientRect.left - parentRect.left + node.offsetParent.scrollLeft,
|
|
722
|
+
y: clientRect.top - parentRect.top + node.offsetParent.scrollTop
|
|
723
|
+
};
|
|
724
|
+
};
|
|
725
|
+
const onDrag = (evt, coreData) => {
|
|
726
|
+
if (!dragging.value) {
|
|
727
|
+
throw new Error("onDrag called before onDragStart");
|
|
728
|
+
}
|
|
729
|
+
const { deltaX, deltaY } = coreData;
|
|
730
|
+
const dragX = dragging.value.x + deltaX;
|
|
731
|
+
const dragY = dragging.value.y + deltaY;
|
|
732
|
+
dragging.value = { x: dragX, y: dragY };
|
|
733
|
+
const { x: x2, y: y2 } = _calcXY(dragX, dragY);
|
|
734
|
+
props.dragFn(evt, { x: x2, y: y2 });
|
|
735
|
+
};
|
|
736
|
+
const onDragStop = (evt) => {
|
|
737
|
+
if (!dragging.value) {
|
|
738
|
+
throw new Error("onDragStop called before onDratStart");
|
|
739
|
+
}
|
|
740
|
+
const { x: _x, y: _y } = dragging.value;
|
|
741
|
+
const { x: x2, y: y2 } = _calcXY(_x, _y);
|
|
742
|
+
dragging.value = void 0;
|
|
743
|
+
props.dragEndFn(evt, { x: x2, y: y2 });
|
|
744
|
+
};
|
|
745
|
+
const onResizeStart = (evt, { width: width2, height: height2 }) => {
|
|
746
|
+
resizing.value = { width: width2, height: height2 };
|
|
747
|
+
};
|
|
748
|
+
const onResize = (evt, coreData) => {
|
|
749
|
+
const { width: width2, height: height2 } = coreData;
|
|
750
|
+
const { w, h: h5 } = _calcWH(width2, height2);
|
|
751
|
+
resizing.value = { width: width2, height: height2 };
|
|
752
|
+
props.resizeFn(evt, { w, h: h5 });
|
|
753
|
+
};
|
|
754
|
+
const onResizeStop = (evt, coreData) => {
|
|
755
|
+
resizing.value = void 0;
|
|
756
|
+
const { width: width2, height: height2 } = coreData;
|
|
757
|
+
const { w, h: h5 } = _calcWH(width2, height2);
|
|
758
|
+
props.resizeStopFn(evt, { w, h: h5 });
|
|
759
|
+
};
|
|
760
|
+
function _calcXY(left, top) {
|
|
761
|
+
let x2 = Math.round((left - margin.value[0]) / (cellWidth.value + margin.value[0]));
|
|
762
|
+
let y2 = Math.round((top - margin.value[1]) / (rowHeight.value + margin.value[1]));
|
|
763
|
+
x2 = clamp(x2, 0, cols.value - props.width);
|
|
764
|
+
y2 = clamp(y2, 0, maxRows.value - props.height);
|
|
765
|
+
return { x: x2, y: y2 };
|
|
766
|
+
}
|
|
767
|
+
function _calcWH(width2, height2) {
|
|
768
|
+
let w = Math.round((width2 + margin.value[0]) / (cellWidth.value + margin.value[0]));
|
|
769
|
+
let h5 = Math.round((height2 + margin.value[1]) / (rowHeight.value + margin.value[1]));
|
|
770
|
+
w = clamp(w, 0, cols.value - props.x);
|
|
771
|
+
h5 = clamp(h5, 0, maxRows.value - props.y);
|
|
772
|
+
return { w, h: h5 };
|
|
773
|
+
}
|
|
774
|
+
return {
|
|
775
|
+
x,
|
|
776
|
+
y,
|
|
777
|
+
width,
|
|
778
|
+
height,
|
|
779
|
+
dragging,
|
|
780
|
+
resizing,
|
|
781
|
+
style,
|
|
782
|
+
minWidth,
|
|
783
|
+
minHeight,
|
|
784
|
+
onDragStart,
|
|
785
|
+
onDrag,
|
|
786
|
+
onDragStop,
|
|
787
|
+
onResizeStart,
|
|
788
|
+
onResize,
|
|
789
|
+
onResizeStop
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/components/freeDom.ts
|
|
794
|
+
import { computed as computed6, defineComponent as defineComponent4, onMounted as onMounted2, reactive as reactive2, ref as ref9 } from "vue-demi";
|
|
795
|
+
|
|
796
|
+
// src/components/freeDomCore.ts
|
|
797
|
+
import { computed as computed4, defineComponent as defineComponent2, isVue2 as isVue22, onUnmounted, ref as ref8 } from "vue-demi";
|
|
798
|
+
function noop() {
|
|
799
|
+
}
|
|
800
|
+
var freeDomCoreProps = {
|
|
801
|
+
userSelectHack: {
|
|
617
802
|
type: Boolean,
|
|
803
|
+
default: true
|
|
804
|
+
},
|
|
805
|
+
startFn: {
|
|
806
|
+
type: Function,
|
|
807
|
+
default: noop
|
|
808
|
+
},
|
|
809
|
+
stopFn: {
|
|
810
|
+
type: Function,
|
|
811
|
+
default: noop
|
|
812
|
+
},
|
|
813
|
+
dragFn: {
|
|
814
|
+
type: Function,
|
|
815
|
+
default: noop
|
|
816
|
+
},
|
|
817
|
+
disabled: Boolean
|
|
818
|
+
};
|
|
819
|
+
var freeDomCore = defineComponent2({
|
|
820
|
+
name: "FreeDomCore",
|
|
821
|
+
props: freeDomCoreProps,
|
|
822
|
+
setup(props) {
|
|
823
|
+
const { only } = useDefaultSlot();
|
|
824
|
+
const dragging = ref8(false);
|
|
825
|
+
const coreRef = ref8();
|
|
826
|
+
const node = computed4(() => coreRef.value?.$el || coreRef.value);
|
|
827
|
+
const ownerDoc = computed4(() => node.value?.ownerDocument);
|
|
828
|
+
const { lastX, lastY, create } = useCoreData(node);
|
|
829
|
+
let parentNode;
|
|
830
|
+
let parentRect;
|
|
831
|
+
onUnmounted(() => {
|
|
832
|
+
if (!ownerDoc.value)
|
|
833
|
+
return;
|
|
834
|
+
if (props.userSelectHack)
|
|
835
|
+
_removeUserSelectStyle(ownerDoc.value);
|
|
836
|
+
ownerDoc.value.removeEventListener("mousemove", _handleDrag);
|
|
837
|
+
ownerDoc.value.removeEventListener("mouseup", _handleDragStop);
|
|
838
|
+
});
|
|
839
|
+
function mousedownFn(evt) {
|
|
840
|
+
return _handleDragstart(evt);
|
|
841
|
+
}
|
|
842
|
+
function mouseupFn(evt) {
|
|
843
|
+
_handleDragStop(evt);
|
|
844
|
+
}
|
|
845
|
+
function _addUserSelectStyle(doc) {
|
|
846
|
+
if (!doc)
|
|
847
|
+
return;
|
|
848
|
+
if (!doc.getElementById("free-dom-style-el")) {
|
|
849
|
+
const styleEl = doc.createElement("style");
|
|
850
|
+
styleEl.id = "free-dom-style-el";
|
|
851
|
+
styleEl.innerHTML = ".free-dom-transparent-selection *::selection {all: inherit;}";
|
|
852
|
+
doc.getElementsByTagName("head")[0].appendChild(styleEl);
|
|
853
|
+
}
|
|
854
|
+
if (doc.body)
|
|
855
|
+
doc.body.classList.add("free-dom-transparent-selection");
|
|
856
|
+
}
|
|
857
|
+
function _removeUserSelectStyle(doc) {
|
|
858
|
+
if (!doc)
|
|
859
|
+
return;
|
|
860
|
+
if (doc.body) {
|
|
861
|
+
doc.body.classList.remove("free-dom-transparent-selection");
|
|
862
|
+
}
|
|
863
|
+
const selection = doc.getSelection();
|
|
864
|
+
if (selection) {
|
|
865
|
+
selection.removeAllRanges();
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
function _handleDragstart(evt) {
|
|
869
|
+
if (props.disabled || !evt.target || !(evt.target instanceof node.value.ownerDocument.defaultView.Node))
|
|
870
|
+
return;
|
|
871
|
+
const { x, y } = _offsetFormat(evt);
|
|
872
|
+
const coreEvent = create(x, y);
|
|
873
|
+
props.startFn(evt, coreEvent);
|
|
874
|
+
lastX.value = x;
|
|
875
|
+
lastY.value = y;
|
|
876
|
+
dragging.value = true;
|
|
877
|
+
if (props.userSelectHack)
|
|
878
|
+
_addUserSelectStyle(ownerDoc.value);
|
|
879
|
+
ownerDoc.value?.addEventListener("mousemove", _handleDrag);
|
|
880
|
+
ownerDoc.value?.addEventListener("mouseup", _handleDragStop);
|
|
881
|
+
}
|
|
882
|
+
function _handleDragStop(evt) {
|
|
883
|
+
if (!dragging.value)
|
|
884
|
+
return;
|
|
885
|
+
const { x, y } = _offsetFormat(evt);
|
|
886
|
+
const coreEvent = create(x, y);
|
|
887
|
+
props.stopFn(evt, coreEvent);
|
|
888
|
+
if (props.userSelectHack)
|
|
889
|
+
_removeUserSelectStyle(ownerDoc.value);
|
|
890
|
+
dragging.value = false;
|
|
891
|
+
lastX.value = NaN;
|
|
892
|
+
lastY.value = NaN;
|
|
893
|
+
ownerDoc.value?.removeEventListener("mousemove", _handleDrag);
|
|
894
|
+
ownerDoc.value?.removeEventListener("mouseup", _handleDragStop);
|
|
895
|
+
}
|
|
896
|
+
function _handleDrag(evt) {
|
|
897
|
+
const { x, y } = _offsetFormat(evt);
|
|
898
|
+
const coreEvent = create(x, y);
|
|
899
|
+
props.dragFn(evt, coreEvent);
|
|
900
|
+
lastX.value = x;
|
|
901
|
+
lastY.value = y;
|
|
902
|
+
}
|
|
903
|
+
function _offsetFormat(evt) {
|
|
904
|
+
const parent = node.value?.offsetParent || ownerDoc.value.body;
|
|
905
|
+
const isBody = parent === parent.ownerDocument.body;
|
|
906
|
+
if (!parentNode || parentNode !== parent) {
|
|
907
|
+
parentNode = parent;
|
|
908
|
+
parentRect = isBody ? { left: 0, top: 0 } : parent.getBoundingClientRect();
|
|
909
|
+
}
|
|
910
|
+
const x = evt.clientX + parent.scrollLeft - parentRect.left;
|
|
911
|
+
const y = evt.clientY + parent.scrollTop - parentRect.top;
|
|
912
|
+
return { x, y };
|
|
913
|
+
}
|
|
914
|
+
return {
|
|
915
|
+
only,
|
|
916
|
+
coreRef,
|
|
917
|
+
mousedownFn,
|
|
918
|
+
mouseupFn
|
|
919
|
+
};
|
|
920
|
+
},
|
|
921
|
+
render() {
|
|
922
|
+
const vue2Props = {
|
|
923
|
+
on: {
|
|
924
|
+
mousedown: (evt) => {
|
|
925
|
+
evt.stopPropagation();
|
|
926
|
+
this.mousedownFn(evt);
|
|
927
|
+
},
|
|
928
|
+
mouseup: this.mouseupFn
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
const vue3Props = {
|
|
932
|
+
onMousedown: (evt) => {
|
|
933
|
+
evt.stopPropagation();
|
|
934
|
+
this.mousedownFn(evt);
|
|
935
|
+
},
|
|
936
|
+
onMouseup: this.mouseupFn
|
|
937
|
+
};
|
|
938
|
+
const res = createRender(
|
|
939
|
+
// @ts-expect-error: maybe vue2
|
|
940
|
+
this.only,
|
|
941
|
+
{ ref: (el) => {
|
|
942
|
+
this.coreRef = el;
|
|
943
|
+
} },
|
|
944
|
+
isVue22 ? {} : vue3Props,
|
|
945
|
+
isVue22 ? vue2Props.on : {}
|
|
946
|
+
);
|
|
947
|
+
if (typeof res === "function") {
|
|
948
|
+
return res();
|
|
949
|
+
} else {
|
|
950
|
+
return res;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
var freeDomCore_default = freeDomCore;
|
|
955
|
+
|
|
956
|
+
// src/components/resizeDomCore.ts
|
|
957
|
+
import { computed as computed5, defineComponent as defineComponent3, h as h3, shallowRef as shallowRef3 } from "vue-demi";
|
|
958
|
+
var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
|
|
959
|
+
function noop2() {
|
|
960
|
+
}
|
|
961
|
+
var resizeDomCoreProps = {
|
|
962
|
+
dragOpts: {
|
|
963
|
+
type: Object,
|
|
964
|
+
default: () => ({})
|
|
965
|
+
},
|
|
966
|
+
width: {
|
|
967
|
+
type: Number,
|
|
968
|
+
default: 0
|
|
969
|
+
},
|
|
970
|
+
height: {
|
|
971
|
+
type: Number,
|
|
972
|
+
default: 0
|
|
973
|
+
},
|
|
974
|
+
scale: {
|
|
975
|
+
type: [Boolean, Array],
|
|
618
976
|
default: void 0
|
|
619
977
|
},
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
978
|
+
startFn: {
|
|
979
|
+
type: Function,
|
|
980
|
+
default: noop2
|
|
981
|
+
},
|
|
982
|
+
stopFn: {
|
|
983
|
+
type: Function,
|
|
984
|
+
default: noop2
|
|
985
|
+
},
|
|
986
|
+
resizeFn: {
|
|
987
|
+
type: Function,
|
|
988
|
+
default: noop2
|
|
989
|
+
},
|
|
990
|
+
minWidth: {
|
|
991
|
+
type: Number,
|
|
992
|
+
default: 50
|
|
993
|
+
},
|
|
994
|
+
minHeight: {
|
|
995
|
+
type: Number,
|
|
996
|
+
default: 50
|
|
997
|
+
},
|
|
998
|
+
lockAspectRatio: Boolean
|
|
999
|
+
};
|
|
1000
|
+
var resizeDomCore = defineComponent3({
|
|
1001
|
+
name: "ResizeDomCore",
|
|
1002
|
+
props: resizeDomCoreProps,
|
|
1003
|
+
setup(props, { slots }) {
|
|
1004
|
+
const { slots: _slots } = useDefaultSlot();
|
|
1005
|
+
const dots = computed5(() => {
|
|
1006
|
+
const _dots = props.scale;
|
|
1007
|
+
return Array.isArray(_dots) ? _dots : Dots;
|
|
1008
|
+
});
|
|
1009
|
+
const lastRect = shallowRef3();
|
|
1010
|
+
function runConstraints(width, height) {
|
|
1011
|
+
const { lockAspectRatio } = props;
|
|
1012
|
+
if (!props.minHeight && !props.minWidth && !lockAspectRatio)
|
|
1013
|
+
return [width, height];
|
|
1014
|
+
if (lockAspectRatio) {
|
|
1015
|
+
const ratio = props.width / props.height;
|
|
1016
|
+
const deltaW = width - props.width;
|
|
1017
|
+
const deltaH = height - props.height;
|
|
1018
|
+
if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
|
|
1019
|
+
height = width / ratio;
|
|
1020
|
+
} else {
|
|
1021
|
+
width = height * ratio;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
width = Math.max(width, props.minWidth);
|
|
1025
|
+
height = Math.max(height, props.minHeight);
|
|
1026
|
+
return [width, height];
|
|
1027
|
+
}
|
|
1028
|
+
function handleResize(handleName, axis) {
|
|
1029
|
+
return (evt, { node, deltaX, deltaY }) => {
|
|
1030
|
+
if (handleName === "start")
|
|
1031
|
+
lastRect.value = void 0;
|
|
1032
|
+
const canDragX = axis !== "t" && axis !== "b";
|
|
1033
|
+
const canDragY = axis !== "l" && axis !== "r";
|
|
1034
|
+
const axisH = axis[0];
|
|
1035
|
+
const axisV = axis[axis.length - 1];
|
|
1036
|
+
const handleRect = node.getBoundingClientRect();
|
|
1037
|
+
lastRect.value = handleRect;
|
|
1038
|
+
if (axisH === "l")
|
|
1039
|
+
deltaX = -deltaX;
|
|
1040
|
+
if (axisV === "t")
|
|
1041
|
+
deltaY = -deltaY;
|
|
1042
|
+
let width = props.width + (canDragX ? deltaX : 0);
|
|
1043
|
+
let height = props.height + (canDragY ? deltaY : 0);
|
|
1044
|
+
[width, height] = runConstraints(width, height);
|
|
1045
|
+
const sizeChanged = width !== props.width || height !== props.height;
|
|
1046
|
+
const fnName = `${handleName}Fn`;
|
|
1047
|
+
const cb = typeof props[fnName] === "function" ? props[fnName] : null;
|
|
1048
|
+
const shouldSkipCb = handleName === "resize" && !sizeChanged;
|
|
1049
|
+
if (cb && !shouldSkipCb) {
|
|
1050
|
+
cb(evt, { node, width, height, handle: axis });
|
|
1051
|
+
}
|
|
1052
|
+
if (handleName === "stop")
|
|
1053
|
+
lastRect.value = void 0;
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
function renderResizehandler(axis) {
|
|
1057
|
+
if (!slots.handler) {
|
|
1058
|
+
return () => h3("i", {
|
|
1059
|
+
class: [
|
|
1060
|
+
"vv-resize-dom--handler",
|
|
1061
|
+
`vv-resize-dom--handler__${axis}`
|
|
1062
|
+
]
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
return () => slots.handler?.(axis);
|
|
1066
|
+
}
|
|
1067
|
+
return {
|
|
1068
|
+
dots,
|
|
1069
|
+
children: _slots,
|
|
1070
|
+
handleResize,
|
|
1071
|
+
renderResizehandler
|
|
1072
|
+
};
|
|
1073
|
+
},
|
|
1074
|
+
render() {
|
|
1075
|
+
const slots = [
|
|
1076
|
+
...this.children || [],
|
|
1077
|
+
this.dots.map((dot) => {
|
|
1078
|
+
return createRender(
|
|
1079
|
+
freeDomCore_default,
|
|
1080
|
+
{ class: [this.dragOpts.disabled && "vv-resize-dom--disabled"] },
|
|
1081
|
+
{
|
|
1082
|
+
...this.dragOpts,
|
|
1083
|
+
stopFn: this.handleResize("stop", dot),
|
|
1084
|
+
startFn: this.handleResize("start", dot),
|
|
1085
|
+
dragFn: this.handleResize("resize", dot)
|
|
1086
|
+
}
|
|
1087
|
+
)(this.renderResizehandler(dot));
|
|
1088
|
+
})
|
|
1089
|
+
];
|
|
1090
|
+
return createRender(
|
|
1091
|
+
"div",
|
|
1092
|
+
{ class: "vv-resize-dom--box" }
|
|
1093
|
+
)(slots);
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
var resizeDomCore_default = resizeDomCore;
|
|
1097
|
+
|
|
1098
|
+
// src/components/freeDom.ts
|
|
1099
|
+
function noop3() {
|
|
1100
|
+
}
|
|
1101
|
+
var freeDomProps = {
|
|
1102
|
+
modelValue: {
|
|
1103
|
+
type: Object,
|
|
1104
|
+
default: () => ({})
|
|
1105
|
+
},
|
|
1106
|
+
x: {
|
|
1107
|
+
type: Number,
|
|
1108
|
+
default: 0
|
|
1109
|
+
},
|
|
1110
|
+
y: {
|
|
624
1111
|
type: Number,
|
|
625
|
-
default:
|
|
1112
|
+
default: 0
|
|
626
1113
|
},
|
|
627
|
-
|
|
628
|
-
type:
|
|
1114
|
+
width: {
|
|
1115
|
+
type: Number,
|
|
1116
|
+
default: void 0
|
|
1117
|
+
},
|
|
1118
|
+
height: {
|
|
1119
|
+
type: Number,
|
|
629
1120
|
default: void 0
|
|
630
1121
|
},
|
|
631
|
-
|
|
1122
|
+
lockAspectRatio: Boolean,
|
|
1123
|
+
dragStartFn: {
|
|
1124
|
+
type: Function,
|
|
1125
|
+
default: noop3
|
|
1126
|
+
},
|
|
1127
|
+
dragStopFn: {
|
|
1128
|
+
type: Function,
|
|
1129
|
+
default: noop3
|
|
1130
|
+
},
|
|
1131
|
+
dargFn: {
|
|
1132
|
+
type: Function,
|
|
1133
|
+
default: noop3
|
|
1134
|
+
},
|
|
1135
|
+
resizeStartFn: {
|
|
1136
|
+
type: Function,
|
|
1137
|
+
default: noop3
|
|
1138
|
+
},
|
|
1139
|
+
resizeFn: {
|
|
1140
|
+
type: Function,
|
|
1141
|
+
default: noop3
|
|
1142
|
+
},
|
|
1143
|
+
resizeStopFn: {
|
|
1144
|
+
type: Function,
|
|
1145
|
+
default: noop3
|
|
1146
|
+
},
|
|
1147
|
+
autoSize: {
|
|
632
1148
|
type: Boolean,
|
|
1149
|
+
default: true
|
|
1150
|
+
},
|
|
1151
|
+
minWidth: resizeDomCoreProps.minWidth,
|
|
1152
|
+
minHeight: resizeDomCoreProps.minHeight,
|
|
1153
|
+
disabledDrag: Boolean,
|
|
1154
|
+
disabledResize: Boolean,
|
|
1155
|
+
scale: resizeDomCoreProps.scale,
|
|
1156
|
+
fixNonMonospaced: Boolean
|
|
1157
|
+
};
|
|
1158
|
+
var freeDom = defineComponent4({
|
|
1159
|
+
name: "FreeDom",
|
|
1160
|
+
props: freeDomProps,
|
|
1161
|
+
emits: [
|
|
1162
|
+
"update:width",
|
|
1163
|
+
"update:height",
|
|
1164
|
+
"update:x",
|
|
1165
|
+
"update:y",
|
|
1166
|
+
"update:modelValue"
|
|
1167
|
+
],
|
|
1168
|
+
setup(props, { emit, expose, slots }) {
|
|
1169
|
+
const domRef = ref9();
|
|
1170
|
+
const {
|
|
1171
|
+
x,
|
|
1172
|
+
y,
|
|
1173
|
+
deltaX,
|
|
1174
|
+
deltaY,
|
|
1175
|
+
create,
|
|
1176
|
+
handleDrag,
|
|
1177
|
+
handleDragStop
|
|
1178
|
+
} = useDraggableData(props);
|
|
1179
|
+
const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
|
|
1180
|
+
const context = {
|
|
1181
|
+
_rect: reactive2({
|
|
1182
|
+
x,
|
|
1183
|
+
y,
|
|
1184
|
+
width,
|
|
1185
|
+
height,
|
|
1186
|
+
deltaX,
|
|
1187
|
+
deltaY
|
|
1188
|
+
}),
|
|
1189
|
+
trigger: () => {
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
const sceneContext = useSceneContext(context, props);
|
|
1193
|
+
const syncSize = () => {
|
|
1194
|
+
_syncSize(
|
|
1195
|
+
sceneContext.fixNonMonospaced.value,
|
|
1196
|
+
sceneContext.minWidth.value,
|
|
1197
|
+
sceneContext.minHeight.value
|
|
1198
|
+
);
|
|
1199
|
+
};
|
|
1200
|
+
onMounted2(() => {
|
|
1201
|
+
props.autoSize && syncSize();
|
|
1202
|
+
});
|
|
1203
|
+
const style = computed6(() => ({
|
|
1204
|
+
position: "absolute",
|
|
1205
|
+
width: `${width.value}px`,
|
|
1206
|
+
height: `${height.value}px`,
|
|
1207
|
+
transform: `translate(${x.value}px, ${y.value}px)`
|
|
1208
|
+
}));
|
|
1209
|
+
const onDrag = (evt, coreData) => {
|
|
1210
|
+
const data = create(coreData);
|
|
1211
|
+
const newPos = {
|
|
1212
|
+
x: data.x,
|
|
1213
|
+
y: data.y,
|
|
1214
|
+
width: width.value,
|
|
1215
|
+
height: height.value
|
|
1216
|
+
};
|
|
1217
|
+
const isValid = sceneContext.check?.(newPos);
|
|
1218
|
+
if (!isValid)
|
|
1219
|
+
return;
|
|
1220
|
+
handleDrag(evt, data);
|
|
1221
|
+
sceneContext.emit("move");
|
|
1222
|
+
};
|
|
1223
|
+
const onDragStop = (evt, coreData) => {
|
|
1224
|
+
const newPos = {
|
|
1225
|
+
x: x.value,
|
|
1226
|
+
y: y.value,
|
|
1227
|
+
width: width.value,
|
|
1228
|
+
height: height.value
|
|
1229
|
+
};
|
|
1230
|
+
const isValid = sceneContext.check?.(newPos);
|
|
1231
|
+
if (!isValid) {
|
|
1232
|
+
x.value = clamp(x.value, 0, sceneContext.width);
|
|
1233
|
+
y.value = clamp(y.value, 0, sceneContext.height);
|
|
1234
|
+
}
|
|
1235
|
+
handleDragStop(evt, coreData);
|
|
1236
|
+
sceneContext.emit("moveup");
|
|
1237
|
+
emit("update:x", x.value);
|
|
1238
|
+
emit("update:y", y.value);
|
|
1239
|
+
emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
|
|
1240
|
+
};
|
|
1241
|
+
const onResize = (evt, { node, width: w, height: h5, handle: axis }) => {
|
|
1242
|
+
const offsetW = -(w - width.value);
|
|
1243
|
+
const offsetH = -(h5 - height.value);
|
|
1244
|
+
const axisH = axis[0];
|
|
1245
|
+
const axisV = axis[axis.length - 1];
|
|
1246
|
+
let _x = x.value;
|
|
1247
|
+
let _y = y.value;
|
|
1248
|
+
if (axisH === "l") {
|
|
1249
|
+
_x += offsetW;
|
|
1250
|
+
}
|
|
1251
|
+
if (axisV === "t") {
|
|
1252
|
+
_y += offsetH;
|
|
1253
|
+
}
|
|
1254
|
+
const isValid = sceneContext.check?.({ x: _x, y: _y, width: w, height: h5 });
|
|
1255
|
+
if (!isValid)
|
|
1256
|
+
return;
|
|
1257
|
+
width.value = w;
|
|
1258
|
+
height.value = h5;
|
|
1259
|
+
x.value = _x;
|
|
1260
|
+
y.value = _y;
|
|
1261
|
+
props.resizeFn(evt, { node, width: w, height: h5, handle: axis });
|
|
1262
|
+
sceneContext?.emit("move");
|
|
1263
|
+
};
|
|
1264
|
+
const onResizeStop = () => {
|
|
1265
|
+
const isValid = sceneContext.check?.({ x: x.value, y: y.value, width: width.value, height: height.value });
|
|
1266
|
+
if (!isValid) {
|
|
1267
|
+
x.value = clamp(x.value, 0, sceneContext.width);
|
|
1268
|
+
y.value = clamp(y.value, 0, sceneContext.height);
|
|
1269
|
+
}
|
|
1270
|
+
emit("update:width", width.value);
|
|
1271
|
+
emit("update:height", height.value);
|
|
1272
|
+
emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
|
|
1273
|
+
sceneContext.emit("moveup");
|
|
1274
|
+
};
|
|
1275
|
+
const resizeNode = () => {
|
|
1276
|
+
const props2 = {
|
|
1277
|
+
width: width.value,
|
|
1278
|
+
height: height.value,
|
|
1279
|
+
lockAspectRatio: sceneContext.lockAspectRatio.value,
|
|
1280
|
+
dragOpts: { disabled: sceneContext.disabledResize.value },
|
|
1281
|
+
resizeFn: onResize,
|
|
1282
|
+
stopFn: onResizeStop,
|
|
1283
|
+
minHeight: sceneContext.minHeight.value,
|
|
1284
|
+
minWidth: sceneContext.minWidth.value,
|
|
1285
|
+
scale: sceneContext.scale.value
|
|
1286
|
+
};
|
|
1287
|
+
return createRender(resizeDomCore_default, {}, props2)(slots);
|
|
1288
|
+
};
|
|
1289
|
+
expose?.({
|
|
1290
|
+
syncSize
|
|
1291
|
+
});
|
|
1292
|
+
return {
|
|
1293
|
+
domRef,
|
|
1294
|
+
style,
|
|
1295
|
+
onDragStop,
|
|
1296
|
+
onDrag,
|
|
1297
|
+
resizeNode,
|
|
1298
|
+
disabled: sceneContext.disabledDrag
|
|
1299
|
+
};
|
|
1300
|
+
},
|
|
1301
|
+
render() {
|
|
1302
|
+
const props = {
|
|
1303
|
+
stopFn: this.onDragStop,
|
|
1304
|
+
dragFn: this.onDrag,
|
|
1305
|
+
disabled: this.disabled
|
|
1306
|
+
};
|
|
1307
|
+
const slots = () => this.resizeNode();
|
|
1308
|
+
return createRender(
|
|
1309
|
+
freeDomCore_default,
|
|
1310
|
+
{
|
|
1311
|
+
ref: "domRef",
|
|
1312
|
+
class: "vv-free-dom--draggable",
|
|
1313
|
+
style: this.style
|
|
1314
|
+
},
|
|
1315
|
+
props
|
|
1316
|
+
)?.(slots);
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
var freeDom_default = freeDom;
|
|
1320
|
+
|
|
1321
|
+
// src/components/freeDomWrap.ts
|
|
1322
|
+
var freeDomWrapProps = {
|
|
1323
|
+
width: {
|
|
1324
|
+
type: Number,
|
|
633
1325
|
default: void 0
|
|
634
1326
|
},
|
|
635
|
-
|
|
636
|
-
type:
|
|
1327
|
+
height: {
|
|
1328
|
+
type: Number,
|
|
637
1329
|
default: void 0
|
|
638
|
-
}
|
|
1330
|
+
},
|
|
1331
|
+
diff: {
|
|
1332
|
+
type: Number,
|
|
1333
|
+
default: 2
|
|
1334
|
+
},
|
|
1335
|
+
showLine: {
|
|
1336
|
+
type: Boolean,
|
|
1337
|
+
default: true
|
|
1338
|
+
},
|
|
1339
|
+
minWidth: freeDomProps.minWidth,
|
|
1340
|
+
minHeight: freeDomProps.minHeight,
|
|
1341
|
+
lockAspectRatio: freeDomProps.lockAspectRatio,
|
|
1342
|
+
disabledDrag: freeDomProps.disabledDrag,
|
|
1343
|
+
disabledResize: freeDomProps.disabledResize,
|
|
1344
|
+
scale: freeDomProps.scale,
|
|
1345
|
+
fixNonMonospaced: freeDomProps.fixNonMonospaced
|
|
639
1346
|
};
|
|
640
|
-
var FreeDomWrap =
|
|
1347
|
+
var FreeDomWrap = defineComponent5({
|
|
641
1348
|
name: "FreeDomWrap",
|
|
642
1349
|
props: freeDomWrapProps,
|
|
643
1350
|
setup(props) {
|
|
644
|
-
const
|
|
645
|
-
const
|
|
646
|
-
const
|
|
1351
|
+
const { slots } = useDefaultSlot();
|
|
1352
|
+
const eventBus = useEventBus();
|
|
1353
|
+
const rectRef = shallowRef4();
|
|
1354
|
+
const nodes = ref10([]);
|
|
1355
|
+
const width = ref10(props.width);
|
|
1356
|
+
const height = ref10(props.height);
|
|
1357
|
+
watchEffect4(() => {
|
|
1358
|
+
width.value = props.width;
|
|
1359
|
+
});
|
|
1360
|
+
watchEffect4(() => {
|
|
1361
|
+
height.value = props.height;
|
|
1362
|
+
});
|
|
1363
|
+
onMounted3(() => {
|
|
1364
|
+
if (!props.width || !props.height) {
|
|
1365
|
+
if (!rectRef.value)
|
|
1366
|
+
console.warn("[free-dom] cannot find element, width or height may be set to 0");
|
|
1367
|
+
const { width: w, height: h5 } = rectRef.value?.getBoundingClientRect() || {};
|
|
1368
|
+
if (!props.width)
|
|
1369
|
+
width.value = w || 0;
|
|
1370
|
+
if (!props.height)
|
|
1371
|
+
height.value = h5 || 0;
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
647
1374
|
function register(uuid, node) {
|
|
648
1375
|
nodes.value.push({ uuid, node });
|
|
649
1376
|
}
|
|
650
1377
|
function checkValid(pos) {
|
|
651
|
-
const { x, y, width, height } = pos;
|
|
652
|
-
return x >= 0 &&
|
|
1378
|
+
const { x, y, width: w, height: h5 } = pos;
|
|
1379
|
+
return x >= 0 && // @ts-expect-error: trigger after mounted
|
|
1380
|
+
x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
|
|
1381
|
+
y + h5 <= height.value;
|
|
653
1382
|
}
|
|
654
1383
|
provide(
|
|
655
1384
|
SceneToken,
|
|
656
1385
|
reactive3({
|
|
657
1386
|
...toRefs(props),
|
|
658
1387
|
nodes,
|
|
1388
|
+
width,
|
|
1389
|
+
height,
|
|
659
1390
|
register,
|
|
660
|
-
checkValid
|
|
1391
|
+
checkValid,
|
|
1392
|
+
on: eventBus.on,
|
|
1393
|
+
off: eventBus.off,
|
|
1394
|
+
emit: eventBus.emit
|
|
661
1395
|
})
|
|
662
1396
|
);
|
|
1397
|
+
const style = computed7(() => ({
|
|
1398
|
+
width: `${props.width}px`,
|
|
1399
|
+
height: `${props.height}px`
|
|
1400
|
+
}));
|
|
1401
|
+
return {
|
|
1402
|
+
rectRef,
|
|
1403
|
+
style,
|
|
1404
|
+
slots
|
|
1405
|
+
};
|
|
1406
|
+
},
|
|
1407
|
+
render() {
|
|
1408
|
+
const marklineComp = createRender(markLine_default, {}, { showLine: this.showLine })();
|
|
1409
|
+
const slots = [this.slots, marklineComp];
|
|
1410
|
+
return createRender(
|
|
1411
|
+
"section",
|
|
1412
|
+
{
|
|
1413
|
+
ref: "rectRef",
|
|
1414
|
+
class: "vv-free-dom--scene",
|
|
1415
|
+
style: this.style
|
|
1416
|
+
}
|
|
1417
|
+
)(slots);
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// src/components/gridLayout.ts
|
|
1422
|
+
import { defineComponent as defineComponent7, h as h4, provide as provide2, ref as ref11 } from "vue-demi";
|
|
1423
|
+
|
|
1424
|
+
// src/components/gridItem.ts
|
|
1425
|
+
import { defineComponent as defineComponent6, inject as inject3 } from "vue-demi";
|
|
1426
|
+
|
|
1427
|
+
// src/components/tokens.ts
|
|
1428
|
+
var gridLayoutContextKey = Symbol("gridLayoutContext");
|
|
1429
|
+
|
|
1430
|
+
// src/components/gridItem.ts
|
|
1431
|
+
var noop4 = () => {
|
|
1432
|
+
};
|
|
1433
|
+
var gridItemProps = {
|
|
1434
|
+
x: {
|
|
1435
|
+
type: Number,
|
|
1436
|
+
required: true
|
|
1437
|
+
},
|
|
1438
|
+
y: {
|
|
1439
|
+
type: Number,
|
|
1440
|
+
required: true
|
|
1441
|
+
},
|
|
1442
|
+
width: {
|
|
1443
|
+
type: Number,
|
|
1444
|
+
required: true
|
|
1445
|
+
},
|
|
1446
|
+
height: {
|
|
1447
|
+
type: Number,
|
|
1448
|
+
required: true
|
|
1449
|
+
},
|
|
1450
|
+
dragStartFn: {
|
|
1451
|
+
type: Function,
|
|
1452
|
+
default: noop4
|
|
1453
|
+
},
|
|
1454
|
+
dragFn: {
|
|
1455
|
+
type: Function,
|
|
1456
|
+
default: noop4
|
|
1457
|
+
},
|
|
1458
|
+
dragEndFn: {
|
|
1459
|
+
type: Function,
|
|
1460
|
+
default: noop4
|
|
1461
|
+
},
|
|
1462
|
+
resizeStartFn: {
|
|
1463
|
+
type: Function,
|
|
1464
|
+
default: noop4
|
|
1465
|
+
},
|
|
1466
|
+
resizeFn: {
|
|
1467
|
+
type: Function,
|
|
1468
|
+
default: noop4
|
|
1469
|
+
},
|
|
1470
|
+
resizeStopFn: {
|
|
1471
|
+
type: Function,
|
|
1472
|
+
default: noop4
|
|
1473
|
+
},
|
|
1474
|
+
isDraggable: Boolean,
|
|
1475
|
+
isResizable: Boolean,
|
|
1476
|
+
scale: {
|
|
1477
|
+
type: resizeDomCoreProps.scale.type,
|
|
1478
|
+
default: () => ["rb"]
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
var gridItemEmits = ["dragMove"];
|
|
1482
|
+
var GridItem = defineComponent6({
|
|
1483
|
+
name: "GridItem",
|
|
1484
|
+
props: gridItemProps,
|
|
1485
|
+
emits: gridItemEmits,
|
|
1486
|
+
setup(props) {
|
|
1487
|
+
const layout = inject3(gridLayoutContextKey);
|
|
1488
|
+
if (!layout) {
|
|
1489
|
+
throw new Error("TODO");
|
|
1490
|
+
}
|
|
1491
|
+
const {
|
|
1492
|
+
x,
|
|
1493
|
+
y,
|
|
1494
|
+
width,
|
|
1495
|
+
height,
|
|
1496
|
+
dragging,
|
|
1497
|
+
style,
|
|
1498
|
+
minWidth,
|
|
1499
|
+
minHeight,
|
|
1500
|
+
onDragStart,
|
|
1501
|
+
onDrag,
|
|
1502
|
+
onDragStop,
|
|
1503
|
+
onResizeStart,
|
|
1504
|
+
onResize,
|
|
1505
|
+
onResizeStop
|
|
1506
|
+
} = useLayoutItem(props, layout);
|
|
1507
|
+
const { only, slots } = useDefaultSlot();
|
|
1508
|
+
const resizeNode = (child) => {
|
|
1509
|
+
const _props = {
|
|
1510
|
+
width: width.value,
|
|
1511
|
+
height: height.value,
|
|
1512
|
+
scale: props.scale,
|
|
1513
|
+
dragOpts: {
|
|
1514
|
+
disabled: !props.isResizable
|
|
1515
|
+
},
|
|
1516
|
+
minWidth: minWidth.value,
|
|
1517
|
+
minHeight: minHeight.value,
|
|
1518
|
+
startFn: onResizeStart,
|
|
1519
|
+
resizeFn: onResize,
|
|
1520
|
+
stopFn: onResizeStop
|
|
1521
|
+
};
|
|
1522
|
+
return createRender(resizeDomCore_default, {}, _props)(() => child);
|
|
1523
|
+
};
|
|
1524
|
+
const dragNode = (child) => {
|
|
1525
|
+
const _attrs = {
|
|
1526
|
+
class: [
|
|
1527
|
+
dragging.value && "vv-grid-layout--item__draggable",
|
|
1528
|
+
"vv-grid-layout--item",
|
|
1529
|
+
!props.isDraggable && "vv-grid-layout--item__disabled"
|
|
1530
|
+
],
|
|
1531
|
+
style: style.value
|
|
1532
|
+
};
|
|
1533
|
+
const _props = {
|
|
1534
|
+
disabled: !props.isDraggable,
|
|
1535
|
+
startFn: onDragStart,
|
|
1536
|
+
stopFn: onDragStop,
|
|
1537
|
+
dragFn: onDrag
|
|
1538
|
+
};
|
|
1539
|
+
return createRender(freeDomCore_default, _attrs, _props)(() => resizeNode(child));
|
|
1540
|
+
};
|
|
1541
|
+
return {
|
|
1542
|
+
x,
|
|
1543
|
+
y,
|
|
1544
|
+
width,
|
|
1545
|
+
height,
|
|
1546
|
+
child: only,
|
|
1547
|
+
slots,
|
|
1548
|
+
style,
|
|
1549
|
+
dragging,
|
|
1550
|
+
onDragStart,
|
|
1551
|
+
onDrag,
|
|
1552
|
+
onDragStop,
|
|
1553
|
+
onResizeStart,
|
|
1554
|
+
onResize,
|
|
1555
|
+
onResizeStop,
|
|
1556
|
+
dragNode
|
|
1557
|
+
};
|
|
1558
|
+
},
|
|
1559
|
+
render() {
|
|
1560
|
+
const node = this.slots;
|
|
1561
|
+
return this.dragNode(node);
|
|
1562
|
+
}
|
|
1563
|
+
});
|
|
1564
|
+
|
|
1565
|
+
// src/components/gridLayout.ts
|
|
1566
|
+
var gridLayoutProps = {
|
|
1567
|
+
modelValue: {
|
|
1568
|
+
type: Array,
|
|
1569
|
+
required: true,
|
|
1570
|
+
default: () => []
|
|
1571
|
+
},
|
|
1572
|
+
autoHeight: {
|
|
1573
|
+
type: Boolean,
|
|
1574
|
+
default: true
|
|
1575
|
+
},
|
|
1576
|
+
cols: {
|
|
1577
|
+
type: Number,
|
|
1578
|
+
default: 12
|
|
1579
|
+
},
|
|
1580
|
+
maxRows: {
|
|
1581
|
+
type: Number,
|
|
1582
|
+
default: Infinity
|
|
1583
|
+
},
|
|
1584
|
+
minW: {
|
|
1585
|
+
type: Number,
|
|
1586
|
+
default: 1
|
|
1587
|
+
},
|
|
1588
|
+
minH: {
|
|
1589
|
+
type: Number,
|
|
1590
|
+
default: 1
|
|
1591
|
+
},
|
|
1592
|
+
rowHeight: {
|
|
1593
|
+
type: Number,
|
|
1594
|
+
default: 150
|
|
1595
|
+
},
|
|
1596
|
+
width: {
|
|
1597
|
+
type: Number,
|
|
1598
|
+
default: 1200
|
|
1599
|
+
},
|
|
1600
|
+
margin: {
|
|
1601
|
+
type: Array,
|
|
1602
|
+
default: () => [10, 10]
|
|
1603
|
+
},
|
|
1604
|
+
containerPadding: {
|
|
1605
|
+
type: Array,
|
|
1606
|
+
default: void 0
|
|
1607
|
+
},
|
|
1608
|
+
disabledDrag: Boolean,
|
|
1609
|
+
disabledResize: Boolean,
|
|
1610
|
+
collision: Boolean
|
|
1611
|
+
};
|
|
1612
|
+
var GridLayout = defineComponent7({
|
|
1613
|
+
name: "GridLayout",
|
|
1614
|
+
inheritAttrs: false,
|
|
1615
|
+
props: gridLayoutProps,
|
|
1616
|
+
emits: ["update:modelValue"],
|
|
1617
|
+
setup(props, { emit }) {
|
|
1618
|
+
const layout = useLayout(props);
|
|
1619
|
+
provide2(gridLayoutContextKey, layout);
|
|
1620
|
+
const activeDrag = ref11(null);
|
|
1621
|
+
function processItem(node) {
|
|
1622
|
+
const key = node.key;
|
|
1623
|
+
if (!key)
|
|
1624
|
+
return;
|
|
1625
|
+
const config = layout.getItem(String(key));
|
|
1626
|
+
if (!config)
|
|
1627
|
+
return;
|
|
1628
|
+
const isDraggable = !config.static && !props.disabledDrag;
|
|
1629
|
+
const isResizable = !config.static && !props.disabledResize;
|
|
1630
|
+
const _props = {
|
|
1631
|
+
x: config.x,
|
|
1632
|
+
y: config.y,
|
|
1633
|
+
width: config.w,
|
|
1634
|
+
height: config.h,
|
|
1635
|
+
isDraggable,
|
|
1636
|
+
isResizable,
|
|
1637
|
+
scale: config.scale,
|
|
1638
|
+
dragEndFn: (evt, rect) => {
|
|
1639
|
+
const { x, y } = rect;
|
|
1640
|
+
const _layout = layout.moveTo(config, x, y);
|
|
1641
|
+
emit("update:modelValue", _layout);
|
|
1642
|
+
activeDrag.value = null;
|
|
1643
|
+
},
|
|
1644
|
+
dragStartFn: () => {
|
|
1645
|
+
},
|
|
1646
|
+
dragFn: (evt, data) => {
|
|
1647
|
+
if (!config)
|
|
1648
|
+
return;
|
|
1649
|
+
const placeholder2 = {
|
|
1650
|
+
x: config.x,
|
|
1651
|
+
y: config.y,
|
|
1652
|
+
width: config.w,
|
|
1653
|
+
height: config.h
|
|
1654
|
+
};
|
|
1655
|
+
const { x, y } = data;
|
|
1656
|
+
layout.moveTo(config, x, y);
|
|
1657
|
+
activeDrag.value = placeholder2;
|
|
1658
|
+
},
|
|
1659
|
+
resizeFn: (evt, data) => {
|
|
1660
|
+
const placeholder2 = {
|
|
1661
|
+
x: config.x,
|
|
1662
|
+
y: config.y,
|
|
1663
|
+
width: config.w,
|
|
1664
|
+
height: config.h
|
|
1665
|
+
};
|
|
1666
|
+
activeDrag.value = placeholder2;
|
|
1667
|
+
const { w, h: h5 } = data;
|
|
1668
|
+
layout.resizeTo(config, w, h5);
|
|
1669
|
+
},
|
|
1670
|
+
resizeStopFn: (evt, data) => {
|
|
1671
|
+
const { w, h: h5 } = data;
|
|
1672
|
+
layout.resizeTo(config, w, h5);
|
|
1673
|
+
activeDrag.value = null;
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
return createRender(GridItem, {}, _props)({ default: () => node });
|
|
1677
|
+
}
|
|
1678
|
+
function placeholder() {
|
|
1679
|
+
if (!activeDrag.value)
|
|
1680
|
+
return null;
|
|
1681
|
+
const { x, y, width, height } = activeDrag.value;
|
|
1682
|
+
const _props = {
|
|
1683
|
+
x,
|
|
1684
|
+
y,
|
|
1685
|
+
width,
|
|
1686
|
+
height,
|
|
1687
|
+
move: false
|
|
1688
|
+
};
|
|
1689
|
+
return createRender(GridItem, {
|
|
1690
|
+
class: "vv-grid-layout--placeholder"
|
|
1691
|
+
}, _props)();
|
|
1692
|
+
}
|
|
663
1693
|
return {
|
|
664
|
-
|
|
1694
|
+
processItem,
|
|
1695
|
+
placeholder,
|
|
1696
|
+
layout
|
|
665
1697
|
};
|
|
666
1698
|
},
|
|
667
1699
|
render() {
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
1700
|
+
const mergedStyle = {
|
|
1701
|
+
...this.$attrs.style || {},
|
|
1702
|
+
height: this.layout.calContainerHeight()
|
|
1703
|
+
};
|
|
1704
|
+
const defaultSlot = typeof this.$slots.default === "function" ? this.$slots.default() : this.$slots.default || [];
|
|
1705
|
+
return h4("div", {
|
|
1706
|
+
class: "vv-grid-layout",
|
|
1707
|
+
style: mergedStyle
|
|
1708
|
+
}, [
|
|
1709
|
+
defaultSlot.map(this.processItem),
|
|
1710
|
+
this.placeholder()
|
|
1711
|
+
]);
|
|
672
1712
|
}
|
|
673
1713
|
});
|
|
1714
|
+
var gridLayout_default = GridLayout;
|
|
674
1715
|
|
|
675
1716
|
// src/index.ts
|
|
676
|
-
var
|
|
677
|
-
var
|
|
1717
|
+
var FreeScene = FreeDomWrap;
|
|
1718
|
+
var GridLayout2 = gridLayout_default;
|
|
1719
|
+
var FreeDom = freeDom_default;
|
|
678
1720
|
export {
|
|
679
|
-
|
|
680
|
-
|
|
1721
|
+
FreeDom,
|
|
1722
|
+
FreeScene,
|
|
1723
|
+
GridLayout2 as GridLayout
|
|
681
1724
|
};
|