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