@stonecrop/atable 0.4.12 → 0.4.13

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.
@@ -4,19 +4,67 @@ import { createTableStore } from '../stores/table';
4
4
  * Table column definition.
5
5
  * @public
6
6
  */
7
- export type TableColumn = {
7
+ export interface TableColumn {
8
+ /**
9
+ * The key of the column. This is used to identify the column in the table.
10
+ */
8
11
  name: string;
12
+ /**
13
+ * The alignment of the column. Possible values:
14
+ * - `left` - left aligned
15
+ * - `center` - center aligned
16
+ * - `right` - right aligned
17
+ * - `start` - aligned to the start of the column
18
+ * - `end` - aligned to the end of the column
19
+ *
20
+ * @defaultValue 'center'
21
+ */
9
22
  align?: CanvasTextAlign;
23
+ /**
24
+ * Control whether cells for the column is editable.
25
+ *
26
+ * @defaultValue false
27
+ */
10
28
  edit?: boolean;
29
+ /**
30
+ * The label of the column. This is displayed in the table header.
31
+ *
32
+ * @defaultValue If no label is provided, a character will be assigned alphabetically,
33
+ * starting from 'A' for the first column, 'B' for the second column, and so on.
34
+ */
11
35
  label?: string;
36
+ /**
37
+ * The data-type of the column. Possible values:
38
+ * - `Data` - the column contains text data
39
+ * - `Select` - the column contains a select input
40
+ * - `Date` - the column contains a date input
41
+ * - `component` - the column contains a custom component
42
+ *
43
+ * @beta
44
+ */
12
45
  type?: string;
46
+ /**
47
+ * The width of the column. This can be a number (in pixels) or a string (in CSS units).
48
+ *
49
+ * @defaultValue '40ch'
50
+ */
13
51
  width?: string;
52
+ /**
53
+ * Control whether the column should be pinned to the table.
54
+ *
55
+ * @defaultValue false
56
+ */
14
57
  pinned?: boolean;
15
- colspan?: number;
16
- ganttComponent?: string;
17
- isGantt?: boolean;
18
- originalIndex?: number;
58
+ /**
59
+ * The component to use to render the cell for the column. If not provided, the table will
60
+ * render the default `<td>` element.
61
+ */
19
62
  cellComponent?: string;
63
+ /**
64
+ * Additional properties to pass to the table's cell component.
65
+ *
66
+ * Only applicable if the `cellComponent` property is set for the column.
67
+ */
20
68
  cellComponentProps?: Record<string, any>;
21
69
  /**
22
70
  * The component to use for the modal. If a function is provided, it will be called with the cell context.
@@ -33,26 +81,82 @@ export type TableColumn = {
33
81
  * - `store` - the table data store
34
82
  */
35
83
  modalComponent?: string | ((context: CellContext) => string);
84
+ /**
85
+ * Additional properties to pass to the modal component.
86
+ *
87
+ * Only applicable if the `modalComponent` property is set for the column.
88
+ */
36
89
  modalComponentExtraProps?: Record<string, any>;
90
+ /**
91
+ * The format function to use to format the value of the cell. This can either be a normal or stringified
92
+ * function that takes the value and the cell context and returns a string.
93
+ */
37
94
  format?: string | ((value: any, context: CellContext) => string);
95
+ /**
96
+ * The masking function to use to apply an input mask to the cell. This will accept an input value and
97
+ * return the masked value.
98
+ */
38
99
  mask?: (value: any) => any;
39
- };
100
+ /**
101
+ * Whether the column is a Gantt column.
102
+ *
103
+ * Only applicable for Gantt tables.
104
+ *
105
+ * @defaultValue false
106
+ */
107
+ isGantt?: boolean;
108
+ /**
109
+ * The component to use to render the Gantt bar for the column.
110
+ *
111
+ * Only applicable for Gantt tables.
112
+ *
113
+ * @defaultValue 'AGanttCell'
114
+ */
115
+ ganttComponent?: string;
116
+ /**
117
+ * The colspan of the Gantt-bar for the column. This is used to determine how many columns
118
+ * the Gantt-bar should span.
119
+ *
120
+ * Only applicable for Gantt tables.
121
+ *
122
+ * @defaultValue The number of columns in the table, excluding any pinned columns.
123
+ */
124
+ colspan?: number;
125
+ /**
126
+ * The starting column index for the Gantt-bar, excluding any pinned columns. This is
127
+ * evaluated automatically while rendering the table.
128
+ *
129
+ * Only applicable for Gantt tables.
130
+ *
131
+ * @defaultValue 0
132
+ */
133
+ originalIndex?: number;
134
+ }
40
135
  /**
41
136
  * Table cell context definition.
42
137
  * @public
43
138
  */
