@sepveneto/free-dom 0.8.0 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- /* ../../../../../../../tmp/tmp-1883-O1p5mboxRMKz/core/src/style/index.css */
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.js CHANGED
@@ -370,14 +370,23 @@ function useSceneContext(context, props) {
370
370
  (0, import_vue_demi7.onMounted)(() => {
371
371
  SceneContext?.register(uuid, context);
372
372
  });
373
+ (0, import_vue_demi7.onUnmounted)(() => {
374
+ SceneContext?.remove(uuid);
375
+ });
373
376
  function check(pos) {
374
377
  if (!SceneContext)
375
378
  return true;
376
379
  return SceneContext.checkValid(pos);
377
380
  }
381
+ function correct(pos) {
382
+ if (!SceneContext)
383
+ return pos;
384
+ return SceneContext.correct(pos);
385
+ }
378
386
  return {
379
387
  emit: (name) => SceneContext?.emit(name, uuid),
380
388
  check,
389
+ correct,
381
390
  width: SceneContext?.width,
382
391
  height: SceneContext?.height,
383
392
  scale,
@@ -1227,7 +1236,8 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
1227
1236
  deltaX,
1228
1237
  deltaY
1229
1238
  }),
1230
- trigger: () => {
1239
+ trigger: (pos) => {
1240
+ emit("update:modelValue", pos);
1231
1241
  }
1232
1242
  };
1233
1243
  const sceneContext = useSceneContext(context, props);
@@ -1241,6 +1251,8 @@ var freeDom = (0, import_vue_demi13.defineComponent)({
1241
1251
  const canDrag = (0, import_vue_demi13.ref)(false);
1242
1252
  (0, import_vue_demi13.onMounted)(() => {
1243
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 });
1244
1256
  });
