@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,150 @@
|
|
|
1
|
+
import type { DialogStoreFunctions, DialogStoreOptions, DialogStoreState } from "../dialog/dialog-store.js";
|
|
2
|
+
import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
|
|
3
|
+
import type { SetState } from "../utils/types.js";
|
|
4
|
+
type BasePlacement = "top" | "bottom" | "left" | "right";
|
|
5
|
+
type Placement = BasePlacement | `${BasePlacement}-start` | `${BasePlacement}-end`;
|
|
6
|
+
type AnchorRect = {
|
|
7
|
+
x?: number;
|
|
8
|
+
y?: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates a popover store.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createPopoverStore({ getAnchorRect, renderCallback, popover: otherPopover, ...props }?: PopoverStoreProps): PopoverStore;
|
|
16
|
+
export interface PopoverStoreRenderCallbackProps extends Pick<PopoverStoreState, "anchorElement" | "popoverElement" | "arrowElement" | "mounted" | "placement" | "fixed" | "gutter" | "shift" | "overlap" | "flip" | "sameWidth" | "fitViewport" | "arrowPadding" | "overflowPadding"> {
|
|
17
|
+
/**
|
|
18
|
+
* A method that updates the `currentPlacement` state.
|
|
19
|
+
*/
|
|
20
|
+
setPlacement: SetState<Placement>;
|
|
21
|
+
/**
|
|
22
|
+
* The default render callback that will be called when the `renderCallback`
|
|
23
|
+
* prop is not provided.
|
|
24
|
+
*/
|
|
25
|
+
defaultRenderCallback: () => () => void;
|
|
26
|
+
}
|
|
27
|
+
export interface PopoverStoreState extends DialogStoreState {
|
|
28
|
+
/**
|
|
29
|
+
* The anchor element.
|
|
30
|
+
*/
|
|
31
|
+
anchorElement: HTMLElement | null;
|
|
32
|
+
/**
|
|
33
|
+
* The popover element that will render the placement attributes.
|
|
34
|
+
*/
|
|
35
|
+
popoverElement: HTMLElement | null;
|
|
36
|
+
/**
|
|
37
|
+
* The arrow element.
|
|
38
|
+
*/
|
|
39
|
+
arrowElement: HTMLElement | null;
|
|
40
|
+
/**
|
|
41
|
+
* The current temporary placement state of the popover. This may be different
|
|
42
|
+
* from the the `placement` state if the popover has needed to update its
|
|
43
|
+
* position on the fly.
|
|
44
|
+
*/
|
|
45
|
+
currentPlacement: Placement;
|
|
46
|
+
/**
|
|
47
|
+
* The placement of the popover.
|
|
48
|
+
* @default "bottom"
|
|
49
|
+
*/
|
|
50
|
+
placement: Placement;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the popover has `position: fixed` or not.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
fixed: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The distance between the popover and the anchor element. By default, it's 0
|
|
58
|
+
* plus half of the arrow offset, if it exists.
|
|
59
|
+
*/
|
|
60
|
+
gutter: number | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* The skidding of the popover along the anchor element.
|
|
63
|
+
* @default 0
|
|
64
|
+
*/
|
|
65
|
+
shift: number;
|
|
66
|
+
/**
|
|
67
|
+
* Controls the behavior of the popover when it overflows the viewport:
|
|
68
|
+
* - If a `boolean`, specifies whether the popover should flip to the
|
|
69
|
+
* opposite side when it overflows.
|
|
70
|
+
* - If a `string`, indicates the preferred fallback placements when it
|
|
71
|
+
* overflows. The placements must be spaced-delimited, e.g. "top left".
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
flip: boolean | string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the popover should slide when it overflows.
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
slide: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Whether the popover can overlap the anchor element when it overflows.
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
overlap: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Whether the popover should have the same width as the anchor element. This
|
|
87
|
+
* will be exposed to CSS as `--popover-anchor-width`.
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
sameWidth: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether the popover should fit the viewport. If this is set to true, the
|
|
93
|
+
* popover wrapper will have `maxWidth` and `maxHeight` set to the viewport
|
|
94
|
+
* size. This will be exposed to CSS as `--popover-available-width` and
|
|
95
|
+
* `--popover-available-height`.
|
|
96
|
+
* @default false
|
|
97
|
+
*/
|
|
98
|
+
fitViewport: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* The minimum padding between the arrow and the popover corner.
|
|
101
|
+
* @default 4
|
|
102
|
+
*/
|
|
103
|
+
arrowPadding: number;
|
|
104
|
+
/**
|
|
105
|
+
* The minimum padding between the popover and the viewport edge. This will be
|
|
106
|
+
* exposed to CSS as `--popover-overflow-padding`.
|
|
107
|
+
* @default 8
|
|
108
|
+
*/
|
|
109
|
+
overflowPadding: number;
|
|
110
|
+
}
|
|
111
|
+
export interface PopoverStoreFunctions extends DialogStoreFunctions {
|
|
112
|
+
/**
|
|
113
|
+
* Sets the anchor element.
|
|
114
|
+
*/
|
|
115
|
+
setAnchorElement: SetState<PopoverStoreState["anchorElement"]>;
|
|
116
|
+
/**
|
|
117
|
+
* Sets the popover element.
|
|
118
|
+
*/
|
|
119
|
+
setPopoverElement: SetState<PopoverStoreState["popoverElement"]>;
|
|
120
|
+
/**
|
|
121
|
+
* Sets the arrow element.
|
|
122
|
+
*/
|
|
123
|
+
setArrowElement: SetState<PopoverStoreState["arrowElement"]>;
|
|
124
|
+
/**
|
|
125
|
+
* Function that returns the anchor element's DOMRect. If this is explicitly
|
|
126
|
+
* passed, it will override the anchor `getBoundingClientRect` method.
|
|
127
|
+
* @param anchor The anchor element.
|
|
128
|
+
*/
|
|
129
|
+
getAnchorRect?: (anchor: HTMLElement | null) => AnchorRect | null;
|
|
130
|
+
/**
|
|
131
|
+
* A function that will be called when the popover needs to calculate its
|
|
132
|
+
* styles. It will override the internal behavior.
|
|
133
|
+
*/
|
|
134
|
+
renderCallback?: (props: PopoverStoreRenderCallbackProps) => void | (() => void);
|
|
135
|
+
/**
|
|
136
|
+
* A function that can be used to recompute the popover styles. This is useful
|
|
137
|
+
* when the popover anchor changes in a way that affects the popover position.
|
|
138
|
+
*/
|
|
139
|
+
render: () => void;
|
|
140
|
+
}
|
|
141
|
+
export interface PopoverStoreOptions extends StoreOptions<PopoverStoreState, "placement" | "fixed" | "gutter" | "shift" | "flip" | "slide" | "overlap" | "sameWidth" | "fitViewport" | "arrowPadding" | "overflowPadding">, Partial<Pick<PopoverStoreFunctions, "getAnchorRect" | "renderCallback">>, DialogStoreOptions {
|
|
142
|
+
/**
|
|
143
|
+
* A reference to another popover store that's controlling another popover to
|
|
144
|
+
* keep them in sync.
|
|
145
|
+
*/
|
|
146
|
+
popover?: PopoverStore;
|
|
147
|
+
}
|
|
148
|
+
export type PopoverStoreProps = PopoverStoreOptions & StoreProps<PopoverStoreState>;
|
|
149
|
+
export type PopoverStore = PopoverStoreFunctions & Store<PopoverStoreState>;
|
|
150
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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 _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
|
|
4
|
+
require('../__chunks/NX5OHIMM.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
|
|
11
|
+
require('../__chunks/OFNGELMA.cjs');
|
|
12
|
+
require('../__chunks/GDZQUFNP.cjs');
|
|
13
|
+
|
|
14
|
+
// src/radio/radio-store.ts
|
|
15
|
+
function createRadioStore({
|
|
16
|
+
...props
|
|
17
|
+
} = {}) {
|
|
18
|
+
const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
|
|
19
|
+
const composite = _AZVDLKO3cjs.createCompositeStore.call(void 0, {
|
|
20
|
+
...props,
|
|
21
|
+
focusLoop: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusLoop, _optionalChain([syncState, 'optionalAccess', _4 => _4.focusLoop]), true)
|
|
22
|
+
});
|
|
23
|
+
const initialState = {
|
|
24
|
+
...composite.getState(),
|
|
25
|
+
value: _5D5Y5EI4cjs.defaultValue.call(void 0, props.value, _optionalChain([syncState, 'optionalAccess', _5 => _5.value]), null)
|
|
26
|
+
};
|
|
27
|
+
const radio = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, composite, props.store);
|
|
28
|
+
return {
|
|
29
|
+
...composite,
|
|
30
|
+
...radio,
|
|
31
|
+
setValue: (value) => radio.setState("value", value)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exports.createRadioStore = createRadioStore;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
|
|
2
|
+
import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
|
|
3
|
+
import type { SetState } from "../utils/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a radio store.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createRadioStore({ ...props }?: RadioStoreProps): RadioStore;
|
|
8
|
+
export interface RadioStoreState extends CompositeStoreState {
|
|
9
|
+
/**
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
focusLoop: CompositeStoreState["focusLoop"];
|
|
13
|
+
/**
|
|
14
|
+
* The value of the radio group.
|
|
15
|
+
* @default null
|
|
16
|
+
*/
|
|
17
|
+
value: string | number | null;
|
|
18
|
+
}
|
|
19
|
+
export interface RadioStoreFunctions extends CompositeStoreFunctions {
|
|
20
|
+
/**
|
|
21
|
+
* Sets the `value` state.
|
|
22
|
+
* @example
|
|
23
|
+
* store.setValue("apple");
|
|
24
|
+
* store.setValue((value) => value === "apple" ? "orange" : "apple");
|
|
25
|
+
*/
|
|
26
|
+
setValue: SetState<RadioStoreState["value"]>;
|
|
27
|
+
}
|
|
28
|
+
export interface RadioStoreOptions extends StoreOptions<RadioStoreState, "focusLoop" | "value">, CompositeStoreOptions {
|
|
29
|
+
}
|
|
30
|
+
export type RadioStoreProps = RadioStoreOptions & StoreProps<RadioStoreState>;
|
|
31
|
+
export type RadioStore = RadioStoreFunctions & Store<RadioStoreState>;
|
|
@@ -0,0 +1,164 @@
|
|
|
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 _3KP2MDG6cjs = require('../__chunks/3KP2MDG6.cjs');
|
|
4
|
+
require('../__chunks/EFEGT32M.cjs');
|
|
5
|
+
require('../__chunks/7ZXWQTAY.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
|
|
9
|
+
require('../__chunks/NX5OHIMM.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
|
|
17
|
+
require('../__chunks/OFNGELMA.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _GDZQUFNPcjs = require('../__chunks/GDZQUFNP.cjs');
|
|
21
|
+
|
|
22
|
+
// src/select/select-store.ts
|
|
23
|
+
function createSelectStore({
|
|
24
|
+
combobox,
|
|
25
|
+
...props
|
|
26
|
+
} = {}) {
|
|
27
|
+
const store = _3BBA3Z5Gcjs.mergeStore.call(void 0,
|
|
28
|
+
props.store,
|
|
29
|
+
_optionalChain([combobox, 'optionalAccess', _ => _.omit, 'call', _2 => _2(
|
|
30
|
+
"value",
|
|
31
|
+
"items",
|
|
32
|
+
"renderedItems",
|
|
33
|
+
"baseElement",
|
|
34
|
+
"arrowElement",
|
|
35
|
+
"anchorElement",
|
|
36
|
+
"contentElement",
|
|
37
|
+
"popoverElement",
|
|
38
|
+
"disclosureElement"
|
|
39
|
+
)])
|
|
40
|
+
);
|
|
41
|
+
const syncState = store.getState();
|
|
42
|
+
const composite = _AZVDLKO3cjs.createCompositeStore.call(void 0, {
|
|
43
|
+
...props,
|
|
44
|
+
store,
|
|
45
|
+
virtualFocus: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
46
|
+
props.virtualFocus,
|
|
47
|
+
syncState.virtualFocus,
|
|
48
|
+
true
|
|
49
|
+
),
|
|
50
|
+
includesBaseElement: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
51
|
+
props.includesBaseElement,
|
|
52
|
+
syncState.includesBaseElement,
|
|
53
|
+
false
|
|
54
|
+
),
|
|
55
|
+
activeId: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
56
|
+
props.activeId,
|
|
57
|
+
syncState.activeId,
|
|
58
|
+
props.defaultActiveId,
|
|
59
|
+
null
|
|
60
|
+
),
|
|
61
|
+
orientation: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
62
|
+
props.orientation,
|
|
63
|
+
syncState.orientation,
|
|
64
|
+
"vertical"
|
|
65
|
+
)
|
|
66
|
+
});
|
|
67
|
+
const popover = _3KP2MDG6cjs.createPopoverStore.call(void 0, {
|
|
68
|
+
...props,
|
|
69
|
+
store,
|
|
70
|
+
placement: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
71
|
+
props.placement,
|
|
72
|
+
syncState.placement,
|
|
73
|
+
"bottom-start"
|
|
74
|
+
)
|
|
75
|
+
});
|
|
76
|
+
const initialValue = new String("");
|
|
77
|
+
const initialState = {
|
|
78
|
+
...composite.getState(),
|
|
79
|
+
...popover.getState(),
|
|
80
|
+
value: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
81
|
+
props.value,
|
|
82
|
+
syncState.value,
|
|
83
|
+
props.defaultValue,
|
|
84
|
+
initialValue
|
|
85
|
+
),
|
|
86
|
+
setValueOnMove: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
87
|
+
props.setValueOnMove,
|
|
88
|
+
syncState.setValueOnMove,
|
|
89
|
+
false
|
|
90
|
+
),
|
|
91
|
+
selectElement: _5D5Y5EI4cjs.defaultValue.call(void 0, syncState.selectElement, null),
|
|
92
|
+
labelElement: _5D5Y5EI4cjs.defaultValue.call(void 0, syncState.labelElement, null)
|
|
93
|
+
};
|
|
94
|
+
const select = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, composite, popover, store);
|
|
95
|
+
select.setup(
|
|
96
|
+
() => select.sync(
|
|
97
|
+
(state) => {
|
|
98
|
+
if (state.value !== initialValue)
|
|
99
|
+
return;
|
|
100
|
+
if (!state.items.length)
|
|
101
|
+
return;
|
|
102
|
+
const item = state.items.find(
|
|
103
|
+
(item2) => !item2.disabled && item2.value != null
|
|
104
|
+
);
|
|
105
|
+
if (_optionalChain([item, 'optionalAccess', _3 => _3.value]) == null)
|
|
106
|
+
return;
|
|
107
|
+
select.setState("value", item.value);
|
|
108
|
+
},
|
|
109
|
+
["value", "items"]
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
select.setup(
|
|
113
|
+
() => select.sync(
|
|
114
|
+
(state) => {
|
|
115
|
+
if (combobox)
|
|
116
|
+
return;
|
|
117
|
+
if (state.mounted)
|
|
118
|
+
return;
|
|
119
|
+
const values = _GDZQUFNPcjs.toArray.call(void 0, state.value);
|
|
120
|
+
const lastValue = values[values.length - 1];
|
|
121
|
+
if (lastValue == null)
|
|
122
|
+
return;
|
|
123
|
+
const item = state.items.find(
|
|
124
|
+
(item2) => !item2.disabled && item2.value === lastValue
|
|
125
|
+
);
|
|
126
|
+
if (!item)
|
|
127
|
+
return;
|
|
128
|
+
select.setState("activeId", item.id);
|
|
129
|
+
},
|
|
130
|
+
["mounted", "items", "value"]
|
|
131
|
+
)
|
|
132
|
+
);
|
|
133
|
+
select.setup(
|
|
134
|
+
() => select.syncBatch(
|
|
135
|
+
(state) => {
|
|
136
|
+
const { mounted, value, activeId } = select.getState();
|
|
137
|
+
if (!state.setValueOnMove && mounted)
|
|
138
|
+
return;
|
|
139
|
+
if (Array.isArray(value))
|
|
140
|
+
return;
|
|
141
|
+
if (!state.moves)
|
|
142
|
+
return;
|
|
143
|
+
if (!activeId)
|
|
144
|
+
return;
|
|
145
|
+
const item = composite.item(activeId);
|
|
146
|
+
if (!item || item.disabled || item.value == null)
|
|
147
|
+
return;
|
|
148
|
+
select.setState("value", item.value);
|
|
149
|
+
},
|
|
150
|
+
["setValueOnMove", "moves"]
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
return {
|
|
154
|
+
...composite,
|
|
155
|
+
...popover,
|
|
156
|
+
...select,
|
|
157
|
+
setValue: (value) => select.setState("value", value),
|
|
158
|
+
setSelectElement: (element) => select.setState("selectElement", element),
|
|
159
|
+
setLabelElement: (element) => select.setState("labelElement", element)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
exports.createSelectStore = createSelectStore;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ComboboxStore } from "../combobox/combobox-store.js";
|
|
2
|
+
import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
|
|
3
|
+
import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
|
|
4
|
+
import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
|
|
5
|
+
import type { PickRequired, SetState } from "../utils/types.js";
|
|
6
|
+
type Value = string | string[];
|
|
7
|
+
type MutableValue<T extends Value = Value> = T extends string ? string : T;
|
|
8
|
+
type Item = CompositeStoreItem & {
|
|
9
|
+
value?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function createSelectStore<T extends Value = Value>(props: PickRequired<SelectStoreProps<T>, "value" | "defaultValue">): SelectStore<T>;
|
|
12
|
+
export declare function createSelectStore(props?: SelectStoreProps): SelectStore;
|
|
13
|
+
export type SelectStoreItem = Item;
|
|
14
|
+
export type SelectStoreValue = Value;
|
|
15
|
+
export interface SelectStoreState<T extends Value = Value> extends CompositeStoreState<Item>, PopoverStoreState {
|
|
16
|
+
/**
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
virtualFocus: CompositeStoreState<Item>["virtualFocus"];
|
|
20
|
+
/**
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
includesBaseElement: CompositeStoreState<Item>["includesBaseElement"];
|
|
24
|
+
/**
|
|
25
|
+
* @default null
|
|
26
|
+
*/
|
|
27
|
+
activeId: CompositeStoreState<Item>["activeId"];
|
|
28
|
+
/**
|
|
29
|
+
* @default "vertical"
|
|
30
|
+
*/
|
|
31
|
+
orientation: CompositeStoreState<Item>["orientation"];
|
|
32
|
+
/**
|
|
33
|
+
* @default "bottom-start"
|
|
34
|
+
*/
|
|
35
|
+
placement: PopoverStoreState["placement"];
|
|
36
|
+
/**
|
|
37
|
+
* The select value.
|
|
38
|
+
*/
|
|
39
|
+
value: MutableValue<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the select value should be set when the active item changes by
|
|
42
|
+
* moving (which usually happens when moving to an item using the keyboard).
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
setValueOnMove: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The select button element.
|
|
48
|
+
*/
|
|
49
|
+
selectElement: HTMLElement | null;
|
|
50
|
+
/**
|
|
51
|
+
* The select label element.
|
|
52
|
+
*/
|
|
53
|
+
labelElement: HTMLElement | null;
|
|
54
|
+
}
|
|
55
|
+
export interface SelectStoreFunctions<T extends Value = Value> extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
|
|
56
|
+
/**
|
|
57
|
+
* Sets the `value` state.
|
|
58
|
+
* @example
|
|
59
|
+
* store.setValue("Apple");
|
|
60
|
+
* store.setValue(["Apple", "Banana"]);
|
|
61
|
+
* store.setValue((value) => value === "Apple" ? "Banana" : "Apple"));
|
|
62
|
+
*/
|
|
63
|
+
setValue: SetState<SelectStoreState<T>["value"]>;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the `selectElement` state.
|
|
66
|
+
*/
|
|
67
|
+
setSelectElement: SetState<SelectStoreState<T>["selectElement"]>;
|
|
68
|
+
/**
|
|
69
|
+
* Sets the `labelElement` state.
|
|
70
|
+
*/
|
|
71
|
+
setLabelElement: SetState<SelectStoreState<T>["labelElement"]>;
|
|
72
|
+
}
|
|
73
|
+
export interface SelectStoreOptions<T extends Value = Value> extends StoreOptions<SelectStoreState<T>, "virtualFocus" | "includesBaseElement" | "activeId" | "orientation" | "placement" | "value" | "setValueOnMove">, CompositeStoreOptions<Item>, PopoverStoreOptions {
|
|
74
|
+
/**
|
|
75
|
+
* A reference to a combobox store. This is used when combining the combobox
|
|
76
|
+
* with a select (e.g., select with a search input). The stores will share the
|
|
77
|
+
* same state.
|
|
78
|
+
*/
|
|
79
|
+
combobox?: ComboboxStore;
|
|
80
|
+
/**
|
|
81
|
+
* The default value. If not set, the first non-disabled item will be used.
|
|
82
|
+
*/
|
|
83
|
+
defaultValue?: SelectStoreState<T>["value"];
|
|
84
|
+
}
|
|
85
|
+
export type SelectStoreProps<T extends Value = Value> = SelectStoreOptions<T> & StoreProps<SelectStoreState<T>>;
|
|
86
|
+
export type SelectStore<T extends Value = Value> = SelectStoreFunctions<T> & Store<SelectStoreState<T>>;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
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 _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _NX5OHIMMcjs = require('../__chunks/NX5OHIMM.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
|
|
13
|
+
require('../__chunks/OFNGELMA.cjs');
|
|
14
|
+
require('../__chunks/GDZQUFNP.cjs');
|
|
15
|
+
|
|
16
|
+
// src/tab/tab-store.ts
|
|
17
|
+
function createTabStore(props = {}) {
|
|
18
|
+
const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
|
|
19
|
+
const composite = _AZVDLKO3cjs.createCompositeStore.call(void 0, {
|
|
20
|
+
...props,
|
|
21
|
+
orientation: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
22
|
+
props.orientation,
|
|
23
|
+
_optionalChain([syncState, 'optionalAccess', _4 => _4.orientation]),
|
|
24
|
+
"horizontal"
|
|
25
|
+
),
|
|
26
|
+
focusLoop: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusLoop, _optionalChain([syncState, 'optionalAccess', _5 => _5.focusLoop]), true)
|
|
27
|
+
});
|
|
28
|
+
const panels = _NX5OHIMMcjs.createCollectionStore.call(void 0, );
|
|
29
|
+
const initialState = {
|
|
30
|
+
...composite.getState(),
|
|
31
|
+
selectedId: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
32
|
+
props.selectedId,
|
|
33
|
+
_optionalChain([syncState, 'optionalAccess', _6 => _6.selectedId]),
|
|
34
|
+
props.defaultSelectedId,
|
|
35
|
+
void 0
|
|
36
|
+
),
|
|
37
|
+
selectOnMove: _5D5Y5EI4cjs.defaultValue.call(void 0,
|
|
38
|
+
props.selectOnMove,
|
|
39
|
+
_optionalChain([syncState, 'optionalAccess', _7 => _7.selectOnMove]),
|
|
40
|
+
true
|
|
41
|
+
)
|
|
42
|
+
};
|
|
43
|
+
const tab = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, composite, props.store);
|
|
44
|
+
tab.setup(
|
|
45
|
+
() => tab.sync(() => {
|
|
46
|
+
const { activeId, selectOnMove } = tab.getState();
|
|
47
|
+
if (!selectOnMove)
|
|
48
|
+
return;
|
|
49
|
+
if (!activeId)
|
|
50
|
+
return;
|
|
51
|
+
const tabItem = composite.item(activeId);
|
|
52
|
+
if (!tabItem)
|
|
53
|
+
return;
|
|
54
|
+
if (tabItem.dimmed)
|
|
55
|
+
return;
|
|
56
|
+
if (tabItem.disabled)
|
|
57
|
+
return;
|
|
58
|
+
tab.setState("selectedId", tabItem.id);
|
|
59
|
+
}, ["moves"])
|
|
60
|
+
);
|
|
61
|
+
tab.setup(
|
|
62
|
+
() => tab.sync(
|
|
63
|
+
(state) => tab.setState("activeId", state.selectedId),
|
|
64
|
+
["selectedId"]
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
tab.setup(
|
|
68
|
+
() => tab.sync(
|
|
69
|
+
(state) => {
|
|
70
|
+
if (state.selectedId !== void 0)
|
|
71
|
+
return;
|
|
72
|
+
const { activeId, renderedItems } = tab.getState();
|
|
73
|
+
const tabItem = composite.item(activeId);
|
|
74
|
+
if (tabItem && !tabItem.disabled && !tabItem.dimmed) {
|
|
75
|
+
tab.setState("selectedId", tabItem.id);
|
|
76
|
+
} else {
|
|
77
|
+
const tabItem2 = renderedItems.find(
|
|
78
|
+
(item) => !item.disabled && !item.dimmed
|
|
79
|
+
);
|
|
80
|
+
tab.setState("selectedId", _optionalChain([tabItem2, 'optionalAccess', _8 => _8.id]));
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
["selectedId", "renderedItems"]
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
tab.setup(
|
|
87
|
+
() => tab.sync(
|
|
88
|
+
(state) => {
|
|
89
|
+
const tabs = state.renderedItems;
|
|
90
|
+
if (!tabs.length)
|
|
91
|
+
return;
|
|
92
|
+
return panels.sync(
|
|
93
|
+
(state2) => {
|
|
94
|
+
const items = state2.renderedItems;
|
|
95
|
+
const hasOrphanPanels = items.some((panel) => !panel.tabId);
|
|
96
|
+
if (!hasOrphanPanels)
|
|
97
|
+
return;
|
|
98
|
+
items.forEach((panel, i) => {
|
|
99
|
+
if (panel.tabId)
|
|
100
|
+
return;
|
|
101
|
+
const tabItem = tabs[i];
|
|
102
|
+
if (!tabItem)
|
|
103
|
+
return;
|
|
104
|
+
panels.renderItem({ ...panel, tabId: tabItem.id });
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
["renderedItems"]
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
["renderedItems"]
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
return {
|
|
114
|
+
...composite,
|
|
115
|
+
...tab,
|
|
116
|
+
panels,
|
|
117
|
+
setSelectedId: (id) => tab.setState("selectedId", id),
|
|
118
|
+
select: (id) => {
|
|
119
|
+
tab.setState("selectedId", id);
|
|
120
|
+
composite.move(id);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
exports.createTabStore = createTabStore;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CollectionStore, CollectionStoreItem } from "../collection/collection-store.js";
|
|
2
|
+
import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
|
|
3
|
+
import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
|
|
4
|
+
import type { SetState } from "../utils/types.js";
|
|
5
|
+
type Item = CompositeStoreItem & {
|
|
6
|
+
dimmed?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type Panel = CollectionStoreItem & {
|
|
9
|
+
tabId?: string | null;
|
|
10
|
+
};
|
|
11
|
+
export declare function createTabStore(props?: TabStoreProps): TabStore;
|
|
12
|
+
export type TabStoreItem = Item;
|
|
13
|
+
export type TabStorePanel = Panel;
|
|
14
|
+
export interface TabStoreState extends CompositeStoreState<Item> {
|
|
15
|
+
/**
|
|
16
|
+
* @default "horizontal"
|
|
17
|
+
*/
|
|
18
|
+
orientation: CompositeStoreState<Item>["orientation"];
|
|
19
|
+
/**
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
focusLoop: CompositeStoreState<Item>["focusLoop"];
|
|
23
|
+
/**
|
|
24
|
+
* The id of the tab whose panel is currently visible. If it's `undefined`, it
|
|
25
|
+
* will be automatically set to the first enabled tab.
|
|
26
|
+
*/
|
|
27
|
+
selectedId: TabStoreState["activeId"];
|
|
28
|
+
/**
|
|
29
|
+
* Whether the tab should be selected when it receives focus. If it's set to
|
|
30
|
+
* `false`, the tab will be selected only when it's clicked.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
selectOnMove?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface TabStoreFunctions extends CompositeStoreFunctions<Item> {
|
|
36
|
+
/**
|
|
37
|
+
* Sets the `selectedId` state without moving focus. If you want to move focus,
|
|
38
|
+
* use the `select` function instead.
|
|
39
|
+
* @example
|
|
40
|
+
* // Selects the tab with id "tab-1"
|
|
41
|
+
* store.setSelectedId("tab-1");
|
|
42
|
+
* // Toggles between "tab-1" and "tab-2"
|
|
43
|
+
* store.setSelectedId((id) => id === "tab-1" ? "tab-2" : "tab-1"));
|
|
44
|
+
* // Selects the first tab
|
|
45
|
+
* store.setSelectedId(store.first());
|
|
46
|
+
* // Selects the next tab
|
|
47
|
+
* store.setSelectedId(store.next());
|
|
48
|
+
*/
|
|
49
|
+
setSelectedId: SetState<TabStoreState["selectedId"]>;
|
|
50
|
+
/**
|
|
51
|
+
* A collection store containing the tab panels.
|
|
52
|
+
*/
|
|
53
|
+
panels: CollectionStore<Panel>;
|
|
54
|
+
/**
|
|
55
|
+
* Selects the tab for the given id and moves focus to it. If you want to set
|
|
56
|
+
* the `selectedId` state without moving focus, use the `setSelectedId`
|
|
57
|
+
* function instead.
|
|
58
|
+
* @param id The id of the tab to select.
|
|
59
|
+
* @example
|
|
60
|
+
* // Selects the tab with id "tab-1"
|
|
61
|
+
* store.select("tab-1");
|
|
62
|
+
* // Selects the first tab
|
|
63
|
+
* store.select(store.first());
|
|
64
|
+
* // Selects the next tab
|
|
65
|
+
* store.select(store.next());
|
|
66
|
+
*/
|
|
67
|
+
select: TabStore["move"];
|
|
68
|
+
}
|
|
69
|
+
export interface TabStoreOptions extends StoreOptions<TabStoreState, "orientation" | "focusLoop" | "selectedId" | "selectOnMove">, CompositeStoreOptions<Item> {
|
|
70
|
+
/**
|
|
71
|
+
* The id of the tab whose panel is currently visible. If it's `undefined`, it
|
|
72
|
+
* will be automatically set to the first enabled tab.
|
|
73
|
+
*/
|
|
74
|
+
defaultSelectedId?: TabStoreState["selectedId"];
|
|
75
|
+
}
|
|
76
|
+
export type TabStoreProps = TabStoreOptions & StoreProps<TabStoreState>;
|
|
77
|
+
export type TabStore = TabStoreFunctions & Store<TabStoreState>;
|
|
78
|
+
export {};
|