Current section

Files

Jump to
live_pane priv static live_pane.min.js
Raw

priv/static/live_pane.min.js

"use strict";var LiveMotion=(()=>{var R=Object.defineProperty,le=Object.defineProperties,ue=Object.getOwnPropertyDescriptor,ce=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertyNames,U=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var j=(t,e,n)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,K=(t,e)=>{for(var n in e||(e={}))q.call(e,n)&&j(t,n,e[n]);if(U)for(var n of U(e))pe.call(e,n)&&j(t,n,e[n]);return t},_=(t,e)=>le(t,ce(e));var fe=(t,e)=>{for(var n in e)R(t,n,{get:e[n],enumerable:!0})},me=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of de(e))!q.call(t,r)&&r!==n&&R(t,r,{get:()=>e[r],enumerable:!(s=ue(e,r))||s.enumerable});return t};var be=t=>me(R({},"__esModule",{value:!0}),t);var Re={};fe(Re,{createLivePaneHooks:()=>Ae});function m(t,e="Assertion failed!"){if(!t)throw console.error(e),Error(e)}function V(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function W(t){return t.type.startsWith("mouse")}function B(t){return t.type.startsWith("touch")}function $(t){return t.type==="keydown"}function x(t){let e=new Set;function n(i){if(V(t,i)){t=i;for(let a of e)a(i)}}function s(){return t}function r(i){n(i(t))}function o(i){return e.add(i),i(t),()=>{e.delete(i)}}return{set:n,get:s,update:r,subscribe:o}}var k=10,v=new Map,L=new Map,C=new Map,y=x(null);function z(t,e,n=k){return S(t,e,n)===0}function S(t,e,n=k){let s=X(t,n),r=X(e,n);return Math.sign(s-r)}function D(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function X(t,e){return parseFloat(t.toFixed(e))}function P({paneConstraintsArray:t,paneIndex:e,size:n}){m(t[e]!=null,"Pane constraints should not be null.");let{collapsedSize:s,collapsible:r,maxSize:o,minSize:i}=t[e],a=n;return S(a,i)<0&&(a=ge(a,r,s,i)),a=Math.min(o,a),parseFloat(a.toFixed(k))}function ge(t,e,n,s){if(!e)return s;let r=(n+s)/2;return S(t,r)<0?n:s}function Y(){return{mounted(){if(!this.el.id)throw Error("Pane Group must have an id.");if(v.has(this.el.id))throw Error(`Pane Group with id "${this.el.id}" already exists.`);let e=this.el.getAttribute("data-pane-direction")||"horizontal",n=this.el.getAttribute("keyboard-resize-by"),s=n?Number(n):null,r=x([]),o=x(!1),i=x(e),a=x([]),l=x(0),d="",c={},u=new Map,f=ye(a,r,o),p={paneDataArray:r,paneDataArrayChanged:o,direction:i,dragHandleId:d,layout:a,prevDelta:l,keyboardResizeBy:s,paneIdToLastNotifiedSizeMap:c,paneSizeBeforeCollapseMap:u,unsubFromPaneDataChange:f};v.set(this.el.id,p)},destroyed(){var e;(e=v.get(this.el.id))==null||e.unsubFromPaneDataChange(),v.delete(this.el.id)}}}function ye(t,e,n){return n.subscribe(s=>{if(!s)return;n.set(!1);let r=t.get(),o=e.get(),i=null;i==null&&(i=he({paneDataArray:o}));let a=ze({layout:i,paneConstraintsArray:o.map(l=>l.constraints)});D(r,a)||t.set(a)})}function he({paneDataArray:t}){let e=Array(t.length),n=t.map(o=>o.constraints),s=0,r=100;for(let o=0;o<t.length;o++){let i=n[o];m(i);let{defaultSize:a}=i;a!=null&&(s++,e[o]=a,r-=a)}for(let o=0;o<t.length;o++){let i=n[o];m(i);let{defaultSize:a}=i;if(a!=null)continue;let l=t.length-s,d=r/l;s++,e[o]=d,r-=d}return e}function ze({layout:t,paneConstraintsArray:e}){let n=[...t],s=n.reduce((o,i)=>o+i,0);if(n.length!==e.length)throw Error(`Invalid ${e.length} pane layout: ${n.map(o=>`${o}%`).join(", ")}`);if(!z(s,100))for(let o=0;o<e.length;o++){let i=n[o];m(i!=null);let a=100/s*i;n[o]=a}let r=0;for(let o=0;o<e.length;o++){let i=n[o];m(i!=null);let a=P({paneConstraintsArray:e,paneIndex:o,size:i});i!=a&&(r+=i-a,n[o]=a)}if(!z(r,0))for(let o=0;o<e.length;o++){let i=n[o];m(i!=null);let a=i+r,l=P({paneConstraintsArray:e,paneIndex:o,size:a});if(i!==l&&(r-=l-i,n[o]=l,z(r,0)))break}return n}function N(t){return Object.keys(t).reduce((e,n)=>t[n]===void 0?e:e+`${n}:${t[n]};`,"")}var F=null,H=null;function O(t){switch(t){case"horizontal":return"ew-resize";case"horizontal-max":return"w-resize";case"horizontal-min":return"e-resize";case"vertical":return"ns-resize";case"vertical-max":return"n-resize";case"vertical-min":return"s-resize"}}function w(){H!==null&&(document.head.removeChild(H),F=null,H=null)}function M(t){if(F===t)return;F=t;let e=O(t);H===null&&(H=document.createElement("style"),document.head.appendChild(H)),H.innerHTML=`*{cursor: ${e}!important;}`}function J({defaultSize:t,dragState:e,layout:n,paneData:s,paneIndex:r,precision:o=3}){let i=n[r],a;return i==null?a=t!=null?t:"1":s.length===1?a="1":a=i.toPrecision(o),N({"flex-basis":0,"flex-grow":a,"flex-shrink":1,overflow:"hidden","pointer-events":e!==null?"none":void 0})}function T({delta:t,layout:e,paneConstraintsArray:n,pivotIndices:s,trigger:r}){if(z(t,0))return e;let o=[...e],[i,a]=s;m(i!=null,"Invalid first pivot index"),m(a!=null,"Invalid second pivot index");let l=0;if(r==="keyboard"){{let c=t<0?a:i,u=n[c];if(m(u),u.collapsible){let f=e[c];m(f!=null);let p=n[c];m(p);let{collapsedSize:b=0,minSize:h=0}=p;if(z(f,b)){let g=h-f;S(g,Math.abs(t))>0&&(t=t<0?0-g:g)}}}{let c=t<0?i:a,u=n[c];m(u);let{collapsible:f}=u;if(f){let p=e[c];m(p!=null);let b=n[c];m(b);let{collapsedSize:h=0,minSize:g=0}=b;if(z(p,g)){let E=p-h;S(E,Math.abs(t))>0&&(t=t<0?0-E:E)}}}}{let c=t<0?1:-1,u=t<0?a:i,f=0;for(;;){let b=e[u];m(b!=null);let g=P({paneConstraintsArray:n,paneIndex:u,size:100})-b;if(f+=g,u+=c,u<0||u>=n.length)break}let p=Math.min(Math.abs(t),Math.abs(f));t=t<0?0-p:p}{let u=t<0?i:a;for(;u>=0&&u<n.length;){let f=Math.abs(t)-Math.abs(l),p=e[u];m(p!=null);let b=p-f,h=P({paneConstraintsArray:n,paneIndex:u,size:b});if(!z(p,h)&&(l+=p-h,o[u]=h,l.toPrecision(3).localeCompare(Math.abs(t).toPrecision(3),void 0,{numeric:!0})>=0))break;t<0?u--:u++}}if(z(l,0))return e;{let c=t<0?a:i,u=e[c];m(u!=null);let f=u+l,p=P({paneConstraintsArray:n,paneIndex:c,size:f});if(o[c]=p,!z(p,f)){let b=f-p,g=t<0?a:i;for(;g>=0&&g<n.length;){let E=o[g];m(E!=null);let ae=E+b,G=P({paneConstraintsArray:n,paneIndex:g,size:ae});if(z(E,G)||(b-=G-E,o[g]=G),z(b,0))break;t>0?g--:g++}}}let d=o.reduce((c,u)=>u+c,0);return z(d,100)?o:e}function Q(){return{mounted(){let e=this.el.getAttribute("data-pane-group-id");if(!e)throw Error("data-pane-group-id must exist for pane components!");let n=this.el.id;if(!n)throw Error("Id must exist for pane components!");let s=this.el.getAttribute("data-pane-order"),r=s?Number(s):0,o=v.get(e);if(!o)throw Error('Group with id "'+e+'" does not exist.');let i=Number(this.el.getAttribute("collapsed-size"))||0,a=this.el.getAttribute("collapsible")==="true",l=Number(this.el.getAttribute("default-size"))||void 0,d=Number(this.el.getAttribute("max-size"))||100,c=Number(this.el.getAttribute("min-size"))||0,u={id:this.el.id,order:r,constraints:{collapsedSize:i,collapsible:a,defaultSize:l,maxSize:d,minSize:c}};xe(u,o.paneDataArray,o.paneDataArrayChanged);let f=Ee(this.el,o,u,l);L.set(n,{groupId:e,unsubs:f}),this.handleEvent("collapse",({pane_id:p})=>{n===p&&Pe(u,o)}),this.handleEvent("expand",({pane_id:p})=>{n===p&&Se(u,o)})},destroyed(){let{groupId:e,unsubs:n}=L.get(this.el.id);for(let r of n)r();let s=v.get(e);ve(this.el.id,s.paneDataArray,s.paneDataArrayChanged),L.delete(this.el.id)}}}function xe(t,e,n){e.update(s=>{let r=[...s,t];return r.sort((o,i)=>{let a=o.order,l=i.order;return a==null&&l==null?0:a==null?-1:l==null?1:a-l}),r}),n.set(!0)}function ve(t,e,n){let s=e.get(),r=A(s,t);r<0||e.update(o=>(o.splice(r,1),n.set(!0),o))}function A(t,e){return t.findIndex(n=>n.id===e)}function Ee(t,e,n,s){let r=()=>{let l=A(e.paneDataArray.get(),n.id);return J({defaultSize:s,dragState:y.get(),layout:e.layout.get(),paneData:e.paneDataArray.get(),paneIndex:l})},o=e.paneDataArray.subscribe(l=>t.style.cssText=r()),i=e.layout.subscribe(l=>{t.style.cssText=r()}),a=y.subscribe(l=>t.style.cssText=r());return[o,i,a]}function Pe(t,e){let n=e.layout.get(),s=e.paneDataArray.get();if(!t.constraints.collapsible)return;let r=s.map(f=>f.constraints),{collapsedSize:o=0,paneSize:i,pivotIndices:a}=Z(s,t,n);if(m(i!=null),i===o)return;e.paneSizeBeforeCollapseMap.set(t.id,i);let d=A(s,t.id)===s.length-1?i-o:o-i,c=T({delta:d,layout:n,paneConstraintsArray:r,pivotIndices:a,trigger:"imperative-api"});if(D(n,c))return;e.layout.set(c);let u=e.onLayoutChange;u&&u(c)}function Se(t,e){var b;let n=e.layout.get(),s=e.paneDataArray.get();if(!t.constraints.collapsible)return;let r=s.map(h=>h.constraints),{collapsedSize:o=0,paneSize:i,minSize:a=0,pivotIndices:l}=Z(s,t,n);if(i!==o)return;let d=e.paneSizeBeforeCollapseMap.get(t.id),c=d!=null&&d>=a?d:a,f=A(s,t.id)===s.length-1?i-c:c-i,p=T({delta:f,layout:n,paneConstraintsArray:r,pivotIndices:l,trigger:"imperative-api"});D(n,p)||(e.layout.set(p),(b=e.onLayoutChange)==null||b.call(e,p))}function Z(t,e,n){let s=t.map(d=>d.constraints),r=A(t,e.id),o=s[r],a=r===t.length-1?[r-1,r]:[r,r+1],l=n[r];return _(K({},o),{paneSize:l,pivotIndices:a})}function ee(...t){return(...e)=>{for(let n of t)typeof n=="function"&&n(...e)}}function I(t,e,n,s){let r=Array.isArray(e)?e:[e];return r.forEach(o=>t.addEventListener(o,n,s)),()=>{r.forEach(o=>t.removeEventListener(o,n,s))}}function ne(){return{mounted(){let e=this.el.getAttribute("data-pane-group-id");if(!e)throw Error("data-pane-group-id must exist for resizer components!");let n=this.el.getAttribute("id");if(!n)throw Error("Resizer id must exist for resizer components!");let s=v.get(e);if(!s)throw Error(`Missing group "${e} for resizer "${n}`);let r={disabled:x(!1),isDragging:x(!1),resizeHandlerCallback:null,unsubs:[],isFocused:x(!1)};if(C.set(n,r),r.disabled.set(this.el.getAttribute("data-pane-disabled")==="true"),!r.disabled.get()){let a=s.keyboardResizeBy;r.resizeHandlerCallback=l=>{var u,f,p,b;let d=(f=(u=y.get())==null?void 0:u.initialCursorPosition)!=null?f:null,c=(b=(p=y.get())==null?void 0:p.initialLayout)!=null?b:null;He(e,n,s,c,d,a,l)}}let o=De(n,this.el,r);r.unsubs.push(o);let i=N({cursor:O(s.direction.get()),"touch-action":"none","user-select":"none","-webkit-user-select":"none","-webkit-touch-callout":"none"});this.el.style.cssText=i,this.el.onblur=()=>r.isFocused.set(!1),this.el.onfocus=()=>r.isFocused.set(!0),this.el.onmousedown=a=>{var d;a.preventDefault();let l=te(s.direction,s.layout,n,a);y.set(l),r.isDragging.set(((d=y.get())==null?void 0:d.dragHandleId)===n)},this.el.onmouseup=()=>{y.set(null),w(),r.isDragging.set(!1)},this.el.ontouchcancel=()=>{y.set(null),w(),r.isDragging.set(!1)},this.el.ontouchend=()=>{y.set(null),w(),r.isDragging.set(!1)},this.el.ontouchstart=a=>{var d;a.preventDefault();let l=te(s.direction,s.layout,n,a);y.set(l),r.isDragging.set(((d=y.get())==null?void 0:d.dragHandleId)===n)},this.el.onkeydown=a=>{Te(e,n,r.disabled.get(),r.resizeHandlerCallback,a)}},destroyed(){var n,s;let e=this.el.getAttribute("id");for(let r of(s=(n=C.get(e))==null?void 0:n.unsubs)!=null?s:[])r();C.delete(e)}}}function De(t,e,n){let{disabled:s,resizeHandlerCallback:r,isDragging:o}=n,i=d=>{var c;t!==((c=y.get())==null?void 0:c.dragHandleId)||s.get()||!o.get()||r===null||r(d)},a=d=>{var c;t!==((c=y.get())==null?void 0:c.dragHandleId)||s.get()||!o.get()||r===null||r(d)},l=()=>{var d;t===((d=y.get())==null?void 0:d.dragHandleId)&&(e.blur(),o.set(!1),y.set(null),w())};return ee(I(document.body,"contextmenu",l),I(document.body,"mousemove",i),I(document.body,"mouseleave",a),I(window,"mouseup",l),I(document.body,"touchmove",i,{passive:!1}),I(window,"touchend",l))}function He(t,e,n,s,r,o,i){i.preventDefault();let a=n.direction.get(),l=n.layout.get(),d=n.paneDataArray.get(),c=Ie(t,e),u=ke(i,e,a,r,o);if(u===0)return;let f=a==="horizontal";document.dir==="rtl"&&f&&(u=-u);let p=d.map(g=>g.constraints),b=T({delta:u,layout:s!=null?s:l,paneConstraintsArray:p,pivotIndices:c,trigger:$(i)?"keyboard":"mouse-or-touch"}),h=!D(l,b);(W(i)||B(i))&&n.prevDelta.get()!=u&&(n.prevDelta.set(u),h?M(f?"horizontal":"vertical"):f?M(u<0?"horizontal-min":"horizontal-max"):M(u<0?"vertical-min":"vertical-max")),h&&n.layout.set(b)}function te(t,e,n,s){let r=se(n);return m(r),{dragHandleId:n,dragHandleRect:r.getBoundingClientRect(),initialCursorPosition:re(t.get(),s),initialLayout:e.get()}}function Ie(t,e){let n=ie(t,e);return n!=null?[n,n+1]:[-1,-1]}function ke(t,e,n,s,r){if($(t)){let o=n==="horizontal",i=0;t.shiftKey?i=100:r!=null||(i=5);let a=0;switch(t.key){case"ArrowDown":a=o?0:i;break;case"ArrowLeft":a=o?-i:0;break;case"ArrowRight":a=o?i:0;break;case"ArrowUp":a=o?0:-i;break;case"End":a=100;break;case"Home":a=-100;break}return a}else{if(s==null)return 0;let o=n==="horizontal",i=se(e);m(i);let a=i.getAttribute("data-pane-group-id");m(a);let l=re(n,t),d=we(a);m(d);let c=d.getBoundingClientRect(),u=o?c.width:c.height;return(l-s)/u*100}}function re(t,e){var s;let n=t==="horizontal";if(W(e))return n?e.clientX:e.clientY;if(B(e)){let r=e.touches[0];return m(r),n?r.screenX:r.screenY}else throw Error(`Unsupported event type "${(s=e.type)!=null?s:"unknown"}"`)}function oe(t){return Array.from(document.querySelectorAll(`[data-pane-resizer-id][data-pane-group-id="${t}"]`))}function ie(t,e){let s=oe(t).findIndex(r=>r.getAttribute("data-pane-resizer-id")===e);return s!=null?s:null}function se(t){let e=document.querySelector(`[data-pane-resizer][data-pane-resizer-id="${t}"]`);return e||null}function we(t){let e=document.querySelector(`[data-pane-group][data-pane-group-id="${t}"]`);return e||null}function Te(t,e,n,s,r){if(n||!s||r.defaultPrevented)return;if(["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","End","Home"].includes(r.key)){r.preventDefault(),s(r);return}if(r.key!=="F6")return;r.preventDefault();let i=oe(t),a=ie(t,e);if(a===null)return;let l=r.shiftKey?a>0?a-1:i.length-1:a+1<i.length?a+1:0;i[l].focus()}function Ae(){let t=Y(),e=Q(),n=ne();return{groupHook:t,paneHook:e,resizerHook:n}}return be(Re);})();