44
- export type CellContext = {
139
+ export interface CellContext {
140
+ /**
141
+ * The row object for the current cell.
142
+ */
45
143
  row: TableRow;
144
+ /**
145
+ * The column object for the current cell.
146
+ */
46
147
  column: TableColumn;
148
+ /**
149
+ * The table object for the current cell.
150
+ */
47
151
  table: {
48
152
  [key: string]: any;
49
153
  };
50
- };
154
+ }
51
155
  /**
52
156
  * Table configuration definition.
53
157
  * @public
54
158
  */
55
- export type TableConfig = {
159
+ export interface TableConfig {
56
160
  /**
57
161
  * The type of view to display the table in. Possible values:
58
162
  * - `uncounted` - row numbers are not displayed in the table
@@ -61,61 +165,232 @@ export type TableConfig = {
61
165
  * - `tree` - carets are displayed in the number column that expand/collapse grouped rows
62
166
  */
63
167
  view?: 'uncounted' | 'list' | 'list-expansion' | 'tree' | 'gantt';
168
+ /**
169
+ * Control whether the table should be allowed to use the full width of its container.
170
+ *
171
+ * @defaultValue false
172
+ */
64
173
  fullWidth?: boolean;
65
- };
174
+ }
66
175
  /**
67
176
  * Table display definition.
68
177
  * @public
69
178
  */
70
- export type TableDisplay = {
71
- childrenOpen?: boolean;
179
+ export interface TableDisplay {
180
+ /**
181
+ * Indicates whether a row node is expanded or collapsed.
182
+ *
183
+ * Only applicable for list-expansion views.
184
+ *
185
+ * @defaultValue false
186
+ */
72
187
  expanded?: boolean;
73
- indent?: number;
188
+ /**
189
+ * Indicates whether a row node's child nodes are open or closed.
190
+ *
191
+ * Only applicable for tree views.
192
+ *
193
+ * @defaultValue false
194
+ */
195
+ childrenOpen?: boolean;
196
+ /**
197
+ * Indicates whether a row node is a parent node. This is evaluated automatically
198
+ * while rendering the table.
199
+ *
200
+ * Only applicable for tree views.
201
+ */
74
202
  isParent?: boolean;
203
+ /**
204
+ * Indicates whether a row node is a root node. This is evaluated automatically
205
+ * while rendering the table.
206
+ *
207
+ * Only applicable for tree views.
208
+ */
75
209
  isRoot?: boolean;
210
+ /**
211
+ * Indicates whether a row node is visible. This is evaluated automatically
212
+ * while rendering the table.
213
+ *
214
+ * Only applicable for tree views.
215
+ */
76
216
  open?: boolean;
217
+ /**
218
+ * The indentation level of the row node.
219
+ *
220
+ * Only applicable for tree and gantt views.
221
+ *
222
+ * @defaultValue 0
223
+ */
224
+ indent?: number;
225
+ /**
226
+ * The HTML parent element for the row node. This is evaluated automatically while rendering
227
+ * the table.
228
+ *
229
+ * Only applicable for tree and gantt views.
230
+ */
77
231
  parent?: number;
232
+ /**
233
+ * Indicates whether a row node has been modified. This is evaluated automatically when a cell
234
+ * is edited.
235
+ *
236
+ * @defaultValue false
237
+ */
78
238
  rowModified?: boolean;
79
- };
239
+ }
80
240
  /**
81
241
  * Table row definition.
82
242
  * @public
83
243
  */
