soda-heroui 0.11.33 → 0.12.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/README.md +23 -23
- package/dist/components/EnumSelect.cjs +17 -4
- package/dist/components/EnumSelect.d.ts +10 -3
- package/dist/components/EnumSelect.js +13 -3
- package/dist/components/FormCalendar.d.ts +0 -1
- package/dist/components/FormDateInput.d.ts +0 -1
- package/dist/components/FormDateRangePicker.d.ts +0 -1
- package/dist/components/FormRangeCalendar.d.ts +0 -1
- package/package.json +4 -4
- package/src/components/EnumSelect.tsx +43 -5
- package/tsconfig.json +16 -16
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# soda-tanstack-form
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.com/package/soda-tanstack-form)
|
|
4
|
-
[](https://npmjs.com/package/soda-tanstack-form)
|
|
5
|
-
|
|
6
|
-
## Install
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
$ pnpm install
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
$ npm run dev
|
|
14
|
-
$ npm run build
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Options
|
|
18
|
-
|
|
19
|
-
TODO
|
|
20
|
-
|
|
21
|
-
## LICENSE
|
|
22
|
-
|
|
23
|
-
MIT
|
|
1
|
+
# soda-tanstack-form
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/soda-tanstack-form)
|
|
4
|
+
[](https://npmjs.com/package/soda-tanstack-form)
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
$ pnpm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
$ npm run dev
|
|
14
|
+
$ npm run build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
TODO
|
|
20
|
+
|
|
21
|
+
## LICENSE
|
|
22
|
+
|
|
23
|
+
MIT
|
|
@@ -26,20 +26,22 @@ var __webpack_exports__ = {};
|
|
|
26
26
|
__webpack_require__.r(__webpack_exports__);
|
|
27
27
|
__webpack_require__.d(__webpack_exports__, {
|
|
28
28
|
EnumSelect: ()=>EnumSelect,
|
|
29
|
-
createEnumSelect: ()=>createEnumSelect
|
|
29
|
+
createEnumSelect: ()=>createEnumSelect,
|
|
30
|
+
createFieldEnumSelect: ()=>createFieldEnumSelect
|
|
30
31
|
});
|
|
31
32
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
32
33
|
const external_react_namespaceObject = require("react");
|
|
33
34
|
const react_namespaceObject = require("@heroui/react");
|
|
34
35
|
const external_deepsea_tools_namespaceObject = require("deepsea-tools");
|
|
35
36
|
const external_soda_hooks_namespaceObject = require("soda-hooks");
|
|
37
|
+
const getFieldProps_cjs_namespaceObject = require("../utils/getFieldProps.cjs");
|
|
36
38
|
const external_FormProvider_cjs_namespaceObject = require("./FormProvider.cjs");
|
|
37
39
|
function render({ label, value }) {
|
|
38
40
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_namespaceObject.SelectItem, {
|
|
39
41
|
children: label
|
|
40
42
|
}, value);
|
|
41
43
|
}
|
|
42
|
-
function EnumSelect({ enumObject, selectionMode, value: _value, onValueChange, emptyValue, ...rest }) {
|
|
44
|
+
function EnumSelect({ enumObject, selectionMode, value: _value, onValueChange, emptyValue, component: Select2 = react_namespaceObject.Select, ...rest }) {
|
|
43
45
|
const context = (0, external_react_namespaceObject.useContext)(external_FormProvider_cjs_namespaceObject.FormContext);
|
|
44
46
|
emptyValue ??= context.emptyValue;
|
|
45
47
|
const [value, setValue] = (0, external_soda_hooks_namespaceObject.useInputState)(_value);
|
|
@@ -67,7 +69,7 @@ function EnumSelect({ enumObject, selectionMode, value: _value, onValueChange, e
|
|
|
67
69
|
})) : enumObject ? (0, external_deepsea_tools_namespaceObject.getEnumOptions)(enumObject) : [], [
|
|
68
70
|
enumObject
|
|
69
71
|
]);
|
|
70
|
-
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(
|
|
72
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Select2, {
|
|
71
73
|
items: items,
|
|
72
74
|
selectionMode: selectionMode,
|
|
73
75
|
selectedKeys: isNumberEnum ? selectedKeys.map(String) : selectedKeys,
|
|
@@ -84,11 +86,22 @@ function createEnumSelect(enumObject) {
|
|
|
84
86
|
});
|
|
85
87
|
};
|
|
86
88
|
}
|
|
89
|
+
function createFieldEnumSelect(enumObject) {
|
|
90
|
+
return function({ field, ...rest }) {
|
|
91
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EnumSelect, {
|
|
92
|
+
enumObject: enumObject,
|
|
93
|
+
...(0, getFieldProps_cjs_namespaceObject.getFieldProps)(field),
|
|
94
|
+
...rest
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
87
98
|
exports.EnumSelect = __webpack_exports__.EnumSelect;
|
|
88
99
|
exports.createEnumSelect = __webpack_exports__.createEnumSelect;
|
|
100
|
+
exports.createFieldEnumSelect = __webpack_exports__.createFieldEnumSelect;
|
|
89
101
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
90
102
|
"EnumSelect",
|
|
91
|
-
"createEnumSelect"
|
|
103
|
+
"createEnumSelect",
|
|
104
|
+
"createFieldEnumSelect"
|
|
92
105
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
93
106
|
Object.defineProperty(exports, '__esModule', {
|
|
94
107
|
value: true
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ComponentProps, ReactNode } from "react";
|
|
2
|
-
import { Select } from "@heroui/react";
|
|
1
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Select, SelectProps } from "@heroui/react";
|
|
3
3
|
import { ValueOf } from "deepsea-tools";
|
|
4
|
+
import { Field } from "soda-tanstack-form";
|
|
4
5
|
import { EmptyValue, GetEmptyValue } from "./FormProvider";
|
|
5
6
|
import { SelectionMode } from "./FormSelect";
|
|
6
7
|
/** enumObject 的类型 */
|
|
@@ -20,9 +21,15 @@ export interface EnumSelectPropsBase<Options extends SelectOptions, Mode extends
|
|
|
20
21
|
value?: Value;
|
|
21
22
|
onValueChange?: (value: Value) => void;
|
|
22
23
|
emptyValue?: Empty;
|
|
24
|
+
component?: <T extends object>(props: SelectProps<T>) => ReactElement;
|
|
23
25
|
}
|
|
24
26
|
export interface EnumSelectProps<Options extends SelectOptions, Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null"> extends EnumSelectPropsBase<Options, Mode, DisallowEmptySelection, Empty> {
|
|
25
27
|
}
|
|
26
|
-
export declare function EnumSelect<Options extends SelectOptions, Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null">({ enumObject, selectionMode, value: _value, onValueChange, emptyValue, ...rest }: EnumSelectProps<Options, Mode, DisallowEmptySelection, Empty>): ReactNode;
|
|
28
|
+
export declare function EnumSelect<Options extends SelectOptions, Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null">({ enumObject, selectionMode, value: _value, onValueChange, emptyValue, component: Select2, ...rest }: EnumSelectProps<Options, Mode, DisallowEmptySelection, Empty>): ReactNode;
|
|
27
29
|
export declare function createEnumSelect<Options extends SelectOptions>(enumObject?: Options): EnumSelectComponent<EnumValue<Options>>;
|
|
28
30
|
export type EnumSelectComponent<Value extends string | number> = <Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null">(props: Omit<EnumSelectProps<[ReactNode, Value][], Mode, DisallowEmptySelection, Empty>, "enumObject">) => ReactNode;
|
|
31
|
+
export interface FieldEnumSelectProps<Options extends SelectOptions, Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null"> extends Omit<EnumSelectProps<Options, Mode, DisallowEmptySelection, Empty>, "enumObject"> {
|
|
32
|
+
field: Field<EnumValue<Options>>;
|
|
33
|
+
}
|
|
34
|
+
export type FieldEnumSelectComponent<Value extends string | number> = <Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null">(props: FieldEnumSelectProps<[ReactNode, Value][], Mode, DisallowEmptySelection, Empty>) => ReactNode;
|
|
35
|
+
export declare function createFieldEnumSelect<Options extends SelectOptions>(enumObject?: Options): FieldEnumSelectComponent<EnumValue<Options>>;
|
|
@@ -4,13 +4,14 @@ import { useCallback, useContext, useMemo } from "react";
|
|
|
4
4
|
import { Select, SelectItem } from "@heroui/react";
|
|
5
5
|
import { getEnumOptions, intParser, isNonNullable } from "deepsea-tools";
|
|
6
6
|
import { useInputState } from "soda-hooks";
|
|
7
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
8
|
import { FormContext, getEmptyValue } from "./FormProvider.js";
|
|
8
9
|
function render({ label, value }) {
|
|
9
10
|
return /*#__PURE__*/ jsx(SelectItem, {
|
|
10
11
|
children: label
|
|
11
12
|
}, value);
|
|
12
13
|
}
|
|
13
|
-
function EnumSelect({ enumObject, selectionMode, value: _value, onValueChange, emptyValue, ...rest }) {
|
|
14
|
+
function EnumSelect({ enumObject, selectionMode, value: _value, onValueChange, emptyValue, component: Select2 = Select, ...rest }) {
|
|
14
15
|
const context = useContext(FormContext);
|
|
15
16
|
emptyValue ??= context.emptyValue;
|
|
16
17
|
const [value, setValue] = useInputState(_value);
|
|
@@ -38,7 +39,7 @@ function EnumSelect({ enumObject, selectionMode, value: _value, onValueChange, e
|
|
|
38
39
|
})) : enumObject ? getEnumOptions(enumObject) : [], [
|
|
39
40
|
enumObject
|
|
40
41
|
]);
|
|
41
|
-
return /*#__PURE__*/ jsx(
|
|
42
|
+
return /*#__PURE__*/ jsx(Select2, {
|
|
42
43
|
items: items,
|
|
43
44
|
selectionMode: selectionMode,
|
|
44
45
|
selectedKeys: isNumberEnum ? selectedKeys.map(String) : selectedKeys,
|
|
@@ -55,4 +56,13 @@ function createEnumSelect(enumObject) {
|
|
|
55
56
|
});
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
+
function createFieldEnumSelect(enumObject) {
|
|
60
|
+
return function({ field, ...rest }) {
|
|
61
|
+
return /*#__PURE__*/ jsx(EnumSelect, {
|
|
62
|
+
enumObject: enumObject,
|
|
63
|
+
...getFieldProps(field),
|
|
64
|
+
...rest
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export { EnumSelect, createEnumSelect, createFieldEnumSelect };
|
|
@@ -14,4 +14,3 @@ export interface FormCalendarProps<ValueMode extends TimeValueMode = "date", Fie
|
|
|
14
14
|
component?: <T extends DateValue>(props: CalendarProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormCalendar<ValueMode extends TimeValueMode = "date", FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined>({ field, valueMode, emptyValue, dateMode, defaultTime, component: Calendar2, ...rest }: FormCalendarProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
-
ctNode;
|
|
@@ -14,4 +14,3 @@ export interface FormDateInputProps<ValueMode extends TimeValueMode = "date", Fi
|
|
|
14
14
|
component?: <T extends DateValue>(props: DateInputProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormDateInput<ValueMode extends TimeValueMode = "date", FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined>({ field, valueMode, emptyValue, dateMode, defaultTime, component: DateInput2, ...rest }: FormDateInputProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
-
ctNode;
|
|
@@ -14,4 +14,3 @@ export interface FormDateRangePickerProps<ValueMode extends TimeValueMode = "dat
|
|
|
14
14
|
component?: <T extends DateValue>(props: DateRangePickerProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormDateRangePicker<ValueMode extends TimeValueMode = "date", FieldValue extends [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined = [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined>({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: DateRangePicker2, ...rest }: FormDateRangePickerProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
-
ctNode;
|
|
@@ -14,4 +14,3 @@ export interface FormRangeCalendarProps<ValueMode extends TimeValueMode = "date"
|
|
|
14
14
|
component?: <T extends DateValue>(props: RangeCalendarProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormRangeCalendar<ValueMode extends TimeValueMode = "date", FieldValue extends [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined = [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined>({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: RangeCalendar2, ...rest }: FormRangeCalendarProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
-
ctNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soda-heroui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@internationalized/date": ">=3.10.0",
|
|
39
39
|
"@tanstack/react-form": "^1.27.1",
|
|
40
|
-
"deepsea-tools": "5.
|
|
40
|
+
"deepsea-tools": "5.46.0",
|
|
41
41
|
"soda-tanstack-form": "0.3.6",
|
|
42
|
-
"soda-
|
|
43
|
-
"soda-
|
|
42
|
+
"soda-type": "6.7.4",
|
|
43
|
+
"soda-hooks": "6.16.9"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@react-types/shared": "^3.32.1",
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { ComponentProps, ReactNode, useCallback, useContext, useMemo } from "react"
|
|
3
|
+
import { ComponentProps, ReactElement, ReactNode, useCallback, useContext, useMemo } from "react"
|
|
4
4
|
|
|
5
|
-
import { Select, SelectItem, SharedSelection } from "@heroui/react"
|
|
5
|
+
import { Select, SelectItem, SelectProps, SharedSelection } from "@heroui/react"
|
|
6
6
|
import { getEnumOptions, intParser, isNonNullable, ValueOf } from "deepsea-tools"
|
|
7
7
|
import { useInputState } from "soda-hooks"
|
|
8
|
+
import { Field } from "soda-tanstack-form"
|
|
9
|
+
|
|
10
|
+
import { getFieldProps } from "@/utils/getFieldProps"
|
|
8
11
|
|
|
9
12
|
import { EmptyValue, FormContext, getEmptyValue, GetEmptyValue } from "./FormProvider"
|
|
10
13
|
import { SelectionMode } from "./FormSelect"
|
|
@@ -44,6 +47,7 @@ export interface EnumSelectPropsBase<
|
|
|
44
47
|
value?: Value
|
|
45
48
|
onValueChange?: (value: Value) => void
|
|
46
49
|
emptyValue?: Empty
|
|
50
|
+
component?: <T extends object>(props: SelectProps<T>) => ReactElement
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
export interface EnumSelectProps<
|
|
@@ -65,7 +69,15 @@ export function EnumSelect<
|
|
|
65
69
|
Mode extends SelectionMode = "single",
|
|
66
70
|
DisallowEmptySelection extends boolean = false,
|
|
67
71
|
Empty extends EmptyValue = "null",
|
|
68
|
-
>({
|
|
72
|
+
>({
|
|
73
|
+
enumObject,
|
|
74
|
+
selectionMode,
|
|
75
|
+
value: _value,
|
|
76
|
+
onValueChange,
|
|
77
|
+
emptyValue,
|
|
78
|
+
component: Select2 = Select,
|
|
79
|
+
...rest
|
|
80
|
+
}: EnumSelectProps<Options, Mode, DisallowEmptySelection, Empty>): ReactNode {
|
|
69
81
|
const context = useContext(FormContext)
|
|
70
82
|
emptyValue ??= context.emptyValue as Empty
|
|
71
83
|
|
|
@@ -96,7 +108,7 @@ export function EnumSelect<
|
|
|
96
108
|
)
|
|
97
109
|
|
|
98
110
|
return (
|
|
99
|
-
<
|
|
111
|
+
<Select2
|
|
100
112
|
items={items}
|
|
101
113
|
selectionMode={selectionMode}
|
|
102
114
|
selectedKeys={isNumberEnum ? selectedKeys.map(String) : selectedKeys}
|
|
@@ -104,7 +116,7 @@ export function EnumSelect<
|
|
|
104
116
|
{...rest}
|
|
105
117
|
>
|
|
106
118
|
{render}
|
|
107
|
-
</
|
|
119
|
+
</Select2>
|
|
108
120
|
)
|
|
109
121
|
}
|
|
110
122
|
|
|
@@ -123,3 +135,29 @@ export type EnumSelectComponent<Value extends string | number> = <
|
|
|
123
135
|
>(
|
|
124
136
|
props: Omit<EnumSelectProps<[ReactNode, Value][], Mode, DisallowEmptySelection, Empty>, "enumObject">,
|
|
125
137
|
) => ReactNode
|
|
138
|
+
|
|
139
|
+
export interface FieldEnumSelectProps<
|
|
140
|
+
Options extends SelectOptions,
|
|
141
|
+
Mode extends SelectionMode = "single",
|
|
142
|
+
DisallowEmptySelection extends boolean = false,
|
|
143
|
+
Empty extends EmptyValue = "null",
|
|
144
|
+
> extends Omit<EnumSelectProps<Options, Mode, DisallowEmptySelection, Empty>, "enumObject"> {
|
|
145
|
+
field: Field<EnumValue<Options>>
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type FieldEnumSelectComponent<Value extends string | number> = <
|
|
149
|
+
Mode extends SelectionMode = "single",
|
|
150
|
+
DisallowEmptySelection extends boolean = false,
|
|
151
|
+
Empty extends EmptyValue = "null",
|
|
152
|
+
>(
|
|
153
|
+
props: FieldEnumSelectProps<[ReactNode, Value][], Mode, DisallowEmptySelection, Empty>,
|
|
154
|
+
) => ReactNode
|
|
155
|
+
|
|
156
|
+
export function createFieldEnumSelect<Options extends SelectOptions>(enumObject?: Options): FieldEnumSelectComponent<EnumValue<Options>> {
|
|
157
|
+
return function EnumSelect2<Mode extends SelectionMode = "single", DisallowEmptySelection extends boolean = false, Empty extends EmptyValue = "null">({
|
|
158
|
+
field,
|
|
159
|
+
...rest
|
|
160
|
+
}: FieldEnumSelectProps<Options, Mode, DisallowEmptySelection, Empty>): ReactNode {
|
|
161
|
+
return <EnumSelect<Options, Mode, DisallowEmptySelection, Empty> enumObject={enumObject} {...getFieldProps(field)} {...rest} />
|
|
162
|
+
} as unknown as FieldEnumSelectComponent<EnumValue<Options>>
|
|
163
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
4
|
-
"strict": true,
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"jsx": "react-jsx",
|
|
8
|
-
"target": "ESNext",
|
|
9
|
-
"module": "ESNext",
|
|
10
|
-
"moduleResolution": "Bundler",
|
|
11
|
-
"paths": {
|
|
12
|
-
"@/*": ["src/*"]
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"]
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"strict": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"target": "ESNext",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "Bundler",
|
|
11
|
+
"paths": {
|
|
12
|
+
"@/*": ["src/*"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"]
|
|
16
|
+
}
|