Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@devbookhq/splitter

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devbookhq/splitter - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

6

lib/index.d.ts

@@ -12,4 +12,4 @@ import React from 'react';

direction: SplitDirection;
minWidth?: number;
minHeight?: number;
minWidths?: number[];
minHeights?: number[];
initialSizes?: number[];

@@ -23,3 +23,3 @@ gutterTheme?: GutterTheme;

}
declare function Split({ direction, minWidth, minHeight, initialSizes, gutterTheme, gutterClassName, draggerClassName, children, onDidResize, classes, }: SplitProps): JSX.Element;
declare function Split({ direction, minWidths, minHeights, initialSizes, gutterTheme, gutterClassName, draggerClassName, children, onDidResize, classes, }: SplitProps): JSX.Element;
export default Split;

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

Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),i=require("styled-components");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t),o=r(i),a=function(){return(a=Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++)for(var n in t=arguments[i])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};function d(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function s(e,t){var i=getComputedStyle(t);if(i){var r=e===exports.SplitDirection.Horizontal?t.clientWidth:t.clientHeight;if(0!==r)return e===exports.SplitDirection.Horizontal?r-=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight):r-=parseFloat(i.paddingTop)+parseFloat(i.paddingBottom),r}}function g(e,i,r){void 0===r&&(r=[]),t.useEffect((function(){return window.addEventListener(e,i),function(){return window.removeEventListener(e,i)}}),function(){for(var e=0,t=0,i=arguments.length;t<i;t++)e+=arguments[t].length;var r=Array(e),n=0;for(t=0;t<i;t++)for(var o=arguments[t],a=0,d=o.length;a<d;a++,n++)r[n]=o[a];return r}([e,i],r))}var u,l,c,h,p,f=o.default.div(u||(u=d(["\n padding: ",";\n ",";\n\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: ",";\n\n background: ",";\n\n :hover {\n cursor: ",";\n\n // Set the Dragger background.\n & > * {\n background: ",";\n }\n }\n"],["\n padding: ",";\n ",";\n\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: ",";\n\n background: ",";\n\n :hover {\n cursor: ",";\n\n // Set the Dragger background.\n & > * {\n background: ",";\n }\n }\n"])),(function(e){return e.dir===exports.SplitDirection.Horizontal?"0 2px":"2px 0"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"height: 100%":"width: 100%"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"column":"row"}),(function(e){return e.theme===exports.GutterTheme.Dark?"#020203":"#EDF0EF"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"col-resize":"row-resize"}),(function(e){return e.theme===exports.GutterTheme.Dark?"#9995A3":"#76747B"})),x=o.default.div(l||(l=d(["\n width: ","px;\n height: ","px;\n background: ",";\n border-radius: 2px;\n"],["\n width: ","px;\n height: ","px;\n background: ",";\n border-radius: 2px;\n"])),(function(e){return e.dir===exports.SplitDirection.Horizontal?"4":"24"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"24":"4"}),(function(e){return e.theme===exports.GutterTheme.Dark?"#434252":"#A6ACB5"})),z=n.default.forwardRef((function(t,i){var r=t.className,n=t.theme,o=t.draggerClassName,d=t.direction,s=t.onMouseDown,g=function(){return e.jsx(x,{dir:d,theme:n},void 0)};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",a({className:r,ref:i,dir:d,onMouseDown:s},{children:[o&&e.jsx("div",{className:o,dir:d},void 0),!o&&e.jsx(g,{},void 0)]}),void 0),!r&&e.jsxs(f,a({ref:i,className:r,dir:d,onMouseDown:s,theme:n},{children:[o&&e.jsx("div",{className:o,dir:d},void 0),!o&&e.jsx(g,{},void 0)]}),void 0)]},void 0)}));function v(e,t,i){var r,n;return t?(r=e/2,n=e):i?(r=e,n=e/2):(r=e,n=e),{aGutterSize:r,bGutterSize:n}}function w(e,t){switch(t.type){case c.CreatePairs:var i=t.payload,r=i.direction,n=i.children,o=i.gutters,d=n[0].parentNode;if(!d)throw new Error("Cannot create pairs - parent is undefined.");if(void 0===(l=s(r,d)))throw new Error("Cannot create pairs - parent has undefined or zero size: "+l+".");var g=[];return n.forEach((function(e,t){if(t>0){var i=n[t-1],a=n[t],s=o[t-1],u=r===exports.SplitDirection.Horizontal?i.getBoundingClientRect().left:i.getBoundingClientRect().top,l=r===exports.SplitDirection.Horizontal?a.getBoundingClientRect().right:a.getBoundingClientRect().bottom,c=r===exports.SplitDirection.Horizontal?i.getBoundingClientRect().width+s.getBoundingClientRect().width+a.getBoundingClientRect().width:i.getBoundingClientRect().height+s.getBoundingClientRect().height+a.getBoundingClientRect().height,h=r===exports.SplitDirection.Horizontal?s.getBoundingClientRect().width:s.getBoundingClientRect().height,p={idx:t-1,a:i,b:a,gutter:s,parent:d,start:u,end:l,size:c,gutterSize:h,aSizePct:100/n.length,bSizePct:100/n.length};g.push(p)}})),a(a({},e),{pairs:g});case c.StartDragging:var u=t.payload.gutterIdx;return a(a({},e),{isDragging:!0,draggingIdx:u});case c.StopDragging:return a(a({},e),{isDragging:!1});case c.CalculateSizes:var l,h=t.payload,p=h.direction,f=(u=h.gutterIdx,e.pairs[u]);if(!(l=s(p,f.parent)))throw new Error("Cannot calculate sizes - 'pair.parent' has undefined or zero size.");var x=f.gutter[p===exports.SplitDirection.Horizontal?"clientWidth":"clientHeight"],z=v(x,0===u,u===e.pairs.length-1),w=z.aGutterSize,S=z.bGutterSize,C=void 0,D=void 0,y=void 0,b=void 0,m=void 0;return p===exports.SplitDirection.Horizontal?(C=f.a.getBoundingClientRect().left,D=f.b.getBoundingClientRect().right,b=(f.a.getBoundingClientRect().width+w)/l*100,m=(f.b.getBoundingClientRect().width+S)/l*100,y=f.a.getBoundingClientRect().width+w+S+f.b.getBoundingClientRect().width):(C=f.a.getBoundingClientRect().top,D=f.b.getBoundingClientRect().bottom,b=(f.a.getBoundingClientRect().height+w)/l*100,m=(f.b.getBoundingClientRect().height+S)/l*100,y=f.a.getBoundingClientRect().height+w+S+f.b.getBoundingClientRect().height),e.pairs[u]=a(a({},f),{start:C,end:D,size:y,aSizePct:b,bSizePct:m,gutterSize:x}),a({},e);default:return e}}!function(e){e[e.CreatePairs=0]="CreatePairs",e[e.CalculateSizes=1]="CalculateSizes",e[e.StartDragging=2]="StartDragging",e[e.StopDragging=3]="StopDragging"}(c||(c={})),exports.SplitDirection=void 0,(h=exports.SplitDirection||(exports.SplitDirection={})).Horizontal="Horizontal",h.Vertical="Vertical",exports.GutterTheme=void 0,(p=exports.GutterTheme||(exports.GutterTheme={})).Light="Light",p.Dark="Dark";var S=o.default.div(y||(y=d(["\n height: 100%;\n width: 100%;\n\n display: flex;\n flex-direction: ",";\n overflow: hidden;\n"],["\n height: 100%;\n width: 100%;\n\n display: flex;\n flex-direction: ",";\n overflow: hidden;\n"])),(function(e){return e.dir===exports.SplitDirection.Horizontal?"row":"column"})),C=o.default.div(b||(b=d(["\n height: 100%;\n width: 100%;\n"],["\n height: 100%;\n width: 100%;\n"])));function D(e){return e===exports.SplitDirection.Horizontal?"col-resize":"row-resize"}var y,b,m={isDragging:!1,pairs:[]};exports.default=function(i){var r=i.direction,o=i.minWidth,d=i.minHeight,u=i.initialSizes,l=i.gutterTheme,h=void 0===l?exports.GutterTheme.Dark:l,p=i.gutterClassName,f=i.draggerClassName,x=i.children,y=i.onDidResize,b=i.classes,R=void 0===b?[]:b,B=t.useReducer(w,m),E=B[0],H=B[1],j=t.useRef([]),k=t.useRef([]);j.current=[],k.current=[];var I=n.default.useCallback((function(e,t){H({type:c.StartDragging,payload:{gutterIdx:t}});var i=E.pairs[t];i.a.style.userSelect="none",i.b.style.userSelect="none",i.gutter.style.cursor=D(e),i.parent.style.cursor=D(e),document.body.style.cursor=D(e)}),[E.pairs]),G=n.default.useCallback((function(){H({type:c.StopDragging});for(var e=[],t=0;t<E.pairs.length;t++){var i=E.pairs[t],n=s(r,i.parent);if(void 0===n)throw new Error("Cannot call the 'onDidResize' callback - parentSize is undefined.");if(void 0===i.gutterSize)throw new Error("Cannot call 'onDidResize' callback - gutterSize is undefined.");var o=0===t,a=t===E.pairs.length-1,d=i.a.getBoundingClientRect()[r===exports.SplitDirection.Horizontal?"width":"height"],g=v(i.gutterSize,o,a),u=g.aGutterSize,l=g.bGutterSize,h=(d+u)/n*100;if(e.push(h),a){var p=(i.b.getBoundingClientRect()[r===exports.SplitDirection.Horizontal?"width":"height"]+l)/n*100;e.push(p)}}if(void 0===E.draggingIdx)throw new Error("Could not reset cursor and user-select because 'state.draggingIdx' is undefined.");var f=E.pairs[E.draggingIdx];null==y||y(f.idx,e),f.a.style.userSelect="",f.b.style.userSelect="",f.gutter.style.cursor="",f.parent.style.cursor="",document.body.style.cursor=""}),[E.draggingIdx,E.pairs,r]),P=n.default.useCallback((function(e,t){H({type:c.CalculateSizes,payload:{direction:e,gutterIdx:t}})}),[]),N=n.default.useCallback((function(e,t,i){H({type:c.CreatePairs,payload:{direction:e,children:t,gutters:i}})}),[]),F=n.default.useCallback((function(e,t,i,r){var n=t[0].parentNode;if(!n)throw new Error("Cannot set initial sizes - parent is undefined.");if(void 0===s(e,n))throw new Error("Cannot set initial sizes - parent has undefined size.");t.forEach((function(n,o){var a,d=0===o,s=o===t.length-1,g=i[s?o-1:o].getBoundingClientRect()[e===exports.SplitDirection.Horizontal?"width":"height"];g=d||s?g/2:g,a=r&&o<r.length?"calc("+r[o]+"% - "+g+"px)":"calc("+100/t.length+"% - "+g+"px)",e===exports.SplitDirection.Horizontal?(n.style.width=a,n.style.height="100%"):(n.style.height=a,n.style.width="100%")}))}),[]),T=n.default.useCallback((function(e,t){if(void 0===E.draggingIdx)throw new Error("Cannot adjust size - 'draggingIdx' is undefined.");var i=E.pairs[E.draggingIdx];if(void 0===i.size)throw new Error("Cannot adjust size - 'pair.size' is undefined.");if(void 0===i.gutterSize)throw new Error("Cannot adjust size - 'pair.gutterSize' is undefined.");var r=i.aSizePct+i.bSizePct,n=t/i.size*r,o=r-t/i.size*r,a=0===E.draggingIdx,d=E.draggingIdx===E.pairs.length-1,s=v(i.gutterSize,a,d),g="calc("+n+"% - "+s.aGutterSize+"px)",u="calc("+o+"% - "+s.bGutterSize+"px)";e===exports.SplitDirection.Horizontal?(i.a.style.width=g,i.b.style.width=u):(i.a.style.height=g,i.b.style.height=u)}),[E.draggingIdx,E.pairs,r]),A=n.default.useCallback((function(e,t,i){if(E.isDragging){if(void 0===E.draggingIdx)throw new Error("Cannot drag - 'draggingIdx' is undefined.");var r=E.pairs[E.draggingIdx];if(void 0===r.start)throw new Error("Cannot drag - 'pair.start' is undefined.");if(void 0===r.size)throw new Error("Cannot drag - 'pair.size' is undefined.");if(void 0===r.gutterSize)throw new Error("Cannot drag - 'pair.gutterSize' is undefined.");var n=function(e,t){return e===exports.SplitDirection.Horizontal?t.clientX:t.clientY}(t,e)-r.start,o=void 0===i?16:i;n<r.gutterSize+o&&(n=r.gutterSize+o),n>=r.size-(r.gutterSize+o)&&(n=r.size-(r.gutterSize+o)),T(t,n)}}),[E.isDragging,E.draggingIdx,E.pairs,T]);function O(e,t){if(!e.current)throw new Error("Can't add element to ref object - ref isn't initialized");t&&!e.current.includes(t)&&e.current.push(t)}return g("mouseup",(function(){if(E.isDragging){if(void 0===E.draggingIdx)throw new Error("Cannot calculate sizes after dragging = 'state.draggingIdx' is undefined");P(r,E.draggingIdx),G()}}),[E.isDragging,G]),g("mousemove",(function(e){E.isDragging&&A(e,r,r===exports.SplitDirection.Horizontal?o:d)}),[r,E.isDragging,A,o,d]),t.useEffect((function(){if(void 0===x)throw new Error("Cannot initialize split - 'children' is undefined");if(!Array.isArray(x))throw new Error("Cannot initialize split - 'children' isn't an array.");if(x.length<=1)throw new Error("Cannot initialize split - the 'children' array has 1 or less elements. Provide at least 2 child views for the split.");if(!j.current||!k.current)throw new Error("Cannot create pairs - 'childRefs' or 'gutterRefs' is undefined.");F(r,j.current,k.current,u),N(r,j.current,k.current)}),[r,F,N,u]),e.jsx(e.Fragment,{children:e.jsx(S,a({dir:r},{children:x&&Array.isArray(x)&&x.map((function(t,i){return e.jsxs(n.default.Fragment,{children:[e.jsx(C,a({ref:function(e){return O(j,e)},className:i<R.length?R[i]:""},{children:t}),void 0),i<x.length-1&&e.jsx(z,{ref:function(e){return O(k,e)},className:p,theme:h,draggerClassName:f,direction:r,onMouseDown:function(e){return function(e,t){t.preventDefault(),P(r,e),I(r,e)}(i,e)}},void 0)]},i)}))}),void 0)},void 0)};
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),i=require("styled-components");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t),o=r(i),a=function(){return(a=Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++)for(var n in t=arguments[i])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};function d(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function s(e,t){var i=getComputedStyle(t);if(i){var r=e===exports.SplitDirection.Horizontal?t.clientWidth:t.clientHeight;if(0!==r)return e===exports.SplitDirection.Horizontal?r-=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight):r-=parseFloat(i.paddingTop)+parseFloat(i.paddingBottom),r}}function g(e,i,r){void 0===r&&(r=[]),t.useEffect((function(){return window.addEventListener(e,i),function(){return window.removeEventListener(e,i)}}),function(){for(var e=0,t=0,i=arguments.length;t<i;t++)e+=arguments[t].length;var r=Array(e),n=0;for(t=0;t<i;t++)for(var o=arguments[t],a=0,d=o.length;a<d;a++,n++)r[n]=o[a];return r}([e,i],r))}var u,l,c,h,p,f=o.default.div(u||(u=d(["\n padding: ",";\n ",";\n\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: ",";\n\n background: ",";\n\n :hover {\n cursor: ",";\n\n // Set the Dragger background.\n & > * {\n background: ",";\n }\n }\n"],["\n padding: ",";\n ",";\n\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: ",";\n\n background: ",";\n\n :hover {\n cursor: ",";\n\n // Set the Dragger background.\n & > * {\n background: ",";\n }\n }\n"])),(function(e){return e.dir===exports.SplitDirection.Horizontal?"0 2px":"2px 0"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"height: 100%":"width: 100%"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"column":"row"}),(function(e){return e.theme===exports.GutterTheme.Dark?"#020203":"#EDF0EF"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"col-resize":"row-resize"}),(function(e){return e.theme===exports.GutterTheme.Dark?"#9995A3":"#76747B"})),x=o.default.div(l||(l=d(["\n width: ","px;\n height: ","px;\n background: ",";\n border-radius: 2px;\n"],["\n width: ","px;\n height: ","px;\n background: ",";\n border-radius: 2px;\n"])),(function(e){return e.dir===exports.SplitDirection.Horizontal?"4":"24"}),(function(e){return e.dir===exports.SplitDirection.Horizontal?"24":"4"}),(function(e){return e.theme===exports.GutterTheme.Dark?"#434252":"#A6ACB5"})),v=n.default.forwardRef((function(t,i){var r=t.className,n=t.theme,o=t.draggerClassName,d=t.direction,s=t.onMouseDown,g=function(){return e.jsx(x,{dir:d,theme:n},void 0)};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",a({className:r,ref:i,dir:d,onMouseDown:s},{children:[o&&e.jsx("div",{className:o,dir:d},void 0),!o&&e.jsx(g,{},void 0)]}),void 0),!r&&e.jsxs(f,a({ref:i,className:r,dir:d,onMouseDown:s,theme:n},{children:[o&&e.jsx("div",{className:o,dir:d},void 0),!o&&e.jsx(g,{},void 0)]}),void 0)]},void 0)}));function z(e,t,i){var r,n;return t?(r=e/2,n=e):i?(r=e,n=e/2):(r=e,n=e),{aGutterSize:r,bGutterSize:n}}function w(e,t){switch(t.type){case c.CreatePairs:var i=t.payload,r=i.direction,n=i.children,o=i.gutters,d=n[0].parentNode;if(!d)throw new Error("Cannot create pairs - parent is undefined.");if(void 0===(l=s(r,d)))throw new Error("Cannot create pairs - parent has undefined or zero size: "+l+".");var g=[];return n.forEach((function(e,t){if(t>0){var i=n[t-1],a=n[t],s=o[t-1],u=r===exports.SplitDirection.Horizontal?i.getBoundingClientRect().left:i.getBoundingClientRect().top,l=r===exports.SplitDirection.Horizontal?a.getBoundingClientRect().right:a.getBoundingClientRect().bottom,c=r===exports.SplitDirection.Horizontal?i.getBoundingClientRect().width+s.getBoundingClientRect().width+a.getBoundingClientRect().width:i.getBoundingClientRect().height+s.getBoundingClientRect().height+a.getBoundingClientRect().height,h=r===exports.SplitDirection.Horizontal?s.getBoundingClientRect().width:s.getBoundingClientRect().height,p={idx:t-1,a:i,b:a,gutter:s,parent:d,start:u,end:l,size:c,gutterSize:h,aSizePct:100/n.length,bSizePct:100/n.length};g.push(p)}})),a(a({},e),{pairs:g});case c.StartDragging:var u=t.payload.gutterIdx;return a(a({},e),{isDragging:!0,draggingIdx:u});case c.StopDragging:return a(a({},e),{isDragging:!1});case c.CalculateSizes:var l,h=t.payload,p=h.direction,f=(u=h.gutterIdx,e.pairs[u]);if(!(l=s(p,f.parent)))throw new Error("Cannot calculate sizes - 'pair.parent' has undefined or zero size.");var x=f.gutter[p===exports.SplitDirection.Horizontal?"clientWidth":"clientHeight"],v=z(x,0===u,u===e.pairs.length-1),w=v.aGutterSize,S=v.bGutterSize,C=void 0,D=void 0,y=void 0,b=void 0,m=void 0;return p===exports.SplitDirection.Horizontal?(C=f.a.getBoundingClientRect().left,D=f.b.getBoundingClientRect().right,b=(f.a.getBoundingClientRect().width+w)/l*100,m=(f.b.getBoundingClientRect().width+S)/l*100,y=f.a.getBoundingClientRect().width+w+S+f.b.getBoundingClientRect().width):(C=f.a.getBoundingClientRect().top,D=f.b.getBoundingClientRect().bottom,b=(f.a.getBoundingClientRect().height+w)/l*100,m=(f.b.getBoundingClientRect().height+S)/l*100,y=f.a.getBoundingClientRect().height+w+S+f.b.getBoundingClientRect().height),e.pairs[u]=a(a({},f),{start:C,end:D,size:y,aSizePct:b,bSizePct:m,gutterSize:x}),a({},e);default:return e}}!function(e){e[e.CreatePairs=0]="CreatePairs",e[e.CalculateSizes=1]="CalculateSizes",e[e.StartDragging=2]="StartDragging",e[e.StopDragging=3]="StopDragging"}(c||(c={})),exports.SplitDirection=void 0,(h=exports.SplitDirection||(exports.SplitDirection={})).Horizontal="Horizontal",h.Vertical="Vertical",exports.GutterTheme=void 0,(p=exports.GutterTheme||(exports.GutterTheme={})).Light="Light",p.Dark="Dark";var S=o.default.div(y||(y=d(["\n height: 100%;\n width: 100%;\n\n display: flex;\n flex-direction: ",";\n overflow: hidden;\n"],["\n height: 100%;\n width: 100%;\n\n display: flex;\n flex-direction: ",";\n overflow: hidden;\n"])),(function(e){return e.dir===exports.SplitDirection.Horizontal?"row":"column"})),C=o.default.div(b||(b=d(["\n height: 100%;\n width: 100%;\n"],["\n height: 100%;\n width: 100%;\n"])));function D(e){return e===exports.SplitDirection.Horizontal?"col-resize":"row-resize"}var y,b,m={isDragging:!1,pairs:[]};exports.default=function(i){var r=i.direction,o=i.minWidths,d=void 0===o?[]:o,u=i.minHeights,l=void 0===u?[]:u,h=i.initialSizes,p=i.gutterTheme,f=void 0===p?exports.GutterTheme.Dark:p,x=i.gutterClassName,y=i.draggerClassName,b=i.children,R=i.onDidResize,B=i.classes,E=void 0===B?[]:B,H=t.useReducer(w,m),j=H[0],k=H[1],I=t.useRef([]),G=t.useRef([]);I.current=[],G.current=[];var P=n.default.useCallback((function(e,t){k({type:c.StartDragging,payload:{gutterIdx:t}});var i=j.pairs[t];i.a.style.userSelect="none",i.b.style.userSelect="none",i.gutter.style.cursor=D(e),i.parent.style.cursor=D(e),document.body.style.cursor=D(e)}),[j.pairs]),N=n.default.useCallback((function(){k({type:c.StopDragging});for(var e=[],t=0;t<j.pairs.length;t++){var i=j.pairs[t],n=s(r,i.parent);if(void 0===n)throw new Error("Cannot call the 'onDidResize' callback - parentSize is undefined.");if(void 0===i.gutterSize)throw new Error("Cannot call 'onDidResize' callback - gutterSize is undefined.");var o=0===t,a=t===j.pairs.length-1,d=i.a.getBoundingClientRect()[r===exports.SplitDirection.Horizontal?"width":"height"],g=z(i.gutterSize,o,a),u=g.aGutterSize,l=g.bGutterSize,h=(d+u)/n*100;if(e.push(h),a){var p=(i.b.getBoundingClientRect()[r===exports.SplitDirection.Horizontal?"width":"height"]+l)/n*100;e.push(p)}}if(void 0===j.draggingIdx)throw new Error("Could not reset cursor and user-select because 'state.draggingIdx' is undefined.");var f=j.pairs[j.draggingIdx];null==R||R(f.idx,e),f.a.style.userSelect="",f.b.style.userSelect="",f.gutter.style.cursor="",f.parent.style.cursor="",document.body.style.cursor=""}),[j.draggingIdx,j.pairs,r]),F=n.default.useCallback((function(e,t){k({type:c.CalculateSizes,payload:{direction:e,gutterIdx:t}})}),[]),T=n.default.useCallback((function(e,t,i){k({type:c.CreatePairs,payload:{direction:e,children:t,gutters:i}})}),[]),A=n.default.useCallback((function(e,t,i,r){var n=t[0].parentNode;if(!n)throw new Error("Cannot set initial sizes - parent is undefined.");if(void 0===s(e,n))throw new Error("Cannot set initial sizes - parent has undefined size.");t.forEach((function(n,o){var a,d=0===o,s=o===t.length-1,g=i[s?o-1:o].getBoundingClientRect()[e===exports.SplitDirection.Horizontal?"width":"height"];g=d||s?g/2:g,a=r&&o<r.length?"calc("+r[o]+"% - "+g+"px)":"calc("+100/t.length+"% - "+g+"px)",e===exports.SplitDirection.Horizontal?(n.style.width=a,n.style.height="100%"):(n.style.height=a,n.style.width="100%")}))}),[]),O=n.default.useCallback((function(e,t){if(void 0===j.draggingIdx)throw new Error("Cannot adjust size - 'draggingIdx' is undefined.");var i=j.pairs[j.draggingIdx];if(void 0===i.size)throw new Error("Cannot adjust size - 'pair.size' is undefined.");if(void 0===i.gutterSize)throw new Error("Cannot adjust size - 'pair.gutterSize' is undefined.");var r=i.aSizePct+i.bSizePct,n=t/i.size*r,o=r-t/i.size*r,a=0===j.draggingIdx,d=j.draggingIdx===j.pairs.length-1,s=z(i.gutterSize,a,d),g="calc("+n+"% - "+s.aGutterSize+"px)",u="calc("+o+"% - "+s.bGutterSize+"px)";e===exports.SplitDirection.Horizontal?(i.a.style.width=g,i.b.style.width=u):(i.a.style.height=g,i.b.style.height=u)}),[j.draggingIdx,j.pairs,r]),L=n.default.useCallback((function(e,t,i){if(j.isDragging){if(void 0===j.draggingIdx)throw new Error("Cannot drag - 'draggingIdx' is undefined.");var r=j.pairs[j.draggingIdx];if(void 0===r.start)throw new Error("Cannot drag - 'pair.start' is undefined.");if(void 0===r.size)throw new Error("Cannot drag - 'pair.size' is undefined.");if(void 0===r.gutterSize)throw new Error("Cannot drag - 'pair.gutterSize' is undefined.");var n=function(e,t){return e===exports.SplitDirection.Horizontal?t.clientX:t.clientY}(t,e)-r.start,o=void 0===i?16:i[j.draggingIdx];n<r.gutterSize+o&&(n=r.gutterSize+o),n>=r.size-(r.gutterSize+o)&&(n=r.size-(r.gutterSize+o)),O(t,n)}}),[j.isDragging,j.draggingIdx,j.pairs,O]);function M(e,t){if(!e.current)throw new Error("Can't add element to ref object - ref isn't initialized");t&&!e.current.includes(t)&&e.current.push(t)}return g("mouseup",(function(){if(j.isDragging){if(void 0===j.draggingIdx)throw new Error("Cannot calculate sizes after dragging = 'state.draggingIdx' is undefined");F(r,j.draggingIdx),N()}}),[j.isDragging,N]),g("mousemove",(function(e){j.isDragging&&L(e,r,r===exports.SplitDirection.Horizontal?d:l)}),[r,j.isDragging,L,d,l]),t.useEffect((function(){if(void 0===b)throw new Error("Cannot initialize split - 'children' is undefined");if(!Array.isArray(b))throw new Error("Cannot initialize split - 'children' isn't an array.");if(b.length<=1)throw new Error("Cannot initialize split - the 'children' array has 1 or less elements. Provide at least 2 child views for the split.");if(!I.current||!G.current)throw new Error("Cannot create pairs - 'childRefs' or 'gutterRefs' is undefined.");A(r,I.current,G.current,h),T(r,I.current,G.current)}),[r,A,T,h]),e.jsx(e.Fragment,{children:e.jsx(S,a({dir:r},{children:b&&Array.isArray(b)&&b.map((function(t,i){return e.jsxs(n.default.Fragment,{children:[e.jsx(C,a({ref:function(e){return M(I,e)},className:i<E.length?E[i]:""},{children:t}),void 0),i<b.length-1&&e.jsx(v,{ref:function(e){return M(G,e)},className:x,theme:f,draggerClassName:y,direction:r,onMouseDown:function(e){return function(e,t){t.preventDefault(),F(r,e),P(r,e)}(i,e)}},void 0)]},i)}))}),void 0)},void 0)};
//# sourceMappingURL=index.js.map
{
"name": "@devbookhq/splitter",
"version": "1.0.8",
"version": "1.1.0",
"description": "Create resizable split views - like in VS Code",

@@ -5,0 +5,0 @@ "license": "MIT",

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