@honed/table 0.7.0 → 0.8.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
@@ -1,67 +1,70 @@
1
1
  import { BindingOptions } from '@honed/refine';
2
- import { BulkAction } from '@honed/action';
2
+ import { BulkOperation } from '@honed/action';
3
3
  import { BulkSelection } from '@honed/action';
4
- import { Config as Config_2 } from '@honed/refine';
5
- import { Confirm } from '@honed/action';
6
4
  import { Direction } from '@honed/refine';
7
5
  import { Filter } from '@honed/refine';
8
6
  import { FilterValue } from '@honed/refine';
9
- import { InlineAction } from '@honed/action';
7
+ import { InlineOperation } from '@honed/action';
8
+ import { MaybeEndpoint } from '@honed/action';
9
+ import { MaybeId } from '@honed/action';
10
10
  import { Option as Option_2 } from '@honed/refine';
11
- import { PageAction } from '@honed/action';
11
+ import { PageOperation } from '@honed/action';
12
+ import { PageOperationData } from '@honed/action';
12
13
  import { PromisifyFn } from '@vueuse/shared';
13
14
  import { Refine } from '@honed/refine';
14
- import { Route } from '@honed/action';
15
15
  import { Search } from '@honed/refine';
16
16
  import { Sort } from '@honed/refine';
17
17
  import { Visit } from '@inertiajs/core';
18
18
  import { VisitCallbacks } from '@inertiajs/core';
19
19
  import { VisitOptions } from '@inertiajs/core';
20
20
 
