@dataloop-ai/components 0.19.23 → 0.19.25
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/basic/DlGrid/DlGrid.vue +34 -10
- package/src/components/basic/DlGrid/types.ts +5 -0
- package/src/components/compound/DlTable/components/DlTh.vue +1 -5
- package/src/components/shared/DlVirtualScroll/DlVirtualScroll.vue +10 -3
- package/src/components/shared/DlVirtualScroll/useVirtualScroll.ts +14 -3
- package/src/demos/DlGridDemo.vue +106 -8
- package/src/utils/abbreviate-to-string.ts +0 -23
package/package.json
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
<template>
|
|
2
|
+
<div v-if="hasVirtualScroll">
|
|
3
|
+
<dl-virtual-scroll
|
|
4
|
+
v-slot="{ item }"
|
|
5
|
+
style="height: 500px"
|
|
6
|
+
:items="items"
|
|
7
|
+
:styles="{ gridStyles, gridClass }"
|
|
8
|
+
>
|
|
9
|
+
<slot
|
|
10
|
+
:key="item.id"
|
|
11
|
+
name="item-slot"
|
|
12
|
+
v-bind="{ item }"
|
|
13
|
+
/>
|
|
14
|
+
</dl-virtual-scroll>
|
|
15
|
+
</div>
|
|
2
16
|
<div
|
|
17
|
+
v-else
|
|
3
18
|
ref="grid"
|
|
4
19
|
:style="gridStyles"
|
|
5
20
|
:class="gridClass"
|
|
@@ -24,9 +39,13 @@ import {
|
|
|
24
39
|
import { getGridTemplate, swapElementsInMatrix } from './utils'
|
|
25
40
|
import { isCustomEvent } from '../utils'
|
|
26
41
|
import { getElementAbove } from '../../../utils'
|
|
27
|
-
import { DlGridMode } from './types'
|
|
42
|
+
import { DlGridMode, GridItem } from './types'
|
|
43
|
+
import { DlVirtualScroll } from '../../shared/DlVirtualScroll'
|
|
28
44
|
|
|
29
45
|
export default defineComponent({
|
|
46
|
+
components: {
|
|
47
|
+
DlVirtualScroll
|
|
48
|
+
},
|
|
30
49
|
model: {
|
|
31
50
|
prop: 'modelValue',
|
|
32
51
|
event: 'update:model-value'
|
|
@@ -36,6 +55,10 @@ export default defineComponent({
|
|
|
36
55
|
type: Array as PropType<(string | number)[][]>,
|
|
37
56
|
default: null
|
|
38
57
|
},
|
|
58
|
+
items: {
|
|
59
|
+
type: Array as PropType<GridItem[]>,
|
|
60
|
+
default: null
|
|
61
|
+
},
|
|
39
62
|
rowGap: {
|
|
40
63
|
type: String,
|
|
41
64
|
default: '30px'
|
|
@@ -70,10 +93,16 @@ export default defineComponent({
|
|
|
70
93
|
: 'dl-grid-wrapper__flex'
|
|
71
94
|
)
|
|
72
95
|
|
|
96
|
+
const hasVirtualScroll = computed(() => props.items?.length > 100)
|
|
97
|
+
|
|
73
98
|
const gridStyles = computed(() => {
|
|
74
99
|
const gridStyles: Dictionary<string | number> = {
|
|
75
100
|
'--row-gap': rowGap.value,
|
|
76
|
-
'--column-gap': columnGap.value
|
|
101
|
+
'--column-gap': columnGap.value,
|
|
102
|
+
display: 'grid',
|
|
103
|
+
rowGap: 'var(--row-gap)',
|
|
104
|
+
columnGap: 'var(--column-gap)',
|
|
105
|
+
gridTemplateColumns: 'repeat(var(--element-per-row), 1fr)'
|
|
77
106
|
}
|
|
78
107
|
|
|
79
108
|
if (!isGridMode.value) {
|
|
@@ -112,7 +141,7 @@ export default defineComponent({
|
|
|
112
141
|
}
|
|
113
142
|
|
|
114
143
|
const applyGridElementStyles = () => {
|
|
115
|
-
const childrenElements = Array.from(grid.value
|
|
144
|
+
const childrenElements = Array.from(grid.value?.children || [])
|
|
116
145
|
const layoutOrder = modelValue.value?.flat() ?? []
|
|
117
146
|
|
|
118
147
|
// The check is needed to avoid errors and incorrect behavior
|
|
@@ -186,7 +215,8 @@ export default defineComponent({
|
|
|
186
215
|
isFlexMode,
|
|
187
216
|
gridClass,
|
|
188
217
|
gridStyles,
|
|
189
|
-
grid
|
|
218
|
+
grid,
|
|
219
|
+
hasVirtualScroll
|
|
190
220
|
}
|
|
191
221
|
}
|
|
192
222
|
})
|
|
@@ -194,12 +224,6 @@ export default defineComponent({
|
|
|
194
224
|
|
|
195
225
|
<style lang="scss" scoped>
|
|
196
226
|
.dl-grid-wrapper {
|
|
197
|
-
&__grid {
|
|
198
|
-
display: grid;
|
|
199
|
-
row-gap: var(--row-gap);
|
|
200
|
-
column-gap: var(--column-gap);
|
|
201
|
-
grid-template-columns: repeat(var(--element-per-row), 1fr);
|
|
202
|
-
}
|
|
203
227
|
&__flex {
|
|
204
228
|
display: flex;
|
|
205
229
|
gap: var(--row-gap);
|
|
@@ -89,11 +89,7 @@ export default defineComponent({
|
|
|
89
89
|
|
|
90
90
|
const isDense = computed(() => {
|
|
91
91
|
// @ts-ignore
|
|
92
|
-
return
|
|
93
|
-
!!props.props?.dense ||
|
|
94
|
-
!!props.dense ||
|
|
95
|
-
!!props.props?.col?.dense
|
|
96
|
-
)
|
|
92
|
+
return !!props.props?.dense || !!props.props?.col?.dense
|
|
97
93
|
})
|
|
98
94
|
|
|
99
95
|
const column = computed(() => {
|
|
@@ -13,14 +13,15 @@ import {
|
|
|
13
13
|
isVue2,
|
|
14
14
|
h,
|
|
15
15
|
onUnmounted,
|
|
16
|
-
toRefs
|
|
16
|
+
toRefs,
|
|
17
|
+
PropType
|
|
17
18
|
} from 'vue-demi'
|
|
18
19
|
import getTableMiddle from '../../compound/DlTable/utils/getTableMiddle'
|
|
19
20
|
import { listenOpts, mergeSlot } from '../../../utils'
|
|
20
21
|
import { getScrollTarget } from '../../../utils/scroll'
|
|
21
22
|
import { DlList } from '../../essential/DlList'
|
|
22
23
|
import { DlMarkupTable } from '../../basic/DlMarkupTable'
|
|
23
|
-
import { useVirtualScroll } from './useVirtualScroll'
|
|
24
|
+
import { useVirtualScroll, GridStyles } from './useVirtualScroll'
|
|
24
25
|
import { stateManager } from '../../../StateManager'
|
|
25
26
|
|
|
26
27
|
const comps = {
|
|
@@ -91,6 +92,11 @@ export default defineComponent({
|
|
|
91
92
|
typeOptions.includes(v)
|
|
92
93
|
},
|
|
93
94
|
|
|
95
|
+
styles: {
|
|
96
|
+
type: Object as PropType<GridStyles>,
|
|
97
|
+
default: null
|
|
98
|
+
},
|
|
99
|
+
|
|
94
100
|
itemsFn: { type: Function, default: null },
|
|
95
101
|
itemsSize: { type: Number, default: 0 },
|
|
96
102
|
|
|
@@ -251,7 +257,8 @@ export default defineComponent({
|
|
|
251
257
|
type.value as 'list' | 'table' | '__dltable'
|
|
252
258
|
] || 'div',
|
|
253
259
|
virtualScrollScope.value.map(slots.default),
|
|
254
|
-
create
|
|
260
|
+
create,
|
|
261
|
+
props.styles
|
|
255
262
|
)
|
|
256
263
|
|
|
257
264
|
if (isDefined(slots.before)) {
|
|
@@ -25,6 +25,11 @@ export interface ScrollDetails {
|
|
|
25
25
|
offsetEnd: number
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export interface GridStyles {
|
|
29
|
+
gridStyles: object
|
|
30
|
+
gridClass: string
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
const aggBucketSize = 1000
|
|
29
34
|
|
|
30
35
|
const scrollToEdges = [
|
|
@@ -828,7 +833,12 @@ export function useVirtualScroll({
|
|
|
828
833
|
}
|
|
829
834
|
}
|
|
830
835
|
|
|
831
|
-
function padVirtualScroll(
|
|
836
|
+
function padVirtualScroll(
|
|
837
|
+
tag: string,
|
|
838
|
+
content: any[],
|
|
839
|
+
create: Function,
|
|
840
|
+
styles: GridStyles
|
|
841
|
+
) {
|
|
832
842
|
const paddingSize =
|
|
833
843
|
props.virtualScrollHorizontal === true ? 'width' : 'height'
|
|
834
844
|
|
|
@@ -874,9 +884,10 @@ export function useVirtualScroll({
|
|
|
874
884
|
create(
|
|
875
885
|
tag,
|
|
876
886
|
{
|
|
877
|
-
class:
|
|
887
|
+
class: `dl-virtual-scroll__content ${styles?.gridClass}`,
|
|
888
|
+
style: styles?.gridStyles,
|
|
878
889
|
key: 'content',
|
|
879
|
-
ref: contentRef,
|
|
890
|
+
ref: styles ? 'grid' : contentRef,
|
|
880
891
|
tabindex: -1
|
|
881
892
|
},
|
|
882
893
|
content.flat()
|
package/src/demos/DlGridDemo.vue
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="widgets-demo-wrapper">
|
|
3
|
-
<div>
|
|
3
|
+
<div class="select-wrapper">
|
|
4
|
+
<div style="width: 40%">
|
|
5
|
+
<p>Select mode:</p>
|
|
6
|
+
<dl-select
|
|
7
|
+
v-model="activeMode"
|
|
8
|
+
:options="[flex, grid, layout]"
|
|
9
|
+
/>
|
|
10
|
+
</div>
|
|
11
|
+
<div style="width: 40%">
|
|
12
|
+
<p>Select content type:</p>
|
|
13
|
+
<dl-select
|
|
14
|
+
v-model="activeContentType"
|
|
15
|
+
:options="[
|
|
16
|
+
{ value: 'images', label: 'Images' },
|
|
17
|
+
{ value: 'widgets', label: 'Widgets' },
|
|
18
|
+
{
|
|
19
|
+
value: 'prop',
|
|
20
|
+
label: 'Prop + ItemSlot + VirtualScroll'
|
|
21
|
+
}
|
|
22
|
+
]"
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div v-if="activeMode === layout">
|
|
4
28
|
<h3>Layout mode</h3>
|
|
5
29
|
<dl-button
|
|
30
|
+
v-if="activeContentType.value === 'widgets'"
|
|
6
31
|
class="select-layout__button"
|
|
7
32
|
style="width: 200px; margin-bottom: 20px"
|
|
8
33
|
@click="addWidget(layout)"
|
|
@@ -10,6 +35,7 @@
|
|
|
10
35
|
Add widget
|
|
11
36
|
</dl-button>
|
|
12
37
|
<dl-grid
|
|
38
|
+
v-if="activeContentType.value === 'widgets'"
|
|
13
39
|
:key="cmWidgets.length"
|
|
14
40
|
v-model="cmLayout"
|
|
15
41
|
:max-elements-per-row="cmMaxWidgetsPerRow"
|
|
@@ -46,10 +72,22 @@
|
|
|
46
72
|
</template>
|
|
47
73
|
</dl-widget>
|
|
48
74
|
</dl-grid>
|
|
75
|
+
<dl-grid
|
|
76
|
+
v-if="activeContentType.value === 'images'"
|
|
77
|
+
v-model="cmLayout"
|
|
78
|
+
:mode="layout"
|
|
79
|
+
>
|
|
80
|
+
<img
|
|
81
|
+
v-for="img in images"
|
|
82
|
+
:key="img.id"
|
|
83
|
+
:src="img.src"
|
|
84
|
+
>
|
|
85
|
+
</dl-grid>
|
|
49
86
|
</div>
|
|
50
|
-
<div>
|
|
87
|
+
<div v-else-if="activeMode === grid">
|
|
51
88
|
<h3>Grid mode</h3>
|
|
52
89
|
<dl-button
|
|
90
|
+
v-if="activeContentType.value === 'widgets'"
|
|
53
91
|
class="select-layout__button"
|
|
54
92
|
style="width: 200px; margin-bottom: 20px"
|
|
55
93
|
@click="addWidget(grid)"
|
|
@@ -57,6 +95,7 @@
|
|
|
57
95
|
Add widget
|
|
58
96
|
</dl-button>
|
|
59
97
|
<dl-grid
|
|
98
|
+
v-if="activeContentType.value === 'widgets'"
|
|
60
99
|
:key="dmWidgets.length"
|
|
61
100
|
v-model="dmLayout"
|
|
62
101
|
:max-elements-per-row="dmMaxWidgetsPerRow"
|
|
@@ -93,10 +132,22 @@
|
|
|
93
132
|
</template>
|
|
94
133
|
</dl-widget>
|
|
95
134
|
</dl-grid>
|
|
135
|
+
<dl-grid
|
|
136
|
+
v-if="activeContentType.value === 'images'"
|
|
137
|
+
v-model="dmLayout"
|
|
138
|
+
:mode="layout"
|
|
139
|
+
>
|
|
140
|
+
<img
|
|
141
|
+
v-for="img in images"
|
|
142
|
+
:key="img.id"
|
|
143
|
+
:src="img.src"
|
|
144
|
+
>
|
|
145
|
+
</dl-grid>
|
|
96
146
|
</div>
|
|
97
|
-
<div>
|
|
147
|
+
<div v-else-if="activeMode === flex">
|
|
98
148
|
<h3>Flex mode</h3>
|
|
99
149
|
<dl-button
|
|
150
|
+
v-if="activeContentType.value === 'widgets'"
|
|
100
151
|
class="select-layout__button"
|
|
101
152
|
style="width: 200px; margin-bottom: 20px"
|
|
102
153
|
@click="addWidget(flex)"
|
|
@@ -104,6 +155,7 @@
|
|
|
104
155
|
Add widget
|
|
105
156
|
</dl-button>
|
|
106
157
|
<dl-grid
|
|
158
|
+
v-if="activeContentType.value === 'widgets'"
|
|
107
159
|
:key="fmWidgets.length"
|
|
108
160
|
:mode="flex"
|
|
109
161
|
>
|
|
@@ -140,13 +192,38 @@
|
|
|
140
192
|
</template>
|
|
141
193
|
</dl-widget>
|
|
142
194
|
</dl-grid>
|
|
195
|
+
<dl-grid
|
|
196
|
+
v-if="activeContentType.value === 'images'"
|
|
197
|
+
:mode="layout"
|
|
198
|
+
>
|
|
199
|
+
<img
|
|
200
|
+
v-for="img in images"
|
|
201
|
+
:key="img.id"
|
|
202
|
+
:src="img.src"
|
|
203
|
+
>
|
|
204
|
+
</dl-grid>
|
|
205
|
+
</div>
|
|
206
|
+
<div v-if="activeContentType.value === 'prop'">
|
|
207
|
+
<dl-grid :items="images">
|
|
208
|
+
<template #item-slot="{ item }">
|
|
209
|
+
<img :src="item.src">
|
|
210
|
+
</template>
|
|
211
|
+
</dl-grid>
|
|
143
212
|
</div>
|
|
144
213
|
</div>
|
|
145
214
|
</template>
|
|
146
215
|
|
|
147
216
|
<script lang="ts">
|
|
217
|
+
import { v4 } from 'uuid'
|
|
148
218
|
import { defineComponent, Ref, ref } from 'vue-demi'
|
|
149
|
-
import {
|
|
219
|
+
import {
|
|
220
|
+
DlWidget,
|
|
221
|
+
DlGrid,
|
|
222
|
+
DlBarChart,
|
|
223
|
+
DlIcon,
|
|
224
|
+
DlButton,
|
|
225
|
+
DlSelect
|
|
226
|
+
} from '../components'
|
|
150
227
|
import { DlGridMode } from '../types'
|
|
151
228
|
|
|
152
229
|
const data = {
|
|
@@ -173,9 +250,16 @@ export default defineComponent({
|
|
|
173
250
|
DlWidget,
|
|
174
251
|
DlBarChart,
|
|
175
252
|
DlIcon,
|
|
176
|
-
DlButton
|
|
253
|
+
DlButton,
|
|
254
|
+
DlSelect
|
|
177
255
|
},
|
|
178
256
|
setup() {
|
|
257
|
+
const activeMode = ref('layout')
|
|
258
|
+
const activeContentType = ref({
|
|
259
|
+
value: 'images',
|
|
260
|
+
label: 'Images'
|
|
261
|
+
})
|
|
262
|
+
|
|
179
263
|
const cmLayout: Ref<string[][]> = ref([
|
|
180
264
|
['a', 'b', 'c'],
|
|
181
265
|
['d', 'e']
|
|
@@ -266,6 +350,13 @@ export default defineComponent({
|
|
|
266
350
|
return template
|
|
267
351
|
}
|
|
268
352
|
|
|
353
|
+
const images = []
|
|
354
|
+
for (let i = 0; i < 101; i++) {
|
|
355
|
+
images.push({
|
|
356
|
+
id: v4(),
|
|
357
|
+
src: 'https://picsum.photos/200/200'
|
|
358
|
+
})
|
|
359
|
+
}
|
|
269
360
|
return {
|
|
270
361
|
data,
|
|
271
362
|
deleteWidget,
|
|
@@ -281,13 +372,22 @@ export default defineComponent({
|
|
|
281
372
|
dmMaxWidgetsPerRow,
|
|
282
373
|
layout: DlGridMode.LAYOUT,
|
|
283
374
|
flex: DlGridMode.FLEX,
|
|
284
|
-
grid: DlGridMode.GRID
|
|
375
|
+
grid: DlGridMode.GRID,
|
|
376
|
+
activeMode,
|
|
377
|
+
activeContentType,
|
|
378
|
+
images
|
|
285
379
|
}
|
|
286
380
|
}
|
|
287
381
|
})
|
|
288
382
|
</script>
|
|
289
383
|
|
|
290
384
|
<style lang="scss" scoped>
|
|
385
|
+
.select-wrapper {
|
|
386
|
+
width: 100%;
|
|
387
|
+
display: flex;
|
|
388
|
+
flex-direction: row;
|
|
389
|
+
justify-content: space-evenly;
|
|
390
|
+
}
|
|
291
391
|
.widgets-demo-wrapper {
|
|
292
392
|
display: flex;
|
|
293
393
|
flex-direction: column;
|
|
@@ -296,8 +396,6 @@ export default defineComponent({
|
|
|
296
396
|
gap: 20px;
|
|
297
397
|
|
|
298
398
|
& > * {
|
|
299
|
-
display: flex;
|
|
300
|
-
flex-direction: column;
|
|
301
399
|
gap: 10px;
|
|
302
400
|
border: 1px solid var(--dl-color-separator);
|
|
303
401
|
padding: 10px;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function abbreviateToString(num: number, precision: number = 1): string {
|
|
2
|
-
const abbreviations = [
|
|
3
|
-
{ value: 1e12, suffix: 'T' },
|
|
4
|
-
{ value: 1e9, suffix: 'B' },
|
|
5
|
-
{ value: 1e6, suffix: 'M' },
|
|
6
|
-
{ value: 1e3, suffix: 'K' }
|
|
7
|
-
]
|
|
8
|
-
|
|
9
|
-
const match = abbreviations.find((abb) => num >= abb.value)
|
|
10
|
-
if (!match) {
|
|
11
|
-
return num.toString()
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const abbreviated = (num / match.value).toFixed(precision)
|
|
15
|
-
const formatted = Number(abbreviated).toString()
|
|
16
|
-
const suffix = match.suffix
|
|
17
|
-
|
|
18
|
-
if (formatted.includes('.')) {
|
|
19
|
-
return formatted.replace(/\.?0*$/, '') + suffix
|
|
20
|
-
} else {
|
|
21
|
-
return formatted + suffix
|
|
22
|
-
}
|
|
23
|
-
}
|