@dataloop-ai/components 0.19.105 → 0.19.107

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.19.105",
3
+ "version": "0.19.107",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -193,7 +193,7 @@ body {
193
193
  --dl-color-hover: #7b8cff;
194
194
  --dl-color-disabled: #b3b3b3;
195
195
  --dl-color-fill: #00000005;
196
- --dl-color-fill-hover: #00000010;
196
+ --dl-color-fill-hover: #f8f8f8;
197
197
  --dl-color-separator: #e4e4e4;
198
198
  --dl-color-scrollbar: #e4e4e4;
199
199
  --dl-color-body-background: #eef1ff;
@@ -254,7 +254,7 @@ body {
254
254
  --dl-color-disabled: #ffffff40;
255
255
  --dl-color-fill: #ffffff05;
256
256
  --dl-color-fill-secondary: #f8f8f81a;
257
- --dl-color-fill-hover: #ffffff10;
257
+ --dl-color-fill-hover: #454a50;
258
258
  --dl-color-separator: #ffffff26;
259
259
  --dl-color-body-background: #24282d;
260
260
  --dl-color-panel-background: #30363d;
@@ -124,7 +124,9 @@ import {
124
124
  replaceJSDatesWithStringifiedDates,
125
125
  replaceStringifiedDatesWithJSDates,
126
126
  setAliases,
127
- revertAliases
127
+ revertAliases,
128
+ setValueAliases,
129
+ revertValueAliases
128
130
  } from '../utils'
129
131
  import { v4 } from 'uuid'
130
132
  import {
@@ -569,7 +571,9 @@ export default defineComponent({
569
571
  const replacedDate = replaceStringifiedDatesWithJSDates(value)
570
572
  const json = parseSmartQuery(replacedDate ?? searchQuery.value)
571
573
 
572
- return isValidJSON(json) ? json : searchQuery.value
574
+ return isValidJSON(json)
575
+ ? revertValueAliases(json, schema.value)
576
+ : searchQuery.value
573
577
  }
574
578
 
575
579
  const fromJSON = (value: { [key: string]: any }) => {
@@ -579,7 +583,9 @@ export default defineComponent({
579
583
  dateKeys.value
580
584
  )
581
585
 
582
- const stringQuery = stringifySmartQuery(replacedDate)
586
+ const stringQuery = stringifySmartQuery(
587
+ setValueAliases(replacedDate, schema.value)
588
+ )
583
589
  const aliased = setAliases(stringQuery, aliases.value)
584
590
  return aliased
585
591
  } catch (e) {
@@ -5,6 +5,7 @@ import { ColorSchema, SyntaxColorSchema, Filters } from '../types'
5
5
  import {
6
6
  operators,
7
7
  Alias,
8
+ Data,
8
9
  datePattern,
9
10
  datePatternNoBrackets,
10
11
  removeBrackets
@@ -187,6 +188,62 @@ export function setAliases(str: string, aliases: Alias[]) {
187
188
  return str.replace(regex, replacement)
188
189
  }
189
190
 
191
+ function valueAliases(schema: Data, field: string) {
192
+ let aliases: Data = {}
193
+ const type: any = schema[field]
194
+ if (Array.isArray(type)) {
195
+ for (const element of type) {
196
+ if (typeof element === 'object')
197
+ aliases = Object.assign(aliases, element)
198
+ }
199
+ } else {
200
+ if (typeof type === 'object') aliases = Object.assign(aliases, type)
201
+ }
202
+ return aliases
203
+ }
204
+
205
+ export function revertValueAliases(json: Data, schema: Data) {
206
+ const clone = cloneDeep(json)
207
+ const replaceAliases = (where: Data) => {
208
+ for (const key in where) {
209
+ if (typeof where[key] === 'object') {
210
+ replaceAliases(where[key])
211
+ } else {
212
+ const aliases = valueAliases(schema, key)
213
+ const value = aliases[where[key] as string]
214
+ if (value) {
215
+ where[key] = value
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ replaceAliases(clone)
222
+ return clone
223
+ }
224
+
225
+ export function setValueAliases(json: Data, schema: Data) {
226
+ const clone = cloneDeep(json)
227
+ const replaceValues = (where: Data) => {
228
+ for (const key in where) {
229
+ if (typeof where[key] === 'object') {
230
+ replaceValues(where[key])
231
+ } else {
232
+ const aliases = valueAliases(schema, key)
233
+ for (const alias in aliases) {
234
+ if (where[key] === aliases[alias]) {
235
+ where[key] = alias
236
+ break
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ replaceValues(clone)
244
+ return clone
245
+ }
246
+
190
247
  export function createColorSchema(
191
248
  colorSchema: ColorSchema,
192
249
  aliases: Alias[]
@@ -141,14 +141,16 @@
141
141
  @click="onThClick($event, col.name)"
142
142
  >
143
143
  <span
144
- class="inner-th"
144
+ :class="`inner-th ${`inner-th--${col.align}`}`"
145
145
  :style="
146
146
  col.width && {
147
147
  maxWidth: 'calc(100% - 15px)'
148
148
  }
149
149
  "
150
150
  >
151
- {{ col.label }}
151
+ <dl-ellipsis>
152
+ {{ col.label }}
153
+ </dl-ellipsis>
152
154
  </span>
153
155
  </DlTh>
154
156
  </slot>
@@ -157,6 +159,7 @@
157
159
  key="visibleColumnsSlot"
158
160
  :col-index="-1"
159
161
  no-tooltip
162
+ padding="0"
160
163
  >
161
164
  <slot
162
165
  name="header-cell-visible-columns-button"
@@ -179,8 +182,8 @@
179
182
  flat
180
183
  icon="icon-dl-column"
181
184
  tooltip="Manage columns"
182
- :disabled="isDataEmpty"
183
185
  padding="0"
186
+ :disabled="isDataEmpty"
184
187
  >
185
188
  <slot
186
189
  name="header-cell-visible-columns-menu"
@@ -531,14 +534,16 @@
531
534
  @click="onThClick($event, col.name)"
532
535
  >
533
536
  <span
534
- class="inner-th"
537
+ :class="`inner-th ${`inner-th--${col.align}`}`"
535
538
  :style="
536
539
  col.width && {
537
540
  maxWidth: 'calc(100% - 15px)'
538
541
  }
539
542
  "
540
543
  >
541
- {{ col.label }}
544
+ <dl-ellipsis>
545
+ {{ col.label }}
546
+ </dl-ellipsis>
542
547
  </span>
543
548
  </DlTh>
544
549
  </slot>
@@ -957,9 +962,20 @@ import {
957
962
  import { useTableActions, useTableActionsProps } from './hooks/tableActions'
958
963
  import { applyDraggableColumns, applyResizableColumns } from '../../../utils'
959
964
  import { injectProp } from '../../../utils/inject-object-prop'
960
- import { DlTableRow, DlTableProps, DlTableColumn } from './types'
965
+ import {
966
+ DlTableRow,
967
+ DlTableProps,
968
+ DlTableColumn,
969
+ TableStickyPosition
970
+ } from './types'
961
971
  import { DlPagination } from '../DlPagination'
962
- import { DlIcon, DlCheckbox, DlProgressBar, DlList } from '../../essential'
972
+ import {
973
+ DlIcon,
974
+ DlCheckbox,
975
+ DlProgressBar,
976
+ DlList,
977
+ DlEllipsis
978
+ } from '../../essential'
963
979
  import { DlButton, DlPopup } from '../../basic'
964
980
  import DlOptionGroup from '../DlOptionGroup/DlOptionGroup.vue'
965
981
  import DlEmptyState from '../../basic/DlEmptyState/DlEmptyState.vue'
@@ -994,7 +1010,8 @@ export default defineComponent({
994
1010
  DlOptionGroup,
995
1011
  DlPopup,
996
1012
  DlList,
997
- Sortable
1013
+ Sortable,
1014
+ DlEllipsis
998
1015
  },
999
1016
  props: {
1000
1017
  /**
@@ -1214,7 +1231,7 @@ export default defineComponent({
1214
1231
  },
1215
1232
  fitAllColumns: {
1216
1233
  type: Boolean,
1217
- default: true
1234
+ default: false
1218
1235
  },
1219
1236
  expandableRows: {
1220
1237
  type: Boolean,
@@ -1224,6 +1241,12 @@ export default defineComponent({
1224
1241
  type: String,
1225
1242
  default: 'No data'
1226
1243
  },
1244
+ stickyColumns: {
1245
+ type: Object as PropType<TableStickyPosition>,
1246
+ default: null,
1247
+ validator: (value: string) =>
1248
+ ['first', 'last', 'both'].includes(value)
1249
+ },
1227
1250
  ...useTableActionsProps,
1228
1251
  ...commonVirtScrollProps,
1229
1252
  ...useTableRowExpandProps,
@@ -1396,7 +1419,12 @@ export default defineComponent({
1396
1419
  (document.querySelector('table.dl-table') as HTMLTableElement)
1397
1420
 
1398
1421
  nextTick(() => {
1399
- setAllColumnWidths(tableEl, columns.value as DlTableColumn[])
1422
+ setAllColumnWidths(
1423
+ tableEl,
1424
+ columns.value as DlTableColumn[],
1425
+ props.stickyColumns,
1426
+ props.fitAllColumns
1427
+ )
1400
1428
  })
1401
1429
  if (visibleColumns.value) return
1402
1430
  if (resizable.value) {
@@ -1424,7 +1452,9 @@ export default defineComponent({
1424
1452
  nextTick(() => {
1425
1453
  setAllColumnWidths(
1426
1454
  tableEl,
1427
- props.columns as DlTableColumn[]
1455
+ props.columns as DlTableColumn[],
1456
+ props.stickyColumns,
1457
+ props.fitAllColumns
1428
1458
  )
1429
1459
  })
1430
1460
  if (visibleColumns.value) return
@@ -1462,7 +1492,9 @@ export default defineComponent({
1462
1492
  nextTick(() => {
1463
1493
  setAllColumnWidths(
1464
1494
  tableRef.value,
1465
- newColumns as DlTableColumn[]
1495
+ newColumns as DlTableColumn[],
1496
+ props.stickyColumns,
1497
+ props.fitAllColumns
1466
1498
  )
1467
1499
  })
1468
1500
  },
@@ -8,26 +8,9 @@
8
8
  @mouseenter="iconHover = true"
9
9
  @mouseleave="iconHover = false"
10
10
  >
11
- <dl-icon
12
- v-if="isSortable && align === 'right'"
13
- :class="iconClass"
14
- :icon="computedSortIcon"
15
- :style="
16
- !isCurrentlySorted && !iconHover
17
- ? 'display: none !important;'
18
- : ''
19
- "
20
- />
21
- <dl-tooltip v-if="hasEllipsis">
22
- <slot />
23
- </dl-tooltip>
24
- <slot />
25
- <span
26
- class="th-icons"
27
- :style="{ top: isDense ? '5px' : '12px' }"
28
- >
11
+ <div class="inner-th-wrapper">
29
12
  <dl-icon
30
- v-if="isSortable && ['left', 'center'].includes(align)"
13
+ v-if="isSortable && align === 'right'"
31
14
  :class="iconClass"
32
15
  :icon="computedSortIcon"
33
16
  :style="
@@ -36,17 +19,34 @@
36
19
  : ''
37
20
  "
38
21
  />
39
- <dl-icon
40
- v-if="hasHint"
41
- icon="icon-dl-info"
42
- size="10px"
43
- style="max-width: 30%"
44
- >
45
- <dl-tooltip>
46
- {{ props.col.hint }}
47
- </dl-tooltip>
48
- </dl-icon>
49
- </span>
22
+ <dl-tooltip v-if="hasEllipsis">
23
+ <slot />
24
+ </dl-tooltip>
25
+ <slot />
26
+ <span class="th-icons">
27
+ <dl-icon
28
+ v-if="hasHint"
29
+ icon="icon-dl-info"
30
+ size="10px"
31
+ style="max-width: 30%; margin-top: 1px"
32
+ >
33
+ <dl-tooltip>
34
+ {{ props.col.hint }}
35
+ </dl-tooltip>
36
+ </dl-icon>
37
+ <dl-icon
38
+ v-if="isSortable && ['left', 'center'].includes(align)"
39
+ :class="iconClass"
40
+ :icon="computedSortIcon"
41
+ size="16px"
42
+ :style="
43
+ !isCurrentlySorted && !iconHover
44
+ ? 'opacity: 0 !important;'
45
+ : ''
46
+ "
47
+ />
48
+ </span>
49
+ </div>
50
50
  </th>
51
51
  </template>
52
52
 
@@ -8,16 +8,40 @@
8
8
  border-right: 1px solid var(--dl-color-separator);
9
9
  }
10
10
 
11
+ .sticky-col {
12
+ position: sticky;
13
+ background-color: var(--dl-color-panel-background);
14
+ z-index: 50;
15
+ }
16
+
17
+ .inner-th-wrapper {
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: space-between;
21
+ gap: 6px;
22
+ height: 34px;
23
+ position: relative;
24
+ }
11
25
  .inner-th {
12
26
  display: inline-block;
27
+ flex: 0 1 auto;
28
+ position: absolute;
29
+ left: 50%;
30
+ transform: translateX(-50%);
13
31
  overflow: hidden;
14
- margin-right: 5px;
15
32
  position: relative;
33
+ line-height: 34px;
34
+ &--left {
35
+ left: 0;
36
+ transform: none;
37
+ }
16
38
  }
17
39
  .th-icons {
18
40
  display: flex;
19
- right: 0;
20
- position: absolute;
41
+ flex: 0 1 auto;
42
+ margin-left: auto;
43
+ align-items: center;
44
+ justify-content: flex-end;
21
45
  }
22
46
 
23
47
  .expanded-row {
@@ -76,11 +100,6 @@
76
100
  padding-left: 8px;
77
101
  }
78
102
 
79
- th:last-child,
80
- td:last-child {
81
- padding-right: 8px;
82
- }
83
-
84
103
  thead tr {
85
104
  height: 34px;
86
105
  }
@@ -92,7 +111,6 @@
92
111
  .dl-table__drag-icon > div {
93
112
  opacity: 1;
94
113
  }
95
-
96
114
  td:not(.dl-td--no-hover) {
97
115
  background-color: var(--dl-color-fill-hover);
98
116
  }
@@ -425,8 +443,8 @@
425
443
 
426
444
  .dl-table {
427
445
  th {
428
- font-size: 12px;
429
- line-height: 12px;
446
+ font-size: 14px;
447
+ line-height: 14px;
430
448
  }
431
449
 
432
450
  thead tr {
@@ -1,5 +1,7 @@
1
1
  import { DlTextTransformOptions } from '../../shared/types'
2
2
 
3
+ export type TableStickyPosition = 'first' | 'last' | 'both' | ''
4
+
3
5
  export interface SortingMovement {
4
6
  lastId: string
5
7
  direction: 'up' | 'down'
@@ -41,6 +43,7 @@ export type DlTableColumn = {
41
43
  textTransform?: DlTextTransformOptions
42
44
  width?: number
43
45
  hint?: string
46
+ sticky?: boolean
44
47
  }
45
48
 
46
49
  export type DlTableFilterMethod = (
@@ -117,6 +117,63 @@
117
117
  @col-update="updateColumns"
118
118
  @row-reorder="reorderRows"
119
119
  />
120
+ <div style="margin-top: 100px">
121
+ Fit table columns
122
+ <DlTable
123
+ :selected="selected"
124
+ :separator="separator"
125
+ :columns="tableColumns"
126
+ fit-all-columns
127
+ :bordered="bordered"
128
+ :draggable="draggable"
129
+ :dense="dense"
130
+ class="sticky-header"
131
+ :filter="filter"
132
+ :selection="selection"
133
+ :loading="loading"
134
+ :rows="tableRows"
135
+ :resizable="resizable"
136
+ row-key="name"
137
+ color="dl-color-secondary"
138
+ title="Table Title"
139
+ :virtual-scroll="vScroll"
140
+ style="height: 500px"
141
+ :rows-per-page-options="rowsPerPageOptions"
142
+ @row-click="log"
143
+ @th-click="log"
144
+ @update:selected="updateSeleted"
145
+ @col-update="updateColumns"
146
+ @row-reorder="reorderRows"
147
+ />
148
+
149
+ ALot of columns and fit
150
+ <DlTable
151
+ :selected="selected"
152
+ :separator="separator"
153
+ :columns="[...tableColumns, ...tableColumns]"
154
+ fit-all-columns
155
+ :bordered="bordered"
156
+ :draggable="draggable"
157
+ :dense="dense"
158
+ class="sticky-header"
159
+ :filter="filter"
160
+ :selection="selection"
161
+ :loading="loading"
162
+ :rows="tableRows"
163
+ :resizable="resizable"
164
+ row-key="name"
165
+ color="dl-color-secondary"
166
+ title="Table Title"
167
+ :virtual-scroll="vScroll"
168
+ style="height: 500px"
169
+ :rows-per-page-options="rowsPerPageOptions"
170
+ @row-click="log"
171
+ @th-click="log"
172
+ @update:selected="updateSeleted"
173
+ @col-update="updateColumns"
174
+ @row-reorder="reorderRows"
175
+ />
176
+ </div>
120
177
 
121
178
  <div style="margin-top: 100px">
122
179
  Custom Slot row-body
@@ -198,6 +255,33 @@
198
255
  </DlTable>
199
256
  </div>
200
257
 
258
+ <div style="margin-top: 100px">
259
+ With sticky columns: both
260
+ <DlTable
261
+ :columns="[...tableColumns, ...tableColumns]"
262
+ sticky-columns="both"
263
+ :rows="tableRows"
264
+ row-key="id"
265
+ style="height: 300px"
266
+ />
267
+ With sticky columns: first
268
+ <DlTable
269
+ :columns="[...tableColumns, ...tableColumns]"
270
+ sticky-columns="first"
271
+ :rows="tableRows"
272
+ row-key="id"
273
+ style="height: 300px"
274
+ />
275
+ With sticky columns: last
276
+ <DlTable
277
+ :columns="[...tableColumns, ...tableColumns]"
278
+ sticky-columns="last"
279
+ :rows="tableRows"
280
+ row-key="id"
281
+ style="height: 300px"
282
+ />
283
+ </div>
284
+
201
285
  <div style="margin-top: 100px">
202
286
  Loading WIth custom row
203
287
  <DlTable
@@ -541,6 +625,7 @@
541
625
  :rows="tableRows"
542
626
  row-key="id"
543
627
  style="height: 500px"
628
+ sticky-columns="last"
544
629
  :rows-per-page-options="rowsPerPageOptions"
545
630
  @row-click="log"
546
631
  @th-click="log"
@@ -625,7 +710,7 @@ const columns = [
625
710
  label: 'Calories',
626
711
  field: 'calories',
627
712
  sortable: true,
628
- width: 100
713
+ width: '50px'
629
714
  },
630
715
  {
631
716
  name: 'fat',
@@ -1044,7 +1129,6 @@ export default defineComponent({
1044
1129
  }
1045
1130
 
1046
1131
  const updateColumns = (newColumns: any) => {
1047
- console.log(newColumns)
1048
1132
  tableColumns.value = newColumns
1049
1133
  }
1050
1134
 
@@ -140,6 +140,13 @@ export default defineComponent({
140
140
  test2: ['true', 'false']
141
141
  }
142
142
  const schema2: any = {
143
+ value: [
144
+ 'string',
145
+ {
146
+ John: 'AB34',
147
+ Connor: '42'
148
+ }
149
+ ],
143
150
  type: [
144
151
  'class',
145
152
  'point',
@@ -3,12 +3,16 @@ import { splitByQuotes } from '../utils/splitByQuotes'
3
3
  import { flatten } from 'flat'
4
4
  import { isObject } from 'lodash'
5
5
 
6
+ export type Data = {
7
+ [key: string]: any
8
+ }
9
+
6
10
  export type Schema = {
7
11
  [key: string]:
8
12
  | string
9
13
  | number
10
14
  | boolean
11
- | (number | boolean | string)[]
15
+ | (number | boolean | string | Data)[]
12
16
  | Schema
13
17
  }
14
18
 
@@ -245,8 +249,10 @@ export const useSuggestions = (
245
249
 
246
250
  if (Array.isArray(dataType)) {
247
251
  localSuggestions = dataType.filter(
248
- (type) => !knownDataTypes.includes(type)
249
- )
252
+ (type) =>
253
+ typeof type === 'string' &&
254
+ !knownDataTypes.includes(type)
255
+ ) as string[]
250
256
 
251
257
  if (!value) continue
252
258
 
@@ -402,7 +408,7 @@ const getError = (
402
408
 
403
409
  const isValidByDataType = (
404
410
  str: string | string[],
405
- dataType: string | string[],
411
+ dataType: string | (string | Data)[],
406
412
  operator: string
407
413
  ): boolean => {
408
414
  if (dataType === 'any') {
@@ -423,9 +429,16 @@ const isValidByDataType = (
423
429
  */
424
430
 
425
431
  if (Array.isArray(dataType)) {
426
- let isOneOf = !!getValueMatch(dataType, str)
432
+ let isOneOf = !!getValueMatch(
433
+ dataType.filter((type) => typeof type !== 'object') as string[],
434
+ str
435
+ )
427
436
  for (const type of dataType) {
428
- isOneOf = isOneOf || isValidByDataType(str, type, operator)
437
+ if (typeof type === 'object') {
438
+ isOneOf = isOneOf || !!getValueMatch(Object.keys(type), str)
439
+ } else {
440
+ isOneOf = isOneOf || isValidByDataType(str, type, operator)
441
+ }
429
442
  }
430
443
  return isOneOf
431
444
  }
@@ -507,7 +520,7 @@ const getDataType = (
507
520
  schema: Schema,
508
521
  aliases: Alias[],
509
522
  key: string
510
- ): string | string[] | null => {
523
+ ): string | (string | Data)[] | null => {
511
524
  const aliasedKey = getAliasObjByAlias(aliases, key)?.key ?? key
512
525
 
513
526
  const nestedKey = aliasedKey.split('.').filter((el) => el)
@@ -529,7 +542,7 @@ const getDataType = (
529
542
  return 'object'
530
543
  }
531
544
 
532
- return value as unknown as string | string[] | null
545
+ return value as unknown as string | (string | Data)[] | null
533
546
  }
534
547
 
535
548
  const getAliasObjByAlias = (aliases: Alias[], alias: string): Alias | null => {
@@ -666,13 +679,22 @@ export const removeLeadingExpression = (str: string) => {
666
679
  return str.match(/\s+(.*)$/)?.[1] || ''
667
680
  }
668
681
 
669
- const getValueSuggestions = (dataType: string | string[], operator: string) => {
670
- const types: string[] = Array.isArray(dataType) ? dataType : [dataType]
682
+ const getValueSuggestions = (
683
+ dataType: string | (string | Data)[],
684
+ operator: string
685
+ ) => {
686
+ const types: (string | Data)[] = Array.isArray(dataType)
687
+ ? dataType
688
+ : [dataType]
671
689
  const suggestion: string[] = []
672
690
 
673
691
  if (Array.isArray(dataType)) {
674
692
  suggestion.push(
675
- ...dataType.filter((type) => !knownDataTypes.includes(type))
693
+ ...(dataType.filter(
694
+ (type) =>
695
+ !knownDataTypes.includes(type as string) &&
696
+ typeof type !== 'object'
697
+ ) as string[])
676
698
  )
677
699
  }
678
700
 
@@ -688,7 +710,10 @@ const getValueSuggestions = (dataType: string | string[], operator: string) => {
688
710
  case 'datetime':
689
711
  suggestion.push(dateSuggestionPattern)
690
712
  default:
691
- // do nothing
713
+ if (typeof type === 'object') {
714
+ // value aliases: key is the alias, value is the actual value
715
+ for (const key in type) suggestion.push(key)
716
+ }
692
717
  break
693
718
  }
694
719
  }
@@ -1,5 +1,5 @@
1
1
  import { cloneDeep } from 'lodash'
2
- import { DlTableColumn } from '../types'
2
+ import { DlTableColumn, TableStickyPosition } from '../types'
3
3
  import { browseNestedNodes } from './browse-nested-nodes'
4
4
  import { swapNodes } from './swap-nodes'
5
5
 
@@ -121,9 +121,24 @@ function getIconWidth(el: HTMLElement) {
121
121
  return iconEl?.scrollWidth
122
122
  }
123
123
 
124
+ function addStickyPosition(
125
+ element: HTMLElement,
126
+ position: TableStickyPosition,
127
+ index: number,
128
+ totalElements: number
129
+ ) {
130
+ if (position === 'both')
131
+ position =
132
+ index === 0 ? 'first' : index === totalElements - 1 ? 'last' : ''
133
+ element.style.left = position === 'first' ? '0' : ''
134
+ element.style.right = position === 'last' ? '0' : ''
135
+ }
136
+
124
137
  export function setAllColumnWidths(
125
138
  table: HTMLElement,
126
- columns: DlTableColumn[]
139
+ columns: DlTableColumn[],
140
+ stickyColumns: TableStickyPosition,
141
+ fitAllColumns: boolean
127
142
  ) {
128
143
  const hasWidth = columns.some((col) => col.hasOwnProperty('width'))
129
144
  if (!hasWidth) return
@@ -135,12 +150,37 @@ export function setAllColumnWidths(
135
150
  (el.tagName === 'TH' || el.tagName === 'TD') &&
136
151
  parseInt(el.dataset.colIndex) === i,
137
152
  (targetEl) => {
138
- const width =
139
- (col.width ?? targetEl.scrollWidth) +
140
- getIconWidth(targetEl) +
141
- 15
142
- targetEl.style.width = `${width}px`
143
- // then
153
+ if (!fitAllColumns && targetEl.tagName === 'TH') {
154
+ // Calculate the width for the column
155
+ const width =
156
+ (col.width ??
157
+ targetEl.querySelector('.inner-th').scrollWidth) +
158
+ getIconWidth(targetEl) +
159
+ 35
160
+
161
+ // Set the width of the column
162
+ targetEl.style.width =
163
+ typeof col.width === 'number' || !col.width
164
+ ? `${width}px`
165
+ : col.width
166
+ } else if (targetEl.tagName === 'TH') {
167
+ // Adjust the maximum width for TH elements
168
+ const innerTh = targetEl.querySelector(
169
+ '.inner-th'
170
+ ) as HTMLElement
171
+ innerTh.style.maxWidth = '80%'
172
+ }
173
+
174
+ if (stickyColumns && (i === 0 || i === columns.length - 1)) {
175
+ // Add sticky column class and position for sticky columns
176
+ targetEl.classList.add('sticky-col')
177
+ addStickyPosition(
178
+ targetEl,
179
+ stickyColumns,
180
+ i,
181
+ columns.length
182
+ )
183
+ }
144
184
  }
145
185
  )
146
186
  })