@sepveneto/free-dom 0.11.3 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- /* ../../../../../../../tmp/tmp-1881-SB3y5ybBKUrY/core/src/style/index.css */
1
+ /* ../../../../../../../tmp/tmp-1904-Fhi89l99xkzO/core/src/style/index.css */
2
2
  :root {
3
3
  --vv-free-dom--theme: rgb(64, 137, 239);
4
4
  --vv-free-dom--line: var(--vv-free-dom--theme);
package/dist/index.d.ts CHANGED
@@ -114,6 +114,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
114
114
  default: number;
115
115
  };
116
116
  keyboard: BooleanConstructor;
117
+ disabledBatch: BooleanConstructor;
117
118
  handle: {
118
119
  type: StringConstructor;
119
120
  default: undefined;
@@ -129,6 +130,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
129
130
  lockAspectRatio: BooleanConstructor;
130
131
  disabledDrag: BooleanConstructor;
131
132
  disabledResize: BooleanConstructor;
133
+ disabledSelect: BooleanConstructor;
132
134
  scale: {
133
135
  type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
134
136
  default: undefined;
@@ -167,6 +169,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
167
169
  default: number;
168
170
  };
169
171
  keyboard: BooleanConstructor;
172
+ disabledBatch: BooleanConstructor;
170
173
  handle: {
171
174
  type: StringConstructor;
172
175
  default: undefined;
@@ -182,6 +185,7 @@ declare const FreeScene: vue_demi.DefineComponent<{
182
185
  lockAspectRatio: BooleanConstructor;
183
186
  disabledDrag: BooleanConstructor;
184
187
  disabledResize: BooleanConstructor;
188
+ disabledSelect: BooleanConstructor;
185
189
  scale: {
186
190
  type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
187
191
  default: undefined;
@@ -193,12 +197,14 @@ declare const FreeScene: vue_demi.DefineComponent<{
193
197
  showLine: boolean;
194
198
  transformScale: number;
195
199
  keyboard: boolean;
200
+ disabledBatch: boolean;
196
201
  handle: string;
197
202
  minWidth: number;
198
203
  minHeight: number;
199
204
  lockAspectRatio: boolean;
200
205
  disabledDrag: boolean;
201
206
  disabledResize: boolean;
207
+ disabledSelect: boolean;
202
208
  fixNonMonospaced: boolean;
203
209
  }, {}>;
204
210
  declare const GridLayout: vue_demi.DefineComponent<{
@@ -402,6 +408,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
402
408
  };
403
409
  disabledDrag: BooleanConstructor;
404
410
  disabledResize: BooleanConstructor;
411
+ disabledSelect: BooleanConstructor;
405
412
  scale: {
406
413
  type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
407
414
  default: undefined;
@@ -594,6 +601,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
594
601
  };
595
602
  disabledDrag: BooleanConstructor;
596
603
  disabledResize: BooleanConstructor;
604
+ disabledSelect: BooleanConstructor;
597
605
  scale: {
598
606
  type: vue_demi.PropType<boolean | ("t" | "r" | "l" | "b" | "lt" | "lb" | "rt" | "rb")[]>;
599
607
  default: undefined;
@@ -622,6 +630,7 @@ declare const FreeDom: vue_demi.DefineComponent<{
622
630
  lockAspectRatio: boolean;
623
631
  disabledDrag: boolean;
624
632
  disabledResize: boolean;
633
+ disabledSelect: boolean;
625
634
  fixNonMonospaced: boolean;
626
635
  modelValue: Partial<{
627
636
  x: number;
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
- on: listeners
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
- SceneContext?.register(uuid, context);
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);
@@ -1216,8 +1269,12 @@ function useMask(target, nodes) {
1216
1269
  const selecting = (0, import_vue_demi13.ref)(false);
1217
1270
  const rect = useElementBounding(target);
1218
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
+ }));
1219
1275
  function checkNode() {
1220
- nodes.value.forEach((node) => {
1276
+ let selectedNode;
1277
+ activeNodes.value.forEach((node) => {
1221
1278
  const rect2 = node.node._rect;
1222
1279
  if (rect2.x == void 0 || // eslint-disable-next-line eqeqeq
1223
1280
  rect2.y == void 0 || // eslint-disable-next-line eqeqeq
@@ -1228,8 +1285,13 @@ function useMask(target, nodes) {
1228
1285
  const y1 = rect2.y;
1229
1286
  const x2 = x1 + rect2.width;
1230
1287
  const y2 = y1 + rect2.height;
1231
- node.node.selected = inArea(x1, y1, x2, y2);
1288
+ const isSelected = inArea(x1, y1, x2, y2);
1289
+ node.node.selected = isSelected;
1290
+ if (isSelected) {
1291
+ selectedNode = node;
1292
+ }
1232
1293
  });
1294
+ selectedNode?.el.focus();
1233
1295
  }
1234
1296
  function inArea(x1, y1, x2, y2) {
1235
1297
  const areaStartX = Math.min(startX.value, lastX.value);
@@ -1252,6 +1314,8 @@ function useMask(target, nodes) {
1252
1314
  };
1253
1315
  }
1254
1316
  function handleMousedown(evt) {
1317
+ if (props.disabledBatch)
1318
+ return;
1255
1319
  addUserSelectStyle(ownerDoc.value);
1256
1320
  const { x: offsetX, y: offsetY } = offsetFormat(evt);
1257
1321
  selecting.value = true;
@@ -1447,30 +1511,20 @@ var freeDomCore = (0, import_vue_demi15.defineComponent)({
1447
1511
  },
1448
1512
  render() {
1449
1513
  const { only } = useDefaultSlot();
1450
- const vue2Props = {
1451
- on: {
1452
- mousedown: (evt) => {
1453
- evt.stopPropagation();
1454
- this.mousedownFn(evt);
1455
- },
1456
- mouseup: this.mouseupFn
1457
- }
1458
- };
1459
- const vue3Props = {
1460
- onMousedown: (evt) => {
1461
- evt.stopPropagation();
1462
- this.mousedownFn(evt);
1463
- },
1464
- onMouseup: this.mouseupFn
1465
- };
1466
1514
  const res = createRender(
1467
1515
  // @ts-expect-error: maybe vue2
1468
1516
  only,
1469
1517
  { ref: (el) => {
1470
1518
  this.coreRef = el;
1471
1519
  } },
1472
- import_vue_demi15.isVue2 ? {} : vue3Props,
1473
- import_vue_demi15.isVue2 ? vue2Props.on : {}
1520
+ {},
1521
+ {
1522
+ onMousedown: (evt) => {
1523
+ evt.stopPropagation();
1524
+ this.mousedownFn(evt);
1525
+ },
1526
+ onMouseup: this.mouseupFn
1527
+ }
1474
1528
  );
1475
1529
  if (typeof res === "function") {
1476
1530
  return res();
@@ -1685,6 +1739,7 @@ var freeDomProps = {
1685
1739
  minHeight: resizeDomCoreProps.minHeight,
1686
1740
  disabledDrag: Boolean,
1687
1741
  disabledResize: Boolean,
1742
+ disabledSelect: Boolean,
1688
1743
  scale: resizeDomCoreProps.scale,
1689
1744
  transformScale: {
1690
1745
  type: Number,
@@ -1722,6 +1777,7 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
1722
1777
  const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
1723
1778
  const selected = (0, import_vue_demi17.ref)(false);
1724
1779
  const context = (0, import_vue_demi17.reactive)({
1780
+ disabledSelect: (0, import_vue_demi17.toRef)(props, "disabledSelect"),
1725
1781
  selected,
1726
1782
  _rect: (0, import_vue_demi17.reactive)({
1727
1783
  x,
@@ -1735,7 +1791,7 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
1735
1791
  emit("update:modelValue", pos);
1736
1792
  }
1737
1793
  });
1738
- const sceneContext = useSceneContext(context, props);
1794
+ const sceneContext = useSceneContext(domRef, context, props);
1739
1795
  onClickOutside(domRef, () => {
1740
1796
  if (!selected.value || isBatchSelecting.value)
1741
1797
  return;
@@ -1868,6 +1924,8 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
1868
1924
  return createRender(resizeDomCore_default, {}, props2)(slots);
1869
1925
  };
1870
1926
  function handleSelect(evt) {
1927
+ if (sceneContext.disabledSelect.value)
1928
+ return;
1871
1929
  if (evt.ctrlKey) {
1872
1930
  selected.value = !selected.value;
1873
1931
  sceneContext.history?.push({ type: "select" });
@@ -1878,23 +1936,32 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
1878
1936
  }
1879
1937
  }
1880
1938
  function handleKeyboard(evt) {
1881
- if (!canDrag.value || !sceneContext.keyboard.value)
1939
+ if (sceneContext.disabledDrag.value || !sceneContext.keyboard.value)
1882
1940
  return;
1883
1941
  evt.preventDefault();
1884
1942
  switch (evt.key) {
1885
1943
  case "ArrowUp":
1886
- y.value -= 1;
1944
+ deltaY.value = -1;
1945
+ deltaX.value = 0;
1887
1946
  break;
1888
1947
  case "ArrowDown":
1889
- y.value += 1;
1948
+ deltaY.value = 1;
1949
+ deltaX.value = 0;
1890
1950
  break;
1891
1951
  case "ArrowLeft":
1892
- x.value -= 1;
1952
+ deltaX.value = -1;
1953
+ deltaY.value = 0;
1893
1954
  break;
1894
1955
  case "ArrowRight":
1895
- x.value += 1;
1956
+ deltaX.value = 1;
1957
+ deltaY.value = 0;
1896
1958
  break;
1959
+ default:
1960
+ deltaX.value = 0;
1961
+ deltaY.value = 0;
1897
1962
  }
1963
+ x.value += deltaX.value;
1964
+ y.value += deltaY.value;
1898
1965
  const newPos = {
1899
1966
  x: x.value,
1900
1967
  y: y.value,
@@ -1934,19 +2001,7 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
1934
2001
  stopFn: this.onDragStop,
1935
2002
  dragFn: this.onDrag,
1936
2003
  disabled: this.disabled,
1937
- scale: this.scale,
1938
- keyboard: this.keyboard
1939
- };
1940
- const vue2Listener = {
1941
- on: {
1942
- click: this.handleSelect,
1943
- keydown: this.handleKeyboard
1944
- }
1945
- };
1946
- const vue3Props = {
1947
- ...props,
1948
- onClick: this.handleSelect,
1949
- onKeydown: this.handleKeyboard
2004
+ scale: this.scale
1950
2005
  };
1951
2006
  const slots = () => this.resizeNode();
1952
2007
  return createRender(
@@ -1961,8 +2016,11 @@ var freeDom = (0, import_vue_demi17.defineComponent)({
1961
2016
  ],
1962
2017
  style: this.style
1963
2018
  },
1964
- import_vue_demi17.isVue2 ? props : vue3Props,
1965
- import_vue_demi17.isVue2 ? vue2Listener.on : {}
2019
+ props,
2020
+ {
2021
+ nativeOnClick: this.handleSelect,
2022
+ nativeOnKeydown: this.handleKeyboard
2023
+ }
1966
2024
  )?.(slots);
1967
2025
  }
1968
2026
  });
@@ -1983,12 +2041,14 @@ var freeDomWrapProps = {
1983
2041
  default: 1
1984
2042
  },
1985
2043
  keyboard: Boolean,
2044
+ disabledBatch: Boolean,
1986
2045
  handle: freeDomProps.handle,
1987
2046
  minWidth: freeDomProps.minWidth,
1988
2047
  minHeight: freeDomProps.minHeight,
1989
2048
  lockAspectRatio: freeDomProps.lockAspectRatio,
1990
2049
  disabledDrag: freeDomProps.disabledDrag,
1991
2050
  disabledResize: freeDomProps.disabledResize,
2051
+ disabledSelect: freeDomProps.disabledSelect,
1992
2052
  scale: freeDomProps.scale,
1993
2053
  fixNonMonospaced: freeDomProps.fixNonMonospaced
1994
2054
  };
@@ -2028,7 +2088,7 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
2028
2088
  });
2029
2089
  });
2030
2090
  const selecting = (0, import_vue_demi18.ref)(false);
2031
- const mask = useMask(rectRef, nodes);
2091
+ const mask = useMask(rectRef, props, nodes);
2032
2092
  function runCorrect() {
2033
2093
  nodes.value.forEach((pos) => {
2034
2094
  const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
@@ -2039,8 +2099,9 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
2039
2099
  pos.node.trigger({ x, y, w: width2, h: height2 });
2040
2100
  });
2041
2101
  }
2042
- function register(uuid, node) {
2102
+ function register(el, uuid, node) {
2043
2103
  nodes.value.push({
2104
+ el,
2044
2105
  uuid,
2045
2106
  node
2046
2107
  });
@@ -2123,14 +2184,11 @@ var FreeDomWrap = (0, import_vue_demi18.defineComponent)({
2123
2184
  ref: "rectRef",
2124
2185
  class: "vv-free-dom--scene"
2125
2186
  },
2126
- import_vue_demi18.isVue2 ? {} : {
2187
+ {},
2188
+ {
2127
2189
  onMousedown: this.mask.handleMousedown,
2128
2190
  onMousemove: this.mask.handleMousemove
2129
- },
2130
- import_vue_demi18.isVue2 ? {
2131
- mousedown: this.mask.handleMousedown,
2132
- mousemove: this.mask.handleMousemove
2133
- } : {}
2191
+ }
2134
2192
  )(slotList);
2135
2193
  }
2136
2194
  });
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@
2
2
  import {
3
3
  computed as computed11,
4
4
  defineComponent as defineComponent6,
5
- isVue2 as isVue26,
6
5
  provide as provide2,
7
6
  reactive as reactive5,
8
7
  ref as ref13,
@@ -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
- on: listeners
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
- SceneContext?.register(uuid, context);
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);
@@ -1196,8 +1248,12 @@ function useMask(target, nodes) {
1196
1248
  const selecting = ref9(false);
1197
1249
  const rect = useElementBounding(target);
1198
1250
  const ownerDoc = computed6(() => unrefElement(target)?.ownerDocument);
1251
+ const activeNodes = computed6(() => nodes.value.filter((node) => {
1252
+ return !(props.disabledSelect || node.node.disabledSelect);
1253
+ }));
1199
1254
  function checkNode() {
1200
- nodes.value.forEach((node) => {
1255
+ let selectedNode;
1256
+ activeNodes.value.forEach((node) => {
1201
1257
  const rect2 = node.node._rect;
1202
1258
  if (rect2.x == void 0 || // eslint-disable-next-line eqeqeq
1203
1259
  rect2.y == void 0 || // eslint-disable-next-line eqeqeq
@@ -1208,8 +1264,13 @@ function useMask(target, nodes) {
1208
1264
  const y1 = rect2.y;
1209
1265
  const x2 = x1 + rect2.width;
1210
1266
  const y2 = y1 + rect2.height;
1211
- node.node.selected = inArea(x1, y1, x2, y2);
1267
+ const isSelected = inArea(x1, y1, x2, y2);
1268
+ node.node.selected = isSelected;
1269
+ if (isSelected) {
1270
+ selectedNode = node;
1271
+ }
1212
1272
  });
1273
+ selectedNode?.el.focus();
1213
1274
  }
1214
1275
  function inArea(x1, y1, x2, y2) {
1215
1276
  const areaStartX = Math.min(startX.value, lastX.value);
@@ -1232,6 +1293,8 @@ function useMask(target, nodes) {
1232
1293
  };
1233
1294
  }
1234
1295
  function handleMousedown(evt) {
1296
+ if (props.disabledBatch)
1297
+ return;
1235
1298
  addUserSelectStyle(ownerDoc.value);
1236
1299
  const { x: offsetX, y: offsetY } = offsetFormat(evt);
1237
1300
  selecting.value = true;
@@ -1312,10 +1375,10 @@ function useOperateHistory(nodes) {
1312
1375
  }
1313
1376
 
1314
1377
  // src/components/freeDom.ts
1315
- import { computed as computed10, defineComponent as defineComponent5, isVue2 as isVue25, onMounted as onMounted4, reactive as reactive4, ref as ref12 } from "vue-demi";
1378
+ import { computed as computed10, defineComponent as defineComponent5, onMounted as onMounted4, reactive as reactive4, ref as ref12, toRef as toRef2 } from "vue-demi";
1316
1379
 
1317
1380
  // src/components/freeDomCore.ts
1318
- import { computed as computed8, defineComponent as defineComponent3, isVue2 as isVue24, onUnmounted as onUnmounted3, ref as ref11 } from "vue-demi";
1381
+ import { computed as computed8, defineComponent as defineComponent3, onUnmounted as onUnmounted3, ref as ref11 } from "vue-demi";
1319
1382
  function noop2() {
1320
1383
  }
1321
1384
  var freeDomCoreProps = {
@@ -1427,30 +1490,20 @@ var freeDomCore = defineComponent3({
1427
1490
  },
1428
1491
  render() {
1429
1492
  const { only } = useDefaultSlot();
1430
- const vue2Props = {
1431
- on: {
1432
- mousedown: (evt) => {
1433
- evt.stopPropagation();
1434
- this.mousedownFn(evt);
1435
- },
1436
- mouseup: this.mouseupFn
1437
- }
1438
- };
1439
- const vue3Props = {
1440
- onMousedown: (evt) => {
1441
- evt.stopPropagation();
1442
- this.mousedownFn(evt);
1443
- },
1444
- onMouseup: this.mouseupFn
1445
- };
1446
1493
  const res = createRender(
1447
1494
  // @ts-expect-error: maybe vue2
1448
1495
  only,
1449
1496
  { ref: (el) => {
1450
1497
  this.coreRef = el;
1451
1498
  } },
1452
- isVue24 ? {} : vue3Props,
1453
- isVue24 ? vue2Props.on : {}
1499
+ {},
1500
+ {
1501
+ onMousedown: (evt) => {
1502
+ evt.stopPropagation();
1503
+ this.mousedownFn(evt);
1504
+ },
1505
+ onMouseup: this.mouseupFn
1506
+ }
1454
1507
  );
1455
1508
  if (typeof res === "function") {
1456
1509
  return res();
@@ -1665,6 +1718,7 @@ var freeDomProps = {
1665
1718
  minHeight: resizeDomCoreProps.minHeight,
1666
1719
  disabledDrag: Boolean,
1667
1720
  disabledResize: Boolean,
1721
+ disabledSelect: Boolean,
1668
1722
  scale: resizeDomCoreProps.scale,
1669
1723
  transformScale: {
1670
1724
  type: Number,
@@ -1702,6 +1756,7 @@ var freeDom = defineComponent5({
1702
1756
  const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
1703
1757
  const selected = ref12(false);
1704
1758
  const context = reactive4({
1759
+ disabledSelect: toRef2(props, "disabledSelect"),
1705
1760
  selected,
1706
1761
  _rect: reactive4({
1707
1762
  x,
@@ -1715,7 +1770,7 @@ var freeDom = defineComponent5({
1715
1770
  emit("update:modelValue", pos);
1716
1771
  }
1717
1772
  });
1718
- const sceneContext = useSceneContext(context, props);
1773
+ const sceneContext = useSceneContext(domRef, context, props);
1719
1774
  onClickOutside(domRef, () => {
1720
1775
  if (!selected.value || isBatchSelecting.value)
1721
1776
  return;
@@ -1848,6 +1903,8 @@ var freeDom = defineComponent5({
1848
1903
  return createRender(resizeDomCore_default, {}, props2)(slots);
1849
1904
  };
1850
1905
  function handleSelect(evt) {
1906
+ if (sceneContext.disabledSelect.value)
1907
+ return;
1851
1908
  if (evt.ctrlKey) {
1852
1909
  selected.value = !selected.value;
1853
1910
  sceneContext.history?.push({ type: "select" });
@@ -1858,23 +1915,32 @@ var freeDom = defineComponent5({
1858
1915
  }
1859
1916
  }
1860
1917
  function handleKeyboard(evt) {
1861
- if (!canDrag.value || !sceneContext.keyboard.value)
1918
+ if (sceneContext.disabledDrag.value || !sceneContext.keyboard.value)
1862
1919
  return;
1863
1920
  evt.preventDefault();
1864
1921
  switch (evt.key) {
1865
1922
  case "ArrowUp":
1866
- y.value -= 1;
1923
+ deltaY.value = -1;
1924
+ deltaX.value = 0;
1867
1925
  break;
1868
1926
  case "ArrowDown":
1869
- y.value += 1;
1927
+ deltaY.value = 1;
1928
+ deltaX.value = 0;
1870
1929
  break;
1871
1930
  case "ArrowLeft":
1872
- x.value -= 1;
1931
+ deltaX.value = -1;
1932
+ deltaY.value = 0;
1873
1933
  break;
1874
1934
  case "ArrowRight":
1875
- x.value += 1;
1935
+ deltaX.value = 1;
1936
+ deltaY.value = 0;
1876
1937
  break;
1938
+ default:
1939
+ deltaX.value = 0;
1940
+ deltaY.value = 0;
1877
1941
  }
1942
+ x.value += deltaX.value;
1943
+ y.value += deltaY.value;
1878
1944
  const newPos = {
1879
1945
  x: x.value,
1880
1946
  y: y.value,
@@ -1914,19 +1980,7 @@ var freeDom = defineComponent5({
1914
1980
  stopFn: this.onDragStop,
1915
1981
  dragFn: this.onDrag,
1916
1982
  disabled: this.disabled,
1917
- scale: this.scale,
1918
- keyboard: this.keyboard
1919
- };
1920
- const vue2Listener = {
1921
- on: {
1922
- click: this.handleSelect,
1923
- keydown: this.handleKeyboard
1924
- }
1925
- };
1926
- const vue3Props = {
1927
- ...props,
1928
- onClick: this.handleSelect,
1929
- onKeydown: this.handleKeyboard
1983
+ scale: this.scale
1930
1984
  };
1931
1985
  const slots = () => this.resizeNode();
1932
1986
  return createRender(
@@ -1941,8 +1995,11 @@ var freeDom = defineComponent5({
1941
1995
  ],
1942
1996
  style: this.style
1943
1997
  },
1944
- isVue25 ? props : vue3Props,
1945
- isVue25 ? vue2Listener.on : {}
1998
+ props,
1999
+ {
2000
+ nativeOnClick: this.handleSelect,
2001
+ nativeOnKeydown: this.handleKeyboard
2002
+ }
1946
2003
  )?.(slots);
1947
2004
  }
1948
2005
  });
@@ -1963,12 +2020,14 @@ var freeDomWrapProps = {
1963
2020
  default: 1
1964
2021
  },
1965
2022
  keyboard: Boolean,
2023
+ disabledBatch: Boolean,
1966
2024
  handle: freeDomProps.handle,
1967
2025
  minWidth: freeDomProps.minWidth,
1968
2026
  minHeight: freeDomProps.minHeight,
1969
2027
  lockAspectRatio: freeDomProps.lockAspectRatio,
1970
2028
  disabledDrag: freeDomProps.disabledDrag,
1971
2029
  disabledResize: freeDomProps.disabledResize,
2030
+ disabledSelect: freeDomProps.disabledSelect,
1972
2031
  scale: freeDomProps.scale,
1973
2032
  fixNonMonospaced: freeDomProps.fixNonMonospaced
1974
2033
  };
@@ -2008,7 +2067,7 @@ var FreeDomWrap = defineComponent6({
2008
2067
  });
2009
2068
  });
2010
2069
  const selecting = ref13(false);
2011
- const mask = useMask(rectRef, nodes);
2070
+ const mask = useMask(rectRef, props, nodes);
2012
2071
  function runCorrect() {
2013
2072
  nodes.value.forEach((pos) => {
2014
2073
  const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
@@ -2019,8 +2078,9 @@ var FreeDomWrap = defineComponent6({
2019
2078
  pos.node.trigger({ x, y, w: width2, h: height2 });
2020
2079
  });
2021
2080
  }
2022
- function register(uuid, node) {
2081
+ function register(el, uuid, node) {
2023
2082
  nodes.value.push({
2083
+ el,
2024
2084
  uuid,
2025
2085
  node
2026
2086
  });
@@ -2103,14 +2163,11 @@ var FreeDomWrap = defineComponent6({
2103
2163
  ref: "rectRef",
2104
2164
  class: "vv-free-dom--scene"
2105
2165
  },
2106
- isVue26 ? {} : {
2166
+ {},
2167
+ {
2107
2168
  onMousedown: this.mask.handleMousedown,
2108
2169
  onMousemove: this.mask.handleMousemove
2109
- },
2110
- isVue26 ? {
2111
- mousedown: this.mask.handleMousedown,
2112
- mousemove: this.mask.handleMousemove
2113
- } : {}
2170
+ }
2114
2171
  )(slotList);
2115
2172
  }
2116
2173
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sepveneto/free-dom",
3
- "version": "0.11.3",
3
+ "version": "0.11.4",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",