@zag-js/popover 2.0.0-next.2 → 2.0.0-next.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.d.mts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +12 -38
- package/dist/index.mjs +2 -7
- package/dist/popover.anatomy.d.mts +2 -6
- package/dist/popover.anatomy.d.ts +2 -6
- package/dist/popover.anatomy.js +8 -44
- package/dist/popover.anatomy.mjs +4 -18
- package/dist/popover.connect.d.mts +3 -9
- package/dist/popover.connect.d.ts +3 -9
- package/dist/popover.connect.js +270 -212
- package/dist/popover.connect.mjs +263 -174
- package/dist/popover.dom.d.mts +19 -21
- package/dist/popover.dom.d.ts +19 -21
- package/dist/popover.dom.js +59 -84
- package/dist/popover.dom.mjs +38 -43
- package/dist/popover.machine.d.mts +2 -9
- package/dist/popover.machine.d.ts +2 -9
- package/dist/popover.machine.js +466 -357
- package/dist/popover.machine.mjs +459 -319
- package/dist/popover.props.d.mts +3 -10
- package/dist/popover.props.d.ts +3 -10
- package/dist/popover.props.js +34 -59
- package/dist/popover.props.mjs +30 -33
- package/dist/popover.style.d.mts +15 -0
- package/dist/popover.style.d.ts +15 -0
- package/dist/popover.style.js +15 -0
- package/dist/popover.style.mjs +11 -0
- package/dist/popover.types.d.mts +350 -237
- package/dist/popover.types.d.ts +350 -237
- package/dist/popover.types.js +4 -18
- package/dist/popover.types.mjs +1 -0
- package/package.json +12 -12
package/dist/popover.connect.js
CHANGED
|
@@ -1,215 +1,273 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/popover.connect.ts
|
|
31
|
-
var popover_connect_exports = {};
|
|
32
|
-
__export(popover_connect_exports, {
|
|
33
|
-
connect: () => connect
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
4
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
5
|
+
const require_popover_anatomy = require("./popover.anatomy.js");
|
|
6
|
+
const require_popover_dom = require("./popover.dom.js");
|
|
7
|
+
const require_popover_style = require("./popover.style.js");
|
|
8
|
+
let _zag_js_dismissable = require("@zag-js/dismissable");
|
|
9
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
10
|
+
let _zag_js_popper = require("@zag-js/popper");
|
|
11
|
+
let _zag_js_utils = require("@zag-js/utils");
|
|
12
|
+
// src/popover.connect.ts
|
|
13
|
+
const defaultTranslations = { closeTriggerLabel: "close" };
|
|
45
14
|
function connect(service, normalize) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
15
|
+
const { state, context, send, prop, scope } = service;
|
|
16
|
+
const layer = context.get("layer");
|
|
17
|
+
const translations = (0, _zag_js_utils.mergeWithDefault)(defaultTranslations, prop("translations"));
|
|
18
|
+
const open = state.matches("open");
|
|
19
|
+
const currentPlacement = context.get("currentPlacement");
|
|
20
|
+
const currentPlacementSide = currentPlacement ? (0, _zag_js_popper.getPlacementSide)(currentPlacement) : void 0;
|
|
21
|
+
const rendered = context.get("renderedElements");
|
|
22
|
+
const triggerValue = context.get("triggerValue");
|
|
23
|
+
const transitioning = context.get("transitioning");
|
|
24
|
+
const instant = context.get("instant");
|
|
25
|
+
const activationDirection = context.get("activationDirection");
|
|
26
|
+
const viewportRendered = rendered.viewport;
|
|
27
|
+
const popperStyles = (0, _zag_js_popper.getPlacementStyles)({
|
|
28
|
+
...prop("positioning"),
|
|
29
|
+
placement: currentPlacement
|
|
30
|
+
});
|
|
31
|
+
function getTriggerState(props = {}) {
|
|
32
|
+
const { value } = props;
|
|
33
|
+
const current = value == null ? false : triggerValue === value;
|
|
34
|
+
return {
|
|
35
|
+
value,
|
|
36
|
+
current,
|
|
37
|
+
open: value == null ? open : open && current
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function getPositionerState() {
|
|
41
|
+
return {
|
|
42
|
+
nested: !!layer?.nested,
|
|
43
|
+
hasNested: !!layer?.hasNested,
|
|
44
|
+
transitioning,
|
|
45
|
+
instant
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function getContentState(props = {}) {
|
|
49
|
+
const { value } = props;
|
|
50
|
+
return {
|
|
51
|
+
open: value == null ? open : triggerValue === value,
|
|
52
|
+
modal: !!prop("modal"),
|
|
53
|
+
nested: !!layer?.nested,
|
|
54
|
+
hasNested: !!layer?.hasNested,
|
|
55
|
+
placement: currentPlacement,
|
|
56
|
+
side: currentPlacementSide,
|
|
57
|
+
activationDirection,
|
|
58
|
+
instant
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function getViewportState() {
|
|
62
|
+
return {
|
|
63
|
+
open,
|
|
64
|
+
instant,
|
|
65
|
+
side: currentPlacementSide,
|
|
66
|
+
activationDirection,
|
|
67
|
+
transitioning
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
open,
|
|
72
|
+
setOpen(nextOpen, reason = "script") {
|
|
73
|
+
send({
|
|
74
|
+
type: nextOpen ? "OPEN" : "CLOSE",
|
|
75
|
+
src: reason,
|
|
76
|
+
replaces: "open"
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
triggerValue,
|
|
80
|
+
activationDirection,
|
|
81
|
+
getContentValues() {
|
|
82
|
+
const previousValue = context.get("previousTriggerValue");
|
|
83
|
+
const values = [];
|
|
84
|
+
if (previousValue != null && previousValue !== triggerValue) values.push(previousValue);
|
|
85
|
+
if (triggerValue != null) values.push(triggerValue);
|
|
86
|
+
return values;
|
|
87
|
+
},
|
|
88
|
+
setTriggerValue(value) {
|
|
89
|
+
send({
|
|
90
|
+
type: "TRIGGER_VALUE.SET",
|
|
91
|
+
value
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
reposition(options = {}) {
|
|
95
|
+
send({
|
|
96
|
+
type: "POSITIONING.SET",
|
|
97
|
+
options
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
getArrowProps() {
|
|
101
|
+
return normalize.element({
|
|
102
|
+
...require_popover_anatomy.parts.arrow.attrs(scope.id),
|
|
103
|
+
dir: prop("dir"),
|
|
104
|
+
hidden: viewportRendered ? !open : void 0,
|
|
105
|
+
"data-state": open ? "open" : "closed",
|
|
106
|
+
style: popperStyles.arrow
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
getArrowTipProps() {
|
|
110
|
+
return normalize.element({
|
|
111
|
+
...require_popover_anatomy.parts.arrowTip.attrs(scope.id),
|
|
112
|
+
dir: prop("dir"),
|
|
113
|
+
style: popperStyles.arrowTip
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
getAnchorProps() {
|
|
117
|
+
return normalize.element({
|
|
118
|
+
...require_popover_anatomy.parts.anchor.attrs(scope.id),
|
|
119
|
+
dir: prop("dir")
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
getTriggerState,
|
|
123
|
+
getTriggerProps(props = {}) {
|
|
124
|
+
const { value } = props;
|
|
125
|
+
const triggerState = getTriggerState(props);
|
|
126
|
+
const { current } = triggerState;
|
|
127
|
+
return normalize.button({
|
|
128
|
+
...require_popover_anatomy.parts.trigger.attrs(scope.id),
|
|
129
|
+
dir: prop("dir"),
|
|
130
|
+
type: "button",
|
|
131
|
+
"data-placement": currentPlacement,
|
|
132
|
+
"data-side": currentPlacementSide,
|
|
133
|
+
"data-value": value,
|
|
134
|
+
"data-current": (0, _zag_js_dom_query.dataAttr)(current),
|
|
135
|
+
"aria-haspopup": "dialog",
|
|
136
|
+
"aria-expanded": triggerState.open,
|
|
137
|
+
"data-state": open ? "open" : "closed",
|
|
138
|
+
"aria-controls": require_popover_dom.getContentId(scope, viewportRendered ? value : null),
|
|
139
|
+
onPointerDown(event) {
|
|
140
|
+
if (!(0, _zag_js_dom_query.isLeftClick)(event)) return;
|
|
141
|
+
if ((0, _zag_js_dom_query.isSafari)()) event.currentTarget.focus();
|
|
142
|
+
},
|
|
143
|
+
onClick(event) {
|
|
144
|
+
if (event.defaultPrevented) return;
|
|
145
|
+
const shouldSwitch = open && value != null && !current;
|
|
146
|
+
const instant = event.detail === 0 ? "click" : null;
|
|
147
|
+
send({
|
|
148
|
+
type: shouldSwitch ? "TRIGGER_VALUE.SET" : "TOGGLE",
|
|
149
|
+
value,
|
|
150
|
+
instant,
|
|
151
|
+
src: "trigger-click"
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
onBlur(event) {
|
|
155
|
+
send({
|
|
156
|
+
type: "TRIGGER_BLUR",
|
|
157
|
+
target: event.relatedTarget
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
getIndicatorProps() {
|
|
163
|
+
return normalize.element({
|
|
164
|
+
...require_popover_anatomy.parts.indicator.attrs(scope.id),
|
|
165
|
+
dir: prop("dir"),
|
|
166
|
+
"data-state": open ? "open" : "closed"
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
getPositionerState,
|
|
170
|
+
getPositionerProps() {
|
|
171
|
+
const positionerState = getPositionerState();
|
|
172
|
+
return normalize.element({
|
|
173
|
+
...require_popover_anatomy.parts.positioner.attrs(scope.id),
|
|
174
|
+
dir: prop("dir"),
|
|
175
|
+
"data-transitioning": (0, _zag_js_dom_query.dataAttr)(positionerState.transitioning),
|
|
176
|
+
"data-instant": positionerState.instant ?? void 0,
|
|
177
|
+
...(0, _zag_js_dismissable.getDismissableLayerAttrs)(layer),
|
|
178
|
+
style: {
|
|
179
|
+
...popperStyles.floating,
|
|
180
|
+
...(0, _zag_js_dismissable.getDismissableLayerStyle)(layer),
|
|
181
|
+
...require_popover_style.getViewportSizeStyle(viewportRendered ? context.get("viewportSize") : null)
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
getContentState,
|
|
186
|
+
getContentProps(props = {}) {
|
|
187
|
+
const { value } = props;
|
|
188
|
+
const contentState = getContentState(props);
|
|
189
|
+
const contentLayer = viewportRendered ? null : layer;
|
|
190
|
+
return normalize.element({
|
|
191
|
+
...require_popover_anatomy.parts.content.attrs(scope.id),
|
|
192
|
+
dir: prop("dir"),
|
|
193
|
+
id: require_popover_dom.getContentId(scope, value),
|
|
194
|
+
tabIndex: -1,
|
|
195
|
+
role: "dialog",
|
|
196
|
+
"aria-modal": (0, _zag_js_dom_query.ariaAttr)(contentState.modal),
|
|
197
|
+
hidden: !contentState.open,
|
|
198
|
+
"data-value": value,
|
|
199
|
+
"data-state": contentState.open ? "open" : "closed",
|
|
200
|
+
"data-expanded": (0, _zag_js_dom_query.dataAttr)(contentState.open),
|
|
201
|
+
"aria-labelledby": rendered.title ? require_popover_dom.getTitleId(scope, value) : void 0,
|
|
202
|
+
"aria-describedby": rendered.description ? require_popover_dom.getDescriptionId(scope, value) : void 0,
|
|
203
|
+
"data-placement": contentState.placement,
|
|
204
|
+
"data-side": contentState.side,
|
|
205
|
+
"data-activation-direction": contentState.activationDirection ?? void 0,
|
|
206
|
+
"data-instant": contentState.instant ?? void 0,
|
|
207
|
+
...(0, _zag_js_dismissable.getDismissableLayerAttrs)(contentLayer),
|
|
208
|
+
style: (0, _zag_js_dismissable.getDismissableLayerStyle)(contentLayer, { pointerEvents: true })
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
getViewportState,
|
|
212
|
+
getViewportProps() {
|
|
213
|
+
const viewportState = getViewportState();
|
|
214
|
+
return normalize.element({
|
|
215
|
+
...require_popover_anatomy.parts.viewport.attrs(scope.id),
|
|
216
|
+
dir: prop("dir"),
|
|
217
|
+
hidden: !viewportState.open,
|
|
218
|
+
"data-state": viewportState.open ? "open" : "closed",
|
|
219
|
+
"data-side": viewportState.side,
|
|
220
|
+
"data-instant": viewportState.instant ?? void 0,
|
|
221
|
+
"data-activation-direction": viewportState.activationDirection ?? void 0,
|
|
222
|
+
"data-transitioning": (0, _zag_js_dom_query.dataAttr)(viewportState.transitioning),
|
|
223
|
+
...(0, _zag_js_dismissable.getDismissableLayerAttrs)(layer),
|
|
224
|
+
style: {
|
|
225
|
+
...(0, _zag_js_dismissable.getDismissableLayerStyle)(layer, { pointerEvents: true }),
|
|
226
|
+
...getViewportStyle(viewportState.side)
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
getTitleProps(props = {}) {
|
|
231
|
+
return normalize.element({
|
|
232
|
+
...require_popover_anatomy.parts.title.attrs(scope.id),
|
|
233
|
+
id: require_popover_dom.getTitleId(scope, props.value),
|
|
234
|
+
dir: prop("dir")
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
getDescriptionProps(props = {}) {
|
|
238
|
+
return normalize.element({
|
|
239
|
+
...require_popover_anatomy.parts.description.attrs(scope.id),
|
|
240
|
+
id: require_popover_dom.getDescriptionId(scope, props.value),
|
|
241
|
+
dir: prop("dir")
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
getCloseTriggerProps() {
|
|
245
|
+
return normalize.button({
|
|
246
|
+
...require_popover_anatomy.parts.closeTrigger.attrs(scope.id),
|
|
247
|
+
dir: prop("dir"),
|
|
248
|
+
type: "button",
|
|
249
|
+
"aria-label": translations.closeTriggerLabel,
|
|
250
|
+
onClick(event) {
|
|
251
|
+
if (event.defaultPrevented) return;
|
|
252
|
+
event.stopPropagation();
|
|
253
|
+
send({
|
|
254
|
+
type: "CLOSE",
|
|
255
|
+
src: "close-trigger"
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
};
|
|
211
261
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
262
|
+
function getViewportStyle(side) {
|
|
263
|
+
return {
|
|
264
|
+
position: "absolute",
|
|
265
|
+
width: "var(--viewport-width)",
|
|
266
|
+
height: "var(--viewport-height)",
|
|
267
|
+
top: side === "top" ? void 0 : "0px",
|
|
268
|
+
bottom: side === "top" ? "0px" : void 0,
|
|
269
|
+
left: side === "left" ? void 0 : "0px",
|
|
270
|
+
right: side === "left" ? "0px" : void 0
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
exports.connect = connect;
|