@column-resizer/core
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -1,8 +0,1 @@ | ||
'use strict'; | ||
var K=Object.defineProperty;var _=(n,t,e)=>t in n?K(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var o=(n,t,e)=>(_(n,typeof t!="symbol"?t+"":t,e),e);var y=(e=>(e.BAR="BAR",e.SECTION="SECTION",e))(y||{}),F=(i=>(i.ACTIVATE="activate",i.MOVE="move",i.DEACTIVATE="deactivate",i))(F||{});function I(){let n=[],t=0,e=0;return {collect(i){n.push(i),i.disableResponsive||(t+=1,e+=i.currentSize);},getResult(){return {sizeInfoArray:n,flexGrowRatio:t/e}}}}function c(n){return Number.isFinite(n)&&n>0}function C(n,t,e){let{collect:i,getResult:r}=I(),s=g(n,t,-1,e),l=g(n,-t,1,e),u=t-s.remainingOffset,a=-t-l.remainingOffset;function d(p,N){p.forEach(i),i(e[n]),N.forEach(i);}if(u===-a)d(s.sizeInfoArray,l.sizeInfoArray);else if(Math.abs(u)<Math.abs(a)){let p=g(n,-u,1,e);d(s.sizeInfoArray,p.sizeInfoArray);}else {let p=g(n,-a,-1,e);d(p.sizeInfoArray,l.sizeInfoArray);}return r()}function g(n,t,e,i){let r=[],s=t;for(let a=n+e;u(a);a+=e)if(s){let{sizeInfo:d,remainingOffset:p}=G(s,i[a]);s=p,l(d);}else l(i[a]);function l(a){e===-1?r.unshift(a):r.push(a);}function u(a){return e===-1?a>=0:a<=i.length-1}return {sizeInfoArray:r,remainingOffset:s}}function G(n,t){if(t.isSolid)return {remainingOffset:n,sizeInfo:t};let{nextSize:e,remainingOffset:i}=P(t.currentSize+n,t);return {sizeInfo:{...t,currentSize:e},remainingOffset:i}}function P(n,{maxSize:t,minSize:e=0}){return n<e?{nextSize:e,remainingOffset:n-e}:c(t)&&n>t?{nextSize:t,remainingOffset:n-t}:{nextSize:n,remainingOffset:0}}var x={x:0,y:0};function L(n,t){return t?{x:n.x-t.x,y:n.y-t.y}:x}var T={barIndex:-1,offset:0,type:"deactivate",originalCoordinate:x,defaultSizeInfoArray:[],sizeInfoArray:[],discard:!0,flexGrowRatio:0};function w(n){let t=T,e=new Set;return {dispatch(i){t=(()=>{let r={barIndex:i.barIndex,type:i.type};switch(i.type){case"activate":let{sizeInfoArray:s,flexGrowRatio:l}=n.getSizeRelatedInfo();return {...T,...r,originalCoordinate:i.coordinate,defaultSizeInfoArray:s,sizeInfoArray:s,flexGrowRatio:l};case"move":let u=n.calculateOffset(i.coordinate,t.originalCoordinate);return {...r,...C(i.barIndex,u,t.defaultSizeInfoArray),offset:u,originalCoordinate:t.originalCoordinate,defaultSizeInfoArray:t.defaultSizeInfoArray,discard:!1};case"deactivate":return T}})(),e.forEach(r=>r(t));},subscribe(i){return e.add(i),()=>e.delete(i)},unsubscribeAll(){e.clear();}}}function f(n,t,e){n==null||n.dispatchEvent(new CustomEvent(t,{detail:e}));}var b=class{constructor(){o(this,"disposeFnSet",new Set);o(this,"watchResizerEvent",(t,e,i)=>{t==null||t.addEventListener(e,i);let r=()=>t==null?void 0:t.removeEventListener(e,i);return this.disposeFnSet.add(r),r});o(this,"reset",()=>{this.disposeFnSet.forEach(t=>t()),this.disposeFnSet.clear();});}};var R=class{constructor(){o(this,"infoMap",new Map);o(this,"items",[]);}update(t){this.infoMap.clear(),this.items.forEach(e=>e.destroy()),this.items=t,t.forEach((e,i)=>{this.infoMap.set(e.elm,{item:e,index:i});});}reset(){this.update([]);}getItems(){return this.items}getItem(t){var e,i;return (i=(e=this.infoMap.get(t))==null?void 0:e.item)!=null?i:null}getItemIndex(t){var e,i;return (i=(e=this.infoMap.get(t))==null?void 0:e.index)!=null?i:null}};var v=!0;try{window.addEventListener("test",null,{get passive(){return v={passive:!1},!0}});}catch(n){}function E({size:n}){return c(n)}function M(n){let{disableResponsive:t}=n;return E(n)&&t===void 0?!0:!!t}function V(n){return !!n&&n in y}function B(n){return t=>({"data-item-type":n,"data-item-config":JSON.stringify(t)})}function D(n){return Array.from(n.childNodes).map(t=>{if(!(t instanceof HTMLElement))return null;let e=t.getAttribute("data-item-type");return V(e)?{type:e,elm:t}:null}).filter(t=>!!t)}function A({elm:n}){var t;try{let e=JSON.parse((t=n.getAttribute("data-item-config"))!=null?t:"");return e&&typeof e=="object"?e:{}}catch(e){return {}}}function k(n){return n*2+1}function O(n){return n*2}var S=class{constructor(t){this.resizeResult=t;o(this,"isDiscarded",!1);}resizeSection(t,e){if(this.isDiscarded)return;let i=O(t),r=this.getSize(i);if(r>=0&&e.toSize>=0){let s=e.toSize-r;i===this.resizeResult.sizeInfoArray.length-1||e.preferMoveLeftBar?this.moveBar(t-1,{withOffset:-s}):this.moveBar(t,{withOffset:s});}}moveBar(t,e){this.isDiscarded||(this.resizeResult=C(k(t),e.withOffset,this.resizeResult.sizeInfoArray));}discard(){this.isDiscarded=!0;}isSectionResized(t){let e=O(t);return "defaultSizeInfoArray"in this.resizeResult?this.getSize(e)!==this.resizeResult.defaultSizeInfoArray[e].currentSize:!1}isBarActivated(t){return "barIndex"in this.resizeResult?this.resizeResult.barIndex===k(t):!1}getSectionSize(t){return this.getSize(O(t))}getResult(){return {...this.resizeResult,discard:this.isDiscarded}}getTotalSize(){return this.resizeResult.sizeInfoArray.filter((t,e)=>t&&e%2===0).reduce((t,{currentSize:e})=>t+e,0)}getSize(t){let e=this.resizeResult.sizeInfoArray[t];return e?e.currentSize:-1}};var z=class{constructor(t,e,i){this.type=t;this.elm=e;this.getConfig=i;o(this,"_config");o(this,"_observer");this._config=this.getConfig(),this._observer=new MutationObserver(()=>this._config=this.getConfig()),this._observer.observe(e,{attributes:!0,attributeFilter:["data-item-config"]});}get config(){return this._config}destroy(){this._observer.disconnect();}};var h=class extends z{constructor(e,i){super("BAR",e.elm,()=>U(e));this.dispatchBarAction=i;o(this,"isActive",!1);o(this,"isValidClick",!0);let r=[this.attachListener(this.elm,"mousedown","activate"),this.attachListener(document,"mousemove","move"),this.attachListener(document,"mouseup","deactivate"),this.attachListener(this.elm,"touchstart","activate",v),this.attachListener(document,"touchmove","move",v),this.attachListener(document,"touchend","deactivate"),this.attachListener(document,"touchcancel","deactivate")];this.destroy=()=>{super.destroy(),r.forEach(s=>s());};}static getStyle({size:e}){return {flex:`0 0 ${e}px`}}attachListener(e,i,r,s){let l=u=>{this.disableUserSelectIfResizing(u,r);let{clientX:a,clientY:d}=("touches"in u?u.touches[0]:u)||{clientX:0,clientY:0};this.triggerAction(this.elm,r,{x:a,y:d});};return e.addEventListener(i,l,s),()=>e.removeEventListener(i,l,s)}disableUserSelectIfResizing(e,i){(this.isActive||i==="activate")&&e.preventDefault();}triggerAction(e,i,r){(this.isActive||i==="activate")&&this.dispatchBarAction(e,{type:i,coordinate:r}),this.isActive&&this.isValidClick&&i==="deactivate"&&(this.isValidClick=!1,f(e,"bar:click",null)),this.updateStatusIfNeed(e,i),this.updateClickStatus(i);}updateStatusIfNeed(e,i){let r=s=>{this.isActive!==s&&(this.isActive=s,f(e,"bar:status-change",{isActive:s}));};i==="activate"?r(!0):i==="deactivate"&&r(!1);}updateClickStatus(e){this.isActive&&(e==="activate"?this.isValidClick=!0:e==="move"&&(this.isValidClick=!1));}};function U(n){let{size:t}=A(n);return {size:c(t)?t:10}}var m=class extends z{constructor(e){super("SECTION",e.elm,()=>$(e));o(this,"sizeInfo",null);o(this,"flexGrowRatio",0);this.updateStyle();}static getStyle({maxSize:e,minSize:i},r){let s=l=>c(l)?`${l}px`:void 0;return {overflow:"hidden",[r?"maxHeight":"maxWidth"]:s(e),[r?"minHeight":"minWidth"]:s(i)}}update({sizeInfo:e,flexGrowRatio:i}){this.sizeInfo=e,this.flexGrowRatio=i,this.updateStyle(),f(this.elm,"section:size-change",{size:e.currentSize});}updateStyle(){let{flexGrow:e,flexShrink:i,flexBasis:r}=this.getStyle();this.elm.style.flexGrow=`${e}`,this.elm.style.flexShrink=`${i}`,this.elm.style.flexBasis=`${r}px`;}getStyle(){let e=c(this.config.size)?0:this.config.disableResponsive?1:0;if(this.sizeInfo){let{disableResponsive:i,currentSize:r}=this.sizeInfo;return {flexShrink:e,flexGrow:i?0:this.flexGrowRatio*r,flexBasis:i?r:0}}else {let i=this.config.size||this.config.defaultSize;return c(i)?{flexShrink:e,flexGrow:0,flexBasis:i}:{flexShrink:e,flexGrow:1,flexBasis:0}}}};function $(n){let{size:t,defaultSize:e,maxSize:i,minSize:r,disableResponsive:s}=A(n);return {size:c(t)?t:void 0,defaultSize:c(e)?e:void 0,maxSize:c(i)?i:void 0,minSize:c(r)?r:void 0,disableResponsive:!!s}}var H=class{constructor(t){this.config=t;o(this,"styles",{container:t=>({...t,display:"flex",flexDirection:this.direction}),section:(t,e)=>({...e,...m.getStyle(t,this.config.vertical)}),bar:(t,e)=>({...e,...h.getStyle(t)})});o(this,"attributes",{bar:B("BAR"),section:B("SECTION")});o(this,"itemsCache",new R);o(this,"eventHub",new b);o(this,"container",null);o(this,"barStore");o(this,"dispatchBarAction",(t,e)=>{let i=this.itemsCache.getItemIndex(t);i&&this.barStore.dispatch({...e,barIndex:i});});this.barStore=w({calculateOffset:(e,i)=>L(e,i)[this.axis],getSizeRelatedInfo:()=>this.makeSizeInfos()});}get axis(){return this.config.vertical?"y":"x"}get dimension(){return this.config.vertical?"height":"width"}get direction(){return this.config.vertical?"column":"row"}get on(){return this.eventHub.watchResizerEvent}init(t){this.dispose(),this.container=t,t&&(this.itemsCache.update(D(t).map(e=>{switch(e.type){case"BAR":return new h(e,this.dispatchBarAction);case"SECTION":return new m(e)}})),this.initStyles(t,this.itemsCache.getItems()),this.sizeRelatedInfoChange(this.makeSizeInfos()),this.barStore.subscribe(e=>{this.monitorBarStatusChanges(e),this.sizeRelatedInfoChange(e);}));}dispose(){this.container=null,this.itemsCache.reset(),this.barStore.unsubscribeAll(),this.eventHub.reset();}getResizer(){return new S(this.makeSizeInfos())}applyResizer(t){this.sizeRelatedInfoChange(t.getResult());}sizeRelatedInfoChange(t){t.discard||(t=(()=>{if(typeof this.config.beforeApplyResizer=="function"){let e=new S(t);return this.config.beforeApplyResizer(e),e.getResult()}else return t})(),!t.discard&&t.sizeInfoArray.forEach(e=>{let i=this.itemsCache.getItem(e.elm);i instanceof m&&i.update({sizeInfo:e,flexGrowRatio:t.flexGrowRatio});}));}monitorBarStatusChanges({type:t}){switch(t){case"activate":return f(this.container,"column:activate",null);case"deactivate":return f(this.container,"column:after-resizing",null);default:return}}makeSizeInfos(){let{collect:t,getResult:e}=I();return this.itemsCache.getItems().forEach(i=>{i instanceof h&&t({elm:i.elm,disableResponsive:!0,isSolid:!0,currentSize:i.elm.getBoundingClientRect()[this.dimension]}),i instanceof m&&t({elm:i.elm,maxSize:i.config.maxSize,minSize:i.config.minSize,disableResponsive:M(i.config),isSolid:E(i.config),currentSize:i.elm.getBoundingClientRect()[this.dimension]});}),e()}initStyles(t,e){Object.assign(t.style,this.styles.container()),e.forEach(i=>{i instanceof h&&Object.assign(i.elm.style,this.styles.bar(i.config)),i instanceof m&&Object.assign(i.elm.style,this.styles.section(i.config));});}}; | ||
exports.BarActionType = F; | ||
exports.ColumnResizer = H; | ||
exports.ItemType = y; | ||
exports.Resizer = S; | ||
"use strict";function e(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function t(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}function i(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||false;n.configurable=true;if("value"in n)n.writable=true;Object.defineProperty(e,n.key,n)}}function n(e,t,n){if(t)i(e.prototype,t);if(n)i(e,n);return e}function r(e,t,i){if(t in e){Object.defineProperty(e,t,{value:i,enumerable:true,configurable:true,writable:true})}else{e[t]=i}return e}function o(e,t,i){if(typeof Reflect!=="undefined"&&Reflect.get){o=Reflect.get}else{o=function e(e,t,i){var n=d(e,t);if(!n)return;var r=Object.getOwnPropertyDescriptor(n,t);if(r.get){return r.get.call(i||e)}return r.value}}return o(e,t,i||e)}function a(e){a=Object.setPrototypeOf?Object.getPrototypeOf:function e(e){return e.__proto__||Object.getPrototypeOf(e)};return a(e)}function s(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});if(t)h(e,t)}function u(e,t){if(t!=null&&typeof Symbol!=="undefined"&&t[Symbol.hasInstance]){return!!t[Symbol.hasInstance](e)}else{return e instanceof t}}function c(e){for(var t=1;t<arguments.length;t++){var i=arguments[t]!=null?arguments[t]:{};var n=Object.keys(i);if(typeof Object.getOwnPropertySymbols==="function"){n=n.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))}n.forEach(function(t){r(e,t,i[t])})}return e}function f(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);if(t){n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})}i.push.apply(i,n)}return i}function l(e,t){t=t!=null?t:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(t))}else{f(Object(t)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(t,i))})}return e}function v(t,i){if(i&&(y(i)==="object"||typeof i==="function")){return i}return e(t)}function h(e,t){h=Object.setPrototypeOf||function e(e,t){e.__proto__=t;return e};return h(e,t)}function d(e,t){while(!Object.prototype.hasOwnProperty.call(e,t)){e=a(e);if(e===null)break}return e}function y(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function p(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}function g(e){var t=p();return function i(){var i=a(e),n;if(t){var r=a(this).constructor;n=Reflect.construct(i,arguments,r)}else{n=i.apply(this,arguments)}return v(this,n)}}var m=Object.defineProperty;var z=function(e,t,i){return t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i};var b=function(e,t,i){return z(e,(typeof t==="undefined"?"undefined":y(t))!="symbol"?t+"":t,i),i};var S=function(e){return e.BAR="BAR",e.SECTION="SECTION",e}(S||{}),I=function(e){return e.ACTIVATE="activate",e.MOVE="move",e.DEACTIVATE="deactivate",e}(I||{});function x(){var e=[],t=0,i=0;return{collect:function n(n){e.push(n),n.disableResponsive||(t+=1,i+=n.currentSize)},getResult:function n(){return{sizeInfoArray:e,flexGrowRatio:t/i}}}}function R(e){return Number.isFinite(e)&&e>0}function O(e,t,i){var n=x(),r=n.collect,o=n.getResult,a=w(e,t,-1,i),s=w(e,-t,1,i),u=t-a.remainingOffset,c=-t-s.remainingOffset;function f(t,n){t.forEach(r),r(i[e]),n.forEach(r)}if(u===-c)f(a.sizeInfoArray,s.sizeInfoArray);else if(Math.abs(u)<Math.abs(c)){var l=w(e,-u,1,i);f(a.sizeInfoArray,l.sizeInfoArray)}else{var v=w(e,-c,-1,i);f(v.sizeInfoArray,s.sizeInfoArray)}return o()}function w(e,t,i,n){var r=[],o=t;for(var a=e+i;l(a);a+=i)if(o){var s=k(o,n[a]),u=s.sizeInfo,c=s.remainingOffset;o=c,f(u)}else f(n[a]);function f(e){i===-1?r.unshift(e):r.push(e)}function l(e){return i===-1?e>=0:e<=n.length-1}return{sizeInfoArray:r,remainingOffset:o}}function k(e,t){if(t.isSolid)return{remainingOffset:e,sizeInfo:t};var i=A(t.currentSize+e,t),n=i.nextSize,r=i.remainingOffset;return{sizeInfo:l(c({},t),{currentSize:n}),remainingOffset:r}}function A(e,t){var i=t.maxSize,n=t.minSize,r=n===void 0?0:n;return e<r?{nextSize:r,remainingOffset:e-r}:R(i)&&e>i?{nextSize:i,remainingOffset:e-i}:{nextSize:e,remainingOffset:0}}var C={x:0,y:0};function E(e,t){return t?{x:e.x-t.x,y:e.y-t.y}:C}var j={barIndex:-1,offset:0,type:"deactivate",originalCoordinate:C,defaultSizeInfoArray:[],sizeInfoArray:[],discard:!0,flexGrowRatio:0};function B(e){var t=j,i=new Set;return{dispatch:function n(n){t=function(){var i={barIndex:n.barIndex,type:n.type};switch(n.type){case"activate":var r=e.getSizeRelatedInfo(),o=r.sizeInfoArray,a=r.flexGrowRatio;return l(c({},j,i),{originalCoordinate:n.coordinate,defaultSizeInfoArray:o,sizeInfoArray:o,flexGrowRatio:a});case"move":var s=e.calculateOffset(n.coordinate,t.originalCoordinate);return l(c({},i,O(n.barIndex,s,t.defaultSizeInfoArray)),{offset:s,originalCoordinate:t.originalCoordinate,defaultSizeInfoArray:t.defaultSizeInfoArray,discard:!1});case"deactivate":return j}}(),i.forEach(function(e){return e(t)})},subscribe:function e(e){return i.add(e),function(){return i.delete(e)}},unsubscribeAll:function e(){i.clear()}}}function P(e,t,i){e===null||e===void 0?void 0:e.dispatchEvent(new CustomEvent(t,{detail:i}))}var _=function e(){var i=this;t(this,e);b(this,"disposeFnSet",new Set);b(this,"watchResizerEvent",function(e,t,n){e===null||e===void 0?void 0:e.addEventListener(t,n);var r=function(){return e===null||e===void 0?void 0:e.removeEventListener(t,n)};return i.disposeFnSet.add(r),r});b(this,"reset",function(){i.disposeFnSet.forEach(function(e){return e()}),i.disposeFnSet.clear()})};var G=/*#__PURE__*/function(){function e(){t(this,e);b(this,"infoMap",new Map);b(this,"items",[])}n(e,[{key:"update",value:function e(e){var t=this;this.infoMap.clear(),this.items.forEach(function(e){return e.destroy()}),this.items=e,e.forEach(function(e,i){t.infoMap.set(e.elm,{item:e,index:i})})}},{key:"reset",value:function e(){this.update([])}},{key:"getItems",value:function e(){return this.items}},{key:"getItem",value:function e(e){var t;var i;return(i=(t=this.infoMap.get(e))===null||t===void 0?void 0:t.item)!==null&&i!==void 0?i:null}},{key:"getItemIndex",value:function e(e){var t;var i;return(i=(t=this.infoMap.get(e))===null||t===void 0?void 0:t.index)!==null&&i!==void 0?i:null}}]);return e}();var L=!0;try{window.addEventListener("test",null,{get passive(){return L={passive:!1},!0}})}catch(e){}function T(e){var t=e.size;return R(t)}function D(e){var t=e.disableResponsive;return T(e)&&t===void 0?!0:!!t}function M(e){return!!e&&e in S}function N(e){return function(t){return{"data-item-type":e,"data-item-config":JSON.stringify(t)}}}function V(e){return Array.from(e.childNodes).map(function(e){if(!u(e,HTMLElement))return null;var t=e.getAttribute("data-item-type");return M(t)?{type:t,elm:e}:null}).filter(function(e){return!!e})}function F(e){var t=e.elm;try{var i;var n=JSON.parse((i=t.getAttribute("data-item-config"))!==null&&i!==void 0?i:"");return n&&typeof n=="object"?n:{}}catch(e){return{}}}function H(e){return e*2+1}function J(e){return e*2}var U=/*#__PURE__*/function(){function e(i){t(this,e);this.resizeResult=i;b(this,"isDiscarded",!1)}n(e,[{key:"resizeSection",value:function e(e,t){if(this.isDiscarded)return;var i=J(e),n=this.getSize(i);if(n>=0&&t.toSize>=0){var r=t.toSize-n;i===this.resizeResult.sizeInfoArray.length-1||t.preferMoveLeftBar?this.moveBar(e-1,{withOffset:-r}):this.moveBar(e,{withOffset:r})}}},{key:"moveBar",value:function e(e,t){this.isDiscarded||(this.resizeResult=O(H(e),t.withOffset,this.resizeResult.sizeInfoArray))}},{key:"discard",value:function e(){this.isDiscarded=!0}},{key:"isSectionResized",value:function e(e){var t=J(e);return"defaultSizeInfoArray"in this.resizeResult?this.getSize(t)!==this.resizeResult.defaultSizeInfoArray[t].currentSize:!1}},{key:"isBarActivated",value:function e(e){return"barIndex"in this.resizeResult?this.resizeResult.barIndex===H(e):!1}},{key:"getSectionSize",value:function e(e){return this.getSize(J(e))}},{key:"getResult",value:function e(){return l(c({},this.resizeResult),{discard:this.isDiscarded})}},{key:"getTotalSize",value:function e(){return this.resizeResult.sizeInfoArray.filter(function(e,t){return e&&t%2===0}).reduce(function(e,t){var i=t.currentSize;return e+i},0)}},{key:"getSize",value:function e(e){var t=this.resizeResult.sizeInfoArray[e];return t?t.currentSize:-1}}]);return e}();var W=/*#__PURE__*/function(){function e(i,n,r){var o=this;t(this,e);this.type=i;this.elm=n;this.getConfig=r;b(this,"_config");b(this,"_observer");this._config=this.getConfig(),this._observer=new MutationObserver(function(){return o._config=o.getConfig()}),this._observer.observe(n,{attributes:!0,attributeFilter:["data-item-config"]})}n(e,[{key:"config",get:function e(){return this._config}},{key:"destroy",value:function e(){this._observer.disconnect()}}]);return e}();var X=/*#__PURE__*/function(i){s(u,i);var r=g(u);function u(i,n){t(this,u);var s;s=r.call(this,"BAR",i.elm,function(){return Y(i)});s.dispatchBarAction=n;b(e(s),"isActive",!1);b(e(s),"isValidClick",!0);var c=[s.attachListener(s.elm,"mousedown","activate"),s.attachListener(document,"mousemove","move"),s.attachListener(document,"mouseup","deactivate"),s.attachListener(s.elm,"touchstart","activate",L),s.attachListener(document,"touchmove","move",L),s.attachListener(document,"touchend","deactivate"),s.attachListener(document,"touchcancel","deactivate")];s.destroy=function(){o((e(s),a(u.prototype)),"destroy",s).call(s),c.forEach(function(e){return e()})};return s}n(u,[{key:"attachListener",value:function e(e,t,i,n){var r=this;var o=function(e){r.disableUserSelectIfResizing(e,i);var t=("touches"in e?e.touches[0]:e)||{clientX:0,clientY:0},n=t.clientX,o=t.clientY;r.triggerAction(r.elm,i,{x:n,y:o})};return e.addEventListener(t,o,n),function(){return e.removeEventListener(t,o,n)}}},{key:"disableUserSelectIfResizing",value:function e(e,t){(this.isActive||t==="activate")&&e.preventDefault()}},{key:"triggerAction",value:function e(e,t,i){(this.isActive||t==="activate")&&this.dispatchBarAction(e,{type:t,coordinate:i}),this.isActive&&this.isValidClick&&t==="deactivate"&&(this.isValidClick=!1,P(e,"bar:click",null)),this.updateStatusIfNeed(e,t),this.updateClickStatus(t)}},{key:"updateStatusIfNeed",value:function e(e,t){var i=this;var n=function(t){i.isActive!==t&&(i.isActive=t,P(e,"bar:status-change",{isActive:t}))};t==="activate"?n(!0):t==="deactivate"&&n(!1)}},{key:"updateClickStatus",value:function e(e){this.isActive&&(e==="activate"?this.isValidClick=!0:e==="move"&&(this.isValidClick=!1))}}],[{key:"getStyle",value:function e(e){var t=e.size;return{flex:"0 0 ".concat(t,"px")}}}]);return u}(W);function Y(e){var t=F(e),i=t.size;return{size:R(i)?i:10}}var q=/*#__PURE__*/function(i){s(a,i);var o=g(a);function a(i){t(this,a);var n;n=o.call(this,"SECTION",i.elm,function(){return K(i)});b(e(n),"sizeInfo",null);b(e(n),"flexGrowRatio",0);n.updateStyle();return n}n(a,[{key:"update",value:function e(e){var t=e.sizeInfo,i=e.flexGrowRatio;this.sizeInfo=t,this.flexGrowRatio=i,this.updateStyle(),P(this.elm,"section:size-change",{size:t.currentSize})}},{key:"updateStyle",value:function e(){var e=this.getStyle(),t=e.flexGrow,i=e.flexShrink,n=e.flexBasis;this.elm.style.flexGrow="".concat(t),this.elm.style.flexShrink="".concat(i),this.elm.style.flexBasis="".concat(n,"px")}},{key:"getStyle",value:function e(){var e=R(this.config.size)?0:this.config.disableResponsive?1:0;if(this.sizeInfo){var t=this.sizeInfo,i=t.disableResponsive,n=t.currentSize;return{flexShrink:e,flexGrow:i?0:this.flexGrowRatio*n,flexBasis:i?n:0}}else{var r=this.config.size||this.config.defaultSize;return R(r)?{flexShrink:e,flexGrow:0,flexBasis:r}:{flexShrink:e,flexGrow:1,flexBasis:0}}}}],[{key:"getStyle",value:function e(e,t){var i=e.maxSize,n=e.minSize;var o=function(e){return R(e)?"".concat(e,"px"):void 0};var a;return a={overflow:"hidden"},r(a,t?"maxHeight":"maxWidth",o(i)),r(a,t?"minHeight":"minWidth",o(n)),a}}]);return a}(W);function K(e){var t=F(e),i=t.size,n=t.defaultSize,r=t.maxSize,o=t.minSize,a=t.disableResponsive;return{size:R(i)?i:void 0,defaultSize:R(n)?n:void 0,maxSize:R(r)?r:void 0,minSize:R(o)?o:void 0,disableResponsive:!!a}}var Q=/*#__PURE__*/function(){function e(i){var n=this;t(this,e);this.config=i;b(this,"styles",{container:function(e){return l(c({},e),{display:"flex",flexDirection:n.direction})},section:function(e,t){return c({},t,q.getStyle(e,n.config.vertical))},bar:function(e,t){return c({},t,X.getStyle(e))}});b(this,"attributes",{bar:N("BAR"),section:N("SECTION")});b(this,"itemsCache",new G);b(this,"eventHub",new _);b(this,"container",null);b(this,"barStore");b(this,"dispatchBarAction",function(e,t){var i=n.itemsCache.getItemIndex(e);i&&n.barStore.dispatch(l(c({},t),{barIndex:i}))});this.barStore=B({calculateOffset:function(e,t){return E(e,t)[n.axis]},getSizeRelatedInfo:function(){return n.makeSizeInfos()}})}n(e,[{key:"axis",get:function e(){return this.config.vertical?"y":"x"}},{key:"dimension",get:function e(){return this.config.vertical?"height":"width"}},{key:"direction",get:function e(){return this.config.vertical?"column":"row"}},{key:"on",get:function e(){return this.eventHub.watchResizerEvent}},{key:"init",value:function e(e){var t=this;this.dispose(),this.container=e,e&&(this.itemsCache.update(V(e).map(function(e){switch(e.type){case"BAR":return new X(e,t.dispatchBarAction);case"SECTION":return new q(e)}})),this.initStyles(e,this.itemsCache.getItems()),this.sizeRelatedInfoChange(this.makeSizeInfos()),this.barStore.subscribe(function(e){t.monitorBarStatusChanges(e),t.sizeRelatedInfoChange(e)}))}},{key:"dispose",value:function e(){this.container=null,this.itemsCache.reset(),this.barStore.unsubscribeAll(),this.eventHub.reset()}},{key:"getResizer",value:function e(){return new U(this.makeSizeInfos())}},{key:"applyResizer",value:function e(e){this.sizeRelatedInfoChange(e.getResult())}},{key:"sizeRelatedInfoChange",value:function e(e){var t=this;e.discard||(e=function(){if(typeof t.config.beforeApplyResizer=="function"){var i=new U(e);return t.config.beforeApplyResizer(i),i.getResult()}else return e}(),!e.discard&&e.sizeInfoArray.forEach(function(i){var n=t.itemsCache.getItem(i.elm);u(n,q)&&n.update({sizeInfo:i,flexGrowRatio:e.flexGrowRatio})}))}},{key:"monitorBarStatusChanges",value:function e(e){var t=e.type;switch(t){case"activate":return P(this.container,"column:activate",null);case"deactivate":return P(this.container,"column:after-resizing",null);default:return}}},{key:"makeSizeInfos",value:function e(){var e=this;var t=x(),i=t.collect,n=t.getResult;return this.itemsCache.getItems().forEach(function(t){u(t,X)&&i({elm:t.elm,disableResponsive:!0,isSolid:!0,currentSize:t.elm.getBoundingClientRect()[e.dimension]}),u(t,q)&&i({elm:t.elm,maxSize:t.config.maxSize,minSize:t.config.minSize,disableResponsive:D(t.config),isSolid:T(t.config),currentSize:t.elm.getBoundingClientRect()[e.dimension]})}),n()}},{key:"initStyles",value:function e(e,t){var i=this;Object.assign(e.style,this.styles.container()),t.forEach(function(e){u(e,X)&&Object.assign(e.elm.style,i.styles.bar(e.config)),u(e,q)&&Object.assign(e.elm.style,i.styles.section(e.config))})}}]);return e}();exports.BarActionType=I;exports.ColumnResizer=Q;exports.ItemType=S;exports.Resizer=U; |
{ | ||
"name": "@column-resizer/core", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "github:Runjuu/column-resizer", |
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
48135
215