New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

treeboxjs

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treeboxjs - npm Package Compare versions

Comparing version 0.0.23 to 0.0.24

2

dist/index.browser.js

@@ -1,1 +0,1 @@

export default class TreeBox{constructor({config:e={},nodes:t,root:r}={}){if(!t)throw new Error("TreeBox: nodes not provided.");if(!r)throw new Error("TreeBox: root element not provided.");this.nodes=t,this._prepareNodesChildren(this.nodes),this.root=r,this.activeElement=null,this.selectedNode=null,this.navigate("/")}_activate(e){const t=this._getNodeAtPath(this.nodes,e);this.selectedNode=t;const{children:r,display:i}=t;if(i)return this._display(i),!0;if(r)return r;throw new Error("TreeBox: given path yields invalid result.")}_display(e){if("string"!=typeof e&&(e=e.toString()),e=e.trim(),"undefined"!=typeof window){const t=document.createElement("DIV");t.innerHTML=e,e=t.firstChild}e=this._prepareNewEl(e),this.activeElement&&(this.removeCb(this.activeElement),this.root.removeChild(this.activeElement)),this.removeCb=this.selectedNode.onremove||(()=>{}),this.beforeAppendCb=this.selectedNode.onbeforeadded||(()=>{}),this.appendCb=this.selectedNode.onadded||(()=>{}),this.beforeAppendCb(e),this.activeElement=e,this.root.appendChild(e),this.appendCb(this.activeElement)}_getDOMNodeFromString(e,t){return e.parseFromString(t,"text/xml").documentElement}_getNodeAtPath(e,t){let r=e,i="";return t.forEach((e,t)=>{if(i+="/"+e,!r.hasOwnProperty("children")||!r.children.hasOwnProperty(e))throw new Error(`Path does not exist at "${i}"`);r=r.children[e]}),r}_prepareNewEl(e){return e.querySelectorAll&&Array.from(e.querySelectorAll("[treebox-href]")).forEach(e=>{const t=e.getAttribute("treebox-href");e.href="treebox: "+t,e.onclick=r=>(r.preventDefault(),e.blur(),this.navigate(t))}),e}_prepareNodesChildren(e,t=[]){Object.keys(e.children).forEach(r=>{e.children[r].id=r;const i=t.concat(e.children[r].id);e.children[r].keyPath=i,e.children[r].hasOwnProperty("children")&&this._prepareNodesChildren(e.children[r],i)})}_pathToKeys(e){return e.split("/").filter(e=>e)}navigate(e){return this._activate(this._pathToKeys(e))}}
export default class TreeBox{constructor({config:{initialPath:e="/",onnavigate:t=(()=>{})}={},nodes:i,root:r}={}){if(!i)throw new Error("TreeBox: nodes not provided.");if(!r)throw new Error("TreeBox: root element not provided.");this.config=config,this.root=r,this.nodes=i,this._prepareNodesChildren(this.nodes),this.activeElement=null,this.selectedNode=null,this.path=config.initialPath,this.navigateCb=config.onnavigate,this.navigate(config.initialPath)}_activate(){const e=this._getNodeAtPath(this.nodes,this._pathToKeys());this.selectedNode=e;const{children:t,display:i}=e;if(i)return this._display(i),!0;if(t)return t;throw new Error("TreeBox: given path yields invalid result.")}_display(e){if("string"!=typeof e&&(e=e.toString()),e=e.trim(),"undefined"!=typeof window){const t=document.createElement("DIV");t.innerHTML=e,e=t.firstChild}e=this._prepareNewEl(e),this.activeElement&&(this.removeCb(this.activeElement),this.root.removeChild(this.activeElement)),this.removeCb=this.selectedNode.onremove||(()=>{}),this.beforeAppendCb=this.selectedNode.onbeforeadded||(()=>{}),this.appendCb=this.selectedNode.onadded||(()=>{}),this.beforeAppendCb(e),this.activeElement=e,this.root.appendChild(e),this.appendCb(this.activeElement)}_getDOMNodeFromString(e,t){return e.parseFromString(t,"text/xml").documentElement}_getNodeAtPath(e,t){let i=e,r="";return t.forEach((e,t)=>{if(r+="/"+e,!i.hasOwnProperty("children")||!i.children.hasOwnProperty(e))throw new Error(`Path does not exist at "${r}"`);i=i.children[e]}),i}_prepareNewEl(e){return e.querySelectorAll&&Array.from(e.querySelectorAll("[treebox-href]")).forEach(e=>{const t=e.getAttribute("treebox-href");t&&!e.href&&(e.href="treebox: "+t),e.onclick=i=>{if(!i.metaKey&&!i.ctrlKey)return i.preventDefault(),e.blur(),this.navigate(t)}}),e}_prepareNodesChildren(e,t=[]){Object.keys(e.children).forEach(i=>{e.children[i].id=i;const r=t.concat(e.children[i].id);e.children[i].keyPath=r,e.children[i].hasOwnProperty("children")&&this._prepareNodesChildren(e.children[i],r)})}_pathToKeys(){return this.path.split("/").filter(e=>e)}navigate(e){return this.navigateCb({old:this.path,new:e}),this.path=e,this._activate()}}

@@ -1,1 +0,1 @@

