@zag-js/popper 0.2.3 → 0.2.5
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 +10 -87
- package/dist/auto-update.mjs +1 -1
- package/dist/{chunk-L7FW633C.mjs → chunk-K6E3OR2A.mjs} +3 -3
- package/dist/chunk-KMOWWEFH.mjs +43 -0
- package/dist/get-placement.js +14 -90
- package/dist/get-placement.mjs +2 -2
- package/dist/get-styles.d.ts +1 -1
- package/dist/index.js +14 -90
- package/dist/index.mjs +2 -2
- package/package.json +6 -5
- package/dist/chunk-A2YMJLJJ.mjs +0 -121
package/dist/auto-update.js
CHANGED
|
@@ -24,94 +24,17 @@ __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 ?? 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?.nodeType === Node.ELEMENT_NODE && typeof 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?.addEventListener(eventName, handler, options);
|
|
53
|
-
return () => {
|
|
54
|
-
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
|
-
const bool =
|
|
37
|
+
const bool = typeof option === "boolean";
|
|
115
38
|
return {
|
|
116
39
|
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
117
40
|
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
@@ -126,9 +49,9 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
126
49
|
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
127
50
|
}
|
|
128
51
|
function addResizeListeners() {
|
|
129
|
-
let cleanups = [
|
|
52
|
+
let cleanups = [(0, import_element_rect.trackElementRect)(floating, update)];
|
|
130
53
|
if (referenceResize && isHTMLElement(reference)) {
|
|
131
|
-
cleanups.push(
|
|
54
|
+
cleanups.push((0, import_element_rect.trackElementRect)(reference, update));
|
|
132
55
|
}
|
|
133
56
|
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
134
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-A2YMJLJJ.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",
|
|
@@ -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,97 +25,21 @@ __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 ?? void 0;
|
|
33
|
-
};
|
|
34
|
-
var callAll = (...fns) => (...a) => {
|
|
35
|
-
fns.forEach(function(fn) {
|
|
36
|
-
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?.addEventListener(eventName, handler, options);
|
|
57
|
-
return () => {
|
|
58
|
-
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
|
-
const bool =
|
|
42
|
+
const bool = typeof option === "boolean";
|
|
119
43
|
return {
|
|
120
44
|
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
121
45
|
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
@@ -130,9 +54,9 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
130
54
|
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
131
55
|
}
|
|
132
56
|
function addResizeListeners() {
|
|
133
|
-
let cleanups = [
|
|
57
|
+
let cleanups = [(0, import_element_rect.trackElementRect)(floating, update)];
|
|
134
58
|
if (referenceResize && isHTMLElement(reference)) {
|
|
135
|
-
cleanups.push(
|
|
59
|
+
cleanups.push((0, import_element_rect.trackElementRect)(reference, update));
|
|
136
60
|
}
|
|
137
61
|
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
138
62
|
return () => cleanups.forEach((fn) => fn());
|
|
@@ -286,7 +210,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
286
210
|
});
|
|
287
211
|
}
|
|
288
212
|
compute();
|
|
289
|
-
return callAll(
|
|
213
|
+
return (0, import_utils.callAll)(
|
|
290
214
|
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
291
215
|
options.onCleanup
|
|
292
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,97 +28,21 @@ 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 ?? void 0;
|
|
36
|
-
};
|
|
37
|
-
var callAll = (...fns) => (...a) => {
|
|
38
|
-
fns.forEach(function(fn) {
|
|
39
|
-
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?.addEventListener(eventName, handler, options);
|
|
60
|
-
return () => {
|
|
61
|
-
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
|
-
const bool =
|
|
45
|
+
const bool = typeof option === "boolean";
|
|
122
46
|
return {
|
|
123
47
|
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
124
48
|
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
@@ -133,9 +57,9 @@ function autoUpdate(reference, floating, update, options = false) {
|
|
|
133
57
|
ancestors.push(...(0, import_dom.getOverflowAncestors)(reference));
|
|
134
58
|
}
|
|
135
59
|
function addResizeListeners() {
|
|
136
|
-
let cleanups = [
|
|
60
|
+
let cleanups = [(0, import_element_rect.trackElementRect)(floating, update)];
|
|
137
61
|
if (referenceResize && isHTMLElement(reference)) {
|
|
138
|
-
cleanups.push(
|
|
62
|
+
cleanups.push((0, import_element_rect.trackElementRect)(reference, update));
|
|
139
63
|
}
|
|
140
64
|
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
141
65
|
return () => cleanups.forEach((fn) => fn());
|
|
@@ -289,7 +213,7 @@ function getPlacement(reference, floating, opts = {}) {
|
|
|
289
213
|
});
|
|
290
214
|
}
|
|
291
215
|
compute();
|
|
292
|
-
return callAll(
|
|
216
|
+
return (0, import_utils.callAll)(
|
|
293
217
|
options.listeners ? autoUpdate(reference, floating, compute, options.listeners) : void 0,
|
|
294
218
|
options.onCleanup
|
|
295
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.5",
|
|
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.4",
|
|
27
|
+
"@zag-js/element-rect": "0.2.2",
|
|
28
|
+
"@zag-js/utils": "0.3.3"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"clean-package": "2.2.0"
|
|
29
|
-
"@zag-js/dom-utils": "0.2.4",
|
|
30
|
-
"@zag-js/utils": "0.3.3"
|
|
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-A2YMJLJJ.mjs
DELETED
|
@@ -1,121 +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 ?? void 0;
|
|
8
|
-
};
|
|
9
|
-
var callAll = (...fns) => (...a) => {
|
|
10
|
-
fns.forEach(function(fn) {
|
|
11
|
-
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?.nodeType === Node.ELEMENT_NODE && typeof 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?.addEventListener(eventName, handler, options);
|
|
29
|
-
return () => {
|
|
30
|
-
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
|
-
const bool = isBoolean(option);
|
|
91
|
-
return {
|
|
92
|
-
ancestorResize: bool ? option : option.ancestorResize ?? true,
|
|
93
|
-
ancestorScroll: bool ? option : option.ancestorScroll ?? true,
|
|
94
|
-
referenceResize: bool ? option : option.referenceResize ?? true
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function autoUpdate(reference, floating, update, options = false) {
|
|
98
|
-
const { ancestorScroll, ancestorResize, referenceResize } = resolveOptions(options);
|
|
99
|
-
const useAncestors = ancestorScroll || ancestorResize;
|
|
100
|
-
const ancestors = [];
|
|
101
|
-
if (useAncestors && isHTMLElement(reference)) {
|
|
102
|
-
ancestors.push(...getOverflowAncestors(reference));
|
|
103
|
-
}
|
|
104
|
-
function addResizeListeners() {
|
|
105
|
-
let cleanups = [observeElementRect(floating, update)];
|
|
106
|
-
if (referenceResize && isHTMLElement(reference)) {
|
|
107
|
-
cleanups.push(observeElementRect(reference, update));
|
|
108
|
-
}
|
|
109
|
-
cleanups.push(callAll(...ancestors.map((el) => addDomEvent(el, "resize", update))));
|
|
110
|
-
return () => cleanups.forEach((fn) => fn());
|
|
111
|
-
}
|
|
112
|
-
function addScrollListeners() {
|
|
113
|
-
return callAll(...ancestors.map((el) => addDomEvent(el, "scroll", update, { passive: true })));
|
|
114
|
-
}
|
|
115
|
-
return callAll(addResizeListeners(), addScrollListeners());
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export {
|
|
119
|
-
callAll,
|
|
120
|
-
autoUpdate
|
|
121
|
-
};
|