@dataloop-ai/components 0.19.64 → 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 +1 -1
- package/src/components/compound/DlInput/DlInput.vue +105 -31
- package/src/components/compound/DlJsonEditor/DlJsonEditor.vue +2 -2
- package/src/components/compound/DlTable/DlTable.vue +53 -33
- package/src/components/compound/DlTable/components/DlTh.vue +11 -12
- package/src/components/compound/DlTable/styles/dl-table-styles.scss +0 -3
- package/src/demos/DlInputDemo.vue +10 -11
- package/src/demos/DlTableDemo.vue +1 -0
- package/src/utils/draggable-table.ts +3 -12
- package/src/utils/table-columns.ts +15 -64
package/package.json
CHANGED
|
@@ -100,11 +100,7 @@
|
|
|
100
100
|
'placeholder-string': showPlaceholder,
|
|
101
101
|
'placeholder-string--disabled': disabled
|
|
102
102
|
}"
|
|
103
|
-
>{{
|
|
104
|
-
showPlaceholder
|
|
105
|
-
? placeholder
|
|
106
|
-
: modelValue
|
|
107
|
-
}}</span>
|
|
103
|
+
>{{ spanText }}</span>
|
|
108
104
|
</div>
|
|
109
105
|
<div
|
|
110
106
|
v-if="
|
|
@@ -336,14 +332,14 @@
|
|
|
336
332
|
</template>
|
|
337
333
|
|
|
338
334
|
<script lang="ts">
|
|
339
|
-
import { debounce, cloneDeep } from 'lodash'
|
|
335
|
+
import { debounce as debounceFunc, cloneDeep } from 'lodash'
|
|
340
336
|
import {
|
|
341
337
|
computed,
|
|
342
338
|
defineComponent,
|
|
343
|
-
onMounted,
|
|
344
339
|
PropType,
|
|
345
340
|
ref,
|
|
346
341
|
toRefs,
|
|
342
|
+
nextTick,
|
|
347
343
|
watch
|
|
348
344
|
} from 'vue-demi'
|
|
349
345
|
import { DlInfoErrorMessage, DlTooltip } from '../../shared'
|
|
@@ -397,7 +393,7 @@ export default defineComponent({
|
|
|
397
393
|
*/
|
|
398
394
|
modelValue: {
|
|
399
395
|
type: [String, Number],
|
|
400
|
-
default: null
|
|
396
|
+
default: null as string
|
|
401
397
|
},
|
|
402
398
|
/**
|
|
403
399
|
* An array of InputFile objects contained and modeled in the input
|
|
@@ -637,6 +633,20 @@ export default defineComponent({
|
|
|
637
633
|
debounce: {
|
|
638
634
|
type: Number,
|
|
639
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
|
|
640
650
|
}
|
|
641
651
|
},
|
|
642
652
|
emits: [
|
|
@@ -658,15 +668,23 @@ export default defineComponent({
|
|
|
658
668
|
autoSuggestItems,
|
|
659
669
|
maxLength,
|
|
660
670
|
files,
|
|
661
|
-
syntaxHighlightColor
|
|
671
|
+
syntaxHighlightColor,
|
|
672
|
+
placeholder,
|
|
673
|
+
readonly,
|
|
674
|
+
disabled,
|
|
675
|
+
autoTrim,
|
|
676
|
+
debounce,
|
|
677
|
+
trimDebounce
|
|
662
678
|
} = toRefs(props)
|
|
663
679
|
|
|
680
|
+
const isInternalChange = ref(false)
|
|
681
|
+
|
|
664
682
|
const suggestItems = computed<DlInputSuggestion[]>(() => {
|
|
665
683
|
if (!modelValue.value) return []
|
|
666
684
|
return getSuggestItems(
|
|
667
685
|
autoSuggestItems.value,
|
|
668
686
|
modelValue.value?.toString()
|
|
669
|
-
)
|
|
687
|
+
) as DlInputSuggestion[]
|
|
670
688
|
})
|
|
671
689
|
const input = ref(null)
|
|
672
690
|
|
|
@@ -676,6 +694,48 @@ export default defineComponent({
|
|
|
676
694
|
const handleSelectedItem = (value: any) => {
|
|
677
695
|
onAutoSuggestClick(null, value)
|
|
678
696
|
}
|
|
697
|
+
|
|
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, ' ')
|
|
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) => {
|
|
728
|
+
isInternalChange.value = true
|
|
729
|
+
isMenuOpen.value = true
|
|
730
|
+
updateSyntax()
|
|
731
|
+
const target = e.target as HTMLElement
|
|
732
|
+
emit('input', target.innerText, e)
|
|
733
|
+
emit('update:model-value', target.innerText)
|
|
734
|
+
if (autoTrim.value) {
|
|
735
|
+
debouncedHandleValueTrim.value()
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
679
739
|
const onAutoSuggestClick = (e: Event, item: string): void => {
|
|
680
740
|
const newValue = clearSuggestion(modelValue.value.toString(), item)
|
|
681
741
|
if (!maxLength.value || newValue.length < maxLength.value) {
|
|
@@ -735,26 +795,42 @@ export default defineComponent({
|
|
|
735
795
|
() => !modelValue.value || !String(modelValue.value)?.length
|
|
736
796
|
)
|
|
737
797
|
|
|
738
|
-
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
input.value.innerHTML = modelValue.value
|
|
742
|
-
}
|
|
743
|
-
} else {
|
|
744
|
-
input.value.innerHTML = ''
|
|
798
|
+
const spanText = computed<string>(() => {
|
|
799
|
+
if (showPlaceholder.value) {
|
|
800
|
+
return placeholder.value
|
|
745
801
|
}
|
|
802
|
+
return modelValue.value?.toString()
|
|
746
803
|
})
|
|
747
804
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
805
|
+
watch(
|
|
806
|
+
modelValue,
|
|
807
|
+
(val) => {
|
|
808
|
+
nextTick(() => {
|
|
809
|
+
if (
|
|
810
|
+
!isInternalChange.value &&
|
|
811
|
+
val !== null &&
|
|
812
|
+
val !== undefined
|
|
813
|
+
) {
|
|
814
|
+
if (readonly.value || disabled.value) {
|
|
815
|
+
return
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
input.value.innerHTML = val
|
|
819
|
+
.toString()
|
|
820
|
+
.replace(/ /g, ' ')
|
|
821
|
+
} else {
|
|
822
|
+
isInternalChange.value = false
|
|
823
|
+
}
|
|
824
|
+
})
|
|
825
|
+
},
|
|
826
|
+
{ immediate: true }
|
|
827
|
+
)
|
|
753
828
|
|
|
754
829
|
return {
|
|
755
830
|
suggestItems,
|
|
756
831
|
highlightedIndex,
|
|
757
832
|
onAutoSuggestClick,
|
|
833
|
+
onChange,
|
|
758
834
|
isMenuOpen,
|
|
759
835
|
setHighlightedIndex,
|
|
760
836
|
handleSelectedItem,
|
|
@@ -764,7 +840,10 @@ export default defineComponent({
|
|
|
764
840
|
emitRemoveFile,
|
|
765
841
|
updateSyntax,
|
|
766
842
|
stringSuggestions,
|
|
767
|
-
showPlaceholder
|
|
843
|
+
showPlaceholder,
|
|
844
|
+
spanText,
|
|
845
|
+
handleValueTrim,
|
|
846
|
+
debouncedHandleValueTrim
|
|
768
847
|
}
|
|
769
848
|
},
|
|
770
849
|
data() {
|
|
@@ -910,7 +989,7 @@ export default defineComponent({
|
|
|
910
989
|
if (stateManager.disableDebounce) {
|
|
911
990
|
return this.onBlur.bind(this)
|
|
912
991
|
}
|
|
913
|
-
const debounced =
|
|
992
|
+
const debounced = debounceFunc(
|
|
914
993
|
this.onBlur.bind(this),
|
|
915
994
|
this.debounce ?? 50
|
|
916
995
|
)
|
|
@@ -963,13 +1042,6 @@ export default defineComponent({
|
|
|
963
1042
|
onClick(e: Event, item: DlInputSuggestion) {
|
|
964
1043
|
this.onAutoSuggestClick(e, item.suggestion)
|
|
965
1044
|
},
|
|
966
|
-
onChange(e: Event): void {
|
|
967
|
-
this.isMenuOpen = true
|
|
968
|
-
this.updateSyntax()
|
|
969
|
-
const target = e.target as HTMLElement
|
|
970
|
-
this.$emit('input', target.innerText, e)
|
|
971
|
-
this.$emit('update:model-value', target.innerText)
|
|
972
|
-
},
|
|
973
1045
|
async handlePaste() {
|
|
974
1046
|
const content = await readClipboard()
|
|
975
1047
|
|
|
@@ -1014,6 +1086,7 @@ export default defineComponent({
|
|
|
1014
1086
|
inputRef.focus()
|
|
1015
1087
|
},
|
|
1016
1088
|
onFocus(e: InputEvent): void {
|
|
1089
|
+
this.handleValueTrim()
|
|
1017
1090
|
const el = e.target as HTMLElement
|
|
1018
1091
|
if (this.modelValue) {
|
|
1019
1092
|
el.scroll(el.scrollWidth, 0)
|
|
@@ -1030,6 +1103,7 @@ export default defineComponent({
|
|
|
1030
1103
|
el.scroll(0, 0)
|
|
1031
1104
|
this.focused = false
|
|
1032
1105
|
this.$emit('blur', e)
|
|
1106
|
+
this.handleValueTrim()
|
|
1033
1107
|
},
|
|
1034
1108
|
onEnterPress(e: any): void {
|
|
1035
1109
|
this.$emit('enter', e.target.innerText, e)
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
PropType,
|
|
14
14
|
ref,
|
|
15
15
|
toRefs,
|
|
16
|
-
watch
|
|
16
|
+
watch,
|
|
17
|
+
nextTick
|
|
17
18
|
} from 'vue-demi'
|
|
18
19
|
import {
|
|
19
20
|
Content,
|
|
@@ -26,7 +27,6 @@ import {
|
|
|
26
27
|
} from 'vanilla-jsoneditor'
|
|
27
28
|
import { debounce } from 'lodash'
|
|
28
29
|
import { stateManager } from '../../../StateManager'
|
|
29
|
-
import { nextTick } from 'process'
|
|
30
30
|
|
|
31
31
|
export default defineComponent({
|
|
32
32
|
model: {
|
|
@@ -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
|
|
84
|
+
style="width: 25px"
|
|
85
85
|
@mousedown="stopAndPrevent"
|
|
86
86
|
/>
|
|
87
87
|
<th
|
|
88
88
|
v-if="singleSelection"
|
|
89
|
-
class="dl-table--col-auto-
|
|
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
|
|
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
|
|
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
|
|
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 (
|
|
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 =
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
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
|
-
|
|
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' : '
|
|
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>
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
<div>
|
|
3
3
|
<div>
|
|
4
4
|
<input v-model="textVal">
|
|
5
|
-
|
|
6
5
|
<div>This is to test v-model reactivity</div>
|
|
7
6
|
<dl-input
|
|
8
7
|
v-model="textVal"
|
|
@@ -21,7 +20,15 @@
|
|
|
21
20
|
v-model="textVal"
|
|
22
21
|
readonly
|
|
23
22
|
/>
|
|
24
|
-
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div>
|
|
26
|
+
<div>With auto trim</div>
|
|
27
|
+
|
|
28
|
+
<dl-input
|
|
29
|
+
v-model="trimmedValue"
|
|
30
|
+
auto-trim
|
|
31
|
+
/>
|
|
25
32
|
</div>
|
|
26
33
|
|
|
27
34
|
<dl-input
|
|
@@ -293,15 +300,7 @@ export default defineComponent({
|
|
|
293
300
|
|
|
294
301
|
const textVal = ref<string>('test me')
|
|
295
302
|
|
|
296
|
-
const
|
|
297
|
-
const trimmedValue = computed<string>({
|
|
298
|
-
get: () => {
|
|
299
|
-
return textVal.value.trim()
|
|
300
|
-
},
|
|
301
|
-
set: (value: string) => {
|
|
302
|
-
textVal.value = value
|
|
303
|
-
}
|
|
304
|
-
})
|
|
303
|
+
const trimmedValue = ref('')
|
|
305
304
|
|
|
306
305
|
return {
|
|
307
306
|
log: console.log,
|
|
@@ -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
|
-
|
|
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
|
|
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) =>
|
|
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
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
)
|