@zag-js/popper 0.2.2 → 0.2.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/auto-update.js +13 -91
- package/dist/auto-update.mjs +1 -1
- package/dist/{chunk-7DJY6BDG.mjs → chunk-K6E3OR2A.mjs} +5 -6
- package/dist/chunk-KMOWWEFH.mjs +43 -0
- package/dist/get-placement.js +19 -97
- package/dist/get-placement.mjs +2 -2
- package/dist/get-styles.d.ts +1 -1
- package/dist/index.js +19 -97
- package/dist/index.mjs +2 -2
- package/package.json +6 -5
- package/dist/chunk-MDQJEIPL.mjs +0 -122
package/dist/auto-update.js
CHANGED
|
@@ -24,99 +24,21 @@ __export(auto_update_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(auto_update_exports);
|
|
26
26
|
var import_dom = require("@floating-ui/dom");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
return res != null ? res : void 0;
|
|
27
|
+
var import_element_rect = require("@zag-js/element-rect");
|
|
28
|
+
var callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
29
|
+
var isHTMLElement = (el) => {
|
|
30
|
+
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
32
31
|
};
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
32
|
+
var addDomEvent = (el, type, fn, options) => {
|
|
33
|
+
el.addEventListener(type, fn, options);
|
|
34
|
+
return () => el.removeEventListener(type, fn, options);
|
|
37
35
|
};
|
|
38
|
-
|
|
39
|
-
// ../core/src/guard.ts
|
|
40
|
-
var isBoolean = (v) => v === true || v === false;
|
|
41
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
42
|
-
|
|
43
|
-
// ../dom/src/query.ts
|
|
44
|
-
function isHTMLElement(v) {
|
|
45
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ../dom/src/listener.ts
|
|
49
|
-
var isRef = (v) => hasProp(v, "current");
|
|
50
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
51
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
52
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
53
|
-
return () => {
|
|
54
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ../dom/src/rect-observer.ts
|
|
59
|
-
function getObservedElements() {
|
|
60
|
-
;
|
|
61
|
-
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
62
|
-
return globalThis.__rectObserverMap__;
|
|
63
|
-
}
|
|
64
|
-
function observeElementRect(el, fn) {
|
|
65
|
-
const observedElements = getObservedElements();
|
|
66
|
-
const data = observedElements.get(el);
|
|
67
|
-
if (!data) {
|
|
68
|
-
observedElements.set(el, { rect: {}, callbacks: [fn] });
|
|
69
|
-
if (observedElements.size === 1) {
|
|
70
|
-
rafId = requestAnimationFrame(runLoop);
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
data.callbacks.push(fn);
|
|
74
|
-
fn(el.getBoundingClientRect());
|
|
75
|
-
}
|
|
76
|
-
return function unobserve() {
|
|
77
|
-
const data2 = observedElements.get(el);
|
|
78
|
-
if (!data2)
|
|
79
|
-
return;
|
|
80
|
-
const index = data2.callbacks.indexOf(fn);
|
|
81
|
-
if (index > -1) {
|
|
82
|
-
data2.callbacks.splice(index, 1);
|
|
83
|
-
}
|
|
84
|
-
if (data2.callbacks.length === 0) {
|
|
85
|
-
observedElements.delete(el);
|
|
86
|
-
if (observedElements.size === 0) {
|
|
87
|
-
cancelAnimationFrame(rafId);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
var rafId;
|
|
93
|
-
function runLoop() {
|
|
94
|
-
const observedElements = getObservedElements();
|
|
95
|
-
const changedRectsData = [];
|
|
96
|
-
observedElements.forEach((data, element) => {
|
|
97
|
-
const newRect = element.getBoundingClientRect();
|
|
98
|
-
if (!isEqual(data.rect, newRect)) {
|
|
99
|
-
data.rect = newRect;
|
|
100
|
-
changedRectsData.push(data);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
changedRectsData.forEach((data) => {
|
|
104
|
-
data.callbacks.forEach((callback) => callback(data.rect));
|
|
105
|
-
});
|
|
106
|
-
rafId = requestAnimationFrame(runLoop);
|
|
107
|
-
}
|
|
108
|
-
function isEqual(rect1, rect2) {
|
|
109
|
-
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/auto-update.ts
|
|
113
36
|
function resolveOptions(option) {
|
|
114
|
-
|
|
115
|
-
const bool = isBoolean(option);
|
|
37
|
+
const bool = typeof option === "boolean";
|
|
116
38
|
return {
|
|
117
|
-
ancestorResize: bool ? option :
|
|
118
|
-
ancestorScroll: bool ? option :
|
|
119
|
-
referenceResize: bool ? option :
|
|
39
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
40
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
41
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
120
42
|
};
|
|
121
43
|
}
|
|
122
44
|
function autoUpdate(reference, floating, update, options = false) {
|
|
@@ -127,9 +49,9 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
127
49
|
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
128
50
|
}
|
|
129
51
|
function addResizeListeners() {
|
|
130
|
-
let cleanups = [
|
|
52
|
+
let cleanups = [(0, import_element_rect.trackElementRect)(floating, update)];
|
|
131
53
|
if (referenceResize && isHTMLElement(reference)) {
|
|
132
|
-
cleanups.push(
|
|
54
|
+
cleanups.push((0, import_element_rect.trackElementRect)(reference, update));
|
|
133
55
|
}
|
|
134
56
|
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
135
57
|
return () => cleanups.forEach((fn) => fn());
|
package/dist/auto-update.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
autoUpdate
|
|
3
|
-
|
|
4
|
-
} from "./chunk-MDQJEIPL.mjs";
|
|
2
|
+
autoUpdate
|
|
3
|
+
} from "./chunk-KMOWWEFH.mjs";
|
|
5
4
|
import {
|
|
6
5
|
shiftArrow,
|
|
7
6
|
transformOrigin
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
|
|
10
9
|
// src/get-placement.ts
|
|
11
10
|
import { arrow, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
|
|
11
|
+
import { callAll } from "@zag-js/utils";
|
|
12
12
|
var defaultOptions = {
|
|
13
13
|
strategy: "absolute",
|
|
14
14
|
placement: "bottom",
|
|
@@ -36,7 +36,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
36
36
|
if (options.gutter || options.offset) {
|
|
37
37
|
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
38
38
|
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
39
|
-
if (
|
|
39
|
+
if (data?.mainAxis != null)
|
|
40
40
|
data.mainAxis += arrowOffset;
|
|
41
41
|
middleware.push(offset(data));
|
|
42
42
|
}
|
|
@@ -87,7 +87,6 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
87
87
|
strategy,
|
|
88
88
|
...config
|
|
89
89
|
}).then((data) => {
|
|
90
|
-
var _a;
|
|
91
90
|
const x = Math.round(data.x);
|
|
92
91
|
const y = Math.round(data.y);
|
|
93
92
|
Object.assign(floating.style, {
|
|
@@ -96,7 +95,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
96
95
|
left: "0",
|
|
97
96
|
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
98
97
|
});
|
|
99
|
-
|
|
98
|
+
options.onComplete?.({ ...data, compute });
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
compute();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/auto-update.ts
|
|
2
|
+
import { getOverflowAncestors } from "@floating-ui/dom";
|
|
3
|
+
import { trackElementRect } from "@zag-js/element-rect";
|
|
4
|
+
var callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
5
|
+
var isHTMLElement = (el) => {
|
|
6
|
+
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
7
|
+
};
|
|
8
|
+
var addDomEvent = (el, type, fn, options) => {
|
|
9
|
+
el.addEventListener(type, fn, options);
|
|
10
|
+
return () => el.removeEventListener(type, fn, options);
|
|
11
|
+
};
|
|
12
|
+
function resolveOptions(option) {
|
|
13
|
+
const bool = typeof option === "boolean";
|
|
14
|
+
return {
|
|
15
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
16
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
17
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function autoUpdate(reference, floating, update, options = false) {
|
|
21
|
+
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
22
|
+
const useAncestors = ancestorScroll || ancestorResize;
|
|
23
|
+
const ancestors = [];
|
|
24
|
+
if (useAncestors && isHTMLElement(reference)) {
|
|
25
|
+
ancestors.push(...getOverflowAncestors(reference));
|
|
26
|
+
}
|
|
27
|
+
function addResizeListeners() {
|
|
28
|
+
let cleanups = [trackElementRect(floating, update)];
|
|
29
|
+
if (referenceResize && isHTMLElement(reference)) {
|
|
30
|
+
cleanups.push(trackElementRect(reference, update));
|
|
31
|
+
}
|
|
32
|
+
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
33
|
+
return () => cleanups.forEach((fn) => fn());
|
|
34
|
+
}
|
|
35
|
+
function addScrollListeners() {
|
|
36
|
+
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
37
|
+
}
|
|
38
|
+
return callAll(addResizeListeners(), addScrollListeners());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
autoUpdate
|
|
43
|
+
};
|
package/dist/get-placement.js
CHANGED
|
@@ -25,102 +25,25 @@ __export(get_placement_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(get_placement_exports);
|
|
27
27
|
var import_dom2 = require("@floating-ui/dom");
|
|
28
|
-
|
|
29
|
-
// ../core/src/functions.ts
|
|
30
|
-
var runIfFn = (v, ...a) => {
|
|
31
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
32
|
-
return res != null ? res : void 0;
|
|
33
|
-
};
|
|
34
|
-
var callAll = (...fns) => (...a) => {
|
|
35
|
-
fns.forEach(function(fn) {
|
|
36
|
-
fn == null ? void 0 : fn(...a);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// ../core/src/guard.ts
|
|
41
|
-
var isBoolean = (v) => v === true || v === false;
|
|
42
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
28
|
+
var import_utils = require("@zag-js/utils");
|
|
43
29
|
|
|
44
30
|
// src/auto-update.ts
|
|
45
31
|
var import_dom = require("@floating-ui/dom");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return typeof
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
56
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
57
|
-
return () => {
|
|
58
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ../dom/src/rect-observer.ts
|
|
63
|
-
function getObservedElements() {
|
|
64
|
-
;
|
|
65
|
-
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
66
|
-
return globalThis.__rectObserverMap__;
|
|
67
|
-
}
|
|
68
|
-
function observeElementRect(el, fn) {
|
|
69
|
-
const observedElements = getObservedElements();
|
|
70
|
-
const data = observedElements.get(el);
|
|
71
|
-
if (!data) {
|
|
72
|
-
observedElements.set(el, { rect: {}, callbacks: [fn] });
|
|
73
|
-
if (observedElements.size === 1) {
|
|
74
|
-
rafId = requestAnimationFrame(runLoop);
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
data.callbacks.push(fn);
|
|
78
|
-
fn(el.getBoundingClientRect());
|
|
79
|
-
}
|
|
80
|
-
return function unobserve() {
|
|
81
|
-
const data2 = observedElements.get(el);
|
|
82
|
-
if (!data2)
|
|
83
|
-
return;
|
|
84
|
-
const index = data2.callbacks.indexOf(fn);
|
|
85
|
-
if (index > -1) {
|
|
86
|
-
data2.callbacks.splice(index, 1);
|
|
87
|
-
}
|
|
88
|
-
if (data2.callbacks.length === 0) {
|
|
89
|
-
observedElements.delete(el);
|
|
90
|
-
if (observedElements.size === 0) {
|
|
91
|
-
cancelAnimationFrame(rafId);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
var rafId;
|
|
97
|
-
function runLoop() {
|
|
98
|
-
const observedElements = getObservedElements();
|
|
99
|
-
const changedRectsData = [];
|
|
100
|
-
observedElements.forEach((data, element) => {
|
|
101
|
-
const newRect = element.getBoundingClientRect();
|
|
102
|
-
if (!isEqual(data.rect, newRect)) {
|
|
103
|
-
data.rect = newRect;
|
|
104
|
-
changedRectsData.push(data);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
changedRectsData.forEach((data) => {
|
|
108
|
-
data.callbacks.forEach((callback) => callback(data.rect));
|
|
109
|
-
});
|
|
110
|
-
rafId = requestAnimationFrame(runLoop);
|
|
111
|
-
}
|
|
112
|
-
function isEqual(rect1, rect2) {
|
|
113
|
-
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/auto-update.ts
|
|
32
|
+
var import_element_rect = require("@zag-js/element-rect");
|
|
33
|
+
var callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
34
|
+
var isHTMLElement = (el) => {
|
|
35
|
+
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
36
|
+
};
|
|
37
|
+
var addDomEvent = (el, type, fn, options) => {
|
|
38
|
+
el.addEventListener(type, fn, options);
|
|
39
|
+
return () => el.removeEventListener(type, fn, options);
|
|
40
|
+
};
|
|
117
41
|
function resolveOptions(option) {
|
|
118
|
-
|
|
119
|
-
const bool = isBoolean(option);
|
|
42
|
+
const bool = typeof option === "boolean";
|
|
120
43
|
return {
|
|
121
|
-
ancestorResize: bool ? option :
|
|
122
|
-
ancestorScroll: bool ? option :
|
|
123
|
-
referenceResize: bool ? option :
|
|
44
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
45
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
46
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
124
47
|
};
|
|
125
48
|
}
|
|
126
49
|
function autoUpdate(reference, floating, update, options = false) {
|
|
@@ -131,9 +54,9 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
131
54
|
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
132
55
|
}
|
|
133
56
|
function addResizeListeners() {
|
|
134
|
-
let cleanups = [
|
|
57
|
+
let cleanups = [(0, import_element_rect.trackElementRect)(floating, update)];
|
|
135
58
|
if (referenceResize && isHTMLElement(reference)) {
|
|
136
|
-
cleanups.push(
|
|
59
|
+
cleanups.push((0, import_element_rect.trackElementRect)(reference, update));
|
|
137
60
|
}
|
|
138
61
|
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
139
62
|
return () => cleanups.forEach((fn) => fn());
|
|
@@ -224,7 +147,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
224
147
|
if (options.gutter || options.offset) {
|
|
225
148
|
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
226
149
|
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
227
|
-
if (
|
|
150
|
+
if (data?.mainAxis != null)
|
|
228
151
|
data.mainAxis += arrowOffset;
|
|
229
152
|
middleware.push((0, import_dom2.offset)(data));
|
|
230
153
|
}
|
|
@@ -275,7 +198,6 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
275
198
|
strategy,
|
|
276
199
|
...config
|
|
277
200
|
}).then((data) => {
|
|
278
|
-
var _a;
|
|
279
201
|
const x = Math.round(data.x);
|
|
280
202
|
const y = Math.round(data.y);
|
|
281
203
|
Object.assign(floating.style, {
|
|
@@ -284,11 +206,11 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
284
206
|
left: "0",
|
|
285
207
|
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
286
208
|
});
|
|
287
|
-
|
|
209
|
+
options.onComplete?.({ ...data, compute });
|
|
288
210
|
});
|
|
289
211
|
}
|
|
290
212
|
compute();
|
|
291
|
-
return callAll(
|
|
213
|
+
return (0, import_utils.callAll)(
|
|
292
214
|
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
293
215
|
options.onCleanup
|
|
294
216
|
);
|
package/dist/get-placement.mjs
CHANGED
package/dist/get-styles.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare function getPlacementStyles(options: Options): {
|
|
|
24
24
|
readonly zIndex: "inherit";
|
|
25
25
|
};
|
|
26
26
|
floating: {
|
|
27
|
-
position: "
|
|
27
|
+
position: "absolute" | "fixed";
|
|
28
28
|
readonly top?: 0 | undefined;
|
|
29
29
|
readonly left?: 0 | undefined;
|
|
30
30
|
readonly opacity?: 0 | undefined;
|
package/dist/index.js
CHANGED
|
@@ -28,102 +28,25 @@ module.exports = __toCommonJS(src_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/get-placement.ts
|
|
30
30
|
var import_dom2 = require("@floating-ui/dom");
|
|
31
|
-
|
|
32
|
-
// ../core/src/functions.ts
|
|
33
|
-
var runIfFn = (v, ...a) => {
|
|
34
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
35
|
-
return res != null ? res : void 0;
|
|
36
|
-
};
|
|
37
|
-
var callAll = (...fns) => (...a) => {
|
|
38
|
-
fns.forEach(function(fn) {
|
|
39
|
-
fn == null ? void 0 : fn(...a);
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// ../core/src/guard.ts
|
|
44
|
-
var isBoolean = (v) => v === true || v === false;
|
|
45
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
31
|
+
var import_utils = require("@zag-js/utils");
|
|
46
32
|
|
|
47
33
|
// src/auto-update.ts
|
|
48
34
|
var import_dom = require("@floating-ui/dom");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return typeof
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
59
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
60
|
-
return () => {
|
|
61
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ../dom/src/rect-observer.ts
|
|
66
|
-
function getObservedElements() {
|
|
67
|
-
;
|
|
68
|
-
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
69
|
-
return globalThis.__rectObserverMap__;
|
|
70
|
-
}
|
|
71
|
-
function observeElementRect(el, fn) {
|
|
72
|
-
const observedElements = getObservedElements();
|
|
73
|
-
const data = observedElements.get(el);
|
|
74
|
-
if (!data) {
|
|
75
|
-
observedElements.set(el, { rect: {}, callbacks: [fn] });
|
|
76
|
-
if (observedElements.size === 1) {
|
|
77
|
-
rafId = requestAnimationFrame(runLoop);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
data.callbacks.push(fn);
|
|
81
|
-
fn(el.getBoundingClientRect());
|
|
82
|
-
}
|
|
83
|
-
return function unobserve() {
|
|
84
|
-
const data2 = observedElements.get(el);
|
|
85
|
-
if (!data2)
|
|
86
|
-
return;
|
|
87
|
-
const index = data2.callbacks.indexOf(fn);
|
|
88
|
-
if (index > -1) {
|
|
89
|
-
data2.callbacks.splice(index, 1);
|
|
90
|
-
}
|
|
91
|
-
if (data2.callbacks.length === 0) {
|
|
92
|
-
observedElements.delete(el);
|
|
93
|
-
if (observedElements.size === 0) {
|
|
94
|
-
cancelAnimationFrame(rafId);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
var rafId;
|
|
100
|
-
function runLoop() {
|
|
101
|
-
const observedElements = getObservedElements();
|
|
102
|
-
const changedRectsData = [];
|
|
103
|
-
observedElements.forEach((data, element) => {
|
|
104
|
-
const newRect = element.getBoundingClientRect();
|
|
105
|
-
if (!isEqual(data.rect, newRect)) {
|
|
106
|
-
data.rect = newRect;
|
|
107
|
-
changedRectsData.push(data);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
changedRectsData.forEach((data) => {
|
|
111
|
-
data.callbacks.forEach((callback) => callback(data.rect));
|
|
112
|
-
});
|
|
113
|
-
rafId = requestAnimationFrame(runLoop);
|
|
114
|
-
}
|
|
115
|
-
function isEqual(rect1, rect2) {
|
|
116
|
-
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/auto-update.ts
|
|
35
|
+
var import_element_rect = require("@zag-js/element-rect");
|
|
36
|
+
var callAll = (...fns) => () => fns.forEach((fn) => fn());
|
|
37
|
+
var isHTMLElement = (el) => {
|
|
38
|
+
return typeof el === "object" && el !== null && el.nodeType === 1;
|
|
39
|
+
};
|
|
40
|
+
var addDomEvent = (el, type, fn, options) => {
|
|
41
|
+
el.addEventListener(type, fn, options);
|
|
42
|
+
return () => el.removeEventListener(type, fn, options);
|
|
43
|
+
};
|
|
120
44
|
function resolveOptions(option) {
|
|
121
|
-
|
|
122
|
-
const bool = isBoolean(option);
|
|
45
|
+
const bool = typeof option === "boolean";
|
|
123
46
|
return {
|
|
124
|
-
ancestorResize: bool ? option :
|
|
125
|
-
ancestorScroll: bool ? option :
|
|
126
|
-
referenceResize: bool ? option :
|
|
47
|
+
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
48
|
+
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
49
|
+
referenceResize: bool ? option : option.referenceResize ?? true
|
|
127
50
|
};
|
|
128
51
|
}
|
|
129
52
|
function autoUpdate(reference, floating, update, options = false) {
|
|
@@ -134,9 +57,9 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
134
57
|
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
135
58
|
}
|
|
136
59
|
function addResizeListeners() {
|
|
137
|
-
let cleanups = [
|
|
60
|
+
let cleanups = [(0, import_element_rect.trackElementRect)(floating, update)];
|
|
138
61
|
if (referenceResize && isHTMLElement(reference)) {
|
|
139
|
-
cleanups.push(
|
|
62
|
+
cleanups.push((0, import_element_rect.trackElementRect)(reference, update));
|
|
140
63
|
}
|
|
141
64
|
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
142
65
|
return () => cleanups.forEach((fn) => fn());
|
|
@@ -227,7 +150,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
227
150
|
if (options.gutter || options.offset) {
|
|
228
151
|
const arrowOffset = arrowEl ? arrowEl.offsetHeight / 2 : 0;
|
|
229
152
|
const data = options.gutter ? { mainAxis: options.gutter } : options.offset;
|
|
230
|
-
if (
|
|
153
|
+
if (data?.mainAxis != null)
|
|
231
154
|
data.mainAxis += arrowOffset;
|
|
232
155
|
middleware.push((0, import_dom2.offset)(data));
|
|
233
156
|
}
|
|
@@ -278,7 +201,6 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
278
201
|
strategy,
|
|
279
202
|
...config
|
|
280
203
|
}).then((data) => {
|
|
281
|
-
var _a;
|
|
282
204
|
const x = Math.round(data.x);
|
|
283
205
|
const y = Math.round(data.y);
|
|
284
206
|
Object.assign(floating.style, {
|
|
@@ -287,11 +209,11 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
287
209
|
left: "0",
|
|
288
210
|
transform: `translate3d(${x}px, ${y}px, 0)`
|
|
289
211
|
});
|
|
290
|
-
|
|
212
|
+
options.onComplete?.({ ...data, compute });
|
|
291
213
|
});
|
|
292
214
|
}
|
|
293
215
|
compute();
|
|
294
|
-
return callAll(
|
|
216
|
+
return (0, import_utils.callAll)(
|
|
295
217
|
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
296
218
|
options.onCleanup
|
|
297
219
|
);
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/popper",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Dynamic positioning logic for ui machines",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@floating-ui/dom": "1.1
|
|
25
|
+
"@floating-ui/dom": "1.2.1",
|
|
26
|
+
"@zag-js/dom-query": "0.1.3",
|
|
27
|
+
"@zag-js/utils": "0.3.3",
|
|
28
|
+
"@zag-js/element-rect": "0.2.2"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"clean-package": "2.2.0"
|
|
29
|
-
"@zag-js/dom-utils": "0.2.2",
|
|
30
|
-
"@zag-js/utils": "0.3.2"
|
|
31
|
+
"clean-package": "2.2.0"
|
|
31
32
|
},
|
|
32
33
|
"clean-package": "../../../clean-package.config.json",
|
|
33
34
|
"main": "dist/index.js",
|
package/dist/chunk-MDQJEIPL.mjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// src/auto-update.ts
|
|
2
|
-
import { getOverflowAncestors } from "@floating-ui/dom";
|
|
3
|
-
|
|
4
|
-
// ../core/src/functions.ts
|
|
5
|
-
var runIfFn = (v, ...a) => {
|
|
6
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
7
|
-
return res != null ? res : void 0;
|
|
8
|
-
};
|
|
9
|
-
var callAll = (...fns) => (...a) => {
|
|
10
|
-
fns.forEach(function(fn) {
|
|
11
|
-
fn == null ? void 0 : fn(...a);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// ../core/src/guard.ts
|
|
16
|
-
var isBoolean = (v) => v === true || v === false;
|
|
17
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
18
|
-
|
|
19
|
-
// ../dom/src/query.ts
|
|
20
|
-
function isHTMLElement(v) {
|
|
21
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ../dom/src/listener.ts
|
|
25
|
-
var isRef = (v) => hasProp(v, "current");
|
|
26
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
27
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
28
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
29
|
-
return () => {
|
|
30
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ../dom/src/rect-observer.ts
|
|
35
|
-
function getObservedElements() {
|
|
36
|
-
;
|
|
37
|
-
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map();
|
|
38
|
-
return globalThis.__rectObserverMap__;
|
|
39
|
-
}
|
|
40
|
-
function observeElementRect(el, fn) {
|
|
41
|
-
const observedElements = getObservedElements();
|
|
42
|
-
const data = observedElements.get(el);
|
|
43
|
-
if (!data) {
|
|
44
|
-
observedElements.set(el, { rect: {}, callbacks: [fn] });
|
|
45
|
-
if (observedElements.size === 1) {
|
|
46
|
-
rafId = requestAnimationFrame(runLoop);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
data.callbacks.push(fn);
|
|
50
|
-
fn(el.getBoundingClientRect());
|
|
51
|
-
}
|
|
52
|
-
return function unobserve() {
|
|
53
|
-
const data2 = observedElements.get(el);
|
|
54
|
-
if (!data2)
|
|
55
|
-
return;
|
|
56
|
-
const index = data2.callbacks.indexOf(fn);
|
|
57
|
-
if (index > -1) {
|
|
58
|
-
data2.callbacks.splice(index, 1);
|
|
59
|
-
}
|
|
60
|
-
if (data2.callbacks.length === 0) {
|
|
61
|
-
observedElements.delete(el);
|
|
62
|
-
if (observedElements.size === 0) {
|
|
63
|
-
cancelAnimationFrame(rafId);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
var rafId;
|
|
69
|
-
function runLoop() {
|
|
70
|
-
const observedElements = getObservedElements();
|
|
71
|
-
const changedRectsData = [];
|
|
72
|
-
observedElements.forEach((data, element) => {
|
|
73
|
-
const newRect = element.getBoundingClientRect();
|
|
74
|
-
if (!isEqual(data.rect, newRect)) {
|
|
75
|
-
data.rect = newRect;
|
|
76
|
-
changedRectsData.push(data);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
changedRectsData.forEach((data) => {
|
|
80
|
-
data.callbacks.forEach((callback) => callback(data.rect));
|
|
81
|
-
});
|
|
82
|
-
rafId = requestAnimationFrame(runLoop);
|
|
83
|
-
}
|
|
84
|
-
function isEqual(rect1, rect2) {
|
|
85
|
-
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/auto-update.ts
|
|
89
|
-
function resolveOptions(option) {
|
|
90
|
-
var _a, _b, _c;
|
|
91
|
-
const bool = isBoolean(option);
|
|
92
|
-
return {
|
|
93
|
-
ancestorResize: bool ? option : (_a = option.ancestorResize) != null ? _a : true,
|
|
94
|
-
ancestorScroll: bool ? option : (_b = option.ancestorScroll) != null ? _b : true,
|
|
95
|
-
referenceResize: bool ? option : (_c = option.referenceResize) != null ? _c : true
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function autoUpdate(reference, floating, update, options = false) {
|
|
99
|
-
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
100
|
-
const useAncestors = ancestorScroll || ancestorResize;
|
|
101
|
-
const ancestors = [];
|
|
102
|
-
if (useAncestors && isHTMLElement(reference)) {
|
|
103
|
-
ancestors.push(...getOverflowAncestors(reference));
|
|
104
|
-
}
|
|
105
|
-
function addResizeListeners() {
|
|
106
|
-
let cleanups = [observeElementRect(floating, update)];
|
|
107
|
-
if (referenceResize && isHTMLElement(reference)) {
|
|
108
|
-
cleanups.push(observeElementRect(reference, update));
|
|
109
|
-
}
|
|
110
|
-
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
111
|
-
return () => cleanups.forEach((fn) => fn());
|
|
112
|
-
}
|
|
113
|
-
function addScrollListeners() {
|
|
114
|
-
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
115
|
-
}
|
|
116
|
-
return callAll(addResizeListeners(), addScrollListeners());
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export {
|
|
120
|
-
callAll,
|
|
121
|
-
autoUpdate
|
|
122
|
-
};
|