@pisell/materials 6.0.11 → 6.0.12
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/build/lowcode/assets-daily.json +11 -15
- package/build/lowcode/assets-dev.json +2 -6
- package/build/lowcode/assets-prod.json +11 -15
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +7 -7
- package/build/lowcode/preview.js +8 -8
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +22 -22
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +22 -22
- package/dist/umd/materials.min.css +1 -0
- package/dist/umd/materials.min.js +1 -0
- package/dist/umd/static/DotsSix.57d66266.svg +1 -0
- package/dist/umd/static/arrow-left.e542294f.svg +1 -0
- package/dist/umd/static/arrow-right.763f03e0.svg +1 -0
- package/dist/umd/static/filter-lines.04a54ae9.svg +1 -0
- package/dist/umd/static/help-circle.31c9be40.svg +1 -0
- package/dist/umd/static/switch-vertical-01.7ebe3ba8.svg +1 -0
- package/es/components/dataSourceComponents/dataSourceForm/BaseForm.js +94 -3
- package/es/components/dataSourceComponents/dataSourceForm/submitButton/index.js +7 -6
- package/es/components/dataSourceComponents/dataSourceForm/type.d.ts +8 -0
- package/es/components/dataSourceComponents/dataSourceForm/utils.d.ts +1 -0
- package/es/components/dataSourceComponents/dataSourceForm/utils.js +120 -38
- package/es/components/dataSourceComponents/dataSourceMenu/index.d.ts +2 -0
- package/es/components/dataSourceComponents/dataSourceMenu/index.js +19 -0
- package/es/components/dataSourceComponents/dataSourceTable/BaseTable.js +46 -8
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +3 -3
- package/es/components/dataSourceComponents/fields/Input.Mobile/WithMode.d.ts +0 -1
- package/es/components/dataSourceComponents/fields/Input.Mobile/WithMode.js +90 -35
- package/es/components/dataSourceComponents/fields/Input.Mobile/index.js +11 -1
- package/es/components/dataSourceComponents/fields/Input.Phone/WithMode.d.ts +0 -1
- package/es/components/dataSourceComponents/fields/Input.Phone/WithMode.js +73 -19
- package/es/components/dataSourceComponents/fields/Input.Subdomain/WithMode.d.ts +4 -2
- package/es/components/dataSourceComponents/fields/Input.Subdomain/WithMode.js +161 -52
- package/es/components/dataSourceComponents/fields/Input.Subdomain/index.d.ts +4 -2
- package/es/components/dataSourceComponents/fields/Input.Subdomain/index.js +2 -2
- package/es/components/dataSourceComponents/fields/Input.Subdomain/serve.d.ts +3 -13
- package/es/components/dataSourceComponents/fields/Input.Subdomain/serve.js +15 -13
- package/es/components/dataSourceComponents/fields/Translation/BaseTranslation.js +15 -4
- package/es/components/dataSourceComponents/fields/Translation/type.d.ts +1 -0
- package/es/components/dataSourceComponents/fields/Upload/BaseUpload.js +17 -13
- package/es/components/dataSourceComponents/fields/Upload/ReadPretty.d.ts +1 -1
- package/es/components/dataSourceComponents/fields/Upload/ReadPretty.js +4 -2
- package/es/components/dataSourceComponents/fields/Upload/WithMode.js +5 -4
- package/es/components/dataSourceComponents/fields/Upload/index.less +1 -1
- package/es/components/dataSourceComponents/fields/Upload/serve.d.ts +1 -1
- package/es/components/dataSourceComponents/fields/Upload/serve.js +5 -5
- package/es/components/dataSourceComponents/fields/Upload/type.d.ts +8 -0
- package/es/components/dataSourceComponents/fields/index.d.ts +9 -5
- package/es/components/dataSourceComponents/fields/type.d.ts +1 -0
- package/es/components/dataSourceComponents/fields/utils.js +1 -0
- package/es/components/dataSourceComponents/provider/actions/ActionsContext.d.ts +6 -1
- package/es/components/dataSourceComponents/provider/actions/ActionsProvider.d.ts +4 -1
- package/es/components/dataSourceComponents/provider/actions/ActionsProvider.js +0 -1
- package/es/components/form/index.js +12 -0
- package/es/components/iconfont/index.js +1 -1
- package/es/components/pisellDraggable/components/Action/Action.d.ts +10 -0
- package/es/components/pisellDraggable/components/Action/Action.js +31 -0
- package/es/components/pisellDraggable/components/Action/Action.less +50 -0
- package/es/components/pisellDraggable/components/Action/index.d.ts +2 -0
- package/es/components/pisellDraggable/components/Action/index.js +1 -0
- package/es/components/pisellDraggable/components/Handle/Handle.d.ts +3 -0
- package/es/components/pisellDraggable/components/Handle/Handle.js +15 -0
- package/es/components/pisellDraggable/components/Handle/index.d.ts +1 -0
- package/es/components/pisellDraggable/components/Handle/index.js +1 -0
- package/es/components/pisellDraggable/components/Remove/Remove.d.ts +3 -0
- package/es/components/pisellDraggable/components/Remove/Remove.js +17 -0
- package/es/components/pisellDraggable/components/Remove/index.d.ts +1 -0
- package/es/components/pisellDraggable/components/Remove/index.js +1 -0
- package/es/components/pisellDraggable/components/TreeItem/SortableTreeItem.d.ts +8 -0
- package/es/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +51 -0
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +21 -0
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.js +57 -0
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.less +128 -0
- package/es/components/pisellDraggable/components/TreeItem/index.d.ts +2 -0
- package/es/components/pisellDraggable/components/TreeItem/index.js +2 -0
- package/es/components/pisellDraggable/components/index.d.ts +4 -0
- package/es/components/pisellDraggable/components/index.js +4 -0
- package/es/components/pisellDraggable/index.d.ts +27 -0
- package/es/components/pisellDraggable/index.js +380 -0
- package/es/components/pisellDraggable/types.d.ts +17 -0
- package/es/components/pisellDraggable/types.js +1 -0
- package/es/components/pisellDraggable/utilities.d.ts +17 -0
- package/es/components/pisellDraggable/utilities.js +230 -0
- package/es/components/pisellLayout/content.d.ts +1 -0
- package/es/components/pisellLayout/content.js +19 -2
- package/es/components/pisellMenu/PisellMenu.d.ts +5 -0
- package/es/components/pisellMenu/PisellMenu.js +55 -0
- package/es/components/pisellMenu/PisellMenu.less +53 -0
- package/es/components/pisellMenu/index.d.ts +3 -0
- package/es/components/pisellMenu/index.js +2 -0
- package/es/components/pisellMenu/types.d.ts +30 -0
- package/es/components/pisellMenu/types.js +1 -0
- package/es/components/pisellModal/components/functions/index.less +3 -0
- package/es/components/table/Table/utils.d.ts +1 -1
- package/es/components/versionModal/index.d.ts +15 -0
- package/es/components/versionModal/index.js +192 -0
- package/es/components/versionModal/index.less +3 -0
- package/es/index.d.ts +5 -0
- package/es/index.js +5 -1
- package/es/locales/en-US.d.ts +22 -0
- package/es/locales/en-US.js +24 -1
- package/es/locales/zh-CN.d.ts +21 -0
- package/es/locales/zh-CN.js +24 -2
- package/es/locales/zh-TW.d.ts +20 -0
- package/es/locales/zh-TW.js +23 -2
- package/lib/components/dataSourceComponents/dataSourceForm/BaseForm.js +77 -4
- package/lib/components/dataSourceComponents/dataSourceForm/submitButton/index.js +1 -0
- package/lib/components/dataSourceComponents/dataSourceForm/type.d.ts +8 -0
- package/lib/components/dataSourceComponents/dataSourceForm/utils.d.ts +1 -0
- package/lib/components/dataSourceComponents/dataSourceForm/utils.js +138 -41
- package/lib/components/dataSourceComponents/dataSourceMenu/index.d.ts +2 -0
- package/lib/components/dataSourceComponents/dataSourceMenu/index.js +45 -0
- package/lib/components/dataSourceComponents/dataSourceTable/BaseTable.js +14 -2
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +3 -3
- package/lib/components/dataSourceComponents/fields/Input.Mobile/WithMode.d.ts +0 -1
- package/lib/components/dataSourceComponents/fields/Input.Mobile/WithMode.js +44 -29
- package/lib/components/dataSourceComponents/fields/Input.Mobile/index.js +11 -1
- package/lib/components/dataSourceComponents/fields/Input.Phone/WithMode.d.ts +0 -1
- package/lib/components/dataSourceComponents/fields/Input.Phone/WithMode.js +34 -17
- package/lib/components/dataSourceComponents/fields/Input.Subdomain/WithMode.d.ts +4 -2
- package/lib/components/dataSourceComponents/fields/Input.Subdomain/WithMode.js +96 -36
- package/lib/components/dataSourceComponents/fields/Input.Subdomain/index.d.ts +4 -2
- package/lib/components/dataSourceComponents/fields/Input.Subdomain/serve.d.ts +3 -13
- package/lib/components/dataSourceComponents/fields/Input.Subdomain/serve.js +19 -14
- package/lib/components/dataSourceComponents/fields/Translation/BaseTranslation.js +15 -4
- package/lib/components/dataSourceComponents/fields/Translation/type.d.ts +1 -0
- package/lib/components/dataSourceComponents/fields/Upload/BaseUpload.js +5 -3
- package/lib/components/dataSourceComponents/fields/Upload/ReadPretty.d.ts +1 -1
- package/lib/components/dataSourceComponents/fields/Upload/ReadPretty.js +2 -2
- package/lib/components/dataSourceComponents/fields/Upload/WithMode.js +4 -4
- package/lib/components/dataSourceComponents/fields/Upload/index.less +1 -1
- package/lib/components/dataSourceComponents/fields/Upload/serve.d.ts +1 -1
- package/lib/components/dataSourceComponents/fields/Upload/serve.js +5 -5
- package/lib/components/dataSourceComponents/fields/Upload/type.d.ts +8 -0
- package/lib/components/dataSourceComponents/fields/index.d.ts +9 -5
- package/lib/components/dataSourceComponents/fields/type.d.ts +1 -0
- package/lib/components/dataSourceComponents/fields/utils.js +1 -0
- package/lib/components/dataSourceComponents/provider/actions/ActionsContext.d.ts +6 -1
- package/lib/components/dataSourceComponents/provider/actions/ActionsProvider.d.ts +4 -1
- package/lib/components/form/index.js +10 -1
- package/lib/components/iconfont/index.js +1 -1
- package/lib/components/pisellDraggable/components/Action/Action.d.ts +10 -0
- package/lib/components/pisellDraggable/components/Action/Action.js +60 -0
- package/lib/components/pisellDraggable/components/Action/Action.less +50 -0
- package/lib/components/pisellDraggable/components/Action/index.d.ts +2 -0
- package/lib/components/pisellDraggable/components/Action/index.js +29 -0
- package/lib/components/pisellDraggable/components/Handle/Handle.d.ts +3 -0
- package/lib/components/pisellDraggable/components/Handle/Handle.js +54 -0
- package/lib/components/pisellDraggable/components/Handle/index.d.ts +1 -0
- package/lib/components/pisellDraggable/components/Handle/index.js +29 -0
- package/lib/components/pisellDraggable/components/Remove/Remove.d.ts +3 -0
- package/lib/components/pisellDraggable/components/Remove/Remove.js +53 -0
- package/lib/components/pisellDraggable/components/Remove/index.d.ts +1 -0
- package/lib/components/pisellDraggable/components/Remove/index.js +29 -0
- package/lib/components/pisellDraggable/components/TreeItem/SortableTreeItem.d.ts +8 -0
- package/lib/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +83 -0
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +21 -0
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.js +93 -0
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.less +128 -0
- package/lib/components/pisellDraggable/components/TreeItem/index.d.ts +2 -0
- package/lib/components/pisellDraggable/components/TreeItem/index.js +32 -0
- package/lib/components/pisellDraggable/components/index.d.ts +4 -0
- package/lib/components/pisellDraggable/components/index.js +40 -0
- package/lib/components/pisellDraggable/index.d.ts +27 -0
- package/lib/components/pisellDraggable/index.js +271 -0
- package/lib/components/pisellDraggable/types.d.ts +17 -0
- package/lib/components/pisellDraggable/types.js +17 -0
- package/lib/components/pisellDraggable/utilities.d.ts +17 -0
- package/lib/components/pisellDraggable/utilities.js +190 -0
- package/lib/components/pisellLayout/content.d.ts +1 -0
- package/lib/components/pisellLayout/content.js +9 -1
- package/lib/components/pisellMenu/PisellMenu.d.ts +5 -0
- package/lib/components/pisellMenu/PisellMenu.js +91 -0
- package/lib/components/pisellMenu/PisellMenu.less +53 -0
- package/lib/components/pisellMenu/index.d.ts +3 -0
- package/lib/components/pisellMenu/index.js +36 -0
- package/lib/components/pisellMenu/types.d.ts +30 -0
- package/lib/components/pisellMenu/types.js +17 -0
- package/lib/components/pisellModal/components/functions/index.less +3 -0
- package/lib/components/table/Table/utils.d.ts +1 -1
- package/lib/components/versionModal/index.d.ts +15 -0
- package/lib/components/versionModal/index.js +219 -0
- package/lib/components/versionModal/index.less +3 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +12 -0
- package/lib/locales/en-US.d.ts +22 -0
- package/lib/locales/en-US.js +24 -1
- package/lib/locales/zh-CN.d.ts +21 -0
- package/lib/locales/zh-CN.js +24 -2
- package/lib/locales/zh-TW.d.ts +20 -0
- package/lib/locales/zh-TW.js +23 -2
- package/lowcode/_utils/defaultSchema.ts +23 -2
- package/lowcode/button/meta.ts +4 -20
- package/lowcode/data-source-form/meta.ts +138 -1
- package/lowcode/data-source-form/snippets.ts +54 -0
- package/lowcode/data-source-menu/meta.ts +122 -0
- package/lowcode/data-source-table/meta.ts +32 -27
- package/lowcode/data-source-table/utils.tsx +33 -1
- package/lowcode/data-source-wrapper/meta.ts +6 -2
- package/lowcode/form-group/meta.ts +5 -1
- package/lowcode/form-item-input.mobile/__screenshots__/mobile.png +0 -0
- package/lowcode/form-item-input.mobile/meta.ts +36 -46
- package/lowcode/form-item-input.mobile/snippets.ts +8 -2
- package/lowcode/form-item-input.phone/meta.ts +8 -42
- package/lowcode/form-item-input.phone/snippets.ts +6 -0
- package/lowcode/form-item-input.subdomain/__screenshots__/subdomain.png +0 -0
- package/lowcode/form-item-input.subdomain/meta.ts +20 -6
- package/lowcode/form-item-input.subdomain/snippets.ts +10 -11
- package/lowcode/form.item/meta.ts +48 -0
- package/lowcode/pisell-content/meta.ts +12 -9
- package/lowcode/pisell-draggable/meta.ts +190 -0
- package/lowcode/pisell-layout/meta.ts +9 -9
- package/lowcode/pisell-menu/meta.ts +112 -0
- package/package.json +1 -1
- package/lowcode/form-item-input.mobile/__screenshots__/phone.png +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
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); } }
|
|
4
|
+
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); }); }; }
|
|
5
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
+
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."); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
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."); }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
19
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
20
|
+
/**
|
|
21
|
+
* 可拖拽树形组件
|
|
22
|
+
* 基于@dnd-kit库实现,支持拖拽排序、展开折叠、删除等功能
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { DndContext, DragOverlay, MeasuringStrategy, PointerSensor, closestCenter, defaultDropAnimation, useSensor, useSensors } from '@dnd-kit/core';
|
|
26
|
+
import { SortableContext, arrayMove, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
|
27
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
28
|
+
import { createPortal } from 'react-dom';
|
|
29
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
30
|
+
import { SortableTreeItem } from "./components";
|
|
31
|
+
import { buildTree, flattenTree, getChildCount, getProjection, removeChildrenOf, removeItem, setProperty } from "./utilities";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 初始化树形数据结构
|
|
35
|
+
* 包含了基本的导航菜单结构:首页、商品集合、关于我们、我的账户等
|
|
36
|
+
*/
|
|
37
|
+
var initialItems = [{
|
|
38
|
+
id: 'Home',
|
|
39
|
+
children: []
|
|
40
|
+
}, {
|
|
41
|
+
id: 'Collections',
|
|
42
|
+
children: [{
|
|
43
|
+
id: 'Spring',
|
|
44
|
+
children: []
|
|
45
|
+
}, {
|
|
46
|
+
id: 'Summer',
|
|
47
|
+
children: []
|
|
48
|
+
}, {
|
|
49
|
+
id: 'Fall',
|
|
50
|
+
children: []
|
|
51
|
+
}, {
|
|
52
|
+
id: 'Winter',
|
|
53
|
+
children: []
|
|
54
|
+
}]
|
|
55
|
+
}, {
|
|
56
|
+
id: 'About Us',
|
|
57
|
+
children: []
|
|
58
|
+
}, {
|
|
59
|
+
id: 'My Account',
|
|
60
|
+
children: [{
|
|
61
|
+
id: 'Addresses',
|
|
62
|
+
children: []
|
|
63
|
+
}, {
|
|
64
|
+
id: 'Order History',
|
|
65
|
+
children: []
|
|
66
|
+
}]
|
|
67
|
+
}];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 测量策略配置
|
|
71
|
+
* strategy: MeasuringStrategy.Always - 始终测量可放置区域的尺寸
|
|
72
|
+
*/
|
|
73
|
+
var measuring = {
|
|
74
|
+
droppable: {
|
|
75
|
+
strategy: MeasuringStrategy.Always
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 拖拽动画配置
|
|
81
|
+
* 定义了拖拽时的动画效果,包括透明度变化和位置移动
|
|
82
|
+
*/
|
|
83
|
+
var dropAnimationConfig = {
|
|
84
|
+
keyframes: function keyframes(_ref) {
|
|
85
|
+
var transform = _ref.transform;
|
|
86
|
+
return [{
|
|
87
|
+
opacity: 1,
|
|
88
|
+
transform: CSS.Transform.toString(transform.initial)
|
|
89
|
+
}, {
|
|
90
|
+
opacity: 0,
|
|
91
|
+
transform: CSS.Transform.toString(_objectSpread(_objectSpread({}, transform.final), {}, {
|
|
92
|
+
x: transform.final.x + 5,
|
|
93
|
+
y: transform.final.y + 5
|
|
94
|
+
}))
|
|
95
|
+
}];
|
|
96
|
+
},
|
|
97
|
+
easing: 'ease-out',
|
|
98
|
+
sideEffects: function sideEffects(_ref2) {
|
|
99
|
+
var active = _ref2.active;
|
|
100
|
+
active.node.animate([{
|
|
101
|
+
opacity: 0
|
|
102
|
+
}, {
|
|
103
|
+
opacity: 1
|
|
104
|
+
}], {
|
|
105
|
+
duration: defaultDropAnimation.duration,
|
|
106
|
+
easing: defaultDropAnimation.easing
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
export function SortableTree(_ref3) {
|
|
111
|
+
var _ref3$collapsible = _ref3.collapsible,
|
|
112
|
+
collapsible = _ref3$collapsible === void 0 ? true : _ref3$collapsible,
|
|
113
|
+
_ref3$value = _ref3.value,
|
|
114
|
+
value = _ref3$value === void 0 ? initialItems : _ref3$value,
|
|
115
|
+
_ref3$indicator = _ref3.indicator,
|
|
116
|
+
indicator = _ref3$indicator === void 0 ? false : _ref3$indicator,
|
|
117
|
+
_ref3$indentationWidt = _ref3.indentationWidth,
|
|
118
|
+
indentationWidth = _ref3$indentationWidt === void 0 ? 50 : _ref3$indentationWidt,
|
|
119
|
+
_ref3$removable = _ref3.removable,
|
|
120
|
+
removable = _ref3$removable === void 0 ? true : _ref3$removable,
|
|
121
|
+
renderItem = _ref3.renderItem,
|
|
122
|
+
onChange = _ref3.onChange,
|
|
123
|
+
onRemoveBefore = _ref3.onRemoveBefore;
|
|
124
|
+
// 状态管理
|
|
125
|
+
/** 当前树形数据 */
|
|
126
|
+
var _useState = useState([]),
|
|
127
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
128
|
+
items = _useState2[0],
|
|
129
|
+
setItems = _useState2[1];
|
|
130
|
+
/** 当前正在拖拽的节点ID */
|
|
131
|
+
var _useState3 = useState(null),
|
|
132
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
133
|
+
activeId = _useState4[0],
|
|
134
|
+
setActiveId = _useState4[1];
|
|
135
|
+
/** 当前拖拽悬停的节点ID */
|
|
136
|
+
var _useState5 = useState(null),
|
|
137
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
138
|
+
overId = _useState6[0],
|
|
139
|
+
setOverId = _useState6[1];
|
|
140
|
+
/** 水平偏移量,用于确定拖拽时的层级变化 */
|
|
141
|
+
var _useState7 = useState(0),
|
|
142
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
143
|
+
offsetLeft = _useState8[0],
|
|
144
|
+
setOffsetLeft = _useState8[1];
|
|
145
|
+
useEffect(function () {
|
|
146
|
+
console.log('初始化', value);
|
|
147
|
+
setItems(value);
|
|
148
|
+
}, [value]);
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 扁平化处理树形数据
|
|
152
|
+
* 1. 将树形结构转换为扁平数组
|
|
153
|
+
* 2. 处理折叠状态
|
|
154
|
+
* 3. 移除被折叠节点的子节点
|
|
155
|
+
*/
|
|
156
|
+
var flattenedItems = useMemo(function () {
|
|
157
|
+
var flattenedTree = flattenTree(items);
|
|
158
|
+
var collapsedItems = flattenedTree.reduce(function (acc, _ref4) {
|
|
159
|
+
var children = _ref4.children,
|
|
160
|
+
collapsed = _ref4.collapsed,
|
|
161
|
+
id = _ref4.id;
|
|
162
|
+
return collapsed && children.length ? [].concat(_toConsumableArray(acc), [id]) : acc;
|
|
163
|
+
}, []);
|
|
164
|
+
return removeChildrenOf(flattenedTree, activeId != null ? [activeId].concat(_toConsumableArray(collapsedItems)) : collapsedItems);
|
|
165
|
+
}, [activeId, items]);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 计算拖拽投影
|
|
169
|
+
* 根据当前拖拽状态计算目标位置和深度
|
|
170
|
+
*/
|
|
171
|
+
var projected = activeId && overId ? getProjection(flattenedItems, activeId, overId, offsetLeft, indentationWidth) : null;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 传感器上下文
|
|
175
|
+
* 存储扁平化的节点数据和偏移量信息
|
|
176
|
+
*/
|
|
177
|
+
var sensorContext = useRef({
|
|
178
|
+
items: flattenedItems,
|
|
179
|
+
offset: offsetLeft
|
|
180
|
+
});
|
|
181
|
+
var sensors = useSensors(useSensor(PointerSensor));
|
|
182
|
+
var sortedIds = useMemo(function () {
|
|
183
|
+
return flattenedItems.map(function (_ref5) {
|
|
184
|
+
var id = _ref5.id;
|
|
185
|
+
return id;
|
|
186
|
+
});
|
|
187
|
+
}, [flattenedItems]);
|
|
188
|
+
var activeItem = activeId ? flattenedItems.find(function (_ref6) {
|
|
189
|
+
var id = _ref6.id;
|
|
190
|
+
return id === activeId;
|
|
191
|
+
}) : null;
|
|
192
|
+
useEffect(function () {
|
|
193
|
+
sensorContext.current = {
|
|
194
|
+
items: flattenedItems,
|
|
195
|
+
offset: offsetLeft
|
|
196
|
+
};
|
|
197
|
+
}, [flattenedItems, offsetLeft]);
|
|
198
|
+
useEffect(function () {
|
|
199
|
+
document.body.id = 'body';
|
|
200
|
+
}, []);
|
|
201
|
+
return /*#__PURE__*/React.createElement(DndContext, {
|
|
202
|
+
sensors: sensors,
|
|
203
|
+
collisionDetection: closestCenter,
|
|
204
|
+
measuring: measuring,
|
|
205
|
+
onDragStart: handleDragStart,
|
|
206
|
+
onDragMove: handleDragMove,
|
|
207
|
+
onDragOver: handleDragOver,
|
|
208
|
+
onDragEnd: handleDragEnd,
|
|
209
|
+
onDragCancel: handleDragCancel
|
|
210
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
211
|
+
items: sortedIds,
|
|
212
|
+
strategy: verticalListSortingStrategy
|
|
213
|
+
}, flattenedItems.map(function (item) {
|
|
214
|
+
var id = item.id,
|
|
215
|
+
children = item.children,
|
|
216
|
+
collapsed = item.collapsed,
|
|
217
|
+
depth = item.depth;
|
|
218
|
+
return /*#__PURE__*/React.createElement(SortableTreeItem, {
|
|
219
|
+
key: id,
|
|
220
|
+
id: id,
|
|
221
|
+
item: item,
|
|
222
|
+
depth: id === activeId && projected ? projected.depth : depth,
|
|
223
|
+
indentationWidth: indentationWidth,
|
|
224
|
+
indicator: indicator,
|
|
225
|
+
collapsed: Boolean(collapsed && children.length),
|
|
226
|
+
onCollapse: collapsible && children.length ? function () {
|
|
227
|
+
return handleCollapse(id);
|
|
228
|
+
} : undefined,
|
|
229
|
+
onRemove: removable ? function () {
|
|
230
|
+
return handleRemove(item);
|
|
231
|
+
} : undefined,
|
|
232
|
+
renderItem: renderItem
|
|
233
|
+
});
|
|
234
|
+
}), /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(DragOverlay, {
|
|
235
|
+
dropAnimation: dropAnimationConfig,
|
|
236
|
+
modifiers: indicator ? [adjustTranslate] : undefined
|
|
237
|
+
}, activeId && activeItem ? /*#__PURE__*/React.createElement(SortableTreeItem, {
|
|
238
|
+
id: activeId,
|
|
239
|
+
depth: activeItem.depth,
|
|
240
|
+
clone: true,
|
|
241
|
+
childCount: getChildCount(items, activeId) + 1,
|
|
242
|
+
item: activeItem,
|
|
243
|
+
indentationWidth: indentationWidth,
|
|
244
|
+
renderItem: renderItem
|
|
245
|
+
}) : null), document.body)));
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 处理拖拽开始事件
|
|
249
|
+
* 设置当前拖拽项和初始状态
|
|
250
|
+
*/
|
|
251
|
+
function handleDragStart(_ref7) {
|
|
252
|
+
var activeId = _ref7.active.id;
|
|
253
|
+
setActiveId(activeId);
|
|
254
|
+
setOverId(activeId);
|
|
255
|
+
document.body.style.setProperty('cursor', 'grabbing');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 处理拖拽移动事件
|
|
260
|
+
* 更新水平偏移量
|
|
261
|
+
*/
|
|
262
|
+
function handleDragMove(_ref8) {
|
|
263
|
+
var delta = _ref8.delta;
|
|
264
|
+
setOffsetLeft(delta.x);
|
|
265
|
+
}
|
|
266
|
+
function handleDragOver(_ref9) {
|
|
267
|
+
var _over$id;
|
|
268
|
+
var over = _ref9.over;
|
|
269
|
+
setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : null);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 处理拖拽结束事件
|
|
274
|
+
* 1. 重置状态
|
|
275
|
+
* 2. 更新节点位置和层级
|
|
276
|
+
* 3. 重建树形结构
|
|
277
|
+
*/
|
|
278
|
+
function handleDragEnd(_ref10) {
|
|
279
|
+
var active = _ref10.active,
|
|
280
|
+
over = _ref10.over;
|
|
281
|
+
resetState();
|
|
282
|
+
if (projected && over) {
|
|
283
|
+
var depth = projected.depth,
|
|
284
|
+
parentId = projected.parentId;
|
|
285
|
+
var clonedItems = JSON.parse(JSON.stringify(flattenTree(items)));
|
|
286
|
+
var overIndex = clonedItems.findIndex(function (_ref11) {
|
|
287
|
+
var id = _ref11.id;
|
|
288
|
+
return id === over.id;
|
|
289
|
+
});
|
|
290
|
+
var activeIndex = clonedItems.findIndex(function (_ref12) {
|
|
291
|
+
var id = _ref12.id;
|
|
292
|
+
return id === active.id;
|
|
293
|
+
});
|
|
294
|
+
var activeTreeItem = clonedItems[activeIndex];
|
|
295
|
+
clonedItems[activeIndex] = _objectSpread(_objectSpread({}, activeTreeItem), {}, {
|
|
296
|
+
depth: depth,
|
|
297
|
+
parentId: parentId
|
|
298
|
+
});
|
|
299
|
+
var sortedItems = arrayMove(clonedItems, activeIndex, overIndex);
|
|
300
|
+
var newItems = buildTree(sortedItems);
|
|
301
|
+
setItems(newItems);
|
|
302
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newItems);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function handleDragCancel() {
|
|
306
|
+
resetState();
|
|
307
|
+
}
|
|
308
|
+
function resetState() {
|
|
309
|
+
setOverId(null);
|
|
310
|
+
setActiveId(null);
|
|
311
|
+
setOffsetLeft(0);
|
|
312
|
+
document.body.style.setProperty('cursor', '');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* 处理节点删除
|
|
317
|
+
* 从树形结构中移除指定节点
|
|
318
|
+
*/
|
|
319
|
+
function handleRemove(_x2) {
|
|
320
|
+
return _handleRemove.apply(this, arguments);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* 处理节点折叠/展开
|
|
324
|
+
* 切换指定节点的折叠状态
|
|
325
|
+
*/
|
|
326
|
+
function _handleRemove() {
|
|
327
|
+
_handleRemove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item) {
|
|
328
|
+
var res;
|
|
329
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
330
|
+
while (1) switch (_context.prev = _context.next) {
|
|
331
|
+
case 0:
|
|
332
|
+
if (!onRemoveBefore) {
|
|
333
|
+
_context.next = 6;
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
_context.next = 3;
|
|
337
|
+
return onRemoveBefore === null || onRemoveBefore === void 0 ? void 0 : onRemoveBefore(item);
|
|
338
|
+
case 3:
|
|
339
|
+
res = _context.sent;
|
|
340
|
+
if (res) {
|
|
341
|
+
_context.next = 6;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
return _context.abrupt("return");
|
|
345
|
+
case 6:
|
|
346
|
+
setItems(function (items) {
|
|
347
|
+
return removeItem(items, item.id);
|
|
348
|
+
});
|
|
349
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(items);
|
|
350
|
+
case 8:
|
|
351
|
+
case "end":
|
|
352
|
+
return _context.stop();
|
|
353
|
+
}
|
|
354
|
+
}, _callee);
|
|
355
|
+
}));
|
|
356
|
+
return _handleRemove.apply(this, arguments);
|
|
357
|
+
}
|
|
358
|
+
function handleCollapse(id) {
|
|
359
|
+
setItems(function (items) {
|
|
360
|
+
return setProperty(items, id, 'collapsed', function (value) {
|
|
361
|
+
return !value;
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* 调整拖拽项的位置
|
|
369
|
+
* 对拖拽时的位置进行微调,提升视觉效果
|
|
370
|
+
*/
|
|
371
|
+
var adjustTranslate = function adjustTranslate(_ref13) {
|
|
372
|
+
var transform = _ref13.transform;
|
|
373
|
+
return _objectSpread(_objectSpread({}, transform), {}, {
|
|
374
|
+
y: transform.y - 25
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
var Demo = function Demo() {
|
|
378
|
+
return /*#__PURE__*/React.createElement(SortableTree, null);
|
|
379
|
+
};
|
|
380
|
+
export default Demo;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import type { UniqueIdentifier } from '@dnd-kit/core';
|
|
3
|
+
export interface TreeItem {
|
|
4
|
+
id: UniqueIdentifier;
|
|
5
|
+
children: TreeItem[];
|
|
6
|
+
collapsed?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare type TreeItems = TreeItem[];
|
|
9
|
+
export interface FlattenedItem extends TreeItem {
|
|
10
|
+
parentId: UniqueIdentifier | null;
|
|
11
|
+
depth: number;
|
|
12
|
+
index: number;
|
|
13
|
+
}
|
|
14
|
+
export declare type SensorContext = MutableRefObject<{
|
|
15
|
+
items: FlattenedItem[];
|
|
16
|
+
offset: number;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UniqueIdentifier } from '@dnd-kit/core';
|
|
2
|
+
import type { FlattenedItem, TreeItem, TreeItems } from './types';
|
|
3
|
+
export declare const iOS: boolean;
|
|
4
|
+
export declare function getProjection(items: FlattenedItem[], activeId: UniqueIdentifier, overId: UniqueIdentifier, dragOffset: number, indentationWidth: number): {
|
|
5
|
+
depth: number;
|
|
6
|
+
maxDepth: number;
|
|
7
|
+
minDepth: number;
|
|
8
|
+
parentId: UniqueIdentifier | null;
|
|
9
|
+
};
|
|
10
|
+
export declare function flattenTree(items: TreeItems): FlattenedItem[];
|
|
11
|
+
export declare function buildTree(flattenedItems: FlattenedItem[]): TreeItems;
|
|
12
|
+
export declare function findItem(items: TreeItem[], itemId: UniqueIdentifier): TreeItem | undefined;
|
|
13
|
+
export declare function findItemDeep(items: TreeItems, itemId: UniqueIdentifier): TreeItem | undefined;
|
|
14
|
+
export declare function removeItem(items: TreeItems, id: UniqueIdentifier): TreeItem[];
|
|
15
|
+
export declare function setProperty<T extends keyof TreeItem>(items: TreeItems, id: UniqueIdentifier, property: T, setter: (value: TreeItem[T]) => TreeItem[T]): TreeItem[];
|
|
16
|
+
export declare function getChildCount(items: TreeItems, id: UniqueIdentifier): number;
|
|
17
|
+
export declare function removeChildrenOf(items: FlattenedItem[], ids: UniqueIdentifier[]): FlattenedItem[];
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
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."); }
|
|
10
|
+
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); }
|
|
11
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
+
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; }
|
|
14
|
+
import { arrayMove } from '@dnd-kit/sortable';
|
|
15
|
+
export var iOS = /iPad|iPhone|iPod/.test(navigator.platform);
|
|
16
|
+
function getDragDepth(offset, indentationWidth) {
|
|
17
|
+
return Math.round(offset / indentationWidth);
|
|
18
|
+
}
|
|
19
|
+
export function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
|
|
20
|
+
var overItemIndex = items.findIndex(function (_ref) {
|
|
21
|
+
var id = _ref.id;
|
|
22
|
+
return id === overId;
|
|
23
|
+
});
|
|
24
|
+
var activeItemIndex = items.findIndex(function (_ref2) {
|
|
25
|
+
var id = _ref2.id;
|
|
26
|
+
return id === activeId;
|
|
27
|
+
});
|
|
28
|
+
var activeItem = items[activeItemIndex];
|
|
29
|
+
var newItems = arrayMove(items, activeItemIndex, overItemIndex);
|
|
30
|
+
var previousItem = newItems[overItemIndex - 1];
|
|
31
|
+
var nextItem = newItems[overItemIndex + 1];
|
|
32
|
+
var dragDepth = getDragDepth(dragOffset, indentationWidth);
|
|
33
|
+
var projectedDepth = activeItem.depth + dragDepth;
|
|
34
|
+
var maxDepth = getMaxDepth({
|
|
35
|
+
previousItem: previousItem
|
|
36
|
+
});
|
|
37
|
+
var minDepth = getMinDepth({
|
|
38
|
+
nextItem: nextItem
|
|
39
|
+
});
|
|
40
|
+
var depth = projectedDepth;
|
|
41
|
+
if (projectedDepth >= maxDepth) {
|
|
42
|
+
depth = maxDepth;
|
|
43
|
+
} else if (projectedDepth < minDepth) {
|
|
44
|
+
depth = minDepth;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
depth: depth,
|
|
48
|
+
maxDepth: maxDepth,
|
|
49
|
+
minDepth: minDepth,
|
|
50
|
+
parentId: getParentId()
|
|
51
|
+
};
|
|
52
|
+
function getParentId() {
|
|
53
|
+
var _newItems$slice$rever;
|
|
54
|
+
if (depth === 0 || !previousItem) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (depth === previousItem.depth) {
|
|
58
|
+
return previousItem.parentId;
|
|
59
|
+
}
|
|
60
|
+
if (depth > previousItem.depth) {
|
|
61
|
+
return previousItem.id;
|
|
62
|
+
}
|
|
63
|
+
var newParent = (_newItems$slice$rever = newItems.slice(0, overItemIndex).reverse().find(function (item) {
|
|
64
|
+
return item.depth === depth;
|
|
65
|
+
})) === null || _newItems$slice$rever === void 0 ? void 0 : _newItems$slice$rever.parentId;
|
|
66
|
+
return newParent !== null && newParent !== void 0 ? newParent : null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function getMaxDepth(_ref3) {
|
|
70
|
+
var previousItem = _ref3.previousItem;
|
|
71
|
+
if (previousItem) {
|
|
72
|
+
return previousItem.depth + 1;
|
|
73
|
+
}
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
function getMinDepth(_ref4) {
|
|
77
|
+
var nextItem = _ref4.nextItem;
|
|
78
|
+
if (nextItem) {
|
|
79
|
+
return nextItem.depth;
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
function flatten(items) {
|
|
84
|
+
var parentId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
85
|
+
var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
86
|
+
return items.reduce(function (acc, item, index) {
|
|
87
|
+
return [].concat(_toConsumableArray(acc), [_objectSpread(_objectSpread({}, item), {}, {
|
|
88
|
+
parentId: parentId,
|
|
89
|
+
depth: depth,
|
|
90
|
+
index: index
|
|
91
|
+
})], _toConsumableArray(flatten(item.children, item.id, depth + 1)));
|
|
92
|
+
}, []);
|
|
93
|
+
}
|
|
94
|
+
export function flattenTree(items) {
|
|
95
|
+
return flatten(items);
|
|
96
|
+
}
|
|
97
|
+
export function buildTree(flattenedItems) {
|
|
98
|
+
var root = {
|
|
99
|
+
id: 'root',
|
|
100
|
+
children: []
|
|
101
|
+
};
|
|
102
|
+
var nodes = _defineProperty({}, root.id, root);
|
|
103
|
+
var items = flattenedItems.map(function (item) {
|
|
104
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
105
|
+
children: []
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
var _iterator = _createForOfIteratorHelper(items),
|
|
109
|
+
_step;
|
|
110
|
+
try {
|
|
111
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
112
|
+
var _item$parentId, _nodes$parentId;
|
|
113
|
+
var item = _step.value;
|
|
114
|
+
var id = item.id,
|
|
115
|
+
children = item.children;
|
|
116
|
+
var parentId = (_item$parentId = item.parentId) !== null && _item$parentId !== void 0 ? _item$parentId : root.id;
|
|
117
|
+
var parent = (_nodes$parentId = nodes[parentId]) !== null && _nodes$parentId !== void 0 ? _nodes$parentId : findItem(items, parentId);
|
|
118
|
+
nodes[id] = {
|
|
119
|
+
id: id,
|
|
120
|
+
children: children
|
|
121
|
+
};
|
|
122
|
+
parent.children.push(item);
|
|
123
|
+
}
|
|
124
|
+
} catch (err) {
|
|
125
|
+
_iterator.e(err);
|
|
126
|
+
} finally {
|
|
127
|
+
_iterator.f();
|
|
128
|
+
}
|
|
129
|
+
return root.children;
|
|
130
|
+
}
|
|
131
|
+
export function findItem(items, itemId) {
|
|
132
|
+
return items.find(function (_ref5) {
|
|
133
|
+
var id = _ref5.id;
|
|
134
|
+
return id === itemId;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export function findItemDeep(items, itemId) {
|
|
138
|
+
var _iterator2 = _createForOfIteratorHelper(items),
|
|
139
|
+
_step2;
|
|
140
|
+
try {
|
|
141
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
142
|
+
var item = _step2.value;
|
|
143
|
+
var id = item.id,
|
|
144
|
+
children = item.children;
|
|
145
|
+
if (id === itemId) {
|
|
146
|
+
return item;
|
|
147
|
+
}
|
|
148
|
+
if (children.length) {
|
|
149
|
+
var child = findItemDeep(children, itemId);
|
|
150
|
+
if (child) {
|
|
151
|
+
return child;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
_iterator2.e(err);
|
|
157
|
+
} finally {
|
|
158
|
+
_iterator2.f();
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
export function removeItem(items, id) {
|
|
163
|
+
var newItems = [];
|
|
164
|
+
var _iterator3 = _createForOfIteratorHelper(items),
|
|
165
|
+
_step3;
|
|
166
|
+
try {
|
|
167
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
168
|
+
var item = _step3.value;
|
|
169
|
+
if (item.id === id) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (item.children.length) {
|
|
173
|
+
item.children = removeItem(item.children, id);
|
|
174
|
+
}
|
|
175
|
+
newItems.push(item);
|
|
176
|
+
}
|
|
177
|
+
} catch (err) {
|
|
178
|
+
_iterator3.e(err);
|
|
179
|
+
} finally {
|
|
180
|
+
_iterator3.f();
|
|
181
|
+
}
|
|
182
|
+
return newItems;
|
|
183
|
+
}
|
|
184
|
+
export function setProperty(items, id, property, setter) {
|
|
185
|
+
var _iterator4 = _createForOfIteratorHelper(items),
|
|
186
|
+
_step4;
|
|
187
|
+
try {
|
|
188
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
189
|
+
var item = _step4.value;
|
|
190
|
+
if (item.id === id) {
|
|
191
|
+
item[property] = setter(item[property]);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (item.children.length) {
|
|
195
|
+
item.children = setProperty(item.children, id, property, setter);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (err) {
|
|
199
|
+
_iterator4.e(err);
|
|
200
|
+
} finally {
|
|
201
|
+
_iterator4.f();
|
|
202
|
+
}
|
|
203
|
+
return _toConsumableArray(items);
|
|
204
|
+
}
|
|
205
|
+
function countChildren(items) {
|
|
206
|
+
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
207
|
+
return items.reduce(function (acc, _ref6) {
|
|
208
|
+
var children = _ref6.children;
|
|
209
|
+
if (children.length) {
|
|
210
|
+
return countChildren(children, acc + 1);
|
|
211
|
+
}
|
|
212
|
+
return acc + 1;
|
|
213
|
+
}, count);
|
|
214
|
+
}
|
|
215
|
+
export function getChildCount(items, id) {
|
|
216
|
+
var item = findItemDeep(items, id);
|
|
217
|
+
return item ? countChildren(item.children) : 0;
|
|
218
|
+
}
|
|
219
|
+
export function removeChildrenOf(items, ids) {
|
|
220
|
+
var excludeParentIds = _toConsumableArray(ids);
|
|
221
|
+
return items.filter(function (item) {
|
|
222
|
+
if (item.parentId && excludeParentIds.includes(item.parentId)) {
|
|
223
|
+
if (item.children.length) {
|
|
224
|
+
excludeParentIds.push(item.id);
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
});
|
|
230
|
+
}
|