@honed/table 0.8.0 → 0.9.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,19 +1,28 @@
1
1
  import { BindingOptions } from '@honed/refine';
2
2
  import { BulkOperation } from '@honed/action';
3
3
  import { BulkSelection } from '@honed/action';
4
+ import { ComputedRef } from 'vue';
4
5
  import { Direction } from '@honed/refine';
6
+ import { Executable } from '@honed/action';
5
7
  import { Filter } from '@honed/refine';
8
+ import { FilterBinding } from '@honed/refine';
6
9
  import { FilterValue } from '@honed/refine';
10
+ import { HonedFilter } from '@honed/refine';
11
+ import { HonedRefine } from '@honed/refine';
12
+ import { HonedSearch } from '@honed/refine';
13
+ import { HonedSort } from '@honed/refine';
7
14
  import { InlineOperation } from '@honed/action';
15
+ import { MatchBinding } from '@honed/refine';
8
16
  import { MaybeEndpoint } from '@honed/action';
9
17
  import { MaybeId } from '@honed/action';
10
- import { Option as Option_2 } from '@honed/refine';
11
18
  import { PageOperation } from '@honed/action';
12
19
  import { PageOperationData } from '@honed/action';
13
- import { PromisifyFn } from '@vueuse/shared';
20
+ import { Ref } from 'vue';
14
21
  import { Refine } from '@honed/refine';
15
22
  import { Search } from '@honed/refine';
23
+ import { SearchBinding } from '@honed/refine';
16
24
  import { Sort } from '@honed/refine';
25
+ import { SortBinding } from '@honed/refine';
17
26
  import { Visit } from '@inertiajs/core';
18
27
  import { VisitCallbacks } from '@inertiajs/core';
19
28
  import { VisitOptions } from '@inertiajs/core';
@@ -60,6 +69,40 @@ export declare interface Heading<T extends Record<string, any> = Record<string,
60
69
  toggleSort: (options: VisitOptions) => void;
61
70
  }
62
71
 
72
+ export declare interface HonedTable<T extends Record<string, any> = Record<string, any>, K extends Paginate = "length-aware"> extends HonedRefine {
73
+ meta: ComputedRef<Record<string, any> | null>;
74
+ isPageable: ComputedRef<boolean>;
75
+ isToggleable: ComputedRef<boolean>;
76
+ getRecordKey: (record: TableEntry<T>) => Identifier;
77
+ headings: ComputedRef<Heading<T>[]>;
78
+ columns: ComputedRef<Column<T>[]>;
79
+ records: ComputedRef<TableRecord<T>[]>;
80
+ inline: ComputedRef<boolean>;
81
+ bulk: ComputedRef<Executable<BulkOperation>[]>;
82
+ page: ComputedRef<Executable<PageOperation>[]>;
83
+ pages: ComputedRef<PageOption[]>;
84
+ currentPage: ComputedRef<PageOption | undefined>;
85
+ paginator: ComputedRef<PaginateMap[K]>;
86
+ executeInline: (operation: InlineOperation, data: TableEntry<T>, options?: VisitOptions) => void;
87
+ executeBulk: (operation: BulkOperation, options?: VisitOptions) => void;
88
+ executePage: (operation: PageOperation, data?: PageOperationData, options?: VisitOptions) => void;
89
+ applyPage: (page: PageOption, options?: VisitOptions) => void;
90
+ selection: Ref<BulkSelection<Identifier>, BulkSelection<Identifier>>;
91
+ select: (record: TableEntry<T>) => void;
92
+ deselect: (record: TableEntry<T>) => void;
93
+ toggle: (record: TableEntry<T>) => void;
94
+ selectPage: () => void;
95
+ deselectPage: () => void;
96
+ selected: (record: TableEntry<T>) => boolean;
97
+ selectAll: () => void;
98
+ deselectAll: () => void;
99
+ isPageSelected: ComputedRef<boolean>;
100
+ hasSelected: ComputedRef<boolean>;
101
+ bindCheckbox: (record: TableEntry<T>) => void;
102
+ bindPage: () => void;
103
+ bindAll: () => void;
104
+ }
105
+
63
106
  export declare type Identifier = string | number;
