@honed/table 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -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;
37
+ }
38
+
39
+ export declare interface Column<T extends Record<string, any> = Record<string, any>> extends BaseColumn<T> {
40
+ toggle: (options: VisitOptions) => void;
54
41
  }
55
42
 
56
- export declare interface CursorPaginator extends CollectionPaginator {
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
+ operations: 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
+ recordOperations?: 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
+ operations: InlineOperation[];
128
144
  select: () => void;
129
145
  deselect: () => void;
130
146
  toggle: () => void;
@@ -136,14 +152,14 @@ 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
+ };
147
163
  type: string;
148
164
  value: FilterValue;
149
165
  options: Option_2[];
@@ -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,116 +185,76 @@ 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
- bind: () => {
188
+ bind: () => void | {
173
189
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
174
190
  modelValue: boolean;
175
191
  value: string;
176
- } | undefined;
192
+ };
177
193
  type: string;
178
194
  name: string;
179
195
  label: string;
180
196
  active: boolean;
181
197
  meta: Record<string, any>;
182
- }[] | undefined;
183
- getFilter: (name: string) => Filter | undefined;
184
- getSort: (name: string, direction?: Direction | undefined) => Sort | undefined;
185
- getSearch: (name: string) => Search | undefined;
198
+ }[];
186
199
  currentFilters: Filter[];
187
200
  currentSort: Sort | undefined;
188
201
  currentSearches: Search[];
202
+ isSortable: boolean;
203
+ isSearchable: boolean;
204
+ isMatchable: boolean;
189
205
  isFiltering: (name?: string | Filter | undefined) => boolean;
190
206
  isSorting: (name?: string | Sort | undefined) => boolean;
191
207
  isSearching: (name?: string | Search | undefined) => boolean;
