rsuite 5.70.0 → 5.70.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.
Files changed (51) hide show
  1. package/Breadcrumb/styles/index.css +16 -0
  2. package/Breadcrumb/styles/index.less +10 -0
  3. package/CHANGELOG.md +19 -0
  4. package/cjs/Breadcrumb/Breadcrumb.d.ts +14 -4
  5. package/cjs/Breadcrumb/Breadcrumb.js +30 -32
  6. package/cjs/Breadcrumb/BreadcrumbItem.d.ts +20 -0
  7. package/cjs/Breadcrumb/BreadcrumbItem.js +13 -17
  8. package/cjs/Button/Button.js +3 -3
  9. package/cjs/Calendar/TableRow.js +6 -2
  10. package/cjs/CustomProvider/CustomProvider.d.ts +60 -9
  11. package/cjs/Form/Form.js +1 -1
  12. package/cjs/Form/hooks/useFormValidate.js +20 -3
  13. package/cjs/Form/hooks/useSchemaModel.d.ts +1 -1
  14. package/cjs/Form/hooks/useSchemaModel.js +61 -8
  15. package/cjs/FormControl/hooks/useField.js +4 -0
  16. package/cjs/internals/types/index.d.ts +14 -0
  17. package/cjs/internals/utils/ReactChildren.d.ts +11 -0
  18. package/cjs/internals/utils/ReactChildren.js +22 -0
  19. package/cjs/locales/index.d.ts +4 -1
  20. package/dist/rsuite-no-reset-rtl.css +16 -0
  21. package/dist/rsuite-no-reset-rtl.min.css +1 -1
  22. package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
  23. package/dist/rsuite-no-reset.css +16 -0
  24. package/dist/rsuite-no-reset.min.css +1 -1
  25. package/dist/rsuite-no-reset.min.css.map +1 -1
  26. package/dist/rsuite-rtl.css +16 -0
  27. package/dist/rsuite-rtl.min.css +1 -1
  28. package/dist/rsuite-rtl.min.css.map +1 -1
  29. package/dist/rsuite.css +16 -0
  30. package/dist/rsuite.js +10 -10
  31. package/dist/rsuite.min.css +1 -1
  32. package/dist/rsuite.min.css.map +1 -1
  33. package/dist/rsuite.min.js +1 -1
  34. package/dist/rsuite.min.js.map +1 -1
  35. package/esm/Breadcrumb/Breadcrumb.d.ts +14 -4
  36. package/esm/Breadcrumb/Breadcrumb.js +32 -34
  37. package/esm/Breadcrumb/BreadcrumbItem.d.ts +20 -0
  38. package/esm/Breadcrumb/BreadcrumbItem.js +13 -17
  39. package/esm/Button/Button.js +4 -4
  40. package/esm/Calendar/TableRow.js +6 -2
  41. package/esm/CustomProvider/CustomProvider.d.ts +60 -9
  42. package/esm/Form/Form.js +1 -1
  43. package/esm/Form/hooks/useFormValidate.js +20 -3
  44. package/esm/Form/hooks/useSchemaModel.d.ts +1 -1
  45. package/esm/Form/hooks/useSchemaModel.js +62 -9
  46. package/esm/FormControl/hooks/useField.js +4 -0
  47. package/esm/internals/types/index.d.ts +14 -0
  48. package/esm/internals/utils/ReactChildren.d.ts +11 -0
  49. package/esm/internals/utils/ReactChildren.js +21 -0
  50. package/esm/locales/index.d.ts +4 -1
  51. package/package.json +1 -1
@@ -3,17 +3,27 @@ import BreadcrumbItem from './BreadcrumbItem';
3
3
  import { WithAsProps, RsRefForwardingComponent } from '../internals/types';
4
4
  import { BreadcrumbLocale } from '../locales';
5
5
  export interface BreadcrumbProps extends WithAsProps {
6
- /** Shorthand for primary content of the React.ReactNode */
6
+ /**
7
+ * The separator between each breadcrumb item.
8
+ */
7
9
  separator?: React.ReactNode;
8
10
  /**
9
11
  * Set the maximum number of breadcrumbs to display.
10
12
  * When there are more than the maximum number,
11
13
  * only the first and last will be shown, with an ellipsis in between.
12
- * */
14
+ */
13
15
  maxItems?: number;
14
- /** Custom locale */
16
+ /**
17
+ * The locale of the component.
18
+ */
15
19
  locale?: BreadcrumbLocale;
16
- /** A function to be called when you are in the collapsed view and click the ellipsis. */
20
+ /**
21
+ * The ellipsis element.
22
+ */
23
+ ellipsis?: React.ReactNode;
24
+ /**
25
+ * Callback function for clicking the ellipsis.
26
+ */
17
27
  onExpand?: (event: React.MouseEvent) => void;
18
28
  }
