@nokecy/qc-ui 1.0.66 → 1.0.67

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.
Files changed (123) hide show
  1. package/dist/cjs/components/RegexEditor/core/RegexEditor.d.ts +34 -0
  2. package/dist/cjs/components/RegexEditor/core/RegexEditor.js +223 -0
  3. package/dist/cjs/components/RegexEditor/core/RegexEditor.less +119 -0
  4. package/dist/cjs/components/RegexEditor/core/extensions/errorMarker.d.ts +49 -0
  5. package/dist/cjs/components/RegexEditor/core/extensions/errorMarker.js +158 -0
  6. package/dist/cjs/components/RegexEditor/core/types.d.ts +79 -0
  7. package/dist/cjs/components/RegexEditor/core/types.js +5 -0
  8. package/dist/cjs/components/RegexEditor/hooks/index.d.ts +9 -0
  9. package/dist/cjs/components/RegexEditor/hooks/index.js +19 -0
  10. package/dist/cjs/components/RegexEditor/hooks/useRegexTester.d.ts +95 -0
  11. package/dist/cjs/components/RegexEditor/hooks/useRegexTester.js +234 -0
  12. package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.d.ts +71 -0
  13. package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.js +215 -0
  14. package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.d.ts +64 -0
  15. package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.js +438 -0
  16. package/dist/cjs/components/RegexEditor/index.d.ts +16 -0
  17. package/dist/cjs/components/RegexEditor/index.js +232 -0
  18. package/dist/cjs/components/RegexEditor/templates/TemplateSelector.d.ts +36 -0
  19. package/dist/cjs/components/RegexEditor/templates/TemplateSelector.js +322 -0
  20. package/dist/cjs/components/RegexEditor/templates/builtinTemplates.d.ts +36 -0
  21. package/dist/cjs/components/RegexEditor/templates/builtinTemplates.js +340 -0
  22. package/dist/cjs/components/RegexEditor/templates/index.d.ts +10 -0
  23. package/dist/cjs/components/RegexEditor/templates/index.js +184 -0
  24. package/dist/cjs/components/RegexEditor/templates/storage.d.ts +74 -0
  25. package/dist/cjs/components/RegexEditor/templates/storage.js +337 -0
  26. package/dist/cjs/components/RegexEditor/templates/templateManager.d.ts +67 -0
  27. package/dist/cjs/components/RegexEditor/templates/templateManager.js +277 -0
  28. package/dist/cjs/components/RegexEditor/templates/types.d.ts +111 -0
  29. package/dist/cjs/components/RegexEditor/templates/types.js +94 -0
  30. package/dist/cjs/components/RegexEditor/testing/types.d.ts +55 -0
  31. package/dist/cjs/components/RegexEditor/testing/types.js +5 -0
  32. package/dist/cjs/components/RegexEditor/validation/complexity.d.ts +22 -0
  33. package/dist/cjs/components/RegexEditor/validation/complexity.js +196 -0
  34. package/dist/cjs/components/RegexEditor/validation/parser.d.ts +53 -0
  35. package/dist/cjs/components/RegexEditor/validation/parser.js +129 -0
  36. package/dist/cjs/components/RegexEditor/validation/types.d.ts +146 -0
  37. package/dist/cjs/components/RegexEditor/validation/types.js +5 -0
  38. package/dist/cjs/components/RegexEditor/validation/validator.d.ts +60 -0
  39. package/dist/cjs/components/RegexEditor/validation/validator.js +218 -0
  40. package/dist/cjs/components/RegexEditor/visualizer/FlagsSelector.d.ts +20 -0
  41. package/dist/cjs/components/RegexEditor/visualizer/FlagsSelector.js +98 -0
  42. package/dist/cjs/components/RegexEditor/visualizer/MatchItem.d.ts +25 -0
  43. package/dist/cjs/components/RegexEditor/visualizer/MatchItem.js +201 -0
  44. package/dist/cjs/components/RegexEditor/visualizer/RegexRailroadDiagram.d.ts +32 -0
  45. package/dist/cjs/components/RegexEditor/visualizer/RegexRailroadDiagram.js +192 -0
  46. package/dist/cjs/components/RegexEditor/visualizer/RegexTester.d.ts +22 -0
  47. package/dist/cjs/components/RegexEditor/visualizer/RegexTester.js +255 -0
  48. package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.d.ts +19 -0
  49. package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.js +155 -0
  50. package/dist/cjs/components/RegexEditor/visualizer/index.d.ts +12 -0
  51. package/dist/cjs/components/RegexEditor/visualizer/index.js +76 -0
  52. package/dist/cjs/components/RegexEditor/visualizer/types.d.ts +131 -0
  53. package/dist/cjs/components/RegexEditor/visualizer/types.js +5 -0
  54. package/dist/cjs/components/RegexEditor/visualizer/utils.d.ts +106 -0
  55. package/dist/cjs/components/RegexEditor/visualizer/utils.js +268 -0
  56. package/dist/cjs/index.d.ts +3 -1
  57. package/dist/cjs/index.js +55 -0
  58. package/dist/cjs/standardFormDialog/useStandardFormSchema.d.ts +1 -1
  59. package/dist/cjs/standardFormDialog/withStandardForm.d.ts +2 -2
  60. package/dist/cjs/types/railroad-diagrams.d.ts +59 -0
  61. package/dist/cjs/types/regexp-tree.d.ts +175 -0
  62. package/dist/esm/components/RegexEditor/core/RegexEditor.d.ts +34 -0
  63. package/dist/esm/components/RegexEditor/core/RegexEditor.js +214 -0
  64. package/dist/esm/components/RegexEditor/core/RegexEditor.less +119 -0
  65. package/dist/esm/components/RegexEditor/core/extensions/errorMarker.d.ts +49 -0
  66. package/dist/esm/components/RegexEditor/core/extensions/errorMarker.js +154 -0
  67. package/dist/esm/components/RegexEditor/core/types.d.ts +79 -0
  68. package/dist/esm/components/RegexEditor/core/types.js +1 -0
  69. package/dist/esm/components/RegexEditor/hooks/index.d.ts +9 -0
  70. package/dist/esm/components/RegexEditor/hooks/index.js +8 -0
  71. package/dist/esm/components/RegexEditor/hooks/useRegexTester.d.ts +95 -0
  72. package/dist/esm/components/RegexEditor/hooks/useRegexTester.js +230 -0
  73. package/dist/esm/components/RegexEditor/hooks/useRegexValidation.d.ts +71 -0
  74. package/dist/esm/components/RegexEditor/hooks/useRegexValidation.js +211 -0
  75. package/dist/esm/components/RegexEditor/hooks/useTemplateManager.d.ts +64 -0
  76. package/dist/esm/components/RegexEditor/hooks/useTemplateManager.js +430 -0
  77. package/dist/esm/components/RegexEditor/index.d.ts +16 -0
  78. package/dist/esm/components/RegexEditor/index.js +27 -0
  79. package/dist/esm/components/RegexEditor/templates/TemplateSelector.d.ts +36 -0
  80. package/dist/esm/components/RegexEditor/templates/TemplateSelector.js +316 -0
  81. package/dist/esm/components/RegexEditor/templates/builtinTemplates.d.ts +36 -0
  82. package/dist/esm/components/RegexEditor/templates/builtinTemplates.js +335 -0
  83. package/dist/esm/components/RegexEditor/templates/index.d.ts +10 -0
  84. package/dist/esm/components/RegexEditor/templates/index.js +19 -0
  85. package/dist/esm/components/RegexEditor/templates/storage.d.ts +74 -0
  86. package/dist/esm/components/RegexEditor/templates/storage.js +335 -0
  87. package/dist/esm/components/RegexEditor/templates/templateManager.d.ts +67 -0
  88. package/dist/esm/components/RegexEditor/templates/templateManager.js +274 -0
  89. package/dist/esm/components/RegexEditor/templates/types.d.ts +111 -0
  90. package/dist/esm/components/RegexEditor/templates/types.js +90 -0
  91. package/dist/esm/components/RegexEditor/testing/types.d.ts +55 -0
  92. package/dist/esm/components/RegexEditor/testing/types.js +1 -0
  93. package/dist/esm/components/RegexEditor/validation/complexity.d.ts +22 -0
  94. package/dist/esm/components/RegexEditor/validation/complexity.js +190 -0
  95. package/dist/esm/components/RegexEditor/validation/parser.d.ts +53 -0
  96. package/dist/esm/components/RegexEditor/validation/parser.js +123 -0
  97. package/dist/esm/components/RegexEditor/validation/types.d.ts +145 -0
  98. package/dist/esm/components/RegexEditor/validation/types.js +1 -0
  99. package/dist/esm/components/RegexEditor/validation/validator.d.ts +60 -0
  100. package/dist/esm/components/RegexEditor/validation/validator.js +213 -0
  101. package/dist/esm/components/RegexEditor/visualizer/FlagsSelector.d.ts +20 -0
  102. package/dist/esm/components/RegexEditor/visualizer/FlagsSelector.js +93 -0
  103. package/dist/esm/components/RegexEditor/visualizer/MatchItem.d.ts +25 -0
  104. package/dist/esm/components/RegexEditor/visualizer/MatchItem.js +194 -0
  105. package/dist/esm/components/RegexEditor/visualizer/RegexRailroadDiagram.d.ts +32 -0
  106. package/dist/esm/components/RegexEditor/visualizer/RegexRailroadDiagram.js +186 -0
  107. package/dist/esm/components/RegexEditor/visualizer/RegexTester.d.ts +22 -0
  108. package/dist/esm/components/RegexEditor/visualizer/RegexTester.js +248 -0
  109. package/dist/esm/components/RegexEditor/visualizer/astToRailroad.d.ts +18 -0
  110. package/dist/esm/components/RegexEditor/visualizer/astToRailroad.js +150 -0
  111. package/dist/esm/components/RegexEditor/visualizer/index.d.ts +12 -0
  112. package/dist/esm/components/RegexEditor/visualizer/index.js +17 -0
  113. package/dist/esm/components/RegexEditor/visualizer/types.d.ts +131 -0
  114. package/dist/esm/components/RegexEditor/visualizer/types.js +1 -0
  115. package/dist/esm/components/RegexEditor/visualizer/utils.d.ts +106 -0
  116. package/dist/esm/components/RegexEditor/visualizer/utils.js +256 -0
  117. package/dist/esm/index.d.ts +3 -1
  118. package/dist/esm/index.js +5 -2
  119. package/dist/esm/types/railroad-diagrams.d.ts +59 -0
  120. package/dist/esm/types/regexp-tree.d.ts +175 -0
  121. package/dist/umd/qc-ui.min.css +1 -1
  122. package/dist/umd/qc-ui.min.js +1 -1
  123. package/package.json +23 -7
