@honed/table 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Joshua Wallace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ export { }
@@ -0,0 +1,535 @@
1
+ import { ref as D, computed as p, toValue as R, reactive as _ } from "vue";
2
+ import { router as S } from "@inertiajs/vue3";
3
+ function H() {
4
+ const a = D({
5
+ all: !1,
6
+ only: /* @__PURE__ */ new Set(),
7
+ except: /* @__PURE__ */ new Set()
8
+ });
9
+ function v() {
10
+ a.value.all = !0, a.value.only.clear(), a.value.except.clear();
11
+ }
12
+ function s() {
13
+ a.value.all = !1, a.value.only.clear(), a.value.except.clear();
14
+ }
15
+ function l(...u) {
16
+ u.forEach((d) => a.value.except.delete(d)), u.forEach((d) => a.value.only.add(d));
17
+ }
18
+ function o(...u) {
19
+ u.forEach((d) => a.value.except.add(d)), u.forEach((d) => a.value.only.delete(d));
20
+ }
21
+ function i(u, d) {
22
+ if (h(u) || d === !1)
23
+ return o(u);
24
+ if (!h(u) || d === !0)
25
+ return l(u);
26
+ }
27
+ function h(u) {
28
+ return a.value.all ? !a.value.except.has(u) : a.value.only.has(u);
29
+ }
30
+ const f = p(() => a.value.all && a.value.except.size === 0), y = p(() => a.value.only.size > 0 || f.value);
31
+ function x(u) {
32
+ return {
33
+ "onUpdate:modelValue": (d) => {
34
+ console.log("Checked:", d), d ? l(u) : o(u);
35
+ },
36
+ modelValue: h(u),
37
+ value: u
38
+ };
39
+ }
40
+ function b() {
41
+ return {
42
+ "onUpdate:modelValue": (u) => {
43
+ console.log("Checked:", u), u ? v() : s();
44
+ },
45
+ modelValue: f.value
46
+ };
47
+ }
48
+ return {
49
+ allSelected: f,
50
+ selection: a,
51
+ hasSelected: y,
52
+ selectAll: v,
53
+ deselectAll: s,
54
+ select: l,
55
+ deselect: o,
56
+ toggle: i,
57
+ selected: h,
58
+ bind: x,
59
+ bindAll: b
60
+ };
61
+ }
62
+ function I(a, v, s = {}, l = {}) {
63
+ return a.route ? (S.visit(a.route.href, {
64
+ ...l,
65
+ method: a.route.method
66
+ }), !0) : a.action && v ? (S.post(
67
+ v,
68
+ {
69
+ ...s,
70
+ name: a.name,
71
+ type: a.type
72
+ },
73
+ l
74
+ ), !0) : !1;
75
+ }
76
+ typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
77
+ const q = () => {
78
+ };
79
+ function J(a, v) {
80
+ function s(...l) {
81
+ return new Promise((o, i) => {
82
+ Promise.resolve(a(() => v.apply(this, l), { fn: v, thisArg: this, args: l })).then(o).catch(i);
83
+ });
84
+ }
85
+ return s;
86
+ }
87
+ function M(a, v = {}) {
88
+ let s, l, o = q;
89
+ const i = (f) => {
90
+ clearTimeout(f), o(), o = q;
91
+ };
92
+ let h;
93
+ return (f) => {
94
+ const y = R(a), x = R(v.maxWait);
95
+ return s && i(s), y <= 0 || x !== void 0 && x <= 0 ? (l && (i(l), l = null), Promise.resolve(f())) : new Promise((b, u) => {
96
+ o = v.rejectOnCancel ? u : b, h = f, x && !l && (l = setTimeout(() => {
97
+ s && i(s), l = null, b(h());
98
+ }, x)), s = setTimeout(() => {
99
+ l && i(l), l = null, b(f());
100
+ }, y);
101
+ });
102
+ };
103
+ }
104
+ function K(a, v = 200, s = {}) {
105
+ return J(
106
+ M(v, s),
107
+ a
108
+ );
109
+ }
110
+ function N(a, v, s = {}) {
111
+ const l = p(() => a[v]), o = p(
112
+ () => l.value.filters.map((e) => ({
113
+ ...e,
114
+ apply: (n, r = {}) => P(e, n, r),
115
+ clear: (n = {}) => U(e, n),
116
+ bind: () => C(e.name)
117
+ }))
118
+ ), i = p(
119
+ () => l.value.sorts.map((e) => ({
120
+ ...e,
121
+ apply: (n = {}) => w(e, e.direction, n),
122
+ clear: (n = {}) => $(n),
123
+ bind: () => z(e)
124
+ }))
125
+ );
126
+ function h(e) {
127
+ return Array.isArray(e) ? e.join(l.value.config.delimiter) : e;
128
+ }
129
+ function f(e) {
130
+ return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
131
+ }
132
+ function y(e) {
133
+ if (!["", null, void 0, []].includes(e))
134
+ return e;
135
+ }
136
+ function x(e, n) {
137
+ return n = Array.isArray(n) ? n : [n], n.includes(e) ? n.filter((r) => r !== e) : [...n, e];
138
+ }
139
+ function b(e, n = null) {
140
+ return l.value.sorts.find(
141
+ (r) => r.name === e && r.direction === n
142
+ );
143
+ }
144
+ function u(e) {
145
+ return l.value.filters.find((n) => n.name === e);
146
+ }
147
+ function d(e) {
148
+ var n;
149
+ return (n = l.value.searches) == null ? void 0 : n.find((r) => r.name === e);
150
+ }
151
+ function V() {
152
+ return l.value.sorts.find(({ active: e }) => e);
153
+ }
154
+ function L() {
155
+ return l.value.filters.filter(({ active: e }) => e);
156
+ }
157
+ function m() {
158
+ var e;
159
+ return ((e = l.value.searches) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
160
+ }
161
+ function T(e) {
162
+ var n;
163
+ return e ? ((n = V()) == null ? void 0 : n.name) === e : !!V();
164
+ }
165
+ function g(e) {
166
+ return e ? L().some((n) => n.name === e) : !!L().length;
167
+ }
168
+ function A(e) {
169
+ var n, r;
170
+ return e ? (n = m()) == null ? void 0 : n.some((c) => c.name === e) : !!((r = m()) != null && r.length);
171
+ }
172
+ function P(e, n, r = {}) {
173
+ const c = typeof e == "string" ? u(e) : e;
174
+ if (!c) {
175
+ console.warn(`Filter [${e}] does not exist.`);
176
+ return;
177
+ }
178
+ "multiple" in c && c.multiple && (n = x(n, c.value)), n = [h, f, y].reduce(
179
+ (k, E) => E(k),
180
+ n
181
+ ), console.log(n), S.reload({
182
+ ...s,
183
+ ...r,
184
+ data: {
185
+ [c.name]: n
186
+ }
187
+ });
188
+ }
189
+ function w(e, n = null, r = {}) {
190
+ const c = typeof e == "string" ? b(e, n) : e;
191
+ if (!c) {
192
+ console.warn(`Sort [${e}] does not exist.`);
193
+ return;
194
+ }
195
+ S.reload({
196
+ ...s,
197
+ ...r,
198
+ data: {
199
+ [l.value.config.sorts]: y(c.next)
200
+ }
201
+ });
202
+ }
203
+ function F(e, n = {}) {
204
+ e = [f, y].reduce(
205
+ (r, c) => c(r),
206
+ e
207
+ ), S.reload({
208
+ ...s,
209
+ ...n,
210
+ data: {
211
+ [l.value.config.searches]: e
212
+ }
213
+ });
214
+ }
215
+ function U(e, n = {}) {
216
+ P(e, void 0, n);
217
+ }
218
+ function $(e = {}) {
219
+ S.reload({
220
+ ...s,
221
+ ...e,
222
+ data: {
223
+ [l.value.config.sorts]: null
224
+ }
225
+ });
226
+ }
227
+ function B(e = {}) {
228
+ F(void 0, e);
229
+ }
230
+ function j(e = {}) {
231
+ S.reload({
232
+ ...s,
233
+ ...e,
234
+ data: {
235
+ [l.value.config.searches]: void 0,
236
+ [l.value.config.sorts]: void 0,
237
+ ...Object.fromEntries(
238
+ l.value.filters.map((n) => [n.name, void 0])
239
+ ),
240
+ ...l.value.config.matches ? { [l.value.config.matches]: void 0 } : {}
241
+ }
242
+ });
243
+ }
244
+ function C(e, n = {}) {
245
+ const r = typeof e == "string" ? u(e) : e;
246
+ if (!r) {
247
+ console.warn(`Filter [${e}] does not exist.`);
248
+ return;
249
+ }
250
+ const c = r.value, {
251
+ debounce: k = 250,
252
+ transform: E = (G) => G,
253
+ ...W
254
+ } = n;
255
+ return {
256
+ "onUpdate:modelValue": K((G) => {
257
+ P(r, E(G), W);
258
+ }, k),
259
+ modelValue: c,
260
+ value: c
261
+ };
262
+ }
263
+ function z(e, n = {}) {
264
+ const r = typeof e == "string" ? b(e) : e;
265
+ if (!r) {
266
+ console.warn(`Sort [${e}] does not exist.`);
267
+ return;
268
+ }
269
+ const { debounce: c = 0, transform: k, ...E } = n;
270
+ return {
271
+ onClick: K(() => {
272
+ var W;
273
+ w(r, (W = V()) == null ? void 0 : W.direction, E);
274
+ }, c)
275
+ };
276
+ }
277
+ function t(e = {}) {
278
+ const { debounce: n = 700, transform: r, ...c } = e;
279
+ return {
280
+ "onUpdate:modelValue": K((k) => {
281
+ F(k, c);
282
+ }, n),
283
+ modelValue: l.value.config.search ?? ""
284
+ };
285
+ }
286
+ return {
287
+ // refinements,
288
+ filters: o,
289
+ sorts: i,
290
+ // searches,
291
+ getSort: b,
292
+ getFilter: u,
293
+ getSearch: d,
294
+ currentSort: V,
295
+ currentFilters: L,
296
+ currentSearches: m,
297
+ isSorting: T,
298
+ isFiltering: g,
299
+ isSearching: A,
300
+ applyFilter: P,
301
+ applySort: w,
302
+ applySearch: F,
303
+ clearFilter: U,
304
+ clearSort: $,
305
+ clearSearch: B,
306
+ reset: j,
307
+ bindFilter: C,
308
+ bindSort: z,
309
+ // bindMatch,
310
+ bindSearch: t,
311
+ /** Provide the helpers */
312
+ stringValue: f,
313
+ omitValue: y,
314
+ toggleValue: x,
315
+ delimitArray: h
316
+ };
317
+ }
318
+ function Y(a, v, s = {}, l = {}) {
319
+ l = {
320
+ ...l,
321
+ only: [...l.only ?? [], v.toString()]
322
+ };
323
+ const o = p(() => a[v]), i = H(), h = N(a, v, l), f = p(() => o.value.config), y = p(
324
+ () => o.value.columns.filter(({ active: t, hidden: e }) => t && !e).map((t) => ({
325
+ ...t,
326
+ applySort: (e = {}) => $(t, e)
327
+ }))
328
+ ), x = p(
329
+ () => o.value.columns.filter(({ hidden: t }) => !t).map((t) => ({
330
+ ...t,
331
+ toggleColumn: (e = {}) => B(t, e)
332
+ }))
333
+ ), b = p(
334
+ () => o.value.records.map((t) => ({
335
+ ...t,
336
+ /** Perform this action when the record is clicked */
337
+ default: (e = {}) => {
338
+ const n = t.actions.find(
339
+ (r) => r.default
340
+ );
341
+ n && P(n, t, e);
342
+ },
343
+ /** The actions available for the record */
344
+ actions: t.actions.map((e) => ({
345
+ ...e,
346
+ /** Executes this action */
347
+ execute: (n = {}) => P(e, t, n)
348
+ })),
349
+ /** Selects this record */
350
+ select: () => i.select(g(t)),
351
+ /** Deselects this record */
352
+ deselect: () => i.deselect(g(t)),
353
+ /** Toggles the selection of this record */
354
+ toggle: () => i.toggle(g(t)),
355
+ /** Determine if the record is selected */
356
+ selected: i.selected(g(t)),
357
+ /** Bind the record to a checkbox */
358
+ bind: () => i.bind(g(t))
359
+ }))
360
+ ), u = p(
361
+ () => o.value.actions.bulk.map((t) => ({
362
+ ...t,
363
+ /** Executes this bulk action */
364
+ execute: (e = {}) => w(t, e)
365
+ }))
366
+ ), d = p(
367
+ () => o.value.actions.page.map((t) => ({
368
+ ...t,
369
+ /** Executes this page action */
370
+ execute: (e = {}) => F(t, e)
371
+ }))
372
+ ), V = p(
373
+ () => o.value.recordsPerPage.map((t) => ({
374
+ ...t,
375
+ /** Changes the number of records to display per page */
376
+ apply: (e = {}) => U(t, e)
377
+ }))
378
+ ), L = p(
379
+ () => o.value.recordsPerPage.find(({ active: t }) => t)
380
+ ), m = p(() => ({
381
+ ...o.value.paginator,
382
+ next: (t = {}) => {
383
+ "nextLink" in m.value && m.value.nextLink && A(m.value.nextLink, t);
384
+ },
385
+ previous: (t = {}) => {
386
+ "prevLink" in m.value && m.value.prevLink && A(m.value.prevLink, t);
387
+ },
388
+ first: (t = {}) => {
389
+ "firstLink" in m.value && m.value.firstLink && A(m.value.firstLink, t);
390
+ },
391
+ last: (t = {}) => {
392
+ "lastLink" in m.value && m.value.lastLink && A(m.value.lastLink, t);
393
+ },
394
+ ..."links" in o.value.paginator && o.value.paginator.links ? {
395
+ links: o.value.paginator.links.map((t) => ({
396
+ ...t,
397
+ navigate: (e = {}) => t.url && A(t.url, e)
398
+ }))
399
+ } : {}
400
+ })), T = p(
401
+ () => o.value.records.length > 0 && o.value.records.every(
402
+ (t) => i.selected(g(t))
403
+ )
404
+ );
405
+ function g(t) {
406
+ return t[f.value.record];
407
+ }
408
+ function A(t, e = {}) {
409
+ S.visit(t, {
410
+ ...l,
411
+ ...e,
412
+ preserveState: !0,
413
+ method: "get"
414
+ });
415
+ }
416
+ function P(t, e, n = {}) {
417
+ var c, k;
418
+ I(
419
+ t,
420
+ f.value.endpoint,
421
+ {
422
+ table: o.value.id,
423
+ id: g(e)
424
+ },
425
+ n
426
+ ) || (k = (c = s.recordActions) == null ? void 0 : c[t.name]) == null || k.call(c, e);
427
+ }
428
+ function w(t, e = {}) {
429
+ I(
430
+ t,
431
+ f.value.endpoint,
432
+ {
433
+ table: o.value.id,
434
+ all: i.selection.value.all,
435
+ only: Array.from(i.selection.value.only),
436
+ except: Array.from(i.selection.value.except)
437
+ },
438
+ e
439
+ );
440
+ }
441
+ function F(t, e = {}) {
442
+ I(
443
+ t,
444
+ f.value.endpoint,
445
+ {
446
+ table: o.value.id
447
+ },
448
+ e
449
+ );
450
+ }
451
+ function U(t, e = {}) {
452
+ S.reload({
453
+ ...l,
454
+ ...e,
455
+ data: {
456
+ [f.value.records]: t.value,
457
+ [f.value.pages]: void 0
458
+ }
459
+ });
460
+ }
461
+ function $(t, e = {}) {
462
+ t.sort && S.reload({
463
+ ...l,
464
+ ...e,
465
+ data: {
466
+ [f.value.sorts]: h.omitValue(t.sort.next)
467
+ }
468
+ });
469
+ }
470
+ function B(t, e = {}) {
471
+ const n = h.toggleValue(
472
+ t.name,
473
+ y.value.map(({ name: r }) => r)
474
+ );
475
+ S.reload({
476
+ ...l,
477
+ ...e,
478
+ data: {
479
+ [f.value.columns]: h.delimitArray(n)
480
+ }
481
+ });
482
+ }
483
+ function j() {
484
+ i.select(
485
+ ...o.value.records.map((t) => g(t))
486
+ );
487
+ }
488
+ function C() {
489
+ i.deselect(
490
+ ...o.value.records.map((t) => g(t))
491
+ );
492
+ }
493
+ function z() {
494
+ return {
495
+ "onUpdate:modelValue": (t) => {
496
+ t ? j() : C();
497
+ },
498
+ modelValue: T.value
499
+ };
500
+ }
501
+ return _({
502
+ headings: y,
503
+ columns: x,
504
+ records: b,
505
+ bulkActions: u,
506
+ pageActions: d,
507
+ rowsPerPage: V,
508
+ currentPage: L,
509
+ paginator: m,
510
+ isPageSelected: T,
511
+ selectPage: j,
512
+ deselectPage: C,
513
+ /** The current selection of records */
514
+ selection: i.selection,
515
+ /** Select the given records */
516
+ select: (t) => i.select(g(t)),
517
+ /** Deselect the given records */
518
+ deselect: (t) => i.deselect(g(t)),
519
+ /** Toggle the selection of the given records */
520
+ toggle: (t) => i.toggle(g(t)),
521
+ /** Determine if the given record is selected */
522
+ selected: (t) => i.selected(g(t)),
523
+ /** Determine if any records are selected */
524
+ hasSelected: i.hasSelected,
525
+ /** Bind the select all checkbox to the current page */
526
+ bindPage: z,
527
+ /** Bind the given record to a checkbox */
528
+ bind: (t) => i.bind(g(t)),
529
+ /** Include the sorts, filters, and search query */
530
+ ...h
531
+ });
532
+ }
533
+ export {
534
+ Y as useTable
535
+ };
@@ -0,0 +1 @@
1
+ (function(A,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],c):(A=typeof globalThis<"u"?globalThis:A||self,c(A["@honed/table"]={},A.Vue,A.Inertia))})(this,function(A,c,b){"use strict";function D(){const o=c.ref({all:!1,only:new Set,except:new Set});function v(){o.value.all=!0,o.value.only.clear(),o.value.except.clear()}function d(){o.value.all=!1,o.value.only.clear(),o.value.except.clear()}function l(...u){u.forEach(p=>o.value.except.delete(p)),u.forEach(p=>o.value.only.add(p))}function a(...u){u.forEach(p=>o.value.except.add(p)),u.forEach(p=>o.value.only.delete(p))}function i(u,p){if(h(u)||p===!1)return a(u);if(!h(u)||p===!0)return l(u)}function h(u){return o.value.all?!o.value.except.has(u):o.value.only.has(u)}const f=c.computed(()=>o.value.all&&o.value.except.size===0),y=c.computed(()=>o.value.only.size>0||f.value);function x(u){return{"onUpdate:modelValue":p=>{console.log("Checked:",p),p?l(u):a(u)},modelValue:h(u),value:u}}function S(){return{"onUpdate:modelValue":u=>{console.log("Checked:",u),u?v():d()},modelValue:f.value}}return{allSelected:f,selection:o,hasSelected:y,selectAll:v,deselectAll:d,select:l,deselect:a,toggle:i,selected:h,bind:x,bindAll:S}}function W(o,v,d={},l={}){return o.route?(b.router.visit(o.route.href,{...l,method:o.route.method}),!0):o.action&&v?(b.router.post(v,{...d,name:o.name,type:o.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const R=()=>{};function M(o,v){function d(...l){return new Promise((a,i)=>{Promise.resolve(o(()=>v.apply(this,l),{fn:v,thisArg:this,args:l})).then(a).catch(i)})}return d}function _(o,v={}){let d,l,a=R;const i=f=>{clearTimeout(f),a(),a=R};let h;return f=>{const y=c.toValue(o),x=c.toValue(v.maxWait);return d&&i(d),y<=0||x!==void 0&&x<=0?(l&&(i(l),l=null),Promise.resolve(f())):new Promise((S,u)=>{a=v.rejectOnCancel?u:S,h=f,x&&!l&&(l=setTimeout(()=>{d&&i(d),l=null,S(h())},x)),d=setTimeout(()=>{l&&i(l),l=null,S(f())},y)})}}function B(o,v=200,d={}){return M(_(v,d),o)}function H(o,v,d={}){const l=c.computed(()=>o[v]),a=c.computed(()=>l.value.filters.map(e=>({...e,apply:(n,r={})=>V(e,n,r),clear:(n={})=>U(e,n),bind:()=>j(e.name)}))),i=c.computed(()=>l.value.sorts.map(e=>({...e,apply:(n={})=>T(e,e.direction,n),clear:(n={})=>$(n),bind:()=>z(e)})));function h(e){return Array.isArray(e)?e.join(l.value.config.delimiter):e}function f(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function y(e){if(!["",null,void 0,[]].includes(e))return e}function x(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(r=>r!==e):[...n,e]}function S(e,n=null){return l.value.sorts.find(r=>r.name===e&&r.direction===n)}function u(e){return l.value.filters.find(n=>n.name===e)}function p(e){var n;return(n=l.value.searches)==null?void 0:n.find(r=>r.name===e)}function L(){return l.value.sorts.find(({active:e})=>e)}function w(){return l.value.filters.filter(({active:e})=>e)}function m(){var e;return((e=l.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]}function E(e){var n;return e?((n=L())==null?void 0:n.name)===e:!!L()}function g(e){return e?w().some(n=>n.name===e):!!w().length}function P(e){var n,r;return e?(n=m())==null?void 0:n.some(s=>s.name===e):!!((r=m())!=null&&r.length)}function V(e,n,r={}){const s=typeof e=="string"?u(e):e;if(!s){console.warn(`Filter [${e}] does not exist.`);return}"multiple"in s&&s.multiple&&(n=x(n,s.value)),n=[h,f,y].reduce((k,C)=>C(k),n),console.log(n),b.router.reload({...d,...r,data:{[s.name]:n}})}function T(e,n=null,r={}){const s=typeof e=="string"?S(e,n):e;if(!s){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...d,...r,data:{[l.value.config.sorts]:y(s.next)}})}function F(e,n={}){e=[f,y].reduce((r,s)=>s(r),e),b.router.reload({...d,...n,data:{[l.value.config.searches]:e}})}function U(e,n={}){V(e,void 0,n)}function $(e={}){b.router.reload({...d,...e,data:{[l.value.config.sorts]:null}})}function G(e={}){F(void 0,e)}function q(e={}){b.router.reload({...d,...e,data:{[l.value.config.searches]:void 0,[l.value.config.sorts]:void 0,...Object.fromEntries(l.value.filters.map(n=>[n.name,void 0])),...l.value.config.matches?{[l.value.config.matches]:void 0}:{}}})}function j(e,n={}){const r=typeof e=="string"?u(e):e;if(!r){console.warn(`Filter [${e}] does not exist.`);return}const s=r.value,{debounce:k=250,transform:C=K=>K,...I}=n;return{"onUpdate:modelValue":B(K=>{V(r,C(K),I)},k),modelValue:s,value:s}}function z(e,n={}){const r=typeof e=="string"?S(e):e;if(!r){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:s=0,transform:k,...C}=n;return{onClick:B(()=>{var I;T(r,(I=L())==null?void 0:I.direction,C)},s)}}function t(e={}){const{debounce:n=700,transform:r,...s}=e;return{"onUpdate:modelValue":B(k=>{F(k,s)},n),modelValue:l.value.config.search??""}}return{filters:a,sorts:i,getSort:S,getFilter:u,getSearch:p,currentSort:L,currentFilters:w,currentSearches:m,isSorting:E,isFiltering:g,isSearching:P,applyFilter:V,applySort:T,applySearch:F,clearFilter:U,clearSort:$,clearSearch:G,reset:q,bindFilter:j,bindSort:z,bindSearch:t,stringValue:f,omitValue:y,toggleValue:x,delimitArray:h}}function J(o,v,d={},l={}){l={...l,only:[...l.only??[],v.toString()]};const a=c.computed(()=>o[v]),i=D(),h=H(o,v,l),f=c.computed(()=>a.value.config),y=c.computed(()=>a.value.columns.filter(({active:t,hidden:e})=>t&&!e).map(t=>({...t,applySort:(e={})=>$(t,e)}))),x=c.computed(()=>a.value.columns.filter(({hidden:t})=>!t).map(t=>({...t,toggleColumn:(e={})=>G(t,e)}))),S=c.computed(()=>a.value.records.map(t=>({...t,default:(e={})=>{const n=t.actions.find(r=>r.default);n&&V(n,t,e)},actions:t.actions.map(e=>({...e,execute:(n={})=>V(e,t,n)})),select:()=>i.select(g(t)),deselect:()=>i.deselect(g(t)),toggle:()=>i.toggle(g(t)),selected:i.selected(g(t)),bind:()=>i.bind(g(t))}))),u=c.computed(()=>a.value.actions.bulk.map(t=>({...t,execute:(e={})=>T(t,e)}))),p=c.computed(()=>a.value.actions.page.map(t=>({...t,execute:(e={})=>F(t,e)}))),L=c.computed(()=>a.value.recordsPerPage.map(t=>({...t,apply:(e={})=>U(t,e)}))),w=c.computed(()=>a.value.recordsPerPage.find(({active:t})=>t)),m=c.computed(()=>({...a.value.paginator,next:(t={})=>{"nextLink"in m.value&&m.value.nextLink&&P(m.value.nextLink,t)},previous:(t={})=>{"prevLink"in m.value&&m.value.prevLink&&P(m.value.prevLink,t)},first:(t={})=>{"firstLink"in m.value&&m.value.firstLink&&P(m.value.firstLink,t)},last:(t={})=>{"lastLink"in m.value&&m.value.lastLink&&P(m.value.lastLink,t)},..."links"in a.value.paginator&&a.value.paginator.links?{links:a.value.paginator.links.map(t=>({...t,navigate:(e={})=>t.url&&P(t.url,e)}))}:{}})),E=c.computed(()=>a.value.records.length>0&&a.value.records.every(t=>i.selected(g(t))));function g(t){return t[f.value.record]}function P(t,e={}){b.router.visit(t,{...l,...e,preserveState:!0,method:"get"})}function V(t,e,n={}){var s,k;W(t,f.value.endpoint,{table:a.value.id,id:g(e)},n)||(k=(s=d.recordActions)==null?void 0:s[t.name])==null||k.call(s,e)}function T(t,e={}){W(t,f.value.endpoint,{table:a.value.id,all:i.selection.value.all,only:Array.from(i.selection.value.only),except:Array.from(i.selection.value.except)},e)}function F(t,e={}){W(t,f.value.endpoint,{table:a.value.id},e)}function U(t,e={}){b.router.reload({...l,...e,data:{[f.value.records]:t.value,[f.value.pages]:void 0}})}function $(t,e={}){t.sort&&b.router.reload({...l,...e,data:{[f.value.sorts]:h.omitValue(t.sort.next)}})}function G(t,e={}){const n=h.toggleValue(t.name,y.value.map(({name:r})=>r));b.router.reload({...l,...e,data:{[f.value.columns]:h.delimitArray(n)}})}function q(){i.select(...a.value.records.map(t=>g(t)))}function j(){i.deselect(...a.value.records.map(t=>g(t)))}function z(){return{"onUpdate:modelValue":t=>{t?q():j()},modelValue:E.value}}return c.reactive({headings:y,columns:x,records:S,bulkActions:u,pageActions:p,rowsPerPage:L,currentPage:w,paginator:m,isPageSelected:E,selectPage:q,deselectPage:j,selection:i.selection,select:t=>i.select(g(t)),deselect:t=>i.deselect(g(t)),toggle:t=>i.toggle(g(t)),selected:t=>i.selected(g(t)),hasSelected:i.hasSelected,bindPage:z,bind:t=>i.bind(g(t)),...h})}A.useTable=J,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@honed/table",
3
+ "private": false,
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "description": "-",
7
+ "keywords": [
8
+ "honed",
9
+ "table",
10
+ "vue",
11
+ "inertia"
12
+ ],
13
+ "scripts": {
14
+ "dev": "vite",
15
+ "build": "npm run format && npm run type-check && vite build",
16
+ "format": "npx @biomejs/biome format --write src/",
17
+ "type-check": "vue-tsc --noEmit",
18
+ "test": "vitest",
19
+ "coverage": "vitest run --coverage",
20
+ "patch": "npm version patch --no-git-tag-version",
21
+ "minor": "npm version minor --no-git-tag-version",
22
+ "major": "npm version major --no-git-tag-version",
23
+ "release": "npm run build && npm publish --access public"
24
+ },
25
+ "author": {
26
+ "name": "Joshua Wallace",
27
+ "email": "josh@joshua-wallace.com",
28
+ "url": "https://joshua-wallace.com"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/honedlabs/table.git"
33
+ },
34
+ "homepage": "https://github.com/honedlabs/table#readme",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "type": "module",
39
+ "main": "./dist/index.umd.js",
40
+ "module": "./dist/index.es.js",
41
+ "types": "./dist/index.d.ts",
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "import": "./dist/index.es.js",
46
+ "require": "./dist/index.umd.js",
47
+ "default": "./dist/index.es.js"
48
+ }
49
+ },
50
+ "peerDependencies": {
51
+ "vue": "^3.4.0",
52
+ "@vueuse/core": "^11.0.0||^12.0.0",
53
+ "@inertiajs/vue3": "^1.2.0||^2.0.0",
54
+ "@honed/action": "^0.1.6",
55
+ "@honed/refine": "^0.1.2",
56
+ "axios": "^1.2.0"
57
+ },
58
+ "devDependencies": {
59
+ "@biomejs/biome": "1.9.4",
60
+ "@types/node": "^22.9.3",
61
+ "@vue/test-utils": "^2.4.6",
62
+ "axios": "^1.2.0",
63
+ "jsdom": "^25.0.1",
64
+ "typescript": "~5.4.0",
65
+ "vite": "^5.4.11",
66
+ "vite-plugin-dts": "^4.3.0",
67
+ "vitest": "^2.1.5",
68
+ "vue-tsc": "^2.1.10"
69
+ }
70
+ }