@honed/table 0.8.1 → 0.9.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,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,41 @@ 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
+ isEmpty: ComputedRef<boolean>;
75
+ isPageable: ComputedRef<boolean>;
76
+ isToggleable: ComputedRef<boolean>;
77
+ getRecordKey: (record: TableEntry<T>) => Identifier;
78
+ headings: ComputedRef<Heading<T>[]>;
79
+ columns: ComputedRef<Column<T>[]>;
80
+ records: ComputedRef<TableRecord<T>[]>;
81
+ inline: ComputedRef<boolean>;
82
+ bulk: ComputedRef<Executable<BulkOperation>[]>;
83
+ page: ComputedRef<Executable<PageOperation>[]>;
84
+ pages: ComputedRef<PageOption[]>;
85
+ currentPage: ComputedRef<PageOption | undefined>;
86
+ paginator: ComputedRef<PaginateMap[K]>;
87
+ executeInline: (operation: InlineOperation, data: TableEntry<T>, options?: VisitOptions) => void;
88
+ executeBulk: (operation: BulkOperation, options?: VisitOptions) => void;
89
+ executePage: (operation: PageOperation, data?: PageOperationData, options?: VisitOptions) => void;
90
+ applyPage: (page: PageOption, options?: VisitOptions) => void;
91
+ selection: Ref<BulkSelection<Identifier>, BulkSelection<Identifier>>;
92
+ select: (record: TableEntry<T>) => void;
93
+ deselect: (record: TableEntry<T>) => void;
94
+ toggle: (record: TableEntry<T>) => void;
95
+ selectPage: () => void;
96
+ deselectPage: () => void;
97
+ selected: (record: TableEntry<T>) => boolean;
98
+ selectAll: () => void;
99
+ deselectAll: () => void;
100
+ isPageSelected: ComputedRef<boolean>;
101
+ hasSelected: ComputedRef<boolean>;
102
+ bindCheckbox: (record: TableEntry<T>) => void;
103
+ bindPage: () => void;
104
+ bindAll: () => void;
105
+ }
106
+
63
107
  export declare type Identifier = string | number;
64
108
 
65
109
  export declare function is(column: Column | string | null | undefined, type: ColumnType): boolean;
@@ -73,6 +117,11 @@ export declare interface LengthAwarePaginate extends SimplePaginate {
73
117
  links: PaginatorLink[];
74
118
  }
75
119
 
120
+ export declare interface PageBinding {
121
+ "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
122
+ modelValue: boolean;
123
+ }
124
+
76
125
  export declare interface PageOption {
77
126
  value: number;
78
127
  active: boolean;
@@ -121,84 +170,44 @@ export declare interface Table<T extends Record<string, any> = Record<string, an
121
170
  meta: Record<string, any>;
122
171
  }
123
172
 