1245
1257
  const style = (0, import_vue_demi13.computed)(() => ({
1246
1258
  position: "absolute",
@@ -1434,22 +1446,61 @@ var FreeDomWrap = (0, import_vue_demi14.defineComponent)({
1434
1446
  if (!props.width || !props.height) {
1435
1447
  if (!rectRef.value)
1436
1448
  console.warn("[free-dom] cannot find element, width or height may be set to 0");
1437
- const { width: w, height: h5 } = rectRef.value?.getBoundingClientRect() || {};
1449
+ const h5 = rectRef.value?.clientHeight;
1450
+ const w = rectRef.value?.clientWidth;
1438
1451
  if (!props.width)
1439
1452
  width.value = w || 0;
1440
1453
  if (!props.height)
1441
1454
  height.value = h5 || 0;
1442
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
+ });
1443
1464
  });
1444
1465
  function register(uuid, node) {
1445
1466
  nodes.value.push({ uuid, node });
1446
1467
  }
1468
+ function remove(uuid) {
1469
+ const index = nodes.value.findIndex((item) => item.uuid === uuid);
1470
+ nodes.value.splice(index, 1);
1471
+ }
1447
1472
  function checkValid(pos) {
1448
1473
  const { x, y, width: w, height: h5 } = pos;
1449
1474
  return x >= 0 && // @ts-expect-error: trigger after mounted
1450
1475
  x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
1451
1476
  y + h5 <= height.value;
1452
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
+ }
1453
1504
  (0, import_vue_demi14.provide)(
1454
1505
  SceneToken,
1455
1506
  (0, import_vue_demi14.reactive)({
@@ -1458,7 +1509,9 @@ var FreeDomWrap = (0, import_vue_demi14.defineComponent)({
1458
1509
  width,
1459
1510
  height,
1460
1511
  register,
1512
+ remove,
1461
1513
  checkValid,
1514
+ correct,
1462
1515
  on: eventBus.on,
1463
1516
  off: eventBus.off,
1464
1517
  emit: eventBus.emit
package/dist/index.mjs CHANGED
@@ -322,7 +322,7 @@ function useDraggableData(props) {
322
322
  }
323
323
 
324
324
  // src/hooks/use-scene-context.ts
325
- import { computed as computed2, inject as inject2, onMounted } from "vue-demi";
325
+ import { computed as computed2, inject as inject2, onMounted, onUnmounted } from "vue-demi";
326
326
  var id = 0;
327
327
  function useSceneContext(context, props) {
328
328
  const SceneContext = inject2(SceneToken, void 0);
@@ -340,14 +340,23 @@ function useSceneContext(context, props) {
340
340
  onMounted(() => {
341
341
  SceneContext?.register(uuid, context);
342
342
  });
343
+ onUnmounted(() => {
344
+ SceneContext?.remove(uuid);
345
+ });
343
346
  function check(pos) {
344
347
  if (!SceneContext)
345
348
  return true;
346
349
  return SceneContext.checkValid(pos);
347
350
  }
351
+ function correct(pos) {
352
+ if (!SceneContext)
353
+ return pos;
354
+ return SceneContext.correct(pos);
355
+ }
348
356
  return {
349
357
  emit: (name) => SceneContext?.emit(name, uuid),
350
358
  check,
359
+ correct,
351
360
  width: SceneContext?.width,
352
361
  height: SceneContext?.height,
353
362
  scale,
@@ -800,7 +809,7 @@ function useLayoutItem(props, layout) {
800
809
  import { computed as computed6, defineComponent as defineComponent4, onMounted as onMounted2, reactive as reactive2, ref as ref9 } from "vue-demi";
801
810
 
802
811
  // src/components/freeDomCore.ts
803
- 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";
804
813
  function noop() {
805
814
  }
806
815
  var freeDomCoreProps = {
@@ -834,7 +843,7 @@ var freeDomCore = defineComponent2({
834
843
  const { lastX, lastY, create } = useCoreData(node);
835
844
  let parentNode;
836
845
  let parentRect;
837
- onUnmounted(() => {
846
+ onUnmounted2(() => {
838
847
  if (!ownerDoc.value)
839
848
  return;
840
849
  if (props.userSelectHack)
@@ -1197,7 +1206,8 @@ var freeDom = defineComponent4({
1197
1206
  deltaX,
1198
1207
  deltaY
1199
1208
  }),
1200
- trigger: () => {
1209
+ trigger: (pos) => {
1210
+ emit("update:modelValue", pos);
1201
1211
  }
1202
1212
  };
1203
1213
  const sceneContext = useSceneContext(context, props);
@@ -1211,6 +1221,8 @@ var freeDom = defineComponent4({
1211
1221
  const canDrag = ref9(false);
1212
1222
  onMounted2(() => {
1213
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 });
1214
1226
  });
1215
1227
  const style = computed6(() => ({
1216
1228
  position: "absolute",
@@ -1404,22 +1416,61 @@ var FreeDomWrap = defineComponent5({
1404
1416
  if (!props.width || !props.height) {
1405
1417
  if (!rectRef.value)
1406
1418
  console.warn("[free-dom] cannot find element, width or height may be set to 0");
1407
- const { width: w, height: h5 } = rectRef.value?.getBoundingClientRect() || {};
1419
+ const h5 = rectRef.value?.clientHeight;
1420
+ const w = rectRef.value?.clientWidth;
1408
1421
  if (!props.width)
1409
1422
  width.value = w || 0;
1410
1423
  if (!props.height)
1411
1424
  height.value = h5 || 0;
1412
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
+ });
1413
1434
  });
1414
1435
  function register(uuid, node) {
1415
1436
  nodes.value.push({ uuid, node });
1416
1437
  }
1438
+ function remove(uuid) {
1439
+ const index = nodes.value.findIndex((item) => item.uuid === uuid);
1440
+ nodes.value.splice(index, 1);
1441
+ }
1417
1442
  function checkValid(pos) {
1418
1443
  const { x, y, width: w, height: h5 } = pos;
1419
1444
  return x >= 0 && // @ts-expect-error: trigger after mounted
1420
1445
  x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
1421
1446
  y + h5 <= height.value;
1422
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
+ }
1423
1474
  provide(
1424
1475
  SceneToken,
1425
1476
  reactive3({
@@ -1428,7 +1479,9 @@ var FreeDomWrap = defineComponent5({
1428
1479
  width,
1429
1480
  height,
1430
1481
  register,
1482
+ remove,
1431
1483
  checkValid,
1484
+ correct,
1432
1485
  on: eventBus.on,
1433
1486
  off: eventBus.off,
1434
1487
  emit: eventBus.emit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sepveneto/free-dom",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",