@dataloop-ai/components 0.19.65 → 0.19.66

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.65",
3
+ "version": "0.19.66",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -332,7 +332,7 @@
332
332
  </template>
333
333
 
334
334
  <script lang="ts">
335
- import { debounce, cloneDeep } from 'lodash'
335
+ import { debounce as debounceFunc, cloneDeep } from 'lodash'
336
336
  import {
337
337
  computed,
338
338
  defineComponent,
@@ -393,7 +393,7 @@ export default defineComponent({
393
393
  */
394
394
  modelValue: {
395
395
  type: [String, Number],
396
- default: null
396
+ default: null as string
397
397
  },
398
398
  /**
399
399
  * An array of InputFile objects contained and modeled in the input
@@ -633,6 +633,20 @@ export default defineComponent({
633
633
  debounce: {
634
634
  type: Number,
635
635
  default: 100
636
+ },
637
+ /**
638
+ * Auto trim input value after debounce time
639
+ */
640
+ autoTrim: {
641
+ type: Boolean,
642
+ default: false
643
+ },
644
+ /**
645
+ * Debounce time for input
646
+ */
647
+ trimDebounce: {
648
+ type: Number,
649
+ default: 500
636
650
  }
637
651
  },
638
652
  emits: [
@@ -657,7 +671,10 @@ export default defineComponent({
657
671
  syntaxHighlightColor,
658
672
  placeholder,
659
673
  readonly,
660
- disabled
674
+ disabled,
675
+ autoTrim,
676
+ debounce,
677
+ trimDebounce
661
678
  } = toRefs(props)
662
679
 
663
680
  const isInternalChange = ref(false)
@@ -667,7 +684,7 @@ export default defineComponent({
667
684
  return getSuggestItems(
668
685
  autoSuggestItems.value,
669
686
  modelValue.value?.toString()
670
- )
687
+ ) as DlInputSuggestion[]
671
688
  })
672
689
  const input = ref(null)
673
690
 
@@ -678,13 +695,45 @@ export default defineComponent({
678
695
  onAutoSuggestClick(null, value)
679
696
  }
680
697
 
681
- const onChange = (e: KeyboardEvent) => {
698
+ const handleValueTrim = () => {
699
+ nextTick(() => {
700
+ const trimmed = String(modelValue.value).trim()
701
+ if (trimmed !== String(modelValue.value)) {
702
+ isInternalChange.value = true
703
+
704
+ input.value.innerHTML = trimmed
705
+ .toString()
706
+ .replace(/ /g, '&nbsp;')
707
+ updateSyntax()
708
+ setCaretAtTheEnd(input.value)
709
+
710
+ emit('input', trimmed)
711
+ emit('update:model-value', trimmed)
712
+ }
713
+ })
714
+ }
715
+
716
+ const debouncedHandleValueTrim = computed<Function>(() => {
717
+ if (stateManager.disableDebounce) {
718
+ return handleValueTrim.bind(this)
719
+ }
720
+ const debounced = debounceFunc(
721
+ handleValueTrim.bind(this),
722
+ trimDebounce.value ?? 50
723
+ )
724
+ return debounced
725
+ })
726
+
727
+ const onChange = (e: KeyboardEvent | Event) => {
682
728
  isInternalChange.value = true
683
729
  isMenuOpen.value = true
684
730
  updateSyntax()
685
731
  const target = e.target as HTMLElement
686
732
  emit('input', target.innerText, e)
687
733
  emit('update:model-value', target.innerText)
734
+ if (autoTrim.value) {
735
+ debouncedHandleValueTrim.value()
736
+ }
688
737
  }
689
738
 
690
739
  const onAutoSuggestClick = (e: Event, item: string): void => {
@@ -792,7 +841,9 @@ export default defineComponent({
792
841
  updateSyntax,
793
842
  stringSuggestions,
794
843
  showPlaceholder,
795
- spanText
844
+ spanText,
845
+ handleValueTrim,
846
+ debouncedHandleValueTrim
796
847
  }
797
848
  },
798
849
  data() {
@@ -938,7 +989,7 @@ export default defineComponent({
938
989
  if (stateManager.disableDebounce) {
939
990
  return this.onBlur.bind(this)
940
991
  }
941
- const debounced = debounce(
992
+ const debounced = debounceFunc(
942
993
  this.onBlur.bind(this),
943
994
  this.debounce ?? 50
944
995
  )
@@ -1035,6 +1086,7 @@ export default defineComponent({
1035
1086
  inputRef.focus()
1036
1087
  },
1037
1088
  onFocus(e: InputEvent): void {
1089
+ this.handleValueTrim()
1038
1090
  const el = e.target as HTMLElement
1039
1091
  if (this.modelValue) {
1040
1092
  el.scroll(el.scrollWidth, 0)
@@ -1051,6 +1103,7 @@ export default defineComponent({
1051
1103
  el.scroll(0, 0)
1052
1104
  this.focused = false
1053
1105
  this.$emit('blur', e)
1106
+ this.handleValueTrim()
1054
1107
  },
1055
1108
  onEnterPress(e: any): void {
1056
1109
  this.$emit('enter', e.target.innerText, e)
@@ -58,19 +58,19 @@
58
58
  <!-- Virtual scroll -->
59
59
  <DlVirtualScroll
60
60
  v-if="hasVirtScroll"
61
+ v-bind="virtProps"
61
62
  ref="virtScrollRef"
62
63
  type="__dltable"
63
- :class="tableClass"
64
+ :class="tableClass + additionalClasses"
64
65
  :style="tableStyle"
65
66
  :table-colspan="colspanWithActionsRow"
66
67
  :scroll-target="virtualScrollTarget"
67
68
  :items="computedRows"
68
69
  :scroll-debounce="scrollDebounce"
69
- v-bind="virtProps"
70
70
  @virtual-scroll="onVScroll"
71
71
  >
72
72
  <template #before>
73
- <thead>
73
+ <thead :colspan="columns.length">
74
74
  <slot
75
75
  v-if="!hideHeader"
76
76
  name="header"
@@ -81,14 +81,15 @@
81
81
  v-if="hasDraggableRows"
82
82
  class="dl-table--col-auto-with empty-col"
83
83
  :data-resizable="false"
84
- style="width: 25px; padding: 5px"
84
+ style="width: 25px"
85
85
  @mousedown="stopAndPrevent"
86
86
  />
87
87
  <th
88
88
  v-if="singleSelection"
89
- class="dl-table--col-auto-width"
89
+ class="dl-table--col-auto-with dl-table--col-checkbox-wrapper"
90
90
  @mousedown="stopAndPrevent"
91
91
  />
92
+
92
93
  <th
93
94
  v-else-if="multipleSelection"
94
95
  class="dl-table--col-auto-with dl-table--col-checkbox-wrapper"
@@ -102,9 +103,7 @@
102
103
  <DlCheckbox
103
104
  :color="color"
104
105
  :model-value="headerSelectedValue"
105
- :indeterminate-value="
106
- selectionCheckboxIndeterminateVal
107
- "
106
+ :indeterminate-value="true"
108
107
  @update:model-value="
109
108
  onMultipleSelectionSet
110
109
  "
@@ -120,14 +119,14 @@
120
119
 
121
120
  <th
122
121
  v-if="isTreeTable"
123
- class="dl-table--col-auto-with empty-col chevron-header"
122
+ class="dl-table--col-auto-with empty-col"
124
123
  :data-resizable="false"
125
- style="width: 25px"
124
+ style="width: 25px; padding: 5px"
126
125
  />
127
126
 
128
127
  <slot
129
128
  v-for="(col, colIndex) in computedCols"
130
- v-bind="getHeaderScope({ col })"
129
+ v-bind="getHeaderScope({ col, onThClick })"
131
130
  :name="
132
131
  hasSlotByName(`header-cell-${col.name}`)
133
132
  ? `header-cell-${col.name}`
@@ -139,13 +138,20 @@
139
138
  :props="getHeaderScope({ col })"
140
139
  :col-index="colIndex"
141
140
  :pagination="computedPagination"
141
+ @click="onThClick($event, col.name)"
142
142
  >
143
- <span class="inner-th">
143
+ <span
144
+ class="inner-th"
145
+ :style="
146
+ col.width && {
147
+ maxWidth: 'calc(100% - 15px)'
148
+ }
149
+ "
150
+ >
144
151
  {{ col.label }}
145
152
  </span>
146
153
  </DlTh>
147
154
  </slot>
148
-
149
155
  <DlTh
150
156
  v-if="showRowActions"
151
157
  key="visibleColumnsSlot"
@@ -517,7 +523,14 @@
517
523
  :pagination="computedPagination"
518
524
  @click="onThClick($event, col.name)"
519
525
  >
520
- <span class="inner-th">
526
+ <span
527
+ class="inner-th"
528
+ :style="
529
+ col.width && {
530
+ maxWidth: 'calc(100% - 15px)'
531
+ }
532
+ "
533
+ >
521
534
  {{ col.label }}
522
535
  </span>
523
536
  </DlTh>
@@ -1368,15 +1381,14 @@ export default defineComponent({
1368
1381
  onMounted(() => {
1369
1382
  tableEl =
1370
1383
  tableRef.value ||
1384
+ virtScrollRef.value.rootRef.querySelector('table') ||
1371
1385
  (document.querySelector('table.dl-table') as HTMLTableElement)
1386
+
1372
1387
  nextTick(() => {
1373
- setAllColumnWidths(
1374
- tableEl,
1375
- columns.value as DlTableColumn[],
1376
- fitAllColumns.value
1377
- )
1388
+ setAllColumnWidths(tableEl, columns.value as DlTableColumn[])
1378
1389
  })
1379
- if (resizable.value === true) {
1390
+ if (visibleColumns.value) return
1391
+ if (resizable.value) {
1380
1392
  applyResizableColumns(tableEl, vm)
1381
1393
  }
1382
1394
  if (hasDraggableColumns.value === true) {
@@ -1391,22 +1403,24 @@ export default defineComponent({
1391
1403
  watch(
1392
1404
  hasVirtScroll,
1393
1405
  () => {
1394
- tableEl = (rootRef.value as HTMLDivElement).querySelector(
1395
- 'table.dl-table'
1396
- ) as HTMLTableElement
1397
-
1398
- if (resizable.value) {
1399
- applyResizableColumns(tableEl, vm)
1400
- }
1406
+ tableEl =
1407
+ tableRef.value ||
1408
+ virtScrollRef.value.rootRef.querySelector('table') ||
1409
+ (document.querySelector(
1410
+ 'table.dl-table'
1411
+ ) as HTMLTableElement)
1401
1412
 
1402
1413
  nextTick(() => {
1403
1414
  setAllColumnWidths(
1404
- tableRef.value,
1405
- props.columns as DlTableColumn[],
1406
- props.fitAllColumns
1415
+ tableEl,
1416
+ props.columns as DlTableColumn[]
1407
1417
  )
1408
1418
  })
1419
+ if (visibleColumns.value) return
1409
1420
 
1421
+ if (resizable.value) {
1422
+ applyResizableColumns(tableEl, vm)
1423
+ }
1410
1424
  if (hasDraggableColumns.value === true) {
1411
1425
  applyDraggableColumns(
1412
1426
  tableEl,
@@ -1421,17 +1435,23 @@ export default defineComponent({
1421
1435
  )
1422
1436
 
1423
1437
  watch(resizable, () => {
1438
+ if (visibleColumns.value) return
1424
1439
  applyResizableColumns(tableEl, vm)
1425
1440
  })
1426
1441
 
1427
1442
  watch(
1428
1443
  columns,
1429
1444
  (newColumns) => {
1445
+ tableEl =
1446
+ tableRef.value ||
1447
+ virtScrollRef.value.rootRef.querySelector('table') ||
1448
+ (document.querySelector(
1449
+ 'table.dl-table'
1450
+ ) as HTMLTableElement)
1430
1451
  nextTick(() => {
1431
1452
  setAllColumnWidths(
1432
1453
  tableRef.value,
1433
- newColumns as DlTableColumn[],
1434
- props.fitAllColumns
1454
+ newColumns as DlTableColumn[]
1435
1455
  )
1436
1456
  })
1437
1457
  },
@@ -1451,7 +1471,7 @@ export default defineComponent({
1451
1471
  watch(
1452
1472
  draggable,
1453
1473
  () => {
1454
- if (tableEl) {
1474
+ if (tableEl && !visibleColumns.value) {
1455
1475
  if (hasDraggableColumns.value === true) {
1456
1476
  applyDraggableColumns(
1457
1477
  tableEl,
@@ -24,21 +24,10 @@
24
24
  <slot />
25
25
  <span
26
26
  class="th-icons"
27
- :style="{ top: isDense ? '5px' : '10px' }"
27
+ :style="{ top: isDense ? '5px' : '12px' }"
28
28
  >
29
- <dl-icon
30
- v-if="hasHint"
31
- icon="icon-dl-info"
32
- size="10px"
33
- style="max-width: 30%"
34
- >
35
- <dl-tooltip>
36
- {{ props.col.hint }}
37
- </dl-tooltip>
38
- </dl-icon>
39
29
  <dl-icon
40
30
  v-if="isSortable && ['left', 'center'].includes(align)"
41
- style="margin-top: 2px"
42
31
  :class="iconClass"
43
32
  :icon="computedSortIcon"
44
33
  :style="
@@ -47,6 +36,16 @@
47
36
  : ''
48
37
  "
49
38
  />
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>
50
49
  </span>
51
50
  </th>
52
51
  </template>
@@ -16,7 +16,6 @@
16
16
  }
17
17
  .th-icons {
18
18
  display: flex;
19
- align-items: center;
20
19
  right: 0;
21
20
  position: absolute;
22
21
  }
@@ -132,8 +131,6 @@
132
131
  opacity: 0.64 !important;
133
132
  }
134
133
  }
135
-
136
-
137
134
  }
138
135
 
139
136
  thead,
@@ -20,7 +20,15 @@
20
20
  v-model="textVal"
21
21
  readonly
22
22
  />
23
- <dl-input v-model="trimmedValue" />
23
+ </div>
24
+
25
+ <div>
26
+ <div>With auto trim</div>
27
+
28
+ <dl-input
29
+ v-model="trimmedValue"
30
+ auto-trim
31
+ />
24
32
  </div>
25
33
 
26
34
  <dl-input
@@ -292,15 +300,7 @@ export default defineComponent({
292
300
 
293
301
  const textVal = ref<string>('test me')
294
302
 
295
- const val = ref('')
296
- const trimmedValue = computed<string>({
297
- get: () => {
298
- return textVal.value.trim()
299
- },
300
- set: (value: string) => {
301
- textVal.value = value
302
- }
303
- })
303
+ const trimmedValue = ref('')
304
304
 
305
305
  return {
306
306
  log: console.log,
@@ -348,6 +348,7 @@
348
348
  row-key="index"
349
349
  virtual-scroll
350
350
  @virtual-scroll="onScroll"
351
+ @col-update="updateColumns"
351
352
  />
352
353
  </div>
353
354
  </div>
@@ -3,12 +3,10 @@ import { removeAllChildNodes } from './remove-child-nodes'
3
3
  import {
4
4
  calculateColIndexOffset,
5
5
  getColIndex,
6
- getTableColumn,
7
6
  getTreeTableColumn,
8
7
  justifyMouseInsideTargetCell,
9
8
  removeTableVerticalBorders,
10
- swapTableColumns,
11
- swapTreeTableColumns
9
+ swapTableColumns
12
10
  } from './table-columns'
13
11
  import { isVue2, watch } from 'vue-demi'
14
12
 
@@ -17,7 +15,6 @@ export function applyDraggableColumns(
17
15
  vm?: any,
18
16
  draggableClone?: HTMLDivElement
19
17
  ) {
20
- const isTreeTable = vm.props.isTreeTable
21
18
  let originalColIndex: number = null
22
19
  let sourceColIndex: number = null
23
20
  let targetColIndex: number = null
@@ -93,11 +90,7 @@ export function applyDraggableColumns(
93
90
  newTargetColIndex !== targetColIndex &&
94
91
  newTargetColIndex !== sourceColIndex
95
92
  ) {
96
- if (isTreeTable) {
97
- swapTreeTableColumns(table, sourceColIndex, newTargetColIndex)
98
- } else {
99
- swapTableColumns(table, sourceColIndex, newTargetColIndex)
100
- }
93
+ swapTableColumns(table, sourceColIndex, newTargetColIndex)
101
94
  sourceColIndex = newTargetColIndex
102
95
  targetColIndex = newTargetColIndex
103
96
  }
@@ -108,8 +101,6 @@ export function applyDraggableColumns(
108
101
  const colIndex = getColIndex(targetTh)
109
102
  sourceColIndex = colIndex
110
103
  originalColIndex = colIndex
111
- return isTreeTable
112
- ? getTreeTableColumn(table, sourceColIndex)
113
- : getTableColumn(table, sourceColIndex)
104
+ return getTreeTableColumn(table, sourceColIndex)
114
105
  }
115
106
  }
@@ -3,8 +3,6 @@ import { DlTableColumn } from '../types'
3
3
  import { browseNestedNodes } from './browse-nested-nodes'
4
4
  import { swapNodes } from './swap-nodes'
5
5
 
6
- const DEFAULT_COL_WIDTH = 'fit-content'
7
-
8
6
  export function setColumnVerticalBorder(
9
7
  table: HTMLTableElement,
10
8
  index: string
@@ -45,38 +43,6 @@ export function getColIndex(el: Node) {
45
43
  return Array.from(el.parentElement.children).indexOf(el as HTMLElement)
46
44
  }
47
45
 
48
- export function getTableColumn(
49
- table: HTMLTableElement,
50
- columnIndex: number
51
- ): HTMLTableElement {
52
- const rowCount = table.rows.length
53
-
54
- const originalColumnWidth = table.rows[0].cells[columnIndex].offsetWidth
55
- const originalColumnHeight = table.rows[0].offsetHeight
56
-
57
- const columnTable: HTMLTableElement = document.createElement('table')
58
- const columnTbody: HTMLTableSectionElement = document.createElement('tbody')
59
- columnTable.appendChild(columnTbody)
60
-
61
- for (let i = 0; i < rowCount; i++) {
62
- const row = table.rows[i]
63
- if (row.cells.length > columnIndex) {
64
- const columnRow: HTMLTableRowElement = document.createElement('tr')
65
- const cell: HTMLTableCellElement = row.cells[columnIndex].cloneNode(
66
- true
67
- ) as HTMLTableCellElement
68
-
69
- cell.style.width = originalColumnWidth + 'px'
70
- columnRow.style.height = originalColumnHeight + 'px'
71
-
72
- columnRow.appendChild(cell)
73
- columnTbody.appendChild(columnRow)
74
- }
75
- }
76
-
77
- return columnTable
78
- }
79
-
80
46
  export function getTreeTableColumn(
81
47
  table: HTMLTableElement,
82
48
  columnIndex: number
@@ -89,7 +55,9 @@ export function getTreeTableColumn(
89
55
  const width = th.getBoundingClientRect().width
90
56
  browseNestedNodes(
91
57
  newTable,
92
- (el) => el.dataset.colIndex && el.dataset.colIndex !== thColIndex, // if
58
+ (el) =>
59
+ (el.dataset.colIndex && el.dataset.colIndex !== thColIndex) ||
60
+ el.classList.contains('dl-virtual-scroll__padding'), // if
93
61
  (el) => {
94
62
  el.parentNode?.removeChild(el) // then
95
63
  },
@@ -105,29 +73,6 @@ export function getTreeTableColumn(
105
73
  }
106
74
 
107
75
  export function swapTableColumns(
108
- table: HTMLTableElement,
109
- sourceIndex: number,
110
- targetIndex: number
111
- ): void {
112
- const rows = table.rows
113
-
114
- for (let i = 0; i < rows.length; i++) {
115
- const row = rows[i]
116
- const cells = row.cells
117
-
118
- const tempCell = cells[sourceIndex].cloneNode(true) as HTMLElement
119
- cells[sourceIndex].parentNode!.replaceChild(
120
- cells[targetIndex].cloneNode(true),
121
- cells[sourceIndex]
122
- )
123
- cells[targetIndex].parentNode!.replaceChild(
124
- tempCell,
125
- cells[targetIndex]
126
- )
127
- }
128
- }
129
-
130
- export function swapTreeTableColumns(
131
76
  table: HTMLTableElement,
132
77
  sourceIndex: number,
133
78
  targeIndex: number
@@ -171,14 +116,18 @@ export function justifyMouseInsideTargetCell(
171
116
  )
172
117
  }
173
118
 
119
+ function getIconWidth(el: HTMLElement) {
120
+ const iconEl = el.querySelector('.th-icons')
121
+ return iconEl?.scrollWidth
122
+ }
123
+
174
124
  export function setAllColumnWidths(
175
125
  table: HTMLElement,
176
- columns: DlTableColumn[],
177
- fitAllColumns: boolean
126
+ columns: DlTableColumn[]
178
127
  ) {
179
128
  const hasWidth = columns.some((col) => col.hasOwnProperty('width'))
180
129
  if (!hasWidth) return
181
- // table.style.tableLayout = fitAllColumns ? 'auto' : 'fixed'
130
+ table.style.tableLayout = 'fixed'
182
131
  columns.forEach((col, i) => {
183
132
  browseNestedNodes(
184
133
  table,
@@ -186,9 +135,11 @@ export function setAllColumnWidths(
186
135
  (el.tagName === 'TH' || el.tagName === 'TD') &&
187
136
  parseInt(el.dataset.colIndex) === i,
188
137
  (targetEl) => {
189
- targetEl.style.width = col.width
190
- ? `${col.width}px`
191
- : DEFAULT_COL_WIDTH
138
+ const width =
139
+ (col.width ?? targetEl.scrollWidth) +
140
+ getIconWidth(targetEl) +
141
+ 15
142
+ targetEl.style.width = `${width}px`
192
143
  // then
193
144
  }
194
145
  )