@nokecy/qc-ui 1.0.70 → 1.0.72
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/ag-gridPlus.js +409 -206
- package/dist/cjs/ag-grid-plus/context/gridContext.d.ts +30 -5
- package/dist/cjs/ag-grid-plus/context/gridContext.js +6 -1
- package/dist/cjs/ag-grid-plus/errors/ErrorBoundary.d.ts +36 -0
- package/dist/cjs/ag-grid-plus/errors/ErrorBoundary.js +143 -0
- package/dist/cjs/ag-grid-plus/errors/index.d.ts +3 -0
- package/dist/cjs/ag-grid-plus/errors/index.js +31 -0
- package/dist/cjs/ag-grid-plus/errors/types.d.ts +71 -0
- package/dist/cjs/ag-grid-plus/errors/types.js +137 -0
- package/dist/cjs/ag-grid-plus/hooks/index.d.ts +7 -0
- package/dist/cjs/ag-grid-plus/hooks/index.js +51 -0
- package/dist/cjs/ag-grid-plus/hooks/useAgGridCalculation.d.ts +88 -0
- package/dist/cjs/ag-grid-plus/hooks/useAgGridCalculation.js +224 -0
- package/dist/cjs/ag-grid-plus/hooks/useAgGridData.d.ts +91 -0
- package/dist/cjs/ag-grid-plus/hooks/useAgGridData.js +230 -0
- package/dist/cjs/ag-grid-plus/hooks/useGridPlusColumnState.d.ts +1 -8
- package/dist/cjs/ag-grid-plus/hooks/useGridState.d.ts +153 -0
- package/dist/cjs/ag-grid-plus/hooks/useGridState.js +258 -0
- package/dist/cjs/ag-grid-plus/index.d.ts +5 -0
- package/dist/cjs/ag-grid-plus/index.js +164 -0
- package/dist/cjs/ag-grid-plus/interface.d.ts +37 -0
- package/dist/cjs/ag-grid-plus/querySchemes/components/QuerySchemesManager.d.ts +21 -0
- package/dist/cjs/ag-grid-plus/querySchemes/components/QuerySchemesManager.js +580 -0
- package/dist/cjs/ag-grid-plus/querySchemes/components/QuerySchemesManager.less +86 -0
- package/dist/cjs/ag-grid-plus/querySchemes/components/index.d.ts +5 -0
- package/dist/cjs/ag-grid-plus/querySchemes/components/index.js +12 -0
- package/dist/cjs/ag-grid-plus/querySchemes/constants.d.ts +17 -0
- package/dist/cjs/ag-grid-plus/querySchemes/constants.js +30 -0
- package/dist/cjs/ag-grid-plus/querySchemes/hooks/useQueryOrderManager.d.ts +10 -0
- package/dist/cjs/ag-grid-plus/querySchemes/hooks/useQueryOrderManager.js +65 -0
- package/dist/cjs/ag-grid-plus/querySchemes/hooks/useQuerySchemes.d.ts +6 -0
- package/dist/cjs/ag-grid-plus/querySchemes/hooks/useQuerySchemes.js +542 -0
- package/dist/cjs/ag-grid-plus/querySchemes/hooks/useQuerySchemes.refactored.d.ts +7 -0
- package/dist/cjs/ag-grid-plus/querySchemes/hooks/useQuerySchemes.refactored.js +32 -0
- package/dist/cjs/ag-grid-plus/querySchemes/index.d.ts +11 -0
- package/dist/cjs/ag-grid-plus/querySchemes/index.js +113 -0
- package/dist/cjs/ag-grid-plus/querySchemes/storage/localStorageAdapter.d.ts +44 -0
- package/dist/cjs/ag-grid-plus/querySchemes/storage/localStorageAdapter.js +261 -0
- package/dist/cjs/ag-grid-plus/querySchemes/types.d.ts +143 -0
- package/dist/cjs/ag-grid-plus/querySchemes/types.js +5 -0
- package/dist/cjs/ag-grid-plus/querySchemes/utils/validator.d.ts +36 -0
- package/dist/cjs/ag-grid-plus/querySchemes/utils/validator.js +155 -0
- package/dist/cjs/ag-grid-plus/schemes/components/SchemeManager.d.ts +16 -0
- package/dist/cjs/ag-grid-plus/schemes/components/SchemeManager.js +342 -0
- package/dist/cjs/ag-grid-plus/schemes/components/SchemeManager.less +35 -0
- package/dist/cjs/ag-grid-plus/schemes/components/SchemeSelector.d.ts +20 -0
- package/dist/cjs/ag-grid-plus/schemes/components/SchemeSelector.js +289 -0
- package/dist/cjs/ag-grid-plus/schemes/components/SchemeSelector.less +39 -0
- package/dist/cjs/ag-grid-plus/schemes/components/index.d.ts +4 -0
- package/dist/cjs/ag-grid-plus/schemes/components/index.js +19 -0
- package/dist/cjs/ag-grid-plus/schemes/constants.d.ts +23 -0
- package/dist/cjs/ag-grid-plus/schemes/constants.js +39 -0
- package/dist/cjs/ag-grid-plus/schemes/hooks/useColumnSchemes.d.ts +6 -0
- package/dist/cjs/ag-grid-plus/schemes/hooks/useColumnSchemes.js +542 -0
- package/dist/cjs/ag-grid-plus/schemes/hooks/useColumnSchemes.refactored.d.ts +7 -0
- package/dist/cjs/ag-grid-plus/schemes/hooks/useColumnSchemes.refactored.js +32 -0
- package/dist/cjs/ag-grid-plus/schemes/index.d.ts +16 -0
- package/dist/cjs/ag-grid-plus/schemes/index.js +124 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/localStorageAdapter.d.ts +64 -0
- package/dist/cjs/ag-grid-plus/schemes/storage/localStorageAdapter.js +368 -0
- package/dist/cjs/ag-grid-plus/schemes/types.d.ts +126 -0
- package/dist/cjs/ag-grid-plus/schemes/types.js +5 -0
- package/dist/cjs/ag-grid-plus/schemes/utils/validator.d.ts +27 -0
- package/dist/cjs/ag-grid-plus/schemes/utils/validator.js +113 -0
- package/dist/cjs/ag-grid-plus/setting/ColumnSetting.d.ts +17 -0
- package/dist/cjs/ag-grid-plus/setting/ColumnSetting.js +955 -0
- package/dist/cjs/ag-grid-plus/setting/index.d.ts +1 -1
- package/dist/cjs/ag-grid-plus/setting/index.js +74 -111
- package/dist/cjs/ag-grid-plus/shared/hooks/useSchemeManager.d.ts +66 -0
- package/dist/cjs/ag-grid-plus/shared/hooks/useSchemeManager.js +648 -0
- package/dist/cjs/ag-grid-plus/storage/MemoryStorageAdapter.d.ts +76 -0
- package/dist/cjs/ag-grid-plus/storage/MemoryStorageAdapter.js +276 -0
- package/dist/cjs/ag-grid-plus/storage/SchemeSyncManager.d.ts +114 -0
- package/dist/cjs/ag-grid-plus/storage/SchemeSyncManager.js +615 -0
- package/dist/cjs/ag-grid-plus/storage/globalSyncManager.d.ts +100 -0
- package/dist/cjs/ag-grid-plus/storage/globalSyncManager.js +335 -0
- package/dist/cjs/ag-grid-plus/storage/index.d.ts +8 -0
- package/dist/cjs/ag-grid-plus/storage/index.js +49 -0
- package/dist/cjs/ag-grid-plus/storage/types.d.ts +144 -0
- package/dist/cjs/ag-grid-plus/storage/types.js +5 -0
- package/dist/cjs/ag-grid-plus/types.d.ts +310 -0
- package/dist/cjs/ag-grid-plus/types.js +5 -0
- package/dist/cjs/ag-grid-plus/utils/columnProcessors.d.ts +95 -0
- package/dist/cjs/ag-grid-plus/utils/columnProcessors.js +265 -0
- package/dist/cjs/ag-grid-plus/utils/constants.d.ts +41 -0
- package/dist/cjs/ag-grid-plus/utils/constants.js +56 -0
- package/dist/cjs/ag-grid-plus/utils/logger.d.ts +34 -0
- package/dist/cjs/ag-grid-plus/utils/logger.js +119 -0
- package/dist/cjs/ag-grid-plus/utils/sanitize.d.ts +15 -0
- package/dist/cjs/ag-grid-plus/utils/sanitize.js +39 -0
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +84 -0
- package/dist/esm/ag-grid-plus/ag-gridPlus.js +410 -206
- package/dist/esm/ag-grid-plus/context/gridContext.d.ts +30 -5
- package/dist/esm/ag-grid-plus/context/gridContext.js +6 -1
- package/dist/esm/ag-grid-plus/errors/ErrorBoundary.d.ts +36 -0
- package/dist/esm/ag-grid-plus/errors/ErrorBoundary.js +137 -0
- package/dist/esm/ag-grid-plus/errors/index.d.ts +3 -0
- package/dist/esm/ag-grid-plus/errors/index.js +2 -0
- package/dist/esm/ag-grid-plus/errors/types.d.ts +71 -0
- package/dist/esm/ag-grid-plus/errors/types.js +135 -0
- package/dist/esm/ag-grid-plus/hooks/index.d.ts +7 -0
- package/dist/esm/ag-grid-plus/hooks/index.js +10 -0
- package/dist/esm/ag-grid-plus/hooks/useAgGridCalculation.d.ts +88 -0
- package/dist/esm/ag-grid-plus/hooks/useAgGridCalculation.js +217 -0
- package/dist/esm/ag-grid-plus/hooks/useAgGridData.d.ts +91 -0
- package/dist/esm/ag-grid-plus/hooks/useAgGridData.js +225 -0
- package/dist/esm/ag-grid-plus/hooks/useGridPlusColumnState.d.ts +1 -8
- package/dist/esm/ag-grid-plus/hooks/useGridState.d.ts +153 -0
- package/dist/esm/ag-grid-plus/hooks/useGridState.js +258 -0
- package/dist/esm/ag-grid-plus/index.d.ts +5 -0
- package/dist/esm/ag-grid-plus/index.js +6 -1
- package/dist/esm/ag-grid-plus/interface.d.ts +37 -0
- package/dist/esm/ag-grid-plus/querySchemes/components/QuerySchemesManager.d.ts +21 -0
- package/dist/esm/ag-grid-plus/querySchemes/components/QuerySchemesManager.js +572 -0
- package/dist/esm/ag-grid-plus/querySchemes/components/QuerySchemesManager.less +86 -0
- package/dist/esm/ag-grid-plus/querySchemes/components/index.d.ts +5 -0
- package/dist/esm/ag-grid-plus/querySchemes/components/index.js +5 -0
- package/dist/esm/ag-grid-plus/querySchemes/constants.d.ts +17 -0
- package/dist/esm/ag-grid-plus/querySchemes/constants.js +24 -0
- package/dist/esm/ag-grid-plus/querySchemes/hooks/useQueryOrderManager.d.ts +10 -0
- package/dist/esm/ag-grid-plus/querySchemes/hooks/useQueryOrderManager.js +60 -0
- package/dist/esm/ag-grid-plus/querySchemes/hooks/useQuerySchemes.d.ts +6 -0
- package/dist/esm/ag-grid-plus/querySchemes/hooks/useQuerySchemes.js +537 -0
- package/dist/esm/ag-grid-plus/querySchemes/hooks/useQuerySchemes.refactored.d.ts +7 -0
- package/dist/esm/ag-grid-plus/querySchemes/hooks/useQuerySchemes.refactored.js +27 -0
- package/dist/esm/ag-grid-plus/querySchemes/index.d.ts +11 -0
- package/dist/esm/ag-grid-plus/querySchemes/index.js +20 -0
- package/dist/esm/ag-grid-plus/querySchemes/storage/localStorageAdapter.d.ts +44 -0
- package/dist/esm/ag-grid-plus/querySchemes/storage/localStorageAdapter.js +256 -0
- package/dist/esm/ag-grid-plus/querySchemes/types.d.ts +143 -0
- package/dist/esm/ag-grid-plus/querySchemes/types.js +1 -0
- package/dist/esm/ag-grid-plus/querySchemes/utils/validator.d.ts +36 -0
- package/dist/esm/ag-grid-plus/querySchemes/utils/validator.js +144 -0
- package/dist/esm/ag-grid-plus/schemes/components/SchemeManager.d.ts +16 -0
- package/dist/esm/ag-grid-plus/schemes/components/SchemeManager.js +334 -0
- package/dist/esm/ag-grid-plus/schemes/components/SchemeManager.less +35 -0
- package/dist/esm/ag-grid-plus/schemes/components/SchemeSelector.d.ts +20 -0
- package/dist/esm/ag-grid-plus/schemes/components/SchemeSelector.js +281 -0
- package/dist/esm/ag-grid-plus/schemes/components/SchemeSelector.less +39 -0
- package/dist/esm/ag-grid-plus/schemes/components/index.d.ts +4 -0
- package/dist/esm/ag-grid-plus/schemes/components/index.js +2 -0
- package/dist/esm/ag-grid-plus/schemes/constants.d.ts +23 -0
- package/dist/esm/ag-grid-plus/schemes/constants.js +33 -0
- package/dist/esm/ag-grid-plus/schemes/hooks/useColumnSchemes.d.ts +6 -0
- package/dist/esm/ag-grid-plus/schemes/hooks/useColumnSchemes.js +537 -0
- package/dist/esm/ag-grid-plus/schemes/hooks/useColumnSchemes.refactored.d.ts +7 -0
- package/dist/esm/ag-grid-plus/schemes/hooks/useColumnSchemes.refactored.js +27 -0
- package/dist/esm/ag-grid-plus/schemes/index.d.ts +16 -0
- package/dist/esm/ag-grid-plus/schemes/index.js +25 -0
- package/dist/esm/ag-grid-plus/schemes/storage/localStorageAdapter.d.ts +64 -0
- package/dist/esm/ag-grid-plus/schemes/storage/localStorageAdapter.js +363 -0
- package/dist/esm/ag-grid-plus/schemes/types.d.ts +126 -0
- package/dist/esm/ag-grid-plus/schemes/types.js +1 -0
- package/dist/esm/ag-grid-plus/schemes/utils/validator.d.ts +27 -0
- package/dist/esm/ag-grid-plus/schemes/utils/validator.js +104 -0
- package/dist/esm/ag-grid-plus/setting/ColumnSetting.d.ts +17 -0
- package/dist/esm/ag-grid-plus/setting/ColumnSetting.js +946 -0
- package/dist/esm/ag-grid-plus/setting/index.d.ts +1 -1
- package/dist/esm/ag-grid-plus/setting/index.js +69 -107
- package/dist/esm/ag-grid-plus/shared/hooks/useSchemeManager.d.ts +66 -0
- package/dist/esm/ag-grid-plus/shared/hooks/useSchemeManager.js +643 -0
- package/dist/esm/ag-grid-plus/storage/MemoryStorageAdapter.d.ts +76 -0
- package/dist/esm/ag-grid-plus/storage/MemoryStorageAdapter.js +273 -0
- package/dist/esm/ag-grid-plus/storage/SchemeSyncManager.d.ts +114 -0
- package/dist/esm/ag-grid-plus/storage/SchemeSyncManager.js +609 -0
- package/dist/esm/ag-grid-plus/storage/globalSyncManager.d.ts +100 -0
- package/dist/esm/ag-grid-plus/storage/globalSyncManager.js +321 -0
- package/dist/esm/ag-grid-plus/storage/index.d.ts +8 -0
- package/dist/esm/ag-grid-plus/storage/index.js +9 -0
- package/dist/esm/ag-grid-plus/storage/types.d.ts +144 -0
- package/dist/esm/ag-grid-plus/storage/types.js +1 -0
- package/dist/esm/ag-grid-plus/types.d.ts +310 -0
- package/dist/esm/ag-grid-plus/types.js +1 -0
- package/dist/esm/ag-grid-plus/utils/columnProcessors.d.ts +95 -0
- package/dist/esm/ag-grid-plus/utils/columnProcessors.js +251 -0
- package/dist/esm/ag-grid-plus/utils/constants.d.ts +41 -0
- package/dist/esm/ag-grid-plus/utils/constants.js +50 -0
- package/dist/esm/ag-grid-plus/utils/logger.d.ts +34 -0
- package/dist/esm/ag-grid-plus/utils/logger.js +114 -0
- package/dist/esm/ag-grid-plus/utils/sanitize.d.ts +15 -0
- package/dist/esm/ag-grid-plus/utils/sanitize.js +32 -0
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +8 -2
- package/dist/esm/standardFormDialog/useStandardFormSchema.d.ts +1 -1
- package/dist/esm/standardFormDialog/withStandardForm.d.ts +2 -2
- package/dist/umd/qc-ui.min.css +1 -1
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,648 @@
|
|
|
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.useSchemeManager = useSchemeManager;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _uuid = require("uuid");
|
|
10
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
+
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."); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
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; }
|
|
20
|
+
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); } }
|
|
21
|
+
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); }); }; }
|
|
22
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
|
+
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."); }
|
|
24
|
+
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); }
|
|
25
|
+
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; }
|
|
26
|
+
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; } }
|
|
27
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
+
/**
|
|
29
|
+
* 基础方案接口
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 存储适配器接口
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 方案管理器配置
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 验证结果
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 方案管理器返回值
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 常量配置
|
|
50
|
+
*/
|
|
51
|
+
var DEFAULT_MAX_SCHEMES = 50;
|
|
52
|
+
var MIN_NAME_LENGTH = 1;
|
|
53
|
+
var MAX_NAME_LENGTH = 50;
|
|
54
|
+
var MAX_DESCRIPTION_LENGTH = 200;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 验证方案名称
|
|
58
|
+
*/
|
|
59
|
+
function validateSchemeName(name) {
|
|
60
|
+
if (!name || name.trim().length < MIN_NAME_LENGTH) {
|
|
61
|
+
return {
|
|
62
|
+
valid: false,
|
|
63
|
+
error: '方案名称不能为空'
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
67
|
+
return {
|
|
68
|
+
valid: false,
|
|
69
|
+
error: "\u65B9\u6848\u540D\u79F0\u4E0D\u80FD\u8D85\u8FC7".concat(MAX_NAME_LENGTH, "\u4E2A\u5B57\u7B26")
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
valid: true
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 验证方案描述
|
|
79
|
+
*/
|
|
80
|
+
function validateSchemeDescription(description) {
|
|
81
|
+
if (description && description.length > MAX_DESCRIPTION_LENGTH) {
|
|
82
|
+
return {
|
|
83
|
+
valid: false,
|
|
84
|
+
error: "\u65B9\u6848\u63CF\u8FF0\u4E0D\u80FD\u8D85\u8FC7".concat(MAX_DESCRIPTION_LENGTH, "\u4E2A\u5B57\u7B26")
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
valid: true
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 检查重名
|
|
94
|
+
*/
|
|
95
|
+
function checkDuplicateName(name, schemes, excludeId) {
|
|
96
|
+
return schemes.some(function (s) {
|
|
97
|
+
return s.id !== excludeId && s.name === name;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 生成唯一名称
|
|
103
|
+
*/
|
|
104
|
+
function generateUniqueName(baseName, schemes) {
|
|
105
|
+
var counter = 1;
|
|
106
|
+
var newName = "".concat(baseName, "(").concat(counter, ")");
|
|
107
|
+
while (schemes.some(function (s) {
|
|
108
|
+
return s.name === newName;
|
|
109
|
+
})) {
|
|
110
|
+
counter++;
|
|
111
|
+
newName = "".concat(baseName, "(").concat(counter, ")");
|
|
112
|
+
}
|
|
113
|
+
return newName;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 通用方案管理 Hook
|
|
118
|
+
* 提供方案的 CRUD 操作、验证、自动保存等功能
|
|
119
|
+
*
|
|
120
|
+
* @template T 方案类型,必须继承自 BaseScheme
|
|
121
|
+
* @param config 方案管理器配置
|
|
122
|
+
* @returns 方案管理器操作方法和状态
|
|
123
|
+
*/
|
|
124
|
+
function useSchemeManager(config) {
|
|
125
|
+
var gridId = config.gridId,
|
|
126
|
+
storageAdapter = config.storageAdapter,
|
|
127
|
+
_config$enableAutoSav = config.enableAutoSave,
|
|
128
|
+
enableAutoSave = _config$enableAutoSav === void 0 ? true : _config$enableAutoSav,
|
|
129
|
+
_config$maxSchemes = config.maxSchemes,
|
|
130
|
+
maxSchemes = _config$maxSchemes === void 0 ? DEFAULT_MAX_SCHEMES : _config$maxSchemes,
|
|
131
|
+
onSchemeChange = config.onSchemeChange,
|
|
132
|
+
onSchemeSave = config.onSchemeSave,
|
|
133
|
+
onSchemeDelete = config.onSchemeDelete;
|
|
134
|
+
|
|
135
|
+
// 状态管理
|
|
136
|
+
var _useState = (0, _react.useState)([]),
|
|
137
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
138
|
+
schemes = _useState2[0],
|
|
139
|
+
setSchemes = _useState2[1];
|
|
140
|
+
var _useState3 = (0, _react.useState)(null),
|
|
141
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
142
|
+
currentScheme = _useState4[0],
|
|
143
|
+
setCurrentScheme = _useState4[1];
|
|
144
|
+
var _useState5 = (0, _react.useState)(false),
|
|
145
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
146
|
+
isDirty = _useState6[0],
|
|
147
|
+
setIsDirty = _useState6[1];
|
|
148
|
+
var _useState7 = (0, _react.useState)(true),
|
|
149
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
150
|
+
loading = _useState8[0],
|
|
151
|
+
setLoading = _useState8[1];
|
|
152
|
+
|
|
153
|
+
// 用于防抖和缓存
|
|
154
|
+
var saveTimeoutRef = (0, _react.useRef)();
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 初始化:加载方案列表
|
|
158
|
+
*/
|
|
159
|
+
(0, _react.useEffect)(function () {
|
|
160
|
+
loadSchemesList();
|
|
161
|
+
}, [gridId]);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 加载方案列表
|
|
165
|
+
*/
|
|
166
|
+
var loadSchemesList = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
167
|
+
var loadedSchemes, schemeToLoad, lastSchemeId;
|
|
168
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
169
|
+
while (1) switch (_context.prev = _context.next) {
|
|
170
|
+
case 0:
|
|
171
|
+
_context.prev = 0;
|
|
172
|
+
setLoading(true);
|
|
173
|
+
_context.next = 4;
|
|
174
|
+
return storageAdapter.getSchemes(gridId);
|
|
175
|
+
case 4:
|
|
176
|
+
loadedSchemes = _context.sent;
|
|
177
|
+
setSchemes(loadedSchemes);
|
|
178
|
+
|
|
179
|
+
// 优先加载上次使用的方案,如果没有则加载默认方案
|
|
180
|
+
if (!(!currentScheme && loadedSchemes.length > 0)) {
|
|
181
|
+
_context.next = 15;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
schemeToLoad = null; // 1. 尝试加载上次使用的方案
|
|
185
|
+
if (!storageAdapter.getCurrentSchemeId) {
|
|
186
|
+
_context.next = 13;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
_context.next = 11;
|
|
190
|
+
return storageAdapter.getCurrentSchemeId(gridId);
|
|
191
|
+
case 11:
|
|
192
|
+
lastSchemeId = _context.sent;
|
|
193
|
+
if (lastSchemeId) {
|
|
194
|
+
schemeToLoad = loadedSchemes.find(function (s) {
|
|
195
|
+
return s.id === lastSchemeId;
|
|
196
|
+
}) || null;
|
|
197
|
+
}
|
|
198
|
+
case 13:
|
|
199
|
+
// 2. 如果没有上次使用的方案,加载默认方案
|
|
200
|
+
if (!schemeToLoad) {
|
|
201
|
+
schemeToLoad = loadedSchemes.find(function (s) {
|
|
202
|
+
return s.isDefault;
|
|
203
|
+
}) || null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 3. 应用方案
|
|
207
|
+
if (schemeToLoad) {
|
|
208
|
+
setCurrentScheme(schemeToLoad);
|
|
209
|
+
onSchemeChange === null || onSchemeChange === void 0 || onSchemeChange(schemeToLoad);
|
|
210
|
+
}
|
|
211
|
+
case 15:
|
|
212
|
+
_context.next = 20;
|
|
213
|
+
break;
|
|
214
|
+
case 17:
|
|
215
|
+
_context.prev = 17;
|
|
216
|
+
_context.t0 = _context["catch"](0);
|
|
217
|
+
console.error('[useSchemeManager] 加载方案失败:', _context.t0);
|
|
218
|
+
case 20:
|
|
219
|
+
_context.prev = 20;
|
|
220
|
+
setLoading(false);
|
|
221
|
+
return _context.finish(20);
|
|
222
|
+
case 23:
|
|
223
|
+
case "end":
|
|
224
|
+
return _context.stop();
|
|
225
|
+
}
|
|
226
|
+
}, _callee, null, [[0, 17, 20, 23]]);
|
|
227
|
+
})), [gridId, storageAdapter]);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 保存方案列表到存储
|
|
231
|
+
*/
|
|
232
|
+
var saveSchemesToStorage = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
233
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(updatedSchemes) {
|
|
234
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
235
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
236
|
+
case 0:
|
|
237
|
+
_context2.prev = 0;
|
|
238
|
+
_context2.next = 3;
|
|
239
|
+
return storageAdapter.saveSchemes(gridId, updatedSchemes);
|
|
240
|
+
case 3:
|
|
241
|
+
setSchemes(updatedSchemes);
|
|
242
|
+
_context2.next = 10;
|
|
243
|
+
break;
|
|
244
|
+
case 6:
|
|
245
|
+
_context2.prev = 6;
|
|
246
|
+
_context2.t0 = _context2["catch"](0);
|
|
247
|
+
console.error('[useSchemeManager] 保存方案失败:', _context2.t0);
|
|
248
|
+
throw _context2.t0;
|
|
249
|
+
case 10:
|
|
250
|
+
case "end":
|
|
251
|
+
return _context2.stop();
|
|
252
|
+
}
|
|
253
|
+
}, _callee2, null, [[0, 6]]);
|
|
254
|
+
}));
|
|
255
|
+
return function (_x) {
|
|
256
|
+
return _ref2.apply(this, arguments);
|
|
257
|
+
};
|
|
258
|
+
}(), [gridId, storageAdapter]);
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 加载指定方案
|
|
262
|
+
*/
|
|
263
|
+
var loadScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
264
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schemeId) {
|
|
265
|
+
var scheme;
|
|
266
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
267
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
268
|
+
case 0:
|
|
269
|
+
scheme = schemes.find(function (s) {
|
|
270
|
+
return s.id === schemeId;
|
|
271
|
+
});
|
|
272
|
+
if (scheme) {
|
|
273
|
+
_context3.next = 4;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
console.error("[useSchemeManager] \u65B9\u6848\u4E0D\u5B58\u5728: ".concat(schemeId));
|
|
277
|
+
return _context3.abrupt("return");
|
|
278
|
+
case 4:
|
|
279
|
+
setCurrentScheme(scheme);
|
|
280
|
+
setIsDirty(false);
|
|
281
|
+
|
|
282
|
+
// 保存当前方案ID,用于刷新后恢复
|
|
283
|
+
if (!storageAdapter.saveCurrentSchemeId) {
|
|
284
|
+
_context3.next = 15;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
_context3.prev = 7;
|
|
288
|
+
_context3.next = 10;
|
|
289
|
+
return storageAdapter.saveCurrentSchemeId(gridId, schemeId);
|
|
290
|
+
case 10:
|
|
291
|
+
_context3.next = 15;
|
|
292
|
+
break;
|
|
293
|
+
case 12:
|
|
294
|
+
_context3.prev = 12;
|
|
295
|
+
_context3.t0 = _context3["catch"](7);
|
|
296
|
+
console.error('[useSchemeManager] 保存当前方案ID失败:', _context3.t0);
|
|
297
|
+
case 15:
|
|
298
|
+
onSchemeChange === null || onSchemeChange === void 0 || onSchemeChange(scheme);
|
|
299
|
+
case 16:
|
|
300
|
+
case "end":
|
|
301
|
+
return _context3.stop();
|
|
302
|
+
}
|
|
303
|
+
}, _callee3, null, [[7, 12]]);
|
|
304
|
+
}));
|
|
305
|
+
return function (_x2) {
|
|
306
|
+
return _ref3.apply(this, arguments);
|
|
307
|
+
};
|
|
308
|
+
}(), [schemes, gridId, storageAdapter, onSchemeChange]);
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* 保存当前方案(更新)
|
|
312
|
+
*/
|
|
313
|
+
var saveScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
314
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(updates) {
|
|
315
|
+
var nameValidation, descValidation, updatedScheme, updatedSchemes;
|
|
316
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
317
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
318
|
+
case 0:
|
|
319
|
+
if (currentScheme) {
|
|
320
|
+
_context4.next = 3;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
console.error('[useSchemeManager] 没有激活的方案');
|
|
324
|
+
return _context4.abrupt("return");
|
|
325
|
+
case 3:
|
|
326
|
+
if (!(updates !== null && updates !== void 0 && updates.name)) {
|
|
327
|
+
_context4.next = 9;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
nameValidation = validateSchemeName(updates.name);
|
|
331
|
+
if (nameValidation.valid) {
|
|
332
|
+
_context4.next = 7;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
throw new Error(nameValidation.error);
|
|
336
|
+
case 7:
|
|
337
|
+
if (!checkDuplicateName(updates.name, schemes, currentScheme.id)) {
|
|
338
|
+
_context4.next = 9;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
throw new Error('方案名称已存在');
|
|
342
|
+
case 9:
|
|
343
|
+
if (!(updates !== null && updates !== void 0 && updates.description)) {
|
|
344
|
+
_context4.next = 13;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
descValidation = validateSchemeDescription(updates.description);
|
|
348
|
+
if (descValidation.valid) {
|
|
349
|
+
_context4.next = 13;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
throw new Error(descValidation.error);
|
|
353
|
+
case 13:
|
|
354
|
+
updatedScheme = _objectSpread(_objectSpread(_objectSpread({}, currentScheme), updates), {}, {
|
|
355
|
+
updatedAt: Date.now()
|
|
356
|
+
});
|
|
357
|
+
updatedSchemes = schemes.map(function (s) {
|
|
358
|
+
return s.id === currentScheme.id ? updatedScheme : s;
|
|
359
|
+
});
|
|
360
|
+
_context4.next = 17;
|
|
361
|
+
return saveSchemesToStorage(updatedSchemes);
|
|
362
|
+
case 17:
|
|
363
|
+
setCurrentScheme(updatedScheme);
|
|
364
|
+
setIsDirty(false);
|
|
365
|
+
onSchemeSave === null || onSchemeSave === void 0 || onSchemeSave(updatedScheme);
|
|
366
|
+
case 20:
|
|
367
|
+
case "end":
|
|
368
|
+
return _context4.stop();
|
|
369
|
+
}
|
|
370
|
+
}, _callee4);
|
|
371
|
+
}));
|
|
372
|
+
return function (_x3) {
|
|
373
|
+
return _ref4.apply(this, arguments);
|
|
374
|
+
};
|
|
375
|
+
}(), [currentScheme, schemes, saveSchemesToStorage, onSchemeSave]);
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 创建新方案
|
|
379
|
+
*/
|
|
380
|
+
var createScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
381
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(name, data, options) {
|
|
382
|
+
var nameValidation, uniqueName, newScheme, updatedSchemes;
|
|
383
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
384
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
385
|
+
case 0:
|
|
386
|
+
// 验证方案名称
|
|
387
|
+
nameValidation = validateSchemeName(name);
|
|
388
|
+
if (nameValidation.valid) {
|
|
389
|
+
_context5.next = 3;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
throw new Error(nameValidation.error);
|
|
393
|
+
case 3:
|
|
394
|
+
if (!(schemes.length >= maxSchemes)) {
|
|
395
|
+
_context5.next = 5;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
throw new Error("\u65B9\u6848\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF08".concat(maxSchemes, "\u4E2A\uFF09\uFF0C\u8BF7\u5220\u9664\u4E00\u4E9B\u65B9\u6848\u540E\u518D\u8BD5"));
|
|
399
|
+
case 5:
|
|
400
|
+
// 处理重名情况
|
|
401
|
+
uniqueName = checkDuplicateName(name, schemes) ? generateUniqueName(name, schemes) : name;
|
|
402
|
+
newScheme = _objectSpread(_objectSpread({
|
|
403
|
+
id: (0, _uuid.v4)(),
|
|
404
|
+
name: uniqueName,
|
|
405
|
+
createdAt: Date.now(),
|
|
406
|
+
updatedAt: Date.now()
|
|
407
|
+
}, data), options); // 如果设置为默认方案,取消其他方案的默认标记
|
|
408
|
+
updatedSchemes = schemes;
|
|
409
|
+
if (newScheme.isDefault) {
|
|
410
|
+
updatedSchemes = schemes.map(function (s) {
|
|
411
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
412
|
+
isDefault: false
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
updatedSchemes = [].concat(_toConsumableArray(updatedSchemes), [newScheme]);
|
|
417
|
+
_context5.next = 12;
|
|
418
|
+
return saveSchemesToStorage(updatedSchemes);
|
|
419
|
+
case 12:
|
|
420
|
+
onSchemeSave === null || onSchemeSave === void 0 || onSchemeSave(newScheme);
|
|
421
|
+
return _context5.abrupt("return", newScheme);
|
|
422
|
+
case 14:
|
|
423
|
+
case "end":
|
|
424
|
+
return _context5.stop();
|
|
425
|
+
}
|
|
426
|
+
}, _callee5);
|
|
427
|
+
}));
|
|
428
|
+
return function (_x4, _x5, _x6) {
|
|
429
|
+
return _ref5.apply(this, arguments);
|
|
430
|
+
};
|
|
431
|
+
}(), [schemes, maxSchemes, saveSchemesToStorage, onSchemeSave]);
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 更新方案信息
|
|
435
|
+
*/
|
|
436
|
+
var updateScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
437
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schemeId, updates) {
|
|
438
|
+
var scheme, nameValidation, updatedScheme, updatedSchemes;
|
|
439
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
440
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
441
|
+
case 0:
|
|
442
|
+
scheme = schemes.find(function (s) {
|
|
443
|
+
return s.id === schemeId;
|
|
444
|
+
});
|
|
445
|
+
if (scheme) {
|
|
446
|
+
_context6.next = 3;
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
throw new Error('方案不存在');
|
|
450
|
+
case 3:
|
|
451
|
+
if (!(scheme.isSystem && (updates.name || updates.isSystem === false))) {
|
|
452
|
+
_context6.next = 5;
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
throw new Error('系统预设方案不允许修改');
|
|
456
|
+
case 5:
|
|
457
|
+
if (!updates.name) {
|
|
458
|
+
_context6.next = 11;
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
nameValidation = validateSchemeName(updates.name);
|
|
462
|
+
if (nameValidation.valid) {
|
|
463
|
+
_context6.next = 9;
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
throw new Error(nameValidation.error);
|
|
467
|
+
case 9:
|
|
468
|
+
if (!checkDuplicateName(updates.name, schemes, schemeId)) {
|
|
469
|
+
_context6.next = 11;
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
throw new Error('方案名称已存在');
|
|
473
|
+
case 11:
|
|
474
|
+
updatedScheme = _objectSpread(_objectSpread(_objectSpread({}, scheme), updates), {}, {
|
|
475
|
+
updatedAt: Date.now()
|
|
476
|
+
});
|
|
477
|
+
updatedSchemes = schemes.map(function (s) {
|
|
478
|
+
return s.id === schemeId ? updatedScheme : s;
|
|
479
|
+
}); // 如果设置为默认方案,取消其他方案的默认标记
|
|
480
|
+
if (updates.isDefault) {
|
|
481
|
+
updatedSchemes = updatedSchemes.map(function (s) {
|
|
482
|
+
return s.id === schemeId ? s : _objectSpread(_objectSpread({}, s), {}, {
|
|
483
|
+
isDefault: false
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
_context6.next = 16;
|
|
488
|
+
return saveSchemesToStorage(updatedSchemes);
|
|
489
|
+
case 16:
|
|
490
|
+
// 如果更新的是当前方案,同步更新
|
|
491
|
+
if ((currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id) === schemeId) {
|
|
492
|
+
setCurrentScheme(updatedScheme);
|
|
493
|
+
}
|
|
494
|
+
case 17:
|
|
495
|
+
case "end":
|
|
496
|
+
return _context6.stop();
|
|
497
|
+
}
|
|
498
|
+
}, _callee6);
|
|
499
|
+
}));
|
|
500
|
+
return function (_x7, _x8) {
|
|
501
|
+
return _ref6.apply(this, arguments);
|
|
502
|
+
};
|
|
503
|
+
}(), [schemes, currentScheme, saveSchemesToStorage]);
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* 删除方案
|
|
507
|
+
*/
|
|
508
|
+
var deleteScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
509
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(schemeId) {
|
|
510
|
+
var scheme, updatedSchemes, nextScheme;
|
|
511
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
512
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
513
|
+
case 0:
|
|
514
|
+
scheme = schemes.find(function (s) {
|
|
515
|
+
return s.id === schemeId;
|
|
516
|
+
});
|
|
517
|
+
if (scheme) {
|
|
518
|
+
_context7.next = 3;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
throw new Error('方案不存在');
|
|
522
|
+
case 3:
|
|
523
|
+
if (!scheme.isSystem) {
|
|
524
|
+
_context7.next = 5;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
throw new Error('系统预设方案不允许删除');
|
|
528
|
+
case 5:
|
|
529
|
+
updatedSchemes = schemes.filter(function (s) {
|
|
530
|
+
return s.id !== schemeId;
|
|
531
|
+
});
|
|
532
|
+
_context7.next = 8;
|
|
533
|
+
return saveSchemesToStorage(updatedSchemes);
|
|
534
|
+
case 8:
|
|
535
|
+
if (!((currentScheme === null || currentScheme === void 0 ? void 0 : currentScheme.id) === schemeId)) {
|
|
536
|
+
_context7.next = 22;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
nextScheme = updatedSchemes.find(function (s) {
|
|
540
|
+
return s.isDefault;
|
|
541
|
+
}) || updatedSchemes[0] || null;
|
|
542
|
+
setCurrentScheme(nextScheme);
|
|
543
|
+
setIsDirty(false);
|
|
544
|
+
|
|
545
|
+
// 保存新的当前方案ID
|
|
546
|
+
if (!storageAdapter.saveCurrentSchemeId) {
|
|
547
|
+
_context7.next = 21;
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
_context7.prev = 13;
|
|
551
|
+
_context7.next = 16;
|
|
552
|
+
return storageAdapter.saveCurrentSchemeId(gridId, (nextScheme === null || nextScheme === void 0 ? void 0 : nextScheme.id) || null);
|
|
553
|
+
case 16:
|
|
554
|
+
_context7.next = 21;
|
|
555
|
+
break;
|
|
556
|
+
case 18:
|
|
557
|
+
_context7.prev = 18;
|
|
558
|
+
_context7.t0 = _context7["catch"](13);
|
|
559
|
+
console.error('[useSchemeManager] 更新当前方案ID失败:', _context7.t0);
|
|
560
|
+
case 21:
|
|
561
|
+
onSchemeChange === null || onSchemeChange === void 0 || onSchemeChange(nextScheme);
|
|
562
|
+
case 22:
|
|
563
|
+
onSchemeDelete === null || onSchemeDelete === void 0 || onSchemeDelete(schemeId);
|
|
564
|
+
case 23:
|
|
565
|
+
case "end":
|
|
566
|
+
return _context7.stop();
|
|
567
|
+
}
|
|
568
|
+
}, _callee7, null, [[13, 18]]);
|
|
569
|
+
}));
|
|
570
|
+
return function (_x9) {
|
|
571
|
+
return _ref7.apply(this, arguments);
|
|
572
|
+
};
|
|
573
|
+
}(), [schemes, currentScheme, gridId, storageAdapter, saveSchemesToStorage, onSchemeChange, onSchemeDelete]);
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* 重置到方案原始状态
|
|
577
|
+
*/
|
|
578
|
+
var resetToScheme = (0, _react.useCallback)(function () {
|
|
579
|
+
if (currentScheme) {
|
|
580
|
+
setIsDirty(false);
|
|
581
|
+
// 触发方案重新加载
|
|
582
|
+
onSchemeChange === null || onSchemeChange === void 0 || onSchemeChange(currentScheme);
|
|
583
|
+
}
|
|
584
|
+
}, [currentScheme, onSchemeChange]);
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* 设置默认方案
|
|
588
|
+
*/
|
|
589
|
+
var setDefaultScheme = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
590
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(schemeId) {
|
|
591
|
+
var updatedSchemes;
|
|
592
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
593
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
594
|
+
case 0:
|
|
595
|
+
updatedSchemes = schemes.map(function (s) {
|
|
596
|
+
return _objectSpread(_objectSpread({}, s), {}, {
|
|
597
|
+
isDefault: s.id === schemeId
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
_context8.next = 3;
|
|
601
|
+
return saveSchemesToStorage(updatedSchemes);
|
|
602
|
+
case 3:
|
|
603
|
+
case "end":
|
|
604
|
+
return _context8.stop();
|
|
605
|
+
}
|
|
606
|
+
}, _callee8);
|
|
607
|
+
}));
|
|
608
|
+
return function (_x10) {
|
|
609
|
+
return _ref8.apply(this, arguments);
|
|
610
|
+
};
|
|
611
|
+
}(), [schemes, saveSchemesToStorage]);
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* 验证方案有效性(可由子类实现具体逻辑)
|
|
615
|
+
*/
|
|
616
|
+
var validateScheme = (0, _react.useCallback)(function (scheme, context) {
|
|
617
|
+
// 基础验证
|
|
618
|
+
var nameValidation = validateSchemeName(scheme.name);
|
|
619
|
+
if (!nameValidation.valid) {
|
|
620
|
+
return nameValidation;
|
|
621
|
+
}
|
|
622
|
+
if (scheme.description) {
|
|
623
|
+
var descValidation = validateSchemeDescription(scheme.description);
|
|
624
|
+
if (!descValidation.valid) {
|
|
625
|
+
return descValidation;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// 可扩展的自定义验证逻辑
|
|
630
|
+
return {
|
|
631
|
+
valid: true
|
|
632
|
+
};
|
|
633
|
+
}, []);
|
|
634
|
+
return {
|
|
635
|
+
currentScheme: currentScheme,
|
|
636
|
+
schemes: schemes,
|
|
637
|
+
isDirty: isDirty,
|
|
638
|
+
loading: loading,
|
|
639
|
+
loadScheme: loadScheme,
|
|
640
|
+
saveScheme: saveScheme,
|
|
641
|
+
createScheme: createScheme,
|
|
642
|
+
updateScheme: updateScheme,
|
|
643
|
+
deleteScheme: deleteScheme,
|
|
644
|
+
resetToScheme: resetToScheme,
|
|
645
|
+
setDefaultScheme: setDefaultScheme,
|
|
646
|
+
validateScheme: validateScheme
|
|
647
|
+
};
|
|
648
|
+
}
|