@honed/table 0.9.0 → 0.9.1

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 CHANGED
@@ -71,6 +71,7 @@ export declare interface Heading<T extends Record<string, any> = Record<string,
71
71
 
72
72
  export declare interface HonedTable<T extends Record<string, any> = Record<string, any>, K extends Paginate = "length-aware"> extends HonedRefine {
73
73
  meta: ComputedRef<Record<string, any> | null>;
74
+ isEmpty: ComputedRef<boolean>;
74
75
  isPageable: ComputedRef<boolean>;
75
76
  isToggleable: ComputedRef<boolean>;
76
77
  getRecordKey: (record: TableEntry<T>) => Identifier;
@@ -235,6 +236,7 @@ export declare function useTable<T extends Record<string, Table>, K extends Reco
235
236
  toggleValue: (value: any, values: any) => any;
236
237
  delimitArray: (value: any) => string;
237
238
  meta: Record<string, any>;
239
+ isEmpty: boolean;
238
240
  isPageable: boolean;
239
241
  isToggleable: boolean;
240
242
  getRecordKey: (record: TableEntry<K>) => Identifier;
package/dist/index.es.js CHANGED
@@ -1,65 +1,65 @@
1
- import { ref as Y, computed as d, toValue as J, reactive as Z } from "vue";
2
- import { router as S } from "@inertiajs/vue3";
3
- function _(l, v, c, a = {}) {
4
- return l.route ? (S.visit(l.route.url, {
5
- ...a,
6
- method: l.route.method
7
- }), !0) : l.action && v ? (S.post(
1
+ import { ref as Y, computed as f, toValue as J, reactive as Z } from "vue";
2
+ import { router as b } from "@inertiajs/vue3";
3
+ function _(a, v, c, r = {}) {
4
+ return a.route ? (b.visit(a.route.url, {
5
+ ...r,
6
+ method: a.route.method
7
+ }), !0) : a.action && v ? (b.post(
8
8
  v,
9
- { ...c, name: l.name, type: l.type },
10
- a
9
+ { ...c, name: a.name, type: a.type },
10
+ r
11
11
  ), !0) : !1;
12
12
  }
13
- function X(l, v, c, a = {}, m = {}) {
13
+ function X(a, v, c, r = {}, d = {}) {
14
14
  return _(
15
- l,
15
+ a,
16
16
  v,
17
- { ...a, id: c ?? void 0 },
18
- m
17
+ { ...r, id: c ?? void 0 },
18
+ d
19
19
  );
20
20
  }
21
- function ee(l, v, c, a = {}) {
22
- return l.map((m) => ({
23
- ...m,
24
- execute: (o = {}, i = {}) => X(m, v, c, o, { ...a, ...i })
21
+ function ee(a, v, c, r = {}) {
22
+ return a.map((d) => ({
23
+ ...d,
24
+ execute: (o = {}, i = {}) => X(d, v, c, o, { ...r, ...i })
25
25
  }));
26
26
  }
27
27
  function te() {
28
- const l = Y({
28
+ const a = Y({
29
29
  all: !1,
30
30
  only: /* @__PURE__ */ new Set(),
31
31
  except: /* @__PURE__ */ new Set()
32
32
  });
33
33
  function v() {
34
- l.value.all = !0, l.value.only.clear(), l.value.except.clear();
34
+ a.value.all = !0, a.value.only.clear(), a.value.except.clear();
35
35
  }
36
36
  function c() {
37
- l.value.all = !1, l.value.only.clear(), l.value.except.clear();
37
+ a.value.all = !1, a.value.only.clear(), a.value.except.clear();
38
38
  }
39
- function a(...s) {
40
- s.forEach((h) => l.value.except.delete(h)), s.forEach((h) => l.value.only.add(h));
39
+ function r(...s) {
40
+ s.forEach((p) => a.value.except.delete(p)), s.forEach((p) => a.value.only.add(p));
41
41
  }
42
- function m(...s) {
43
- s.forEach((h) => l.value.except.add(h)), s.forEach((h) => l.value.only.delete(h));
42
+ function d(...s) {
43
+ s.forEach((p) => a.value.except.add(p)), s.forEach((p) => a.value.only.delete(p));
44
44
  }
45
- function o(s, h) {
46
- if (i(s) || h === !1) return m(s);
47
- if (!i(s) || h === !0) return a(s);
45
+ function o(s, p) {
46
+ if (i(s) || p === !1) return d(s);
47
+ if (!i(s) || p === !0) return r(s);
48
48
  }
49
49
  function i(s) {
50
- return l.value.all ? !l.value.except.has(s) : l.value.only.has(s);
50
+ return a.value.all ? !a.value.except.has(s) : a.value.only.has(s);
51
51
  }
52
- const g = d(() => l.value.all && l.value.except.size === 0), k = d(() => l.value.only.size > 0 || g.value);
52
+ const g = f(() => a.value.all && a.value.except.size === 0), w = f(() => a.value.only.size > 0 || g.value);
53
53
  function x(s) {
54
54
  return {
55
- "onUpdate:modelValue": (h) => {
56
- h ? a(s) : m(s);
55
+ "onUpdate:modelValue": (p) => {
56
+ p ? r(s) : d(s);
57
57
  },
58
58
  modelValue: i(s),
59
59
  value: s
60
60
  };
61
61
  }
62
- function w() {
62
+ function S() {
63
63
  return {
64
64
  "onUpdate:modelValue": (s) => {
65
65
  s ? v() : c();
@@ -69,469 +69,469 @@ function te() {
69
69
  }
70
70
  return {
71
71
  allSelected: g,
72
- selection: l,
73
- hasSelected: k,
72
+ selection: a,
73
+ hasSelected: w,
74
74
  selectAll: v,
75
75
  deselectAll: c,
76
- select: a,
77
- deselect: m,
76
+ select: r,
77
+ deselect: d,
78
78
  toggle: o,
79
79
  selected: i,
80
80
  bind: x,
81
- bindAll: w
81
+ bindAll: S
82
82
  };
83
83
  }
84
84
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
85
85
  const Q = () => {
86
86
  };
87
- function ne(l, v) {
88
- function c(...a) {
89
- return new Promise((m, o) => {
90
- Promise.resolve(l(() => v.apply(this, a), { fn: v, thisArg: this, args: a })).then(m).catch(o);
87
+ function ne(a, v) {
88
+ function c(...r) {
89
+ return new Promise((d, o) => {
90
+ Promise.resolve(a(() => v.apply(this, r), { fn: v, thisArg: this, args: r })).then(d).catch(o);
91
91
  });
92
92
  }
93
93
  return c;
94
94
  }
95
- function le(l, v = {}) {
96
- let c, a, m = Q;
95
+ function le(a, v = {}) {
96
+ let c, r, d = Q;
97
97
  const o = (g) => {
98
- clearTimeout(g), m(), m = Q;
98
+ clearTimeout(g), d(), d = Q;
99
99
  };
100
100
  let i;
101
101
  return (g) => {
102
- const k = J(l), x = J(v.maxWait);
103
- return c && o(c), k <= 0 || x !== void 0 && x <= 0 ? (a && (o(a), a = null), Promise.resolve(g())) : new Promise((w, s) => {
104
- m = v.rejectOnCancel ? s : w, i = g, x && !a && (a = setTimeout(() => {
105
- c && o(c), a = null, w(i());
102
+ const w = J(a), x = J(v.maxWait);
103
+ return c && o(c), w <= 0 || x !== void 0 && x <= 0 ? (r && (o(r), r = null), Promise.resolve(g())) : new Promise((S, s) => {
104
+ d = v.rejectOnCancel ? s : S, i = g, x && !r && (r = setTimeout(() => {
105
+ c && o(c), r = null, S(i());
106
106
  }, x)), c = setTimeout(() => {
107
- a && o(a), a = null, w(g());
108
- }, k);
107
+ r && o(r), r = null, S(g());
108
+ }, w);
109
109
  });
110
110
  };
111
111
  }
112
- function D(l, v = 200, c = {}) {
112
+ function q(a, v = 200, c = {}) {
113
113
  return ne(
114
114
  le(v, c),
115
- l
115
+ a
116
116
  );
117
117
  }
118
- function ae(l, v, c = {}) {
119
- if (!(l != null && l[v]))
118
+ function ae(a, v, c = {}) {
119
+ if (!(a != null && a[v]))
120
120
  throw new Error("The refine must be provided with valid props and key.");
121
- const a = d(() => l[v]), m = d(() => !!a.value.sort), o = d(() => !!a.value.search), i = d(() => !!a.value.match), g = d(
121
+ const r = f(() => a[v]), d = f(() => !!r.value.sort), o = f(() => !!r.value.search), i = f(() => !!r.value.match), g = f(
122
122
  () => {
123
123
  var e;
124
- return (e = a.value.filters) == null ? void 0 : e.map((n) => ({
124
+ return (e = r.value.filters) == null ? void 0 : e.map((n) => ({
125
125
  ...n,
126
- apply: (r, p = {}) => P(n, r, p),
127
- clear: (r = {}) => B(n, r),
128
- bind: () => q(n.name)
126
+ apply: (l, m = {}) => V(n, l, m),
127
+ clear: (l = {}) => B(n, l),
128
+ bind: () => C(n.name)
129
129
  }));
130
130
  }
131
- ), k = d(
131
+ ), w = f(
132
132
  () => {
133
133
  var e;
134
- return (e = a.value.sorts) == null ? void 0 : e.map((n) => ({
134
+ return (e = r.value.sorts) == null ? void 0 : e.map((n) => ({
135
135
  ...n,
136
- apply: (r = {}) => A(n, n.direction, r),
137
- clear: (r = {}) => I(r),
138
- bind: () => t(n)
136
+ apply: (l = {}) => L(n, n.direction, l),
137
+ clear: (l = {}) => I(l),
138
+ bind: () => N(n)
139
139
  }));
140
140
  }
141
- ), x = d(
141
+ ), x = f(
142
142
  () => {
143
143
  var e;
144
- return (e = a.value.searches) == null ? void 0 : e.map((n) => ({
144
+ return (e = r.value.searches) == null ? void 0 : e.map((n) => ({
145
145
  ...n,
146
- apply: (r = {}) => $(n, r),
147
- clear: (r = {}) => $(n, r),
148
- bind: () => f(n)
146
+ apply: (l = {}) => E(n, l),
147
+ clear: (l = {}) => E(n, l),
148
+ bind: () => u(n)
149
149
  }));
150
150
  }
151
- ), w = d(
151
+ ), S = f(
152
152
  () => g.value.filter(({ active: e }) => e)
153
- ), s = d(
154
- () => k.value.find(({ active: e }) => e)
155
- ), h = d(
153
+ ), s = f(
154
+ () => w.value.find(({ active: e }) => e)
155
+ ), p = f(
156
156
  () => x.value.filter(({ active: e }) => e)
157
157
  );
158
- function M(e) {
159
- return Array.isArray(e) ? e.join(a.value.delimiter) : e;
158
+ function F(e) {
159
+ return Array.isArray(e) ? e.join(r.value.delimiter) : e;
160
160
  }
161
- function R(e) {
161
+ function j(e) {
162
162
  return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
163
163
  }
164
- function E(e) {
164
+ function T(e) {
165
165
  if (!["", null, void 0, []].includes(e))
166
166
  return e;
167
167
  }
168
168
  function W(e) {
169
- return [M, R, E].reduce(
170
- (n, r) => r(n),
169
+ return [F, j, T].reduce(
170
+ (n, l) => l(n),
171
171
  e
172
172
  );
173
173
  }
174
174
  function z(e, n) {
175
- return n = Array.isArray(n) ? n : [n], n.includes(e) ? n.filter((r) => r !== e) : [...n, e];
175
+ return n = Array.isArray(n) ? n : [n], n.includes(e) ? n.filter((l) => l !== e) : [...n, e];
176
176
  }
177
- function U(e) {
177
+ function $(e) {
178
178
  return typeof e != "string" ? e : g.value.find(({ name: n }) => n === e);
179
179
  }
180
- function y(e, n = null) {
181
- return typeof e != "string" ? e : k.value.find(
182
- ({ name: r, direction: p }) => r === e && p === n
180
+ function M(e, n = null) {
181
+ return typeof e != "string" ? e : w.value.find(
182
+ ({ name: l, direction: m }) => l === e && m === n
183
183
  );
184
184
  }
185
- function T(e) {
185
+ function h(e) {
186
186
  return typeof e != "string" ? e : x.value.find(({ name: n }) => n === e);
187
187
  }
188
- function b(e) {
189
- return e ? typeof e == "string" ? w.value.some((n) => n.name === e) : e.active : !!w.value.length;
190
- }
191
188
  function G(e) {
189
+ return e ? typeof e == "string" ? S.value.some((n) => n.name === e) : e.active : !!S.value.length;
190
+ }
191
+ function y(e) {
192
192
  var n;
193
193
  return e ? typeof e == "string" ? ((n = s.value) == null ? void 0 : n.name) === e : e.active : !!s.value;
194
194
  }
195
- function F(e) {
195
+ function R(e) {
196
196
  var n;
197
- return e ? typeof e == "string" ? (n = h.value) == null ? void 0 : n.some((r) => r.name === e) : e.active : !!a.value.term;
197
+ return e ? typeof e == "string" ? (n = p.value) == null ? void 0 : n.some((l) => l.name === e) : e.active : !!r.value.term;
198
198
  }
199
- function C(e, n = {}) {
200
- const r = Object.fromEntries(
201
- Object.entries(e).map(([p, V]) => [p, W(V)])
199
+ function U(e, n = {}) {
200
+ const l = Object.fromEntries(
201
+ Object.entries(e).map(([m, A]) => [m, W(A)])
202
202
  );
203
- S.reload({
203
+ b.reload({
204
204
  ...c,
205
205
  ...n,
206
- data: r
206
+ data: l
207
207
  });
208
208
  }
209
- function P(e, n, r = {}) {
210
- const p = U(e);
211
- if (!p) return console.warn(`Filter [${e}] does not exist.`);
212
- S.reload({
209
+ function V(e, n, l = {}) {
210
+ const m = $(e);
211
+ if (!m) return console.warn(`Filter [${e}] does not exist.`);
212
+ b.reload({
213
213
  ...c,
214
- ...r,
214
+ ...l,
215
215
  data: {
216
- [p.name]: W(n)
216
+ [m.name]: W(n)
217
217
  }
218
218
  });
219
219
  }
220
- function A(e, n = null, r = {}) {
221
- if (!m.value)
220
+ function L(e, n = null, l = {}) {
221
+ if (!d.value)
222
222
  return console.warn("Refine cannot perform sorting.");
223
- const p = y(e, n);
224
- if (!p) return console.warn(`Sort [${e}] does not exist.`);
225
- S.reload({
223
+ const m = M(e, n);
224
+ if (!m) return console.warn(`Sort [${e}] does not exist.`);
225
+ b.reload({
226
226
  ...c,
227
- ...r,
227
+ ...l,
228
228
  data: {
229
- [a.value.sort]: E(p.next)
229
+ [r.value.sort]: T(m.next)
230
230
  }
231
231
  });
232
232
  }
233
- function j(e, n = {}) {
233
+ function k(e, n = {}) {
234
234
  if (!o.value)
235
235
  return console.warn("Refine cannot perform searching.");
236
- e = [R, E].reduce(
237
- (r, p) => p(r),
236
+ e = [j, T].reduce(
237
+ (l, m) => m(l),
238
238
  e
239
- ), S.reload({
239
+ ), b.reload({
240
240
  ...c,
241
241
  ...n,
242
242
  data: {
243
- [a.value.search]: e
243
+ [r.value.search]: e
244
244
  }
245
245
  });
246
246
  }
247
- function $(e, n = {}) {
247
+ function E(e, n = {}) {
248
248
  if (!i.value || !o.value)
249
249
  return console.warn("Refine cannot perform matching.");
250
- const r = T(e);
251
- if (!r) return console.warn(`Match [${e}] does not exist.`);
252
- const p = z(
253
- r.name,
254
- h.value.map(({ name: V }) => V)
250
+ const l = h(e);
251
+ if (!l) return console.warn(`Match [${e}] does not exist.`);
252
+ const m = z(
253
+ l.name,
254
+ p.value.map(({ name: A }) => A)
255
255
  );
256
- S.reload({
256
+ b.reload({
257
257
  ...c,
258
258
  ...n,
259
259
  data: {
260
- [a.value.match]: M(p)
260
+ [r.value.match]: F(m)
261
261
  }
262
262
  });
263
263
  }
264
264
  function B(e, n = {}) {
265
- if (e) return P(e, null, n);
266
- S.reload({
265
+ if (e) return V(e, null, n);
266
+ b.reload({
267
267
  ...c,
268
268
  ...n,
269
269
  data: Object.fromEntries(
270
- w.value.map(({ name: r }) => [r, null])
270
+ S.value.map(({ name: l }) => [l, null])
271
271
  )
272
272
  });
273
273
  }
274
274
  function I(e = {}) {
275
- if (!m.value)
275
+ if (!d.value)
276
276
  return console.warn("Refine cannot perform sorting.");
277
- S.reload({
277
+ b.reload({
278
278
  ...c,
279
279
  ...e,
280
280
  data: {
281
- [a.value.sort]: null
281
+ [r.value.sort]: null
282
282
  }
283
283
  });
284
284
  }
285
- function H(e = {}) {
286
- j(null, e);
285
+ function D(e = {}) {
286
+ k(null, e);
287
287
  }
288
- function K(e = {}) {
288
+ function H(e = {}) {
289
289
  if (!i.value)
290
290
  return console.warn("Refine cannot perform matching.");
291
- S.reload({
291
+ b.reload({
292
292
  ...c,
293
293
  ...e,
294
294
  data: {
295
- [a.value.match]: null
295
+ [r.value.match]: null
296
296
  }
297
297
  });
298
298
  }
299
- function N(e = {}) {
299
+ function K(e = {}) {
300
300
  var n;
301
- S.reload({
301
+ b.reload({
302
302
  ...c,
303
303
  ...e,
304
304
  data: {
305
- [a.value.search ?? ""]: void 0,
306
- [a.value.sort ?? ""]: void 0,
307
- [a.value.match ?? ""]: void 0,
305
+ [r.value.search ?? ""]: void 0,
306
+ [r.value.sort ?? ""]: void 0,
307
+ [r.value.match ?? ""]: void 0,
308
308
  ...Object.fromEntries(
309
- ((n = a.value.filters) == null ? void 0 : n.map((r) => [
310
- r.name,
309
+ ((n = r.value.filters) == null ? void 0 : n.map((l) => [
310
+ l.name,
311
311
  void 0
312
312
  ])) ?? []
313
313
  )
314
314
  }
315
315
  });
316
316
  }
317
- function q(e, n = {}) {
318
- const r = U(e);
319
- if (!r) return console.warn(`Filter [${e}] does not exist.`);
317
+ function C(e, n = {}) {
318
+ const l = $(e);
319
+ if (!l) return console.warn(`Filter [${e}] does not exist.`);
320
320
  const {
321
- debounce: p = 250,
322
- transform: V = (L) => L,
321
+ debounce: m = 250,
322
+ transform: A = (P) => P,
323
323
  ...O
324
324
  } = n;
325
325
  return {
326
- "onUpdate:modelValue": D((L) => {
327
- P(r, V(L), O);
328
- }, p),
329
- modelValue: r.value
326
+ "onUpdate:modelValue": q((P) => {
327
+ V(l, A(P), O);
328
+ }, m),
329
+ modelValue: l.value
330
330
  };
331
331
  }
332
- function t(e, n = {}) {
333
- const r = y(e);
334
- if (!r) return console.warn(`Sort [${e}] does not exist.`);
335
- const { debounce: p = 0, transform: V, ...O } = n;
332
+ function N(e, n = {}) {
333
+ const l = M(e);
334
+ if (!l) return console.warn(`Sort [${e}] does not exist.`);
335
+ const { debounce: m = 0, transform: A, ...O } = n;
336
336
  return {
337
- onClick: D(() => {
338
- var L;
339
- A(r, (L = s.value) == null ? void 0 : L.direction, O);
340
- }, p)
337
+ onClick: q(() => {
338
+ var P;
339
+ L(l, (P = s.value) == null ? void 0 : P.direction, O);
340
+ }, m)
341
341
  };
342
342
  }
343
- function u(e = {}) {
344
- const { debounce: n = 700, transform: r, ...p } = e;
343
+ function t(e = {}) {
344
+ const { debounce: n = 700, transform: l, ...m } = e;
345
345
  return {
346
- "onUpdate:modelValue": D(
347
- (V) => {
348
- j(V, p);
346
+ "onUpdate:modelValue": q(
347
+ (A) => {
348
+ k(A, m);
349
349
  },
350
350
  n
351
351
  ),
352
- modelValue: a.value.term ?? ""
352
+ modelValue: r.value.term ?? ""
353
353
  };
354
354
  }
355
- function f(e, n = {}) {
356
- const r = T(e);
357
- if (!r) return console.warn(`Match [${e}] does not exist.`);
358
- const { debounce: p = 0, transform: V, ...O } = n;
355
+ function u(e, n = {}) {
356
+ const l = h(e);
357
+ if (!l) return console.warn(`Match [${e}] does not exist.`);
358
+ const { debounce: m = 0, transform: A, ...O } = n;
359
359
  return {
360
- "onUpdate:modelValue": D((L) => {
361
- $(L, O);
362
- }, p),
363
- modelValue: F(r),
364
- value: r.name
360
+ "onUpdate:modelValue": q((P) => {
361
+ E(P, O);
362
+ }, m),
363
+ modelValue: R(l),
364
+ value: l.name
365
365
  };
366
366
  }
367
367
  return {
368
368
  filters: g,
369
- sorts: k,
369
+ sorts: w,
370
370
  searches: x,
371
- currentFilters: w,
371
+ currentFilters: S,
372
372
  currentSort: s,
373
- currentSearches: h,
374
- isSortable: m,
373
+ currentSearches: p,
374
+ isSortable: d,
375
375
  isSearchable: o,
376
376
  isMatchable: i,
377
- isFiltering: b,
378
- isSorting: G,
379
- isSearching: F,
380
- getFilter: U,
381
- getSort: y,
382
- getSearch: T,
383
- apply: C,
384
- applyFilter: P,
385
- applySort: A,
386
- applySearch: j,
387
- applyMatch: $,
377
+ isFiltering: G,
378
+ isSorting: y,
379
+ isSearching: R,
380
+ getFilter: $,
381
+ getSort: M,
382
+ getSearch: h,
383
+ apply: U,
384
+ applyFilter: V,
385
+ applySort: L,
386
+ applySearch: k,
387
+ applyMatch: E,
388
388
  clearFilter: B,
389
389
  clearSort: I,
390
- clearSearch: H,
391
- clearMatch: K,
392
- reset: N,
393
- bindFilter: q,
394
- bindSort: t,
395
- bindSearch: u,
396
- bindMatch: f,
397
- stringValue: R,
398
- omitValue: E,
390
+ clearSearch: D,
391
+ clearMatch: H,
392
+ reset: K,
393
+ bindFilter: C,
394
+ bindSort: N,
395
+ bindSearch: t,
396
+ bindMatch: u,
397
+ stringValue: j,
398
+ omitValue: T,
399
399
  toggleValue: z,
400
- delimitArray: M
400
+ delimitArray: F
401
401
  };
402
402
  }
403
- function ue(l, v, c = {}) {
404
- if (!(l != null && l[v]))
403
+ function ue(a, v, c = {}) {
404
+ if (!(a != null && a[v]))
405
405
  throw new Error("The table must be provided with valid props and key.");
406
- const { recordOperations: a = {}, ...m } = {
406
+ const { recordOperations: r = {}, ...d } = {
407
407
  only: [...c.only ?? [], v.toString()],
408
408
  ...c
409
- }, o = d(() => l[v]), i = te(), g = ae(l, v, m), k = d(() => o.value.meta), x = d(() => !!o.value.page && !!o.value.record), w = d(() => !!o.value.column), s = d(
409
+ }, o = f(() => a[v]), i = te(), g = ae(a, v, d), w = f(() => o.value.meta), x = f(() => !!o.value.emptyState), S = f(() => !!o.value.page && !!o.value.record), s = f(() => !!o.value.column), p = f(
410
410
  () => o.value.columns.filter(({ active: t, hidden: u }) => t && !u).map((t) => {
411
411
  var u;
412
412
  return {
413
413
  ...t,
414
414
  isSorting: !!((u = t.sort) != null && u.active),
415
- toggleSort: (f = {}) => g.applySort(t.sort, null, f)
415
+ toggleSort: (e = {}) => g.applySort(t.sort, null, e)
416
416
  };
417
417
  })
418
- ), h = d(
418
+ ), F = f(
419
419
  () => o.value.columns.filter(({ hidden: t }) => !t).map((t) => ({
420
420
  ...t,
421
421
  toggle: (u = {}) => H(t.name, u)
422
422
  }))
423
- ), M = d(
423
+ ), j = f(
424
424
  () => o.value.records.map((t) => ({
425
425
  /** The operations available for the record */
426
- operations: P(t.operations),
426
+ operations: L(t.operations),
427
427
  /** Perform this operation when the record is clicked */
428
428
  default: (u = {}) => {
429
- const f = t.operations.find(
430
- ({ default: e }) => e
429
+ const e = t.operations.find(
430
+ ({ default: n }) => n
431
431
  );
432
- f && j(f, t, u);
432
+ e && E(e, t, u);
433
433
  },
434
434
  /** Selects this record */
435
- select: () => i.select(b(t)),
435
+ select: () => i.select(y(t)),
436
436
  /** Deselects this record */
437
- deselect: () => i.deselect(b(t)),
437
+ deselect: () => i.deselect(y(t)),
438
438
  /** Toggles the selection of this record */
439
- toggle: () => i.toggle(b(t)),
439
+ toggle: () => i.toggle(y(t)),
440
440
  /** Determine if the record is selected */
441
- selected: i.selected(b(t)),
441
+ selected: i.selected(y(t)),
442
442
  /** Bind the record to a checkbox */
443
- bind: () => i.bind(b(t)),
443
+ bind: () => i.bind(y(t)),
444
444
  /** Get the entry of the record for the column */
445
- entry: (u) => F(t, u),
445
+ entry: (u) => U(t, u),
446
446
  /** Get the value of the record for the column */
447
447
  value: (u) => {
448
- var f;
449
- return ((f = F(t, u)) == null ? void 0 : f.v) ?? null;
448
+ var e;
449
+ return ((e = U(t, u)) == null ? void 0 : e.v) ?? null;
450
450
  },
451
451
  /** Get the extra data of the record for the column */
452
452
  extra: (u) => {
453
- var f;
454
- return ((f = F(t, u)) == null ? void 0 : f.e) ?? null;
453
+ var e;
454
+ return ((e = U(t, u)) == null ? void 0 : e.e) ?? null;
455
455
  }
456
456
  }))
457
- ), R = d(() => !!o.value.operations.inline), E = d(() => P(o.value.operations.bulk)), W = d(() => P(o.value.operations.page)), z = d(
457
+ ), T = f(() => !!o.value.operations.inline), W = f(() => L(o.value.operations.bulk)), z = f(() => L(o.value.operations.page)), $ = f(
458
458
  () => o.value.pages.find(({ active: t }) => t)
459
- ), U = d(() => o.value.pages), y = d(() => ({
459
+ ), M = f(() => o.value.pages), h = f(() => ({
460
460
  ...o.value.paginate,
461
461
  next: (t = {}) => {
462
- "nextLink" in y.value && y.value.nextLink && A(y.value.nextLink, t);
462
+ "nextLink" in h.value && h.value.nextLink && k(h.value.nextLink, t);
463
463
  },
464
464
  previous: (t = {}) => {
465
- "prevLink" in y.value && y.value.prevLink && A(y.value.prevLink, t);
465
+ "prevLink" in h.value && h.value.prevLink && k(h.value.prevLink, t);
466
466
  },
467
467
  first: (t = {}) => {
468
- "firstLink" in y.value && y.value.firstLink && A(y.value.firstLink, t);
468
+ "firstLink" in h.value && h.value.firstLink && k(h.value.firstLink, t);
469
469
  },
470
470
  last: (t = {}) => {
471
- "lastLink" in y.value && y.value.lastLink && A(y.value.lastLink, t);
471
+ "lastLink" in h.value && h.value.lastLink && k(h.value.lastLink, t);
472
472
  },
473
473
  ..."links" in o.value.paginate && o.value.paginate.links ? {
474
474
  links: o.value.paginate.links.map((t) => ({
475
475
  ...t,
476
- navigate: (u = {}) => t.url && A(t.url, u)
476
+ navigate: (u = {}) => t.url && k(t.url, u)
477
477
  }))
478
478
  } : {}
479
- })), T = d(
479
+ })), G = f(
480
480
  () => o.value.records.length > 0 && o.value.records.every(
481
- (t) => i.selected(b(t))
481
+ (t) => i.selected(y(t))
482
482
  )
483
483
  );
484
- function b(t) {
484
+ function y(t) {
485
485
  return t[o.value.key].v;
486
486
  }
487
- function G(t) {
487
+ function R(t) {
488
488
  return typeof t == "string" ? t : t.name;
489
489
  }
490
- function F(t, u) {
491
- const f = G(u);
492
- return f in t ? t[f] : null;
490
+ function U(t, u) {
491
+ const e = R(u);
492
+ return e in t ? t[e] : null;
493
493
  }
494
- function C(t, u = {}, f = {}) {
494
+ function V(t, u = {}, e = {}) {
495
495
  return X(
496
496
  t,
497
497
  o.value.endpoint,
498
498
  o.value.id,
499
499
  u,
500
500
  {
501
- ...m,
502
- ...f
501
+ ...d,
502
+ ...e
503
503
  }
504
504
  );
505
505
  }
506
- function P(t) {
506
+ function L(t) {
507
507
  return ee(
508
508
  t,
509
509
  o.value.endpoint,
510
510
  o.value.id,
511
- m
511
+ d
512
512
  );
513
513
  }
514
- function A(t, u = {}) {
515
- S.visit(t, {
514
+ function k(t, u = {}) {
515
+ b.visit(t, {
516
516
  preserveScroll: !0,
517
517
  preserveState: !0,
518
- ...m,
518
+ ...d,
519
519
  ...u,
520
520
  method: "get"
521
521
  });
522
522
  }
523
- function j(t, u, f = {}) {
524
- var n;
525
- C(
523
+ function E(t, u, e = {}) {
524
+ var l;
525
+ V(
526
526
  t,
527
527
  {
528
- record: b(u)
528
+ record: y(u)
529
529
  },
530
- f
531
- ) || (n = a == null ? void 0 : a[t.name]) == null || n.call(a, u);
530
+ e
531
+ ) || (l = r == null ? void 0 : r[t.name]) == null || l.call(r, u);
532
532
  }
533
- function $(t, u = {}) {
534
- C(
533
+ function B(t, u = {}) {
534
+ V(
535
535
  t,
536
536
  {
537
537
  all: i.selection.value.all,
@@ -540,21 +540,21 @@ function ue(l, v, c = {}) {
540
540
  },
541
541
  {
542
542
  ...u,
543
- onSuccess: (f) => {
544
- var e;
545
- (e = u.onSuccess) == null || e.call(u, f), t.keepSelected || i.deselectAll();
543
+ onSuccess: (e) => {
544
+ var n;
545
+ (n = u.onSuccess) == null || n.call(u, e), t.keepSelected || i.deselectAll();
546
546
  }
547
547
  }
548
548
  );
549
549
  }
550
- function B(t, u = {}, f = {}) {
551
- return C(t, u, f);
550
+ function I(t, u = {}, e = {}) {
551
+ return V(t, u, e);
552
552
  }
553
- function I(t, u = {}) {
554
- if (!x.value)
553
+ function D(t, u = {}) {
554
+ if (!S.value)
555
555
  return console.warn("The table does not support pagination changes.");
556
- S.reload({
557
- ...m,
556
+ b.reload({
557
+ ...d,
558
558
  ...u,
559
559
  data: {
560
560
  [o.value.record]: t.value,
@@ -563,113 +563,115 @@ function ue(l, v, c = {}) {
563
563
  });
564
564
  }
565
565
  function H(t, u = {}) {
566
- if (!w.value)
566
+ if (!s.value)
567
567
  return console.warn("The table does not support column toggling.");
568
- const f = G(t);
569
- if (!f) return console.log(`Column [${t}] does not exist.`);
570
- const e = g.toggleValue(
571
- f,
572
- s.value.map(({ name: n }) => n)
568
+ const e = R(t);
569
+ if (!e) return console.log(`Column [${t}] does not exist.`);
570
+ const n = g.toggleValue(
571
+ e,
572
+ p.value.map(({ name: l }) => l)
573
573
  );
574
- S.reload({
575
- ...m,
574
+ b.reload({
575
+ ...d,
576
576
  ...u,
577
577
  data: {
578
- [o.value.column]: g.delimitArray(e)
578
+ [o.value.column]: g.delimitArray(n)
579
579
  }
580
580
  });
581
581
  }
582
582
  function K() {
583
583
  i.select(
584
584
  ...o.value.records.map(
585
- (t) => b(t)
585
+ (t) => y(t)
586
586
  )
587
587
  );
588
588
  }
589
- function N() {
589
+ function C() {
590
590
  i.deselect(
591
591
  ...o.value.records.map(
592
- (t) => b(t)
592
+ (t) => y(t)
593
593
  )
594
594
  );
595
595
  }
596
- function q() {
596
+ function N() {
597
597
  return {
598
598
  "onUpdate:modelValue": (t) => {
599
- t ? K() : N();
599
+ t ? K() : C();
600
600
  },
601
- modelValue: T.value
601
+ modelValue: G.value
602
602
  };
603
603
  }
604
604
  return Z({
605
605
  /** Table-specific metadata */
606
- meta: k,
606
+ meta: w,
607
+ /** Whether the table is empty */
608
+ isEmpty: x,
607
609
  /** Whether the table supports changing the number of records to display per page */
608
- isPageable: x,
610
+ isPageable: S,
609
611
  /** Whether the table supports toggling columns */
610
- isToggleable: w,
612
+ isToggleable: s,
611
613
  /** Retrieve a record's identifier */
612
- getRecordKey: b,
614
+ getRecordKey: y,
613
615
  /** The heading columns for the table */
614
- headings: s,
616
+ headings: p,
615
617
  /** All of the table's columns */
616
- columns: h,
618
+ columns: F,
617
619
  /** The records of the table */
618
- records: M,
620
+ records: j,
619
621
  /** Whether the table has record operations */
620
- inline: R,
622
+ inline: T,
621
623
  /** The available bulk operations */
622
- bulk: E,
624
+ bulk: W,
623
625
  /** The available page operations */
624
- page: W,
626
+ page: z,
625
627
  /** The available number of records to display per page */
626
- pages: U,
628
+ pages: M,
627
629
  /** The current record per page item */
628
- currentPage: z,
630
+ currentPage: $,
629
631
  /** The pagination metadata */
630
- paginator: y,
632
+ paginator: h,
631
633
  /** Execute an inline operation */
632
- executeInline: j,
634
+ executeInline: E,
633
635
  /** Execute a bulk operation */
634
- executeBulk: $,
636
+ executeBulk: B,
635
637
  /** Execute a page operation */
636
- executePage: B,
638
+ executePage: I,
637
639
  /** Apply a new page by changing the number of records to display */
638
- applyPage: I,
640
+ applyPage: D,
639
641
  /** The current selection of records */
640
642
  selection: i.selection,
641
643
  /** Select the given records */
642
- select: (t) => i.select(b(t)),
644
+ select: (t) => i.select(y(t)),
643
645
  /** Deselect the given records */
644
- deselect: (t) => i.deselect(b(t)),
646
+ deselect: (t) => i.deselect(y(t)),
645
647
  /** Select records on the current page */
646
648
  selectPage: K,
647
649
  /** Deselect records on the current page */
648
- deselectPage: N,
650
+ deselectPage: C,
649
651
  /** Toggle the selection of the given records */
650
- toggle: (t) => i.toggle(b(t)),
652
+ toggle: (t) => i.toggle(y(t)),
651
653
  /** Determine if the given record is selected */
652
- selected: (t) => i.selected(b(t)),
654
+ selected: (t) => i.selected(y(t)),
653
655
  /** Select all records */
654
656
  selectAll: i.selectAll,
655
657
  /** Deselect all records */
656
658
  deselectAll: i.deselectAll,
657
659
  /** Whether all records on the current page are selected */
658
- isPageSelected: T,
660
+ isPageSelected: G,
659
661
  /** Determine if any records are selected */
660
662
  hasSelected: i.hasSelected,
661
663
  /** Bind the given record to a checkbox */
662
- bindCheckbox: (t) => i.bind(b(t)),
664
+ bindCheckbox: (t) => i.bind(y(t)),
663
665
  /** Bind the select all checkbox to the current page */
664
- bindPage: q,
666
+ bindPage: N,
665
667
  /** Bind select all records to the checkbox */
666
668
  bindAll: i.bindAll,
667
669
  /** Include the sorts, filters, and search query */
668
670
  ...g
669
671
  });
670
672
  }
671
- function ie(l, v) {
672
- return l ? typeof l == "object" ? l.type === v : l === v : !1;
673
+ function ie(a, v) {
674
+ return a ? typeof a == "object" ? a.type === v : a === v : !1;
673
675
  }
674
676
  export {
675
677
  ie as is,
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(V,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):(V=typeof globalThis<"u"?globalThis:V||self,c(V["@honed/table"]={},V.Vue,V.Inertia))})(this,function(V,c,S){"use strict";function Y(l,f,s,a={}){return l.route?(S.router.visit(l.route.url,{...a,method:l.route.method}),!0):l.action&&f?(S.router.post(f,{...s,name:l.name,type:l.type},a),!0):!1}function Q(l,f,s,a={},p={}){return Y(l,f,{...a,id:s??void 0},p)}function Z(l,f,s,a={}){return l.map(p=>({...p,execute:(o={},i={})=>Q(p,f,s,o,{...a,...i})}))}function _(){const l=c.ref({all:!1,only:new Set,except:new Set});function f(){l.value.all=!0,l.value.only.clear(),l.value.except.clear()}function s(){l.value.all=!1,l.value.only.clear(),l.value.except.clear()}function a(...d){d.forEach(h=>l.value.except.delete(h)),d.forEach(h=>l.value.only.add(h))}function p(...d){d.forEach(h=>l.value.except.add(h)),d.forEach(h=>l.value.only.delete(h))}function o(d,h){if(i(d)||h===!1)return p(d);if(!i(d)||h===!0)return a(d)}function i(d){return l.value.all?!l.value.except.has(d):l.value.only.has(d)}const g=c.computed(()=>l.value.all&&l.value.except.size===0),k=c.computed(()=>l.value.only.size>0||g.value);function x(d){return{"onUpdate:modelValue":h=>{h?a(d):p(d)},modelValue:i(d),value:d}}function w(){return{"onUpdate:modelValue":d=>{d?f():s()},modelValue:g.value}}return{allSelected:g,selection:l,hasSelected:k,selectAll:f,deselectAll:s,select:a,deselect:p,toggle:o,selected:i,bind:x,bindAll:w}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const X=()=>{};function ee(l,f){function s(...a){return new Promise((p,o)=>{Promise.resolve(l(()=>f.apply(this,a),{fn:f,thisArg:this,args:a})).then(p).catch(o)})}return s}function te(l,f={}){let s,a,p=X;const o=g=>{clearTimeout(g),p(),p=X};let i;return g=>{const k=c.toValue(l),x=c.toValue(f.maxWait);return s&&o(s),k<=0||x!==void 0&&x<=0?(a&&(o(a),a=null),Promise.resolve(g())):new Promise((w,d)=>{p=f.rejectOnCancel?d:w,i=g,x&&!a&&(a=setTimeout(()=>{s&&o(s),a=null,w(i())},x)),s=setTimeout(()=>{a&&o(a),a=null,w(g())},k)})}}function q(l,f=200,s={}){return ee(te(f,s),l)}function ne(l,f,s={}){if(!(l!=null&&l[f]))throw new Error("The refine must be provided with valid props and key.");const a=c.computed(()=>l[f]),p=c.computed(()=>!!a.value.sort),o=c.computed(()=>!!a.value.search),i=c.computed(()=>!!a.value.match),g=c.computed(()=>{var e;return(e=a.value.filters)==null?void 0:e.map(n=>({...n,apply:(r,v={})=>T(n,r,v),clear:(r={})=>B(n,r),bind:()=>H(n.name)}))}),k=c.computed(()=>{var e;return(e=a.value.sorts)==null?void 0:e.map(n=>({...n,apply:(r={})=>A(n,n.direction,r),clear:(r={})=>K(r),bind:()=>t(n)}))}),x=c.computed(()=>{var e;return(e=a.value.searches)==null?void 0:e.map(n=>({...n,apply:(r={})=>$(n,r),clear:(r={})=>$(n,r),bind:()=>m(n)}))}),w=c.computed(()=>g.value.filter(({active:e})=>e)),d=c.computed(()=>k.value.find(({active:e})=>e)),h=c.computed(()=>x.value.filter(({active:e})=>e));function R(e){return Array.isArray(e)?e.join(a.value.delimiter):e}function U(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function j(e){if(!["",null,void 0,[]].includes(e))return e}function z(e){return[R,U,j].reduce((n,r)=>r(n),e)}function G(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(r=>r!==e):[...n,e]}function C(e){return typeof e!="string"?e:g.value.find(({name:n})=>n===e)}function y(e,n=null){return typeof e!="string"?e:k.value.find(({name:r,direction:v})=>r===e&&v===n)}function E(e){return typeof e!="string"?e:x.value.find(({name:n})=>n===e)}function b(e){return e?typeof e=="string"?w.value.some(n=>n.name===e):e.active:!!w.value.length}function I(e){var n;return e?typeof e=="string"?((n=d.value)==null?void 0:n.name)===e:e.active:!!d.value}function F(e){var n;return e?typeof e=="string"?(n=h.value)==null?void 0:n.some(r=>r.name===e):e.active:!!a.value.term}function O(e,n={}){const r=Object.fromEntries(Object.entries(e).map(([v,P])=>[v,z(P)]));S.router.reload({...s,...n,data:r})}function T(e,n,r={}){const v=C(e);if(!v)return console.warn(`Filter [${e}] does not exist.`);S.router.reload({...s,...r,data:{[v.name]:z(n)}})}function A(e,n=null,r={}){if(!p.value)return console.warn("Refine cannot perform sorting.");const v=y(e,n);if(!v)return console.warn(`Sort [${e}] does not exist.`);S.router.reload({...s,...r,data:{[a.value.sort]:j(v.next)}})}function M(e,n={}){if(!o.value)return console.warn("Refine cannot perform searching.");e=[U,j].reduce((r,v)=>v(r),e),S.router.reload({...s,...n,data:{[a.value.search]:e}})}function $(e,n={}){if(!i.value||!o.value)return console.warn("Refine cannot perform matching.");const r=E(e);if(!r)return console.warn(`Match [${e}] does not exist.`);const v=G(r.name,h.value.map(({name:P})=>P));S.router.reload({...s,...n,data:{[a.value.match]:R(v)}})}function B(e,n={}){if(e)return T(e,null,n);S.router.reload({...s,...n,data:Object.fromEntries(w.value.map(({name:r})=>[r,null]))})}function K(e={}){if(!p.value)return console.warn("Refine cannot perform sorting.");S.router.reload({...s,...e,data:{[a.value.sort]:null}})}function J(e={}){M(null,e)}function N(e={}){if(!i.value)return console.warn("Refine cannot perform matching.");S.router.reload({...s,...e,data:{[a.value.match]:null}})}function D(e={}){var n;S.router.reload({...s,...e,data:{[a.value.search??""]:void 0,[a.value.sort??""]:void 0,[a.value.match??""]:void 0,...Object.fromEntries(((n=a.value.filters)==null?void 0:n.map(r=>[r.name,void 0]))??[])}})}function H(e,n={}){const r=C(e);if(!r)return console.warn(`Filter [${e}] does not exist.`);const{debounce:v=250,transform:P=L=>L,...W}=n;return{"onUpdate:modelValue":q(L=>{T(r,P(L),W)},v),modelValue:r.value}}function t(e,n={}){const r=y(e);if(!r)return console.warn(`Sort [${e}] does not exist.`);const{debounce:v=0,transform:P,...W}=n;return{onClick:q(()=>{var L;A(r,(L=d.value)==null?void 0:L.direction,W)},v)}}function u(e={}){const{debounce:n=700,transform:r,...v}=e;return{"onUpdate:modelValue":q(P=>{M(P,v)},n),modelValue:a.value.term??""}}function m(e,n={}){const r=E(e);if(!r)return console.warn(`Match [${e}] does not exist.`);const{debounce:v=0,transform:P,...W}=n;return{"onUpdate:modelValue":q(L=>{$(L,W)},v),modelValue:F(r),value:r.name}}return{filters:g,sorts:k,searches:x,currentFilters:w,currentSort:d,currentSearches:h,isSortable:p,isSearchable:o,isMatchable:i,isFiltering:b,isSorting:I,isSearching:F,getFilter:C,getSort:y,getSearch:E,apply:O,applyFilter:T,applySort:A,applySearch:M,applyMatch:$,clearFilter:B,clearSort:K,clearSearch:J,clearMatch:N,reset:D,bindFilter:H,bindSort:t,bindSearch:u,bindMatch:m,stringValue:U,omitValue:j,toggleValue:G,delimitArray:R}}function le(l,f,s={}){if(!(l!=null&&l[f]))throw new Error("The table must be provided with valid props and key.");const{recordOperations:a={},...p}={only:[...s.only??[],f.toString()],...s},o=c.computed(()=>l[f]),i=_(),g=ne(l,f,p),k=c.computed(()=>o.value.meta),x=c.computed(()=>!!o.value.page&&!!o.value.record),w=c.computed(()=>!!o.value.column),d=c.computed(()=>o.value.columns.filter(({active:t,hidden:u})=>t&&!u).map(t=>{var u;return{...t,isSorting:!!((u=t.sort)!=null&&u.active),toggleSort:(m={})=>g.applySort(t.sort,null,m)}})),h=c.computed(()=>o.value.columns.filter(({hidden:t})=>!t).map(t=>({...t,toggle:(u={})=>J(t.name,u)}))),R=c.computed(()=>o.value.records.map(t=>({operations:T(t.operations),default:(u={})=>{const m=t.operations.find(({default:e})=>e);m&&M(m,t,u)},select:()=>i.select(b(t)),deselect:()=>i.deselect(b(t)),toggle:()=>i.toggle(b(t)),selected:i.selected(b(t)),bind:()=>i.bind(b(t)),entry:u=>F(t,u),value:u=>{var m;return((m=F(t,u))==null?void 0:m.v)??null},extra:u=>{var m;return((m=F(t,u))==null?void 0:m.e)??null}}))),U=c.computed(()=>!!o.value.operations.inline),j=c.computed(()=>T(o.value.operations.bulk)),z=c.computed(()=>T(o.value.operations.page)),G=c.computed(()=>o.value.pages.find(({active:t})=>t)),C=c.computed(()=>o.value.pages),y=c.computed(()=>({...o.value.paginate,next:(t={})=>{"nextLink"in y.value&&y.value.nextLink&&A(y.value.nextLink,t)},previous:(t={})=>{"prevLink"in y.value&&y.value.prevLink&&A(y.value.prevLink,t)},first:(t={})=>{"firstLink"in y.value&&y.value.firstLink&&A(y.value.firstLink,t)},last:(t={})=>{"lastLink"in y.value&&y.value.lastLink&&A(y.value.lastLink,t)},..."links"in o.value.paginate&&o.value.paginate.links?{links:o.value.paginate.links.map(t=>({...t,navigate:(u={})=>t.url&&A(t.url,u)}))}:{}})),E=c.computed(()=>o.value.records.length>0&&o.value.records.every(t=>i.selected(b(t))));function b(t){return t[o.value.key].v}function I(t){return typeof t=="string"?t:t.name}function F(t,u){const m=I(u);return m in t?t[m]:null}function O(t,u={},m={}){return Q(t,o.value.endpoint,o.value.id,u,{...p,...m})}function T(t){return Z(t,o.value.endpoint,o.value.id,p)}function A(t,u={}){S.router.visit(t,{preserveScroll:!0,preserveState:!0,...p,...u,method:"get"})}function M(t,u,m={}){var n;O(t,{record:b(u)},m)||(n=a==null?void 0:a[t.name])==null||n.call(a,u)}function $(t,u={}){O(t,{all:i.selection.value.all,only:Array.from(i.selection.value.only),except:Array.from(i.selection.value.except)},{...u,onSuccess:m=>{var e;(e=u.onSuccess)==null||e.call(u,m),t.keepSelected||i.deselectAll()}})}function B(t,u={},m={}){return O(t,u,m)}function K(t,u={}){if(!x.value)return console.warn("The table does not support pagination changes.");S.router.reload({...p,...u,data:{[o.value.record]:t.value,[o.value.page]:void 0}})}function J(t,u={}){if(!w.value)return console.warn("The table does not support column toggling.");const m=I(t);if(!m)return console.log(`Column [${t}] does not exist.`);const e=g.toggleValue(m,d.value.map(({name:n})=>n));S.router.reload({...p,...u,data:{[o.value.column]:g.delimitArray(e)}})}function N(){i.select(...o.value.records.map(t=>b(t)))}function D(){i.deselect(...o.value.records.map(t=>b(t)))}function H(){return{"onUpdate:modelValue":t=>{t?N():D()},modelValue:E.value}}return c.reactive({meta:k,isPageable:x,isToggleable:w,getRecordKey:b,headings:d,columns:h,records:R,inline:U,bulk:j,page:z,pages:C,currentPage:G,paginator:y,executeInline:M,executeBulk:$,executePage:B,applyPage:K,selection:i.selection,select:t=>i.select(b(t)),deselect:t=>i.deselect(b(t)),selectPage:N,deselectPage:D,toggle:t=>i.toggle(b(t)),selected:t=>i.selected(b(t)),selectAll:i.selectAll,deselectAll:i.deselectAll,isPageSelected:E,hasSelected:i.hasSelected,bindCheckbox:t=>i.bind(b(t)),bindPage:H,bindAll:i.bindAll,...g})}function ae(l,f){return l?typeof l=="object"?l.type===f:l===f:!1}V.is=ae,V.useTable=le,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,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):(k=typeof globalThis<"u"?globalThis:k||self,c(k["@honed/table"]={},k.Vue,k.Inertia))})(this,function(k,c,b){"use strict";function Y(a,f,s,r={}){return a.route?(b.router.visit(a.route.url,{...r,method:a.route.method}),!0):a.action&&f?(b.router.post(f,{...s,name:a.name,type:a.type},r),!0):!1}function Q(a,f,s,r={},m={}){return Y(a,f,{...r,id:s??void 0},m)}function Z(a,f,s,r={}){return a.map(m=>({...m,execute:(o={},i={})=>Q(m,f,s,o,{...r,...i})}))}function _(){const a=c.ref({all:!1,only:new Set,except:new Set});function f(){a.value.all=!0,a.value.only.clear(),a.value.except.clear()}function s(){a.value.all=!1,a.value.only.clear(),a.value.except.clear()}function r(...d){d.forEach(v=>a.value.except.delete(v)),d.forEach(v=>a.value.only.add(v))}function m(...d){d.forEach(v=>a.value.except.add(v)),d.forEach(v=>a.value.only.delete(v))}function o(d,v){if(i(d)||v===!1)return m(d);if(!i(d)||v===!0)return r(d)}function i(d){return a.value.all?!a.value.except.has(d):a.value.only.has(d)}const g=c.computed(()=>a.value.all&&a.value.except.size===0),w=c.computed(()=>a.value.only.size>0||g.value);function x(d){return{"onUpdate:modelValue":v=>{v?r(d):m(d)},modelValue:i(d),value:d}}function S(){return{"onUpdate:modelValue":d=>{d?f():s()},modelValue:g.value}}return{allSelected:g,selection:a,hasSelected:w,selectAll:f,deselectAll:s,select:r,deselect:m,toggle:o,selected:i,bind:x,bindAll:S}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const X=()=>{};function ee(a,f){function s(...r){return new Promise((m,o)=>{Promise.resolve(a(()=>f.apply(this,r),{fn:f,thisArg:this,args:r})).then(m).catch(o)})}return s}function te(a,f={}){let s,r,m=X;const o=g=>{clearTimeout(g),m(),m=X};let i;return g=>{const w=c.toValue(a),x=c.toValue(f.maxWait);return s&&o(s),w<=0||x!==void 0&&x<=0?(r&&(o(r),r=null),Promise.resolve(g())):new Promise((S,d)=>{m=f.rejectOnCancel?d:S,i=g,x&&!r&&(r=setTimeout(()=>{s&&o(s),r=null,S(i())},x)),s=setTimeout(()=>{r&&o(r),r=null,S(g())},w)})}}function q(a,f=200,s={}){return ee(te(f,s),a)}function ne(a,f,s={}){if(!(a!=null&&a[f]))throw new Error("The refine must be provided with valid props and key.");const r=c.computed(()=>a[f]),m=c.computed(()=>!!r.value.sort),o=c.computed(()=>!!r.value.search),i=c.computed(()=>!!r.value.match),g=c.computed(()=>{var e;return(e=r.value.filters)==null?void 0:e.map(n=>({...n,apply:(l,p={})=>P(n,l,p),clear:(l={})=>B(n,l),bind:()=>O(n.name)}))}),w=c.computed(()=>{var e;return(e=r.value.sorts)==null?void 0:e.map(n=>({...n,apply:(l={})=>L(n,n.direction,l),clear:(l={})=>K(l),bind:()=>D(n)}))}),x=c.computed(()=>{var e;return(e=r.value.searches)==null?void 0:e.map(n=>({...n,apply:(l={})=>j(n,l),clear:(l={})=>j(n,l),bind:()=>u(n)}))}),S=c.computed(()=>g.value.filter(({active:e})=>e)),d=c.computed(()=>w.value.find(({active:e})=>e)),v=c.computed(()=>x.value.filter(({active:e})=>e));function F(e){return Array.isArray(e)?e.join(r.value.delimiter):e}function M(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function E(e){if(!["",null,void 0,[]].includes(e))return e}function z(e){return[F,M,E].reduce((n,l)=>l(n),e)}function G(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(l=>l!==e):[...n,e]}function $(e){return typeof e!="string"?e:g.value.find(({name:n})=>n===e)}function R(e,n=null){return typeof e!="string"?e:w.value.find(({name:l,direction:p})=>l===e&&p===n)}function h(e){return typeof e!="string"?e:x.value.find(({name:n})=>n===e)}function I(e){return e?typeof e=="string"?S.value.some(n=>n.name===e):e.active:!!S.value.length}function y(e){var n;return e?typeof e=="string"?((n=d.value)==null?void 0:n.name)===e:e.active:!!d.value}function U(e){var n;return e?typeof e=="string"?(n=v.value)==null?void 0:n.some(l=>l.name===e):e.active:!!r.value.term}function C(e,n={}){const l=Object.fromEntries(Object.entries(e).map(([p,A])=>[p,z(A)]));b.router.reload({...s,...n,data:l})}function P(e,n,l={}){const p=$(e);if(!p)return console.warn(`Filter [${e}] does not exist.`);b.router.reload({...s,...l,data:{[p.name]:z(n)}})}function L(e,n=null,l={}){if(!m.value)return console.warn("Refine cannot perform sorting.");const p=R(e,n);if(!p)return console.warn(`Sort [${e}] does not exist.`);b.router.reload({...s,...l,data:{[r.value.sort]:E(p.next)}})}function V(e,n={}){if(!o.value)return console.warn("Refine cannot perform searching.");e=[M,E].reduce((l,p)=>p(l),e),b.router.reload({...s,...n,data:{[r.value.search]:e}})}function j(e,n={}){if(!i.value||!o.value)return console.warn("Refine cannot perform matching.");const l=h(e);if(!l)return console.warn(`Match [${e}] does not exist.`);const p=G(l.name,v.value.map(({name:A})=>A));b.router.reload({...s,...n,data:{[r.value.match]:F(p)}})}function B(e,n={}){if(e)return P(e,null,n);b.router.reload({...s,...n,data:Object.fromEntries(S.value.map(({name:l})=>[l,null]))})}function K(e={}){if(!m.value)return console.warn("Refine cannot perform sorting.");b.router.reload({...s,...e,data:{[r.value.sort]:null}})}function H(e={}){V(null,e)}function J(e={}){if(!i.value)return console.warn("Refine cannot perform matching.");b.router.reload({...s,...e,data:{[r.value.match]:null}})}function N(e={}){var n;b.router.reload({...s,...e,data:{[r.value.search??""]:void 0,[r.value.sort??""]:void 0,[r.value.match??""]:void 0,...Object.fromEntries(((n=r.value.filters)==null?void 0:n.map(l=>[l.name,void 0]))??[])}})}function O(e,n={}){const l=$(e);if(!l)return console.warn(`Filter [${e}] does not exist.`);const{debounce:p=250,transform:A=T=>T,...W}=n;return{"onUpdate:modelValue":q(T=>{P(l,A(T),W)},p),modelValue:l.value}}function D(e,n={}){const l=R(e);if(!l)return console.warn(`Sort [${e}] does not exist.`);const{debounce:p=0,transform:A,...W}=n;return{onClick:q(()=>{var T;L(l,(T=d.value)==null?void 0:T.direction,W)},p)}}function t(e={}){const{debounce:n=700,transform:l,...p}=e;return{"onUpdate:modelValue":q(A=>{V(A,p)},n),modelValue:r.value.term??""}}function u(e,n={}){const l=h(e);if(!l)return console.warn(`Match [${e}] does not exist.`);const{debounce:p=0,transform:A,...W}=n;return{"onUpdate:modelValue":q(T=>{j(T,W)},p),modelValue:U(l),value:l.name}}return{filters:g,sorts:w,searches:x,currentFilters:S,currentSort:d,currentSearches:v,isSortable:m,isSearchable:o,isMatchable:i,isFiltering:I,isSorting:y,isSearching:U,getFilter:$,getSort:R,getSearch:h,apply:C,applyFilter:P,applySort:L,applySearch:V,applyMatch:j,clearFilter:B,clearSort:K,clearSearch:H,clearMatch:J,reset:N,bindFilter:O,bindSort:D,bindSearch:t,bindMatch:u,stringValue:M,omitValue:E,toggleValue:G,delimitArray:F}}function le(a,f,s={}){if(!(a!=null&&a[f]))throw new Error("The table must be provided with valid props and key.");const{recordOperations:r={},...m}={only:[...s.only??[],f.toString()],...s},o=c.computed(()=>a[f]),i=_(),g=ne(a,f,m),w=c.computed(()=>o.value.meta),x=c.computed(()=>!!o.value.emptyState),S=c.computed(()=>!!o.value.page&&!!o.value.record),d=c.computed(()=>!!o.value.column),v=c.computed(()=>o.value.columns.filter(({active:t,hidden:u})=>t&&!u).map(t=>{var u;return{...t,isSorting:!!((u=t.sort)!=null&&u.active),toggleSort:(e={})=>g.applySort(t.sort,null,e)}})),F=c.computed(()=>o.value.columns.filter(({hidden:t})=>!t).map(t=>({...t,toggle:(u={})=>J(t.name,u)}))),M=c.computed(()=>o.value.records.map(t=>({operations:L(t.operations),default:(u={})=>{const e=t.operations.find(({default:n})=>n);e&&j(e,t,u)},select:()=>i.select(y(t)),deselect:()=>i.deselect(y(t)),toggle:()=>i.toggle(y(t)),selected:i.selected(y(t)),bind:()=>i.bind(y(t)),entry:u=>C(t,u),value:u=>{var e;return((e=C(t,u))==null?void 0:e.v)??null},extra:u=>{var e;return((e=C(t,u))==null?void 0:e.e)??null}}))),E=c.computed(()=>!!o.value.operations.inline),z=c.computed(()=>L(o.value.operations.bulk)),G=c.computed(()=>L(o.value.operations.page)),$=c.computed(()=>o.value.pages.find(({active:t})=>t)),R=c.computed(()=>o.value.pages),h=c.computed(()=>({...o.value.paginate,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&V(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&V(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&V(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&V(h.value.lastLink,t)},..."links"in o.value.paginate&&o.value.paginate.links?{links:o.value.paginate.links.map(t=>({...t,navigate:(u={})=>t.url&&V(t.url,u)}))}:{}})),I=c.computed(()=>o.value.records.length>0&&o.value.records.every(t=>i.selected(y(t))));function y(t){return t[o.value.key].v}function U(t){return typeof t=="string"?t:t.name}function C(t,u){const e=U(u);return e in t?t[e]:null}function P(t,u={},e={}){return Q(t,o.value.endpoint,o.value.id,u,{...m,...e})}function L(t){return Z(t,o.value.endpoint,o.value.id,m)}function V(t,u={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...m,...u,method:"get"})}function j(t,u,e={}){var l;P(t,{record:y(u)},e)||(l=r==null?void 0:r[t.name])==null||l.call(r,u)}function B(t,u={}){P(t,{all:i.selection.value.all,only:Array.from(i.selection.value.only),except:Array.from(i.selection.value.except)},{...u,onSuccess:e=>{var n;(n=u.onSuccess)==null||n.call(u,e),t.keepSelected||i.deselectAll()}})}function K(t,u={},e={}){return P(t,u,e)}function H(t,u={}){if(!S.value)return console.warn("The table does not support pagination changes.");b.router.reload({...m,...u,data:{[o.value.record]:t.value,[o.value.page]:void 0}})}function J(t,u={}){if(!d.value)return console.warn("The table does not support column toggling.");const e=U(t);if(!e)return console.log(`Column [${t}] does not exist.`);const n=g.toggleValue(e,v.value.map(({name:l})=>l));b.router.reload({...m,...u,data:{[o.value.column]:g.delimitArray(n)}})}function N(){i.select(...o.value.records.map(t=>y(t)))}function O(){i.deselect(...o.value.records.map(t=>y(t)))}function D(){return{"onUpdate:modelValue":t=>{t?N():O()},modelValue:I.value}}return c.reactive({meta:w,isEmpty:x,isPageable:S,isToggleable:d,getRecordKey:y,headings:v,columns:F,records:M,inline:E,bulk:z,page:G,pages:R,currentPage:$,paginator:h,executeInline:j,executeBulk:B,executePage:K,applyPage:H,selection:i.selection,select:t=>i.select(y(t)),deselect:t=>i.deselect(y(t)),selectPage:N,deselectPage:O,toggle:t=>i.toggle(y(t)),selected:t=>i.selected(y(t)),selectAll:i.selectAll,deselectAll:i.deselectAll,isPageSelected:I,hasSelected:i.hasSelected,bindCheckbox:t=>i.bind(y(t)),bindPage:D,bindAll:i.bindAll,...g})}function ae(a,f){return a?typeof a=="object"?a.type===f:a===f:!1}k.is=ae,k.useTable=le,Object.defineProperty(k,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.9.0",
4
+ "version": "0.9.1",
5
5
  "license": "MIT",
6
6
  "description": "-",
7
7
  "keywords": [