@stonecrop/atable 0.2.44 → 0.2.45
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 +336 -330
- package/dist/atable.js.map +1 -1
- package/dist/atable.umd.cjs +1 -1
- package/dist/atable.umd.cjs.map +1 -1
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/utils.js +4 -0
- package/package.json +3 -3
- package/src/components/ACell.vue +8 -2
- package/src/utils.ts +4 -0
package/dist/atable.umd.cjs
CHANGED
|
@@ -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 at=Object.defineProperty;var st=(w,n,I)=>n in w?at(w,n,{enumerable:!0,configurable:!0,writable:!0,value:I}):w[n]=I;var A=(w,n,I)=>st(w,typeof n!="symbol"?n+"":n,I);function I(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function W(e){return typeof e=="function"?e():n.unref(e)}const ge=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const be=e=>e!=null,ke=Object.prototype.toString,Ee=e=>ke.call(e)==="[object Object]",xe=()=>{},D=ge?window:void 0;function $(e){var t;const o=W(e);return(t=o==null?void 0:o.$el)!=null?t:o}function O(...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 xe;Array.isArray(o)||(o=[o]),Array.isArray(r)||(r=[r]);const l=[],d=()=>{l.forEach(u=>u()),l.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[$(t),W(i)],([u,p])=>{if(d(),!u)return;const c=Ee(p)?{...p}:p;l.push(...o.flatMap(m=>r.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return I(f),f}function Ce(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function Se(e){const t=Ce();return n.computed(()=>(t.value,!!e()))}function Ae(e,t,o={}){const{window:r=D,...i}=o;let l;const d=Se(()=>r&&"MutationObserver"in r),a=()=>{l&&(l.disconnect(),l=void 0)},s=n.computed(()=>{const c=W(e),m=(Array.isArray(c)?c:[c]).map($).filter(be);return new Set(m)}),f=n.watch(()=>s.value,c=>{a(),d.value&&c.size&&(l=new MutationObserver(t),c.forEach(m=>l.observe(m,i)))},{immediate:!0,flush:"post"}),u=()=>l==null?void 0:l.takeRecords(),p=()=>{f(),a()};return I(p),{isSupported:d,stop:p,takeRecords:u}}function Ie(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,d=()=>{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},a=n.ref(),s=()=>{a.value=d()};return o&&(O(o,"blur",f=>{f.relatedTarget===null&&s()},!0),O(o,"focus",s,!0)),i&&Ae(l,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 Te="focusin",De="focusout";function $e(e,t={}){const{window:o=D}=t,r=n.computed(()=>$(e)),i=n.ref(!1),l=n.computed(()=>i.value),d=Ie(t);return!o||!d.value?{focused:l}:(O(r,Te,()=>i.value=!0),O(r,De,()=>i.value=!1),{focused:l})}function Oe(e,{window:t=D,scrollTarget:o}={}){const r=n.ref(!1),i=()=>{if(!t)return;const l=t.document,d=$(e);if(!d)r.value=!1;else{const a=d.getBoundingClientRect();r.value=a.top<=(t.innerHeight||l.documentElement.clientHeight)&&a.left<=(t.innerWidth||l.documentElement.clientWidth)&&a.bottom>=0&&a.right>=0}};return n.watch(()=>$(e),()=>i(),{immediate:!0,flush:"post"}),t&&O(o||t,"scroll",i,{capture:!1,passive:!0}),r}const C=e=>{let t=Oe(e).value;return t=t&&e.offsetHeight>0,t},S=e=>e.tabIndex>=0,_=e=>{const t=e.target;return j(t)},j=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&&(!S(o)||!C(o))?j(o):o},Be=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&&(!S(r)||!C(r))?N(r):r},ee=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&&(!S(o)||!C(o))?N(o):o},Re=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&&(!S(r)||!C(r))?j(r):r},te=e=>{const t=e.target;return H(t)},H=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&&(!S(o)||!C(o))?H(o):o},ne=e=>{const t=e.target;return V(t)},V=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&&(!S(o)||!C(o))?V(o):o},oe=e=>{const t=e.target.parentElement.firstElementChild;return t&&(!S(t)||!C(t))?V(t):t},le=e=>{const t=e.target.parentElement.lastElementChild;return t&&(!S(t)||!C(t))?H(t):t},L=["alt","control","shift","meta"],Me={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},z={"keydown.up":e=>{const t=_(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.down":e=>{const t=ee(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.left":e=>{const t=te(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.right":e=>{const t=ne(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.control.up":e=>{const t=Be(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.down":e=>{const t=Re(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.left":e=>{const t=oe(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.right":e=>{const t=le(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.end":e=>{const t=le(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=ee(e);t&&t.focus()}},"keydown.shift.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=_(e);t&&t.focus()}},"keydown.home":e=>{const t=oe(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.tab":e=>{const t=ne(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.shift.tab":e=>{const t=te(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())}};function F(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},r=d=>{const a=t(d);let s=[];return d.selectors?s=o(d):a&&(s=Array.from(a.children).filter(f=>S(f)&&C(f))),s},i=d=>a=>{const s=Me[a.key]||a.key.toLowerCase();if(L.includes(s))return;const f=d.handlers||z;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=>L.includes(y)),g=L.some(y=>{const E=y.charAt(0).toUpperCase()+y.slice(1);return a.getModifierState(E)});if(h.length>0){if(g){for(const y of L)if(c.includes(y)){const E=y.charAt(0).toUpperCase()+y.slice(1);a.getModifierState(E)&&m(a)}}}else g||m(a)}}},l=[];n.onMounted(()=>{for(const d of e){const a=t(d),s=r(d),f=i(d),u=a?[a]:s;for(const p of u){const{focused:c}=$e(n.ref(p)),m=n.watch(c,h=>{h?p.addEventListener("keydown",f):p.removeEventListener("keydown",f)});l.push(m)}}}),n.onBeforeUnmount(()=>{for(const d of l)d()})}function q(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function v(e){return typeof e=="function"?e():n.unref(e)}const Le=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const ve=e=>e!=null,Pe=Object.prototype.toString,We=e=>Pe.call(e)==="[object Object]",je=()=>{};function Ne(e){return n.getCurrentInstance()}function He(e,t=!0,o){Ne()?n.onMounted(e,o):t?e():n.nextTick(e)}const G=Le?window:void 0;function T(e){var t;const o=v(e);return(t=o==null?void 0:o.$el)!=null?t:o}function re(...e){let t,o,r,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,r,i]=e,t=G):[t,o,r,i]=e,!t)return je;Array.isArray(o)||(o=[o]),Array.isArray(r)||(r=[r]);const l=[],d=()=>{l.forEach(u=>u()),l.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[T(t),v(i)],([u,p])=>{if(d(),!u)return;const c=We(p)?{...p}:p;l.push(...o.flatMap(m=>r.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return q(f),f}function Ve(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function ie(e){const t=Ve();return n.computed(()=>(t.value,!!e()))}function ae(e,t,o={}){const{window:r=G,...i}=o;let l;const d=ie(()=>r&&"MutationObserver"in r),a=()=>{l&&(l.disconnect(),l=void 0)},s=n.computed(()=>{const c=v(e),m=(Array.isArray(c)?c:[c]).map(T).filter(ve);return new Set(m)}),f=n.watch(()=>s.value,c=>{a(),d.value&&c.size&&(l=new MutationObserver(t),c.forEach(m=>l.observe(m,i)))},{immediate:!0,flush:"post"}),u=()=>l==null?void 0:l.takeRecords(),p=()=>{f(),a()};return q(p),{isSupported:d,stop:p,takeRecords:u}}function ze(e,t,o={}){const{window:r=G,...i}=o;let l;const d=ie(()=>r&&"ResizeObserver"in r),a=()=>{l&&(l.disconnect(),l=void 0)},s=n.computed(()=>{const p=v(e);return Array.isArray(p)?p.map(c=>T(c)):[T(p)]}),f=n.watch(s,p=>{if(a(),d.value&&r){l=new ResizeObserver(t);for(const c of p)c&&l.observe(c,i)}},{immediate:!0,flush:"post"}),u=()=>{a(),f()};return q(u),{isSupported:d,stop:u}}function Fe(e,t={}){const{reset:o=!0,windowResize:r=!0,windowScroll:i=!0,immediate:l=!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 g(){const E=T(e);if(!E){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 k=E.getBoundingClientRect();a.value=k.height,s.value=k.bottom,f.value=k.left,u.value=k.right,p.value=k.top,c.value=k.width,m.value=k.x,h.value=k.y}function y(){d==="sync"?g():d==="next-frame"&&requestAnimationFrame(()=>g())}return ze(e,y),n.watch(()=>T(e),E=>!E&&y()),ae(e,y,{attributeFilter:["style","class"]}),i&&re("scroll",y,{capture:!0,passive:!0}),r&&re("resize",y,{passive:!0}),He(()=>{l&&y()}),{height:a,bottom:s,left:f,right:u,top:p,width:c,x:m,y:h,update:y}}const qe=["data-colindex","data-rowindex","data-editable","contenteditable","tabindex"],Ge={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 k;const t=n.inject(e.tableid),o=n.useTemplateRef("cell"),r=n.ref(""),i=n.ref(!1),{bottom:l,left:d}=Fe(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 b=t.cellData(e.colIndex,e.rowIndex),x=s.format;return x?typeof x=="function"?x(b,{table:a,row:f,column:s}):typeof x=="string"?Function(`"use strict";return (${x})`)()(b,{table:a,row:f,column:s}):b:b}),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=l.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 b={...z,"keydown.f2":m,"keydown.alt.up":m,"keydown.alt.down":m,"keydown.alt.left":m,"keydown.alt.right":m};typeof e.addNavigation=="object"&&(b={...b,...e.addNavigation}),F([{selectors:o,handlers:b}])}const h=()=>{o.value&&(r.value=o.value.textContent)},g=()=>{o.value&&o.value.textContent!==r.value&&(r.value=o.value.textContent,o.value.dispatchEvent(new Event("change")),i.value=!0,s.format||t.setCellData(e.rowIndex,e.colIndex,r.value))},y=(b,x)=>x&&b===0&&x>0?`${x}ch`:"inherit",E={textAlign:u.value,width:p.value,backgroundColor:i.value?"var(--cell-modified-color)":"inherit",fontWeight:i.value?"bold":"inherit",paddingLeft:y(e.colIndex,(k=t.display[e.rowIndex])==null?void 0:k.indent)};return(b,x)=>(n.openBlock(),n.createElementBlock("td",{ref:"cell","data-colindex":b.colIndex,"data-rowindex":b.rowIndex,"data-editable":n.unref(s).edit,contenteditable:n.unref(s).edit,tabindex:b.tabIndex,spellcheck:!1,style:E,onFocus:h,onPaste:g,onBlur:g,onInput:g,onClick:m,onMousedown:m,class:n.normalizeClass(["atable__cell",b.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",Ge,n.toDisplayString(c.value),1))],42,qe))}}),Ue=["tabindex"],Ye=["tabindex"],Xe=["colspan"],se=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),F([{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]=d=>n.unref(t).toggleRowExpand(i.rowIndex)),class:"row-index"},n.toDisplayString(r.value),1),n.renderSlot(i.$slots,"row")],16,Ue),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,Xe)],8,Ye)):n.createCommentVNode("",!0)],64))}}),Je=["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(a=>a.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?"-":"+":""),d=a=>{t.toggleRowExpand(a)};if(e.addNavigation){let a=z;typeof e.addNavigation=="object"&&(a={...a,...e.addNavigation}),F([{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",r.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",r.value?"sticky-index":""]),onClick:s[0]||(s[0]=f=>d(a.rowIndex))},n.toDisplayString(l.value),3)):n.createCommentVNode("",!0)]),n.renderSlot(a.$slots,"default")],8,Je)),[[n.vShow,i.value]])}});function ce(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function B(e){return typeof e=="function"?e():n.unref(e)}const de=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Qe=Object.prototype.toString,Ze=e=>Qe.call(e)==="[object Object]",R=()=>{},X=Ke();function Ke(){var e,t;return de&&((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 fe={mounted:"mounted",updated:"updated",unmounted:"unmounted"};function _e(...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 M(e){var t;const o=B(e);return(t=o==null?void 0:o.$el)!=null?t:o}const ue=de?window:void 0;function P(...e){let t,o,r,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,r,i]=e,t=ue):[t,o,r,i]=e,!t)return R;Array.isArray(o)||(o=[o]),Array.isArray(r)||(r=[r]);const l=[],d=()=>{l.forEach(u=>u()),l.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[M(t),B(i)],([u,p])=>{if(d(),!u)return;const c=Ze(p)?{...p}:p;l.push(...o.flatMap(m=>r.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return ce(f),f}let me=!1;function pe(e,t,o={}){const{window:r=ue,ignore:i=[],capture:l=!0,detectIframe:d=!1}=o;if(!r)return R;X&&!me&&(me=!0,Array.from(r.document.body.children).forEach(c=>c.addEventListener("click",R)),r.document.documentElement.addEventListener("click",R));let a=!0;const s=c=>i.some(m=>{if(typeof m=="string")return Array.from(r.document.querySelectorAll(m)).some(h=>h===c.target||c.composedPath().includes(h));{const h=M(m);return h&&(c.target===h||c.composedPath().includes(h))}}),u=[P(r,"click",c=>{const m=M(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:l}),P(r,"pointerdown",c=>{const m=M(e);a=!s(c)&&!!(m&&!c.composedPath().includes(m))},{passive:!0}),d&&P(r,"blur",c=>{setTimeout(()=>{var m;const h=M(e);((m=r.document.activeElement)==null?void 0:m.tagName)==="IFRAME"&&!(h!=null&&h.contains(r.document.activeElement))&&t(c)},0)})].filter(Boolean);return()=>u.forEach(c=>c())}const et={[fe.mounted](e,t){const o=!t.modifiers.bubble;if(typeof t.value=="function")e.__onClickOutside_stop=pe(e,t.value,{capture:o});else{const[r,i]=t.value;e.__onClickOutside_stop=pe(e,r,Object.assign({capture:o},i))}},[fe.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 he(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:he(o)}}function tt(e){const t=e||window.event,o=t.target;return he(o)?!1:t.touches.length>1?!0:(t.preventDefault&&t.preventDefault(),!1)}const Q=new WeakMap;function nt(e,t=!1){const o=n.ref(t);let r=null,i="";n.watch(_e(e),a=>{const s=J(B(a));if(s){const f=s;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 a=J(B(e));!a||o.value||(X&&(r=P(a,"touchmove",s=>{tt(s)},{passive:!1})),a.style.overflow="hidden",o.value=!0)},d=()=>{const a=J(B(e));!a||!o.value||(X&&(r==null||r()),a.style.overflow=i,Q.delete(a),o.value=!1)};return ce(d),n.computed({get(){return o.value},set(a){a?l():d()}})}function ot(){let e=!1;const t=n.ref(!1);return(o,r)=>{if(t.value=r.value,e)return;e=!0;const i=nt(o,r.value);n.watch(t,l=>i.value=l)}}ot();class we{constructor(t,o,r,i,l,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||crypto.randomUUID(),this.rows=r,this.columns=n.reactive(o),this.config=n.reactive(i),this.table=l||n.reactive(this.createTableObject()),this.display=this.createDisplayObject(d),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 lt={key:0,id:"resizable"},rt={class:"atable-header-row",tabindex:"-1"},Z=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",lt,[n.createElementVNode("tr",rt,[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(r(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)}}),K=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))}}),ye=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 we(e.id,e.columns,i,e.config);n.provide(l.id,l),n.watch(()=>l.rows,s=>{o("update:modelValue",s)},{deep:!0}),n.onMounted(()=>{e.columns.some(s=>s.pinned)&&(d(),l.config.view==="tree"&&ae(r,d,{childList:!0,subtree:!0}))});const d=()=>{const s=r.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 g of c.cells)(g.classList.contains("sticky-column")||g.classList.contains("sticky-index"))&&(g.style.left=`${m}px`,m+=g.offsetWidth,h.push(g));h.length>0&&h[h.length-1].classList.add("sticky-column-edge")}},a=s=>{var f;s.target instanceof Node&&(f=l.modal.parent)!=null&&f.contains(s.target)||l.modal.visible&&(l.modal.visible=!1)};return window.addEventListener("keydown",s=>{if(s.key==="Escape"&&l.modal.visible){l.modal.visible=!1;const f=l.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(l).config.fullWidth?"100%":"auto"})},[n.renderSlot(s.$slots,"header",{data:n.unref(l)},()=>[n.createVNode(Z,{columns:n.unref(l).columns,tableid:n.unref(l).id},null,8,["columns","tableid"])]),n.createElementVNode("tbody",null,[n.renderSlot(s.$slots,"body",{data:n.unref(l)},()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(l).rows,(u,p)=>(n.openBlock(),n.createBlock(Y,{key:u.id,row:u,rowIndex:p,tableid:n.unref(l).id},{default:n.withCtx(()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(l).columns,(c,m)=>(n.openBlock(),n.createBlock(U,{key:c.name,tableid:n.unref(l).id,col:c,spellcheck:"false",pinned:c.pinned,rowIndex:p,colIndex:m+(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(s.$slots,"footer",{data:n.unref(l)}),n.renderSlot(s.$slots,"modal",{data:n.unref(l)},()=>[n.withDirectives(n.createVNode(K,{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(et),a]])}});function it(e){e.component("ACell",U),e.component("AExpansionRow",se),e.component("ARow",Y),e.component("ATable",ye),e.component("ATableHeader",Z),e.component("ATableModal",K)}w.ACell=U,w.AExpansionRow=se,w.ARow=Y,w.ATable=ye,w.ATableHeader=Z,w.ATableModal=K,w.TableDataStore=we,w.install=it,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 dt=Object.defineProperty;var ft=(w,n,I)=>n in w?dt(w,n,{enumerable:!0,configurable:!0,writable:!0,value:I}):w[n]=I;var A=(w,n,I)=>ft(w,typeof n!="symbol"?n+"":n,I);function I(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function N(e){return typeof e=="function"?e():n.unref(e)}const be=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const ke=e=>e!=null,Ee=Object.prototype.toString,xe=e=>Ee.call(e)==="[object Object]",Ce=()=>{},D=be?window:void 0;function $(e){var t;const o=N(e);return(t=o==null?void 0:o.$el)!=null?t:o}function O(...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 Ce;Array.isArray(o)||(o=[o]),Array.isArray(r)||(r=[r]);const l=[],d=()=>{l.forEach(u=>u()),l.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[$(t),N(i)],([u,p])=>{if(d(),!u)return;const c=xe(p)?{...p}:p;l.push(...o.flatMap(m=>r.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return I(f),f}function Se(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function Ae(e){const t=Se();return n.computed(()=>(t.value,!!e()))}function Ie(e,t,o={}){const{window:r=D,...i}=o;let l;const d=Ae(()=>r&&"MutationObserver"in r),a=()=>{l&&(l.disconnect(),l=void 0)},s=n.computed(()=>{const c=N(e),m=(Array.isArray(c)?c:[c]).map($).filter(ke);return new Set(m)}),f=n.watch(()=>s.value,c=>{a(),d.value&&c.size&&(l=new MutationObserver(t),c.forEach(m=>l.observe(m,i)))},{immediate:!0,flush:"post"}),u=()=>l==null?void 0:l.takeRecords(),p=()=>{f(),a()};return I(p),{isSupported:d,stop:p,takeRecords:u}}function Te(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,d=()=>{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},a=n.ref(),s=()=>{a.value=d()};return o&&(O(o,"blur",f=>{f.relatedTarget===null&&s()},!0),O(o,"focus",s,!0)),i&&Ie(l,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 De="focusin",$e="focusout";function Oe(e,t={}){const{window:o=D}=t,r=n.computed(()=>$(e)),i=n.ref(!1),l=n.computed(()=>i.value),d=Te(t);return!o||!d.value?{focused:l}:(O(r,De,()=>i.value=!0),O(r,$e,()=>i.value=!1),{focused:l})}function Be(e,{window:t=D,scrollTarget:o}={}){const r=n.ref(!1),i=()=>{if(!t)return;const l=t.document,d=$(e);if(!d)r.value=!1;else{const a=d.getBoundingClientRect();r.value=a.top<=(t.innerHeight||l.documentElement.clientHeight)&&a.left<=(t.innerWidth||l.documentElement.clientWidth)&&a.bottom>=0&&a.right>=0}};return n.watch(()=>$(e),()=>i(),{immediate:!0,flush:"post"}),t&&O(o||t,"scroll",i,{capture:!1,passive:!0}),r}const C=e=>{let t=Be(e).value;return t=t&&e.offsetHeight>0,t},S=e=>e.tabIndex>=0,_=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&&(!S(o)||!C(o))?W(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.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&&(!S(r)||!C(r))?j(r):r},ee=e=>{const t=e.target;return j(t)},j=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&&(!S(o)||!C(o))?j(o):o},Re=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&&(!S(r)||!C(r))?W(r):r},te=e=>{const t=e.target;return H(t)},H=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&&(!S(o)||!C(o))?H(o):o},ne=e=>{const t=e.target;return V(t)},V=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&&(!S(o)||!C(o))?V(o):o},oe=e=>{const t=e.target.parentElement.firstElementChild;return t&&(!S(t)||!C(t))?V(t):t},le=e=>{const t=e.target.parentElement.lastElementChild;return t&&(!S(t)||!C(t))?H(t):t},L=["alt","control","shift","meta"],Le={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},z={"keydown.up":e=>{const t=_(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.down":e=>{const t=ee(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.left":e=>{const t=te(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.right":e=>{const t=ne(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=Re(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.left":e=>{const t=oe(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.right":e=>{const t=le(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.end":e=>{const t=le(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=ee(e);t&&t.focus()}},"keydown.shift.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const t=_(e);t&&t.focus()}},"keydown.home":e=>{const t=oe(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.tab":e=>{const t=ne(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.shift.tab":e=>{const t=te(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())}};function F(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},r=d=>{const a=t(d);let s=[];return d.selectors?s=o(d):a&&(s=Array.from(a.children).filter(f=>S(f)&&C(f))),s},i=d=>a=>{const s=Le[a.key]||a.key.toLowerCase();if(L.includes(s))return;const f=d.handlers||z;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=>L.includes(y)),b=L.some(y=>{const k=y.charAt(0).toUpperCase()+y.slice(1);return a.getModifierState(k)});if(h.length>0){if(b){for(const y of L)if(c.includes(y)){const k=y.charAt(0).toUpperCase()+y.slice(1);a.getModifierState(k)&&m(a)}}}else b||m(a)}}},l=[];n.onMounted(()=>{for(const d of e){const a=t(d),s=r(d),f=i(d),u=a?[a]:s;for(const p of u){const{focused:c}=Oe(n.ref(p)),m=n.watch(c,h=>{h?p.addEventListener("keydown",f):p.removeEventListener("keydown",f)});l.push(m)}}}),n.onBeforeUnmount(()=>{for(const d of l)d()})}function q(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function v(e){return typeof e=="function"?e():n.unref(e)}const ve=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Pe=e=>e!=null,Ne=Object.prototype.toString,We=e=>Ne.call(e)==="[object Object]",je=()=>{};function He(e){return n.getCurrentInstance()}function Ve(e,t=!0,o){He()?n.onMounted(e,o):t?e():n.nextTick(e)}const G=ve?window:void 0;function T(e){var t;const o=v(e);return(t=o==null?void 0:o.$el)!=null?t:o}function re(...e){let t,o,r,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,r,i]=e,t=G):[t,o,r,i]=e,!t)return je;Array.isArray(o)||(o=[o]),Array.isArray(r)||(r=[r]);const l=[],d=()=>{l.forEach(u=>u()),l.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[T(t),v(i)],([u,p])=>{if(d(),!u)return;const c=We(p)?{...p}:p;l.push(...o.flatMap(m=>r.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return q(f),f}function ze(){const e=n.ref(!1),t=n.getCurrentInstance();return t&&n.onMounted(()=>{e.value=!0},t),e}function ie(e){const t=ze();return n.computed(()=>(t.value,!!e()))}function ae(e,t,o={}){const{window:r=G,...i}=o;let l;const d=ie(()=>r&&"MutationObserver"in r),a=()=>{l&&(l.disconnect(),l=void 0)},s=n.computed(()=>{const c=v(e),m=(Array.isArray(c)?c:[c]).map(T).filter(Pe);return new Set(m)}),f=n.watch(()=>s.value,c=>{a(),d.value&&c.size&&(l=new MutationObserver(t),c.forEach(m=>l.observe(m,i)))},{immediate:!0,flush:"post"}),u=()=>l==null?void 0:l.takeRecords(),p=()=>{f(),a()};return q(p),{isSupported:d,stop:p,takeRecords:u}}function Fe(e,t,o={}){const{window:r=G,...i}=o;let l;const d=ie(()=>r&&"ResizeObserver"in r),a=()=>{l&&(l.disconnect(),l=void 0)},s=n.computed(()=>{const p=v(e);return Array.isArray(p)?p.map(c=>T(c)):[T(p)]}),f=n.watch(s,p=>{if(a(),d.value&&r){l=new ResizeObserver(t);for(const c of p)c&&l.observe(c,i)}},{immediate:!0,flush:"post"}),u=()=>{a(),f()};return q(u),{isSupported:d,stop:u}}function qe(e,t={}){const{reset:o=!0,windowResize:r=!0,windowScroll:i=!0,immediate:l=!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 k=T(e);if(!k){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=k.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 Fe(e,y),n.watch(()=>T(e),k=>!k&&y()),ae(e,y,{attributeFilter:["style","class"]}),i&&re("scroll",y,{capture:!0,passive:!0}),r&&re("resize",y,{passive:!0}),Ve(()=>{l&&y()}),{height:a,bottom:s,left:f,right:u,top:p,width:c,x:m,y:h,update:y}}const Ge=e=>{const t=new DOMParser().parseFromString(e,"text/html");return Array.from(t.body.childNodes).some(o=>o.nodeType===1)},Ue=["data-colindex","data-rowindex","data-editable","contenteditable","tabindex"],Ye=["innerHTML"],Xe={key:2},U=n.defineComponent({__name:"ACell",props:{colIndex:{},rowIndex:{},tableid:{},addNavigation:{type:[Boolean,Object],default:!0},tabIndex:{default:0},pinned:{type:Boolean}},setup(e){var ge;const t=n.inject(e.tableid),o=n.useTemplateRef("cell"),r=n.ref(""),i=n.ref(!1),{bottom:l,left:d}=qe(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 g=t.cellData(e.colIndex,e.rowIndex),x=s.format;return x?typeof x=="function"?x(g,{table:a,row:f,column:s}):typeof x=="string"?Function(`"use strict";return (${x})`)()(g,{table:a,row:f,column:s}):g:g}),m=n.computed(()=>typeof c.value=="string"?Ge(c.value):!1),h=()=>{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=l.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 g={...z,"keydown.f2":h,"keydown.alt.up":h,"keydown.alt.down":h,"keydown.alt.left":h,"keydown.alt.right":h};typeof e.addNavigation=="object"&&(g={...g,...e.addNavigation}),F([{selectors:o,handlers:g}])}const b=()=>{o.value&&(r.value=o.value.textContent)},y=()=>{o.value&&o.value.textContent!==r.value&&(r.value=o.value.textContent,o.value.dispatchEvent(new Event("change")),i.value=!0,s.format||t.setCellData(e.rowIndex,e.colIndex,r.value))},k=(g,x)=>x&&g===0&&x>0?`${x}ch`:"inherit",E={textAlign:u.value,width:p.value,backgroundColor:i.value?"var(--cell-modified-color)":"inherit",fontWeight:i.value?"bold":"inherit",paddingLeft:k(e.colIndex,(ge=t.display[e.rowIndex])==null?void 0:ge.indent)};return(g,x)=>(n.openBlock(),n.createElementBlock("td",{ref:"cell","data-colindex":g.colIndex,"data-rowindex":g.rowIndex,"data-editable":n.unref(s).edit,contenteditable:n.unref(s).edit,tabindex:g.tabIndex,spellcheck:!1,style:E,onFocus:b,onPaste:y,onBlur:y,onInput:y,onClick:h,onMousedown:h,class:n.normalizeClass(["atable__cell",g.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"])):m.value?(n.openBlock(),n.createElementBlock("span",{key:1,innerHTML:c.value},null,8,Ye)):(n.openBlock(),n.createElementBlock("span",Xe,n.toDisplayString(c.value),1))],42,Ue))}}),Je=["tabindex"],Qe=["tabindex"],Ze=["colspan"],se=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),F([{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]=d=>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(a=>a.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?"-":"+":""),d=a=>{t.toggleRowExpand(a)};if(e.addNavigation){let a=z;typeof e.addNavigation=="object"&&(a={...a,...e.addNavigation}),F([{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",r.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",r.value?"sticky-index":""]),onClick:s[0]||(s[0]=f=>d(a.rowIndex))},n.toDisplayString(l.value),3)):n.createCommentVNode("",!0)]),n.renderSlot(a.$slots,"default")],8,Ke)),[[n.vShow,i.value]])}});function ce(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function B(e){return typeof e=="function"?e():n.unref(e)}const de=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const _e=Object.prototype.toString,et=e=>_e.call(e)==="[object Object]",M=()=>{},X=tt();function tt(){var e,t;return de&&((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 fe={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:M}))):n.ref(t)}function R(e){var t;const o=B(e);return(t=o==null?void 0:o.$el)!=null?t:o}const ue=de?window:void 0;function P(...e){let t,o,r,i;if(typeof e[0]=="string"||Array.isArray(e[0])?([o,r,i]=e,t=ue):[t,o,r,i]=e,!t)return M;Array.isArray(o)||(o=[o]),Array.isArray(r)||(r=[r]);const l=[],d=()=>{l.forEach(u=>u()),l.length=0},a=(u,p,c,m)=>(u.addEventListener(p,c,m),()=>u.removeEventListener(p,c,m)),s=n.watch(()=>[R(t),B(i)],([u,p])=>{if(d(),!u)return;const c=et(p)?{...p}:p;l.push(...o.flatMap(m=>r.map(h=>a(u,m,h,c))))},{immediate:!0,flush:"post"}),f=()=>{s(),d()};return ce(f),f}let me=!1;function pe(e,t,o={}){const{window:r=ue,ignore:i=[],capture:l=!0,detectIframe:d=!1}=o;if(!r)return M;X&&!me&&(me=!0,Array.from(r.document.body.children).forEach(c=>c.addEventListener("click",M)),r.document.documentElement.addEventListener("click",M));let a=!0;const s=c=>i.some(m=>{if(typeof m=="string")return Array.from(r.document.querySelectorAll(m)).some(h=>h===c.target||c.composedPath().includes(h));{const h=R(m);return h&&(c.target===h||c.composedPath().includes(h))}}),u=[P(r,"click",c=>{const m=R(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:l}),P(r,"pointerdown",c=>{const m=R(e);a=!s(c)&&!!(m&&!c.composedPath().includes(m))},{passive:!0}),d&&P(r,"blur",c=>{setTimeout(()=>{var m;const h=R(e);((m=r.document.activeElement)==null?void 0:m.tagName)==="IFRAME"&&!(h!=null&&h.contains(r.document.activeElement))&&t(c)},0)})].filter(Boolean);return()=>u.forEach(c=>c())}const ot={[fe.mounted](e,t){const o=!t.modifiers.bubble;if(typeof t.value=="function")e.__onClickOutside_stop=pe(e,t.value,{capture:o});else{const[r,i]=t.value;e.__onClickOutside_stop=pe(e,r,Object.assign({capture:o},i))}},[fe.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 he(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:he(o)}}function lt(e){const t=e||window.event,o=t.target;return he(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),a=>{const s=J(B(a));if(s){const f=s;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 a=J(B(e));!a||o.value||(X&&(r=P(a,"touchmove",s=>{lt(s)},{passive:!1})),a.style.overflow="hidden",o.value=!0)},d=()=>{const a=J(B(e));!a||!o.value||(X&&(r==null||r()),a.style.overflow=i,Q.delete(a),o.value=!1)};return ce(d),n.computed({get(){return o.value},set(a){a?l():d()}})}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();class we{constructor(t,o,r,i,l,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||crypto.randomUUID(),this.rows=r,this.columns=n.reactive(o),this.config=n.reactive(i),this.table=l||n.reactive(this.createTableObject()),this.display=this.createDisplayObject(d),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 at={key:0,id:"resizable"},st={class:"atable-header-row",tabindex:"-1"},Z=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",at,[n.createElementVNode("tr",st,[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(r(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)}}),K=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))}}),ye=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 we(e.id,e.columns,i,e.config);n.provide(l.id,l),n.watch(()=>l.rows,s=>{o("update:modelValue",s)},{deep:!0}),n.onMounted(()=>{e.columns.some(s=>s.pinned)&&(d(),l.config.view==="tree"&&ae(r,d,{childList:!0,subtree:!0}))});const d=()=>{const s=r.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=l.modal.parent)!=null&&f.contains(s.target)||l.modal.visible&&(l.modal.visible=!1)};return window.addEventListener("keydown",s=>{if(s.key==="Escape"&&l.modal.visible){l.modal.visible=!1;const f=l.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(l).config.fullWidth?"100%":"auto"})},[n.renderSlot(s.$slots,"header",{data:n.unref(l)},()=>[n.createVNode(Z,{columns:n.unref(l).columns,tableid:n.unref(l).id},null,8,["columns","tableid"])]),n.createElementVNode("tbody",null,[n.renderSlot(s.$slots,"body",{data:n.unref(l)},()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(l).rows,(u,p)=>(n.openBlock(),n.createBlock(Y,{key:u.id,row:u,rowIndex:p,tableid:n.unref(l).id},{default:n.withCtx(()=>[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(l).columns,(c,m)=>(n.openBlock(),n.createBlock(U,{key:c.name,tableid:n.unref(l).id,col:c,spellcheck:"false",pinned:c.pinned,rowIndex:p,colIndex:m+(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(s.$slots,"footer",{data:n.unref(l)}),n.renderSlot(s.$slots,"modal",{data:n.unref(l)},()=>[n.withDirectives(n.createVNode(K,{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),a]])}});function ct(e){e.component("ACell",U),e.component("AExpansionRow",se),e.component("ARow",Y),e.component("ATable",ye),e.component("ATableHeader",Z),e.component("ATableModal",K)}w.ACell=U,w.AExpansionRow=se,w.ARow=Y,w.ATable=ye,w.ATableHeader=Z,w.ATableModal=K,w.TableDataStore=we,w.install=ct,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=atable.umd.cjs.map
|