x-ui-design 0.3.47 → 0.3.49

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.
@@ -0,0 +1 @@
1
+ export declare function flattenChildren(children: React.ReactNode): React.ReactElement[];
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import require$$1 from 'react/jsx-runtime';
2
- import React$1, { useRef, useState, useContext, useMemo, useEffect, Children, isValidElement, Fragment, createContext, forwardRef, useImperativeHandle, useCallback } from 'react';
2
+ import React$1, { useRef, useState, Children, isValidElement, Fragment, Suspense, useContext, useMemo, useEffect, createContext, forwardRef, useImperativeHandle, useCallback } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import ReactDOMServer from 'react-dom/server';
5
5
 
@@ -883,6 +883,21 @@ function clsx(...args) {
883
883
  }).filter(Boolean).join(' ');
884
884
  }
885
885
 
886
+ function flattenChildren(children) {
887
+ const result = [];
888
+ Children.forEach(children, child => {
889
+ if (! /*#__PURE__*/isValidElement(child)) return;
890
+ if (child.type === Fragment || child.type === Suspense) {
891
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
892
+ // @ts-expect-error
893
+ result.push(...flattenChildren(child.props.children));
894
+ } else {
895
+ result.push(child);
896
+ }
897
+ });
898
+ return result;
899
+ }
900
+
886
901
  var css_248z$k = ".xUi-form-item{display:flex;margin-bottom:10px;position:relative}.xUi-form-item.noStyle{display:inline-flex;margin-bottom:0}.xUi-form-item-label{align-items:center;color:var(--xui-text-color);display:flex;font-size:var(--xui-font-size-md);font-weight:500;line-height:20px;margin-bottom:4px}.xUi-form-item-error{bottom:-6px;color:var(--xui-error-color);font-size:var(--xui-font-size-xs);line-height:16px;position:absolute;right:0;user-select:none}.xUi-form-item-required{color:var(--xui-error-color);display:inline-block;font-size:var(--xui-font-size-md);line-height:1;margin-left:4px;margin-right:4px}.xUi-form-item.horizontal{align-items:center;flex-direction:row;gap:4px}.xUi-form-item.vertical{align-self:flex-start;flex-direction:column}.xUi-form-item .xUi-input-container{margin-bottom:12px!important;width:-webkit-fill-available}.xUi-form-item .xUi-datepicker-container{margin-bottom:10px}.xUi-form-item .xUi-select{margin-bottom:15px}";
887
902
  styleInject(css_248z$k);
888
903
 
@@ -917,7 +932,7 @@ const FormItem$1 = ({
917
932
  subscribeToFields,
918
933
  validateFields
919
934
  } = formContext;
920
- const childrenList = useMemo(() => (Array.isArray(children) ? children : [children]).filter(Boolean), [children]);
935
+ const childrenList = useMemo(() => flattenChildren(children), [children]);
921
936
  useEffect(() => {
922
937
  if (name && !getFieldInstance(name)) {
923
938
  registerField(name, rules);
@@ -960,7 +975,10 @@ const FormItem$1 = ({
960
975
  className: `${prefixCls}-required`
961
976
  }, "*")), Children.map(childrenList, (child, key) => {
962
977
  if (/*#__PURE__*/isValidElement(child) && child.type !== Fragment) {
978
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
979
+ // @ts-expect-error
963
980
  const {
981
+ onChange,
964
982
  value,
965
983
  ...childProps
966
984
  } = child.props;
@@ -980,8 +998,9 @@ const FormItem$1 = ({
980
998
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
981
999
  // @ts-expect-error
982
1000
  ,
983
- size: childProps.size || props.size
984
- }));
1001
+ size: childProps.size || props.size,
1002
+ onChange: onChange
1003
+ }, childProps));
985
1004
  }
986
1005
  return child;
987
1006
  }), !props.noStyle && errorMessage && /*#__PURE__*/React$1.createElement("span", {
@@ -1075,7 +1094,7 @@ const Form$1 = ({
1075
1094
  });
1076
1095
  }
1077
1096
  };
1078
- const childrenList = useMemo(() => (Array.isArray(children) ? children : [children]).filter(Boolean), [children]);
1097
+ const childrenList = useMemo(() => flattenChildren(children), [children]);
1079
1098
  useEffect(() => {
1080
1099
  if (onFieldsChange) {
1081
1100
  formInstance.onFieldsChange = onFieldsChange;