84
- export type TableRow = {
244
+ export interface TableRow {
245
+ /**
246
+ * Additional arbitrary properties that can be passed to the row object.
247
+ */
85
248
  [key: string]: any;
249
+ /**
250
+ * The indentation level of the row node.
251
+ *
252
+ * Only applicable for tree and gantt views.
253
+ *
254
+ * @defaultValue 0
255
+ */
86
256
  indent?: number;
257
+ /**
258
+ * The HTML parent element for the row node. This is evaluated automatically while rendering
259
+ * the table.
260
+ *
261
+ * Only applicable for tree and gantt views.
262
+ */
87
263
  parent?: number;
88
264
  /**
89
- * When a table is being viewed as a Gantt chart, this colour would be applied to the row's gantt bar, if one exists.
265
+ * The options to use when rendering the row as a Gantt table.
90
266
  */
91
- gantt_color?: string;
267
+ gantt?: GanttOptions;
268
+ }
269
+ /**
270
+ * This interface defines the options for a row when it is being viewed as a Gantt chart.
271
+ * @public
272
+ */
273
+ export interface GanttOptions {
274
+ /**
275
+ * The colour to be applied to the row's gantt bar.
276
+ */
277
+ color?: string;
278
+ /**
279
+ * The starting column index for the gantt bar.
280
+ */
281
+ startIndex?: number;
282
+ /**
283
+ * The ending column index for the gantt bar. If the endIndex and colspan are not provided,
284
+ * the bar will stretch to the end of the table.
285
+ */
286
+ endIndex?: number;
287
+ /**
288
+ * The length of the gantt bar. Useful when only the start index is provided. If the
289
+ * colspan and endIndex are not provided, the bar will stretch to the end of the table.
290
+ */
291
+ colspan?: number;
292
+ }
293
+ /**
294
+ * Gantt table drag event definition.
295
+ * @public
296
+ */
297
+ export type GanttDragEvent = {
298
+ rowIndex: number;
299
+ colIndex: number;
300
+ type: 'bar';
301
+ start: number;
302
+ end: number;
303
+ } | {
304
+ rowIndex: number;
305
+ colIndex: number;
306
+ type: 'resize';
307
+ edge: 'start' | 'end';
308
+ value: number;
92
309
  };
93
310
  /**
94
311
  * Table modal definition.
95
312
  * @public
96
313
  */
97
- export type TableModal = {
98
- bottom?: ReturnType<typeof useElementBounding>['bottom'];
314
+ export interface TableModal {
315
+ /**
316
+ * Indicates whether the table modal is currently visible.
317
+ *
318
+ * @defaultValue false
319
+ */
320
+ visible?: boolean;
321
+ /**
322
+ * The HTML cell element that the modal is currently being displayed for. The field is unset
323
+ * when the modal is not being displayed.
324
+ */
99
325
  cell?: HTMLTableCellElement | null;
100
- colIndex?: number;
101
- event?: string;
102
- height?: ReturnType<typeof useElementBounding>['height'];
103
- left?: ReturnType<typeof useElementBounding>['left'];
326
+ /**
327
+ * The HTML parent element that the modal is currently being displayed for. The field is unset
328
+ * when the modal is not being displayed.
329
+ */
104
330
  parent?: HTMLElement;
331
+ /**
332
+ * The index of the column that the modal is currently being displayed for. The field is
333
+ * unset when the modal is not being displayed.
334
+ */
335
+ colIndex?: number;
336
+ /**
337
+ * The index of the row that the modal is currently being displayed for. The field is
338
+ * unset when the modal is not being displayed.
339
+ */
105
340
  rowIndex?: number;
106
- visible?: boolean;
107
- width?: ReturnType<typeof useElementBounding>['width'];
341
+ /**
342
+ * The component to use to render the modal. If not provided, the table will
343
+ * try to use the column's `modalComponent` property, if set. If that is not set,
344
+ * the table will not display a modal.
345
+ *
346
+ * @see {@link TableColumn.modalComponent}
347
+ */
108
348
  component?: string;
349
+ /**
350
+ * Additional properties to pass to the table's modal component.
351
+ */
109
352
  componentProps?: Record<string, any>;
110
- };
353
+ /**
354
+ * Reactive bottom value for the modal's bounding box. The field is unset when the modal
355
+ * is not being displayed.
356
+ */
357
+ bottom?: ReturnType<typeof useElementBounding>['bottom'];
358
+ /**
359
+ * Reactive height value for the modal's bounding box. The field is unset when the modal
360
+ * is not being displayed.
361
+ */
362
+ height?: ReturnType<typeof useElementBounding>['height'];
363
+ /**
364
+ * Reactive left value for the modal's bounding box. The field is unset when the modal
365
+ * is not being displayed.
366
+ */
367
+ left?: ReturnType<typeof useElementBounding>['left'];
368
+ /**
369
+ * Reactive width value for the modal's bounding box. The field is unset when the modal
370
+ * is not being displayed.
371
+ */
372
+ width?: ReturnType<typeof useElementBounding>['width'];
373
+ }
111
374
  /**
112
375
  * Table modal component props definition.
113
376
  * @public
114
377
  */
115
- export type TableModalProps = {
378
+ export interface TableModalProps {
379
+ /**
380
+ * Additional arbitrary properties that can be passed to the modal component.
381
+ */
116
382
  [key: string]: any;
383
+ /**
384
+ * The index of the column that the modal is currently being displayed for.
385
+ */
117
386
  colIndex: number;
387
+ /**
388
+ * The index of the row that the modal is currently being displayed for.
389
+ */
118
390
  rowIndex: number;
391
+ /**
392
+ * The store for managing the current table's state.
393
+ */
119
394
  store: ReturnType<typeof createTableStore>;
120
- };
395
+ }
121
396
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IAEZ,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAGhB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,aAAa,CA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ACH,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;IAEpD;;;OAGG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAA;CACtD;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAElB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,KAAK,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA;CAC1C"}
@@ -92,7 +92,6 @@ export const createTableStore = (initData) => {
92
92
  });
