@sepveneto/free-dom 0.8.0 → 0.9.1

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-1888-2C7SiiG2SRG2/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
@@ -86,7 +86,7 @@ var markLine_default = (0, import_vue_demi2.defineComponent)({
86
86
  setup() {
87
87
  const SceneContext = (0, import_vue_demi2.inject)(SceneToken);
88
88
  const lines = (0, import_vue_demi2.shallowRef)(lineType);
89
- const diff = (0, import_vue_demi2.ref)(SceneContext.diff);
89
+ const diff = (0, import_vue_demi2.computed)(() => SceneContext.diff);
90
90
  const nodes = SceneContext.nodes;
91
91
  const lineStatus = (0, import_vue_demi2.reactive)({
92
92
  xt: {
@@ -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
@@ -1,5 +1,5 @@
1
1
  // src/components/freeDomWrap.ts
2
- import { computed as computed7, defineComponent as defineComponent5, onMounted as onMounted3, provide, reactive as reactive3, ref as ref10, shallowRef as shallowRef4, toRefs, watchEffect as watchEffect4 } from "vue-demi";
2
+ import { computed as computed8, defineComponent as defineComponent5, onMounted as onMounted3, provide, reactive as reactive3, ref as ref9, shallowRef as shallowRef4, toRefs, watchEffect as watchEffect4 } from "vue-demi";
3
3
 
4
4
  // src/util/tokens.ts
5
5
  var SceneToken = Symbol("Scene");
@@ -47,7 +47,7 @@ function log(...args) {
47
47
  }
48
48
 
49
49
  // src/components/markLine.ts
50
- import { defineComponent, h as h2, inject, onBeforeUnmount, reactive, ref, shallowRef } from "vue-demi";
50
+ import { computed, defineComponent, h as h2, inject, onBeforeUnmount, reactive, shallowRef } from "vue-demi";
51
51
  var lineType = ["xt", "xc", "xb", "yl", "yc", "yr"];
52
52
  var markLine_default = defineComponent({
53
53
  props: {
@@ -56,7 +56,7 @@ var markLine_default = defineComponent({
56
56
  setup() {
57
57
  const SceneContext = inject(SceneToken);
58
58
  const lines = shallowRef(lineType);
59
- const diff = ref(SceneContext.diff);
59
+ const diff = computed(() => SceneContext.diff);
60
60
  const nodes = SceneContext.nodes;
61
61
  const lineStatus = reactive({
62
62
  xt: {
@@ -214,16 +214,16 @@ var markLine_default = defineComponent({
214
214
  });
215
215
 
216
216
  // src/hooks/use-normalize-style.ts
217
- import { ref as ref2, unref, watch } from "vue-demi";
217
+ import { ref, unref, watch } from "vue-demi";
218
218
 
219
219
  // src/hooks/use-default-slot.ts
220
- import { computed, useSlots } from "vue-demi";
220
+ import { computed as computed2, useSlots } from "vue-demi";
221
221
  function useDefaultSlot() {
222
222
  const slots = useSlots();
223
- const slotList = computed(() => {
223
+ const slotList = computed2(() => {
224
224
  return typeof slots.default === "function" ? slots.default() : slots.default;
225
225
  });
226
- const only = computed(() => slotList.value?.[0]);
226
+ const only = computed2(() => slotList.value?.[0]);
227
227
  return {
228
228
  slots: slotList,
229
229
  only
@@ -231,10 +231,10 @@ function useDefaultSlot() {
231
231
  }
232
232
 
233
233
  // src/hooks/use-core-date.ts
234
- import { ref as ref3, unref as unref2 } from "vue-demi";
234
+ import { ref as ref2, unref as unref2 } from "vue-demi";
235
235
  function useCoreData(node) {
236
- const lastX = ref3(NaN);
237
- const lastY = ref3(NaN);
236
+ const lastX = ref2(NaN);
237
+ const lastY = ref2(NaN);
238
238
  function create(x, y) {
239
239
  const isStart = isNaN(lastX.value);
240
240
  const _node = unref2(node);
@@ -271,13 +271,13 @@ function useCoreData(node) {
271
271
  }
272
272
 
273
273
  // src/hooks/use-draggable-data.ts
274
- import { ref as ref4, watchEffect } from "vue-demi";
274
+ import { ref as ref3, watchEffect } from "vue-demi";
275
275
  function useDraggableData(props) {
276
- const x = ref4(props.x || props.modelValue.x || 0);
277
- const y = ref4(props.y || props.modelValue.y || 0);
278
- const deltaX = ref4(0);
279
- const deltaY = ref4(0);
280
- const dragData = ref4();
276
+ const x = ref3(props.x || props.modelValue.x || 0);
277
+ const y = ref3(props.y || props.modelValue.y || 0);
278
+ const deltaX = ref3(0);
279
+ const deltaY = ref3(0);
280
+ const dragData = ref3();
281
281
  watchEffect(() => {
282
282
  x.value = props.x || props.modelValue.x || 0;
283
283
  });
@@ -322,32 +322,41 @@ 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 computed3, 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);
329
329
  const uuid = id++;
330
- const handle = computed2(() => SceneContext?.handle || props.handle);
331
- const lockAspectRatio = computed2(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
332
- const minWidth = computed2(() => SceneContext?.minWidth || props.minWidth);
333
- const minHeight = computed2(() => SceneContext?.minHeight || props.minHeight);
334
- const disabledDrag = computed2(() => SceneContext?.disabledDrag || props.disabledDrag);
335
- const disabledResize = computed2(() => SceneContext?.disabledResize || props.disabledResize);
336
- const scale = computed2(() => SceneContext?.scale || props.scale);
337
- const fixNonMonospaced = computed2(() => {
330
+ const handle = computed3(() => SceneContext?.handle || props.handle);
331
+ const lockAspectRatio = computed3(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
332
+ const minWidth = computed3(() => SceneContext?.minWidth || props.minWidth);
333
+ const minHeight = computed3(() => SceneContext?.minHeight || props.minHeight);
334
+ const disabledDrag = computed3(() => SceneContext?.disabledDrag || props.disabledDrag);
335
+ const disabledResize = computed3(() => SceneContext?.disabledResize || props.disabledResize);
336
+ const scale = computed3(() => SceneContext?.scale || props.scale);
337
+ const fixNonMonospaced = computed3(() => {
338
338
  return SceneContext?.fixNonMonospaced || props.fixNonMonospaced;
339
339
  });
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,
@@ -362,9 +371,9 @@ function useSceneContext(context, props) {
362
371
  }
363
372
 
364
373
  // src/hooks/use-event-bus.ts
365
- import { ref as ref5 } from "vue-demi";
374
+ import { ref as ref4 } from "vue-demi";
366
375
  function useEventBus() {
367
- const callbacks = ref5({});
376
+ const callbacks = ref4({});
368
377
  const on = (name, cb) => {
369
378
  if (!callbacks.value[name]) {
370
379
  callbacks.value[name] = [cb];
@@ -387,10 +396,10 @@ function useEventBus() {
387
396
  }
388
397
 
389
398
  // src/hooks/use-resizable-data.ts
390
- import { ref as ref6, watchEffect as watchEffect2 } from "vue-demi";
399
+ import { ref as ref5, watchEffect as watchEffect2 } from "vue-demi";
391
400
  function useResizableData(props, domRef) {
392
- const width = ref6(getWidth());
393
- const height = ref6(getHeight());
401
+ const width = ref5(getWidth());
402
+ const height = ref5(getHeight());
394
403
  watchEffect2(() => {
395
404
  width.value = getWidth();
396
405
  });
@@ -423,22 +432,22 @@ function useResizableData(props, domRef) {
423
432
  }
424
433
 
425
434
  // src/hooks/use-layout.ts
426
- import { computed as computed3, ref as ref7, shallowRef as shallowRef2, watchEffect as watchEffect3 } from "vue-demi";
435
+ import { computed as computed4, ref as ref6, shallowRef as shallowRef2, watchEffect as watchEffect3 } from "vue-demi";
427
436
  function useLayout(props) {
428
437
  const layout = shallowRef2(props.modelValue);
429
438
  watchEffect3(() => {
430
439
  layout.value = props.modelValue;
431
440
  });
432
- const cellWidth = computed3(
441
+ const cellWidth = computed4(
433
442
  () => (props.width - margin.value[0] * (cols.value - 1) - (containerPadding.value?.[0] || margin.value[0]) * 2) / props.cols
434
443
  );
435
- const cols = computed3(() => props.cols);
436
- const rowHeight = computed3(() => props.rowHeight);
437
- const margin = computed3(() => props.margin);
438
- const maxRows = computed3(() => props.maxRows);
439
- const containerPadding = computed3(() => props.containerPadding);
440
- const minW = computed3(() => props.minW);
441
- const minH = computed3(() => props.minH);
444
+ const cols = computed4(() => props.cols);
445
+ const rowHeight = computed4(() => props.rowHeight);
446
+ const margin = computed4(() => props.margin);
447
+ const maxRows = computed4(() => props.maxRows);
448
+ const containerPadding = computed4(() => props.containerPadding);
449
+ const minW = computed4(() => props.minW);
450
+ const minH = computed4(() => props.minH);
442
451
  function getItem(key) {
443
452
  return layout.value.find((item) => item.i === key);
444
453
  }
@@ -673,46 +682,46 @@ function useLayout(props) {
673
682
  }
674
683
  function useLayoutItem(props, layout) {
675
684
  const { cellWidth, margin, rowHeight, cols, maxRows, containerPadding: cPadding } = layout;
676
- const dragging = ref7();
677
- const resizing = ref7();
678
- const containerPadding = computed3(() => cPadding.value || margin.value);
679
- const x = computed3(() => {
685
+ const dragging = ref6();
686
+ const resizing = ref6();
687
+ const containerPadding = computed4(() => cPadding.value || margin.value);
688
+ const x = computed4(() => {
680
689
  if (!dragging.value) {
681
690
  return Math.round(props.x * (cellWidth.value + margin.value[0]) + containerPadding.value[0]);
682
691
  } else {
683
692
  return Math.round(dragging.value.x);
684
693
  }
685
694
  });
686
- const y = computed3(() => {
695
+ const y = computed4(() => {
687
696
  if (!dragging.value) {
688
697
  return Math.round(props.y * (rowHeight.value + margin.value[1]) + containerPadding.value[1]);
689
698
  } else {
690
699
  return Math.round(dragging.value.y);
691
700
  }
692
701
  });
693
- const width = computed3(() => {
702
+ const width = computed4(() => {
694
703
  if (!resizing.value) {
695
704
  return Math.round(cellWidth.value * props.width + Math.max(0, props.width - 1) * margin.value[0]);
696
705
  } else {
697
706
  return Math.round(resizing.value.width);
698
707
  }
699
708
  });
700
- const height = computed3(() => {
709
+ const height = computed4(() => {
701
710
  if (!resizing.value) {
702
711
  return Math.round(rowHeight.value * props.height + Math.max(0, props.height - 1) * margin.value[1]);
703
712
  } else {
704
713
  return Math.round(resizing.value.height);
705
714
  }
706
715
  });
707
- const minWidth = computed3(() => {
716
+ const minWidth = computed4(() => {
708
717
  const minW = layout.minW.value;
709
718
  return Math.round(cellWidth.value * minW + Math.max(0, minW - 1) * margin.value[0]);
710
719
  });
711
- const minHeight = computed3(() => {
720
+ const minHeight = computed4(() => {
712
721
  const minH = layout.minH.value;
713
722
  return Math.round(rowHeight.value * minH + Math.max(0, minH - 1) * margin.value[1]);
714
723
  });
715
- const style = computed3(() => {
724
+ const style = computed4(() => {
716
725
  return {
717
726
  position: "absolute",
718
727
  width: `${width.value}px`,
@@ -797,10 +806,10 @@ function useLayoutItem(props, layout) {
797
806
  }
798
807
 
799
808
  // src/components/freeDom.ts
800
- import { computed as computed6, defineComponent as defineComponent4, onMounted as onMounted2, reactive as reactive2, ref as ref9 } from "vue-demi";
809
+ import { computed as computed7, defineComponent as defineComponent4, onMounted as onMounted2, reactive as reactive2, ref as ref8 } 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 computed5, defineComponent as defineComponent2, isVue2 as isVue22, onUnmounted as onUnmounted2, ref as ref7 } from "vue-demi";
804
813
  function noop() {
805
814
  }
806
815
  var freeDomCoreProps = {
@@ -827,14 +836,14 @@ var freeDomCore = defineComponent2({
827
836
  props: freeDomCoreProps,
828
837
  setup(props) {
829
838
  const { only } = useDefaultSlot();
830
- const dragging = ref8(false);
831
- const coreRef = ref8();
832
- const node = computed4(() => coreRef.value?.$el || coreRef.value);
833
- const ownerDoc = computed4(() => node.value?.ownerDocument);
839
+ const dragging = ref7(false);
840
+ const coreRef = ref7();
841
+ const node = computed5(() => coreRef.value?.$el || coreRef.value);
842
+ const ownerDoc = computed5(() => node.value?.ownerDocument);
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)
@@ -960,7 +969,7 @@ var freeDomCore = defineComponent2({
960
969
  var freeDomCore_default = freeDomCore;
961
970
 
962
971
  // src/components/resizeDomCore.ts
963
- import { computed as computed5, defineComponent as defineComponent3, h as h3, shallowRef as shallowRef3 } from "vue-demi";
972
+ import { computed as computed6, defineComponent as defineComponent3, h as h3, shallowRef as shallowRef3 } from "vue-demi";
964
973
  var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
965
974
  function noop2() {
966
975
  }
@@ -1008,7 +1017,7 @@ var resizeDomCore = defineComponent3({
1008
1017
  props: resizeDomCoreProps,
1009
1018
  setup(props, { slots }) {
1010
1019
  const { slots: _slots } = useDefaultSlot();
1011
- const dots = computed5(() => {
1020
+ const dots = computed6(() => {
1012
1021
  const _dots = props.scale;
1013
1022
  return Array.isArray(_dots) ? _dots : Dots;
1014
1023
  });
@@ -1176,7 +1185,7 @@ var freeDom = defineComponent4({
1176
1185
  "update:modelValue"
1177
1186
  ],
1178
1187
  setup(props, { emit, expose, slots }) {
1179
- const domRef = ref9();
1188
+ const domRef = ref8();
1180
1189
  const {
1181
1190
  x,
1182
1191
  y,
@@ -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);
@@ -1208,11 +1218,13 @@ var freeDom = defineComponent4({
1208
1218
  sceneContext.minHeight.value
1209
1219
  );
1210
1220
  };
1211
- const canDrag = ref9(false);
1221
+ const canDrag = ref8(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
- const style = computed6(() => ({
1227
+ const style = computed7(() => ({
1216
1228
  position: "absolute",
1217
1229
  width: `${width.value}px`,
1218
1230
  height: `${height.value}px`,
@@ -1391,9 +1403,9 @@ var FreeDomWrap = defineComponent5({
1391
1403
  const { slots } = useDefaultSlot();
1392
1404
  const eventBus = useEventBus();
1393
1405
  const rectRef = shallowRef4();
1394
- const nodes = ref10([]);
1395
- const width = ref10(props.width);
1396
- const height = ref10(props.height);
1406
+ const nodes = ref9([]);
1407
+ const width = ref9(props.width);
1408
+ const height = ref9(props.height);
1397
1409
  watchEffect4(() => {
1398
1410
  width.value = props.width;
1399
1411
  });
@@ -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,13 +1479,15 @@ 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
1435
1488
  })
1436
1489
  );
1437
- const style = computed7(() => ({
1490
+ const style = computed8(() => ({
1438
1491
  width: `${props.width}px`,
1439
1492
  height: `${props.height}px`
1440
1493
  }));
@@ -1459,7 +1512,7 @@ var FreeDomWrap = defineComponent5({
1459
1512
  });
1460
1513
 
1461
1514
  // src/components/gridLayout.ts
1462
- import { defineComponent as defineComponent7, h as h4, provide as provide2, ref as ref11 } from "vue-demi";
1515
+ import { defineComponent as defineComponent7, h as h4, provide as provide2, ref as ref10 } from "vue-demi";
1463
1516
 
1464
1517
  // src/components/gridItem.ts
1465
1518
  import { defineComponent as defineComponent6, inject as inject3 } from "vue-demi";
@@ -1657,7 +1710,7 @@ var GridLayout = defineComponent7({
1657
1710
  setup(props, { emit }) {
1658
1711
  const layout = useLayout(props);
1659
1712
  provide2(gridLayoutContextKey, layout);
1660
- const activeDrag = ref11(null);
1713
+ const activeDrag = ref10(null);
1661
1714
  function processItem(node) {
1662
1715
  const key = node.key;
1663
1716
  if (!key)
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.1",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",