@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.
Files changed (143) hide show
  1. package/dist/cjs/ag-grid-plus/hooks/useGridPlusColumnState.d.ts +12 -0
  2. package/dist/cjs/ag-grid-plus/hooks/useGridPlusColumnState.js +15 -0
  3. package/dist/cjs/ag-grid-plus/index.d.ts +2 -9
  4. package/dist/cjs/ag-grid-plus/index.js +8 -6
  5. package/dist/cjs/ag-grid-plus/setting/index.js +2 -2
  6. package/dist/cjs/array-table/columnHelper.d.ts +126 -0
  7. package/dist/cjs/array-table/columnHelper.js +241 -0
  8. package/dist/cjs/array-table/hooks.d.ts +23 -0
  9. package/dist/cjs/array-table/hooks.js +230 -0
  10. package/dist/cjs/array-table/index.js +141 -208
  11. package/dist/cjs/components/RegexEditor/core/RegexEditor.d.ts +34 -0
  12. package/dist/cjs/components/RegexEditor/core/RegexEditor.js +223 -0
  13. package/dist/cjs/components/RegexEditor/core/RegexEditor.less +119 -0
  14. package/dist/cjs/components/RegexEditor/core/extensions/errorMarker.d.ts +49 -0
  15. package/dist/cjs/components/RegexEditor/core/extensions/errorMarker.js +158 -0
  16. package/dist/cjs/components/RegexEditor/core/types.d.ts +79 -0
  17. package/dist/cjs/components/RegexEditor/core/types.js +5 -0
  18. package/dist/cjs/components/RegexEditor/hooks/index.d.ts +9 -0
  19. package/dist/cjs/components/RegexEditor/hooks/index.js +19 -0
  20. package/dist/cjs/components/RegexEditor/hooks/useRegexTester.d.ts +95 -0
  21. package/dist/cjs/components/RegexEditor/hooks/useRegexTester.js +234 -0
  22. package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.d.ts +71 -0
  23. package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.js +215 -0
  24. package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.d.ts +64 -0
  25. package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.js +438 -0
  26. package/dist/cjs/components/RegexEditor/index.d.ts +16 -0
  27. package/dist/cjs/components/RegexEditor/index.js +232 -0
  28. package/dist/cjs/components/RegexEditor/templates/TemplateSelector.d.ts +36 -0
  29. package/dist/cjs/components/RegexEditor/templates/TemplateSelector.js +322 -0
  30. package/dist/cjs/components/RegexEditor/templates/builtinTemplates.d.ts +36 -0
  31. package/dist/cjs/components/RegexEditor/templates/builtinTemplates.js +340 -0
  32. package/dist/cjs/components/RegexEditor/templates/index.d.ts +10 -0
  33. package/dist/cjs/components/RegexEditor/templates/index.js +184 -0
  34. package/dist/cjs/components/RegexEditor/templates/storage.d.ts +74 -0
  35. package/dist/cjs/components/RegexEditor/templates/storage.js +337 -0
  36. package/dist/cjs/components/RegexEditor/templates/templateManager.d.ts +67 -0
  37. package/dist/cjs/components/RegexEditor/templates/templateManager.js +277 -0
  38. package/dist/cjs/components/RegexEditor/templates/types.d.ts +111 -0
  39. package/dist/cjs/components/RegexEditor/templates/types.js +94 -0
  40. package/dist/cjs/components/RegexEditor/testing/types.d.ts +55 -0
  41. package/dist/cjs/components/RegexEditor/testing/types.js +5 -0
  42. package/dist/cjs/components/RegexEditor/validation/complexity.d.ts +22 -0
  43. package/dist/cjs/components/RegexEditor/validation/complexity.js +196 -0
  44. package/dist/cjs/components/RegexEditor/validation/parser.d.ts +53 -0
  45. package/dist/cjs/components/RegexEditor/validation/parser.js +129 -0
  46. package/dist/cjs/components/RegexEditor/validation/types.d.ts +146 -0
  47. package/dist/cjs/components/RegexEditor/validation/types.js +5 -0
  48. package/dist/cjs/components/RegexEditor/validation/validator.d.ts +60 -0
  49. package/dist/cjs/components/RegexEditor/validation/validator.js +218 -0
  50. package/dist/cjs/components/RegexEditor/visualizer/FlagsSelector.d.ts +20 -0
  51. package/dist/cjs/components/RegexEditor/visualizer/FlagsSelector.js +98 -0
  52. package/dist/cjs/components/RegexEditor/visualizer/MatchItem.d.ts +25 -0
  53. package/dist/cjs/components/RegexEditor/visualizer/MatchItem.js +201 -0
  54. package/dist/cjs/components/RegexEditor/visualizer/RegexRailroadDiagram.d.ts +32 -0
  55. package/dist/cjs/components/RegexEditor/visualizer/RegexRailroadDiagram.js +192 -0
  56. package/dist/cjs/components/RegexEditor/visualizer/RegexTester.d.ts +22 -0
  57. package/dist/cjs/components/RegexEditor/visualizer/RegexTester.js +255 -0
  58. package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.d.ts +19 -0
  59. package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.js +155 -0
  60. package/dist/cjs/components/RegexEditor/visualizer/index.d.ts +12 -0
  61. package/dist/cjs/components/RegexEditor/visualizer/index.js +76 -0
  62. package/dist/cjs/components/RegexEditor/visualizer/types.d.ts +131 -0
  63. package/dist/cjs/components/RegexEditor/visualizer/types.js +5 -0
  64. package/dist/cjs/components/RegexEditor/visualizer/utils.d.ts +106 -0
  65. package/dist/cjs/components/RegexEditor/visualizer/utils.js +268 -0
  66. package/dist/cjs/index.d.ts +6 -2
  67. package/dist/cjs/index.js +68 -0
  68. package/dist/cjs/standardFormDialog/useStandardFormSchema.d.ts +1 -1
  69. package/dist/cjs/standardFormDialog/withStandardForm.d.ts +2 -2
  70. package/dist/cjs/types/railroad-diagrams.d.ts +59 -0
  71. package/dist/cjs/types/regexp-tree.d.ts +175 -0
  72. package/dist/esm/ag-grid-plus/hooks/useGridPlusColumnState.d.ts +12 -0
  73. package/dist/esm/ag-grid-plus/hooks/useGridPlusColumnState.js +10 -0
  74. package/dist/esm/ag-grid-plus/index.d.ts +2 -9
  75. package/dist/esm/ag-grid-plus/index.js +2 -5
  76. package/dist/esm/ag-grid-plus/setting/index.js +1 -1
  77. package/dist/esm/array-table/columnHelper.d.ts +126 -0
  78. package/dist/esm/array-table/columnHelper.js +235 -0
  79. package/dist/esm/array-table/hooks.d.ts +23 -0
  80. package/dist/esm/array-table/hooks.js +224 -0
  81. package/dist/esm/array-table/index.js +142 -209
  82. package/dist/esm/components/RegexEditor/core/RegexEditor.d.ts +34 -0
  83. package/dist/esm/components/RegexEditor/core/RegexEditor.js +214 -0
  84. package/dist/esm/components/RegexEditor/core/RegexEditor.less +119 -0
  85. package/dist/esm/components/RegexEditor/core/extensions/errorMarker.d.ts +49 -0
  86. package/dist/esm/components/RegexEditor/core/extensions/errorMarker.js +154 -0
  87. package/dist/esm/components/RegexEditor/core/types.d.ts +79 -0
  88. package/dist/esm/components/RegexEditor/core/types.js +1 -0
  89. package/dist/esm/components/RegexEditor/hooks/index.d.ts +9 -0
  90. package/dist/esm/components/RegexEditor/hooks/index.js +8 -0
  91. package/dist/esm/components/RegexEditor/hooks/useRegexTester.d.ts +95 -0
  92. package/dist/esm/components/RegexEditor/hooks/useRegexTester.js +230 -0
  93. package/dist/esm/components/RegexEditor/hooks/useRegexValidation.d.ts +71 -0
  94. package/dist/esm/components/RegexEditor/hooks/useRegexValidation.js +211 -0
  95. package/dist/esm/components/RegexEditor/hooks/useTemplateManager.d.ts +64 -0
  96. package/dist/esm/components/RegexEditor/hooks/useTemplateManager.js +430 -0
  97. package/dist/esm/components/RegexEditor/index.d.ts +16 -0
  98. package/dist/esm/components/RegexEditor/index.js +27 -0
  99. package/dist/esm/components/RegexEditor/templates/TemplateSelector.d.ts +36 -0
  100. package/dist/esm/components/RegexEditor/templates/TemplateSelector.js +316 -0
  101. package/dist/esm/components/RegexEditor/templates/builtinTemplates.d.ts +36 -0
  102. package/dist/esm/components/RegexEditor/templates/builtinTemplates.js +335 -0
  103. package/dist/esm/components/RegexEditor/templates/index.d.ts +10 -0
  104. package/dist/esm/components/RegexEditor/templates/index.js +19 -0
  105. package/dist/esm/components/RegexEditor/templates/storage.d.ts +74 -0
  106. package/dist/esm/components/RegexEditor/templates/storage.js +335 -0
  107. package/dist/esm/components/RegexEditor/templates/templateManager.d.ts +67 -0
  108. package/dist/esm/components/RegexEditor/templates/templateManager.js +274 -0
  109. package/dist/esm/components/RegexEditor/templates/types.d.ts +111 -0
  110. package/dist/esm/components/RegexEditor/templates/types.js +90 -0
  111. package/dist/esm/components/RegexEditor/testing/types.d.ts +55 -0
  112. package/dist/esm/components/RegexEditor/testing/types.js +1 -0
  113. package/dist/esm/components/RegexEditor/validation/complexity.d.ts +22 -0
  114. package/dist/esm/components/RegexEditor/validation/complexity.js +190 -0
  115. package/dist/esm/components/RegexEditor/validation/parser.d.ts +53 -0
  116. package/dist/esm/components/RegexEditor/validation/parser.js +123 -0
  117. package/dist/esm/components/RegexEditor/validation/types.d.ts +145 -0
  118. package/dist/esm/components/RegexEditor/validation/types.js +1 -0
  119. package/dist/esm/components/RegexEditor/validation/validator.d.ts +60 -0
  120. package/dist/esm/components/RegexEditor/validation/validator.js +213 -0
  121. package/dist/esm/components/RegexEditor/visualizer/FlagsSelector.d.ts +20 -0
  122. package/dist/esm/components/RegexEditor/visualizer/FlagsSelector.js +93 -0
  123. package/dist/esm/components/RegexEditor/visualizer/MatchItem.d.ts +25 -0
  124. package/dist/esm/components/RegexEditor/visualizer/MatchItem.js +194 -0
  125. package/dist/esm/components/RegexEditor/visualizer/RegexRailroadDiagram.d.ts +32 -0
  126. package/dist/esm/components/RegexEditor/visualizer/RegexRailroadDiagram.js +186 -0
  127. package/dist/esm/components/RegexEditor/visualizer/RegexTester.d.ts +22 -0
  128. package/dist/esm/components/RegexEditor/visualizer/RegexTester.js +248 -0
  129. package/dist/esm/components/RegexEditor/visualizer/astToRailroad.d.ts +18 -0
  130. package/dist/esm/components/RegexEditor/visualizer/astToRailroad.js +150 -0
  131. package/dist/esm/components/RegexEditor/visualizer/index.d.ts +12 -0
  132. package/dist/esm/components/RegexEditor/visualizer/index.js +17 -0
  133. package/dist/esm/components/RegexEditor/visualizer/types.d.ts +131 -0
  134. package/dist/esm/components/RegexEditor/visualizer/types.js +1 -0
  135. package/dist/esm/components/RegexEditor/visualizer/utils.d.ts +106 -0
  136. package/dist/esm/components/RegexEditor/visualizer/utils.js +256 -0
  137. package/dist/esm/index.d.ts +6 -2
  138. package/dist/esm/index.js +7 -3
  139. package/dist/esm/types/railroad-diagrams.d.ts +59 -0
  140. package/dist/esm/types/regexp-tree.d.ts +175 -0
  141. package/dist/umd/qc-ui.min.css +1 -1
  142. package/dist/umd/qc-ui.min.js +1 -1
  143. package/package.json +23 -7
