@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.
- 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 +3 -1
- package/dist/cjs/index.js +55 -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/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 +3 -1
- package/dist/esm/index.js +5 -2
- 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,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RegexEditor Visualizer - 导出索引
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/visualizer
|
|
5
|
+
* @description 可视化组件导出
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// 组件导出
|
|
9
|
+
export { RegexTester } from "./RegexTester";
|
|
10
|
+
export { FlagsSelector } from "./FlagsSelector";
|
|
11
|
+
export { MatchItem } from "./MatchItem";
|
|
12
|
+
export { RegexRailroadDiagram } from "./RegexRailroadDiagram";
|
|
13
|
+
|
|
14
|
+
// 类型导出
|
|
15
|
+
|
|
16
|
+
// 工具函数导出
|
|
17
|
+
export { flagsToString, stringToFlags, performMatch, performReplace, highlightMatches, formatPosition, isValidRegex } from "./utils";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式可视化 - 类型定义
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/visualizer/types
|
|
5
|
+
* @description 定义可视化组件的类型和接口
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
/**
|
|
9
|
+
* 正则表达式标志
|
|
10
|
+
*/
|
|
11
|
+
export interface RegexFlags {
|
|
12
|
+
/** 全局匹配 */
|
|
13
|
+
global?: boolean;
|
|
14
|
+
/** 忽略大小写 */
|
|
15
|
+
ignoreCase?: boolean;
|
|
16
|
+
/** 多行模式 */
|
|
17
|
+
multiline?: boolean;
|
|
18
|
+
/** dotAll 模式 (. 匹配换行符) */
|
|
19
|
+
dotAll?: boolean;
|
|
20
|
+
/** Unicode 模式 */
|
|
21
|
+
unicode?: boolean;
|
|
22
|
+
/** 粘性匹配 */
|
|
23
|
+
sticky?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 匹配结果
|
|
27
|
+
*/
|
|
28
|
+
export interface MatchResult {
|
|
29
|
+
/** 匹配的索引位置 */
|
|
30
|
+
index: number;
|
|
31
|
+
/** 匹配结束位置 */
|
|
32
|
+
lastIndex: number;
|
|
33
|
+
/** 完整匹配的文本 */
|
|
34
|
+
fullMatch: string;
|
|
35
|
+
/** 捕获组数组 (索引 0 是完整匹配) */
|
|
36
|
+
groups: string[];
|
|
37
|
+
/** 命名捕获组 */
|
|
38
|
+
namedGroups?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* RegexTester 组件属性
|
|
42
|
+
*/
|
|
43
|
+
export interface RegexTesterProps {
|
|
44
|
+
/** 正则表达式模式 */
|
|
45
|
+
pattern: string;
|
|
46
|
+
/** 正则表达式标志 */
|
|
47
|
+
flags?: RegexFlags;
|
|
48
|
+
/** 测试文本 */
|
|
49
|
+
testText?: string;
|
|
50
|
+
/** 测试文本变化回调 */
|
|
51
|
+
onTestTextChange?: (text: string) => void;
|
|
52
|
+
/** 标志变化回调 */
|
|
53
|
+
onFlagsChange?: (flags: RegexFlags) => void;
|
|
54
|
+
/** 匹配结果回调 */
|
|
55
|
+
onMatchResults?: (results: MatchResult[]) => void;
|
|
56
|
+
/** 是否启用替换功能 */
|
|
57
|
+
enableReplace?: boolean;
|
|
58
|
+
/** 最大匹配数量限制 */
|
|
59
|
+
maxMatches?: number;
|
|
60
|
+
/** 匹配超时时间 (毫秒) */
|
|
61
|
+
matchTimeout?: number;
|
|
62
|
+
/** 是否只读 */
|
|
63
|
+
readOnly?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* RegexVisualizer 主容器组件属性
|
|
67
|
+
*/
|
|
68
|
+
export interface RegexVisualizerProps {
|
|
69
|
+
/** 正则表达式模式 */
|
|
70
|
+
pattern: string;
|
|
71
|
+
/** 是否显示 AST 可视化 */
|
|
72
|
+
showAST?: boolean;
|
|
73
|
+
/** 是否显示 Railroad 图 */
|
|
74
|
+
showRailroad?: boolean;
|
|
75
|
+
/** 其他 RegexTester 属性 */
|
|
76
|
+
testerProps?: Omit<RegexTesterProps, 'pattern'>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* FlagsSelector 组件属性
|
|
80
|
+
*/
|
|
81
|
+
export interface FlagsSelectorProps {
|
|
82
|
+
/** 当前标志值 */
|
|
83
|
+
value?: RegexFlags;
|
|
84
|
+
/** 标志变化回调 */
|
|
85
|
+
onChange?: (flags: RegexFlags) => void;
|
|
86
|
+
/** 是否禁用 */
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* MatchItem 组件属性
|
|
91
|
+
*/
|
|
92
|
+
export interface MatchItemProps {
|
|
93
|
+
/** 匹配结果 */
|
|
94
|
+
match: MatchResult;
|
|
95
|
+
/** 匹配项索引 */
|
|
96
|
+
index: number;
|
|
97
|
+
/** 是否高亮显示 */
|
|
98
|
+
highlighted?: boolean;
|
|
99
|
+
/** 点击回调 */
|
|
100
|
+
onClick?: (match: MatchResult, index: number) => void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* ReplacePreview 组件属性
|
|
104
|
+
*/
|
|
105
|
+
export interface ReplacePreviewProps {
|
|
106
|
+
/** 原始文本 */
|
|
107
|
+
originalText: string;
|
|
108
|
+
/** 正则表达式模式 */
|
|
109
|
+
pattern: string;
|
|
110
|
+
/** 标志 */
|
|
111
|
+
flags?: RegexFlags;
|
|
112
|
+
/** 替换文本 (支持 $1, $2 等) */
|
|
113
|
+
replaceText: string;
|
|
114
|
+
/** 替换文本变化回调 */
|
|
115
|
+
onReplaceTextChange?: (text: string) => void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* RegexRailroadDiagram 组件属性
|
|
119
|
+
*/
|
|
120
|
+
export interface RegexRailroadDiagramProps {
|
|
121
|
+
/** 正则表达式模式 */
|
|
122
|
+
pattern: string;
|
|
123
|
+
/** 是否显示标题 */
|
|
124
|
+
showTitle?: boolean;
|
|
125
|
+
/** 卡片大小 */
|
|
126
|
+
size?: 'small' | 'default';
|
|
127
|
+
/** 自定义样式 */
|
|
128
|
+
style?: React.CSSProperties;
|
|
129
|
+
/** 自定义类名 */
|
|
130
|
+
className?: string;
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正则表达式可视化 - 工具函数
|
|
3
|
+
*
|
|
4
|
+
* @module RegexEditor/visualizer/utils
|
|
5
|
+
* @description 提供匹配、标志转换等工具函数
|
|
6
|
+
*/
|
|
7
|
+
import type { RegexFlags, MatchResult } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* 将标志对象转换为标志字符串
|
|
10
|
+
*
|
|
11
|
+
* @param flags - 标志对象
|
|
12
|
+
* @returns 标志字符串 (如 "gim")
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* flagsToString({ global: true, ignoreCase: true })
|
|
17
|
+
* // => "gi"
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function flagsToString(flags?: RegexFlags): string;
|
|
21
|
+
/**
|
|
22
|
+
* 将标志字符串转换为标志对象
|
|
23
|
+
*
|
|
24
|
+
* @param flagsStr - 标志字符串 (如 "gim")
|
|
25
|
+
* @returns 标志对象
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* stringToFlags("gi")
|
|
30
|
+
* // => { global: true, ignoreCase: true }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function stringToFlags(flagsStr: string): RegexFlags;
|
|
34
|
+
/**
|
|
35
|
+
* 执行正则匹配并返回所有匹配结果
|
|
36
|
+
*
|
|
37
|
+
* @param pattern - 正则表达式模式
|
|
38
|
+
* @param text - 测试文本
|
|
39
|
+
* @param flags - 标志
|
|
40
|
+
* @param maxMatches - 最大匹配数量限制
|
|
41
|
+
* @param timeout - 超时时间 (毫秒)
|
|
42
|
+
* @returns 匹配结果数组,如果出错返回 null
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const results = performMatch('\\d+', 'abc 123 def 456', { global: true });
|
|
47
|
+
* // => [
|
|
48
|
+
* // { index: 4, lastIndex: 7, fullMatch: '123', groups: ['123'] },
|
|
49
|
+
* // { index: 12, lastIndex: 15, fullMatch: '456', groups: ['456'] }
|
|
50
|
+
* // ]
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function performMatch(pattern: string, text: string, flags?: RegexFlags, maxMatches?: number, timeout?: number): MatchResult[] | null;
|
|
54
|
+
/**
|
|
55
|
+
* 执行正则替换并返回结果
|
|
56
|
+
*
|
|
57
|
+
* @param pattern - 正则表达式模式
|
|
58
|
+
* @param text - 原始文本
|
|
59
|
+
* @param replaceText - 替换文本 (支持 $1, $2 等)
|
|
60
|
+
* @param flags - 标志
|
|
61
|
+
* @returns 替换后的文本,如果出错返回 null
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* performReplace('(\\d+)', 'abc 123 def', 'NUM:$1', { global: true })
|
|
66
|
+
* // => "abc NUM:123 def"
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function performReplace(pattern: string, text: string, replaceText: string, flags?: RegexFlags): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* 高亮文本中的匹配部分
|
|
72
|
+
*
|
|
73
|
+
* @param text - 原始文本
|
|
74
|
+
* @param matches - 匹配结果数组
|
|
75
|
+
* @returns 带高亮标记的 HTML 字符串
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* highlightMatches('abc 123 def', [
|
|
80
|
+
* { index: 4, lastIndex: 7, fullMatch: '123', groups: ['123'] }
|
|
81
|
+
* ])
|
|
82
|
+
* // => 'abc <mark class="regex-match">123</mark> def'
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function highlightMatches(text: string, matches: MatchResult[]): string;
|
|
86
|
+
/**
|
|
87
|
+
* 格式化匹配位置
|
|
88
|
+
*
|
|
89
|
+
* @param match - 匹配结果
|
|
90
|
+
* @returns 格式化的位置字符串
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* formatPosition({ index: 10, lastIndex: 15, ... })
|
|
95
|
+
* // => "10-15"
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function formatPosition(match: MatchResult): string;
|
|
99
|
+
/**
|
|
100
|
+
* 检查正则表达式是否有效
|
|
101
|
+
*
|
|
102
|
+
* @param pattern - 正则表达式模式
|
|
103
|
+
* @param flags - 标志
|
|
104
|
+
* @returns 是否有效
|
|
105
|
+
*/
|
|
106
|
+
export declare function isValidRegex(pattern: string, flags?: RegexFlags): boolean;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
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."); }
|
|
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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
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; }
|
|
7
|
+
/**
|
|
8
|
+
* 正则表达式可视化 - 工具函数
|
|
9
|
+
*
|
|
10
|
+
* @module RegexEditor/visualizer/utils
|
|
11
|
+
* @description 提供匹配、标志转换等工具函数
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 将标志对象转换为标志字符串
|
|
16
|
+
*
|
|
17
|
+
* @param flags - 标志对象
|
|
18
|
+
* @returns 标志字符串 (如 "gim")
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* flagsToString({ global: true, ignoreCase: true })
|
|
23
|
+
* // => "gi"
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function flagsToString(flags) {
|
|
27
|
+
if (!flags) return '';
|
|
28
|
+
var result = '';
|
|
29
|
+
if (flags.global) result += 'g';
|
|
30
|
+
if (flags.ignoreCase) result += 'i';
|
|
31
|
+
if (flags.multiline) result += 'm';
|
|
32
|
+
if (flags.dotAll) result += 's';
|
|
33
|
+
if (flags.unicode) result += 'u';
|
|
34
|
+
if (flags.sticky) result += 'y';
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 将标志字符串转换为标志对象
|
|
40
|
+
*
|
|
41
|
+
* @param flagsStr - 标志字符串 (如 "gim")
|
|
42
|
+
* @returns 标志对象
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* stringToFlags("gi")
|
|
47
|
+
* // => { global: true, ignoreCase: true }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function stringToFlags(flagsStr) {
|
|
51
|
+
return {
|
|
52
|
+
global: flagsStr.includes('g'),
|
|
53
|
+
ignoreCase: flagsStr.includes('i'),
|
|
54
|
+
multiline: flagsStr.includes('m'),
|
|
55
|
+
dotAll: flagsStr.includes('s'),
|
|
56
|
+
unicode: flagsStr.includes('u'),
|
|
57
|
+
sticky: flagsStr.includes('y')
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 执行正则匹配并返回所有匹配结果
|
|
63
|
+
*
|
|
64
|
+
* @param pattern - 正则表达式模式
|
|
65
|
+
* @param text - 测试文本
|
|
66
|
+
* @param flags - 标志
|
|
67
|
+
* @param maxMatches - 最大匹配数量限制
|
|
68
|
+
* @param timeout - 超时时间 (毫秒)
|
|
69
|
+
* @returns 匹配结果数组,如果出错返回 null
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const results = performMatch('\\d+', 'abc 123 def 456', { global: true });
|
|
74
|
+
* // => [
|
|
75
|
+
* // { index: 4, lastIndex: 7, fullMatch: '123', groups: ['123'] },
|
|
76
|
+
* // { index: 12, lastIndex: 15, fullMatch: '456', groups: ['456'] }
|
|
77
|
+
* // ]
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function performMatch(pattern, text, flags) {
|
|
81
|
+
var maxMatches = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1000;
|
|
82
|
+
var timeout = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 5000;
|
|
83
|
+
try {
|
|
84
|
+
// 创建正则表达式
|
|
85
|
+
var flagsStr = flagsToString(flags);
|
|
86
|
+
var regex = new RegExp(pattern, flagsStr);
|
|
87
|
+
var results = [];
|
|
88
|
+
var startTime = Date.now();
|
|
89
|
+
|
|
90
|
+
// 如果是全局匹配,使用 exec 循环
|
|
91
|
+
if (flags !== null && flags !== void 0 && flags.global) {
|
|
92
|
+
var match;
|
|
93
|
+
while ((match = regex.exec(text)) !== null) {
|
|
94
|
+
// 检查超时
|
|
95
|
+
if (Date.now() - startTime > timeout) {
|
|
96
|
+
console.warn('正则匹配超时');
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 检查数量限制
|
|
101
|
+
if (results.length >= maxMatches) {
|
|
102
|
+
console.warn("\u5339\u914D\u6570\u91CF\u8D85\u8FC7\u9650\u5236 (".concat(maxMatches, ")"));
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (match.index !== undefined) {
|
|
106
|
+
results.push({
|
|
107
|
+
index: match.index,
|
|
108
|
+
lastIndex: match.index + match[0].length,
|
|
109
|
+
fullMatch: match[0],
|
|
110
|
+
groups: Array.from(match),
|
|
111
|
+
namedGroups: match.groups
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 防止无限循环(零宽匹配)
|
|
116
|
+
if (match.index === regex.lastIndex) {
|
|
117
|
+
regex.lastIndex++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
// 非全局匹配,只匹配一次
|
|
122
|
+
var _match = regex.exec(text);
|
|
123
|
+
if (_match && _match.index !== undefined) {
|
|
124
|
+
results.push({
|
|
125
|
+
index: _match.index,
|
|
126
|
+
lastIndex: _match.index + _match[0].length,
|
|
127
|
+
fullMatch: _match[0],
|
|
128
|
+
groups: Array.from(_match),
|
|
129
|
+
namedGroups: _match.groups
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return results;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error('正则匹配错误:', error);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 执行正则替换并返回结果
|
|
142
|
+
*
|
|
143
|
+
* @param pattern - 正则表达式模式
|
|
144
|
+
* @param text - 原始文本
|
|
145
|
+
* @param replaceText - 替换文本 (支持 $1, $2 等)
|
|
146
|
+
* @param flags - 标志
|
|
147
|
+
* @returns 替换后的文本,如果出错返回 null
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* performReplace('(\\d+)', 'abc 123 def', 'NUM:$1', { global: true })
|
|
152
|
+
* // => "abc NUM:123 def"
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function performReplace(pattern, text, replaceText, flags) {
|
|
156
|
+
try {
|
|
157
|
+
var flagsStr = flagsToString(flags);
|
|
158
|
+
var regex = new RegExp(pattern, flagsStr);
|
|
159
|
+
return text.replace(regex, replaceText);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('正则替换错误:', error);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 高亮文本中的匹配部分
|
|
168
|
+
*
|
|
169
|
+
* @param text - 原始文本
|
|
170
|
+
* @param matches - 匹配结果数组
|
|
171
|
+
* @returns 带高亮标记的 HTML 字符串
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* highlightMatches('abc 123 def', [
|
|
176
|
+
* { index: 4, lastIndex: 7, fullMatch: '123', groups: ['123'] }
|
|
177
|
+
* ])
|
|
178
|
+
* // => 'abc <mark class="regex-match">123</mark> def'
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export function highlightMatches(text, matches) {
|
|
182
|
+
if (!matches || matches.length === 0) {
|
|
183
|
+
return escapeHtml(text);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 按索引排序
|
|
187
|
+
var sortedMatches = _toConsumableArray(matches).sort(function (a, b) {
|
|
188
|
+
return a.index - b.index;
|
|
189
|
+
});
|
|
190
|
+
var result = '';
|
|
191
|
+
var lastIndex = 0;
|
|
192
|
+
sortedMatches.forEach(function (match, idx) {
|
|
193
|
+
// 添加未匹配部分
|
|
194
|
+
if (match.index > lastIndex) {
|
|
195
|
+
result += escapeHtml(text.substring(lastIndex, match.index));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 添加匹配部分 (带高亮)
|
|
199
|
+
result += "<mark class=\"regex-match\" data-match-index=\"".concat(idx, "\">").concat(escapeHtml(match.fullMatch), "</mark>");
|
|
200
|
+
lastIndex = match.lastIndex;
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// 添加剩余部分
|
|
204
|
+
if (lastIndex < text.length) {
|
|
205
|
+
result += escapeHtml(text.substring(lastIndex));
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 转义 HTML 特殊字符
|
|
212
|
+
*/
|
|
213
|
+
function escapeHtml(text) {
|
|
214
|
+
var map = {
|
|
215
|
+
'&': '&',
|
|
216
|
+
'<': '<',
|
|
217
|
+
'>': '>',
|
|
218
|
+
'"': '"',
|
|
219
|
+
"'": '''
|
|
220
|
+
};
|
|
221
|
+
return text.replace(/[&<>"']/g, function (char) {
|
|
222
|
+
return map[char];
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 格式化匹配位置
|
|
228
|
+
*
|
|
229
|
+
* @param match - 匹配结果
|
|
230
|
+
* @returns 格式化的位置字符串
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* formatPosition({ index: 10, lastIndex: 15, ... })
|
|
235
|
+
* // => "10-15"
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export function formatPosition(match) {
|
|
239
|
+
return "".concat(match.index, "-").concat(match.lastIndex);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 检查正则表达式是否有效
|
|
244
|
+
*
|
|
245
|
+
* @param pattern - 正则表达式模式
|
|
246
|
+
* @param flags - 标志
|
|
247
|
+
* @returns 是否有效
|
|
248
|
+
*/
|
|
249
|
+
export function isValidRegex(pattern, flags) {
|
|
250
|
+
try {
|
|
251
|
+
new RegExp(pattern, flagsToString(flags));
|
|
252
|
+
return true;
|
|
253
|
+
} catch (_unused) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -19,10 +19,12 @@ import { GeneratedListPage } from "./generatedListPage";
|
|
|
19
19
|
import { StandardFormDialog, withStandardForm, FieldCreators, createSelectField, createCascaderField } from "./standardFormDialog";
|
|
20
20
|
import DeleteConfirm from "./deleteConfirm";
|
|
21
21
|
import { RuleBuilder } from "./RuleBuilder";
|
|
22
|
-
|
|
22
|
+
import { RegexEditor, useRegexValidation, useTemplateManager, TemplateSelector, TemplateCategory, RegexTester, FlagsSelector, MatchItem, RegexRailroadDiagram } from "./components/RegexEditor";
|
|
23
|
+
export { AgGridColumn, AgGridPlus, ArrayTable, ArrayTableIndex, Card, Dashboard, DialogSelect, DraggableModal, Editable, ExtensibleGrid, flattenTreeDeep, FormDesigner, FormProContext, FormProLayout, GridPlusContext, ImportModal, QueryBuilder, ToolBar, FullScreenAlert, ConfirmPro, GeneratedListPage, StandardFormDialog, withStandardForm, FieldCreators, createSelectField, createCascaderField, DeleteConfirm, RuleBuilder, RegexEditor, useRegexValidation, useTemplateManager, TemplateSelector, TemplateCategory, RegexTester, FlagsSelector, MatchItem, RegexRailroadDiagram, };
|
|
23
24
|
export type * from "./generatedListPage";
|
|
24
25
|
export type * from "./standardFormDialog";
|
|
25
26
|
export type * from "./deleteConfirm";
|
|
26
27
|
export type * from "./importModal";
|
|
27
28
|
export type * from "./fullScreenAlert";
|
|
28
29
|
export type * from "./RuleBuilder";
|
|
30
|
+
export type { ParseResult as RegexParseResult, ValidationResult as RegexValidationResult, RegexError, ComplexityMetrics, ASTNode, AstRegExp, RegexTemplate, TestResult as RegexTestResult, CodeMirrorWrapperProps, RegexEditorProps, RegexFlags, MatchResult, RegexTesterProps, FlagsSelectorProps, MatchItemProps, RegexRailroadDiagramProps, } from "./components/RegexEditor";
|
package/dist/esm/index.js
CHANGED
|
@@ -19,6 +19,9 @@ import { GeneratedListPage } from "./generatedListPage";
|
|
|
19
19
|
import { StandardFormDialog, withStandardForm, FieldCreators, createSelectField, createCascaderField } from "./standardFormDialog";
|
|
20
20
|
import DeleteConfirm from "./deleteConfirm";
|
|
21
21
|
import { RuleBuilder } from "./RuleBuilder";
|
|
22
|
-
|
|
22
|
+
import { RegexEditor, useRegexValidation, useTemplateManager, TemplateSelector, TemplateCategory, RegexTester, FlagsSelector, MatchItem, RegexRailroadDiagram } from "./components/RegexEditor";
|
|
23
|
+
export { AgGridColumn, AgGridPlus, ArrayTable, ArrayTableIndex, Card, Dashboard, DialogSelect, DraggableModal, Editable, ExtensibleGrid, flattenTreeDeep, FormDesigner, FormProContext, FormProLayout, GridPlusContext, ImportModal, QueryBuilder, ToolBar, FullScreenAlert, ConfirmPro, GeneratedListPage, StandardFormDialog, withStandardForm, FieldCreators, createSelectField, createCascaderField, DeleteConfirm, RuleBuilder, RegexEditor, useRegexValidation, useTemplateManager, TemplateSelector, TemplateCategory, RegexTester, FlagsSelector, MatchItem, RegexRailroadDiagram };
|
|
23
24
|
|
|
24
|
-
// 导出类型定义
|
|
25
|
+
// 导出类型定义
|
|
26
|
+
|
|
27
|
+
// RegexEditor 类型定义 - 使用命名导出避免冲突
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for railroad-diagrams
|
|
3
|
+
* Project: https://github.com/tabatkins/railroad-diagrams
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare module 'railroad-diagrams' {
|
|
7
|
+
export class Diagram {
|
|
8
|
+
constructor(children: DiagramNode[]);
|
|
9
|
+
toSVG(): SVGElement;
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class ComplexDiagram extends Diagram {}
|
|
14
|
+
|
|
15
|
+
export class Sequence {
|
|
16
|
+
constructor(children: DiagramNode[]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class Choice {
|
|
20
|
+
constructor(defaultIndex: number, children: DiagramNode[]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Optional {
|
|
24
|
+
constructor(child: DiagramNode, skip?: 'skip');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class OneOrMore {
|
|
28
|
+
constructor(child: DiagramNode, repeat?: DiagramNode);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ZeroOrMore {
|
|
32
|
+
constructor(child: DiagramNode, repeat?: DiagramNode, skip?: 'skip');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class Terminal {
|
|
36
|
+
constructor(text: string);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class NonTerminal {
|
|
40
|
+
constructor(text: string);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Comment {
|
|
44
|
+
constructor(text: string);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class Skip {}
|
|
48
|
+
|
|
49
|
+
export type DiagramNode =
|
|
50
|
+
| Sequence
|
|
51
|
+
| Choice
|
|
52
|
+
| Optional
|
|
53
|
+
| OneOrMore
|
|
54
|
+
| ZeroOrMore
|
|
55
|
+
| Terminal
|
|
56
|
+
| NonTerminal
|
|
57
|
+
| Comment
|
|
58
|
+
| Skip;
|
|
59
|
+
}
|