@vuu-ui/vuu-table-types 0.0.26 → 0.8.12

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.
Files changed (2) hide show
  1. package/index.d.ts +190 -106
  2. package/package.json +4 -2
package/index.d.ts CHANGED
@@ -1,33 +1,65 @@
1
+ import type {
2
+ DataSourceRow,
3
+ DataSourceRowObject,
4
+ DataValueDescriptor,
5
+ DataValueTypeSimple,
6
+ DataValueValidationChecker,
7
+ EditValidationRule,
8
+ } from "@vuu-ui/vuu-data-types";
1
9
  import type { Filter } from "@vuu-ui/vuu-filter-types";
2
10
  import type {
3
11
  VuuAggType,
4
- VuuColumnDataType,
12
+ VuuMenuItem,
5
13
  VuuRowDataItemType,
6
14
  VuuSortType,
7
15
  VuuTable,
8
16
  } from "@vuu-ui/vuu-protocol-types";
9
- import type { ClientSideValidationChecker } from "@vuu-ui/vuu-ui-controls";
10
- import type { DateTimePattern } from "@vuu-ui/vuu-utils";
11
- import { DataSourceRow, DataSourceRowObject } from "@vuu-ui/vuu-data-types";
12
- import type { FunctionComponent, MouseEvent } from "react";
13
- import type { HTMLAttributes } from "react";
14
-
15
- export type TableSelectionModel = "none" | "single" | "checkbox" | "extended";
16
-
17
- export type TableHeading = { label: string; width: number };
18
- export type TableHeadings = TableHeading[][];
19
-
20
- export type ValueFormatter = (value: unknown) => string;
17
+ import { CellPos } from "@vuu-ui/vuu-table/src/table-dom-utils";
18
+ import type {
19
+ ColumnMap,
20
+ DateTimePattern,
21
+ RowClassNameGenerator,
22
+ } from "@vuu-ui/vuu-utils";
23
+ import type {
24
+ ComponentType,
25
+ CSSProperties,
26
+ FunctionComponent,
27
+ FunctionComponentElement,
28
+ HTMLAttributes,
29
+ MouseEvent,
30
+ } from "react";
31
+
32
+ export declare type GroupToggleTarget = "toggle-icon" | "group-column";
33
+
34
+ export declare type TableSelectionModel =
35
+ | "none"
36
+ | "single"
37
+ | "checkbox"
38
+ | "extended";
39
+
40
+ export declare type TableHeading = { label: string; width: number };
41
+ export declare type TableHeadings = TableHeading[][];
42
+
43
+ export declare type ValueFormatter<T extends string | JSX.Element = string> = (
44
+ value: unknown,
45
+ ) => T;
46
+
47
+ export interface EditEventState {
48
+ editType?: EditType;
49
+ isValid?: boolean;
50
+ // value: unknown;
51
+ previousValue?: VuuRowDataItemType;
52
+ value: VuuRowDataItemType;
53
+ }
21
54
 
22
- export type ClientSideValidationChecker = (
23
- value?: VuuRowDataItemType
24
- ) => string | false | undefined;
55
+ export interface DataCellEditEvent extends EditEventState {
56
+ row: DataSourceRow;
57
+ columnName: string;
58
+ }
25
59
 
26
- export type DataCellEditHandler = (
27
- row: DataSourceRow,
28
- columnName: string,
29
- value: VuuRowDataItemType
30
- ) => Promise<string | true>;
60
+ export declare type DataCellEditNotification = (
61
+ editEvent: DataCellEditEvent,
62
+ ) => void;
31
63
 