19
29
  export interface BreadcrumbComponent extends RsRefForwardingComponent<'ol', BreadcrumbProps> {
@@ -1,13 +1,18 @@
1
1
  'use client';
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
4
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- var _templateObject;
6
- var _excluded = ["as", "className", "classPrefix", "children", "maxItems", "separator", "locale", "onExpand"];
7
- import React, { useState, useCallback } from 'react';
4
+ var _excluded = ["as", "className", "classPrefix", "children", "ellipsis", "maxItems", "separator", "locale", "onExpand"];
5
+ import React, { useState, useMemo } from 'react';
8
6
  import PropTypes from 'prop-types';
9
- import { useClassNames, useCustom } from "../internals/hooks/index.js";
7
+ import { useClassNames, useCustom, useEventCallback } from "../internals/hooks/index.js";
8
+ import { ReactChildren, createComponent } from "../internals/utils/index.js";
10
9
  import BreadcrumbItem from "./BreadcrumbItem.js";
10
+ var Separator = createComponent({
11
+ name: 'BreadcrumbSeparator',
12
+ componentAs: 'span',
13
+ 'aria-hidden': true
14
+ });
15
+
11
16
  /**
12
17
  * The Breadcrumb component is used to indicate the current page location and navigate.
13
18
  * @see https://rsuitejs.com/components/breadcrumb
@@ -19,6 +24,8 @@ var Breadcrumb = /*#__PURE__*/React.forwardRef(function (props, ref) {
19
24
  _props$classPrefix = props.classPrefix,
20
25
  classPrefix = _props$classPrefix === void 0 ? 'breadcrumb' : _props$classPrefix,
21
26
  children = props.children,
27
+ _props$ellipsis = props.ellipsis,
28
+ ellipsis = _props$ellipsis === void 0 ? '...' : _props$ellipsis,
22
29
  _props$maxItems = props.maxItems,
23
30
  maxItems = _props$maxItems === void 0 ? 5 : _props$maxItems,
24
31
  _props$separator = props.separator,
@@ -28,62 +35,53 @@ var Breadcrumb = /*#__PURE__*/React.forwardRef(function (props, ref) {
28
35
  rest = _objectWithoutPropertiesLoose(props, _excluded);
29
36
  var _useClassNames = useClassNames(classPrefix),
30
37
  merge = _useClassNames.merge,
31
- prefix = _useClassNames.prefix,
32
38
  withClassPrefix = _useClassNames.withClassPrefix;
33
39
  var _useState = useState(true),
34
- ellipsis = _useState[0],
35
- setEllipsis = _useState[1];
40
+ showEllipsis = _useState[0],
41
+ setShowEllipsis = _useState[1];
36
42
  var _useCustom = useCustom('Breadcrumb', overrideLocale),
37
43
  locale = _useCustom.locale;
38
- var renderSeparator = function renderSeparator(key) {
39
- return /*#__PURE__*/React.createElement("span", {
40
- key: "breadcrumb-separator-" + key,
41
- "aria-hidden": true,
42
- className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["separator"])))
43
- }, separator);
44
- };
45
- var handleClickEllipsis = useCallback(function (event) {
46
- setEllipsis(false);
44
+ var handleClickEllipsis = useEventCallback(function (event) {
45
+ setShowEllipsis(false);
47
46
  onExpand === null || onExpand === void 0 ? void 0 : onExpand(event);
48
- }, [onExpand]);
49
- var items = [];
50
- var count = React.Children.count(children);
51
- if (count) {
52
- React.Children.forEach(children, function (item, index) {
53
- items.push(item);
54
- if (index < count - 1) {
55
- items.push(renderSeparator(index));
56
- }
47
+ });
48
+ var content = useMemo(function () {
49
+ var count = ReactChildren.count(children);
50
+ var items = ReactChildren.mapCloneElement(children, function (item, index) {
51
+ var isLast = index === count - 1;
52
+ return _extends({}, item.props, {
53
+ separator: isLast ? null : /*#__PURE__*/React.createElement(Separator, null, separator)
54
+ });
57
55
  });
58
- }
59
- var renderCollapseItems = function renderCollapseItems() {
60
- if (count > maxItems && count > 2 && ellipsis) {
61
- return [].concat(items.slice(0, 2), [[/*#__PURE__*/React.createElement(BreadcrumbItem, {
56
+ if (count > maxItems && count > 2 && showEllipsis) {
57
+ return [].concat(items.slice(0, 1), [[/*#__PURE__*/React.createElement(BreadcrumbItem, {
62
58
  role: "button",
63
59
  key: "ellipsis",
64
60
  title: locale.expandText,
65
61
  "aria-label": locale.expandText,
62
+ separator: /*#__PURE__*/React.createElement(Separator, null, separator),
66
63
  onClick: handleClickEllipsis
67
64
  }, /*#__PURE__*/React.createElement("span", {
68
65
  "aria-hidden": true
69
- }, "..."))]], items.slice(items.length - 2, items.length));
66
+ }, ellipsis))]], items.slice(items.length - 1, items.length));
70
67
  }
71
68
  return items;
72
- };
69
+ }, [children, ellipsis, handleClickEllipsis, locale.expandText, maxItems, separator, showEllipsis]);
73
70
  var classes = merge(className, withClassPrefix());
74
71
  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
75
72
  ref: ref,
76
73
  className: classes
77
- }), renderCollapseItems());
74
+ }), /*#__PURE__*/React.createElement("ol", null, content));
78
75
  });
