@buildinams/core 0.0.2 → 0.2.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/dist/navigation/index.d.ts +51 -0
- package/dist/navigation/index.js +29 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/store/index.d.ts +47 -1
- package/dist/store/index.js +106 -1
- package/dist/store/index.js.map +1 -1
- package/package.json +8 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the schema for parsing and stringifying states to and from hrefs.
|
|
3
|
+
*
|
|
4
|
+
* The `HrefSchema` type is a generic that takes a state shape and declares three methods:
|
|
5
|
+
*
|
|
6
|
+
* - `parse`: A function that takes an href string and returns the corresponding state object.
|
|
7
|
+
* - `stringify`: A function that takes a state object and the current href, and returns a new href string that represents the given state.
|
|
8
|
+
* - `parseStringify`: A function that takes a current href and a mutation function, and returns a new href string that represents the mutated state.
|
|
9
|
+
*
|
|
10
|
+
* This schema is used to map application state to URL hrefs and vice versa.
|
|
11
|
+
*/
|
|
12
|
+
type HrefSchema<State = any> = {
|
|
13
|
+
/** Parse a href string into the state shape */
|
|
14
|
+
parse: (href: string) => State & {
|
|
15
|
+
href: string;
|
|
16
|
+
};
|
|
17
|
+
/** Stringify a state shape and current href into a new href string */
|
|
18
|
+
stringify: (state: State & {
|
|
19
|
+
href: string;
|
|
20
|
+
}) => string;
|
|
21
|
+
/** Compute a new href string based on a given href and a mutation of the current state. */
|
|
22
|
+
parseStringify: (href: string, mutate: (state: State) => State) => string;
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
_template: HrefSchemaTemplate<State>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A utility type to extract the state shape from a given `HrefSchema`. It infers the state type from the `HrefSchema` and adds the `href` property to it.
|
|
30
|
+
*/
|
|
31
|
+
type HrefSchemaState<T extends HrefSchema> = T extends HrefSchema<infer U> ? U & {
|
|
32
|
+
href: string;
|
|
33
|
+
} : never;
|
|
34
|
+
/**
|
|
35
|
+
* Helper function to create a `HrefSchema` from a simpler template that only requires the logic for converting between URLs and state objects. The `createSchema` function takes care of implementing the `parse`, `stringify`, and `parseStringify` methods based on the provided template functions.
|
|
36
|
+
*
|
|
37
|
+
* The template requires two functions:
|
|
38
|
+
* - `urlToState`: A function that takes a URL object and returns the corresponding state object.
|
|
39
|
+
* - `stateToUrl`: A function that takes a state object and the current URL, and returns a new URL object that represents the given state.
|
|
40
|
+
*
|
|
41
|
+
* This allows you to focus on the logic for how your application's state maps to the URL structure without having to manually handle the parsing and stringifying of hrefs.
|
|
42
|
+
*/
|
|
43
|
+
declare const createHrefSchema: <T>(template: HrefSchemaTemplate<T>) => HrefSchema<T>;
|
|
44
|
+
type HrefSchemaTemplate<State = never> = {
|
|
45
|
+
/** Parse a href string into the state shape */
|
|
46
|
+
urlToState: (url: URL) => State;
|
|
47
|
+
/** Stringify a state shape and current href into a new href string */
|
|
48
|
+
stateToUrl: (state: State, url: URL) => URL;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { type HrefSchema, type HrefSchemaState, createHrefSchema };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/navigation/href-schema.ts
|
|
2
|
+
var hrefToUrl = (href) => new URL(href, "http://localhost");
|
|
3
|
+
var createHrefSchema = (template) => ({
|
|
4
|
+
_template: template,
|
|
5
|
+
stringify: (state) => {
|
|
6
|
+
const current = hrefToUrl(state.href);
|
|
7
|
+
const next = template.stateToUrl(state, current);
|
|
8
|
+
return next.pathname + next.search;
|
|
9
|
+
},
|
|
10
|
+
parse: (href) => {
|
|
11
|
+
const current = hrefToUrl(href);
|
|
12
|
+
return {
|
|
13
|
+
...template.urlToState(current),
|
|
14
|
+
href: current.pathname + current.search
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
parseStringify: (href, mutate) => {
|
|
18
|
+
const current = hrefToUrl(href);
|
|
19
|
+
const next = template.stateToUrl(
|
|
20
|
+
mutate(template.urlToState(current)),
|
|
21
|
+
current
|
|
22
|
+
);
|
|
23
|
+
return next.pathname + next.search;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export { createHrefSchema };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/navigation/href-schema.ts"],"names":[],"mappings":";AAmCA,IAAM,YAAY,CAAC,IAAA,KAAiB,IAAI,GAAA,CAAI,MAAM,kBAAkB,CAAA;AAW7D,IAAM,gBAAA,GAAmB,CAC/B,QAAA,MACoB;AAAA,EACpB,SAAA,EAAW,QAAA;AAAA,EACX,SAAA,EAAW,CAAC,KAAA,KAAU;AACrB,IAAA,MAAM,OAAA,GAAU,SAAA,CAAU,KAAA,CAAM,IAAI,CAAA;AACpC,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,UAAA,CAAW,KAAA,EAAO,OAAO,CAAA;AAC/C,IAAA,OAAO,IAAA,CAAK,WAAW,IAAA,CAAK,MAAA;AAAA,EAC7B,CAAA;AAAA,EAEA,KAAA,EAAO,CAAC,IAAA,KAAS;AAChB,IAAA,MAAM,OAAA,GAAU,UAAU,IAAI,CAAA;AAC9B,IAAA,OAAO;AAAA,MACN,GAAG,QAAA,CAAS,UAAA,CAAW,OAAO,CAAA;AAAA,MAC9B,IAAA,EAAM,OAAA,CAAQ,QAAA,GAAW,OAAA,CAAQ;AAAA,KAClC;AAAA,EACD,CAAA;AAAA,EAEA,cAAA,EAAgB,CAAC,IAAA,EAAM,MAAA,KAAW;AACjC,IAAA,MAAM,OAAA,GAAU,UAAU,IAAI,CAAA;AAC9B,IAAA,MAAM,OAAO,QAAA,CAAS,UAAA;AAAA,MACrB,MAAA,CAAO,QAAA,CAAS,UAAA,CAAW,OAAO,CAAC,CAAA;AAAA,MACnC;AAAA,KACD;AACA,IAAA,OAAO,IAAA,CAAK,WAAW,IAAA,CAAK,MAAA;AAAA,EAC7B;AACD,CAAA","file":"index.js","sourcesContent":["/**\n * Defines the schema for parsing and stringifying states to and from hrefs.\n *\n * The `HrefSchema` type is a generic that takes a state shape and declares three methods:\n *\n * - `parse`: A function that takes an href string and returns the corresponding state object.\n * - `stringify`: A function that takes a state object and the current href, and returns a new href string that represents the given state.\n * - `parseStringify`: A function that takes a current href and a mutation function, and returns a new href string that represents the mutated state.\n *\n * This schema is used to map application state to URL hrefs and vice versa.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type HrefSchema<State = any> = {\n\t/** Parse a href string into the state shape */\n\tparse: (href: string) => State & { href: string };\n\t/** Stringify a state shape and current href into a new href string */\n\tstringify: (state: State & { href: string }) => string;\n\n\t/** Compute a new href string based on a given href and a mutation of the current state. */\n\tparseStringify: (href: string, mutate: (state: State) => State) => string;\n\n\t/**\n\t * @internal\n\t */\n\t_template: HrefSchemaTemplate<State>;\n};\n\n/**\n * A utility type to extract the state shape from a given `HrefSchema`. It infers the state type from the `HrefSchema` and adds the `href` property to it.\n */\nexport type HrefSchemaState<T extends HrefSchema> =\n\tT extends HrefSchema<infer U> ? U & { href: string } : never;\n\n// This is fine as we only use the `pathname` an `search` properties from the URL object,\n// which do not contain the \"https://localhost\" origin.\nconst hrefToUrl = (href: string) => new URL(href, \"http://localhost\");\n\n/**\n * Helper function to create a `HrefSchema` from a simpler template that only requires the logic for converting between URLs and state objects. The `createSchema` function takes care of implementing the `parse`, `stringify`, and `parseStringify` methods based on the provided template functions.\n *\n * The template requires two functions:\n * - `urlToState`: A function that takes a URL object and returns the corresponding state object.\n * - `stateToUrl`: A function that takes a state object and the current URL, and returns a new URL object that represents the given state.\n *\n * This allows you to focus on the logic for how your application's state maps to the URL structure without having to manually handle the parsing and stringifying of hrefs.\n */\nexport const createHrefSchema = <T>(\n\ttemplate: HrefSchemaTemplate<T>,\n): HrefSchema<T> => ({\n\t_template: template,\n\tstringify: (state) => {\n\t\tconst current = hrefToUrl(state.href);\n\t\tconst next = template.stateToUrl(state, current);\n\t\treturn next.pathname + next.search;\n\t},\n\n\tparse: (href) => {\n\t\tconst current = hrefToUrl(href);\n\t\treturn {\n\t\t\t...template.urlToState(current),\n\t\t\thref: current.pathname + current.search,\n\t\t};\n\t},\n\n\tparseStringify: (href, mutate) => {\n\t\tconst current = hrefToUrl(href);\n\t\tconst next = template.stateToUrl(\n\t\t\tmutate(template.urlToState(current)),\n\t\t\tcurrent,\n\t\t);\n\t\treturn next.pathname + next.search;\n\t},\n});\n\ntype HrefSchemaTemplate<State = never> = {\n\t/** Parse a href string into the state shape */\n\turlToState: (url: URL) => State;\n\t/** Stringify a state shape and current href into a new href string */\n\tstateToUrl: (state: State, url: URL) => URL;\n};\n"]}
|
package/dist/store/index.d.ts
CHANGED
|
@@ -158,4 +158,50 @@ type CollectionStoreOptions<T extends CollectionStoreItem = CollectionStoreItem>
|
|
|
158
158
|
type CollectionStoreProps<T extends CollectionStoreItem = CollectionStoreItem> = {} & CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;
|
|
159
159
|
type CollectionStore<T extends CollectionStoreItem = CollectionStoreItem> = {} & CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Creates a grouped store.
|
|
163
|
+
*/
|
|
164
|
+
declare function createStoreGroupStore<StoreT extends Store>(props?: StoreGroupStoreProps<StoreT>): StoreGroupStore<StoreT>;
|
|
165
|
+
type StoreGroupStoreItem<StoreT extends Store> = {
|
|
166
|
+
/**
|
|
167
|
+
* The id of the item.
|
|
168
|
+
*/
|
|
169
|
+
id: string;
|
|
170
|
+
store?: StoreT;
|
|
171
|
+
};
|
|
172
|
+
type StoreGroupStoreState<StoreT extends Store, ItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>> = {
|
|
173
|
+
items: ItemT[];
|
|
174
|
+
states: Array<StoreT extends Store<infer StateT> ? StateT : never>;
|
|
175
|
+
};
|
|
176
|
+
type StoreGroupStoreFunctions<StoreT extends Store, ItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>> = {
|
|
177
|
+
/**
|
|
178
|
+
* Registers an item in the collection. This function returns a cleanup
|
|
179
|
+
* function that unregisters the item.
|
|
180
|
+
*
|
|
181
|
+
* Note: This method is usually called internally by components that expose a group provider.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const unregisterItem = store.registerItem({ id: "item-1", store: itemStore });
|
|
185
|
+
* // on cleanup
|
|
186
|
+
* unregisterItem();
|
|
187
|
+
*/
|
|
188
|
+
registerItem: BivariantCallback<(item: ItemT) => () => void>;
|
|
189
|
+
/**
|
|
190
|
+
* Gets an item's store by its id.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* const itemStore = store.item("item-1");
|
|
194
|
+
*/
|
|
195
|
+
item: (id: string | null | undefined) => StoreT | undefined;
|
|
196
|
+
};
|
|
197
|
+
type StoreGroupStoreOptions<StoreT extends Store, ItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>> = {
|
|
198
|
+
/**
|
|
199
|
+
* The defaut value for the `items` state.
|
|
200
|
+
* @default []
|
|
201
|
+
*/
|
|
202
|
+
defaultItems?: StoreGroupStoreState<StoreT, ItemT>["items"];
|
|
203
|
+
} & StoreOptions<StoreGroupStoreState<StoreT, ItemT>, "items">;
|
|
204
|
+
type StoreGroupStoreProps<StoreT extends Store, ItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>> = {} & StoreGroupStoreOptions<StoreT, ItemT> & StoreProps<StoreGroupStoreState<StoreT, ItemT>>;
|
|
205
|
+
type StoreGroupStore<StoreT extends Store, ItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>> = {} & StoreGroupStoreFunctions<StoreT, ItemT> & Store<StoreGroupStoreState<StoreT, ItemT>>;
|
|
206
|
+
|
|
207
|
+
export { type CollectionStore, type CollectionStoreFunctions, type CollectionStoreItem, type CollectionStoreOptions, type CollectionStoreProps, type CollectionStoreState, type State, type Store, type StoreGroupStore, type StoreGroupStoreFunctions, type StoreGroupStoreItem, type StoreGroupStoreOptions, type StoreGroupStoreProps, type StoreGroupStoreState, type StoreOptions, type StoreProps, type StoreState, batch, createCollectionStore, createStore, createStoreGroupStore, init, mergeStore, omit, pick, setup, subscribe, sync, throwOnConflictingProps };
|
package/dist/store/index.js
CHANGED
|
@@ -412,6 +412,111 @@ function createCollectionStore(props = {}) {
|
|
|
412
412
|
};
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
|
|
415
|
+
// src/store/store-group-store.ts
|
|
416
|
+
function getPrivateStore2(store) {
|
|
417
|
+
return store?.__unstablePrivateStore;
|
|
418
|
+
}
|
|
419
|
+
function createStoreGroupStore(props = {}) {
|
|
420
|
+
throwOnConflictingProps(props, props.store);
|
|
421
|
+
const syncState = props.store?.getState();
|
|
422
|
+
const items = defaultValue(
|
|
423
|
+
props.items,
|
|
424
|
+
syncState?.items,
|
|
425
|
+
props.defaultItems,
|
|
426
|
+
[]
|
|
427
|
+
);
|
|
428
|
+
const itemsMap = new Map(items.map((item) => [item.id, item]));
|
|
429
|
+
const initialState = {
|
|
430
|
+
items,
|
|
431
|
+
states: items.map((item) => item.store?.getState())
|
|
432
|
+
};
|
|
433
|
+
const syncPrivateStore = getPrivateStore2(props.store);
|
|
434
|
+
const privateStore = createStore({ items }, syncPrivateStore);
|
|
435
|
+
const store = createStore(initialState, props.store);
|
|
436
|
+
setup(store, () => init(privateStore));
|
|
437
|
+
setup(privateStore, () => {
|
|
438
|
+
return batch(privateStore, ["items"], (state) => {
|
|
439
|
+
store.setState("items", state.items);
|
|
440
|
+
store.setState(
|
|
441
|
+
"states",
|
|
442
|
+
state.items.map((item) => item.store?.getState())
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
const mergeItem = (item, setItems, canDeleteFromMap = false) => {
|
|
447
|
+
let prevItem;
|
|
448
|
+
setItems((items2) => {
|
|
449
|
+
const index = items2.findIndex(({ id }) => id === item.id);
|
|
450
|
+
const nextItems = items2.slice();
|
|
451
|
+
if (index !== -1) {
|
|
452
|
+
prevItem = items2[index];
|
|
453
|
+
const nextItem = { ...prevItem, ...item };
|
|
454
|
+
nextItems[index] = nextItem;
|
|
455
|
+
itemsMap.set(item.id, nextItem);
|
|
456
|
+
} else {
|
|
457
|
+
nextItems.push(item);
|
|
458
|
+
itemsMap.set(item.id, item);
|
|
459
|
+
}
|
|
460
|
+
return nextItems;
|
|
461
|
+
});
|
|
462
|
+
const unmergeItem = () => {
|
|
463
|
+
setItems((items2) => {
|
|
464
|
+
if (!prevItem) {
|
|
465
|
+
if (canDeleteFromMap) {
|
|
466
|
+
itemsMap.delete(item.id);
|
|
467
|
+
}
|
|
468
|
+
return items2.filter(({ id }) => id !== item.id);
|
|
469
|
+
}
|
|
470
|
+
const index = items2.findIndex(({ id }) => id === item.id);
|
|
471
|
+
if (index === -1) return items2;
|
|
472
|
+
const nextItems = items2.slice();
|
|
473
|
+
nextItems[index] = prevItem;
|
|
474
|
+
itemsMap.set(item.id, prevItem);
|
|
475
|
+
return nextItems;
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
return unmergeItem;
|
|
479
|
+
};
|
|
480
|
+
const registerItem = (item) => {
|
|
481
|
+
const unsubscribe = subscribe(item.store, null, () => {
|
|
482
|
+
const index = privateStore.getState().items.findIndex((i) => i.id === item.id);
|
|
483
|
+
if (index === -1) return;
|
|
484
|
+
store.setState("states", (states) => {
|
|
485
|
+
const nextStates = states.slice();
|
|
486
|
+
nextStates[index] = item.store?.getState();
|
|
487
|
+
return nextStates;
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
const cleanup = mergeItem(
|
|
491
|
+
item,
|
|
492
|
+
(getItems) => privateStore.setState("items", getItems),
|
|
493
|
+
true
|
|
494
|
+
);
|
|
495
|
+
return () => {
|
|
496
|
+
unsubscribe();
|
|
497
|
+
cleanup();
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
return {
|
|
501
|
+
...store,
|
|
502
|
+
registerItem,
|
|
503
|
+
item: (id) => {
|
|
504
|
+
if (!id) return void 0;
|
|
505
|
+
let item = itemsMap.get(id);
|
|
506
|
+
if (!item) {
|
|
507
|
+
const { items: items2 } = privateStore.getState();
|
|
508
|
+
item = items2.find((item2) => item2.id === id);
|
|
509
|
+
if (item) {
|
|
510
|
+
itemsMap.set(id, item);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return item?.store || void 0;
|
|
514
|
+
},
|
|
515
|
+
// @ts-expect-error Internal
|
|
516
|
+
__unstablePrivateStore: privateStore
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export { batch, createCollectionStore, createStore, createStoreGroupStore, init, mergeStore, omit2 as omit, pick2 as pick, setup, subscribe, sync, throwOnConflictingProps };
|
|
416
521
|
//# sourceMappingURL=index.js.map
|
|
417
522
|
//# sourceMappingURL=index.js.map
|
package/dist/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/store/dom.ts","../../src/store/utils.ts","../../src/store/store.ts","../../src/store/collection-store.ts"],"names":["state","setup","omit","pick","store","items","item"],"mappings":";;;AAGO,SAAS,YAAY,IAAA,EAAkD;AAC7E,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,IAAI,MAAA,IAAU,IAAA,EAAM,OAAO,IAAA,CAAK,QAAA;AAChC,EAAA,OAAO,KAAK,aAAA,IAAiB,QAAA;AAC9B;AAKO,SAAS,sBAAA,CACf,OACA,UAAA,EACC;AACD,EAAA,MAAM,KAAA,GAAQ,MAAM,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU,CAAC,KAAA,EAAO,IAAI,CAAU,CAAA;AAC/D,EAAA,IAAI,gBAAA,GAAmB,KAAA;AACvB,EAAA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A,UAAA,EAAY,CAAC,IAAA,KACZ,KAAA;AAAA,MACC,aAAa,IAAI,CAAA;AAAA,MACjB,SAAA;AAAA,QAAU,IAAA;AAAA,QAAM,CAAC,QAAA,KAChB,YAAA,CAAa,QAAA,CAAS,iBAAiB,QAAQ;AAAA;AAChD,KACD;AAAA,IAED,IAAA,EAAM,CAAC,EAAA,KAAO;AACb,MAAA,IAAI,CAAC,IAAI,OAAO,IAAA;AAChB,MAAA,IAAI,IAAA,GAAO,QAAA,CAAS,GAAA,CAAI,EAAE,CAAA;AAC1B,MAAA,IAAI,CAAC,IAAA,EAAM;AACV,QAAA,MAAM,EAAE,KAAA,EAAAA,MAAAA,EAAM,GAAI,aAAa,QAAA,EAAS;AACxC,QAAA,IAAA,GAAOA,OAAM,IAAA,CAAK,CAACC,KAAAA,KAASA,KAAAA,CAAK,OAAO,EAAE,CAAA;AAC1C,QAAA,IAAI,IAAA,EAAM;AACT,UAAA,QAAA,CAAS,GAAA,CAAI,IAAI,IAAI,CAAA;AAAA,QACtB;AAAA,MACD;AACA,MAAA,OAAO,IAAA,IAAQ,IAAA;AAAA,IAChB,CAAA;AAAA;AAAA,IAGA,sBAAA,EAAwB;AAAA,GACzB;AACD","file":"index.js","sourcesContent":["/**\n * Returns `element.ownerDocument || document`.\n */\nexport function getDocument(node?: Window | Document | Node | null): Document {\n\tif (!node) return document;\n\tif (\"self\" in node) return node.document;\n\treturn node.ownerDocument || document;\n}\n\n/**\n * Sort the items based on their DOM position.\n */\nexport function sortBasedOnDOMPosition<T>(\n\titems: T[],\n\tgetElement: (item: T) => Element | null | undefined,\n) {\n\tconst pairs = items.map((item, index) => [index, item] as const);\n\tlet isOrderDifferent = false;\n\tpairs.sort(([indexA, a], [indexB, b]) => {\n\t\tconst elementA = getElement(a);\n\t\tconst elementB = getElement(b);\n\t\tif (elementA === elementB) return 0;\n\t\tif (!elementA || !elementB) return 0;\n\t\t// a before b\n\t\tif (isElementPreceding(elementA, elementB)) {\n\t\t\tif (indexA > indexB) {\n\t\t\t\tisOrderDifferent = true;\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\t\t// a after b\n\t\tif (indexA < indexB) {\n\t\t\tisOrderDifferent = true;\n\t\t}\n\t\treturn 1;\n\t});\n\tif (isOrderDifferent) {\n\t\treturn pairs.map(([_, item]) => item);\n\t}\n\treturn items;\n}\n\nfunction isElementPreceding(a: Element, b: Element) {\n\treturn Boolean(\n\t\tb.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING,\n\t);\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { hasOwnProperty, isObject } from \"src/functions\";\nimport type { AnyFunction, AnyObject } from \"src/types\";\n\n/**\n * ============================================================================\n * STORE UTILITIES\n * ============================================================================\n *\n * Implementation taken from AriaKit (https://ariakit.org/)\n *\n * https://github.com/ariakit/ariakit/blob/295118174512ee27b81822f7f16d7cdf9d0d0be6/packages/ariakit-core/src/utils/misc.ts\n */\n/** */\n\n/**\n * Empty function.\n */\nexport function noop(..._: any[]): any {}\n\n/**\n * Checks whether `arg` is empty or not.\n * @example\n * isEmpty([]); // true\n * isEmpty([\"a\"]); // false\n * isEmpty({}); // true\n * isEmpty({ a: \"a\" }); // false\n * isEmpty(); // true\n * isEmpty(null); // true\n * isEmpty(undefined); // true\n * isEmpty(\"\"); // true\n */\nexport function isEmpty(arg: any): boolean {\n\tif (Array.isArray(arg)) return !arg.length;\n\tif (isObject(arg)) return !Object.keys(arg).length;\n\tif (arg == null) return true;\n\tif (arg === \"\") return true;\n\treturn false;\n}\n\n/**\n * Receives functions as arguments and returns a new function that calls all.\n */\nexport function chain<T>(...fns: T[]) {\n\treturn (...args: T extends AnyFunction ? Parameters<T> : never) => {\n\t\tfor (const fn of fns) {\n\t\t\tif (typeof fn === \"function\") {\n\t\t\t\tfn(...args);\n\t\t\t}\n\t\t}\n\t};\n}\n\n/**\n * Omits specific keys from an object.\n * @example\n * omit({ a: \"a\", b: \"b\" }, [\"a\"]); // { b: \"b\" }\n */\nexport function omit<T extends AnyObject, K extends keyof T>(\n\tobject: T,\n\tkeys: ReadonlyArray<K> | K[],\n) {\n\tconst result = { ...object } as Omit<T, K>;\n\tfor (const key of keys) {\n\t\tif (hasOwnProperty(result, key)) {\n\t\t\tdelete result[key];\n\t\t}\n\t}\n\treturn result;\n}\n\n/**\n * Picks specific keys from an object.\n * @example\n * pick({ a: \"a\", b: \"b\" }, [\"a\"]); // { a: \"a\" }\n */\nexport function pick<T extends AnyObject, K extends keyof T>(\n\tobject: T,\n\tpaths: ReadonlyArray<K> | K[],\n) {\n\tconst result = {} as Pick<T, K>;\n\tfor (const key of paths) {\n\t\tif (hasOwnProperty(object, key)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\treturn result;\n}\n\n/**\n * Similar to `Object.keys` but returns a type-safe array of keys.\n */\nexport function getKeys<T extends object>(obj: T) {\n\treturn Object.keys(obj) as Array<keyof T>;\n}\n\n/**\n * Checks whether something is disabled or not based on its props.\n */\nexport function disabledFromProps(props: {\n\tdisabled?: boolean;\n\t\"aria-disabled\"?: boolean | \"true\" | \"false\";\n}) {\n\treturn (\n\t\tprops.disabled ||\n\t\tprops[\"aria-disabled\"] === true ||\n\t\tprops[\"aria-disabled\"] === \"true\"\n\t);\n}\n","import { applyState, hasOwnProperty, invariant } from \"src/functions\";\nimport type { AnyObject, SetStateAction } from \"src/types\";\n\nimport { chain, getKeys, noop, omit as _omit, pick as _pick } from \"./utils\";\n\n/**\n * ============================================================================\n * STORE\n * ============================================================================\n *\n * Implementation taken from AriaKit (https://ariakit.org/)\n *\n * https://github.com/ariakit/ariakit/blob/295118174512ee27b81822f7f16d7cdf9d0d0be6/packages/ariakit-core/src/utils/store.ts\n */\n/** */\n\ntype Listener<S> = (state: S, prevState: S) => void | (() => void);\n\ntype Sync<S, K extends keyof S> = (\n\tkeys: K[] | null,\n\tlistener: Listener<Pick<S, K>>,\n) => () => void;\n\ntype StoreSetup = (callback: () => void | (() => void)) => () => void;\ntype StoreInit = () => () => void;\ntype StoreSubscribe<S = State, K extends keyof S = keyof S> = Sync<S, K>;\ntype StoreSync<S = State, K extends keyof S = keyof S> = Sync<S, K>;\ntype StoreBatch<S = State, K extends keyof S = keyof S> = Sync<S, K>;\ntype StorePick<\n\tS = State,\n\tK extends ReadonlyArray<keyof S> = ReadonlyArray<keyof S>,\n> = (keys: K) => Store<Pick<S, K[number]>>;\ntype StoreOmit<\n\tS = State,\n\tK extends ReadonlyArray<keyof S> = ReadonlyArray<keyof S>,\n> = (keys: K) => Store<Omit<S, K[number]>>;\n\ntype StoreInternals<S = State> = {\n\tsetup: StoreSetup;\n\tinit: StoreInit;\n\tsubscribe: StoreSubscribe<S>;\n\tsync: StoreSync<S>;\n\tbatch: StoreBatch<S>;\n\tpick: StorePick<S>;\n\tomit: StoreOmit<S>;\n};\n\nfunction getInternal<K extends keyof StoreInternals>(\n\tstore: Store & { __unstableInternals?: StoreInternals },\n\tkey: K,\n): StoreInternals[K] {\n\tconst internals = store.__unstableInternals;\n\tinvariant(internals, \"Invalid store\");\n\treturn internals[key];\n}\n\n/**\n * Creates a store.\n * @param initialState Initial state.\n * @param stores Stores to extend.\n */\nexport function createStore<S extends State>(\n\tinitialState: S,\n\t...stores: Array<Store<Partial<S>> | undefined>\n): Store<S> {\n\tlet state = initialState;\n\tlet prevStateBatch = state;\n\tlet lastUpdate = Symbol();\n\tlet destroy = noop;\n\tconst instances = new Set<symbol>();\n\tconst updatedKeys = new Set<keyof S>();\n\n\tconst setups = new Set<() => void | (() => void)>();\n\tconst listeners = new Set<Listener<S>>();\n\tconst batchListeners = new Set<Listener<S>>();\n\tconst disposables = new WeakMap<Listener<S>, void | (() => void)>();\n\tconst listenerKeys = new WeakMap<Listener<S>, Array<keyof S> | null>();\n\n\tconst storeSetup: StoreSetup = (callback) => {\n\t\tsetups.add(callback);\n\t\treturn () => setups.delete(callback);\n\t};\n\n\tconst storeInit: StoreInit = () => {\n\t\t// Make sure we only initialize the store once, even when it's passed to\n\t\t// other stores. However, the store can't be destroyed until all instances\n\t\t// are unmounted. See https://github.com/ariakit/ariakit/issues/3147. See\n\t\t// select-default-open-controlled tests.\n\t\tconst initialized = instances.size;\n\t\tconst instance = Symbol();\n\t\tinstances.add(instance);\n\n\t\tconst maybeDestroy = () => {\n\t\t\tinstances.delete(instance);\n\t\t\tif (instances.size) return;\n\t\t\tdestroy();\n\t\t};\n\n\t\tif (initialized) return maybeDestroy;\n\n\t\tconst desyncs = getKeys(state).map((key) =>\n\t\t\tchain(\n\t\t\t\t...stores.map((store) => {\n\t\t\t\t\tconst storeState = store?.getState?.();\n\t\t\t\t\tif (!storeState) return;\n\t\t\t\t\tif (!hasOwnProperty(storeState, key)) return;\n\t\t\t\t\treturn sync(store, [key], (state) => {\n\t\t\t\t\t\tsetState(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tstate[key]!,\n\t\t\t\t\t\t\t// @ts-expect-error - Not public API. This is just to prevent\n\t\t\t\t\t\t\t// infinite loops.\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\n\t\tconst teardowns: Array<void | (() => void)> = [];\n\t\tfor (const setup of setups) {\n\t\t\tteardowns.push(setup());\n\t\t}\n\n\t\tconst cleanups = stores.map(init);\n\n\t\tdestroy = chain(...desyncs, ...teardowns, ...cleanups);\n\n\t\treturn maybeDestroy;\n\t};\n\n\tconst sub = (\n\t\tkeys: Array<keyof S> | null,\n\t\tlistener: Listener<S>,\n\t\tset = listeners,\n\t) => {\n\t\tset.add(listener);\n\t\tlistenerKeys.set(listener, keys);\n\t\treturn () => {\n\t\t\tdisposables.get(listener)?.();\n\t\t\tdisposables.delete(listener);\n\t\t\tlistenerKeys.delete(listener);\n\t\t\tset.delete(listener);\n\t\t};\n\t};\n\n\tconst storeSubscribe: StoreSubscribe<S> = (keys, listener) =>\n\t\tsub(keys, listener);\n\n\tconst storeSync: StoreSync<S> = (keys, listener) => {\n\t\tdisposables.set(listener, listener(state, state));\n\t\treturn sub(keys, listener);\n\t};\n\n\tconst storeBatch: StoreBatch<S> = (keys, listener) => {\n\t\tdisposables.set(listener, listener(state, prevStateBatch));\n\t\treturn sub(keys, listener, batchListeners);\n\t};\n\n\tconst storePick: StorePick<S, ReadonlyArray<keyof S>> = (keys) =>\n\t\tcreateStore(_pick(state, keys), finalStore);\n\n\tconst storeOmit: StoreOmit<S, ReadonlyArray<keyof S>> = (keys) =>\n\t\tcreateStore(_omit(state, keys), finalStore);\n\n\tconst getState: Store<S>[\"getState\"] = () => state;\n\n\tconst setState: Store<S>[\"setState\"] = (key, value, fromStores = false) => {\n\t\tif (!hasOwnProperty(state, key)) return;\n\n\t\tconst nextValue = applyState(value, state[key]);\n\n\t\tif (nextValue === state[key]) return;\n\n\t\tif (!fromStores) {\n\t\t\tfor (const store of stores) {\n\t\t\t\tstore?.setState?.(key, nextValue);\n\t\t\t}\n\t\t}\n\n\t\tconst prevState = state;\n\t\tstate = { ...state, [key]: nextValue };\n\n\t\tconst thisUpdate = Symbol();\n\t\tlastUpdate = thisUpdate;\n\t\tupdatedKeys.add(key);\n\n\t\tconst run = (listener: Listener<S>, prev: S, uKeys?: Set<keyof S>) => {\n\t\t\tconst keys = listenerKeys.get(listener);\n\t\t\tconst updated = (k: keyof S) => (uKeys ? uKeys.has(k) : k === key);\n\t\t\tif (!keys || keys.some(updated)) {\n\t\t\t\tdisposables.get(listener)?.();\n\t\t\t\tdisposables.set(listener, listener(state, prev));\n\t\t\t}\n\t\t};\n\n\t\tfor (const listener of listeners) {\n\t\t\trun(listener, prevState);\n\t\t}\n\n\t\tqueueMicrotask(() => {\n\t\t\t// If setState is called again before this microtask runs, skip this\n\t\t\t// update. This is to prevent unnecessary updates when multiple keys are\n\t\t\t// updated in a single microtask.\n\t\t\tif (lastUpdate !== thisUpdate) return;\n\t\t\t// Take a snapshot of the state before running batch listeners. This is\n\t\t\t// necessary because batch listeners can setState.\n\t\t\tconst snapshot = state;\n\t\t\tfor (const listener of batchListeners) {\n\t\t\t\trun(listener, prevStateBatch, updatedKeys);\n\t\t\t}\n\t\t\tprevStateBatch = snapshot;\n\t\t\tupdatedKeys.clear();\n\t\t});\n\t};\n\n\tconst finalStore = {\n\t\tgetState,\n\t\tsetState,\n\t\t__unstableInternals: {\n\t\t\tsetup: storeSetup,\n\t\t\tinit: storeInit,\n\t\t\tsubscribe: storeSubscribe,\n\t\t\tsync: storeSync,\n\t\t\tbatch: storeBatch,\n\t\t\tpick: storePick,\n\t\t\tomit: storeOmit,\n\t\t},\n\t};\n\n\treturn finalStore;\n}\n\nexport function setup<T extends Store>(\n\tstore?: T | null,\n\t...args: Parameters<StoreSetup>\n): T extends Store ? ReturnType<StoreSetup> : void;\n\n/**\n * Register a callback function that's called when the store is initialized.\n */\nexport function setup(store?: Store, ...args: Parameters<StoreSetup>) {\n\tif (!store) return;\n\treturn getInternal(store, \"setup\")(...args);\n}\n\nexport function init<T extends Store>(\n\tstore?: T | null,\n\t...args: Parameters<StoreInit>\n): T extends Store ? ReturnType<StoreInit> : void;\n\n/**\n * Function that should be called when the store is initialized.\n */\nexport function init(store?: Store, ...args: Parameters<StoreInit>) {\n\tif (!store) return;\n\treturn getInternal(store, \"init\")(...args);\n}\n\nexport function subscribe<T extends Store, K extends keyof StoreState<T>>(\n\tstore?: T | null,\n\t...args: Parameters<StoreSubscribe<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreSubscribe<StoreState<T>, K>> : void;\n\n/**\n * Registers a listener function that's called after state changes in the store.\n */\nexport function subscribe(store?: Store, ...args: Parameters<StoreSubscribe>) {\n\tif (!store) return;\n\treturn getInternal(store, \"subscribe\")(...args);\n}\n\nexport function sync<T extends Store, K extends keyof StoreState<T>>(\n\tstore?: T | null,\n\t...args: Parameters<StoreSync<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreSync<StoreState<T>, K>> : void;\n\n/**\n * Registers a listener function that's called immediately and synchronously\n * whenever the store state changes.\n */\nexport function sync(store?: Store, ...args: Parameters<StoreSync>) {\n\tif (!store) return;\n\treturn getInternal(store, \"sync\")(...args);\n}\n\nexport function batch<T extends Store, K extends keyof StoreState<T>>(\n\tstore?: T | null,\n\t...args: Parameters<StoreBatch<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreBatch<StoreState<T>, K>> : void;\n\n/**\n * Registers a listener function that's called immediately and after a batch\n * of state changes in the store.\n */\nexport function batch(store?: Store, ...args: Parameters<StoreBatch>) {\n\tif (!store) return;\n\treturn getInternal(store, \"batch\")(...args);\n}\n\nexport function omit<\n\tT extends Store,\n\tK extends ReadonlyArray<keyof StoreState<T>>,\n>(\n\tstore?: T | null,\n\t...args: Parameters<StoreOmit<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreOmit<StoreState<T>, K>> : void;\n\n/**\n * Creates a new store with a subset of the current store state and keeps them\n * in sync.\n */\nexport function omit(store?: Store, ...args: Parameters<StoreOmit>) {\n\tif (!store) return;\n\treturn getInternal(store, \"omit\")(...args);\n}\n\nexport function pick<\n\tT extends Store,\n\tK extends ReadonlyArray<keyof StoreState<T>>,\n>(\n\tstore?: T | null,\n\t...args: Parameters<StorePick<StoreState<T>, K>>\n): T extends Store ? ReturnType<StorePick<StoreState<T>, K>> : void;\n\n/**\n * Creates a new store with a subset of the current store state and keeps them\n * in sync.\n */\nexport function pick(store: Store, ...args: Parameters<StorePick>) {\n\tif (!store) return;\n\treturn getInternal(store, \"pick\")(...args);\n}\n\n/**\n * Merges multiple stores into a single store.\n */\nexport function mergeStore<S extends State>(\n\t...stores: Array<Store<S> | undefined>\n): Store<S> {\n\tconst initialState = {} as S;\n\tfor (const store of stores) {\n\t\tconst nextState = store?.getState?.();\n\t\tif (nextState) {\n\t\t\tObject.assign(initialState, nextState);\n\t\t}\n\t}\n\tconst store = createStore(initialState, ...stores);\n\treturn Object.assign({}, ...stores, store);\n}\n\n/**\n * Throws when a store prop is passed in conjunction with a default state.\n */\nexport function throwOnConflictingProps(props: AnyObject, store?: Store) {\n\tif (process.env.NODE_ENV === \"production\") return;\n\tif (!store) return;\n\tconst defaultKeys = Object.entries(props)\n\t\t.filter(([key, value]) => key.startsWith(\"default\") && value !== undefined)\n\t\t.map(([key]) => {\n\t\t\tconst stateKey = key.replace(\"default\", \"\");\n\t\t\treturn `${stateKey[0]?.toLowerCase() || \"\"}${stateKey.slice(1)}`;\n\t\t});\n\tif (!defaultKeys.length) return;\n\tconst storeState = store.getState();\n\tconst conflictingProps = defaultKeys.filter((key) =>\n\t\thasOwnProperty(storeState, key),\n\t);\n\tif (!conflictingProps.length) return;\n\tthrow new Error(\n\t\t`Passing a store prop in conjunction with a default state is not supported.\n\nconst store = useSelectStore();\n<SelectProvider store={store} defaultValue=\"Apple\" />\n ^ ^\n\nInstead, pass the default state to the topmost store:\n\nconst store = useSelectStore({ defaultValue: \"Apple\" });\n<SelectProvider store={store} />\n`,\n\t);\n}\n\n/**\n * Store state type.\n */\nexport type State = AnyObject;\n\n/**\n * Initial state that can be passed to a store creator function.\n * @template S State type.\n * @template K Key type.\n */\nexport type StoreOptions<S extends State, K extends keyof S> = Partial<\n\tPick<S, K>\n>;\n\n/**\n * Props that can be passed to a store creator function.\n * @template S State type.\n */\nexport type StoreProps<S extends State = State> = {\n\t/**\n\t * Another store object that will be kept in sync with the original store.\n\t *\n\t * Live examples:\n\t * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)\n\t */\n\tstore?: Store<Partial<S>>;\n};\n\n/**\n * Extracts the state type from a store type.\n * @template T Store type.\n */\nexport type StoreState<T> = T extends Store<infer S> ? S : never;\n\n/**\n * Store.\n * @template S State type.\n */\nexport type Store<S = State> = {\n\t/**\n\t * Returns the current store state.\n\t */\n\tgetState(): S;\n\t/**\n\t * Sets a state value.\n\t */\n\tsetState<K extends keyof S>(key: K, value: SetStateAction<S[K]>): void;\n};\n","import { defaultValue } from \"../functions/default-value\";\nimport type { BivariantCallback } from \"../types/state\";\nimport { getDocument, sortBasedOnDOMPosition } from \"./dom\";\nimport type { Store, StoreOptions, StoreProps } from \"./store\";\nimport {\n\tbatch,\n\tcreateStore,\n\tinit,\n\tsetup,\n\tthrowOnConflictingProps,\n} from \"./store\";\nimport { chain } from \"./utils\";\n\nfunction getCommonParent(items: CollectionStoreItem[]) {\n\tconst firstItem = items.find((item) => !!item.element);\n\tconst lastItem = [...items].reverse().find((item) => !!item.element);\n\tlet parentElement = firstItem?.element?.parentElement;\n\twhile (parentElement && lastItem?.element) {\n\t\tconst parent = parentElement;\n\t\tif (lastItem && parent.contains(lastItem.element)) {\n\t\t\treturn parentElement;\n\t\t}\n\t\tparentElement = parentElement.parentElement;\n\t}\n\treturn getDocument(parentElement).body;\n}\n\nfunction getPrivateStore<T extends CollectionStoreItem>(\n\tstore?: Store & {\n\t\t__unstablePrivateStore?: Store<{\n\t\t\trenderedItems: T[];\n\t\t}>;\n\t},\n) {\n\treturn store?.__unstablePrivateStore;\n}\n\n/**\n * Creates a collection store.\n */\nexport function createCollectionStore<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n>(props: CollectionStoreProps<T> = {}): CollectionStore<T> {\n\tthrowOnConflictingProps(props, props.store);\n\n\tconst syncState = props.store?.getState();\n\n\tconst items = defaultValue(\n\t\tprops.items,\n\t\tsyncState?.items,\n\t\tprops.defaultItems,\n\t\t[],\n\t);\n\n\tconst itemsMap = new Map<string, T>(items.map((item) => [item.id, item]));\n\n\tconst initialState: CollectionStoreState<T> = {\n\t\titems,\n\t\trenderedItems: defaultValue(syncState?.renderedItems, []),\n\t};\n\n\tconst syncPrivateStore = getPrivateStore<T>(props.store);\n\n\tconst privateStore = createStore(\n\t\t{ items, renderedItems: initialState.renderedItems },\n\t\tsyncPrivateStore,\n\t);\n\n\tconst collection = createStore(initialState, props.store);\n\n\tconst sortItems = (renderedItems: T[]) => {\n\t\tconst sortedItems = sortBasedOnDOMPosition(renderedItems, (i) => i.element);\n\t\tprivateStore.setState(\"renderedItems\", sortedItems);\n\t\tcollection.setState(\"renderedItems\", sortedItems);\n\t};\n\n\tsetup(collection, () => init(privateStore));\n\n\t// Use the private store to register items and then batch the changes to the\n\t// public store so we don't trigger multiple updates on the store when adding\n\t// multiple items.\n\tsetup(privateStore, () => {\n\t\treturn batch(privateStore, [\"items\"], (state) => {\n\t\t\tcollection.setState(\"items\", state.items);\n\t\t});\n\t});\n\n\tsetup(privateStore, () => {\n\t\treturn batch(privateStore, [\"renderedItems\"], (state) => {\n\t\t\tlet firstRun = true;\n\n\t\t\tlet raf = requestAnimationFrame(() => {\n\t\t\t\tconst { renderedItems } = collection.getState();\n\t\t\t\t// Bail out if the rendered items haven't changed. This is important\n\t\t\t\t// because the following lines can cause this function to be called\n\t\t\t\t// again.\n\t\t\t\tif (state.renderedItems === renderedItems) return;\n\t\t\t\tsortItems(state.renderedItems);\n\t\t\t});\n\n\t\t\tif (typeof IntersectionObserver !== \"function\") {\n\t\t\t\treturn () => cancelAnimationFrame(raf);\n\t\t\t}\n\n\t\t\tconst ioCallback: IntersectionObserverCallback = () => {\n\t\t\t\tif (firstRun) {\n\t\t\t\t\t// The IntersectionObserver callback is called synchronously the first\n\t\t\t\t\t// time. We just ignore it.\n\t\t\t\t\tfirstRun = false;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcancelAnimationFrame(raf);\n\t\t\t\traf = requestAnimationFrame(() => sortItems(state.renderedItems));\n\t\t\t};\n\n\t\t\tconst root = getCommonParent(state.renderedItems);\n\t\t\tconst observer = new IntersectionObserver(ioCallback, { root });\n\n\t\t\tfor (const item of state.renderedItems) {\n\t\t\t\tif (!item.element) continue;\n\t\t\t\tobserver.observe(item.element);\n\t\t\t}\n\n\t\t\treturn () => {\n\t\t\t\tcancelAnimationFrame(raf);\n\t\t\t\tobserver.disconnect();\n\t\t\t};\n\t\t});\n\t});\n\n\tconst mergeItem = (\n\t\titem: T,\n\t\tsetItems: (getItems: (items: T[]) => T[]) => void,\n\t\tcanDeleteFromMap = false,\n\t) => {\n\t\tlet prevItem: T | undefined;\n\t\tsetItems((items) => {\n\t\t\tconst index = items.findIndex(({ id }) => id === item.id);\n\t\t\tconst nextItems = items.slice();\n\t\t\tif (index !== -1) {\n\t\t\t\tprevItem = items[index];\n\t\t\t\tconst nextItem = { ...prevItem, ...item };\n\t\t\t\tnextItems[index] = nextItem;\n\t\t\t\titemsMap.set(item.id, nextItem);\n\t\t\t} else {\n\t\t\t\tnextItems.push(item);\n\t\t\t\titemsMap.set(item.id, item);\n\t\t\t}\n\t\t\treturn nextItems;\n\t\t});\n\t\tconst unmergeItem = () => {\n\t\t\tsetItems((items) => {\n\t\t\t\tif (!prevItem) {\n\t\t\t\t\tif (canDeleteFromMap) {\n\t\t\t\t\t\titemsMap.delete(item.id);\n\t\t\t\t\t}\n\t\t\t\t\treturn items.filter(({ id }) => id !== item.id);\n\t\t\t\t}\n\t\t\t\tconst index = items.findIndex(({ id }) => id === item.id);\n\t\t\t\tif (index === -1) return items;\n\t\t\t\tconst nextItems = items.slice();\n\t\t\t\tnextItems[index] = prevItem;\n\t\t\t\titemsMap.set(item.id, prevItem);\n\t\t\t\treturn nextItems;\n\t\t\t});\n\t\t};\n\t\treturn unmergeItem;\n\t};\n\n\tconst registerItem: CollectionStore<T>[\"registerItem\"] = (item) =>\n\t\tmergeItem(\n\t\t\titem,\n\t\t\t(getItems) => privateStore.setState(\"items\", getItems),\n\t\t\ttrue,\n\t\t);\n\n\treturn {\n\t\t...collection,\n\n\t\tregisterItem,\n\t\trenderItem: (item) =>\n\t\t\tchain(\n\t\t\t\tregisterItem(item),\n\t\t\t\tmergeItem(item, (getItems) =>\n\t\t\t\t\tprivateStore.setState(\"renderedItems\", getItems),\n\t\t\t\t),\n\t\t\t),\n\n\t\titem: (id) => {\n\t\t\tif (!id) return null;\n\t\t\tlet item = itemsMap.get(id);\n\t\t\tif (!item) {\n\t\t\t\tconst { items } = privateStore.getState();\n\t\t\t\titem = items.find((item) => item.id === id);\n\t\t\t\tif (item) {\n\t\t\t\t\titemsMap.set(id, item);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn item || null;\n\t\t},\n\n\t\t// @ts-expect-error Internal\n\t\t__unstablePrivateStore: privateStore,\n\t};\n}\n\nexport type CollectionStoreItem = {\n\t/**\n\t * The id of the item.\n\t */\n\tid: string;\n\t/**\n\t * The item HTML element. This is automatically set when the item is rendered.\n\t */\n\telement?: HTMLElement | null;\n};\n\nexport type CollectionStoreState<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n> = {\n\t/**\n\t * Lists all items along with their metadata. This state is automatically\n\t * updated when an item is registered or unregistered using the\n\t * [`registerItem`](https://ariakit.org/reference/use-collection-store#registeritem)\n\t * function.\n\t *\n\t * Live examples:\n\t * - [Command Menu with\n\t * Tabs](https://ariakit.org/examples/dialog-combobox-tab-command-menu)\n\t */\n\titems: T[];\n\t/**\n\t * Lists all items, along with their metadata, in the exact order they appear in\n\t * the DOM. This state is automatically updated when an item is rendered or\n\t * unmounted using the\n\t * [`renderItem`](https://ariakit.org/reference/use-collection-store#renderitem)\n\t * function.\n\t */\n\trenderedItems: T[];\n};\n\nexport type CollectionStoreFunctions<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n> = {\n\t/**\n\t * Registers an item in the collection. This function returns a cleanup\n\t * function that unregisters the item.\n\t * @example\n\t * const unregisterItem = store.registerItem({ id: \"item-1\" });\n\t * // on cleanup\n\t * unregisterItem();\n\t */\n\tregisterItem: BivariantCallback<(item: T) => () => void>;\n\t/**\n\t * Renders an item in the collection. This function returns a cleanup function\n\t * that unmounts the item.\n\t * @example\n\t * const unrenderItem = store.renderItem({ id: \"item-1\" });\n\t * // on cleanup\n\t * unrenderItem();\n\t */\n\trenderItem: BivariantCallback<(item: T) => () => void>;\n\t/**\n\t * Gets an item by its id.\n\t *\n\t * Live examples:\n\t * - [Animated TabPanel](https://ariakit.org/examples/tab-panel-animated)\n\t * @example\n\t * const item = store.item(\"item-1\");\n\t */\n\titem: (id: string | null | undefined) => T | null;\n};\n\nexport type CollectionStoreOptions<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n> = {\n\t/**\n\t * The defaut value for the\n\t * [`items`](https://ariakit.org/reference/collection-provider#items) state.\n\t * @default []\n\t */\n\tdefaultItems?: CollectionStoreState<T>[\"items\"];\n} & StoreOptions<CollectionStoreState<T>, \"items\">;\n\nexport type CollectionStoreProps<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n> = {} & CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;\n\nexport type CollectionStore<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n> = {} & CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/store/dom.ts","../../src/store/utils.ts","../../src/store/store.ts","../../src/store/collection-store.ts","../../src/store/store-group-store.ts"],"names":["state","setup","omit","pick","store","items","item","getPrivateStore"],"mappings":";;;AAGO,SAAS,YAAY,IAAA,EAAkD;AAC7E,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,IAAI,MAAA,IAAU,IAAA,EAAM,OAAO,IAAA,CAAK,QAAA;AAChC,EAAA,OAAO,KAAK,aAAA,IAAiB,QAAA;AAC9B;AAKO,SAAS,sBAAA,CACf,OACA,UAAA,EACC;AACD,EAAA,MAAM,KAAA,GAAQ,MAAM,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU,CAAC,KAAA,EAAO,IAAI,CAAU,CAAA;AAC/D,EAAA,IAAI,gBAAA,GAAmB,KAAA;AACvB,EAAA,KAAA,CAAM,IAAA,CAAK,CAAC,CAAC,MAAA,EAAQ,CAAC,CAAA,EAAG,CAAC,MAAA,EAAQ,CAAC,CAAA,KAAM;AACxC,IAAA,MAAM,QAAA,GAAW,WAAW,CAAC,CAAA;AAC7B,IAAA,MAAM,QAAA,GAAW,WAAW,CAAC,CAAA;AAC7B,IAAA,IAA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ument || document`.\n */\nexport function getDocument(node?: Window | Document | Node | null): Document {\n\tif (!node) return document;\n\tif (\"self\" in node) return node.document;\n\treturn node.ownerDocument || document;\n}\n\n/**\n * Sort the items based on their DOM position.\n */\nexport function sortBasedOnDOMPosition<T>(\n\titems: T[],\n\tgetElement: (item: T) => Element | null | undefined,\n) {\n\tconst pairs = items.map((item, index) => [index, item] as const);\n\tlet isOrderDifferent = false;\n\tpairs.sort(([indexA, a], [indexB, b]) => {\n\t\tconst elementA = getElement(a);\n\t\tconst elementB = getElement(b);\n\t\tif (elementA === elementB) return 0;\n\t\tif (!elementA || !elementB) return 0;\n\t\t// a before b\n\t\tif (isElementPreceding(elementA, elementB)) {\n\t\t\tif (indexA > indexB) {\n\t\t\t\tisOrderDifferent = true;\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\t\t// a after b\n\t\tif (indexA < indexB) {\n\t\t\tisOrderDifferent = true;\n\t\t}\n\t\treturn 1;\n\t});\n\tif (isOrderDifferent) {\n\t\treturn pairs.map(([_, item]) => item);\n\t}\n\treturn items;\n}\n\nfunction isElementPreceding(a: Element, b: Element) {\n\treturn Boolean(\n\t\tb.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING,\n\t);\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { hasOwnProperty, isObject } from \"src/functions\";\nimport type { AnyFunction, AnyObject } from \"src/types\";\n\n/**\n * ============================================================================\n * STORE UTILITIES\n * ============================================================================\n *\n * Implementation taken from AriaKit (https://ariakit.org/)\n *\n * https://github.com/ariakit/ariakit/blob/295118174512ee27b81822f7f16d7cdf9d0d0be6/packages/ariakit-core/src/utils/misc.ts\n */\n/** */\n\n/**\n * Empty function.\n */\nexport function noop(..._: any[]): any {}\n\n/**\n * Checks whether `arg` is empty or not.\n * @example\n * isEmpty([]); // true\n * isEmpty([\"a\"]); // false\n * isEmpty({}); // true\n * isEmpty({ a: \"a\" }); // false\n * isEmpty(); // true\n * isEmpty(null); // true\n * isEmpty(undefined); // true\n * isEmpty(\"\"); // true\n */\nexport function isEmpty(arg: any): boolean {\n\tif (Array.isArray(arg)) return !arg.length;\n\tif (isObject(arg)) return !Object.keys(arg).length;\n\tif (arg == null) return true;\n\tif (arg === \"\") return true;\n\treturn false;\n}\n\n/**\n * Receives functions as arguments and returns a new function that calls all.\n */\nexport function chain<T>(...fns: T[]) {\n\treturn (...args: T extends AnyFunction ? Parameters<T> : never) => {\n\t\tfor (const fn of fns) {\n\t\t\tif (typeof fn === \"function\") {\n\t\t\t\tfn(...args);\n\t\t\t}\n\t\t}\n\t};\n}\n\n/**\n * Omits specific keys from an object.\n * @example\n * omit({ a: \"a\", b: \"b\" }, [\"a\"]); // { b: \"b\" }\n */\nexport function omit<T extends AnyObject, K extends keyof T>(\n\tobject: T,\n\tkeys: ReadonlyArray<K> | K[],\n) {\n\tconst result = { ...object } as Omit<T, K>;\n\tfor (const key of keys) {\n\t\tif (hasOwnProperty(result, key)) {\n\t\t\tdelete result[key];\n\t\t}\n\t}\n\treturn result;\n}\n\n/**\n * Picks specific keys from an object.\n * @example\n * pick({ a: \"a\", b: \"b\" }, [\"a\"]); // { a: \"a\" }\n */\nexport function pick<T extends AnyObject, K extends keyof T>(\n\tobject: T,\n\tpaths: ReadonlyArray<K> | K[],\n) {\n\tconst result = {} as Pick<T, K>;\n\tfor (const key of paths) {\n\t\tif (hasOwnProperty(object, key)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\treturn result;\n}\n\n/**\n * Similar to `Object.keys` but returns a type-safe array of keys.\n */\nexport function getKeys<T extends object>(obj: T) {\n\treturn Object.keys(obj) as Array<keyof T>;\n}\n\n/**\n * Checks whether something is disabled or not based on its props.\n */\nexport function disabledFromProps(props: {\n\tdisabled?: boolean;\n\t\"aria-disabled\"?: boolean | \"true\" | \"false\";\n}) {\n\treturn (\n\t\tprops.disabled ||\n\t\tprops[\"aria-disabled\"] === true ||\n\t\tprops[\"aria-disabled\"] === \"true\"\n\t);\n}\n","import { applyState, hasOwnProperty, invariant } from \"src/functions\";\nimport type { AnyObject, SetStateAction } from \"src/types\";\n\nimport { chain, getKeys, noop, omit as _omit, pick as _pick } from \"./utils\";\n\n/**\n * ============================================================================\n * STORE\n * ============================================================================\n *\n * Implementation taken from AriaKit (https://ariakit.org/)\n *\n * https://github.com/ariakit/ariakit/blob/295118174512ee27b81822f7f16d7cdf9d0d0be6/packages/ariakit-core/src/utils/store.ts\n */\n/** */\n\ntype Listener<S> = (state: S, prevState: S) => void | (() => void);\n\ntype Sync<S, K extends keyof S> = (\n\tkeys: K[] | null,\n\tlistener: Listener<Pick<S, K>>,\n) => () => void;\n\ntype StoreSetup = (callback: () => void | (() => void)) => () => void;\ntype StoreInit = () => () => void;\ntype StoreSubscribe<S = State, K extends keyof S = keyof S> = Sync<S, K>;\ntype StoreSync<S = State, K extends keyof S = keyof S> = Sync<S, K>;\ntype StoreBatch<S = State, K extends keyof S = keyof S> = Sync<S, K>;\ntype StorePick<\n\tS = State,\n\tK extends ReadonlyArray<keyof S> = ReadonlyArray<keyof S>,\n> = (keys: K) => Store<Pick<S, K[number]>>;\ntype StoreOmit<\n\tS = State,\n\tK extends ReadonlyArray<keyof S> = ReadonlyArray<keyof S>,\n> = (keys: K) => Store<Omit<S, K[number]>>;\n\ntype StoreInternals<S = State> = {\n\tsetup: StoreSetup;\n\tinit: StoreInit;\n\tsubscribe: StoreSubscribe<S>;\n\tsync: StoreSync<S>;\n\tbatch: StoreBatch<S>;\n\tpick: StorePick<S>;\n\tomit: StoreOmit<S>;\n};\n\nfunction getInternal<K extends keyof StoreInternals>(\n\tstore: Store & { __unstableInternals?: StoreInternals },\n\tkey: K,\n): StoreInternals[K] {\n\tconst internals = store.__unstableInternals;\n\tinvariant(internals, \"Invalid store\");\n\treturn internals[key];\n}\n\n/**\n * Creates a store.\n * @param initialState Initial state.\n * @param stores Stores to extend.\n */\nexport function createStore<S extends State>(\n\tinitialState: S,\n\t...stores: Array<Store<Partial<S>> | undefined>\n): Store<S> {\n\tlet state = initialState;\n\tlet prevStateBatch = state;\n\tlet lastUpdate = Symbol();\n\tlet destroy = noop;\n\tconst instances = new Set<symbol>();\n\tconst updatedKeys = new Set<keyof S>();\n\n\tconst setups = new Set<() => void | (() => void)>();\n\tconst listeners = new Set<Listener<S>>();\n\tconst batchListeners = new Set<Listener<S>>();\n\tconst disposables = new WeakMap<Listener<S>, void | (() => void)>();\n\tconst listenerKeys = new WeakMap<Listener<S>, Array<keyof S> | null>();\n\n\tconst storeSetup: StoreSetup = (callback) => {\n\t\tsetups.add(callback);\n\t\treturn () => setups.delete(callback);\n\t};\n\n\tconst storeInit: StoreInit = () => {\n\t\t// Make sure we only initialize the store once, even when it's passed to\n\t\t// other stores. However, the store can't be destroyed until all instances\n\t\t// are unmounted. See https://github.com/ariakit/ariakit/issues/3147. See\n\t\t// select-default-open-controlled tests.\n\t\tconst initialized = instances.size;\n\t\tconst instance = Symbol();\n\t\tinstances.add(instance);\n\n\t\tconst maybeDestroy = () => {\n\t\t\tinstances.delete(instance);\n\t\t\tif (instances.size) return;\n\t\t\tdestroy();\n\t\t};\n\n\t\tif (initialized) return maybeDestroy;\n\n\t\tconst desyncs = getKeys(state).map((key) =>\n\t\t\tchain(\n\t\t\t\t...stores.map((store) => {\n\t\t\t\t\tconst storeState = store?.getState?.();\n\t\t\t\t\tif (!storeState) return;\n\t\t\t\t\tif (!hasOwnProperty(storeState, key)) return;\n\t\t\t\t\treturn sync(store, [key], (state) => {\n\t\t\t\t\t\tsetState(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tstate[key]!,\n\t\t\t\t\t\t\t// @ts-expect-error - Not public API. This is just to prevent\n\t\t\t\t\t\t\t// infinite loops.\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\n\t\tconst teardowns: Array<void | (() => void)> = [];\n\t\tfor (const setup of setups) {\n\t\t\tteardowns.push(setup());\n\t\t}\n\n\t\tconst cleanups = stores.map(init);\n\n\t\tdestroy = chain(...desyncs, ...teardowns, ...cleanups);\n\n\t\treturn maybeDestroy;\n\t};\n\n\tconst sub = (\n\t\tkeys: Array<keyof S> | null,\n\t\tlistener: Listener<S>,\n\t\tset = listeners,\n\t) => {\n\t\tset.add(listener);\n\t\tlistenerKeys.set(listener, keys);\n\t\treturn () => {\n\t\t\tdisposables.get(listener)?.();\n\t\t\tdisposables.delete(listener);\n\t\t\tlistenerKeys.delete(listener);\n\t\t\tset.delete(listener);\n\t\t};\n\t};\n\n\tconst storeSubscribe: StoreSubscribe<S> = (keys, listener) =>\n\t\tsub(keys, listener);\n\n\tconst storeSync: StoreSync<S> = (keys, listener) => {\n\t\tdisposables.set(listener, listener(state, state));\n\t\treturn sub(keys, listener);\n\t};\n\n\tconst storeBatch: StoreBatch<S> = (keys, listener) => {\n\t\tdisposables.set(listener, listener(state, prevStateBatch));\n\t\treturn sub(keys, listener, batchListeners);\n\t};\n\n\tconst storePick: StorePick<S, ReadonlyArray<keyof S>> = (keys) =>\n\t\tcreateStore(_pick(state, keys), finalStore);\n\n\tconst storeOmit: StoreOmit<S, ReadonlyArray<keyof S>> = (keys) =>\n\t\tcreateStore(_omit(state, keys), finalStore);\n\n\tconst getState: Store<S>[\"getState\"] = () => state;\n\n\tconst setState: Store<S>[\"setState\"] = (key, value, fromStores = false) => {\n\t\tif (!hasOwnProperty(state, key)) return;\n\n\t\tconst nextValue = applyState(value, state[key]);\n\n\t\tif (nextValue === state[key]) return;\n\n\t\tif (!fromStores) {\n\t\t\tfor (const store of stores) {\n\t\t\t\tstore?.setState?.(key, nextValue);\n\t\t\t}\n\t\t}\n\n\t\tconst prevState = state;\n\t\tstate = { ...state, [key]: nextValue };\n\n\t\tconst thisUpdate = Symbol();\n\t\tlastUpdate = thisUpdate;\n\t\tupdatedKeys.add(key);\n\n\t\tconst run = (listener: Listener<S>, prev: S, uKeys?: Set<keyof S>) => {\n\t\t\tconst keys = listenerKeys.get(listener);\n\t\t\tconst updated = (k: keyof S) => (uKeys ? uKeys.has(k) : k === key);\n\t\t\tif (!keys || keys.some(updated)) {\n\t\t\t\tdisposables.get(listener)?.();\n\t\t\t\tdisposables.set(listener, listener(state, prev));\n\t\t\t}\n\t\t};\n\n\t\tfor (const listener of listeners) {\n\t\t\trun(listener, prevState);\n\t\t}\n\n\t\tqueueMicrotask(() => {\n\t\t\t// If setState is called again before this microtask runs, skip this\n\t\t\t// update. This is to prevent unnecessary updates when multiple keys are\n\t\t\t// updated in a single microtask.\n\t\t\tif (lastUpdate !== thisUpdate) return;\n\t\t\t// Take a snapshot of the state before running batch listeners. This is\n\t\t\t// necessary because batch listeners can setState.\n\t\t\tconst snapshot = state;\n\t\t\tfor (const listener of batchListeners) {\n\t\t\t\trun(listener, prevStateBatch, updatedKeys);\n\t\t\t}\n\t\t\tprevStateBatch = snapshot;\n\t\t\tupdatedKeys.clear();\n\t\t});\n\t};\n\n\tconst finalStore = {\n\t\tgetState,\n\t\tsetState,\n\t\t__unstableInternals: {\n\t\t\tsetup: storeSetup,\n\t\t\tinit: storeInit,\n\t\t\tsubscribe: storeSubscribe,\n\t\t\tsync: storeSync,\n\t\t\tbatch: storeBatch,\n\t\t\tpick: storePick,\n\t\t\tomit: storeOmit,\n\t\t},\n\t};\n\n\treturn finalStore;\n}\n\nexport function setup<T extends Store>(\n\tstore?: T | null,\n\t...args: Parameters<StoreSetup>\n): T extends Store ? ReturnType<StoreSetup> : void;\n\n/**\n * Register a callback function that's called when the store is initialized.\n */\nexport function setup(store?: Store, ...args: Parameters<StoreSetup>) {\n\tif (!store) return;\n\treturn getInternal(store, \"setup\")(...args);\n}\n\nexport function init<T extends Store>(\n\tstore?: T | null,\n\t...args: Parameters<StoreInit>\n): T extends Store ? ReturnType<StoreInit> : void;\n\n/**\n * Function that should be called when the store is initialized.\n */\nexport function init(store?: Store, ...args: Parameters<StoreInit>) {\n\tif (!store) return;\n\treturn getInternal(store, \"init\")(...args);\n}\n\nexport function subscribe<T extends Store, K extends keyof StoreState<T>>(\n\tstore?: T | null,\n\t...args: Parameters<StoreSubscribe<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreSubscribe<StoreState<T>, K>> : void;\n\n/**\n * Registers a listener function that's called after state changes in the store.\n */\nexport function subscribe(store?: Store, ...args: Parameters<StoreSubscribe>) {\n\tif (!store) return;\n\treturn getInternal(store, \"subscribe\")(...args);\n}\n\nexport function sync<T extends Store, K extends keyof StoreState<T>>(\n\tstore?: T | null,\n\t...args: Parameters<StoreSync<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreSync<StoreState<T>, K>> : void;\n\n/**\n * Registers a listener function that's called immediately and synchronously\n * whenever the store state changes.\n */\nexport function sync(store?: Store, ...args: Parameters<StoreSync>) {\n\tif (!store) return;\n\treturn getInternal(store, \"sync\")(...args);\n}\n\nexport function batch<T extends Store, K extends keyof StoreState<T>>(\n\tstore?: T | null,\n\t...args: Parameters<StoreBatch<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreBatch<StoreState<T>, K>> : void;\n\n/**\n * Registers a listener function that's called immediately and after a batch\n * of state changes in the store.\n */\nexport function batch(store?: Store, ...args: Parameters<StoreBatch>) {\n\tif (!store) return;\n\treturn getInternal(store, \"batch\")(...args);\n}\n\nexport function omit<\n\tT extends Store,\n\tK extends ReadonlyArray<keyof StoreState<T>>,\n>(\n\tstore?: T | null,\n\t...args: Parameters<StoreOmit<StoreState<T>, K>>\n): T extends Store ? ReturnType<StoreOmit<StoreState<T>, K>> : void;\n\n/**\n * Creates a new store with a subset of the current store state and keeps them\n * in sync.\n */\nexport function omit(store?: Store, ...args: Parameters<StoreOmit>) {\n\tif (!store) return;\n\treturn getInternal(store, \"omit\")(...args);\n}\n\nexport function pick<\n\tT extends Store,\n\tK extends ReadonlyArray<keyof StoreState<T>>,\n>(\n\tstore?: T | null,\n\t...args: Parameters<StorePick<StoreState<T>, K>>\n): T extends Store ? ReturnType<StorePick<StoreState<T>, K>> : void;\n\n/**\n * Creates a new store with a subset of the current store state and keeps them\n * in sync.\n */\nexport function pick(store: Store, ...args: Parameters<StorePick>) {\n\tif (!store) return;\n\treturn getInternal(store, \"pick\")(...args);\n}\n\n/**\n * Merges multiple stores into a single store.\n */\nexport function mergeStore<S extends State>(\n\t...stores: Array<Store<S> | undefined>\n): Store<S> {\n\tconst initialState = {} as S;\n\tfor (const store of stores) {\n\t\tconst nextState = store?.getState?.();\n\t\tif (nextState) {\n\t\t\tObject.assign(initialState, nextState);\n\t\t}\n\t}\n\tconst store = createStore(initialState, ...stores);\n\treturn Object.assign({}, ...stores, store);\n}\n\n/**\n * Throws when a store prop is passed in conjunction with a default state.\n */\nexport function throwOnConflictingProps(props: AnyObject, store?: Store) {\n\tif (process.env.NODE_ENV === \"production\") return;\n\tif (!store) return;\n\tconst defaultKeys = Object.entries(props)\n\t\t.filter(([key, value]) => key.startsWith(\"default\") && value !== undefined)\n\t\t.map(([key]) => {\n\t\t\tconst stateKey = key.replace(\"default\", \"\");\n\t\t\treturn `${stateKey[0]?.toLowerCase() || \"\"}${stateKey.slice(1)}`;\n\t\t});\n\tif (!defaultKeys.length) return;\n\tconst storeState = store.getState();\n\tconst conflictingProps = defaultKeys.filter((key) =>\n\t\thasOwnProperty(storeState, key),\n\t);\n\tif (!conflictingProps.length) return;\n\tthrow new Error(\n\t\t`Passing a store prop in conjunction with a default state is not supported.\n\nconst store = useSelectStore();\n<SelectProvider store={store} defaultValue=\"Apple\" />\n ^ ^\n\nInstead, pass the default state to the topmost store:\n\nconst store = useSelectStore({ defaultValue: \"Apple\" });\n<SelectProvider store={store} />\n`,\n\t);\n}\n\n/**\n * Store state type.\n */\nexport type State = AnyObject;\n\n/**\n * Initial state that can be passed to a store creator function.\n * @template S State type.\n * @template K Key type.\n */\nexport type StoreOptions<S extends State, K extends keyof S> = Partial<\n\tPick<S, K>\n>;\n\n/**\n * Props that can be passed to a store creator function.\n * @template S State type.\n */\nexport type StoreProps<S extends State = State> = {\n\t/**\n\t * Another store object that will be kept in sync with the original store.\n\t *\n\t * Live examples:\n\t * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)\n\t */\n\tstore?: Store<Partial<S>>;\n};\n\n/**\n * Extracts the state type from a store type.\n * @template T Store type.\n */\nexport type StoreState<T> = T extends Store<infer S> ? S : never;\n\n/**\n * Store.\n * @template S State type.\n */\nexport type Store<S = State> = {\n\t/**\n\t * Returns the current store state.\n\t */\n\tgetState(): S;\n\t/**\n\t * Sets a state value.\n\t */\n\tsetState<K extends keyof S>(key: K, value: SetStateAction<S[K]>): void;\n};\n","import { defaultValue } from \"../functions/default-value\";\nimport type { BivariantCallback } from \"../types/state\";\nimport { getDocument, sortBasedOnDOMPosition } from \"./dom\";\nimport type { Store, StoreOptions, StoreProps } from \"./store\";\nimport {\n\tbatch,\n\tcreateStore,\n\tinit,\n\tsetup,\n\tthrowOnConflictingProps,\n} from \"./store\";\nimport { chain } from \"./utils\";\n\nfunction getCommonParent(items: CollectionStoreItem[]) {\n\tconst firstItem = items.find((item) => !!item.element);\n\tconst lastItem = [...items].reverse().find((item) => !!item.element);\n\tlet parentElement = firstItem?.element?.parentElement;\n\twhile (parentElement && lastItem?.element) {\n\t\tconst parent = parentElement;\n\t\tif (lastItem && parent.contains(lastItem.element)) {\n\t\t\treturn parentElement;\n\t\t}\n\t\tparentElement = parentElement.parentElement;\n\t}\n\treturn getDocument(parentElement).body;\n}\n\nfunction getPrivateStore<T extends CollectionStoreItem>(\n\tstore?: Store & {\n\t\t__unstablePrivateStore?: Store<{\n\t\t\trenderedItems: T[];\n\t\t}>;\n\t},\n) {\n\treturn store?.__unstablePrivateStore;\n}\n\n/**\n * Creates a collection store.\n */\nexport function createCollectionStore<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n>(props: CollectionStoreProps<T> = {}): CollectionStore<T> {\n\tthrowOnConflictingProps(props, props.store);\n\n\tconst syncState = props.store?.getState();\n\n\tconst items = defaultValue(\n\t\tprops.items,\n\t\tsyncState?.items,\n\t\tprops.defaultItems,\n\t\t[],\n\t);\n\n\tconst itemsMap = new Map<string, T>(items.map((item) => [item.id, item]));\n\n\tconst initialState: CollectionStoreState<T> = {\n\t\titems,\n\t\trenderedItems: defaultValue(syncState?.renderedItems, []),\n\t};\n\n\tconst syncPrivateStore = getPrivateStore<T>(props.store);\n\n\tconst privateStore = createStore(\n\t\t{ items, renderedItems: initialState.renderedItems },\n\t\tsyncPrivateStore,\n\t);\n\n\tconst collection = createStore(initialState, props.store);\n\n\tconst sortItems = (renderedItems: T[]) => {\n\t\tconst sortedItems = sortBasedOnDOMPosition(renderedItems, (i) => i.element);\n\t\tprivateStore.setState(\"renderedItems\", sortedItems);\n\t\tcollection.setState(\"renderedItems\", sortedItems);\n\t};\n\n\tsetup(collection, () => init(privateStore));\n\n\t// Use the private store to register items and then batch the changes to the\n\t// public store so we don't trigger multiple updates on the store when adding\n\t// multiple items.\n\tsetup(privateStore, () => {\n\t\treturn batch(privateStore, [\"items\"], (state) => {\n\t\t\tcollection.setState(\"items\", state.items);\n\t\t});\n\t});\n\n\tsetup(privateStore, () => {\n\t\treturn batch(privateStore, [\"renderedItems\"], (state) => {\n\t\t\tlet firstRun = true;\n\n\t\t\tlet raf = requestAnimationFrame(() => {\n\t\t\t\tconst { renderedItems } = collection.getState();\n\t\t\t\t// Bail out if the rendered items haven't changed. This is important\n\t\t\t\t// because the following lines can cause this function to be called\n\t\t\t\t// again.\n\t\t\t\tif (state.renderedItems === renderedItems) return;\n\t\t\t\tsortItems(state.renderedItems);\n\t\t\t});\n\n\t\t\tif (typeof IntersectionObserver !== \"function\") {\n\t\t\t\treturn () => cancelAnimationFrame(raf);\n\t\t\t}\n\n\t\t\tconst ioCallback: IntersectionObserverCallback = () => {\n\t\t\t\tif (firstRun) {\n\t\t\t\t\t// The IntersectionObserver callback is called synchronously the first\n\t\t\t\t\t// time. We just ignore it.\n\t\t\t\t\tfirstRun = false;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcancelAnimationFrame(raf);\n\t\t\t\traf = requestAnimationFrame(() => sortItems(state.renderedItems));\n\t\t\t};\n\n\t\t\tconst root = getCommonParent(state.renderedItems);\n\t\t\tconst observer = new IntersectionObserver(ioCallback, { root });\n\n\t\t\tfor (const item of state.renderedItems) {\n\t\t\t\tif (!item.element) continue;\n\t\t\t\tobserver.observe(item.element);\n\t\t\t}\n\n\t\t\treturn () => {\n\t\t\t\tcancelAnimationFrame(raf);\n\t\t\t\tobserver.disconnect();\n\t\t\t};\n\t\t});\n\t});\n\n\tconst mergeItem = (\n\t\titem: T,\n\t\tsetItems: (getItems: (items: T[]) => T[]) => void,\n\t\tcanDeleteFromMap = false,\n\t) => {\n\t\tlet prevItem: T | undefined;\n\t\tsetItems((items) => {\n\t\t\tconst index = items.findIndex(({ id }) => id === item.id);\n\t\t\tconst nextItems = items.slice();\n\t\t\tif (index !== -1) {\n\t\t\t\tprevItem = items[index];\n\t\t\t\tconst nextItem = { ...prevItem, ...item };\n\t\t\t\tnextItems[index] = nextItem;\n\t\t\t\titemsMap.set(item.id, nextItem);\n\t\t\t} else {\n\t\t\t\tnextItems.push(item);\n\t\t\t\titemsMap.set(item.id, item);\n\t\t\t}\n\t\t\treturn nextItems;\n\t\t});\n\t\tconst unmergeItem = () => {\n\t\t\tsetItems((items) => {\n\t\t\t\tif (!prevItem) {\n\t\t\t\t\tif (canDeleteFromMap) {\n\t\t\t\t\t\titemsMap.delete(item.id);\n\t\t\t\t\t}\n\t\t\t\t\treturn items.filter(({ id }) => id !== item.id);\n\t\t\t\t}\n\t\t\t\tconst index = items.findIndex(({ id }) => id === item.id);\n\t\t\t\tif (index === -1) return items;\n\t\t\t\tconst nextItems = items.slice();\n\t\t\t\tnextItems[index] = prevItem;\n\t\t\t\titemsMap.set(item.id, prevItem);\n\t\t\t\treturn nextItems;\n\t\t\t});\n\t\t};\n\t\treturn unmergeItem;\n\t};\n\n\tconst registerItem: CollectionStore<T>[\"registerItem\"] = (item) =>\n\t\tmergeItem(\n\t\t\titem,\n\t\t\t(getItems) => privateStore.setState(\"items\", getItems),\n\t\t\ttrue,\n\t\t);\n\n\treturn {\n\t\t...collection,\n\n\t\tregisterItem,\n\t\trenderItem: (item) =>\n\t\t\tchain(\n\t\t\t\tregisterItem(item),\n\t\t\t\tmergeItem(item, (getItems) =>\n\t\t\t\t\tprivateStore.setState(\"renderedItems\", getItems),\n\t\t\t\t),\n\t\t\t),\n\n\t\titem: (id) => {\n\t\t\tif (!id) return null;\n\t\t\tlet item = itemsMap.get(id);\n\t\t\tif (!item) {\n\t\t\t\tconst { items } = privateStore.getState();\n\t\t\t\titem = items.find((item) => item.id === id);\n\t\t\t\tif (item) {\n\t\t\t\t\titemsMap.set(id, item);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn item || null;\n\t\t},\n\n\t\t// @ts-expect-error Internal\n\t\t__unstablePrivateStore: privateStore,\n\t};\n}\n\nexport type CollectionStoreItem = {\n\t/**\n\t * The id of the item.\n\t */\n\tid: string;\n\t/**\n\t * The item HTML element. This is automatically set when the item is rendered.\n\t */\n\telement?: HTMLElement | null;\n};\n\nexport type CollectionStoreState<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n> = {\n\t/**\n\t * Lists all items along with their metadata. This state is automatically\n\t * updated when an item is registered or unregistered using the\n\t * [`registerItem`](https://ariakit.org/reference/use-collection-store#registeritem)\n\t * function.\n\t *\n\t * Live examples:\n\t * - [Command Menu with\n\t * Tabs](https://ariakit.org/examples/dialog-combobox-tab-command-menu)\n\t */\n\titems: T[];\n\t/**\n\t * Lists all items, along with their metadata, in the exact order they appear in\n\t * the DOM. This state is automatically updated when an item is rendered or\n\t * unmounted using the\n\t * [`renderItem`](https://ariakit.org/reference/use-collection-store#renderitem)\n\t * function.\n\t */\n\trenderedItems: T[];\n};\n\nexport type CollectionStoreFunctions<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n> = {\n\t/**\n\t * Registers an item in the collection. This function returns a cleanup\n\t * function that unregisters the item.\n\t * @example\n\t * const unregisterItem = store.registerItem({ id: \"item-1\" });\n\t * // on cleanup\n\t * unregisterItem();\n\t */\n\tregisterItem: BivariantCallback<(item: T) => () => void>;\n\t/**\n\t * Renders an item in the collection. This function returns a cleanup function\n\t * that unmounts the item.\n\t * @example\n\t * const unrenderItem = store.renderItem({ id: \"item-1\" });\n\t * // on cleanup\n\t * unrenderItem();\n\t */\n\trenderItem: BivariantCallback<(item: T) => () => void>;\n\t/**\n\t * Gets an item by its id.\n\t *\n\t * Live examples:\n\t * - [Animated TabPanel](https://ariakit.org/examples/tab-panel-animated)\n\t * @example\n\t * const item = store.item(\"item-1\");\n\t */\n\titem: (id: string | null | undefined) => T | null;\n};\n\nexport type CollectionStoreOptions<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n> = {\n\t/**\n\t * The defaut value for the\n\t * [`items`](https://ariakit.org/reference/collection-provider#items) state.\n\t * @default []\n\t */\n\tdefaultItems?: CollectionStoreState<T>[\"items\"];\n} & StoreOptions<CollectionStoreState<T>, \"items\">;\n\nexport type CollectionStoreProps<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n> = {} & CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;\n\nexport type CollectionStore<\n\tT extends CollectionStoreItem = CollectionStoreItem,\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n> = {} & CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;\n","import { defaultValue } from \"../functions/default-value\";\nimport type { BivariantCallback } from \"../types/state\";\nimport type { Store, StoreOptions, StoreProps } from \"./store\";\nimport {\n\tbatch,\n\tcreateStore,\n\tinit,\n\tsetup,\n\tsubscribe,\n\tthrowOnConflictingProps,\n} from \"./store\";\n\nfunction getPrivateStore<\n\tStoreT extends Store,\n\tItemT extends StoreGroupStoreItem<StoreT>,\n>(\n\tstore?: Store & {\n\t\t__unstablePrivateStore?: Store<{\n\t\t\titems: ItemT[];\n\t\t}>;\n\t},\n) {\n\treturn store?.__unstablePrivateStore;\n}\n\n/**\n * Creates a grouped store.\n */\nexport function createStoreGroupStore<StoreT extends Store>(\n\tprops: StoreGroupStoreProps<StoreT> = {},\n): StoreGroupStore<StoreT> {\n\ttype ItemT = StoreGroupStoreItem<StoreT>;\n\ttype ItemStateT = StoreT extends Store<infer S> ? S : never;\n\n\tthrowOnConflictingProps(props, props.store);\n\n\tconst syncState = props.store?.getState();\n\n\tconst items = defaultValue(\n\t\tprops.items,\n\t\tsyncState?.items,\n\t\tprops.defaultItems,\n\t\t[],\n\t);\n\n\tconst itemsMap = new Map<string, ItemT>(items.map((item) => [item.id, item]));\n\n\tconst initialState: StoreGroupStoreState<StoreT, ItemT> = {\n\t\titems,\n\t\tstates: items.map((item) => item.store?.getState() as ItemStateT),\n\t};\n\n\tconst syncPrivateStore = getPrivateStore<StoreT, ItemT>(props.store);\n\n\tconst privateStore = createStore({ items }, syncPrivateStore);\n\n\tconst store = createStore(initialState, props.store);\n\n\tsetup(store, () => init(privateStore));\n\n\t// Use the private store to register items and then batch the changes to the\n\t// public store so we don't trigger multiple updates on the store when adding\n\t// multiple items.\n\tsetup(privateStore, () => {\n\t\treturn batch(privateStore, [\"items\"], (state) => {\n\t\t\tstore.setState(\"items\", state.items);\n\t\t\tstore.setState(\n\t\t\t\t\"states\",\n\t\t\t\tstate.items.map((item) => item.store?.getState() as ItemStateT),\n\t\t\t);\n\t\t});\n\t});\n\n\tconst mergeItem = (\n\t\titem: ItemT,\n\t\tsetItems: (getItems: (items: ItemT[]) => ItemT[]) => void,\n\t\tcanDeleteFromMap = false,\n\t) => {\n\t\tlet prevItem: ItemT | undefined;\n\t\tsetItems((items) => {\n\t\t\tconst index = items.findIndex(({ id }) => id === item.id);\n\t\t\tconst nextItems = items.slice();\n\t\t\tif (index !== -1) {\n\t\t\t\tprevItem = items[index];\n\t\t\t\tconst nextItem = { ...prevItem, ...item };\n\t\t\t\tnextItems[index] = nextItem;\n\t\t\t\titemsMap.set(item.id, nextItem);\n\t\t\t} else {\n\t\t\t\tnextItems.push(item);\n\t\t\t\titemsMap.set(item.id, item);\n\t\t\t}\n\t\t\treturn nextItems;\n\t\t});\n\t\tconst unmergeItem = () => {\n\t\t\tsetItems((items) => {\n\t\t\t\tif (!prevItem) {\n\t\t\t\t\tif (canDeleteFromMap) {\n\t\t\t\t\t\titemsMap.delete(item.id);\n\t\t\t\t\t}\n\t\t\t\t\treturn items.filter(({ id }) => id !== item.id);\n\t\t\t\t}\n\t\t\t\tconst index = items.findIndex(({ id }) => id === item.id);\n\t\t\t\tif (index === -1) return items;\n\t\t\t\tconst nextItems = items.slice();\n\t\t\t\tnextItems[index] = prevItem;\n\t\t\t\titemsMap.set(item.id, prevItem);\n\t\t\t\treturn nextItems;\n\t\t\t});\n\t\t};\n\t\treturn unmergeItem;\n\t};\n\n\tconst registerItem: StoreGroupStore<StoreT>[\"registerItem\"] = (item) => {\n\t\tconst unsubscribe = subscribe(item.store, null, () => {\n\t\t\tconst index = privateStore\n\t\t\t\t.getState()\n\t\t\t\t.items.findIndex((i) => i.id === item.id);\n\t\t\tif (index === -1) return;\n\n\t\t\tstore.setState(\"states\", (states) => {\n\t\t\t\tconst nextStates = states.slice();\n\t\t\t\tnextStates[index] = item.store?.getState() as ItemStateT;\n\t\t\t\treturn nextStates;\n\t\t\t});\n\t\t});\n\n\t\tconst cleanup = mergeItem(\n\t\t\titem,\n\t\t\t(getItems) => privateStore.setState(\"items\", getItems),\n\t\t\ttrue,\n\t\t);\n\n\t\treturn () => {\n\t\t\tunsubscribe();\n\t\t\tcleanup();\n\t\t};\n\t};\n\n\treturn {\n\t\t...store,\n\n\t\tregisterItem,\n\n\t\titem: (id) => {\n\t\t\tif (!id) return undefined;\n\t\t\tlet item = itemsMap.get(id);\n\t\t\tif (!item) {\n\t\t\t\tconst { items } = privateStore.getState();\n\t\t\t\titem = items.find((item) => item.id === id);\n\t\t\t\tif (item) {\n\t\t\t\t\titemsMap.set(id, item);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn item?.store || undefined;\n\t\t},\n\n\t\t// @ts-expect-error Internal\n\t\t__unstablePrivateStore: privateStore,\n\t};\n}\n\nexport type StoreGroupStoreItem<StoreT extends Store> = {\n\t/**\n\t * The id of the item.\n\t */\n\tid: string;\n\n\tstore?: StoreT;\n};\n\nexport type StoreGroupStoreState<\n\tStoreT extends Store,\n\tItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>,\n> = {\n\titems: ItemT[];\n\tstates: Array<StoreT extends Store<infer StateT> ? StateT : never>;\n};\n\nexport type StoreGroupStoreFunctions<\n\tStoreT extends Store,\n\tItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>,\n> = {\n\t/**\n\t * Registers an item in the collection. This function returns a cleanup\n\t * function that unregisters the item.\n\t *\n\t * Note: This method is usually called internally by components that expose a group provider.\n\t *\n\t * @example\n\t * const unregisterItem = store.registerItem({ id: \"item-1\", store: itemStore });\n\t * // on cleanup\n\t * unregisterItem();\n\t */\n\tregisterItem: BivariantCallback<(item: ItemT) => () => void>;\n\n\t/**\n\t * Gets an item's store by its id.\n\t *\n\t * @example\n\t * const itemStore = store.item(\"item-1\");\n\t */\n\titem: (id: string | null | undefined) => StoreT | undefined;\n};\n\nexport type StoreGroupStoreOptions<\n\tStoreT extends Store,\n\tItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>,\n> = {\n\t/**\n\t * The defaut value for the `items` state.\n\t * @default []\n\t */\n\tdefaultItems?: StoreGroupStoreState<StoreT, ItemT>[\"items\"];\n} & StoreOptions<StoreGroupStoreState<StoreT, ItemT>, \"items\">;\n\nexport type StoreGroupStoreProps<\n\tStoreT extends Store,\n\tItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>,\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n> = {} & StoreGroupStoreOptions<StoreT, ItemT> &\n\tStoreProps<StoreGroupStoreState<StoreT, ItemT>>;\n\nexport type StoreGroupStore<\n\tStoreT extends Store,\n\tItemT extends StoreGroupStoreItem<StoreT> = StoreGroupStoreItem<StoreT>,\n\t// eslint-disable-next-line @typescript-eslint/ban-types\n> = {} & StoreGroupStoreFunctions<StoreT, ItemT> &\n\tStore<StoreGroupStoreState<StoreT, ItemT>>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildinams/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Build in Amsterdam <development@buildinamsterdam.com> (https://www.buildinamsterdam.com/)",
|
|
6
6
|
"repository": {
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
27
|
},
|
|
28
|
+
"./navigation": {
|
|
29
|
+
"types": "./dist/navigation/index.d.ts",
|
|
30
|
+
"default": "./dist/navigation/index.js"
|
|
31
|
+
},
|
|
28
32
|
"./store": {
|
|
29
33
|
"types": "./dist/store/index.d.ts",
|
|
30
34
|
"default": "./dist/store/index.js"
|
|
@@ -35,6 +39,9 @@
|
|
|
35
39
|
"*": [
|
|
36
40
|
"./dist/index.d.ts"
|
|
37
41
|
],
|
|
42
|
+
"./navigation": [
|
|
43
|
+
"./dist/navigation/index.d.ts"
|
|
44
|
+
],
|
|
38
45
|
"./store": [
|
|
39
46
|
"./dist/store/index.d.ts"
|
|
40
47
|
]
|