diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2220d83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/lib +/cjs +/esm +/dist diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..2e1fa2d --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.md \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b2349f2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,18 @@ +{ + "arrowParens": "always", + "bracketSpacing": true, + "endOfLine": "auto", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 100, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "requirePragma": false, + "semi": true, + "singleQuote": false, + "tabWidth": 4, + "trailingComma": "es5", + "useTabs": true +} diff --git a/LICENSE b/LICENSE index 49f1ff6..38f142f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 react-widget +Copyright (c) 2020 nobo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index afc5fb7..6c0dd12 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# tree-basic \ No newline at end of file +# react-widget-tree-basic + +`npm install --save react-widget-tree-basic` diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..0ea13b0 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,15 @@ +module.exports = api => { + const isTest = api.env("test"); + if (!isTest) return {}; + + return { + presets: [ + [ + "babel-preset-packez", + { + modules: "cjs", + }, + ], + ], + }; +}; diff --git a/docs/asset-manifest.json b/docs/asset-manifest.json new file mode 100644 index 0000000..2df6efc --- /dev/null +++ b/docs/asset-manifest.json @@ -0,0 +1,7 @@ +{ + "index.css": "static/css/index.a0a710ab.chunk.css", + "index.js": "static/js/index.a0a710ab.chunk.js", + "runtime-index.js": "static/js/runtime-index.92eae014.js", + "static/js/2.e9b6bfc8.chunk.js": "static/js/2.e9b6bfc8.chunk.js", + "index.html": "index.html" +} \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..6a5eff8 --- /dev/null +++ b/docs/index.html @@ -0,0 +1 @@ +Tree Basic
\ No newline at end of file diff --git a/docs/static/css/index.a0a710ab.chunk.css b/docs/static/css/index.a0a710ab.chunk.css new file mode 100644 index 0000000..8805b3c --- /dev/null +++ b/docs/static/css/index.a0a710ab.chunk.css @@ -0,0 +1 @@ +.container{display:flex;height:100%}.slider{width:200px;border-right:1px solid #f2f2fe}.slider>div{padding:10px;border-bottom:1px solid #f2f2fe;cursor:pointer}.slider .active{background:#39f;color:#fff}.content{overflow:auto;padding:10px;flex:1 1}.table-tree{border-collapse:collapse}.table-tree tbody tr:hover{background-color:#efefef}.table-tree td{border-bottom:1px solid #f2f2f2}.rw-tree-item{padding:5px 2px;cursor:pointer}.rw-tree-item:hover{background:#f2f2f2} \ No newline at end of file diff --git a/docs/static/js/2.e9b6bfc8.chunk.js b/docs/static/js/2.e9b6bfc8.chunk.js new file mode 100644 index 0000000..ab7c552 --- /dev/null +++ b/docs/static/js/2.e9b6bfc8.chunk.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[2],[function(e,t,n){"use strict";e.exports=n(114)},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t,n){(function(t){var n=function(e){return e&&e.Math==Math&&e};e.exports=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof t&&t)||Function("return this")()}).call(this,n(87))},function(e,t,n){var r=n(2),i=n(47),o=n(6),a=n(50),l=n(51),u=n(88),c=i("wks"),s=r.Symbol,f=u?s:s&&s.withoutSetter||a;e.exports=function(e){return o(c,e)||(l&&o(s,e)?c[e]=s[e]:c[e]=f("Symbol."+e)),c[e]}},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){e.exports=function(e){try{return!!e()}catch(t){return!0}}},function(e,t){var n={}.hasOwnProperty;e.exports=function(e,t){return n.call(e,t)}},function(e,t){e.exports=function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}},function(e,t){e.exports=function(e){return"object"===typeof e?null!==e:"function"===typeof e}},function(e,t,n){var r=n(8);e.exports=function(e){if(!r(e))throw TypeError(String(e)+" is not an object");return e}},function(e,t,n){var r=n(2),i=n(38).f,o=n(12),a=n(16),l=n(29),u=n(93),c=n(60);e.exports=function(e,t){var n,s,f,d,p,h=e.target,m=e.global,v=e.stat;if(n=m?r:v?r[h]||l(h,{}):(r[h]||{}).prototype)for(s in t){if(d=t[s],f=e.noTargetGet?(p=i(n,s))&&p.value:n[s],!c(m?s:h+(v?".":"#")+s,e.forced)&&void 0!==f){if(typeof d===typeof f)continue;u(d,f)}(e.sham||f&&f.sham)&&o(d,"sham",!0),a(n,s,d,e)}}},function(e,t,n){var r=n(5);e.exports=!r((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}))},function(e,t,n){var r=n(11),i=n(13),o=n(24);e.exports=r?function(e,t,n){return i.f(e,t,o(1,n))}:function(e,t,n){return e[t]=n,e}},function(e,t,n){var r=n(11),i=n(49),o=n(9),a=n(31),l=Object.defineProperty;t.f=r?l:function(e,t,n){if(o(e),t=a(t,!0),o(n),i)try{return l(e,t,n)}catch(r){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e}},function(e,t){var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t,n){var r=n(90),i=n(2),o=function(e){return"function"==typeof e?e:void 0};e.exports=function(e,t){return arguments.length<2?o(r[e])||o(i[e]):r[e]&&r[e][t]||i[e]&&i[e][t]}},function(e,t,n){var r=n(2),i=n(12),o=n(6),a=n(29),l=n(37),u=n(36),c=u.get,s=u.enforce,f=String(String).split("String");(e.exports=function(e,t,n,l){var u=!!l&&!!l.unsafe,c=!!l&&!!l.enumerable,d=!!l&&!!l.noTargetGet;"function"==typeof n&&("string"!=typeof t||o(n,"name")||i(n,"name",t),s(n).source=f.join("string"==typeof t?t:"")),e!==r?(u?!d&&e[t]&&(c=!0):delete e[t],c?e[t]=n:i(e,t,n)):c?e[t]=n:a(t,n)})(Function.prototype,"toString",(function(){return"function"==typeof this&&c(this).source||l(this)}))},function(e,t){e.exports=!1},function(e,t,n){var r=n(32),i=Math.min;e.exports=function(e){return e>0?i(r(e),9007199254740991):0}},function(e,t){e.exports={}},function(e,t,n){var r=n(46);e.exports=function(e){return Object(r(e))}},,function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var r=function(){function e(){this._caches=Object.create(null)}var t=e.prototype;return t.set=function(e,t){this._caches[e]=t},t.get=function(e){return this._caches[e]},t.has=function(e){return e in this._caches},t.delete=function(e){delete this._caches[e]},t.clear=function(){this._caches=Object.create(null)},e}();function i(e,t){return e===t}function o(e){return void 0===e}function a(e,t){return void 0===e?t:e}var l=function(e){this.id=e.id,this.pid=e.pid,this.root=e.root||!1,this.leaf=e.leaf,this.depth=e.depth,this.data=e.data,this.dirty=null!=e.dirty&&e.dirty};var u=1;function c(){return"node_"+u++}var s=function(){function e(e,t){void 0===t&&(t={}),this.__init=!0,this._cache=new r,this.options=Object.assign({rootId:null,simpleData:!1,idField:"id",pidField:"pid",childrenField:"children",leafField:"leaf",dataProcessor:null,childrenFilter:null,cache:!0},t);var n={pid:this.options.rootId,id:this.options.rootId};this.__root=new l({pid:this.options.rootId,id:this.options.rootId,leaf:!1,root:!0,depth:0,data:n}),this.__NodeList=[],this.__NodeMap={},e&&this.setData(e),this.__init=!1}var t=e.prototype;return t._getChildrenCacheKey=function(e){return e+"_children"},t.clearCache=function(){this._cache.clear()},t.isSimpleData=function(){return this.options.simpleData},t.getNodeList=function(){return this.__NodeList},t.getNodeMap=function(){return this.__NodeMap},t.getRootId=function(){return this.options.rootId},t.hasNode=function(e){return this.__NodeMap.hasOwnProperty(e+"")},t.isRoot=function(e){return i(e,this.getRootId())},t.setData=function(e,t,n){void 0===t&&(t=this.options.rootId),void 0===n&&(n=!0);var r=Array.isArray(e)?e:[e];return r.length?this.isSimpleData()?this._parseSimpleData(r,t,n):this._parseData(r,t,n):[]},t._parseData=function(e,t,n){var r=this;void 0===n&&(n=!0);var i=this.options,a=i.idField,u=i.childrenField,s=i.leafField,f=i.dataProcessor,d=i.cache,p=this.__NodeList,h=this.__NodeMap,m=this.__init,v=this.isRoot(t)?this.getRootNode():this.getNode(t),g=[],y=[t];if(!v)return g;return e.forEach((function(e){return function e(t,i,d){void 0===d&&(d=1),f&&(t=f(t));var m=t[a],v=t[u];void 0===m&&(m=c());var b=t[s];o(b)&&(b=o(v));var w=new l({id:m,pid:i,depth:d,data:t,leaf:!!b});r.hasNode(m)||(g.push(w),n&&p.push(w),h[m]=w),!b&&Array.isArray(v)&&v.forEach((function(t){return e(t,m,d+1)})),b||y.push(m)}(e,v.id,v.depth+1)})),!m&&d&&y.forEach((function(e){return r._cache.delete(r._getChildrenCacheKey(e))})),g},t._parseSimpleData=function(e,t,n){var r=this;void 0===n&&(n=!0);var i=this.options,o=i.idField,u=i.pidField,s=i.dataProcessor,f=i.cache,d=this.__NodeList,p=this.__NodeMap,h=this.isRoot(t)?this.getRootNode():this.getNode(t),m=this.__init,v=[];return h?(e.forEach((function(e){s&&(e=s(e));var t=e[o],i=a(e[u],h.id);void 0===t&&(t=c());var f=new l({id:t,pid:i,depth:0,leaf:!1,data:e,dirty:!0});r.hasNode(t)||(v.push(f),n&&d.push(f),p[t]=f)})),!m&&f&&this._clearCacheByPID(h.id),n&&this._updateDepth(h.id),v):v},t._updateDepth=function(e){var t=this;void 0===e&&(e=this.getRootId());var n=this.isRoot(e)?this.getRootNode():this.getNode(e),r=n?n.depth:0,i=this.getChildren(e);n&&n.dirty&&(n.leaf=!i.length,n.dirty=!1),i.forEach((function(e){e.depth=r+1,t._updateDepth(e.id)}))},t._clearCacheByPID=function(e){var t=this,n=this.getAllChildren(e);this._cache.delete(this._getChildrenCacheKey(e)),n.forEach((function(e){t._cache.delete(t._getChildrenCacheKey(e.id))}))},t.getRootNode=function(){return this.__root},t.getNode=function(e){var t=this.__NodeMap;return this.isRoot(e)?null:t[String(e)]||null},t.getNodeIndex=function(e){if(this.isRoot(e))return 0;for(var t=this.__NodeList,n=-1,r=0;r=0&&(i.splice(n,1),delete o[String(e)],this._cache.delete(this._getChildrenCacheKey(a.id)),r.forEach((function(r){t.getNodeIndex(r.id)>=0&&(i.splice(n,1),delete o[String(e)]),t._cache.delete(t._getChildrenCacheKey(r.id))})))},t.replaceNode=function(e,t,n){if(void 0===n&&(n=this.options.simpleData),!this.isRoot(t)){var r=this.getNode(t);if(r){var i=this.getParentNode(t);if(i){var o=this.getChildren(i.id),a=o.indexOf(r),l=-1===a?null:o[a-1];this.removeNode(r.id),l?this.insertAfter(e,l.id,n):this.prependChild(e,i.id,n)}}}},t.removeAllNode=function(){this.__NodeList=[],this.__NodeMap={},this.clearCache()},t.toData=function(e){var t=this,n=this.options,r=n.idField,i=n.childrenField;return this.getChildren(this.getRootId()).map((function n(o){var a=Object.assign({},o.data);if(!o.leaf){var l=t.getChildren(o.id);a[i]=l.map(n)}return a[r]=o.id,e&&(a=e(a)),a}))},t.toSimpleData=function(e){var t=this.options,n=t.idField,r=t.pidField,i=t.childrenField,o=t.simpleData;return this.getNodeList().map((function(t){var a=Object.assign({},t.data);return a[n]=t.id,a[r]=t.pid,o||delete a[i],e&&(a=e(a)),a}))},t.toPaths=function(e,t){var n=this;return void 0===e&&(e="id"),void 0===t&&(t="/"),this.getAllChildren(this.getRootId()).filter((function(e){return e.leaf})).map((function(r){return n.getPath(r.id,e,t)}))},t.toAllPaths=function(e,t){var n=this;return void 0===e&&(e="id"),void 0===t&&(t="/"),this.getNodeList().map((function(r){return n.getPath(r.id,e,t)}))},t.clone=function(){var t=this.options,n=new e(this.toSimpleData(),{simpleData:!0});return n.options=Object.assign({},t),n},e}()},function(e,t,n){var r=n(28),i=n(46);e.exports=function(e){return r(i(e))}},function(e,t){e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e}},function(e,t,n){"use strict";var r=n(10),i=n(75).map,o=n(45),a=n(27),l=o("map"),u=a("map");r({target:"Array",proto:!0,forced:!l||!u},{map:function(e){return i(this,e,arguments.length>1?arguments[1]:void 0)}})},function(e,t,n){var r=n(11),i=n(5),o=n(6),a=Object.defineProperty,l={},u=function(e){throw e};e.exports=function(e,t){if(o(l,e))return l[e];t||(t={});var n=[][e],c=!!o(t,"ACCESSORS")&&t.ACCESSORS,s=o(t,0)?t[0]:u,f=o(t,1)?t[1]:void 0;return l[e]=!!n&&!i((function(){if(c&&!r)return!0;var e={length:-1};c?a(e,1,{enumerable:!0,get:u}):e[1]=1,n.call(e,s,f)}))}},function(e,t,n){var r=n(5),i=n(14),o="".split;e.exports=r((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==i(e)?o.call(e,""):Object(e)}:Object},function(e,t,n){var r=n(2),i=n(12);e.exports=function(e,t){try{i(r,e,t)}catch(n){r[e]=t}return t}},function(e,t,n){var r=n(2),i=n(8),o=r.document,a=i(o)&&i(o.createElement);e.exports=function(e){return a?o.createElement(e):{}}},function(e,t,n){var r=n(8);e.exports=function(e,t){if(!r(e))return e;var n,i;if(t&&"function"==typeof(n=e.toString)&&!r(i=n.call(e)))return i;if("function"==typeof(n=e.valueOf)&&!r(i=n.call(e)))return i;if(!t&&"function"==typeof(n=e.toString)&&!r(i=n.call(e)))return i;throw TypeError("Can't convert object to primitive value")}},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t){e.exports={}},function(e,t){e.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},function(e,t,n){var r=n(47),i=n(50),o=r("keys");e.exports=function(e){return o[e]||(o[e]=i(e))}},function(e,t,n){var r,i,o,a=n(91),l=n(2),u=n(8),c=n(12),s=n(6),f=n(35),d=n(33),p=l.WeakMap;if(a){var h=new p,m=h.get,v=h.has,g=h.set;r=function(e,t){return g.call(h,e,t),t},i=function(e){return m.call(h,e)||{}},o=function(e){return v.call(h,e)}}else{var y=f("state");d[y]=!0,r=function(e,t){return c(e,y,t),t},i=function(e){return s(e,y)?e[y]:{}},o=function(e){return s(e,y)}}e.exports={set:r,get:i,has:o,enforce:function(e){return o(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!u(t)||(n=i(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}}},function(e,t,n){var r=n(48),i=Function.toString;"function"!=typeof r.inspectSource&&(r.inspectSource=function(e){return i.call(e)}),e.exports=r.inspectSource},function(e,t,n){var r=n(11),i=n(58),o=n(24),a=n(23),l=n(31),u=n(6),c=n(49),s=Object.getOwnPropertyDescriptor;t.f=r?s:function(e,t){if(e=a(e),t=l(t,!0),c)try{return s(e,t)}catch(n){}if(u(e,t))return o(!i.f.call(e,t),e[t])}},function(e,t,n){var r=n(13).f,i=n(6),o=n(3)("toStringTag");e.exports=function(e,t,n){e&&!i(e=n?e:e.prototype,o)&&r(e,o,{configurable:!0,value:t})}},function(e,t,n){var r=n(25);e.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}}},function(e,t,n){var r={};r[n(3)("toStringTag")]="z",e.exports="[object z]"===String(r)},function(e,t,n){var r,i,o=n(2),a=n(69),l=o.process,u=l&&l.versions,c=u&&u.v8;c?i=(r=c.split("."))[0]+r[1]:a&&(!(r=a.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=a.match(/Chrome\/(\d+)/))&&(i=r[1]),e.exports=i&&+i},function(e,t,n){"use strict";var r=n(10),i=n(5),o=n(73),a=n(8),l=n(20),u=n(18),c=n(74),s=n(44),f=n(45),d=n(3),p=n(42),h=d("isConcatSpreadable"),m=p>=51||!i((function(){var e=[];return e[h]=!1,e.concat()[0]!==e})),v=f("concat"),g=function(e){if(!a(e))return!1;var t=e[h];return void 0!==t?!!t:o(e)};r({target:"Array",proto:!0,forced:!m||!v},{concat:function(e){var t,n,r,i,o,a=l(this),f=s(a,0),d=0;for(t=-1,r=arguments.length;t9007199254740991)throw TypeError("Maximum allowed index exceeded");for(n=0;n=9007199254740991)throw TypeError("Maximum allowed index exceeded");c(f,d++,o)}return f.length=d,f}})},function(e,t,n){var r=n(8),i=n(73),o=n(3)("species");e.exports=function(e,t){var n;return i(e)&&("function"!=typeof(n=e.constructor)||n!==Array&&!i(n.prototype)?r(n)&&null===(n=n[o])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===t?0:t)}},function(e,t,n){var r=n(5),i=n(3),o=n(42),a=i("species");e.exports=function(e){return o>=51||!r((function(){var t=[];return(t.constructor={})[a]=function(){return{foo:1}},1!==t[e](Boolean).foo}))}},function(e,t){e.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){var r=n(17),i=n(48);(e.exports=function(e,t){return i[e]||(i[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.6.5",mode:r?"pure":"global",copyright:"\xa9 2020 Denis Pushkarev (zloirock.ru)"})},function(e,t,n){var r=n(2),i=n(29),o=r["__core-js_shared__"]||i("__core-js_shared__",{});e.exports=o},function(e,t,n){var r=n(11),i=n(5),o=n(30);e.exports=!r&&!i((function(){return 7!=Object.defineProperty(o("div"),"a",{get:function(){return 7}}).a}))},function(e,t){var n=0,r=Math.random();e.exports=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++n+r).toString(36)}},function(e,t,n){var r=n(5);e.exports=!!Object.getOwnPropertySymbols&&!r((function(){return!String(Symbol())}))},function(e,t,n){var r,i=n(9),o=n(89),a=n(34),l=n(33),u=n(57),c=n(30),s=n(35),f=s("IE_PROTO"),d=function(){},p=function(e){return"