@nocobase/plugin-collection-tree 2.1.0-beta.9 → 2.2.0-beta.1

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/client-v2.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/client-v2';
2
+ export { default } from './dist/client-v2';
package/client-v2.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('./dist/client-v2/index.js');
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-tree",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-tree"]=t(require("@nocobase/client")):e["@nocobase/plugin-collection-tree"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var t={772:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var u=n[e]={exports:{}};return t[e](u,u.exports,r),u.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return!function(){r.r(o),r.d(o,{PluginCollectionTreeClient:function(){return p}});var e=r(772);function t(e,t,n,r,o,u,i){try{var c=e[u](i),l=c.value}catch(e){n(e);return}c.done?t(l):Promise.resolve(l).then(r,o)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(o,u){var i=e.apply(n,r);function c(e){t(i,o,u,c,l,"next",e)}function l(e){t(i,o,u,c,l,"throw",e)}c(void 0)})}}function u(e,t,n){return(u=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return u(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}function f(e,t){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(u){return function(c){var l=[u,c];if(n)throw TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}var p=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=i(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],i(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&c(r,e),t=[{key:"afterAdd",value:function(){return n(function(){return f(this,function(e){return[2]})})()}},{key:"beforeLoad",value:function(){return n(function(){return f(this,function(e){return[2]})})()}},{key:"load",value:function(){return n(function(){return f(this,function(e){return[2]})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(l(e.Plugin));o.default=p}(),o}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-tree",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-tree"]=t(require("@nocobase/client")):e["@nocobase/plugin-collection-tree"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var t={342:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.g.importScripts&&(o=r.g.location+"");var o,i=r.g.document;if(!o&&i&&(i.currentScript&&"SCRIPT"===i.currentScript.tagName.toUpperCase()&&(o=i.currentScript.src),!o)){var c=i.getElementsByTagName("script");if(c.length)for(var u=c.length-1;u>-1&&(!o||!/^http(s?):/.test(o));)o=c[u--].src}if(!o)throw Error("Automatic publicPath is not supported in this browser");r.p=o.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var a={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),e=n+"static/plugins/@nocobase/plugin-collection-tree/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var c=window.location.pathname||"/",u=c.indexOf(i);e=u>=0?c.slice(0,u+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/@nocobase/plugin-collection-tree/dist/client/"}r.p=e}(),!function(){r.r(a),r.d(a,{PluginCollectionTreeClient:function(){return p}});var e=r(342);function t(e,t,n,r,o,i,c){try{var u=e[i](c),a=u.value}catch(e){n(e);return}u.done?t(a):Promise.resolve(a).then(r,o)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(o,i){var c=e.apply(n,r);function u(e){t(c,o,i,u,a,"next",e)}function a(e){t(c,o,i,u,a,"throw",e)}u(void 0)})}}function o(e,t,n){return(o=l()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function f(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},c=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(c,"next",{value:a(0)}),u(c,"throw",{value:a(1)}),u(c,"return",{value:a(2)}),"function"==typeof Symbol&&u(c,Symbol.iterator,{value:function(){return this}}),c;function a(u){return function(a){var l=[u,a];if(n)throw TypeError("Generator is already executing.");for(;c&&(c=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}var p=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=i(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,l()?Reflect.construct(e,t||[],i(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&c(r,e),t=[{key:"afterAdd",value:function(){return n(function(){return f(this,function(e){return[2]})})()}},{key:"beforeLoad",value:function(){return n(function(){return f(this,function(e){return[2]})})()}},{key:"load",value:function(){return n(function(){return f(this,function(e){return[2]})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(u(e.Plugin));a.default=p}(),a}()});
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export { default } from './plugin';
10
+ export * from './plugin';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-tree/client-v2",["@nocobase/client-v2"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-tree/client-v2"]=t(require("@nocobase/client-v2")):e["@nocobase/plugin-collection-tree/client-v2"]=t(e["@nocobase/client-v2"])}(self,function(e){return function(){"use strict";var t={485:function(t){t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.g.importScripts&&(o=n.g.location+"");var o,i=n.g.document;if(!o&&i&&(i.currentScript&&"SCRIPT"===i.currentScript.tagName.toUpperCase()&&(o=i.currentScript.src),!o)){var c=i.getElementsByTagName("script");if(c.length)for(var a=c.length-1;a>-1&&(!o||!/^http(s?):/.test(o));)o=c[a--].src}if(!o)throw Error("Automatic publicPath is not supported in this browser");n.p=o.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var l={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src&&(e=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/@nocobase/plugin-collection-tree/dist/client-v2/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var c=window.location.pathname||"/",a=c.indexOf(i);e=a>=0?c.slice(0,a+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/@nocobase/plugin-collection-tree/dist/client-v2/"}n.p=e}(),!function(){n.r(l),n.d(l,{default:function(){return s},PluginCollectionTreeClientV2:function(){return f}});var e=n(485);function t(e,t,r,n,o,i,c){try{var a=e[i](c),l=a.value}catch(e){r(e);return}a.done?t(l):Promise.resolve(l).then(n,o)}function r(e,t,n){return(r=a()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&i(o,r.prototype),o}).apply(null,arguments)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return r(e,arguments,o(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),i(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}function u(){return[{interface:"integer",name:"parentId",type:"bigInt",title:'{{t("Parent ID")}}',isForeignKey:!0,uiSchema:{"x-read-pretty":!0}},{interface:"m2o",type:"belongsTo",name:"parent",title:'{{t("Parent")}}',foreignKey:"parentId",treeParent:!0,onDelete:"CASCADE",componentProps:{multiple:!1,fieldNames:{label:"id",value:"id"}}},{interface:"o2m",type:"hasMany",name:"children",title:'{{t("Children")}}',foreignKey:"parentId",treeChildren:!0,onDelete:"CASCADE",componentProps:{multiple:!0,fieldNames:{label:"id",value:"id"}}}]}function p(e){if(Array.isArray(e.fields)){e.fields=e.fields.map(function(t){if(!t.target&&["belongsToMany","belongsTo","hasMany","hasOne"].includes(t.type)){var r,n;return r=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},t),n=n={target:e.name},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(n)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}),r}return t});var t=e.fields.find(function(e){return e.primaryKey}),r=e.fields.find(function(e){return"parentId"===e.name&&e.isForeignKey});if(t&&r){var n,o=null==(n=r.uiSchema)?void 0:n.title;r.interface=t.interface,r.type=t.type,r.uiSchema=structuredClone(t.uiSchema||{}),r.uiSchema.title=o,r.autoFill=!1}}}var f=function(e){var r;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function n(){var e,t;if(!(this instanceof n))throw TypeError("Cannot call a class as a function");return e=n,t=arguments,e=o(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],o(this).constructor):e.apply(this,t))}return n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),e&&i(n,e),r=[{key:"load",value:function(){var e;return(e=function(){var e,t;return function(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},c=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),a=Object.defineProperty;return a(c,"next",{value:l(0)}),a(c,"throw",{value:l(1)}),a(c,"return",{value:l(2)}),"function"==typeof Symbol&&a(c,Symbol.iterator,{value:function(){return this}}),c;function l(a){return function(l){var u=[a,l];if(r)throw TypeError("Generator is already executing.");for(;c&&(c=0,u[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(r){return null==(t=this.app.pm.get("@nocobase/plugin-data-source-manager")||this.app.pm.get("data-source-manager"))||null==(e=t.registerCollectionTemplate)||e.call(t,{name:"tree",title:'{{t("Tree collection")}}',order:24,color:"blue",collection:{options:{template:"tree",tree:"adjacencyList"},fields:u},presetFields:{disabledIncludes:["id"]},configure:{transformSubmitValues:p}}),[2]})},function(){var r=this,n=arguments;return new Promise(function(o,i){var c=e.apply(r,n);function a(e){t(c,o,i,a,l,"next",e)}function l(e){t(c,o,i,a,l,"throw",e)}a(void 0)})}).call(this)}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n.prototype,r),n}(c(e.Plugin)),s=f}(),l}()});
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Application, Plugin } from '@nocobase/client-v2';
10
+ export declare class PluginCollectionTreeClientV2 extends Plugin<any, Application> {
11
+ load(): Promise<void>;
12
+ }
13
+ export default PluginCollectionTreeClientV2;
@@ -8,11 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.1.0-beta.9",
12
- "@nocobase/database": "2.1.0-beta.9",
13
- "@nocobase/utils": "2.1.0-beta.9",
14
- "lodash": "4.17.21",
15
- "@nocobase/data-source-manager": "2.1.0-beta.9",
16
- "@nocobase/server": "2.1.0-beta.9",
11
+ "@nocobase/client": "2.2.0-beta.1",
12
+ "@nocobase/client-v2": "2.2.0-beta.1",
13
+ "@nocobase/plugin-data-source-manager": "2.2.0-beta.1",
14
+ "@nocobase/database": "2.2.0-beta.1",
15
+ "@nocobase/utils": "2.2.0-beta.1",
16
+ "lodash": "4.18.1",
17
+ "@nocobase/data-source-manager": "2.2.0-beta.1",
18
+ "@nocobase/server": "2.2.0-beta.1",
17
19
  "sequelize": "6.35.2"
18
20
  };
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(adjacency_list_repository_exports);
42
42
  var import_database = require("@nocobase/database");
43
43
  var import_utils = require("@nocobase/utils");
44
44
  var import_lodash = __toESM(require("lodash"));
45
+ var import_cycle_detection = require("./cycle-detection");
45
46
  class AdjacencyListRepository extends import_database.Repository {
46
47
  async update(options) {
47
48
  return super.update({
@@ -118,13 +119,23 @@ class AdjacencyListRepository extends import_database.Repository {
118
119
  }
119
120
  nodeMap[`${node[foreignKey]}`].push(node);
120
121
  });
121
- function buildTree(rootId) {
122
- const children = nodeMap[rootId];
122
+ const getNodePrimaryKey = (node) => node.get(primaryKey);
123
+ function buildTree(rootId, path, pathIndex) {
124
+ const children = nodeMap[String(rootId)];
123
125
  if (!children) {
124
126
  return [];
125
127
  }
126
128
  return children.map((child) => {
127
- const childrenValues = buildTree(child.id);
129
+ const childPrimaryKey = getNodePrimaryKey(child);
130
+ const cycleStartIndex = pathIndex.get(String(childPrimaryKey));
131
+ if (cycleStartIndex !== void 0) {
132
+ throw new Error((0, import_cycle_detection.formatTreeCycleError)(collection.name, [...path.slice(cycleStartIndex), childPrimaryKey]));
133
+ }
134
+ pathIndex.set(String(childPrimaryKey), path.length);
135
+ path.push(childPrimaryKey);
136
+ const childrenValues = buildTree(childPrimaryKey, path, pathIndex);
137
+ path.pop();
138
+ pathIndex.delete(String(childPrimaryKey));
128
139
  if (childrenValues.length > 0) {
129
140
  child.setDataValue(childrenKey, childrenValues);
130
141
  }
@@ -132,8 +143,8 @@ class AdjacencyListRepository extends import_database.Repository {
132
143
  });
133
144
  }
134
145
  for (const root of rootNodes) {
135
- const rootId = root[primaryKey];
136
- const children = buildTree(rootId);
146
+ const rootId = getNodePrimaryKey(root);
147
+ const children = buildTree(rootId, [rootId], /* @__PURE__ */ new Map([[String(rootId), 0]]));
137
148
  if (children.length > 0) {
138
149
  root.setDataValue(childrenKey, children);
139
150
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export type TreeNodeKey = string | number;
10
+ export declare function findCyclePath(path: TreeNodeKey[], nodeKey: TreeNodeKey): TreeNodeKey[] | null;
11
+ export declare function formatTreeCycleError(collectionName: string, cyclePath: TreeNodeKey[]): string;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var cycle_detection_exports = {};
28
+ __export(cycle_detection_exports, {
29
+ findCyclePath: () => findCyclePath,
30
+ formatTreeCycleError: () => formatTreeCycleError
31
+ });
32
+ module.exports = __toCommonJS(cycle_detection_exports);
33
+ function findCyclePath(path, nodeKey) {
34
+ const nodeKeyString = String(nodeKey);
35
+ const cycleStartIndex = path.findIndex((pathNodeKey) => String(pathNodeKey) === nodeKeyString);
36
+ if (cycleStartIndex === -1) {
37
+ return null;
38
+ }
39
+ return [...path.slice(cycleStartIndex), nodeKey];
40
+ }
41
+ function formatTreeCycleError(collectionName, cyclePath) {
42
+ return `Cycle detected in ${collectionName}: ${cyclePath.join(" -> ")}`;
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ findCyclePath,
47
+ formatTreeCycleError
48
+ });
@@ -11,6 +11,7 @@ declare class PluginCollectionTreeServer extends Plugin {
11
11
  beforeLoad(): Promise<void>;
12
12
  private defineTreePathCollection;
13
13
  private getTreePath;
14
+ private validateTreeParent;
14
15
  private updateTreePath;
15
16
  }
16
17
  export default PluginCollectionTreeServer;
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(plugin_exports);
42
42
  var import_data_source_manager = require("@nocobase/data-source-manager");
43
43
  var import_server = require("@nocobase/server");
44
44
  var import_lodash = __toESM(require("lodash"));
45
+ var import_cycle_detection = require("./cycle-detection");
45
46
  var import_tree_collection = require("./tree-collection");
46
47
  class PluginCollectionTreeServer extends import_server.Plugin {
47
48
  async beforeLoad() {
@@ -138,13 +139,28 @@ class PluginCollectionTreeServer extends import_server.Plugin {
138
139
  transaction: options2.transaction
139
140
  });
140
141
  });
141
- this.db.on(`${collection.name}.beforeSave`, async (model) => {
142
- var _a;
142
+ this.db.on(`${collection.name}.beforeSave`, async (model, options2) => {
143
+ var _a, _b;
143
144
  const tk = collection.filterTargetKey;
144
145
  const parentForeignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
145
- if (model.get(tk) && model.get(parentForeignKey) === model.get(tk)) {
146
+ const nodePrimaryKey = model.get(tk);
147
+ const parentPrimaryKey = model.get(parentForeignKey);
148
+ if (nodePrimaryKey !== null && nodePrimaryKey !== void 0 && parentPrimaryKey !== null && parentPrimaryKey !== void 0 && String(parentPrimaryKey) === String(nodePrimaryKey)) {
146
149
  throw new Error("Cannot set itself as the parent node");
147
150
  }
151
+ if (nodePrimaryKey === null || nodePrimaryKey === void 0 || parentPrimaryKey === null || parentPrimaryKey === void 0) {
152
+ return;
153
+ }
154
+ const isParentChanged = model.isNewRecord || typeof model.changed === "function" && Boolean(model.changed(parentForeignKey)) || ((_b = model["_changed"]) == null ? void 0 : _b.has(parentForeignKey));
155
+ if (!isParentChanged) {
156
+ return;
157
+ }
158
+ await this.validateTreeParent({
159
+ collection,
160
+ nodePrimaryKey,
161
+ parentPrimaryKey,
162
+ transaction: options2 == null ? void 0 : options2.transaction
163
+ });
148
164
  });
149
165
  this.db.on("collections.afterDestroy", async (collection2, { transaction }) => {
150
166
  const name2 = `main_${collection2.get("name")}_path`;
@@ -224,6 +240,35 @@ class PluginCollectionTreeServer extends import_server.Plugin {
224
240
  }
225
241
  return path;
226
242
  }
243
+ async validateTreeParent({
244
+ collection,
245
+ nodePrimaryKey,
246
+ parentPrimaryKey,
247
+ transaction
248
+ }) {
249
+ var _a;
250
+ const tk = collection.filterTargetKey;
251
+ const parentForeignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
252
+ const path = [nodePrimaryKey];
253
+ let currentParentPrimaryKey = parentPrimaryKey;
254
+ while (currentParentPrimaryKey !== null && currentParentPrimaryKey !== void 0) {
255
+ if ((0, import_cycle_detection.findCyclePath)(path, currentParentPrimaryKey)) {
256
+ throw new Error("Cannot set a descendant node as the parent node");
257
+ }
258
+ path.push(currentParentPrimaryKey);
259
+ const parent = await this.app.db.getRepository(collection.name).findOne({
260
+ fields: [tk, parentForeignKey],
261
+ filter: {
262
+ [tk]: currentParentPrimaryKey
263
+ },
264
+ transaction
265
+ });
266
+ if (!parent) {
267
+ return;
268
+ }
269
+ currentParentPrimaryKey = parent.get(parentForeignKey);
270
+ }
271
+ }
227
272
  async updateTreePath(model, collection, pathCollectionName, transaction) {
228
273
  const tk = collection.filterTargetKey;
229
274
  let path = `/${model.get(tk)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-collection-tree",
3
- "version": "2.1.0-beta.9",
3
+ "version": "2.2.0-beta.1",
4
4
  "displayName": "Collection: Tree",
5
5
  "displayName.ru-RU": "Древовидная Коллекция",
6
6
  "displayName.zh-CN": "数据表:树",
@@ -13,9 +13,11 @@
13
13
  "main": "dist/server/index.js",
14
14
  "peerDependencies": {
15
15
  "@nocobase/client": "2.x",
16
+ "@nocobase/client-v2": "2.x",
17
+ "@nocobase/plugin-data-source-manager": "2.x",
16
18
  "@nocobase/server": "2.x",
17
19
  "@nocobase/test": "2.x"
18
20
  },
19
21
  "license": "Apache-2.0",
20
- "gitHead": "c3a2875e4cbbb43b1f2361e6f9f5f84a7d3f3c3c"
22
+ "gitHead": "f82fa9d0c3aa8e00e53dd94e404a312483b4866b"
21
23
  }