21
- export declare type AsRecord<RecordType extends Record<string, any> = any> = {
22
- [K in keyof RecordType]: {
23
- value: RecordType[K];
24
- extra: Record<string, any>;
25
- };
26
- };
27
-
28
- export declare interface CollectionPaginator {
29
- empty: boolean;
30
- }
31
-
32
- export declare interface Column<T extends Record<string, any> = Record<string, any>> {
21
+ export declare interface BaseColumn<T extends Record<string, any> = Record<string, any>> {
33
22
  name: keyof T;
34
23
  label: string;
35
- type: "array" | "badge" | "boolean" | "currency" | "date" | "hidden" | "key" | "number" | "text" | string;
24
+ type?: ColumnType;
36
25
  hidden: boolean;
37
26
  active: boolean;
27
+ badge?: boolean;
38
28
  toggleable: boolean;
39
- icon?: string;
40
29
  class?: string;
41
- sort?: {
42
- active: boolean;
43
- direction: Direction;
44
- next: string | null;
45
- };
30
+ record_class?: string;
31
+ icon?: string;
32
+ sort?: Pick<Sort, "active" | "direction" | "next">;
46
33
  }
47
34
 
48
- export declare interface Config extends Config_2 {
49
- endpoint: string;
50
- key: string;
51
- record: string;
52
- column: string;
53
- page: string;
35
+ export declare interface CollectionPaginate {
36
+ empty: boolean;
54
37
  }
55
38
 
56
- export declare interface CursorPaginator extends CollectionPaginator {
39
+ export declare interface Column<T extends Record<string, any> = Record<string, any>> extends BaseColumn<T> {
40
+ toggle: (options: VisitOptions) => void;
41
+ }
42
+
43
+ export declare type ColumnType = "array" | "badge" | "boolean" | "color" | "date" | "datetime" | "icon" | "image" | "numeric" | "text" | "time" | string;
44
+
45
+ export declare interface CursorPaginate extends CollectionPaginate {
57
46
  prevLink: string | null;
58
47
  nextLink: string | null;
59
48
  perPage: number;
60
49
  }
61
50
 
51
+ export declare interface EmptyState {
52
+ title: string;
53
+ description: string;
54
+ icon?: string;
55
+ operations: PageOperation[];
56
+ }
57
+
58
+ export declare interface Heading<T extends Record<string, any> = Record<string, any>> extends BaseColumn<T> {
59
+ isSorting: boolean;
60
+ toggleSort: (options: VisitOptions) => void;
61
+ }
62
+
62
63
  export declare type Identifier = string | number;
63
64
 
64
- export declare interface LengthAwarePaginator extends SimplePaginator {
65
+ export declare function is(column: Column | string | null | undefined, type: ColumnType): boolean;
66
+
67
+ export declare interface LengthAwarePaginate extends SimplePaginate {
65
68
  total: number;
66
69
  from: number;
67
70
  to: number;
@@ -70,7 +73,19 @@ export declare interface LengthAwarePaginator extends SimplePaginator {
70
73
  links: PaginatorLink[];
71
74
  }
72
75
 
73
- export declare type PaginatorKind = "cursor" | "length-aware" | "simple" | "collection";
76
+ export declare interface PageOption {
77
+ value: number;
78
+ active: boolean;
79
+ }
80
+
81
+ export declare type Paginate = "cursor" | "length-aware" | "simple" | "collection";
82
+
83
+ export declare type PaginateMap = {
84
+ cursor: CursorPaginate;
85
+ "length-aware": LengthAwarePaginate;
86
+ simple: SimplePaginate;
87
+ collection: CollectionPaginate;
88
+ };
74
89
 
75
90
  export declare interface PaginatorLink {
76
91
  url: string | null;
@@ -78,53 +93,54 @@ export declare interface PaginatorLink {
78
93
  active: boolean;
79
94
  }
80
95
 
81
- export declare interface PerPageRecord {
82
- value: number;
83
- active: boolean;
84
- }
85
-
86
- export declare interface SimplePaginator extends CursorPaginator {
96
+ export declare interface SimplePaginate extends CursorPaginate {
87
97
  currentPage: number;
88
98
  }
89
99
 
90
- export declare interface Table<RecordType extends Record<string, any> = any, Paginator extends PaginatorKind = "length-aware"> extends Refine {
91
- config: Config;
92
- id: string;
93
- records: Array<AsRecord<RecordType> & {
94
- actions: InlineAction[];
100
+ export declare interface Table<T extends Record<string, any> = Record<string, any>, K extends Paginate = "length-aware"> extends Refine {
101
+ id: MaybeId;
102
+ endpoint: MaybeEndpoint;
103
+ key: string;
104
+ column?: string;
105
+ record?: string;
106
+ page?: string;
107
+ records: Array<TableEntry<T> & {
108
+ actions: InlineOperation[];
95
109
  }>;
96
- paginator: Paginator extends "length-aware" ? LengthAwarePaginator : Paginator extends "simple" ? SimplePaginator : Paginator extends "cursor" ? CursorPaginator : CollectionPaginator;
97
- columns?: Column<RecordType>[];
98
- recordsPerPage?: PerPageRecord[];
110
+ paginate: PaginateMap[K];
111
+ columns: BaseColumn<T>[];
112
+ pages: PageOption[];
99
113
  toggleable: boolean;
100
- actions: {
114
+ operations: {
101
115
  inline: boolean;
102
- bulk: BulkAction[];
103
- page: PageAction[];
116
+ bulk: BulkOperation[];
117
+ page: PageOperation[];
104
118
  };
119
+ emptyState?: EmptyState;
120
+ views?: View[];
105
121
  meta: Record<string, any>;
106
122
  }
107
123
 
108
- export declare interface TableColumn<T extends Record<string, any> = Record<string, any>> extends Column<T> {
109
- toggle: (options: VisitOptions) => void;
110
- }
111
-
112
- export declare interface TableHeading<T extends Record<string, any> = Record<string, any>> extends Column<T> {
113
- isSorting: boolean;
114
- toggleSort: (options: VisitOptions) => void;
115
- }
124
+ export declare type TableEntry<RecordType extends Record<string, any> = any> = {
125
+ [K in keyof RecordType]: {
126
+ v: RecordType[K];
127
+ e: any;
128
+ c: string | null;
129
+ f: boolean;
130
+ };
131
+ };
116
132
 
117
- export declare interface TableOptions<RecordType extends Record<string, any> = Record<string, any>> {
133
+ export declare interface TableOptions<RecordType extends Record<string, any> = Record<string, any>> extends VisitOptions {
118
134
  /**
119
- * Actions to be applied on a record in JavaScript.
135
+ * Mappings of operations to be applied on a record in JavaScript.
120
136
  */
121
- recordActions?: Record<string, (record: AsRecord<RecordType>) => void>;
137
+ recordActions?: Record<string, (record: TableEntry<RecordType>) => void>;
122
138
  }
123
139
 
124
140
  export declare interface TableRecord<RecordType extends Record<string, any> = Record<string, any>> {
125
141
  record: RecordType;
126
142
  default: (options?: VisitOptions) => void;
127
- actions: InlineAction[];
143
+ actions: InlineOperation[];
128
144
  select: () => void;
129
145
  deselect: () => void;
130
146
  toggle: () => void;
@@ -136,18 +152,18 @@ export declare interface TableRecord<RecordType extends Record<string, any> = Re
136
152
 
137
153
  export declare type UseTable = typeof useTable;
138
154
 
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): {
155
+ export declare function useTable<T extends Record<string, Table>, K extends Record<string, any> = Record<string, any>, U extends Paginate = "length-aware">(props: T, key: keyof T, defaults?: TableOptions): {
140
156
  filters: {
141
- apply: (value: Props, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
157
+ apply: (value: T, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
142
158
  clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
143
- bind: () => {
159
+ bind: () => void | {
144
160
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
145
- modelValue: unknown;
146
- } | undefined;
161
+ modelValue: FilterValue;
162
+ }; /** Bind the record to a checkbox */
147
163
  type: string;
148
164
  value: FilterValue;
149
165
  options: Option_2[];
150
- name: string;
166
+ name: string; /** Get the value of the record for the column */
151
167
  label: string;
152
168
  active: boolean;
153
169
  meta: Record<string, any>;
@@ -155,9 +171,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
155
171
  sorts: {
156
172
  apply: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
157
173
  clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
158
- bind: () => {
174
+ bind: () => void | {
159
175
  onClick: PromisifyFn<() => void>;
160
- } | undefined;
176
+ };
161
177
  type: string;
162
178
  direction: Direction;
163
179
  next: string | null;
@@ -169,115 +185,72 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
169
185
  searches: {
170
186
  apply: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
171
187
  clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
172
- /**
173
- * Get the bulk actions.
174
- */
175
- bind: () => {
188
+ bind: () => void | {
176
189
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
177
190
  modelValue: boolean;
178
191
  value: string;
179
- } | undefined;
192
+ };
180
193
  type: string;
181
194
  name: string;
182
195
  label: string;
183
196
  active: boolean;
184
- /**
185
- * Get page actions.
186
- */
187
197
  meta: Record<string, any>;
188
- }[] | undefined;
189
- getFilter: (name: string) => Filter | undefined;
190
- getSort: (name: string, direction?: Direction | undefined) => Sort | undefined;
191
- getSearch: (name: string) => Search | undefined;
198
+ }[];
192
199
  currentFilters: Filter[];
193
200
  currentSort: Sort | undefined;
194
201
  currentSearches: Search[];
202
+ isSortable: boolean;
203
+ isSearchable: boolean;
204
+ isMatchable: boolean;
195
205
  isFiltering: (name?: string | Filter | undefined) => boolean;
196
206
  isSorting: (name?: string | Sort | undefined) => boolean;
197
207
  isSearching: (name?: string | Search | undefined) => boolean;
198
- apply: (values: Record<string, any>, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
208
+ getFilter: (filter: string | Filter) => Filter | undefined;
209
+ getSort: (sort: string | Sort, dir?: Direction | undefined) => Sort | undefined;
210
+ getSearch: (search: string | Search) => Search | undefined;
211
+ apply: (values: Record<string, FilterValue>, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
199
212
  applyFilter: (filter: string | Filter, value: any, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
200
213
  applySort: (sort: string | Sort, direction?: Direction | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
201
214
  applySearch: (value: string | null | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
202
215
  applyMatch: (search: string | Search, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
203
- clearFilter: (filter: string | Filter, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
216
+ clearFilter: (filter?: string | Filter | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
204
217
  clearSort: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
205
218
  clearSearch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
206
219
  clearMatch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
207
220
  reset: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
208
- bindFilter: <T_1 extends unknown>(filter: string | Filter, options?: BindingOptions | undefined) => {
221
+ bindFilter: (filter: string | Filter, options?: BindingOptions | undefined) => void | {
209
222
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
210
- modelValue: T_1;
211
- } | undefined;
212
- bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => {
223
+ modelValue: FilterValue;
224
+ };
225
+ bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => void | {
213
226
  onClick: PromisifyFn<() => void>;
214
- } | undefined;
227
+ };
215
228
  bindSearch: (options?: BindingOptions | undefined) => {
216
229
  "onUpdate:modelValue": PromisifyFn<(value: string | null | undefined) => void>;
217
230
  modelValue: string;
218
231
  };
219
- bindMatch: (match: string | Search, options?: BindingOptions | undefined) => {
232
+ bindMatch: (match: string | Search, options?: BindingOptions | undefined) => void | {
220
233
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
221
234
  modelValue: boolean;
222
235
  value: string;
223
- } | undefined;
236
+ };
224
237
  stringValue: (value: any) => any;
225
238
  omitValue: (value: any) => any;
226
239
  toggleValue: (value: any, values: any) => any;
227
240
  delimitArray: (value: any) => any;
228
- getRecordKey: (record: AsRecord<RecordType>) => Identifier;
241
+ table: Table<K, U>;
242
+ getRecordKey: (record: TableEntry<K>) => Identifier;
229
243
  meta: Record<string, any>;
230
- headings: {
231
- isSorting: boolean | undefined;
232
- toggleSort: (options?: VisitOptions) => void;
233
- name: keyof RecordType;
234
- label: string;
235
- type: string;
236
- hidden: boolean;
237
- active: boolean;
238
- toggleable: boolean;
239
- icon?: string | undefined;
240
- class?: string | undefined;
241
- sort?: {
242
- active: boolean;
243
- direction: Direction;
244
- next: string | null;
245
- } | undefined;
246
- }[];
247
- columns: {
248
- toggle: (options?: VisitOptions) => void;
249
- name: keyof RecordType;
250
- label: string;
251
- type: string;
252
- hidden: boolean;
253
- active: boolean;
254
- toggleable: boolean;
255
- icon?: string | undefined;
256
- class?: string | undefined;
257
- sort?: {
258
- active: boolean;
259
- direction: Direction;
260
- next: string | null;
261
- } | undefined;
262
- }[];
244
+ headings: Heading<K>[];
245
+ columns: Column<K>[];
263
246
  records: {
264
- record: Omit<AsRecord<RecordType> & {
265
- actions: InlineAction[];
247
+ record: Omit<TableEntry<K> & {
248
+ actions: InlineOperation[];
266
249
  }, "actions">;
267
250
  /** The actions available for the record */
268
- actions: {
269
- /** Executes this action */
270
- execute: (options?: VisitOptions) => void;
271
- type: "inline";
272
- default: boolean;
273
- name: string;
274
- label: string;
275
- icon?: string | undefined;
276
- extra?: Record<string, unknown> | undefined;
277
- action?: boolean | undefined;
278
- confirm?: Confirm | undefined;
279
- route?: Route | undefined;
280
- }[];
251
+ actions: (InlineOperation & {
252
+ execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
253
+ })[];
281
254
  /** Perform this action when the record is clicked */
282
255
  default: (options?: VisitOptions) => void;
283
256
  /** Selects this record */
@@ -290,48 +263,28 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
290
263
  selected: boolean;
291
264
  /** Bind the record to a checkbox */
292
265
  bind: () => {
293
- "onUpdate:modelValue": (checked: boolean | "indeterminate") => void; /**
294
- * The current number of records to display per page.
295
- */
266
+ "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
296
267
  modelValue: boolean;
297
268
  value: Identifier;
298
269
  };
299
270
  /** Get the value of the record for the column */
300
- value: (column: Column<RecordType> | string) => RecordType[string] | RecordType[number] | RecordType[symbol] | null;
271
+ value: (column: Column<K> | string) => K[string] | K[number] | K[symbol] | null;
301
272
  /** Get the extra data of the record for the column */
302
- extra: (column: Column<RecordType> | string) => Record<string, any> | null;
273
+ extra: (column: Column<K> | string) => any;
303
274
  }[];
304
275
  inline: boolean;
305
- bulkActions: {
306
- execute: (options?: VisitOptions) => void;
307
- type: "bulk";
308
- keepSelected: boolean;
309
- name: string;
310
- label: string;
311
- icon?: string | undefined;
312
- extra?: Record<string, unknown> | undefined;
313
- action?: boolean | undefined;
314
- confirm?: Confirm | undefined;
315
- route?: Route | undefined;
316
- }[];
317
- pageActions: {
318
- execute: (options?: VisitOptions) => void;
319
- type: "page";
320
- name: string;
321
- label: string;
322
- icon?: string | undefined;
323
- extra?: Record<string, unknown> | undefined;
324
- action?: boolean | undefined;
325
- confirm?: Confirm | undefined;
326
- route?: Route | undefined;
327
- }[];
328
- rowsPerPage: {
329
- apply: (options?: VisitOptions) => void;
276
+ bulk: (BulkOperation & {
277
+ execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
278
+ })[];
279
+ page: (PageOperation & {
280
+ execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
281
+ })[];
282
+ pages: {
330
283
  value: number;
331
284
  active: boolean;
332
285
  }[];
333
- currentPage: PerPageRecord | undefined;
334
- paginator: (Paginator extends "length-aware" ? LengthAwarePaginator : Paginator extends "simple" ? SimplePaginator : Paginator extends "cursor" ? CursorPaginator : CollectionPaginator) & {
286
+ currentPage: PageOption | undefined;
287
+ paginator: PaginateMap[U] & {
335
288
  links?: {
336
289
  navigate: (options?: VisitOptions) => void | "" | null;
337
290
  url: string | null;
@@ -343,25 +296,23 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
343
296
  first: (options?: VisitOptions) => void;
344
297
  last: (options?: VisitOptions) => void;
345
298
  };
346
- executeInlineAction: (action: InlineAction, record: AsRecord<RecordType>, options?: VisitOptions) => void;
347
- executeBulkAction: (action: BulkAction, options?: VisitOptions) => void;
348
- executePageAction: (action: PageAction, options?: VisitOptions) => void;
349
- applyPage: (page: PerPageRecord, options?: VisitOptions) => void;
299
+ executeInline: (operation: InlineOperation, data: TableEntry<K>, options?: VisitOptions) => void;
300
+ executeBulk: (operation: BulkOperation, options?: VisitOptions) => void;
301
+ executePage: (operation: PageOperation, data?: PageOperationData, options?: VisitOptions) => boolean;
302
+ applyPage: (page: PageOption, options?: VisitOptions) => void;
350
303
  selection: BulkSelection<Identifier>;
351
- select: (record: AsRecord<RecordType>) => void;
352
- deselect: (record: AsRecord<RecordType>) => void;
304
+ select: (record: TableEntry<K>) => void;
305
+ deselect: (record: TableEntry<K>) => void;
353
306
  selectPage: () => void;
354
307
  deselectPage: () => void;
355
- toggle: (record: AsRecord<RecordType>) => void;
356
- selected: (record: AsRecord<RecordType>) => boolean;
308
+ toggle: (record: TableEntry<K>) => void;
309
+ selected: (record: TableEntry<K>) => boolean;
357
310
  selectAll: () => void;
358
311
  deselectAll: () => void;
359
312
  isPageSelected: boolean;
360
313
  hasSelected: boolean;
361
- bindCheckbox: (record: AsRecord<RecordType>) => {
362
- "onUpdate:modelValue": (checked: boolean | "indeterminate") => void; /**
363
- * The current number of records to display per page.
364
- */
314
+ bindCheckbox: (record: TableEntry<K>) => {
315
+ "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
365
316
  modelValue: boolean;
366
317
  value: Identifier;
367
318
  };
@@ -372,8 +323,13 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
372
323
  bindAll: () => {
373
324
  "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
374
325
  modelValue: boolean;
375
- value: boolean;
376
326
  };
377
327
  };
378
328
 
329
+ export declare interface View {
330
+ id: number;
331
+ name: string;
332
+ view: string;
333
+ }
334
+
379
335
  export { }