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