@nokecy/qc-ui 1.0.63 → 1.0.66
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/cjs/RuleBuilder/LogicSelector.d.ts +23 -0
- package/dist/cjs/RuleBuilder/LogicSelector.js +54 -0
- package/dist/cjs/RuleBuilder/RuleBuilderContainer.d.ts +20 -0
- package/dist/cjs/RuleBuilder/RuleBuilderContainer.js +209 -0
- package/dist/cjs/RuleBuilder/RuleCard.d.ts +20 -0
- package/dist/cjs/RuleBuilder/RuleCard.js +196 -0
- package/dist/cjs/RuleBuilder/RuleGroupEditor.d.ts +25 -0
- package/dist/cjs/RuleBuilder/RuleGroupEditor.js +191 -0
- package/dist/cjs/RuleBuilder/constants/operators.d.ts +47 -0
- package/dist/cjs/RuleBuilder/constants/operators.js +172 -0
- package/dist/cjs/RuleBuilder/context/RuleBuilderContext.d.ts +72 -0
- package/dist/cjs/RuleBuilder/context/RuleBuilderContext.js +286 -0
- package/dist/cjs/RuleBuilder/index.d.ts +25 -0
- package/dist/cjs/RuleBuilder/index.js +308 -0
- package/dist/cjs/RuleBuilder/inputs/BetweenValueInput.d.ts +23 -0
- package/dist/cjs/RuleBuilder/inputs/BetweenValueInput.js +80 -0
- package/dist/cjs/RuleBuilder/inputs/MultiValueInput.d.ts +21 -0
- package/dist/cjs/RuleBuilder/inputs/MultiValueInput.js +128 -0
- package/dist/cjs/RuleBuilder/inputs/SingleValueInput.d.ts +25 -0
- package/dist/cjs/RuleBuilder/inputs/SingleValueInput.js +81 -0
- package/dist/cjs/RuleBuilder/inputs/ValueInput.d.ts +29 -0
- package/dist/cjs/RuleBuilder/inputs/ValueInput.js +80 -0
- package/dist/cjs/RuleBuilder/selectors/FieldSelector.d.ts +22 -0
- package/dist/cjs/RuleBuilder/selectors/FieldSelector.js +45 -0
- package/dist/cjs/RuleBuilder/selectors/OperatorSelector.d.ts +22 -0
- package/dist/cjs/RuleBuilder/selectors/OperatorSelector.js +51 -0
- package/dist/cjs/RuleBuilder/styles/index.module.less +443 -0
- package/dist/cjs/RuleBuilder/styles/index.module.less.d.ts +43 -0
- package/dist/cjs/RuleBuilder/types/index.d.ts +232 -0
- package/dist/cjs/RuleBuilder/types/index.js +83 -0
- package/dist/cjs/RuleBuilder/utils/pathHelpers.d.ts +65 -0
- package/dist/cjs/RuleBuilder/utils/pathHelpers.js +241 -0
- package/dist/cjs/RuleBuilder/utils/ruleHelpers.d.ts +47 -0
- package/dist/cjs/RuleBuilder/utils/ruleHelpers.js +154 -0
- package/dist/cjs/RuleBuilder/utils/validation.d.ts +25 -0
- package/dist/cjs/RuleBuilder/utils/validation.js +241 -0
- package/dist/cjs/generatedListPage/_utils/defaultHandlers.js +24 -11
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/standardFormDialog/StandardFormDialog.js +26 -5
- package/dist/cjs/standardFormDialog/withStandardForm.js +6 -1
- package/dist/esm/RuleBuilder/LogicSelector.d.ts +23 -0
- package/dist/esm/RuleBuilder/LogicSelector.js +47 -0
- package/dist/esm/RuleBuilder/RuleBuilderContainer.d.ts +20 -0
- package/dist/esm/RuleBuilder/RuleBuilderContainer.js +203 -0
- package/dist/esm/RuleBuilder/RuleCard.d.ts +20 -0
- package/dist/esm/RuleBuilder/RuleCard.js +191 -0
- package/dist/esm/RuleBuilder/RuleGroupEditor.d.ts +25 -0
- package/dist/esm/RuleBuilder/RuleGroupEditor.js +184 -0
- package/dist/esm/RuleBuilder/constants/operators.d.ts +47 -0
- package/dist/esm/RuleBuilder/constants/operators.js +169 -0
- package/dist/esm/RuleBuilder/context/RuleBuilderContext.d.ts +72 -0
- package/dist/esm/RuleBuilder/context/RuleBuilderContext.js +271 -0
- package/dist/esm/RuleBuilder/index.d.ts +25 -0
- package/dist/esm/RuleBuilder/index.js +42 -0
- package/dist/esm/RuleBuilder/inputs/BetweenValueInput.d.ts +23 -0
- package/dist/esm/RuleBuilder/inputs/BetweenValueInput.js +73 -0
- package/dist/esm/RuleBuilder/inputs/MultiValueInput.d.ts +21 -0
- package/dist/esm/RuleBuilder/inputs/MultiValueInput.js +121 -0
- package/dist/esm/RuleBuilder/inputs/SingleValueInput.d.ts +25 -0
- package/dist/esm/RuleBuilder/inputs/SingleValueInput.js +74 -0
- package/dist/esm/RuleBuilder/inputs/ValueInput.d.ts +29 -0
- package/dist/esm/RuleBuilder/inputs/ValueInput.js +73 -0
- package/dist/esm/RuleBuilder/selectors/FieldSelector.d.ts +22 -0
- package/dist/esm/RuleBuilder/selectors/FieldSelector.js +38 -0
- package/dist/esm/RuleBuilder/selectors/OperatorSelector.d.ts +22 -0
- package/dist/esm/RuleBuilder/selectors/OperatorSelector.js +44 -0
- package/dist/esm/RuleBuilder/styles/index.module.less +443 -0
- package/dist/esm/RuleBuilder/styles/index.module.less.d.ts +43 -0
- package/dist/esm/RuleBuilder/types/index.d.ts +232 -0
- package/dist/esm/RuleBuilder/types/index.js +91 -0
- package/dist/esm/RuleBuilder/utils/pathHelpers.d.ts +65 -0
- package/dist/esm/RuleBuilder/utils/pathHelpers.js +228 -0
- package/dist/esm/RuleBuilder/utils/ruleHelpers.d.ts +47 -0
- package/dist/esm/RuleBuilder/utils/ruleHelpers.js +145 -0
- package/dist/esm/RuleBuilder/utils/validation.d.ts +25 -0
- package/dist/esm/RuleBuilder/utils/validation.js +236 -0
- package/dist/esm/generatedListPage/_utils/defaultHandlers.js +24 -11
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/standardFormDialog/StandardFormDialog.js +26 -5
- package/dist/esm/standardFormDialog/withStandardForm.js +7 -2
- package/dist/umd/qc-ui.min.css +1 -1
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 操作符常量定义
|
|
3
|
+
*/
|
|
4
|
+
import { MatchOperator, FieldDataType } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* 操作符显示信息
|
|
7
|
+
*/
|
|
8
|
+
export interface OperatorInfo {
|
|
9
|
+
value: MatchOperator;
|
|
10
|
+
label: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
description: string;
|
|
13
|
+
/** 是否需要输入值 */
|
|
14
|
+
requiresValue: boolean;
|
|
15
|
+
/** 是否需要第二个值(Between) */
|
|
16
|
+
requiresValue2: boolean;
|
|
17
|
+
/** 是否需要多个值(In/NotIn) */
|
|
18
|
+
requiresMultiValue: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 所有操作符的显示信息
|
|
22
|
+
*/
|
|
23
|
+
export declare const OPERATOR_INFO_MAP: Record<MatchOperator, OperatorInfo>;
|
|
24
|
+
/**
|
|
25
|
+
* 根据数据类型获取可用操作符
|
|
26
|
+
*/
|
|
27
|
+
export declare const getOperatorsByDataType: (dataType: FieldDataType) => MatchOperator[];
|
|
28
|
+
/**
|
|
29
|
+
* 获取操作符信息
|
|
30
|
+
*/
|
|
31
|
+
export declare const getOperatorInfo: (operator: MatchOperator) => OperatorInfo;
|
|
32
|
+
/**
|
|
33
|
+
* 检查操作符是否需要值输入
|
|
34
|
+
*/
|
|
35
|
+
export declare const operatorRequiresValue: (operator: MatchOperator) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* 检查操作符是否需要第二个值(Between)
|
|
38
|
+
*/
|
|
39
|
+
export declare const operatorRequiresValue2: (operator: MatchOperator) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 检查操作符是否需要多个值(In/NotIn)
|
|
42
|
+
*/
|
|
43
|
+
export declare const operatorRequiresMultiValue: (operator: MatchOperator) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 最大嵌套层级
|
|
46
|
+
*/
|
|
47
|
+
export declare const MAX_NESTING_LEVEL = 5;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var _OPERATOR_INFO_MAP;
|
|
2
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
/**
|
|
7
|
+
* 操作符常量定义
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { MatchOperator } from "../types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 操作符显示信息
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 所有操作符的显示信息
|
|
18
|
+
*/
|
|
19
|
+
export var OPERATOR_INFO_MAP = (_OPERATOR_INFO_MAP = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_OPERATOR_INFO_MAP, MatchOperator.Equals, {
|
|
20
|
+
value: MatchOperator.Equals,
|
|
21
|
+
label: '等于',
|
|
22
|
+
symbol: '=',
|
|
23
|
+
description: '字段值等于指定值',
|
|
24
|
+
requiresValue: true,
|
|
25
|
+
requiresValue2: false,
|
|
26
|
+
requiresMultiValue: false
|
|
27
|
+
}), MatchOperator.NotEquals, {
|
|
28
|
+
value: MatchOperator.NotEquals,
|
|
29
|
+
label: '不等于',
|
|
30
|
+
symbol: '≠',
|
|
31
|
+
description: '字段值不等于指定值',
|
|
32
|
+
requiresValue: true,
|
|
33
|
+
requiresValue2: false,
|
|
34
|
+
requiresMultiValue: false
|
|
35
|
+
}), MatchOperator.GreaterThan, {
|
|
36
|
+
value: MatchOperator.GreaterThan,
|
|
37
|
+
label: '大于',
|
|
38
|
+
symbol: '>',
|
|
39
|
+
description: '字段值大于指定值',
|
|
40
|
+
requiresValue: true,
|
|
41
|
+
requiresValue2: false,
|
|
42
|
+
requiresMultiValue: false
|
|
43
|
+
}), MatchOperator.GreaterThanOrEqual, {
|
|
44
|
+
value: MatchOperator.GreaterThanOrEqual,
|
|
45
|
+
label: '大于等于',
|
|
46
|
+
symbol: '≥',
|
|
47
|
+
description: '字段值大于或等于指定值',
|
|
48
|
+
requiresValue: true,
|
|
49
|
+
requiresValue2: false,
|
|
50
|
+
requiresMultiValue: false
|
|
51
|
+
}), MatchOperator.LessThan, {
|
|
52
|
+
value: MatchOperator.LessThan,
|
|
53
|
+
label: '小于',
|
|
54
|
+
symbol: '<',
|
|
55
|
+
description: '字段值小于指定值',
|
|
56
|
+
requiresValue: true,
|
|
57
|
+
requiresValue2: false,
|
|
58
|
+
requiresMultiValue: false
|
|
59
|
+
}), MatchOperator.LessThanOrEqual, {
|
|
60
|
+
value: MatchOperator.LessThanOrEqual,
|
|
61
|
+
label: '小于等于',
|
|
62
|
+
symbol: '≤',
|
|
63
|
+
description: '字段值小于或等于指定值',
|
|
64
|
+
requiresValue: true,
|
|
65
|
+
requiresValue2: false,
|
|
66
|
+
requiresMultiValue: false
|
|
67
|
+
}), MatchOperator.In, {
|
|
68
|
+
value: MatchOperator.In,
|
|
69
|
+
label: '在集合中',
|
|
70
|
+
symbol: 'IN',
|
|
71
|
+
description: '字段值在指定的值集合中',
|
|
72
|
+
requiresValue: false,
|
|
73
|
+
requiresValue2: false,
|
|
74
|
+
requiresMultiValue: true
|
|
75
|
+
}), MatchOperator.NotIn, {
|
|
76
|
+
value: MatchOperator.NotIn,
|
|
77
|
+
label: '不在集合中',
|
|
78
|
+
symbol: 'NOT IN',
|
|
79
|
+
description: '字段值不在指定的值集合中',
|
|
80
|
+
requiresValue: false,
|
|
81
|
+
requiresValue2: false,
|
|
82
|
+
requiresMultiValue: true
|
|
83
|
+
}), MatchOperator.Between, {
|
|
84
|
+
value: MatchOperator.Between,
|
|
85
|
+
label: '介于之间',
|
|
86
|
+
symbol: 'BETWEEN',
|
|
87
|
+
description: '字段值在指定的范围之间',
|
|
88
|
+
requiresValue: true,
|
|
89
|
+
requiresValue2: true,
|
|
90
|
+
requiresMultiValue: false
|
|
91
|
+
}), MatchOperator.Like, {
|
|
92
|
+
value: MatchOperator.Like,
|
|
93
|
+
label: '模糊匹配',
|
|
94
|
+
symbol: 'LIKE',
|
|
95
|
+
description: '字段值模糊匹配指定模式(支持 % 通配符)',
|
|
96
|
+
requiresValue: true,
|
|
97
|
+
requiresValue2: false,
|
|
98
|
+
requiresMultiValue: false
|
|
99
|
+
}), _defineProperty(_defineProperty(_OPERATOR_INFO_MAP, MatchOperator.IsNull, {
|
|
100
|
+
value: MatchOperator.IsNull,
|
|
101
|
+
label: '为空',
|
|
102
|
+
symbol: 'IS NULL',
|
|
103
|
+
description: '字段值为空(NULL)',
|
|
104
|
+
requiresValue: false,
|
|
105
|
+
requiresValue2: false,
|
|
106
|
+
requiresMultiValue: false
|
|
107
|
+
}), MatchOperator.IsNotNull, {
|
|
108
|
+
value: MatchOperator.IsNotNull,
|
|
109
|
+
label: '不为空',
|
|
110
|
+
symbol: 'IS NOT NULL',
|
|
111
|
+
description: '字段值不为空(NOT NULL)',
|
|
112
|
+
requiresValue: false,
|
|
113
|
+
requiresValue2: false,
|
|
114
|
+
requiresMultiValue: false
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 根据数据类型获取可用操作符
|
|
119
|
+
*/
|
|
120
|
+
export var getOperatorsByDataType = function getOperatorsByDataType(dataType) {
|
|
121
|
+
switch (dataType) {
|
|
122
|
+
case 'string':
|
|
123
|
+
return [MatchOperator.Equals, MatchOperator.NotEquals, MatchOperator.In, MatchOperator.NotIn, MatchOperator.Like, MatchOperator.IsNull, MatchOperator.IsNotNull];
|
|
124
|
+
case 'number':
|
|
125
|
+
return [MatchOperator.Equals, MatchOperator.NotEquals, MatchOperator.GreaterThan, MatchOperator.GreaterThanOrEqual, MatchOperator.LessThan, MatchOperator.LessThanOrEqual, MatchOperator.In, MatchOperator.NotIn, MatchOperator.Between, MatchOperator.IsNull, MatchOperator.IsNotNull];
|
|
126
|
+
case 'date':
|
|
127
|
+
return [MatchOperator.Equals, MatchOperator.NotEquals, MatchOperator.GreaterThan, MatchOperator.GreaterThanOrEqual, MatchOperator.LessThan, MatchOperator.LessThanOrEqual, MatchOperator.Between, MatchOperator.IsNull, MatchOperator.IsNotNull];
|
|
128
|
+
case 'boolean':
|
|
129
|
+
return [MatchOperator.Equals, MatchOperator.NotEquals, MatchOperator.IsNull, MatchOperator.IsNotNull];
|
|
130
|
+
default:
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 获取操作符信息
|
|
137
|
+
*/
|
|
138
|
+
export var getOperatorInfo = function getOperatorInfo(operator) {
|
|
139
|
+
return OPERATOR_INFO_MAP[operator];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 检查操作符是否需要值输入
|
|
144
|
+
*/
|
|
145
|
+
export var operatorRequiresValue = function operatorRequiresValue(operator) {
|
|
146
|
+
var _OPERATOR_INFO_MAP$op;
|
|
147
|
+
return ((_OPERATOR_INFO_MAP$op = OPERATOR_INFO_MAP[operator]) === null || _OPERATOR_INFO_MAP$op === void 0 ? void 0 : _OPERATOR_INFO_MAP$op.requiresValue) || false;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 检查操作符是否需要第二个值(Between)
|
|
152
|
+
*/
|
|
153
|
+
export var operatorRequiresValue2 = function operatorRequiresValue2(operator) {
|
|
154
|
+
var _OPERATOR_INFO_MAP$op2;
|
|
155
|
+
return ((_OPERATOR_INFO_MAP$op2 = OPERATOR_INFO_MAP[operator]) === null || _OPERATOR_INFO_MAP$op2 === void 0 ? void 0 : _OPERATOR_INFO_MAP$op2.requiresValue2) || false;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 检查操作符是否需要多个值(In/NotIn)
|
|
160
|
+
*/
|
|
161
|
+
export var operatorRequiresMultiValue = function operatorRequiresMultiValue(operator) {
|
|
162
|
+
var _OPERATOR_INFO_MAP$op3;
|
|
163
|
+
return ((_OPERATOR_INFO_MAP$op3 = OPERATOR_INFO_MAP[operator]) === null || _OPERATOR_INFO_MAP$op3 === void 0 ? void 0 : _OPERATOR_INFO_MAP$op3.requiresMultiValue) || false;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 最大嵌套层级
|
|
168
|
+
*/
|
|
169
|
+
export var MAX_NESTING_LEVEL = 5;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 规则构建器状态管理 Context
|
|
3
|
+
* 使用 React Context + useReducer 模式实现全局状态管理
|
|
4
|
+
*/
|
|
5
|
+
import React, { type ReactNode } from 'react';
|
|
6
|
+
import type { RuleBuilderState, RuleBuilderAction, RuleGroupDto, FieldDefinition, ValidationResult } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Context 类型定义
|
|
9
|
+
*/
|
|
10
|
+
interface RuleBuilderContextValue {
|
|
11
|
+
/** 当前状态 */
|
|
12
|
+
state: RuleBuilderState;
|
|
13
|
+
/** Dispatch 方法 */
|
|
14
|
+
dispatch: React.Dispatch<RuleBuilderAction>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Provider Props
|
|
18
|
+
*/
|
|
19
|
+
interface RuleBuilderProviderProps {
|
|
20
|
+
/** 子组件 */
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
/** 初始规则组 */
|
|
23
|
+
initialRule?: RuleGroupDto;
|
|
24
|
+
/** 字段定义列表 */
|
|
25
|
+
fields: FieldDefinition[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* RuleBuilder Provider 组件
|
|
29
|
+
*/
|
|
30
|
+
export declare function RuleBuilderProvider({ children, initialRule, fields, }: RuleBuilderProviderProps): JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* 使用 RuleBuilder Context 的 Hook
|
|
33
|
+
* @throws {Error} 如果在 Provider 外部使用
|
|
34
|
+
*/
|
|
35
|
+
export declare function useRuleBuilderContext(): RuleBuilderContextValue;
|
|
36
|
+
/**
|
|
37
|
+
* 便捷 Hook: 获取当前规则组
|
|
38
|
+
*/
|
|
39
|
+
export declare function useRuleGroup(): RuleGroupDto;
|
|
40
|
+
/**
|
|
41
|
+
* 便捷 Hook: 获取字段列表
|
|
42
|
+
*/
|
|
43
|
+
export declare function useFields(): FieldDefinition[];
|
|
44
|
+
/**
|
|
45
|
+
* 便捷 Hook: 获取加载状态
|
|
46
|
+
*/
|
|
47
|
+
export declare function useLoading(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 便捷 Hook: 获取验证结果
|
|
50
|
+
*/
|
|
51
|
+
export declare function useValidation(): ValidationResult;
|
|
52
|
+
/**
|
|
53
|
+
* 便捷 Hook: 获取修改状态
|
|
54
|
+
*/
|
|
55
|
+
export declare function useIsDirty(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* 便捷 Hook: 获取 state
|
|
58
|
+
*/
|
|
59
|
+
export declare function useRuleBuilderState(): RuleBuilderState;
|
|
60
|
+
/**
|
|
61
|
+
* 便捷 Hook: 获取 dispatch
|
|
62
|
+
*/
|
|
63
|
+
export declare function useRuleBuilderDispatch(): React.Dispatch<RuleBuilderAction>;
|
|
64
|
+
/**
|
|
65
|
+
* 便捷 Hook: 获取字段列表(别名,与 useFields 相同)
|
|
66
|
+
*/
|
|
67
|
+
export declare function useRuleBuilderFields(): FieldDefinition[];
|
|
68
|
+
/**
|
|
69
|
+
* 便捷 Hook: 获取验证结果(别名,与 useValidation 相同)
|
|
70
|
+
*/
|
|
71
|
+
export declare function useRuleBuilderValidation(): ValidationResult;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
/**
|
|
14
|
+
* 规则构建器状态管理 Context
|
|
15
|
+
* 使用 React Context + useReducer 模式实现全局状态管理
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React, { createContext, useContext, useReducer, useMemo } from 'react';
|
|
19
|
+
import { updateRuleAtPath, deleteRuleAtPath, addRuleAtPath, updateRuleGroupAtPath, deleteRuleGroupAtPath, addRuleGroupAtPath } from "../utils/pathHelpers";
|
|
20
|
+
import { createEmptyRuleGroup } from "../utils/ruleHelpers";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 初始验证结果
|
|
24
|
+
*/
|
|
25
|
+
var INITIAL_VALIDATION = {
|
|
26
|
+
isValid: true,
|
|
27
|
+
errors: [],
|
|
28
|
+
warnings: []
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 创建初始状态
|
|
33
|
+
*/
|
|
34
|
+
function createInitialState(initialRule) {
|
|
35
|
+
var fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
36
|
+
return {
|
|
37
|
+
ruleGroup: initialRule || createEmptyRuleGroup(0),
|
|
38
|
+
// And 逻辑组
|
|
39
|
+
fields: fields,
|
|
40
|
+
loading: false,
|
|
41
|
+
validationResult: INITIAL_VALIDATION,
|
|
42
|
+
isDirty: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reducer 函数
|
|
48
|
+
*/
|
|
49
|
+
function ruleBuilderReducer(state, action) {
|
|
50
|
+
switch (action.type) {
|
|
51
|
+
case 'SET_RULE_GROUP':
|
|
52
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
53
|
+
ruleGroup: action.payload,
|
|
54
|
+
isDirty: false
|
|
55
|
+
});
|
|
56
|
+
case 'SET_FIELDS':
|
|
57
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
58
|
+
fields: action.payload
|
|
59
|
+
});
|
|
60
|
+
case 'SET_LOADING':
|
|
61
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
62
|
+
loading: action.payload
|
|
63
|
+
});
|
|
64
|
+
case 'UPDATE_RULE':
|
|
65
|
+
{
|
|
66
|
+
var _action$payload = action.payload,
|
|
67
|
+
path = _action$payload.path,
|
|
68
|
+
rule = _action$payload.rule;
|
|
69
|
+
var newRuleGroup = updateRuleAtPath(state.ruleGroup, path, rule);
|
|
70
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
71
|
+
ruleGroup: newRuleGroup,
|
|
72
|
+
isDirty: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
case 'DELETE_RULE':
|
|
76
|
+
{
|
|
77
|
+
var _path = action.payload.path;
|
|
78
|
+
var _newRuleGroup = deleteRuleAtPath(state.ruleGroup, _path);
|
|
79
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
80
|
+
ruleGroup: _newRuleGroup,
|
|
81
|
+
isDirty: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
case 'ADD_RULE':
|
|
85
|
+
{
|
|
86
|
+
var _action$payload2 = action.payload,
|
|
87
|
+
_path2 = _action$payload2.path,
|
|
88
|
+
_rule = _action$payload2.rule;
|
|
89
|
+
var _newRuleGroup2 = addRuleAtPath(state.ruleGroup, _path2, _rule);
|
|
90
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
91
|
+
ruleGroup: _newRuleGroup2,
|
|
92
|
+
isDirty: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
case 'UPDATE_RULE_GROUP':
|
|
96
|
+
{
|
|
97
|
+
var _action$payload3 = action.payload,
|
|
98
|
+
_path3 = _action$payload3.path,
|
|
99
|
+
group = _action$payload3.group;
|
|
100
|
+
var _newRuleGroup3 = updateRuleGroupAtPath(state.ruleGroup, _path3, group);
|
|
101
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
102
|
+
ruleGroup: _newRuleGroup3,
|
|
103
|
+
isDirty: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
case 'DELETE_RULE_GROUP':
|
|
107
|
+
{
|
|
108
|
+
var _path4 = action.payload.path;
|
|
109
|
+
var _newRuleGroup4 = deleteRuleGroupAtPath(state.ruleGroup, _path4);
|
|
110
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
111
|
+
ruleGroup: _newRuleGroup4,
|
|
112
|
+
isDirty: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
case 'ADD_RULE_GROUP':
|
|
116
|
+
{
|
|
117
|
+
var _action$payload4 = action.payload,
|
|
118
|
+
_path5 = _action$payload4.path,
|
|
119
|
+
_group = _action$payload4.group;
|
|
120
|
+
var _newRuleGroup5 = addRuleGroupAtPath(state.ruleGroup, _path5, _group);
|
|
121
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
122
|
+
ruleGroup: _newRuleGroup5,
|
|
123
|
+
isDirty: true
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
case 'SET_VALIDATION_RESULT':
|
|
127
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
128
|
+
validationResult: action.payload
|
|
129
|
+
});
|
|
130
|
+
case 'RESET':
|
|
131
|
+
{
|
|
132
|
+
return createInitialState(undefined, state.fields);
|
|
133
|
+
}
|
|
134
|
+
default:
|
|
135
|
+
return state;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Context 类型定义
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Context 对象
|
|
145
|
+
*/
|
|
146
|
+
var RuleBuilderContext = /*#__PURE__*/createContext(undefined);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Provider Props
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* RuleBuilder Provider 组件
|
|
154
|
+
*/
|
|
155
|
+
export function RuleBuilderProvider(_ref) {
|
|
156
|
+
var children = _ref.children,
|
|
157
|
+
initialRule = _ref.initialRule,
|
|
158
|
+
fields = _ref.fields;
|
|
159
|
+
var _useReducer = useReducer(ruleBuilderReducer, createInitialState(initialRule, fields)),
|
|
160
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
161
|
+
state = _useReducer2[0],
|
|
162
|
+
dispatch = _useReducer2[1];
|
|
163
|
+
|
|
164
|
+
// 监听fields变化,同步更新到state
|
|
165
|
+
React.useEffect(function () {
|
|
166
|
+
dispatch({
|
|
167
|
+
type: 'SET_FIELDS',
|
|
168
|
+
payload: fields
|
|
169
|
+
});
|
|
170
|
+
}, [fields]);
|
|
171
|
+
|
|
172
|
+
// 使用 useMemo 避免不必要的重渲染
|
|
173
|
+
var contextValue = useMemo(function () {
|
|
174
|
+
return {
|
|
175
|
+
state: state,
|
|
176
|
+
dispatch: dispatch
|
|
177
|
+
};
|
|
178
|
+
}, [state]);
|
|
179
|
+
return /*#__PURE__*/React.createElement(RuleBuilderContext.Provider, {
|
|
180
|
+
value: contextValue
|
|
181
|
+
}, children);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 使用 RuleBuilder Context 的 Hook
|
|
186
|
+
* @throws {Error} 如果在 Provider 外部使用
|
|
187
|
+
*/
|
|
188
|
+
export function useRuleBuilderContext() {
|
|
189
|
+
var context = useContext(RuleBuilderContext);
|
|
190
|
+
if (context === undefined) {
|
|
191
|
+
throw new Error('useRuleBuilderContext 必须在 RuleBuilderProvider 内部使用');
|
|
192
|
+
}
|
|
193
|
+
return context;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 便捷 Hook: 获取当前规则组
|
|
198
|
+
*/
|
|
199
|
+
export function useRuleGroup() {
|
|
200
|
+
var _useRuleBuilderContex = useRuleBuilderContext(),
|
|
201
|
+
state = _useRuleBuilderContex.state;
|
|
202
|
+
return state.ruleGroup;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 便捷 Hook: 获取字段列表
|
|
207
|
+
*/
|
|
208
|
+
export function useFields() {
|
|
209
|
+
var _useRuleBuilderContex2 = useRuleBuilderContext(),
|
|
210
|
+
state = _useRuleBuilderContex2.state;
|
|
211
|
+
return state.fields;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 便捷 Hook: 获取加载状态
|
|
216
|
+
*/
|
|
217
|
+
export function useLoading() {
|
|
218
|
+
var _useRuleBuilderContex3 = useRuleBuilderContext(),
|
|
219
|
+
state = _useRuleBuilderContex3.state;
|
|
220
|
+
return state.loading;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 便捷 Hook: 获取验证结果
|
|
225
|
+
*/
|
|
226
|
+
export function useValidation() {
|
|
227
|
+
var _useRuleBuilderContex4 = useRuleBuilderContext(),
|
|
228
|
+
state = _useRuleBuilderContex4.state;
|
|
229
|
+
return state.validationResult;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 便捷 Hook: 获取修改状态
|
|
234
|
+
*/
|
|
235
|
+
export function useIsDirty() {
|
|
236
|
+
var _useRuleBuilderContex5 = useRuleBuilderContext(),
|
|
237
|
+
state = _useRuleBuilderContex5.state;
|
|
238
|
+
return state.isDirty;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 便捷 Hook: 获取 state
|
|
243
|
+
*/
|
|
244
|
+
export function useRuleBuilderState() {
|
|
245
|
+
var _useRuleBuilderContex6 = useRuleBuilderContext(),
|
|
246
|
+
state = _useRuleBuilderContex6.state;
|
|
247
|
+
return state;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* 便捷 Hook: 获取 dispatch
|
|
252
|
+
*/
|
|
253
|
+
export function useRuleBuilderDispatch() {
|
|
254
|
+
var _useRuleBuilderContex7 = useRuleBuilderContext(),
|
|
255
|
+
dispatch = _useRuleBuilderContex7.dispatch;
|
|
256
|
+
return dispatch;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 便捷 Hook: 获取字段列表(别名,与 useFields 相同)
|
|
261
|
+
*/
|
|
262
|
+
export function useRuleBuilderFields() {
|
|
263
|
+
return useFields();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 便捷 Hook: 获取验证结果(别名,与 useValidation 相同)
|
|
268
|
+
*/
|
|
269
|
+
export function useRuleBuilderValidation() {
|
|
270
|
+
return useValidation();
|
|
271
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RuleBuilder 规则构建器组件
|
|
3
|
+
*
|
|
4
|
+
* 主导出文件 - 导出所有公共 API
|
|
5
|
+
*
|
|
6
|
+
* @module RuleBuilder
|
|
7
|
+
*/
|
|
8
|
+
export { RuleBuilderContainer as RuleBuilder } from './RuleBuilderContainer';
|
|
9
|
+
export { RuleBuilderContainer } from './RuleBuilderContainer';
|
|
10
|
+
export { RuleGroupEditor } from './RuleGroupEditor';
|
|
11
|
+
export { RuleCard } from './RuleCard';
|
|
12
|
+
export { LogicSelector } from './LogicSelector';
|
|
13
|
+
export { FieldSelector } from './selectors/FieldSelector';
|
|
14
|
+
export { OperatorSelector } from './selectors/OperatorSelector';
|
|
15
|
+
export { ValueInput } from './inputs/ValueInput';
|
|
16
|
+
export { SingleValueInput } from './inputs/SingleValueInput';
|
|
17
|
+
export { BetweenValueInput } from './inputs/BetweenValueInput';
|
|
18
|
+
export { MultiValueInput } from './inputs/MultiValueInput';
|
|
19
|
+
export { RuleBuilderProvider, useRuleBuilderContext, useRuleBuilderState, useRuleBuilderDispatch, useRuleBuilderFields, useRuleBuilderValidation, useRuleGroup, useFields, useLoading, useValidation, useIsDirty, } from './context/RuleBuilderContext';
|
|
20
|
+
export { createEmptyRule, createEmptyRuleGroup, generateRuleDescription, cloneRuleGroup, isRuleGroupEmpty, countRules, getMaxDepth, } from './utils/ruleHelpers';
|
|
21
|
+
export { getRuleGroupByPath, getRuleByPath, updateRuleAtPath, deleteRuleAtPath, addRuleAtPath, updateRuleGroupAtPath, deleteRuleGroupAtPath, addRuleGroupAtPath, } from './utils/pathHelpers';
|
|
22
|
+
export { validateRuleGroup, validateRule, isRuleGroupValid, } from './utils/validation';
|
|
23
|
+
export { OPERATOR_INFO_MAP, getOperatorInfo, operatorRequiresValue, operatorRequiresValue2, operatorRequiresMultiValue, getOperatorsByDataType, MAX_NESTING_LEVEL, } from './constants/operators';
|
|
24
|
+
export type { MatchOperator, MatchLogic, FieldDataType, RuleDto, RuleGroupDto, FieldDefinition, ValidationResult, ValidationError, RuleBuilderProps, RuleBuilderConfig, RulePath, RuleBuilderState, RuleBuilderAction, OperatorInfo, } from './types';
|
|
25
|
+
export { RuleBuilderContainer as default } from './RuleBuilderContainer';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RuleBuilder 规则构建器组件
|
|
3
|
+
*
|
|
4
|
+
* 主导出文件 - 导出所有公共 API
|
|
5
|
+
*
|
|
6
|
+
* @module RuleBuilder
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ============ 主组件 ============
|
|
10
|
+
export { RuleBuilderContainer as RuleBuilder } from "./RuleBuilderContainer";
|
|
11
|
+
export { RuleBuilderContainer } from "./RuleBuilderContainer";
|
|
12
|
+
|
|
13
|
+
// ============ 子组件 ============
|
|
14
|
+
export { RuleGroupEditor } from "./RuleGroupEditor";
|
|
15
|
+
export { RuleCard } from "./RuleCard";
|
|
16
|
+
export { LogicSelector } from "./LogicSelector";
|
|
17
|
+
|
|
18
|
+
// ============ 选择器组件 ============
|
|
19
|
+
export { FieldSelector } from "./selectors/FieldSelector";
|
|
20
|
+
export { OperatorSelector } from "./selectors/OperatorSelector";
|
|
21
|
+
|
|
22
|
+
// ============ 值输入组件 ============
|
|
23
|
+
export { ValueInput } from "./inputs/ValueInput";
|
|
24
|
+
export { SingleValueInput } from "./inputs/SingleValueInput";
|
|
25
|
+
export { BetweenValueInput } from "./inputs/BetweenValueInput";
|
|
26
|
+
export { MultiValueInput } from "./inputs/MultiValueInput";
|
|
27
|
+
|
|
28
|
+
// ============ Context & Hooks ============
|
|
29
|
+
export { RuleBuilderProvider, useRuleBuilderContext, useRuleBuilderState, useRuleBuilderDispatch, useRuleBuilderFields, useRuleBuilderValidation, useRuleGroup, useFields, useLoading, useValidation, useIsDirty } from "./context/RuleBuilderContext";
|
|
30
|
+
|
|
31
|
+
// ============ 工具函数 ============
|
|
32
|
+
export { createEmptyRule, createEmptyRuleGroup, generateRuleDescription, cloneRuleGroup, isRuleGroupEmpty, countRules, getMaxDepth } from "./utils/ruleHelpers";
|
|
33
|
+
export { getRuleGroupByPath, getRuleByPath, updateRuleAtPath, deleteRuleAtPath, addRuleAtPath, updateRuleGroupAtPath, deleteRuleGroupAtPath, addRuleGroupAtPath } from "./utils/pathHelpers";
|
|
34
|
+
export { validateRuleGroup, validateRule, isRuleGroupValid } from "./utils/validation";
|
|
35
|
+
|
|
36
|
+
// ============ 常量 ============
|
|
37
|
+
export { OPERATOR_INFO_MAP, getOperatorInfo, operatorRequiresValue, operatorRequiresValue2, operatorRequiresMultiValue, getOperatorsByDataType, MAX_NESTING_LEVEL } from "./constants/operators";
|
|
38
|
+
|
|
39
|
+
// ============ 类型定义 ============
|
|
40
|
+
|
|
41
|
+
// ============ 默认导出 ============
|
|
42
|
+
export { RuleBuilderContainer as default } from "./RuleBuilderContainer";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 区间值输入组件
|
|
3
|
+
*
|
|
4
|
+
* 用于 Between 操作符,渲染两个输入框(最小值和最大值)
|
|
5
|
+
* 支持数值和日期类型
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
export interface BetweenValueInputProps {
|
|
9
|
+
/** 最小值 */
|
|
10
|
+
value: any;
|
|
11
|
+
/** 最大值 */
|
|
12
|
+
value2: any;
|
|
13
|
+
/** 值变更回调 */
|
|
14
|
+
onChange: (value: any, value2: any) => void;
|
|
15
|
+
/** 字段数据类型 */
|
|
16
|
+
dataType: 'number' | 'date';
|
|
17
|
+
/** 是否禁用 */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** 尺寸 */
|
|
20
|
+
size?: 'small' | 'middle' | 'large';
|
|
21
|
+
}
|
|
22
|
+
export declare const BetweenValueInput: React.FC<BetweenValueInputProps>;
|
|
23
|
+
export default BetweenValueInput;
|