@sepveneto/free-dom 0.7.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +2 -1
- package/dist/index.d.ts +22 -3
- package/dist/index.js +98 -5
- package/dist/index.mjs +101 -8
- package/package.json +1 -1
package/dist/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ../../../../../../../tmp/tmp-
|
|
1
|
+
/* ../../../../../../../tmp/tmp-1880-p3aCZArVLO4k/core/src/style/index.css */
|
|
2
2
|
:root {
|
|
3
3
|
--vv-free-dom--theme: #4089ef;
|
|
4
4
|
--vv-free-dom--line: var(--vv-free-dom--theme);
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
}
|
|
79
79
|
.vv-free-dom--scene {
|
|
80
80
|
position: relative;
|
|
81
|
+
box-sizing: content-box;
|
|
81
82
|
}
|
|
82
83
|
.vv-grid-layout {
|
|
83
84
|
position: relative;
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
113
113
|
type: BooleanConstructor;
|
|
114
114
|
default: boolean;
|
|
115
115
|
};
|
|
116
|
+
handle: {
|
|
117
|
+
type: StringConstructor;
|
|
118
|
+
default: undefined;
|
|
119
|
+
};
|
|
116
120
|
minWidth: {
|
|
117
121
|
type: NumberConstructor;
|
|
118
122
|
default: number;
|
|
@@ -155,6 +159,10 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
155
159
|
type: BooleanConstructor;
|
|
156
160
|
default: boolean;
|
|
157
161
|
};
|
|
162
|
+
handle: {
|
|
163
|
+
type: StringConstructor;
|
|
164
|
+
default: undefined;
|
|
165
|
+
};
|
|
158
166
|
minWidth: {
|
|
159
167
|
type: NumberConstructor;
|
|
160
168
|
default: number;
|
|
@@ -176,6 +184,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
176
184
|
height: number;
|
|
177
185
|
diff: number;
|
|
178
186
|
showLine: boolean;
|
|
187
|
+
handle: string;
|
|
179
188
|
minWidth: number;
|
|
180
189
|
minHeight: number;
|
|
181
190
|
lockAspectRatio: boolean;
|
|
@@ -341,6 +350,10 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
341
350
|
type: NumberConstructor;
|
|
342
351
|
default: undefined;
|
|
343
352
|
};
|
|
353
|
+
handle: {
|
|
354
|
+
type: StringConstructor;
|
|
355
|
+
default: undefined;
|
|
356
|
+
};
|
|
344
357
|
lockAspectRatio: BooleanConstructor;
|
|
345
358
|
dragStartFn: {
|
|
346
359
|
type: vue_demi.PropType<CoreFnCallback>;
|
|
@@ -350,7 +363,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
350
363
|
type: vue_demi.PropType<CoreFnCallback>;
|
|
351
364
|
default: () => void;
|
|
352
365
|
};
|
|
353
|
-
|
|
366
|
+
dragFn: {
|
|
354
367
|
type: vue_demi.PropType<CoreFnCallback>;
|
|
355
368
|
default: () => void;
|
|
356
369
|
};
|
|
@@ -538,6 +551,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
538
551
|
}>;
|
|
539
552
|
onDragStop: CoreFnCallback;
|
|
540
553
|
onDrag: CoreFnCallback;
|
|
554
|
+
onDragStart: CoreFnCallback;
|
|
541
555
|
resizeNode: () => vue_demi.VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
|
|
542
556
|
[key: string]: any;
|
|
543
557
|
}>;
|
|
@@ -568,6 +582,10 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
568
582
|
type: NumberConstructor;
|
|
569
583
|
default: undefined;
|
|
570
584
|
};
|
|
585
|
+
handle: {
|
|
586
|
+
type: StringConstructor;
|
|
587
|
+
default: undefined;
|
|
588
|
+
};
|
|
571
589
|
lockAspectRatio: BooleanConstructor;
|
|
572
590
|
dragStartFn: {
|
|
573
591
|
type: vue_demi.PropType<CoreFnCallback>;
|
|
@@ -577,7 +595,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
577
595
|
type: vue_demi.PropType<CoreFnCallback>;
|
|
578
596
|
default: () => void;
|
|
579
597
|
};
|
|
580
|
-
|
|
598
|
+
dragFn: {
|
|
581
599
|
type: vue_demi.PropType<CoreFnCallback>;
|
|
582
600
|
default: () => void;
|
|
583
601
|
};
|
|
@@ -621,8 +639,10 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
621
639
|
}, {
|
|
622
640
|
x: number;
|
|
623
641
|
y: number;
|
|
642
|
+
dragFn: CoreFnCallback;
|
|
624
643
|
width: number;
|
|
625
644
|
height: number;
|
|
645
|
+
handle: string;
|
|
626
646
|
minWidth: number;
|
|
627
647
|
minHeight: number;
|
|
628
648
|
lockAspectRatio: boolean;
|
|
@@ -638,7 +658,6 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
638
658
|
}>;
|
|
639
659
|
dragStartFn: CoreFnCallback;
|
|
640
660
|
dragStopFn: CoreFnCallback;
|
|
641
|
-
dargFn: CoreFnCallback;
|
|
642
661
|
resizeStartFn: (evt: MouseEvent, resizeData: ResizeData) => void;
|
|
643
662
|
resizeFn: (evt: MouseEvent, resizeData: ResizeData) => void;
|
|
644
663
|
resizeStopFn: (evt: MouseEvent, resizeData: ResizeData) => void;
|
package/dist/index.js
CHANGED
|
@@ -314,12 +314,15 @@ function useDraggableData(props) {
|
|
|
314
314
|
(0, import_vue_demi6.watchEffect)(() => {
|
|
315
315
|
y.value = props.y || props.modelValue.y || 0;
|
|
316
316
|
});
|
|
317
|
+
const handleDragStart = (evt, data) => {
|
|
318
|
+
props.dragStartFn(evt, data);
|
|
319
|
+
};
|
|
317
320
|
const handleDrag = (evt, data) => {
|
|
318
321
|
x.value = data.x;
|
|
319
322
|
y.value = data.y;
|
|
320
323
|
deltaX.value = data.deltaX;
|
|
321
324
|
deltaY.value = data.deltaY;
|
|
322
|
-
props.
|
|
325
|
+
props.dragFn(evt, data);
|
|
323
326
|
};
|
|
324
327
|
const handleDragStop = (evt, coreData) => {
|
|
325
328
|
const data = dragData.value = create(coreData);
|
|
@@ -342,6 +345,7 @@ function useDraggableData(props) {
|
|
|
342
345
|
deltaX,
|
|
343
346
|
deltaY,
|
|
344
347
|
create,
|
|
348
|
+
handleDragStart,
|
|
345
349
|
handleDrag,
|
|
346
350
|
handleDragStop
|
|
347
351
|
};
|
|
@@ -353,6 +357,7 @@ var id = 0;
|
|
|
353
357
|
function useSceneContext(context, props) {
|
|
354
358
|
const SceneContext = (0, import_vue_demi7.inject)(SceneToken, void 0);
|
|
355
359
|
const uuid = id++;
|
|
360
|
+
const handle = (0, import_vue_demi7.computed)(() => SceneContext?.handle || props.handle);
|
|
356
361
|
const lockAspectRatio = (0, import_vue_demi7.computed)(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
|
|
357
362
|
const minWidth = (0, import_vue_demi7.computed)(() => SceneContext?.minWidth || props.minWidth);
|
|
358
363
|
const minHeight = (0, import_vue_demi7.computed)(() => SceneContext?.minHeight || props.minHeight);
|
|
@@ -365,17 +370,27 @@ function useSceneContext(context, props) {
|
|
|
365
370
|
(0, import_vue_demi7.onMounted)(() => {
|
|
366
371
|
SceneContext?.register(uuid, context);
|
|
367
372
|
});
|
|
373
|
+
(0, import_vue_demi7.onUnmounted)(() => {
|
|
374
|
+
SceneContext?.remove(uuid);
|
|
375
|
+
});
|
|
368
376
|
function check(pos) {
|
|
369
377
|
if (!SceneContext)
|
|
370
378
|
return true;
|
|
371
379
|
return SceneContext.checkValid(pos);
|
|
372
380
|
}
|
|
381
|
+
function correct(pos) {
|
|
382
|
+
if (!SceneContext)
|
|
383
|
+
return pos;
|
|
384
|
+
return SceneContext.correct(pos);
|
|
385
|
+
}
|
|
373
386
|
return {
|
|
374
387
|
emit: (name) => SceneContext?.emit(name, uuid),
|
|
375
388
|
check,
|
|
389
|
+
correct,
|
|
376
390
|
width: SceneContext?.width,
|
|
377
391
|
height: SceneContext?.height,
|
|
378
392
|
scale,
|
|
393
|
+
handle,
|
|
379
394
|
lockAspectRatio,
|
|
380
395
|
minWidth,
|
|
381
396
|
minHeight,
|
|
@@ -1149,6 +1164,10 @@ var freeDomProps = {
|
|
|
1149
1164
|
type: Number,
|
|
1150
1165
|
default: void 0
|
|
1151
1166
|
},
|
|
1167
|
+
handle: {
|
|
1168
|
+
type: String,
|
|
1169
|
+
default: void 0
|
|
1170
|
+
},
|
|
1152
1171
|
lockAspectRatio: Boolean,
|
|
1153
1172
|
dragStartFn: {
|
|
1154
1173
|
type: Function,
|
|
@@ -1158,7 +1177,7 @@ var freeDomProps = {
|
|
|
1158
1177
|
type: Function,
|
|
1159
1178
|
default: noop3
|
|
1160
1179
|
},
|
|
1161
|
-
|
|
1180
|
+
dragFn: {
|
|
1162
1181
|
type: Function,
|
|
1163
1182
|
default: noop3
|
|
1164
1183
|
},
|
|
@@ -1203,6 +1222,7 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1203
1222
|
deltaX,
|
|
1204
1223
|
deltaY,
|
|
1205
1224
|
create,
|
|
1225
|
+
handleDragStart,
|
|
1206
1226
|
handleDrag,
|
|
1207
1227
|
handleDragStop
|
|
1208
1228
|
} = useDraggableData(props);
|
|
@@ -1216,7 +1236,8 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1216
1236
|
deltaX,
|
|
1217
1237
|
deltaY
|
|
1218
1238
|
}),
|
|
1219
|
-
trigger: () => {
|
|
1239
|
+
trigger: (pos) => {
|
|
1240
|
+
emit("update:modelValue", pos);
|
|
1220
1241
|
}
|
|
1221
1242
|
};
|
|
1222
1243
|
const sceneContext = useSceneContext(context, props);
|
|
@@ -1227,8 +1248,11 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1227
1248
|
sceneContext.minHeight.value
|
|
1228
1249
|
);
|
|
1229
1250
|
};
|
|
1251
|
+
const canDrag = (0, import_vue_demi13.ref)(false);
|
|
1230
1252
|
(0, import_vue_demi13.onMounted)(() => {
|
|
1231
1253
|
props.autoSize && syncSize();
|
|
1254
|
+
const pos = sceneContext.correct(context._rect);
|
|
1255
|
+
context.trigger({ x: pos.x, y: pos.y, w: pos.width, h: pos.height });
|
|
1232
1256
|
});
|
|
1233
1257
|
const style = (0, import_vue_demi13.computed)(() => ({
|
|
1234
1258
|
position: "absolute",
|
|
@@ -1237,6 +1261,8 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1237
1261
|
transform: `translate(${x.value}px, ${y.value}px)`
|
|
1238
1262
|
}));
|
|
1239
1263
|
const onDrag = (evt, coreData) => {
|
|
1264
|
+
if (!canDrag.value)
|
|
1265
|
+
return;
|
|
1240
1266
|
const data = create(coreData);
|
|
1241
1267
|
const newPos = {
|
|
1242
1268
|
x: data.x,
|
|
@@ -1251,6 +1277,8 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1251
1277
|
sceneContext.emit("move");
|
|
1252
1278
|
};
|
|
1253
1279
|
const onDragStop = (evt, coreData) => {
|
|
1280
|
+
if (!canDrag.value)
|
|
1281
|
+
return;
|
|
1254
1282
|
const newPos = {
|
|
1255
1283
|
x: x.value,
|
|
1256
1284
|
y: y.value,
|
|
@@ -1268,6 +1296,22 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1268
1296
|
emit("update:y", y.value);
|
|
1269
1297
|
emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
|
|
1270
1298
|
};
|
|
1299
|
+
const onDragStart = (evt, coreData) => {
|
|
1300
|
+
const handle = sceneContext.handle.value;
|
|
1301
|
+
if (handle) {
|
|
1302
|
+
if (handle.startsWith(".")) {
|
|
1303
|
+
canDrag.value = evt.target.classList.contains(handle.slice(1));
|
|
1304
|
+
} else if (handle.startsWith("#")) {
|
|
1305
|
+
canDrag.value = evt.target.id === handle.slice(1);
|
|
1306
|
+
} else {
|
|
1307
|
+
console.warn(`[free-dom] can not find element with ${handle}`);
|
|
1308
|
+
canDrag.value = true;
|
|
1309
|
+
}
|
|
1310
|
+
} else {
|
|
1311
|
+
canDrag.value = true;
|
|
1312
|
+
}
|
|
1313
|
+
canDrag.value && handleDragStart(evt, coreData);
|
|
1314
|
+
};
|
|
1271
1315
|
const onResize = (evt, { node, width: w, height: h5, handle: axis }) => {
|
|
1272
1316
|
const offsetW = -(w - width.value);
|
|
1273
1317
|
const offsetH = -(h5 - height.value);
|
|
@@ -1291,23 +1335,28 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1291
1335
|
props.resizeFn(evt, { node, width: w, height: h5, handle: axis });
|
|
1292
1336
|
sceneContext?.emit("move");
|
|
1293
1337
|
};
|
|
1294
|
-
const onResizeStop = () => {
|
|
1338
|
+
const onResizeStop = (evt, data) => {
|
|
1295
1339
|
const isValid = sceneContext.check?.({ x: x.value, y: y.value, width: width.value, height: height.value });
|
|
1296
1340
|
if (!isValid) {
|
|
1297
1341
|
x.value = clamp(x.value, 0, sceneContext.width);
|
|
1298
1342
|
y.value = clamp(y.value, 0, sceneContext.height);
|
|
1299
1343
|
}
|
|
1344
|
+
props.resizeStopFn(evt, data);
|
|
1300
1345
|
emit("update:width", width.value);
|
|
1301
1346
|
emit("update:height", height.value);
|
|
1302
1347
|
emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
|
|
1303
1348
|
sceneContext.emit("moveup");
|
|
1304
1349
|
};
|
|
1350
|
+
const onResizeStart = (evt, data) => {
|
|
1351
|
+
props.resizeStartFn(evt, data);
|
|
1352
|
+
};
|
|
1305
1353
|
const resizeNode = () => {
|
|
1306
1354
|
const props2 = {
|
|
1307
1355
|
width: width.value,
|
|
1308
1356
|
height: height.value,
|
|
1309
1357
|
lockAspectRatio: sceneContext.lockAspectRatio.value,
|
|
1310
1358
|
dragOpts: { disabled: sceneContext.disabledResize.value },
|
|
1359
|
+
startFn: onResizeStart,
|
|
1311
1360
|
resizeFn: onResize,
|
|
1312
1361
|
stopFn: onResizeStop,
|
|
1313
1362
|
minHeight: sceneContext.minHeight.value,
|
|
@@ -1324,12 +1373,14 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
|
|
|
1324
1373
|
style,
|
|
1325
1374
|
onDragStop,
|
|
1326
1375
|
onDrag,
|
|
1376
|
+
onDragStart,
|
|
1327
1377
|
resizeNode,
|
|
1328
1378
|
disabled: sceneContext.disabledDrag
|
|
1329
1379
|
};
|
|
1330
1380
|
},
|
|
1331
1381
|
render() {
|
|
1332
1382
|
const props = {
|
|
1383
|
+
startFn: this.onDragStart,
|
|
1333
1384
|
stopFn: this.onDragStop,
|
|
1334
1385
|
dragFn: this.onDrag,
|
|
1335
1386
|
disabled: this.disabled
|
|
@@ -1366,6 +1417,7 @@ var freeDomWrapProps = {
|
|
|
1366
1417
|
type: Boolean,
|
|
1367
1418
|
default: true
|
|
1368
1419
|
},
|
|
1420
|
+
handle: freeDomProps.handle,
|
|
1369
1421
|
minWidth: freeDomProps.minWidth,
|
|
1370
1422
|
minHeight: freeDomProps.minHeight,
|
|
1371
1423
|
lockAspectRatio: freeDomProps.lockAspectRatio,
|
|
@@ -1394,22 +1446,61 @@ var FreeDomWrap = (0, import_vue_demi14.defineComponent)({
|
|
|
1394
1446
|
if (!props.width || !props.height) {
|
|
1395
1447
|
if (!rectRef.value)
|
|
1396
1448
|
console.warn("[free-dom] cannot find element, width or height may be set to 0");
|
|
1397
|
-
const
|
|
1449
|
+
const h5 = rectRef.value?.clientHeight;
|
|
1450
|
+
const w = rectRef.value?.clientWidth;
|
|
1398
1451
|
if (!props.width)
|
|
1399
1452
|
width.value = w || 0;
|
|
1400
1453
|
if (!props.height)
|
|
1401
1454
|
height.value = h5 || 0;
|
|
1402
1455
|
}
|
|
1456
|
+
nodes.value.forEach((pos) => {
|
|
1457
|
+
const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
|
|
1458
|
+
pos.node._rect.x = x;
|
|
1459
|
+
pos.node._rect.y = y;
|
|
1460
|
+
pos.node._rect.width = width2;
|
|
1461
|
+
pos.node._rect.height = height2;
|
|
1462
|
+
pos.node.trigger({ x, y, w: width2, h: height2 });
|
|
1463
|
+
});
|
|
1403
1464
|
});
|
|
1404
1465
|
function register(uuid, node) {
|
|
1405
1466
|
nodes.value.push({ uuid, node });
|
|
1406
1467
|
}
|
|
1468
|
+
function remove(uuid) {
|
|
1469
|
+
const index = nodes.value.findIndex((item) => item.uuid === uuid);
|
|
1470
|
+
nodes.value.splice(index, 1);
|
|
1471
|
+
}
|
|
1407
1472
|
function checkValid(pos) {
|
|
1408
1473
|
const { x, y, width: w, height: h5 } = pos;
|
|
1409
1474
|
return x >= 0 && // @ts-expect-error: trigger after mounted
|
|
1410
1475
|
x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
|
|
1411
1476
|
y + h5 <= height.value;
|
|
1412
1477
|
}
|
|
1478
|
+
function correct(pos) {
|
|
1479
|
+
let x = Math.max(pos.x, 0);
|
|
1480
|
+
let y = Math.max(pos.y, 0);
|
|
1481
|
+
let w = pos.width;
|
|
1482
|
+
let h5 = pos.height;
|
|
1483
|
+
if (pos.x + pos.width > width.value) {
|
|
1484
|
+
x = width.value - pos.width;
|
|
1485
|
+
if (x < 0) {
|
|
1486
|
+
w = width.value;
|
|
1487
|
+
x = 0;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
if (pos.y + pos.height > height.value) {
|
|
1491
|
+
y = height.value - pos.height;
|
|
1492
|
+
if (y < 0) {
|
|
1493
|
+
h5 = height.value;
|
|
1494
|
+
y = 0;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
x,
|
|
1499
|
+
y,
|
|
1500
|
+
width: w,
|
|
1501
|
+
height: h5
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1413
1504
|
(0, import_vue_demi14.provide)(
|
|
1414
1505
|
SceneToken,
|
|
1415
1506
|
(0, import_vue_demi14.reactive)({
|
|
@@ -1418,7 +1509,9 @@ var FreeDomWrap = (0, import_vue_demi14.defineComponent)({
|
|
|
1418
1509
|
width,
|
|
1419
1510
|
height,
|
|
1420
1511
|
register,
|
|
1512
|
+
remove,
|
|
1421
1513
|
checkValid,
|
|
1514
|
+
correct,
|
|
1422
1515
|
on: eventBus.on,
|
|
1423
1516
|
off: eventBus.off,
|
|
1424
1517
|
emit: eventBus.emit
|
package/dist/index.mjs
CHANGED
|
@@ -284,12 +284,15 @@ function useDraggableData(props) {
|
|
|
284
284
|
watchEffect(() => {
|
|
285
285
|
y.value = props.y || props.modelValue.y || 0;
|
|
286
286
|
});
|
|
287
|
+
const handleDragStart = (evt, data) => {
|
|
288
|
+
props.dragStartFn(evt, data);
|
|
289
|
+
};
|
|
287
290
|
const handleDrag = (evt, data) => {
|
|
288
291
|
x.value = data.x;
|
|
289
292
|
y.value = data.y;
|
|
290
293
|
deltaX.value = data.deltaX;
|
|
291
294
|
deltaY.value = data.deltaY;
|
|
292
|
-
props.
|
|
295
|
+
props.dragFn(evt, data);
|
|
293
296
|
};
|
|
294
297
|
const handleDragStop = (evt, coreData) => {
|
|
295
298
|
const data = dragData.value = create(coreData);
|
|
@@ -312,17 +315,19 @@ function useDraggableData(props) {
|
|
|
312
315
|
deltaX,
|
|
313
316
|
deltaY,
|
|
314
317
|
create,
|
|
318
|
+
handleDragStart,
|
|
315
319
|
handleDrag,
|
|
316
320
|
handleDragStop
|
|
317
321
|
};
|
|
318
322
|
}
|
|
319
323
|
|
|
320
324
|
// src/hooks/use-scene-context.ts
|
|
321
|
-
import { computed as computed2, inject as inject2, onMounted } from "vue-demi";
|
|
325
|
+
import { computed as computed2, inject as inject2, onMounted, onUnmounted } from "vue-demi";
|
|
322
326
|
var id = 0;
|
|
323
327
|
function useSceneContext(context, props) {
|
|
324
328
|
const SceneContext = inject2(SceneToken, void 0);
|
|
325
329
|
const uuid = id++;
|
|
330
|
+
const handle = computed2(() => SceneContext?.handle || props.handle);
|
|
326
331
|
const lockAspectRatio = computed2(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
|
|
327
332
|
const minWidth = computed2(() => SceneContext?.minWidth || props.minWidth);
|
|
328
333
|
const minHeight = computed2(() => SceneContext?.minHeight || props.minHeight);
|
|
@@ -335,17 +340,27 @@ function useSceneContext(context, props) {
|
|
|
335
340
|
onMounted(() => {
|
|
336
341
|
SceneContext?.register(uuid, context);
|
|
337
342
|
});
|
|
343
|
+
onUnmounted(() => {
|
|
344
|
+
SceneContext?.remove(uuid);
|
|
345
|
+
});
|
|
338
346
|
function check(pos) {
|
|
339
347
|
if (!SceneContext)
|
|
340
348
|
return true;
|
|
341
349
|
return SceneContext.checkValid(pos);
|
|
342
350
|
}
|
|
351
|
+
function correct(pos) {
|
|
352
|
+
if (!SceneContext)
|
|
353
|
+
return pos;
|
|
354
|
+
return SceneContext.correct(pos);
|
|
355
|
+
}
|
|
343
356
|
return {
|
|
344
357
|
emit: (name) => SceneContext?.emit(name, uuid),
|
|
345
358
|
check,
|
|
359
|
+
correct,
|
|
346
360
|
width: SceneContext?.width,
|
|
347
361
|
height: SceneContext?.height,
|
|
348
362
|
scale,
|
|
363
|
+
handle,
|
|
349
364
|
lockAspectRatio,
|
|
350
365
|
minWidth,
|
|
351
366
|
minHeight,
|
|
@@ -794,7 +809,7 @@ function useLayoutItem(props, layout) {
|
|
|
794
809
|
import { computed as computed6, defineComponent as defineComponent4, onMounted as onMounted2, reactive as reactive2, ref as ref9 } from "vue-demi";
|
|
795
810
|
|
|
796
811
|
// src/components/freeDomCore.ts
|
|
797
|
-
import { computed as computed4, defineComponent as defineComponent2, isVue2 as isVue22, onUnmounted, ref as ref8 } from "vue-demi";
|
|
812
|
+
import { computed as computed4, defineComponent as defineComponent2, isVue2 as isVue22, onUnmounted as onUnmounted2, ref as ref8 } from "vue-demi";
|
|
798
813
|
function noop() {
|
|
799
814
|
}
|
|
800
815
|
var freeDomCoreProps = {
|
|
@@ -828,7 +843,7 @@ var freeDomCore = defineComponent2({
|
|
|
828
843
|
const { lastX, lastY, create } = useCoreData(node);
|
|
829
844
|
let parentNode;
|
|
830
845
|
let parentRect;
|
|
831
|
-
|
|
846
|
+
onUnmounted2(() => {
|
|
832
847
|
if (!ownerDoc.value)
|
|
833
848
|
return;
|
|
834
849
|
if (props.userSelectHack)
|
|
@@ -1119,6 +1134,10 @@ var freeDomProps = {
|
|
|
1119
1134
|
type: Number,
|
|
1120
1135
|
default: void 0
|
|
1121
1136
|
},
|
|
1137
|
+
handle: {
|
|
1138
|
+
type: String,
|
|
1139
|
+
default: void 0
|
|
1140
|
+
},
|
|
1122
1141
|
lockAspectRatio: Boolean,
|
|
1123
1142
|
dragStartFn: {
|
|
1124
1143
|
type: Function,
|
|
@@ -1128,7 +1147,7 @@ var freeDomProps = {
|
|
|
1128
1147
|
type: Function,
|
|
1129
1148
|
default: noop3
|
|
1130
1149
|
},
|
|
1131
|
-
|
|
1150
|
+
dragFn: {
|
|
1132
1151
|
type: Function,
|
|
1133
1152
|
default: noop3
|
|
1134
1153
|
},
|
|
@@ -1173,6 +1192,7 @@ var freeDom = defineComponent4({
|
|
|
1173
1192
|
deltaX,
|
|
1174
1193
|
deltaY,
|
|
1175
1194
|
create,
|
|
1195
|
+
handleDragStart,
|
|
1176
1196
|
handleDrag,
|
|
1177
1197
|
handleDragStop
|
|
1178
1198
|
} = useDraggableData(props);
|
|
@@ -1186,7 +1206,8 @@ var freeDom = defineComponent4({
|
|
|
1186
1206
|
deltaX,
|
|
1187
1207
|
deltaY
|
|
1188
1208
|
}),
|
|
1189
|
-
trigger: () => {
|
|
1209
|
+
trigger: (pos) => {
|
|
1210
|
+
emit("update:modelValue", pos);
|
|
1190
1211
|
}
|
|
1191
1212
|
};
|
|
1192
1213
|
const sceneContext = useSceneContext(context, props);
|
|
@@ -1197,8 +1218,11 @@ var freeDom = defineComponent4({
|
|
|
1197
1218
|
sceneContext.minHeight.value
|
|
1198
1219
|
);
|
|
1199
1220
|
};
|
|
1221
|
+
const canDrag = ref9(false);
|
|
1200
1222
|
onMounted2(() => {
|
|
1201
1223
|
props.autoSize && syncSize();
|
|
1224
|
+
const pos = sceneContext.correct(context._rect);
|
|
1225
|
+
context.trigger({ x: pos.x, y: pos.y, w: pos.width, h: pos.height });
|
|
1202
1226
|
});
|
|
1203
1227
|
const style = computed6(() => ({
|
|
1204
1228
|
position: "absolute",
|
|
@@ -1207,6 +1231,8 @@ var freeDom = defineComponent4({
|
|
|
1207
1231
|
transform: `translate(${x.value}px, ${y.value}px)`
|
|
1208
1232
|
}));
|
|
1209
1233
|
const onDrag = (evt, coreData) => {
|
|
1234
|
+
if (!canDrag.value)
|
|
1235
|
+
return;
|
|
1210
1236
|
const data = create(coreData);
|
|
1211
1237
|
const newPos = {
|
|
1212
1238
|
x: data.x,
|
|
@@ -1221,6 +1247,8 @@ var freeDom = defineComponent4({
|
|
|
1221
1247
|
sceneContext.emit("move");
|
|
1222
1248
|
};
|
|
1223
1249
|
const onDragStop = (evt, coreData) => {
|
|
1250
|
+
if (!canDrag.value)
|
|
1251
|
+
return;
|
|
1224
1252
|
const newPos = {
|
|
1225
1253
|
x: x.value,
|
|
1226
1254
|
y: y.value,
|
|
@@ -1238,6 +1266,22 @@ var freeDom = defineComponent4({
|
|
|
1238
1266
|
emit("update:y", y.value);
|
|
1239
1267
|
emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
|
|
1240
1268
|
};
|
|
1269
|
+
const onDragStart = (evt, coreData) => {
|
|
1270
|
+
const handle = sceneContext.handle.value;
|
|
1271
|
+
if (handle) {
|
|
1272
|
+
if (handle.startsWith(".")) {
|
|
1273
|
+
canDrag.value = evt.target.classList.contains(handle.slice(1));
|
|
1274
|
+
} else if (handle.startsWith("#")) {
|
|
1275
|
+
canDrag.value = evt.target.id === handle.slice(1);
|
|
1276
|
+
} else {
|
|
1277
|
+
console.warn(`[free-dom] can not find element with ${handle}`);
|
|
1278
|
+
canDrag.value = true;
|
|
1279
|
+
}
|
|
1280
|
+
} else {
|
|
1281
|
+
canDrag.value = true;
|
|
1282
|
+
}
|
|
1283
|
+
canDrag.value && handleDragStart(evt, coreData);
|
|
1284
|
+
};
|
|
1241
1285
|
const onResize = (evt, { node, width: w, height: h5, handle: axis }) => {
|
|
1242
1286
|
const offsetW = -(w - width.value);
|
|
1243
1287
|
const offsetH = -(h5 - height.value);
|
|
@@ -1261,23 +1305,28 @@ var freeDom = defineComponent4({
|
|
|
1261
1305
|
props.resizeFn(evt, { node, width: w, height: h5, handle: axis });
|
|
1262
1306
|
sceneContext?.emit("move");
|
|
1263
1307
|
};
|
|
1264
|
-
const onResizeStop = () => {
|
|
1308
|
+
const onResizeStop = (evt, data) => {
|
|
1265
1309
|
const isValid = sceneContext.check?.({ x: x.value, y: y.value, width: width.value, height: height.value });
|
|
1266
1310
|
if (!isValid) {
|
|
1267
1311
|
x.value = clamp(x.value, 0, sceneContext.width);
|
|
1268
1312
|
y.value = clamp(y.value, 0, sceneContext.height);
|
|
1269
1313
|
}
|
|
1314
|
+
props.resizeStopFn(evt, data);
|
|
1270
1315
|
emit("update:width", width.value);
|
|
1271
1316
|
emit("update:height", height.value);
|
|
1272
1317
|
emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
|
|
1273
1318
|
sceneContext.emit("moveup");
|
|
1274
1319
|
};
|
|
1320
|
+
const onResizeStart = (evt, data) => {
|
|
1321
|
+
props.resizeStartFn(evt, data);
|
|
1322
|
+
};
|
|
1275
1323
|
const resizeNode = () => {
|
|
1276
1324
|
const props2 = {
|
|
1277
1325
|
width: width.value,
|
|
1278
1326
|
height: height.value,
|
|
1279
1327
|
lockAspectRatio: sceneContext.lockAspectRatio.value,
|
|
1280
1328
|
dragOpts: { disabled: sceneContext.disabledResize.value },
|
|
1329
|
+
startFn: onResizeStart,
|
|
1281
1330
|
resizeFn: onResize,
|
|
1282
1331
|
stopFn: onResizeStop,
|
|
1283
1332
|
minHeight: sceneContext.minHeight.value,
|
|
@@ -1294,12 +1343,14 @@ var freeDom = defineComponent4({
|
|
|
1294
1343
|
style,
|
|
1295
1344
|
onDragStop,
|
|
1296
1345
|
onDrag,
|
|
1346
|
+
onDragStart,
|
|
1297
1347
|
resizeNode,
|
|
1298
1348
|
disabled: sceneContext.disabledDrag
|
|
1299
1349
|
};
|
|
1300
1350
|
},
|
|
1301
1351
|
render() {
|
|
1302
1352
|
const props = {
|
|
1353
|
+
startFn: this.onDragStart,
|
|
1303
1354
|
stopFn: this.onDragStop,
|
|
1304
1355
|
dragFn: this.onDrag,
|
|
1305
1356
|
disabled: this.disabled
|
|
@@ -1336,6 +1387,7 @@ var freeDomWrapProps = {
|
|
|
1336
1387
|
type: Boolean,
|
|
1337
1388
|
default: true
|
|
1338
1389
|
},
|
|
1390
|
+
handle: freeDomProps.handle,
|
|
1339
1391
|
minWidth: freeDomProps.minWidth,
|
|
1340
1392
|
minHeight: freeDomProps.minHeight,
|
|
1341
1393
|
lockAspectRatio: freeDomProps.lockAspectRatio,
|
|
@@ -1364,22 +1416,61 @@ var FreeDomWrap = defineComponent5({
|
|
|
1364
1416
|
if (!props.width || !props.height) {
|
|
1365
1417
|
if (!rectRef.value)
|
|
1366
1418
|
console.warn("[free-dom] cannot find element, width or height may be set to 0");
|
|
1367
|
-
const
|
|
1419
|
+
const h5 = rectRef.value?.clientHeight;
|
|
1420
|
+
const w = rectRef.value?.clientWidth;
|
|
1368
1421
|
if (!props.width)
|
|
1369
1422
|
width.value = w || 0;
|
|
1370
1423
|
if (!props.height)
|
|
1371
1424
|
height.value = h5 || 0;
|
|
1372
1425
|
}
|
|
1426
|
+
nodes.value.forEach((pos) => {
|
|
1427
|
+
const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
|
|
1428
|
+
pos.node._rect.x = x;
|
|
1429
|
+
pos.node._rect.y = y;
|
|
1430
|
+
pos.node._rect.width = width2;
|
|
1431
|
+
pos.node._rect.height = height2;
|
|
1432
|
+
pos.node.trigger({ x, y, w: width2, h: height2 });
|
|
1433
|
+
});
|
|
1373
1434
|
});
|
|
1374
1435
|
function register(uuid, node) {
|
|
1375
1436
|
nodes.value.push({ uuid, node });
|
|
1376
1437
|
}
|
|
1438
|
+
function remove(uuid) {
|
|
1439
|
+
const index = nodes.value.findIndex((item) => item.uuid === uuid);
|
|
1440
|
+
nodes.value.splice(index, 1);
|
|
1441
|
+
}
|
|
1377
1442
|
function checkValid(pos) {
|
|
1378
1443
|
const { x, y, width: w, height: h5 } = pos;
|
|
1379
1444
|
return x >= 0 && // @ts-expect-error: trigger after mounted
|
|
1380
1445
|
x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
|
|
1381
1446
|
y + h5 <= height.value;
|
|
1382
1447
|
}
|
|
1448
|
+
function correct(pos) {
|
|
1449
|
+
let x = Math.max(pos.x, 0);
|
|
1450
|
+
let y = Math.max(pos.y, 0);
|
|
1451
|
+
let w = pos.width;
|
|
1452
|
+
let h5 = pos.height;
|
|
1453
|
+
if (pos.x + pos.width > width.value) {
|
|
1454
|
+
x = width.value - pos.width;
|
|
1455
|
+
if (x < 0) {
|
|
1456
|
+
w = width.value;
|
|
1457
|
+
x = 0;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (pos.y + pos.height > height.value) {
|
|
1461
|
+
y = height.value - pos.height;
|
|
1462
|
+
if (y < 0) {
|
|
1463
|
+
h5 = height.value;
|
|
1464
|
+
y = 0;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return {
|
|
1468
|
+
x,
|
|
1469
|
+
y,
|
|
1470
|
+
width: w,
|
|
1471
|
+
height: h5
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1383
1474
|
provide(
|
|
1384
1475
|
SceneToken,
|
|
1385
1476
|
reactive3({
|
|
@@ -1388,7 +1479,9 @@ var FreeDomWrap = defineComponent5({
|
|
|
1388
1479
|
width,
|
|
1389
1480
|
height,
|
|
1390
1481
|
register,
|
|
1482
|
+
remove,
|
|
1391
1483
|
checkValid,
|
|
1484
|
+
correct,
|
|
1392
1485
|
on: eventBus.on,
|
|
1393
1486
|
off: eventBus.off,
|
|
1394
1487
|
emit: eventBus.emit
|