@@ -0,0 +1,213 @@
1
+ /**
2
+ * 正则表达式语法验证器
3
+ *
4
+ * @module RegexEditor/validation/validator
5
+ * @description 检测正则表达式的常见语法错误和安全问题
6
+ *
7
+ * @remarks
8
+ * 该模块基于 regexp-tree AST 提供以下验证规则:
9
+ * 1. 空捕获组检测 - 检测 () 并建议使用 (?:)
10
+ * 2. 无效量词检测 - 检测 {min,max} 中 min > max
11
+ * 3. 嵌套量词检测 - 检测 (a+)+ 等导致灾难性回溯的模式
12
+ * 4. 未闭合组检测 - 通过解析错误自动检测
13
+ *
14
+ * @see {@link parseRegex} 用于解析正则表达式
15
+ */
16
+
17
+ import { traverseAST } from "./parser";
18
+ import { parseRegex } from "./parser";
19
+ /**
20
+ * 验证正则表达式 AST
21
+ *
22
+ * @param ast - 抽象语法树节点
23
+ * @returns {RegexError[]} 错误和警告列表
24
+ *
25
+ * @remarks
26
+ * 该函数遍历 AST 节点,应用以下验证规则:
27
+ * - 空捕获组 (警告)
28
+ * - 无效量词 (错误)
29
+ * - 嵌套量词/灾难性回溯 (错误)
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const result = parseRegex('()test');
34
+ * const errors = validateRegex(result.ast!);
35
+ * console.log(errors); // [{ type: 'empty_group', severity: 'warning', ... }]
36
+ * ```
37
+ */
38
+ export var validateRegex = function validateRegex(ast) {
39
+ var errors = [];
40
+
41
+ // 规则1: 检查空捕获组
42
+ traverseAST(ast, {
43
+ Group: function Group(path) {
44
+ var node = path.node;
45
+
46
+ // 检查是否是捕获组且为空
47
+ if (node.capturing) {
48
+ // 空组的判断条件:
49
+ // - expression 为 undefined/null
50
+ // - expression.type 为 'Empty'
51
+ // - expression.type 为 'Alternative' 且 expressions 为空数组
52
+ var expression = node.expression;
53
+ var isEmpty = !expression || expression.type === 'Empty' || expression.type === 'Alternative' && Array.isArray(expression.expressions) && expression.expressions.length === 0;
54
+ if (isEmpty) {
55
+ var _node$loc, _node$loc2;
56
+ errors.push({
57
+ type: 'empty_group',
58
+ message: '空的捕获组,建议使用非捕获组 (?:)',
59
+ position: {
60
+ start: ((_node$loc = node.loc) === null || _node$loc === void 0 ? void 0 : _node$loc.start) || 0,
61
+ end: ((_node$loc2 = node.loc) === null || _node$loc2 === void 0 ? void 0 : _node$loc2.end) || 0
62
+ },
63
+ severity: 'warning',
64
+ suggestion: '使用 (?:) 代替 ()'
65
+ });
66
+ }
67
+ }
68
+ }
69
+ });
70
+
71
+ // 规则2: 检查无效量词
72
+ traverseAST(ast, {
73
+ Repetition: function Repetition(path) {
74
+ var node = path.node;
75
+ var quantifier = node.quantifier;
76
+
77
+ // 检查 {min,max} 形式的量词
78
+ if (quantifier && quantifier.kind === 'Range') {
79
+ var from = quantifier.from;
80
+ var to = quantifier.to;
81
+
82
+ // 检查最小值是否大于最大值
83
+ if (typeof from === 'number' && typeof to === 'number' && from > to) {
84
+ var _node$loc3, _node$loc4;
85
+ errors.push({
86
+ type: 'invalid_quantifier',
87
+ message: "\u65E0\u6548\u7684\u91CF\u8BCD: {".concat(from, ",").concat(to, "} - \u6700\u5C0F\u503C\u4E0D\u80FD\u5927\u4E8E\u6700\u5927\u503C"),
88
+ position: {
89
+ start: ((_node$loc3 = node.loc) === null || _node$loc3 === void 0 ? void 0 : _node$loc3.start) || 0,
90
+ end: ((_node$loc4 = node.loc) === null || _node$loc4 === void 0 ? void 0 : _node$loc4.end) || 0
91
+ },
92
+ severity: 'error',
93
+ suggestion: "\u4F7F\u7528 {".concat(to, ",").concat(from, "} \u6216\u4FEE\u6539\u4E3A\u6B63\u786E\u7684\u8303\u56F4")
94
+ });
95
+ }
96
+ }
97
+ }
98
+ });
99
+
100
+ // 规则3: 检查嵌套量词(灾难性回溯风险)
101
+ traverseAST(ast, {
102
+ Repetition: function Repetition(path) {
103
+ var _node$expression;
104
+ var node = path.node;
105
+
106
+ // 检查量词内部是否包含另一个量词
107
+ // 模式: (a+)+, (a*)+, (a?)+, (a{n,m})+
108
+ if (((_node$expression = node.expression) === null || _node$expression === void 0 ? void 0 : _node$expression.type) === 'Group') {
109
+ var group = node.expression;
110
+ var innerExpression = group.expression;
111
+
112
+ // 检查组内表达式是否是量词
113
+ if ((innerExpression === null || innerExpression === void 0 ? void 0 : innerExpression.type) === 'Repetition') {
114
+ var _node$loc5, _node$loc6;
115
+ errors.push({
116
+ type: 'catastrophic_backtracking',
117
+ message: '嵌套的量词可能导致灾难性回溯',
118
+ position: {
119
+ start: ((_node$loc5 = node.loc) === null || _node$loc5 === void 0 ? void 0 : _node$loc5.start) || 0,
120
+ end: ((_node$loc6 = node.loc) === null || _node$loc6 === void 0 ? void 0 : _node$loc6.end) || 0
121
+ },
122
+ severity: 'error',
123
+ suggestion: '考虑使用原子组 (?>...) 或重新设计表达式'
124
+ });
125
+ }
126
+
127
+ // 检查更复杂的嵌套: (a|b)+c
128
+ // Alternative 包含 Repetition
129
+ if ((innerExpression === null || innerExpression === void 0 ? void 0 : innerExpression.type) === 'Alternative') {
130
+ var expressions = innerExpression.expressions || [];
131
+ var hasInnerQuantifier = expressions.some(function (expr) {
132
+ return expr.type === 'Repetition';
133
+ });
134
+ if (hasInnerQuantifier) {
135
+ var _node$loc7, _node$loc8;
136
+ errors.push({
137
+ type: 'catastrophic_backtracking',
138
+ message: '嵌套的量词可能导致灾难性回溯',
139
+ position: {
140
+ start: ((_node$loc7 = node.loc) === null || _node$loc7 === void 0 ? void 0 : _node$loc7.start) || 0,
141
+ end: ((_node$loc8 = node.loc) === null || _node$loc8 === void 0 ? void 0 : _node$loc8.end) || 0
142
+ },
143
+ severity: 'error',
144
+ suggestion: '考虑使用原子组 (?>...) 或重新设计表达式'
145
+ });
146
+ }
147
+ }
148
+ }
149
+ }
150
+ });
151
+ return errors;
152
+ };
153
+
154
+ /**
155
+ * 整合验证流程: 解析 + 语法验证
156
+ *
157
+ * @param pattern - 正则表达式字符串
158
+ * @param flags - 可选的正则表达式标志
159
+ * @returns {ValidationResult} 完整的验证结果
160
+ *
161
+ * @remarks
162
+ * 该函数整合了以下步骤:
163
+ * 1. 解析正则表达式 {@link parseRegex}
164
+ * 2. 语法验证 {@link validateRegex}
165
+ * 3. 分类错误、警告和信息
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const result = validatePattern('^LOT\\d{6}$');
170
+ * if (result.valid) {
171
+ * console.log('验证通过');
172
+ * } else {
173
+ * console.error('错误:', result.errors);
174
+ * }
175
+ * ```
176
+ */
177
+ export var validatePattern = function validatePattern(pattern, flags) {
178
+ // 1. 解析正则表达式
179
+ var parseResult = parseRegex(pattern, flags);
180
+
181
+ // 解析失败,返回解析错误
182
+ if (!parseResult.success) {
183
+ return {
184
+ valid: false,
185
+ errors: parseResult.error ? [parseResult.error] : [],
186
+ warnings: [],
187
+ infos: [],
188
+ pattern: pattern
189
+ };
190
+ }
191
+
192
+ // 2. 语法验证
193
+ var allErrors = validateRegex(parseResult.ast);
194
+
195
+ // 3. 分类错误、警告和信息
196
+ var errors = allErrors.filter(function (e) {
197
+ return e.severity === 'error';
198
+ });
199
+ var warnings = allErrors.filter(function (e) {
200
+ return e.severity === 'warning';
201
+ });
202
+ var infos = allErrors.filter(function (e) {
203
+ return e.severity === 'info';
204
+ });
205
+ return {
206
+ valid: errors.length === 0,
207
+ // 只有错误才影响 valid 状态
208
+ errors: errors,
209
+ warnings: warnings,
210
+ infos: infos,
211
+ pattern: pattern
212
+ };
213
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * FlagsSelector 组件
3
+ *
4
+ * @module RegexEditor/visualizer/FlagsSelector
5
+ * @description 正则表达式标志选择器组件
6
+ */
7
+ import React from 'react';
8
+ import type { FlagsSelectorProps } from './types';
9
+ /**
10
+ * 标志选择器组件
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * <FlagsSelector
15
+ * value={{ global: true, ignoreCase: true }}
16
+ * onChange={(flags) => console.log(flags)}
17
+ * />
18
+ * ```
19
+ */
20
+ export declare const FlagsSelector: React.FC<FlagsSelectorProps>;
@@ -0,0 +1,93 @@
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
+ /**
8
+ * FlagsSelector 组件
9
+ *
10
+ * @module RegexEditor/visualizer/FlagsSelector
11
+ * @description 正则表达式标志选择器组件
12
+ */
13
+
14
+ import React from 'react';
15
+ import { Checkbox, Space, Tooltip } from 'antd';
16
+ /**
17
+ * 标志配置
18
+ */
19
+ var FLAG_CONFIG = [{
20
+ key: 'global',
21
+ label: 'g',
22
+ tooltip: '全局匹配 (global) - 查找所有匹配项'
23
+ }, {
24
+ key: 'ignoreCase',
25
+ label: 'i',
26
+ tooltip: '忽略大小写 (ignoreCase) - 不区分大小写'
27
+ }, {
28
+ key: 'multiline',
29
+ label: 'm',
30
+ tooltip: '多行模式 (multiline) - ^ 和 $ 匹配行首行尾'
31
+ }, {
32
+ key: 'dotAll',
33
+ label: 's',
34
+ tooltip: 'dotAll 模式 - . 匹配包括换行符在内的所有字符'
35
+ }, {
36
+ key: 'unicode',
37
+ label: 'u',
38
+ tooltip: 'Unicode 模式 - 启用 Unicode 匹配'
39
+ }, {
40
+ key: 'sticky',
41
+ label: 'y',
42
+ tooltip: '粘性匹配 (sticky) - 从 lastIndex 位置开始匹配'
43
+ }];
44
+
45
+ /**
46
+ * 标志选择器组件
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * <FlagsSelector
51
+ * value={{ global: true, ignoreCase: true }}
52
+ * onChange={(flags) => console.log(flags)}
53
+ * />
54
+ * ```
55
+ */
56
+ export var FlagsSelector = function FlagsSelector(_ref) {
57
+ var _ref$value = _ref.value,
58
+ value = _ref$value === void 0 ? {} : _ref$value,
59
+ onChange = _ref.onChange,
60
+ _ref$disabled = _ref.disabled,
61
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
62
+ /**
63
+ * 处理标志变化
64
+ */
65
+ var handleChange = function handleChange(key) {
66
+ return function (e) {
67
+ if (onChange) {
68
+ onChange(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, key, e.target.checked)));
69
+ }
70
+ };
71
+ };
72
+ return /*#__PURE__*/React.createElement(Space, {
73
+ size: "small"
74
+ }, /*#__PURE__*/React.createElement("span", {
75
+ style: {
76
+ color: '#666'
77
+ }
78
+ }, "\u6807\u5FD7:"), FLAG_CONFIG.map(function (flag) {
79
+ return /*#__PURE__*/React.createElement(Tooltip, {
80
+ key: flag.key,
81
+ title: flag.tooltip
82
+ }, /*#__PURE__*/React.createElement(Checkbox, {
83
+ checked: value[flag.key],
84
+ onChange: handleChange(flag.key),
85
+ disabled: disabled
86
+ }, /*#__PURE__*/React.createElement("code", {
87
+ style: {
88
+ fontSize: '13px',
89
+ fontWeight: 'bold'
90
+ }
91
+ }, flag.label)));
92
+ }));
93
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * MatchItem 组件
3
+ *
4
+ * @module RegexEditor/visualizer/MatchItem
5
+ * @description 匹配结果项组件
6
+ */
7
+ import React from 'react';
8
+ import type { MatchItemProps } from './types';
9
+ /**
10
+ * 匹配项组件
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * <MatchItem
15
+ * match={{
16
+ * index: 0,
17
+ * lastIndex: 3,
18
+ * fullMatch: 'abc',
19
+ * groups: ['abc', 'ab', 'c'],
20
+ * }}
21
+ * index={0}
22
+ * />
23
+ * ```
24
+ */
25
+ export declare const MatchItem: React.FC<MatchItemProps>;
@@ -0,0 +1,194 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ /**
8
+ * MatchItem 组件
9
+ *
10
+ * @module RegexEditor/visualizer/MatchItem
11
+ * @description 匹配结果项组件
12
+ */
13
+
14
+ import React, { useState } from 'react';
15
+ import { Card, Tag, Typography, Collapse, Space } from 'antd';
16
+ import { formatPosition } from "./utils";
17
+ var Text = Typography.Text,
18
+ Paragraph = Typography.Paragraph;
19
+ var Panel = Collapse.Panel;
20
+
21
+ /**
22
+ * 匹配项组件
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <MatchItem
27
+ * match={{
28
+ * index: 0,
29
+ * lastIndex: 3,
30
+ * fullMatch: 'abc',
31
+ * groups: ['abc', 'ab', 'c'],
32
+ * }}
33
+ * index={0}
34
+ * />
35
+ * ```
36
+ */
37
+ export var MatchItem = function MatchItem(_ref) {
38
+ var match = _ref.match,
39
+ index = _ref.index,
40
+ _ref$highlighted = _ref.highlighted,
41
+ highlighted = _ref$highlighted === void 0 ? false : _ref$highlighted,
42
+ _onClick = _ref.onClick;
43
+ var _useState = useState(false),
44
+ _useState2 = _slicedToArray(_useState, 2),
45
+ isHovered = _useState2[0],
46
+ setIsHovered = _useState2[1];
47
+ var hasGroups = match.groups.length > 1;
48
+ var hasNamedGroups = match.namedGroups && Object.keys(match.namedGroups).length > 0;
49
+ return /*#__PURE__*/React.createElement(Card, {
50
+ size: "small",
51
+ className: "regex-match-item ".concat(highlighted ? 'highlighted' : ''),
52
+ style: {
53
+ marginBottom: 8,
54
+ cursor: _onClick ? 'pointer' : 'default',
55
+ borderColor: isHovered ? '#1890ff' : undefined,
56
+ transition: 'border-color 0.3s'
57
+ },
58
+ onMouseEnter: function onMouseEnter() {
59
+ return setIsHovered(true);
60
+ },
61
+ onMouseLeave: function onMouseLeave() {
62
+ return setIsHovered(false);
63
+ },
64
+ onClick: function onClick() {
65
+ return _onClick === null || _onClick === void 0 ? void 0 : _onClick(match, index);
66
+ }
67
+ }, /*#__PURE__*/React.createElement("div", {
68
+ style: {
69
+ marginBottom: 8
70
+ }
71
+ }, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Tag, {
72
+ color: "blue"
73
+ }, "\u5339\u914D #", index + 1), /*#__PURE__*/React.createElement(Text, {
74
+ type: "secondary",
75
+ style: {
76
+ fontSize: '12px'
77
+ }
78
+ }, "\u4F4D\u7F6E: ", formatPosition(match)))), /*#__PURE__*/React.createElement("div", {
79
+ style: {
80
+ marginBottom: hasGroups || hasNamedGroups ? 8 : 0
81
+ }
82
+ }, /*#__PURE__*/React.createElement(Text, {
83
+ strong: true,
84
+ style: {
85
+ fontSize: '12px',
86
+ color: '#666'
87
+ }
88
+ }, "\u5B8C\u6574\u5339\u914D:"), /*#__PURE__*/React.createElement(Paragraph, {
89
+ code: true,
90
+ copyable: true,
91
+ style: {
92
+ margin: '4px 0 0 0',
93
+ backgroundColor: '#f6f6f6',
94
+ padding: '4px 8px',
95
+ borderRadius: '2px'
96
+ }
97
+ }, match.fullMatch)), hasGroups && /*#__PURE__*/React.createElement(Collapse, {
98
+ size: "small",
99
+ bordered: false,
100
+ ghost: true
101
+ }, /*#__PURE__*/React.createElement(Panel, {
102
+ header: /*#__PURE__*/React.createElement(Text, {
103
+ strong: true,
104
+ style: {
105
+ fontSize: '12px',
106
+ color: '#666'
107
+ }
108
+ }, "\u6355\u83B7\u7EC4 (", match.groups.length - 1, ")"),
109
+ key: "groups"
110
+ }, /*#__PURE__*/React.createElement("div", {
111
+ style: {
112
+ paddingLeft: 8
113
+ }
114
+ }, match.groups.slice(1).map(function (group, i) {
115
+ return /*#__PURE__*/React.createElement("div", {
116
+ key: i,
117
+ style: {
118
+ marginBottom: 8
119
+ }
120
+ }, /*#__PURE__*/React.createElement("div", {
121
+ style: {
122
+ marginBottom: 2
123
+ }
124
+ }, /*#__PURE__*/React.createElement(Tag, {
125
+ color: "geekblue",
126
+ style: {
127
+ fontSize: '11px'
128
+ }
129
+ }, "Group ", i + 1)), /*#__PURE__*/React.createElement(Paragraph, {
130
+ code: true,
131
+ copyable: true,
132
+ style: {
133
+ margin: 0,
134
+ backgroundColor: '#f0f5ff',
135
+ padding: '2px 6px',
136
+ borderRadius: '2px',
137
+ fontSize: '12px'
138
+ }
139
+ }, group || /*#__PURE__*/React.createElement(Text, {
140
+ type: "secondary"
141
+ }, "(empty)")));
142
+ })))), hasNamedGroups && /*#__PURE__*/React.createElement(Collapse, {
143
+ size: "small",
144
+ bordered: false,
145
+ ghost: true,
146
+ style: {
147
+ marginTop: hasGroups ? 8 : 0
148
+ }
149
+ }, /*#__PURE__*/React.createElement(Panel, {
150
+ header: /*#__PURE__*/React.createElement(Text, {
151
+ strong: true,
152
+ style: {
153
+ fontSize: '12px',
154
+ color: '#666'
155
+ }
156
+ }, "\u547D\u540D\u6355\u83B7\u7EC4 (", Object.keys(match.namedGroups).length, ")"),
157
+ key: "named-groups"
158
+ }, /*#__PURE__*/React.createElement("div", {
159
+ style: {
160
+ paddingLeft: 8
161
+ }
162
+ }, Object.entries(match.namedGroups).map(function (_ref2) {
163
+ var _ref3 = _slicedToArray(_ref2, 2),
164
+ name = _ref3[0],
165
+ value = _ref3[1];
166
+ return /*#__PURE__*/React.createElement("div", {
167
+ key: name,
168
+ style: {
169
+ marginBottom: 8
170
+ }
171
+ }, /*#__PURE__*/React.createElement("div", {
172
+ style: {
173
+ marginBottom: 2
174
+ }
175
+ }, /*#__PURE__*/React.createElement(Tag, {
176
+ color: "purple",
177
+ style: {
178
+ fontSize: '11px'
179
+ }
180
+ }, name)), /*#__PURE__*/React.createElement(Paragraph, {
181
+ code: true,
182
+ copyable: true,
183
+ style: {
184
+ margin: 0,
185
+ backgroundColor: '#f9f0ff',
186
+ padding: '2px 6px',
187
+ borderRadius: '2px',
188
+ fontSize: '12px'
189
+ }
190
+ }, value || /*#__PURE__*/React.createElement(Text, {
191
+ type: "secondary"
192
+ }, "(empty)")));
193
+ })))));
194
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * RegexRailroadDiagram 组件
3
+ *
4
+ * @module RegexEditor/visualizer/RegexRailroadDiagram
5
+ * @description 使用 Railroad Diagram 可视化正则表达式结构
6
+ */
7
+ import React from 'react';
8
+ import 'railroad-diagrams/railroad-diagrams.css';
9
+ export interface RegexRailroadDiagramProps {
10
+ /** 正则表达式模式 */
11
+ pattern: string;
12
+ /** 是否显示标题 */
13
+ showTitle?: boolean;
14
+ /** 卡片大小 */
15
+ size?: 'small' | 'default';
16
+ /** 自定义样式 */
17
+ style?: React.CSSProperties;
18
+ /** 自定义类名 */
19
+ className?: string;
20
+ }
21
+ /**
22
+ * Railroad Diagram 可视化组件
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <RegexRailroadDiagram
27
+ * pattern="\d{3}-\d{4}"
28
+ * showTitle={true}
29
+ * />
30
+ * ```
31
+ */
32
+ export declare const RegexRailroadDiagram: React.FC<RegexRailroadDiagramProps>;