module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t){class r{constructor({config:e={},nodes:t,root:r}={}){if(!t)throw new Error("TreeBox: nodes not provided.");if(!r)throw new Error("TreeBox: root element not provided.");this.nodes=t,this._prepareNodesChildren(this.nodes),this.root=r,this.activeElement=null,this.selectedNode=null,this.navigate("/")}_activate(e){const t=this._getNodeAtPath(this.nodes,e);this.selectedNode=t;const{children:r,display:n}=t;if(n)return this._display(n),!0;if(r)return r;throw new Error("TreeBox: given path yields invalid result.")}_display(e){if("string"!=typeof e&&(e=e.toString()),e=e.trim(),"undefined"!=typeof window){const t=document.createElement("DIV");t.innerHTML=e,e=t.firstChild}e=this._prepareNewEl(e),this.activeElement&&(this.removeCb(this.activeElement),this.root.removeChild(this.activeElement)),this.removeCb=this.selectedNode.onremove||(()=>{}),this.beforeAppendCb=this.selectedNode.onbeforeadded||(()=>{}),this.appendCb=this.selectedNode.onadded||(()=>{}),this.beforeAppendCb(e),this.activeElement=e,this.root.appendChild(e),this.appendCb(this.activeElement)}_getDOMNodeFromString(e,t){return e.parseFromString(t,"text/xml").documentElement}_getNodeAtPath(e,t){let r=e,n="";return t.forEach((e,t)=>{if(n+="/"+e,!r.hasOwnProperty("children")||!r.children.hasOwnProperty(e))throw new Error(`Path does not exist at "${n}"`);r=r.children[e]}),r}_prepareNewEl(e){return e.querySelectorAll&&Array.from(e.querySelectorAll("[treebox-href]")).forEach(e=>{const t=e.getAttribute("treebox-href");e.href="treebox: "+t,e.onclick=r=>(r.preventDefault(),e.blur(),this.navigate(t))}),e}_prepareNodesChildren(e,t=[]){Object.keys(e.children).forEach(r=>{e.children[r].id=r;const n=t.concat(e.children[r].id);e.children[r].keyPath=n,e.children[r].hasOwnProperty("children")&&this._prepareNodesChildren(e.children[r],n)})}_pathToKeys(e){return e.split("/").filter(e=>e)}navigate(e){return this._activate(this._pathToKeys(e))}}e.exports=r,e.exports.default=r}]);
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t){class r{constructor({config:{initialPath:e="/",onnavigate:t=(()=>{})}={},nodes:r,root:n}={}){if(!r)throw new Error("TreeBox: nodes not provided.");if(!n)throw new Error("TreeBox: root element not provided.");this.config=config,this.root=n,this.nodes=r,this._prepareNodesChildren(this.nodes),this.activeElement=null,this.selectedNode=null,this.path=config.initialPath,this.navigateCb=config.onnavigate,this.navigate(config.initialPath)}_activate(){const e=this._getNodeAtPath(this.nodes,this._pathToKeys());this.selectedNode=e;const{children:t,display:r}=e;if(r)return this._display(r),!0;if(t)return t;throw new Error("TreeBox: given path yields invalid result.")}_display(e){if("string"!=typeof e&&(e=e.toString()),e=e.trim(),"undefined"!=typeof window){const t=document.createElement("DIV");t.innerHTML=e,e=t.firstChild}e=this._prepareNewEl(e),this.activeElement&&(this.removeCb(this.activeElement),this.root.removeChild(this.activeElement)),this.removeCb=this.selectedNode.onremove||(()=>{}),this.beforeAppendCb=this.selectedNode.onbeforeadded||(()=>{}),this.appendCb=this.selectedNode.onadded||(()=>{}),this.beforeAppendCb(e),this.activeElement=e,this.root.appendChild(e),this.appendCb(this.activeElement)}_getDOMNodeFromString(e,t){return e.parseFromString(t,"text/xml").documentElement}_getNodeAtPath(e,t){let r=e,n="";return t.forEach((e,t)=>{if(n+="/"+e,!r.hasOwnProperty("children")||!r.children.hasOwnProperty(e))throw new Error(`Path does not exist at "${n}"`);r=r.children[e]}),r}_prepareNewEl(e){return e.querySelectorAll&&Array.from(e.querySelectorAll("[treebox-href]")).forEach(e=>{const t=e.getAttribute("treebox-href");t&&!e.href&&(e.href="treebox: "+t),e.onclick=r=>{if(!r.metaKey&&!r.ctrlKey)return r.preventDefault(),e.blur(),this.navigate(t)}}),e}_prepareNodesChildren(e,t=[]){Object.keys(e.children).forEach(r=>{e.children[r].id=r;const n=t.concat(e.children[r].id);e.children[r].keyPath=n,e.children[r].hasOwnProperty("children")&&this._prepareNodesChildren(e.children[r],n)})}_pathToKeys(){return this.path.split("/").filter(e=>e)}navigate(e){return this.navigateCb({old:this.path,new:e}),this.path=e,this._activate()}}e.exports=r,e.exports.default=r}]);
{
"name": "treeboxjs",
"version": "0.0.23",
"version": "0.0.24",
"description": " Display and navigate hierarchical views ",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -0,1 +1,6 @@

<div align="right">
<img alt="David" src="https://img.shields.io/david/jaredgorski/treebox">&nbsp;
<img alt="npm" src="https://img.shields.io/npm/v/treeboxjs">
</div>
<div align="center">

@@ -69,2 +74,3 @@ <h1>

<p>Multiple elements must be wrapped in a single enclosing element</p>
<a treebox-href="/directory/file">Link to /directory/file within treebox</a>
</div>

@@ -71,0 +77,0 @@ `,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc