@devbookhq/splitter
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -20,4 +20,5 @@ import React from 'react'; | ||
onDidResize?: (pairIdx: number, newSizes: number[]) => void; | ||
classes?: string[]; | ||
} | ||
declare function Split({ direction, minWidth, minHeight, initialSizes, gutterTheme, gutterClassName, draggerClassName, children, onDidResize, }: SplitProps): JSX.Element; | ||
declare function Split({ direction, minWidth, minHeight, 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,p,h,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,p=r===exports.SplitDirection.Horizontal?s.getBoundingClientRect().width:s.getBoundingClientRect().height,h={idx:t-1,a:i,b:a,gutter:s,parent:d,start:u,end:l,size:c,gutterSize:p,aSizePct:100/n.length,bSizePct:100/n.length};g.push(h)}})),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,p=t.payload,h=p.direction,f=(u=p.gutterIdx,e.pairs[u]);if(!(l=s(h,f.parent)))throw new Error("Cannot calculate sizes - 'pair.parent' has undefined or zero size.");var x=f.gutter[h===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 h===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,(p=exports.SplitDirection||(exports.SplitDirection={})).Horizontal="Horizontal",p.Vertical="Vertical",exports.GutterTheme=void 0,(h=exports.GutterTheme||(exports.GutterTheme={})).Light="Light",h.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,p=void 0===l?exports.GutterTheme.Dark:l,h=i.gutterClassName,f=i.draggerClassName,x=i.children,y=i.onDidResize,b=t.useReducer(w,m),R=b[0],B=b[1],E=t.useRef([]),H=t.useRef([]);E.current=[],H.current=[];var j=n.default.useCallback((function(e,t){B({type:c.StartDragging,payload:{gutterIdx:t}});var i=R.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)}),[R.pairs]),k=n.default.useCallback((function(){B({type:c.StopDragging});for(var e=[],t=0;t<R.pairs.length;t++){var i=R.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===R.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,p=(d+u)/n*100;if(e.push(p),a){var h=(i.b.getBoundingClientRect()[r===exports.SplitDirection.Horizontal?"width":"height"]+l)/n*100;e.push(h)}}if(void 0===R.draggingIdx)throw new Error("Could not reset cursor and user-select because 'state.draggingIdx' is undefined.");var f=R.pairs[R.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=""}),[R.draggingIdx,R.pairs,r]),I=n.default.useCallback((function(e,t){B({type:c.CalculateSizes,payload:{direction:e,gutterIdx:t}})}),[]),G=n.default.useCallback((function(e,t,i){B({type:c.CreatePairs,payload:{direction:e,children:t,gutters:i}})}),[]),P=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%")}))}),[]),N=n.default.useCallback((function(e,t){if(void 0===R.draggingIdx)throw new Error("Cannot adjust size - 'draggingIdx' is undefined.");var i=R.pairs[R.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===R.draggingIdx,d=R.draggingIdx===R.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)}),[R.draggingIdx,R.pairs,r]),F=n.default.useCallback((function(e,t,i){if(R.isDragging){if(void 0===R.draggingIdx)throw new Error("Cannot drag - 'draggingIdx' is undefined.");var r=R.pairs[R.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)),N(t,n)}}),[R.isDragging,R.draggingIdx,R.pairs,N]);function T(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(R.isDragging){if(void 0===R.draggingIdx)throw new Error("Cannot calculate sizes after dragging = 'state.draggingIdx' is undefined");I(r,R.draggingIdx),k()}}),[R.isDragging,k]),g("mousemove",(function(e){R.isDragging&&F(e,r,r===exports.SplitDirection.Horizontal?o:d)}),[r,R.isDragging,F,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(!E.current||!H.current)throw new Error("Cannot create pairs - 'childRefs' or 'gutterRefs' is undefined.");P(r,E.current,H.current,u),G(r,E.current,H.current)}),[r,P,G,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 T(E,e)}},{children:t}),void 0),i<x.length-1&&e.jsx(z,{ref:function(e){return T(H,e)},className:h,theme:p,draggerClassName:f,direction:r,onMouseDown:function(e){return function(e,t){t.preventDefault(),I(r,e),j(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"})),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)}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@devbookhq/splitter", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Create resizable split views - like in VS Code", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20121
141