93
93
  const isRowGantt = (rowIndex) => {
94
94
  const row = rows.value[rowIndex];
95
- console.log(config.value.view, row.indent);
96
95
  return config.value.view === 'gantt' && row.indent === 0;
97
96
  };
98
97
  const isRowVisible = (rowIndex) => {
@@ -165,6 +164,24 @@ export const createTableStore = (initData) => {
165
164
  return 'inherit';
166
165
  }
167
166
  };
167
+ const updateGanttBar = (event) => {
168
+ // update the local gantt bar cache
169
+ const ganttBar = rows.value[event.rowIndex]?.gantt;
170
+ if (ganttBar) {
171
+ if (event.type === 'resize') {
172
+ if (event.edge === 'start') {
173
+ ganttBar.startIndex = event.value;
174
+ }
175
+ else if (event.edge === 'end') {
176
+ ganttBar.endIndex = event.value;
177
+ }
178
+ }
179
+ else if (event.type === 'bar') {
180
+ ganttBar.startIndex = event.start;
181
+ ganttBar.endIndex = event.end;
182
+ }
183
+ }
184
+ };
168
185
  return {
169
186
  // state
170
187
  columns,
@@ -191,6 +208,7 @@ export const createTableStore = (initData) => {
191
208
  setCellData,
192
209
  setCellText,
193
210
  toggleRowExpand,
211
+ updateGanttBar,
194
212
  };
195
213
  });
196
214
  return createStore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/atable",
3
- "version": "0.4.12",
3
+ "version": "0.4.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -38,8 +38,8 @@
38
38
  "@vueuse/core": "^12.7.0",
39
39
  "pinia": "^3.0.1",
40
40
  "vue": "^3.5.13",
41
- "@stonecrop/themes": "0.4.12",
42
- "@stonecrop/utilities": "0.4.12"
41
+ "@stonecrop/themes": "0.4.13",
42
+ "@stonecrop/utilities": "0.4.13"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-documenter": "^7.26.10",
@@ -26,16 +26,26 @@
26
26
  </template>
27
27
 
28
28
  <script setup lang="ts">
29
- import { ref, computed, onMounted, useTemplateRef } from 'vue'
30
29
  import { useDraggable, useElementBounding } from '@vueuse/core'
30
+ import { ref, computed, onMounted, useTemplateRef } from 'vue'
31
+
32
+ import { createTableStore } from '../stores/table'
31
33
 
32
34
  const {
35
+ store,
36
+ columnsCount,
37
+ rowIndex,
38
+ colIndex,
33
39
  start,
34
40
  end,
35
41
  colspan = 1,
36
42
  label,
37
43
  color,
38
44
  } = defineProps<{
45
+ store: ReturnType<typeof createTableStore>
46
+ columnsCount: number
47
+ rowIndex: number
48
+ colIndex: number
39
49
  start?: number
40
50
  end?: number
41
51
  colspan?: number
@@ -53,12 +63,6 @@ onMounted(() => {
53
63
  }
54
64
  })
55
65
 
56
- const emit = defineEmits<{
57
- 'update:start': [value: number]
58
- 'update:end': [value: number]
59
- drag: [{ type: 'bar'; start: number; end: number } | { type: 'resize'; edge: 'start' | 'end'; value: number }]
60
- }>()
61
-
62
66
  const containerRef = useTemplateRef('container')
63
67
  const barRef = useTemplateRef('bar')
64
68
  const leftHandleRef = useTemplateRef('leftHandle')
@@ -67,7 +71,7 @@ const rightHandleRef = useTemplateRef('rightHandle')
67
71
  const { width: totalBarWidth } = useElementBounding(containerRef)
