@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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTemplateManager Hook
|
|
3
|
+
* 提供完整的模板管理功能,包括加载、创建、更新、删除、搜索等
|
|
4
|
+
*/
|
|
5
|
+
import type { RegexTemplate } from '../templates/types';
|
|
6
|
+
import { TemplateCategory } from '../templates/types';
|
|
7
|
+
import { getTemplateStats } from '../templates';
|
|
8
|
+
export interface UseTemplateManagerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* 是否自动加载模板
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
autoLoad?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 初始搜索关键词
|
|
16
|
+
*/
|
|
17
|
+
initialKeyword?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 初始分类过滤
|
|
20
|
+
*/
|
|
21
|
+
initialCategory?: TemplateCategory | 'all';
|
|
22
|
+
/**
|
|
23
|
+
* 初始排序方式
|
|
24
|
+
*/
|
|
25
|
+
initialSortBy?: 'default' | 'popular' | 'recent';
|
|
26
|
+
}
|
|
27
|
+
export interface UseTemplateManagerReturn {
|
|
28
|
+
templates: RegexTemplate[];
|
|
29
|
+
filteredTemplates: RegexTemplate[];
|
|
30
|
+
selectedTemplate: RegexTemplate | null;
|
|
31
|
+
searchKeyword: string;
|
|
32
|
+
selectedCategory: TemplateCategory | 'all';
|
|
33
|
+
sortBy: 'default' | 'popular' | 'recent';
|
|
34
|
+
stats: ReturnType<typeof getTemplateStats>;
|
|
35
|
+
isStorageAvailable: boolean;
|
|
36
|
+
loading: boolean;
|
|
37
|
+
error: string | null;
|
|
38
|
+
selectTemplate: (id: string) => void;
|
|
39
|
+
clearSelection: () => void;
|
|
40
|
+
useTemplate: (id: string) => RegexTemplate | undefined;
|
|
41
|
+
setSearchKeyword: (keyword: string) => void;
|
|
42
|
+
setSelectedCategory: (category: TemplateCategory | 'all') => void;
|
|
43
|
+
setSortBy: (sortBy: 'default' | 'popular' | 'recent') => void;
|
|
44
|
+
resetFilters: () => void;
|
|
45
|
+
createTemplate: (template: Omit<RegexTemplate, 'id' | 'isCustom' | 'useCount' | 'lastUsed'>) => Promise<RegexTemplate>;
|
|
46
|
+
updateTemplate: (id: string, updates: Partial<Omit<RegexTemplate, 'id' | 'isCustom'>>) => Promise<boolean>;
|
|
47
|
+
deleteTemplate: (id: string) => Promise<boolean>;
|
|
48
|
+
duplicateTemplate: (id: string, newName?: string) => Promise<RegexTemplate | null>;
|
|
49
|
+
deleteMultipleTemplates: (ids: string[]) => Promise<boolean>;
|
|
50
|
+
clearAllCustomTemplates: () => Promise<boolean>;
|
|
51
|
+
exportTemplates: () => string;
|
|
52
|
+
importTemplates: (jsonString: string, merge?: boolean) => Promise<boolean>;
|
|
53
|
+
validateTemplate: (template: Partial<RegexTemplate>) => {
|
|
54
|
+
valid: boolean;
|
|
55
|
+
errors: string[];
|
|
56
|
+
};
|
|
57
|
+
getMostUsedTemplates: (limit?: number) => RegexTemplate[];
|
|
58
|
+
getRecentlyUsedTemplates: (limit?: number) => RegexTemplate[];
|
|
59
|
+
refresh: () => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* useTemplateManager Hook
|
|
63
|
+
*/
|
|
64
|
+
export declare const useTemplateManager: (options?: UseTemplateManagerOptions) => UseTemplateManagerReturn;
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useTemplateManager = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _templates = require("../templates");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
13
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
14
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
+
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."); }
|
|
17
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
18
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
20
|
+
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."); }
|
|
21
|
+
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); }
|
|
22
|
+
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; }
|
|
23
|
+
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; } }
|
|
24
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /**
|
|
25
|
+
* useTemplateManager Hook
|
|
26
|
+
* 提供完整的模板管理功能,包括加载、创建、更新、删除、搜索等
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* useTemplateManager Hook
|
|
30
|
+
*/
|
|
31
|
+
var useTemplateManager = exports.useTemplateManager = function useTemplateManager() {
|
|
32
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
33
|
+
var _options$autoLoad = options.autoLoad,
|
|
34
|
+
autoLoad = _options$autoLoad === void 0 ? true : _options$autoLoad,
|
|
35
|
+
_options$initialKeywo = options.initialKeyword,
|
|
36
|
+
initialKeyword = _options$initialKeywo === void 0 ? '' : _options$initialKeywo,
|
|
37
|
+
_options$initialCateg = options.initialCategory,
|
|
38
|
+
initialCategory = _options$initialCateg === void 0 ? 'all' : _options$initialCateg,
|
|
39
|
+
_options$initialSortB = options.initialSortBy,
|
|
40
|
+
initialSortBy = _options$initialSortB === void 0 ? 'default' : _options$initialSortB;
|
|
41
|
+
|
|
42
|
+
// 状态管理
|
|
43
|
+
var _useState = (0, _react.useState)([]),
|
|
44
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
45
|
+
templates = _useState2[0],
|
|
46
|
+
setTemplates = _useState2[1];
|
|
47
|
+
var _useState3 = (0, _react.useState)(null),
|
|
48
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
49
|
+
selectedTemplate = _useState4[0],
|
|
50
|
+
setSelectedTemplate = _useState4[1];
|
|
51
|
+
var _useState5 = (0, _react.useState)(initialKeyword),
|
|
52
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
53
|
+
searchKeyword = _useState6[0],
|
|
54
|
+
setSearchKeyword = _useState6[1];
|
|
55
|
+
var _useState7 = (0, _react.useState)(initialCategory),
|
|
56
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
57
|
+
selectedCategory = _useState8[0],
|
|
58
|
+
setSelectedCategory = _useState8[1];
|
|
59
|
+
var _useState9 = (0, _react.useState)(initialSortBy),
|
|
60
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
61
|
+
sortBy = _useState10[0],
|
|
62
|
+
setSortBy = _useState10[1];
|
|
63
|
+
var _useState11 = (0, _react.useState)(false),
|
|
64
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
65
|
+
loading = _useState12[0],
|
|
66
|
+
setLoading = _useState12[1];
|
|
67
|
+
var _useState13 = (0, _react.useState)(null),
|
|
68
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
69
|
+
error = _useState14[0],
|
|
70
|
+
setError = _useState14[1];
|
|
71
|
+
|
|
72
|
+
// 加载模板数据
|
|
73
|
+
var loadTemplates = (0, _react.useCallback)(function () {
|
|
74
|
+
setLoading(true);
|
|
75
|
+
setError(null);
|
|
76
|
+
try {
|
|
77
|
+
var allTemplates = (0, _templates.getAllTemplates)();
|
|
78
|
+
setTemplates(allTemplates);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
setError(err instanceof Error ? err.message : '加载模板失败');
|
|
81
|
+
console.error('加载模板失败:', err);
|
|
82
|
+
} finally {
|
|
83
|
+
setLoading(false);
|
|
84
|
+
}
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
// 初始加载
|
|
88
|
+
(0, _react.useEffect)(function () {
|
|
89
|
+
if (autoLoad) {
|
|
90
|
+
loadTemplates();
|
|
91
|
+
}
|
|
92
|
+
}, [autoLoad, loadTemplates]);
|
|
93
|
+
|
|
94
|
+
// 计算过滤后的模板
|
|
95
|
+
var filteredTemplates = (0, _react.useMemo)(function () {
|
|
96
|
+
var result = templates;
|
|
97
|
+
|
|
98
|
+
// 分类过滤
|
|
99
|
+
if (selectedCategory !== 'all') {
|
|
100
|
+
result = result.filter(function (t) {
|
|
101
|
+
return t.category === selectedCategory;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 关键词搜索
|
|
106
|
+
if (searchKeyword.trim()) {
|
|
107
|
+
var _keyword = searchKeyword.toLowerCase();
|
|
108
|
+
result = result.filter(function (t) {
|
|
109
|
+
return t.name.toLowerCase().includes(_keyword) || t.description.toLowerCase().includes(_keyword) || t.tags.some(function (tag) {
|
|
110
|
+
return tag.toLowerCase().includes(_keyword);
|
|
111
|
+
}) || t.pattern.toLowerCase().includes(_keyword);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 排序
|
|
116
|
+
if (sortBy === 'popular') {
|
|
117
|
+
result = _toConsumableArray(result).sort(function (a, b) {
|
|
118
|
+
return (b.useCount || 0) - (a.useCount || 0);
|
|
119
|
+
});
|
|
120
|
+
} else if (sortBy === 'recent') {
|
|
121
|
+
result = _toConsumableArray(result).sort(function (a, b) {
|
|
122
|
+
var _a$lastUsed, _b$lastUsed;
|
|
123
|
+
var timeA = ((_a$lastUsed = a.lastUsed) === null || _a$lastUsed === void 0 ? void 0 : _a$lastUsed.getTime()) || 0;
|
|
124
|
+
var timeB = ((_b$lastUsed = b.lastUsed) === null || _b$lastUsed === void 0 ? void 0 : _b$lastUsed.getTime()) || 0;
|
|
125
|
+
return timeB - timeA;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}, [templates, selectedCategory, searchKeyword, sortBy]);
|
|
130
|
+
|
|
131
|
+
// 统计信息
|
|
132
|
+
var stats = (0, _react.useMemo)(function () {
|
|
133
|
+
return (0, _templates.getTemplateStats)();
|
|
134
|
+
}, [templates]);
|
|
135
|
+
|
|
136
|
+
// 选择模板
|
|
137
|
+
var selectTemplate = (0, _react.useCallback)(function (id) {
|
|
138
|
+
var template = (0, _templates.getTemplateById)(id);
|
|
139
|
+
setSelectedTemplate(template || null);
|
|
140
|
+
}, [templates]);
|
|
141
|
+
|
|
142
|
+
// 清除选择
|
|
143
|
+
var clearSelection = (0, _react.useCallback)(function () {
|
|
144
|
+
setSelectedTemplate(null);
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
// 使用模板
|
|
148
|
+
var useTemplateCallback = (0, _react.useCallback)(function (id) {
|
|
149
|
+
var template = (0, _templates.useTemplate)(id);
|
|
150
|
+
if (template) {
|
|
151
|
+
// 刷新模板列表以更新使用统计
|
|
152
|
+
loadTemplates();
|
|
153
|
+
}
|
|
154
|
+
return template;
|
|
155
|
+
}, [loadTemplates]);
|
|
156
|
+
|
|
157
|
+
// 重置过滤条件
|
|
158
|
+
var resetFilters = (0, _react.useCallback)(function () {
|
|
159
|
+
setSearchKeyword('');
|
|
160
|
+
setSelectedCategory('all');
|
|
161
|
+
setSortBy('default');
|
|
162
|
+
}, []);
|
|
163
|
+
|
|
164
|
+
// 创建模板
|
|
165
|
+
var createTemplateCallback = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
166
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(template) {
|
|
167
|
+
var newTemplate, errorMsg;
|
|
168
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
169
|
+
while (1) switch (_context.prev = _context.next) {
|
|
170
|
+
case 0:
|
|
171
|
+
_context.prev = 0;
|
|
172
|
+
newTemplate = (0, _templates.createCustomTemplate)(template);
|
|
173
|
+
loadTemplates();
|
|
174
|
+
return _context.abrupt("return", newTemplate);
|
|
175
|
+
case 6:
|
|
176
|
+
_context.prev = 6;
|
|
177
|
+
_context.t0 = _context["catch"](0);
|
|
178
|
+
errorMsg = _context.t0 instanceof Error ? _context.t0.message : '创建模板失败';
|
|
179
|
+
setError(errorMsg);
|
|
180
|
+
throw new Error(errorMsg);
|
|
181
|
+
case 11:
|
|
182
|
+
case "end":
|
|
183
|
+
return _context.stop();
|
|
184
|
+
}
|
|
185
|
+
}, _callee, null, [[0, 6]]);
|
|
186
|
+
}));
|
|
187
|
+
return function (_x) {
|
|
188
|
+
return _ref.apply(this, arguments);
|
|
189
|
+
};
|
|
190
|
+
}(), [loadTemplates]);
|
|
191
|
+
|
|
192
|
+
// 更新模板
|
|
193
|
+
var updateTemplateCallback = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
194
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id, updates) {
|
|
195
|
+
var success, updatedTemplate, errorMsg;
|
|
196
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
197
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
198
|
+
case 0:
|
|
199
|
+
_context2.prev = 0;
|
|
200
|
+
success = (0, _templates.updateCustomTemplate)(id, updates);
|
|
201
|
+
if (success) {
|
|
202
|
+
loadTemplates();
|
|
203
|
+
// 如果更新的是当前选中的模板,刷新选中状态
|
|
204
|
+
if ((selectedTemplate === null || selectedTemplate === void 0 ? void 0 : selectedTemplate.id) === id) {
|
|
205
|
+
updatedTemplate = (0, _templates.getTemplateById)(id);
|
|
206
|
+
setSelectedTemplate(updatedTemplate || null);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return _context2.abrupt("return", success);
|
|
210
|
+
case 6:
|
|
211
|
+
_context2.prev = 6;
|
|
212
|
+
_context2.t0 = _context2["catch"](0);
|
|
213
|
+
errorMsg = _context2.t0 instanceof Error ? _context2.t0.message : '更新模板失败';
|
|
214
|
+
setError(errorMsg);
|
|
215
|
+
return _context2.abrupt("return", false);
|
|
216
|
+
case 11:
|
|
217
|
+
case "end":
|
|
218
|
+
return _context2.stop();
|
|
219
|
+
}
|
|
220
|
+
}, _callee2, null, [[0, 6]]);
|
|
221
|
+
}));
|
|
222
|
+
return function (_x2, _x3) {
|
|
223
|
+
return _ref2.apply(this, arguments);
|
|
224
|
+
};
|
|
225
|
+
}(), [loadTemplates, selectedTemplate]);
|
|
226
|
+
|
|
227
|
+
// 删除模板
|
|
228
|
+
var deleteTemplateCallback = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
229
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(id) {
|
|
230
|
+
var success, errorMsg;
|
|
231
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
232
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
233
|
+
case 0:
|
|
234
|
+
_context3.prev = 0;
|
|
235
|
+
success = (0, _templates.deleteCustomTemplateById)(id);
|
|
236
|
+
if (success) {
|
|
237
|
+
loadTemplates();
|
|
238
|
+
// 如果删除的是当前选中的模板,清除选中状态
|
|
239
|
+
if ((selectedTemplate === null || selectedTemplate === void 0 ? void 0 : selectedTemplate.id) === id) {
|
|
240
|
+
setSelectedTemplate(null);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return _context3.abrupt("return", success);
|
|
244
|
+
case 6:
|
|
245
|
+
_context3.prev = 6;
|
|
246
|
+
_context3.t0 = _context3["catch"](0);
|
|
247
|
+
errorMsg = _context3.t0 instanceof Error ? _context3.t0.message : '删除模板失败';
|
|
248
|
+
setError(errorMsg);
|
|
249
|
+
return _context3.abrupt("return", false);
|
|
250
|
+
case 11:
|
|
251
|
+
case "end":
|
|
252
|
+
return _context3.stop();
|
|
253
|
+
}
|
|
254
|
+
}, _callee3, null, [[0, 6]]);
|
|
255
|
+
}));
|
|
256
|
+
return function (_x4) {
|
|
257
|
+
return _ref3.apply(this, arguments);
|
|
258
|
+
};
|
|
259
|
+
}(), [loadTemplates, selectedTemplate]);
|
|
260
|
+
|
|
261
|
+
// 复制模板
|
|
262
|
+
var duplicateTemplateCallback = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
263
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(id, newName) {
|
|
264
|
+
var duplicated, errorMsg;
|
|
265
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
266
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
267
|
+
case 0:
|
|
268
|
+
_context4.prev = 0;
|
|
269
|
+
duplicated = (0, _templates.duplicateTemplate)(id, newName);
|
|
270
|
+
if (duplicated) {
|
|
271
|
+
loadTemplates();
|
|
272
|
+
}
|
|
273
|
+
return _context4.abrupt("return", duplicated);
|
|
274
|
+
case 6:
|
|
275
|
+
_context4.prev = 6;
|
|
276
|
+
_context4.t0 = _context4["catch"](0);
|
|
277
|
+
errorMsg = _context4.t0 instanceof Error ? _context4.t0.message : '复制模板失败';
|
|
278
|
+
setError(errorMsg);
|
|
279
|
+
return _context4.abrupt("return", null);
|
|
280
|
+
case 11:
|
|
281
|
+
case "end":
|
|
282
|
+
return _context4.stop();
|
|
283
|
+
}
|
|
284
|
+
}, _callee4, null, [[0, 6]]);
|
|
285
|
+
}));
|
|
286
|
+
return function (_x5, _x6) {
|
|
287
|
+
return _ref4.apply(this, arguments);
|
|
288
|
+
};
|
|
289
|
+
}(), [loadTemplates]);
|
|
290
|
+
|
|
291
|
+
// 批量删除模板
|
|
292
|
+
var deleteMultipleTemplates = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
293
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(ids) {
|
|
294
|
+
var results, errorMsg;
|
|
295
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
296
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
297
|
+
case 0:
|
|
298
|
+
_context5.prev = 0;
|
|
299
|
+
_context5.next = 3;
|
|
300
|
+
return Promise.all(ids.map(function (id) {
|
|
301
|
+
return deleteTemplateCallback(id);
|
|
302
|
+
}));
|
|
303
|
+
case 3:
|
|
304
|
+
results = _context5.sent;
|
|
305
|
+
return _context5.abrupt("return", results.every(function (r) {
|
|
306
|
+
return r;
|
|
307
|
+
}));
|
|
308
|
+
case 7:
|
|
309
|
+
_context5.prev = 7;
|
|
310
|
+
_context5.t0 = _context5["catch"](0);
|
|
311
|
+
errorMsg = _context5.t0 instanceof Error ? _context5.t0.message : '批量删除失败';
|
|
312
|
+
setError(errorMsg);
|
|
313
|
+
return _context5.abrupt("return", false);
|
|
314
|
+
case 12:
|
|
315
|
+
case "end":
|
|
316
|
+
return _context5.stop();
|
|
317
|
+
}
|
|
318
|
+
}, _callee5, null, [[0, 7]]);
|
|
319
|
+
}));
|
|
320
|
+
return function (_x7) {
|
|
321
|
+
return _ref5.apply(this, arguments);
|
|
322
|
+
};
|
|
323
|
+
}(), [deleteTemplateCallback]);
|
|
324
|
+
|
|
325
|
+
// 清空所有自定义模板
|
|
326
|
+
var clearAllCustomTemplates = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
327
|
+
var _yield$import, clearAllTemplates, success, errorMsg;
|
|
328
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
329
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
330
|
+
case 0:
|
|
331
|
+
_context6.prev = 0;
|
|
332
|
+
_context6.next = 3;
|
|
333
|
+
return Promise.resolve().then(function () {
|
|
334
|
+
return _interopRequireWildcard(require("../templates/storage"));
|
|
335
|
+
});
|
|
336
|
+
case 3:
|
|
337
|
+
_yield$import = _context6.sent;
|
|
338
|
+
clearAllTemplates = _yield$import.clearAllTemplates;
|
|
339
|
+
success = clearAllTemplates();
|
|
340
|
+
if (success) {
|
|
341
|
+
loadTemplates();
|
|
342
|
+
setSelectedTemplate(null);
|
|
343
|
+
}
|
|
344
|
+
return _context6.abrupt("return", success);
|
|
345
|
+
case 10:
|
|
346
|
+
_context6.prev = 10;
|
|
347
|
+
_context6.t0 = _context6["catch"](0);
|
|
348
|
+
errorMsg = _context6.t0 instanceof Error ? _context6.t0.message : '清空模板失败';
|
|
349
|
+
setError(errorMsg);
|
|
350
|
+
return _context6.abrupt("return", false);
|
|
351
|
+
case 15:
|
|
352
|
+
case "end":
|
|
353
|
+
return _context6.stop();
|
|
354
|
+
}
|
|
355
|
+
}, _callee6, null, [[0, 10]]);
|
|
356
|
+
})), [loadTemplates]);
|
|
357
|
+
|
|
358
|
+
// 导出模板
|
|
359
|
+
var exportTemplatesCallback = (0, _react.useCallback)(function () {
|
|
360
|
+
return (0, _templates.exportTemplates)();
|
|
361
|
+
}, []);
|
|
362
|
+
|
|
363
|
+
// 导入模板
|
|
364
|
+
var importTemplatesCallback = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
365
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(jsonString) {
|
|
366
|
+
var merge,
|
|
367
|
+
success,
|
|
368
|
+
errorMsg,
|
|
369
|
+
_args7 = arguments;
|
|
370
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
371
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
372
|
+
case 0:
|
|
373
|
+
merge = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : true;
|
|
374
|
+
_context7.prev = 1;
|
|
375
|
+
success = (0, _templates.importTemplates)(jsonString, merge);
|
|
376
|
+
if (success) {
|
|
377
|
+
loadTemplates();
|
|
378
|
+
}
|
|
379
|
+
return _context7.abrupt("return", success);
|
|
380
|
+
case 7:
|
|
381
|
+
_context7.prev = 7;
|
|
382
|
+
_context7.t0 = _context7["catch"](1);
|
|
383
|
+
errorMsg = _context7.t0 instanceof Error ? _context7.t0.message : '导入模板失败';
|
|
384
|
+
setError(errorMsg);
|
|
385
|
+
return _context7.abrupt("return", false);
|
|
386
|
+
case 12:
|
|
387
|
+
case "end":
|
|
388
|
+
return _context7.stop();
|
|
389
|
+
}
|
|
390
|
+
}, _callee7, null, [[1, 7]]);
|
|
391
|
+
}));
|
|
392
|
+
return function (_x8) {
|
|
393
|
+
return _ref7.apply(this, arguments);
|
|
394
|
+
};
|
|
395
|
+
}(), [loadTemplates]);
|
|
396
|
+
return {
|
|
397
|
+
// 模板数据
|
|
398
|
+
templates: templates,
|
|
399
|
+
filteredTemplates: filteredTemplates,
|
|
400
|
+
selectedTemplate: selectedTemplate,
|
|
401
|
+
// 过滤和搜索
|
|
402
|
+
searchKeyword: searchKeyword,
|
|
403
|
+
selectedCategory: selectedCategory,
|
|
404
|
+
sortBy: sortBy,
|
|
405
|
+
// 统计信息
|
|
406
|
+
stats: stats,
|
|
407
|
+
isStorageAvailable: (0, _templates.isStorageAvailable)(),
|
|
408
|
+
// 加载状态
|
|
409
|
+
loading: loading,
|
|
410
|
+
error: error,
|
|
411
|
+
// 模板操作
|
|
412
|
+
selectTemplate: selectTemplate,
|
|
413
|
+
clearSelection: clearSelection,
|
|
414
|
+
useTemplate: useTemplateCallback,
|
|
415
|
+
// 搜索和过滤
|
|
416
|
+
setSearchKeyword: setSearchKeyword,
|
|
417
|
+
setSelectedCategory: setSelectedCategory,
|
|
418
|
+
setSortBy: setSortBy,
|
|
419
|
+
resetFilters: resetFilters,
|
|
420
|
+
// CRUD 操作
|
|
421
|
+
createTemplate: createTemplateCallback,
|
|
422
|
+
updateTemplate: updateTemplateCallback,
|
|
423
|
+
deleteTemplate: deleteTemplateCallback,
|
|
424
|
+
duplicateTemplate: duplicateTemplateCallback,
|
|
425
|
+
// 批量操作
|
|
426
|
+
deleteMultipleTemplates: deleteMultipleTemplates,
|
|
427
|
+
clearAllCustomTemplates: clearAllCustomTemplates,
|
|
428
|
+
// 导入导出
|
|
429
|
+
exportTemplates: exportTemplatesCallback,
|
|
430
|
+
importTemplates: importTemplatesCallback,
|
|
431
|
+
// 工具方法
|
|
432
|
+
validateTemplate: _templates.validateTemplate,
|
|
433
|
+
getMostUsedTemplates: _templates.getMostUsedTemplates,
|
|
434
|
+
getRecentlyUsedTemplates: _templates.getRecentlyUsedTemplates,
|
|
435
|
+
// 刷新数据
|
|
436
|
+
refresh: loadTemplates
|
|
437
|
+
};
|
|
438
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { RegexEditor } from './core/RegexEditor';
|
|
2
|
+
export { RegexTester, FlagsSelector, MatchItem, RegexRailroadDiagram } from './visualizer';
|
|
3
|
+
export { parseRegex, traverseAST } from './validation/parser';
|
|
4
|
+
export { validateRegex, validatePattern } from './validation/validator';
|
|
5
|
+
export { analyzeComplexity } from './validation/complexity';
|
|
6
|
+
export { useRegexValidation } from './hooks/useRegexValidation';
|
|
7
|
+
export { useTemplateManager } from './hooks/useTemplateManager';
|
|
8
|
+
export { getAllTemplates, getTemplateById, getTemplatesByCategory, searchTemplates, getMostUsedTemplates, getRecentlyUsedTemplates, createCustomTemplate, updateCustomTemplate, deleteCustomTemplate, duplicateTemplate, useTemplate, getTemplateStats, validateTemplate, } from './templates/templateManager';
|
|
9
|
+
export { loadCustomTemplates, saveCustomTemplate, deleteCustomTemplate as deleteStoredTemplate, updateTemplateUsage, clearAllTemplates, exportTemplates, importTemplates, getStorageStats, isStorageAvailable, } from './templates/storage';
|
|
10
|
+
export { TemplateSelector } from './templates/TemplateSelector';
|
|
11
|
+
export type { ParseResult, ValidationResult, RegexError, ComplexityMetrics, ASTNode, AstRegExp, } from './validation/types';
|
|
12
|
+
export type { RegexTemplate, } from './templates/types';
|
|
13
|
+
export { TemplateCategory } from './templates/types';
|
|
14
|
+
export type { TestResult, } from './testing/types';
|
|
15
|
+
export type { CodeMirrorWrapperProps, RegexEditorProps, } from './core/types';
|
|
16
|
+
export type { RegexFlags, MatchResult, RegexTesterProps, RegexVisualizerProps, FlagsSelectorProps, MatchItemProps, ReplacePreviewProps, RegexRailroadDiagramProps, } from './visualizer/types';
|