@stonecrop/atable 0.2.40 → 0.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- (function(w,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(w=typeof globalThis<"u"?globalThis:w||self,n(w["@stonecrop/atable"]={},w.Vue))})(this,function(w,n){"use strict";var Ze=Object.defineProperty;var Ke=(w,n,I)=>n in w?Ze(w,n,{enumerable:!0,configurable:!0,writable:!0,value:I}):w[n]=I;var C=(w,n,I)=>Ke(w,typeof n!="symbol"?n+"":n,I);function I(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function P(e){return typeof e=="function"?e():n.unref(e)}const me=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const pe=e=>e!=null,he=Object.prototype.toString,we=e=>he.call(e)==="[object Object]",ge=()=>{},S=me?window:void 0;function A(e){var t;const o=P(e);return(t=o==null?void 0:o.$el)!=null?t:o}function D(...e){let t,o,l,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,l,a]=e,t=S):[t,o,l,a]=e,!t)return ge;Array.isArray(o)||(o=[o]),Array.isArray(l)||(l=[l]);const r=[],i=()=>{r.forEach(u=>u()),r.length=0},s=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),d=n.watch(()=>[A(t),P(a)],([u,p])=>{if(i(),!u)return;const c=we(p)?{...p}:p;r.push(...o.flatMap(m=>l.map(g=>s(u,m,g,c))))},{immediate:!0,flush:"post"}),f=()=>{d(),i()};return I(f),f}function ye(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function be(e){const t=ye();return n.computed(()=>(t.value,!!e()))}function ke(e,t,o={}){const{window:l=S,...a}=o;let r;const i=be(()=>l&&"MutationObserver"in l),s=()=>{r&&(r.disconnect(),r=void 0)},d=n.computed(()=>{const c=P(e),m=(Array.isArray(c)?c:[c]).map(A).filter(pe);return new Set(m)}),f=n.watch(()=>d.value,c=>{s(),i.value&&c.size&&(r=new MutationObserver(t),c.forEach(m=>r.observe(m,a)))},{immediate:!0,flush:"post"}),u=()=>r==null?void 0:r.takeRecords(),p=()=>{f(),s()};return I(p),{isSupported:i,stop:p,takeRecords:u}}function Ee(e={}){var t;const{window:o=S,deep:l=!0,triggerOnRemoval:a=!1}=e,r=(t=e.document)!=null?t:o==null?void 0:o.document,i=()=>{var f;let u=r==null?void 0:r.activeElement;if(l)for(;u!=null&&u.shadowRoot;)u=(f=u==null?void 0:u.shadowRoot)==null?void 0:f.activeElement;return u},s=n.ref(),d=()=>{s.value=i()};return o&&(D(o,"blur",f=>{f.relatedTarget===null&&d()},!0),D(o,"focus",d,!0)),a&&ke(r,f=>{f.filter(u=>u.removedNodes.length).map(u=>Array.from(u.removedNodes)).flat().forEach(u=>{u===s.value&&d()})},{childList:!0,subtree:!0}),d(),s}const xe="focusin",Ce="focusout";function Ie(e,t={}){const{window:o=S}=t,l=n.computed(()=>A(e)),a=n.ref(!1),r=n.computed(()=>a.value),i=Ee(t);return!o||!i.value?{focused:r}:(D(l,xe,()=>a.value=!0),D(l,Ce,()=>a.value=!1),{focused:r})}function Se(e,{window:t=S,scrollTarget:o}={}){const l=n.ref(!1),a=()=>{if(!t)return;const r=t.document,i=A(e);if(!i)l.value=!1;else{const s=i.getBoundingClientRect();l.value=s.top<=(t.innerHeight||r.documentElement.clientHeight)&&s.left<=(t.innerWidth||r.documentElement.clientWidth)&&s.bottom>=0&&s.right>=0}};return n.watch(()=>A(e),()=>a(),{immediate:!0,flush:"post"}),t&&D(o||t,"scroll",a,{capture:!1,passive:!0}),l}const E=e=>{let t=Se(e).value;return t=t&&e.offsetHeight>0,t},x=e=>e.tabIndex>=0,Q=e=>{const t=e.target;return v(t)},v=e=>{var t;let o;if(e instanceof HTMLTableCellElement){const l=(t=e.parentElement)==null?void 0:t.previousElementSibling;if(l){const a=Array.from(l.children)[e.cellIndex];a&&(o=a)}}else if(e instanceof HTMLTableRowElement){const l=e.previousElementSibling;l&&(o=l)}return o&&(!x(o)||!E(o))?v(o):o},Ae=e=>{var t;const o=e.target;let l;if(o instanceof HTMLTableCellElement){const a=(t=o.parentElement)==null?void 0:t.parentElement;if(a){const r=a.firstElementChild.children[o.cellIndex];r&&(l=r)}}else if(o instanceof HTMLTableRowElement){const a=o.parentElement;if(a){const r=a.firstElementChild;r&&(l=r)}}return l&&(!x(l)||!E(l))?N(l):l},Z=e=>{const t=e.target;return N(t)},N=e=>{var t;let o;if(e instanceof HTMLTableCellElement){const l=(t=e.parentElement)==null?void 0:t.nextElementSibling;if(l){const a=Array.from(l.children)[e.cellIndex];a&&(o=a)}}else if(e instanceof HTMLTableRowElement){const l=e.nextElementSibling;l&&(o=l)}return o&&(!x(o)||!E(o))?N(o):o},De=e=>{var t;const o=e.target;let l;if(o instanceof HTMLTableCellElement){const a=(t=o.parentElement)==null?void 0:t.parentElement;if(a){const r=a.lastElementChild.children[o.cellIndex];r&&(l=r)}}else if(o instanceof HTMLTableRowElement){const a=o.parentElement;if(a){const r=a.lastElementChild;r&&(l=r)}}return l&&(!x(l)||!E(l))?v(l):l},K=e=>{const t=e.target;return j(t)},j=e=>{var t;let o;if(e.previousElementSibling)o=e.previousElementSibling;else{const l=(t=e.parentElement)==null?void 0:t.previousElementSibling;o=l==null?void 0:l.lastElementChild}return o&&(!x(o)||!E(o))?j(o):o},_=e=>{const t=e.target;return W(t)},W=e=>{var t;let o;if(e.nextElementSibling)o=e.nextElementSibling;else{const l=(t=e.parentElement)==null?void 0:t.nextElementSibling;o=l==null?void 0:l.firstElementChild}return o&&(!x(o)||!E(o))?W(o):o},ee=e=>{const t=e.target.parentElement.firstElementChild;return t&&(!x(t)||!E(t))?W(t):t},te=e=>{const t=e.target.parentElement.lastElementChild;return t&&(!x(t)||!E(t))?j(t):t},$=["alt","control","shift","meta"],Te={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},H={"keydown.up":e=>{const t=Q(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.down":e=>{const t=Z(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.left":e=>{const t=K(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.right":e=>{const t=_(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.control.up":e=>{const t=Ae(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.down":e=>{const t=De(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.left":e=>{const t=ee(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.right":e=>{const t=te(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.end":e=>{const t=te(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=Z(e);t&&t.focus()}},"keydown.shift.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=Q(e);t&&t.focus()}},"keydown.home":e=>{const t=ee(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.tab":e=>{const t=_(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.shift.tab":e=>{const t=K(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())}};function V(e){const t=i=>{let s=null;return i.parent&&(typeof i.parent=="string"?s=document.querySelector(i.parent):i.parent instanceof HTMLElement?s=i.parent:s=i.parent.value),s},o=i=>{const s=t(i);let d=[];if(typeof i.selectors=="string")d=s?Array.from(s.querySelectorAll(i.selectors)):Array.from(document.querySelectorAll(i.selectors));else if(Array.isArray(i.selectors))for(const f of i.selectors)f instanceof HTMLElement?d.push(f):d.push(f.$el);else if(i.selectors instanceof HTMLElement)d.push(i.selectors);else if(Array.isArray(i.selectors.value))for(const f of i.selectors.value)f instanceof HTMLElement?d.push(f):d.push(f.$el);else d.push(i.selectors.value);return d},l=i=>{const s=t(i);let d=[];return i.selectors?d=o(i):s&&(d=Array.from(s.children).filter(f=>x(f)&&E(f))),d},a=i=>s=>{const d=Te[s.key]||s.key.toLowerCase();if($.includes(d))return;const f=i.handlers||H;for(const u of Object.keys(f)){const[p,...c]=u.split(".");if(p==="keydown"&&c.includes(d)){const m=f[u],g=c.filter(b=>$.includes(b)),M=$.some(b=>{const h=b.charAt(0).toUpperCase()+b.slice(1);return s.getModifierState(h)});if(g.length>0){if(M){for(const b of $)if(c.includes(b)){const h=b.charAt(0).toUpperCase()+b.slice(1);s.getModifierState(h)&&m(s)}}}else M||m(s)}}},r=[];n.onMounted(()=>{for(const i of e){const s=t(i),d=l(i),f=a(i),u=s?[s]:d;for(const p of u){const{focused:c}=Ie(n.ref(p)),m=n.watch(c,g=>{g?p.addEventListener("keydown",f):p.removeEventListener("keydown",f)});r.push(m)}}}),n.onBeforeUnmount(()=>{for(const i of r)i()})}const Be=["data-colindex","data-rowindex","data-editable","contenteditable","tabindex"],Re={key:1},U=n.defineComponent({__name:"ACell",props:{colIndex:{},rowIndex:{},tableid:{},addNavigation:{type:[Boolean,Object],default:!0},tabIndex:{default:0},pinned:{type:Boolean}},setup(e){var b;const t=n.inject(e.tableid),o=n.useTemplateRef("cell"),l=n.ref(""),a=n.ref(!1),r=t.table,i=t.columns[e.colIndex],s=t.rows[e.rowIndex],d=n.computed(()=>{const h=t.cellData(e.colIndex,e.rowIndex),k=i.format;return k?typeof k=="function"?k(h,{table:r,row:s,column:i}):typeof k=="string"?Function(`"use strict";return (${k})`)()(h,{table:r,row:s,column:i}):h:h}),f=()=>{if(i.mask,i.modalComponent){const h=o.value.getBoundingClientRect();t.modal.visible=!0,t.modal.colIndex=e.colIndex,t.modal.rowIndex=e.rowIndex,t.modal.parent=o.value,t.modal.top=h.top+h.height,t.modal.left=h.left,t.modal.width=p.value,typeof i.modalComponent=="function"?t.modal.component=i.modalComponent({table:r,row:s,column:i}):t.modal.component=i.modalComponent,t.modal.componentProps=i.modalComponentExtraProps}};if(e.addNavigation){let h={...H,"keydown.f2":f,"keydown.alt.up":f,"keydown.alt.down":f,"keydown.alt.left":f,"keydown.alt.right":f};typeof e.addNavigation=="object"&&(h={...h,...e.addNavigation}),V([{selectors:o,handlers:h}])}const u=n.computed(()=>i.align||"center"),p=n.computed(()=>i.width||"40ch"),c=()=>{o.value&&(l.value=o.value.textContent)},m=()=>{o.value&&o.value.textContent!==l.value&&(l.value=o.value.textContent,o.value.dispatchEvent(new Event("change")),a.value=!0,i.format||t.setCellData(e.rowIndex,e.colIndex,l.value))},g=(h,k)=>k&&h===0&&k>0?`${k}ch`:"inherit",M={textAlign:u.value,width:p.value,backgroundColor:a.value?"var(--cell-modified-color)":"inherit",fontWeight:a.value?"bold":"inherit",paddingLeft:g(e.colIndex,(b=t.display[e.rowIndex])==null?void 0:b.indent)};return(h,k)=>(n.openBlock(),n.createElementBlock("td",{ref:"cell","data-colindex":h.colIndex,"data-rowindex":h.rowIndex,"data-editable":n.unref(i).edit,contenteditable:n.unref(i).edit,tabindex:h.tabIndex,spellcheck:!1,style:M,onFocus:c,onPaste:m,onBlur:m,onInput:m,onClick:f,onMousedown:f,class:n.normalizeClass(["atable__cell",h.pinned?"sticky-column":""])},[n.unref(i).cellComponent?(n.openBlock(),n.createBlock(n.resolveDynamicComponent(n.unref(i).cellComponent),n.mergeProps({key:0,value:d.value},n.unref(i).cellComponentProps),null,16,["value"])):(n.openBlock(),n.createElementBlock("span",Re,n.toDisplayString(d.value),1))],42,Be))}}),$e=["tabindex"],Le=["tabindex"],Oe=["colspan"],ne=n.defineComponent({__name:"AExpansionRow",props:{rowIndex:{},tableid:{},tabIndex:{default:()=>-1},addNavigation:{type:[Boolean,Object]}},setup(e){const t=n.inject(e.tableid),o=n.useTemplateRef("rowEl"),l=n.computed(()=>t.display[e.rowIndex].expanded?"▼":"►");if(e.addNavigation){const a={"keydown.control.g":r=>{r.stopPropagation(),r.preventDefault(),t.toggleRowExpand(e.rowIndex)}};typeof e.addNavigation=="object"&&Object.assign(a,e.addNavigation),V([{selectors:o,handlers:a}])}return(a,r)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createElementVNode("tr",n.mergeProps(a.$attrs,{ref:"rowEl",tabindex:a.tabIndex,class:"expandable-row"}),[n.createElementVNode("td",{tabIndex:-1,onClick:r[0]||(r[0]=i=>n.unref(t).toggleRowExpand(a.rowIndex)),class:"row-index"},n.toDisplayString(l.value),1),n.renderSlot(a.$slots,"row")],16,$e),n.unref(t).display[a.rowIndex].expanded?(n.openBlock(),n.createElementBlock("tr",{key:0,ref:"rowExpanded",tabindex:a.tabIndex,class:"expanded-row"},[n.createElementVNode("td",{tabIndex:-1,colspan:n.unref(t).columns.length+1,class:"expanded-row-content"},[n.renderSlot(a.$slots,"content")],8,Oe)],8,Le)):n.createCommentVNode("",!0)],64))}}),Me=["tabindex"],z=n.defineComponent({__name:"ARow",props:{rowIndex:{},tableid:{},tabIndex:{default:()=>-1},addNavigation:{type:[Boolean,Object],default:!1}},setup(e){const t=n.inject(e.tableid),o=n.useTemplateRef("rowEl"),l=n.computed(()=>t.columns.some(s=>s.pinned)),a=n.computed(()=>t.config.view!=="tree"||t.display[e.rowIndex].isRoot||t.display[e.rowIndex].open),r=n.computed(()=>t.config.view!=="tree"?"":t.display[e.rowIndex].isRoot||t.display[e.rowIndex].isParent?t.display[e.rowIndex].childrenOpen?"-":"+":""),i=s=>{t.toggleRowExpand(s)};if(e.addNavigation){let s=H;typeof e.addNavigation=="object"&&(s={...s,...e.addNavigation}),V([{selectors:o,handlers:s}])}return(s,d)=>n.withDirectives((n.openBlock(),n.createElementBlock("tr",{ref:"rowEl",tabindex:s.tabIndex,class:"table-row"},[n.renderSlot(s.$slots,"index",{},()=>[n.unref(t).config.view==="list"?(n.openBlock(),n.createElementBlock("td",{key:0,tabIndex:-1,class:n.normalizeClass(["list-index",l.value?"sticky-index":""])},n.toDisplayString(s.rowIndex+1),3)):n.unref(t).config.view==="tree"?(n.openBlock(),n.createElementBlock("td",{key:1,tabIndex:-1,class:n.normalizeClass(["tree-index",l.value?"sticky-index":""]),onClick:d[0]||(d[0]=f=>i(s.rowIndex))},n.toDisplayString(r.value),3)):n.createCommentVNode("",!0)]),n.renderSlot(s.$slots,"default")],8,Me)),[[n.vShow,a.value]])}});function oe(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function T(e){return typeof e=="function"?e():n.unref(e)}const le=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Pe=Object.prototype.toString,ve=e=>Pe.call(e)==="[object Object]",B=()=>{},F=Ne();function Ne(){var e,t;return le&&((e=window==null?void 0:window.navigator)==null?void 0:e.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((t=window==null?void 0:window.navigator)==null?void 0:t.maxTouchPoints)>2&&/iPad|Macintosh/.test(window==null?void 0:window.navigator.userAgent))}const re={mounted:"mounted",updated:"updated",unmounted:"unmounted"};function je(...e){if(e.length!==1)return n.toRef(...e);const t=e[0];return typeof t=="function"?n.readonly(n.customRef(()=>({get:t,set:B}))):n.ref(t)}function R(e){var t;const o=T(e);return(t=o==null?void 0:o.$el)!=null?t:o}const ae=le?window:void 0;function L(...e){let t,o,l,a;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,l,a]=e,t=ae):[t,o,l,a]=e,!t)return B;Array.isArray(o)||(o=[o]),Array.isArray(l)||(l=[l]);const r=[],i=()=>{r.forEach(u=>u()),r.length=0},s=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),d=n.watch(()=>[R(t),T(a)],([u,p])=>{if(i(),!u)return;const c=ve(p)?{...p}:p;r.push(...o.flatMap(m=>l.map(g=>s(u,m,g,c))))},{immediate:!0,flush:"post"}),f=()=>{d(),i()};return oe(f),f}let ie=!1;function se(e,t,o={}){const{window:l=ae,ignore:a=[],capture:r=!0,detectIframe:i=!1}=o;if(!l)return B;F&&!ie&&(ie=!0,Array.from(l.document.body.children).forEach(c=>c.addEventListener("click",B)),l.document.documentElement.addEventListener("click",B));let s=!0;const d=c=>a.some(m=>{if(typeof m=="string")return Array.from(l.document.querySelectorAll(m)).some(g=>g===c.target||c.composedPath().includes(g));{const g=R(m);return g&&(c.target===g||c.composedPath().includes(g))}}),u=[L(l,"click",c=>{const m=R(e);if(!(!m||m===c.target||c.composedPath().includes(m))){if(c.detail===0&&(s=!d(c)),!s){s=!0;return}t(c)}},{passive:!0,capture:r}),L(l,"pointerdown",c=>{const m=R(e);s=!d(c)&&!!(m&&!c.composedPath().includes(m))},{passive:!0}),i&&L(l,"blur",c=>{setTimeout(()=>{var m;const g=R(e);((m=l.document.activeElement)==null?void 0:m.tagName)==="IFRAME"&&!(g!=null&&g.contains(l.document.activeElement))&&t(c)},0)})].filter(Boolean);return()=>u.forEach(c=>c())}const We={[re.mounted](e,t){const o=!t.modifiers.bubble;if(typeof t.value=="function")e.__onClickOutside_stop=se(e,t.value,{capture:o});else{const[l,a]=t.value;e.__onClickOutside_stop=se(e,l,Object.assign({capture:o},a))}},[re.unmounted](e){e.__onClickOutside_stop()}};function q(e){return typeof Window<"u"&&e instanceof Window?e.document.documentElement:typeof Document<"u"&&e instanceof Document?e.documentElement:e}function ce(e){const t=window.getComputedStyle(e);if(t.overflowX==="scroll"||t.overflowY==="scroll"||t.overflowX==="auto"&&e.clientWidth<e.scrollWidth||t.overflowY==="auto"&&e.clientHeight<e.scrollHeight)return!0;{const o=e.parentNode;return!o||o.tagName==="BODY"?!1:ce(o)}}function He(e){const t=e||window.event,o=t.target;return ce(o)?!1:t.touches.length>1?!0:(t.preventDefault&&t.preventDefault(),!1)}const G=new WeakMap;function Ve(e,t=!1){const o=n.ref(t);let l=null,a="";n.watch(je(e),s=>{const d=q(T(s));if(d){const f=d;if(G.get(f)||G.set(f,f.style.overflow),f.style.overflow!=="hidden"&&(a=f.style.overflow),f.style.overflow==="hidden")return o.value=!0;if(o.value)return f.style.overflow="hidden"}},{immediate:!0});const r=()=>{const s=q(T(e));!s||o.value||(F&&(l=L(s,"touchmove",d=>{He(d)},{passive:!1})),s.style.overflow="hidden",o.value=!0)},i=()=>{const s=q(T(e));!s||!o.value||(F&&(l==null||l()),s.style.overflow=a,G.delete(s),o.value=!1)};return oe(i),n.computed({get(){return o.value},set(s){s?r():i()}})}function Ue(){let e=!1;const t=n.ref(!1);return(o,l)=>{if(t.value=l.value,e)return;e=!0;const a=Ve(o,l.value);n.watch(t,r=>a.value=r)}}Ue();for(var y=[],Y=0;Y<256;++Y)y.push((Y+256).toString(16).slice(1));function ze(e,t=0){return(y[e[t+0]]+y[e[t+1]]+y[e[t+2]]+y[e[t+3]]+"-"+y[e[t+4]]+y[e[t+5]]+"-"+y[e[t+6]]+y[e[t+7]]+"-"+y[e[t+8]]+y[e[t+9]]+"-"+y[e[t+10]]+y[e[t+11]]+y[e[t+12]]+y[e[t+13]]+y[e[t+14]]+y[e[t+15]]).toLowerCase()}var O,Fe=new Uint8Array(16);function qe(){if(!O&&(O=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!O))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return O(Fe)}var Ge=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const de={randomUUID:Ge};function Ye(e,t,o){if(de.randomUUID&&!t&&!e)return de.randomUUID();e=e||{};var l=e.random||(e.rng||qe)();return l[6]=l[6]&15|64,l[8]=l[8]&63|128,ze(l)}class fe{constructor(t,o,l,a,r,i){C(this,"id");C(this,"rows");C(this,"columns");C(this,"config");C(this,"table");C(this,"display");C(this,"modal");this.id=t||Ye(),this.rows=l,this.columns=n.reactive(o),this.config=n.reactive(a),this.table=r||n.reactive(this.createTableObject()),this.display=this.createDisplayObject(i),this.modal=n.reactive({visible:!1})}createTableObject(){const t={};for(const[o,l]of this.columns.entries())for(const[a,r]of this.rows.entries())t[`${o}:${a}`]=r[l.name];return t}createDisplayObject(t){const o=[Object.assign({},{modified:!1})];if(t&&"0:0"in t)return t;const l=new Set;for(let a=this.rows.length-1;a>=0;a--){const r=this.rows[a];r.parent&&l.add(r.parent),o[a]={childrenOpen:!1,expanded:!1,indent:r.indent||null,isParent:l.has(a),isRoot:r.parent===null||r.parent===void 0,modified:!1,open:r.parent===null||r.parent===void 0,parent:r.parent}}return n.reactive(o)}get zeroColumn(){return["list","tree","list-expansion"].includes(this.config.view)}get numberedRowWidth(){return n.computed(()=>String(Math.ceil(this.rows.length/100)+1)+"ch")}cellData(t,o){return this.table[`${t}:${o}`]}setCellData(t,o,l){this.table[`${o}:${t}`]!==l&&(this.display[t].modified=!0),this.table[`${o}:${t}`]=l;const a=this.columns[o];return this.rows[t][a.name]=l,this.table[`${o}:${t}`]}toggleRowExpand(t){if(this.config.view==="tree"){this.display[t].childrenOpen=!this.display[t].childrenOpen;for(let o=this.rows.length-1;o>=0;o--)this.display[o].parent===t&&(this.display[o].open=!this.display[o].open,this.display[o].childrenOpen&&this.toggleRowExpand(o))}else this.config.view==="list-expansion"&&(this.display[t].expanded=!this.display[t].expanded)}}const Xe={key:0,id:"resizable"},Je={class:"atable-header-row",tabindex:"-1"},X=n.defineComponent({__name:"ATableHeader",props:{columns:{},tableid:{}},setup(e){const t=n.inject(e.tableid),o=n.computed(()=>t.columns.some(a=>a.pinned)),l=a=>({minWidth:a.width||"40ch",textAlign:a.align||"center",width:t.config.fullWidth?"auto":null});return(a,r)=>a.columns.length?(n.openBlock(),n.createElementBlock("thead",Xe,[n.createElementVNode("tr",Je,[n.unref(t).zeroColumn?(n.openBlock(),n.createElementBlock("th",{key:0,id:"header-index",class:n.normalizeClass(o.value?"sticky-index":"")},null,2)):n.createCommentVNode("",!0),(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(a.columns,(i,s)=>(n.openBlock(),n.createElementBlock("th",{key:i.name,tabindex:"-1",style:n.normalizeStyle(l(i)),class:n.normalizeClass(i.pinned?"sticky-column":"")},[n.renderSlot(a.$slots,"default",{},()=>[n.createTextVNode(n.toDisplayString(i.label||String.fromCharCode(s+97).toUpperCase()),1)])],6))),128))])])):n.createCommentVNode("",!0)}}),J=n.defineComponent({__name:"ATableModal",props:{colIndex:{},rowIndex:{},tableid:{}},setup(e){const t=o=>{o.stopPropagation()};return(o,l)=>(n.openBlock(),n.createElementBlock("div",{class:"amodal",tabindex:"-1",onClick:t,onInput:t},[n.renderSlot(o.$slots,"default")],32))}}),ue=n.defineComponent({__name:"ATable",props:{id:{},modelValue:{},columns:{},rows:{default:()=>[]},config:{default:()=>new Object}},emits:["update:modelValue"],setup(e,{emit:t}){const o=t,l=n.useTemplateRef("table"),a=e.modelValue?e.modelValue:e.rows,r=new fe(e.id,e.columns,a,e.config);n.provide(r.id,r),n.watch(()=>r.rows,d=>{o("update:modelValue",d)},{deep:!0}),n.onMounted(()=>{i(),r.config.view==="tree"&&new MutationObserver(()=>i()).observe(l.value,{childList:!0,subtree:!0})});const i=()=>{const d=l.value,f=Array.from(d.rows[0].cells);for(const[u,p]of f.entries()){const c=d.rows[1].cells[u];p.style.width=`${c.offsetWidth}px`}for(const u of d.rows){let p=0;const c=[];for(const m of u.cells)(m.classList.contains("sticky-column")||m.classList.contains("sticky-index"))&&(m.style.left=`${p}px`,p+=m.offsetWidth,c.push(m));c.length>0&&c[c.length-1].classList.add("sticky-column-edge")}},s=d=>{var f;d.target instanceof Node&&(f=r.modal.parent)!=null&&f.contains(d.target)||r.modal.visible&&(r.modal.visible=!1)};return window.addEventListener("keydown",d=>{if(d.key==="Escape"&&r.modal.visible){r.modal.visible=!1;const f=r.modal.parent;f&&n.nextTick().then(()=>{f.focus()})}}),(d,f)=>n.withDirectives((n.openBlock(),n.createElementBlock("table",{ref:"table",class:"atable",style:n.normalizeStyle({width:n.unref(r).config.fullWidth?"100%":"auto"})},[n.renderSlot(d.$slots,"header",{data:n.unref(r)},()=>[n.createVNode(X,{columns:n.unref(r).columns,tableid:n.unref(r).id},null,8,["columns","tableid"])]),n.createElementVNode("tbody",null,[n.renderSlot(d.$slots,"body",{data:n.unref(r)},()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(r).rows,(u,p)=>(n.openBlock(),n.createBlock(z,{key:u.id,row:u,rowIndex:p,tableid:n.unref(r).id},{default:n.withCtx(()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(r).columns,(c,m)=>(n.openBlock(),n.createBlock(U,{key:c.name,tableid:n.unref(r).id,col:c,spellcheck:"false",pinned:c.pinned,rowIndex:p,colIndex:m+(n.unref(r).zeroColumn?0:-1),component:c.cellComponent,style:n.normalizeStyle({textAlign:(c==null?void 0:c.align)||"center",minWidth:(c==null?void 0:c.width)||"40ch",width:n.unref(r).config.fullWidth?"auto":null})},null,8,["tableid","col","pinned","rowIndex","colIndex","component","style"]))),128))]),_:2},1032,["row","rowIndex","tableid"]))),128))])]),n.renderSlot(d.$slots,"footer",{data:n.unref(r)}),n.renderSlot(d.$slots,"modal",{data:n.unref(r)},()=>[n.withDirectives(n.createVNode(J,{colIndex:n.unref(r).modal.colIndex,rowIndex:n.unref(r).modal.rowIndex,tableid:n.unref(r).id,style:n.normalizeStyle({left:n.unref(r).modal.left+"px",top:n.unref(r).modal.top+"px",maxWidth:n.unref(r).modal.width+"px"})},{default:n.withCtx(()=>[(n.openBlock(),n.createBlock(n.resolveDynamicComponent(n.unref(r).modal.component),n.mergeProps({key:`${n.unref(r).modal.rowIndex}:${n.unref(r).modal.colIndex}`,colIndex:n.unref(r).modal.colIndex,rowIndex:n.unref(r).modal.rowIndex,tableid:n.unref(r).id},n.unref(r).modal.componentProps),null,16,["colIndex","rowIndex","tableid"]))]),_:1},8,["colIndex","rowIndex","tableid","style"]),[[n.vShow,n.unref(r).modal.visible]])])],4)),[[n.unref(We),s]])}});function Qe(e){e.component("ACell",U),e.component("AExpansionRow",ne),e.component("ARow",z),e.component("ATable",ue),e.component("ATableHeader",X),e.component("ATableModal",J)}w.ACell=U,w.AExpansionRow=ne,w.ARow=z,w.ATable=ue,w.ATableHeader=X,w.ATableModal=J,w.TableDataStore=fe,w.install=Qe,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
1
+ (function(w,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(w=typeof globalThis<"u"?globalThis:w||self,n(w["@stonecrop/atable"]={},w.Vue))})(this,function(w,n){"use strict";var wt=Object.defineProperty;var yt=(w,n,D)=>n in w?wt(w,n,{enumerable:!0,configurable:!0,writable:!0,value:D}):w[n]=D;var A=(w,n,D)=>yt(w,typeof n!="symbol"?n+"":n,D);function D(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function N(e){return typeof e=="function"?e():n.unref(e)}const xe=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ce=e=>e!=null,Se=Object.prototype.toString,Ie=e=>Se.call(e)==="[object Object]",Ae=()=>{},$=xe?window:void 0;function O(e){var t;const o=N(e);return(t=o==null?void 0:o.$el)!=null?t:o}function R(...e){let t,o,l,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,l,i]=e,t=$):[t,o,l,i]=e,!t)return Ae;Array.isArray(o)||(o=[o]),Array.isArray(l)||(l=[l]);const r=[],d=()=>{r.forEach(u=>u()),r.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[O(t),N(i)],([u,p])=>{if(d(),!u)return;const c=Ie(p)?{...p}:p;r.push(...o.flatMap(m=>l.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return D(f),f}function De(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function Te(e){const t=De();return n.computed(()=>(t.value,!!e()))}function $e(e,t,o={}){const{window:l=$,...i}=o;let r;const d=Te(()=>l&&"MutationObserver"in l),a=()=>{r&&(r.disconnect(),r=void 0)},s=n.computed(()=>{const c=N(e),m=(Array.isArray(c)?c:[c]).map(O).filter(Ce);return new Set(m)}),f=n.watch(()=>s.value,c=>{a(),d.value&&c.size&&(r=new MutationObserver(t),c.forEach(m=>r.observe(m,i)))},{immediate:!0,flush:"post"}),u=()=>r==null?void 0:r.takeRecords(),p=()=>{f(),a()};return D(p),{isSupported:d,stop:p,takeRecords:u}}function Oe(e={}){var t;const{window:o=$,deep:l=!0,triggerOnRemoval:i=!1}=e,r=(t=e.document)!=null?t:o==null?void 0:o.document,d=()=>{var f;let u=r==null?void 0:r.activeElement;if(l)for(;u!=null&&u.shadowRoot;)u=(f=u==null?void 0:u.shadowRoot)==null?void 0:f.activeElement;return u},a=n.ref(),s=()=>{a.value=d()};return o&&(R(o,"blur",f=>{f.relatedTarget===null&&s()},!0),R(o,"focus",s,!0)),i&&$e(r,f=>{f.filter(u=>u.removedNodes.length).map(u=>Array.from(u.removedNodes)).flat().forEach(u=>{u===a.value&&s()})},{childList:!0,subtree:!0}),s(),a}const Re="focusin",Be="focusout";function ve(e,t={}){const{window:o=$}=t,l=n.computed(()=>O(e)),i=n.ref(!1),r=n.computed(()=>i.value),d=Oe(t);return!o||!d.value?{focused:r}:(R(l,Re,()=>i.value=!0),R(l,Be,()=>i.value=!1),{focused:r})}function Le(e,{window:t=$,scrollTarget:o}={}){const l=n.ref(!1),i=()=>{if(!t)return;const r=t.document,d=O(e);if(!d)l.value=!1;else{const a=d.getBoundingClientRect();l.value=a.top<=(t.innerHeight||r.documentElement.clientHeight)&&a.left<=(t.innerWidth||r.documentElement.clientWidth)&&a.bottom>=0&&a.right>=0}};return n.watch(()=>O(e),()=>i(),{immediate:!0,flush:"post"}),t&&R(o||t,"scroll",i,{capture:!1,passive:!0}),l}const S=e=>{let t=Le(e).value;return t=t&&e.offsetHeight>0,t},I=e=>e.tabIndex>=0,ne=e=>{const t=e.target;return V(t)},V=e=>{var t;let o;if(e instanceof HTMLTableCellElement){const l=(t=e.parentElement)==null?void 0:t.previousElementSibling;if(l){const i=Array.from(l.children)[e.cellIndex];i&&(o=i)}}else if(e instanceof HTMLTableRowElement){const l=e.previousElementSibling;l&&(o=l)}return o&&(!I(o)||!S(o))?V(o):o},Me=e=>{var t;const o=e.target;let l;if(o instanceof HTMLTableCellElement){const i=(t=o.parentElement)==null?void 0:t.parentElement;if(i){const r=i.firstElementChild.children[o.cellIndex];r&&(l=r)}}else if(o instanceof HTMLTableRowElement){const i=o.parentElement;if(i){const r=i.firstElementChild;r&&(l=r)}}return l&&(!I(l)||!S(l))?H(l):l},oe=e=>{const t=e.target;return H(t)},H=e=>{var t;let o;if(e instanceof HTMLTableCellElement){const l=(t=e.parentElement)==null?void 0:t.nextElementSibling;if(l){const i=Array.from(l.children)[e.cellIndex];i&&(o=i)}}else if(e instanceof HTMLTableRowElement){const l=e.nextElementSibling;l&&(o=l)}return o&&(!I(o)||!S(o))?H(o):o},Pe=e=>{var t;const o=e.target;let l;if(o instanceof HTMLTableCellElement){const i=(t=o.parentElement)==null?void 0:t.parentElement;if(i){const r=i.lastElementChild.children[o.cellIndex];r&&(l=r)}}else if(o instanceof HTMLTableRowElement){const i=o.parentElement;if(i){const r=i.lastElementChild;r&&(l=r)}}return l&&(!I(l)||!S(l))?V(l):l},le=e=>{const t=e.target;return z(t)},z=e=>{var t;let o;if(e.previousElementSibling)o=e.previousElementSibling;else{const l=(t=e.parentElement)==null?void 0:t.previousElementSibling;o=l==null?void 0:l.lastElementChild}return o&&(!I(o)||!S(o))?z(o):o},re=e=>{const t=e.target;return U(t)},U=e=>{var t;let o;if(e.nextElementSibling)o=e.nextElementSibling;else{const l=(t=e.parentElement)==null?void 0:t.nextElementSibling;o=l==null?void 0:l.firstElementChild}return o&&(!I(o)||!S(o))?U(o):o},ie=e=>{const t=e.target.parentElement.firstElementChild;return t&&(!I(t)||!S(t))?U(t):t},ae=e=>{const t=e.target.parentElement.lastElementChild;return t&&(!I(t)||!S(t))?z(t):t},M=["alt","control","shift","meta"],je={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},F={"keydown.up":e=>{const t=ne(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.down":e=>{const t=oe(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.left":e=>{const t=le(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.right":e=>{const t=re(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.control.up":e=>{const t=Me(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.down":e=>{const t=Pe(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.left":e=>{const t=ie(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.right":e=>{const t=ae(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.end":e=>{const t=ae(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=oe(e);t&&t.focus()}},"keydown.shift.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=ne(e);t&&t.focus()}},"keydown.home":e=>{const t=ie(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.tab":e=>{const t=re(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.shift.tab":e=>{const t=le(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())}};function q(e){const t=d=>{let a=null;return d.parent&&(typeof d.parent=="string"?a=document.querySelector(d.parent):d.parent instanceof HTMLElement?a=d.parent:a=d.parent.value),a},o=d=>{const a=t(d);let s=[];if(typeof d.selectors=="string")s=a?Array.from(a.querySelectorAll(d.selectors)):Array.from(document.querySelectorAll(d.selectors));else if(Array.isArray(d.selectors))for(const f of d.selectors)f instanceof HTMLElement?s.push(f):s.push(f.$el);else if(d.selectors instanceof HTMLElement)s.push(d.selectors);else if(Array.isArray(d.selectors.value))for(const f of d.selectors.value)f instanceof HTMLElement?s.push(f):s.push(f.$el);else s.push(d.selectors.value);return s},l=d=>{const a=t(d);let s=[];return d.selectors?s=o(d):a&&(s=Array.from(a.children).filter(f=>I(f)&&S(f))),s},i=d=>a=>{const s=je[a.key]||a.key.toLowerCase();if(M.includes(s))return;const f=d.handlers||F;for(const u of Object.keys(f)){const[p,...c]=u.split(".");if(p==="keydown"&&c.includes(s)){const m=f[u],h=c.filter(y=>M.includes(y)),b=M.some(y=>{const x=y.charAt(0).toUpperCase()+y.slice(1);return a.getModifierState(x)});if(h.length>0){if(b){for(const y of M)if(c.includes(y)){const x=y.charAt(0).toUpperCase()+y.slice(1);a.getModifierState(x)&&m(a)}}}else b||m(a)}}},r=[];n.onMounted(()=>{for(const d of e){const a=t(d),s=l(d),f=i(d),u=a?[a]:s;for(const p of u){const{focused:c}=ve(n.ref(p)),m=n.watch(c,h=>{h?p.addEventListener("keydown",f):p.removeEventListener("keydown",f)});r.push(m)}}}),n.onBeforeUnmount(()=>{for(const d of r)d()})}function G(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function P(e){return typeof e=="function"?e():n.unref(e)}const We=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ne=e=>e!=null,Ve=Object.prototype.toString,He=e=>Ve.call(e)==="[object Object]",ze=()=>{};function Ue(e){return n.getCurrentInstance()}function Fe(e,t=!0,o){Ue()?n.onMounted(e,o):t?e():n.nextTick(e)}const Y=We?window:void 0;function T(e){var t;const o=P(e);return(t=o==null?void 0:o.$el)!=null?t:o}function se(...e){let t,o,l,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,l,i]=e,t=Y):[t,o,l,i]=e,!t)return ze;Array.isArray(o)||(o=[o]),Array.isArray(l)||(l=[l]);const r=[],d=()=>{r.forEach(u=>u()),r.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[T(t),P(i)],([u,p])=>{if(d(),!u)return;const c=He(p)?{...p}:p;r.push(...o.flatMap(m=>l.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return G(f),f}function qe(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function ce(e){const t=qe();return n.computed(()=>(t.value,!!e()))}function de(e,t,o={}){const{window:l=Y,...i}=o;let r;const d=ce(()=>l&&"MutationObserver"in l),a=()=>{r&&(r.disconnect(),r=void 0)},s=n.computed(()=>{const c=P(e),m=(Array.isArray(c)?c:[c]).map(T).filter(Ne);return new Set(m)}),f=n.watch(()=>s.value,c=>{a(),d.value&&c.size&&(r=new MutationObserver(t),c.forEach(m=>r.observe(m,i)))},{immediate:!0,flush:"post"}),u=()=>r==null?void 0:r.takeRecords(),p=()=>{f(),a()};return G(p),{isSupported:d,stop:p,takeRecords:u}}function Ge(e,t,o={}){const{window:l=Y,...i}=o;let r;const d=ce(()=>l&&"ResizeObserver"in l),a=()=>{r&&(r.disconnect(),r=void 0)},s=n.computed(()=>{const p=P(e);return Array.isArray(p)?p.map(c=>T(c)):[T(p)]}),f=n.watch(s,p=>{if(a(),d.value&&l){r=new ResizeObserver(t);for(const c of p)c&&r.observe(c,i)}},{immediate:!0,flush:"post"}),u=()=>{a(),f()};return G(u),{isSupported:d,stop:u}}function Ye(e,t={}){const{reset:o=!0,windowResize:l=!0,windowScroll:i=!0,immediate:r=!0,updateTiming:d="sync"}=t,a=n.ref(0),s=n.ref(0),f=n.ref(0),u=n.ref(0),p=n.ref(0),c=n.ref(0),m=n.ref(0),h=n.ref(0);function b(){const x=T(e);if(!x){o&&(a.value=0,s.value=0,f.value=0,u.value=0,p.value=0,c.value=0,m.value=0,h.value=0);return}const E=x.getBoundingClientRect();a.value=E.height,s.value=E.bottom,f.value=E.left,u.value=E.right,p.value=E.top,c.value=E.width,m.value=E.x,h.value=E.y}function y(){d==="sync"?b():d==="next-frame"&&requestAnimationFrame(()=>b())}return Ge(e,y),n.watch(()=>T(e),x=>!x&&y()),de(e,y,{attributeFilter:["style","class"]}),i&&se("scroll",y,{capture:!0,passive:!0}),l&&se("resize",y,{passive:!0}),Fe(()=>{r&&y()}),{height:a,bottom:s,left:f,right:u,top:p,width:c,x:m,y:h,update:y}}const Xe=["data-colindex","data-rowindex","data-editable","contenteditable","tabindex"],Je={key:1},X=n.defineComponent({__name:"ACell",props:{colIndex:{},rowIndex:{},tableid:{},addNavigation:{type:[Boolean,Object],default:!0},tabIndex:{default:0},pinned:{type:Boolean}},setup(e){var E;const t=n.inject(e.tableid),o=n.useTemplateRef("cell"),l=n.ref(""),i=n.ref(!1),{bottom:r,left:d}=Ye(o),a=t.table,s=t.columns[e.colIndex],f=t.rows[e.rowIndex],u=n.computed(()=>s.align||"center"),p=n.computed(()=>s.width||"40ch"),c=n.computed(()=>{const k=t.cellData(e.colIndex,e.rowIndex),C=s.format;return C?typeof C=="function"?C(k,{table:a,row:f,column:s}):typeof C=="string"?Function(`"use strict";return (${C})`)()(k,{table:a,row:f,column:s}):k:k}),m=()=>{s.mask,s.modalComponent&&(t.modal.visible=!0,t.modal.colIndex=e.colIndex,t.modal.rowIndex=e.rowIndex,t.modal.parent=o.value,t.modal.top=r.value,t.modal.left=d.value,t.modal.width=p.value,typeof s.modalComponent=="function"?t.modal.component=s.modalComponent({table:a,row:f,column:s}):t.modal.component=s.modalComponent,t.modal.componentProps=s.modalComponentExtraProps)};if(e.addNavigation){let k={...F,"keydown.f2":m,"keydown.alt.up":m,"keydown.alt.down":m,"keydown.alt.left":m,"keydown.alt.right":m};typeof e.addNavigation=="object"&&(k={...k,...e.addNavigation}),q([{selectors:o,handlers:k}])}const h=()=>{o.value&&(l.value=o.value.textContent)},b=()=>{o.value&&o.value.textContent!==l.value&&(l.value=o.value.textContent,o.value.dispatchEvent(new Event("change")),i.value=!0,s.format||t.setCellData(e.rowIndex,e.colIndex,l.value))},y=(k,C)=>C&&k===0&&C>0?`${C}ch`:"inherit",x={textAlign:u.value,width:p.value,backgroundColor:i.value?"var(--cell-modified-color)":"inherit",fontWeight:i.value?"bold":"inherit",paddingLeft:y(e.colIndex,(E=t.display[e.rowIndex])==null?void 0:E.indent)};return(k,C)=>(n.openBlock(),n.createElementBlock("td",{ref:"cell","data-colindex":k.colIndex,"data-rowindex":k.rowIndex,"data-editable":n.unref(s).edit,contenteditable:n.unref(s).edit,tabindex:k.tabIndex,spellcheck:!1,style:x,onFocus:h,onPaste:b,onBlur:b,onInput:b,onClick:m,onMousedown:m,class:n.normalizeClass(["atable__cell",k.pinned?"sticky-column":""])},[n.unref(s).cellComponent?(n.openBlock(),n.createBlock(n.resolveDynamicComponent(n.unref(s).cellComponent),n.mergeProps({key:0,value:c.value},n.unref(s).cellComponentProps),null,16,["value"])):(n.openBlock(),n.createElementBlock("span",Je,n.toDisplayString(c.value),1))],42,Xe))}}),Qe=["tabindex"],Ze=["tabindex"],Ke=["colspan"],fe=n.defineComponent({__name:"AExpansionRow",props:{rowIndex:{},tableid:{},tabIndex:{default:()=>-1},addNavigation:{type:[Boolean,Object]}},setup(e){const t=n.inject(e.tableid),o=n.useTemplateRef("rowEl"),l=n.computed(()=>t.display[e.rowIndex].expanded?"▼":"►");if(e.addNavigation){const i={"keydown.control.g":r=>{r.stopPropagation(),r.preventDefault(),t.toggleRowExpand(e.rowIndex)}};typeof e.addNavigation=="object"&&Object.assign(i,e.addNavigation),q([{selectors:o,handlers:i}])}return(i,r)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[n.createElementVNode("tr",n.mergeProps(i.$attrs,{ref:"rowEl",tabindex:i.tabIndex,class:"expandable-row"}),[n.createElementVNode("td",{tabIndex:-1,onClick:r[0]||(r[0]=d=>n.unref(t).toggleRowExpand(i.rowIndex)),class:"row-index"},n.toDisplayString(l.value),1),n.renderSlot(i.$slots,"row")],16,Qe),n.unref(t).display[i.rowIndex].expanded?(n.openBlock(),n.createElementBlock("tr",{key:0,ref:"rowExpanded",tabindex:i.tabIndex,class:"expanded-row"},[n.createElementVNode("td",{tabIndex:-1,colspan:n.unref(t).columns.length+1,class:"expanded-row-content"},[n.renderSlot(i.$slots,"content")],8,Ke)],8,Ze)):n.createCommentVNode("",!0)],64))}}),_e=["tabindex"],J=n.defineComponent({__name:"ARow",props:{rowIndex:{},tableid:{},tabIndex:{default:()=>-1},addNavigation:{type:[Boolean,Object],default:!1}},setup(e){const t=n.inject(e.tableid),o=n.useTemplateRef("rowEl"),l=n.computed(()=>t.columns.some(a=>a.pinned)),i=n.computed(()=>t.config.view!=="tree"||t.display[e.rowIndex].isRoot||t.display[e.rowIndex].open),r=n.computed(()=>t.config.view!=="tree"?"":t.display[e.rowIndex].isRoot||t.display[e.rowIndex].isParent?t.display[e.rowIndex].childrenOpen?"-":"+":""),d=a=>{t.toggleRowExpand(a)};if(e.addNavigation){let a=F;typeof e.addNavigation=="object"&&(a={...a,...e.addNavigation}),q([{selectors:o,handlers:a}])}return(a,s)=>n.withDirectives((n.openBlock(),n.createElementBlock("tr",{ref:"rowEl",tabindex:a.tabIndex,class:"table-row"},[n.renderSlot(a.$slots,"index",{},()=>[n.unref(t).config.view==="list"?(n.openBlock(),n.createElementBlock("td",{key:0,tabIndex:-1,class:n.normalizeClass(["list-index",l.value?"sticky-index":""])},n.toDisplayString(a.rowIndex+1),3)):n.unref(t).config.view==="tree"?(n.openBlock(),n.createElementBlock("td",{key:1,tabIndex:-1,class:n.normalizeClass(["tree-index",l.value?"sticky-index":""]),onClick:s[0]||(s[0]=f=>d(a.rowIndex))},n.toDisplayString(r.value),3)):n.createCommentVNode("",!0)]),n.renderSlot(a.$slots,"default")],8,_e)),[[n.vShow,i.value]])}});function ue(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function B(e){return typeof e=="function"?e():n.unref(e)}const me=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const et=Object.prototype.toString,tt=e=>et.call(e)==="[object Object]",v=()=>{},Q=nt();function nt(){var e,t;return me&&((e=window==null?void 0:window.navigator)==null?void 0:e.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((t=window==null?void 0:window.navigator)==null?void 0:t.maxTouchPoints)>2&&/iPad|Macintosh/.test(window==null?void 0:window.navigator.userAgent))}const pe={mounted:"mounted",updated:"updated",unmounted:"unmounted"};function ot(...e){if(e.length!==1)return n.toRef(...e);const t=e[0];return typeof t=="function"?n.readonly(n.customRef(()=>({get:t,set:v}))):n.ref(t)}function L(e){var t;const o=B(e);return(t=o==null?void 0:o.$el)!=null?t:o}const he=me?window:void 0;function j(...e){let t,o,l,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,l,i]=e,t=he):[t,o,l,i]=e,!t)return v;Array.isArray(o)||(o=[o]),Array.isArray(l)||(l=[l]);const r=[],d=()=>{r.forEach(u=>u()),r.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[L(t),B(i)],([u,p])=>{if(d(),!u)return;const c=tt(p)?{...p}:p;r.push(...o.flatMap(m=>l.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return ue(f),f}let we=!1;function ye(e,t,o={}){const{window:l=he,ignore:i=[],capture:r=!0,detectIframe:d=!1}=o;if(!l)return v;Q&&!we&&(we=!0,Array.from(l.document.body.children).forEach(c=>c.addEventListener("click",v)),l.document.documentElement.addEventListener("click",v));let a=!0;const s=c=>i.some(m=>{if(typeof m=="string")return Array.from(l.document.querySelectorAll(m)).some(h=>h===c.target||c.composedPath().includes(h));{const h=L(m);return h&&(c.target===h||c.composedPath().includes(h))}}),u=[j(l,"click",c=>{const m=L(e);if(!(!m||m===c.target||c.composedPath().includes(m))){if(c.detail===0&&(a=!s(c)),!a){a=!0;return}t(c)}},{passive:!0,capture:r}),j(l,"pointerdown",c=>{const m=L(e);a=!s(c)&&!!(m&&!c.composedPath().includes(m))},{passive:!0}),d&&j(l,"blur",c=>{setTimeout(()=>{var m;const h=L(e);((m=l.document.activeElement)==null?void 0:m.tagName)==="IFRAME"&&!(h!=null&&h.contains(l.document.activeElement))&&t(c)},0)})].filter(Boolean);return()=>u.forEach(c=>c())}const lt={[pe.mounted](e,t){const o=!t.modifiers.bubble;if(typeof t.value=="function")e.__onClickOutside_stop=ye(e,t.value,{capture:o});else{const[l,i]=t.value;e.__onClickOutside_stop=ye(e,l,Object.assign({capture:o},i))}},[pe.unmounted](e){e.__onClickOutside_stop()}};function Z(e){return typeof Window<"u"&&e instanceof Window?e.document.documentElement:typeof Document<"u"&&e instanceof Document?e.documentElement:e}function ge(e){const t=window.getComputedStyle(e);if(t.overflowX==="scroll"||t.overflowY==="scroll"||t.overflowX==="auto"&&e.clientWidth<e.scrollWidth||t.overflowY==="auto"&&e.clientHeight<e.scrollHeight)return!0;{const o=e.parentNode;return!o||o.tagName==="BODY"?!1:ge(o)}}function rt(e){const t=e||window.event,o=t.target;return ge(o)?!1:t.touches.length>1?!0:(t.preventDefault&&t.preventDefault(),!1)}const K=new WeakMap;function it(e,t=!1){const o=n.ref(t);let l=null,i="";n.watch(ot(e),a=>{const s=Z(B(a));if(s){const f=s;if(K.get(f)||K.set(f,f.style.overflow),f.style.overflow!=="hidden"&&(i=f.style.overflow),f.style.overflow==="hidden")return o.value=!0;if(o.value)return f.style.overflow="hidden"}},{immediate:!0});const r=()=>{const a=Z(B(e));!a||o.value||(Q&&(l=j(a,"touchmove",s=>{rt(s)},{passive:!1})),a.style.overflow="hidden",o.value=!0)},d=()=>{const a=Z(B(e));!a||!o.value||(Q&&(l==null||l()),a.style.overflow=i,K.delete(a),o.value=!1)};return ue(d),n.computed({get(){return o.value},set(a){a?r():d()}})}function at(){let e=!1;const t=n.ref(!1);return(o,l)=>{if(t.value=l.value,e)return;e=!0;const i=it(o,l.value);n.watch(t,r=>i.value=r)}}at();for(var g=[],_=0;_<256;++_)g.push((_+256).toString(16).slice(1));function st(e,t=0){return(g[e[t+0]]+g[e[t+1]]+g[e[t+2]]+g[e[t+3]]+"-"+g[e[t+4]]+g[e[t+5]]+"-"+g[e[t+6]]+g[e[t+7]]+"-"+g[e[t+8]]+g[e[t+9]]+"-"+g[e[t+10]]+g[e[t+11]]+g[e[t+12]]+g[e[t+13]]+g[e[t+14]]+g[e[t+15]]).toLowerCase()}var W,ct=new Uint8Array(16);function dt(){if(!W&&(W=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!W))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return W(ct)}var ft=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const be={randomUUID:ft};function ut(e,t,o){if(be.randomUUID&&!t&&!e)return be.randomUUID();e=e||{};var l=e.random||(e.rng||dt)();return l[6]=l[6]&15|64,l[8]=l[8]&63|128,st(l)}class ke{constructor(t,o,l,i,r,d){A(this,"id");A(this,"rows");A(this,"columns");A(this,"config");A(this,"table");A(this,"display");A(this,"modal");this.id=t||ut(),this.rows=l,this.columns=n.reactive(o),this.config=n.reactive(i),this.table=r||n.reactive(this.createTableObject()),this.display=this.createDisplayObject(d),this.modal=n.reactive({visible:!1})}createTableObject(){const t={};for(const[o,l]of this.columns.entries())for(const[i,r]of this.rows.entries())t[`${o}:${i}`]=r[l.name];return t}createDisplayObject(t){const o=[Object.assign({},{modified:!1})];if(t&&"0:0"in t)return t;const l=new Set;for(let i=this.rows.length-1;i>=0;i--){const r=this.rows[i];r.parent&&l.add(r.parent),o[i]={childrenOpen:!1,expanded:!1,indent:r.indent||null,isParent:l.has(i),isRoot:r.parent===null||r.parent===void 0,modified:!1,open:r.parent===null||r.parent===void 0,parent:r.parent}}return n.reactive(o)}get zeroColumn(){return["list","tree","list-expansion"].includes(this.config.view)}get numberedRowWidth(){return n.computed(()=>String(Math.ceil(this.rows.length/100)+1)+"ch")}cellData(t,o){return this.table[`${t}:${o}`]}setCellData(t,o,l){this.table[`${o}:${t}`]!==l&&(this.display[t].modified=!0),this.table[`${o}:${t}`]=l;const i=this.columns[o];return this.rows[t][i.name]=l,this.table[`${o}:${t}`]}toggleRowExpand(t){if(this.config.view==="tree"){this.display[t].childrenOpen=!this.display[t].childrenOpen;for(let o=this.rows.length-1;o>=0;o--)this.display[o].parent===t&&(this.display[o].open=!this.display[o].open,this.display[o].childrenOpen&&this.toggleRowExpand(o))}else this.config.view==="list-expansion"&&(this.display[t].expanded=!this.display[t].expanded)}}const mt={key:0,id:"resizable"},pt={class:"atable-header-row",tabindex:"-1"},ee=n.defineComponent({__name:"ATableHeader",props:{columns:{},tableid:{}},setup(e){const t=n.inject(e.tableid),o=n.computed(()=>t.columns.some(i=>i.pinned)),l=i=>({minWidth:i.width||"40ch",textAlign:i.align||"center",width:t.config.fullWidth?"auto":null});return(i,r)=>i.columns.length?(n.openBlock(),n.createElementBlock("thead",mt,[n.createElementVNode("tr",pt,[n.unref(t).zeroColumn?(n.openBlock(),n.createElementBlock("th",{key:0,id:"header-index",class:n.normalizeClass(o.value?"sticky-index":"")},null,2)):n.createCommentVNode("",!0),(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(i.columns,(d,a)=>(n.openBlock(),n.createElementBlock("th",{key:d.name,tabindex:"-1",style:n.normalizeStyle(l(d)),class:n.normalizeClass(d.pinned?"sticky-column":"")},[n.renderSlot(i.$slots,"default",{},()=>[n.createTextVNode(n.toDisplayString(d.label||String.fromCharCode(a+97).toUpperCase()),1)])],6))),128))])])):n.createCommentVNode("",!0)}}),te=n.defineComponent({__name:"ATableModal",props:{colIndex:{},rowIndex:{},tableid:{}},setup(e){const t=o=>{o.stopPropagation()};return(o,l)=>(n.openBlock(),n.createElementBlock("div",{class:"amodal",tabindex:"-1",onClick:t,onInput:t},[n.renderSlot(o.$slots,"default")],32))}}),Ee=n.defineComponent({__name:"ATable",props:{id:{},modelValue:{},columns:{},rows:{default:()=>[]},config:{default:()=>new Object}},emits:["update:modelValue"],setup(e,{emit:t}){const o=t,l=n.useTemplateRef("table"),i=e.modelValue?e.modelValue:e.rows,r=new ke(e.id,e.columns,i,e.config);n.provide(r.id,r),n.watch(()=>r.rows,s=>{o("update:modelValue",s)},{deep:!0}),n.onMounted(()=>{e.columns.some(s=>s.pinned)&&(d(),r.config.view==="tree"&&de(l,d,{childList:!0,subtree:!0}))});const d=()=>{const s=l.value,f=s.rows[0],u=s.rows[1],p=f?Array.from(f.cells):[];for(const[c,m]of p.entries()){const h=u.cells[c];h&&(m.style.width=`${h.offsetWidth}px`)}for(const c of s.rows){let m=0;const h=[];for(const b of c.cells)(b.classList.contains("sticky-column")||b.classList.contains("sticky-index"))&&(b.style.left=`${m}px`,m+=b.offsetWidth,h.push(b));h.length>0&&h[h.length-1].classList.add("sticky-column-edge")}},a=s=>{var f;s.target instanceof Node&&(f=r.modal.parent)!=null&&f.contains(s.target)||r.modal.visible&&(r.modal.visible=!1)};return window.addEventListener("keydown",s=>{if(s.key==="Escape"&&r.modal.visible){r.modal.visible=!1;const f=r.modal.parent;f&&n.nextTick().then(()=>{f.focus()})}}),(s,f)=>n.withDirectives((n.openBlock(),n.createElementBlock("table",{ref:"table",class:"atable",style:n.normalizeStyle({width:n.unref(r).config.fullWidth?"100%":"auto"})},[n.renderSlot(s.$slots,"header",{data:n.unref(r)},()=>[n.createVNode(ee,{columns:n.unref(r).columns,tableid:n.unref(r).id},null,8,["columns","tableid"])]),n.createElementVNode("tbody",null,[n.renderSlot(s.$slots,"body",{data:n.unref(r)},()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(r).rows,(u,p)=>(n.openBlock(),n.createBlock(J,{key:u.id,row:u,rowIndex:p,tableid:n.unref(r).id},{default:n.withCtx(()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(r).columns,(c,m)=>(n.openBlock(),n.createBlock(X,{key:c.name,tableid:n.unref(r).id,col:c,spellcheck:"false",pinned:c.pinned,rowIndex:p,colIndex:m+(n.unref(r).zeroColumn?0:-1),component:c.cellComponent,style:n.normalizeStyle({textAlign:(c==null?void 0:c.align)||"center",minWidth:(c==null?void 0:c.width)||"40ch",width:n.unref(r).config.fullWidth?"auto":null})},null,8,["tableid","col","pinned","rowIndex","colIndex","component","style"]))),128))]),_:2},1032,["row","rowIndex","tableid"]))),128))])]),n.renderSlot(s.$slots,"footer",{data:n.unref(r)}),n.renderSlot(s.$slots,"modal",{data:n.unref(r)},()=>[n.withDirectives(n.createVNode(te,{colIndex:n.unref(r).modal.colIndex,rowIndex:n.unref(r).modal.rowIndex,tableid:n.unref(r).id,style:n.normalizeStyle({left:n.unref(r).modal.left+"px",top:n.unref(r).modal.top+"px",maxWidth:n.unref(r).modal.width+"px"})},{default:n.withCtx(()=>[(n.openBlock(),n.createBlock(n.resolveDynamicComponent(n.unref(r).modal.component),n.mergeProps({key:`${n.unref(r).modal.rowIndex}:${n.unref(r).modal.colIndex}`,colIndex:n.unref(r).modal.colIndex,rowIndex:n.unref(r).modal.rowIndex,tableid:n.unref(r).id},n.unref(r).modal.componentProps),null,16,["colIndex","rowIndex","tableid"]))]),_:1},8,["colIndex","rowIndex","tableid","style"]),[[n.vShow,n.unref(r).modal.visible]])])],4)),[[n.unref(lt),a]])}});function ht(e){e.component("ACell",X),e.component("AExpansionRow",fe),e.component("ARow",J),e.component("ATable",Ee),e.component("ATableHeader",ee),e.component("ATableModal",te)}w.ACell=X,w.AExpansionRow=fe,w.ARow=J,w.ATable=Ee,w.ATableHeader=ee,w.ATableModal=te,w.TableDataStore=ke,w.install=ht,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=atable.umd.cjs.map