@carbon/vue 3.0.21 → 3.0.22
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/dist/carbon-vue-3.common.js +686 -1162
- package/dist/carbon-vue-3.common.js.map +1 -1
- package/dist/carbon-vue-3.umd.js +686 -1162
- package/dist/carbon-vue-3.umd.js.map +1 -1
- package/dist/carbon-vue-3.umd.min.js +4 -4
- package/dist/carbon-vue-3.umd.min.js.map +1 -1
- package/dist/web-types.json +1 -1
- package/package.json +4 -4
- package/src/components/CvAspectRatio/CvAspectRatio.stories.js +2 -5
- package/src/components/CvBreadcrumb/CvBreadcrumb.stories.js +2 -5
- package/src/components/CvButton/CvButton.stories.js +1 -3
- package/src/components/CvButton/CvButtonSet.stories.js +2 -6
- package/src/components/CvButton/CvButtonSkeleton.stories.js +1 -3
- package/src/components/CvButton/CvIconButton.stories.js +1 -3
- package/src/components/CvCheckbox/CvCheckbox.stories.js +1 -2
- package/src/components/CvCodeSnippet/CvCodeSnippet.stories.js +1 -2
- package/src/components/CvComboBox/CvComboBox.stories.js +2 -5
- package/src/components/CvCopyButton/CvCopyButton.stories.js +2 -5
- package/src/components/CvDataTable/CvDataTable.stories.mdx +56 -9
- package/src/components/CvDataTable/CvDataTable.vue +71 -97
- package/src/components/CvDataTable/CvDataTableHeading.vue +25 -45
- package/src/components/CvDataTable/CvDataTableRow.vue +46 -50
- package/src/components/CvDataTable/_CvDataTableRowInner.vue +9 -18
- package/src/components/CvDatePicker/CvDatePicker.stories.js +2 -5
- package/src/components/CvDatePicker/CvDatePicker.vue +1 -1
- package/src/components/CvLink/CvLink.stories.js +1 -2
- package/src/components/CvList/CvList.stories.js +2 -5
- package/src/components/CvLoading/CvLoading.stories.js +2 -5
- package/src/components/CvMultiSelect/CvMultiSelect.vue +4 -1
- package/src/components/CvNotification/CvInlineNotification.stories.js +2 -2
- package/src/components/CvNotification/CvToastNotification.stories.js +2 -2
- package/src/components/CvNumberInput/CvNumberInput.stories.js +2 -6
- package/src/components/CvNumberInput/CvNumberInputSkeleton.stories.js +2 -6
- package/src/components/CvRadioButton/CvRadioButton.stories.js +2 -5
- package/src/components/CvSkeletonText/CvSkeletonText.stories.js +2 -5
- package/src/components/CvSlider/CvSlider.stories.js +2 -6
- package/src/components/CvSlider/CvSliderSkeleton.stories.js +2 -6
- package/src/components/CvStructuredList/CvStructuredList.stories.js +2 -5
- package/src/components/CvTag/CvTag.stories.js +2 -5
- package/src/components/CvTag/CvTagSkeleton.stories.js +2 -5
- package/src/components/CvTextArea/CvTextArea.stories.js +2 -6
- package/src/components/CvTextArea/CvTextAreaSkeleton.stories.js +2 -6
- package/src/components/CvTextInput/CvTextInput.stories.js +2 -5
- package/src/components/CvToggle/CvToggle.stories.js +2 -5
- package/src/components/CvTooltip/CvDefinitionTooltip.stories.js +2 -6
- package/src/components/CvTooltip/CvInteractiveTooltip.stories.js +2 -6
- package/src/components/CvTooltip/CvTooltip.stories.js +2 -6
- package/src/use/overflow.js +2 -2
- package/src/components/CvDataTable/cvDataTableStore.js +0 -314
package/dist/web-types.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/vue",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.22",
|
|
5
5
|
"description": "A collection of components for the Carbon Design System built using Vue.js",
|
|
6
6
|
"packageManager": "yarn@3.2.0",
|
|
7
7
|
"main": "dist/carbon-vue-3.umd.min.js",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
"copy-webpack-plugin": "^10.2.4",
|
|
62
62
|
"css-loader": "^6.7.2",
|
|
63
63
|
"eslint": "^8.28.0",
|
|
64
|
-
"eslint-plugin-prettier": "^
|
|
64
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
65
65
|
"eslint-plugin-vue": "^8.7.1",
|
|
66
66
|
"husky": "^7.0.4",
|
|
67
67
|
"jest": "^27.5.1",
|
|
68
68
|
"lerna": "^6.5.1",
|
|
69
69
|
"lint-staged": "^12.5.0",
|
|
70
70
|
"postcss": "^8.4.19",
|
|
71
|
-
"postcss-loader": "^
|
|
71
|
+
"postcss-loader": "^8.1.1",
|
|
72
72
|
"prettier": "^2.8.0",
|
|
73
73
|
"sass": "^1.56.1",
|
|
74
|
-
"sass-loader": "^
|
|
74
|
+
"sass-loader": "^16.0.2",
|
|
75
75
|
"storybook": "^6.5.13",
|
|
76
76
|
"style-loader": "^3.3.1",
|
|
77
77
|
"stylelint": "^14.15.0",
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { h } from 'vue';
|
|
2
|
-
import {
|
|
3
|
-
sbCompPrefix,
|
|
4
|
-
storyParametersObject,
|
|
5
|
-
} from '../../global/storybook-utils';
|
|
2
|
+
import { storyParametersObject } from '../../global/storybook-utils';
|
|
6
3
|
|
|
7
4
|
import { CvAspectRatio, CvAspectRatioConsts } from '.';
|
|
8
5
|
|
|
9
6
|
import './CvAspectRatio.stories.scss';
|
|
10
7
|
|
|
11
8
|
export default {
|
|
12
|
-
title:
|
|
9
|
+
title: 'Component/CvAspectRatio',
|
|
13
10
|
component: CvAspectRatio,
|
|
14
11
|
decorators: [
|
|
15
12
|
story => h('div', { class: 'aspect-ratio-story' }, story().render()),
|
|
@@ -5,13 +5,10 @@ import {
|
|
|
5
5
|
CvBreadcrumbSkeletonItem,
|
|
6
6
|
} from '.';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
sbCompPrefix,
|
|
10
|
-
storyParametersObject,
|
|
11
|
-
} from '../../global/storybook-utils';
|
|
8
|
+
import { storyParametersObject } from '../../global/storybook-utils';
|
|
12
9
|
|
|
13
10
|
export default {
|
|
14
|
-
title:
|
|
11
|
+
title: 'Component/CvBreadcrumb',
|
|
15
12
|
component: CvBreadcrumb,
|
|
16
13
|
argTypes: {
|
|
17
14
|
ariaLabel: {
|
|
@@ -2,12 +2,10 @@ import { action } from '@storybook/addon-actions';
|
|
|
2
2
|
import { CvButton } from './';
|
|
3
3
|
import { buttonKinds, buttonSizes } from './consts';
|
|
4
4
|
import {
|
|
5
|
-
sbCompPrefix,
|
|
6
5
|
splitSlotArgs,
|
|
7
6
|
storybookControlsFromProps,
|
|
8
7
|
storyParametersObject,
|
|
9
8
|
} from '../../global/storybook-utils';
|
|
10
|
-
import { sbBtnPrefix } from './sbBtnPrefix';
|
|
11
9
|
import { props as commonCvButtonProps } from './CvButtonCommon';
|
|
12
10
|
import {
|
|
13
11
|
Bee20,
|
|
@@ -28,7 +26,7 @@ const icons = {
|
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
export default {
|
|
31
|
-
title:
|
|
29
|
+
title: 'Component/CvButton',
|
|
32
30
|
component: CvButton,
|
|
33
31
|
argTypes: {
|
|
34
32
|
...storybookControlsFromProps(commonCvButtonProps),
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { CvButtonSet, CvButton } from './';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
sbCompPrefix,
|
|
5
|
-
storyParametersObject,
|
|
6
|
-
} from '../../global/storybook-utils';
|
|
7
|
-
import { sbBtnPrefix } from './sbBtnPrefix';
|
|
3
|
+
import { storyParametersObject } from '../../global/storybook-utils';
|
|
8
4
|
|
|
9
5
|
export default {
|
|
10
|
-
title:
|
|
6
|
+
title: 'Component/CvButtonSet',
|
|
11
7
|
component: CvButtonSet,
|
|
12
8
|
};
|
|
13
9
|
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { CvButtonSkeleton } from '.';
|
|
2
2
|
import { buttonSizes } from './consts.js';
|
|
3
3
|
import {
|
|
4
|
-
sbCompPrefix,
|
|
5
4
|
storybookControlsFromProps,
|
|
6
5
|
storyParametersObject,
|
|
7
6
|
} from '../../global/storybook-utils';
|
|
8
|
-
import { sbBtnPrefix } from './sbBtnPrefix';
|
|
9
7
|
|
|
10
8
|
import { props as commonCvButtonProps } from './CvButtonCommon';
|
|
11
9
|
|
|
12
10
|
export default {
|
|
13
|
-
title:
|
|
11
|
+
title: 'Component/CvButtonSkeleton',
|
|
14
12
|
component: CvButtonSkeleton,
|
|
15
13
|
argTypes: {
|
|
16
14
|
...storybookControlsFromProps({ size: commonCvButtonProps.size }),
|
|
@@ -2,12 +2,10 @@ import { action } from '@storybook/addon-actions';
|
|
|
2
2
|
import { CvIconButton } from './';
|
|
3
3
|
import { buttonKinds, buttonSizes } from './consts.js';
|
|
4
4
|
import {
|
|
5
|
-
sbCompPrefix,
|
|
6
5
|
storybookControlsFromProps,
|
|
7
6
|
storyParametersObject,
|
|
8
7
|
} from '../../global/storybook-utils';
|
|
9
8
|
import { TipAlignments } from '../CvTooltip/consts.js';
|
|
10
|
-
import { sbBtnPrefix } from './sbBtnPrefix';
|
|
11
9
|
|
|
12
10
|
import { props as commonCvButtonProps } from './CvButtonCommon';
|
|
13
11
|
import {
|
|
@@ -29,7 +27,7 @@ const icons = {
|
|
|
29
27
|
};
|
|
30
28
|
|
|
31
29
|
export default {
|
|
32
|
-
title:
|
|
30
|
+
title: 'Component/CvIconButton',
|
|
33
31
|
component: CvIconButton,
|
|
34
32
|
argTypes: {
|
|
35
33
|
...storybookControlsFromProps(commonCvButtonProps),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
sbCompPrefix,
|
|
3
2
|
storybookControlsFromProps,
|
|
4
3
|
storyParametersObject,
|
|
5
4
|
} from '../../global/storybook-utils';
|
|
@@ -10,7 +9,7 @@ import { props as propsCvCheck } from '../../use/cvCheck';
|
|
|
10
9
|
import { ref } from 'vue';
|
|
11
10
|
|
|
12
11
|
export default {
|
|
13
|
-
title:
|
|
12
|
+
title: 'Component/CvCheckbox',
|
|
14
13
|
component: CvCheckbox,
|
|
15
14
|
argTypes: {
|
|
16
15
|
...storybookControlsFromProps(propsCvCheck),
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { carbonPrefix } from '../../global/settings';
|
|
2
2
|
import {
|
|
3
|
-
sbCompPrefix,
|
|
4
3
|
splitSlotArgs,
|
|
5
4
|
storyParametersObject,
|
|
6
5
|
} from '../../global/storybook-utils';
|
|
@@ -12,7 +11,7 @@ import CvCodeSnippetConsts from './consts';
|
|
|
12
11
|
import './CvCodeSnippet.stories.scss';
|
|
13
12
|
|
|
14
13
|
export default {
|
|
15
|
-
title:
|
|
14
|
+
title: 'Component/CvCodeSnippet',
|
|
16
15
|
component: CvCodeSnippet,
|
|
17
16
|
argTypes: {
|
|
18
17
|
default: { control: { type: 'text' } },
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
sbCompPrefix,
|
|
3
|
-
storyParametersObject,
|
|
4
|
-
} from '../../global/storybook-utils';
|
|
1
|
+
import { storyParametersObject } from '../../global/storybook-utils';
|
|
5
2
|
|
|
6
3
|
import { CvComboBox } from '.';
|
|
7
4
|
import { action } from '@storybook/addon-actions';
|
|
@@ -41,7 +38,7 @@ const initArgs = {
|
|
|
41
38
|
};
|
|
42
39
|
|
|
43
40
|
export default {
|
|
44
|
-
title:
|
|
41
|
+
title: 'Component/CvComboBox',
|
|
45
42
|
component: CvComboBox,
|
|
46
43
|
parameters: {
|
|
47
44
|
a11y: {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import CvCopyButton from '.';
|
|
2
2
|
|
|
3
3
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import {
|
|
5
|
-
sbCompPrefix,
|
|
6
|
-
storyParametersObject,
|
|
7
|
-
} from '../../global/storybook-utils';
|
|
4
|
+
import { storyParametersObject } from '../../global/storybook-utils';
|
|
8
5
|
|
|
9
6
|
export default {
|
|
10
|
-
title:
|
|
7
|
+
title: 'Component/CvCopyButton',
|
|
11
8
|
component: CvCopyButton,
|
|
12
9
|
argTypes: {},
|
|
13
10
|
};
|
|
@@ -44,6 +44,7 @@ function searchTestData(opts) {
|
|
|
44
44
|
else testData.value = originalTestData.value.filter(data => data.name.indexOf(opts) > -1)
|
|
45
45
|
return sortTestData(sortOpts.value)
|
|
46
46
|
}
|
|
47
|
+
const selectedRows = ref(["COBOL"])
|
|
47
48
|
|
|
48
49
|
<Meta title={`${sbCompPrefix}/CvDataTable`} component={CvDataTable} />
|
|
49
50
|
|
|
@@ -75,6 +76,7 @@ setup() {
|
|
|
75
76
|
onRowSelectChange: action('row-select-change'),
|
|
76
77
|
onRowSelectChanges: action('row-select-changes'),
|
|
77
78
|
onOverflowMenuClick: action('overflow-menu-click'),
|
|
79
|
+
onVmodel: action('v-model'),
|
|
78
80
|
onRowExpanded: action('row-expanded'),
|
|
79
81
|
onPagination: action('pagination'),
|
|
80
82
|
onAction1: action('compile'),
|
|
@@ -84,13 +86,15 @@ setup() {
|
|
|
84
86
|
useActions: args.useActions,
|
|
85
87
|
useBatchActions: args.useBatchActions,
|
|
86
88
|
useHelperTextSlot: args.useHelperTextSlot,
|
|
89
|
+
usePagination: args.usePagination,
|
|
87
90
|
skeletonRows: args.skeletonRows,
|
|
88
91
|
skeletonCols: args.skeletonCols,
|
|
89
92
|
skeletonTitle: args.title,
|
|
90
93
|
skeletonHelper: args.helperText,
|
|
91
94
|
testData,
|
|
92
95
|
originalTestData,
|
|
93
|
-
searchOpts
|
|
96
|
+
searchOpts,
|
|
97
|
+
selectedRows
|
|
94
98
|
};
|
|
95
99
|
},
|
|
96
100
|
// And then the `args` are bound to your component with `v-bind="args"`
|
|
@@ -105,6 +109,7 @@ const defaultTemplate = `
|
|
|
105
109
|
@overflow-menu-click="onOverflowMenuClick"
|
|
106
110
|
@row-expanded="onRowExpanded"
|
|
107
111
|
@pagination="onPagination"
|
|
112
|
+
:pagination="usePagination"
|
|
108
113
|
:initialSearchValue="searchOpts"
|
|
109
114
|
>
|
|
110
115
|
<template v-if="useBatchActions" #batch-actions>
|
|
@@ -128,14 +133,14 @@ const defaultTemplate = `
|
|
|
128
133
|
</cv-data-table-action>
|
|
129
134
|
</template>
|
|
130
135
|
<template #headings>
|
|
131
|
-
<cv-data-table-heading heading="Name" name="name" sortable/>
|
|
132
|
-
<cv-data-table-heading heading="Year" name="year" sortable/>
|
|
133
|
-
<cv-data-table-heading heading="Object Oriented"/>
|
|
134
|
-
<cv-data-table-heading heading="Purpose" />
|
|
135
|
-
<cv-data-table-heading heading="Standard" />
|
|
136
|
+
<cv-data-table-heading id="sb-name" heading="Name" name="name" sortable order="ascending"/>
|
|
137
|
+
<cv-data-table-heading id="sb-year" heading="Year" name="year" sortable/>
|
|
138
|
+
<cv-data-table-heading id="sb-oo" heading="Object Oriented"/>
|
|
139
|
+
<cv-data-table-heading id="sb-purpose" heading="Purpose" />
|
|
140
|
+
<cv-data-table-heading id="sb-standard" heading="Standard" />
|
|
136
141
|
</template>
|
|
137
142
|
<template #data>
|
|
138
|
-
<cv-data-table-row v-for="row in testData" :key="row.name" :value="row.name">
|
|
143
|
+
<cv-data-table-row v-for="row in testData" :id="row.name" :key="row.name" :value="row.name">
|
|
139
144
|
<cv-data-table-cell>{{row.name}}</cv-data-table-cell>
|
|
140
145
|
<cv-data-table-cell>{{row.year}}</cv-data-table-cell>
|
|
141
146
|
<cv-data-table-cell>{{row.oo}}</cv-data-table-cell>
|
|
@@ -169,6 +174,17 @@ const skeletonTemplate = `
|
|
|
169
174
|
</template>
|
|
170
175
|
</cv-data-table-skeleton>
|
|
171
176
|
`;
|
|
177
|
+
const vModelTemplate = defaultTemplate
|
|
178
|
+
.replace('@search="onSearch"', 'v-model:rows-selected="selectedRows"')
|
|
179
|
+
.replace('@row-select-change="onRowSelectChange"', '@update:rows-selected="onVmodel"')
|
|
180
|
+
.replace('@row-select-changes="onRowSelectChanges"','')
|
|
181
|
+
.replace('testData', 'originalTestData') + `
|
|
182
|
+
<div style="margin-top:1rem; background-color: #888888; padding:1rem"><div style="font-size: 150%">Sample interaction</div>
|
|
183
|
+
<select name="programming-languages" id="programming-languages" v-model="selectedRows" multiple>
|
|
184
|
+
<option v-for="l in originalTestData" :id="l.name" :key="l.name" :value="l.name">{{l.name}}</option>
|
|
185
|
+
</select>
|
|
186
|
+
<div>selections: {{ selectedRows }} </div>
|
|
187
|
+
</div>`
|
|
172
188
|
|
|
173
189
|
# CvDataTable
|
|
174
190
|
|
|
@@ -251,10 +267,12 @@ when no items were select, please now use the new property `stickyBatchActive`.
|
|
|
251
267
|
helperText: 'Table helper text',
|
|
252
268
|
useActions: false,
|
|
253
269
|
useBatchActions: false,
|
|
270
|
+
usePagination: true
|
|
254
271
|
}}
|
|
255
272
|
argTypes={{
|
|
256
273
|
rowSize: { control: 'select', default: 'lg', options: ['xs', 'sm', 'md', 'lg', 'xl'] },
|
|
257
274
|
rowsSelected: { control: 'multi-select', options: ['Java', 'COBOL', 'C++'] },
|
|
275
|
+
useBatchActions: { description: "To use batch actions you should assign a usable `id` to each row. i.e. `<cv-data-table-row :id=\"item.id\" ...` This `id` value is passed to the row selection events." }
|
|
258
276
|
}}
|
|
259
277
|
>
|
|
260
278
|
{Template.bind({})}
|
|
@@ -268,7 +286,6 @@ when no items were select, please now use the new property `stickyBatchActive`.
|
|
|
268
286
|
controls: { exclude: ['default',
|
|
269
287
|
'template',
|
|
270
288
|
'overflow-menu-click',
|
|
271
|
-
'pagination',
|
|
272
289
|
'row-expanded',
|
|
273
290
|
'row-select-change',
|
|
274
291
|
'row-select-changes',
|
|
@@ -293,6 +310,7 @@ when no items were select, please now use the new property `stickyBatchActive`.
|
|
|
293
310
|
helperText: 'Click row to expand',
|
|
294
311
|
useActions: false,
|
|
295
312
|
useBatchActions: false,
|
|
313
|
+
usePagination: true
|
|
296
314
|
}}
|
|
297
315
|
argTypes={{
|
|
298
316
|
rowSize: { control: 'select', default: 'standard', options: ['compact', 'short', 'standard', 'tall'] },
|
|
@@ -319,7 +337,36 @@ when no items were select, please now use the new property `stickyBatchActive`.
|
|
|
319
337
|
skeletonRows: 5,
|
|
320
338
|
skeletonCols: 5,
|
|
321
339
|
useBatchActions: false,
|
|
322
|
-
useActions: false
|
|
340
|
+
useActions: false,
|
|
341
|
+
usePagination: true
|
|
342
|
+
}}
|
|
343
|
+
argTypes={{
|
|
344
|
+
}}
|
|
345
|
+
>
|
|
346
|
+
{Template.bind({})}
|
|
347
|
+
</Story>
|
|
348
|
+
</Canvas>
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
# Using v-model selected rows
|
|
352
|
+
If you are using the selected rows for batch actions or any other purpose, you should assign usable values to the rows.
|
|
353
|
+
It is these values that are included in the selected rows events and in the selected rows v-model. Set the v-model on the
|
|
354
|
+
cv-table like `<cv-table v-model:rows-selected="selectedRows" ...`
|
|
355
|
+
|
|
356
|
+
<Canvas>
|
|
357
|
+
<Story
|
|
358
|
+
name="v-model Selected Rows"
|
|
359
|
+
parameters={{
|
|
360
|
+
controls: { include: [ ] },
|
|
361
|
+
docs: { source: { code: storySourceCode(vModelTemplate, Template.args) } },
|
|
362
|
+
}}
|
|
363
|
+
args={{
|
|
364
|
+
template: vModelTemplate,
|
|
365
|
+
title: 'v-model example',
|
|
366
|
+
helperText: 'select rows to see updates',
|
|
367
|
+
useBatchActions: true,
|
|
368
|
+
useActions: false,
|
|
369
|
+
usePagination: false
|
|
323
370
|
}}
|
|
324
371
|
argTypes={{
|
|
325
372
|
}}
|
|
@@ -236,11 +236,9 @@ import CvPagination from '../CvPagination';
|
|
|
236
236
|
import Search16 from '@carbon/icons-vue/es/search/16';
|
|
237
237
|
import Close16 from '@carbon/icons-vue/es/close/16';
|
|
238
238
|
import ChevronRight16 from '@carbon/icons-vue/es/chevron--right/16';
|
|
239
|
-
import { getBus, removeBus } from '../../global/component-utils/event-bus';
|
|
240
239
|
import {
|
|
241
240
|
computed,
|
|
242
241
|
nextTick,
|
|
243
|
-
onBeforeMount,
|
|
244
242
|
onMounted,
|
|
245
243
|
onUnmounted,
|
|
246
244
|
onUpdated,
|
|
@@ -251,8 +249,6 @@ import {
|
|
|
251
249
|
provide,
|
|
252
250
|
} from 'vue';
|
|
253
251
|
import { props as propsCvId, useCvId } from '../../use/cvId';
|
|
254
|
-
//TODO: Remove this store and replace with provide/inject
|
|
255
|
-
import store from './cvDataTableStore';
|
|
256
252
|
import Empty from '../CvEmpty/_CvEmpty.vue';
|
|
257
253
|
|
|
258
254
|
const props = defineProps({
|
|
@@ -356,20 +352,6 @@ watch(
|
|
|
356
352
|
() => (isSkeleton.value = props.skeleton)
|
|
357
353
|
);
|
|
358
354
|
|
|
359
|
-
let bus = undefined;
|
|
360
|
-
onBeforeMount(() => {
|
|
361
|
-
bus = getBus(uid.value);
|
|
362
|
-
bus.on('cv:check-change', onRowCheckChange);
|
|
363
|
-
bus.on('cv:click', onMenuItemClick);
|
|
364
|
-
bus.on('cv:sort', onSort);
|
|
365
|
-
bus.on('cv:expanded-change', onCvExpandedChange);
|
|
366
|
-
store.addTable(uid);
|
|
367
|
-
});
|
|
368
|
-
onUnmounted(() => {
|
|
369
|
-
removeBus(uid.value);
|
|
370
|
-
store.removeTable(uid.value);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
355
|
watch(() => props.rowsSelected, updateRowsSelected);
|
|
374
356
|
|
|
375
357
|
const searchContainer = ref(null);
|
|
@@ -393,6 +375,7 @@ watch(
|
|
|
393
375
|
else expandingRowIds.value.delete('table-expand-row');
|
|
394
376
|
}
|
|
395
377
|
);
|
|
378
|
+
const clearSearchVisible = ref(false);
|
|
396
379
|
|
|
397
380
|
onMounted(() => {
|
|
398
381
|
if (searchContainer.value) {
|
|
@@ -416,6 +399,8 @@ onUpdated(checkSlots);
|
|
|
416
399
|
const hasActions = ref(false);
|
|
417
400
|
const hasToolbar = ref(false);
|
|
418
401
|
const hasBatchActions = ref(false);
|
|
402
|
+
const isHelper = ref(false);
|
|
403
|
+
|
|
419
404
|
provide('has-batch-actions', hasBatchActions);
|
|
420
405
|
|
|
421
406
|
function checkSlots() {
|
|
@@ -442,9 +427,11 @@ function columnHeading(c) {
|
|
|
442
427
|
}
|
|
443
428
|
}
|
|
444
429
|
|
|
430
|
+
const sortableHeadings = ref(new Set());
|
|
431
|
+
provide('sortableHeadings', sortableHeadings);
|
|
445
432
|
const isSortable = computed(() => {
|
|
446
433
|
// is any column sortable
|
|
447
|
-
return props.sortable ||
|
|
434
|
+
return props.sortable || sortableHeadings.value.size > 0;
|
|
448
435
|
});
|
|
449
436
|
|
|
450
437
|
function isColSortable(c) {
|
|
@@ -453,7 +440,6 @@ function isColSortable(c) {
|
|
|
453
440
|
return (col && col.sortable) || props.sortable;
|
|
454
441
|
}
|
|
455
442
|
|
|
456
|
-
const isHelper = ref(false);
|
|
457
443
|
const hasTableHeader = computed(() => {
|
|
458
444
|
return props.title || isHelper.value;
|
|
459
445
|
});
|
|
@@ -482,13 +468,15 @@ const internalPagination = computed(() => {
|
|
|
482
468
|
return false;
|
|
483
469
|
});
|
|
484
470
|
|
|
485
|
-
const
|
|
471
|
+
const rowIds = ref(new Set());
|
|
472
|
+
provide('row-ids', rowIds);
|
|
473
|
+
|
|
486
474
|
const internalNumberOfItems = computed(() => {
|
|
487
475
|
const internal = internalPagination.value;
|
|
488
476
|
if (internal.numberOfItems !== undefined) {
|
|
489
477
|
return internal.numberOfItems;
|
|
490
478
|
} else {
|
|
491
|
-
return
|
|
479
|
+
return rowIds.value.size;
|
|
492
480
|
}
|
|
493
481
|
});
|
|
494
482
|
|
|
@@ -527,38 +515,29 @@ function checkSearchExpand(force) {
|
|
|
527
515
|
}
|
|
528
516
|
|
|
529
517
|
const dataRowsSelected = ref(props.rowsSelected);
|
|
530
|
-
|
|
531
|
-
return (
|
|
532
|
-
props.stickyBatchActive ||
|
|
533
|
-
dataRowsSelected.value.length > 0 ||
|
|
534
|
-
headingChecked.value
|
|
535
|
-
);
|
|
536
|
-
});
|
|
518
|
+
provide('rows-selected', dataRowsSelected);
|
|
537
519
|
|
|
538
520
|
const headingChecked = ref(false);
|
|
539
|
-
|
|
540
521
|
watch(
|
|
541
|
-
() =>
|
|
522
|
+
() => dataRowsSelected,
|
|
542
523
|
() => {
|
|
543
|
-
const rows = store.rows(uid);
|
|
544
524
|
headingChecked.value =
|
|
545
|
-
|
|
525
|
+
rowIds.value.size > 0 &&
|
|
526
|
+
dataRowsSelected.value.length === rowIds.value.size;
|
|
546
527
|
},
|
|
547
528
|
{ deep: true }
|
|
548
529
|
);
|
|
530
|
+
|
|
531
|
+
const batchActive = computed(() => {
|
|
532
|
+
return (
|
|
533
|
+
props.stickyBatchActive ||
|
|
534
|
+
dataRowsSelected.value.length > 0 ||
|
|
535
|
+
headingChecked.value
|
|
536
|
+
);
|
|
537
|
+
});
|
|
538
|
+
|
|
549
539
|
function updateRowsSelected() {
|
|
550
|
-
dataRowsSelected.value = [];
|
|
551
|
-
const rows = store.rows(uid);
|
|
552
|
-
for (const i in rows) {
|
|
553
|
-
let child = rows[i];
|
|
554
|
-
const checked = props.rowsSelected.includes(child.value);
|
|
555
|
-
store.updateRow(uid, { id: child.id, isChecked: checked });
|
|
556
|
-
|
|
557
|
-
if (checked) {
|
|
558
|
-
dataRowsSelected.value.push(child.value);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
headingChecked.value = dataRowsSelected.value.length === rows.length;
|
|
540
|
+
dataRowsSelected.value = [...props.rowsSelected];
|
|
562
541
|
}
|
|
563
542
|
|
|
564
543
|
const emit = defineEmits([
|
|
@@ -572,7 +551,6 @@ const emit = defineEmits([
|
|
|
572
551
|
'pagination',
|
|
573
552
|
]);
|
|
574
553
|
const searchValue = ref(props.initialSearchValue);
|
|
575
|
-
const clearSearchVisible = ref(false);
|
|
576
554
|
function onClearClick() {
|
|
577
555
|
searchValue.value = '';
|
|
578
556
|
clearSearchVisible.value = false;
|
|
@@ -584,87 +562,83 @@ function onClearClick() {
|
|
|
584
562
|
}
|
|
585
563
|
function onHeadingCheckChange() {
|
|
586
564
|
// check /uncheck all children
|
|
587
|
-
dataRowsSelected.value = [];
|
|
588
|
-
|
|
589
|
-
for (const child of rows) {
|
|
590
|
-
if (headingChecked.value) {
|
|
591
|
-
dataRowsSelected.value.push(child.value);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
if (child.isChecked !== headingChecked.value) {
|
|
595
|
-
store.updateRow(uid, { id: child.id, isChecked: headingChecked.value });
|
|
596
|
-
|
|
597
|
-
emit('row-select-change', {
|
|
598
|
-
value: child.value,
|
|
599
|
-
selected: headingChecked.value,
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
emit('row-select-changes', dataRowsSelected.value);
|
|
604
|
-
emit('update:rowsSelected', dataRowsSelected.value);
|
|
565
|
+
if (headingChecked.value) dataRowsSelected.value = [...rowIds.value];
|
|
566
|
+
else dataRowsSelected.value = [];
|
|
605
567
|
}
|
|
606
568
|
function deselect() {
|
|
607
569
|
headingChecked.value = false;
|
|
608
570
|
onHeadingCheckChange();
|
|
609
571
|
}
|
|
610
|
-
function onRowCheckChange(payload) {
|
|
611
|
-
const { value, checked } = payload;
|
|
612
|
-
let modelSet = new Set(dataRowsSelected.value);
|
|
613
|
-
|
|
614
|
-
if (!checked) {
|
|
615
|
-
modelSet.delete(value);
|
|
616
|
-
} else {
|
|
617
|
-
modelSet.add(value);
|
|
618
|
-
}
|
|
619
|
-
dataRowsSelected.value = Array.from(modelSet);
|
|
620
|
-
const rows = store.rows(uid);
|
|
621
|
-
headingChecked.value = dataRowsSelected.value.length === rows.length;
|
|
622
572
|
|
|
573
|
+
const previousEmit = ref([...props.rowsSelected]);
|
|
574
|
+
watch(
|
|
575
|
+
dataRowsSelected,
|
|
576
|
+
() => {
|
|
577
|
+
// was tempted to use Set.symmetricDifference but support for that was only
|
|
578
|
+
// add in Feb/June 2024
|
|
579
|
+
const diff = dataRowsSelected.value
|
|
580
|
+
.filter(x => !previousEmit.value.includes(x))
|
|
581
|
+
.concat(
|
|
582
|
+
previousEmit.value.filter(x => !dataRowsSelected.value.includes(x))
|
|
583
|
+
);
|
|
584
|
+
if (diff.length > 0) {
|
|
585
|
+
emit('row-select-changes', dataRowsSelected.value);
|
|
586
|
+
emit('update:rowsSelected', dataRowsSelected.value);
|
|
587
|
+
previousEmit.value = [...dataRowsSelected.value];
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
{ deep: true }
|
|
591
|
+
);
|
|
592
|
+
function onRowCheckChange(value, checked) {
|
|
623
593
|
emit('row-select-change', { value, selected: checked });
|
|
624
|
-
emit('row-select-changes', dataRowsSelected.value);
|
|
625
|
-
emit('update:rowsSelected', dataRowsSelected.value);
|
|
626
594
|
}
|
|
595
|
+
provide('cv:check-change', onRowCheckChange);
|
|
596
|
+
|
|
627
597
|
function onMenuItemClick(val) {
|
|
628
598
|
emit('overflow-menu-click', val);
|
|
629
599
|
}
|
|
600
|
+
provide('cv:click', onMenuItemClick);
|
|
601
|
+
|
|
630
602
|
function onInternalSearch() {
|
|
631
603
|
clearSearchVisible.value = searchValue.value.length > 0;
|
|
632
604
|
// eslint-disable-next-line vue/require-explicit-emits
|
|
633
605
|
emit('search', searchValue.value);
|
|
634
606
|
}
|
|
607
|
+
|
|
608
|
+
const headingIds = ref(new Set());
|
|
609
|
+
provide('heading-ids', headingIds);
|
|
610
|
+
const currentSortHeadingId = ref(null);
|
|
611
|
+
provide('current-sort-heading-id', currentSortHeadingId);
|
|
635
612
|
function onSort(payload) {
|
|
636
613
|
const { heading, value } = payload;
|
|
637
|
-
const headings =
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
const column = headings[colIndex];
|
|
641
|
-
if (column.id === heading.id) {
|
|
642
|
-
store.updateHeading(uid, { ...column, order: value });
|
|
643
|
-
index = colIndex;
|
|
644
|
-
} else {
|
|
645
|
-
store.updateHeading(uid, { ...column, order: 'none' });
|
|
646
|
-
}
|
|
647
|
-
}
|
|
614
|
+
const headings = Array.from(headingIds.value);
|
|
615
|
+
currentSortHeadingId.value = heading.id;
|
|
616
|
+
const index = headings.indexOf(heading.id);
|
|
648
617
|
emit('sort', { index, order: value, name: heading.name });
|
|
649
618
|
}
|
|
619
|
+
provide('cv:sort', onSort);
|
|
650
620
|
|
|
651
621
|
// are all rows expanded
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
622
|
+
/** @type {Ref<Set<String>>} */
|
|
623
|
+
const expandedRowIds = ref(new Set());
|
|
624
|
+
provide('expanded-row-ids', expandedRowIds);
|
|
625
|
+
|
|
626
|
+
const dataExpandAll = computed(
|
|
627
|
+
() => expandedRowIds.value.size === rowIds.value.size
|
|
628
|
+
);
|
|
655
629
|
function toggleExpandAll() {
|
|
656
630
|
const toggle = !dataExpandAll.value;
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
631
|
+
if (toggle) {
|
|
632
|
+
rowIds.value.forEach(rowId => expandedRowIds.value.add(rowId));
|
|
633
|
+
} else expandedRowIds.value.clear();
|
|
661
634
|
}
|
|
662
635
|
|
|
663
636
|
/**
|
|
664
637
|
* A child row is changed
|
|
665
|
-
* @param {{
|
|
638
|
+
* @param {{id:string, value:string, expandable:string, isExpanded:boolean, isChecked:boolean}} row
|
|
666
639
|
*/
|
|
667
640
|
function onCvExpandedChange(row) {
|
|
668
641
|
emit('row-expanded', row);
|
|
669
642
|
}
|
|
643
|
+
provide('cv:expanded-change', onCvExpandedChange);
|
|
670
644
|
</script>
|