32
64
  export interface TableCellProps {
33
65
  className?: string;
@@ -36,46 +68,76 @@ export interface TableCellProps {
36
68
  onClick?: (event: MouseEvent, column: RuntimeColumnDescriptor) => void;
37
69
  onDataEdited?: DataCellEditHandler;
38
70
  row: DataSourceRow;
71
+ searchPattern?: Lowercase<string>;
39
72
  }
40
73
 
41
- export type CommitResponse = Promise<true | string>;
74
+ export declare type CommitResponse = Promise<true | string>;
75
+
76
+ export declare type EditType = "commit" | "change" | "cancel";
42
77
 
43
- export type DataItemCommitHandler<
44
- T extends VuuRowDataItemType = VuuRowDataItemType
45
- > = (value: T) => CommitResponse;
78
+ declare type DataItemEditHandler<T extends EditType = EditType> = (
79
+ editState: EditEventState,
80
+ editPhase: T,
81
+ ) => T extends "commit" ? Promise<string | true> : void;
46
82
 
47
- export type TableRowSelectHandler = (row: DataSourceRowObject | null) => void;
48
- export type TableRowSelectHandlerInternal = (row: DataSourceRow | null) => void;
83
+ export declare type TableRowSelectHandler = (
84
+ row: DataSourceRowObject | null,
85
+ ) => void;
86
+ export declare type TableRowSelectHandlerInternal = (
87
+ row: DataSourceRow | null,
88
+ ) => void;
49
89
 
50
90
  /**
51
91
  * Fired when user clicks a row, returning the row object (DataSourceRowObject)
52
92
  */
53
- export type TableRowClickHandler = (
93
+ export declare type TableRowClickHandler = (
54
94
  evt: MouseEvent<HTMLDivElement>,
55
- row: DataSourceRowObject
95
+ row: DataSourceRowObject,
56
96
  ) => void;
57
97
 
58
- export type TableRowClickHandlerInternal = (
98
+ export declare type TableRowClickHandlerInternal = (
59
99
  evt: MouseEvent<HTMLDivElement>,
60
100
  row: DataSourceRow,
61
101
  rangeSelect: boolean,
62
- keepExistingSelection: boolean
102
+ keepExistingSelection: boolean,
63
103
  ) => void;
64
104
 
65
105
  export interface TableCellRendererProps
66
106
  extends Omit<TableCellProps, "onDataEdited"> {
67
- onCommit?: DataItemCommitHandler;
107
+ onEdit?: DataItemEditHandler;
68
108
  }
69
109
 
110
+ /**
111
+ * static layout simply respects widths specified on column descriptors.
112
+ * fit layout attempts to fit columns to available space, either stretching
113
+ * or squeezing. manual indicates that user has resized one or more columns,
114
+ * on what was originally a fit layout. Once this happens, no further auto
115
+ * fitting will take place. Fit layout always respects max and min widths,
116
+ */
117
+ export declare type ColumnLayout = "static" | "fit" | "manual";
118
+
70
119
  export interface TableAttributes {
71
120
  columnDefaultWidth?: number;
72
121
  columnFormatHeader?: "capitalize" | "uppercase";
122
+ columnLayout?: ColumnLayout;
73
123
  columnSeparators?: boolean;
74
124
  // showHighlightedRow?: boolean;
75
125
  rowSeparators?: boolean;
76
126
  zebraStripes?: boolean;
77
127
  }
78
128
 
129
+ export declare type TableMenuLocation = "grid" | "header" | "filter";
130
+
131
+ export interface VuuCellMenuItem extends VuuMenuItem {
132
+ rowKey: string;
133
+ field: string;
134
+ value: VuuRowDataItemType;
135
+ }
136
+ export interface VuuRowMenuItem extends VuuMenuItem {
137
+ rowKey: string;
138
+ row: { [key: string]: VuuRowDataItemType };
139
+ }
140
+
79
141
  /**
80
142
  * TableConfig describes the configuration used to render a Table. It is
81
143
  * a required prop for Table and provided initially by user. It can be
@@ -91,6 +153,18 @@ export interface GridConfig extends TableConfig {
91
153
  selectionBookendWidth?: number;
92
154
  }
93
155
 
156
+ // TODO tidy up this definition, currently split beween here and data-types
157
+ export declare type DataValueTypeDescriptor = {
158
+ rules?: EditValidationRule[];
159
+ formatting?: ColumnTypeFormatting;
160
+ name: DataValueTypeSimple;
161
+ renderer?:
162
+ | ColumnTypeRendering
163
+ | LookupRenderer
164
+ | MappedValueTypeRenderer
165
+ | ValueListRenderer;
166
+ };
167
+
94
168
  export declare type ColumnTypeFormatting = {
95
169
  alignOnDecimals?: boolean;
96
170
  decimals?: number;
@@ -98,15 +172,9 @@ export declare type ColumnTypeFormatting = {
98
172
  zeroPad?: boolean;
99
173
  };
100
174
 
101
- export type ColumnTypeValueMap = { [key: string]: string };
102
-
103
- export interface EditValidationRule {
104
- name: string;
105
- message?: string;
106
- value?: string;
107
- }
175
+ export declare type ColumnTypeValueMap = { [key: string]: string };
108
176
 
109
- export type ListOption = {
177
+ export declare type ListOption = {
110
178
  label: string;
111
179
  value: number | string;
112
180
  };
@@ -119,13 +187,12 @@ export interface ColumnTypeRendering {
119
187
  // specific to Background renderer
120
188
  flashStyle?: "bg-only" | "arrow-bg" | "arrow";
121
189
  name: string;
122
- rules?: EditValidationRule[];
123
190
  }
124
191
  export interface MappedValueTypeRenderer {
125
192
  map: ColumnTypeValueMap;
126
193
  }
127
194
 
128
- export type LookupTableDetails = {
195
+ export declare type LookupTableDetails = {
129
196
  labelColumn: string;
130
197
  table: VuuTable;
131
198
  valueColumn: string;
@@ -145,45 +212,14 @@ export interface ValueListRenderer {
145
212
  values: string[];
146
213
  }
147
214
 
148
- export declare type DateTimeColumnTypeSimple = "date/time";
149
-
150
- type DateTimeColumnType =
151
- | DateTimeColumnTypeSimple
152
- | (Omit<ColumnTypeDescriptor, "name"> & { name: DateTimeColumnTypeSimple });
153
-
154
- export declare type DateTimeColumnDescriptor = Omit<
155
- ColumnDescriptor,
156
- "type"
157
- > & {
158
- type: DateTimeColumnType;
159
- };
160
-
161
- export declare type ColumnTypeSimple =
162
- | "string"
163
- | "number"
164
- | "boolean"
165
- | "json"
166
- | DateTimeColumnTypeSimple
167
- | "checkbox";
168
-
169
- export declare type ColumnTypeDescriptor = {
170
- formatting?: ColumnTypeFormatting;
171
- name: ColumnTypeSimple;
172
- renderer?:
173
- | ColumnTypeRendering
174
- | LookupRenderer
175
- | MappedValueTypeRenderer
176
- | ValueListRenderer;
177
- };
178
-
179
215
  export declare type ColumnTypeDescriptorCustomRenderer = {
180
216
  formatting?: ColumnTypeFormatting;
181
- name: ColumnTypeSimple;
217
+ name: DataValueTypeSimple;
182
218
  renderer: ColumnTypeRendering;
183
219
  };
184
220
 
185
221
  export interface FormattingSettingsProps<
186
- T extends ColumnDescriptor = ColumnDescriptor
222
+ T extends ColumnDescriptor = ColumnDescriptor,
187
223
  > {
188
224
  column: T;
189
225
  onChangeFormatting: (formatting: ColumnTypeFormatting) => void;
@@ -193,36 +229,39 @@ export interface FormattingSettingsProps<
193
229
  latter. e.g a server data type of long may be further refined as
194
230
  a date/time value using the column descriptor type.
195
231
  */
196
- onChangeColumnType: (type: ColumnTypeSimple) => void;
232
+ onChangeColumnType: (type: DataValueTypeSimple) => void;
197
233
  }
198
234
 
199
- export interface ColumnTypeRendererWithValidationRules
200
- extends ColumnTypeRendering {
235
+ export interface ColumnTypeWithValidationRules
236
+ extends Omit<DataValueTypeDescriptor, "editRules"> {
201
237
  rules: EditValidationRule[];
202
238
  }
203
239
 
204
- export interface ColumnTypeWithValidationRules extends ColumnTypeDescriptor {
205
- renderer: ColumnTypeRendererWithValidationRules;
206
- }
207
-
208
- export declare type ColumnType = ColumnTypeSimple | ColumnTypeDescriptor;
209
-
210
- export type ColumnSort = VuuSortType | number;
240
+ export declare type ColumnSort = VuuSortType | number;
211
241
 
212
- export type PinLocation = "left" | "right" | "floating";
242
+ export declare type PinLocation = "left" | "right" | "floating";
213
243
 
214
- export type ColumnAlignment = "left" | "right";
244
+ export declare type ColumnAlignment = "left" | "right";
215
245
 
216
246
  /** This is a public description of a Column, defining all the
217
247
  * column attributes that can be defined by client. */
218
- export interface ColumnDescriptor {
248
+ export interface ColumnDescriptor extends DataValueDescriptor {
219
249
  aggregate?: VuuAggType;
220
250
  align?: ColumnAlignment;
221
251
  className?: string;
252
+ /**
253
+ * Allows custom content to be rendered into the column header. This will be an identifier.
254
+ * The identifier will be used to retrieve content from the component registry. The componnet
255
+ * yielded will be rendered into the column header.
256
+ */
222
257
  colHeaderContentRenderer?: string;
223
258
  colHeaderLabelRenderer?: string;
224
- editable?: boolean;
225
259
  flex?: number;
260
+ /**
261
+ * Only used when the column is included in a grouby clause.
262
+ * The icon will be displayed alongside the group label
263
+ */
264
+ getIcon?: (row: DataSourceRow) => string | undefined;
226
265
  /**
227
266
  Optional additional level(s) of heading to display above label.
228
267
  May span multiple columns, if multiple adjacent columns declare
@@ -231,17 +270,19 @@ export interface ColumnDescriptor {
231
270
  heading?: string[];
232
271
  hidden?: boolean;
233
272
  isSystemColumn?: boolean;
234
- /** The Label to display on column in Table */
235
- label?: string;
236
273
  locked?: boolean;
237
274
  maxWidth?: number;
238
275
  minWidth?: number;
239
- name: string;
240
276
  pin?: PinLocation;
241
277
  resizeable?: boolean;
242
- serverDataType?: VuuColumnDataType;
243
278
  sortable?: boolean;
244
- type?: ColumnType;
279
+ /**
280
+ * 'client' columns will not receive data from dataSource.
281
+ * They can be used with a custom renderer, e.g to render
282
+ * action buttons.
283
+ * default is 'server'
284
+ */
285
+ source?: "client" | "server";
245
286
  width?: number;
246
287
  }
247
288
 
@@ -254,18 +295,17 @@ export interface ColumnDescriptorCustomRenderer
254
295
  * definitin with internal state values. */
255
296
  export interface RuntimeColumnDescriptor extends ColumnDescriptor {
256
297
  align?: "left" | "right";
298
+ ariaColIndex: number;
257
299
  CellRenderer?: FunctionComponent<TableCellRendererProps>;
258
300
  HeaderCellLabelRenderer?: FunctionComponent<HeaderCellProps>;
259
301
  HeaderCellContentRenderer?: FunctionComponent<HeaderCellProps>;
260
302
  canStretch?: boolean;
261
303
  className?: string;
262
- clientSideEditValidationCheck?: ClientSideValidationChecker;
304
+ clientSideEditValidationCheck?: DataValueValidationChecker;
263
305
  endPin?: true | undefined;
264
306
  filter?: Filter;
265
307
  flex?: number;
266
308
  heading?: [...string[]];
267
- /** A 1 based index for aria-colindex */
268
- index?: number;
269
309
  isGroup?: boolean;
270
310
  isSystemColumn?: boolean;
271
311
  label: string;
@@ -301,17 +341,17 @@ export interface Heading {
301
341
  }
302
342
 
303
343
  // These are the actions that eventually get routed to the DataSource itself
304
- export type DataSourceAction =
344
+ export declare type DataSourceAction =
305
345
  | GridActionCloseTreeNode
306
346
  | GridActionGroup
307
347
  | GridActionOpenTreeNode
308
348
  | GridActionSort;
309
349
 
310
- export type ScrollAction =
350
+ export declare type ScrollAction =
311
351
  | GridActionScrollEndHorizontal
312
352
  | GridActionScrollStartHorizontal;
313
353
 
314
- export type GridAction =
354
+ export declare type GridAction =
315
355
  | DataSourceAction
316
356
  | ScrollAction
317
357
  | GridActionResizeCol
@@ -346,19 +386,52 @@ export interface TableSettingsProps {
346
386
  tableConfig: TableConfig;
347
387
  }
348
388
 
349
- export type DefaultColumnConfiguration = <T extends string = string>(
389
+ export declare type DefaultColumnConfiguration = <T extends string = string>(
350
390
  tableName: T,
351
- columnName: string
391
+ columnName: string,
352
392
  ) => Partial<ColumnDescriptor> | undefined;
353
393
 
354
- export type ResizePhase = "begin" | "resize" | "end";
394
+ export declare type DefaultTableConfiguration = (
395
+ vuuTable?: VuuTable,
396
+ ) => Partial<Omit<TableConfig, "columns">> | undefined;
397
+
398
+ export declare type ResizePhase = "begin" | "resize" | "end";
355
399
 
356
- export type TableColumnResizeHandler = (
400
+ export declare type TableColumnResizeHandler = (
357
401
  phase: ResizePhase,
358
402
  columnName: string,
359
- width?: number
403
+ width?: number,
360
404
  ) => void;
361
405
 
406
+ export interface BaseRowProps {
407
+ ariaRole?: string;
408
+ ariaRowIndex?: number;
409
+ className?: string;
410
+ columns: RuntimeColumnDescriptor[];
411
+ style?: CSSProperties;
412
+ /**
413
+ * In a virtualized row, the total width of leading columns not rendered (as
414
+ * virtualization optimisation)
415
+ */
416
+ virtualColSpan?: number;
417
+ }
418
+
419
+ export interface RowProps extends BaseRowProps {
420
+ classNameGenerator?: RowClassNameGenerator;
421
+ columnMap: ColumnMap;
422
+ groupToggleTarget?: GroupToggleTarget;
423
+ highlighted?: boolean;
424
+ offset: number;
425
+ onCellEdit?: CellEditHandler;
426
+ onClick?: TableRowClickHandlerInternal;
427
+ onDataEdited?: DataCellEditHandler;
428
+ onToggleGroup?: (row: DataSourceRow, column: RuntimeColumnDescriptor) => void;
429
+ row: DataSourceRow;
430
+ searchPattern: Lowercase<string>;
431
+ showBookends?: boolean;
432
+ zebraStripes?: boolean;
433
+ }
434
+
362
435
  export interface HeaderCellProps
363
436
  extends Omit<HTMLAttributes<HTMLDivElement>, "onClick"> {
364
437
  classBase?: string;
@@ -368,4 +441,15 @@ export interface HeaderCellProps
368
441
  showMenu?: boolean;
369
442
  }
370
443
 
371
- export type TableConfigChangeHandler = (config: TableConfig) => void;
444
+ export declare type TableConfigChangeHandler = (config: TableConfig) => void;
445
+
446
+ export declare type CustomHeaderComponent = ComponentType<BaseRowProps>;
447
+ export declare type CustomHeaderElement =
448
+ FunctionComponentElement<BaseRowProps>;
449
+ export declare type CustomHeader = CustomHeaderComponent | CustomHeaderElement;
450
+
451
+ /**
452
+ * The row and column index positions of a table cell
453
+ * [rowIndex, colIndex]
454
+ */
455
+ export declare type CellPos = [number, number];
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@vuu-ui/vuu-table-types",
3
- "version": "0.0.26",
3
+ "version": "0.8.12",
4
4
  "devDependencies": {
5
- "@vuu-ui/vuu-protocol-types": "0.0.26"
5
+ "@vuu-ui/vuu-data-types": "0.8.12",
6
+ "@vuu-ui/vuu-filter-types": "0.8.12",
7
+ "@vuu-ui/vuu-protocol-types": "0.8.12"
6
8
  },
7
9
  "author": "heswell",
8
10
  "license": "Apache-2.0",