@canlooks/can-ui 0.0.78 → 0.0.79

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.
@@ -60,7 +60,7 @@ loading, options, labelKey = 'label', primaryKey = 'value', childrenKey = 'child
60
60
  setInnerOptions(await loadOptions(searchValue, parent));
61
61
  }, loading);
62
62
  (0, react_1.useEffect)(() => {
63
- if (loadOptions && !searchable && !innerOpen.current && (0, utils_1.toArray)(innerValue)?.length) {
63
+ if (loadOptions && !searchable && !innerOpen.current && !(0, utils_1.isNoValue)(innerValue)) {
64
64
  // 第一次渲染就有value,需要请求数据
65
65
  innerLoadOptions(innerSearchValue.current);
66
66
  }
@@ -57,13 +57,10 @@ min, max, step, precision, placeholder, disabled, readOnly, autoFocus, defaultVa
57
57
  }
58
58
  };
59
59
  const shouldRenderClearButton = () => {
60
- if (!clearable || disabled || readOnly || (0, utils_1.isUnset)(innerValue.current)) {
60
+ if (!clearable || disabled || readOnly) {
61
61
  return false;
62
62
  }
63
- if (Array.isArray(innerValue.current) || typeof innerValue.current === 'string') {
64
- return !!innerValue.current.length;
65
- }
66
- return true;
63
+ return (0, utils_1.isNoValue)(innerValue.current);
67
64
  };
68
65
  return ((0, jsx_runtime_1.jsxs)("div", { ...(0, utils_1.mergeComponentProps)(props, {
69
66
  ref: innerRef,
@@ -115,7 +115,7 @@ showCheckbox = !!multiple, loading, options, labelKey = 'label', primaryKey = 'v
115
115
  value: innerValue,
116
116
  onClear,
117
117
  onBlur
118
- }), "data-focused": innerOpen.current, children: inputBaseProps => (0, jsx_runtime_1.jsxs)("div", { className: select_style_1.classes.contentWrap, children: [!(0, utils_1.toArray)(innerValue)?.length
118
+ }), "data-focused": innerOpen.current, children: inputBaseProps => (0, jsx_runtime_1.jsxs)("div", { className: select_style_1.classes.contentWrap, children: [(0, utils_1.isNoValue)(innerValue)
119
119
  ? (0, jsx_runtime_1.jsx)("div", { className: select_style_1.classes.placeholder, children: props.placeholder ?? '请选择' })
120
120
  : (0, jsx_runtime_1.jsx)("div", { className: select_style_1.classes.backfill, children: renderBackfillFn() }), (0, jsx_runtime_1.jsx)("input", { size: 1, ...(0, utils_1.mergeComponentProps)(inputBaseProps, inputProps), "data-hidden": "true" }), (0, jsx_runtime_1.jsx)("div", { className: select_style_1.classes.arrow, "data-open": innerOpen.current, children: loading
121
121
  ? (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, {})
@@ -74,7 +74,7 @@ placeholder = '请选择', autoFocus, clearable, onClear, ...props }) => {
74
74
  return ((0, jsx_runtime_1.jsx)(popper_1.Popper, { css: popper_style_1.popperStyle, open: innerOpen.current, onOpenChange: openChangeHandler, placement: "bottom", variant: "collapse", trigger: ['click', 'enter'], disabled: props.disabled || props.readOnly, sizeAdaptable: sizeAdaptable, content: (0, jsx_runtime_1.jsx)(tree_1.Tree, { ...props, nodes: options, value: innerValue, onChange: setInnerValue }), ...popperProps, popperRef: popperRef, onPointerDown: e => {
75
75
  popperProps?.onPointerDown?.(e);
76
76
  e.preventDefault();
77
- }, children: (0, jsx_runtime_1.jsx)(inputBase_1.InputBase, { clearable: !!props.multiple, css: treeSelect_style_1.style, className: (0, utils_1.clsx)(treeSelect_style_1.classes.root, props.className), "data-focused": open, value: innerValue, onClear: clearHandler, placeholder: placeholder, autoFocus: autoFocus, disabled: props.disabled, readOnly: props.readOnly, children: inputBaseProps => (0, jsx_runtime_1.jsxs)("div", { className: treeSelect_style_1.classes.contentWrap, children: [!(0, utils_1.toArray)(innerValue)?.length
77
+ }, children: (0, jsx_runtime_1.jsx)(inputBase_1.InputBase, { clearable: !!props.multiple, css: treeSelect_style_1.style, className: (0, utils_1.clsx)(treeSelect_style_1.classes.root, props.className), "data-focused": open, value: innerValue, onClear: clearHandler, placeholder: placeholder, autoFocus: autoFocus, disabled: props.disabled, readOnly: props.readOnly, children: inputBaseProps => (0, jsx_runtime_1.jsxs)("div", { className: treeSelect_style_1.classes.contentWrap, children: [(0, utils_1.isNoValue)(innerValue)
78
78
  ? (0, jsx_runtime_1.jsx)("div", { className: treeSelect_style_1.classes.placeholder, children: placeholder })
79
79
  : (0, jsx_runtime_1.jsx)("div", { className: treeSelect_style_1.classes.backfill, children: renderBackfillFn() }), (0, jsx_runtime_1.jsx)("input", { size: 1, ...(0, utils_1.mergeComponentProps)(inputBaseProps, inputProps), "data-hidden": "true" }), (0, jsx_runtime_1.jsx)("div", { className: treeSelect_style_1.classes.arrow, "data-open": open, children: loading
80
80
  ? (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, {})
@@ -22,9 +22,9 @@
22
22
  import { FormProps, FormRef } from '../../components/form';
23
23
  import { ReactElement, Ref } from 'react';
24
24
  import { ReactiveFormItem } from './reactiveFormItem';
25
- export type ReactiveFormPropsRef = Pick<FormRef, 'submit' | 'getFormErrors' | 'getFieldError' | 'resetForm' | 'resetField' | 'isFormTouched' | 'isFieldTouched'>;
25
+ export type ReactiveFormRef = Pick<FormRef, 'submit' | 'getFormErrors' | 'getFieldError' | 'resetForm' | 'resetField' | 'isFormTouched' | 'isFieldTouched'>;
26
26
  export interface ReactiveFormProps extends Omit<FormProps, 'ref' | 'initialValue' | 'onChange' | 'onFinish' | 'items'> {
27
- ref?: Ref<ReactiveFormPropsRef>;
27
+ ref?: Ref<ReactiveFormRef>;
28
28
  onChange?(): void;
29
29
  onFinish?(): void;
30
30
  }
@@ -80,13 +80,18 @@ export declare function isPromise<T>(it: any): it is Promise<T>;
80
80
  * @param promise
81
81
  */
82
82
  export declare function getPromiseState(promise: Promise<any>): Promise<'pending' | 'fulfilled' | 'rejected'>;
83
+ /**
84
+ * 判断表单控件是否为空值
85
+ * @param value
86
+ */
87
+ export declare function isNoValue(value: any): boolean;
83
88
  /**
84
89
  * 将节点用某个分隔符拼接起来,通常用于渲染多选项
85
90
  * @param arr
86
91
  * @param callback
87
- * @param seperator
92
+ * @param separator
88
93
  */
89
- export declare function joinNodes<T>(arr: T[], callback: (item: T, index: number) => ReactNode, seperator?: ReactNode): (string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined)[];
94
+ export declare function joinNodes<T>(arr: T[], callback: (item: T, index: number) => ReactNode, separator?: ReactNode): (string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined)[];
90
95
  /**
91
96
  * 修复数字输入框的值,包括最大值最小值限制,以及小数点精度
92
97
  * @param value
@@ -14,6 +14,7 @@ exports.cloneRef = cloneRef;
14
14
  exports.isUnset = isUnset;
15
15
  exports.isPromise = isPromise;
16
16
  exports.getPromiseState = getPromiseState;
17
+ exports.isNoValue = isNoValue;
17
18
  exports.joinNodes = joinNodes;
18
19
  exports.fixInputNumber = fixInputNumber;
19
20
  exports.isChildOf = isChildOf;
@@ -216,16 +217,29 @@ function getPromiseState(promise) {
216
217
  return res === s ? 'pending' : 'fulfilled';
217
218
  }).catch(() => 'rejected');
218
219
  }
220
+ /**
221
+ * 判断表单控件是否为空值
222
+ * @param value
223
+ */
224
+ function isNoValue(value) {
225
+ if (isUnset(value)) {
226
+ return true;
227
+ }
228
+ if (Array.isArray(value) || typeof value === 'string') {
229
+ return !value.length;
230
+ }
231
+ return false;
232
+ }
219
233
  /**
220
234
  * 将节点用某个分隔符拼接起来,通常用于渲染多选项
221
235
  * @param arr
222
236
  * @param callback
223
- * @param seperator
237
+ * @param separator
224
238
  */
225
- function joinNodes(arr, callback, seperator = ' / ') {
239
+ function joinNodes(arr, callback, separator = ' / ') {
226
240
  return arr.flatMap((item, index) => {
227
241
  return index > 0
228
- ? [seperator, callback(item, index)]
242
+ ? [separator, callback(item, index)]
229
243
  : callback(item, index);
230
244
  });
231
245
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { createContext, memo, useContext, useDeferredValue, useEffect, useMemo, useState } from 'react';
3
- import { useControlled, useLoading, useKeyboard, joinNodes, clsx, toArray, mergeComponentProps } from '../../utils';
3
+ import { useControlled, useLoading, useKeyboard, joinNodes, clsx, mergeComponentProps, isNoValue } from '../../utils';
4
4
  import { Input } from '../input';
5
5
  import { InputBase } from '../inputBase';
6
6
  import { Popper } from '../popper';
@@ -56,7 +56,7 @@ loading, options, labelKey = 'label', primaryKey = 'value', childrenKey = 'child
56
56
  setInnerOptions(await loadOptions(searchValue, parent));
57
57
  }, loading);
58
58
  useEffect(() => {
59
- if (loadOptions && !searchable && !innerOpen.current && toArray(innerValue)?.length) {
59
+ if (loadOptions && !searchable && !innerOpen.current && !isNoValue(innerValue)) {
60
60
  // 第一次渲染就有value,需要请求数据
61
61
  innerLoadOptions(innerSearchValue.current);
62
62
  }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { useImperativeHandle, useRef } from 'react';
3
3
  import { classes, useStyle } from './inputBase.style';
4
- import { fixInputNumber, isUnset, mergeComponentProps, useControlled } from '../../utils';
4
+ import { fixInputNumber, isNoValue, mergeComponentProps, useControlled } from '../../utils';
5
5
  import { useTheme } from '../theme';
6
6
  import { Button } from '../button';
7
7
  import { LoadingIndicator } from '../loadingIndicator';
@@ -54,13 +54,10 @@ min, max, step, precision, placeholder, disabled, readOnly, autoFocus, defaultVa
54
54
  }
55
55
  };
56
56
  const shouldRenderClearButton = () => {
57
- if (!clearable || disabled || readOnly || isUnset(innerValue.current)) {
57
+ if (!clearable || disabled || readOnly) {
58
58
  return false;
59
59
  }
60
- if (Array.isArray(innerValue.current) || typeof innerValue.current === 'string') {
61
- return !!innerValue.current.length;
62
- }
63
- return true;
60
+ return isNoValue(innerValue.current);
64
61
  };
65
62
  return (_jsxs("div", { ...mergeComponentProps(props, {
66
63
  ref: innerRef,
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
2
  import { Children, isValidElement, memo, useCallback, useDeferredValue, useMemo, useRef } from 'react';
3
3
  import { InputBase } from '../inputBase';
4
- import { mergeComponentProps, toArray, useControlled } from '../../utils';
4
+ import { isNoValue, mergeComponentProps, useControlled } from '../../utils';
5
5
  import { classes, style } from './select.style';
6
6
  import { Popper } from '../popper';
7
7
  import { MenuItem } from '../menuItem';
@@ -112,7 +112,7 @@ showCheckbox = !!multiple, loading, options, labelKey = 'label', primaryKey = 'v
112
112
  value: innerValue,
113
113
  onClear,
114
114
  onBlur
115
- }), "data-focused": innerOpen.current, children: inputBaseProps => _jsxs("div", { className: classes.contentWrap, children: [!toArray(innerValue)?.length
115
+ }), "data-focused": innerOpen.current, children: inputBaseProps => _jsxs("div", { className: classes.contentWrap, children: [isNoValue(innerValue)
116
116
  ? _jsx("div", { className: classes.placeholder, children: props.placeholder ?? '请选择' })
117
117
  : _jsx("div", { className: classes.backfill, children: renderBackfillFn() }), _jsx("input", { size: 1, ...mergeComponentProps(inputBaseProps, inputProps), "data-hidden": "true" }), _jsx("div", { className: classes.arrow, "data-open": innerOpen.current, children: loading
118
118
  ? _jsx(LoadingIndicator, {})
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { Children, isValidElement, memo, useMemo } from 'react';
3
3
  import { Popper } from '../popper';
4
4
  import { Tree, TreeNode } from '../tree';
5
- import { useControlled, toArray, clsx, mergeComponentProps } from '../../utils';
5
+ import { useControlled, toArray, clsx, mergeComponentProps, isNoValue } from '../../utils';
6
6
  import { InputBase } from '../inputBase';
7
7
  import { LoadingIndicator } from '../loadingIndicator';
8
8
  import { popperStyle } from '../popper/popper.style';
@@ -71,7 +71,7 @@ placeholder = '请选择', autoFocus, clearable, onClear, ...props }) => {
71
71
  return (_jsx(Popper, { css: popperStyle, open: innerOpen.current, onOpenChange: openChangeHandler, placement: "bottom", variant: "collapse", trigger: ['click', 'enter'], disabled: props.disabled || props.readOnly, sizeAdaptable: sizeAdaptable, content: _jsx(Tree, { ...props, nodes: options, value: innerValue, onChange: setInnerValue }), ...popperProps, popperRef: popperRef, onPointerDown: e => {
72
72
  popperProps?.onPointerDown?.(e);
73
73
  e.preventDefault();
74
- }, children: _jsx(InputBase, { clearable: !!props.multiple, css: style, className: clsx(classes.root, props.className), "data-focused": open, value: innerValue, onClear: clearHandler, placeholder: placeholder, autoFocus: autoFocus, disabled: props.disabled, readOnly: props.readOnly, children: inputBaseProps => _jsxs("div", { className: classes.contentWrap, children: [!toArray(innerValue)?.length
74
+ }, children: _jsx(InputBase, { clearable: !!props.multiple, css: style, className: clsx(classes.root, props.className), "data-focused": open, value: innerValue, onClear: clearHandler, placeholder: placeholder, autoFocus: autoFocus, disabled: props.disabled, readOnly: props.readOnly, children: inputBaseProps => _jsxs("div", { className: classes.contentWrap, children: [isNoValue(innerValue)
75
75
  ? _jsx("div", { className: classes.placeholder, children: placeholder })
76
76
  : _jsx("div", { className: classes.backfill, children: renderBackfillFn() }), _jsx("input", { size: 1, ...mergeComponentProps(inputBaseProps, inputProps), "data-hidden": "true" }), _jsx("div", { className: classes.arrow, "data-open": open, children: loading
77
77
  ? _jsx(LoadingIndicator, {})
@@ -22,9 +22,9 @@
22
22
  import { FormProps, FormRef } from '../../components/form';
23
23
  import { ReactElement, Ref } from 'react';
24
24
  import { ReactiveFormItem } from './reactiveFormItem';
25
- export type ReactiveFormPropsRef = Pick<FormRef, 'submit' | 'getFormErrors' | 'getFieldError' | 'resetForm' | 'resetField' | 'isFormTouched' | 'isFieldTouched'>;
25
+ export type ReactiveFormRef = Pick<FormRef, 'submit' | 'getFormErrors' | 'getFieldError' | 'resetForm' | 'resetField' | 'isFormTouched' | 'isFieldTouched'>;
26
26
  export interface ReactiveFormProps extends Omit<FormProps, 'ref' | 'initialValue' | 'onChange' | 'onFinish' | 'items'> {
27
- ref?: Ref<ReactiveFormPropsRef>;
27
+ ref?: Ref<ReactiveFormRef>;
28
28
  onChange?(): void;
29
29
  onFinish?(): void;
30
30
  }
@@ -80,13 +80,18 @@ export declare function isPromise<T>(it: any): it is Promise<T>;
80
80
  * @param promise
81
81
  */
82
82
  export declare function getPromiseState(promise: Promise<any>): Promise<'pending' | 'fulfilled' | 'rejected'>;
83
+ /**
84
+ * 判断表单控件是否为空值
85
+ * @param value
86
+ */
87
+ export declare function isNoValue(value: any): boolean;
83
88
  /**
84
89
  * 将节点用某个分隔符拼接起来,通常用于渲染多选项
85
90
  * @param arr
86
91
  * @param callback
87
- * @param seperator
92
+ * @param separator
88
93
  */
89
- export declare function joinNodes<T>(arr: T[], callback: (item: T, index: number) => ReactNode, seperator?: ReactNode): (string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined)[];
94
+ export declare function joinNodes<T>(arr: T[], callback: (item: T, index: number) => ReactNode, separator?: ReactNode): (string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined)[];
90
95
  /**
91
96
  * 修复数字输入框的值,包括最大值最小值限制,以及小数点精度
92
97
  * @param value
@@ -191,16 +191,29 @@ export function getPromiseState(promise) {
191
191
  return res === s ? 'pending' : 'fulfilled';
192
192
  }).catch(() => 'rejected');
193
193
  }
194
+ /**
195
+ * 判断表单控件是否为空值
196
+ * @param value
197
+ */
198
+ export function isNoValue(value) {
199
+ if (isUnset(value)) {
200
+ return true;
201
+ }
202
+ if (Array.isArray(value) || typeof value === 'string') {
203
+ return !value.length;
204
+ }
205
+ return false;
206
+ }
194
207
  /**
195
208
  * 将节点用某个分隔符拼接起来,通常用于渲染多选项
196
209
  * @param arr
197
210
  * @param callback
198
- * @param seperator
211
+ * @param separator
199
212
  */
200
- export function joinNodes(arr, callback, seperator = ' / ') {
213
+ export function joinNodes(arr, callback, separator = ' / ') {
201
214
  return arr.flatMap((item, index) => {
202
215
  return index > 0
203
- ? [seperator, callback(item, index)]
216
+ ? [separator, callback(item, index)]
204
217
  : callback(item, index);
205
218
  });
206
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",