@ariakit/core 0.0.1 → 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/.eslintignore +6 -0
- package/CHANGELOG.md +18 -0
- package/checkbox/checkbox-store/package.json +7 -0
- package/cjs/__chunks/2YFRPUZP.cjs +30 -0
- package/cjs/__chunks/3BBA3Z5G.cjs +143 -0
- package/cjs/__chunks/3KP2MDG6.cjs +1491 -0
- package/cjs/__chunks/5D5Y5EI4.cjs +146 -0
- package/cjs/__chunks/7ZXWQTAY.cjs +71 -0
- package/cjs/__chunks/AZVDLKO3.cjs +286 -0
- package/cjs/__chunks/EFEGT32M.cjs +12 -0
- package/cjs/__chunks/EIDN2CWH.cjs +57 -0
- package/cjs/__chunks/GDZQUFNP.cjs +30 -0
- package/cjs/__chunks/NX5OHIMM.cjs +169 -0
- package/cjs/__chunks/OFNGELMA.cjs +182 -0
- package/cjs/checkbox/checkbox-store.cjs +27 -0
- package/cjs/checkbox/checkbox-store.d.ts +34 -0
- package/cjs/collection/collection-store.cjs +9 -0
- package/cjs/collection/collection-store.d.ts +65 -0
- package/cjs/combobox/combobox-store.cjs +163 -0
- package/cjs/combobox/combobox-store.d.ts +67 -0
- package/cjs/composite/composite-overflow-store.cjs +15 -0
- package/cjs/composite/composite-overflow-store.d.ts +10 -0
- package/cjs/composite/composite-store.cjs +11 -0
- package/cjs/composite/composite-store.d.ts +202 -0
- package/cjs/dialog/dialog-store.cjs +9 -0
- package/cjs/dialog/dialog-store.d.ts +10 -0
- package/cjs/disclosure/disclosure-store.cjs +8 -0
- package/cjs/disclosure/disclosure-store.d.ts +87 -0
- package/cjs/form/form-store.cjs +241 -0
- package/cjs/form/form-store.d.ts +236 -0
- package/cjs/form/types.cjs +1 -0
- package/cjs/form/types.d.ts +38 -0
- package/cjs/hovercard/hovercard-store.cjs +11 -0
- package/cjs/hovercard/hovercard-store.d.ts +45 -0
- package/cjs/index.cjs +5 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/menu/menu-bar-store.cjs +27 -0
- package/cjs/menu/menu-bar-store.d.ts +10 -0
- package/cjs/menu/menu-store.cjs +108 -0
- package/cjs/menu/menu-store.d.ts +70 -0
- package/cjs/popover/popover-store.cjs +10 -0
- package/cjs/popover/popover-store.d.ts +150 -0
- package/cjs/radio/radio-store.cjs +36 -0
- package/cjs/radio/radio-store.d.ts +31 -0
- package/cjs/select/select-store.cjs +164 -0
- package/cjs/select/select-store.d.ts +87 -0
- package/cjs/tab/tab-store.cjs +126 -0
- package/cjs/tab/tab-store.d.ts +78 -0
- package/cjs/toolbar/toolbar-store.cjs +27 -0
- package/cjs/toolbar/toolbar-store.d.ts +21 -0
- package/cjs/tooltip/tooltip-store.cjs +98 -0
- package/cjs/tooltip/tooltip-store.d.ts +28 -0
- package/cjs/tsconfig.build.tsbuildinfo +1 -0
- package/cjs/utils/array.cjs +12 -0
- package/cjs/utils/array.d.ts +29 -0
- package/cjs/utils/dom.cjs +38 -0
- package/cjs/utils/dom.d.ts +105 -0
- package/cjs/utils/events.cjs +132 -0
- package/cjs/utils/events.d.ts +73 -0
- package/cjs/utils/focus.cjs +222 -0
- package/cjs/utils/focus.d.ts +117 -0
- package/cjs/utils/misc.cjs +40 -0
- package/cjs/utils/misc.d.ts +111 -0
- package/cjs/utils/platform.cjs +15 -0
- package/cjs/utils/platform.d.ts +20 -0
- package/cjs/utils/store.cjs +9 -0
- package/cjs/utils/store.d.ts +99 -0
- package/cjs/utils/types.cjs +1 -0
- package/cjs/utils/types.d.ts +72 -0
- package/collection/collection-store/package.json +7 -0
- package/combobox/combobox-store/package.json +7 -0
- package/composite/composite-overflow-store/package.json +7 -0
- package/composite/composite-store/package.json +7 -0
- package/dialog/dialog-store/package.json +7 -0
- package/disclosure/disclosure-store/package.json +7 -0
- package/esm/__chunks/5XEKIOCW.js +30 -0
- package/esm/__chunks/6U25WEDX.js +286 -0
- package/esm/__chunks/6UPCMUXT.js +1491 -0
- package/esm/__chunks/ADRUFBEO.js +12 -0
- package/esm/__chunks/DXA3K2FY.js +30 -0
- package/esm/__chunks/HCKYJLMC.js +71 -0
- package/esm/__chunks/KLKI3AIB.js +146 -0
- package/esm/__chunks/L7KN5AYP.js +169 -0
- package/esm/__chunks/RX3ZUQ6U.js +57 -0
- package/esm/__chunks/UOJSZ35L.js +143 -0
- package/esm/__chunks/UVCATTRC.js +182 -0
- package/esm/checkbox/checkbox-store.d.ts +34 -0
- package/esm/checkbox/checkbox-store.js +27 -0
- package/esm/collection/collection-store.d.ts +65 -0
- package/esm/collection/collection-store.js +9 -0
- package/esm/combobox/combobox-store.d.ts +67 -0
- package/esm/combobox/combobox-store.js +163 -0
- package/esm/composite/composite-overflow-store.d.ts +10 -0
- package/esm/composite/composite-overflow-store.js +15 -0
- package/esm/composite/composite-store.d.ts +202 -0
- package/esm/composite/composite-store.js +11 -0
- package/esm/dialog/dialog-store.d.ts +10 -0
- package/esm/dialog/dialog-store.js +9 -0
- package/esm/disclosure/disclosure-store.d.ts +87 -0
- package/esm/disclosure/disclosure-store.js +8 -0
- package/esm/form/form-store.d.ts +236 -0
- package/esm/form/form-store.js +241 -0
- package/esm/form/types.d.ts +38 -0
- package/esm/form/types.js +0 -0
- package/esm/hovercard/hovercard-store.d.ts +45 -0
- package/esm/hovercard/hovercard-store.js +11 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +5 -0
- package/esm/menu/menu-bar-store.d.ts +10 -0
- package/esm/menu/menu-bar-store.js +27 -0
- package/esm/menu/menu-store.d.ts +70 -0
- package/esm/menu/menu-store.js +108 -0
- package/esm/popover/popover-store.d.ts +150 -0
- package/esm/popover/popover-store.js +10 -0
- package/esm/radio/radio-store.d.ts +31 -0
- package/esm/radio/radio-store.js +36 -0
- package/esm/select/select-store.d.ts +87 -0
- package/esm/select/select-store.js +164 -0
- package/esm/tab/tab-store.d.ts +78 -0
- package/esm/tab/tab-store.js +126 -0
- package/esm/toolbar/toolbar-store.d.ts +21 -0
- package/esm/toolbar/toolbar-store.js +27 -0
- package/esm/tooltip/tooltip-store.d.ts +28 -0
- package/esm/tooltip/tooltip-store.js +98 -0
- package/esm/tsconfig.build.tsbuildinfo +1 -0
- package/esm/utils/array.d.ts +29 -0
- package/esm/utils/array.js +12 -0
- package/esm/utils/dom.d.ts +105 -0
- package/esm/utils/dom.js +38 -0
- package/esm/utils/events.d.ts +73 -0
- package/esm/utils/events.js +132 -0
- package/esm/utils/focus.d.ts +117 -0
- package/esm/utils/focus.js +222 -0
- package/esm/utils/misc.d.ts +111 -0
- package/esm/utils/misc.js +40 -0
- package/esm/utils/platform.d.ts +20 -0
- package/esm/utils/platform.js +15 -0
- package/esm/utils/store.d.ts +99 -0
- package/esm/utils/store.js +9 -0
- package/esm/utils/types.d.ts +72 -0
- package/esm/utils/types.js +0 -0
- package/form/form-store/package.json +7 -0
- package/form/types/package.json +7 -0
- package/hovercard/hovercard-store/package.json +7 -0
- package/license +21 -0
- package/menu/menu-bar-store/package.json +7 -0
- package/menu/menu-store/package.json +7 -0
- package/package.json +137 -6
- package/popover/popover-store/package.json +7 -0
- package/radio/radio-store/package.json +7 -0
- package/select/select-store/package.json +7 -0
- package/tab/tab-store/package.json +7 -0
- package/toolbar/toolbar-store/package.json +7 -0
- package/tooltip/tooltip-store/package.json +7 -0
- package/tsconfig.build.json +4 -0
- package/utils/array/package.json +7 -0
- package/utils/dom/package.json +7 -0
- package/utils/events/package.json +7 -0
- package/utils/focus/package.json +7 -0
- package/utils/misc/package.json +7 -0
- package/utils/platform/package.json +7 -0
- package/utils/store/package.json +7 -0
- package/utils/types/package.json +7 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/misc.ts
|
|
2
|
+
function noop(..._) {
|
|
3
|
+
}
|
|
4
|
+
function shallowEqual(a, b) {
|
|
5
|
+
if (a === b)
|
|
6
|
+
return true;
|
|
7
|
+
if (!a)
|
|
8
|
+
return false;
|
|
9
|
+
if (!b)
|
|
10
|
+
return false;
|
|
11
|
+
if (typeof a !== "object")
|
|
12
|
+
return false;
|
|
13
|
+
if (typeof b !== "object")
|
|
14
|
+
return false;
|
|
15
|
+
const aKeys = Object.keys(a);
|
|
16
|
+
const bKeys = Object.keys(b);
|
|
17
|
+
const { length } = aKeys;
|
|
18
|
+
if (bKeys.length !== length)
|
|
19
|
+
return false;
|
|
20
|
+
for (const key of aKeys) {
|
|
21
|
+
if (a[key] !== b[key]) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
function applyState(argument, currentValue) {
|
|
28
|
+
if (isUpdater(argument)) {
|
|
29
|
+
const value = isLazyValue(currentValue) ? currentValue() : currentValue;
|
|
30
|
+
return argument(value);
|
|
31
|
+
}
|
|
32
|
+
return argument;
|
|
33
|
+
}
|
|
34
|
+
function isUpdater(argument) {
|
|
35
|
+
return typeof argument === "function";
|
|
36
|
+
}
|
|
37
|
+
function isLazyValue(value) {
|
|
38
|
+
return typeof value === "function";
|
|
39
|
+
}
|
|
40
|
+
function isObject(arg) {
|
|
41
|
+
return typeof arg === "object" && arg != null;
|
|
42
|
+
}
|
|
43
|
+
function isEmpty(arg) {
|
|
44
|
+
if (Array.isArray(arg))
|
|
45
|
+
return !arg.length;
|
|
46
|
+
if (isObject(arg))
|
|
47
|
+
return !Object.keys(arg).length;
|
|
48
|
+
if (arg == null)
|
|
49
|
+
return true;
|
|
50
|
+
if (arg === "")
|
|
51
|
+
return true;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function isInteger(arg) {
|
|
55
|
+
if (typeof arg === "number") {
|
|
56
|
+
return Math.floor(arg) === arg;
|
|
57
|
+
}
|
|
58
|
+
return String(Math.floor(Number(arg))) === arg;
|
|
59
|
+
}
|
|
60
|
+
function hasOwnProperty(object, prop) {
|
|
61
|
+
return Object.prototype.hasOwnProperty.call(object, prop);
|
|
62
|
+
}
|
|
63
|
+
function chain(...fns) {
|
|
64
|
+
return (...args) => {
|
|
65
|
+
for (const fn of fns) {
|
|
66
|
+
if (typeof fn === "function") {
|
|
67
|
+
fn(...args);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function cx(...args) {
|
|
73
|
+
return args.filter(Boolean).join(" ") || void 0;
|
|
74
|
+
}
|
|
75
|
+
function normalizeString(str) {
|
|
76
|
+
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
77
|
+
}
|
|
78
|
+
function omit(object, keys) {
|
|
79
|
+
const result = { ...object };
|
|
80
|
+
for (const key of keys) {
|
|
81
|
+
if (hasOwnProperty(result, key)) {
|
|
82
|
+
delete result[key];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
function pick(object, paths) {
|
|
88
|
+
const result = {};
|
|
89
|
+
for (const key of paths) {
|
|
90
|
+
if (hasOwnProperty(object, key)) {
|
|
91
|
+
result[key] = object[key];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function identity(value) {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
function beforePaint(cb = noop) {
|
|
100
|
+
const raf = requestAnimationFrame(cb);
|
|
101
|
+
return () => cancelAnimationFrame(raf);
|
|
102
|
+
}
|
|
103
|
+
function afterPaint(cb = noop) {
|
|
104
|
+
let raf = requestAnimationFrame(() => {
|
|
105
|
+
raf = requestAnimationFrame(cb);
|
|
106
|
+
});
|
|
107
|
+
return () => cancelAnimationFrame(raf);
|
|
108
|
+
}
|
|
109
|
+
function invariant(condition, message) {
|
|
110
|
+
if (condition)
|
|
111
|
+
return;
|
|
112
|
+
if (typeof message !== "string")
|
|
113
|
+
throw new Error("Invariant failed");
|
|
114
|
+
throw new Error(message);
|
|
115
|
+
}
|
|
116
|
+
function getKeys(obj) {
|
|
117
|
+
return Object.keys(obj);
|
|
118
|
+
}
|
|
119
|
+
function defaultValue(...values) {
|
|
120
|
+
for (const value of values) {
|
|
121
|
+
if (value !== void 0)
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
return void 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
exports.noop = noop; exports.shallowEqual = shallowEqual; exports.applyState = applyState; exports.isObject = isObject; exports.isEmpty = isEmpty; exports.isInteger = isInteger; exports.hasOwnProperty = hasOwnProperty; exports.chain = chain; exports.cx = cx; exports.normalizeString = normalizeString; exports.omit = omit; exports.pick = pick; exports.identity = identity; exports.beforePaint = beforePaint; exports.afterPaint = afterPaint; exports.invariant = invariant; exports.getKeys = getKeys; exports.defaultValue = defaultValue;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _3BBA3Z5Gcjs = require('./3BBA3Z5G.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _5D5Y5EI4cjs = require('./5D5Y5EI4.cjs');
|
|
7
|
+
|
|
8
|
+
// src/disclosure/disclosure-store.ts
|
|
9
|
+
function createDisclosureStore(props = {}) {
|
|
10
|
+
const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
|
|
11
|
+
const open = _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
12
|
+
props.open,
|
|
13
|
+
_optionalChain([syncState, 'optionalAccess', _4 => _4.open]),
|
|
14
|
+
props.defaultOpen,
|
|
15
|
+
false
|
|
16
|
+
);
|
|
17
|
+
const animated = _5D5Y5EI4cjs.defaultValue.call(void 0, props.animated, _optionalChain([syncState, 'optionalAccess', _5 => _5.animated]), false);
|
|
18
|
+
const initialState = {
|
|
19
|
+
open,
|
|
20
|
+
animated,
|
|
21
|
+
animating: !!animated && open,
|
|
22
|
+
mounted: open,
|
|
23
|
+
contentElement: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _6 => _6.contentElement]), null),
|
|
24
|
+
disclosureElement: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _7 => _7.disclosureElement]), null)
|
|
25
|
+
};
|
|
26
|
+
const disclosure = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, props.store);
|
|
27
|
+
disclosure.setup(
|
|
28
|
+
() => disclosure.sync(
|
|
29
|
+
(state) => {
|
|
30
|
+
if (state.animated)
|
|
31
|
+
return;
|
|
32
|
+
disclosure.setState("animating", false);
|
|
33
|
+
},
|
|
34
|
+
["animated", "animating"]
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
disclosure.setup(
|
|
38
|
+
() => disclosure.sync(
|
|
39
|
+
(state, prev) => {
|
|
40
|
+
if (!state.animated)
|
|
41
|
+
return;
|
|
42
|
+
const mounting = state === prev;
|
|
43
|
+
const animating = mounting ? state.open : state.open !== prev.open;
|
|
44
|
+
disclosure.setState("animating", animating);
|
|
45
|
+
},
|
|
46
|
+
["open", "animated"]
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
disclosure.setup(
|
|
50
|
+
() => disclosure.sync(
|
|
51
|
+
(state) => {
|
|
52
|
+
disclosure.setState("mounted", state.open || state.animating);
|
|
53
|
+
},
|
|
54
|
+
["open", "animating"]
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
return {
|
|
58
|
+
...disclosure,
|
|
59
|
+
setOpen: (value) => disclosure.setState("open", value),
|
|
60
|
+
show: () => disclosure.setState("open", true),
|
|
61
|
+
hide: () => disclosure.setState("open", false),
|
|
62
|
+
toggle: () => disclosure.setState("open", (open2) => !open2),
|
|
63
|
+
stopAnimation: () => disclosure.setState("animating", false),
|
|
64
|
+
setContentElement: (value) => disclosure.setState("contentElement", value),
|
|
65
|
+
setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
exports.createDisclosureStore = createDisclosureStore;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _NX5OHIMMcjs = require('./NX5OHIMM.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _3BBA3Z5Gcjs = require('./3BBA3Z5G.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _5D5Y5EI4cjs = require('./5D5Y5EI4.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _GDZQUFNPcjs = require('./GDZQUFNP.cjs');
|
|
14
|
+
|
|
15
|
+
// src/composite/composite-store.ts
|
|
16
|
+
var NULL_ITEM = { id: null };
|
|
17
|
+
function findFirstEnabledItem(items, excludeId) {
|
|
18
|
+
return items.find((item) => {
|
|
19
|
+
if (excludeId) {
|
|
20
|
+
return !item.disabled && item.id !== excludeId;
|
|
21
|
+
}
|
|
22
|
+
return !item.disabled;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function getEnabledItems(items, excludeId) {
|
|
26
|
+
return items.filter((item) => {
|
|
27
|
+
if (excludeId) {
|
|
28
|
+
return !item.disabled && item.id !== excludeId;
|
|
29
|
+
}
|
|
30
|
+
return !item.disabled;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getOppositeOrientation(orientation) {
|
|
34
|
+
if (orientation === "vertical")
|
|
35
|
+
return "horizontal";
|
|
36
|
+
if (orientation === "horizontal")
|
|
37
|
+
return "vertical";
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
function getItemsInRow(items, rowId) {
|
|
41
|
+
return items.filter((item) => item.rowId === rowId);
|
|
42
|
+
}
|
|
43
|
+
function flipItems(items, activeId, shouldInsertNullItem = false) {
|
|
44
|
+
const index = items.findIndex((item) => item.id === activeId);
|
|
45
|
+
return [
|
|
46
|
+
...items.slice(index + 1),
|
|
47
|
+
...shouldInsertNullItem ? [NULL_ITEM] : [],
|
|
48
|
+
...items.slice(0, index)
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
function groupItemsByRows(items) {
|
|
52
|
+
const rows = [];
|
|
53
|
+
for (const item of items) {
|
|
54
|
+
const row = rows.find((currentRow) => _optionalChain([currentRow, 'access', _ => _[0], 'optionalAccess', _2 => _2.rowId]) === item.rowId);
|
|
55
|
+
if (row) {
|
|
56
|
+
row.push(item);
|
|
57
|
+
} else {
|
|
58
|
+
rows.push([item]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return rows;
|
|
62
|
+
}
|
|
63
|
+
function getMaxRowLength(array) {
|
|
64
|
+
let maxLength = 0;
|
|
65
|
+
for (const { length } of array) {
|
|
66
|
+
if (length > maxLength) {
|
|
67
|
+
maxLength = length;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return maxLength;
|
|
71
|
+
}
|
|
72
|
+
function createEmptyItem(rowId) {
|
|
73
|
+
return {
|
|
74
|
+
id: "__EMPTY_ITEM__",
|
|
75
|
+
disabled: true,
|
|
76
|
+
rowId
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function normalizeRows(rows, activeId, focusShift) {
|
|
80
|
+
const maxLength = getMaxRowLength(rows);
|
|
81
|
+
for (const row of rows) {
|
|
82
|
+
for (let i = 0; i < maxLength; i += 1) {
|
|
83
|
+
const item = row[i];
|
|
84
|
+
if (!item || focusShift && item.disabled) {
|
|
85
|
+
const isFirst = i === 0;
|
|
86
|
+
const previousItem = isFirst && focusShift ? findFirstEnabledItem(row) : row[i - 1];
|
|
87
|
+
row[i] = previousItem && activeId !== previousItem.id && focusShift ? previousItem : createEmptyItem(_optionalChain([previousItem, 'optionalAccess', _3 => _3.rowId]));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return rows;
|
|
92
|
+
}
|
|
93
|
+
function verticalizeItems(items) {
|
|
94
|
+
const rows = groupItemsByRows(items);
|
|
95
|
+
const maxLength = getMaxRowLength(rows);
|
|
96
|
+
const verticalized = [];
|
|
97
|
+
for (let i = 0; i < maxLength; i += 1) {
|
|
98
|
+
for (const row of rows) {
|
|
99
|
+
const item = row[i];
|
|
100
|
+
if (item) {
|
|
101
|
+
verticalized.push({
|
|
102
|
+
...item,
|
|
103
|
+
// If there's no rowId, it means that it's not a grid composite, but
|
|
104
|
+
// a single row instead. So, instead of verticalizing it, that is,
|
|
105
|
+
// assigning a different rowId based on the column index, we keep it
|
|
106
|
+
// undefined so they will be part of the same row. This is useful
|
|
107
|
+
// when using up/down on one-dimensional composites.
|
|
108
|
+
rowId: item.rowId ? `${i}` : void 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return verticalized;
|
|
114
|
+
}
|
|
115
|
+
function createCompositeStore(props = {}) {
|
|
116
|
+
const syncState = _optionalChain([props, 'access', _4 => _4.store, 'optionalAccess', _5 => _5.getState, 'call', _6 => _6()]);
|
|
117
|
+
const collection = _NX5OHIMMcjs.createCollectionStore.call(void 0, props);
|
|
118
|
+
const activeId = _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
119
|
+
props.activeId,
|
|
120
|
+
_optionalChain([syncState, 'optionalAccess', _7 => _7.activeId]),
|
|
121
|
+
props.defaultActiveId
|
|
122
|
+
);
|
|
123
|
+
const initialState = {
|
|
124
|
+
...collection.getState(),
|
|
125
|
+
activeId,
|
|
126
|
+
baseElement: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _8 => _8.baseElement]), null),
|
|
127
|
+
includesBaseElement: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
128
|
+
props.includesBaseElement,
|
|
129
|
+
_optionalChain([syncState, 'optionalAccess', _9 => _9.includesBaseElement]),
|
|
130
|
+
activeId === null
|
|
131
|
+
),
|
|
132
|
+
moves: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _10 => _10.moves]), 0),
|
|
133
|
+
orientation: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
134
|
+
props.orientation,
|
|
135
|
+
_optionalChain([syncState, 'optionalAccess', _11 => _11.orientation]),
|
|
136
|
+
"both"
|
|
137
|
+
),
|
|
138
|
+
rtl: _5D5Y5EI4cjs.defaultValue.call(void 0, props.rtl, _optionalChain([syncState, 'optionalAccess', _12 => _12.rtl]), false),
|
|
139
|
+
virtualFocus: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
140
|
+
props.virtualFocus,
|
|
141
|
+
_optionalChain([syncState, 'optionalAccess', _13 => _13.virtualFocus]),
|
|
142
|
+
false
|
|
143
|
+
),
|
|
144
|
+
focusLoop: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusLoop, _optionalChain([syncState, 'optionalAccess', _14 => _14.focusLoop]), false),
|
|
145
|
+
focusWrap: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusWrap, _optionalChain([syncState, 'optionalAccess', _15 => _15.focusWrap]), false),
|
|
146
|
+
focusShift: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusShift, _optionalChain([syncState, 'optionalAccess', _16 => _16.focusShift]), false)
|
|
147
|
+
};
|
|
148
|
+
const composite = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, collection, props.store);
|
|
149
|
+
composite.setup(
|
|
150
|
+
() => composite.sync(
|
|
151
|
+
(state) => {
|
|
152
|
+
composite.setState("activeId", (activeId2) => {
|
|
153
|
+
if (activeId2 !== void 0)
|
|
154
|
+
return activeId2;
|
|
155
|
+
return _optionalChain([findFirstEnabledItem, 'call', _17 => _17(state.renderedItems), 'optionalAccess', _18 => _18.id]);
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
["renderedItems", "activeId"]
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
const getNextId = (items, orientation, hasNullItem, skip) => {
|
|
162
|
+
const { activeId: activeId2, rtl, focusLoop, focusWrap, includesBaseElement } = composite.getState();
|
|
163
|
+
const isHorizontal = orientation !== "vertical";
|
|
164
|
+
const isRTL = rtl && isHorizontal;
|
|
165
|
+
const allItems = isRTL ? _GDZQUFNPcjs.reverseArray.call(void 0, items) : items;
|
|
166
|
+
if (activeId2 == null) {
|
|
167
|
+
return _optionalChain([findFirstEnabledItem, 'call', _19 => _19(allItems), 'optionalAccess', _20 => _20.id]);
|
|
168
|
+
}
|
|
169
|
+
const activeItem = allItems.find((item) => item.id === activeId2);
|
|
170
|
+
if (!activeItem) {
|
|
171
|
+
return _optionalChain([findFirstEnabledItem, 'call', _21 => _21(allItems), 'optionalAccess', _22 => _22.id]);
|
|
172
|
+
}
|
|
173
|
+
const isGrid = !!activeItem.rowId;
|
|
174
|
+
const activeIndex = allItems.indexOf(activeItem);
|
|
175
|
+
const nextItems = allItems.slice(activeIndex + 1);
|
|
176
|
+
const nextItemsInRow = getItemsInRow(nextItems, activeItem.rowId);
|
|
177
|
+
if (skip !== void 0) {
|
|
178
|
+
const nextEnabledItemsInRow = getEnabledItems(nextItemsInRow, activeId2);
|
|
179
|
+
const nextItem2 = nextEnabledItemsInRow.slice(skip)[0] || // If we can't find an item, just return the last one.
|
|
180
|
+
nextEnabledItemsInRow[nextEnabledItemsInRow.length - 1];
|
|
181
|
+
return _optionalChain([nextItem2, 'optionalAccess', _23 => _23.id]);
|
|
182
|
+
}
|
|
183
|
+
const oppositeOrientation = getOppositeOrientation(
|
|
184
|
+
// If it's a grid and orientation is not set, it's a next/previous call,
|
|
185
|
+
// which is inherently horizontal. up/down will call next with orientation
|
|
186
|
+
// set to vertical by default (see below on up/down methods).
|
|
187
|
+
isGrid ? orientation || "horizontal" : orientation
|
|
188
|
+
);
|
|
189
|
+
const canLoop = focusLoop && focusLoop !== oppositeOrientation;
|
|
190
|
+
const canWrap = isGrid && focusWrap && focusWrap !== oppositeOrientation;
|
|
191
|
+
hasNullItem = hasNullItem || !isGrid && canLoop && includesBaseElement;
|
|
192
|
+
if (canLoop) {
|
|
193
|
+
const loopItems = canWrap && !hasNullItem ? allItems : getItemsInRow(allItems, activeItem.rowId);
|
|
194
|
+
const sortedItems = flipItems(loopItems, activeId2, hasNullItem);
|
|
195
|
+
const nextItem2 = findFirstEnabledItem(sortedItems, activeId2);
|
|
196
|
+
return _optionalChain([nextItem2, 'optionalAccess', _24 => _24.id]);
|
|
197
|
+
}
|
|
198
|
+
if (canWrap) {
|
|
199
|
+
const nextItem2 = findFirstEnabledItem(
|
|
200
|
+
// We can use nextItems, which contains all the next items, including
|
|
201
|
+
// items from other rows, to wrap between rows. However, if there is a
|
|
202
|
+
// null item (the composite container), we'll only use the next items in
|
|
203
|
+
// the row. So moving next from the last item will focus on the
|
|
204
|
+
// composite container. On grid composites, horizontal navigation never
|
|
205
|
+
// focuses on the composite container, only vertical.
|
|
206
|
+
hasNullItem ? nextItemsInRow : nextItems,
|
|
207
|
+
activeId2
|
|
208
|
+
);
|
|
209
|
+
const nextId = hasNullItem ? _optionalChain([nextItem2, 'optionalAccess', _25 => _25.id]) || null : _optionalChain([nextItem2, 'optionalAccess', _26 => _26.id]);
|
|
210
|
+
return nextId;
|
|
211
|
+
}
|
|
212
|
+
const nextItem = findFirstEnabledItem(nextItemsInRow, activeId2);
|
|
213
|
+
if (!nextItem && hasNullItem) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
return _optionalChain([nextItem, 'optionalAccess', _27 => _27.id]);
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
...collection,
|
|
220
|
+
...composite,
|
|
221
|
+
setBaseElement: (element) => composite.setState("baseElement", element),
|
|
222
|
+
setActiveId: (id) => composite.setState("activeId", id),
|
|
223
|
+
move: (id) => {
|
|
224
|
+
if (id === void 0)
|
|
225
|
+
return;
|
|
226
|
+
composite.setState("activeId", id);
|
|
227
|
+
composite.setState("moves", (moves) => moves + 1);
|
|
228
|
+
},
|
|
229
|
+
first: () => _optionalChain([findFirstEnabledItem, 'call', _28 => _28(composite.getState().renderedItems), 'optionalAccess', _29 => _29.id]),
|
|
230
|
+
last: () => _optionalChain([findFirstEnabledItem, 'call', _30 => _30(_GDZQUFNPcjs.reverseArray.call(void 0, composite.getState().renderedItems)), 'optionalAccess', _31 => _31.id]),
|
|
231
|
+
next: (skip) => {
|
|
232
|
+
const { renderedItems, orientation } = composite.getState();
|
|
233
|
+
return getNextId(renderedItems, orientation, false, skip);
|
|
234
|
+
},
|
|
235
|
+
previous: (skip) => {
|
|
236
|
+
const { renderedItems, orientation, includesBaseElement } = composite.getState();
|
|
237
|
+
const isGrid = !!_optionalChain([findFirstEnabledItem, 'call', _32 => _32(renderedItems), 'optionalAccess', _33 => _33.rowId]);
|
|
238
|
+
const hasNullItem = !isGrid && includesBaseElement;
|
|
239
|
+
return getNextId(
|
|
240
|
+
_GDZQUFNPcjs.reverseArray.call(void 0, renderedItems),
|
|
241
|
+
orientation,
|
|
242
|
+
hasNullItem,
|
|
243
|
+
skip
|
|
244
|
+
);
|
|
245
|
+
},
|
|
246
|
+
down: (skip) => {
|
|
247
|
+
const {
|
|
248
|
+
activeId: activeId2,
|
|
249
|
+
renderedItems,
|
|
250
|
+
focusShift,
|
|
251
|
+
focusLoop,
|
|
252
|
+
includesBaseElement
|
|
253
|
+
} = composite.getState();
|
|
254
|
+
const shouldShift = focusShift && !skip;
|
|
255
|
+
const verticalItems = verticalizeItems(
|
|
256
|
+
_GDZQUFNPcjs.flatten2DArray.call(void 0,
|
|
257
|
+
normalizeRows(groupItemsByRows(renderedItems), activeId2, shouldShift)
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
const canLoop = focusLoop && focusLoop !== "horizontal";
|
|
261
|
+
const hasNullItem = canLoop && includesBaseElement;
|
|
262
|
+
return getNextId(verticalItems, "vertical", hasNullItem, skip);
|
|
263
|
+
},
|
|
264
|
+
up: (skip) => {
|
|
265
|
+
const { activeId: activeId2, renderedItems, focusShift, includesBaseElement } = composite.getState();
|
|
266
|
+
const shouldShift = focusShift && !skip;
|
|
267
|
+
const verticalItems = verticalizeItems(
|
|
268
|
+
_GDZQUFNPcjs.reverseArray.call(void 0,
|
|
269
|
+
_GDZQUFNPcjs.flatten2DArray.call(void 0,
|
|
270
|
+
normalizeRows(
|
|
271
|
+
groupItemsByRows(renderedItems),
|
|
272
|
+
activeId2,
|
|
273
|
+
shouldShift
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
)
|
|
277
|
+
);
|
|
278
|
+
const hasNullItem = includesBaseElement;
|
|
279
|
+
return getNextId(verticalItems, "vertical", hasNullItem, skip);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
exports.createCompositeStore = createCompositeStore;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _7ZXWQTAYcjs = require('./7ZXWQTAY.cjs');
|
|
4
|
+
|
|
5
|
+
// src/dialog/dialog-store.ts
|
|
6
|
+
function createDialogStore(props = {}) {
|
|
7
|
+
return _7ZXWQTAYcjs.createDisclosureStore.call(void 0, props);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.createDialogStore = createDialogStore;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _3KP2MDG6cjs = require('./3KP2MDG6.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _3BBA3Z5Gcjs = require('./3BBA3Z5G.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _5D5Y5EI4cjs = require('./5D5Y5EI4.cjs');
|
|
10
|
+
|
|
11
|
+
// src/hovercard/hovercard-store.ts
|
|
12
|
+
function createHovercardStore(props = {}) {
|
|
13
|
+
const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
|
|
14
|
+
const timeout = _5D5Y5EI4cjs.defaultValue.call(void 0, props.timeout, _optionalChain([syncState, 'optionalAccess', _4 => _4.timeout]), 500);
|
|
15
|
+
const popover = _3KP2MDG6cjs.createPopoverStore.call(void 0, {
|
|
16
|
+
...props,
|
|
17
|
+
placement: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
18
|
+
props.placement,
|
|
19
|
+
_optionalChain([syncState, 'optionalAccess', _5 => _5.placement]),
|
|
20
|
+
"bottom"
|
|
21
|
+
)
|
|
22
|
+
});
|
|
23
|
+
const initialState = {
|
|
24
|
+
...popover.getState(),
|
|
25
|
+
timeout,
|
|
26
|
+
showTimeout: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
27
|
+
props.showTimeout,
|
|
28
|
+
_optionalChain([syncState, 'optionalAccess', _6 => _6.showTimeout]),
|
|
29
|
+
timeout
|
|
30
|
+
),
|
|
31
|
+
hideTimeout: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
32
|
+
props.hideTimeout,
|
|
33
|
+
_optionalChain([syncState, 'optionalAccess', _7 => _7.hideTimeout]),
|
|
34
|
+
timeout
|
|
35
|
+
),
|
|
36
|
+
autoFocusOnShow: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _8 => _8.autoFocusOnShow]), false)
|
|
37
|
+
};
|
|
38
|
+
const hovercard = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, popover, props.store);
|
|
39
|
+
hovercard.setup(
|
|
40
|
+
() => hovercard.sync(
|
|
41
|
+
(state) => {
|
|
42
|
+
hovercard.setState("showTimeout", (value) => _nullishCoalesce(value, () => ( state.timeout)));
|
|
43
|
+
hovercard.setState("hideTimeout", (value) => _nullishCoalesce(value, () => ( state.timeout)));
|
|
44
|
+
},
|
|
45
|
+
["timeout"]
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
return {
|
|
49
|
+
...popover,
|
|
50
|
+
...hovercard,
|
|
51
|
+
setAutoFocusOnShow: (value) => hovercard.setState("autoFocusOnShow", value)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
exports.createHovercardStore = createHovercardStore;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/array.ts
|
|
2
|
+
function toArray(arg) {
|
|
3
|
+
if (Array.isArray(arg)) {
|
|
4
|
+
return arg;
|
|
5
|
+
}
|
|
6
|
+
return typeof arg !== "undefined" ? [arg] : [];
|
|
7
|
+
}
|
|
8
|
+
function addItemToArray(array, item, index = -1) {
|
|
9
|
+
if (!(index in array)) {
|
|
10
|
+
return [...array, item];
|
|
11
|
+
}
|
|
12
|
+
return [...array.slice(0, index), item, ...array.slice(index)];
|
|
13
|
+
}
|
|
14
|
+
function flatten2DArray(array) {
|
|
15
|
+
const flattened = [];
|
|
16
|
+
for (const row of array) {
|
|
17
|
+
flattened.push(...row);
|
|
18
|
+
}
|
|
19
|
+
return flattened;
|
|
20
|
+
}
|
|
21
|
+
function reverseArray(array) {
|
|
22
|
+
return array.slice().reverse();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.toArray = toArray; exports.addItemToArray = addItemToArray; exports.flatten2DArray = flatten2DArray; exports.reverseArray = reverseArray;
|