soda-heroui 0.11.0 → 0.11.2
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/components/AutoRefresh.js +5 -5
- package/dist/components/EnumSelect.cjs +2 -2
- package/dist/components/EnumSelect.js +8 -8
- package/dist/components/ErrorMessage.js +5 -5
- package/dist/components/FormAutocomplete.js +6 -6
- package/dist/components/FormCalendar.js +12 -12
- package/dist/components/FormCheckbox.js +6 -6
- package/dist/components/FormCheckboxGroup.js +6 -6
- package/dist/components/FormDateInput.js +12 -12
- package/dist/components/FormDatePicker.js +12 -12
- package/dist/components/FormDateRangePicker.js +12 -12
- package/dist/components/FormInput.js +6 -6
- package/dist/components/FormInputOtp.js +6 -6
- package/dist/components/FormNumberInput.js +6 -6
- package/dist/components/FormPagination.js +6 -6
- package/dist/components/FormProvider.cjs +2 -2
- package/dist/components/FormProvider.js +7 -7
- package/dist/components/FormRadioGroup.js +6 -6
- package/dist/components/FormRangeCalendar.js +12 -12
- package/dist/components/FormSelect.cjs +10 -3
- package/dist/components/FormSelect.d.ts +4 -2
- package/dist/components/FormSelect.js +19 -12
- package/dist/components/FormSwitch.js +6 -6
- package/dist/components/FormTextarea.js +6 -6
- package/dist/components/FormTimeInput.js +12 -12
- package/dist/utils/addBetterToast.cjs +2 -2
- package/dist/utils/addBetterToast.js +6 -6
- package/dist/utils/getFieldProps.js +6 -6
- package/dist/utils/parseTime.cjs +3 -3
- package/dist/utils/parseTime.js +6 -12
- package/dist/utils/range.cjs +2 -2
- package/dist/utils/range.js +13 -13
- package/dist/utils/time.cjs +3 -3
- package/dist/utils/time.js +7 -7
- package/package.json +9 -9
- package/src/components/FormSelect.tsx +23 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button, addToast } from "@heroui/react";
|
|
3
|
+
import { useAutoRefresh } from "soda-hooks";
|
|
4
4
|
const AutoRefresh = ({ children, onRefresh, ...rest })=>{
|
|
5
5
|
if ("development" === process.env.NODE_ENV) return children;
|
|
6
6
|
function onPress(e) {
|
|
@@ -8,12 +8,12 @@ const AutoRefresh = ({ children, onRefresh, ...rest })=>{
|
|
|
8
8
|
closeButton?.click();
|
|
9
9
|
onRefresh?.();
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
useAutoRefresh(()=>addToast({
|
|
12
12
|
title: "\u68C0\u6D4B\u5230\u9875\u9762\u66F4\u65B0",
|
|
13
13
|
description: "\u4E3A\u4E86\u6700\u4F73\u7684\u4F53\u9A8C\uFF0C\u8BF7\u5237\u65B0\u9875\u9762",
|
|
14
14
|
color: "warning",
|
|
15
15
|
timeout: 1 / 0,
|
|
16
|
-
endContent: /*#__PURE__*/
|
|
16
|
+
endContent: /*#__PURE__*/ jsx(Button, {
|
|
17
17
|
color: "warning",
|
|
18
18
|
size: "sm",
|
|
19
19
|
variant: "flat",
|
|
@@ -25,8 +25,8 @@ var __webpack_require__ = {};
|
|
|
25
25
|
var __webpack_exports__ = {};
|
|
26
26
|
__webpack_require__.r(__webpack_exports__);
|
|
27
27
|
__webpack_require__.d(__webpack_exports__, {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
EnumSelect: ()=>EnumSelect,
|
|
29
|
+
createEnumSelect: ()=>createEnumSelect
|
|
30
30
|
});
|
|
31
31
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
32
32
|
const react_namespaceObject = require("@heroui/react");
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { SelectItem } from "@heroui/react";
|
|
4
|
+
import { getEnumOptions } from "deepsea-tools";
|
|
5
|
+
import { FormSelect as external_FormSelect_js_FormSelect } from "./FormSelect.js";
|
|
6
6
|
function EnumSelect({ enumObject, ...rest }) {
|
|
7
|
-
return /*#__PURE__*/
|
|
8
|
-
items:
|
|
7
|
+
return /*#__PURE__*/ jsx(external_FormSelect_js_FormSelect, {
|
|
8
|
+
items: getEnumOptions(enumObject),
|
|
9
9
|
...rest,
|
|
10
|
-
children: ({ label, value })=>/*#__PURE__*/
|
|
10
|
+
children: ({ label, value })=>/*#__PURE__*/ jsx(SelectItem, {
|
|
11
11
|
children: label
|
|
12
12
|
}, value)
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function createEnumSelect(enumObject) {
|
|
16
16
|
return function(props) {
|
|
17
|
-
return /*#__PURE__*/
|
|
17
|
+
return /*#__PURE__*/ jsx(EnumSelect, {
|
|
18
18
|
enumObject: enumObject,
|
|
19
19
|
...props
|
|
20
20
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { isNonNullable } from "deepsea-tools";
|
|
4
4
|
function getErrorMessage(error) {
|
|
5
|
-
if (!
|
|
5
|
+
if (!isNonNullable(error)) return [];
|
|
6
6
|
if ("string" == typeof error) return [
|
|
7
7
|
error
|
|
8
8
|
];
|
|
@@ -14,9 +14,9 @@ function getErrorMessage(error) {
|
|
|
14
14
|
const ErrorMessage = (props)=>{
|
|
15
15
|
const { data, ...rest } = props;
|
|
16
16
|
const errors = data.flatMap(getErrorMessage).filter((item, index, array)=>array.indexOf(item) === index);
|
|
17
|
-
return errors.length > 0 && /*#__PURE__*/
|
|
17
|
+
return errors.length > 0 && /*#__PURE__*/ jsx("div", {
|
|
18
18
|
...rest,
|
|
19
|
-
children: errors.map((item, index)=>/*#__PURE__*/
|
|
19
|
+
children: errors.map((item, index)=>/*#__PURE__*/ jsx("div", {
|
|
20
20
|
children: item
|
|
21
21
|
}, index))
|
|
22
22
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormAutocomplete({ field, component: Autocomplete2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Autocomplete } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormAutocomplete({ field, component: Autocomplete2 = Autocomplete, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Autocomplete2, {
|
|
7
7
|
selectedKey: field.state.value ?? "",
|
|
8
8
|
onSelectionChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormCalendar({ field, valueMode, emptyValue, dateMode, defaultTime, component: Calendar2 =
|
|
9
|
-
const context =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { Calendar } from "@heroui/react";
|
|
5
|
+
import { FormContext } from "./FormProvider.js";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { getFieldValue, getOnChange } from "../utils/time.js";
|
|
8
|
+
function FormCalendar({ field, valueMode, emptyValue, dateMode, defaultTime, component: Calendar2 = Calendar, ...rest }) {
|
|
9
|
+
const context = useContext(FormContext);
|
|
10
10
|
emptyValue ??= context.emptyValue;
|
|
11
|
-
return /*#__PURE__*/
|
|
12
|
-
focusedValue:
|
|
13
|
-
onFocusChange:
|
|
11
|
+
return /*#__PURE__*/ jsx(Calendar2, {
|
|
12
|
+
focusedValue: getFieldValue(field, dateMode),
|
|
13
|
+
onFocusChange: getOnChange({
|
|
14
14
|
field,
|
|
15
15
|
valueMode,
|
|
16
16
|
emptyValue,
|
|
17
17
|
defaultTime
|
|
18
18
|
}),
|
|
19
|
-
...
|
|
19
|
+
...getFieldProps(field),
|
|
20
20
|
...rest
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormCheckbox({ field, component: Checkbox2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Checkbox } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormCheckbox({ field, component: Checkbox2 = Checkbox, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Checkbox2, {
|
|
7
7
|
isSelected: field.state.value ?? false,
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field, true),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormCheckboxGroup({ field, component: CheckboxGroup2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CheckboxGroup } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormCheckboxGroup({ field, component: CheckboxGroup2 = CheckboxGroup, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(CheckboxGroup2, {
|
|
7
7
|
value: field.state.value ?? [],
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormDateInput({ field, valueMode, emptyValue, dateMode, defaultTime, component: DateInput2 =
|
|
9
|
-
const context =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { DateInput } from "@heroui/react";
|
|
5
|
+
import { FormContext } from "./FormProvider.js";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { getFieldValue, getOnChange } from "../utils/time.js";
|
|
8
|
+
function FormDateInput({ field, valueMode, emptyValue, dateMode, defaultTime, component: DateInput2 = DateInput, ...rest }) {
|
|
9
|
+
const context = useContext(FormContext);
|
|
10
10
|
emptyValue ??= context.emptyValue;
|
|
11
|
-
return /*#__PURE__*/
|
|
12
|
-
value:
|
|
13
|
-
onChange:
|
|
11
|
+
return /*#__PURE__*/ jsx(DateInput2, {
|
|
12
|
+
value: getFieldValue(field, dateMode),
|
|
13
|
+
onChange: getOnChange({
|
|
14
14
|
field,
|
|
15
15
|
valueMode,
|
|
16
16
|
emptyValue,
|
|
17
17
|
defaultTime
|
|
18
18
|
}),
|
|
19
|
-
...
|
|
19
|
+
...getFieldProps(field),
|
|
20
20
|
...rest
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormDatePicker({ field, valueMode, emptyValue, dateMode, defaultTime, component: DatePicker2 =
|
|
9
|
-
const context =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { DatePicker } from "@heroui/react";
|
|
5
|
+
import { FormContext } from "./FormProvider.js";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { getFieldValue, getOnChange } from "../utils/time.js";
|
|
8
|
+
function FormDatePicker({ field, valueMode, emptyValue, dateMode, defaultTime, component: DatePicker2 = DatePicker, ...rest }) {
|
|
9
|
+
const context = useContext(FormContext);
|
|
10
10
|
emptyValue ??= context.emptyValue;
|
|
11
|
-
return /*#__PURE__*/
|
|
12
|
-
value:
|
|
13
|
-
onChange:
|
|
11
|
+
return /*#__PURE__*/ jsx(DatePicker2, {
|
|
12
|
+
value: getFieldValue(field, dateMode),
|
|
13
|
+
onChange: getOnChange({
|
|
14
14
|
field,
|
|
15
15
|
valueMode,
|
|
16
16
|
emptyValue,
|
|
17
17
|
defaultTime
|
|
18
18
|
}),
|
|
19
|
-
...
|
|
19
|
+
...getFieldProps(field),
|
|
20
20
|
...rest
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormDateRangePicker({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: DateRangePicker2 =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { DateRangePicker } from "@heroui/react";
|
|
5
|
+
import { FormContext } from "./FormProvider.js";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { getFieldRangeValue, getOnRangeChange } from "../utils/range.js";
|
|
8
|
+
function FormDateRangePicker({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: DateRangePicker2 = DateRangePicker, ...rest }) {
|
|
9
9
|
const field = _field;
|
|
10
|
-
const context =
|
|
10
|
+
const context = useContext(FormContext);
|
|
11
11
|
emptyValue ??= context.emptyValue;
|
|
12
|
-
return /*#__PURE__*/
|
|
13
|
-
value:
|
|
14
|
-
onChange:
|
|
12
|
+
return /*#__PURE__*/ jsx(DateRangePicker2, {
|
|
13
|
+
value: getFieldRangeValue(field, dateMode),
|
|
14
|
+
onChange: getOnRangeChange({
|
|
15
15
|
field,
|
|
16
16
|
valueMode,
|
|
17
17
|
emptyValue,
|
|
18
18
|
defaultTime
|
|
19
19
|
}),
|
|
20
|
-
...
|
|
20
|
+
...getFieldProps(field),
|
|
21
21
|
...rest
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormInput({ field, component: Input2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Input } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormInput({ field, component: Input2 = Input, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Input2, {
|
|
7
7
|
value: field.state.value ?? "",
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormInputOtp({ field, component: InputOtp2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { InputOtp } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormInputOtp({ field, component: InputOtp2 = InputOtp, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(InputOtp2, {
|
|
7
7
|
value: field.state.value ?? "",
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormNumberInput({ field, component: NumberInput2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { NumberInput } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormNumberInput({ field, component: NumberInput2 = NumberInput, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(NumberInput2, {
|
|
7
7
|
value: field.state.value ?? 0,
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormPagination({ field, component: Pagination2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Pagination } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormPagination({ field, component: Pagination2 = Pagination, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Pagination2, {
|
|
7
7
|
page: field.state.value ?? 1,
|
|
8
8
|
onPageChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field, true),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -25,9 +25,9 @@ var __webpack_require__ = {};
|
|
|
25
25
|
var __webpack_exports__ = {};
|
|
26
26
|
__webpack_require__.r(__webpack_exports__);
|
|
27
27
|
__webpack_require__.d(__webpack_exports__, {
|
|
28
|
+
FormContext: ()=>FormContext,
|
|
28
29
|
FormProvider: ()=>FormProvider,
|
|
29
|
-
getEmptyValue: ()=>getEmptyValue
|
|
30
|
-
FormContext: ()=>FormContext
|
|
30
|
+
getEmptyValue: ()=>getEmptyValue
|
|
31
31
|
});
|
|
32
32
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
33
33
|
const external_react_namespaceObject = require("react");
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { assign as external_deepsea_tools_assign } from "deepsea-tools";
|
|
5
5
|
function getEmptyValue(value) {
|
|
6
6
|
return "undefined" === value ? void 0 : null;
|
|
7
7
|
}
|
|
8
|
-
const FormContext = /*#__PURE__*/
|
|
8
|
+
const FormContext = /*#__PURE__*/ createContext({
|
|
9
9
|
emptyValue: "null"
|
|
10
10
|
});
|
|
11
11
|
const FormProvider = ({ children, emptyValue })=>{
|
|
12
|
-
const config =
|
|
13
|
-
const newConfig = (
|
|
12
|
+
const config = useContext(FormContext);
|
|
13
|
+
const newConfig = external_deepsea_tools_assign(config, {
|
|
14
14
|
emptyValue
|
|
15
15
|
});
|
|
16
|
-
return /*#__PURE__*/
|
|
16
|
+
return /*#__PURE__*/ jsx(FormContext, {
|
|
17
17
|
value: newConfig,
|
|
18
18
|
children: children
|
|
19
19
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormRadioGroup({ field, component: RadioGroup2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { RadioGroup } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormRadioGroup({ field, component: RadioGroup2 = RadioGroup, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(RadioGroup2, {
|
|
7
7
|
value: field.state.value ?? "",
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormRangeCalendar({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: RangeCalendar2 =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { RangeCalendar } from "@heroui/react";
|
|
5
|
+
import { FormContext } from "./FormProvider.js";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { getFieldRangeValue, getOnRangeChange } from "../utils/range.js";
|
|
8
|
+
function FormRangeCalendar({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: RangeCalendar2 = RangeCalendar, ...rest }) {
|
|
9
9
|
const field = _field;
|
|
10
|
-
const context =
|
|
10
|
+
const context = useContext(FormContext);
|
|
11
11
|
emptyValue ??= context.emptyValue;
|
|
12
|
-
return /*#__PURE__*/
|
|
13
|
-
value:
|
|
14
|
-
onChange:
|
|
12
|
+
return /*#__PURE__*/ jsx(RangeCalendar2, {
|
|
13
|
+
value: getFieldRangeValue(field, dateMode),
|
|
14
|
+
onChange: getOnRangeChange({
|
|
15
15
|
field,
|
|
16
16
|
valueMode,
|
|
17
17
|
emptyValue,
|
|
18
18
|
defaultTime
|
|
19
19
|
}),
|
|
20
|
-
...
|
|
20
|
+
...getFieldProps(field),
|
|
21
21
|
...rest
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -33,17 +33,24 @@ const react_namespaceObject = require("@heroui/react");
|
|
|
33
33
|
const external_deepsea_tools_namespaceObject = require("deepsea-tools");
|
|
34
34
|
const getFieldProps_cjs_namespaceObject = require("../utils/getFieldProps.cjs");
|
|
35
35
|
const external_FormProvider_cjs_namespaceObject = require("./FormProvider.cjs");
|
|
36
|
-
function FormSelect({ field,
|
|
36
|
+
function FormSelect({ field, emptyValue, component: Select2 = react_namespaceObject.Select, selectionMode, labelPlacement, classNames: { base, label, ...restClassNames } = {}, ...rest }) {
|
|
37
37
|
const context = (0, external_react_namespaceObject.useContext)(external_FormProvider_cjs_namespaceObject.FormContext);
|
|
38
38
|
emptyValue ??= context.emptyValue;
|
|
39
39
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Select2, {
|
|
40
|
-
|
|
40
|
+
classNames: {
|
|
41
|
+
base: (0, external_deepsea_tools_namespaceObject.clsx)("outside-top" === labelPlacement && "flex flex-col", base),
|
|
42
|
+
label: (0, external_deepsea_tools_namespaceObject.clsx)("outside-top" === labelPlacement && "pb-2", label),
|
|
43
|
+
...restClassNames
|
|
44
|
+
},
|
|
45
|
+
selectedKeys: (0, external_deepsea_tools_namespaceObject.isNonNullable)(field.state.value) ? "multiple" === selectionMode ? field.state.value : [
|
|
41
46
|
field.state.value
|
|
42
47
|
] : [],
|
|
43
48
|
onSelectionChange: (keys)=>{
|
|
44
49
|
const value = Array.from(keys);
|
|
45
|
-
field.handleChange(multiple ? value : value.at(0) ?? (0, external_FormProvider_cjs_namespaceObject.getEmptyValue)(emptyValue));
|
|
50
|
+
field.handleChange("multiple" === selectionMode ? value : value.at(0) ?? (0, external_FormProvider_cjs_namespaceObject.getEmptyValue)(emptyValue));
|
|
46
51
|
},
|
|
52
|
+
selectionMode: selectionMode,
|
|
53
|
+
labelPlacement: "outside-top" === labelPlacement ? "outside-left" : labelPlacement,
|
|
47
54
|
...(0, getFieldProps_cjs_namespaceObject.getFieldProps)(field),
|
|
48
55
|
...rest
|
|
49
56
|
});
|
|
@@ -5,9 +5,11 @@ import { FieldComponentProps } from "soda-tanstack-form";
|
|
|
5
5
|
import { StrictOmit } from "soda-type";
|
|
6
6
|
import { EmptyValue } from "./FormProvider";
|
|
7
7
|
export type SelectionMode = "single" | "multiple";
|
|
8
|
-
export
|
|
8
|
+
export type SelectLabelPlacement = "inside" | "outside" | "outside-left" | "outside-top";
|
|
9
|
+
export interface FormSelectProps<Mode extends SelectionMode = "single", Value extends (Mode extends "multiple" ? Key[] : Key) | null | undefined = (Mode extends "multiple" ? Key[] : Key) | null | undefined, RenderItem extends object = object> extends StrictOmit<FieldComponentProps<typeof Select<RenderItem>, Value>, "selectionMode" | "labelPlacement"> {
|
|
10
|
+
labelPlacement?: SelectLabelPlacement;
|
|
9
11
|
selectionMode?: Mode;
|
|
10
12
|
emptyValue?: EmptyValue;
|
|
11
13
|
component?: <RenderItem extends object>(props: SelectProps<RenderItem>) => ReactNode;
|
|
12
14
|
}
|
|
13
|
-
export declare function FormSelect<Mode extends SelectionMode = "single", Value extends (Mode extends "multiple" ? Key[] : Key) | null | undefined = (Mode extends "multiple" ? Key[] : Key) | null | undefined, RenderItem extends object = object>({ field,
|
|
15
|
+
export declare function FormSelect<Mode extends SelectionMode = "single", Value extends (Mode extends "multiple" ? Key[] : Key) | null | undefined = (Mode extends "multiple" ? Key[] : Key) | null | undefined, RenderItem extends object = object>({ field, emptyValue, component: Select2, selectionMode, labelPlacement, classNames: { base, label, ...restClassNames }, ...rest }: FormSelectProps<Mode, Value, RenderItem>): ReactNode;
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormSelect({ field,
|
|
9
|
-
const context =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { Select } from "@heroui/react";
|
|
5
|
+
import { clsx, isNonNullable } from "deepsea-tools";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { FormContext, getEmptyValue } from "./FormProvider.js";
|
|
8
|
+
function FormSelect({ field, emptyValue, component: Select2 = Select, selectionMode, labelPlacement, classNames: { base, label, ...restClassNames } = {}, ...rest }) {
|
|
9
|
+
const context = useContext(FormContext);
|
|
10
10
|
emptyValue ??= context.emptyValue;
|
|
11
|
-
return /*#__PURE__*/
|
|
12
|
-
|
|
11
|
+
return /*#__PURE__*/ jsx(Select2, {
|
|
12
|
+
classNames: {
|
|
13
|
+
base: clsx("outside-top" === labelPlacement && "flex flex-col", base),
|
|
14
|
+
label: clsx("outside-top" === labelPlacement && "pb-2", label),
|
|
15
|
+
...restClassNames
|
|
16
|
+
},
|
|
17
|
+
selectedKeys: isNonNullable(field.state.value) ? "multiple" === selectionMode ? field.state.value : [
|
|
13
18
|
field.state.value
|
|
14
19
|
] : [],
|
|
15
20
|
onSelectionChange: (keys)=>{
|
|
16
21
|
const value = Array.from(keys);
|
|
17
|
-
field.handleChange(multiple ? value : value.at(0) ??
|
|
22
|
+
field.handleChange("multiple" === selectionMode ? value : value.at(0) ?? getEmptyValue(emptyValue));
|
|
18
23
|
},
|
|
19
|
-
|
|
24
|
+
selectionMode: selectionMode,
|
|
25
|
+
labelPlacement: "outside-top" === labelPlacement ? "outside-left" : labelPlacement,
|
|
26
|
+
...getFieldProps(field),
|
|
20
27
|
...rest
|
|
21
28
|
});
|
|
22
29
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormSwitch({ field, component: Switch2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Switch } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormSwitch({ field, component: Switch2 = Switch, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Switch2, {
|
|
7
7
|
isSelected: field.state.value ?? false,
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field, true),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function FormTextarea({ field, component: Textarea2 =
|
|
6
|
-
return /*#__PURE__*/
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Textarea } from "@heroui/react";
|
|
4
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
5
|
+
function FormTextarea({ field, component: Textarea2 = Textarea, ...rest }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Textarea2, {
|
|
7
7
|
value: field.state.value ?? "",
|
|
8
8
|
onValueChange: field.handleChange,
|
|
9
|
-
...
|
|
9
|
+
...getFieldProps(field),
|
|
10
10
|
...rest
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function FormTimeInput({ field, valueMode, emptyValue, timeMode, defaultTime, component: TimeInput2 =
|
|
9
|
-
const context =
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { TimeInput } from "@heroui/react";
|
|
5
|
+
import { FormContext } from "./FormProvider.js";
|
|
6
|
+
import { getFieldProps } from "../utils/getFieldProps.js";
|
|
7
|
+
import { getFieldValue, getOnChange } from "../utils/time.js";
|
|
8
|
+
function FormTimeInput({ field, valueMode, emptyValue, timeMode, defaultTime, component: TimeInput2 = TimeInput, ...rest }) {
|
|
9
|
+
const context = useContext(FormContext);
|
|
10
10
|
emptyValue ??= context.emptyValue;
|
|
11
|
-
return /*#__PURE__*/
|
|
12
|
-
value:
|
|
13
|
-
onChange:
|
|
11
|
+
return /*#__PURE__*/ jsx(TimeInput2, {
|
|
12
|
+
value: getFieldValue(field, timeMode),
|
|
13
|
+
onChange: getOnChange({
|
|
14
14
|
field,
|
|
15
15
|
valueMode,
|
|
16
16
|
emptyValue,
|
|
17
17
|
defaultTime
|
|
18
18
|
}),
|
|
19
|
-
...
|
|
19
|
+
...getFieldProps(field),
|
|
20
20
|
...rest
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -24,8 +24,8 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
closeToast: ()=>closeToast,
|
|
28
|
+
addBetterToast: ()=>addBetterToast
|
|
29
29
|
});
|
|
30
30
|
const react_namespaceObject = require("@heroui/react");
|
|
31
31
|
const external_deepsea_tools_namespaceObject = require("deepsea-tools");
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { addToast } from "@heroui/react";
|
|
2
|
+
import { clsx, nanoid } from "deepsea-tools";
|
|
3
3
|
function closeToast(key) {
|
|
4
4
|
const closeButton = document.querySelector(`.toast-${key}-close-button`);
|
|
5
5
|
if (!closeButton) console.warn(`Toast with key ${key} not found`);
|
|
6
6
|
closeButton?.click();
|
|
7
7
|
}
|
|
8
8
|
function addBetterToast({ key, loading, onClose, classNames, ...rest }) {
|
|
9
|
-
key ??=
|
|
9
|
+
key ??= nanoid();
|
|
10
10
|
classNames = {
|
|
11
11
|
...classNames
|
|
12
12
|
};
|
|
13
|
-
classNames.closeButton =
|
|
13
|
+
classNames.closeButton = clsx(classNames.closeButton, `toast-${key}-close-button`);
|
|
14
14
|
if (loading) {
|
|
15
15
|
const { promise, resolve } = Promise.withResolvers();
|
|
16
16
|
function newOnClose() {
|
|
17
17
|
resolve();
|
|
18
18
|
onClose?.();
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
addToast({
|
|
21
21
|
classNames,
|
|
22
22
|
promise,
|
|
23
23
|
onClose: newOnClose,
|
|
24
24
|
...rest
|
|
25
25
|
});
|
|
26
|
-
} else
|
|
26
|
+
} else addToast({
|
|
27
27
|
classNames,
|
|
28
28
|
onClose,
|
|
29
29
|
...rest
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isFieldInvalid } from "soda-tanstack-form";
|
|
3
|
+
import { ErrorMessage } from "../components/ErrorMessage.js";
|
|
4
4
|
function getFieldProps(field, noErrorMessage) {
|
|
5
5
|
return noErrorMessage ? {
|
|
6
6
|
onBlur: field.handleBlur,
|
|
7
|
-
isInvalid:
|
|
7
|
+
isInvalid: isFieldInvalid(field),
|
|
8
8
|
name: field.name
|
|
9
9
|
} : {
|
|
10
10
|
onBlur: field.handleBlur,
|
|
11
|
-
errorMessage: /*#__PURE__*/
|
|
11
|
+
errorMessage: /*#__PURE__*/ jsx(ErrorMessage, {
|
|
12
12
|
data: field.state.meta.errors
|
|
13
13
|
}),
|
|
14
|
-
isInvalid:
|
|
14
|
+
isInvalid: isFieldInvalid(field),
|
|
15
15
|
name: field.name
|
|
16
16
|
};
|
|
17
17
|
}
|
package/dist/utils/parseTime.cjs
CHANGED
|
@@ -24,13 +24,13 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
fromAbsolute: ()=>date_namespaceObject.fromAbsolute,
|
|
28
27
|
Time: ()=>date_namespaceObject.Time,
|
|
29
|
-
|
|
28
|
+
CalendarDate: ()=>date_namespaceObject.CalendarDate,
|
|
30
29
|
parseTime: ()=>parseTime,
|
|
31
30
|
CalendarDateTime: ()=>date_namespaceObject.CalendarDateTime,
|
|
32
31
|
ZonedDateTime: ()=>date_namespaceObject.ZonedDateTime,
|
|
33
|
-
|
|
32
|
+
fromAbsolute: ()=>date_namespaceObject.fromAbsolute,
|
|
33
|
+
getLocalTimeZone: ()=>date_namespaceObject.getLocalTimeZone
|
|
34
34
|
});
|
|
35
35
|
const date_namespaceObject = require("@internationalized/date");
|
|
36
36
|
function parseTime(ms, type) {
|
package/dist/utils/parseTime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CalendarDate, CalendarDateTime, Time, ZonedDateTime, fromAbsolute, getLocalTimeZone } from "@internationalized/date";
|
|
2
2
|
function parseTime(ms, type) {
|
|
3
|
-
if (type ===
|
|
3
|
+
if (type === ZonedDateTime) return fromAbsolute(ms, getLocalTimeZone());
|
|
4
4
|
const date = new Date(ms);
|
|
5
5
|
const year = date.getFullYear();
|
|
6
6
|
const month = date.getMonth() + 1;
|
|
@@ -9,14 +9,8 @@ function parseTime(ms, type) {
|
|
|
9
9
|
const minute = date.getMinutes();
|
|
10
10
|
const second = date.getSeconds();
|
|
11
11
|
const millisecond = date.getMilliseconds();
|
|
12
|
-
if (type ===
|
|
13
|
-
if (type ===
|
|
14
|
-
return new
|
|
12
|
+
if (type === CalendarDate) return new CalendarDate(year, month, day);
|
|
13
|
+
if (type === Time) return new Time(hour, minute, second, millisecond);
|
|
14
|
+
return new CalendarDateTime(year, month, day, hour, minute, second, millisecond);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
var __webpack_exports__CalendarDateTime = __WEBPACK_EXTERNAL_MODULE__internationalized_date_00f69a87__.CalendarDateTime;
|
|
18
|
-
var __webpack_exports__Time = __WEBPACK_EXTERNAL_MODULE__internationalized_date_00f69a87__.Time;
|
|
19
|
-
var __webpack_exports__ZonedDateTime = __WEBPACK_EXTERNAL_MODULE__internationalized_date_00f69a87__.ZonedDateTime;
|
|
20
|
-
var __webpack_exports__fromAbsolute = __WEBPACK_EXTERNAL_MODULE__internationalized_date_00f69a87__.fromAbsolute;
|
|
21
|
-
var __webpack_exports__getLocalTimeZone = __WEBPACK_EXTERNAL_MODULE__internationalized_date_00f69a87__.getLocalTimeZone;
|
|
22
|
-
export { parseTime, __webpack_exports__CalendarDate as CalendarDate, __webpack_exports__CalendarDateTime as CalendarDateTime, __webpack_exports__Time as Time, __webpack_exports__ZonedDateTime as ZonedDateTime, __webpack_exports__fromAbsolute as fromAbsolute, __webpack_exports__getLocalTimeZone as getLocalTimeZone };
|
|
16
|
+
export { CalendarDate, CalendarDateTime, Time, ZonedDateTime, fromAbsolute, getLocalTimeZone, parseTime };
|
package/dist/utils/range.cjs
CHANGED
|
@@ -24,9 +24,9 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
getRangeUpdater: ()=>getRangeUpdater,
|
|
28
|
-
getRangeValue: ()=>getRangeValue,
|
|
29
27
|
getFieldRangeValue: ()=>getFieldRangeValue,
|
|
28
|
+
getRangeValue: ()=>getRangeValue,
|
|
29
|
+
getRangeUpdater: ()=>getRangeUpdater,
|
|
30
30
|
getOnRangeChange: ()=>getOnRangeChange
|
|
31
31
|
});
|
|
32
32
|
const external_deepsea_tools_namespaceObject = require("deepsea-tools");
|
package/dist/utils/range.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { isNonNullable } from "deepsea-tools";
|
|
2
|
+
import { getEmptyValue } from "../components/FormProvider.js";
|
|
3
|
+
import { getTimeValue } from "./getTimeValue.js";
|
|
4
|
+
import { parseTime } from "./parseTime.js";
|
|
5
5
|
function getRangeValue(value, dateMode) {
|
|
6
|
-
return
|
|
7
|
-
start:
|
|
8
|
-
end:
|
|
6
|
+
return isNonNullable(value) ? {
|
|
7
|
+
start: parseTime(value[0].valueOf(), dateMode),
|
|
8
|
+
end: parseTime(value[1].valueOf(), dateMode)
|
|
9
9
|
} : null;
|
|
10
10
|
}
|
|
11
11
|
function getFieldRangeValue(field, dateMode) {
|
|
@@ -15,20 +15,20 @@ function isRangeDefaultTime(value) {
|
|
|
15
15
|
return "start" in value || "end" in value;
|
|
16
16
|
}
|
|
17
17
|
function getRangeUpdater({ value, valueMode, emptyValue, defaultTime }) {
|
|
18
|
-
if (!
|
|
18
|
+
if (!isNonNullable(value)) return getEmptyValue(emptyValue);
|
|
19
19
|
defaultTime = "function" == typeof defaultTime ? defaultTime() : defaultTime;
|
|
20
|
-
const { start, end } =
|
|
20
|
+
const { start, end } = isNonNullable(defaultTime) && isRangeDefaultTime(defaultTime) ? defaultTime : {
|
|
21
21
|
start: defaultTime,
|
|
22
22
|
end: defaultTime
|
|
23
23
|
};
|
|
24
24
|
if ("timestamp" === valueMode) return [
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
getTimeValue(value.start, start),
|
|
26
|
+
getTimeValue(value.end, end)
|
|
27
27
|
];
|
|
28
28
|
function updater(prev) {
|
|
29
29
|
return prev?.[0] instanceof Date && prev?.[1] instanceof Date && prev[0].valueOf() === value.start.valueOf() && prev[1].valueOf() === value.end.valueOf() ? prev : [
|
|
30
|
-
new Date(
|
|
31
|
-
new Date(
|
|
30
|
+
new Date(getTimeValue(value.start, start)),
|
|
31
|
+
new Date(getTimeValue(value.end, end))
|
|
32
32
|
];
|
|
33
33
|
}
|
|
34
34
|
return updater;
|
package/dist/utils/time.cjs
CHANGED
|
@@ -24,10 +24,10 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
getFieldValue: ()=>getFieldValue,
|
|
28
|
-
getUpdater: ()=>getUpdater,
|
|
29
27
|
getOnChange: ()=>getOnChange,
|
|
30
|
-
|
|
28
|
+
getFieldValue: ()=>getFieldValue,
|
|
29
|
+
getValue: ()=>getValue,
|
|
30
|
+
getUpdater: ()=>getUpdater
|
|
31
31
|
});
|
|
32
32
|
const external_deepsea_tools_namespaceObject = require("deepsea-tools");
|
|
33
33
|
const FormProvider_cjs_namespaceObject = require("../components/FormProvider.cjs");
|
package/dist/utils/time.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { isNonNullable } from "deepsea-tools";
|
|
2
|
+
import { getEmptyValue } from "../components/FormProvider.js";
|
|
3
|
+
import { getTimeValue } from "./getTimeValue.js";
|
|
4
|
+
import { parseTime } from "./parseTime.js";
|
|
5
5
|
function getValue(value, parseMode) {
|
|
6
|
-
return
|
|
6
|
+
return isNonNullable(value) ? parseTime(value.valueOf(), parseMode) : null;
|
|
7
7
|
}
|
|
8
8
|
function getFieldValue(field, parseMode) {
|
|
9
9
|
return getValue(field.state.value, parseMode);
|
|
10
10
|
}
|
|
11
11
|
function getUpdater({ value, valueMode, emptyValue, defaultTime }) {
|
|
12
|
-
const timestamp =
|
|
13
|
-
if (!
|
|
12
|
+
const timestamp = getTimeValue(value, defaultTime);
|
|
13
|
+
if (!isNonNullable(timestamp)) return getEmptyValue(emptyValue);
|
|
14
14
|
if ("timestamp" === valueMode) return timestamp;
|
|
15
15
|
return (prev)=>prev instanceof Date && prev.valueOf() === timestamp ? prev : new Date(timestamp);
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soda-heroui",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"homepage": "https://github.com/1adybug/deepsea/tree/main/packages/soda-heroui",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@internationalized/date": "^3.8.2",
|
|
39
|
-
"@tanstack/react-form": "^1.
|
|
40
|
-
"deepsea-tools": "5.40.
|
|
41
|
-
"soda-
|
|
42
|
-
"soda-
|
|
43
|
-
"soda-
|
|
39
|
+
"@tanstack/react-form": "^1.19.0",
|
|
40
|
+
"deepsea-tools": "5.40.4",
|
|
41
|
+
"soda-hooks": "6.12.7",
|
|
42
|
+
"soda-tanstack-form": "0.2.5",
|
|
43
|
+
"soda-type": "6.3.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ianvs/prettier-plugin-sort-imports": "^4.
|
|
47
|
-
"@react-types/shared": "^3.
|
|
46
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.6.0",
|
|
47
|
+
"@react-types/shared": "^3.31.0",
|
|
48
48
|
"glob": "^11.0.3",
|
|
49
49
|
"prettier": "^3.6.2",
|
|
50
50
|
"prettier-plugin-organize-imports": "^4.2.0",
|
|
51
|
-
"typescript": "^5.
|
|
51
|
+
"typescript": "^5.9.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@types/node": ">=20",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { ReactNode, useContext } from "react"
|
|
4
4
|
import { Select, SelectProps } from "@heroui/react"
|
|
5
5
|
import { Key } from "@react-types/shared"
|
|
6
|
-
import { isNonNullable } from "deepsea-tools"
|
|
6
|
+
import { clsx, isNonNullable } from "deepsea-tools"
|
|
7
7
|
import { FieldComponentProps } from "soda-tanstack-form"
|
|
8
8
|
import { StrictOmit } from "soda-type"
|
|
9
9
|
|
|
@@ -12,11 +12,14 @@ import { EmptyValue, FormContext, getEmptyValue } from "./FormProvider"
|
|
|
12
12
|
|
|
13
13
|
export type SelectionMode = "single" | "multiple"
|
|
14
14
|
|
|
15
|
+
export type SelectLabelPlacement = "inside" | "outside" | "outside-left" | "outside-top"
|
|
16
|
+
|
|
15
17
|
export interface FormSelectProps<
|
|
16
18
|
Mode extends SelectionMode = "single",
|
|
17
19
|
Value extends (Mode extends "multiple" ? Key[] : Key) | null | undefined = (Mode extends "multiple" ? Key[] : Key) | null | undefined,
|
|
18
20
|
RenderItem extends object = object,
|
|
19
|
-
> extends StrictOmit<FieldComponentProps<typeof Select<RenderItem>, Value>, "selectionMode"> {
|
|
21
|
+
> extends StrictOmit<FieldComponentProps<typeof Select<RenderItem>, Value>, "selectionMode" | "labelPlacement"> {
|
|
22
|
+
labelPlacement?: SelectLabelPlacement
|
|
20
23
|
selectionMode?: Mode
|
|
21
24
|
emptyValue?: EmptyValue
|
|
22
25
|
component?: <RenderItem extends object>(props: SelectProps<RenderItem>) => ReactNode
|
|
@@ -26,17 +29,32 @@ export function FormSelect<
|
|
|
26
29
|
Mode extends SelectionMode = "single",
|
|
27
30
|
Value extends (Mode extends "multiple" ? Key[] : Key) | null | undefined = (Mode extends "multiple" ? Key[] : Key) | null | undefined,
|
|
28
31
|
RenderItem extends object = object,
|
|
29
|
-
>({
|
|
32
|
+
>({
|
|
33
|
+
field,
|
|
34
|
+
emptyValue,
|
|
35
|
+
component: Select2 = Select,
|
|
36
|
+
selectionMode,
|
|
37
|
+
labelPlacement,
|
|
38
|
+
classNames: { base, label, ...restClassNames } = {},
|
|
39
|
+
...rest
|
|
40
|
+
}: FormSelectProps<Mode, Value, RenderItem>): ReactNode {
|
|
30
41
|
const context = useContext(FormContext)
|
|
31
42
|
emptyValue ??= context.emptyValue
|
|
32
43
|
|
|
33
44
|
return (
|
|
34
45
|
<Select2<RenderItem>
|
|
35
|
-
|
|
46
|
+
classNames={{
|
|
47
|
+
base: clsx(labelPlacement === "outside-top" && "flex flex-col", base),
|
|
48
|
+
label: clsx(labelPlacement === "outside-top" && "pb-2", label),
|
|
49
|
+
...restClassNames,
|
|
50
|
+
}}
|
|
51
|
+
selectedKeys={isNonNullable(field.state.value) ? (selectionMode === "multiple" ? (field.state.value as Key[]) : [field.state.value as Key]) : []}
|
|
36
52
|
onSelectionChange={keys => {
|
|
37
53
|
const value = Array.from(keys)
|
|
38
|
-
field.handleChange((multiple ? value : (value.at(0) ?? getEmptyValue(emptyValue))) as Value)
|
|
54
|
+
field.handleChange((selectionMode === "multiple" ? value : (value.at(0) ?? getEmptyValue(emptyValue))) as Value)
|
|
39
55
|
}}
|
|
56
|
+
selectionMode={selectionMode}
|
|
57
|
+
labelPlacement={labelPlacement === "outside-top" ? "outside-left" : labelPlacement}
|
|
40
58
|
{...getFieldProps(field)}
|
|
41
59
|
{...rest}
|
|
42
60
|
/>
|