ajo-ui 0.1.0
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/LICENSE +15 -0
- package/README.md +126 -0
- package/dist/accordion.js +130 -0
- package/dist/avatar.js +54 -0
- package/dist/calendar.js +2 -0
- package/dist/carousel.js +239 -0
- package/dist/chart.js +790 -0
- package/dist/checkbox-group.js +70 -0
- package/dist/checkbox.js +77 -0
- package/dist/chunks/bar-CVafh6C1.js +99 -0
- package/dist/chunks/calendar-q8jZ8Cxr.js +1923 -0
- package/dist/chunks/collection-DtRB63U4.js +111 -0
- package/dist/chunks/data-table-DpkWv4y4.js +1039 -0
- package/dist/chunks/menu-B45IyHHC.js +704 -0
- package/dist/chunks/native-BJdhd9XJ.js +20 -0
- package/dist/chunks/popup-C8Bb3l_g.js +459 -0
- package/dist/chunks/popup-surface-BDCgtVU0.js +18 -0
- package/dist/chunks/position-D6_i_SRn.js +434 -0
- package/dist/chunks/virtual-list-B7hjGkjk.js +413 -0
- package/dist/collapsible.js +106 -0
- package/dist/command.js +263 -0
- package/dist/context-menu.js +112 -0
- package/dist/data-table.js +5 -0
- package/dist/dialog.js +207 -0
- package/dist/direction.js +22 -0
- package/dist/drawer.js +139 -0
- package/dist/field.js +26 -0
- package/dist/index.js +38 -0
- package/dist/input-date.js +994 -0
- package/dist/input-group.js +52 -0
- package/dist/input-otp.js +179 -0
- package/dist/menu.js +2 -0
- package/dist/menubar.js +236 -0
- package/dist/message-scroller.js +446 -0
- package/dist/navigation-menu.js +330 -0
- package/dist/popover.js +307 -0
- package/dist/progress.js +39 -0
- package/dist/radio-group.js +107 -0
- package/dist/resizable.js +172 -0
- package/dist/select.js +961 -0
- package/dist/sidebar.js +343 -0
- package/dist/slider.js +259 -0
- package/dist/switch.js +53 -0
- package/dist/tabs.js +182 -0
- package/dist/toast.js +492 -0
- package/dist/toggle-group.js +111 -0
- package/dist/toggle.js +52 -0
- package/dist/toolbar.js +127 -0
- package/dist/tooltip.js +196 -0
- package/dist/utils.js +104 -0
- package/dist/virtual-list.js +2 -0
- package/package.json +250 -0
- package/src/accordion.tsx +261 -0
- package/src/availability.ts +261 -0
- package/src/avatar.tsx +99 -0
- package/src/bar.ts +156 -0
- package/src/calendar.tsx +1441 -0
- package/src/carousel.tsx +424 -0
- package/src/chart.tsx +1194 -0
- package/src/checkbox-group.tsx +132 -0
- package/src/checkbox.tsx +130 -0
- package/src/collapsible.tsx +188 -0
- package/src/collection.ts +154 -0
- package/src/command.tsx +511 -0
- package/src/context-menu.tsx +233 -0
- package/src/data-table-contract.ts +143 -0
- package/src/data-table-model.ts +760 -0
- package/src/data-table.tsx +475 -0
- package/src/dialog.tsx +393 -0
- package/src/direction.tsx +45 -0
- package/src/drawer.tsx +251 -0
- package/src/field.tsx +61 -0
- package/src/index.ts +37 -0
- package/src/input-date.tsx +1539 -0
- package/src/input-group.tsx +142 -0
- package/src/input-otp.tsx +324 -0
- package/src/menu-cluster.ts +124 -0
- package/src/menu.tsx +1095 -0
- package/src/menubar.tsx +459 -0
- package/src/message-scroller.tsx +732 -0
- package/src/native.ts +26 -0
- package/src/navigation-menu.tsx +578 -0
- package/src/popover.tsx +519 -0
- package/src/popup-surface.tsx +31 -0
- package/src/popup.ts +569 -0
- package/src/position.ts +523 -0
- package/src/progress.tsx +70 -0
- package/src/radio-group.tsx +186 -0
- package/src/resizable.tsx +310 -0
- package/src/segments.ts +922 -0
- package/src/select.tsx +1501 -0
- package/src/sidebar.tsx +683 -0
- package/src/slider.tsx +424 -0
- package/src/switch.tsx +104 -0
- package/src/tabs.tsx +314 -0
- package/src/toast.tsx +923 -0
- package/src/toggle-group.tsx +249 -0
- package/src/toggle.tsx +91 -0
- package/src/toolbar.tsx +212 -0
- package/src/tooltip.tsx +359 -0
- package/src/utils.ts +204 -0
- package/src/virtual-list.tsx +205 -0
- package/src/virtual.ts +385 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region packages/ajo-ui/src/native.ts
|
|
2
|
+
/** Checks whether a native popover is currently open. */
|
|
3
|
+
var popoverOpen = (element) => typeof element.matches === "function" && element.matches(":popover-open");
|
|
4
|
+
/** Opens a native popover and reports whether it is open. */
|
|
5
|
+
var openPopover = (element, source) => {
|
|
6
|
+
if (popoverOpen(element)) return true;
|
|
7
|
+
if (typeof element.showPopover !== "function") return false;
|
|
8
|
+
if (source) element.showPopover({ source });
|
|
9
|
+
else element.showPopover();
|
|
10
|
+
return popoverOpen(element);
|
|
11
|
+
};
|
|
12
|
+
/** Closes a native popover and reports whether it is closed. */
|
|
13
|
+
var closePopover = (element) => {
|
|
14
|
+
if (!popoverOpen(element)) return true;
|
|
15
|
+
if (typeof element.hidePopover !== "function") return false;
|
|
16
|
+
element.hidePopover();
|
|
17
|
+
return !popoverOpen(element);
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { openPopover as n, popoverOpen as r, closePopover as t };
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { popupStyle } from "../utils.js";
|
|
2
|
+
import { n as position } from "./position-D6_i_SRn.js";
|
|
3
|
+
import { n as openPopover, r as popoverOpen, t as closePopover } from "./native-BJdhd9XJ.js";
|
|
4
|
+
import { callRef, controlled, dismiss, dom, hover, id, resize } from "ajo-cloves";
|
|
5
|
+
//#region packages/ajo-ui/src/popup.ts
|
|
6
|
+
/** Builds native/manual popup attrs and a composed content ref. */
|
|
7
|
+
var contentAttrs = (options) => {
|
|
8
|
+
const { id, open, ref, setContent, style, tabindex } = options;
|
|
9
|
+
const attrs = {
|
|
10
|
+
popover: "manual",
|
|
11
|
+
style: typeof style === "string" ? style : popupStyle()
|
|
12
|
+
};
|
|
13
|
+
if ("id" in options) attrs.id = id;
|
|
14
|
+
if ("open" in options) attrs["data-state"] = open ? "open" : "closed";
|
|
15
|
+
if ("tabindex" in options) attrs.tabindex = tabindex;
|
|
16
|
+
if ("ref" in options || "setContent" in options) attrs.ref = (element) => {
|
|
17
|
+
setContent?.(element);
|
|
18
|
+
callRef(ref, element);
|
|
19
|
+
};
|
|
20
|
+
return attrs;
|
|
21
|
+
};
|
|
22
|
+
var stacks = /* @__PURE__ */ new WeakMap();
|
|
23
|
+
var handled = /* @__PURE__ */ new WeakSet();
|
|
24
|
+
var declaration = (name, value, priority = "") => value ? `${name}:${value}${priority ? "!important" : ""}` : "";
|
|
25
|
+
var contentOwnedStyle = (element, arrow) => [
|
|
26
|
+
declaration("position", element.style.position),
|
|
27
|
+
declaration("left", element.style.left),
|
|
28
|
+
declaration("top", element.style.top),
|
|
29
|
+
declaration("transform-origin", element.style.transformOrigin),
|
|
30
|
+
declaration("box-sizing", element.style.boxSizing),
|
|
31
|
+
declaration("max-width", element.style.maxWidth),
|
|
32
|
+
declaration("max-height", element.style.maxHeight),
|
|
33
|
+
declaration("visibility", element.style.visibility, element.style.getPropertyPriority("visibility")),
|
|
34
|
+
declaration("pointer-events", element.style.pointerEvents, element.style.getPropertyPriority("pointer-events")),
|
|
35
|
+
declaration("--reference-width", element.style.getPropertyValue("--reference-width")),
|
|
36
|
+
declaration("--reference-height", element.style.getPropertyValue("--reference-height")),
|
|
37
|
+
declaration("--available-width", element.style.getPropertyValue("--available-width")),
|
|
38
|
+
declaration("--available-height", element.style.getPropertyValue("--available-height")),
|
|
39
|
+
declaration("--popup-arrow-center", element.style.getPropertyValue("--popup-arrow-center")),
|
|
40
|
+
arrow ? "overflow:visible" : ""
|
|
41
|
+
].filter(Boolean).join(";");
|
|
42
|
+
var arrowOwnedStyle = (element) => element ? [
|
|
43
|
+
declaration("left", element.style.left),
|
|
44
|
+
declaration("right", element.style.right),
|
|
45
|
+
declaration("top", element.style.top),
|
|
46
|
+
declaration("bottom", element.style.bottom)
|
|
47
|
+
].filter(Boolean).join(";") : "";
|
|
48
|
+
var stack = (element) => {
|
|
49
|
+
const document = element.ownerDocument;
|
|
50
|
+
let current = stacks.get(document);
|
|
51
|
+
if (!current) stacks.set(document, current = []);
|
|
52
|
+
return current;
|
|
53
|
+
};
|
|
54
|
+
var remove = (view, element) => {
|
|
55
|
+
if (!element) return;
|
|
56
|
+
const current = stack(element);
|
|
57
|
+
const index = current.indexOf(view);
|
|
58
|
+
if (index >= 0) current.splice(index, 1);
|
|
59
|
+
};
|
|
60
|
+
var push = (view, element) => {
|
|
61
|
+
const current = stack(element);
|
|
62
|
+
const index = current.indexOf(view);
|
|
63
|
+
if (index >= 0) current.splice(index, 1);
|
|
64
|
+
current.push(view);
|
|
65
|
+
};
|
|
66
|
+
var top = (view, element) => {
|
|
67
|
+
if (!element) return false;
|
|
68
|
+
const current = stack(element);
|
|
69
|
+
return current[current.length - 1] === view;
|
|
70
|
+
};
|
|
71
|
+
/** Private popup Module: Ajo interaction/native lifecycle over the position Adapter. */
|
|
72
|
+
var popup = (host, options) => {
|
|
73
|
+
const rootId = id(options.prefix);
|
|
74
|
+
const contentId = `${rootId}-content`;
|
|
75
|
+
const state = controlled(host, {
|
|
76
|
+
fallback: options.initialOpen,
|
|
77
|
+
onChange: options.onOpenChange
|
|
78
|
+
});
|
|
79
|
+
let arrow = null;
|
|
80
|
+
let content = null;
|
|
81
|
+
let contentInputStyle;
|
|
82
|
+
let opened = state.value;
|
|
83
|
+
let overflowElement = null;
|
|
84
|
+
let preferred = {};
|
|
85
|
+
let referenceElement = null;
|
|
86
|
+
let referenceIsHidden = false;
|
|
87
|
+
let shown = false;
|
|
88
|
+
let trigger = null;
|
|
89
|
+
const generatedTriggerId = `${rootId}-trigger`;
|
|
90
|
+
let triggerId = generatedTriggerId;
|
|
91
|
+
let version = 0;
|
|
92
|
+
let view;
|
|
93
|
+
let opening = false;
|
|
94
|
+
let positionTask;
|
|
95
|
+
let reopen = false;
|
|
96
|
+
let scheduled = false;
|
|
97
|
+
const inputStyle = dom(host) ? host.ownerDocument.createElement("span").style : null;
|
|
98
|
+
let inputPointerEvents = {
|
|
99
|
+
priority: "",
|
|
100
|
+
value: ""
|
|
101
|
+
};
|
|
102
|
+
let inputVisibility = {
|
|
103
|
+
priority: "",
|
|
104
|
+
value: ""
|
|
105
|
+
};
|
|
106
|
+
const rememberContentStyle = (style) => {
|
|
107
|
+
contentInputStyle = style;
|
|
108
|
+
if (!inputStyle) return;
|
|
109
|
+
inputStyle.cssText = typeof style === "string" ? style : "";
|
|
110
|
+
inputPointerEvents = {
|
|
111
|
+
priority: inputStyle.getPropertyPriority("pointer-events"),
|
|
112
|
+
value: inputStyle.getPropertyValue("pointer-events")
|
|
113
|
+
};
|
|
114
|
+
inputVisibility = {
|
|
115
|
+
priority: inputStyle.getPropertyPriority("visibility"),
|
|
116
|
+
value: inputStyle.getPropertyValue("visibility")
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const restore = (target, name, input) => {
|
|
120
|
+
if (input.value) target.style.setProperty(name, input.value, input.priority);
|
|
121
|
+
else target.style.removeProperty(name);
|
|
122
|
+
};
|
|
123
|
+
const conceal = (target, hidden) => {
|
|
124
|
+
if (hidden) {
|
|
125
|
+
target.style.setProperty("visibility", "hidden", "important");
|
|
126
|
+
target.style.setProperty("pointer-events", "none", "important");
|
|
127
|
+
} else {
|
|
128
|
+
restore(target, "visibility", inputVisibility);
|
|
129
|
+
restore(target, "pointer-events", inputPointerEvents);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const reference = () => options.reference?.(view) ?? referenceElement ?? trigger;
|
|
133
|
+
const connectedSource = (element) => element?.isConnected ? element : null;
|
|
134
|
+
const source = () => connectedSource(options.source?.(view)) ?? connectedSource(trigger);
|
|
135
|
+
const clearOverflow = () => {
|
|
136
|
+
if (!overflowElement) return;
|
|
137
|
+
const target = overflowElement;
|
|
138
|
+
overflowElement = null;
|
|
139
|
+
if (target === content) target.setAttribute("style", popupStyle(contentInputStyle, contentOwnedStyle(target, false)));
|
|
140
|
+
else target.style.overflow = "";
|
|
141
|
+
};
|
|
142
|
+
const syncOverflow = () => {
|
|
143
|
+
if (overflowElement && (overflowElement !== content || !arrow)) clearOverflow();
|
|
144
|
+
if (!content || !arrow) return;
|
|
145
|
+
overflowElement = content;
|
|
146
|
+
content.style.overflow = "visible";
|
|
147
|
+
};
|
|
148
|
+
const reveal = (target) => {
|
|
149
|
+
conceal(target, options.referenceHidden === "hide" && referenceIsHidden);
|
|
150
|
+
};
|
|
151
|
+
const geometry = position(host, {
|
|
152
|
+
profile: options.profile,
|
|
153
|
+
elements: () => ({
|
|
154
|
+
reference: reference(),
|
|
155
|
+
floating: content,
|
|
156
|
+
arrow
|
|
157
|
+
}),
|
|
158
|
+
placement: () => preferred.placement,
|
|
159
|
+
gap: () => preferred.gap,
|
|
160
|
+
boundary: () => options.boundary?.(view) ?? null,
|
|
161
|
+
referenceBoundary: () => options.referenceBoundary?.(view) ?? null,
|
|
162
|
+
referenceHidden(hidden) {
|
|
163
|
+
referenceIsHidden = hidden;
|
|
164
|
+
if (!content) return;
|
|
165
|
+
if (options.referenceHidden === "hide") {
|
|
166
|
+
if (hidden || shown) conceal(content, hidden);
|
|
167
|
+
} else if (hidden && options.referenceHidden === "close") view.close();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
const intent = options.hover ? hover(host, {
|
|
171
|
+
openDelay: options.hover.openDelay,
|
|
172
|
+
closeDelay: options.hover.closeDelay,
|
|
173
|
+
onChange: (next, event) => setOpen(next, event)
|
|
174
|
+
}) : void 0;
|
|
175
|
+
const closeTarget = (target) => {
|
|
176
|
+
let error;
|
|
177
|
+
try {
|
|
178
|
+
if (!closePopover(target)) error = /* @__PURE__ */ new Error("Failed to close the native popover");
|
|
179
|
+
} catch (cause) {
|
|
180
|
+
error = cause;
|
|
181
|
+
} finally {
|
|
182
|
+
conceal(target, false);
|
|
183
|
+
}
|
|
184
|
+
return error;
|
|
185
|
+
};
|
|
186
|
+
const discard = (target) => {
|
|
187
|
+
remove(view, target);
|
|
188
|
+
target.dataset.state = "closed";
|
|
189
|
+
const error = closeTarget(target);
|
|
190
|
+
if (error !== void 0 && !host.signal.aborted) host.throw(error);
|
|
191
|
+
};
|
|
192
|
+
const closeCurrent = (target = content, notify = true) => {
|
|
193
|
+
const wasShown = shown;
|
|
194
|
+
if (target) target.dataset.state = "closed";
|
|
195
|
+
version++;
|
|
196
|
+
geometry.stop();
|
|
197
|
+
remove(view, target);
|
|
198
|
+
shown = false;
|
|
199
|
+
positionTask = void 0;
|
|
200
|
+
referenceIsHidden = false;
|
|
201
|
+
if (!target) return;
|
|
202
|
+
const error = closeTarget(target);
|
|
203
|
+
if (wasShown && notify) options.onSync?.(false, view);
|
|
204
|
+
if (error !== void 0 && !host.signal.aborted) host.throw(error);
|
|
205
|
+
};
|
|
206
|
+
const openCurrent = async () => {
|
|
207
|
+
const target = content;
|
|
208
|
+
const currentReference = reference();
|
|
209
|
+
if (!target || !opened || host.signal.aborted) return false;
|
|
210
|
+
if (!currentReference) {
|
|
211
|
+
view.close();
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const wasShown = shown;
|
|
215
|
+
const wasNativeOpen = popoverOpen(target);
|
|
216
|
+
const token = ++version;
|
|
217
|
+
if (!wasShown) target.dataset.state = "closed";
|
|
218
|
+
conceal(target, true);
|
|
219
|
+
try {
|
|
220
|
+
if (!openPopover(target, source())) throw new Error("Failed to open the native popover");
|
|
221
|
+
if (!wasNativeOpen) push(view, target);
|
|
222
|
+
if (!await geometry.start() || token !== version || !opened || content !== target || !popoverOpen(target)) {
|
|
223
|
+
geometry.stop();
|
|
224
|
+
if (reopen && opened && !host.signal.aborted) if (content === target) conceal(target, true);
|
|
225
|
+
else discard(target);
|
|
226
|
+
else if (opened && content === target && !host.signal.aborted) view.close();
|
|
227
|
+
else if (content === target) closeCurrent(target);
|
|
228
|
+
else discard(target);
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
shown = true;
|
|
232
|
+
target.dataset.state = "open";
|
|
233
|
+
reveal(target);
|
|
234
|
+
options.onPosition?.(view);
|
|
235
|
+
if (!wasShown) options.onSync?.(true, view);
|
|
236
|
+
return true;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
geometry.stop();
|
|
239
|
+
if (opened && content === target && !host.signal.aborted) view.close();
|
|
240
|
+
else if (content === target) closeCurrent(target);
|
|
241
|
+
else discard(target);
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const run = async () => {
|
|
246
|
+
scheduled = false;
|
|
247
|
+
if (host.signal.aborted) {
|
|
248
|
+
reopen = false;
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (opening) return;
|
|
252
|
+
opening = true;
|
|
253
|
+
try {
|
|
254
|
+
do {
|
|
255
|
+
reopen = false;
|
|
256
|
+
if (opened) await openCurrent();
|
|
257
|
+
else closeCurrent();
|
|
258
|
+
} while (reopen);
|
|
259
|
+
} finally {
|
|
260
|
+
opening = false;
|
|
261
|
+
if (reopen) schedule();
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
function schedule() {
|
|
265
|
+
if (host.signal.aborted) return;
|
|
266
|
+
reopen = true;
|
|
267
|
+
if (scheduled || opening) return;
|
|
268
|
+
scheduled = true;
|
|
269
|
+
queueMicrotask(() => {
|
|
270
|
+
if (host.signal.aborted) {
|
|
271
|
+
scheduled = false;
|
|
272
|
+
reopen = false;
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
run().catch(report);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
const report = (error) => {
|
|
279
|
+
if (host.signal.aborted) return;
|
|
280
|
+
queueMicrotask(() => {
|
|
281
|
+
if (!host.signal.aborted) host.throw(error);
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
const update = () => {
|
|
285
|
+
if (!opened || host.signal.aborted) return;
|
|
286
|
+
if (!shown && !opening) {
|
|
287
|
+
schedule();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const target = content;
|
|
291
|
+
const pending = geometry.update();
|
|
292
|
+
if (opening || pending === positionTask) return;
|
|
293
|
+
positionTask = pending;
|
|
294
|
+
const clear = () => {
|
|
295
|
+
if (positionTask === pending) positionTask = void 0;
|
|
296
|
+
};
|
|
297
|
+
pending.then((committed) => {
|
|
298
|
+
clear();
|
|
299
|
+
if (committed && opened && shown && target === content) options.onPosition?.(view);
|
|
300
|
+
}, (error) => {
|
|
301
|
+
clear();
|
|
302
|
+
report(error);
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
const arrowSize = resize(host, {
|
|
306
|
+
target: () => opened ? arrow : null,
|
|
307
|
+
onResize: update
|
|
308
|
+
});
|
|
309
|
+
const restart = (reopenSource = false) => {
|
|
310
|
+
if (!opened || host.signal.aborted) return;
|
|
311
|
+
version++;
|
|
312
|
+
geometry.stop();
|
|
313
|
+
positionTask = void 0;
|
|
314
|
+
referenceIsHidden = false;
|
|
315
|
+
if (reopenSource && content && popoverOpen(content)) {
|
|
316
|
+
const error = closeTarget(content);
|
|
317
|
+
if (error !== void 0) report(error);
|
|
318
|
+
}
|
|
319
|
+
if (content) conceal(content, true);
|
|
320
|
+
schedule();
|
|
321
|
+
};
|
|
322
|
+
const setOpen = (next, event) => {
|
|
323
|
+
if (host.signal.aborted) return;
|
|
324
|
+
if (options.disabled?.() && next) return;
|
|
325
|
+
if (next === opened) return;
|
|
326
|
+
state.set(next, event);
|
|
327
|
+
opened = state.value;
|
|
328
|
+
intent?.sync(opened);
|
|
329
|
+
arrowSize.sync();
|
|
330
|
+
if (opened) schedule();
|
|
331
|
+
else closeCurrent();
|
|
332
|
+
};
|
|
333
|
+
view = {
|
|
334
|
+
get open() {
|
|
335
|
+
return opened;
|
|
336
|
+
},
|
|
337
|
+
get trigger() {
|
|
338
|
+
return trigger;
|
|
339
|
+
},
|
|
340
|
+
get content() {
|
|
341
|
+
return content;
|
|
342
|
+
},
|
|
343
|
+
get reference() {
|
|
344
|
+
return referenceElement;
|
|
345
|
+
},
|
|
346
|
+
get triggerId() {
|
|
347
|
+
return triggerId;
|
|
348
|
+
},
|
|
349
|
+
get contentId() {
|
|
350
|
+
return contentId;
|
|
351
|
+
},
|
|
352
|
+
adoptTriggerId(id) {
|
|
353
|
+
triggerId = typeof id === "string" && id ? id : generatedTriggerId;
|
|
354
|
+
return triggerId;
|
|
355
|
+
},
|
|
356
|
+
contentStyle(style) {
|
|
357
|
+
rememberContentStyle(style);
|
|
358
|
+
return popupStyle(style, content ? contentOwnedStyle(content, Boolean(arrow)) : "");
|
|
359
|
+
},
|
|
360
|
+
arrowAttrs() {
|
|
361
|
+
return {
|
|
362
|
+
ref: setArrow,
|
|
363
|
+
style: arrowOwnedStyle(arrow)
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
sync(open, next = {}) {
|
|
367
|
+
const changed = preferred.placement !== next.placement || preferred.gap !== next.gap;
|
|
368
|
+
preferred = next;
|
|
369
|
+
const previous = opened;
|
|
370
|
+
opened = state.sync(open ?? void 0);
|
|
371
|
+
intent?.sync(opened);
|
|
372
|
+
arrowSize.sync();
|
|
373
|
+
if (!opened) {
|
|
374
|
+
if (previous || shown) closeCurrent();
|
|
375
|
+
} else if (!shown && !opening) schedule();
|
|
376
|
+
else if (changed) update();
|
|
377
|
+
return opened;
|
|
378
|
+
},
|
|
379
|
+
setOpen,
|
|
380
|
+
init(open) {
|
|
381
|
+
if (state.controlled || open === opened) return;
|
|
382
|
+
state.init(open);
|
|
383
|
+
opened = open;
|
|
384
|
+
intent?.sync(opened);
|
|
385
|
+
arrowSize.sync();
|
|
386
|
+
if (opened) schedule();
|
|
387
|
+
else closeCurrent();
|
|
388
|
+
},
|
|
389
|
+
close: (event) => setOpen(false, event),
|
|
390
|
+
hold(zone, event) {
|
|
391
|
+
if (!options.disabled?.()) intent?.hold(zone, event);
|
|
392
|
+
},
|
|
393
|
+
release: (zone, event) => intent?.release(zone, event),
|
|
394
|
+
cancelHover: () => intent?.cancel(),
|
|
395
|
+
setTrigger(element) {
|
|
396
|
+
if (element === trigger) return;
|
|
397
|
+
const previousReference = reference();
|
|
398
|
+
const previousSource = source();
|
|
399
|
+
trigger = element;
|
|
400
|
+
if (element?.id && element.id !== triggerId) {
|
|
401
|
+
triggerId = element.id;
|
|
402
|
+
queueMicrotask(() => host.next());
|
|
403
|
+
}
|
|
404
|
+
const referenceChanged = reference() !== previousReference;
|
|
405
|
+
const sourceChanged = source() !== previousSource;
|
|
406
|
+
if (referenceChanged || sourceChanged) restart(sourceChanged);
|
|
407
|
+
},
|
|
408
|
+
setContent(element) {
|
|
409
|
+
if (element === content) return;
|
|
410
|
+
const previous = content;
|
|
411
|
+
if (previous) closeCurrent(previous, false);
|
|
412
|
+
content = element;
|
|
413
|
+
syncOverflow();
|
|
414
|
+
if (element) element.dataset.state = "closed";
|
|
415
|
+
if (opened) schedule();
|
|
416
|
+
},
|
|
417
|
+
setReference(element) {
|
|
418
|
+
if (element === referenceElement) return;
|
|
419
|
+
const previousReference = reference();
|
|
420
|
+
const previousSource = source();
|
|
421
|
+
referenceElement = element;
|
|
422
|
+
const referenceChanged = reference() !== previousReference;
|
|
423
|
+
const sourceChanged = source() !== previousSource;
|
|
424
|
+
if (referenceChanged || sourceChanged) restart(sourceChanged || options.reopenOnReferenceChange);
|
|
425
|
+
},
|
|
426
|
+
update
|
|
427
|
+
};
|
|
428
|
+
function setArrow(element) {
|
|
429
|
+
if (element === arrow) return;
|
|
430
|
+
arrow = element;
|
|
431
|
+
syncOverflow();
|
|
432
|
+
arrowSize.sync();
|
|
433
|
+
restart();
|
|
434
|
+
}
|
|
435
|
+
if (options.dismiss) dismiss(host, {
|
|
436
|
+
active: () => opened && Boolean(content && popoverOpen(content)) && top(view, content),
|
|
437
|
+
inside: () => options.dismiss?.inside?.(view) ?? [trigger, content],
|
|
438
|
+
prevent: options.dismiss.prevent,
|
|
439
|
+
escape: options.dismiss.escape ?? "document",
|
|
440
|
+
outside: options.dismiss.outside,
|
|
441
|
+
onDismiss(event) {
|
|
442
|
+
if (handled.has(event)) return;
|
|
443
|
+
handled.add(event);
|
|
444
|
+
if (options.dismiss?.onDismiss) options.dismiss.onDismiss(event, view);
|
|
445
|
+
else view.close(event);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
host.signal.addEventListener("abort", () => {
|
|
449
|
+
opened = false;
|
|
450
|
+
reopen = false;
|
|
451
|
+
scheduled = false;
|
|
452
|
+
intent?.sync(false);
|
|
453
|
+
closeCurrent(content, false);
|
|
454
|
+
clearOverflow();
|
|
455
|
+
}, { once: true });
|
|
456
|
+
return view;
|
|
457
|
+
};
|
|
458
|
+
//#endregion
|
|
459
|
+
export { popup as n, contentAttrs as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "ajo/jsx-runtime";
|
|
2
|
+
//#region packages/ajo-ui/src/popup-surface.tsx
|
|
3
|
+
var probeStyle = "position:absolute;width:14px;height:14px;pointer-events:none;background:transparent;border:0;box-shadow:none;color:transparent;opacity:0";
|
|
4
|
+
/** Internal visual surface and optional transparent Floating UI arrow probe. */
|
|
5
|
+
var PopupSurface = ({ arrow = false, popup }) => {
|
|
6
|
+
const probe = arrow ? popup?.arrowAttrs() : void 0;
|
|
7
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
8
|
+
"aria-hidden": "true",
|
|
9
|
+
"data-slot": "popup-surface"
|
|
10
|
+
}), arrow ? /* @__PURE__ */ jsx("span", {
|
|
11
|
+
"aria-hidden": "true",
|
|
12
|
+
"data-slot": "popup-arrow",
|
|
13
|
+
ref: probe?.ref,
|
|
14
|
+
style: [probeStyle, probe?.style].filter(Boolean).join(";")
|
|
15
|
+
}) : null] });
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PopupSurface as t };
|