@sepveneto/free-dom 0.11.1 → 0.11.4
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 +1 -1
- package/dist/index.d.ts +14 -27
- package/dist/index.js +132 -91
- package/dist/index.mjs +135 -95
- package/package.json +1 -1
package/dist/index.css
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -101,14 +101,6 @@ type GridLayoutItem = {
|
|
|
101
101
|
type GridLayoutConfig = GridLayoutItem[];
|
|
102
102
|
|
|
103
103
|
declare const FreeScene: vue_demi.DefineComponent<{
|
|
104
|
-
width: {
|
|
105
|
-
type: NumberConstructor;
|
|
106
|
-
default: undefined;
|
|
107
|
-
};
|
|
108
|
-
height: {
|
|
109
|
-
type: NumberConstructor;
|
|
110
|
-
default: undefined;
|
|
111
|
-
};
|
|
112
104
|
diff: {
|
|
113
105
|
type: NumberConstructor;
|
|
114
106
|
default: number;
|
|
@@ -122,6 +114,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
122
114
|
default: number;
|
|
123
115
|
};
|
|
124
116
|
keyboard: BooleanConstructor;
|
|
117
|
+
disabledBatch: BooleanConstructor;
|
|
125
118
|
handle: {
|
|
126
119
|
type: StringConstructor;
|
|
127
120
|
default: undefined;
|
|
@@ -137,6 +130,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
137
130
|
lockAspectRatio: BooleanConstructor;
|
|
138
131
|
disabledDrag: BooleanConstructor;
|
|
139
132
|
disabledResize: BooleanConstructor;
|
|
133
|
+
disabledSelect: BooleanConstructor;
|
|
140
134
|
scale: {
|
|
141
135
|
type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
|
|
142
136
|
default: undefined;
|
|
@@ -144,10 +138,6 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
144
138
|
fixNonMonospaced: BooleanConstructor;
|
|
145
139
|
}, {
|
|
146
140
|
rectRef: vue_demi.ShallowRef<HTMLElement | undefined>;
|
|
147
|
-
style: vue_demi.ComputedRef<{
|
|
148
|
-
width: string;
|
|
149
|
-
height: string;
|
|
150
|
-
}>;
|
|
151
141
|
selecting: vue_demi.Ref<boolean>;
|
|
152
142
|
mask: {
|
|
153
143
|
selecting: vue_demi.Ref<boolean>;
|
|
@@ -166,14 +156,6 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
166
156
|
push: (operate: any) => void;
|
|
167
157
|
};
|
|
168
158
|
}, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, {}, string, vue_demi.PublicProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
169
|
-
width: {
|
|
170
|
-
type: NumberConstructor;
|
|
171
|
-
default: undefined;
|
|
172
|
-
};
|
|
173
|
-
height: {
|
|
174
|
-
type: NumberConstructor;
|
|
175
|
-
default: undefined;
|
|
176
|
-
};
|
|
177
159
|
diff: {
|
|
178
160
|
type: NumberConstructor;
|
|
179
161
|
default: number;
|
|
@@ -187,6 +169,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
187
169
|
default: number;
|
|
188
170
|
};
|
|
189
171
|
keyboard: BooleanConstructor;
|
|
172
|
+
disabledBatch: BooleanConstructor;
|
|
190
173
|
handle: {
|
|
191
174
|
type: StringConstructor;
|
|
192
175
|
default: undefined;
|
|
@@ -202,6 +185,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
202
185
|
lockAspectRatio: BooleanConstructor;
|
|
203
186
|
disabledDrag: BooleanConstructor;
|
|
204
187
|
disabledResize: BooleanConstructor;
|
|
188
|
+
disabledSelect: BooleanConstructor;
|
|
205
189
|
scale: {
|
|
206
190
|
type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
|
|
207
191
|
default: undefined;
|
|
@@ -209,18 +193,18 @@ declare const FreeScene: vue_demi.DefineComponent<{
|
|
|
209
193
|
fixNonMonospaced: BooleanConstructor;
|
|
210
194
|
}>>, {
|
|
211
195
|
scale: boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[];
|
|
212
|
-
width: number;
|
|
213
|
-
height: number;
|
|
214
196
|
diff: number;
|
|
215
197
|
showLine: boolean;
|
|
216
198
|
transformScale: number;
|
|
217
199
|
keyboard: boolean;
|
|
200
|
+
disabledBatch: boolean;
|
|
218
201
|
handle: string;
|
|
219
202
|
minWidth: number;
|
|
220
203
|
minHeight: number;
|
|
221
204
|
lockAspectRatio: boolean;
|
|
222
205
|
disabledDrag: boolean;
|
|
223
206
|
disabledResize: boolean;
|
|
207
|
+
disabledSelect: boolean;
|
|
224
208
|
fixNonMonospaced: boolean;
|
|
225
209
|
}, {}>;
|
|
226
210
|
declare const GridLayout: vue_demi.DefineComponent<{
|
|
@@ -340,7 +324,6 @@ declare const GridLayout: vue_demi.DefineComponent<{
|
|
|
340
324
|
}>> & {
|
|
341
325
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
342
326
|
}, {
|
|
343
|
-
width: number;
|
|
344
327
|
disabledDrag: boolean;
|
|
345
328
|
disabledResize: boolean;
|
|
346
329
|
modelValue: GridLayoutConfig;
|
|
@@ -350,6 +333,7 @@ declare const GridLayout: vue_demi.DefineComponent<{
|
|
|
350
333
|
minW: number;
|
|
351
334
|
minH: number;
|
|
352
335
|
rowHeight: number;
|
|
336
|
+
width: number;
|
|
353
337
|
margin: number[];
|
|
354
338
|
containerPadding: number[];
|
|
355
339
|
collision: boolean;
|
|
@@ -424,6 +408,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
424
408
|
};
|
|
425
409
|
disabledDrag: BooleanConstructor;
|
|
426
410
|
disabledResize: BooleanConstructor;
|
|
411
|
+
disabledSelect: BooleanConstructor;
|
|
427
412
|
scale: {
|
|
428
413
|
type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
|
|
429
414
|
default: undefined;
|
|
@@ -616,6 +601,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
616
601
|
};
|
|
617
602
|
disabledDrag: BooleanConstructor;
|
|
618
603
|
disabledResize: BooleanConstructor;
|
|
604
|
+
disabledSelect: BooleanConstructor;
|
|
619
605
|
scale: {
|
|
620
606
|
type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
|
|
621
607
|
default: undefined;
|
|
@@ -636,8 +622,6 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
636
622
|
y: number;
|
|
637
623
|
dragFn: CoreFnCallback;
|
|
638
624
|
scale: boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[];
|
|
639
|
-
width: number;
|
|
640
|
-
height: number;
|
|
641
625
|
transformScale: number;
|
|
642
626
|
keyboard: boolean;
|
|
643
627
|
handle: string;
|
|
@@ -646,6 +630,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
646
630
|
lockAspectRatio: boolean;
|
|
647
631
|
disabledDrag: boolean;
|
|
648
632
|
disabledResize: boolean;
|
|
633
|
+
disabledSelect: boolean;
|
|
649
634
|
fixNonMonospaced: boolean;
|
|
650
635
|
modelValue: Partial<{
|
|
651
636
|
x: number;
|
|
@@ -653,6 +638,8 @@ declare const FreeDom: vue_demi.DefineComponent<{
|
|
|
653
638
|
w: number;
|
|
654
639
|
h: number;
|
|
655
640
|
}>;
|
|
641
|
+
width: number;
|
|
642
|
+
height: number;
|
|
656
643
|
dragStartFn: CoreFnCallback;
|
|
657
644
|
dragStopFn: CoreFnCallback;
|
|
658
645
|
resizeStartFn: (evt: MouseEvent, resizeData: ResizeData) => void;
|
|
@@ -804,11 +791,11 @@ declare const ResizeDomCore: vue_demi.DefineComponent<{
|
|
|
804
791
|
startFn: ResizeFnCallback;
|
|
805
792
|
stopFn: ResizeFnCallback;
|
|
806
793
|
scale: boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[];
|
|
807
|
-
width: number;
|
|
808
|
-
height: number;
|
|
809
794
|
minWidth: number;
|
|
810
795
|
minHeight: number;
|
|
811
796
|
lockAspectRatio: boolean;
|
|
797
|
+
width: number;
|
|
798
|
+
height: number;
|
|
812
799
|
resizeFn: ResizeFnCallback;
|
|
813
800
|
dragOpts: Partial<FreeDomCoreProps>;
|
|
814
801
|
}, {}>;
|
package/dist/index.js
CHANGED
|
@@ -40,13 +40,15 @@ var import_vue_demi = require("vue-demi");
|
|
|
40
40
|
function createRender(comp, attrs = {}, props = {}, listeners = {}) {
|
|
41
41
|
if (!comp)
|
|
42
42
|
return () => null;
|
|
43
|
+
const _listeners = normalizeListeners(listeners);
|
|
43
44
|
const options = import_vue_demi.isVue2 ? {
|
|
44
|
-
...attrs,
|
|
45
|
+
...normalizeAttrs(attrs),
|
|
45
46
|
props,
|
|
46
|
-
|
|
47
|
+
..._listeners
|
|
47
48
|
} : {
|
|
48
49
|
...attrs,
|
|
49
|
-
...props
|
|
50
|
+
...props,
|
|
51
|
+
..._listeners
|
|
50
52
|
};
|
|
51
53
|
if (import_vue_demi.isVue2 && typeof comp === "object" && !("render" in comp)) {
|
|
52
54
|
(0, import_lodash_unified.merge)(comp.data, options);
|
|
@@ -64,6 +66,50 @@ function createRender(comp, attrs = {}, props = {}, listeners = {}) {
|
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
}
|
|
69
|
+
var NATIVE_ON_REGEXP = /^nativeOn([A-Z]\S*)/;
|
|
70
|
+
var ON_REGEXP = /^on([A-Z]\S*)/;
|
|
71
|
+
function normalizeListeners(listeners) {
|
|
72
|
+
const on = {};
|
|
73
|
+
const nativeOn = {};
|
|
74
|
+
let needOn = false;
|
|
75
|
+
let needNativeOn = false;
|
|
76
|
+
Object.entries(listeners).forEach(([key, fn]) => {
|
|
77
|
+
if (import_vue_demi.isVue2) {
|
|
78
|
+
const onName = key.match(ON_REGEXP)?.[1];
|
|
79
|
+
if (onName) {
|
|
80
|
+
needOn = true;
|
|
81
|
+
const name = onName.replace(/\S/, (letter) => letter.toLowerCase());
|
|
82
|
+
on[name] = fn;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const nativeName = key.match(NATIVE_ON_REGEXP)?.[1];
|
|
86
|
+
if (nativeName) {
|
|
87
|
+
needNativeOn = true;
|
|
88
|
+
const name = nativeName.replace(/\S/, (letter) => letter.toLowerCase());
|
|
89
|
+
nativeOn[name] = fn;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
needOn = true;
|
|
93
|
+
const name = key.replace(NATIVE_ON_REGEXP, (_, $1) => `on${$1}`);
|
|
94
|
+
on[name] = fn;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const res = {};
|
|
98
|
+
if (needOn)
|
|
99
|
+
res.on = on;
|
|
100
|
+
if (needNativeOn)
|
|
101
|
+
res.nativeOn = nativeOn;
|
|
102
|
+
return import_vue_demi.isVue2 ? res : res.on;
|
|
103
|
+
}
|
|
104
|
+
function normalizeAttrs(attrs) {
|
|
105
|
+
const { ref: ref15, class: _class, style, ..._attrs } = attrs;
|
|
106
|
+
return {
|
|
107
|
+
ref: ref15,
|
|
108
|
+
class: _class,
|
|
109
|
+
style,
|
|
110
|
+
attrs: _attrs
|
|
111
|
+
};
|
|
112
|
+
}
|
|
67
113
|
|
|
68
114
|
// src/util/index.ts
|
|
69
115
|
var isProduction = process.env.NODE_ENV === "production";
|
|
@@ -379,7 +425,7 @@ function useDraggableData(props) {
|
|
|
379
425
|
// src/hooks/use-scene-context.ts
|
|
380
426
|
var import_vue_demi7 = require("vue-demi");
|
|
381
427
|
var id = 0;
|
|
382
|
-
function useSceneContext(context, props) {
|
|
428
|
+
function useSceneContext(elm, context, props) {
|
|
383
429
|
const SceneContext = (0, import_vue_demi7.inject)(SceneToken, void 0);
|
|
384
430
|
const uuid = id++;
|
|
385
431
|
const handle = (0, import_vue_demi7.computed)(() => SceneContext?.handle || props.handle);
|
|
@@ -388,6 +434,7 @@ function useSceneContext(context, props) {
|
|
|
388
434
|
const minHeight = (0, import_vue_demi7.computed)(() => SceneContext?.minHeight || props.minHeight);
|
|
389
435
|
const disabledDrag = (0, import_vue_demi7.computed)(() => SceneContext?.disabledDrag || props.disabledDrag);
|
|
390
436
|
const disabledResize = (0, import_vue_demi7.computed)(() => SceneContext?.disabledResize || props.disabledResize);
|
|
437
|
+
const disabledSelect = (0, import_vue_demi7.computed)(() => SceneContext?.disabledSelect || props.disabledSelect);
|
|
391
438
|
const scale = (0, import_vue_demi7.computed)(() => SceneContext?.scale || props.scale);
|
|
392
439
|
const transformScale = (0, import_vue_demi7.computed)(() => SceneContext?.transformScale || props.transformScale);
|
|
393
440
|
const fixNonMonospaced = (0, import_vue_demi7.computed)(() => {
|
|
@@ -395,7 +442,12 @@ function useSceneContext(context, props) {
|
|
|
395
442
|
});
|
|
396
443
|
const keyboard = (0, import_vue_demi7.computed)(() => SceneContext?.keyboard || props.keyboard);
|
|
397
444
|
(0, import_vue_demi7.onMounted)(() => {
|
|
398
|
-
|
|
445
|
+
const node = elm.value;
|
|
446
|
+
if (!node) {
|
|
447
|
+
console.warn("[free-dom] mounted failed: element not found");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
SceneContext?.register(node.$el, uuid, context);
|
|
399
451
|
});
|
|
400
452
|
(0, import_vue_demi7.onUnmounted)(() => {
|
|
401
453
|
SceneContext?.remove(uuid);
|
|
@@ -427,6 +479,7 @@ function useSceneContext(context, props) {
|
|
|
427
479
|
minHeight,
|
|
428
480
|
disabledDrag,
|
|
429
481
|
disabledResize,
|
|
482
|
+
disabledSelect,
|
|
430
483
|
fixNonMonospaced,
|
|
431
484
|
transformScale,
|
|
432
485
|
keyboard
|
|
@@ -1190,7 +1243,7 @@ var DEFAULT_UNITS = [
|
|
|
1190
1243
|
];
|
|
1191
1244
|
|
|
1192
1245
|
// src/hooks/use-mask.ts
|
|
1193
|
-
function useMask(target, nodes) {
|
|
1246
|
+
function useMask(target, props, nodes) {
|
|
1194
1247
|
const eventBus = useEventBus();
|
|
1195
1248
|
const startX = (0, import_vue_demi13.ref)(0);
|
|
1196
1249
|
const startY = (0, import_vue_demi13.ref)(0);
|
|
@@ -1209,14 +1262,19 @@ function useMask(target, nodes) {
|
|
|
1209
1262
|
top: startY.value + (height < 0 ? height : 0) + "px",
|
|
1210
1263
|
left: startX.value + (width < 0 ? width : 0) + "px",
|
|
1211
1264
|
width: Math.abs(width) + "px",
|
|
1212
|
-
height: Math.abs(height) + "px"
|
|
1265
|
+
height: Math.abs(height) + "px",
|
|
1266
|
+
zIndex: 1
|
|
1213
1267
|
};
|
|
1214
1268
|
});
|
|
1215
1269
|
const selecting = (0, import_vue_demi13.ref)(false);
|
|
1216
1270
|
const rect = useElementBounding(target);
|
|
1217
1271
|
const ownerDoc = (0, import_vue_demi13.computed)(() => unrefElement(target)?.ownerDocument);
|
|
1272
|
+
const activeNodes = (0, import_vue_demi13.computed)(() => nodes.value.filter((node) => {
|
|
1273
|
+
return !(props.disabledSelect || node.node.disabledSelect);
|
|
1274
|
+
}));
|
|
1218
1275
|
function checkNode() {
|
|
1219
|
-
|
|
1276
|
+
let selectedNode;
|
|
1277
|
+
activeNodes.value.forEach((node) => {
|
|
1220
1278
|
const rect2 = node.node._rect;
|
|
1221
1279
|
if (rect2.x == void 0 || // eslint-disable-next-line eqeqeq
|
|
1222
1280
|
rect2.y == void 0 || // eslint-disable-next-line eqeqeq
|
|
@@ -1227,8 +1285,13 @@ function useMask(target, nodes) {
|
|
|
1227
1285
|
const y1 = rect2.y;
|
|
1228
1286
|
const x2 = x1 + rect2.width;
|
|
1229
1287
|
const y2 = y1 + rect2.height;
|
|
1230
|
-
|
|
1288
|
+
const isSelected = inArea(x1, y1, x2, y2);
|
|
1289
|
+
node.node.selected = isSelected;
|
|
1290
|
+
if (isSelected) {
|
|
1291
|
+
selectedNode = node;
|
|
1292
|
+
}
|
|
1231
1293
|
});
|
|
1294
|
+
selectedNode?.el.focus();
|
|
1232
1295
|
}
|
|
1233
1296
|
function inArea(x1, y1, x2, y2) {
|
|
1234
1297
|
const areaStartX = Math.min(startX.value, lastX.value);
|
|
@@ -1251,6 +1314,8 @@ function useMask(target, nodes) {
|
|
|
1251
1314
|
};
|
|
1252
1315
|
}
|
|
1253
1316
|
function handleMousedown(evt) {
|
|
1317
|
+
if (props.disabledBatch)
|
|
1318
|
+
return;
|
|
1254
1319
|
addUserSelectStyle(ownerDoc.value);
|
|
1255
1320
|
const { x: offsetX, y: offsetY } = offsetFormat(evt);
|
|
1256
1321
|
selecting.value = true;
|
|
@@ -1446,30 +1511,20 @@ var freeDomCore = (0, import_vue_demi15.defineComponent)({
|
|
|
1446
1511
|
},
|
|
1447
1512
|
render() {
|
|
1448
1513
|
const { only } = useDefaultSlot();
|
|
1449
|
-
const vue2Props = {
|
|
1450
|
-
on: {
|
|
1451
|
-
mousedown: (evt) => {
|
|
1452
|
-
evt.stopPropagation();
|
|
1453
|
-
this.mousedownFn(evt);
|
|
1454
|
-
},
|
|
1455
|
-
mouseup: this.mouseupFn
|
|
1456
|
-
}
|
|
1457
|
-
};
|
|
1458
|
-
const vue3Props = {
|
|
1459
|
-
onMousedown: (evt) => {
|
|
1460
|
-
evt.stopPropagation();
|
|
1461
|
-
this.mousedownFn(evt);
|
|
1462
|
-
},
|
|
1463
|
-
onMouseup: this.mouseupFn
|
|
1464
|
-
};
|
|
1465
1514
|
const res = createRender(
|
|
1466
1515
|
// @ts-expect-error: maybe vue2
|
|
1467
1516
|
only,
|
|
1468
1517
|
{ ref: (el) => {
|
|
1469
1518
|
this.coreRef = el;
|
|
1470
1519
|
} },
|
|
1471
|
-
|
|
1472
|
-
|
|
1520
|
+
{},
|
|
1521
|
+
{
|
|
1522
|
+
onMousedown: (evt) => {
|
|
1523
|
+
evt.stopPropagation();
|
|
1524
|
+
this.mousedownFn(evt);
|
|
1525
|
+
},
|
|
1526
|
+
onMouseup: this.mouseupFn
|
|
1527
|
+
}
|
|
1473
1528
|
);
|
|
1474
1529
|
if (typeof res === "function") {
|
|
1475
1530
|
return res();
|
|
@@ -1684,6 +1739,7 @@ var freeDomProps = {
|
|
|
1684
1739
|
minHeight: resizeDomCoreProps.minHeight,
|
|
1685
1740
|
disabledDrag: Boolean,
|
|
1686
1741
|
disabledResize: Boolean,
|
|
1742
|
+
disabledSelect: Boolean,
|
|
1687
1743
|
scale: resizeDomCoreProps.scale,
|
|
1688
1744
|
transformScale: {
|
|
1689
1745
|
type: Number,
|
|
@@ -1721,6 +1777,7 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1721
1777
|
const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
|
|
1722
1778
|
const selected = (0, import_vue_demi17.ref)(false);
|
|
1723
1779
|
const context = (0, import_vue_demi17.reactive)({
|
|
1780
|
+
disabledSelect: (0, import_vue_demi17.toRef)(props, "disabledSelect"),
|
|
1724
1781
|
selected,
|
|
1725
1782
|
_rect: (0, import_vue_demi17.reactive)({
|
|
1726
1783
|
x,
|
|
@@ -1734,7 +1791,7 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1734
1791
|
emit("update:modelValue", pos);
|
|
1735
1792
|
}
|
|
1736
1793
|
});
|
|
1737
|
-
const sceneContext = useSceneContext(context, props);
|
|
1794
|
+
const sceneContext = useSceneContext(domRef, context, props);
|
|
1738
1795
|
onClickOutside(domRef, () => {
|
|
1739
1796
|
if (!selected.value || isBatchSelecting.value)
|
|
1740
1797
|
return;
|
|
@@ -1750,8 +1807,6 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1750
1807
|
const canDrag = (0, import_vue_demi17.ref)(false);
|
|
1751
1808
|
(0, import_vue_demi17.onMounted)(() => {
|
|
1752
1809
|
props.autoSize && syncSize();
|
|
1753
|
-
const pos = sceneContext.correct(context._rect);
|
|
1754
|
-
context.trigger({ x: pos.x, y: pos.y, w: pos.width, h: pos.height });
|
|
1755
1810
|
});
|
|
1756
1811
|
const style = (0, import_vue_demi17.computed)(() => ({
|
|
1757
1812
|
width: `${width.value}px`,
|
|
@@ -1869,6 +1924,8 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1869
1924
|
return createRender(resizeDomCore_default, {}, props2)(slots);
|
|
1870
1925
|
};
|
|
1871
1926
|
function handleSelect(evt) {
|
|
1927
|
+
if (sceneContext.disabledSelect.value)
|
|
1928
|
+
return;
|
|
1872
1929
|
if (evt.ctrlKey) {
|
|
1873
1930
|
selected.value = !selected.value;
|
|
1874
1931
|
sceneContext.history?.push({ type: "select" });
|
|
@@ -1879,23 +1936,32 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1879
1936
|
}
|
|
1880
1937
|
}
|
|
1881
1938
|
function handleKeyboard(evt) {
|
|
1882
|
-
if (
|
|
1939
|
+
if (sceneContext.disabledDrag.value || !sceneContext.keyboard.value)
|
|
1883
1940
|
return;
|
|
1884
1941
|
evt.preventDefault();
|
|
1885
1942
|
switch (evt.key) {
|
|
1886
1943
|
case "ArrowUp":
|
|
1887
|
-
|
|
1944
|
+
deltaY.value = -1;
|
|
1945
|
+
deltaX.value = 0;
|
|
1888
1946
|
break;
|
|
1889
1947
|
case "ArrowDown":
|
|
1890
|
-
|
|
1948
|
+
deltaY.value = 1;
|
|
1949
|
+
deltaX.value = 0;
|
|
1891
1950
|
break;
|
|
1892
1951
|
case "ArrowLeft":
|
|
1893
|
-
|
|
1952
|
+
deltaX.value = -1;
|
|
1953
|
+
deltaY.value = 0;
|
|
1894
1954
|
break;
|
|
1895
1955
|
case "ArrowRight":
|
|
1896
|
-
|
|
1956
|
+
deltaX.value = 1;
|
|
1957
|
+
deltaY.value = 0;
|
|
1897
1958
|
break;
|
|
1959
|
+
default:
|
|
1960
|
+
deltaX.value = 0;
|
|
1961
|
+
deltaY.value = 0;
|
|
1898
1962
|
}
|
|
1963
|
+
x.value += deltaX.value;
|
|
1964
|
+
y.value += deltaY.value;
|
|
1899
1965
|
const newPos = {
|
|
1900
1966
|
x: x.value,
|
|
1901
1967
|
y: y.value,
|
|
@@ -1935,19 +2001,7 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1935
2001
|
stopFn: this.onDragStop,
|
|
1936
2002
|
dragFn: this.onDrag,
|
|
1937
2003
|
disabled: this.disabled,
|
|
1938
|
-
scale: this.scale
|
|
1939
|
-
keyboard: this.keyboard
|
|
1940
|
-
};
|
|
1941
|
-
const vue2Listener = {
|
|
1942
|
-
on: {
|
|
1943
|
-
click: this.handleSelect,
|
|
1944
|
-
keydown: this.handleKeyboard
|
|
1945
|
-
}
|
|
1946
|
-
};
|
|
1947
|
-
const vue3Props = {
|
|
1948
|
-
...props,
|
|
1949
|
-
onClick: this.handleSelect,
|
|
1950
|
-
onKeydown: this.handleKeyboard
|
|
2004
|
+
scale: this.scale
|
|
1951
2005
|
};
|
|
1952
2006
|
const slots = () => this.resizeNode();
|
|
1953
2007
|
return createRender(
|
|
@@ -1962,8 +2016,11 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
|
|
|
1962
2016
|
],
|
|
1963
2017
|
style: this.style
|
|
1964
2018
|
},
|
|
1965
|
-
|
|
1966
|
-
|
|
2019
|
+
props,
|
|
2020
|
+
{
|
|
2021
|
+
nativeOnClick: this.handleSelect,
|
|
2022
|
+
nativeOnKeydown: this.handleKeyboard
|
|
2023
|
+
}
|
|
1967
2024
|
)?.(slots);
|
|
1968
2025
|
}
|
|
1969
2026
|
});
|
|
@@ -1971,14 +2028,6 @@ var freeDom_default = freeDom;
|
|
|
1971
2028
|
|
|
1972
2029
|
// src/components/freeDomWrap.ts
|
|
1973
2030
|
var freeDomWrapProps = {
|
|
1974
|
-
width: {
|
|
1975
|
-
type: Number,
|
|
1976
|
-
default: void 0
|
|
1977
|
-
},
|
|
1978
|
-
height: {
|
|
1979
|
-
type: Number,
|
|
1980
|
-
default: void 0
|
|
1981
|
-
},
|
|
1982
2031
|
diff: {
|
|
1983
2032
|
type: Number,
|
|
1984
2033
|
default: 2
|
|
@@ -1992,12 +2041,14 @@ var freeDomWrapProps = {
|
|
|
1992
2041
|
default: 1
|
|
1993
2042
|
},
|
|
1994
2043
|
keyboard: Boolean,
|
|
2044
|
+
disabledBatch: Boolean,
|
|
1995
2045
|
handle: freeDomProps.handle,
|
|
1996
2046
|
minWidth: freeDomProps.minWidth,
|
|
1997
2047
|
minHeight: freeDomProps.minHeight,
|
|
1998
2048
|
lockAspectRatio: freeDomProps.lockAspectRatio,
|
|
1999
2049
|
disabledDrag: freeDomProps.disabledDrag,
|
|
2000
2050
|
disabledResize: freeDomProps.disabledResize,
|
|
2051
|
+
disabledSelect: freeDomProps.disabledSelect,
|
|
2001
2052
|
scale: freeDomProps.scale,
|
|
2002
2053
|
fixNonMonospaced: freeDomProps.fixNonMonospaced
|
|
2003
2054
|
};
|
|
@@ -2006,11 +2057,23 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
|
|
|
2006
2057
|
props: freeDomWrapProps,
|
|
2007
2058
|
setup(props) {
|
|
2008
2059
|
const eventBus = useEventBus();
|
|
2009
|
-
const rectRef = (0, import_vue_demi18.shallowRef)();
|
|
2010
2060
|
const nodes = (0, import_vue_demi18.ref)([]);
|
|
2011
2061
|
const history = useOperateHistory(nodes);
|
|
2012
|
-
const width = (0, import_vue_demi18.ref)(
|
|
2013
|
-
const height = (0, import_vue_demi18.ref)(
|
|
2062
|
+
const width = (0, import_vue_demi18.ref)(0);
|
|
2063
|
+
const height = (0, import_vue_demi18.ref)(0);
|
|
2064
|
+
const rectRef = (0, import_vue_demi18.shallowRef)();
|
|
2065
|
+
const wrapRect = useElementBounding(rectRef);
|
|
2066
|
+
(0, import_vue_demi18.watch)([
|
|
2067
|
+
wrapRect.width,
|
|
2068
|
+
wrapRect.height,
|
|
2069
|
+
() => nodes.value.length
|
|
2070
|
+
], ([w, h7]) => {
|
|
2071
|
+
width.value = w;
|
|
2072
|
+
height.value = h7;
|
|
2073
|
+
if (!w || !h7)
|
|
2074
|
+
return;
|
|
2075
|
+
runCorrect();
|
|
2076
|
+
});
|
|
2014
2077
|
const selectedNodes = (0, import_vue_demi18.computed)(() => nodes.value.filter((node) => node.node.selected));
|
|
2015
2078
|
eventBus.on("move", (nodeId) => {
|
|
2016
2079
|
const mainNode = selectedNodes.value.find((node) => node.uuid === nodeId);
|
|
@@ -2025,24 +2088,8 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
|
|
|
2025
2088
|
});
|
|
2026
2089
|
});
|
|
2027
2090
|
const selecting = (0, import_vue_demi18.ref)(false);
|
|
2028
|
-
const mask = useMask(rectRef, nodes);
|
|
2029
|
-
|
|
2030
|
-
width.value = props.width;
|
|
2031
|
-
});
|
|
2032
|
-
(0, import_vue_demi18.watchEffect)(() => {
|
|
2033
|
-
height.value = props.height;
|
|
2034
|
-
});
|
|
2035
|
-
(0, import_vue_demi18.onMounted)(() => {
|
|
2036
|
-
if (!props.width || !props.height) {
|
|
2037
|
-
if (!rectRef.value)
|
|
2038
|
-
console.warn("[free-dom] cannot find element, width or height may be set to 0");
|
|
2039
|
-
const h7 = rectRef.value?.clientHeight;
|
|
2040
|
-
const w = rectRef.value?.clientWidth;
|
|
2041
|
-
if (!props.width)
|
|
2042
|
-
width.value = w || 0;
|
|
2043
|
-
if (!props.height)
|
|
2044
|
-
height.value = h7 || 0;
|
|
2045
|
-
}
|
|
2091
|
+
const mask = useMask(rectRef, props, nodes);
|
|
2092
|
+
function runCorrect() {
|
|
2046
2093
|
nodes.value.forEach((pos) => {
|
|
2047
2094
|
const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
|
|
2048
2095
|
pos.node._rect.x = x;
|
|
@@ -2051,9 +2098,10 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
|
|
|
2051
2098
|
pos.node._rect.height = height2;
|
|
2052
2099
|
pos.node.trigger({ x, y, w: width2, h: height2 });
|
|
2053
2100
|
});
|
|
2054
|
-
}
|
|
2055
|
-
function register(uuid, node) {
|
|
2101
|
+
}
|
|
2102
|
+
function register(el, uuid, node) {
|
|
2056
2103
|
nodes.value.push({
|
|
2104
|
+
el,
|
|
2057
2105
|
uuid,
|
|
2058
2106
|
node
|
|
2059
2107
|
});
|
|
@@ -2064,9 +2112,7 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
|
|
|
2064
2112
|
}
|
|
2065
2113
|
function checkValid(pos) {
|
|
2066
2114
|
const { x, y, width: w, height: h7 } = pos;
|
|
2067
|
-
return x >= 0 &&
|
|
2068
|
-
x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
|
|
2069
|
-
y + h7 <= height.value;
|
|
2115
|
+
return x >= 0 && x + w <= width.value && y >= 0 && y + h7 <= height.value;
|
|
2070
2116
|
}
|
|
2071
2117
|
function correct(pos) {
|
|
2072
2118
|
let x = Math.max(pos.x, 0);
|
|
@@ -2117,13 +2163,8 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
|
|
|
2117
2163
|
emit: eventBus.emit
|
|
2118
2164
|
})
|
|
2119
2165
|
);
|
|
2120
|
-
const style = (0, import_vue_demi18.computed)(() => ({
|
|
2121
|
-
width: `${props.width}px`,
|
|
2122
|
-
height: `${props.height}px`
|
|
2123
|
-
}));
|
|
2124
2166
|
return {
|
|
2125
2167
|
rectRef,
|
|
2126
|
-
style,
|
|
2127
2168
|
selecting,
|
|
2128
2169
|
mask,
|
|
2129
2170
|
history
|
|
@@ -2141,9 +2182,9 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
|
|
|
2141
2182
|
"section",
|
|
2142
2183
|
{
|
|
2143
2184
|
ref: "rectRef",
|
|
2144
|
-
class: "vv-free-dom--scene"
|
|
2145
|
-
style: this.style
|
|
2185
|
+
class: "vv-free-dom--scene"
|
|
2146
2186
|
},
|
|
2187
|
+
{},
|
|
2147
2188
|
{
|
|
2148
2189
|
onMousedown: this.mask.handleMousedown,
|
|
2149
2190
|
onMousemove: this.mask.handleMousemove
|
package/dist/index.mjs
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
computed as computed11,
|
|
4
4
|
defineComponent as defineComponent6,
|
|
5
|
-
onMounted as onMounted5,
|
|
6
5
|
provide as provide2,
|
|
7
6
|
reactive as reactive5,
|
|
8
7
|
ref as ref13,
|
|
9
8
|
shallowRef as shallowRef6,
|
|
10
9
|
toRefs as toRefs2,
|
|
11
|
-
|
|
10
|
+
watch as watch4
|
|
12
11
|
} from "vue-demi";
|
|
13
12
|
|
|
14
13
|
// src/util/tokens.ts
|
|
@@ -20,13 +19,15 @@ import { h, isVue2 } from "vue-demi";
|
|
|
20
19
|
function createRender(comp, attrs = {}, props = {}, listeners = {}) {
|
|
21
20
|
if (!comp)
|
|
22
21
|
return () => null;
|
|
22
|
+
const _listeners = normalizeListeners(listeners);
|
|
23
23
|
const options = isVue2 ? {
|
|
24
|
-
...attrs,
|
|
24
|
+
...normalizeAttrs(attrs),
|
|
25
25
|
props,
|
|
26
|
-
|
|
26
|
+
..._listeners
|
|
27
27
|
} : {
|
|
28
28
|
...attrs,
|
|
29
|
-
...props
|
|
29
|
+
...props,
|
|
30
|
+
..._listeners
|
|
30
31
|
};
|
|
31
32
|
if (isVue2 && typeof comp === "object" && !("render" in comp)) {
|
|
32
33
|
merge(comp.data, options);
|
|
@@ -44,6 +45,50 @@ function createRender(comp, attrs = {}, props = {}, listeners = {}) {
|
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
var NATIVE_ON_REGEXP = /^nativeOn([A-Z]\S*)/;
|
|
49
|
+
var ON_REGEXP = /^on([A-Z]\S*)/;
|
|
50
|
+
function normalizeListeners(listeners) {
|
|
51
|
+
const on = {};
|
|
52
|
+
const nativeOn = {};
|
|
53
|
+
let needOn = false;
|
|
54
|
+
let needNativeOn = false;
|
|
55
|
+
Object.entries(listeners).forEach(([key, fn]) => {
|
|
56
|
+
if (isVue2) {
|
|
57
|
+
const onName = key.match(ON_REGEXP)?.[1];
|
|
58
|
+
if (onName) {
|
|
59
|
+
needOn = true;
|
|
60
|
+
const name = onName.replace(/\S/, (letter) => letter.toLowerCase());
|
|
61
|
+
on[name] = fn;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const nativeName = key.match(NATIVE_ON_REGEXP)?.[1];
|
|
65
|
+
if (nativeName) {
|
|
66
|
+
needNativeOn = true;
|
|
67
|
+
const name = nativeName.replace(/\S/, (letter) => letter.toLowerCase());
|
|
68
|
+
nativeOn[name] = fn;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
needOn = true;
|
|
72
|
+
const name = key.replace(NATIVE_ON_REGEXP, (_, $1) => `on${$1}`);
|
|
73
|
+
on[name] = fn;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const res = {};
|
|
77
|
+
if (needOn)
|
|
78
|
+
res.on = on;
|
|
79
|
+
if (needNativeOn)
|
|
80
|
+
res.nativeOn = nativeOn;
|
|
81
|
+
return isVue2 ? res : res.on;
|
|
82
|
+
}
|
|
83
|
+
function normalizeAttrs(attrs) {
|
|
84
|
+
const { ref: ref15, class: _class, style, ..._attrs } = attrs;
|
|
85
|
+
return {
|
|
86
|
+
ref: ref15,
|
|
87
|
+
class: _class,
|
|
88
|
+
style,
|
|
89
|
+
attrs: _attrs
|
|
90
|
+
};
|
|
91
|
+
}
|
|
47
92
|
|
|
48
93
|
// src/util/index.ts
|
|
49
94
|
var isProduction = process.env.NODE_ENV === "production";
|
|
@@ -359,7 +404,7 @@ function useDraggableData(props) {
|
|
|
359
404
|
// src/hooks/use-scene-context.ts
|
|
360
405
|
import { computed as computed2, inject as inject2, onMounted, onUnmounted } from "vue-demi";
|
|
361
406
|
var id = 0;
|
|
362
|
-
function useSceneContext(context, props) {
|
|
407
|
+
function useSceneContext(elm, context, props) {
|
|
363
408
|
const SceneContext = inject2(SceneToken, void 0);
|
|
364
409
|
const uuid = id++;
|
|
365
410
|
const handle = computed2(() => SceneContext?.handle || props.handle);
|
|
@@ -368,6 +413,7 @@ function useSceneContext(context, props) {
|
|
|
368
413
|
const minHeight = computed2(() => SceneContext?.minHeight || props.minHeight);
|
|
369
414
|
const disabledDrag = computed2(() => SceneContext?.disabledDrag || props.disabledDrag);
|
|
370
415
|
const disabledResize = computed2(() => SceneContext?.disabledResize || props.disabledResize);
|
|
416
|
+
const disabledSelect = computed2(() => SceneContext?.disabledSelect || props.disabledSelect);
|
|
371
417
|
const scale = computed2(() => SceneContext?.scale || props.scale);
|
|
372
418
|
const transformScale = computed2(() => SceneContext?.transformScale || props.transformScale);
|
|
373
419
|
const fixNonMonospaced = computed2(() => {
|
|
@@ -375,7 +421,12 @@ function useSceneContext(context, props) {
|
|
|
375
421
|
});
|
|
376
422
|
const keyboard = computed2(() => SceneContext?.keyboard || props.keyboard);
|
|
377
423
|
onMounted(() => {
|
|
378
|
-
|
|
424
|
+
const node = elm.value;
|
|
425
|
+
if (!node) {
|
|
426
|
+
console.warn("[free-dom] mounted failed: element not found");
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
SceneContext?.register(node.$el, uuid, context);
|
|
379
430
|
});
|
|
380
431
|
onUnmounted(() => {
|
|
381
432
|
SceneContext?.remove(uuid);
|
|
@@ -407,6 +458,7 @@ function useSceneContext(context, props) {
|
|
|
407
458
|
minHeight,
|
|
408
459
|
disabledDrag,
|
|
409
460
|
disabledResize,
|
|
461
|
+
disabledSelect,
|
|
410
462
|
fixNonMonospaced,
|
|
411
463
|
transformScale,
|
|
412
464
|
keyboard
|
|
@@ -1170,7 +1222,7 @@ var DEFAULT_UNITS = [
|
|
|
1170
1222
|
];
|
|
1171
1223
|
|
|
1172
1224
|
// src/hooks/use-mask.ts
|
|
1173
|
-
function useMask(target, nodes) {
|
|
1225
|
+
function useMask(target, props, nodes) {
|
|
1174
1226
|
const eventBus = useEventBus();
|
|
1175
1227
|
const startX = ref9(0);
|
|
1176
1228
|
const startY = ref9(0);
|
|
@@ -1189,14 +1241,19 @@ function useMask(target, nodes) {
|
|
|
1189
1241
|
top: startY.value + (height < 0 ? height : 0) + "px",
|
|
1190
1242
|
left: startX.value + (width < 0 ? width : 0) + "px",
|
|
1191
1243
|
width: Math.abs(width) + "px",
|
|
1192
|
-
height: Math.abs(height) + "px"
|
|
1244
|
+
height: Math.abs(height) + "px",
|
|
1245
|
+
zIndex: 1
|
|
1193
1246
|
};
|
|
1194
1247
|
});
|
|
1195
1248
|
const selecting = ref9(false);
|
|
1196
1249
|
const rect = useElementBounding(target);
|
|
1197
1250
|
const ownerDoc = computed6(() => unrefElement(target)?.ownerDocument);
|
|
1251
|
+
const activeNodes = computed6(() => nodes.value.filter((node) => {
|
|
1252
|
+
return !(props.disabledSelect || node.node.disabledSelect);
|
|
1253
|
+
}));
|
|
1198
1254
|
function checkNode() {
|
|
1199
|
-
|
|
1255
|
+
let selectedNode;
|
|
1256
|
+
activeNodes.value.forEach((node) => {
|
|
1200
1257
|
const rect2 = node.node._rect;
|
|
1201
1258
|
if (rect2.x == void 0 || // eslint-disable-next-line eqeqeq
|
|
1202
1259
|
rect2.y == void 0 || // eslint-disable-next-line eqeqeq
|
|
@@ -1207,8 +1264,13 @@ function useMask(target, nodes) {
|
|
|
1207
1264
|
const y1 = rect2.y;
|
|
1208
1265
|
const x2 = x1 + rect2.width;
|
|
1209
1266
|
const y2 = y1 + rect2.height;
|
|
1210
|
-
|
|
1267
|
+
const isSelected = inArea(x1, y1, x2, y2);
|
|
1268
|
+
node.node.selected = isSelected;
|
|
1269
|
+
if (isSelected) {
|
|
1270
|
+
selectedNode = node;
|
|
1271
|
+
}
|
|
1211
1272
|
});
|
|
1273
|
+
selectedNode?.el.focus();
|
|
1212
1274
|
}
|
|
1213
1275
|
function inArea(x1, y1, x2, y2) {
|
|
1214
1276
|
const areaStartX = Math.min(startX.value, lastX.value);
|
|
@@ -1231,6 +1293,8 @@ function useMask(target, nodes) {
|
|
|
1231
1293
|
};
|
|
1232
1294
|
}
|
|
1233
1295
|
function handleMousedown(evt) {
|
|
1296
|
+
if (props.disabledBatch)
|
|
1297
|
+
return;
|
|
1234
1298
|
addUserSelectStyle(ownerDoc.value);
|
|
1235
1299
|
const { x: offsetX, y: offsetY } = offsetFormat(evt);
|
|
1236
1300
|
selecting.value = true;
|
|
@@ -1311,10 +1375,10 @@ function useOperateHistory(nodes) {
|
|
|
1311
1375
|
}
|
|
1312
1376
|
|
|
1313
1377
|
// src/components/freeDom.ts
|
|
1314
|
-
import { computed as computed10, defineComponent as defineComponent5,
|
|
1378
|
+
import { computed as computed10, defineComponent as defineComponent5, onMounted as onMounted4, reactive as reactive4, ref as ref12, toRef as toRef2 } from "vue-demi";
|
|
1315
1379
|
|
|
1316
1380
|
// src/components/freeDomCore.ts
|
|
1317
|
-
import { computed as computed8, defineComponent as defineComponent3,
|
|
1381
|
+
import { computed as computed8, defineComponent as defineComponent3, onUnmounted as onUnmounted3, ref as ref11 } from "vue-demi";
|
|
1318
1382
|
function noop2() {
|
|
1319
1383
|
}
|
|
1320
1384
|
var freeDomCoreProps = {
|
|
@@ -1426,30 +1490,20 @@ var freeDomCore = defineComponent3({
|
|
|
1426
1490
|
},
|
|
1427
1491
|
render() {
|
|
1428
1492
|
const { only } = useDefaultSlot();
|
|
1429
|
-
const vue2Props = {
|
|
1430
|
-
on: {
|
|
1431
|
-
mousedown: (evt) => {
|
|
1432
|
-
evt.stopPropagation();
|
|
1433
|
-
this.mousedownFn(evt);
|
|
1434
|
-
},
|
|
1435
|
-
mouseup: this.mouseupFn
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
const vue3Props = {
|
|
1439
|
-
onMousedown: (evt) => {
|
|
1440
|
-
evt.stopPropagation();
|
|
1441
|
-
this.mousedownFn(evt);
|
|
1442
|
-
},
|
|
1443
|
-
onMouseup: this.mouseupFn
|
|
1444
|
-
};
|
|
1445
1493
|
const res = createRender(
|
|
1446
1494
|
// @ts-expect-error: maybe vue2
|
|
1447
1495
|
only,
|
|
1448
1496
|
{ ref: (el) => {
|
|
1449
1497
|
this.coreRef = el;
|
|
1450
1498
|
} },
|
|
1451
|
-
|
|
1452
|
-
|
|
1499
|
+
{},
|
|
1500
|
+
{
|
|
1501
|
+
onMousedown: (evt) => {
|
|
1502
|
+
evt.stopPropagation();
|
|
1503
|
+
this.mousedownFn(evt);
|
|
1504
|
+
},
|
|
1505
|
+
onMouseup: this.mouseupFn
|
|
1506
|
+
}
|
|
1453
1507
|
);
|
|
1454
1508
|
if (typeof res === "function") {
|
|
1455
1509
|
return res();
|
|
@@ -1664,6 +1718,7 @@ var freeDomProps = {
|
|
|
1664
1718
|
minHeight: resizeDomCoreProps.minHeight,
|
|
1665
1719
|
disabledDrag: Boolean,
|
|
1666
1720
|
disabledResize: Boolean,
|
|
1721
|
+
disabledSelect: Boolean,
|
|
1667
1722
|
scale: resizeDomCoreProps.scale,
|
|
1668
1723
|
transformScale: {
|
|
1669
1724
|
type: Number,
|
|
@@ -1701,6 +1756,7 @@ var freeDom = defineComponent5({
|
|
|
1701
1756
|
const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
|
|
1702
1757
|
const selected = ref12(false);
|
|
1703
1758
|
const context = reactive4({
|
|
1759
|
+
disabledSelect: toRef2(props, "disabledSelect"),
|
|
1704
1760
|
selected,
|
|
1705
1761
|
_rect: reactive4({
|
|
1706
1762
|
x,
|
|
@@ -1714,7 +1770,7 @@ var freeDom = defineComponent5({
|
|
|
1714
1770
|
emit("update:modelValue", pos);
|
|
1715
1771
|
}
|
|
1716
1772
|
});
|
|
1717
|
-
const sceneContext = useSceneContext(context, props);
|
|
1773
|
+
const sceneContext = useSceneContext(domRef, context, props);
|
|
1718
1774
|
onClickOutside(domRef, () => {
|
|
1719
1775
|
if (!selected.value || isBatchSelecting.value)
|
|
1720
1776
|
return;
|
|
@@ -1730,8 +1786,6 @@ var freeDom = defineComponent5({
|
|
|
1730
1786
|
const canDrag = ref12(false);
|
|
1731
1787
|
onMounted4(() => {
|
|
1732
1788
|
props.autoSize && syncSize();
|
|
1733
|
-
const pos = sceneContext.correct(context._rect);
|
|
1734
|
-
context.trigger({ x: pos.x, y: pos.y, w: pos.width, h: pos.height });
|
|
1735
1789
|
});
|
|
1736
1790
|
const style = computed10(() => ({
|
|
1737
1791
|
width: `${width.value}px`,
|
|
@@ -1849,6 +1903,8 @@ var freeDom = defineComponent5({
|
|
|
1849
1903
|
return createRender(resizeDomCore_default, {}, props2)(slots);
|
|
1850
1904
|
};
|
|
1851
1905
|
function handleSelect(evt) {
|
|
1906
|
+
if (sceneContext.disabledSelect.value)
|
|
1907
|
+
return;
|
|
1852
1908
|
if (evt.ctrlKey) {
|
|
1853
1909
|
selected.value = !selected.value;
|
|
1854
1910
|
sceneContext.history?.push({ type: "select" });
|
|
@@ -1859,23 +1915,32 @@ var freeDom = defineComponent5({
|
|
|
1859
1915
|
}
|
|
1860
1916
|
}
|
|
1861
1917
|
function handleKeyboard(evt) {
|
|
1862
|
-
if (
|
|
1918
|
+
if (sceneContext.disabledDrag.value || !sceneContext.keyboard.value)
|
|
1863
1919
|
return;
|
|
1864
1920
|
evt.preventDefault();
|
|
1865
1921
|
switch (evt.key) {
|
|
1866
1922
|
case "ArrowUp":
|
|
1867
|
-
|
|
1923
|
+
deltaY.value = -1;
|
|
1924
|
+
deltaX.value = 0;
|
|
1868
1925
|
break;
|
|
1869
1926
|
case "ArrowDown":
|
|
1870
|
-
|
|
1927
|
+
deltaY.value = 1;
|
|
1928
|
+
deltaX.value = 0;
|
|
1871
1929
|
break;
|
|
1872
1930
|
case "ArrowLeft":
|
|
1873
|
-
|
|
1931
|
+
deltaX.value = -1;
|
|
1932
|
+
deltaY.value = 0;
|
|
1874
1933
|
break;
|
|
1875
1934
|
case "ArrowRight":
|
|
1876
|
-
|
|
1935
|
+
deltaX.value = 1;
|
|
1936
|
+
deltaY.value = 0;
|
|
1877
1937
|
break;
|
|
1938
|
+
default:
|
|
1939
|
+
deltaX.value = 0;
|
|
1940
|
+
deltaY.value = 0;
|
|
1878
1941
|
}
|
|
1942
|
+
x.value += deltaX.value;
|
|
1943
|
+
y.value += deltaY.value;
|
|
1879
1944
|
const newPos = {
|
|
1880
1945
|
x: x.value,
|
|
1881
1946
|
y: y.value,
|
|
@@ -1915,19 +1980,7 @@ var freeDom = defineComponent5({
|
|
|
1915
1980
|
stopFn: this.onDragStop,
|
|
1916
1981
|
dragFn: this.onDrag,
|
|
1917
1982
|
disabled: this.disabled,
|
|
1918
|
-
scale: this.scale
|
|
1919
|
-
keyboard: this.keyboard
|
|
1920
|
-
};
|
|
1921
|
-
const vue2Listener = {
|
|
1922
|
-
on: {
|
|
1923
|
-
click: this.handleSelect,
|
|
1924
|
-
keydown: this.handleKeyboard
|
|
1925
|
-
}
|
|
1926
|
-
};
|
|
1927
|
-
const vue3Props = {
|
|
1928
|
-
...props,
|
|
1929
|
-
onClick: this.handleSelect,
|
|
1930
|
-
onKeydown: this.handleKeyboard
|
|
1983
|
+
scale: this.scale
|
|
1931
1984
|
};
|
|
1932
1985
|
const slots = () => this.resizeNode();
|
|
1933
1986
|
return createRender(
|
|
@@ -1942,8 +1995,11 @@ var freeDom = defineComponent5({
|
|
|
1942
1995
|
],
|
|
1943
1996
|
style: this.style
|
|
1944
1997
|
},
|
|
1945
|
-
|
|
1946
|
-
|
|
1998
|
+
props,
|
|
1999
|
+
{
|
|
2000
|
+
nativeOnClick: this.handleSelect,
|
|
2001
|
+
nativeOnKeydown: this.handleKeyboard
|
|
2002
|
+
}
|
|
1947
2003
|
)?.(slots);
|
|
1948
2004
|
}
|
|
1949
2005
|
});
|
|
@@ -1951,14 +2007,6 @@ var freeDom_default = freeDom;
|
|
|
1951
2007
|
|
|
1952
2008
|
// src/components/freeDomWrap.ts
|
|
1953
2009
|
var freeDomWrapProps = {
|
|
1954
|
-
width: {
|
|
1955
|
-
type: Number,
|
|
1956
|
-
default: void 0
|
|
1957
|
-
},
|
|
1958
|
-
height: {
|
|
1959
|
-
type: Number,
|
|
1960
|
-
default: void 0
|
|
1961
|
-
},
|
|
1962
2010
|
diff: {
|
|
1963
2011
|
type: Number,
|
|
1964
2012
|
default: 2
|
|
@@ -1972,12 +2020,14 @@ var freeDomWrapProps = {
|
|
|
1972
2020
|
default: 1
|
|
1973
2021
|
},
|
|
1974
2022
|
keyboard: Boolean,
|
|
2023
|
+
disabledBatch: Boolean,
|
|
1975
2024
|
handle: freeDomProps.handle,
|
|
1976
2025
|
minWidth: freeDomProps.minWidth,
|
|
1977
2026
|
minHeight: freeDomProps.minHeight,
|
|
1978
2027
|
lockAspectRatio: freeDomProps.lockAspectRatio,
|
|
1979
2028
|
disabledDrag: freeDomProps.disabledDrag,
|
|
1980
2029
|
disabledResize: freeDomProps.disabledResize,
|
|
2030
|
+
disabledSelect: freeDomProps.disabledSelect,
|
|
1981
2031
|
scale: freeDomProps.scale,
|
|
1982
2032
|
fixNonMonospaced: freeDomProps.fixNonMonospaced
|
|
1983
2033
|
};
|
|
@@ -1986,11 +2036,23 @@ var FreeDomWrap = defineComponent6({
|
|
|
1986
2036
|
props: freeDomWrapProps,
|
|
1987
2037
|
setup(props) {
|
|
1988
2038
|
const eventBus = useEventBus();
|
|
1989
|
-
const rectRef = shallowRef6();
|
|
1990
2039
|
const nodes = ref13([]);
|
|
1991
2040
|
const history = useOperateHistory(nodes);
|
|
1992
|
-
const width = ref13(
|
|
1993
|
-
const height = ref13(
|
|
2041
|
+
const width = ref13(0);
|
|
2042
|
+
const height = ref13(0);
|
|
2043
|
+
const rectRef = shallowRef6();
|
|
2044
|
+
const wrapRect = useElementBounding(rectRef);
|
|
2045
|
+
watch4([
|
|
2046
|
+
wrapRect.width,
|
|
2047
|
+
wrapRect.height,
|
|
2048
|
+
() => nodes.value.length
|
|
2049
|
+
], ([w, h7]) => {
|
|
2050
|
+
width.value = w;
|
|
2051
|
+
height.value = h7;
|
|
2052
|
+
if (!w || !h7)
|
|
2053
|
+
return;
|
|
2054
|
+
runCorrect();
|
|
2055
|
+
});
|
|
1994
2056
|
const selectedNodes = computed11(() => nodes.value.filter((node) => node.node.selected));
|
|
1995
2057
|
eventBus.on("move", (nodeId) => {
|
|
1996
2058
|
const mainNode = selectedNodes.value.find((node) => node.uuid === nodeId);
|
|
@@ -2005,24 +2067,8 @@ var FreeDomWrap = defineComponent6({
|
|
|
2005
2067
|
});
|
|
2006
2068
|
});
|
|
2007
2069
|
const selecting = ref13(false);
|
|
2008
|
-
const mask = useMask(rectRef, nodes);
|
|
2009
|
-
|
|
2010
|
-
width.value = props.width;
|
|
2011
|
-
});
|
|
2012
|
-
watchEffect6(() => {
|
|
2013
|
-
height.value = props.height;
|
|
2014
|
-
});
|
|
2015
|
-
onMounted5(() => {
|
|
2016
|
-
if (!props.width || !props.height) {
|
|
2017
|
-
if (!rectRef.value)
|
|
2018
|
-
console.warn("[free-dom] cannot find element, width or height may be set to 0");
|
|
2019
|
-
const h7 = rectRef.value?.clientHeight;
|
|
2020
|
-
const w = rectRef.value?.clientWidth;
|
|
2021
|
-
if (!props.width)
|
|
2022
|
-
width.value = w || 0;
|
|
2023
|
-
if (!props.height)
|
|
2024
|
-
height.value = h7 || 0;
|
|
2025
|
-
}
|
|
2070
|
+
const mask = useMask(rectRef, props, nodes);
|
|
2071
|
+
function runCorrect() {
|
|
2026
2072
|
nodes.value.forEach((pos) => {
|
|
2027
2073
|
const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
|
|
2028
2074
|
pos.node._rect.x = x;
|
|
@@ -2031,9 +2077,10 @@ var FreeDomWrap = defineComponent6({
|
|
|
2031
2077
|
pos.node._rect.height = height2;
|
|
2032
2078
|
pos.node.trigger({ x, y, w: width2, h: height2 });
|
|
2033
2079
|
});
|
|
2034
|
-
}
|
|
2035
|
-
function register(uuid, node) {
|
|
2080
|
+
}
|
|
2081
|
+
function register(el, uuid, node) {
|
|
2036
2082
|
nodes.value.push({
|
|
2083
|
+
el,
|
|
2037
2084
|
uuid,
|
|
2038
2085
|
node
|
|
2039
2086
|
});
|
|
@@ -2044,9 +2091,7 @@ var FreeDomWrap = defineComponent6({
|
|
|
2044
2091
|
}
|
|
2045
2092
|
function checkValid(pos) {
|
|
2046
2093
|
const { x, y, width: w, height: h7 } = pos;
|
|
2047
|
-
return x >= 0 &&
|
|
2048
|
-
x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
|
|
2049
|
-
y + h7 <= height.value;
|
|
2094
|
+
return x >= 0 && x + w <= width.value && y >= 0 && y + h7 <= height.value;
|
|
2050
2095
|
}
|
|
2051
2096
|
function correct(pos) {
|
|
2052
2097
|
let x = Math.max(pos.x, 0);
|
|
@@ -2097,13 +2142,8 @@ var FreeDomWrap = defineComponent6({
|
|
|
2097
2142
|
emit: eventBus.emit
|
|
2098
2143
|
})
|
|
2099
2144
|
);
|
|
2100
|
-
const style = computed11(() => ({
|
|
2101
|
-
width: `${props.width}px`,
|
|
2102
|
-
height: `${props.height}px`
|
|
2103
|
-
}));
|
|
2104
2145
|
return {
|
|
2105
2146
|
rectRef,
|
|
2106
|
-
style,
|
|
2107
2147
|
selecting,
|
|
2108
2148
|
mask,
|
|
2109
2149
|
history
|
|
@@ -2121,9 +2161,9 @@ var FreeDomWrap = defineComponent6({
|
|
|
2121
2161
|
"section",
|
|
2122
2162
|
{
|
|
2123
2163
|
ref: "rectRef",
|
|
2124
|
-
class: "vv-free-dom--scene"
|
|
2125
|
-
style: this.style
|
|
2164
|
+
class: "vv-free-dom--scene"
|
|
2126
2165
|
},
|
|
2166
|
+
{},
|
|
2127
2167
|
{
|
|
2128
2168
|
onMousedown: this.mask.handleMousedown,
|
|
2129
2169
|
onMousemove: this.mask.handleMousemove
|