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,111 @@
|
|
|
1
|
+
//#region packages/ajo-ui/src/collection.ts
|
|
2
|
+
var enabledOf = (item) => item.dataset.disabled !== "true" && !item.disabled;
|
|
3
|
+
/**
|
|
4
|
+
* One item protocol for list-like families (menus, select, combobox, command):
|
|
5
|
+
* items are marked `data-item="<kind>"` and carry `data-value`, `data-label`,
|
|
6
|
+
* and `data-disabled`; the kind keeps nested families from cross-matching.
|
|
7
|
+
* Discovery is by DOM query (house pattern), highlight is `data-highlighted`.
|
|
8
|
+
*/
|
|
9
|
+
var collection = (kind, defaults = {}) => {
|
|
10
|
+
const selector = `[data-item="${kind}"]`;
|
|
11
|
+
const sweepDefaults = {
|
|
12
|
+
empty: `[data-slot="${kind}-empty"]`,
|
|
13
|
+
group: `[data-slot="${kind}-group"]`,
|
|
14
|
+
separator: `[data-slot="${kind}-separator"]`
|
|
15
|
+
};
|
|
16
|
+
const all = (root) => root ? Array.from(root.querySelectorAll(selector)) : [];
|
|
17
|
+
const items = (root, opts = {}) => {
|
|
18
|
+
const enabled = opts.enabled ?? defaults.enabled ?? true;
|
|
19
|
+
const rendered = opts.rendered ?? defaults.rendered ?? true;
|
|
20
|
+
const shown = opts.shown ?? defaults.shown ?? true;
|
|
21
|
+
return all(root).filter((item) => (!shown || !item.hidden) && (!rendered || item.offsetParent !== null) && (!enabled || enabledOf(item)));
|
|
22
|
+
};
|
|
23
|
+
const clearHighlight = (root) => {
|
|
24
|
+
for (const item of all(root)) delete item.dataset.highlighted;
|
|
25
|
+
};
|
|
26
|
+
/** Marks one item highlighted and clears the rest; does not move focus. */
|
|
27
|
+
const highlight = (root, target) => {
|
|
28
|
+
if (!target) return;
|
|
29
|
+
target.dataset.highlighted = "true";
|
|
30
|
+
for (const item of all(root)) if (item !== target) delete item.dataset.highlighted;
|
|
31
|
+
};
|
|
32
|
+
/** Focus strategy: moves real focus and mirrors it in data-highlighted. */
|
|
33
|
+
const focusItem = (root, target) => {
|
|
34
|
+
if (!target || !(root instanceof Node) || !root.contains(target)) return;
|
|
35
|
+
target.focus();
|
|
36
|
+
highlight(root, target);
|
|
37
|
+
};
|
|
38
|
+
/** Focuses the first or last matching item. */
|
|
39
|
+
const edge = (root, which, opts) => {
|
|
40
|
+
const list = items(root, opts);
|
|
41
|
+
focusItem(root, which === "first" ? list[0] : list[list.length - 1]);
|
|
42
|
+
};
|
|
43
|
+
/** Resolves the item containing an event target. */
|
|
44
|
+
const item = (event) => event.target?.closest(selector);
|
|
45
|
+
/** Marker attrs for one item, meant for JSX spread. */
|
|
46
|
+
const attrs = (opts = {}) => ({
|
|
47
|
+
"data-item": kind,
|
|
48
|
+
"data-disabled": opts.disabled ? "true" : void 0,
|
|
49
|
+
"data-label": opts.label,
|
|
50
|
+
"data-value": opts.value
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Hides empty groups (respecting data-force-mount) and toggles empty
|
|
54
|
+
* states against the current visible set; returns the visible items.
|
|
55
|
+
* Separators survive only between visible items: leading, trailing,
|
|
56
|
+
* and stacked separators hide as filtering empties their groups.
|
|
57
|
+
*/
|
|
58
|
+
const sweep = (root, opts) => {
|
|
59
|
+
const empty = opts?.empty ?? sweepDefaults.empty;
|
|
60
|
+
const group = opts?.group ?? sweepDefaults.group;
|
|
61
|
+
const separator = opts?.separator ?? sweepDefaults.separator;
|
|
62
|
+
if (group) for (const element of root.querySelectorAll(group)) {
|
|
63
|
+
if (element.dataset.forceMount === "true") {
|
|
64
|
+
element.hidden = false;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
element.hidden = !element.querySelector(`${selector}:not([hidden])`);
|
|
68
|
+
}
|
|
69
|
+
const visible = items(root);
|
|
70
|
+
if (separator) {
|
|
71
|
+
const separators = new Set(root.querySelectorAll(separator));
|
|
72
|
+
const order = [...visible, ...separators].sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
73
|
+
const keep = /* @__PURE__ */ new Set();
|
|
74
|
+
let afterItem = false;
|
|
75
|
+
for (const element of order) {
|
|
76
|
+
if (!separators.has(element)) {
|
|
77
|
+
afterItem = true;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (afterItem) keep.add(element);
|
|
81
|
+
afterItem = false;
|
|
82
|
+
}
|
|
83
|
+
let beforeItem = false;
|
|
84
|
+
for (let index = order.length - 1; index >= 0; index--) {
|
|
85
|
+
const element = order[index];
|
|
86
|
+
if (!separators.has(element)) {
|
|
87
|
+
beforeItem = true;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!beforeItem) keep.delete(element);
|
|
91
|
+
}
|
|
92
|
+
for (const separator of separators) separator.hidden = !keep.has(separator);
|
|
93
|
+
}
|
|
94
|
+
if (empty) for (const element of root.querySelectorAll(empty)) element.hidden = visible.length > 0;
|
|
95
|
+
return visible;
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
all,
|
|
99
|
+
attrs,
|
|
100
|
+
clearHighlight,
|
|
101
|
+
edge,
|
|
102
|
+
focusItem,
|
|
103
|
+
highlight,
|
|
104
|
+
item,
|
|
105
|
+
items,
|
|
106
|
+
selector,
|
|
107
|
+
sweep
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
export { collection as t };
|