/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@scena/react-folder@0.9.3/dist/folder.cjs.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var React=require("react"),utils=require("@daybrush/utils"),frameworkUtils=require("framework-utils"),KeyController=require("keycon"),Gesto=require("gesto"),reactCssStyled=require("react-css-styled"),extendStatics=function(e,t){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},extendStatics(e,t)};function __extends(e,t){function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var __assign=function(){return __assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},__assign.apply(this,arguments)};function __rest(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function __spreadArrays(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var i=arguments[t],a=0,l=i.length;a<l;a++,o++)n[o]=i[a];return n}var PREFIX="scena-folder-",RootFolderContext=React.createContext(null);function prefix(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return frameworkUtils.prefixNames.apply(void 0,__spreadArrays([PREFIX],e))}function getId(e,t,r,n){return utils.isString(e)?t[e]:e(t,r,n)}function getName(e,t,r,n){return utils.isString(e)?t[e]:e(t,r,n)}function getChildren(e,t,r){return utils.isString(e)?t[e]:e(t,r)}function getPath(e,t,r,n,o){return utils.isString(e)?n[e]:e(t,r,n,o)}function isEqualArray(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}function isArrayContains(e,t){return e.every((function(e,r){return e===t[r]}))}var FileManager=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.folderRef=React.createRef(),t}__extends(t,e);var r=t.prototype;return r.render=function(){var e,t=this.props,r=t.childrenProperty,n=t.pathProperty,o=t.nameProperty,i=t.idProperty,a=t.index,l=t.info,s=t.scope,p=t.FileComponent,d=t.FoldIcon,f=t.isPadding,c=t.showFoldIcon,u=void 0===c||c,h=t.gap,v=t.multiselect,g=t.selected,y=t.folded,m=t.originalInfos,x=t.pathSeperator,P=t.passWrapperProps,F=t.gapOffset,I=t.preventSelect,_=t.renderOnFolded,b=getId(i,l,a,s),S=getName(o,l,a,s),C=getChildren(r,l,s),R=getPath(n,b,s,l,a),w=R.join(x),E=__spreadArrays(s,[b]),O=s.length,k=C&&C.length>0,U=h*(O+1)+F,M=this.isFolded(w),A=this.isSelected(w),j=prefix("file",A?"selected":""),N=((e={})[f?"paddingLeft":"marginLeft"]=U+"px",e.width=f?"100%":"calc(100% - "+U+"px)",e),D=P({className:j,style:N,scope:s,name:S,value:l,path:R,gapWidth:U,isSelected:A})||{},X=D.style,T=__rest(D,["style"]);return X&&(N=__assign(__assign({},N),X)),React.createElement("div",{className:prefix("property")},React.createElement("div",__assign({className:j,"data-file-path":w,style:N},T),React.createElement("div",{className:prefix("file-name")},k&&d&&u&&React.createElement(d,{className:prefix("fold-icon",M?"fold":""),scope:s,name:S,value:l,path:R,isSelected:A,isFolded:M}),React.createElement(p,{scope:s,name:S,value:l,path:R}))),k&&(_||!M)&&React.createElement(FolderManager,{ref:this.folderRef,scope:E,infos:C,FileComponent:p,FoldIcon:d,nameProperty:o,idProperty:i,pathProperty:n,childrenProperty:r,showFoldIcon:u,selected:g,preventSelect:I,folded:y,renderOnFolded:_,isPadding:f,gap:h,gapOffset:F,multiselect:v,originalInfos:m,isChild:!0,display:M?"none":"block",pathSeperator:x,passWrapperProps:P}))},r.getInfo=function(){return this.props.info},r.isSelected=function(e){var t=this.props.selected;return t&&t.indexOf(e)>-1},r.isFolded=function(e){var t=this.props.folded;return t&&t.indexOf(e)>-1},r.findFile=function(e){var t=this.props,r=t.childrenProperty,n=t.pathProperty,o=t.idProperty,i=t.index,a=t.info,l=t.scope,s=t.pathSeperator,p=getId(o,a,i,l),d=getChildren(r,a,l);if(e===getPath(n,p,l,a,i).join(s))return this;var f=this.folderRef.current;return d&&d.length&&f?f.findFile(e):null},t.defaultProps={},t}(React.PureComponent);function DefaultFoldIcon(e){return React.createElement("div",{className:e.className+" "+prefix("default-fold-icon")})}var FolderElement=reactCssStyled.styled("div",frameworkUtils.prefixCSS(PREFIX,'\n{\n  position: relative;\n  --folder-selected-color: #5bf;\n  --folder-border-color: #444;\n  --folder-guideline-color: #4af;\n  --folder-background-color: #2a2a2a;\n  --folder-icon-color: #fff;\n  --folder-font-color: #fff;\n  background: var(--folder-background-color);\n}\n:host.prevent-select {\n    -webkit-user-select: none;\n    -moz-user-select: none;\n    -ms-user-select: none;\n    user-select: none;\n}\n:host :host {\n  --folder-selected-color: inherit;\n  --folder-border-color: inherit;\n  --folder-guideline-color: inherit;\n  --folder-background-color: inherit;\n  --folder-icon-color: inherit;\n  --folder-font-color: inherit;\n}\n.default-fold-icon {\n  position: absolute;\n  display: inline-block;\n  vertical-align: middle;\n  width: 15px;\n  height: 20px;\n  right: 100%;\n  top: 50%;\n  transform: translateY(-50%);\n}\n.default-fold-icon:before {\n  content: "";\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  transform: translate(-50%, -50%);\n  border-top: 4px solid var(--folder-icon-color);\n  border-left: 3px solid transparent;\n  border-right: 3px solid transparent;\n}\n.default-fold-icon.fold:before {\n  border-right: 0;\n  border-left: 4px solid var(--folder-icon-color);\n  border-top: 3px solid transparent;\n  border-bottom: 3px solid transparent;\n}\n.file {\n  position: relative;\n  box-sizing: border-box;\n  border-bottom: 1px solid var(--folder-border-color);\n  width: 100%;\n  box-sizing: border-box;\n  display: flex;\n  align-items: center;\n  color: var(--folder-font-color);\n}\n.file .file-name {\n  position: relative;\n  display: inline-block;\n  flex: 1;\n}\n.shadows {\n  position: absolute;\n  pointer-events: none;\n  transition: translateY(-50%);\n  opacity: 0.5;\n  top: 0;\n  left: 0;\n  width: 100%;\n  z-index: 10;\n  display: none;\n}\n.file.selected {\n  background: var(--folder-selected-color);\n}\n.guideline {\n  position: absolute;\n  width: 100%;\n  height: 4px;\n  background: var(--folder-guideline-color);\n  transform: translateY(-50%);\n  display: none;\n}\n'));function getCurrentFile(e){for(;e&&!e.hasAttribute("data-file-path");)e=e.parentElement;return e}var FolderManager=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.folderRef=React.createRef(),t.shadowRef=React.createRef(),t.state={shadows:[]},t.fileManagers=[],t.onDragStart=function(e){var r=getCurrentFile(e.inputEvent.target),n=e.datas;if(utils.hasClass(e.inputEvent.target,prefix("fold-icon")))return e.inputEvent.stopPropagation(),e.stop(),t.fold(r),!1;var o=t.flatChildren();n.fileMap=t.flatMap(o),n.fileInfos=o;var i=t.folderRef.current;if(!t.props.isMove)return r&&t.onClickFile({currentTarget:r,datas:n}),e.stop(),!1;if(!(t.props.dragCondtion||function(){return!0})(e))return e.stop(),!1;var a=i.getBoundingClientRect(),l=e.clientX-a.left;n.offsetX=l,n.folderRect=a,n.folderLine=a.left+a.width-10,e.inputEvent.preventDefault(),e.inputEvent.stopPropagation();var s=t.props.selected;return r&&-1===s.indexOf(r.getAttribute("data-file-path"))?(n.clickedFile=r,void t.onClickFile({currentTarget:r,datas:n})):void 0},t.onDrag=function(e){var r,n,o,i=e.clientX,a=e.clientY,l=e.datas;l.isTop=!1,l.depth=0,l.targetInfo=null,l.prevInfo=null,l.nextInfo=null;var s=t.props,p=s.selected,d=s.checkMove,f=s.gap,c=s.pathSeperator;if(t.clearGuideline(),p&&p.length){var u=l.fileInfos,h=l.fileMap,v=l.folderRect,g=p.map((function(e){return h[e]}));if(t.state.shadows.length){t.updateShadowPosition(v,e);var y=getCurrentFile(document.elementFromPoint(l.folderLine,e.clientY));if(y){var m=y.getAttribute("data-file-path"),x=y.getBoundingClientRect(),P=x.top+x.height/2>a,F=utils.findIndex(u,(function(e){return e.pathUrl===m})),I=u[F],_=I.depth,b=i-v.left-(_+1)*f,S=[0,0],C=[],R=u[P?F-1:F],w=u[P?F:F+1],E=null!==(r=null==R?void 0:R.path)&&void 0!==r?r:[],O=null!==(n=null==R?void 0:R.depth)&&void 0!==n?n:0,k=null!==(o=null==w?void 0:w.depth)&&void 0!==o?o:0;if(w||P){if(!R&&P)S=[0,0],C.push({depth:0});else if(O===k)S=[O,O+1],C.push({depth:k,prevInfo:R,parentInfo:R.parentFileInfo}),C.push({depth:k+1,parentInfo:R});else if(O<k)S=[k,k],C.push({depth:k,parentInfo:R});else if(O>k){var U=R.path,M=function(e){var t=U.slice(0,e+1).join(c),r=U.slice(0,e).join(c),n=u.find((function(e){return e.pathUrl===t}));C.push({depth:e,parentInfo:h[r],prevInfo:e>O?null:n})};for(j=(S=[k,O+1])[0];j<=S[1];++j)M(j)}}else for(var A=function(e){var t=E.slice(0,e).join(c),r=u.filter((function(e){return e.parentPathUrl===t}));C.push({depth:e,parentInfo:h[t],prevInfo:r[r.length-1]})},j=(S=[0,_+1])[0];j<=S[1];++j)A(j);var N=p.map((function(e){return e.split(c)}));if(C=C.filter((function(e){var t,r=e.prevInfo,n=e.parentInfo,o=r||n,i=null!==(t=null==o?void 0:o.path)&&void 0!==t?t:[];return!N.some((function(e,t){return(null==r?void 0:r.pathUrl)!==p[t]&&e.every((function(e,t){return e===i[t]}))}))})),C.length){var D=utils.between(_+Math.round((b>0?.2*b:b-f/10)/f),S[0],S[1]),X=C.filter((function(e){return d(e)})).sort((function(e,t){return Math.abs(e.depth-D)-Math.abs(t.depth-D)}))[0];if(X){var T=X.depth,W=T?(T+1)*f:0,q=x.top-v.top+(P?0:x.height);t.guidelineElement.style.cssText="display: block;top: "+q+"px;left: "+W+"px;width: calc(100% - "+W+"px);",l.moveInfo=X,l.isTop=P,l.guidelineDepth=T,l.targetInfo=I,l.prevInfo=R,l.nextInfo=w}}}}else t.setState({shadows:g},(function(){t.updateShadowPosition(v,e)}))}},t.onDragEnd=function(e){var r,n;t.clearGuideline();var o=e.datas;if(e.isDrag||o.clickedFile){var i=t.props,a=i.onMove,l=i.selected,s=i.pathSeperator,p=i.folded,d=o.fileInfos,f=o.targetInfo,c=o.moveInfo,u=o.fileMap,h=l.map((function(e){return u[e]}));if(f){var v=c.prevInfo,g=t.getChildrenFileInfos(c.parentInfo);if(v)for(var y=v.pathUrl,m=utils.findIndex(g,(function(e){return e.pathUrl===y}));m>=-1;--m)if(-1===m)v=null;else if(v=g[m],l.every((function(e){return e!==v.pathUrl})))break;var x=o.prevInfo;if(x){var P=x.pathUrl;for(m=utils.findIndex(d,(function(e){return e.pathUrl===P}));m>=-1;--m)if(-1===m)x=null;else if(x=d[m],h.every((function(e){return!isArrayContains(e.path,x.path)})))break}(g=g.filter((function(e){return!utils.find(h,(function(t){return t.pathUrl===e.pathUrl}))}))).splice.apply(g,__spreadArrays([v?g.findIndex((function(e){return e.pathUrl===v.pathUrl}))+1:0,0],h));var F=null!==(n=null===(r=c.parentInfo)||void 0===r?void 0:r.path)&&void 0!==n?n:[],I=p.map((function(e){var t=u[e];return-1===l.indexOf(e)?e:__spreadArrays(F,[t.id]).join(s)})).filter(Boolean);a(__assign(__assign({},c),{prevInfo:v,children:g.map((function(e){return e.value})),childrenInfos:g,flattenInfos:d,flattenPrevInfo:x,selected:l,selectedInfos:h,nextFolded:I}))}t.setState({shadows:[]},(function(){t.shadowRef.current.style.cssText="display: none"}))}else{var _=getCurrentFile(e.inputEvent.target);_&&t.onClickFile({currentTarget:_,datas:o})}},t.onClickFile=function(e){var r,n=e.currentTarget,o=e.datas,i=n.getAttribute("data-file-path"),a=t.props,l=a.multiselect,s=a.onSelect,p=a.selected,d=a.pathSeperator,f=!1;if(l){var c=(r=(p||[]).slice()).indexOf(i);KeyController.global.shiftKey?c>-1?r.splice(c,1):(f=!0,r.push(i)):(f=!0,r=[i])}else f=!0,r=[i];var u=(r=t.flatChildren().map((function(e){return e.pathUrl})).filter((function(e){return r.indexOf(e)>-1}))).map((function(e){return e.split(d)}));u=u.filter((function(e,t){return u.every((function(r,n){return t===n||!isArrayContains(r,e)}))})),r=u.map((function(e){return e.join(d)}));var h=o.fileMap,v=r.map((function(e){return h[e]}));isEqualArray(p,r)||s({pathUrl:i,path:i.split(d),isSelected:f,selected:r,selectedInfos:v})},t.fold=function(e){var r=t.props,n=r.folded,o=r.pathSeperator,i="";i=e instanceof Element?e.getAttribute("data-file-path"):utils.isArray(e)?e.join(o):e;var a=__spreadArrays(n||[]),l=t.props.onFold,s=a.indexOf(i),p=s>-1;p?a.splice(s,1):a.push(i),l&&l({path:i.split(o),pathUrl:i,isFolded:!p,folded:a})},t}__extends(t,e);var r=t.prototype;return r.render=function(){var e=this._renderFiles();return this.props.scope.length?e:React.createElement(RootFolderContext.Provider,{value:this},e)},r.componentDidMount=function(){if(KeyController.setGlobal(),!this.props.isChild){var e=this.folderRef.current;this.moveGesto=new Gesto(e,{container:window,checkInput:!0,preventDefault:!1}).on("dragStart",this.onDragStart).on("drag",this.onDrag).on("dragEnd",this.onDragEnd)}},r.componentWillUnmount=function(){var e;null===(e=this.moveGesto)||void 0===e||e.unset()},r.isSelected=function(e){var t=this.props,r=t.selected,n=utils.isArray(e)?e.join(t.pathSeperator):e;return r&&r.indexOf(n)>-1},r.isFolded=function(e){var t=this.props,r=utils.isArray(e)?e.join(t.pathSeperator):e,n=t.folded;return n&&n.indexOf(r)>-1},r.findFileInfo=function(e){var t=utils.isString(e)?e:e.join(this.props.pathSeperator),r=this.flatChildren();return utils.find(r,(function(e){return e.pathUrl===t}))||null},r.findFile=function(e){for(var t=this.fileManagers,r=t.length,n=utils.isString(e)?e:e.join(this.props.pathSeperator),o=0;o<r;++o){var i=t[o].findFile(n);if(i)return i}return null},r.renderShadows=function(){var e=this.props,t=e.FileComponent,r=e.nameProperty,n=e.scope,o=e.isPadding,i=e.gap,a=e.passWrapperProps,l=e.gapOffset;if(!n.length)return React.createElement("div",{className:prefix("shadows"),ref:this.shadowRef},this.state.shadows.map((function(e){var n,s=e.scope,p=e.value,d=e.pathUrl,f=e.path,c=e.scope,u=e.index,h=getName(r,p,u,c),v=i*(c.length+1)+l,g=prefix("file","selected","shadow"),y=((n={})[o?"paddingLeft":"marginLeft"]=v+"px",n.width=o?"100%":"calc(100% - "+v+"px)",n),m=a({className:g,style:y,scope:c,name:h,value:p,path:f,gapWidth:v,isSelected:!0,isShadow:!0})||{},x=m.style,P=__rest(m,["style"]);return x&&(y=__assign(__assign({},y),x)),React.createElement("div",__assign({key:d,className:g,style:x},P),React.createElement(t,{scope:s,name:h,value:p,path:f}))})))},r.updateShadowPosition=function(e,t){var r=this.shadowRef.current;if(r&&this.state.shadows.length){var n=t.datas;r.style.cssText="display: block;transform: translate("+(t.clientX-e.left-n.offsetX)+"px, "+(t.clientY-e.top)+"px) translateY(-50%)"}},r.flatMap=function(e){void 0===e&&(e=this.flatChildren());var t={};return e.forEach((function(e){t[e.pathUrl]=e})),t},r.getChildrenFileInfos=function(e){var t=this.props,r=t.childrenProperty,n=t.idProperty,o=t.pathProperty,i=t.infos,a=t.pathSeperator,l=[],s=i,p=[],d="";return e&&(l=__spreadArrays(e.scope,[e.id]),s=getChildren(r,e.value,l),d=e.pathUrl,p=e.path),s?s.map((function(t,r){var i=getId(n,t,r,l),s=getPath(o,i,l,t,r),f=l.length;return{id:i,path:s,parentPath:p,parentValue:null==e?void 0:e.value,parentFileInfo:e||null,pathUrl:s.join(a),parentPathUrl:d,depth:f,scope:l,value:t,index:r}})):[]},r.flatChildren=function(){var e=this.props,t=e.pathProperty,r=e.idProperty,n=e.childrenProperty,o=e.infos,i=e.folded,a=e.pathSeperator,l=[];function s(e,o,p,d,f){var c=getId(r,p,d,f),u=getPath(t,c,f,p,d),h=u.join(a),v=f.length,g={id:c,path:u,pathUrl:h,parentValue:null==e?void 0:e.value,parentFileInfo:e,parentPath:o.split(a),parentPathUrl:o,depth:v,scope:f,value:p,index:d};l.push(g);var y=__spreadArrays(f,[c]),m=getChildren(n,p,f);m&&-1===i.indexOf(h)&&m.forEach((function(e,t){s(g,h,e,t,y)}))}return o.forEach((function(e,t){s(null,"",e,t,[])})),l},r.clearGuideline=function(){this.guidelineElement.style.display="none"},r._renderFiles=function(){var e=this,t=this.props,r=t.scope,n=t.gap,o=t.gapOffset,i=t.isPadding,a=t.infos,l=t.selected,s=t.folded,p=t.multiselect,d=t.FileComponent,f=t.FoldIcon,c=t.nameProperty,u=t.idProperty,h=t.pathProperty,v=t.childrenProperty,g=t.showFoldIcon,y=t.iconColor,m=t.fontColor,x=t.backgroundColor,P=t.borderColor,F=t.guidelineColor,I=t.selectedColor,_=t.originalInfos,b=t.display,S=t.pathSeperator,C=t.preventSelect,R=t.passWrapperProps,w=t.renderOnFolded;return this.fileManagers=this.fileManagers.slice(0,a.length),React.createElement(FolderElement,{className:prefix("folder",C?"prevent-select":""),ref:this.folderRef,style:{"--folder-icon-color":y,"--folder-background-color":x,"--folder-border-color":P,"--folder-guideline-color":F,"--folder-selected-color":I,"--folder-font-color":m,display:b||"block"}},(w||"none"!==b)&&a.map((function(t,y){return React.createElement(FileManager,{ref:frameworkUtils.refs(e,"fileManagers",y),key:y,index:y,info:t,scope:r,selected:l,folded:s,FoldIcon:f,FileComponent:d,isPadding:i,gap:n,renderOnFolded:w,preventSelect:C,gapOffset:o,multiselect:p,showFoldIcon:g,nameProperty:c,idProperty:u,childrenProperty:v,pathProperty:h,originalInfos:_||a,pathSeperator:S,passWrapperProps:R})})),React.createElement("div",{className:prefix("guideline"),ref:frameworkUtils.ref(this,"guidelineElement")}),this.renderShadows())},t.defaultProps={preventSelect:!1,scope:[],selected:[],folded:[],onMove:function(){},checkMove:function(){return!0},onSelect:function(){},gap:15,gapOffset:0,urlProperty:function(e){return e},pathProperty:function(e,t){return __spreadArrays(t,[e])},idProperty:function(e,t){return t},nameProperty:function(e,t){return t},childrenProperty:function(){return[]},passWrapperProps:function(){return{}},pathSeperator:"///",renderOnFolded:!0,FoldIcon:DefaultFoldIcon},t}(React.PureComponent),File=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t}(React.PureComponent),modules={__proto__:null,default:FolderManager,File:File,PREFIX:PREFIX,RootFolderContext:RootFolderContext};for(var name in modules)FolderManager[name]=modules[name];module.exports=FolderManager;
//# sourceMappingURL=/sm/990562022690d73ab5242293479b6ba749a70b9e5964d3923dcd2b4adf4dadff.map