68
72
  const { left: barLeft, right: barRight } = useElementBounding(barRef)
69
73
  const currentStart = ref(start || 0)
70
- const currentEnd = ref(end || colspan)
74
+ const currentEnd = ref(end || currentStart.value + colspan)
71
75
  const dragStartData = ref({ startX: 0, startPos: 0 })
72
76
 
73
77
  const pixelsPerColumn = computed(() => (colspan > 0 ? totalBarWidth.value / colspan : 0))
@@ -108,8 +112,7 @@ const { isDragging: isLeftDragging } = useDraggable(leftHandleRef, {
108
112
  const newStart = Math.max(0, Math.min(currentEnd.value - 1, dragStartData.value.startPos + deltaColumns))
109
113
  currentStart.value = newStart
110
114
 
111
- emit('update:start', newStart)
112
- emit('drag', { type: 'resize', edge: 'start', value: newStart })
115
+ store.updateGanttBar({ rowIndex, colIndex, type: 'resize', edge: 'start', value: newStart })
113
116
  }
114
117
  },
115
118
  })
@@ -127,7 +130,10 @@ const { isDragging: isRightDragging } = useDraggable(rightHandleRef, {
127
130
  if (isRightDragging.value && barRef.value) {
128
131
  const deltaX = x - dragStartData.value.startX
129
132
  const deltaColumns = deltaX / pixelsPerColumn.value
130
- const newEnd = Math.max(currentStart.value + 1, Math.min(colspan, dragStartData.value.startPos + deltaColumns))
133
+ const newEnd = Math.max(
134
+ currentStart.value + 1,
135
+ Math.min(columnsCount, dragStartData.value.startPos + deltaColumns)
136
+ )
131
137
  barRef.value.style.width = `${((newEnd - currentStart.value) / colspan) * 100}%`
132
138
  }
133
139
  },
@@ -135,11 +141,13 @@ const { isDragging: isRightDragging } = useDraggable(rightHandleRef, {
135
141
  if (barRef.value) {
136
142
  const deltaX = x - dragStartData.value.startX
137
143
  const deltaColumns = Math.round(deltaX / pixelsPerColumn.value)
138
- const newEnd = Math.max(currentStart.value + 1, Math.min(colspan, dragStartData.value.startPos + deltaColumns))
144
+ const newEnd = Math.max(
145
+ currentStart.value + 1,
146
+ Math.min(columnsCount, dragStartData.value.startPos + deltaColumns)
147
+ )
139
148
  currentEnd.value = newEnd
140
149
 
141
- emit('update:end', newEnd)
142
- emit('drag', { type: 'resize', edge: 'end', value: newEnd })
150
+ store.updateGanttBar({ rowIndex, colIndex, type: 'resize', edge: 'end', value: newEnd })
143
151
  }
144
152
  },
145
153
  })
@@ -159,7 +167,7 @@ const { isDragging: isBarDragging } = useDraggable(barRef, {
159
167
  const deltaX = x - dragStartData.value.startX
160
168
  const deltaColumns = deltaX / pixelsPerColumn.value
161
169
  const barWidth = currentEnd.value - currentStart.value
162
- const newStart = Math.max(0, Math.min(dragStartData.value.startPos + deltaColumns, colspan - barWidth))
170
+ const newStart = Math.max(0, Math.min(dragStartData.value.startPos + deltaColumns, columnsCount - barWidth))
163
171
  barRef.value.style.left = `${(newStart / colspan) * 100}%`
164
172
  }
165
173
  },
@@ -174,17 +182,15 @@ const { isDragging: isBarDragging } = useDraggable(barRef, {
174
182
  if (newStart < 0) {
175
183
  newStart = 0
176
184
  newEnd = barWidth
177
- } else if (newEnd > colspan) {
178
- newEnd = colspan
185
+ } else if (newEnd > columnsCount) {
186
+ newEnd = columnsCount
179
187
  newStart = newEnd - barWidth
180
188
  }
181
189
 
182
190
  currentStart.value = newStart
183
191
  currentEnd.value = newEnd
184
192
 
185
- emit('update:start', newStart)
186
- emit('update:end', newEnd)
187
- emit('drag', { type: 'bar', start: newStart, end: newEnd })
193
+ store.updateGanttBar({ rowIndex, colIndex, type: 'bar', start: newStart, end: newEnd })
188
194
  }
189
195
  },
190
196
  })