@honed/table 0.3.1 → 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;
@@ -183,7 +197,7 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
183
197
  applyFilter: (filter: string | Filter, value: any, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
184
198
  applySort: (sort: string | Sort, direction?: Direction | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
185
199
  applySearch: (value: string | null | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
186
- applyMatch: (value: string | Search, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
200
+ applyMatch: (search: string | Search, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
187
201
  clearFilter: (filter: string | Filter, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
188
202
  clearSort: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
189
203
  clearSearch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
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,273 +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: (r, c = {}) => L(n, r, c),
117
+ apply: (r, v = {}) => L(n, r, v),
118
118
  clear: (r = {}) => N(n, r),
119
- bind: () => a(n.name)
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
127
  apply: (r = {}) => M(n, n.direction, r),
128
- clear: (r = {}) => W(r),
129
- bind: () => f(n)
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
137
  apply: (r = {}) => U(n, r),
138
138
  clear: (r = {}) => U(n, r),
139
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(
168
+ function B(e) {
169
+ return [k, c, g].reduce(
155
170
  (n, r) => r(n),
156
171
  e
157
172
  );
158
173
  }
159
- function s(e, n) {
174
+ function j(e, n) {
160
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((r) => r.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) {
181
+ function h(e, n = null) {
167
182
  var r;
168
- return (r = l.value.sorts) == null ? void 0 : r.find(
169
- (c) => c.name === e && c.direction === n
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((r) => r.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 w() {
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
198
  function P(e) {
196
- var n, r;
197
- return e ? typeof e == "string" ? (r = w()) == null ? void 0 : r.some((c) => c.name === e) : e.active : !!((n = w()) != null && n.length);
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 = {}) {
202
+ function W(e, n = {}) {
200
203
  const r = Object.fromEntries(
201
- Object.entries(e).map(([c, E]) => [c, k(E)])
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
209
  data: r
207
210
  });
208
211
  }
209
212
  function L(e, n, r = {}) {
210
- const c = typeof e == "string" ? p(e) : e;
211
- if (!c) {
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,
218
+ "multiple" in v && v.multiple && n !== void 0 && (n = j(n, v.value)), x.reload({
219
+ ...d,
217
220
  ...r,
218
221
  data: {
219
- [c.name]: k(n)
222
+ [v.name]: B(n)
220
223
  }
221
224
  });
222
225
  }
223
226
  function M(e, n = null, r = {}) {
224
- const c = typeof e == "string" ? j(e, n) : e;
225
- if (!c) {
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,
232
+ x.reload({
233
+ ...d,
231
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
- (r, c) => c(r),
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
- if (!(typeof e == "string" ? C(e) : e)) {
257
+ const r = typeof e == "string" ? E(e) : e;
258
+ if (!r) {
255
259
  console.warn(`Match [${e}] does not exist.`);
256
260
  return;
257
261
  }
258
- const r = s(
259
- e,
260
- w().filter(({ active: c }) => c).map(({ name: c }) => c)
262
+ const v = j(
263
+ r.name,
264
+ S.value.map(({ name: V }) => V)
261
265
  );
262
- S.reload({
263
- ...v,
266
+ x.reload({
267
+ ...d,
264
268
  ...n,
265
269
  data: {
266
- [l.value.config.matches]: d(r)
270
+ [a.value.config.matches]: k(v)
267
271
  }
268
272
  });
269
273
  }
270
274
  function N(e, n = {}) {
271
275
  L(e, void 0, n);
272
276
  }
273
- function W(e = {}) {
274
- S.reload({
275
- ...v,
277
+ function z(e = {}) {
278
+ x.reload({
279
+ ...d,
276
280
  ...e,
277
281
  data: {
278
- [l.value.config.sorts]: null
282
+ [a.value.config.sorts]: void 0
279
283
  }
280
284
  });
281
285
  }
@@ -283,91 +287,91 @@ function ee(o, m, v = {}) {
283
287
  T(void 0, e);
284
288
  }
285
289
  function D(e = {}) {
286
- if (!l.value.config.matches) {
290
+ if (!a.value.config.matches) {
287
291
  console.warn("Matches key is not set.");
288
292
  return;
289
293
  }
290
- S.reload({
291
- ...v,
294
+ x.reload({
295
+ ...d,
292
296
  ...e,
293
297
  data: {
294
- [l.value.config.matches]: void 0
298
+ [a.value.config.matches]: void 0
295
299
  }
296
300
  });
297
301
  }
298
302
  function t(e = {}) {
299
303
  var n;
300
- S.reload({
301
- ...v,
304
+ x.reload({
305
+ ...d,
302
306
  ...e,
303
307
  data: {
304
- [l.value.config.searches]: void 0,
305
- [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,
306
311
  ...Object.fromEntries(
307
- ((n = l.value.filters) == null ? void 0 : n.map((r) => [
312
+ ((n = a.value.filters) == null ? void 0 : n.map((r) => [
308
313
  r.name,
309
314
  void 0
310
315
  ])) ?? []
311
- ),
312
- ...l.value.config.matches ? { [l.value.config.matches]: void 0 } : {}
316
+ )
313
317
  }
314
318
  });
315
319
  }
316
- function a(e, n = {}) {
317
- const r = typeof e == "string" ? p(e) : e;
320
+ function l(e, n = {}) {
321
+ const r = typeof e == "string" ? C(e) : e;
318
322
  if (!r) {
319
323
  console.warn(`Filter [${e}] does not exist.`);
320
324
  return;
321
325
  }
322
- const c = r.value, {
323
- debounce: E = 250,
324
- transform: B = (H) => H,
326
+ const v = r.value, {
327
+ debounce: V = 250,
328
+ transform: G = (H) => H,
325
329
  ...$
326
330
  } = n;
327
331
  return {
328
332
  "onUpdate:modelValue": q((H) => {
329
- L(r, B(H), $);
330
- }, E),
331
- modelValue: c
333
+ L(r, G(H), $);
334
+ }, V),
335
+ modelValue: v
332
336
  };
333
337
  }
334
- function f(e, n = {}) {
335
- const r = typeof e == "string" ? j(e) : e;
338
+ function s(e, n = {}) {
339
+ const r = typeof e == "string" ? h(e) : e;
336
340
  if (!r) {
337
341
  console.warn(`Sort [${e}] does not exist.`);
338
342
  return;
339
343
  }
340
- const { debounce: c = 0, transform: E, ...B } = n;
344
+ const { debounce: v = 0, transform: V, ...G } = n;
341
345
  return {
342
346
  onClick: q(() => {
343
347
  var $;
344
- M(r, ($ = g()) == null ? void 0 : $.direction, B);
345
- }, c)
348
+ M(r, ($ = A.value) == null ? void 0 : $.direction, G);
349
+ }, v)
346
350
  };
347
351
  }
348
- function V(e = {}) {
349
- const { debounce: n = 700, transform: r, ...c } = e;
352
+ function w(e = {}) {
353
+ const { debounce: n = 700, transform: r, ...v } = e;
350
354
  return {
351
355
  "onUpdate:modelValue": q(
352
- (E) => {
353
- T(E, c);
356
+ (V) => {
357
+ T(V, v);
354
358
  },
355
359
  n
356
360
  ),
357
- modelValue: l.value.config.search ?? ""
361
+ modelValue: a.value.config.search ?? ""
358
362
  };
359
363
  }
360
364
  function F(e, n = {}) {
361
- const r = typeof e == "string" ? C(e) : e;
365
+ const r = typeof e == "string" ? E(e) : e;
362
366
  if (!r) {
363
367
  console.warn(`Match [${e}] does not exist.`);
364
368
  return;
365
369
  }
366
- const { debounce: c = 0, transform: E, ...B } = n;
370
+ const { debounce: v = 0, transform: V, ...G } = n;
367
371
  return {
368
372
  "onUpdate:modelValue": q(($) => {
369
- U($, B);
370
- }, c),
373
+ U($, G);
374
+ }, v),
371
375
  modelValue: P(r),
372
376
  value: r.name
373
377
  };
@@ -376,77 +380,77 @@ function ee(o, m, v = {}) {
376
380
  filters: i,
377
381
  sorts: u,
378
382
  searches: b,
379
- getFilter: p,
380
- getSort: j,
381
- getSearch: C,
382
- currentFilters: z,
383
- currentSort: g,
384
- currentSearches: w,
383
+ getFilter: C,
384
+ getSort: h,
385
+ getSearch: E,
386
+ currentFilters: f,
387
+ currentSort: A,
388
+ currentSearches: S,
385
389
  isFiltering: y,
386
390
  isSorting: K,
387
391
  isSearching: P,
388
- apply: G,
392
+ apply: W,
389
393
  applyFilter: L,
390
394
  applySort: M,
391
395
  applySearch: T,
392
396
  applyMatch: U,
393
397
  clearFilter: N,
394
- clearSort: W,
398
+ clearSort: z,
395
399
  clearSearch: R,
396
400
  clearMatch: D,
397
401
  reset: t,
398
- bindFilter: a,
399
- bindSort: f,
400
- bindSearch: V,
402
+ bindFilter: l,
403
+ bindSort: s,
404
+ bindSearch: w,
401
405
  bindMatch: F,
402
- stringValue: A,
403
- omitValue: x,
404
- toggleValue: s,
405
- delimitArray: d
406
+ stringValue: c,
407
+ omitValue: g,
408
+ toggleValue: j,
409
+ delimitArray: k
406
410
  };
407
411
  }
408
- function le(o, m, v = {}, l = {}) {
412
+ function ae(o, m, d = {}, a = {}) {
409
413
  if (!o || !m || !o[m])
410
414
  throw new Error("Table has not been provided with valid props and key.");
411
- l = {
412
- ...l,
413
- only: [...l.only ?? [], m.toString()]
415
+ a = {
416
+ ...a,
417
+ only: [...a.only ?? [], m.toString()]
414
418
  };
415
- 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(
416
420
  () => {
417
421
  var t;
418
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: f }) => a && !f).map((a) => {
419
- var f;
422
+ return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: l, hidden: s }) => l && !s).map((l) => {
423
+ var s;
420
424
  return {
421
- ...a,
422
- isSorting: (f = a.sort) == null ? void 0 : f.active,
423
- toggleSort: (V = {}) => U(a, V)
425
+ ...l,
426
+ isSorting: (s = l.sort) == null ? void 0 : s.active,
427
+ toggleSort: (w = {}) => U(l, w)
424
428
  };
425
429
  })) ?? [];
426
430
  }
427
- ), k = h(
431
+ ), k = p(
428
432
  () => {
429
433
  var t;
430
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
431
- ...a,
432
- toggle: (f = {}) => N(a, 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)
433
437
  }))) ?? [];
434
438
  }
435
- ), s = h(
439
+ ), c = p(
436
440
  () => i.value.records.map((t) => ({
437
- record: (({ actions: a, ...f }) => f)(t),
441
+ record: (({ actions: l, ...s }) => s)(t),
438
442
  /** Perform this action when the record is clicked */
439
- default: (a = {}) => {
440
- const f = t.actions.find(
441
- (V) => V.default
443
+ default: (l = {}) => {
444
+ const s = t.actions.find(
445
+ (w) => w.default
442
446
  );
443
- f && G(f, t, a);
447
+ s && W(s, t, l);
444
448
  },
445
449
  /** The actions available for the record */
446
- actions: t.actions.map((a) => ({
447
- ...a,
450
+ actions: t.actions.map((l) => ({
451
+ ...l,
448
452
  /** Executes this action */
449
- execute: (f = {}) => G(a, t, f)
453
+ execute: (s = {}) => W(l, t, s)
450
454
  })),
451
455
  /** Selects this record */
452
456
  select: () => u.select(y(t)),
@@ -459,144 +463,150 @@ function le(o, m, v = {}, l = {}) {
459
463
  /** Bind the record to a checkbox */
460
464
  bind: () => u.bind(y(t)),
461
465
  /** Get the value of the record for the column */
462
- value: (a) => t[K(a)].value,
466
+ value: (l) => {
467
+ var s;
468
+ return (s = t[K(l)]) == null ? void 0 : s.value;
469
+ },
463
470
  /** Get the extra data of the record for the column */
464
- extra: (a) => t[K(a)].extra
471
+ extra: (l) => {
472
+ var s;
473
+ return (s = t[K(l)]) == null ? void 0 : s.extra;
474
+ }
465
475
  }))
466
- ), p = h(
476
+ ), g = p(
467
477
  () => i.value.actions.bulk.map((t) => ({
468
478
  ...t,
469
479
  /** Executes this bulk action */
470
- execute: (a = {}) => L(t, a)
480
+ execute: (l = {}) => L(t, l)
471
481
  }))
472
- ), j = h(
482
+ ), B = p(
473
483
  () => i.value.actions.page.map((t) => ({
474
484
  ...t,
475
485
  /** Executes this page action */
476
- execute: (a = {}) => M(t, a)
486
+ execute: (l = {}) => M(t, l)
477
487
  }))
478
- ), C = h(
488
+ ), j = p(
479
489
  () => {
480
490
  var t;
481
- return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
482
- ...a,
491
+ return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((l) => ({
492
+ ...l,
483
493
  /** Changes the number of records to display per page */
484
- apply: (f = {}) => T(a, f)
494
+ apply: (s = {}) => T(l, s)
485
495
  }))) ?? [];
486
496
  }
487
- ), z = h(
497
+ ), C = p(
488
498
  () => {
489
499
  var t;
490
- return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: a }) => a);
500
+ return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: l }) => l);
491
501
  }
492
- ), g = h(() => ({
502
+ ), h = p(() => ({
493
503
  ...i.value.paginator,
494
504
  next: (t = {}) => {
495
- "nextLink" in g.value && g.value.nextLink && P(g.value.nextLink, t);
505
+ "nextLink" in h.value && h.value.nextLink && P(h.value.nextLink, t);
496
506
  },
497
507
  previous: (t = {}) => {
498
- "prevLink" in g.value && g.value.prevLink && P(g.value.prevLink, t);
508
+ "prevLink" in h.value && h.value.prevLink && P(h.value.prevLink, t);
499
509
  },
500
510
  first: (t = {}) => {
501
- "firstLink" in g.value && g.value.firstLink && P(g.value.firstLink, t);
511
+ "firstLink" in h.value && h.value.firstLink && P(h.value.firstLink, t);
502
512
  },
503
513
  last: (t = {}) => {
504
- "lastLink" in g.value && g.value.lastLink && P(g.value.lastLink, t);
514
+ "lastLink" in h.value && h.value.lastLink && P(h.value.lastLink, t);
505
515
  },
506
516
  ..."links" in i.value.paginator && i.value.paginator.links ? {
507
517
  links: i.value.paginator.links.map((t) => ({
508
518
  ...t,
509
- navigate: (a = {}) => t.url && P(t.url, a)
519
+ navigate: (l = {}) => t.url && P(t.url, l)
510
520
  }))
511
521
  } : {}
512
- })), w = h(
522
+ })), E = p(
513
523
  () => i.value.records.length > 0 && i.value.records.every(
514
524
  (t) => u.selected(y(t))
515
525
  )
516
526
  );
517
527
  function y(t) {
518
- return t[d.value.record].value;
528
+ return t[f.value.record].value;
519
529
  }
520
530
  function K(t) {
521
531
  return typeof t == "string" ? t : t.name;
522
532
  }
523
- function P(t, a = {}) {
524
- S.visit(t, {
533
+ function P(t, l = {}) {
534
+ x.visit(t, {
525
535
  preserveScroll: !0,
526
536
  preserveState: !0,
527
- ...l,
528
537
  ...a,
538
+ ...l,
529
539
  method: "get"
530
540
  });
531
541
  }
532
- function G(t, a, f = {}) {
542
+ function W(t, l, s = {}) {
533
543
  var F, e;
534
544
  I(
535
545
  t,
536
- d.value.endpoint,
546
+ f.value.endpoint,
537
547
  {
538
548
  table: i.value.id,
539
- id: y(a)
549
+ id: y(l)
540
550
  },
541
- f
542
- ) || (e = (F = v.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
551
+ s
552
+ ) || (e = (F = d.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, l);
543
553
  }
544
- function L(t, a = {}) {
554
+ function L(t, l = {}) {
545
555
  I(
546
556
  t,
547
- d.value.endpoint,
557
+ f.value.endpoint,
548
558
  {
549
559
  table: i.value.id,
550
560
  all: u.selection.value.all,
551
561
  only: Array.from(u.selection.value.only),
552
562
  except: Array.from(u.selection.value.except)
553
563
  },
554
- a
564
+ l
555
565
  );
556
566
  }
557
- function M(t, a = {}) {
567
+ function M(t, l = {}) {
558
568
  I(
559
569
  t,
560
- d.value.endpoint,
570
+ f.value.endpoint,
561
571
  {
562
572
  table: i.value.id
563
573
  },
564
- a
574
+ l
565
575
  );
566
576
  }
567
- function T(t, a = {}) {
568
- S.reload({
569
- ...l,
577
+ function T(t, l = {}) {
578
+ x.reload({
570
579
  ...a,
580
+ ...l,
571
581
  data: {
572
- [d.value.records]: t.value,
573
- [d.value.pages]: void 0
582
+ [f.value.records]: t.value,
583
+ [f.value.pages]: void 0
574
584
  }
575
585
  });
576
586
  }
577
- function U(t, a = {}) {
578
- t.sort && S.reload({
579
- ...l,
587
+ function U(t, l = {}) {
588
+ t.sort && x.reload({
580
589
  ...a,
590
+ ...l,
581
591
  data: {
582
- [d.value.sorts]: b.omitValue(t.sort.next)
592
+ [f.value.sorts]: b.omitValue(t.sort.next)
583
593
  }
584
594
  });
585
595
  }
586
- function N(t, a = {}) {
587
- const f = b.toggleValue(
596
+ function N(t, l = {}) {
597
+ const s = b.toggleValue(
588
598
  t.name,
589
- x.value.map(({ name: V }) => V)
599
+ S.value.map(({ name: w }) => w)
590
600
  );
591
- S.reload({
592
- ...l,
601
+ x.reload({
593
602
  ...a,
603
+ ...l,
594
604
  data: {
595
- [d.value.columns]: b.delimitArray(f)
605
+ [f.value.columns]: b.delimitArray(s)
596
606
  }
597
607
  });
598
608
  }
599
- function W() {
609
+ function z() {
600
610
  u.select(
601
611
  ...i.value.records.map(
602
612
  (t) => y(t)
@@ -613,9 +623,9 @@ function le(o, m, v = {}, l = {}) {
613
623
  function D() {
614
624
  return {
615
625
  "onUpdate:modelValue": (t) => {
616
- t ? W() : R();
626
+ t ? z() : R();
617
627
  },
618
- modelValue: w.value
628
+ modelValue: E.value
619
629
  };
620
630
  }
621
631
  return Q({
@@ -624,23 +634,23 @@ function le(o, m, v = {}, l = {}) {
624
634
  /** Table-specific metadata */
625
635
  meta: A,
626
636
  /** The heading columns for the table */
627
- headings: x,
637
+ headings: S,
628
638
  /** All of the table's columns */
629
639
  columns: k,
630
640
  /** The records of the table */
631
- records: s,
641
+ records: c,
632
642
  /** The available bulk actions */
633
- bulkActions: p,
643
+ bulkActions: g,
634
644
  /** The available page actions */
635
- pageActions: j,
645
+ pageActions: B,
636
646
  /** The available number of records to display per page */
637
- rowsPerPage: C,
647
+ rowsPerPage: j,
638
648
  /** The current record per page item */
639
- currentPage: z,
649
+ currentPage: C,
640
650
  /** The pagination metadata */
641
- paginator: g,
651
+ paginator: h,
642
652
  /** Execute an inline action */
643
- executeInlineAction: G,
653
+ executeInlineAction: W,
644
654
  /** Execute a bulk action */
645
655
  executeBulkAction: L,
646
656
  /** Execute a page action */
@@ -654,7 +664,7 @@ function le(o, m, v = {}, l = {}) {
654
664
  /** Deselect the given records */
655
665
  deselect: (t) => u.deselect(y(t)),
656
666
  /** Select records on the current page */
657
- selectPage: W,
667
+ selectPage: z,
658
668
  /** Deselect records on the current page */
659
669
  deselectPage: R,
660
670
  /** Toggle the selection of the given records */
@@ -666,7 +676,7 @@ function le(o, m, v = {}, l = {}) {
666
676
  /** Deselect all records */
667
677
  deselectAll: u.deselectAll,
668
678
  /** Whether all records on the current page are selected */
669
- isPageSelected: w,
679
+ isPageSelected: E,
670
680
  /** Determine if any records are selected */
671
681
  hasSelected: u.hasSelected,
672
682
  /** Bind the given record to a checkbox */
@@ -680,5 +690,5 @@ function le(o, m, v = {}, l = {}) {
680
690
  });
681
691
  }
682
692
  export {
683
- le as useTable
693
+ ae as useTable
684
694
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(V,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):(V=typeof globalThis<"u"?globalThis:V||self,d(V["@honed/table"]={},V.Vue,V.Inertia))})(this,function(V,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 l(...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 l(s)}function x(s){return r.value.all?!r.value.except.has(s):r.value.only.has(s)}const v=d.computed(()=>r.value.all&&r.value.except.size===0),A=d.computed(()=>r.value.only.size>0||v.value);function S(s){return{"onUpdate:modelValue":g=>{g?l(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:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,m,f={},l={}){return r.route?(b.router.visit(r.route.href,{...l,method:r.route.method}),!0):r.action&&m?(b.router.post(m,{...f,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,m){function f(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>m.apply(this,l),{fn:m,thisArg:this,args:l})).then(i).catch(u)})}return f}function X(r,m={}){let f,l,i=Y;const u=v=>{clearTimeout(v),i(),i=Y};let x;return v=>{const A=d.toValue(r),S=d.toValue(m.maxWait);return f&&u(f),A<=0||S!==void 0&&S<=0?(l&&(u(l),l=null),Promise.resolve(v())):new Promise((k,s)=>{i=m.rejectOnCancel?s:k,x=v,S&&!l&&(l=setTimeout(()=>{f&&u(f),l=null,k(x())},S)),f=setTimeout(()=>{l&&u(l),l=null,k(v())},A)})}}function I(r,m=200,f={}){return Q(X(m,f),r)}function Z(r,m,f={}){const l=d.computed(()=>r[m]),i=d.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,c={})=>T(n,o,c),clear:(o={})=>N(n,o),bind:()=>a(n.name)})))??[]}),u=d.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>E(n,n.direction,o),clear:(o={})=>W(o),bind:()=>p(n)})))??[]}),x=d.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>U(n,o),clear:(o={})=>U(n,o),bind:()=>j(n)}))});function v(e){return Array.isArray(e)?e.join(l.value.config.delimiter):e}function A(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function S(e){if(!["",null,void 0,[]].includes(e))return e}function k(e){return[v,A,S].reduce((n,o)=>o(n),e)}function s(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(o=>o!==e):[...n,e]}function g(e){var n;return(n=l.value.filters)==null?void 0:n.find(o=>o.name===e)}function C(e,n=null){var o;return(o=l.value.sorts)==null?void 0:o.find(c=>c.name===e&&c.direction===n)}function q(e){var n;return(n=l.value.searches)==null?void 0:n.find(o=>o.name===e)}function z(){var e;return((e=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}function h(){var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}function L(){var e;return((e=l.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 P(e){var n,o;return e?typeof e=="string"?(o=L())==null?void 0:o.some(c=>c.name===e):e.active:!!((n=L())!=null&&n.length)}function G(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([c,F])=>[c,k(F)]));b.router.reload({...f,...n,data:o})}function T(e,n,o={}){const c=typeof e=="string"?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,...o,data:{[c.name]:k(n)}})}function E(e,n=null,o={}){const c=typeof e=="string"?C(e,n):e;if(!c){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...f,...o,data:{[l.value.config.sorts]:S(c.next)}})}function M(e,n={}){e=[A,S].reduce((o,c)=>c(o),e),b.router.reload({...f,...n,data:{[l.value.config.searches]:e}})}function U(e,n={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}if(!(typeof e=="string"?q(e):e)){console.warn(`Match [${e}] does not exist.`);return}const o=s(e,L().filter(({active:c})=>c).map(({name:c})=>c));b.router.reload({...f,...n,data:{[l.value.config.matches]:v(o)}})}function N(e,n={}){T(e,void 0,n)}function W(e={}){b.router.reload({...f,...e,data:{[l.value.config.sorts]:null}})}function R(e={}){M(void 0,e)}function H(e={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}b.router.reload({...f,...e,data:{[l.value.config.matches]:void 0}})}function t(e={}){var n;b.router.reload({...f,...e,data:{[l.value.config.searches]:void 0,[l.value.config.sorts]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[]),...l.value.config.matches?{[l.value.config.matches]:void 0}:{}}})}function a(e,n={}){const o=typeof e=="string"?g(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const c=o.value,{debounce:F=250,transform:B=J=>J,...$}=n;return{"onUpdate:modelValue":I(J=>{T(o,B(J),$)},F),modelValue:c}}function p(e,n={}){const o=typeof e=="string"?C(e):e;if(!o){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:c=0,transform:F,...B}=n;return{onClick:I(()=>{var $;E(o,($=h())==null?void 0:$.direction,B)},c)}}function w(e={}){const{debounce:n=700,transform:o,...c}=e;return{"onUpdate:modelValue":I(F=>{M(F,c)},n),modelValue:l.value.config.search??""}}function j(e,n={}){const o=typeof e=="string"?q(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const{debounce:c=0,transform:F,...B}=n;return{"onUpdate:modelValue":I($=>{U($,B)},c),modelValue:P(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:g,getSort:C,getSearch:q,currentFilters:z,currentSort:h,currentSearches:L,isFiltering:y,isSorting:K,isSearching:P,apply:G,applyFilter:T,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:W,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:p,bindSearch:w,bindMatch:j,stringValue:A,omitValue:S,toggleValue:s,delimitArray:v}}function O(r,m,f={},l={}){if(!r||!m||!r[m])throw new Error("Table has not been provided with valid props and key.");l={...l,only:[...l.only??[],m.toString()]};const i=d.computed(()=>r[m]),u=_(),x=Z(r,m,l),v=d.computed(()=>i.value.config),A=d.computed(()=>i.value.meta),S=d.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:a,hidden:p})=>a&&!p).map(a=>{var p;return{...a,isSorting:(p=a.sort)==null?void 0:p.active,toggleSort:(w={})=>U(a,w)}}))??[]}),k=d.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(p={})=>N(a,p)})))??[]}),s=d.computed(()=>i.value.records.map(t=>({record:(({actions:a,...p})=>p)(t),default:(a={})=>{const p=t.actions.find(w=>w.default);p&&G(p,t,a)},actions:t.actions.map(a=>({...a,execute:(p={})=>G(a,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:a=>t[K(a)].value,extra:a=>t[K(a)].extra}))),g=d.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>T(t,a)}))),C=d.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>E(t,a)}))),q=d.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(p={})=>M(a,p)})))??[]}),z=d.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),h=d.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&P(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&P(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&P(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&P(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(a={})=>t.url&&P(t.url,a)}))}:{}})),L=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 P(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function G(t,a,p={}){var j,e;D(t,v.value.endpoint,{table:i.value.id,id:y(a)},p)||(e=(j=f.recordActions)==null?void 0:j[t.name])==null||e.call(j,a)}function T(t,a={}){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)},a)}function E(t,a={}){D(t,v.value.endpoint,{table:i.value.id},a)}function M(t,a={}){b.router.reload({...l,...a,data:{[v.value.records]:t.value,[v.value.pages]:void 0}})}function U(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[v.value.sorts]:x.omitValue(t.sort.next)}})}function N(t,a={}){const p=x.toggleValue(t.name,S.value.map(({name:w})=>w));b.router.reload({...l,...a,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:L.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:T,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:L,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:H,bindAll:u.bindAll,...x})}V.useTable=O,Object.defineProperty(V,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.1",
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.1",
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",