@sprawlify/solid 0.0.13 → 0.0.15
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/chunk-C4aQI7lE.jsx +18 -0
- package/dist/chunk-CKcAJnC7.js +18 -0
- package/dist/collapsible-Cg7zPadX.js +129 -0
- package/dist/collapsible-CjuC6xYl.jsx +117 -0
- package/dist/collection-BiyRTWsX.js +219 -0
- package/dist/collection-BlnS2UQy.jsx +219 -0
- package/dist/components/accordion/index.d.ts +69 -0
- package/dist/components/accordion/index.js +183 -0
- package/dist/components/accordion/index.jsx +157 -0
- package/dist/components/angle-slider/index.d.ts +74 -0
- package/dist/components/angle-slider/index.js +155 -0
- package/dist/components/angle-slider/index.jsx +144 -0
- package/dist/components/avatar/index.d.ts +49 -0
- package/dist/components/avatar/index.js +95 -0
- package/dist/components/avatar/index.jsx +88 -0
- package/dist/components/bottom-sheet/index.d.ts +80 -0
- package/dist/components/bottom-sheet/index.js +218 -0
- package/dist/components/bottom-sheet/index.jsx +177 -0
- package/dist/components/carousel/index.d.ts +98 -0
- package/dist/components/carousel/index.js +207 -0
- package/dist/components/carousel/index.jsx +192 -0
- package/dist/components/checkbox/index.d.ts +138 -0
- package/dist/components/checkbox/index.js +265 -0
- package/dist/components/checkbox/index.jsx +247 -0
- package/dist/components/client-only/index.d.ts +10 -0
- package/dist/components/client-only/index.js +24 -0
- package/dist/components/client-only/index.jsx +15 -0
- package/dist/components/clipboard/index.d.ts +72 -0
- package/dist/components/clipboard/index.js +149 -0
- package/dist/components/clipboard/index.jsx +132 -0
- package/dist/components/collapsible/index.d.ts +60 -0
- package/dist/components/collapsible/index.js +8 -0
- package/dist/components/collapsible/index.jsx +8 -0
- package/dist/components/collection/index.d.ts +3 -0
- package/dist/components/collection/index.js +4 -0
- package/dist/components/collection/index.jsx +4 -0
- package/dist/components/field/index.d.ts +201 -0
- package/dist/components/field/index.js +9 -0
- package/dist/components/field/index.jsx +9 -0
- package/dist/components/fieldset/index.d.ts +109 -0
- package/dist/components/fieldset/index.js +8 -0
- package/dist/components/fieldset/index.jsx +8 -0
- package/dist/components/presence/index.d.ts +5 -0
- package/dist/components/presence/index.js +8 -0
- package/dist/components/presence/index.jsx +8 -0
- package/dist/components/select/index.d.ts +134 -0
- package/dist/components/select/index.js +361 -0
- package/dist/components/select/index.jsx +310 -0
- package/dist/compose-refs-CzyOb8yH.jsx +20 -0
- package/dist/compose-refs-vsrTrt13.js +20 -0
- package/dist/create-context-PS2j4mEo.js +29 -0
- package/dist/create-context-h3cXiEld.jsx +29 -0
- package/dist/create-split-props-CQVsvhvg.jsx +41 -0
- package/dist/factory-B6RK6SH4.d.ts +14 -0
- package/dist/factory-CEdj72aS.js +47 -0
- package/dist/field-C_WuoXOj.js +287 -0
- package/dist/field-CphvciGc.jsx +259 -0
- package/dist/fieldset-BG-0ZqWT.jsx +167 -0
- package/dist/fieldset-D1BO0LmU.js +182 -0
- package/dist/index-B0YoIRC4.d.ts +14 -0
- package/dist/index-C3ATynHc.d.ts +23 -0
- package/dist/index-DXheKbqg.d.ts +76 -0
- package/dist/index-NWiNyxpL.d.ts +38 -0
- package/dist/index-vSwYtc2L.d.ts +38 -0
- package/dist/index.d.ts +40 -19
- package/dist/index.js +5 -415
- package/dist/index.jsx +5 -415
- package/dist/presence-Bfjusgm3.js +79 -0
- package/dist/presence-arWh1hVd.jsx +66 -0
- package/dist/providers-CHqGPEsc.jsx +82 -0
- package/dist/providers-CQkAUunr.js +96 -0
- package/dist/render-strategy-COrlrUuR.js +12 -0
- package/dist/render-strategy-CZDG_yDi.jsx +12 -0
- package/dist/render-strategy-CtRkdWei.d.ts +9 -0
- package/dist/run-if-fn-DRWB51JE.jsx +421 -0
- package/dist/run-if-fn-eYlaegHy.js +421 -0
- package/dist/types-bQRbEioA.d.ts +9 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.jsx +4 -0
- package/dist/utils-DYer-9SY.js +0 -0
- package/dist/utils-DrvO4Hk3.jsx +0 -0
- package/package.json +62 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all, symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __export as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all, symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __export as t };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { t as __export } from "./chunk-CKcAJnC7.js";
|
|
2
|
+
import { a as useMachine, i as mergeProps$2, r as normalizeProps, t as runIfFn } from "./run-if-fn-eYlaegHy.js";
|
|
3
|
+
import { t as createContext$1 } from "./create-context-PS2j4mEo.js";
|
|
4
|
+
import { i as useLocaleContext, o as useEnvironmentContext } from "./providers-CQkAUunr.js";
|
|
5
|
+
import { n as createSplitProps, t as sprawlify } from "./factory-CEdj72aS.js";
|
|
6
|
+
import { n as splitRenderStrategyProps } from "./render-strategy-COrlrUuR.js";
|
|
7
|
+
import { Show, createEffect, createMemo, createSignal, createUniqueId } from "solid-js";
|
|
8
|
+
import { createComponent } from "solid-js/web";
|
|
9
|
+
import * as collapsible from "@sprawlify/primitives/machines/collapsible";
|
|
10
|
+
import { anatomy as collapsibleAnatomy } from "@sprawlify/primitives/machines/collapsible";
|
|
11
|
+
|
|
12
|
+
//#region src/components/collapsible/use-collapsible-context.ts
|
|
13
|
+
const [CollapsibleProvider, useCollapsibleContext] = createContext$1({
|
|
14
|
+
hookName: "useCollapsibleContext",
|
|
15
|
+
providerName: "<CollapsibleProvider />"
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/components/collapsible/collapsible-content.tsx
|
|
20
|
+
const CollapsibleContent = (props) => {
|
|
21
|
+
const api = useCollapsibleContext();
|
|
22
|
+
const mergedProps = mergeProps$2(() => api().getContentProps(), props);
|
|
23
|
+
return createComponent(Show, {
|
|
24
|
+
get when() {
|
|
25
|
+
return !api().unmounted;
|
|
26
|
+
},
|
|
27
|
+
get children() {
|
|
28
|
+
return createComponent(sprawlify.div, mergedProps);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/components/collapsible/collapsible-context.tsx
|
|
35
|
+
const CollapsibleContext = (props) => props.children(useCollapsibleContext());
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/components/collapsible/use-collapsible.ts
|
|
39
|
+
const useCollapsible = (props = {}) => {
|
|
40
|
+
const id = createUniqueId();
|
|
41
|
+
const locale = useLocaleContext();
|
|
42
|
+
const environment = useEnvironmentContext();
|
|
43
|
+
const [renderStrategyProps, collapsibleProps] = splitRenderStrategyProps(runIfFn(props));
|
|
44
|
+
const machineProps = createMemo(() => ({
|
|
45
|
+
id,
|
|
46
|
+
dir: locale().dir,
|
|
47
|
+
getRootNode: environment().getRootNode,
|
|
48
|
+
...collapsibleProps
|
|
49
|
+
}));
|
|
50
|
+
const service = useMachine(collapsible.machine, machineProps);
|
|
51
|
+
const [wasVisible, setWasVisible] = createSignal(false);
|
|
52
|
+
createEffect(() => {
|
|
53
|
+
if (api().visible) setWasVisible(true);
|
|
54
|
+
});
|
|
55
|
+
const api = createMemo(() => collapsible.connect(service, normalizeProps));
|
|
56
|
+
return createMemo(() => ({
|
|
57
|
+
...api(),
|
|
58
|
+
unmounted: !api().visible && !wasVisible() && renderStrategyProps.lazyMount || renderStrategyProps.unmountOnExit && !api().visible && wasVisible()
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/components/collapsible/collapsible-root.tsx
|
|
64
|
+
const CollapsibleRoot = (props) => {
|
|
65
|
+
const [useCollapsibleProps, localProps] = createSplitProps()(props, [
|
|
66
|
+
"collapsedHeight",
|
|
67
|
+
"collapsedWidth",
|
|
68
|
+
"defaultOpen",
|
|
69
|
+
"disabled",
|
|
70
|
+
"id",
|
|
71
|
+
"ids",
|
|
72
|
+
"lazyMount",
|
|
73
|
+
"onExitComplete",
|
|
74
|
+
"onOpenChange",
|
|
75
|
+
"open",
|
|
76
|
+
"unmountOnExit"
|
|
77
|
+
]);
|
|
78
|
+
const api = useCollapsible(useCollapsibleProps);
|
|
79
|
+
const mergedProps = mergeProps$2(() => api().getRootProps(), localProps);
|
|
80
|
+
return createComponent(CollapsibleProvider, {
|
|
81
|
+
value: api,
|
|
82
|
+
get children() {
|
|
83
|
+
return createComponent(sprawlify.div, mergedProps);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/components/collapsible/collapsible-root-provider.tsx
|
|
90
|
+
const CollapsibleRootProvider = (props) => {
|
|
91
|
+
const [{ value: collapsible$1 }, localProps] = createSplitProps()(props, ["value"]);
|
|
92
|
+
const mergedProps = mergeProps$2(() => collapsible$1().getRootProps(), localProps);
|
|
93
|
+
return createComponent(CollapsibleProvider, {
|
|
94
|
+
value: collapsible$1,
|
|
95
|
+
get children() {
|
|
96
|
+
return createComponent(sprawlify.div, mergedProps);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/components/collapsible/collapsible-trigger.tsx
|
|
103
|
+
const CollapsibleTrigger = (props) => {
|
|
104
|
+
const api = useCollapsibleContext();
|
|
105
|
+
const mergedProps = mergeProps$2(() => api().getTriggerProps(), props);
|
|
106
|
+
return createComponent(sprawlify.button, mergedProps);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/components/collapsible/collapsible-indicator.tsx
|
|
111
|
+
const CollapsibleIndicator = (props) => {
|
|
112
|
+
const collapsible$1 = useCollapsibleContext();
|
|
113
|
+
const mergedProps = mergeProps$2(() => collapsible$1().getIndicatorProps(), props);
|
|
114
|
+
return createComponent(sprawlify.div, mergedProps);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/components/collapsible/collapsible.ts
|
|
119
|
+
var collapsible_exports = /* @__PURE__ */ __export({
|
|
120
|
+
Content: () => CollapsibleContent,
|
|
121
|
+
Context: () => CollapsibleContext,
|
|
122
|
+
Indicator: () => CollapsibleIndicator,
|
|
123
|
+
Root: () => CollapsibleRoot,
|
|
124
|
+
RootProvider: () => CollapsibleRootProvider,
|
|
125
|
+
Trigger: () => CollapsibleTrigger
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
export { CollapsibleRootProvider as a, CollapsibleContext as c, CollapsibleTrigger as i, CollapsibleContent as l, collapsibleAnatomy as n, CollapsibleRoot as o, CollapsibleIndicator as r, useCollapsible as s, collapsible_exports as t, useCollapsibleContext as u };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { t as __export } from "./chunk-C4aQI7lE.jsx";
|
|
2
|
+
import { a as useMachine, i as mergeProps$1, r as normalizeProps, t as runIfFn } from "./run-if-fn-DRWB51JE.jsx";
|
|
3
|
+
import { t as createContext$1 } from "./create-context-h3cXiEld.jsx";
|
|
4
|
+
import { i as useLocaleContext, o as useEnvironmentContext } from "./providers-CHqGPEsc.jsx";
|
|
5
|
+
import { n as sprawlify, t as createSplitProps } from "./create-split-props-CQVsvhvg.jsx";
|
|
6
|
+
import { n as splitRenderStrategyProps } from "./render-strategy-CZDG_yDi.jsx";
|
|
7
|
+
import { Show, createEffect, createMemo, createSignal, createUniqueId } from "solid-js";
|
|
8
|
+
import * as collapsible from "@sprawlify/primitives/machines/collapsible";
|
|
9
|
+
import { anatomy as collapsibleAnatomy } from "@sprawlify/primitives/machines/collapsible";
|
|
10
|
+
|
|
11
|
+
//#region src/components/collapsible/use-collapsible-context.ts
|
|
12
|
+
const [CollapsibleProvider, useCollapsibleContext] = createContext$1({
|
|
13
|
+
hookName: "useCollapsibleContext",
|
|
14
|
+
providerName: "<CollapsibleProvider />"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/components/collapsible/collapsible-content.tsx
|
|
19
|
+
const CollapsibleContent = (props) => {
|
|
20
|
+
const api = useCollapsibleContext();
|
|
21
|
+
const mergedProps = mergeProps$1(() => api().getContentProps(), props);
|
|
22
|
+
return <Show when={!api().unmounted}>
|
|
23
|
+
<sprawlify.div {...mergedProps} />
|
|
24
|
+
</Show>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/components/collapsible/collapsible-context.tsx
|
|
29
|
+
const CollapsibleContext = (props) => props.children(useCollapsibleContext());
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/components/collapsible/use-collapsible.ts
|
|
33
|
+
const useCollapsible = (props = {}) => {
|
|
34
|
+
const id = createUniqueId();
|
|
35
|
+
const locale = useLocaleContext();
|
|
36
|
+
const environment = useEnvironmentContext();
|
|
37
|
+
const [renderStrategyProps, collapsibleProps] = splitRenderStrategyProps(runIfFn(props));
|
|
38
|
+
const machineProps = createMemo(() => ({
|
|
39
|
+
id,
|
|
40
|
+
dir: locale().dir,
|
|
41
|
+
getRootNode: environment().getRootNode,
|
|
42
|
+
...collapsibleProps
|
|
43
|
+
}));
|
|
44
|
+
const service = useMachine(collapsible.machine, machineProps);
|
|
45
|
+
const [wasVisible, setWasVisible] = createSignal(false);
|
|
46
|
+
createEffect(() => {
|
|
47
|
+
if (api().visible) setWasVisible(true);
|
|
48
|
+
});
|
|
49
|
+
const api = createMemo(() => collapsible.connect(service, normalizeProps));
|
|
50
|
+
return createMemo(() => ({
|
|
51
|
+
...api(),
|
|
52
|
+
unmounted: !api().visible && !wasVisible() && renderStrategyProps.lazyMount || renderStrategyProps.unmountOnExit && !api().visible && wasVisible()
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/components/collapsible/collapsible-root.tsx
|
|
58
|
+
const CollapsibleRoot = (props) => {
|
|
59
|
+
const [useCollapsibleProps, localProps] = createSplitProps()(props, [
|
|
60
|
+
"collapsedHeight",
|
|
61
|
+
"collapsedWidth",
|
|
62
|
+
"defaultOpen",
|
|
63
|
+
"disabled",
|
|
64
|
+
"id",
|
|
65
|
+
"ids",
|
|
66
|
+
"lazyMount",
|
|
67
|
+
"onExitComplete",
|
|
68
|
+
"onOpenChange",
|
|
69
|
+
"open",
|
|
70
|
+
"unmountOnExit"
|
|
71
|
+
]);
|
|
72
|
+
const api = useCollapsible(useCollapsibleProps);
|
|
73
|
+
const mergedProps = mergeProps$1(() => api().getRootProps(), localProps);
|
|
74
|
+
return <CollapsibleProvider value={api}>
|
|
75
|
+
<sprawlify.div {...mergedProps} />
|
|
76
|
+
</CollapsibleProvider>;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/components/collapsible/collapsible-root-provider.tsx
|
|
81
|
+
const CollapsibleRootProvider = (props) => {
|
|
82
|
+
const [{ value: collapsible$1 }, localProps] = createSplitProps()(props, ["value"]);
|
|
83
|
+
const mergedProps = mergeProps$1(() => collapsible$1().getRootProps(), localProps);
|
|
84
|
+
return <CollapsibleProvider value={collapsible$1}>
|
|
85
|
+
<sprawlify.div {...mergedProps} />
|
|
86
|
+
</CollapsibleProvider>;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/components/collapsible/collapsible-trigger.tsx
|
|
91
|
+
const CollapsibleTrigger = (props) => {
|
|
92
|
+
const api = useCollapsibleContext();
|
|
93
|
+
const mergedProps = mergeProps$1(() => api().getTriggerProps(), props);
|
|
94
|
+
return <sprawlify.button {...mergedProps} />;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/components/collapsible/collapsible-indicator.tsx
|
|
99
|
+
const CollapsibleIndicator = (props) => {
|
|
100
|
+
const collapsible$1 = useCollapsibleContext();
|
|
101
|
+
const mergedProps = mergeProps$1(() => collapsible$1().getIndicatorProps(), props);
|
|
102
|
+
return <sprawlify.div {...mergedProps} />;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/components/collapsible/collapsible.ts
|
|
107
|
+
var collapsible_exports = /* @__PURE__ */ __export({
|
|
108
|
+
Content: () => CollapsibleContent,
|
|
109
|
+
Context: () => CollapsibleContext,
|
|
110
|
+
Indicator: () => CollapsibleIndicator,
|
|
111
|
+
Root: () => CollapsibleRoot,
|
|
112
|
+
RootProvider: () => CollapsibleRootProvider,
|
|
113
|
+
Trigger: () => CollapsibleTrigger
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { CollapsibleRootProvider as a, CollapsibleContext as c, CollapsibleTrigger as i, CollapsibleContent as l, collapsibleAnatomy as n, CollapsibleRoot as o, CollapsibleIndicator as r, useCollapsible as s, collapsible_exports as t, useCollapsibleContext as u };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { a as useMachine, t as runIfFn } from "./run-if-fn-eYlaegHy.js";
|
|
2
|
+
import { createEffect, createMemo, createSignal, on, splitProps } from "solid-js";
|
|
3
|
+
import { GridCollection, ListCollection, Selection, TreeCollection, filePathToTree } from "@sprawlify/primitives/collection";
|
|
4
|
+
import * as asyncList from "@sprawlify/primitives/machines/async-list";
|
|
5
|
+
|
|
6
|
+
//#region src/components/collection/grid-collection.ts
|
|
7
|
+
const createGridCollection = (options) => new GridCollection(options);
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/components/collection/list-collection.ts
|
|
11
|
+
const createListCollection = (options) => new ListCollection(options);
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/components/collection/tree-collection.ts
|
|
15
|
+
const createTreeCollection = (options) => new TreeCollection(options);
|
|
16
|
+
const createFileTreeCollection = (paths) => filePathToTree(paths);
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/components/collection/use-async-list.ts
|
|
20
|
+
const useAsyncList = (props) => {
|
|
21
|
+
const machineProps = createMemo(() => runIfFn(props));
|
|
22
|
+
const service = useMachine(asyncList.machine, machineProps);
|
|
23
|
+
return createMemo(() => asyncList.connect(service));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/components/collection/use-list-collection.ts
|
|
28
|
+
function useListCollection(props) {
|
|
29
|
+
const splittedProps = createMemo(() => {
|
|
30
|
+
return splitProps(typeof props === "function" ? props() : props, [
|
|
31
|
+
"initialItems",
|
|
32
|
+
"filter",
|
|
33
|
+
"limit"
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
const init = () => {
|
|
37
|
+
const [localProps] = splittedProps();
|
|
38
|
+
return localProps.initialItems;
|
|
39
|
+
};
|
|
40
|
+
const [items, setItemsImpl] = createSignal(init());
|
|
41
|
+
const [filterText, setFilterText] = createSignal("");
|
|
42
|
+
const setItems = (newItems) => {
|
|
43
|
+
setItemsImpl(newItems);
|
|
44
|
+
setFilterText("");
|
|
45
|
+
};
|
|
46
|
+
const create = (itemsToCreate) => {
|
|
47
|
+
const [, collectionOptions] = splittedProps();
|
|
48
|
+
return createListCollection({
|
|
49
|
+
...collectionOptions,
|
|
50
|
+
items: itemsToCreate
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
collection: createMemo(() => {
|
|
55
|
+
const [localProps, collectionOptions] = splittedProps();
|
|
56
|
+
const filter = localProps.filter;
|
|
57
|
+
let activeItems = items();
|
|
58
|
+
if (filterText() && filter) activeItems = create(items()).filter((itemString, _index, item) => filter(itemString, filterText(), item)).items;
|
|
59
|
+
const limitedItems = localProps.limit == null ? activeItems : activeItems.slice(0, localProps.limit);
|
|
60
|
+
return createListCollection({
|
|
61
|
+
...collectionOptions,
|
|
62
|
+
items: limitedItems
|
|
63
|
+
});
|
|
64
|
+
}),
|
|
65
|
+
filter: (inputValue = "") => {
|
|
66
|
+
setFilterText(inputValue);
|
|
67
|
+
},
|
|
68
|
+
set: (newItems) => {
|
|
69
|
+
setItems(newItems);
|
|
70
|
+
},
|
|
71
|
+
reset: () => {
|
|
72
|
+
const [localProps] = splittedProps();
|
|
73
|
+
setItems(localProps.initialItems);
|
|
74
|
+
},
|
|
75
|
+
clear: () => {
|
|
76
|
+
setItems([]);
|
|
77
|
+
},
|
|
78
|
+
insert: (index, ...itemsToInsert) => {
|
|
79
|
+
const newItems = create(items()).insert(index, ...itemsToInsert).items;
|
|
80
|
+
setItems(newItems);
|
|
81
|
+
},
|
|
82
|
+
insertBefore: (value, ...itemsToInsert) => {
|
|
83
|
+
const newItems = create(items()).insertBefore(value, ...itemsToInsert).items;
|
|
84
|
+
setItems(newItems);
|
|
85
|
+
},
|
|
86
|
+
insertAfter: (value, ...itemsToInsert) => {
|
|
87
|
+
const newItems = create(items()).insertAfter(value, ...itemsToInsert).items;
|
|
88
|
+
setItems(newItems);
|
|
89
|
+
},
|
|
90
|
+
remove: (...itemOrValues) => {
|
|
91
|
+
const newItems = create(items()).remove(...itemOrValues).items;
|
|
92
|
+
setItems(newItems);
|
|
93
|
+
},
|
|
94
|
+
move: (value, to) => {
|
|
95
|
+
const newItems = create(items()).move(value, to).items;
|
|
96
|
+
setItems(newItems);
|
|
97
|
+
},
|
|
98
|
+
moveBefore: (value, ...values) => {
|
|
99
|
+
const newItems = create(items()).moveBefore(value, ...values).items;
|
|
100
|
+
setItems(newItems);
|
|
101
|
+
},
|
|
102
|
+
moveAfter: (value, ...values) => {
|
|
103
|
+
const newItems = create(items()).moveAfter(value, ...values).items;
|
|
104
|
+
setItems(newItems);
|
|
105
|
+
},
|
|
106
|
+
reorder: (from, to) => {
|
|
107
|
+
const newItems = create(items()).reorder(from, to).items;
|
|
108
|
+
setItems(newItems);
|
|
109
|
+
},
|
|
110
|
+
append: (...itemsToAppend) => {
|
|
111
|
+
const newItems = create(items()).append(...itemsToAppend).items;
|
|
112
|
+
setItems(newItems);
|
|
113
|
+
},
|
|
114
|
+
upsert: (value, item, mode = "append") => {
|
|
115
|
+
const newItems = create(items()).upsert(value, item, mode).items;
|
|
116
|
+
setItems(newItems);
|
|
117
|
+
},
|
|
118
|
+
prepend: (...itemsToPrepend) => {
|
|
119
|
+
const newItems = create(items()).prepend(...itemsToPrepend).items;
|
|
120
|
+
setItems(newItems);
|
|
121
|
+
},
|
|
122
|
+
update: (value, item) => {
|
|
123
|
+
const newItems = create(items()).update(value, item).items;
|
|
124
|
+
setItems(newItems);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/components/collection/use-list-selection.ts
|
|
131
|
+
function useListSelection(props) {
|
|
132
|
+
const splittedProps = createMemo(() => {
|
|
133
|
+
return splitProps(typeof props === "function" ? props() : props, [
|
|
134
|
+
"collection",
|
|
135
|
+
"selectionMode",
|
|
136
|
+
"deselectable",
|
|
137
|
+
"initialSelectedValues",
|
|
138
|
+
"resetOnCollectionChange"
|
|
139
|
+
]);
|
|
140
|
+
});
|
|
141
|
+
const createSelection = (values = []) => {
|
|
142
|
+
const [localProps] = splittedProps();
|
|
143
|
+
const selection$1 = new Selection(values);
|
|
144
|
+
selection$1.selectionMode = localProps.selectionMode ?? "single";
|
|
145
|
+
selection$1.deselectable = localProps.deselectable ?? true;
|
|
146
|
+
return selection$1;
|
|
147
|
+
};
|
|
148
|
+
const init = () => {
|
|
149
|
+
const [localProps] = splittedProps();
|
|
150
|
+
return createSelection(localProps.initialSelectedValues ?? []);
|
|
151
|
+
};
|
|
152
|
+
const [selection, setSelection] = createSignal(init());
|
|
153
|
+
const watchDeps = () => {
|
|
154
|
+
const [{ collection, resetOnCollectionChange }] = splittedProps();
|
|
155
|
+
return [collection.getValues(), resetOnCollectionChange];
|
|
156
|
+
};
|
|
157
|
+
createEffect(on(watchDeps, ([, resetOnCollectionChange]) => {
|
|
158
|
+
if (resetOnCollectionChange) setSelection(createSelection());
|
|
159
|
+
}, { defer: true }));
|
|
160
|
+
return {
|
|
161
|
+
selectedValues: createMemo(() => Array.from(selection())),
|
|
162
|
+
isEmpty: createMemo(() => selection().isEmpty()),
|
|
163
|
+
firstSelectedValue: createMemo(() => {
|
|
164
|
+
const [localProps] = splittedProps();
|
|
165
|
+
return selection().firstSelectedValue(localProps.collection);
|
|
166
|
+
}),
|
|
167
|
+
lastSelectedValue: createMemo(() => {
|
|
168
|
+
const [localProps] = splittedProps();
|
|
169
|
+
return selection().lastSelectedValue(localProps.collection);
|
|
170
|
+
}),
|
|
171
|
+
isSelected: (value) => {
|
|
172
|
+
return selection().isSelected(value);
|
|
173
|
+
},
|
|
174
|
+
isAllSelected: () => {
|
|
175
|
+
const [localProps] = splittedProps();
|
|
176
|
+
const allValues = localProps.collection.getValues();
|
|
177
|
+
return allValues.length > 0 && allValues.every((value) => selection().isSelected(value));
|
|
178
|
+
},
|
|
179
|
+
isSomeSelected: () => {
|
|
180
|
+
const [localProps] = splittedProps();
|
|
181
|
+
return localProps.collection.getValues().some((value) => selection().isSelected(value));
|
|
182
|
+
},
|
|
183
|
+
canSelect: (value) => {
|
|
184
|
+
const [localProps] = splittedProps();
|
|
185
|
+
return selection().canSelect(localProps.collection, value);
|
|
186
|
+
},
|
|
187
|
+
select: (value, forceToggle) => {
|
|
188
|
+
const [localProps] = splittedProps();
|
|
189
|
+
setSelection(selection().select(localProps.collection, value, forceToggle));
|
|
190
|
+
},
|
|
191
|
+
deselect: (value) => {
|
|
192
|
+
setSelection(selection().deselect(value));
|
|
193
|
+
},
|
|
194
|
+
toggle: (value) => {
|
|
195
|
+
const [localProps] = splittedProps();
|
|
196
|
+
setSelection(selection().toggleSelection(localProps.collection, value));
|
|
197
|
+
},
|
|
198
|
+
replace: (value) => {
|
|
199
|
+
const [localProps] = splittedProps();
|
|
200
|
+
setSelection(selection().replaceSelection(localProps.collection, value));
|
|
201
|
+
},
|
|
202
|
+
extend: (anchorValue, targetValue) => {
|
|
203
|
+
const [localProps] = splittedProps();
|
|
204
|
+
setSelection(selection().extendSelection(localProps.collection, anchorValue, targetValue));
|
|
205
|
+
},
|
|
206
|
+
setSelectedValues: (values) => {
|
|
207
|
+
setSelection(selection().setSelection(values));
|
|
208
|
+
},
|
|
209
|
+
clear: () => {
|
|
210
|
+
setSelection(selection().clearSelection());
|
|
211
|
+
},
|
|
212
|
+
resetSelection: () => {
|
|
213
|
+
setSelection(createSelection());
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
export { createTreeCollection as a, createFileTreeCollection as i, useListCollection as n, createListCollection as o, useAsyncList as r, createGridCollection as s, useListSelection as t };
|