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