79
76
  Breadcrumb.Item = BreadcrumbItem;
80
77
  Breadcrumb.displayName = 'Breadcrumb';
81
78
  Breadcrumb.propTypes = {
82
- separator: PropTypes.node,
83
79
  as: PropTypes.elementType,
84
80
  children: PropTypes.node,
85
81
  className: PropTypes.string,
86
82
  classPrefix: PropTypes.string,
83
+ ellipsis: PropTypes.node,
84
+ separator: PropTypes.node,
87
85
  maxItems: PropTypes.number,
88
86
  onExpand: PropTypes.func
89
87
  };
@@ -1,10 +1,30 @@
1
1
  import React from 'react';
2
2
  import { WithAsProps, RsRefForwardingComponent } from '../internals/types';
3
3
  export interface BreadcrumbItemProps extends WithAsProps<React.ElementType | string> {
4
+ /**
5
+ * The wrapper element of the BreadcrumbItem.
6
+ */
7
+ wrapperAs?: React.ElementType;
8
+ /**
9
+ * The active state of the BreadcrumbItem.
10
+ */
4
11
  active?: boolean;
12
+ /**
13
+ * The href attribute specifies the URL of the page the link goes to.
14
+ */
5
15
  href?: string;
16
+ /**
17
+ * The title attribute specifies extra information about an element.
18
+ */
6
19
  title?: string;
20
+ /**
21
+ * The target attribute specifies where to open the linked document.
22
+ */
7
23
  target?: string;
24
+ /**
25
+ * The separator between each breadcrumb item.
26
+ */
27
+ separator?: React.ReactNode;
8
28
  }
9
29
  /**
10
30
  * The `<Breadcrumb.Item>` component is used to specify each section of the Breadcrumb.
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
- var _excluded = ["as", "href", "classPrefix", "title", "target", "className", "style", "active", "children"];
4
+ var _excluded = ["wrapperAs", "href", "as", "classPrefix", "title", "target", "className", "style", "active", "children", "separator"];
5
5
  import React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import SafeAnchor from "../SafeAnchor/index.js";
@@ -11,9 +11,11 @@ import { useClassNames } from "../internals/hooks/index.js";
11
11
  * @see https://rsuitejs.com/components/breadcrumb
12
12
  */
13
13
  var BreadcrumbItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
14
- var _props$as = props.as,
15
- Component = _props$as === void 0 ? props.href ? SafeAnchor : 'span' : _props$as,
14
+ var _props$wrapperAs = props.wrapperAs,
15
+ WrapperComponent = _props$wrapperAs === void 0 ? 'li' : _props$wrapperAs,
16
16
  href = props.href,
