@dataloop-ai/components 0.13.19 → 0.14.4
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/.nvmrc +1 -0
- package/README.md +3 -1
- package/package.json +19 -17
- package/src/assets/globals.scss +38 -3
- package/src/assets/grid.scss +9 -0
- package/src/components/DlAccordion/DlAccordion.vue +4 -4
- package/src/components/DlAlert.vue +6 -6
- package/src/components/DlChart/BrushThumb.vue +83 -0
- package/src/components/DlChart/DlBarChart.vue +545 -0
- package/src/components/DlChart/DlBrush.vue +475 -0
- package/src/components/DlChart/DlChartLabels.vue +279 -0
- package/src/components/DlChart/DlChartLegend.vue +141 -0
- package/src/components/DlChart/DlColumnChart.vue +555 -0
- package/src/components/DlChart/DlLineChart.vue +644 -0
- package/src/components/DlChart/DlScrollBar.vue +147 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChart.vue +448 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChartLegend.vue +281 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChartWidget.vue +64 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartAnimation.ts +4 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartData.ts +16 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartOptions.ts +11 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartProps.ts +8 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutWithOriginalColor.ts +13 -0
- package/src/components/DlChart/chart.ts +122 -0
- package/src/components/DlChart/index.ts +36 -0
- package/src/components/DlChart/props.ts +348 -0
- package/src/components/DlChart/typedCharts.ts +88 -0
- package/src/components/DlChart/types.ts +63 -0
- package/src/components/DlChart/utils.ts +153 -0
- package/src/components/DlChip/DlChip.vue +40 -13
- package/src/components/DlCounters.vue +31 -7
- package/src/components/DlDatePicker/DlCalendar.vue +22 -10
- package/src/components/DlDatePicker/DlDatePicker.vue +8 -5
- package/src/components/DlDateTimeRange/types.ts +2 -2
- package/src/components/DlDropdownButton.vue +5 -3
- package/src/components/DlMenu/DlMenu.vue +4 -2
- package/src/components/DlPagination/RowsSelector.vue +15 -2
- package/src/components/DlPopup/DlPopup.vue +0 -1
- package/src/components/DlRange/DlRange.vue +3 -2
- package/src/components/DlSearch.vue +1 -1
- package/src/components/DlSelect/DlSelect.vue +3 -2
- package/src/components/DlSlider/sliderStyles.scss +4 -0
- package/src/components/DlSlider/useSlider.ts +39 -12
- package/src/components/DlSmartSearch/DlSuggestionsDropdown.vue +1 -1
- package/src/components/DlSpinner.vue +259 -0
- package/src/components/DlTable/DlTable.vue +4 -1
- package/src/components/DlTable/hooks/tablePagination.ts +8 -2
- package/src/components/DlTextArea.vue +9 -0
- package/src/components/DlTextInput.vue +4 -2
- package/src/components/DlThemeProvider.vue +22 -13
- package/src/components/DlToastMessage/api/useToast.ts +23 -0
- package/src/components/DlToastMessage/components/ToastComponent.vue +279 -0
- package/src/components/DlToastMessage/index.ts +5 -0
- package/src/components/DlToastMessage/types.ts +4 -0
- package/src/components/DlToastMessage/utils/config.ts +17 -0
- package/src/components/DlToastMessage/utils/render.ts +56 -0
- package/src/components/DlTypography.vue +1 -1
- package/src/components/DlWidget/DlGrid.vue +33 -0
- package/src/components/DlWidget/DlGridRow.vue +32 -0
- package/src/components/DlWidget/DlWidget.vue +202 -11
- package/src/components/DlWidget/index.ts +2 -2
- package/src/components/DlWidget/utils.ts +26 -19
- package/src/components/index.ts +8 -3
- package/src/demo/BarChartDemo.vue +77 -0
- package/src/demo/ColumnChartDemo.vue +230 -0
- package/src/demo/DlButtonDemo.vue +1 -1
- package/src/demo/DlChartDoughnutDemo.vue +229 -0
- package/src/demo/DlChipDemo.vue +42 -18
- package/src/demo/DlDialogBoxDemo.vue +4 -4
- package/src/demo/DlDropdownButtonDemo.vue +1 -1
- package/src/demo/DlLineChartDemo.vue +375 -0
- package/src/demo/DlMenuDemo.vue +1 -1
- package/src/demo/DlOptionGroupDemo.vue +1 -1
- package/src/demo/DlSelectDemo.vue +1 -1
- package/src/demo/DlSpinnerDemo.vue +20 -0
- package/src/demo/DlTableDemo.vue +13 -94
- package/src/demo/DlToastMessageDemo.vue +143 -0
- package/src/demo/DlWidgetDemo.vue +105 -143
- package/src/demo/index.ts +20 -2
- package/src/hooks/use-theme.ts +19 -0
- package/src/utils/abbreviate-to-string.ts +14 -0
- package/src/utils/colors.ts +47 -0
- package/src/utils/getRootStyles.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/position-engine.ts +11 -2
- package/src/utils/swapNodes.ts +30 -0
- package/src/utils/update-key.ts +90 -0
- package/tsconfig.json +0 -1
- package/vite.config.ts +17 -0
- package/Dockerfile +0 -12
- package/jest.config.js +0 -16
- package/jest.setup.js +0 -59
- package/src/components/DlWidget/DlWidgetGrid.vue +0 -360
- package/storybook.js +0 -8
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { cloneDeep } from 'lodash'
|
|
2
|
+
|
|
3
|
+
export function updateKey(
|
|
4
|
+
data: Record<string, any>,
|
|
5
|
+
key: string,
|
|
6
|
+
mapFn: Function
|
|
7
|
+
): Record<string, any> {
|
|
8
|
+
const input = cloneDeep(data)
|
|
9
|
+
|
|
10
|
+
recursiveKeyUpdate(input, key, mapFn)
|
|
11
|
+
|
|
12
|
+
return input
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function recursiveKeyUpdate(
|
|
16
|
+
input: Record<string, any>,
|
|
17
|
+
key: string,
|
|
18
|
+
mapFn: Function
|
|
19
|
+
): Record<string, any> {
|
|
20
|
+
if (input instanceof Array) {
|
|
21
|
+
for (let i = 0; i < input.length; i++) {
|
|
22
|
+
recursiveKeyUpdate(input[i], key, mapFn)
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
for (const prop in input) {
|
|
26
|
+
if (prop === key) {
|
|
27
|
+
input[prop] = mapFn(input[prop])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (input[prop] instanceof Object || input[prop] instanceof Array) {
|
|
31
|
+
recursiveKeyUpdate(input[prop], key, mapFn)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return input
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function updateKeys(
|
|
40
|
+
data: Record<string, any>,
|
|
41
|
+
keys: string[],
|
|
42
|
+
mapFn: Function
|
|
43
|
+
): Record<string, any> {
|
|
44
|
+
const input = cloneDeep(data)
|
|
45
|
+
recursiveKeysUpdate(input, keys, mapFn)
|
|
46
|
+
return input
|
|
47
|
+
}
|
|
48
|
+
export function recursiveKeysUpdate(
|
|
49
|
+
input: Record<string, any>,
|
|
50
|
+
keys: string[],
|
|
51
|
+
mapFn: Function
|
|
52
|
+
): Record<string, any> {
|
|
53
|
+
if (input instanceof Array) {
|
|
54
|
+
for (let i = 0; i < input.length; i++) {
|
|
55
|
+
recursiveKeysUpdate(input[i], keys, mapFn)
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
for (const prop in input) {
|
|
59
|
+
if (keys.includes(prop)) {
|
|
60
|
+
input[prop] = mapFn(input[prop])
|
|
61
|
+
}
|
|
62
|
+
if (input[prop] instanceof Object || input[prop] instanceof Array) {
|
|
63
|
+
recursiveKeysUpdate(input[prop], keys, mapFn)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return input
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function updateNestedArrayValues(
|
|
71
|
+
data: Record<string, any>,
|
|
72
|
+
keys: string[],
|
|
73
|
+
mapFn: Function
|
|
74
|
+
) {
|
|
75
|
+
if (keys.length === 0) {
|
|
76
|
+
// If there are no more keys left in the array, apply the callback to the data and return the result
|
|
77
|
+
return mapFn(data)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const key = keys[0] // Get the first key in the array
|
|
81
|
+
const restKeys = keys.slice(1) // Get the rest of the keys in the array
|
|
82
|
+
|
|
83
|
+
// If the data is an object and contains the key, update the value of the key with the recursive call of the function
|
|
84
|
+
if (typeof data === 'object' && data !== null && data.hasOwnProperty(key)) {
|
|
85
|
+
data[key] = data[key].map((item: string) => mapFn(item))
|
|
86
|
+
updateNestedArrayValues(data, restKeys, mapFn)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return data // Return the updated data
|
|
90
|
+
}
|
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
/// <reference types="vitest" />
|
|
1
2
|
import { defineConfig } from 'vite'
|
|
2
3
|
import vue from '@vitejs/plugin-vue'
|
|
3
4
|
|
|
4
5
|
// https://vitejs.dev/config/
|
|
5
6
|
export default defineConfig({
|
|
6
7
|
plugins: [vue()],
|
|
8
|
+
test: {
|
|
9
|
+
environment: 'jsdom',
|
|
10
|
+
setupFiles: ['tests/setup.js'],
|
|
11
|
+
deps: {
|
|
12
|
+
inline: ['vitest-canvas-mock']
|
|
13
|
+
},
|
|
14
|
+
coverage: {
|
|
15
|
+
reporter: ['lcovonly', 'text']
|
|
16
|
+
}
|
|
17
|
+
},
|
|
7
18
|
optimizeDeps: {
|
|
8
19
|
exclude: ['vue-demi']
|
|
9
20
|
},
|
|
10
21
|
define: {
|
|
11
22
|
'process.env': process.env
|
|
23
|
+
},
|
|
24
|
+
server: { port: 3000 },
|
|
25
|
+
resolve: {
|
|
26
|
+
alias: {
|
|
27
|
+
vue: 'vue/dist/vue.esm-bundler.js'
|
|
28
|
+
}
|
|
12
29
|
}
|
|
13
30
|
})
|
package/Dockerfile
DELETED
package/jest.config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'jsdom',
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.vue$': 'vue3-jest',
|
|
7
|
-
'.(css|less|scss)$': '<rootDir>/tests/mock/style-mock.js'
|
|
8
|
-
},
|
|
9
|
-
moduleFileExtensions: ['json', 'js', 'jsx', 'ts', 'tsx', 'vue', '.css'],
|
|
10
|
-
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
|
11
|
-
moduleNameMapper: {
|
|
12
|
-
'\\.(css|less|sass|scss)$': '<rootDir>/tests/__mocks__/styleMock.js',
|
|
13
|
-
'\\.(gif|ttf|eot|svg)$': '<rootDir>/tests/__mocks__/fileMock.js',
|
|
14
|
-
'vanilla-jsoneditor': '<rootDir>/tests/mock/style-mock.js'
|
|
15
|
-
}
|
|
16
|
-
}
|
package/jest.setup.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const Environment = require('jest-environment-jsdom')
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-undef */
|
|
4
|
-
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
5
|
-
observe: jest.fn(),
|
|
6
|
-
unobserve: jest.fn(),
|
|
7
|
-
disconnect: jest.fn()
|
|
8
|
-
}))
|
|
9
|
-
|
|
10
|
-
Element.prototype.scrollTo = () => {}
|
|
11
|
-
|
|
12
|
-
if (typeof String.prototype.replaceAll === 'undefined') {
|
|
13
|
-
String.prototype.replaceAll = function (match, replace) {
|
|
14
|
-
return this.replace(new RegExp(match, 'g'), () => replace)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const delay = (delay) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
setTimeout(() => resolve(null), delay)
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
global.delay = delay
|
|
25
|
-
window.delay = delay
|
|
26
|
-
|
|
27
|
-
document.createRange = () => {
|
|
28
|
-
const range = new Range()
|
|
29
|
-
range.getBoundingClientRect = jest.fn(() => ({
|
|
30
|
-
width: 0,
|
|
31
|
-
height: 0,
|
|
32
|
-
top: 0,
|
|
33
|
-
left: 0,
|
|
34
|
-
right: 0,
|
|
35
|
-
bottom: 0
|
|
36
|
-
}))
|
|
37
|
-
range.getClientRects = () => {
|
|
38
|
-
return {
|
|
39
|
-
item: () => null,
|
|
40
|
-
length: 0,
|
|
41
|
-
[Symbol.iterator]: jest.fn()
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
range.startContainer.getBoundingClientRect = jest.fn()
|
|
45
|
-
return range
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = class CustomTestEnvironment extends Environment {
|
|
49
|
-
async setup() {
|
|
50
|
-
await super.setup()
|
|
51
|
-
if (typeof this.global.TextEncoder === 'undefined') {
|
|
52
|
-
const { TextEncoder, TextDecoder } = require('util')
|
|
53
|
-
this.global.TextEncoder = TextEncoder
|
|
54
|
-
this.global.TextDecoder = TextDecoder
|
|
55
|
-
this.global.ArrayBuffer = ArrayBuffer
|
|
56
|
-
this.global.Uint8Array = Uint8Array
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
:id="uuid"
|
|
4
|
-
class="dl-widget-grid"
|
|
5
|
-
:style="gridStyle"
|
|
6
|
-
>
|
|
7
|
-
<div
|
|
8
|
-
v-for="(row, rowIndex) in modelValue"
|
|
9
|
-
:key="row"
|
|
10
|
-
class="dl-widget-grid__row"
|
|
11
|
-
:style="rowStyle"
|
|
12
|
-
@mouseenter="currentRow = rowIndex"
|
|
13
|
-
>
|
|
14
|
-
<div
|
|
15
|
-
v-for="(widget, widgetIndex) in row"
|
|
16
|
-
:id="`${rowIndex}-${widgetIndex}`"
|
|
17
|
-
:key="widget"
|
|
18
|
-
:class="gridItemClasses"
|
|
19
|
-
:style="`flex-basis: ${100 / row.length}%`"
|
|
20
|
-
@mouseenter="
|
|
21
|
-
(e) => {
|
|
22
|
-
handleMouseEnter(e)
|
|
23
|
-
currentItem = widgetIndex
|
|
24
|
-
}
|
|
25
|
-
"
|
|
26
|
-
>
|
|
27
|
-
<dl-widget>
|
|
28
|
-
<template #header>
|
|
29
|
-
<div class="dl-widget-grid__item--header">
|
|
30
|
-
<div class="dl-widget-grid__item--titles">
|
|
31
|
-
<dl-typography size="h2">
|
|
32
|
-
{{ widget.title }}
|
|
33
|
-
</dl-typography>
|
|
34
|
-
<dl-typography size="h4">
|
|
35
|
-
{{ widget.subTitle }}
|
|
36
|
-
</dl-typography>
|
|
37
|
-
</div>
|
|
38
|
-
<dl-icon
|
|
39
|
-
class="dl-widget-grid__item--drag-icon"
|
|
40
|
-
icon="icon-dl-drag"
|
|
41
|
-
color="dl-color-medium"
|
|
42
|
-
size="15px"
|
|
43
|
-
@mousedown="
|
|
44
|
-
startDragging(
|
|
45
|
-
`${rowIndex}-${widgetIndex}`,
|
|
46
|
-
widget
|
|
47
|
-
)
|
|
48
|
-
"
|
|
49
|
-
/>
|
|
50
|
-
<div class="dl-widget-grid__item--menu">
|
|
51
|
-
<slot name="menu" />
|
|
52
|
-
<dl-icon
|
|
53
|
-
v-if="isEditable"
|
|
54
|
-
class="dl-widget-grid__item--delete-icon"
|
|
55
|
-
icon="icon-dl-delete"
|
|
56
|
-
color="dl-color-negative"
|
|
57
|
-
size="20px"
|
|
58
|
-
@mousedown="
|
|
59
|
-
removeWidget(
|
|
60
|
-
`${rowIndex}-${widgetIndex}`
|
|
61
|
-
)
|
|
62
|
-
"
|
|
63
|
-
/>
|
|
64
|
-
</div>
|
|
65
|
-
</div>
|
|
66
|
-
</template>
|
|
67
|
-
<template #content>
|
|
68
|
-
<div class="dl-widget-grid__item--content">
|
|
69
|
-
<component
|
|
70
|
-
:is="widget.content"
|
|
71
|
-
v-if="typeof widget.content === 'object'"
|
|
72
|
-
/>
|
|
73
|
-
<div v-else>
|
|
74
|
-
{{ widget.content }}
|
|
75
|
-
</div>
|
|
76
|
-
</div>
|
|
77
|
-
</template>
|
|
78
|
-
<template #description>
|
|
79
|
-
{{ widget.description }}
|
|
80
|
-
</template>
|
|
81
|
-
</dl-widget>
|
|
82
|
-
</div>
|
|
83
|
-
</div>
|
|
84
|
-
|
|
85
|
-
<div
|
|
86
|
-
ref="clone"
|
|
87
|
-
:class="cloneClasses"
|
|
88
|
-
/>
|
|
89
|
-
</div>
|
|
90
|
-
</template>
|
|
91
|
-
|
|
92
|
-
<script lang="ts">
|
|
93
|
-
import { defineComponent, PropType } from 'vue-demi'
|
|
94
|
-
import { Widget } from './types'
|
|
95
|
-
import { cloneDeep } from 'lodash'
|
|
96
|
-
import { equateElements, getTargetWidget, getIndex } from './utils'
|
|
97
|
-
import DlWidget from './DlWidget.vue'
|
|
98
|
-
import DlIcon from '../DlIcon.vue'
|
|
99
|
-
import DlTypography from '../DlTypography.vue'
|
|
100
|
-
import { v4 } from 'uuid'
|
|
101
|
-
|
|
102
|
-
interface DragSide {
|
|
103
|
-
previous: boolean
|
|
104
|
-
current: boolean
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default defineComponent({
|
|
108
|
-
components: {
|
|
109
|
-
DlWidget,
|
|
110
|
-
DlIcon,
|
|
111
|
-
DlTypography
|
|
112
|
-
},
|
|
113
|
-
props: {
|
|
114
|
-
modelValue: {
|
|
115
|
-
type: Array as PropType<Widget[][]>,
|
|
116
|
-
default: () => [] as Widget[]
|
|
117
|
-
},
|
|
118
|
-
isEditable: { type: Boolean, default: false },
|
|
119
|
-
rowGap: { type: String, default: '30px' },
|
|
120
|
-
columnGap: { type: String, default: '30px' },
|
|
121
|
-
widgetLibrary: { type: Array, default: () => [] as Widget[] }
|
|
122
|
-
},
|
|
123
|
-
emits: ['update:model-value', 'remove'],
|
|
124
|
-
data(): {
|
|
125
|
-
uuid: string
|
|
126
|
-
timer: number
|
|
127
|
-
isDragging: boolean
|
|
128
|
-
dragTarget: HTMLElement
|
|
129
|
-
currentRow: number
|
|
130
|
-
currentItem: number
|
|
131
|
-
draggedWidget: Widget
|
|
132
|
-
draggedWidgetId: string
|
|
133
|
-
dragSide: DragSide
|
|
134
|
-
} {
|
|
135
|
-
return {
|
|
136
|
-
uuid: `dl-widget-grid-${v4()}`,
|
|
137
|
-
timer: null,
|
|
138
|
-
isDragging: false,
|
|
139
|
-
dragTarget: null,
|
|
140
|
-
currentRow: -1,
|
|
141
|
-
currentItem: -1,
|
|
142
|
-
draggedWidget: null,
|
|
143
|
-
draggedWidgetId: null,
|
|
144
|
-
dragSide: { previous: null, current: null }
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
computed: {
|
|
148
|
-
gridStyle(): Record<string, any> {
|
|
149
|
-
return { gap: this.rowGap }
|
|
150
|
-
},
|
|
151
|
-
rowStyle(): Record<string, any> {
|
|
152
|
-
return { gap: this.columnGap }
|
|
153
|
-
},
|
|
154
|
-
cloneClasses(): string {
|
|
155
|
-
return `dl-widget-grid__clone ${
|
|
156
|
-
this.isDragging ? 'dl-widget-grid__clone--dragging' : ''
|
|
157
|
-
}`
|
|
158
|
-
},
|
|
159
|
-
gridItemClasses(): string {
|
|
160
|
-
return `dl-widget-grid__item ${
|
|
161
|
-
this.isDragging ? 'dl-widget-grid__item--dragging' : ''
|
|
162
|
-
}`
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
mounted() {
|
|
166
|
-
window.addEventListener('mouseup', (e) => this.stopDragging(e))
|
|
167
|
-
},
|
|
168
|
-
methods: {
|
|
169
|
-
startDragging(widgetIndex: string, widget: Widget) {
|
|
170
|
-
window.addEventListener('mousemove', (e) => this.moveWidget(e))
|
|
171
|
-
this.isDragging = true
|
|
172
|
-
const draggedWidget = document.getElementById(widgetIndex)
|
|
173
|
-
draggedWidget.style.visibility = 'hidden'
|
|
174
|
-
this.draggedWidgetId = draggedWidget.id
|
|
175
|
-
this.draggedWidget = widget
|
|
176
|
-
equateElements(draggedWidget, this.$refs.clone as HTMLElement)
|
|
177
|
-
},
|
|
178
|
-
stopDragging(e: MouseEvent) {
|
|
179
|
-
if (!this.isDragging) return
|
|
180
|
-
this.isDragging = false
|
|
181
|
-
const targetId = getTargetWidget(e.target as HTMLElement)?.id
|
|
182
|
-
let newWidgets: Widget[][]
|
|
183
|
-
if (targetId && this.draggedWidgetId) {
|
|
184
|
-
newWidgets = cloneDeep(this.modelValue) as Widget[][]
|
|
185
|
-
const targetIndex = getIndex(targetId)
|
|
186
|
-
const sourceIndex = getIndex(this.draggedWidgetId)
|
|
187
|
-
const temp = newWidgets[targetIndex.row][targetIndex.column]
|
|
188
|
-
newWidgets[targetIndex.row][targetIndex.column] =
|
|
189
|
-
this.modelValue[sourceIndex.row][sourceIndex.column]
|
|
190
|
-
newWidgets[sourceIndex.row][sourceIndex.column] = temp
|
|
191
|
-
|
|
192
|
-
this.$emit('update:model-value', newWidgets)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (this.$refs.clone) {
|
|
196
|
-
(this.$refs.clone as HTMLElement).innerHTML = ''
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const activeWidget = document.getElementById(this.draggedWidgetId)
|
|
200
|
-
if (activeWidget) {
|
|
201
|
-
activeWidget.style.visibility = 'visible'
|
|
202
|
-
}
|
|
203
|
-
this.draggedWidgetId = null
|
|
204
|
-
window.removeEventListener('mousemove', this.stopDragging)
|
|
205
|
-
window.removeEventListener('mousemove', this.handleMouseMove)
|
|
206
|
-
},
|
|
207
|
-
moveWidget(e: MouseEvent) {
|
|
208
|
-
const clone = this.$refs.clone as HTMLElement
|
|
209
|
-
clone.style.left = `${e.pageX - clone.offsetWidth / 2 - 5}px`
|
|
210
|
-
clone.style.top = `${e.pageY + 10}px`
|
|
211
|
-
},
|
|
212
|
-
removeWidget(widgetId: string) {
|
|
213
|
-
this.$emit(
|
|
214
|
-
'update:model-value',
|
|
215
|
-
this.modelValue.map((row: Widget[], rowIndex: number) =>
|
|
216
|
-
row.filter((widget: Widget, widgetIndex: number) => {
|
|
217
|
-
if (`${rowIndex}-${widgetIndex}` !== widgetId)
|
|
218
|
-
return widget
|
|
219
|
-
else this.$emit('remove', widget)
|
|
220
|
-
})
|
|
221
|
-
)
|
|
222
|
-
)
|
|
223
|
-
},
|
|
224
|
-
handleMouseEnter(e: Event) {
|
|
225
|
-
this.dragTarget = e.target as HTMLElement
|
|
226
|
-
this.dragSide.previous =
|
|
227
|
-
(e as MouseEvent).x - this.dragTarget.offsetLeft <
|
|
228
|
-
this.dragTarget.offsetWidth / 2
|
|
229
|
-
if (
|
|
230
|
-
!this.isDragging ||
|
|
231
|
-
!(this.modelValue[this.currentRow].length < 3)
|
|
232
|
-
)
|
|
233
|
-
return
|
|
234
|
-
|
|
235
|
-
e.target.addEventListener('mousemove', this.handleMouseMove)
|
|
236
|
-
e.target.addEventListener('mouseleave', (e: Event) => {
|
|
237
|
-
clearTimeout(this.timer)
|
|
238
|
-
e.target.removeEventListener('mousemove', this.handleMouseMove)
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
this.timer = window.setTimeout(() => {
|
|
242
|
-
this.rearrangeWidgets()
|
|
243
|
-
}, 700)
|
|
244
|
-
},
|
|
245
|
-
handleMouseMove(e: Event) {
|
|
246
|
-
this.dragSide.current =
|
|
247
|
-
(e as MouseEvent).x - this.dragTarget.offsetLeft <
|
|
248
|
-
this.dragTarget.offsetWidth / 2
|
|
249
|
-
if (this.dragSide.current !== this.dragSide.previous) {
|
|
250
|
-
clearTimeout(this.timer)
|
|
251
|
-
this.handleMouseEnter(e)
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
rearrangeWidgets() {
|
|
255
|
-
if (
|
|
256
|
-
!this.draggedWidgetId ||
|
|
257
|
-
Number(this.draggedWidgetId[0]) == this.currentRow
|
|
258
|
-
)
|
|
259
|
-
return
|
|
260
|
-
const newTargetRow = this.modelValue[this.currentRow]
|
|
261
|
-
const newSourceRow =
|
|
262
|
-
this.modelValue[Number(this.draggedWidgetId[0])]
|
|
263
|
-
newTargetRow.splice(
|
|
264
|
-
this.dragSide.previous
|
|
265
|
-
? this.currentItem
|
|
266
|
-
: this.currentItem + 1,
|
|
267
|
-
0,
|
|
268
|
-
this.draggedWidget
|
|
269
|
-
)
|
|
270
|
-
newSourceRow.splice(Number(this.draggedWidgetId[2]), 1)
|
|
271
|
-
const newWidgets = this.modelValue
|
|
272
|
-
newWidgets[this.currentRow] = newTargetRow
|
|
273
|
-
newWidgets[Number(this.draggedWidgetId[0])] = newSourceRow
|
|
274
|
-
this.isDragging = false
|
|
275
|
-
;(this.$refs.clone as HTMLElement).innerHTML = ''
|
|
276
|
-
this.$emit('update:model-value', newWidgets)
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
</script>
|
|
281
|
-
|
|
282
|
-
<style lang="scss" scoped>
|
|
283
|
-
.dl-widget-grid {
|
|
284
|
-
display: flex;
|
|
285
|
-
flex-direction: column;
|
|
286
|
-
|
|
287
|
-
&__row {
|
|
288
|
-
display: flex;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
&__clone {
|
|
292
|
-
position: absolute;
|
|
293
|
-
background-color: var(--dl-color-shadow);
|
|
294
|
-
outline: 1px solid var(--dl-color-separator);
|
|
295
|
-
visibility: hidden;
|
|
296
|
-
padding: 10px;
|
|
297
|
-
border-radius: 2px;
|
|
298
|
-
|
|
299
|
-
&--dragging {
|
|
300
|
-
visibility: visible;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
&__item {
|
|
305
|
-
transition: 0.05s;
|
|
306
|
-
user-select: none;
|
|
307
|
-
outline: 1px solid var(--dl-color-separator);
|
|
308
|
-
border-radius: 2px;
|
|
309
|
-
|
|
310
|
-
&--dragging {
|
|
311
|
-
&:hover {
|
|
312
|
-
background-color: var(--dl-color-fill);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
&--header {
|
|
317
|
-
display: flex;
|
|
318
|
-
justify-content: space-between;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
&--titles {
|
|
322
|
-
display: flex;
|
|
323
|
-
flex-direction: column;
|
|
324
|
-
width: 45%;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
&--menu {
|
|
328
|
-
width: 50%;
|
|
329
|
-
display: flex;
|
|
330
|
-
justify-content: flex-end;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
&--drag-icon {
|
|
334
|
-
transform: rotate(90deg);
|
|
335
|
-
margin-top: -30px;
|
|
336
|
-
cursor: grab;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
&--delete-icon {
|
|
340
|
-
cursor: pointer;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
&--content {
|
|
344
|
-
width: 100%;
|
|
345
|
-
margin-bottom: 20px;
|
|
346
|
-
margin-top: 20px;
|
|
347
|
-
color: var(--dl-color-darker);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
&--footer {
|
|
351
|
-
overflow: hidden;
|
|
352
|
-
text-overflow: ellipsis;
|
|
353
|
-
display: -webkit-box;
|
|
354
|
-
-webkit-line-clamp: 2;
|
|
355
|
-
-webkit-box-orient: vertical;
|
|
356
|
-
margin-top: auto;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
</style>
|
package/storybook.js
DELETED