aloha-vue 2.59.0 → 2.60.0
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/CHANGELOG.md +4 -0
- package/dist/aloha-vue.css +5 -0
- package/dist/aloha-vue.css.map +1 -1
- package/dist/aloha-vue.es.js +9554 -9521
- package/dist/aloha-vue.umd.js +45 -43
- package/package.json +1 -1
- package/scss/components/ATableForm.scss +261 -256
- package/src/ATableForm/ATableForm.js +613 -606
- package/src/ATableForm/ATableFormCellDnd/ATableFormCellDnd.js +182 -176
- package/src/ATableForm/__tests__/ATableForm.DragAndDropAPI.test.js +162 -0
- package/src/ATableForm/compositionAPI/DragAndDropAPI.js +302 -268
- package/src/ATableForm/compositionAPI/TextsAPI.js +35 -34
- package/src/ATableForm/i18n/ar.json +18 -17
- package/src/ATableForm/i18n/de.json +18 -17
- package/src/ATableForm/i18n/en.json +18 -17
- package/src/ATableForm/i18n/es.json +18 -17
- package/src/ATableForm/i18n/fr.json +18 -17
- package/src/ATableForm/i18n/hr.json +18 -17
- package/src/ATableForm/i18n/it.json +18 -17
- package/src/ATableForm/i18n/ru.json +18 -17
|
@@ -1,176 +1,182 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computed,
|
|
3
|
-
h,
|
|
4
|
-
} from "vue";
|
|
5
|
-
|
|
6
|
-
import AButton from "../../AButton/AButton";
|
|
7
|
-
import AIcon from "../../AIcon/AIcon";
|
|
8
|
-
import ATranslation from "../../ATranslation/ATranslation";
|
|
9
|
-
|
|
10
|
-
import IdAPI from "./compositionAPI/IdAPI";
|
|
11
|
-
|
|
12
|
-
import ChevronDown from "aloha-svg/dist/js/bootstrap/ChevronDown";
|
|
13
|
-
import ChevronUp from "aloha-svg/dist/js/bootstrap/ChevronUp";
|
|
14
|
-
import GripVertical from "aloha-svg/dist/js/bootstrap/GripVertical";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
h,
|
|
4
|
+
} from "vue";
|
|
5
|
+
|
|
6
|
+
import AButton from "../../AButton/AButton";
|
|
7
|
+
import AIcon from "../../AIcon/AIcon";
|
|
8
|
+
import ATranslation from "../../ATranslation/ATranslation";
|
|
9
|
+
|
|
10
|
+
import IdAPI from "./compositionAPI/IdAPI";
|
|
11
|
+
|
|
12
|
+
import ChevronDown from "aloha-svg/dist/js/bootstrap/ChevronDown";
|
|
13
|
+
import ChevronUp from "aloha-svg/dist/js/bootstrap/ChevronUp";
|
|
14
|
+
import GripVertical from "aloha-svg/dist/js/bootstrap/GripVertical";
|
|
15
|
+
import LockFill from "aloha-svg/dist/js/bootstrap/LockFill";
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: "ATableFormCellDnd",
|
|
19
|
+
props: {
|
|
20
|
+
canMoveRowDown: {
|
|
21
|
+
type: Function,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
canMoveRowUp: {
|
|
25
|
+
type: Function,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
id: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
isCreateMode: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
required: false,
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
isDragAndDrop: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
required: false,
|
|
40
|
+
default: false,
|
|
41
|
+
},
|
|
42
|
+
isDndDisabled: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
required: false,
|
|
45
|
+
default: false,
|
|
46
|
+
},
|
|
47
|
+
isFooter: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
required: false,
|
|
50
|
+
default: false,
|
|
51
|
+
},
|
|
52
|
+
isHeader: {
|
|
53
|
+
type: Boolean,
|
|
54
|
+
required: false,
|
|
55
|
+
default: false,
|
|
56
|
+
},
|
|
57
|
+
moveRowDown: {
|
|
58
|
+
type: Function,
|
|
59
|
+
required: true,
|
|
60
|
+
},
|
|
61
|
+
moveRowUp: {
|
|
62
|
+
type: Function,
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
onDragend: {
|
|
66
|
+
type: Function,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
onDragstart: {
|
|
70
|
+
type: Function,
|
|
71
|
+
required: true,
|
|
72
|
+
},
|
|
73
|
+
rowIndex: {
|
|
74
|
+
type: Number,
|
|
75
|
+
required: true,
|
|
76
|
+
},
|
|
77
|
+
texts: {
|
|
78
|
+
type: Object,
|
|
79
|
+
required: false,
|
|
80
|
+
default: () => ({}),
|
|
81
|
+
},
|
|
82
|
+
widths: {
|
|
83
|
+
type: Object,
|
|
84
|
+
required: false,
|
|
85
|
+
default: () => ({}),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
setup(props) {
|
|
89
|
+
const {
|
|
90
|
+
idBtnDown,
|
|
91
|
+
idBtnUp,
|
|
92
|
+
} = IdAPI(props);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
columnStyles: computed(() => ({
|
|
96
|
+
maxWidth: `${ props.widths.dndColumn }px`,
|
|
97
|
+
minWidth: `${ props.widths.dndColumn }px`,
|
|
98
|
+
width: `${ props.widths.dndColumn }px`,
|
|
99
|
+
})),
|
|
100
|
+
idBtnDown,
|
|
101
|
+
idBtnUp,
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
render() {
|
|
105
|
+
const tag = this.isHeader ? "th" : "td";
|
|
106
|
+
const isHandleDraggable = this.isDragAndDrop && !this.isDndDisabled;
|
|
107
|
+
|
|
108
|
+
return h(tag, {
|
|
109
|
+
class: [
|
|
110
|
+
"a_table_form__cell",
|
|
111
|
+
`a_table_form__cell_${ tag }`,
|
|
112
|
+
"a_table_form__cell_reorder",
|
|
113
|
+
],
|
|
114
|
+
style: this.columnStyles,
|
|
115
|
+
}, [
|
|
116
|
+
this.isHeader ?
|
|
117
|
+
h("span", {
|
|
118
|
+
class: "a_sr_only",
|
|
119
|
+
}, [
|
|
120
|
+
h(ATranslation, {
|
|
121
|
+
tag: "span",
|
|
122
|
+
text: this.texts.reorderColumn,
|
|
123
|
+
}),
|
|
124
|
+
]) :
|
|
125
|
+
this.isCreateMode ?
|
|
126
|
+
null :
|
|
127
|
+
this.isFooter ?
|
|
128
|
+
null :
|
|
129
|
+
h("div", {
|
|
130
|
+
class: "a_table_form__reorder_actions",
|
|
131
|
+
}, [
|
|
132
|
+
this.canMoveRowUp(this.rowIndex) && h(AButton, {
|
|
133
|
+
id: this.idBtnUp,
|
|
134
|
+
class: "a_sr_only_focusable a_btn a_btn_transparent_dark a_table_form__reorder_button",
|
|
135
|
+
disabled: this.isDndDisabled,
|
|
136
|
+
iconLeft: ChevronUp,
|
|
137
|
+
preventKeyboardRepeat: true,
|
|
138
|
+
tabindex: this.isDndDisabled ? -1 : undefined,
|
|
139
|
+
title: this.texts.reorderUp,
|
|
140
|
+
textScreenReader: this.texts.reorderUp,
|
|
141
|
+
onClick: () => this.moveRowUp(this.rowIndex),
|
|
142
|
+
}),
|
|
143
|
+
h("span", {
|
|
144
|
+
ariaHidden: true,
|
|
145
|
+
class: [
|
|
146
|
+
"a_table_form__reorder_handle",
|
|
147
|
+
{
|
|
148
|
+
a_table_form__reorder_handle_disabled: this.isDndDisabled,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
draggable: isHandleDraggable,
|
|
152
|
+
onDragend: isHandleDraggable ? this.onDragend : undefined,
|
|
153
|
+
onDragstart: isHandleDraggable ? ($event => this.onDragstart($event, this.rowIndex)) : undefined,
|
|
154
|
+
}, [
|
|
155
|
+
h(AIcon, {
|
|
156
|
+
class: "a_table_form__reorder_icon",
|
|
157
|
+
icon: this.isDndDisabled ? LockFill : GripVertical,
|
|
158
|
+
}),
|
|
159
|
+
]),
|
|
160
|
+
h("span", {
|
|
161
|
+
class: "a_sr_only",
|
|
162
|
+
}, [
|
|
163
|
+
h(ATranslation, {
|
|
164
|
+
tag: "span",
|
|
165
|
+
text: this.isDndDisabled ? this.texts.reorderDisabled : this.texts.reorderHandle,
|
|
166
|
+
}),
|
|
167
|
+
]),
|
|
168
|
+
this.canMoveRowDown(this.rowIndex) && h(AButton, {
|
|
169
|
+
id: this.idBtnDown,
|
|
170
|
+
class: "a_sr_only_focusable a_btn a_btn_transparent_dark a_table_form__reorder_button",
|
|
171
|
+
disabled: this.isDndDisabled,
|
|
172
|
+
iconLeft: ChevronDown,
|
|
173
|
+
preventKeyboardRepeat: true,
|
|
174
|
+
tabindex: this.isDndDisabled ? -1 : undefined,
|
|
175
|
+
title: this.texts.reorderDown,
|
|
176
|
+
textScreenReader: this.texts.reorderDown,
|
|
177
|
+
onClick: () => this.moveRowDown(this.rowIndex),
|
|
178
|
+
}),
|
|
179
|
+
]),
|
|
180
|
+
]);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
reactive,
|
|
4
|
+
} from "vue";
|
|
5
|
+
import {
|
|
6
|
+
describe,
|
|
7
|
+
expect,
|
|
8
|
+
it,
|
|
9
|
+
jest,
|
|
10
|
+
} from "@jest/globals";
|
|
11
|
+
import {
|
|
12
|
+
mount,
|
|
13
|
+
} from "@vue/test-utils";
|
|
14
|
+
|
|
15
|
+
import AIcon from "../../AIcon/AIcon";
|
|
16
|
+
import ATableFormCellDnd from "../ATableFormCellDnd/ATableFormCellDnd";
|
|
17
|
+
|
|
18
|
+
import DragAndDropAPI from "../compositionAPI/DragAndDropAPI";
|
|
19
|
+
|
|
20
|
+
import LockFill from "aloha-svg/dist/js/bootstrap/LockFill";
|
|
21
|
+
|
|
22
|
+
jest.mock("../../AButton/AButton", () => {
|
|
23
|
+
const {
|
|
24
|
+
h,
|
|
25
|
+
} = require("vue");
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
__esModule: true,
|
|
29
|
+
default: {
|
|
30
|
+
name: "AButton",
|
|
31
|
+
inheritAttrs: false,
|
|
32
|
+
props: {
|
|
33
|
+
disabled: Boolean,
|
|
34
|
+
textScreenReader: String,
|
|
35
|
+
},
|
|
36
|
+
render() {
|
|
37
|
+
return h("button", {
|
|
38
|
+
disabled: this.disabled,
|
|
39
|
+
}, this.textScreenReader);
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
jest.mock("aloha-svg/dist/js/bootstrap/ChevronDown", () => ({
|
|
45
|
+
__esModule: true,
|
|
46
|
+
default: "ChevronDown",
|
|
47
|
+
}));
|
|
48
|
+
jest.mock("aloha-svg/dist/js/bootstrap/ChevronUp", () => ({
|
|
49
|
+
__esModule: true,
|
|
50
|
+
default: "ChevronUp",
|
|
51
|
+
}));
|
|
52
|
+
jest.mock("aloha-svg/dist/js/bootstrap/GripVertical", () => ({
|
|
53
|
+
__esModule: true,
|
|
54
|
+
default: "GripVertical",
|
|
55
|
+
}));
|
|
56
|
+
jest.mock("aloha-svg/dist/js/bootstrap/LockFill", () => ({
|
|
57
|
+
__esModule: true,
|
|
58
|
+
default: "LockFill",
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
describe("ATableForm DragAndDropAPI", () => {
|
|
62
|
+
it("prevents dragging, dropping on, and moving across a disabled row", () => {
|
|
63
|
+
const emit = jest.fn();
|
|
64
|
+
const props = reactive({
|
|
65
|
+
dndDisabledCallback: ({ row }) => row.dndDisabled,
|
|
66
|
+
focusAfterMove: false,
|
|
67
|
+
id: "table",
|
|
68
|
+
isDragAndDrop: true,
|
|
69
|
+
rows: [
|
|
70
|
+
{ id: 1 },
|
|
71
|
+
{ dndDisabled: true, id: 2 },
|
|
72
|
+
{ id: 3 },
|
|
73
|
+
{ id: 4 },
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
const {
|
|
77
|
+
draggedRowIndex,
|
|
78
|
+
isDndDisabledForRow,
|
|
79
|
+
moveRowDown,
|
|
80
|
+
onDragover,
|
|
81
|
+
onDragstart,
|
|
82
|
+
onDrop,
|
|
83
|
+
} = DragAndDropAPI(props, { emit }, {
|
|
84
|
+
isDndDisabled: computed(() => false),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(isDndDisabledForRow(0)).toBe(false);
|
|
88
|
+
expect(isDndDisabledForRow(1)).toBe(true);
|
|
89
|
+
|
|
90
|
+
onDragstart({}, 1);
|
|
91
|
+
expect(draggedRowIndex.value).toBeUndefined();
|
|
92
|
+
|
|
93
|
+
onDragstart({}, 0);
|
|
94
|
+
expect(draggedRowIndex.value).toBe(0);
|
|
95
|
+
|
|
96
|
+
const preventDefaultDisabled = jest.fn();
|
|
97
|
+
onDragover({
|
|
98
|
+
preventDefault: preventDefaultDisabled,
|
|
99
|
+
}, 1);
|
|
100
|
+
onDrop({
|
|
101
|
+
preventDefault: preventDefaultDisabled,
|
|
102
|
+
}, 1);
|
|
103
|
+
|
|
104
|
+
expect(preventDefaultDisabled).not.toHaveBeenCalled();
|
|
105
|
+
expect(emit).not.toHaveBeenCalled();
|
|
106
|
+
|
|
107
|
+
const preventDefaultAfterLock = jest.fn();
|
|
108
|
+
onDragover({
|
|
109
|
+
currentTarget: undefined,
|
|
110
|
+
preventDefault: preventDefaultAfterLock,
|
|
111
|
+
}, 2);
|
|
112
|
+
onDrop({
|
|
113
|
+
preventDefault: preventDefaultAfterLock,
|
|
114
|
+
}, 2);
|
|
115
|
+
|
|
116
|
+
expect(preventDefaultAfterLock).toHaveBeenCalledTimes(2);
|
|
117
|
+
expect(emit).not.toHaveBeenCalled();
|
|
118
|
+
|
|
119
|
+
moveRowDown(2);
|
|
120
|
+
|
|
121
|
+
expect(emit).toHaveBeenCalledWith("updateRows", expect.objectContaining({
|
|
122
|
+
fromIndex: 2,
|
|
123
|
+
toIndex: 3,
|
|
124
|
+
trigger: "moveRowDown",
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("ATableFormCellDnd", () => {
|
|
130
|
+
it("shows a lock and disables move buttons for a disabled row", () => {
|
|
131
|
+
const wrapper = mount(ATableFormCellDnd, {
|
|
132
|
+
props: {
|
|
133
|
+
canMoveRowDown: () => true,
|
|
134
|
+
canMoveRowUp: () => true,
|
|
135
|
+
id: "table_1",
|
|
136
|
+
isDndDisabled: true,
|
|
137
|
+
isDragAndDrop: true,
|
|
138
|
+
moveRowDown: jest.fn(),
|
|
139
|
+
moveRowUp: jest.fn(),
|
|
140
|
+
onDragend: jest.fn(),
|
|
141
|
+
onDragstart: jest.fn(),
|
|
142
|
+
rowIndex: 1,
|
|
143
|
+
texts: {
|
|
144
|
+
reorderDisabled: "Row reordering disabled",
|
|
145
|
+
reorderDown: "Move row down",
|
|
146
|
+
reorderHandle: "Drag row to reorder",
|
|
147
|
+
reorderUp: "Move row up",
|
|
148
|
+
},
|
|
149
|
+
widths: {
|
|
150
|
+
dndColumn: 56,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(wrapper.findComponent(AIcon).props("icon")).toBe(LockFill);
|
|
156
|
+
expect(wrapper.find(".a_table_form__reorder_handle").attributes("draggable")).toBe("false");
|
|
157
|
+
expect(wrapper.find(".a_table_form__reorder_handle_disabled").exists()).toBe(true);
|
|
158
|
+
expect(wrapper.text()).toContain("Row reordering disabled");
|
|
159
|
+
expect(wrapper.findAll("button")).toHaveLength(2);
|
|
160
|
+
expect(wrapper.findAll("button").every(button => button.attributes("disabled") !== undefined)).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
});
|