@nokecy/qc-ui 1.0.66 → 1.0.68
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/ag-grid-plus/hooks/useGridPlusColumnState.d.ts +12 -0
- package/dist/cjs/ag-grid-plus/hooks/useGridPlusColumnState.js +15 -0
- package/dist/cjs/ag-grid-plus/index.d.ts +2 -9
- package/dist/cjs/ag-grid-plus/index.js +8 -6
- package/dist/cjs/ag-grid-plus/setting/index.js +2 -2
- package/dist/cjs/array-table/columnHelper.d.ts +126 -0
- package/dist/cjs/array-table/columnHelper.js +241 -0
- package/dist/cjs/array-table/hooks.d.ts +23 -0
- package/dist/cjs/array-table/hooks.js +230 -0
- package/dist/cjs/array-table/index.js +141 -208
- package/dist/cjs/components/RegexEditor/core/RegexEditor.d.ts +34 -0
- package/dist/cjs/components/RegexEditor/core/RegexEditor.js +223 -0
- package/dist/cjs/components/RegexEditor/core/RegexEditor.less +119 -0
- package/dist/cjs/components/RegexEditor/core/extensions/errorMarker.d.ts +49 -0
- package/dist/cjs/components/RegexEditor/core/extensions/errorMarker.js +158 -0
- package/dist/cjs/components/RegexEditor/core/types.d.ts +79 -0
- package/dist/cjs/components/RegexEditor/core/types.js +5 -0
- package/dist/cjs/components/RegexEditor/hooks/index.d.ts +9 -0
- package/dist/cjs/components/RegexEditor/hooks/index.js +19 -0
- package/dist/cjs/components/RegexEditor/hooks/useRegexTester.d.ts +95 -0
- package/dist/cjs/components/RegexEditor/hooks/useRegexTester.js +234 -0
- package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.d.ts +71 -0
- package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.js +215 -0
- package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.d.ts +64 -0
- package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.js +438 -0
- package/dist/cjs/components/RegexEditor/index.d.ts +16 -0
- package/dist/cjs/components/RegexEditor/index.js +232 -0
- package/dist/cjs/components/RegexEditor/templates/TemplateSelector.d.ts +36 -0
- package/dist/cjs/components/RegexEditor/templates/TemplateSelector.js +322 -0
- package/dist/cjs/components/RegexEditor/templates/builtinTemplates.d.ts +36 -0
- package/dist/cjs/components/RegexEditor/templates/builtinTemplates.js +340 -0
- package/dist/cjs/components/RegexEditor/templates/index.d.ts +10 -0
- package/dist/cjs/components/RegexEditor/templates/index.js +184 -0
- package/dist/cjs/components/RegexEditor/templates/storage.d.ts +74 -0
- package/dist/cjs/components/RegexEditor/templates/storage.js +337 -0
- package/dist/cjs/components/RegexEditor/templates/templateManager.d.ts +67 -0
- package/dist/cjs/components/RegexEditor/templates/templateManager.js +277 -0
- package/dist/cjs/components/RegexEditor/templates/types.d.ts +111 -0
- package/dist/cjs/components/RegexEditor/templates/types.js +94 -0
- package/dist/cjs/components/RegexEditor/testing/types.d.ts +55 -0
- package/dist/cjs/components/RegexEditor/testing/types.js +5 -0
- package/dist/cjs/components/RegexEditor/validation/complexity.d.ts +22 -0
- package/dist/cjs/components/RegexEditor/validation/complexity.js +196 -0
- package/dist/cjs/components/RegexEditor/validation/parser.d.ts +53 -0
- package/dist/cjs/components/RegexEditor/validation/parser.js +129 -0
- package/dist/cjs/components/RegexEditor/validation/types.d.ts +146 -0
- package/dist/cjs/components/RegexEditor/validation/types.js +5 -0
- package/dist/cjs/components/RegexEditor/validation/validator.d.ts +60 -0
- package/dist/cjs/components/RegexEditor/validation/validator.js +218 -0
- package/dist/cjs/components/RegexEditor/visualizer/FlagsSelector.d.ts +20 -0
- package/dist/cjs/components/RegexEditor/visualizer/FlagsSelector.js +98 -0
- package/dist/cjs/components/RegexEditor/visualizer/MatchItem.d.ts +25 -0
- package/dist/cjs/components/RegexEditor/visualizer/MatchItem.js +201 -0
- package/dist/cjs/components/RegexEditor/visualizer/RegexRailroadDiagram.d.ts +32 -0
- package/dist/cjs/components/RegexEditor/visualizer/RegexRailroadDiagram.js +192 -0
- package/dist/cjs/components/RegexEditor/visualizer/RegexTester.d.ts +22 -0
- package/dist/cjs/components/RegexEditor/visualizer/RegexTester.js +255 -0
- package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.d.ts +19 -0
- package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.js +155 -0
- package/dist/cjs/components/RegexEditor/visualizer/index.d.ts +12 -0
- package/dist/cjs/components/RegexEditor/visualizer/index.js +76 -0
- package/dist/cjs/components/RegexEditor/visualizer/types.d.ts +131 -0
- package/dist/cjs/components/RegexEditor/visualizer/types.js +5 -0
- package/dist/cjs/components/RegexEditor/visualizer/utils.d.ts +106 -0
- package/dist/cjs/components/RegexEditor/visualizer/utils.js +268 -0
- package/dist/cjs/index.d.ts +6 -2
- package/dist/cjs/index.js +68 -0
- package/dist/cjs/standardFormDialog/useStandardFormSchema.d.ts +1 -1
- package/dist/cjs/standardFormDialog/withStandardForm.d.ts +2 -2
- package/dist/cjs/types/railroad-diagrams.d.ts +59 -0
- package/dist/cjs/types/regexp-tree.d.ts +175 -0
- package/dist/esm/ag-grid-plus/hooks/useGridPlusColumnState.d.ts +12 -0
- package/dist/esm/ag-grid-plus/hooks/useGridPlusColumnState.js +10 -0
- package/dist/esm/ag-grid-plus/index.d.ts +2 -9
- package/dist/esm/ag-grid-plus/index.js +2 -5
- package/dist/esm/ag-grid-plus/setting/index.js +1 -1
- package/dist/esm/array-table/columnHelper.d.ts +126 -0
- package/dist/esm/array-table/columnHelper.js +235 -0
- package/dist/esm/array-table/hooks.d.ts +23 -0
- package/dist/esm/array-table/hooks.js +224 -0
- package/dist/esm/array-table/index.js +142 -209
- package/dist/esm/components/RegexEditor/core/RegexEditor.d.ts +34 -0
- package/dist/esm/components/RegexEditor/core/RegexEditor.js +214 -0
- package/dist/esm/components/RegexEditor/core/RegexEditor.less +119 -0
- package/dist/esm/components/RegexEditor/core/extensions/errorMarker.d.ts +49 -0
- package/dist/esm/components/RegexEditor/core/extensions/errorMarker.js +154 -0
- package/dist/esm/components/RegexEditor/core/types.d.ts +79 -0
- package/dist/esm/components/RegexEditor/core/types.js +1 -0
- package/dist/esm/components/RegexEditor/hooks/index.d.ts +9 -0
- package/dist/esm/components/RegexEditor/hooks/index.js +8 -0
- package/dist/esm/components/RegexEditor/hooks/useRegexTester.d.ts +95 -0
- package/dist/esm/components/RegexEditor/hooks/useRegexTester.js +230 -0
- package/dist/esm/components/RegexEditor/hooks/useRegexValidation.d.ts +71 -0
- package/dist/esm/components/RegexEditor/hooks/useRegexValidation.js +211 -0
- package/dist/esm/components/RegexEditor/hooks/useTemplateManager.d.ts +64 -0
- package/dist/esm/components/RegexEditor/hooks/useTemplateManager.js +430 -0
- package/dist/esm/components/RegexEditor/index.d.ts +16 -0
- package/dist/esm/components/RegexEditor/index.js +27 -0
- package/dist/esm/components/RegexEditor/templates/TemplateSelector.d.ts +36 -0
- package/dist/esm/components/RegexEditor/templates/TemplateSelector.js +316 -0
- package/dist/esm/components/RegexEditor/templates/builtinTemplates.d.ts +36 -0
- package/dist/esm/components/RegexEditor/templates/builtinTemplates.js +335 -0
- package/dist/esm/components/RegexEditor/templates/index.d.ts +10 -0
- package/dist/esm/components/RegexEditor/templates/index.js +19 -0
- package/dist/esm/components/RegexEditor/templates/storage.d.ts +74 -0
- package/dist/esm/components/RegexEditor/templates/storage.js +335 -0
- package/dist/esm/components/RegexEditor/templates/templateManager.d.ts +67 -0
- package/dist/esm/components/RegexEditor/templates/templateManager.js +274 -0
- package/dist/esm/components/RegexEditor/templates/types.d.ts +111 -0
- package/dist/esm/components/RegexEditor/templates/types.js +90 -0
- package/dist/esm/components/RegexEditor/testing/types.d.ts +55 -0
- package/dist/esm/components/RegexEditor/testing/types.js +1 -0
- package/dist/esm/components/RegexEditor/validation/complexity.d.ts +22 -0
- package/dist/esm/components/RegexEditor/validation/complexity.js +190 -0
- package/dist/esm/components/RegexEditor/validation/parser.d.ts +53 -0
- package/dist/esm/components/RegexEditor/validation/parser.js +123 -0
- package/dist/esm/components/RegexEditor/validation/types.d.ts +145 -0
- package/dist/esm/components/RegexEditor/validation/types.js +1 -0
- package/dist/esm/components/RegexEditor/validation/validator.d.ts +60 -0
- package/dist/esm/components/RegexEditor/validation/validator.js +213 -0
- package/dist/esm/components/RegexEditor/visualizer/FlagsSelector.d.ts +20 -0
- package/dist/esm/components/RegexEditor/visualizer/FlagsSelector.js +93 -0
- package/dist/esm/components/RegexEditor/visualizer/MatchItem.d.ts +25 -0
- package/dist/esm/components/RegexEditor/visualizer/MatchItem.js +194 -0
- package/dist/esm/components/RegexEditor/visualizer/RegexRailroadDiagram.d.ts +32 -0
- package/dist/esm/components/RegexEditor/visualizer/RegexRailroadDiagram.js +186 -0
- package/dist/esm/components/RegexEditor/visualizer/RegexTester.d.ts +22 -0
- package/dist/esm/components/RegexEditor/visualizer/RegexTester.js +248 -0
- package/dist/esm/components/RegexEditor/visualizer/astToRailroad.d.ts +18 -0
- package/dist/esm/components/RegexEditor/visualizer/astToRailroad.js +150 -0
- package/dist/esm/components/RegexEditor/visualizer/index.d.ts +12 -0
- package/dist/esm/components/RegexEditor/visualizer/index.js +17 -0
- package/dist/esm/components/RegexEditor/visualizer/types.d.ts +131 -0
- package/dist/esm/components/RegexEditor/visualizer/types.js +1 -0
- package/dist/esm/components/RegexEditor/visualizer/utils.d.ts +106 -0
- package/dist/esm/components/RegexEditor/visualizer/utils.js +256 -0
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +7 -3
- package/dist/esm/types/railroad-diagrams.d.ts +59 -0
- package/dist/esm/types/regexp-tree.d.ts +175 -0
- package/dist/umd/qc-ui.min.css +1 -1
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +23 -7
|
@@ -0,0 +1,274 @@
|
|
|
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 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; }
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
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); }
|
|
10
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
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; }
|
|
13
|
+
/**
|
|
14
|
+
* 模板管理器
|
|
15
|
+
* 统一管理内置模板和自定义模板
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { TemplateCategory } from "./types";
|
|
19
|
+
import { getAllBuiltinTemplates, getTemplateById as getBuiltinById } from "./builtinTemplates";
|
|
20
|
+
import { TemplateStorage } from "./storage";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取所有模板(内置 + 自定义)
|
|
24
|
+
*/
|
|
25
|
+
export var getAllTemplates = function getAllTemplates() {
|
|
26
|
+
var builtinTemplates = getAllBuiltinTemplates();
|
|
27
|
+
var customTemplates = TemplateStorage.loadCustomTemplates();
|
|
28
|
+
return [].concat(_toConsumableArray(builtinTemplates), _toConsumableArray(customTemplates));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 根据 ID 获取模板(优先查找自定义模板)
|
|
33
|
+
*/
|
|
34
|
+
export var getTemplateById = function getTemplateById(id) {
|
|
35
|
+
// 先查找自定义模板
|
|
36
|
+
var customTemplates = TemplateStorage.loadCustomTemplates();
|
|
37
|
+
var customTemplate = customTemplates.find(function (t) {
|
|
38
|
+
return t.id === id;
|
|
39
|
+
});
|
|
40
|
+
if (customTemplate) {
|
|
41
|
+
return customTemplate;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 再查找内置模板
|
|
45
|
+
return getBuiltinById(id);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 根据分类获取模板
|
|
50
|
+
*/
|
|
51
|
+
export var getTemplatesByCategory = function getTemplatesByCategory(category) {
|
|
52
|
+
var allTemplates = getAllTemplates();
|
|
53
|
+
return allTemplates.filter(function (t) {
|
|
54
|
+
return t.category === category;
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 搜索模板(支持关键词搜索)
|
|
60
|
+
*/
|
|
61
|
+
export var searchTemplates = function searchTemplates(keyword) {
|
|
62
|
+
if (!keyword.trim()) {
|
|
63
|
+
return getAllTemplates();
|
|
64
|
+
}
|
|
65
|
+
var allTemplates = getAllTemplates();
|
|
66
|
+
var lowerKeyword = keyword.toLowerCase();
|
|
67
|
+
return allTemplates.filter(function (t) {
|
|
68
|
+
return t.name.toLowerCase().includes(lowerKeyword) || t.description.toLowerCase().includes(lowerKeyword) || t.tags.some(function (tag) {
|
|
69
|
+
return tag.toLowerCase().includes(lowerKeyword);
|
|
70
|
+
}) || t.pattern.toLowerCase().includes(lowerKeyword);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 获取最常用的模板
|
|
76
|
+
*/
|
|
77
|
+
export var getMostUsedTemplates = function getMostUsedTemplates() {
|
|
78
|
+
var limit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
79
|
+
var allTemplates = getAllTemplates();
|
|
80
|
+
return allTemplates.filter(function (t) {
|
|
81
|
+
return t.useCount && t.useCount > 0;
|
|
82
|
+
}).sort(function (a, b) {
|
|
83
|
+
return (b.useCount || 0) - (a.useCount || 0);
|
|
84
|
+
}).slice(0, limit);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 获取最近使用的模板
|
|
89
|
+
*/
|
|
90
|
+
export var getRecentlyUsedTemplates = function getRecentlyUsedTemplates() {
|
|
91
|
+
var limit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
92
|
+
var allTemplates = getAllTemplates();
|
|
93
|
+
return allTemplates.filter(function (t) {
|
|
94
|
+
return t.lastUsed;
|
|
95
|
+
}).sort(function (a, b) {
|
|
96
|
+
var _a$lastUsed, _b$lastUsed;
|
|
97
|
+
var timeA = ((_a$lastUsed = a.lastUsed) === null || _a$lastUsed === void 0 ? void 0 : _a$lastUsed.getTime()) || 0;
|
|
98
|
+
var timeB = ((_b$lastUsed = b.lastUsed) === null || _b$lastUsed === void 0 ? void 0 : _b$lastUsed.getTime()) || 0;
|
|
99
|
+
return timeB - timeA;
|
|
100
|
+
}).slice(0, limit);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 创建新的自定义模板
|
|
105
|
+
*/
|
|
106
|
+
export var createCustomTemplate = function createCustomTemplate(template) {
|
|
107
|
+
var newTemplate = _objectSpread(_objectSpread({}, template), {}, {
|
|
108
|
+
id: "custom_".concat(Date.now(), "_").concat(Math.random().toString(36).substr(2, 9)),
|
|
109
|
+
category: template.category || TemplateCategory.CUSTOM,
|
|
110
|
+
isCustom: true,
|
|
111
|
+
useCount: 0
|
|
112
|
+
});
|
|
113
|
+
TemplateStorage.saveCustomTemplate(newTemplate);
|
|
114
|
+
return newTemplate;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 更新自定义模板
|
|
119
|
+
*/
|
|
120
|
+
export var updateCustomTemplate = function updateCustomTemplate(id, updates) {
|
|
121
|
+
var template = getTemplateById(id);
|
|
122
|
+
if (!template || !template.isCustom) {
|
|
123
|
+
console.error('只能更新自定义模板');
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
var updatedTemplate = _objectSpread(_objectSpread(_objectSpread({}, template), updates), {}, {
|
|
127
|
+
id: template.id,
|
|
128
|
+
// 保持 ID 不变
|
|
129
|
+
isCustom: true // 保持自定义标记
|
|
130
|
+
});
|
|
131
|
+
return TemplateStorage.saveCustomTemplate(updatedTemplate);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 删除自定义模板
|
|
136
|
+
*/
|
|
137
|
+
export var deleteCustomTemplate = function deleteCustomTemplate(id) {
|
|
138
|
+
var template = getTemplateById(id);
|
|
139
|
+
if (!template || !template.isCustom) {
|
|
140
|
+
console.error('只能删除自定义模板');
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return TemplateStorage.deleteCustomTemplate(id);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 复制模板(创建副本)
|
|
148
|
+
*/
|
|
149
|
+
export var duplicateTemplate = function duplicateTemplate(id, newName) {
|
|
150
|
+
var template = getTemplateById(id);
|
|
151
|
+
if (!template) {
|
|
152
|
+
console.error('模板不存在');
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
var duplicated = {
|
|
156
|
+
name: newName || "".concat(template.name, " (\u526F\u672C)"),
|
|
157
|
+
pattern: template.pattern,
|
|
158
|
+
description: template.description,
|
|
159
|
+
category: template.category,
|
|
160
|
+
tags: _toConsumableArray(template.tags),
|
|
161
|
+
examples: {
|
|
162
|
+
valid: _toConsumableArray(template.examples.valid),
|
|
163
|
+
invalid: _toConsumableArray(template.examples.invalid)
|
|
164
|
+
},
|
|
165
|
+
complexity: template.complexity
|
|
166
|
+
};
|
|
167
|
+
return createCustomTemplate(duplicated);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 使用模板(更新使用统计)
|
|
172
|
+
*/
|
|
173
|
+
export var useTemplate = function useTemplate(id) {
|
|
174
|
+
var template = getTemplateById(id);
|
|
175
|
+
if (!template) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 如果是自定义模板,更新使用统计
|
|
180
|
+
if (template.isCustom) {
|
|
181
|
+
TemplateStorage.updateTemplateUsage(id);
|
|
182
|
+
// 重新获取更新后的模板
|
|
183
|
+
return getTemplateById(id);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 内置模板不更新统计,直接返回
|
|
187
|
+
return template;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 获取模板统计信息
|
|
192
|
+
*/
|
|
193
|
+
export var getTemplateStats = function getTemplateStats() {
|
|
194
|
+
var allTemplates = getAllTemplates();
|
|
195
|
+
var builtinCount = getAllBuiltinTemplates().length;
|
|
196
|
+
var customCount = allTemplates.length - builtinCount;
|
|
197
|
+
var byCategory = {};
|
|
198
|
+
var byComplexity = {
|
|
199
|
+
simple: 0,
|
|
200
|
+
medium: 0,
|
|
201
|
+
complex: 0
|
|
202
|
+
};
|
|
203
|
+
allTemplates.forEach(function (t) {
|
|
204
|
+
// 按分类统计
|
|
205
|
+
byCategory[t.category] = (byCategory[t.category] || 0) + 1;
|
|
206
|
+
|
|
207
|
+
// 按复杂度统计
|
|
208
|
+
byComplexity[t.complexity] += 1;
|
|
209
|
+
});
|
|
210
|
+
return {
|
|
211
|
+
total: allTemplates.length,
|
|
212
|
+
builtin: builtinCount,
|
|
213
|
+
custom: customCount,
|
|
214
|
+
byCategory: byCategory,
|
|
215
|
+
byComplexity: byComplexity
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 验证模板是否有效
|
|
221
|
+
*/
|
|
222
|
+
export var validateTemplate = function validateTemplate(template) {
|
|
223
|
+
var _template$name, _template$pattern, _template$description;
|
|
224
|
+
var errors = [];
|
|
225
|
+
|
|
226
|
+
// 必填字段检查
|
|
227
|
+
if (!((_template$name = template.name) !== null && _template$name !== void 0 && _template$name.trim())) {
|
|
228
|
+
errors.push('模板名称不能为空');
|
|
229
|
+
}
|
|
230
|
+
if (!((_template$pattern = template.pattern) !== null && _template$pattern !== void 0 && _template$pattern.trim())) {
|
|
231
|
+
errors.push('正则表达式不能为空');
|
|
232
|
+
}
|
|
233
|
+
if (!((_template$description = template.description) !== null && _template$description !== void 0 && _template$description.trim())) {
|
|
234
|
+
errors.push('模板描述不能为空');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 正则表达式语法检查
|
|
238
|
+
if (template.pattern) {
|
|
239
|
+
try {
|
|
240
|
+
new RegExp(template.pattern);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
errors.push("\u6B63\u5219\u8868\u8FBE\u5F0F\u8BED\u6CD5\u9519\u8BEF: ".concat(e instanceof Error ? e.message : '未知错误'));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 分类检查
|
|
247
|
+
if (template.category && !Object.values(TemplateCategory).includes(template.category)) {
|
|
248
|
+
errors.push('无效的模板分类');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 标签检查
|
|
252
|
+
if (template.tags && !Array.isArray(template.tags)) {
|
|
253
|
+
errors.push('标签必须是数组');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 示例检查
|
|
257
|
+
if (template.examples) {
|
|
258
|
+
if (!Array.isArray(template.examples.valid)) {
|
|
259
|
+
errors.push('有效示例必须是数组');
|
|
260
|
+
}
|
|
261
|
+
if (!Array.isArray(template.examples.invalid)) {
|
|
262
|
+
errors.push('无效示例必须是数组');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 复杂度检查
|
|
267
|
+
if (template.complexity && !['simple', 'medium', 'complex'].includes(template.complexity)) {
|
|
268
|
+
errors.push('无效的复杂度级别');
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
valid: errors.length === 0,
|
|
272
|
+
errors: errors
|
|
273
|
+
};
|
|
274
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式模板系统 - 类型定义
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/templates/types
|
|
5
|
+
* @description 定义正则表达式模板库相关的核心类型
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 正则表达式模板
|
|
9
|
+
*
|
|
10
|
+
* @interface RegexTemplate
|
|
11
|
+
* @property {string} id - 模板唯一标识符
|
|
12
|
+
* @property {string} name - 模板名称(显示用)
|
|
13
|
+
* @property {string} pattern - 正则表达式字符串
|
|
14
|
+
* @property {string} description - 模板详细描述
|
|
15
|
+
* @property {TemplateCategory} category - 模板分类
|
|
16
|
+
* @property {string[]} tags - 标签列表(用于搜索和过滤)
|
|
17
|
+
* @property {Object} examples - 匹配示例
|
|
18
|
+
* @property {string[]} examples.valid - 有效匹配示例
|
|
19
|
+
* @property {string[]} examples.invalid - 无效匹配示例
|
|
20
|
+
* @property {'simple' | 'medium' | 'complex'} complexity - 复杂度等级
|
|
21
|
+
* @property {number} [useCount] - 使用次数(用于热门排序)
|
|
22
|
+
* @property {Date} [lastUsed] - 最后使用时间
|
|
23
|
+
* @property {boolean} [isCustom] - 是否为用户自定义模板
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const lotNumberTemplate: RegexTemplate = {
|
|
28
|
+
* id: 'lot-number',
|
|
29
|
+
* name: '批次号',
|
|
30
|
+
* pattern: '^LOT\\d{6}$',
|
|
31
|
+
* description: '标准批次号格式:LOT + 6位数字',
|
|
32
|
+
* category: TemplateCategory.BUSINESS,
|
|
33
|
+
* tags: ['批次', 'LOT', '业务'],
|
|
34
|
+
* examples: {
|
|
35
|
+
* valid: ['LOT123456', 'LOT000001'],
|
|
36
|
+
* invalid: ['LOT12345', 'lot123456', 'LOT1234567']
|
|
37
|
+
* },
|
|
38
|
+
* complexity: 'simple',
|
|
39
|
+
* useCount: 42,
|
|
40
|
+
* lastUsed: new Date('2025-01-27'),
|
|
41
|
+
* isCustom: false
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface RegexTemplate {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
pattern: string;
|
|
49
|
+
description: string;
|
|
50
|
+
category: TemplateCategory;
|
|
51
|
+
tags: string[];
|
|
52
|
+
examples: {
|
|
53
|
+
valid: string[];
|
|
54
|
+
invalid: string[];
|
|
55
|
+
};
|
|
56
|
+
complexity: 'simple' | 'medium' | 'complex';
|
|
57
|
+
useCount?: number;
|
|
58
|
+
lastUsed?: Date;
|
|
59
|
+
isCustom?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 模板分类枚举
|
|
63
|
+
*
|
|
64
|
+
* @enum TemplateCategory
|
|
65
|
+
* @property {string} BUSINESS - 业务相关(批次号、订单号等)
|
|
66
|
+
* @property {string} COMMON - 通用模式(邮箱、电话等)
|
|
67
|
+
* @property {string} DATE_TIME - 日期时间格式
|
|
68
|
+
* @property {string} NUMBER - 数字格式(整数、小数、科学计数法等)
|
|
69
|
+
* @property {string} TEXT - 文本格式(中文、英文、特殊字符等)
|
|
70
|
+
* @property {string} VALIDATION - 数据验证(长度、范围等)
|
|
71
|
+
* @property {string} EXTRACTION - 数据提取(提取特定部分)
|
|
72
|
+
* @property {string} CUSTOM - 用户自定义
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // 按分类过滤模板
|
|
77
|
+
* const businessTemplates = allTemplates.filter(
|
|
78
|
+
* t => t.category === TemplateCategory.BUSINESS
|
|
79
|
+
* );
|
|
80
|
+
*
|
|
81
|
+
* // 获取分类显示名称
|
|
82
|
+
* const categoryNames = {
|
|
83
|
+
* [TemplateCategory.BUSINESS]: '业务模板',
|
|
84
|
+
* [TemplateCategory.COMMON]: '通用模板',
|
|
85
|
+
* [TemplateCategory.DATE_TIME]: '日期时间',
|
|
86
|
+
* [TemplateCategory.NUMBER]: '数字格式',
|
|
87
|
+
* [TemplateCategory.TEXT]: '文本格式',
|
|
88
|
+
* [TemplateCategory.VALIDATION]: '数据验证',
|
|
89
|
+
* [TemplateCategory.EXTRACTION]: '数据提取',
|
|
90
|
+
* [TemplateCategory.CUSTOM]: '自定义'
|
|
91
|
+
* };
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare enum TemplateCategory {
|
|
95
|
+
/** 业务相关模板 */
|
|
96
|
+
BUSINESS = "business",
|
|
97
|
+
/** 通用模式模板 */
|
|
98
|
+
COMMON = "common",
|
|
99
|
+
/** 日期时间格式 */
|
|
100
|
+
DATE_TIME = "datetime",
|
|
101
|
+
/** 数字格式 */
|
|
102
|
+
NUMBER = "number",
|
|
103
|
+
/** 文本格式 */
|
|
104
|
+
TEXT = "text",
|
|
105
|
+
/** 数据验证 */
|
|
106
|
+
VALIDATION = "validation",
|
|
107
|
+
/** 数据提取 */
|
|
108
|
+
EXTRACTION = "extraction",
|
|
109
|
+
/** 用户自定义 */
|
|
110
|
+
CUSTOM = "custom"
|
|
111
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式模板系统 - 类型定义
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/templates/types
|
|
5
|
+
* @description 定义正则表达式模板库相关的核心类型
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 正则表达式模板
|
|
10
|
+
*
|
|
11
|
+
* @interface RegexTemplate
|
|
12
|
+
* @property {string} id - 模板唯一标识符
|
|
13
|
+
* @property {string} name - 模板名称(显示用)
|
|
14
|
+
* @property {string} pattern - 正则表达式字符串
|
|
15
|
+
* @property {string} description - 模板详细描述
|
|
16
|
+
* @property {TemplateCategory} category - 模板分类
|
|
17
|
+
* @property {string[]} tags - 标签列表(用于搜索和过滤)
|
|
18
|
+
* @property {Object} examples - 匹配示例
|
|
19
|
+
* @property {string[]} examples.valid - 有效匹配示例
|
|
20
|
+
* @property {string[]} examples.invalid - 无效匹配示例
|
|
21
|
+
* @property {'simple' | 'medium' | 'complex'} complexity - 复杂度等级
|
|
22
|
+
* @property {number} [useCount] - 使用次数(用于热门排序)
|
|
23
|
+
* @property {Date} [lastUsed] - 最后使用时间
|
|
24
|
+
* @property {boolean} [isCustom] - 是否为用户自定义模板
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const lotNumberTemplate: RegexTemplate = {
|
|
29
|
+
* id: 'lot-number',
|
|
30
|
+
* name: '批次号',
|
|
31
|
+
* pattern: '^LOT\\d{6}$',
|
|
32
|
+
* description: '标准批次号格式:LOT + 6位数字',
|
|
33
|
+
* category: TemplateCategory.BUSINESS,
|
|
34
|
+
* tags: ['批次', 'LOT', '业务'],
|
|
35
|
+
* examples: {
|
|
36
|
+
* valid: ['LOT123456', 'LOT000001'],
|
|
37
|
+
* invalid: ['LOT12345', 'lot123456', 'LOT1234567']
|
|
38
|
+
* },
|
|
39
|
+
* complexity: 'simple',
|
|
40
|
+
* useCount: 42,
|
|
41
|
+
* lastUsed: new Date('2025-01-27'),
|
|
42
|
+
* isCustom: false
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 模板分类枚举
|
|
49
|
+
*
|
|
50
|
+
* @enum TemplateCategory
|
|
51
|
+
* @property {string} BUSINESS - 业务相关(批次号、订单号等)
|
|
52
|
+
* @property {string} COMMON - 通用模式(邮箱、电话等)
|
|
53
|
+
* @property {string} DATE_TIME - 日期时间格式
|
|
54
|
+
* @property {string} NUMBER - 数字格式(整数、小数、科学计数法等)
|
|
55
|
+
* @property {string} TEXT - 文本格式(中文、英文、特殊字符等)
|
|
56
|
+
* @property {string} VALIDATION - 数据验证(长度、范围等)
|
|
57
|
+
* @property {string} EXTRACTION - 数据提取(提取特定部分)
|
|
58
|
+
* @property {string} CUSTOM - 用户自定义
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // 按分类过滤模板
|
|
63
|
+
* const businessTemplates = allTemplates.filter(
|
|
64
|
+
* t => t.category === TemplateCategory.BUSINESS
|
|
65
|
+
* );
|
|
66
|
+
*
|
|
67
|
+
* // 获取分类显示名称
|
|
68
|
+
* const categoryNames = {
|
|
69
|
+
* [TemplateCategory.BUSINESS]: '业务模板',
|
|
70
|
+
* [TemplateCategory.COMMON]: '通用模板',
|
|
71
|
+
* [TemplateCategory.DATE_TIME]: '日期时间',
|
|
72
|
+
* [TemplateCategory.NUMBER]: '数字格式',
|
|
73
|
+
* [TemplateCategory.TEXT]: '文本格式',
|
|
74
|
+
* [TemplateCategory.VALIDATION]: '数据验证',
|
|
75
|
+
* [TemplateCategory.EXTRACTION]: '数据提取',
|
|
76
|
+
* [TemplateCategory.CUSTOM]: '自定义'
|
|
77
|
+
* };
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export var TemplateCategory = /*#__PURE__*/function (TemplateCategory) {
|
|
81
|
+
TemplateCategory["BUSINESS"] = "business";
|
|
82
|
+
TemplateCategory["COMMON"] = "common";
|
|
83
|
+
TemplateCategory["DATE_TIME"] = "datetime";
|
|
84
|
+
TemplateCategory["NUMBER"] = "number";
|
|
85
|
+
TemplateCategory["TEXT"] = "text";
|
|
86
|
+
TemplateCategory["VALIDATION"] = "validation";
|
|
87
|
+
TemplateCategory["EXTRACTION"] = "extraction";
|
|
88
|
+
TemplateCategory["CUSTOM"] = "custom";
|
|
89
|
+
return TemplateCategory;
|
|
90
|
+
}({});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式测试工具 - 类型定义
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/testing/types
|
|
5
|
+
* @description 定义正则表达式测试功能相关的核心类型
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 正则表达式测试结果
|
|
9
|
+
*
|
|
10
|
+
* @interface TestResult
|
|
11
|
+
* @property {string} input - 测试输入字符串
|
|
12
|
+
* @property {string[] | null} matches - 匹配结果数组(未匹配时为 null)
|
|
13
|
+
* @property {boolean} isMatch - 是否匹配成功
|
|
14
|
+
* @property {number} [executionTime] - 执行耗时(毫秒)
|
|
15
|
+
* @property {string} [error] - 执行错误信息(如果有)
|
|
16
|
+
* @property {Record<string, string>} [groups] - 命名捕获组结果
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // 成功匹配的结果
|
|
21
|
+
* const successResult: TestResult = {
|
|
22
|
+
* input: 'LOT123456',
|
|
23
|
+
* matches: ['LOT123456', '123456'],
|
|
24
|
+
* isMatch: true,
|
|
25
|
+
* executionTime: 0.42,
|
|
26
|
+
* groups: {
|
|
27
|
+
* number: '123456'
|
|
28
|
+
* }
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* // 未匹配的结果
|
|
32
|
+
* const failureResult: TestResult = {
|
|
33
|
+
* input: 'LOT12345',
|
|
34
|
+
* matches: null,
|
|
35
|
+
* isMatch: false,
|
|
36
|
+
* executionTime: 0.15
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* // 执行错误的结果
|
|
40
|
+
* const errorResult: TestResult = {
|
|
41
|
+
* input: 'test',
|
|
42
|
+
* matches: null,
|
|
43
|
+
* isMatch: false,
|
|
44
|
+
* error: 'Invalid regular expression'
|
|
45
|
+
* };
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface TestResult {
|
|
49
|
+
input: string;
|
|
50
|
+
matches: string[] | null;
|
|
51
|
+
isMatch: boolean;
|
|
52
|
+
executionTime?: number;
|
|
53
|
+
error?: string;
|
|
54
|
+
groups?: Record<string, string>;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式复杂度分析器
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/validation/complexity
|
|
5
|
+
* @description 分析正则表达式的复杂度,评估性能风险并提供优化建议
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* 该模块通过遍历 AST 来统计以下复杂度指标:
|
|
9
|
+
* - 节点总数
|
|
10
|
+
* - 最大嵌套深度
|
|
11
|
+
* - 分支数量(alternation)
|
|
12
|
+
* - 量词数量(quantifier)
|
|
13
|
+
* - 捕获组数量
|
|
14
|
+
* - 字符类数量
|
|
15
|
+
*
|
|
16
|
+
* 基于这些指标计算:
|
|
17
|
+
* - 回溯风险等级(low/medium/high)
|
|
18
|
+
* - 性能评分(0-100分)
|
|
19
|
+
* - 优化建议列表
|
|
20
|
+
*/
|
|
21
|
+
import type { ASTNode, ComplexityMetrics } from './types';
|
|
22
|
+
export declare const analyzeComplexity: (ast: ASTNode) => ComplexityMetrics;
|