@@ -0,0 +1,34 @@
1
+ /**
2
+ * RegexEditor 组件
3
+ *
4
+ * @description
5
+ * CodeMirror 6 包装器组件,集成正则表达式验证和错误标注功能。
6
+ * 提供实时语法验证、错误高亮、复杂度分析等功能。
7
+ *
8
+ * @module RegexEditor/core/RegexEditor
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <RegexEditor
13
+ * value={pattern}
14
+ * onChange={setPattern}
15
+ * placeholder="请输入正则表达式"
16
+ * showComplexity={true}
17
+ * onValidate={(result) => {
18
+ * if (!result.valid) {
19
+ * console.error('验证失败:', result.errors);
20
+ * }
21
+ * }}
22
+ * />
23
+ * ```
24
+ */
25
+ import React from 'react';
26
+ import type { RegexEditorProps } from './types';
27
+ import './RegexEditor.less';
28
+ /**
29
+ * RegexEditor 组件
30
+ *
31
+ * @param props - 组件属性
32
+ * @returns React 组件
33
+ */
34
+ export declare const RegexEditor: React.FC<RegexEditorProps>;
@@ -0,0 +1,214 @@
1
+ /**
2
+ * RegexEditor 组件
3
+ *
4
+ * @description
5
+ * CodeMirror 6 包装器组件,集成正则表达式验证和错误标注功能。
6
+ * 提供实时语法验证、错误高亮、复杂度分析等功能。
7
+ *
8
+ * @module RegexEditor/core/RegexEditor
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <RegexEditor
13
+ * value={pattern}
14
+ * onChange={setPattern}
15
+ * placeholder="请输入正则表达式"
16
+ * showComplexity={true}
17
+ * onValidate={(result) => {
18
+ * if (!result.valid) {
19
+ * console.error('验证失败:', result.errors);
20
+ * }
21
+ * }}
22
+ * />
23
+ * ```
24
+ */
25
+
26
+ import React, { useMemo, useEffect, useRef } from 'react';
27
+ import CodeMirror from '@uiw/react-codemirror';
28
+ import { javascript } from '@codemirror/lang-javascript';
29
+ import { EditorView } from '@codemirror/view';
30
+ import { useRegexValidation } from "../hooks/useRegexValidation";
31
+ import { createErrorMarkers, updateErrorMarkers } from "./extensions/errorMarker";
32
+ import { RegexRailroadDiagram } from "../visualizer/RegexRailroadDiagram";
33
+ import "./RegexEditor.less";
34
+
35
+ /**
36
+ * RegexEditor 组件
37
+ *
38
+ * @param props - 组件属性
39
+ * @returns React 组件
40
+ */
41
+ export var RegexEditor = function RegexEditor(_ref) {
42
+ var _ref$value = _ref.value,
43
+ value = _ref$value === void 0 ? '' : _ref$value,
44
+ onChange = _ref.onChange,
45
+ _ref$placeholder = _ref.placeholder,
46
+ placeholder = _ref$placeholder === void 0 ? '请输入正则表达式' : _ref$placeholder,
47
+ _ref$readOnly = _ref.readOnly,
48
+ readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
49
+ _ref$disabled = _ref.disabled,
50
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
51
+ _ref$showComplexity = _ref.showComplexity,
52
+ showComplexity = _ref$showComplexity === void 0 ? false : _ref$showComplexity,
53
+ _ref$showRailroadDiag = _ref.showRailroadDiagram,
54
+ showRailroadDiagram = _ref$showRailroadDiag === void 0 ? false : _ref$showRailroadDiag,
55
+ onValidate = _ref.onValidate,
56
+ _ref$height = _ref.height,
57
+ height = _ref$height === void 0 ? '120px' : _ref$height;
58
+ // 编辑器引用
59
+ var editorRef = useRef(null);
60
+
61
+ // 验证 Hook
62
+ var _useRegexValidation = useRegexValidation(value),
63
+ validationResult = _useRegexValidation.validationResult,
64
+ complexity = _useRegexValidation.complexity,
65
+ isValidating = _useRegexValidation.isValidating;
66
+
67
+ // 通知验证结果
68
+ useEffect(function () {
69
+ if (validationResult && onValidate) {
70
+ onValidate(validationResult);
71
+ }
72
+ }, [validationResult, onValidate]);
73
+
74
+ // 更新错误标注
75
+ useEffect(function () {
76
+ var _editorRef$current;
77
+ if ((_editorRef$current = editorRef.current) !== null && _editorRef$current !== void 0 && _editorRef$current.view && validationResult) {
78
+ var errors = validationResult.errors || [];
79
+ updateErrorMarkers(editorRef.current.view, errors);
80
+ }
81
+ }, [validationResult]);
82
+
83
+ // 构建扩展
84
+ var extensions = useMemo(function () {
85
+ var exts = [
86
+ // JavaScript 语法高亮(支持正则表达式)
87
+ javascript(),
88
+ // 自动换行
89
+ EditorView.lineWrapping,
90
+ // 错误标注
91
+ createErrorMarkers([]),
92
+ // 自定义主题
93
+ EditorView.theme({
94
+ '&': {
95
+ fontSize: '14px',
96
+ border: '1px solid #d9d9d9',
97
+ borderRadius: '2px',
98
+ backgroundColor: '#fff'
99
+ },
100
+ '&.cm-focused': {
101
+ outline: 'none',
102
+ borderColor: '#40a9ff',
103
+ boxShadow: '0 0 0 2px rgba(24, 144, 255, 0.2)'
104
+ },
105
+ '.cm-content': {
106
+ padding: '8px 0',
107
+ fontFamily: '"Monaco", "Menlo", "Ubuntu Mono", "Consolas", monospace',
108
+ caretColor: '#000'
109
+ },
110
+ '.cm-line': {
111
+ padding: '0 12px'
112
+ },
113
+ '.cm-scroller': {
114
+ overflow: 'auto',
115
+ maxHeight: '400px'
116
+ },
117
+ '&.cm-editor.cm-focused': {
118
+ outline: 'none'
119
+ },
120
+ // 占位符样式
121
+ '.cm-placeholder': {
122
+ color: '#bfbfbf',
123
+ fontStyle: 'italic'
124
+ }
125
+ })];
126
+
127
+ // 只读模式
128
+ if (readOnly || disabled) {
129
+ exts.push(EditorView.editable.of(false));
130
+ }
131
+ return exts;
132
+ }, [readOnly, disabled]);
133
+
134
+ // 处理值变化
135
+ var handleChange = function handleChange(newValue) {
136
+ if (onChange && !readOnly && !disabled) {
137
+ onChange(newValue);
138
+ }
139
+ };
140
+ return /*#__PURE__*/React.createElement("div", {
141
+ className: "regex-editor"
142
+ }, /*#__PURE__*/React.createElement(CodeMirror, {
143
+ ref: editorRef,
144
+ value: value,
145
+ height: height,
146
+ placeholder: placeholder,
147
+ editable: !readOnly && !disabled,
148
+ extensions: extensions,
149
+ onChange: handleChange,
150
+ basicSetup: {
151
+ lineNumbers: false,
152
+ foldGutter: false,
153
+ highlightActiveLine: false,
154
+ highlightActiveLineGutter: false,
155
+ syntaxHighlighting: true,
156
+ bracketMatching: true,
157
+ autocompletion: false,
158
+ closeBrackets: true,
159
+ highlightSelectionMatches: true
160
+ },
161
+ className: readOnly || disabled ? 'cm-readonly' : ''
162
+ }), showComplexity && complexity && /*#__PURE__*/React.createElement("div", {
163
+ className: "regex-complexity"
164
+ }, /*#__PURE__*/React.createElement("div", {
165
+ className: "complexity-item"
166
+ }, /*#__PURE__*/React.createElement("span", {
167
+ className: "label"
168
+ }, "\u6027\u80FD\u8BC4\u5206:"), /*#__PURE__*/React.createElement("span", {
169
+ className: "score score-".concat(getScoreLevel(complexity.performanceScore))
170
+ }, complexity.performanceScore)), /*#__PURE__*/React.createElement("div", {
171
+ className: "complexity-item"
172
+ }, /*#__PURE__*/React.createElement("span", {
173
+ className: "label"
174
+ }, "\u56DE\u6EAF\u98CE\u9669:"), /*#__PURE__*/React.createElement("span", {
175
+ className: "risk risk-".concat(complexity.backtrackingRisk)
176
+ }, getRiskLabel(complexity.backtrackingRisk))), complexity.suggestions.length > 0 && /*#__PURE__*/React.createElement("div", {
177
+ className: "complexity-suggestions"
178
+ }, /*#__PURE__*/React.createElement("div", {
179
+ className: "suggestions-title"
180
+ }, "\u4F18\u5316\u5EFA\u8BAE:"), /*#__PURE__*/React.createElement("ul", null, complexity.suggestions.map(function (suggestion, index) {
181
+ return /*#__PURE__*/React.createElement("li", {
182
+ key: index
183
+ }, suggestion);
184
+ })))), showRailroadDiagram && /*#__PURE__*/React.createElement("div", {
185
+ style: {
186
+ marginTop: '16px'
187
+ }
188
+ }, /*#__PURE__*/React.createElement(RegexRailroadDiagram, {
189
+ pattern: value,
190
+ showTitle: true,
191
+ size: "default"
192
+ })));
193
+ };
194
+
195
+ /**
196
+ * 获取评分等级
197
+ */
198
+ var getScoreLevel = function getScoreLevel(score) {
199
+ if (score >= 80) return 'high';
200
+ if (score >= 60) return 'medium';
201
+ return 'low';
202
+ };
203
+
204
+ /**
205
+ * 获取风险标签
206
+ */
207
+ var getRiskLabel = function getRiskLabel(risk) {
208
+ var labels = {
209
+ low: '低',
210
+ medium: '中',
211
+ high: '高'
212
+ };
213
+ return labels[risk];
214
+ };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * RegexEditor 组件样式
3
+ */
4
+
5
+ .regex-editor {
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: 12px;
9
+
10
+ // 复杂度信息区域
11
+ .regex-complexity {
12
+ padding: 12px;
13
+ background-color: #fafafa;
14
+ border: 1px solid #d9d9d9;
15
+ border-radius: 2px;
16
+ font-size: 13px;
17
+
18
+ .complexity-item {
19
+ display: flex;
20
+ align-items: center;
21
+ margin-bottom: 8px;
22
+
23
+ &:last-child {
24
+ margin-bottom: 0;
25
+ }
26
+
27
+ .label {
28
+ font-weight: 500;
29
+ color: #595959;
30
+ margin-right: 8px;
31
+ }
32
+
33
+ .score {
34
+ padding: 2px 8px;
35
+ border-radius: 2px;
36
+ font-weight: 600;
37
+
38
+ &.score-high {
39
+ background-color: #f6ffed;
40
+ color: #52c41a;
41
+ }
42
+
43
+ &.score-medium {
44
+ background-color: #fffbe6;
45
+ color: #faad14;
46
+ }
47
+
48
+ &.score-low {
49
+ background-color: #fff2f0;
50
+ color: #ff4d4f;
51
+ }
52
+ }
53
+
54
+ .risk {
55
+ padding: 2px 8px;
56
+ border-radius: 2px;
57
+ font-weight: 600;
58
+
59
+ &.risk-low {
60
+ background-color: #f6ffed;
61
+ color: #52c41a;
62
+ }
63
+
64
+ &.risk-medium {
65
+ background-color: #fffbe6;
66
+ color: #faad14;
67
+ }
68
+
69
+ &.risk-high {
70
+ background-color: #fff2f0;
71
+ color: #ff4d4f;
72
+ }
73
+ }
74
+ }
75
+
76
+ .complexity-suggestions {
77
+ margin-top: 12px;
78
+ padding-top: 12px;
79
+ border-top: 1px solid #e8e8e8;
80
+
81
+ .suggestions-title {
82
+ font-weight: 500;
83
+ color: #595959;
84
+ margin-bottom: 8px;
85
+ }
86
+
87
+ ul {
88
+ margin: 0;
89
+ padding-left: 20px;
90
+
91
+ li {
92
+ color: #8c8c8c;
93
+ line-height: 1.6;
94
+ margin-bottom: 4px;
95
+
96
+ &:last-child {
97
+ margin-bottom: 0;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ // 错误标注样式
105
+ .cm-regex-error {
106
+ text-decoration: wavy underline red;
107
+ text-decoration-skip-ink: none;
108
+ }
109
+
110
+ .cm-regex-warning {
111
+ text-decoration: wavy underline orange;
112
+ text-decoration-skip-ink: none;
113
+ }
114
+
115
+ .cm-regex-info {
116
+ text-decoration: wavy underline blue;
117
+ text-decoration-skip-ink: none;
118
+ }
119
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * CodeMirror 错误标注扩展
3
+ *
4
+ * @description
5
+ * 为 CodeMirror 编辑器添加错误标注功能,支持波浪下划线高亮显示错误位置。
6
+ *
7
+ * @module RegexEditor/core/extensions/errorMarker
8
+ */
9
+ import { DecorationSet, EditorView } from '@codemirror/view';
10
+ import { StateField } from '@codemirror/state';
11
+ import type { RegexError } from '../../validation/types';
12
+ /**
13
+ * 设置错误的 StateEffect
14
+ */
15
+ export declare const setErrorsEffect: import("@codemirror/state").StateEffectType<RegexError[]>;
16
+ /**
17
+ * 错误装饰状态字段
18
+ *
19
+ * @description
20
+ * 管理错误标注的 DecorationSet
21
+ */
22
+ export declare const errorDecorationsField: StateField<DecorationSet>;
23
+ /**
24
+ * 创建错误标注扩展
25
+ *
26
+ * @param errors - 错误列表
27
+ * @returns CodeMirror 扩展数组
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const extensions = [
32
+ * javascript(),
33
+ * createErrorMarkers(errors)
34
+ * ];
35
+ * ```
36
+ */
37
+ export declare const createErrorMarkers: (errors: RegexError[]) => StateField<DecorationSet>[];
38
+ /**
39
+ * 更新错误标注的辅助函数
40
+ *
41
+ * @param view - EditorView 实例
42
+ * @param errors - 新的错误列表
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * updateErrorMarkers(editorView, validationErrors);
47
+ * ```
48
+ */
49
+ export declare const updateErrorMarkers: (view: EditorView, errors: RegexError[]) => void;
@@ -0,0 +1,154 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ 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); }
3
+ 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; }
4
+ /**
5
+ * CodeMirror 错误标注扩展
6
+ *
7
+ * @description
8
+ * 为 CodeMirror 编辑器添加错误标注功能,支持波浪下划线高亮显示错误位置。
9
+ *
10
+ * @module RegexEditor/core/extensions/errorMarker
11
+ */
12
+
13
+ import { Decoration, EditorView } from '@codemirror/view';
14
+ import { StateField, StateEffect } from '@codemirror/state';
15
+ /**
16
+ * 设置错误的 StateEffect
17
+ */
18
+ export var setErrorsEffect = StateEffect.define();
19
+
20
+ /**
21
+ * 错误标注装饰
22
+ *
23
+ * @description
24
+ * 使用红色波浪下划线标注错误位置
25
+ */
26
+ var errorMark = Decoration.mark({
27
+ attributes: {
28
+ class: 'cm-regex-error',
29
+ style: 'text-decoration: wavy underline red; text-decoration-skip-ink: none;'
30
+ }
31
+ });
32
+
33
+ /**
34
+ * 警告标注装饰
35
+ *
36
+ * @description
37
+ * 使用橙色波浪下划线标注警告位置
38
+ */
39
+ var warningMark = Decoration.mark({
40
+ attributes: {
41
+ class: 'cm-regex-warning',
42
+ style: 'text-decoration: wavy underline orange; text-decoration-skip-ink: none;'
43
+ }
44
+ });
45
+
46
+ /**
47
+ * 信息标注装饰
48
+ *
49
+ * @description
50
+ * 使用蓝色波浪下划线标注信息位置
51
+ */
52
+ var infoMark = Decoration.mark({
53
+ attributes: {
54
+ class: 'cm-regex-info',
55
+ style: 'text-decoration: wavy underline blue; text-decoration-skip-ink: none;'
56
+ }
57
+ });
58
+
59
+ /**
60
+ * 错误装饰状态字段
61
+ *
62
+ * @description
63
+ * 管理错误标注的 DecorationSet
64
+ */
65
+ export var errorDecorationsField = StateField.define({
66
+ create: function create() {
67
+ return Decoration.none;
68
+ },
69
+ update: function update(decorations, tr) {
70
+ // 遍历事务中的所有 effect
71
+ var _iterator = _createForOfIteratorHelper(tr.effects),
72
+ _step;
73
+ try {
74
+ var _loop = function _loop() {
75
+ var effect = _step.value;
76
+ if (effect.is(setErrorsEffect)) {
77
+ // 更新错误标注
78
+ var errors = effect.value;
79
+ var newDecorations = [];
80
+ errors.forEach(function (error) {
81
+ var _error$position = error.position,
82
+ start = _error$position.start,
83
+ end = _error$position.end;
84
+
85
+ // 确保位置有效
86
+ if (start >= 0 && end <= tr.newDoc.length && start < end) {
87
+ // 根据严重程度选择装饰
88
+ var mark = errorMark;
89
+ if (error.severity === 'warning') {
90
+ mark = warningMark;
91
+ } else if (error.severity === 'info') {
92
+ mark = infoMark;
93
+ }
94
+ newDecorations.push(mark.range(start, end));
95
+ }
96
+ });
97
+ return {
98
+ v: Decoration.set(newDecorations, true)
99
+ };
100
+ }
101
+ },
102
+ _ret;
103
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
104
+ _ret = _loop();
105
+ if (_ret) return _ret.v;
106
+ }
107
+
108
+ // 如果文档改变,需要映射装饰位置
109
+ } catch (err) {
110
+ _iterator.e(err);
111
+ } finally {
112
+ _iterator.f();
113
+ }
114
+ return decorations.map(tr.changes);
115
+ },
116
+ provide: function provide(f) {
117
+ return EditorView.decorations.from(f);
118
+ }
119
+ });
120
+
121
+ /**
122
+ * 创建错误标注扩展
123
+ *
124
+ * @param errors - 错误列表
125
+ * @returns CodeMirror 扩展数组
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const extensions = [
130
+ * javascript(),
131
+ * createErrorMarkers(errors)
132
+ * ];
133
+ * ```
134
+ */
135
+ export var createErrorMarkers = function createErrorMarkers(errors) {
136
+ return [errorDecorationsField];
137
+ };
138
+
139
+ /**
140
+ * 更新错误标注的辅助函数
141
+ *
142
+ * @param view - EditorView 实例
143
+ * @param errors - 新的错误列表
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * updateErrorMarkers(editorView, validationErrors);
148
+ * ```
149
+ */
150
+ export var updateErrorMarkers = function updateErrorMarkers(view, errors) {
151
+ view.dispatch({
152
+ effects: setErrorsEffect.of(errors)
153
+ });
154
+ };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * 正则表达式编辑器核心组件 - 类型定义
3
+ *
4
+ * @module RegexEditor/core/types
5
+ * @description 定义编辑器核心组件的 Props 和相关类型
6
+ */
7
+ import type { RegexError, ValidationResult } from '../validation/types';
8
+ /**
9
+ * CodeMirror 包装器组件属性
10
+ *
11
+ * @interface CodeMirrorWrapperProps
12
+ * @property {string} value - 编辑器内容
13
+ * @property {(value: string) => void} onChange - 内容变更回调
14
+ * @property {string} [placeholder] - 占位符文本
15
+ * @property {boolean} [readOnly] - 是否只读模式
16
+ * @property {boolean} [disabled] - 是否禁用编辑
17
+ * @property {RegexError[]} [errors] - 错误列表(用于标注)
18
+ * @property {string} [height] - 编辑器高度(CSS 值)
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * <CodeMirrorWrapper
23
+ * value={pattern}
24
+ * onChange={setPattern}
25
+ * placeholder="请输入正则表达式"
26
+ * errors={validationErrors}
27
+ * height="120px"
28
+ * />
29
+ * ```
30
+ */
31
+ export interface CodeMirrorWrapperProps {
32
+ value: string;
33
+ onChange: (value: string) => void;
34
+ placeholder?: string;
35
+ readOnly?: boolean;
36
+ disabled?: boolean;
37
+ errors?: RegexError[];
38
+ height?: string;
39
+ }
40
+ /**
41
+ * 正则表达式编辑器组件属性
42
+ *
43
+ * @interface RegexEditorProps
44
+ * @property {string} [value] - 正则表达式字符串
45
+ * @property {(value: string) => void} [onChange] - 值变更回调
46
+ * @property {string} [placeholder] - 占位符文本
47
+ * @property {boolean} [readOnly] - 是否只读模式
48
+ * @property {boolean} [disabled] - 是否禁用编辑
49
+ * @property {boolean} [showComplexity] - 是否显示复杂度分析
50
+ * @property {boolean} [showRailroadDiagram] - 是否显示 Railroad Diagram 可视化
51
+ * @property {(result: ValidationResult) => void} [onValidate] - 验证结果回调
52
+ * @property {string} [height] - 编辑器高度(CSS 值)
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * <RegexEditor
57
+ * value={pattern}
58
+ * onChange={setPattern}
59
+ * showComplexity={true}
60
+ * height="200px"
61
+ * onValidate={(result) => {
62
+ * if (!result.valid) {
63
+ * console.error('验证失败:', result.errors);
64
+ * }
65
+ * }}
66
+ * />
67
+ * ```
68
+ */
69
+ export interface RegexEditorProps {
70
+ value?: string;
71
+ onChange?: (value: string) => void;
72
+ placeholder?: string;
73
+ readOnly?: boolean;
74
+ disabled?: boolean;
75
+ showComplexity?: boolean;
76
+ showRailroadDiagram?: boolean;
77
+ onValidate?: (result: ValidationResult) => void;
78
+ height?: string;
79
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * React Hooks for RegexEditor
3
+ *
4
+ * @module RegexEditor/hooks
5
+ */
6
+ export { useRegexValidation } from './useRegexValidation';
7
+ export type { UseRegexValidationResult } from './useRegexValidation';
8
+ export { useTemplateManager } from './useTemplateManager';
9
+ export type { UseTemplateManagerOptions, UseTemplateManagerReturn, } from './useTemplateManager';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * React Hooks for RegexEditor
3
+ *
4
+ * @module RegexEditor/hooks
5
+ */
6
+
7
+ export { useRegexValidation } from "./useRegexValidation";
8
+ export { useTemplateManager } from "./useTemplateManager";