@honed/table 0.1.0 → 0.2.0
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/index.d.ts +378 -0
- package/dist/index.es.js +434 -305
- package/dist/index.umd.js +1 -1
- package/package.json +11 -11
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(P,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],d):(P=typeof globalThis<"u"?globalThis:P||self,d(P["@honed/table"]={},P.Vue,P.Inertia))})(this,function(P,d,b){"use strict";function _(){const r=d.ref({all:!1,only:new Set,except:new Set});function p(){r.value.all=!0,r.value.only.clear(),r.value.except.clear()}function f(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function l(...s){s.forEach(m=>r.value.except.delete(m)),s.forEach(m=>r.value.only.add(m))}function i(...s){s.forEach(m=>r.value.except.add(m)),s.forEach(m=>r.value.only.delete(m))}function u(s,m){if(x(s)||m===!1)return i(s);if(!x(s)||m===!0)return l(s)}function x(s){return r.value.all?!r.value.except.has(s):r.value.only.has(s)}const v=d.computed(()=>r.value.all&&r.value.except.size===0),A=d.computed(()=>r.value.only.size>0||v.value);function S(s){return{"onUpdate:modelValue":m=>{m?l(s):i(s)},modelValue:x(s),value:s}}function k(){return{"onUpdate:modelValue":s=>{s?p():f()},modelValue:v.value,value:v.value}}return{allSelected:v,selection:r,hasSelected:A,selectAll:p,deselectAll:f,select:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function H(r,p,f={},l={}){return r.route?(b.router.visit(r.route.href,{...l,method:r.route.method}),!0):r.action&&p?(b.router.post(p,{...f,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,p){function f(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>p.apply(this,l),{fn:p,thisArg:this,args:l})).then(i).catch(u)})}return f}function X(r,p={}){let f,l,i=Y;const u=v=>{clearTimeout(v),i(),i=Y};let x;return v=>{const A=d.toValue(r),S=d.toValue(p.maxWait);return f&&u(f),A<=0||S!==void 0&&S<=0?(l&&(u(l),l=null),Promise.resolve(v())):new Promise((k,s)=>{i=p.rejectOnCancel?s:k,x=v,S&&!l&&(l=setTimeout(()=>{f&&u(f),l=null,k(x())},S)),f=setTimeout(()=>{l&&u(l),l=null,k(v())},A)})}}function R(r,p=200,f={}){return Q(X(p,f),r)}function Z(r,p,f={}){const l=d.computed(()=>r[p]),i=d.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,c={})=>T(n,o,c),clear:(o={})=>G(n,o),bind:()=>h(n.name)})))??[]}),u=d.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>M(n,n.direction,o),clear:(o={})=>B(o),bind:()=>V(n)})))??[]}),x=d.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>E(n,o),clear:(o={})=>E(n,o),bind:()=>I(n)}))});function v(e){return Array.isArray(e)?e.join(l.value.config.delimiter):e}function A(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function S(e){if(!["",null,void 0,[]].includes(e))return e}function k(e){return[v,A,S].reduce((n,o)=>o(n),e)}function s(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(o=>o!==e):[...n,e]}function m(e){var n;return(n=l.value.filters)==null?void 0:n.find(o=>o.name===e)}function C(e,n=null){var o;return(o=l.value.sorts)==null?void 0:o.find(c=>c.name===e&&c.direction===n)}function W(e){var n;return(n=l.value.searches)==null?void 0:n.find(o=>o.name===e)}function q(){var e;return((e=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}function g(){var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}function w(){var e;return((e=l.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]}function y(e){return e?typeof e=="string"?q().some(n=>n.name===e):e.active:!!q().length}function L(e){var n;return e?typeof e=="string"?((n=g())==null?void 0:n.name)===e:e.active:!!g()}function j(e){var n,o;return e?typeof e=="string"?(o=w())==null?void 0:o.some(c=>c.name===e):e.active:!!((n=w())!=null&&n.length)}function D(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([c,F])=>[c,k(F)]));b.router.reload({...f,...n,data:o})}function T(e,n,o={}){const c=typeof e=="string"?m(e):e;if(!c){console.warn(`Filter [${e}] does not exist.`);return}"multiple"in c&&c.multiple&&(n=s(n,c.value)),b.router.reload({...f,...o,data:{[c.name]:k(n)}})}function M(e,n=null,o={}){const c=typeof e=="string"?C(e,n):e;if(!c){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...f,...o,data:{[l.value.config.sorts]:S(c.next)}})}function z(e,n={}){e=[A,S].reduce((o,c)=>c(o),e),b.router.reload({...f,...n,data:{[l.value.config.searches]:e}})}function E(e,n={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}if(!(typeof e=="string"?W(e):e)){console.warn(`Match [${e}] does not exist.`);return}const o=s(e,w().filter(({active:c})=>c).map(({name:c})=>c));b.router.reload({...f,...n,data:{[l.value.config.matches]:v(o)}})}function G(e,n={}){T(e,void 0,n)}function B(e={}){b.router.reload({...f,...e,data:{[l.value.config.sorts]:null}})}function J(e={}){z(void 0,e)}function t(e={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}b.router.reload({...f,...e,data:{[l.value.config.matches]:null}})}function a(e={}){var n;b.router.reload({...f,...e,data:{[l.value.config.searches]:void 0,[l.value.config.sorts]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[]),...l.value.config.matches?{[l.value.config.matches]:void 0}:{}}})}function h(e,n={}){const o=typeof e=="string"?m(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const c=o.value,{debounce:F=250,transform:K=N=>N,...U}=n;return{"onUpdate:modelValue":R(N=>{T(o,K(N),U)},F),modelValue:c,value:c}}function V(e,n={}){const o=typeof e=="string"?C(e):e;if(!o){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:c=0,transform:F,...K}=n;return{onClick:R(()=>{var U;M(o,(U=g())==null?void 0:U.direction,K)},c)}}function $(e={}){const{debounce:n=700,transform:o,...c}=e;return{"onUpdate:modelValue":R(F=>{z(F,c)},n),modelValue:l.value.config.search??"",value:l.value.config.search??""}}function I(e,n={}){const o=typeof e=="string"?W(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const{debounce:c=0,transform:F,...K}=n;return{"onUpdate:modelValue":R(U=>{E(U,K)},c),modelValue:j(o),value:j(o)}}return{filters:i,sorts:u,searches:x,getFilter:m,getSort:C,getSearch:W,currentFilters:q,currentSort:g,currentSearches:w,isFiltering:y,isSorting:L,isSearching:j,apply:D,applyFilter:T,applySort:M,applySearch:z,applyMatch:E,clearFilter:G,clearSort:B,clearSearch:J,clearMatch:t,reset:a,bindFilter:h,bindSort:V,bindSearch:$,bindMatch:I,stringValue:A,omitValue:S,toggleValue:s,delimitArray:v}}function O(r,p,f={},l={}){l={...l,only:[...l.only??[],p.toString()]};const i=d.computed(()=>r[p]),u=_(),x=Z(r,p,l),v=d.computed(()=>i.value.config),A=d.computed(()=>i.value.meta),S=d.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:a,hidden:h})=>a&&!h).map(a=>{var h;return{...a,isSorting:(h=a.sort)==null?void 0:h.active,toggleSort:(V={})=>z(a,V)}}))??[]}),k=d.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(h={})=>E(a,h)})))??[]}),s=d.computed(()=>i.value.records.map(t=>({...t,default:(a={})=>{const h=t.actions.find(V=>V.default);h&&j(h,t,a)},actions:t.actions.map(a=>({...a,execute:(h={})=>j(a,t,h)})),select:()=>u.select(y(t)),deselect:()=>u.deselect(y(t)),toggle:()=>u.toggle(y(t)),selected:u.selected(y(t)),bind:()=>u.bind(y(t))}))),m=d.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>D(t,a)}))),C=d.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>T(t,a)}))),W=d.computed(()=>i.value.recordsPerPage.map(t=>({...t,apply:(a={})=>M(t,a)}))),q=d.computed(()=>i.value.recordsPerPage.find(({active:t})=>t)),g=d.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in g.value&&g.value.nextLink&&L(g.value.nextLink,t)},previous:(t={})=>{"prevLink"in g.value&&g.value.prevLink&&L(g.value.prevLink,t)},first:(t={})=>{"firstLink"in g.value&&g.value.firstLink&&L(g.value.firstLink,t)},last:(t={})=>{"lastLink"in g.value&&g.value.lastLink&&L(g.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(a={})=>t.url&&L(t.url,a)}))}:{}})),w=d.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[v.value.record]}function L(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function j(t,a,h={}){var $,I;H(t,v.value.endpoint,{table:i.value.id,id:y(a)},h)||(I=($=f.recordActions)==null?void 0:$[t.name])==null||I.call($,a)}function D(t,a={}){H(t,v.value.endpoint,{table:i.value.id,all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},a)}function T(t,a={}){H(t,v.value.endpoint,{table:i.value.id},a)}function M(t,a={}){b.router.reload({...l,...a,data:{[v.value.records]:t.value,[v.value.pages]:void 0}})}function z(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[v.value.sorts]:x.omitValue(t.sort.next)}})}function E(t,a={}){const h=x.toggleValue(t.name,S.value.map(({name:V})=>V));b.router.reload({...l,...a,data:{[v.value.columns]:x.delimitArray(h)}})}function G(){u.select(...i.value.records.map(t=>y(t)))}function B(){u.deselect(...i.value.records.map(t=>y(t)))}function J(){return{"onUpdate:modelValue":t=>{t?G():B()},modelValue:w.value}}return d.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:s,bulkActions:m,pageActions:C,rowsPerPage:W,currentPage:q,paginator:g,executeInlineAction:j,executeBulkAction:D,executePageAction:T,applyPage:M,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:G,deselectPage:B,toggle:t=>u.toggle(y(t)),selected:t=>u.selected(y(t)),selectAll:u.selectAll,deselectAll:u.deselectAll,isPageSelected:w,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:J,bindAll:u.bindAll,...x})}P.useTable=O,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@honed/table",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "-",
|
|
7
7
|
"keywords": [
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"
|
|
52
|
-
"@
|
|
51
|
+
"@honed/action": "^0.2.0",
|
|
52
|
+
"@honed/refine": "^0.2.1",
|
|
53
53
|
"@inertiajs/vue3": "^1.2.0||^2.0.0",
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
56
|
-
"
|
|
54
|
+
"@vueuse/core": "^11.0.0||^12.0.0",
|
|
55
|
+
"axios": "^1.2.0",
|
|
56
|
+
"vue": "^3.4.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@biomejs/biome": "1.9.4",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
"axios": "^1.2.0",
|
|
63
63
|
"jsdom": "^25.0.1",
|
|
64
64
|
"typescript": "~5.4.0",
|
|
65
|
-
"vite": "^
|
|
66
|
-
"vite-plugin-dts": "^4.3
|
|
67
|
-
"vitest": "^
|
|
68
|
-
"vue-tsc": "^2.
|
|
65
|
+
"vite": "^6.2.1",
|
|
66
|
+
"vite-plugin-dts": "^4.5.3",
|
|
67
|
+
"vitest": "^3.0.8",
|
|
68
|
+
"vue-tsc": "^2.2.8"
|
|
69
69
|
}
|
|
70
|
-
}
|
|
70
|
+
}
|