@operato/data-grist 2.0.0-alpha.2 → 2.0.0-alpha.22

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 (100) hide show
  1. package/CHANGELOG.md +138 -0
  2. package/dist/src/accumulator/accumulator.js +4 -4
  3. package/dist/src/accumulator/accumulator.js.map +1 -1
  4. package/dist/src/configure/rows-option-builder.js +2 -1
  5. package/dist/src/configure/rows-option-builder.js.map +1 -1
  6. package/dist/src/configure/zero-config.js +1 -0
  7. package/dist/src/configure/zero-config.js.map +1 -1
  8. package/dist/src/data-card/event-handlers/record-card-click-handler.js +1 -1
  9. package/dist/src/data-card/event-handlers/record-card-click-handler.js.map +1 -1
  10. package/dist/src/data-grid/data-grid-accum-field.js +3 -2
  11. package/dist/src/data-grid/data-grid-accum-field.js.map +1 -1
  12. package/dist/src/data-grid/data-grid-body.js +3 -1
  13. package/dist/src/data-grid/data-grid-body.js.map +1 -1
  14. package/dist/src/data-grid/data-grid-header.d.ts +1 -0
  15. package/dist/src/data-grid/data-grid-header.js +16 -14
  16. package/dist/src/data-grid/data-grid-header.js.map +1 -1
  17. package/dist/src/data-grist.d.ts +225 -3
  18. package/dist/src/data-grist.js +195 -3
  19. package/dist/src/data-grist.js.map +1 -1
  20. package/dist/src/data-list/event-handlers/record-partial-click-handler.js +1 -1
  21. package/dist/src/data-list/event-handlers/record-partial-click-handler.js.map +1 -1
  22. package/dist/src/data-manipulator.d.ts +6 -4
  23. package/dist/src/data-manipulator.js +91 -21
  24. package/dist/src/data-manipulator.js.map +1 -1
  25. package/dist/src/editors/ox-grist-editor-number.js +2 -2
  26. package/dist/src/editors/ox-grist-editor-number.js.map +1 -1
  27. package/dist/src/editors/ox-grist-editor.js +6 -2
  28. package/dist/src/editors/ox-grist-editor.js.map +1 -1
  29. package/dist/src/editors/ox-input-tree.js +1 -1
  30. package/dist/src/editors/ox-input-tree.js.map +1 -1
  31. package/dist/src/filters/filter-range-date.js +12 -1
  32. package/dist/src/filters/filter-range-date.js.map +1 -1
  33. package/dist/src/filters/filters-form.d.ts +1 -0
  34. package/dist/src/filters/filters-form.js +21 -3
  35. package/dist/src/filters/filters-form.js.map +1 -1
  36. package/dist/src/handlers/contextmenu-tree-mutation.js +1 -19
  37. package/dist/src/handlers/contextmenu-tree-mutation.js.map +1 -1
  38. package/dist/src/index.d.ts +0 -1
  39. package/dist/src/index.js +0 -1
  40. package/dist/src/index.js.map +1 -1
  41. package/dist/src/renderers/ox-grist-renderer-tree.js +1 -1
  42. package/dist/src/renderers/ox-grist-renderer-tree.js.map +1 -1
  43. package/dist/src/types.d.ts +428 -5
  44. package/dist/src/types.js +9 -0
  45. package/dist/src/types.js.map +1 -1
  46. package/dist/stories/accumulator.stories.js +10 -5
  47. package/dist/stories/accumulator.stories.js.map +1 -1
  48. package/dist/stories/dynamic-editable.stories.js +10 -0
  49. package/dist/stories/dynamic-editable.stories.js.map +1 -1
  50. package/dist/stories/fixed-column.stories.js +3 -3
  51. package/dist/stories/fixed-column.stories.js.map +1 -1
  52. package/dist/stories/grist-modes.stories.js +23 -2
  53. package/dist/stories/grist-modes.stories.js.map +1 -1
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/docs/gutter/gutter.md +7 -0
  56. package/package.json +6 -5
  57. package/src/accumulator/accumulator.ts +4 -4
  58. package/src/configure/rows-option-builder.ts +11 -1
  59. package/src/configure/zero-config.ts +1 -0
  60. package/src/data-card/event-handlers/record-card-click-handler.ts +1 -1
  61. package/src/data-grid/data-grid-accum-field.ts +3 -2
  62. package/src/data-grid/data-grid-body.ts +3 -1
  63. package/src/data-grid/data-grid-header.ts +22 -18
  64. package/src/data-grist.ts +250 -3
  65. package/src/data-list/event-handlers/record-partial-click-handler.ts +1 -1
  66. package/src/data-manipulator.ts +113 -22
  67. package/src/editors/ox-grist-editor-number.ts +3 -2
  68. package/src/editors/ox-grist-editor.ts +6 -2
  69. package/src/editors/ox-input-tree.ts +1 -1
  70. package/src/filters/filter-range-date.ts +16 -1
  71. package/src/filters/filters-form.ts +25 -2
  72. package/src/handlers/contextmenu-tree-mutation.ts +1 -19
  73. package/src/index.ts +0 -1
  74. package/src/renderers/ox-grist-renderer-tree.ts +1 -1
  75. package/src/types.ts +435 -5
  76. package/stories/accumulator.stories.ts +10 -5
  77. package/stories/dynamic-editable.stories.ts +10 -0
  78. package/stories/fixed-column.stories.ts +3 -3
  79. package/stories/grist-modes.stories.ts +23 -2
  80. package/themes/grist-theme.css +1 -1
  81. package/dist/src/data-grid/event-handlers/data-grid-body-focus-change-handler copy.d.ts +0 -7
  82. package/dist/src/data-grid/event-handlers/data-grid-body-focus-change-handler copy.js +0 -19
  83. package/dist/src/data-grid/event-handlers/data-grid-body-focus-change-handler copy.js.map +0 -1
  84. package/dist/src/handlers/contextmenu-tree.d.ts +0 -3
  85. package/dist/src/handlers/contextmenu-tree.js +0 -30
  86. package/dist/src/handlers/contextmenu-tree.js.map +0 -1
  87. package/dist/src/handlers/move-up copy.d.ts +0 -3
  88. package/dist/src/handlers/move-up copy.js +0 -26
  89. package/dist/src/handlers/move-up copy.js.map +0 -1
  90. package/src/value-generator/date-generator.ts +0 -35
  91. package/src/value-generator/hour-time-generator.ts +0 -43
  92. package/src/value-generator/index.ts +0 -1
  93. package/src/value-generator/minute-time-generator.ts +0 -43
  94. package/src/value-generator/month-date-generator.ts +0 -38
  95. package/src/value-generator/now-generator.ts +0 -10
  96. package/src/value-generator/registry.ts +0 -58
  97. package/src/value-generator/time-generator.ts +0 -33
  98. package/src/value-generator/today-generator.ts +0 -10
  99. package/src/value-generator/week-date-generator.ts +0 -40
  100. package/src/value-generator/year-date-generator.ts +0 -36
