@veritree/ui 0.81.0-1 → 0.81.0-2

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.
@@ -1,4 +1,12 @@
1
- import { computePosition, flip, shift, offset, size } from '@floating-ui/dom';
1
+ import {
2
+ autoUpdate,
3
+ computePosition,
4
+ flip,
5
+ shift,
6
+ offset,
7
+ size,
8
+ // update,
9
+ } from '@floating-ui/dom';
2
10
 
3
11
  export const floatingUiMixin = {
4
12
  props: {
@@ -14,6 +22,7 @@ export const floatingUiMixin = {
14
22
  componentTrigger: null,
15
23
  componentContent: null,
16
24
  active: false,
25
+ floatingUiUpdaterDisposer: null,
17
26
  };
18
27
  },
19
28
 
@@ -30,6 +39,12 @@ export const floatingUiMixin = {
30
39
  };
31
40
  },
32
41
 
42
+ beforeDestroy() {
43
+ if (this.floatingUiUpdaterDisposer) {
44
+ this.floatingUiUpdaterDisposer();
45
+ }
46
+ },
47
+
33
48
  methods: {
34
49
  setActive() {
35
50
  this.active = true;
@@ -52,54 +67,69 @@ export const floatingUiMixin = {
52
67
  const contentWidth = contentRect.width;
53
68
  const contentHeight = contentRect.height;
54
69
  const triggerWidth = trigger.getBoundingClientRect().width;
55
-
56
70
  let leftObject = this.leftPosition || {};
57
71
  let topObject = this.topPosition || {};
58
-
59
72
  let left = leftObject.value || 0;
60
73
  let top = topObject.value || 0;
61
74
 
62
75
  if (leftObject.unit === '%') {
63
76
  left = (triggerWidth * left) / 100;
64
77
  }
78
+
65
79
  if (topObject.unit === '%') {
66
80
  top = (triggerWidth * top) / 100;
67
81
  }
82
+
68
83
  if (leftObject.positionBy === 'center') {
69
84
  left = left - contentWidth / 2;
70
85
  }
86
+
71
87
  if (leftObject.positionBy === 'end') {
72
88
  left = left - contentWidth;
73
89
  }
90
+
74
91
  if (topObject.positionBy === 'top') {
75
92
  top = top + contentHeight;
76
93
  }
94
+
77
95
  if (topObject.positionBy === 'center') {
78
96
  top = top + contentHeight / 2;
79
97
  }
80
98
 
81
- computePosition(trigger, content, {
82
- placement: 'top-start',
83
- middleware: [
84
- flip(),
85
- shift({ padding: 5 }),
86
- size({
87
- apply({ rects }) {
88
- if (!minWidthLimit) return;
89
-
90
- const width = rects.reference.width;
91
- const minWidth = width < minWidthLimit ? minWidthLimit : width;
92
-
93
- Object.assign(content.style, {
94
- minWidth: `${minWidth}px`,
95
- });
96
- },
97
- }),
98
- ],
99
- }).then(({ x, y }) => {
100
- Object.assign(content.style, {
101
- left: `${x + left}px`,
102
- top: `${y + top}px`,
99
+ /**
100
+ * Initializes the auto-update functionality for positioning the floating UI element.
101
+ * This method sets up an automatic update mechanism that adjusts the position of the
102
+ * content element in relation to the trigger element based on changes in the environment,
103
+ * such as scroll or resize events.
104
+ *
105
+ * @param {Element} trigger - The DOM element that acts as the reference point for positioning.
106
+ * @param {Element} content - The DOM element representing the floating UI content that needs to be positioned.
107
+ * @param {Function} updateFunction - A callback function that executes the update logic for positioning.
108
+ */
109
+ this.floatingUiUpdaterDisposer = autoUpdate(trigger, content, () => {
110
+ computePosition(trigger, content, {
111
+ placement: 'top-start',
112
+ middleware: [
113
+ flip(),
114
+ shift({ padding: 5 }),
115
+ size({
116
+ apply({ rects }) {
117
+ if (!minWidthLimit) return;
118
+
119
+ const width = rects.reference.width;
120
+ const minWidth = width < minWidthLimit ? minWidthLimit : width;
121
+
122
+ Object.assign(content.style, {
123
+ minWidth: `${minWidth}px`,
124
+ });
125
+ },
126
+ }),
127
+ ],
128
+ }).then(({ x, y }) => {
129
+ Object.assign(content.style, {
130
+ left: `${x + left}px`,
131
+ top: `${y + top}px`,
132
+ });
103
133
  });
104
134
  });
105
135
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.81.0-1",
3
+ "version": "0.81.0-2",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",