@honed/table 0.3.2 → 0.4.0

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