@pisell/utils 3.0.5 → 3.0.7
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/es/arrayUtils.d.ts +72 -0
- package/es/arrayUtils.js +142 -3
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +5 -0
- package/es/common/stateHelper.d.ts +18 -0
- package/es/common/stateHelper.js +25 -0
- package/es/common/types.d.ts +28 -0
- package/es/common/types.js +1 -0
- package/es/componentStorage.d.ts +36 -0
- package/es/componentStorage.js +142 -0
- package/es/format.d.ts +5 -1
- package/es/format.js +53 -8
- package/es/index.d.ts +6 -0
- package/es/index.js +6 -0
- package/es/jsBridge/index.d.ts +9 -105
- package/es/jsBridge/index.js +28 -12
- package/es/jsBridge/types.d.ts +149 -0
- package/es/jsBridge/types.js +1 -0
- package/es/locales.d.ts +2 -5
- package/es/locales.js +36 -7
- package/es/miniRedux.js +7 -2
- package/es/number-input/hooks/index.d.ts +4 -0
- package/es/number-input/hooks/index.js +5 -0
- package/es/number-input/hooks/useNumberInputState.d.ts +25 -0
- package/es/number-input/hooks/useNumberInputState.js +129 -0
- package/es/number-input/index.d.ts +14 -0
- package/es/number-input/index.js +21 -0
- package/es/number-input/types.d.ts +96 -0
- package/es/number-input/types.js +1 -0
- package/es/number-input/utils/formatter.d.ts +53 -0
- package/es/number-input/utils/formatter.js +82 -0
- package/es/number-input/utils/index.d.ts +7 -0
- package/es/number-input/utils/index.js +8 -0
- package/es/number-input/utils/validation.d.ts +27 -0
- package/es/number-input/utils/validation.js +67 -0
- package/es/otherUtils.d.ts +48 -0
- package/es/select/hooks/index.d.ts +5 -0
- package/es/select/hooks/index.js +6 -0
- package/es/select/hooks/useDebouncedSearch.d.ts +20 -0
- package/es/select/hooks/useDebouncedSearch.js +55 -0
- package/es/select/hooks/useSelectState.d.ts +19 -0
- package/es/select/hooks/useSelectState.js +117 -0
- package/es/select/index.d.ts +8 -0
- package/es/select/index.js +13 -0
- package/es/select/types.d.ts +256 -0
- package/es/select/types.js +1 -0
- package/es/select/utils/filterOptions.d.ts +22 -0
- package/es/select/utils/filterOptions.js +34 -0
- package/es/select/utils/helpers.d.ts +42 -0
- package/es/select/utils/helpers.js +61 -0
- package/es/select/utils/index.d.ts +7 -0
- package/es/select/utils/index.js +8 -0
- package/es/select/utils/sortOptions.d.ts +12 -0
- package/es/select/utils/sortOptions.js +32 -0
- package/es/select/utils/tagAggregation.d.ts +25 -0
- package/es/select/utils/tagAggregation.js +48 -0
- package/es/text-input/hooks/index.d.ts +4 -0
- package/es/text-input/hooks/index.js +5 -0
- package/es/text-input/hooks/useTextInputState.d.ts +24 -0
- package/es/text-input/hooks/useTextInputState.js +127 -0
- package/es/text-input/index.d.ts +14 -0
- package/es/text-input/index.js +20 -0
- package/es/text-input/types.d.ts +56 -0
- package/es/text-input/types.js +1 -0
- package/es/text-input/utils/index.d.ts +5 -0
- package/es/text-input/utils/index.js +7 -0
- package/es/text-input/utils/validation.d.ts +23 -0
- package/es/text-input/utils/validation.js +71 -0
- package/es/walletValidity.d.ts +55 -0
- package/es/walletValidity.js +143 -38
- package/es/weighing.d.ts +62 -0
- package/es/weighing.js +119 -0
- package/lib/arrayUtils.d.ts +72 -0
- package/lib/arrayUtils.js +75 -0
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +29 -0
- package/lib/common/stateHelper.d.ts +18 -0
- package/lib/common/stateHelper.js +34 -0
- package/lib/common/types.d.ts +28 -0
- package/lib/common/types.js +17 -0
- package/lib/componentStorage.d.ts +36 -0
- package/lib/componentStorage.js +144 -0
- package/lib/format.d.ts +5 -1
- package/lib/format.js +45 -5
- package/lib/index.d.ts +6 -0
- package/lib/index.js +13 -1
- package/lib/jsBridge/index.d.ts +9 -105
- package/lib/jsBridge/index.js +20 -1
- package/lib/jsBridge/types.d.ts +149 -0
- package/lib/jsBridge/types.js +17 -0
- package/lib/locales.d.ts +2 -5
- package/lib/locales.js +34 -7
- package/lib/miniRedux.js +5 -7
- package/lib/number-input/hooks/index.d.ts +4 -0
- package/lib/number-input/hooks/index.js +29 -0
- package/lib/number-input/hooks/useNumberInputState.d.ts +25 -0
- package/lib/number-input/hooks/useNumberInputState.js +83 -0
- package/lib/number-input/index.d.ts +14 -0
- package/lib/number-input/index.js +41 -0
- package/lib/number-input/types.d.ts +96 -0
- package/lib/number-input/types.js +17 -0
- package/lib/number-input/utils/formatter.d.ts +53 -0
- package/lib/number-input/utils/formatter.js +55 -0
- package/lib/number-input/utils/index.d.ts +7 -0
- package/lib/number-input/utils/index.js +39 -0
- package/lib/number-input/utils/validation.d.ts +27 -0
- package/lib/number-input/utils/validation.js +54 -0
- package/lib/otherUtils.d.ts +48 -0
- package/lib/select/hooks/index.d.ts +5 -0
- package/lib/select/hooks/index.js +34 -0
- package/lib/select/hooks/useDebouncedSearch.d.ts +20 -0
- package/lib/select/hooks/useDebouncedSearch.js +43 -0
- package/lib/select/hooks/useSelectState.d.ts +19 -0
- package/lib/select/hooks/useSelectState.js +97 -0
- package/lib/select/index.d.ts +8 -0
- package/lib/select/index.js +53 -0
- package/lib/select/types.d.ts +256 -0
- package/lib/select/types.js +17 -0
- package/lib/select/utils/filterOptions.d.ts +22 -0
- package/lib/select/utils/filterOptions.js +41 -0
- package/lib/select/utils/helpers.d.ts +42 -0
- package/lib/select/utils/helpers.js +51 -0
- package/lib/select/utils/index.d.ts +7 -0
- package/lib/select/utils/index.js +48 -0
- package/lib/select/utils/sortOptions.d.ts +12 -0
- package/lib/select/utils/sortOptions.js +41 -0
- package/lib/select/utils/tagAggregation.d.ts +25 -0
- package/lib/select/utils/tagAggregation.js +43 -0
- package/lib/text-input/hooks/index.d.ts +4 -0
- package/lib/text-input/hooks/index.js +29 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +24 -0
- package/lib/text-input/hooks/useTextInputState.js +81 -0
- package/lib/text-input/index.d.ts +14 -0
- package/lib/text-input/index.js +35 -0
- package/lib/text-input/types.d.ts +56 -0
- package/lib/text-input/types.js +17 -0
- package/lib/text-input/utils/index.d.ts +5 -0
- package/lib/text-input/utils/index.js +32 -0
- package/lib/text-input/utils/validation.d.ts +23 -0
- package/lib/text-input/utils/validation.js +60 -0
- package/lib/walletValidity.d.ts +55 -0
- package/lib/walletValidity.js +120 -40
- package/lib/weighing.d.ts +62 -0
- package/lib/weighing.js +159 -0
- package/package.json +1 -1
- package/es/date.d.ts +0 -28
- package/es/document.d.ts +0 -13
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/index.d.ts +0 -28
- package/es/image.d.ts +0 -11
- package/es/typeUtils.d.ts +0 -42
- package/lib/date.d.ts +0 -28
- package/lib/document.d.ts +0 -13
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/index.d.ts +0 -28
- package/lib/image.d.ts +0 -11
- package/lib/typeUtils.d.ts +0 -42
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/text-input/hooks/index.ts
|
|
20
|
+
var hooks_exports = {};
|
|
21
|
+
__export(hooks_exports, {
|
|
22
|
+
useTextInputState: () => import_useTextInputState.useTextInputState
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
25
|
+
var import_useTextInputState = require("./useTextInputState");
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
useTextInputState
|
|
29
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BaseTextInputProps, TextInputState } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 文本输入状态管理 Hook
|
|
4
|
+
*
|
|
5
|
+
* 管理组件的内部状态,包括:
|
|
6
|
+
* - 值管理(受控/非受控模式)
|
|
7
|
+
* - 校验状态管理
|
|
8
|
+
* - 事件处理函数封装
|
|
9
|
+
*
|
|
10
|
+
* 支持受控和非受控两种模式:
|
|
11
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
12
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
13
|
+
*
|
|
14
|
+
* @param props 组件 Props(包含校验配置)
|
|
15
|
+
* @returns 文本输入状态对象
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // 受控模式
|
|
19
|
+
* const state = useTextInputState({ value: 'hello', onChange: (v) => console.log(v) });
|
|
20
|
+
*
|
|
21
|
+
* // 非受控模式
|
|
22
|
+
* const state = useTextInputState({ defaultValue: 'hello' });
|
|
23
|
+
*/
|
|
24
|
+
export declare function useTextInputState(props: BaseTextInputProps): TextInputState;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/text-input/hooks/useTextInputState.ts
|
|
20
|
+
var useTextInputState_exports = {};
|
|
21
|
+
__export(useTextInputState_exports, {
|
|
22
|
+
useTextInputState: () => useTextInputState
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useTextInputState_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_validation = require("../utils/validation");
|
|
27
|
+
function useTextInputState(props) {
|
|
28
|
+
const isControlled = props.value !== void 0;
|
|
29
|
+
const [innerValue, setInnerValue] = (0, import_react.useState)(props.defaultValue || "");
|
|
30
|
+
const [isTouched, setIsTouched] = (0, import_react.useState)(false);
|
|
31
|
+
const [isValid, setIsValid] = (0, import_react.useState)(true);
|
|
32
|
+
const [errors, setErrors] = (0, import_react.useState)([]);
|
|
33
|
+
const currentValue = isControlled ? props.value : innerValue;
|
|
34
|
+
const handleChange = (0, import_react.useCallback)(
|
|
35
|
+
(newValue) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (!isControlled) {
|
|
38
|
+
setInnerValue(newValue);
|
|
39
|
+
}
|
|
40
|
+
const shouldValidate = props.validateTrigger === "onChange" || props.validateTrigger === "both";
|
|
41
|
+
if (shouldValidate) {
|
|
42
|
+
const validation = (0, import_validation.validateValue)(newValue, props);
|
|
43
|
+
setIsValid(validation.isValid);
|
|
44
|
+
setErrors(validation.errors);
|
|
45
|
+
(_a = props.onValidate) == null ? void 0 : _a.call(props, validation.isValid, validation.errors);
|
|
46
|
+
}
|
|
47
|
+
(_b = props.onChange) == null ? void 0 : _b.call(props, newValue);
|
|
48
|
+
},
|
|
49
|
+
[isControlled, props]
|
|
50
|
+
);
|
|
51
|
+
const handleBlur = (0, import_react.useCallback)(() => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
setIsTouched(true);
|
|
54
|
+
const shouldValidate = props.validateTrigger !== "onChange";
|
|
55
|
+
if (shouldValidate) {
|
|
56
|
+
const validation = (0, import_validation.validateValue)(currentValue || "", props);
|
|
57
|
+
setIsValid(validation.isValid);
|
|
58
|
+
setErrors(validation.errors);
|
|
59
|
+
(_a = props.onValidate) == null ? void 0 : _a.call(props, validation.isValid, validation.errors);
|
|
60
|
+
}
|
|
61
|
+
(_b = props.onBlur) == null ? void 0 : _b.call(props, currentValue || "");
|
|
62
|
+
}, [currentValue, props]);
|
|
63
|
+
const handleFocus = (0, import_react.useCallback)(() => {
|
|
64
|
+
var _a;
|
|
65
|
+
setIsTouched(true);
|
|
66
|
+
(_a = props.onFocus) == null ? void 0 : _a.call(props);
|
|
67
|
+
}, [props]);
|
|
68
|
+
return {
|
|
69
|
+
value: currentValue,
|
|
70
|
+
isTouched,
|
|
71
|
+
isValid,
|
|
72
|
+
errors,
|
|
73
|
+
handleChange,
|
|
74
|
+
handleBlur,
|
|
75
|
+
handleFocus
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
useTextInputState
|
|
81
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本输入组件公共逻辑导出
|
|
3
|
+
*
|
|
4
|
+
* 供以下组件使用:
|
|
5
|
+
* - PisellSingleLineText
|
|
6
|
+
* - PisellLongText
|
|
7
|
+
* - PisellPhone
|
|
8
|
+
* - PisellEmail
|
|
9
|
+
* - PisellUrl
|
|
10
|
+
*/
|
|
11
|
+
export type { DisplayState, ValidationResult, TextInputState, BaseTextInputProps, } from './types';
|
|
12
|
+
export { useTextInputState } from './hooks';
|
|
13
|
+
export { getDisplayState } from './utils';
|
|
14
|
+
export { validateValue as validateTextValue } from './utils';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/text-input/index.ts
|
|
20
|
+
var text_input_exports = {};
|
|
21
|
+
__export(text_input_exports, {
|
|
22
|
+
getDisplayState: () => import_utils.getDisplayState,
|
|
23
|
+
useTextInputState: () => import_hooks.useTextInputState,
|
|
24
|
+
validateTextValue: () => import_utils2.validateValue
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(text_input_exports);
|
|
27
|
+
var import_hooks = require("./hooks");
|
|
28
|
+
var import_utils = require("./utils");
|
|
29
|
+
var import_utils2 = require("./utils");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
getDisplayState,
|
|
33
|
+
useTextInputState,
|
|
34
|
+
validateTextValue
|
|
35
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本输入组件公共类型定义
|
|
3
|
+
* 供 PisellSingleLineText、PisellLongText、PisellPhone、PisellEmail、PisellUrl 等组件使用
|
|
4
|
+
*/
|
|
5
|
+
export type { DisplayState, ValidationResult } from '../common';
|
|
6
|
+
/**
|
|
7
|
+
* 文本输入状态 Hook 返回值
|
|
8
|
+
*/
|
|
9
|
+
export interface TextInputState {
|
|
10
|
+
/**
|
|
11
|
+
* 当前值
|
|
12
|
+
*/
|
|
13
|
+
value: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 是否已被触摸(交互过)
|
|
16
|
+
*/
|
|
17
|
+
isTouched: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 是否校验通过
|
|
20
|
+
*/
|
|
21
|
+
isValid: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 错误信息数组
|
|
24
|
+
*/
|
|
25
|
+
errors: string[];
|
|
26
|
+
/**
|
|
27
|
+
* 值变更处理函数
|
|
28
|
+
*/
|
|
29
|
+
handleChange: (value: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 失焦处理函数
|
|
32
|
+
*/
|
|
33
|
+
handleBlur: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* 聚焦处理函数
|
|
36
|
+
*/
|
|
37
|
+
handleFocus: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 基础文本输入 Props(供校验和状态管理使用)
|
|
41
|
+
*/
|
|
42
|
+
export interface BaseTextInputProps {
|
|
43
|
+
value?: string;
|
|
44
|
+
defaultValue?: string;
|
|
45
|
+
required?: boolean;
|
|
46
|
+
minLength?: number;
|
|
47
|
+
maxLength?: number;
|
|
48
|
+
pattern?: string | RegExp;
|
|
49
|
+
validator?: (value: string) => boolean | string;
|
|
50
|
+
validateTrigger?: 'onChange' | 'onBlur' | 'both';
|
|
51
|
+
errorMessage?: string;
|
|
52
|
+
onChange?: (value: string) => void;
|
|
53
|
+
onBlur?: (value: string) => void;
|
|
54
|
+
onFocus?: () => void;
|
|
55
|
+
onValidate?: (isValid: boolean, errors: string[]) => void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/text-input/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/text-input/utils/index.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
getDisplayState: () => import_common.getDisplayState,
|
|
23
|
+
validateValue: () => import_validation.validateValue
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var import_common = require("../../common");
|
|
27
|
+
var import_validation = require("./validation");
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
getDisplayState,
|
|
31
|
+
validateValue
|
|
32
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BaseTextInputProps, ValidationResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 校验文本输入值
|
|
4
|
+
*
|
|
5
|
+
* 按照优先级执行校验规则:
|
|
6
|
+
* 1. 必填校验(required)
|
|
7
|
+
* 2. 最小长度校验(minLength)
|
|
8
|
+
* 3. 最大长度校验(maxLength)
|
|
9
|
+
* 4. 正则校验(pattern)
|
|
10
|
+
* 5. 自定义校验函数(validator)
|
|
11
|
+
*
|
|
12
|
+
* @param value 待校验的值
|
|
13
|
+
* @param props 校验配置
|
|
14
|
+
* @returns 校验结果对象,包含 isValid 和 errors
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* validateValue('hello', { required: true, minLength: 3 })
|
|
18
|
+
* // { isValid: true, errors: [] }
|
|
19
|
+
*
|
|
20
|
+
* validateValue('', { required: true })
|
|
21
|
+
* // { isValid: false, errors: ['此字段为必填项'] }
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateValue(value: string, props: BaseTextInputProps): ValidationResult;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/text-input/utils/validation.ts
|
|
20
|
+
var validation_exports = {};
|
|
21
|
+
__export(validation_exports, {
|
|
22
|
+
validateValue: () => validateValue
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(validation_exports);
|
|
25
|
+
function validateValue(value, props) {
|
|
26
|
+
const errors = [];
|
|
27
|
+
if (props.required && !(value == null ? void 0 : value.trim())) {
|
|
28
|
+
errors.push(props.errorMessage || "此字段为必填项");
|
|
29
|
+
return { isValid: false, errors };
|
|
30
|
+
}
|
|
31
|
+
if (!value) {
|
|
32
|
+
return { isValid: true, errors };
|
|
33
|
+
}
|
|
34
|
+
if (props.minLength !== void 0 && value.length < props.minLength) {
|
|
35
|
+
errors.push(`最少需要 ${props.minLength} 个字符`);
|
|
36
|
+
}
|
|
37
|
+
if (props.maxLength !== void 0 && value.length > props.maxLength) {
|
|
38
|
+
errors.push(`最多允许 ${props.maxLength} 个字符`);
|
|
39
|
+
}
|
|
40
|
+
if (props.pattern) {
|
|
41
|
+
const regex = typeof props.pattern === "string" ? new RegExp(props.pattern) : props.pattern;
|
|
42
|
+
if (!regex.test(value)) {
|
|
43
|
+
errors.push(props.errorMessage || "格式不正确");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (props.validator) {
|
|
47
|
+
const result = props.validator(value);
|
|
48
|
+
if (result !== true) {
|
|
49
|
+
errors.push(typeof result === "string" ? result : "校验失败");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
isValid: errors.length === 0,
|
|
54
|
+
errors
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
validateValue
|
|
60
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare type Locale = 'en' | 'zh-CN' | 'zh-HK';
|
|
2
|
+
interface ScheduleItem {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string | {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
type: 'standard' | 'time-slots' | 'designation';
|
|
8
|
+
start_time: string | null;
|
|
9
|
+
end_time: string | null;
|
|
10
|
+
repeat_type: 'none' | 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
11
|
+
repeat_rule: {
|
|
12
|
+
end: {
|
|
13
|
+
type: 'never' | 'date' | 'occurrence';
|
|
14
|
+
end_date: string | null;
|
|
15
|
+
occurrence: number | null;
|
|
16
|
+
};
|
|
17
|
+
frequency: number;
|
|
18
|
+
excluded_date: Array<{
|
|
19
|
+
start: string;
|
|
20
|
+
end: string;
|
|
21
|
+
}>;
|
|
22
|
+
included_date: any[];
|
|
23
|
+
frequency_date: number[];
|
|
24
|
+
} | null;
|
|
25
|
+
designation: Array<{
|
|
26
|
+
start_date: string;
|
|
27
|
+
start_time: string;
|
|
28
|
+
end_date: string;
|
|
29
|
+
end_time: string;
|
|
30
|
+
}> | null;
|
|
31
|
+
is_all: number;
|
|
32
|
+
time_slot: Array<{
|
|
33
|
+
start_time: string;
|
|
34
|
+
end_time: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface WalletPassValidity {
|
|
38
|
+
start_date?: string | null;
|
|
39
|
+
expire_date?: string | null;
|
|
40
|
+
expire_time?: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** 仅计算展示日期的交集,不修改日程的重复起点或每日使用时段。 */
|
|
43
|
+
export declare function getWalletValidityRange(start?: string | null, end?: string | null, validity?: WalletPassValidity): {
|
|
44
|
+
startDate: string | null;
|
|
45
|
+
endDate: string | null;
|
|
46
|
+
isEmpty: boolean;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 获取schedule摘要信息
|
|
50
|
+
* @param scheduleList 日程列表
|
|
51
|
+
* @param locale 语言设置
|
|
52
|
+
* @returns 摘要文本
|
|
53
|
+
*/
|
|
54
|
+
export declare function getScheduleSummary(scheduleList: ScheduleItem[], locale?: Locale, validity?: WalletPassValidity): string;
|
|
55
|
+
export {};
|