17
+ _props$as = props.as,
18
+ Component = _props$as === void 0 ? href ? SafeAnchor : 'span' : _props$as,
17
19
  _props$classPrefix = props.classPrefix,
18
20
  classPrefix = _props$classPrefix === void 0 ? 'breadcrumb-item' : _props$classPrefix,
19
21
  title = props.title,
@@ -22,6 +24,7 @@ var BreadcrumbItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
22
24
  style = props.style,
23
25
  active = props.active,
24
26
  children = props.children,
27
+ separator = props.separator,
25
28
  rest = _objectWithoutPropertiesLoose(props, _excluded);
26
29
  var _useClassNames = useClassNames(classPrefix),
27
30
  merge = _useClassNames.merge,
@@ -29,22 +32,15 @@ var BreadcrumbItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
29
32
  var classes = merge(className, withClassPrefix({
30
33
  active: active
31
34
  }));
32
- if (active) {
33
- return /*#__PURE__*/React.createElement("span", _extends({
34
- ref: ref
35
- }, rest, {
36
- style: style,
37
- className: classes
38
- }), children);
39
- }
40
- return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
35
+ return /*#__PURE__*/React.createElement(WrapperComponent, _extends({
36
+ style: style,
37
+ className: classes,
38
+ ref: ref
39
+ }, rest), active ? /*#__PURE__*/React.createElement("span", null, children) : /*#__PURE__*/React.createElement(Component, {
41
40
  href: href,
42
41
  title: title,
43
- target: target,
44
- ref: ref,
45
- style: style,
46
- className: classes
47
- }), children);
42
+ target: target
43
+ }, children), separator);
48
44
  });
49
45
  BreadcrumbItem.displayName = 'BreadcrumbItem';
50
46
  BreadcrumbItem.propTypes = {
@@ -4,7 +4,7 @@ import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTempla
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
5
  var _templateObject, _templateObject2, _templateObject3;
6
6
  var _excluded = ["as", "active", "appearance", "block", "className", "children", "classPrefix", "color", "disabled", "loading", "ripple", "size", "startIcon", "endIcon", "type"];
7
- import React, { useCallback, useContext } from 'react';
7
+ import React, { useContext, useMemo } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import Ripple from "../internals/Ripple/index.js";
10
10
  import { oneOf } from "../internals/propTypes/index.js";
@@ -48,7 +48,7 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
48
48
  loading: loading,
49
49
  block: block
50
50
  }));
51
- var renderButtonContent = useCallback(function () {
51
+ var buttonContent = useMemo(function () {
52
52
  var spin = /*#__PURE__*/React.createElement("span", {
53
53
  className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["spin"])))
54
54
  });
@@ -66,7 +66,7 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
66
66
  "aria-disabled": disabled,
67
67
  disabled: disabled,
68
68
  className: classes
69
- }), renderButtonContent());
69
+ }), buttonContent);
70
70
  }
71
71
  var Component = as || 'button';
72
72
  var type = typeProp || (Component === 'button' ? 'button' : undefined);
@@ -78,7 +78,7 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
78
78
  disabled: disabled,
79
79
  "aria-disabled": disabled,
80
80
  className: classes
81
- }), renderButtonContent());
81
+ }), buttonContent);
82
82
  });
83
83
  Button.displayName = 'Button';