64
107
 
65
108
  export declare function is(column: Column | string | null | undefined, type: ColumnType): boolean;
@@ -73,6 +116,11 @@ export declare interface LengthAwarePaginate extends SimplePaginate {
73
116
  links: PaginatorLink[];
74
117
  }
75
118
 
119
+ export declare interface PageBinding {
120
+ "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
121
+ modelValue: boolean;
122
+ }
123
+
76
124
  export declare interface PageOption {
77
125
  value: number;
78
126
  active: boolean;
@@ -105,7 +153,7 @@ export declare interface Table<T extends Record<string, any> = Record<string, an
105
153
  record?: string;
106
154
  page?: string;
107
155
  records: Array<TableEntry<T> & {
108
- actions: InlineOperation[];
156
+ operations: InlineOperation[];
109
157
  }>;
110
158
  paginate: PaginateMap[K];
111
159
  columns: BaseColumn<T>[];
@@ -121,84 +169,44 @@ export declare interface Table<T extends Record<string, any> = Record<string, an
121
169
  meta: Record<string, any>;
122
170
  }
123
171
 
124
- export declare type TableEntry<RecordType extends Record<string, any> = any> = {
125
- [K in keyof RecordType]: {
126
- v: RecordType[K];
172
+ export declare type TableEntry<T extends Record<string, any> = any> = {
173
+ [K in keyof T]: {
174
+ v: T[K];
127
175
  e: any;
128
176
  c: string | null;
129
177
  f: boolean;
130
178
  };
131
179
  };
132
180
 
133
- export declare interface TableOptions<RecordType extends Record<string, any> = Record<string, any>> extends VisitOptions {
181
+ export declare interface TableOptions<T extends Record<string, any> = Record<string, any>> extends VisitOptions {
134
182
  /**
135
183
  * Mappings of operations to be applied on a record in JavaScript.
136
184
  */
137
- recordActions?: Record<string, (record: TableEntry<RecordType>) => void>;
185
+ recordOperations?: Record<string, (record: TableEntry<T>) => void>;
138
186
  }
139
187
 
140
- export declare interface TableRecord<RecordType extends Record<string, any> = Record<string, any>> {
141
- record: RecordType;
188
+ export declare interface TableRecord<T extends Record<string, any> = Record<string, any>> {
189
+ operations: Executable<InlineOperation>[];
142
190
  default: (options?: VisitOptions) => void;
143
- actions: InlineOperation[];
144
191
  select: () => void;
145
192
  deselect: () => void;
146
193
  toggle: () => void;
147
194
  selected: boolean;
148
- bind: () => Record<string, any>;
149
- value: (column: Column<RecordType> | string) => any;
150
- extra: (column: Column<RecordType> | string) => any;
195
+ bind: () => any;
196
+ entry: (column: Column<T> | string) => TableEntry<T>[keyof T] | null;
197
+ value: (column: Column<T> | string) => TableEntry<T>[keyof T]["v"] | null;
198
+ extra: (column: Column<T> | string) => TableEntry<T>[keyof T]["e"] | null;
151
199
  }
152
200
 
153
201
  export declare type UseTable = typeof useTable;
154
202
 
155
203
  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): {
156
- filters: {
157
- apply: (value: T, options?: Partial<Visit & VisitCallbacks> | undefined) => void;
158
- clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
159
- bind: () => void | {
160
- "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
161
- modelValue: FilterValue;
162
- }; /** Bind the record to a checkbox */
163
- type: string;
164
- value: FilterValue;
165
- options: Option_2[];
166
- name: string; /** Get the value of the record for the column */
167
- label: string;
168
- active: boolean;
169
- meta: Record<string, any>;
170
- }[];
171
- sorts: {
172
- apply: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
173
- clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
174
- bind: () => void | {
175
- onClick: PromisifyFn<() => void>;
176
- };
177
- type: string;
178
- direction: Direction;
179
- next: string | null;
180
- name: string;
181
- label: string;
182
- active: boolean;
183
- meta: Record<string, any>;
184
- }[];
185
- searches: {
186
- apply: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
187
- clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
188
- bind: () => void | {
189
- "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
190
- modelValue: boolean;
191
- value: string;
192
- };
193
- type: string;
194
- name: string;
195
- label: string;
196
- active: boolean;
197
- meta: Record<string, any>;
198
- }[];
199
- currentFilters: Filter[];
200
- currentSort: Sort | undefined;
201
- currentSearches: Search[];
204
+ filters: HonedFilter[];
205
+ sorts: HonedSort[];
206
+ searches: HonedSearch[];
207
+ currentFilters: HonedFilter[];
208
+ currentSort: HonedSort | undefined;
209
+ currentSearches: HonedSearch[];
202
210
  isSortable: boolean;
203
211
  isSearchable: boolean;
204
212
  isMatchable: boolean;
@@ -218,71 +226,25 @@ export declare function useTable<T extends Record<string, Table>, K extends Reco
218
226
  clearSearch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
219
227
  clearMatch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
220
228
  reset: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
221
- bindFilter: (filter: string | Filter, options?: BindingOptions | undefined) => void | {
222
- "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
223
- modelValue: FilterValue;
224
- };
225
- bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => void | {
226
- onClick: PromisifyFn<() => void>;
227
- };
228
- bindSearch: (options?: BindingOptions | undefined) => {
229
- "onUpdate:modelValue": PromisifyFn<(value: string | null | undefined) => void>;
230
- modelValue: string;
231
- };
232
- bindMatch: (match: string | Search, options?: BindingOptions | undefined) => void | {
233
- "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
234
- modelValue: boolean;
235
- value: string;
236
- };
229
+ bindFilter: (filter: string | Filter, options?: BindingOptions | undefined) => void | FilterBinding;
230
+ bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => void | SortBinding;
231
+ bindSearch: (options?: BindingOptions | undefined) => void | SearchBinding;
232
+ bindMatch: (match: string | Search, options?: BindingOptions | undefined) => void | MatchBinding;
237
233
  stringValue: (value: any) => any;
238
234
  omitValue: (value: any) => any;
239
235
  toggleValue: (value: any, values: any) => any;
240
- delimitArray: (value: any) => any;
241
- table: Table<K, U>;
242
- getRecordKey: (record: TableEntry<K>) => Identifier;
236
+ delimitArray: (value: any) => string;
243
237
  meta: Record<string, any>;
238
+ isPageable: boolean;
239
+ isToggleable: boolean;
240
+ getRecordKey: (record: TableEntry<K>) => Identifier;
244
241
  headings: Heading<K>[];
245
242
  columns: Column<K>[];
246
- records: {
247
- record: Omit<TableEntry<K> & {
248
- actions: InlineOperation[];
249
- }, "actions">;
250
- /** The actions available for the record */
251
- actions: (InlineOperation & {
252
- execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
253
- })[];
254
- /** Perform this action when the record is clicked */
255
- default: (options?: VisitOptions) => void;
256
- /** Selects this record */
257
- select: () => void;
258
- /** Deselects this record */
259
- deselect: () => void;
260
- /** Toggles the selection of this record */
261
- toggle: () => void;
262
- /** Determine if the record is selected */
263
- selected: boolean;
264
- /** Bind the record to a checkbox */
265
- bind: () => {
266
- "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
267
- modelValue: boolean;
268
- value: Identifier;
269
- };
270
- /** Get the value of the record for the column */
271
- value: (column: Column<K> | string) => K[string] | K[number] | K[symbol] | null;
272
- /** Get the extra data of the record for the column */
273
- extra: (column: Column<K> | string) => any;
274
- }[];
243
+ records: TableRecord<K>[];
275
244
  inline: boolean;
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: {
283
- value: number;
284
- active: boolean;
285
- }[];
245
+ bulk: Executable<BulkOperation>[];
246
+ page: Executable<PageOperation>[];
247
+ pages: PageOption[];
286
248
  currentPage: PageOption | undefined;
287
249
  paginator: PaginateMap[U] & {
288
250
  links?: {