package/src/types.ts CHANGED
@@ -12,6 +12,18 @@ import { OxGristEditor } from './editors'
12
12
  import { QueryFilter } from './filters'
13
13
  import { OxGristRenderer } from './renderers/ox-grist-renderer'
14
14
 
15
+ /**
16
+ * Configuration object for defining the structure and behavior of a Grist table.
17
+ *
18
+ * @typedef {Object} GristConfig
19
+ * @property {ColumnConfig[]} columns - An array of column configurations.
20
+ * @property {RowsConfig} rows - Configuration for rows and their behavior.
21
+ * @property {ListConfig} list - Configuration for the list view.
22
+ * @property {TreeConfig} tree - Configuration for tree-related settings.
23
+ * @property {PaginationConfig} [pagination] - Configuration for pagination settings (optional).
24
+ * @property {SortersConfig} [sorters] - Configuration for sorting settings (optional).
25
+ * @property {FiltersConfig} [filters] - Configuration for filtering settings (optional).
26
+ */
15
27
  export type GristConfig = {
16
28
  columns: ColumnConfig[]
17
29
  rows: RowsConfig
@@ -22,8 +34,29 @@ export type GristConfig = {
22
34
  filters?: FiltersConfig
23
35
  }
24
36
 
37
+ /**
38
+ * Configuration object for specifying sorting options.
39
+ *
40
+ * @typedef {Object} SorterConfig
41
+ * @property {string} name - The name of the sorting option.
42
+ * @property {boolean} [desc] - Optional. Indicates whether the sorting is in descending order (optional).
43
+ */
25
44
  export type SorterConfig = { name: string; desc?: boolean }
45
+
46
+ /**
47
+ * Configuration array for specifying multiple sorting options.
48
+ *
49
+ * @typedef {SorterConfig[]} SortersConfig
50
+ */
26
51
  export type SortersConfig = SorterConfig[]
52
+
53
+ /**
54
+ * Enumeration of filter operators used to define filter conditions.
55
+ *
56
+ * @typedef {'search' | 'eq' | 'between' | 'gte' | 'lte' | 'is_not_true' | 'in' | 'like' | 'i_like' | 'noteq' |
57
+ * 'is_empty_num_id' | 'is_blank' | 'is_present' | 'is_not_false' | 'is_true' | 'is_false' | 'is_not_null' |
58
+ * 'is_null' | 'notin_with_null' | 'notin' | 'gt' | 'lt' | 'i_nlike' | 'nlike'} FilterOperator
59
+ */
27
60
  export type FilterOperator =
28
61
  | 'search'
29
62
  | 'eq'
@@ -50,6 +83,16 @@ export type FilterOperator =
50
83
  | 'i_nlike'
51
84
  | 'nlike'
52
85
 
86
+ /**
87
+ * Configuration object for specifying filter conditions.
88
+ *
89
+ * @typedef {Object} FilterConfigObject
90
+ * @property {string} type - The type of the filter condition.
91
+ * @property {FilterOperator} [operator] - The filter operator used to compare values (optional).
92
+ * @property {Object} [options] - Additional options or parameters for the filter condition (optional).
93
+ * @property {string|number|boolean|string[]|number[]|undefined} [value] - The value to compare with in the filter condition (optional).
94
+ * @property {string} [label] - The label to display for the filter condition (optional).
95
+ */
53
96
  export type FilterConfigObject = {
54
97
  type: string
55
98
  operator?: FilterOperator
@@ -57,8 +100,31 @@ export type FilterConfigObject = {
57
100
  value?: string | number | boolean | string[] | number[] | undefined
58
101
  label?: string
59
102
  }
103
+
104
+ /**
105
+ * Configuration option for specifying filter conditions.
106
+ *
107
+ * The `FilterConfig` type can take one of the following forms:
108
+ * - A `FilterConfigObject` representing a specific filter condition.
109
+ * - A `FilterOperator` representing a predefined filter operator.
110
+ * - A boolean value to enable or disable filtering for a specific column.
111
+ *
112
+ * @typedef {Object|FilterOperator|boolean} FilterConfig
113
+ */
60
114
  export type FilterConfig = FilterConfigObject | FilterOperator | boolean
61
115
 
116
+ /**
117
+ * Represents a filter condition with the following properties:
118
+ *
119
+ * - `name`: The name of the column or field being filtered.
120
+ * - `operator`: The filter operator used for comparison.
121
+ * - `value`: The value or values to compare against.
122
+ *
123
+ * @typedef {Object} FilterValue
124
+ * @property {string} name - The name of the column or field.
125
+ * @property {FilterOperator} operator - The filter operator.
126
+ * @property {string|number|boolean|string[]|number[]|undefined} value - The value(s) to compare.
127
+ */
62
128
  export type FilterValue = {
63
129
  name: string
64
130
  operator: FilterOperator
@@ -67,14 +133,23 @@ export type FilterValue = {
67
133
 
68
134
  /**
69
135
  * Configuration options for filters.
136
+ *
137
+ * @typedef {Object} FiltersConfig
138
+ * @property {boolean} [header] - Specifies whether to provide filtering functionality in the header.
70
139
  */
71
140
  export type FiltersConfig = {
72
- /**
73
- * Specifies whether to provide filtering functionality in the header.
74
- */
75
141
  header?: boolean
76
142
  }
77
143
 
144
+ /**
145
+ * Configuration options for pagination.
146
+ *
147
+ * @typedef {Object} PaginationConfig
148
+ * @property {number} [page] - The current page number.
149
+ * @property {number} [limit] - The maximum number of records to display per page.
150
+ * @property {number[]} [pages] - An array of available page numbers.
151
+ * @property {boolean} [infinite] - Specifies whether to use infinite scrolling for pagination.
152
+ */
78
153
  export type PaginationConfig = {
79
154
  page?: number
80
155
  limit?: number
@@ -82,12 +157,33 @@ export type PaginationConfig = {
82
157
  infinite?: boolean
83
158
  }
84
159
 
160
+ /**
161
+ * Option to specify the inheritance behavior for including data from parent domains.
162
+ *
163
+ * - 'None': Do not include data from the parent domain.
164
+ * - 'Include': Include data from the parent domain along with current domain data.
165
+ * - 'Only': Include data only from the parent domain, excluding current domain data.
166
+ *
167
+ * @enum {string}
168
+ */
85
169
  export enum InheritedValueType {
86
170
  None = 'None',
87
171
  Include = 'Include',
88
172
  Only = 'Only'
89
173
  }
90
174
 
175
+ /**
176
+ * Configuration options for fetching data from a data source.
177
+ *
178
+ * @typedef {Object} FetchOption
179
+ * @property {number} [page] - The page number to retrieve.
180
+ * @property {number} [limit] - The maximum number of records to retrieve per page.
181
+ * @property {SortersConfig} [sorters] - An array of sorting configurations for data. Only one of these options needs to be set.
182
+ * @property {SortersConfig} [sortings] - An array of sorting configurations for data. Only one of these options needs to be set.
183
+ * @property {QueryFilter[]} [filters] - An array of filtering criteria.
184
+ * @property {InheritedValueType} [inherited] - Specifies the inheritance behavior for including data from parent domains.
185
+ * @property {object} [options] - Additional options for customizing data fetching behavior.
186
+ */
91
187
  export type FetchOption = {
92
188
  page?: number
93
189
  limit?: number
@@ -97,14 +193,44 @@ export type FetchOption = {
97
193
  inherited?: InheritedValueType
98
194
  options?: object
99
195
  }
196
+
197
+ /**
198
+ * Represents the result of a data fetching operation.
199
+ *
200
+ * @typedef {Object} FetchResult
201
+ * @property {number} [page] - The page number of the fetched data.
202
+ * @property {number} [limit] - The maximum number of records per page.
203
+ * @property {number} total - The total number of records in the data source.
204
+ * @property {GristRecord[]} records - An array of fetched data records.
205
+ */
100
206
  export type FetchResult = {
101
207
  page?: number
102
208
  limit?: number
103
209
  total: number
104
210
  records: GristRecord[]
105
211
  } | void
212
+
213
+ /**
214
+ * A function that handles data fetching operations.
215
+ *
216
+ * @param param - The fetch options specifying how data should be retrieved.
217
+ * @returns A promise that resolves to a `FetchResult`.
218
+ */
106
219
  export type FetchHandler = (param: FetchOption) => Promise<FetchResult>
107
220
 
221
+ /**
222
+ * Represents a Grist event handler function.
223
+ *
224
+ * @typedef {Function} GristEventHandler
225
+ * @param {ColumnConfig[]} columns - An array of column configurations.
226
+ * @param {GristData} [data] - The Grist data associated with the event.
227
+ * @param {ColumnConfig} [column] - The column configuration related to the event (if applicable).
228
+ * @param {GristRecord} [record] - The Grist record related to the event (if applicable).
229
+ * @param {number} [rowIndex] - The index of the row related to the event (if applicable).
230
+ * @param {any} [target] - The target element or object related to the event (if applicable).
231
+ * @param {Event} [e] - The event object (if applicable).
232
+ * @returns {void}
233
+ */
108
234
  export type GristEventHandler = (
109
235
  columns: ColumnConfig[],
110
236
  data?: GristData,
@@ -115,6 +241,14 @@ export type GristEventHandler = (
115
241
  e?: Event
116
242
  ) => void
117
243
 
244
+ /**
245
+ * Represents an accumulator function for data aggregation and accumulation.
246
+ *
247
+ * @typedef {string|'sum'|'avg'|'count'|'min'|'max'|Function} AccumulatorFunc
248
+ * @param {GristData} data - The Grist data for aggregation.
249
+ * @param {ColumnConfig} column - The column configuration for aggregation.
250
+ * @returns {string|number} - The aggregated result.
251
+ */
118
252
  export type AccumulatorFunc =
119
253
  | 'sum'
120
254
  | 'avg'
@@ -123,6 +257,27 @@ export type AccumulatorFunc =
123
257
  | 'max'
124
258
  | ((data: GristData, column: ColumnConfig) => string | number)
125
259
 
260
+ /**
261
+ * Type representing an accumulator function or configuration object.
262
+ *
263
+ * An accumulator is used for data aggregation and accumulation purposes. It can be either
264
+ * a predefined accumulator function (e.g., 'sum', 'avg', 'count', etc.) or a configuration
265
+ * object specifying the type of accumulator and labeling options.
266
+ *
267
+ * @typedef {AccumulatorFunc|{type: AccumulatorFunc, tag?: boolean}} AccumulatorObject
268
+ * @property {AccumulatorFunc} [type] - The type of accumulator function or predefined function name.
269
+ * @property {boolean} [tag] - An option for adding a label to represent the result of an aggregation function. This label is added in front of the aggregated value.
270
+ *
271
+ * @example
272
+ * // Using a predefined accumulator function:
273
+ * const accumulator: AccumulatorObject = 'sum'; // Represents a 'sum' accumulator.
274
+ *
275
+ * // Using an accumulator configuration object:
276
+ * const accumulatorConfig: AccumulatorObject = {
277
+ * type: 'avg', // Specifies the type of accumulator ('avg' for average).
278
+ * tag: true, // Option for adding a label to represent the result of an aggregation function. This label is added in front of the aggregated value.
279
+ * };
280
+ */
126
281
  export type AccumulatorObject =
127
282
  | AccumulatorFunc
128
283
  | {
@@ -130,10 +285,45 @@ export type AccumulatorObject =
130
285
  tag?: boolean
131
286
  }
132
287
 
288
+ /**
289
+ * Type representing column configuration information.
290
+ *
291
+ * @typedef {object} ColumnConfig
292
+ * @property {string} type - Represents the data type of the column (e.g., 'text', 'number', 'date', 'gutter', etc.).
293
+ * @property {string} name - Represents the name of the column.
294
+ * @property {('button'|'sequence'|'row-selector'|'dirty')} [gutterName] - If the column type is 'gutter', specifies the name of one of the registered gutters (only set when the type is 'gutter').
295
+ * @property {boolean} [fixed] - In case of a grid type column, specifies whether the column's position should be fixed and unaffected by horizontal scrolling (optional).
296
+ * @property {HeaderConfig} header - Object representing the header configuration of the column.
297
+ * @property {RecordConfig} record - Object representing the record configuration of the column.
298
+ * @property {GristEventHandlerSet} handlers - Object representing the Grist event handler settings.
299
+ * @property {LabelConfig} label - Object representing the label configuration of the column. This property is used to represent the label of the column's information in list mode, card mode, and when displaying the column in a filter form (ox-filters-form).
300
+ * @property {boolean} [hidden] - Indicates whether the column is hidden or not (optional).
301
+ * @property {boolean} [sortable] - Indicates whether the column is sortable or not (optional). If this setting is true, the header provides the ability to toggle the sorting direction.
302
+ * @property {boolean} [resizable] - Indicates whether the column is resizable or not (optional). This setting determines whether the column's width can be adjusted.
303
+ * @property {(number|string|ColumnWidthCallback)} [width] - Represents the width of the column (e.g., 100, '50%', or a callback function to calculate width).
304
+ * @property {boolean} [forList] - Indicates whether the column is intended for display in list mode (optional, applicable only to gutter type columns).
305
+ * @property {boolean} [forCard] - Indicates whether the column is intended for display in card mode (optional, applicable only to gutter type columns).
306
+ * @property {ValidationCallback} [validation] - Callback function for column validation (optional). This function validates whether the value of the column is valid when edited.
307
+ * @property {AccumulatorObject} [accumulator] - Object used for accumulating values of the column (optional, applicable only in grid mode). It specifies a function to automatically aggregate the values of the column for all records. The aggregated result is displayed in a row below the last record (accumulation record).
308
+ * @property {FilterConfig} [filter] - Object representing the filter configuration of the column.
309
+ * @property {(ImexConfig|boolean)} [imex] - Object or boolean value representing the configuration for importing and exporting column data.
310
+ * @property {boolean} [multiple] - Indicates whether the column allows multiple selections or not (optional).
311
+ * @property {boolean} [rowCount] - Indicates whether the column shows the row count or not (optional).
312
+ */
133
313
  export type ColumnConfig = {
134
314
  type: string
135
315
  name: string
136
- gutterName?: string
316
+ /**
317
+ * "gutter" 타입의 컬럼인 경우, 등록된 gutter들 중의 하나의 이름을 명시합니다(type이 gutter인 경우에만 설정합니다).
318
+ * (e.g., 'button', 'sequence', 'row-selector', 'dirty', etc)
319
+ *
320
+ * "Gutter"는 테이블 형태에서 각 행의 왼쪽 또는 오른쪽에 위치한 추가적인 열(column)을 가리킵니다.
321
+ * 이 열은 주로 각 행(row)을 식별하거나 특정 작업을 수행하기 위한 버튼 또는 링크와 같은 요소를 표시하는 데 사용됩니다.
322
+ * Gutter 열은 주로 데이터 행에 대한 조작 또는 행의 상태를 나타내는 데 사용됩니다.
323
+ * 예를 들어, 테이블에서 각 행이 특정 작업을 수행하는 버튼을 포함할 때, 이러한 버튼이 Gutter 열에 배치될 수 있습니다.
324
+ * 또한 Gutter 열은 행을 선택하거나 행의 상태를 나타내는 체크박스를 포함할 수도 있습니다.
325
+ */
326
+ gutterName?: 'button' | 'sequence' | 'row-selector' | 'dirty'
137
327
  fixed?: boolean
138
328
  header: HeaderConfig
139
329
  record: RecordConfig
@@ -144,6 +334,7 @@ export type ColumnConfig = {
144
334
  resizable?: boolean
145
335
  width?: number | string | ColumnWidthCallback
146
336
  forList?: boolean
337
+ forCard?: boolean
147
338
  validation?: ValidationCallback
148
339
  accumulator?: AccumulatorObject
149
340
  filter?: FilterConfig
@@ -152,8 +343,40 @@ export type ColumnConfig = {
152
343
  rowCount?: boolean
153
344
  }
154
345
 
346
+ /**
347
+ * Callback function type for column validation.
348
+ *
349
+ * This function is used to validate whether the value of a column is valid when edited.
350
+ *
351
+ * @callback ValidationCallback
352
+ * @param {any} after - The new value of the column after editing.
353
+ * @param {any} before - The previous value of the column before editing.
354
+ * @param {GristRecord} record - The record being edited.
355
+ * @param {ColumnConfig} column - The configuration of the column being edited.
356
+ * @returns {boolean} - Returns `true` if the value is valid, `false` otherwise.
357
+ */
155
358
  export type ValidationCallback = (after: any, before: any, record: GristRecord, column: ColumnConfig) => boolean
156
359
 
360
+ /**
361
+ * Configuration options for column labels.
362
+ *
363
+ * The label for a column can be customized using various options.
364
+ *
365
+ * @typedef {string|boolean|Object} LabelConfig
366
+ * @property {LabelRenderer} [renderer] - A custom renderer function for the column label.
367
+ *
368
+ * @example
369
+ * // Using a string as a label:
370
+ * const label: LabelConfig = "Column Label"; // Sets the label as "Column Label".
371
+ *
372
+ * // Using a boolean to determine label visibility:
373
+ * const label: LabelConfig = true; // Shows the default label based on the header configuration.
374
+ *
375
+ * // Using a custom renderer function for the label:
376
+ * const label: LabelConfig = {
377
+ * renderer: customLabelRenderer, // Specifies a custom renderer function.
378
+ * };
379
+ */
157
380
  export type LabelConfig =
158
381
  | string
159
382
  | boolean
@@ -161,19 +384,59 @@ export type LabelConfig =
161
384
  renderer: LabelRenderer
162
385
  }
163
386
 
387
+ /**
388
+ * Custom label renderer function for generating column labels.
389
+ *
390
+ * @callback LabelRenderer
391
+ * @param {ColumnConfig} column - The column configuration object for which the label is being generated.
392
+ * @returns {void}
393
+ */
164
394
  export type LabelRenderer = (column: ColumnConfig) => void
165
395
 
396
+ /**
397
+ * Custom callback function for calculating column width.
398
+ *
399
+ * @callback ColumnWidthCallback
400
+ * @param {ColumnConfig} column - The column configuration object for which the width is being calculated.
401
+ * @returns {string} - The calculated width as a string (e.g., '100', '50%').
402
+ */
166
403
  export type ColumnWidthCallback = (column: ColumnConfig) => string
167
404
 
405
+ /**
406
+ * Configuration for defining the header of a column.
407
+ *
408
+ * @typedef {Object} HeaderConfig
409
+ * @property {HeaderRenderer} renderer - The function used to render the column header.
410
+ * @property {string} [style] - Optional CSS style for the column header.
411
+ * @property {string} [group] - Optional group identifier for the column header.
412
+ * @property {string} [groupStyle] - Optional CSS style for the header group.
413
+ */
168
414
  export type HeaderConfig = {
169
415
  renderer: HeaderRenderer
170
416
  style?: string
171
417
  group?: string
172
418
  groupStyle?: string
173
419
  }
420
+
421
+ /**
422
+ * Function type for rendering column headers.
423
+ *
424
+ * @callback HeaderRenderer
425
+ * @param {ColumnConfig} column - The column configuration object.
426
+ * @returns {*} - The rendered header content.
427
+ */
174
428
  export type HeaderRenderer = (column: ColumnConfig) => any
175
429
 
176
- export type ValueGeneratorFn = (...args: any[]) => any
430
+ /**
431
+ * Configuration for specifying default values for fields in a record.
432
+ * Default values can be set using predefined value generator functions or custom user-defined functions.
433
+ * This configuration allows you to define the default value generation method and any additional parameters.
434
+ *
435
+ * @typedef {Object|Function} DefaultValueFnConfig
436
+ * @property {string} [name] - The name of the default value function to be used for the column.
437
+ * @property {any[]} [params] - The parameters to be passed to the default value function.
438
+ * @property {Function} [Function] - A custom user-defined function for generating default values.
439
+ */
177
440
  export type DefaultValueFnConfig =
178
441
  | {
179
442
  /**
@@ -188,6 +451,24 @@ export type DefaultValueFnConfig =
188
451
  }
189
452
  | Function
190
453
 
454
+ /**
455
+ * Configuration for defining fields within a record.
456
+ * Each field can have various settings such as rendering, editing, alignment, etc.
457
+ * The 'defaultValue' property is used to specify the default value generation method and parameters.
458
+ *
459
+ * @typedef {Object} RecordConfig
460
+ * @property {FieldRenderer} renderer - The rendering function for the field.
461
+ * @property {FieldEditor|undefined} [editor] - The editing function for the field (optional).
462
+ * @property {boolean|Function} [editable] - Specifies if the field is editable. It can be a boolean or a function (optional).
463
+ * @property {boolean} [mandatory] - Specifies if the field is mandatory (optional).
464
+ * @property {GristClassifier} classifier - A classifier function for the field.
465
+ * @property {'left'|'right'|'center'} [align] - The alignment of the field's content (optional).
466
+ * @property {*} options - Additional options for the field.
467
+ * @property {string|undefined} [rowOptionField] - The name of a field for row-level options associated with this field (optional).
468
+ * @property {DefaultValueFnConfig|undefined} [defaultValue] - Configuration for specifying the default value for the field.
469
+ * It can be a predefined value generator function or a custom user-defined function (optional).
470
+ * @property {Object.<string, *>|undefined} [extended] - Additional extended properties that can be added as needed for specific field configurations (optional).
471
+ */
191
472
  export type RecordConfig = {
192
473
  renderer: FieldRenderer
193
474
  editor?: FieldEditor
@@ -201,6 +482,17 @@ export type RecordConfig = {
201
482
  [extended: string]: any
202
483
  }
203
484
 
485
+ /**
486
+ * A function type used for rendering the content of a field in various components.
487
+ *
488
+ * @callback FieldRenderer
489
+ * @param {*} value - The value of the field to be rendered.
490
+ * @param {ColumnConfig} column - The configuration of the column to which the field belongs.
491
+ * @param {GristRecord} record - The record object containing the field's data.
492
+ * @param {number} rowIndex - The index of the row to which the field belongs.
493
+ * @param {DataGridField|RecordCard|DataCardGutter|DataCardField|DataListGutter|DataListField|RecordPartial|DataReportField|Element} owner - The component or element that owns the field.
494
+ * @returns {OxGristRenderer|TemplateResult|string|void} - The rendered content, which can be of different types depending on the implementation.
495
+ */
204
496
  export type FieldRenderer = (
205
497
  value: any,
206
498
  column: ColumnConfig,
@@ -217,6 +509,18 @@ export type FieldRenderer = (
217
509
  | DataReportField
218
510
  | Element
219
511
  ) => OxGristRenderer | TemplateResult | string | void
512
+
513
+ /**
514
+ * A function type used for defining a custom editor for a field in a data grid.
515
+ *
516
+ * @callback FieldEditor
517
+ * @param {*} value - The current value of the field.
518
+ * @param {ColumnConfig} column - The configuration of the column to which the field belongs.
519
+ * @param {GristRecord} record - The record object containing the field's data.
520
+ * @param {number} rowIndex - The index of the row to which the field belongs.
521
+ * @param {DataGridField} field - The data grid field that owns the editor.
522
+ * @returns {OxGristEditor} - The custom editor component.
523
+ */
220
524
  export type FieldEditor = (
221
525
  value: any,
222
526
  column: ColumnConfig,
@@ -225,12 +529,30 @@ export type FieldEditor = (
225
529
  field: DataGridField
226
530
  ) => OxGristEditor
227
531
 
532
+ /**
533
+ * A function type used for rendering the filter select options in a filter form.
534
+ *
535
+ * @callback FilterSelectRenderer
536
+ * @param {ColumnConfig} column - The configuration of the column for which the filter is being rendered.
537
+ * @param {(string|number|boolean|string[]|number[]|any|undefined)} value - The current value of the filter.
538
+ * @param {Element} owner - The DOM element that owns the filter select renderer.
539
+ * @returns {(TemplateResult|string|void)} - The rendered filter select options as a Lit HTML template result, a string, or nothing.
540
+ */
228
541
  export type FilterSelectRenderer = (
229
542
  column: ColumnConfig,
230
543
  value: string | number | boolean | string[] | number[] | any | undefined,
231
544
  owner: Element
232
545
  ) => TemplateResult | string | void
233
546
 
547
+ /**
548
+ * An object representing a set of event handler functions for various events in Grist.
549
+ *
550
+ * @typedef {Object} GristEventHandlerSet
551
+ * @property {GristEventHandler} [click] - The click event handler function.
552
+ * @property {GristEventHandler} [dblclick] - The double-click event handler function.
553
+ * @property {GristEventHandler} [focus] - The focus event handler function.
554
+ * @property {GristEventHandler} [contextmenu] - The context menu event handler function.
555
+ */
234
556
  export type GristEventHandlerSet = {
235
557
  click?: GristEventHandler
236
558
  dblclick?: GristEventHandler
@@ -238,17 +560,41 @@ export type GristEventHandlerSet = {
238
560
  contextmenu?: GristEventHandler
239
561
  }
240
562
 
563
+ /**
564
+ * Configuration options for defining how records are displayed in list mode in a Grist.
565
+ *
566
+ * @typedef {Object} ListConfig
567
+ * @property {string} [thumbnail] - The name of the field to use as a thumbnail image for records in list mode.
568
+ * @property {string[]} fields - An array of field names to display in the list mode.
569
+ * @property {string[]} details - An array of field names to display as additional details in the list mode.
570
+ */
241
571
  export type ListConfig = {
242
572
  thumbnail?: string
243
573
  fields: string[]
244
574
  details: string[]
245
575
  }
246
576
 
577
+ /**
578
+ * Configuration options for managing tree-like structures in a Grist table.
579
+ *
580
+ * @typedef {Object} TreeConfig
581
+ * @property {string} [childrenProperty] - The property name that specifies the children of a record.
582
+ * @property {boolean | Function} [expanded] - Specifies whether tree nodes are initially expanded or a function to determine the initial expansion state for a given record.
583
+ */
247
584
  export type TreeConfig = {
248
585
  childrenProperty?: string
249
586
  expanded?: boolean | ((x: GristRecord) => boolean)
250
587
  }
251
588
 
589
+ /**
590
+ * Configuration options for importing and exporting column data.
591
+ *
592
+ * @typedef {Object} ImexConfig
593
+ * @property {string} header - The header text for the column in import/export settings.
594
+ * @property {string} key - The key or identifier for the column in import/export settings.
595
+ * @property {number} width - The width of the column in import/export settings.
596
+ * @property {string} type - The data type of the column in import/export settings.
597
+ */
252
598
  export type ImexConfig = {
253
599
  header: string
254
600
  key: string
@@ -256,9 +602,23 @@ export type ImexConfig = {
256
602
  type: string
257
603
  }
258
604
 
605
+ /**
606
+ * Configuration options for defining rows within a Grist table or view.
607
+ *
608
+ * @typedef {Object} RowsConfig
609
+ * @property {boolean} [accumulator] - Specifies whether an accumulator row should be displayed.
610
+ * @property {boolean} appendable - Indicates whether new rows can be appended to the table.
611
+ * @property {boolean} insertable - Indicates whether new rows can be inserted into the table.
612
+ * @property {RowSelectableConfig} [selectable] - Configuration for row selection options.
613
+ * @property {GroupConfig[]} groups - An array of group configuration options.
614
+ * @property {string[]} totals - An array of field names for which totals should be calculated and displayed.
615
+ * @property {GristClassifier} classifier - A function that classifies rows based on their attributes.
616
+ * @property {GristEventHandlerSet} handlers - An object containing event handler functions for various row-level events.
617
+ */
259
618
  export type RowsConfig = {
260
619
  accumulator?: boolean
261
620
  appendable: boolean
621
+ editable: boolean
262
622
  insertable: boolean
263
623
  selectable?: RowSelectableConfig
264
624
  groups: GroupConfig[]
@@ -267,11 +627,38 @@ export type RowsConfig = {
267
627
  handlers: GristEventHandlerSet
268
628
  }
269
629
 
630
+ /**
631
+ * A function used to classify and style individual records in a Grist table.
632
+ *
633
+ * @typedef {Function} GristClassifier
634
+ *
635
+ * @param {GristRecord} record - The record to be classified.
636
+ * @param {number} rowIndex - The index of the row in the table.
637
+ *
638
+ * @returns {Object|void} An object containing classification properties or `void`.
639
+ * - `emphasized` (optional): A boolean, string, or array of strings indicating the emphasis style.
640
+ * - Additional properties can be added as needed for custom styling.
641
+ */
270
642
  export type GristClassifier = (
271
643
  record: GristRecord,
272
644
  rowIndex: number
273
645
  ) => { emphasized?: boolean | string | string[]; [key: string]: any } | void
274
646
 
647
+ /**
648
+ * Configuration options for defining group headers in a Grist table.
649
+ *
650
+ * @typedef {Object} GroupConfig
651
+ *
652
+ * @property {string} align - The alignment of the group header ('left', 'center', or 'right').
653
+ * @property {ColumnConfig} [titleColumn] - The column configuration used as the title of the group (optional).
654
+ * @property {string} title - The title of the group.
655
+ * @property {string} [value] - A value associated with the group (optional).
656
+ * @property {string} [groupName] - The name of the group (optional).
657
+ * @property {number} [row] - The row index where the group header should appear (optional).
658
+ * @property {string|number} column - The column name or index where the group header should appear.
659
+ * @property {number} rowspan - The number of rows the group header should span.
660
+ * @property {number} [colspan] - The number of columns the group header should span (optional).
661
+ */
275
662
  export type GroupConfig = {
276
663
  align: string
277
664
  titleColumn?: ColumnConfig
@@ -284,10 +671,36 @@ export type GroupConfig = {
284
671
  colspan?: number
285
672
  }
286
673
 
674
+ /**
675
+ * Configuration options for specifying row selectability in a Grist table.
676
+ *
677
+ * @typedef {Object} RowSelectableConfig
678
+ *
679
+ * @property {boolean} [multiple] - Indicates whether multiple rows can be selected (optional).
680
+ */
287
681
  export type RowSelectableConfig = {
288
682
  multiple?: boolean
289
683
  }
290
684
 
685
+ /**
686
+ * Represents a data record in Grist.
687
+ *
688
+ * @typedef {Object} GristRecord
689
+ * @property {string} [id] - The unique identifier for the record.
690
+ * @property {string} [name] - The name or label associated with the record.
691
+ * @property {GristRecord[]} [children] - An array of child records, if applicable.
692
+ * @property {number} [__seq__] - A numeric sequence identifier for the record.
693
+ * @property {string} [__dirty__] - Indicates if the record is dirty (changed).
694
+ * @property {boolean} [__selected__] - Indicates if the record is selected.
695
+ * @property {object[]} [__changes__] - An array of changes made to the record.
696
+ * @property {object} [__dirtyfields__] - An object representing dirty (changed) fields in the record.
697
+ * @property {any} [__origin__] - The original data or source of the record.
698
+ * @property {boolean} [__collapsed__] - Indicates if the record is collapsed (e.g., in a tree view).
699
+ * @property {number} [__depth__] - The depth or level of the record in a hierarchical structure.
700
+ * @property {'checked' | 'half-checked' | 'unchecked'} [__check_in_tree__] - Indicates the check state of the record in a tree view.
701
+ * @property {GristRecord[]} [__children__] - An array of child records in a tree view.
702
+ * @property {any} [key] - Additional custom properties specific to the record.
703
+ */
291
704
  export type GristRecord = {
292
705
  id?: string
293
706
  name?: string
@@ -305,6 +718,16 @@ export type GristRecord = {
305
718
  [key: string]: any
306
719
  }
307
720
 
721
+ /**
722
+ * Represents a set of data retrieved from a Grist table.
723
+ *
724
+ * @typedef {Object} GristData
725
+ *
726
+ * @property {number} [page] - The page number of the retrieved data (optional).
727
+ * @property {number} [total] - The total number of records in the data source (optional).
728
+ * @property {number} [limit] - The maximum number of records per page (optional).
729
+ * @property {GristRecord[]} records - An array of fetched data records.
730
+ */
308
731
  export type GristData = {
309
732
  page?: number
310
733
  total?: number
@@ -312,4 +735,11 @@ export type GristData = {
312
735
  records: GristRecord[]
313
736
  }
314
737
 
738
+ /**
739
+ * A function that determines whether a Grist record should be selected or not.
740
+ *
741
+ * @callback GristSelectFunction
742
+ * @param {GristRecord} record - The Grist record to evaluate.
743
+ * @returns {boolean} - `true` if the record should be selected, `false` otherwise.
744
+ */
315
745
  export type GristSelectFunction = (record: GristRecord) => boolean