84
84
  Button.propTypes = {
@@ -9,6 +9,7 @@ import { useClassNames } from "../internals/hooks/index.js";
9
9
  import { useCalendarContext } from "./CalendarContext.js";
10
10
  import TableCell from "./TableCell.js";
11
11
  var TableRow = /*#__PURE__*/React.forwardRef(function (props, ref) {
12
+ var _locale$dateLocale$op, _locale$dateLocale;
12
13
  var _props$as = props.as,
13
14
  Component = _props$as === void 0 ? 'div' : _props$as,
14
15
  className = props.className,
@@ -93,10 +94,13 @@ var TableRow = /*#__PURE__*/React.forwardRef(function (props, ref) {
93
94
  return days;
94
95
  };
95
96
  var classes = merge(className, prefix('row'));
97
+ var _ref3 = (_locale$dateLocale$op = locale === null || locale === void 0 ? void 0 : (_locale$dateLocale = locale.dateLocale) === null || _locale$dateLocale === void 0 ? void 0 : _locale$dateLocale.options) !== null && _locale$dateLocale$op !== void 0 ? _locale$dateLocale$op : {},
98
+ firstWeekContainsDate = _ref3.firstWeekContainsDate,
99
+ weekStartsOn = _ref3.weekStartsOn;
96
100
  var week = format(weekendDate, isoWeek ? 'I' : 'w', {
97
101
  locale: locale === null || locale === void 0 ? void 0 : locale.dateLocale,
98
- firstWeekContainsDate: 4,
99
- weekStartsOn: weekStart
102
+ firstWeekContainsDate: firstWeekContainsDate,
103
+ weekStartsOn: weekStart || weekStartsOn
100
104
  });
101
105
  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
102
106
  ref: ref,
@@ -1,18 +1,67 @@
1
1
  import React from 'react';
2
- import type { Locale as DateFnsLocale } from 'date-fns';
3
2
  import { Locale } from '../locales';
4
3
  import { ToastContainerInstance } from '../toaster/ToastContainer';
4
+ import type { Locale as DateFnsLocale } from 'date-fns';
5
+ import type { DateFns } from '../internals/types';
5
6
  export interface FormatDateOptions {
7
+ /**
8
+ * The locale object that contains the language and formatting rules for the date.
9
+ */
6
10
  locale?: DateFnsLocale;
7
- weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
8
- firstWeekContainsDate?: number;
11
+ /**
12
+ * Defines which day of the week should be considered the start of the week.
13
+ *
14
+ * The value should be an integer from 0 to 6, where:
15
+ * - `0` represents Sunday,
16
+ * - `1` represents Monday,
17
+ * - `2` represents Tuesday,
18
+ * - `3` represents Wednesday,
19
+ * - `4` represents Thursday,
20
+ * - `5` represents Friday,
21
+ * - `6` represents Saturday.
22
+ *
23
+ * This option is important for functions that operate on weeks, such as calculating
24
+ * the start or end of a week, determining which week a date falls in, or generating
25
+ * calendar views. The default value varies depending on the locale, with Monday (`1`)
26
+ * being the default in most regions following ISO 8601, while Sunday (`0`) is often
27
+ * the default in regions like the United States.
28
+ */
29
+ weekStartsOn?: DateFns.Day;
30
+ /**
31
+ * `firstWeekContainsDate` is used to determine which week is considered the first week of the year.
32
+ *
33
+ * This option specifies the minimum day of January that must be included in the first week.
34
+ *
35
+ * The value can be set to:
36
+ * - `1`: The first week of the year must include January 1st.
37
+ * - `4`: The first week of the year must include January 4th, which is the default according to ISO 8601.
38
+ *
39
+ * The choice between `1` and `4` typically depends on the regional or business conventions for week numbering.
40
+ *
41
+ * Please note that this option only accepts `1` (Sunday) or `4` (Thursday), aligning with common international standards.
42
+ *
43
+ * For more detailed information, please refer to https://en.wikipedia.org/wiki/Week#Week_numbering.
44
+ */
45
+ firstWeekContainsDate?: DateFns.FirstWeekContainsDate;
46
+ /**
47
+ * If true, allows usage of the week-numbering year tokens `YY` and `YYYY`.
48
+ * See: https://date-fns.org/docs/Unicode-Tokens
49
+ **/
9
50
  useAdditionalWeekYearTokens?: boolean;
51
+ /**
52
+ * If true, allows usage of the day of year tokens `D` and `DD`.
53
+ * See: https://date-fns.org/docs/Unicode-Tokens
54
+ */
10
55
  useAdditionalDayOfYearTokens?: boolean;
11
56
  }
12
57
  export interface CustomValue<T = Locale> {
13
- /** Language configuration */
58
+ /**
59
+ * The locale object that contains the language and formatting rules for the date.
60
+ */
14
61
  locale: T;
15
- /** Support right-to-left */
62
+ /**
63
+ * Right-to-left text direction.
64
+ */
16
65
  rtl: boolean;
17
66
  /**
18
67
  * Return the formatted date string in the given format. The result may vary by locale.
@@ -26,7 +75,7 @@ export interface CustomValue<T = Locale> {
26
75
  * return format(date, formatStr, { locale: eo });
27
76
  * }
28
77
  *
29
- * */
78
+ */
30
79
  formatDate: (date: Date | number, format: string, options?: FormatDateOptions) => string;
31
80
  /**
32
81
  * Return the date parsed from string using the given format string.
@@ -40,13 +89,16 @@ export interface CustomValue<T = Locale> {
40
89
  * return parse(date, formatStr, new Date(), { locale: eo });
41
90
  * }
42
91
  *
43
- * */
92
+ */
44
93
  parseDate: (dateString: string, formatString: string, referenceDate?: Date | number, options?: FormatDateOptions) => Date;
45
94
  /**
46
95
  * A Map of toast containers
47
96
  */
48
97
  toasters?: React.MutableRefObject<Map<string, ToastContainerInstance>>;
49
- /** If true, the ripple effect is disabled. Affected components include: Button, Nav.Item, Pagination. */
98
+ /**
99
+ * If true, the ripple effect is disabled.
100
+ * Affected components include: Button, Nav.Item, Pagination.
101
+ */
50
102
  disableRipple?: boolean;
51
103
  }
52
104
  export interface CustomProviderProps<T = Locale> extends Partial<CustomValue<T>> {
@@ -68,7 +120,6 @@ declare const CustomContext: React.Context<CustomProviderProps<{
68
120
  } | undefined;
69
121
  Plaintext?: {
70
122
  unfilled: string;
71
- /** Support right-to-left */
72
123
  notSelected: string;
73
124
  notUploaded: string;
74
125
  } | undefined;
package/esm/Form/Form.js CHANGED
@@ -53,7 +53,7 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
53
53
  onError = props.onError,
54
54
  onChange = props.onChange,
55
55
  rest = _objectWithoutPropertiesLoose(props, _excluded);
56
- var _useSchemaModel = useSchemaModel(formModel),
56
+ var _useSchemaModel = useSchemaModel(formModel, nestedField),
57
57
  getCombinedModel = _useSchemaModel.getCombinedModel,
58
58
  pushFieldRule = _useSchemaModel.pushFieldRule,
59
59
  removeFieldRule = _useSchemaModel.removeFieldRule;
@@ -32,12 +32,29 @@ export default function useFormValidate(formError, props) {
32
32
  var formError = {};
33
33
  var errorCount = 0;
34
34
  var model = getCombinedModel();
35
- Object.keys(model.getSchemaSpec()).forEach(function (key) {
36
- var checkResult = model.checkForField(key, formValue || {}, checkOptions);
35
+ var checkField = function checkField(key, type, value, formErrorObj) {
36
+ var checkResult = type.check(value);
37
37
  if (checkResult.hasError === true) {
38
38
  errorCount += 1;
39
- formError[key] = (checkResult === null || checkResult === void 0 ? void 0 : checkResult.errorMessage) || checkResult;
39
+ formErrorObj[key] = (checkResult === null || checkResult === void 0 ? void 0 : checkResult.errorMessage) || checkResult;
40
+ }
41
+
42
+ // Check nested object
43
+ if (type !== null && type !== void 0 && type.objectTypeSchemaSpec) {
44
+ Object.entries(type.objectTypeSchemaSpec).forEach(function (_ref) {
45
+ var nestedKey = _ref[0],
46
+ nestedType = _ref[1];
47
+ formErrorObj[key] = formErrorObj[key] || {
48
+ object: {}
49
+ };
50
+ checkField(nestedKey, nestedType, value === null || value === void 0 ? void 0 : value[nestedKey], formErrorObj[key].object);
51
+ });
40
52
  }
53
+ };
54
+ Object.entries(model.getSchemaSpec()).forEach(function (_ref2) {
55
+ var key = _ref2[0],
56
+ type = _ref2[1];
57
+ checkField(key, type, formValue[key], formError);
41
58
  });
42
59
  setFormError(formError);
43
60
  onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
@@ -1,7 +1,7 @@
1
1
  import type { MutableRefObject } from 'react';
2
2
  import type { CheckType, Schema } from 'schema-typed';
3
3
  export type FieldRuleType = MutableRefObject<CheckType<unknown, any> | undefined>;
4
- declare function useSchemaModel(formModel: Schema): {
4
+ declare function useSchemaModel(formModel: Schema, nestedField: boolean): {
5
5
  getCombinedModel: () => Schema<any, string>;
6
6
  pushFieldRule: (name: string, fieldRule: FieldRuleType) => void;
7
7
  removeFieldRule: (name: string) => void;
@@ -1,7 +1,59 @@
1
1
  'use client';
2
- import { SchemaModel } from 'schema-typed';
2
+ import { SchemaModel, ObjectType } from 'schema-typed';
3
3
  import { useRef, useCallback } from 'react';
4
- function useSchemaModel(formModel) {
4
+ /**
5
+ * Convert a flat schema object to a nested schema object
6
+ *
7
+ * @example
8
+ *
9
+ * ```js
10
+ * const schema = {
11
+ * 'address.city': StringType().isRequired('City is required'),
12
+ * 'address.street': StringType().isRequired('Street is required')
13
+ * };
14
+ *
15
+ * const result = unflattenSchemaObject(schema);
16
+ *
17
+ * // result
18
+ * {
19
+ * address: ObjectType().shape({
20
+ * city: StringType().isRequired('City is required'),
21
+ * street: StringType().isRequired('Street is required')
22
+ * })
23
+ * }
24
+ * ```
25
+ */
26
+ function unflattenSchemaObject(schema) {
27
+ var result = {};
28
+ var $type = Symbol('schema-type');
29
+ Object.keys(schema).forEach(function (key) {
30
+ if (key.includes('.')) {
31
+ var keys = key.split('.');
32
+ var lastKey = keys.pop() || '';
33
+ var current = result;
34
+ keys.forEach(function (subKey) {
35
+ var _ref;
36
+ current[subKey] = current[subKey] || (_ref = {}, _ref[$type] = 'object-type', _ref);
37
+ current = current[subKey];
38
+ });
39
+ current[lastKey] = schema[key];
40
+ } else {
41
+ result[key] = schema[key];
42
+ }
43
+ });
44
+ function convertToShape(obj) {
45
+ Object.keys(obj).forEach(function (key) {
46
+ var _obj$key;
47
+ if (((_obj$key = obj[key]) === null || _obj$key === void 0 ? void 0 : _obj$key[$type]) === 'object-type') {
48
+ delete obj[key][$type];
49
+ obj[key] = ObjectType().shape(convertToShape(obj[key]));
50
+ }
51
+ });
52
+ return obj;
53
+ }
54
+ return convertToShape(result);
55
+ }
56
+ function useSchemaModel(formModel, nestedField) {
5
57
  var subRulesRef = useRef([]);
6
58
  var pushFieldRule = useCallback(function (name, fieldRule) {
7
59
  subRulesRef.current.push({
@@ -24,15 +76,16 @@ function useSchemaModel(formModel) {
24
76
  if (realSubRules.length === 0) {
25
77
  return formModel;
26
78
  }
27
- return SchemaModel.combine(formModel, SchemaModel(realSubRules.map(function (_ref) {
28
- var _ref2;
29
- var name = _ref.name,
30
- fieldRule = _ref.fieldRule;
31
- return _ref2 = {}, _ref2[name] = fieldRule.current, _ref2;
79
+ var subRuleObject = realSubRules.map(function (_ref2) {
80
+ var _ref3;
81
+ var name = _ref2.name,
82
+ fieldRule = _ref2.fieldRule;
83
+ return _ref3 = {}, _ref3[name] = fieldRule.current, _ref3;
32
84
  }).reduce(function (a, b) {
33
85
  return Object.assign(a, b);
34
- }, {})));
35
- }, [formModel]);
86
+ }, {});
87
+ return SchemaModel.combine(formModel, SchemaModel(nestedField ? unflattenSchemaObject(subRuleObject) : subRuleObject));
88
+ }, [formModel, nestedField]);
36
89
  return {
37
90
  getCombinedModel: getCombinedModel,
38
91
  pushFieldRule: pushFieldRule,
@@ -6,6 +6,10 @@ import set from 'lodash/set';
6
6
  import { nameToPath } from "../utils.js";
7
7
  function getErrorMessage(error) {
8
8
  var _error$array;
9
+ if (typeof error === 'string') {
10
+ return error;
11
+ }
12
+
9
13
  /**
10
14
  * When using some components as the field, such as TagInput, and using `ArrayType().of` as the validation rule,
11
15
  * the error object won't contain the errorMessage directly. @see https://github.com/rsuite/rsuite/issues/3866
@@ -200,3 +200,17 @@ export type CursorPosition = {
200
200
  clientTop: number;
201
201
  clientLeft: number;
202
202
  };
203
+ export declare namespace DateFns {
204
+ /**
205
+ * FirstWeekContainsDate is used to determine which week is the first week of the year, based on what day the January, 1 is in that week.
206
+ * The day in that week can only be 1 (Monday) or 4 (Thursday).
207
+ * Please see https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system for more information.
208
+ */
209
+ type FirstWeekContainsDate = 1 | 4;
210
+ /**
211
+ * The day of the week type alias.
212
+ * Unlike the date (the number of days since the beginning of the month), which begins with 1 and is dynamic (can go up to 28, 30, or 31), the day starts with 0 and static (always ends at 6).
213
+ * Look at it as an index in an array where Sunday is the first element and Saturday is the last.
214
+ */
215
+ type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6;
216
+ }
@@ -29,6 +29,13 @@ export declare function map(children: React.ReactNode, func: any, context?: any)
29
29
  * @returns An array of the cloned and modified child elements.
30
30
  */
31
31
  export declare function mapCloneElement(children: React.ReactNode, func: any, context?: any): any[];
32
+ /**
33
+ * Iterates over children that are in flat array form.
34
+ * @param children
35
+ * @param func
36
+ * @param context
37
+ */
38
+ export declare function forEach(children: React.ReactNode, func: any, context?: any): void;
32
39
  /**
33
40
  * Returns the number of children.
34
41
  * @param children - The children to count.
@@ -63,6 +70,10 @@ export declare const ReactChildren: {
63
70
  * Maps over the children and applies the given function to each child.
64
71
  */
65
72
  map: typeof map;
73
+ /**
74
+ * Iterates over children that are in flat array form.
75
+ */
76
+ forEach: typeof forEach;
66
77
  /**
67
78
  * Finds the first child that satisfies the given condition.
68
79
  */
@@ -93,6 +93,23 @@ export function mapCloneElement(children, func, context) {
93
93
  }, context);
94
94
  }
95
95
 
96
+ /**
97
+ * Iterates over children that are in flat array form.
98
+ * @param children
99
+ * @param func
100
+ * @param context
101
+ */
102
+ export function forEach(children, func, context) {
103
+ var index = 0;
104
+ React.Children.forEach(flatChildren(children), function (child) {
105
+ if (! /*#__PURE__*/React.isValidElement(child)) {
106
+ return;
107
+ }
108
+ func.call(context, child, index);
109
+ index += 1;
110
+ });
111
+ }
112
+
96
113
  /**
97
114
  * Returns the number of children.
98
115
  * @param children - The children to count.
@@ -148,6 +165,10 @@ export var ReactChildren = {
148
165
  * Maps over the children and applies the given function to each child.
149
166
  */
150
167
  map: map,
168
+ /**
169
+ * Iterates over children that are in flat array form.
170
+ */
171
+ forEach: forEach,
151
172
  /**
152
173
  * Finds the first child that satisfies the given condition.
153
174
  */
@@ -1,4 +1,5 @@
1
1
  import defaultLocale from './default';
2
+ import { Locale as DateFnsLocale } from 'date-fns';
2
3
  export { default as arEG } from './ar_EG';
3
4
  export { default as daDK } from './da_DK';
4
5
  export { default as deDE } from './de_DE';
@@ -29,7 +30,6 @@ type PickKeys<T> = {
29
30
  };
30
31
  export type Locale = PickKeys<typeof defaultLocale>;
31
32
  export type CommonLocale = typeof defaultLocale.common;
32
- export type CalendarLocale = PickKeys<typeof defaultLocale.Calendar>;
33
33
  export type PlaintextLocale = PickKeys<typeof defaultLocale.Plaintext>;
34
34
  export type PaginationLocale = PickKeys<typeof defaultLocale.Pagination>;
35
35
  export type TableLocale = CommonLocale;
@@ -41,3 +41,6 @@ export type UploaderLocale = PickKeys<typeof defaultLocale.Uploader> & CommonLoc
41
41
  export type CloseButtonLocale = PickKeys<typeof defaultLocale.CloseButton>;
42
42
  export type BreadcrumbLocale = PickKeys<typeof defaultLocale.Breadcrumb>;
43
43
  export type ToggleLocale = PickKeys<typeof defaultLocale.Toggle>;
44
+ export interface CalendarLocale extends PickKeys<typeof defaultLocale.Calendar> {
45
+ dateLocale?: DateFnsLocale;
46
+ }