@devbookhq/splitter
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -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"})),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)}; | ||
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 g(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 s(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 l,u,c,h,p,f=o.default.div(l||(l=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(u||(u=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,g=t.onMouseDown,s=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:g},{children:[o&&e.jsx("div",{className:o,dir:d},void 0),!o&&e.jsx(s,{},void 0)]}),void 0),!r&&e.jsxs(f,a({ref:i,className:r,dir:d,onMouseDown:g,theme:n},{children:[o&&e.jsx("div",{className:o,dir:d},void 0),!o&&e.jsx(s,{},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===(u=g(r,d)))throw new Error("Cannot create pairs - parent has undefined or zero size: "+u+".");var s=[];return n.forEach((function(e,t){if(t>0){var i=n[t-1],a=n[t],g=o[t-1],l=r===exports.SplitDirection.Horizontal?i.getBoundingClientRect().left:i.getBoundingClientRect().top,u=r===exports.SplitDirection.Horizontal?a.getBoundingClientRect().right:a.getBoundingClientRect().bottom,c=r===exports.SplitDirection.Horizontal?i.getBoundingClientRect().width+g.getBoundingClientRect().width+a.getBoundingClientRect().width:i.getBoundingClientRect().height+g.getBoundingClientRect().height+a.getBoundingClientRect().height,h=r===exports.SplitDirection.Horizontal?g.getBoundingClientRect().width:g.getBoundingClientRect().height,p={idx:t-1,a:i,b:a,gutter:g,parent:d,start:l,end:u,size:c,gutterSize:h,aSizePct:100/n.length,bSizePct:100/n.length};s.push(p)}})),a(a({},e),{pairs:s});case c.StartDragging:var l=t.payload.gutterIdx;return a(a({},e),{isDragging:!0,draggingIdx:l});case c.StopDragging:return a(a({},e),{isDragging:!1});case c.CalculateSizes:var u,h=t.payload,p=h.direction,f=(l=h.gutterIdx,e.pairs[l]);if(!(u=g(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===l,l===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)/u*100,m=(f.b.getBoundingClientRect().width+S)/u*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)/u*100,m=(f.b.getBoundingClientRect().height+S)/u*100,y=f.a.getBoundingClientRect().height+w+S+f.b.getBoundingClientRect().height),e.pairs[l]=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,l=i.minHeights,u=void 0===l?[]:l,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],I=H[1],k=t.useRef([]),G=t.useRef([]);k.current=[],G.current=[];var P=n.default.useCallback((function(e,t){I({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(){I({type:c.StopDragging});for(var e=[],t=0;t<j.pairs.length;t++){var i=j.pairs[t],n=g(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"],s=z(i.gutterSize,o,a),l=s.aGutterSize,u=s.bGutterSize,h=(d+l)/n*100;if(e.push(h),a){var p=(i.b.getBoundingClientRect()[r===exports.SplitDirection.Horizontal?"width":"height"]+u)/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){I({type:c.CalculateSizes,payload:{direction:e,gutterIdx:t}})}),[]),T=n.default.useCallback((function(e,t,i){I({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===g(e,n))throw new Error("Cannot set initial sizes - parent has undefined size.");t.forEach((function(n,o){var a,d=0===o,g=o===t.length-1,s=i[g?o-1:o].getBoundingClientRect()[e===exports.SplitDirection.Horizontal?"width":"height"];s=d||g?s/2:s,a=r&&o<r.length?"calc("+r[o]+"% - "+s+"px)":"calc("+100/t.length+"% - "+s+"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,g=z(i.gutterSize,a,d),s="calc("+n+"% - "+g.aGutterSize+"px)",l="calc("+o+"% - "+g.bGutterSize+"px)";e===exports.SplitDirection.Horizontal?(i.a.style.width=s,i.b.style.width=l):(i.a.style.height=s,i.b.style.height=l)}),[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=16,a=16;i.length>j.draggingIdx&&(o=i[j.draggingIdx]),i.length>=j.draggingIdx+1&&(a=i[j.draggingIdx+1]),n<r.gutterSize+o&&(n=r.gutterSize+o),n>=r.size-(r.gutterSize+a)&&(n=r.size-(r.gutterSize+a)),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 s("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]),s("mousemove",(function(e){j.isDragging&&L(e,r,r===exports.SplitDirection.Horizontal?d:u)}),[r,j.isDragging,L,d,u]),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(!k.current||!G.current)throw new Error("Cannot create pairs - 'childRefs' or 'gutterRefs' is undefined.");A(r,k.current,G.current,h),T(r,k.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(k,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.1.0", | ||
"version": "1.1.1", | ||
"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
20254
142