124
- export declare type TableEntry<RecordType extends Record<string, any> = any> = {
125
- [K in keyof RecordType]: {
126
- v: RecordType[K];
173
+ export declare type TableEntry<T extends Record<string, any> = any> = {
174
+ [K in keyof T]: {
175
+ v: T[K];
127
176
  e: any;
128
177
  c: string | null;
129
178
  f: boolean;
130
179
  };
131
180
  };
132
181
 
133
- export declare interface TableOptions<RecordType extends Record<string, any> = Record<string, any>> extends VisitOptions {
182
+ export declare interface TableOptions<T extends Record<string, any> = Record<string, any>> extends VisitOptions {
134
183
  /**
135
184
  * Mappings of operations to be applied on a record in JavaScript.
136
185
  */
137
- recordOperations?: Record<string, (record: TableEntry<RecordType>) => void>;
186
+ recordOperations?: Record<string, (record: TableEntry<T>) => void>;
138
187
  }
139
188
 
140
- export declare interface TableRecord<RecordType extends Record<string, any> = Record<string, any>> {
141
- record: RecordType;
189
+ export declare interface TableRecord<T extends Record<string, any> = Record<string, any>> {
190
+ operations: Executable<InlineOperation>[];
142
191
  default: (options?: VisitOptions) => void;
143
- operations: InlineOperation[];
144
192
  select: () => void;
145
193
  deselect: () => void;
146
194
  toggle: () => void;
147
195
  selected: boolean;
148
- bind: () => Record<string, any>;
149
- value: (column: Column<RecordType> | string) => any;
150
- extra: (column: Column<RecordType> | string) => any;
196
+ bind: () => any;
197
+ entry: (column: Column<T> | string) => TableEntry<T>[keyof T] | null;
198
+ value: (column: Column<T> | string) => TableEntry<T>[keyof T]["v"] | null;
199
+ extra: (column: Column<T> | string) => TableEntry<T>[keyof T]["e"] | null;
151
200
  }
152
201
 
153
202
  export declare type UseTable = typeof useTable;
154
203
 
155
204
  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
- };
163
- type: string;
164
- value: FilterValue;
165
- options: Option_2[];
166
- name: string;
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[];
205
+ filters: HonedFilter[];
206
+ sorts: HonedSort[];
207
+ searches: HonedSearch[];
208
+ currentFilters: HonedFilter[];
209
+ currentSort: HonedSort | undefined;
210
+ currentSearches: HonedSearch[];
202
211
  isSortable: boolean;
203
212
  isSearchable: boolean;
204
213
  isMatchable: boolean;
@@ -218,74 +227,26 @@ export declare function useTable<T extends Record<string, Table>, K extends Reco
218
227
  clearSearch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
219
228
  clearMatch: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
220
229
  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
- /**
235
- * Create operations with execute methods
236
- */
237
- modelValue: boolean;
238
- value: string;
239
- };
230
+ bindFilter: (filter: string | Filter, options?: BindingOptions | undefined) => void | FilterBinding;
231
+ bindSort: (sort: string | Sort, options?: BindingOptions | undefined) => void | SortBinding;
232
+ bindSearch: (options?: BindingOptions | undefined) => void | SearchBinding;
233
+ bindMatch: (match: string | Search, options?: BindingOptions | undefined) => void | MatchBinding;
240
234
  stringValue: (value: any) => any;
241
235
  omitValue: (value: any) => any;
242
236
  toggleValue: (value: any, values: any) => any;
243
- delimitArray: (value: any) => any;
244
- table: Table<K, U>;
245
- getRecordKey: (record: TableEntry<K>) => Identifier;
237
+ delimitArray: (value: any) => string;
246
238
  meta: Record<string, any>;
239
+ isEmpty: boolean;
240
+ isPageable: boolean;
241
+ isToggleable: boolean;
242
+ getRecordKey: (record: TableEntry<K>) => Identifier;
247
243
  headings: Heading<K>[];
248
244
  columns: Column<K>[];
249
- records: {
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 */
258
- default: (options?: VisitOptions) => void;
259
- /** Selects this record */
260
- select: () => void;
261
- /** Deselects this record */
262
- deselect: () => void;
263
- /** Toggles the selection of this record */
264
- toggle: () => void;
265
- /** Determine if the record is selected */
266
- selected: boolean;
267
- /** Bind the record to a checkbox */
268
- bind: () => {
269
- "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
270
- modelValue: boolean;
271
- value: Identifier;
272
- };
273
- /** Get the value of the record for the column */
274
- value: (column: Column<K> | string) => K[string] | K[number] | K[symbol] | null;
275
- /** Get the extra data of the record for the column */
276
- extra: (column: Column<K> | string) => any;
277
- }[];
245
+ records: TableRecord<K>[];
278
246
  inline: boolean;
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: {
286
- value: number;
287
- active: boolean;
288
- }[];
247
+ bulk: Executable<BulkOperation>[];
248
+ page: Executable<PageOperation>[];
249
+ pages: PageOption[];
289
250
  currentPage: PageOption | undefined;
290
251
  paginator: PaginateMap[U] & {
291
252
  links?: {