@sepveneto/free-dom 0.4.3 → 0.5.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 +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +32 -49
- package/dist/index.mjs +33 -50
- package/package.json +1 -1
package/dist/index.css
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -3,19 +3,19 @@ import * as vue_demi from 'vue-demi';
|
|
|
3
3
|
declare const freeDom: vue_demi.DefineComponent<{
|
|
4
4
|
x: {
|
|
5
5
|
type: NumberConstructor;
|
|
6
|
-
default:
|
|
6
|
+
default: undefined;
|
|
7
7
|
};
|
|
8
8
|
y: {
|
|
9
9
|
type: NumberConstructor;
|
|
10
|
-
default:
|
|
10
|
+
default: undefined;
|
|
11
11
|
};
|
|
12
12
|
width: {
|
|
13
13
|
type: NumberConstructor;
|
|
14
|
-
default:
|
|
14
|
+
default: undefined;
|
|
15
15
|
};
|
|
16
16
|
height: {
|
|
17
17
|
type: NumberConstructor;
|
|
18
|
-
default:
|
|
18
|
+
default: undefined;
|
|
19
19
|
};
|
|
20
20
|
absolute: {
|
|
21
21
|
type: BooleanConstructor;
|
|
@@ -73,19 +73,19 @@ declare const freeDom: vue_demi.DefineComponent<{
|
|
|
73
73
|
}, unknown, {}, {}, vue_demi.ComponentOptionsMixin, vue_demi.ComponentOptionsMixin, ("update:x" | "update:y" | "update:width" | "update:height" | "select")[], "update:x" | "update:y" | "update:width" | "update:height" | "select", vue_demi.VNodeProps & vue_demi.AllowedComponentProps & vue_demi.ComponentCustomProps, Readonly<vue_demi.ExtractPropTypes<{
|
|
74
74
|
x: {
|
|
75
75
|
type: NumberConstructor;
|
|
76
|
-
default:
|
|
76
|
+
default: undefined;
|
|
77
77
|
};
|
|
78
78
|
y: {
|
|
79
79
|
type: NumberConstructor;
|
|
80
|
-
default:
|
|
80
|
+
default: undefined;
|
|
81
81
|
};
|
|
82
82
|
width: {
|
|
83
83
|
type: NumberConstructor;
|
|
84
|
-
default:
|
|
84
|
+
default: undefined;
|
|
85
85
|
};
|
|
86
86
|
height: {
|
|
87
87
|
type: NumberConstructor;
|
|
88
|
-
default:
|
|
88
|
+
default: undefined;
|
|
89
89
|
};
|
|
90
90
|
absolute: {
|
|
91
91
|
type: BooleanConstructor;
|
package/dist/index.js
CHANGED
|
@@ -146,19 +146,19 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
146
146
|
props: {
|
|
147
147
|
x: {
|
|
148
148
|
type: Number,
|
|
149
|
-
default: 0
|
|
149
|
+
default: void 0
|
|
150
150
|
},
|
|
151
151
|
y: {
|
|
152
152
|
type: Number,
|
|
153
|
-
default: 0
|
|
153
|
+
default: void 0
|
|
154
154
|
},
|
|
155
155
|
width: {
|
|
156
156
|
type: Number,
|
|
157
|
-
default: 0
|
|
157
|
+
default: void 0
|
|
158
158
|
},
|
|
159
159
|
height: {
|
|
160
160
|
type: Number,
|
|
161
|
-
default: 0
|
|
161
|
+
default: void 0
|
|
162
162
|
},
|
|
163
163
|
absolute: {
|
|
164
164
|
type: Boolean,
|
|
@@ -216,12 +216,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
216
216
|
const uuid = (0, import_uuid.v4)();
|
|
217
217
|
const isScale = (0, import_vue_demi2.ref)(false);
|
|
218
218
|
const isMove = (0, import_vue_demi2.ref)(false);
|
|
219
|
-
const _rect = (0, import_vue_demi2.reactive)({
|
|
220
|
-
x: 0,
|
|
221
|
-
y: 0,
|
|
222
|
-
width: 0,
|
|
223
|
-
height: 0
|
|
224
|
-
});
|
|
219
|
+
const _rect = (0, import_vue_demi2.reactive)({});
|
|
225
220
|
const context = {
|
|
226
221
|
_rect,
|
|
227
222
|
trigger
|
|
@@ -229,9 +224,17 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
229
224
|
(0, import_core.onClickOutside)(widgetRef, () => {
|
|
230
225
|
active.value = false;
|
|
231
226
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
});
|
|
235
238
|
(0, import_vue_demi2.watch)(
|
|
236
239
|
[
|
|
237
240
|
() => props.width,
|
|
@@ -239,24 +242,27 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
239
242
|
() => props.x,
|
|
240
243
|
() => props.y
|
|
241
244
|
],
|
|
242
|
-
() => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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 && (_rect.x = x);
|
|
255
|
+
y && (_rect.y = y);
|
|
247
256
|
trigger();
|
|
248
257
|
},
|
|
249
258
|
{ immediate: true }
|
|
250
259
|
);
|
|
251
260
|
(0, import_vue_demi2.onMounted)(async () => {
|
|
252
261
|
SceneContext?.register(uuid, context);
|
|
253
|
-
const
|
|
254
|
-
_rect.
|
|
255
|
-
_rect.
|
|
256
|
-
_rect.x = _rect.x || 0;
|
|
257
|
-
_rect.y = _rect.y || 0;
|
|
262
|
+
const { offsetTop, offsetLeft } = widgetRef.value;
|
|
263
|
+
_rect.x = _rect.x || offsetLeft;
|
|
264
|
+
_rect.y = _rect.y || offsetTop;
|
|
258
265
|
trigger();
|
|
259
|
-
emitPos();
|
|
260
266
|
});
|
|
261
267
|
function trigger() {
|
|
262
268
|
const { x, y, width, height } = _rect;
|
|
@@ -314,9 +320,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
314
320
|
emit("update:height", _rect.height);
|
|
315
321
|
}
|
|
316
322
|
function getDotPos(dot) {
|
|
317
|
-
|
|
318
|
-
return {};
|
|
319
|
-
const { width, height } = _style.value;
|
|
323
|
+
const { width, height } = _rect;
|
|
320
324
|
const isL = /l/.test(dot);
|
|
321
325
|
const isR = /r/.test(dot);
|
|
322
326
|
const isT = /t/.test(dot);
|
|
@@ -348,7 +352,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
348
352
|
const shouldUpdate = props.onDragStart?.();
|
|
349
353
|
if (shouldUpdate === false)
|
|
350
354
|
return;
|
|
351
|
-
const pos =
|
|
355
|
+
const pos = { ..._rect };
|
|
352
356
|
const move = (mouseEvt) => {
|
|
353
357
|
const { clientX, clientY } = mouseEvt;
|
|
354
358
|
const x = clientX - evt.clientX + pos.x;
|
|
@@ -384,27 +388,6 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
384
388
|
return true;
|
|
385
389
|
}
|
|
386
390
|
}
|
|
387
|
-
function getStyle(style) {
|
|
388
|
-
const { transform, width, height } = style;
|
|
389
|
-
const { x, y } = getPos(transform);
|
|
390
|
-
return {
|
|
391
|
-
x: x ? Number(x) : 0,
|
|
392
|
-
y: y ? Number(y) : 0,
|
|
393
|
-
width: parseFloat(width),
|
|
394
|
-
height: parseFloat(height)
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
function getPos(transform) {
|
|
398
|
-
if (!transform) {
|
|
399
|
-
return {
|
|
400
|
-
x: 0,
|
|
401
|
-
y: 0
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
const posRegexp = /translate\(([.0-9]+)px[, ]+([.0-9]+)px\)/;
|
|
405
|
-
const [, x, y] = posRegexp.exec(transform) ?? [];
|
|
406
|
-
return { x: parseNum(x), y: parseNum(y) };
|
|
407
|
-
}
|
|
408
391
|
return {
|
|
409
392
|
widgetRef,
|
|
410
393
|
canMove,
|
package/dist/index.mjs
CHANGED
|
@@ -124,7 +124,7 @@ function useResize(startX, startY, rect, dot, diagonal, snapGrid, callbacks) {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// src/components/freeDom.ts
|
|
127
|
-
import { onClickOutside } from "@vueuse/core";
|
|
127
|
+
import { onClickOutside, useElementSize } from "@vueuse/core";
|
|
128
128
|
import { v4 as uuidv4 } from "uuid";
|
|
129
129
|
var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
|
|
130
130
|
var FreeDom = defineComponent({
|
|
@@ -132,19 +132,19 @@ var FreeDom = defineComponent({
|
|
|
132
132
|
props: {
|
|
133
133
|
x: {
|
|
134
134
|
type: Number,
|
|
135
|
-
default: 0
|
|
135
|
+
default: void 0
|
|
136
136
|
},
|
|
137
137
|
y: {
|
|
138
138
|
type: Number,
|
|
139
|
-
default: 0
|
|
139
|
+
default: void 0
|
|
140
140
|
},
|
|
141
141
|
width: {
|
|
142
142
|
type: Number,
|
|
143
|
-
default: 0
|
|
143
|
+
default: void 0
|
|
144
144
|
},
|
|
145
145
|
height: {
|
|
146
146
|
type: Number,
|
|
147
|
-
default: 0
|
|
147
|
+
default: void 0
|
|
148
148
|
},
|
|
149
149
|
absolute: {
|
|
150
150
|
type: Boolean,
|
|
@@ -202,12 +202,7 @@ var FreeDom = defineComponent({
|
|
|
202
202
|
const uuid = uuidv4();
|
|
203
203
|
const isScale = ref2(false);
|
|
204
204
|
const isMove = ref2(false);
|
|
205
|
-
const _rect = reactive({
|
|
206
|
-
x: 0,
|
|
207
|
-
y: 0,
|
|
208
|
-
width: 0,
|
|
209
|
-
height: 0
|
|
210
|
-
});
|
|
205
|
+
const _rect = reactive({});
|
|
211
206
|
const context = {
|
|
212
207
|
_rect,
|
|
213
208
|
trigger
|
|
@@ -215,9 +210,17 @@ var FreeDom = defineComponent({
|
|
|
215
210
|
onClickOutside(widgetRef, () => {
|
|
216
211
|
active.value = false;
|
|
217
212
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
let rectSize = reactive(useElementSize(widgetRef));
|
|
214
|
+
let autoWidth = true;
|
|
215
|
+
let autoHeight = true;
|
|
216
|
+
const unwatch = watch2(rectSize, ({ width, height }) => {
|
|
217
|
+
if (autoWidth && width) {
|
|
218
|
+
_rect.width = width;
|
|
219
|
+
}
|
|
220
|
+
if (autoHeight && height) {
|
|
221
|
+
_rect.height = height;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
221
224
|
watch2(
|
|
222
225
|
[
|
|
223
226
|
() => props.width,
|
|
@@ -225,24 +228,27 @@ var FreeDom = defineComponent({
|
|
|
225
228
|
() => props.x,
|
|
226
229
|
() => props.y
|
|
227
230
|
],
|
|
228
|
-
() => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
([width, height, x, y]) => {
|
|
232
|
+
autoWidth = width === _rect.width;
|
|
233
|
+
autoHeight = height === _rect.height;
|
|
234
|
+
if (!autoHeight && !autoWidth) {
|
|
235
|
+
unwatch();
|
|
236
|
+
rectSize = null;
|
|
237
|
+
}
|
|
238
|
+
width && (_rect.width = width);
|
|
239
|
+
height && (_rect.height = height);
|
|
240
|
+
x && (_rect.x = x);
|
|
241
|
+
y && (_rect.y = y);
|
|
233
242
|
trigger();
|
|
234
243
|
},
|
|
235
244
|
{ immediate: true }
|
|
236
245
|
);
|
|
237
246
|
onMounted(async () => {
|
|
238
247
|
SceneContext?.register(uuid, context);
|
|
239
|
-
const
|
|
240
|
-
_rect.
|
|
241
|
-
_rect.
|
|
242
|
-
_rect.x = _rect.x || 0;
|
|
243
|
-
_rect.y = _rect.y || 0;
|
|
248
|
+
const { offsetTop, offsetLeft } = widgetRef.value;
|
|
249
|
+
_rect.x = _rect.x || offsetLeft;
|
|
250
|
+
_rect.y = _rect.y || offsetTop;
|
|
244
251
|
trigger();
|
|
245
|
-
emitPos();
|
|
246
252
|
});
|
|
247
253
|
function trigger() {
|
|
248
254
|
const { x, y, width, height } = _rect;
|
|
@@ -300,9 +306,7 @@ var FreeDom = defineComponent({
|
|
|
300
306
|
emit("update:height", _rect.height);
|
|
301
307
|
}
|
|
302
308
|
function getDotPos(dot) {
|
|
303
|
-
|
|
304
|
-
return {};
|
|
305
|
-
const { width, height } = _style.value;
|
|
309
|
+
const { width, height } = _rect;
|
|
306
310
|
const isL = /l/.test(dot);
|
|
307
311
|
const isR = /r/.test(dot);
|
|
308
312
|
const isT = /t/.test(dot);
|
|
@@ -334,7 +338,7 @@ var FreeDom = defineComponent({
|
|
|
334
338
|
const shouldUpdate = props.onDragStart?.();
|
|
335
339
|
if (shouldUpdate === false)
|
|
336
340
|
return;
|
|
337
|
-
const pos =
|
|
341
|
+
const pos = { ..._rect };
|
|
338
342
|
const move = (mouseEvt) => {
|
|
339
343
|
const { clientX, clientY } = mouseEvt;
|
|
340
344
|
const x = clientX - evt.clientX + pos.x;
|
|
@@ -370,27 +374,6 @@ var FreeDom = defineComponent({
|
|
|
370
374
|
return true;
|
|
371
375
|
}
|
|
372
376
|
}
|
|
373
|
-
function getStyle(style) {
|
|
374
|
-
const { transform, width, height } = style;
|
|
375
|
-
const { x, y } = getPos(transform);
|
|
376
|
-
return {
|
|
377
|
-
x: x ? Number(x) : 0,
|
|
378
|
-
y: y ? Number(y) : 0,
|
|
379
|
-
width: parseFloat(width),
|
|
380
|
-
height: parseFloat(height)
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
function getPos(transform) {
|
|
384
|
-
if (!transform) {
|
|
385
|
-
return {
|
|
386
|
-
x: 0,
|
|
387
|
-
y: 0
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
const posRegexp = /translate\(([.0-9]+)px[, ]+([.0-9]+)px\)/;
|
|
391
|
-
const [, x, y] = posRegexp.exec(transform) ?? [];
|
|
392
|
-
return { x: parseNum(x), y: parseNum(y) };
|
|
393
|
-
}
|
|
394
377
|
return {
|
|
395
378
|
widgetRef,
|
|
396
379
|
canMove,
|