192
- 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;
193
212
  applyFilter: (filter: string | Filter, value: any, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
194
213
  applySort: (sort: string | Sort, direction?: Direction | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
195
214
  applySearch: (value: string | null | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
196
215
  applyMatch: (search: string | Search, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
197
- clearFilter: (filter: string | Filter, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
216
+ clearFilter: (filter?: string | Filter | undefined, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
198
217
  clearSort: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
199
218
  clearSearch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
200
219
  clearMatch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
201
220
  reset: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
202
- bindFilter: <T_1 extends unknown>(filter: string | Filter, options?: BindingOptions | undefined) => {
221
+ bindFilter: (filter: string | Filter, options?: BindingOptions | undefined) => void | {
203
222
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
204
- modelValue: T_1;
205
- } | undefined;
206
- bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => {
223
+ modelValue: FilterValue;
224
+ };
225
+ bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => void | {
207
226
  onClick: PromisifyFn<() => void>;
208
- } | undefined;
227
+ };
209
228
  bindSearch: (options?: BindingOptions | undefined) => {
210
229
  "onUpdate:modelValue": PromisifyFn<(value: string | null | undefined) => void>;
211
230
  modelValue: string;
212
231
  };
213
- bindMatch: (match: string | Search, options?: BindingOptions | undefined) => {
232
+ bindMatch: (match: string | Search, options?: BindingOptions | undefined) => void | {
214
233
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
234
+ /**
235
+ * Create operations with execute methods
236
+ */
215
237
  modelValue: boolean;
216
238
  value: string;
217
- } | undefined;
239
+ };
218
240
  stringValue: (value: any) => any;
219
241
  omitValue: (value: any) => any;
220
242
  toggleValue: (value: any, values: any) => any;
221
243
  delimitArray: (value: any) => any;
222
- getRecordKey: (record: AsRecord<RecordType>) => Identifier;
244
+ table: Table<K, U>;
245
+ getRecordKey: (record: TableEntry<K>) => Identifier;
223
246
  meta: Record<string, any>;
224
- headings: {
225
- isSorting: boolean | undefined;
226
- toggleSort: (options?: VisitOptions) => void;
227
- name: keyof RecordType;
228
- /**
229
- * The heading columns for the table.
230
- */
231
- label: string;
232
- type: string;
233
- hidden: boolean;
234
- active: boolean;
235
- toggleable: boolean;
236
- icon?: string | undefined;
237
- class?: string | undefined;
238
- sort?: {
239
- active: boolean;
240
- direction: Direction;
241
- next: string | null;
242
- } | undefined;
243
- }[];
244
- columns: {
245
- toggle: (options?: VisitOptions) => void;
246
- name: keyof RecordType;
247
- /**
248
- * The heading columns for the table.
249
- */
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
- }[];
247
+ headings: Heading<K>[];
248
+ columns: Column<K>[];
263
249
  records: {
264
- record: Omit<AsRecord<RecordType> & {
265
- actions: InlineAction[];
266
- }, "actions">;
267
- /** 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
- }[];
281
- /** Perform this action when the record is clicked */
250
+ record: Omit<TableEntry<K> & {
251
+ operations: InlineOperation[];
252
+ }, "operations">;
253
+ /** The operations available for the record */
254
+ operations: (InlineOperation & {
255
+ execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
256
+ })[];
257
+ /** Perform this operation when the record is clicked */
282
258
  default: (options?: VisitOptions) => void;
283
259
  /** Selects this record */
284
260
  select: () => void;
@@ -295,41 +271,23 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
295
271
  value: Identifier;
296
272
  };
297
273
  /** Get the value of the record for the column */
298
- value: (column: Column<RecordType> | string) => RecordType[string] | RecordType[number] | RecordType[symbol] | null;
274
+ value: (column: Column<K> | string) => K[string] | K[number] | K[symbol] | null;
299
275
  /** Get the extra data of the record for the column */
300
- extra: (column: Column<RecordType> | string) => Record<string, any> | null;
276
+ extra: (column: Column<K> | string) => any;
301
277
  }[];
302
278
  inline: boolean;
303
- bulkActions: {
304
- execute: (options?: VisitOptions) => void;
305
- type: "bulk";
306
- keepSelected: boolean;
307
- name: string;
308
- label: string;
309
- icon?: string | undefined;
310
- extra?: Record<string, unknown> | undefined;
311
- action?: boolean | undefined;
312
- confirm?: Confirm | undefined;
313
- route?: Route | undefined;
314
- }[];
315
- pageActions: {
316
- execute: (options?: VisitOptions) => void;
317
- type: "page";
318
- name: string;
319
- label: string;
320
- icon?: string | undefined;
321
- extra?: Record<string, unknown> | undefined;
322
- action?: boolean | undefined;
323
- confirm?: Confirm | undefined;
324
- route?: Route | undefined;
325
- }[];
326
- rowsPerPage: {
327
- apply: (options?: VisitOptions) => void;
279
+ bulk: (BulkOperation & {
280
+ execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
281
+ })[];
282
+ page: (PageOperation & {
283
+ execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
284
+ })[];
285
+ pages: {
328
286
  value: number;
329
287
  active: boolean;
330
288
  }[];
331
- currentPage: PerPageRecord | undefined;
332
- paginator: (Paginator extends "length-aware" ? LengthAwarePaginator : Paginator extends "simple" ? SimplePaginator : Paginator extends "cursor" ? CursorPaginator : CollectionPaginator) & {
289
+ currentPage: PageOption | undefined;
290
+ paginator: PaginateMap[U] & {
333
291
  links?: {
334
292
  navigate: (options?: VisitOptions) => void | "" | null;
335
293
  url: string | null;
@@ -341,22 +299,22 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
341
299
  first: (options?: VisitOptions) => void;
342
300
  last: (options?: VisitOptions) => void;
343
301
  };
344
- executeInlineAction: (action: InlineAction, record: AsRecord<RecordType>, options?: VisitOptions) => void;
345
- executeBulkAction: (action: BulkAction, options?: VisitOptions) => void;
346
- executePageAction: (action: PageAction, options?: VisitOptions) => void;
347
- applyPage: (page: PerPageRecord, options?: VisitOptions) => void;
302
+ executeInline: (operation: InlineOperation, data: TableEntry<K>, options?: VisitOptions) => void;
303
+ executeBulk: (operation: BulkOperation, options?: VisitOptions) => void;
304
+ executePage: (operation: PageOperation, data?: PageOperationData, options?: VisitOptions) => boolean;
305
+ applyPage: (page: PageOption, options?: VisitOptions) => void;
348
306
  selection: BulkSelection<Identifier>;
349
- select: (record: AsRecord<RecordType>) => void;
350
- deselect: (record: AsRecord<RecordType>) => void;
307
+ select: (record: TableEntry<K>) => void;
308
+ deselect: (record: TableEntry<K>) => void;
351
309
  selectPage: () => void;
352
310
  deselectPage: () => void;
353
- toggle: (record: AsRecord<RecordType>) => void;
354
- selected: (record: AsRecord<RecordType>) => boolean;
311
+ toggle: (record: TableEntry<K>) => void;
312
+ selected: (record: TableEntry<K>) => boolean;
355
313
  selectAll: () => void;
356
314
  deselectAll: () => void;
357
315
  isPageSelected: boolean;
358
316
  hasSelected: boolean;
359
- bindCheckbox: (record: AsRecord<RecordType>) => {
317
+ bindCheckbox: (record: TableEntry<K>) => {
360
318
  "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
361
319
  modelValue: boolean;
362
320
  value: Identifier;
@@ -368,8 +326,13 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
368
326
  bindAll: () => {
369
327
  "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
370
328
  modelValue: boolean;
371
- value: boolean;
372
329
  };
373
330
  };
374
331
 
332
+ export declare interface View {
333
+ id: number;
334
+ name: string;
335
+ view: string;
336
+ }
337
+
375
338
  export { }