@zipify/wysiwyg 2.5.5 → 2.5.6
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/cli.js +1 -1
- package/dist/wysiwyg.css +19 -26
- package/dist/wysiwyg.mjs +294 -270
- package/lib/Wysiwyg.vue +1 -1
- package/lib/components/toolbar/Toolbar.vue +13 -6
- package/lib/components/toolbar/__tests__/Toolbar.test.js +13 -7
- package/lib/components/toolbar/{ToolbarDivider.vue → base/ToolbarDivider.vue} +0 -0
- package/lib/components/toolbar/{ToolbarGroup.vue → base/ToolbarGroup.vue} +0 -0
- package/lib/components/toolbar/{ToolbarRow.vue → base/ToolbarRow.vue} +0 -0
- package/lib/components/toolbar/{__tests__ → base/__tests__}/ToolbarDivider.test.js +0 -0
- package/lib/components/toolbar/base/index.js +3 -0
- package/lib/components/toolbar/controls/index.js +0 -1
- package/lib/components/toolbar/layouts/ToolbarDesktop.vue +95 -0
- package/lib/components/toolbar/{ToolbarFull.vue → layouts/ToolbarMobile.vue} +19 -44
- package/lib/components/toolbar/layouts/ToolbarPopup.vue +95 -0
- package/lib/components/toolbar/layouts/index.js +3 -0
- package/lib/injectionTokens.js +1 -2
- package/package.json +1 -1
- package/lib/components/toolbar/ToolbarDevice.vue +0 -35
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +0 -78
- package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +0 -77
package/lib/Wysiwyg.vue
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<Toolbar
|
|
4
4
|
:toolbar="toolbar"
|
|
5
5
|
:device="device"
|
|
6
|
+
:popup-mode="popupMode"
|
|
6
7
|
ref="toolbarRef"
|
|
7
8
|
/>
|
|
8
9
|
|
|
@@ -201,7 +202,6 @@ export default {
|
|
|
201
202
|
provide(InjectionTokens.LOCAL_STORAGE, new Storage(localStorage));
|
|
202
203
|
provide(InjectionTokens.FAVORITE_COLORS, favoriteColors);
|
|
203
204
|
provide(InjectionTokens.PAGE_BLOCKS, pageBlocks);
|
|
204
|
-
provide(InjectionTokens.POPUP_MODE, props.popupMode);
|
|
205
205
|
|
|
206
206
|
return {
|
|
207
207
|
editor,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<keep-alive>
|
|
3
3
|
<transition name="zw-toolbar-" duration="150">
|
|
4
4
|
<div class="zw-toolbar" :style="toolbarStyles" ref="toolbarRef" v-if="isVisible">
|
|
5
|
-
<component :is="
|
|
5
|
+
<component :is="layoutComponent" />
|
|
6
6
|
</div>
|
|
7
7
|
</transition>
|
|
8
8
|
</keep-alive>
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
<script>
|
|
12
12
|
import { computed, ref, watch } from 'vue';
|
|
13
13
|
import { Devices } from '../../enums';
|
|
14
|
-
import
|
|
15
|
-
import ToolbarDevice from './ToolbarDevice';
|
|
14
|
+
import { ToolbarDesktop, ToolbarMobile, ToolbarPopup } from './layouts';
|
|
16
15
|
|
|
17
16
|
export default {
|
|
18
17
|
name: 'Toolbar',
|
|
@@ -26,13 +25,21 @@ export default {
|
|
|
26
25
|
toolbar: {
|
|
27
26
|
type: Object,
|
|
28
27
|
required: true
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
popupMode: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
required: true
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
|
|
32
36
|
setup(props) {
|
|
33
|
-
const
|
|
34
|
-
|
|
37
|
+
const layoutComponent = computed(() => {
|
|
38
|
+
if (props.popupMode) return ToolbarPopup;
|
|
39
|
+
|
|
40
|
+
return props.device === Devices.MOBILE ? ToolbarMobile : ToolbarDesktop;
|
|
35
41
|
});
|
|
42
|
+
|
|
36
43
|
const isVisible = computed(() => props.toolbar.isActiveRef.value);
|
|
37
44
|
const toolbarRef = ref(null);
|
|
38
45
|
|
|
@@ -45,7 +52,7 @@ export default {
|
|
|
45
52
|
}));
|
|
46
53
|
|
|
47
54
|
return {
|
|
48
|
-
|
|
55
|
+
layoutComponent,
|
|
49
56
|
isVisible,
|
|
50
57
|
toolbarRef,
|
|
51
58
|
toolbarStyles
|
|
@@ -2,10 +2,9 @@ import { shallowMount } from '@vue/test-utils';
|
|
|
2
2
|
import { ref } from 'vue';
|
|
3
3
|
import { Devices } from '../../../enums';
|
|
4
4
|
import Toolbar from '../Toolbar';
|
|
5
|
-
import
|
|
6
|
-
import ToolbarDevice from '../ToolbarDevice';
|
|
5
|
+
import { ToolbarMobile, ToolbarDesktop, ToolbarPopup } from '../layouts';
|
|
7
6
|
|
|
8
|
-
function createComponent({ device }) {
|
|
7
|
+
function createComponent({ device, popupMode }) {
|
|
9
8
|
return shallowMount(Toolbar, {
|
|
10
9
|
propsData: {
|
|
11
10
|
toolbar: {
|
|
@@ -13,7 +12,8 @@ function createComponent({ device }) {
|
|
|
13
12
|
isActiveRef: ref({ value: true }),
|
|
14
13
|
offsets: [0, 8]
|
|
15
14
|
},
|
|
16
|
-
device: device ?? Devices.DESKTOP
|
|
15
|
+
device: device ?? Devices.DESKTOP,
|
|
16
|
+
popupMode: popupMode ?? false
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -22,18 +22,24 @@ describe('rendering', () => {
|
|
|
22
22
|
test('should render desktop toolbar', () => {
|
|
23
23
|
const wrapper = createComponent({ device: Devices.DESKTOP });
|
|
24
24
|
|
|
25
|
-
expect(wrapper).toVueContainComponent(
|
|
25
|
+
expect(wrapper).toVueContainComponent(ToolbarDesktop);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('should render tablet toolbar', () => {
|
|
29
29
|
const wrapper = createComponent({ device: Devices.TABLET });
|
|
30
30
|
|
|
31
|
-
expect(wrapper).toVueContainComponent(
|
|
31
|
+
expect(wrapper).toVueContainComponent(ToolbarDesktop);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('should render mobile toolbar', () => {
|
|
35
35
|
const wrapper = createComponent({ device: Devices.MOBILE });
|
|
36
36
|
|
|
37
|
-
expect(wrapper).toVueContainComponent(
|
|
37
|
+
expect(wrapper).toVueContainComponent(ToolbarMobile);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should render popup toolbar', () => {
|
|
41
|
+
const wrapper = createComponent({ popupMode: true });
|
|
42
|
+
|
|
43
|
+
expect(wrapper).toVueContainComponent(ToolbarPopup);
|
|
38
44
|
});
|
|
39
45
|
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -10,7 +10,6 @@ export { default as StrikeThroughControl } from './StrikeThroughControl';
|
|
|
10
10
|
export { default as SuperscriptControl } from './SuperscriptControl';
|
|
11
11
|
export { default as CaseStyleControl } from './CaseStyleControl';
|
|
12
12
|
export { default as AlignmentControl } from './AlignmentControl';
|
|
13
|
-
export { default as AlignmentDeviceControl } from './AlignmentDeviceControl';
|
|
14
13
|
export { default as LineHeightControl } from './LineHeightControl';
|
|
15
14
|
export { default as ListControl } from './ListControl';
|
|
16
15
|
export { default as RemoveFormatControl } from './RemoveFormatControl';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<ToolbarRow>
|
|
4
|
+
<StylePresetControl />
|
|
5
|
+
<ToolbarDivider vertical />
|
|
6
|
+
<FontFamilyControl />
|
|
7
|
+
<ToolbarDivider vertical />
|
|
8
|
+
<FontWeightControl />
|
|
9
|
+
<ToolbarDivider vertical />
|
|
10
|
+
<FontSizeControl />
|
|
11
|
+
<ToolbarDivider vertical />
|
|
12
|
+
|
|
13
|
+
<ToolbarGroup>
|
|
14
|
+
<FontColorControl />
|
|
15
|
+
<BackgroundColorControl />
|
|
16
|
+
</ToolbarGroup>
|
|
17
|
+
</ToolbarRow>
|
|
18
|
+
|
|
19
|
+
<ToolbarDivider horizontal />
|
|
20
|
+
|
|
21
|
+
<ToolbarRow>
|
|
22
|
+
<ToolbarGroup>
|
|
23
|
+
<ItalicControl />
|
|
24
|
+
<UnderlineControl />
|
|
25
|
+
<StrikeThroughControl />
|
|
26
|
+
<SuperscriptControl />
|
|
27
|
+
<CaseStyleControl />
|
|
28
|
+
</ToolbarGroup>
|
|
29
|
+
|
|
30
|
+
<ToolbarDivider vertical />
|
|
31
|
+
|
|
32
|
+
<AlignmentControl />
|
|
33
|
+
<ToolbarDivider vertical />
|
|
34
|
+
|
|
35
|
+
<LineHeightControl />
|
|
36
|
+
<ToolbarDivider vertical />
|
|
37
|
+
|
|
38
|
+
<ListControl />
|
|
39
|
+
<ToolbarDivider vertical />
|
|
40
|
+
|
|
41
|
+
<ToolbarGroup>
|
|
42
|
+
<LinkControl />
|
|
43
|
+
<RemoveFormatControl />
|
|
44
|
+
</ToolbarGroup>
|
|
45
|
+
</ToolbarRow>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
import { ToolbarDivider, ToolbarRow, ToolbarGroup } from '../base';
|
|
51
|
+
import {
|
|
52
|
+
StylePresetControl,
|
|
53
|
+
AlignmentControl,
|
|
54
|
+
BackgroundColorControl,
|
|
55
|
+
CaseStyleControl,
|
|
56
|
+
FontColorControl,
|
|
57
|
+
FontFamilyControl,
|
|
58
|
+
FontSizeControl,
|
|
59
|
+
FontWeightControl,
|
|
60
|
+
ItalicControl,
|
|
61
|
+
LineHeightControl,
|
|
62
|
+
StrikeThroughControl,
|
|
63
|
+
SuperscriptControl,
|
|
64
|
+
UnderlineControl,
|
|
65
|
+
ListControl,
|
|
66
|
+
RemoveFormatControl,
|
|
67
|
+
LinkControl
|
|
68
|
+
} from '../controls';
|
|
69
|
+
|
|
70
|
+
export default {
|
|
71
|
+
name: 'ToolbarDesktop',
|
|
72
|
+
|
|
73
|
+
components: {
|
|
74
|
+
ToolbarRow,
|
|
75
|
+
ToolbarGroup,
|
|
76
|
+
ToolbarDivider,
|
|
77
|
+
StylePresetControl,
|
|
78
|
+
CaseStyleControl,
|
|
79
|
+
FontFamilyControl,
|
|
80
|
+
FontWeightControl,
|
|
81
|
+
FontSizeControl,
|
|
82
|
+
FontColorControl,
|
|
83
|
+
BackgroundColorControl,
|
|
84
|
+
ItalicControl,
|
|
85
|
+
UnderlineControl,
|
|
86
|
+
SuperscriptControl,
|
|
87
|
+
StrikeThroughControl,
|
|
88
|
+
AlignmentControl,
|
|
89
|
+
LineHeightControl,
|
|
90
|
+
ListControl,
|
|
91
|
+
RemoveFormatControl,
|
|
92
|
+
LinkControl
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
</script>
|
|
@@ -6,8 +6,13 @@
|
|
|
6
6
|
<FontFamilyControl />
|
|
7
7
|
<ToolbarDivider vertical />
|
|
8
8
|
<FontWeightControl />
|
|
9
|
-
|
|
9
|
+
</ToolbarRow>
|
|
10
|
+
|
|
11
|
+
<ToolbarDivider horizontal />
|
|
12
|
+
|
|
13
|
+
<ToolbarRow>
|
|
10
14
|
<FontSizeControl />
|
|
15
|
+
|
|
11
16
|
<ToolbarDivider vertical />
|
|
12
17
|
|
|
13
18
|
<ToolbarGroup>
|
|
@@ -15,47 +20,27 @@
|
|
|
15
20
|
<BackgroundColorControl />
|
|
16
21
|
</ToolbarGroup>
|
|
17
22
|
|
|
18
|
-
<
|
|
19
|
-
<ToolbarDivider vertical />
|
|
23
|
+
<ToolbarDivider vertical />
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</template>
|
|
25
|
+
<ToolbarGroup>
|
|
26
|
+
<ItalicControl />
|
|
27
|
+
<UnderlineControl />
|
|
28
|
+
<StrikeThroughControl />
|
|
29
|
+
<SuperscriptControl />
|
|
30
|
+
<CaseStyleControl />
|
|
31
|
+
</ToolbarGroup>
|
|
29
32
|
</ToolbarRow>
|
|
30
33
|
|
|
31
34
|
<ToolbarDivider horizontal />
|
|
32
35
|
|
|
33
36
|
<ToolbarRow>
|
|
34
|
-
<template v-if="!isPopupMode">
|
|
35
|
-
<ToolbarGroup>
|
|
36
|
-
<ItalicControl />
|
|
37
|
-
<UnderlineControl />
|
|
38
|
-
<StrikeThroughControl />
|
|
39
|
-
<SuperscriptControl />
|
|
40
|
-
<CaseStyleControl />
|
|
41
|
-
</ToolbarGroup>
|
|
42
|
-
|
|
43
|
-
<ToolbarDivider vertical />
|
|
44
|
-
</template>
|
|
45
|
-
|
|
46
37
|
<AlignmentControl />
|
|
47
38
|
<ToolbarDivider vertical />
|
|
48
39
|
|
|
49
|
-
<
|
|
50
|
-
<LineHeightControl />
|
|
51
|
-
</ToolbarGroup>
|
|
52
|
-
|
|
40
|
+
<LineHeightControl />
|
|
53
41
|
<ToolbarDivider vertical />
|
|
54
42
|
|
|
55
|
-
<
|
|
56
|
-
<ListControl />
|
|
57
|
-
</ToolbarGroup>
|
|
58
|
-
|
|
43
|
+
<ListControl />
|
|
59
44
|
<ToolbarDivider vertical />
|
|
60
45
|
|
|
61
46
|
<ToolbarGroup>
|
|
@@ -67,11 +52,7 @@
|
|
|
67
52
|
</template>
|
|
68
53
|
|
|
69
54
|
<script>
|
|
70
|
-
import {
|
|
71
|
-
import { InjectionTokens } from '../../injectionTokens';
|
|
72
|
-
import ToolbarDivider from './ToolbarDivider';
|
|
73
|
-
import ToolbarRow from './ToolbarRow';
|
|
74
|
-
import ToolbarGroup from './ToolbarGroup';
|
|
55
|
+
import { ToolbarDivider, ToolbarRow, ToolbarGroup } from '../base';
|
|
75
56
|
import {
|
|
76
57
|
StylePresetControl,
|
|
77
58
|
AlignmentControl,
|
|
@@ -89,10 +70,10 @@ import {
|
|
|
89
70
|
ListControl,
|
|
90
71
|
RemoveFormatControl,
|
|
91
72
|
LinkControl
|
|
92
|
-
} from '
|
|
73
|
+
} from '../controls';
|
|
93
74
|
|
|
94
75
|
export default {
|
|
95
|
-
name: '
|
|
76
|
+
name: 'ToolbarMobile',
|
|
96
77
|
|
|
97
78
|
components: {
|
|
98
79
|
ToolbarRow,
|
|
@@ -114,12 +95,6 @@ export default {
|
|
|
114
95
|
ListControl,
|
|
115
96
|
RemoveFormatControl,
|
|
116
97
|
LinkControl
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
setup() {
|
|
120
|
-
const isPopupMode = inject(InjectionTokens.POPUP_MODE);
|
|
121
|
-
|
|
122
|
-
return { isPopupMode };
|
|
123
98
|
}
|
|
124
99
|
};
|
|
125
100
|
</script>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<ToolbarRow>
|
|
4
|
+
<StylePresetControl />
|
|
5
|
+
<ToolbarDivider vertical />
|
|
6
|
+
<FontFamilyControl />
|
|
7
|
+
<ToolbarDivider vertical />
|
|
8
|
+
<FontWeightControl />
|
|
9
|
+
<ToolbarDivider vertical />
|
|
10
|
+
<FontSizeControl />
|
|
11
|
+
<ToolbarDivider vertical />
|
|
12
|
+
|
|
13
|
+
<ToolbarGroup>
|
|
14
|
+
<FontColorControl />
|
|
15
|
+
<BackgroundColorControl />
|
|
16
|
+
</ToolbarGroup>
|
|
17
|
+
|
|
18
|
+
<ToolbarDivider vertical />
|
|
19
|
+
|
|
20
|
+
<ToolbarGroup>
|
|
21
|
+
<ItalicControl />
|
|
22
|
+
<UnderlineControl />
|
|
23
|
+
<StrikeThroughControl />
|
|
24
|
+
<SuperscriptControl />
|
|
25
|
+
<CaseStyleControl />
|
|
26
|
+
</ToolbarGroup>
|
|
27
|
+
</ToolbarRow>
|
|
28
|
+
|
|
29
|
+
<ToolbarDivider horizontal />
|
|
30
|
+
|
|
31
|
+
<ToolbarRow>
|
|
32
|
+
<AlignmentControl />
|
|
33
|
+
<ToolbarDivider vertical />
|
|
34
|
+
|
|
35
|
+
<LineHeightControl />
|
|
36
|
+
<ToolbarDivider vertical />
|
|
37
|
+
|
|
38
|
+
<ListControl />
|
|
39
|
+
<ToolbarDivider vertical />
|
|
40
|
+
|
|
41
|
+
<ToolbarGroup>
|
|
42
|
+
<LinkControl />
|
|
43
|
+
<RemoveFormatControl />
|
|
44
|
+
</ToolbarGroup>
|
|
45
|
+
</ToolbarRow>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
import { ToolbarDivider, ToolbarRow, ToolbarGroup } from '../base';
|
|
51
|
+
import {
|
|
52
|
+
StylePresetControl,
|
|
53
|
+
AlignmentControl,
|
|
54
|
+
BackgroundColorControl,
|
|
55
|
+
CaseStyleControl,
|
|
56
|
+
FontColorControl,
|
|
57
|
+
FontFamilyControl,
|
|
58
|
+
FontSizeControl,
|
|
59
|
+
FontWeightControl,
|
|
60
|
+
ItalicControl,
|
|
61
|
+
LineHeightControl,
|
|
62
|
+
StrikeThroughControl,
|
|
63
|
+
SuperscriptControl,
|
|
64
|
+
UnderlineControl,
|
|
65
|
+
ListControl,
|
|
66
|
+
RemoveFormatControl,
|
|
67
|
+
LinkControl
|
|
68
|
+
} from '../controls';
|
|
69
|
+
|
|
70
|
+
export default {
|
|
71
|
+
name: 'ToolbarPopup',
|
|
72
|
+
|
|
73
|
+
components: {
|
|
74
|
+
ToolbarRow,
|
|
75
|
+
ToolbarGroup,
|
|
76
|
+
ToolbarDivider,
|
|
77
|
+
StylePresetControl,
|
|
78
|
+
CaseStyleControl,
|
|
79
|
+
FontFamilyControl,
|
|
80
|
+
FontWeightControl,
|
|
81
|
+
FontSizeControl,
|
|
82
|
+
FontColorControl,
|
|
83
|
+
BackgroundColorControl,
|
|
84
|
+
ItalicControl,
|
|
85
|
+
UnderlineControl,
|
|
86
|
+
SuperscriptControl,
|
|
87
|
+
StrikeThroughControl,
|
|
88
|
+
AlignmentControl,
|
|
89
|
+
LineHeightControl,
|
|
90
|
+
ListControl,
|
|
91
|
+
RemoveFormatControl,
|
|
92
|
+
LinkControl
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
</script>
|
package/lib/injectionTokens.js
CHANGED
|
@@ -4,6 +4,5 @@ export const InjectionTokens = Object.freeze({
|
|
|
4
4
|
EDITOR: Symbol('editor'),
|
|
5
5
|
LOCAL_STORAGE: Symbol('localStorage'),
|
|
6
6
|
FAVORITE_COLORS: Symbol('favoriteColors'),
|
|
7
|
-
PAGE_BLOCKS: Symbol('pageBlocks')
|
|
8
|
-
POPUP_MODE: Symbol('popupMode')
|
|
7
|
+
PAGE_BLOCKS: Symbol('pageBlocks')
|
|
9
8
|
});
|
package/package.json
CHANGED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<ToolbarRow>
|
|
3
|
-
<StylePresetControl />
|
|
4
|
-
<ToolbarDivider vertical />
|
|
5
|
-
<AlignmentDeviceControl />
|
|
6
|
-
<ToolbarDivider vertical />
|
|
7
|
-
<FontSizeControl />
|
|
8
|
-
<ToolbarDivider vertical />
|
|
9
|
-
<LineHeightControl />
|
|
10
|
-
</ToolbarRow>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
import ToolbarRow from './ToolbarRow';
|
|
15
|
-
import ToolbarDivider from './ToolbarDivider';
|
|
16
|
-
import {
|
|
17
|
-
StylePresetControl,
|
|
18
|
-
AlignmentDeviceControl,
|
|
19
|
-
FontSizeControl,
|
|
20
|
-
LineHeightControl
|
|
21
|
-
} from './controls';
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
name: 'ToolbarDevice',
|
|
25
|
-
|
|
26
|
-
components: {
|
|
27
|
-
ToolbarRow,
|
|
28
|
-
ToolbarDivider,
|
|
29
|
-
StylePresetControl,
|
|
30
|
-
AlignmentDeviceControl,
|
|
31
|
-
FontSizeControl,
|
|
32
|
-
LineHeightControl
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
</script>
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="zw-position--relative" ref="wrapperRef">
|
|
3
|
-
<Button
|
|
4
|
-
icon
|
|
5
|
-
skin="toolbar"
|
|
6
|
-
:active="isOpened"
|
|
7
|
-
@click="toggler.open"
|
|
8
|
-
v-tooltip="'Alignment'"
|
|
9
|
-
>
|
|
10
|
-
<Icon :name="icon" size="28px" auto-color />
|
|
11
|
-
</Button>
|
|
12
|
-
|
|
13
|
-
<Modal class="zw-alignment-control__modal" ref="modalRef" :toggler="toggler">
|
|
14
|
-
<AlignmentControl class="zw-alignment-control__toggle" @applied="toggler.close" />
|
|
15
|
-
</Modal>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script>
|
|
20
|
-
import { computed, inject, ref, unref } from 'vue';
|
|
21
|
-
import { InjectionTokens } from '../../../injectionTokens';
|
|
22
|
-
import { tooltip } from '../../../directives';
|
|
23
|
-
import { Alignments } from '../../../enums';
|
|
24
|
-
import { Button, Icon, Modal, useModalToggler } from '../../base';
|
|
25
|
-
import AlignmentControl from './AlignmentControl';
|
|
26
|
-
|
|
27
|
-
export default {
|
|
28
|
-
name: 'AlignmentDeviceControl',
|
|
29
|
-
|
|
30
|
-
components: {
|
|
31
|
-
Button,
|
|
32
|
-
Icon,
|
|
33
|
-
Modal,
|
|
34
|
-
AlignmentControl
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
directives: {
|
|
38
|
-
tooltip
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
setup() {
|
|
42
|
-
const editor = inject(InjectionTokens.EDITOR);
|
|
43
|
-
const currentValue = editor.commands.getAlignment();
|
|
44
|
-
const wrapperRef = ref(null);
|
|
45
|
-
const modalRef = ref(null);
|
|
46
|
-
|
|
47
|
-
const toggler = useModalToggler({
|
|
48
|
-
wrapperRef,
|
|
49
|
-
modalRef
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const icon = computed(() => {
|
|
53
|
-
const name = unref(currentValue) || Alignments.LEFT;
|
|
54
|
-
|
|
55
|
-
return `alignment-${name}`;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
wrapperRef,
|
|
60
|
-
modalRef,
|
|
61
|
-
currentValue,
|
|
62
|
-
icon,
|
|
63
|
-
toggler,
|
|
64
|
-
isOpened: toggler.isOpened
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
</script>
|
|
69
|
-
|
|
70
|
-
<style scoped>
|
|
71
|
-
.zw-alignment-control__modal {
|
|
72
|
-
padding: var(--zw-offset-xxs);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.zw-alignment-control__toggle {
|
|
76
|
-
flex-direction: column;
|
|
77
|
-
}
|
|
78
|
-
</style>
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { ref, h, nextTick } from 'vue';
|
|
3
|
-
import { InjectionTokens } from '../../../../injectionTokens';
|
|
4
|
-
import { Alignments } from '../../../../enums';
|
|
5
|
-
import { Button, Icon, Modal } from '../../../base';
|
|
6
|
-
import AlignmentDeviceControl from '../AlignmentDeviceControl';
|
|
7
|
-
import AlignmentControl from '../AlignmentControl';
|
|
8
|
-
|
|
9
|
-
const createEditor = ({ alignment } = {}) => ({
|
|
10
|
-
commands: {
|
|
11
|
-
getAlignment: () => ref(alignment),
|
|
12
|
-
storeSelection: jest.fn(),
|
|
13
|
-
restoreSelection: jest.fn()
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
function createComponent({ editor } = {}) {
|
|
18
|
-
return shallowMount(AlignmentDeviceControl, {
|
|
19
|
-
stubs: {
|
|
20
|
-
Modal: {
|
|
21
|
-
render() {
|
|
22
|
-
return h('div', null, this.$slots.default);
|
|
23
|
-
},
|
|
24
|
-
props: ['toggler']
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
provide: {
|
|
28
|
-
[InjectionTokens.EDITOR]: editor ?? createEditor()
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe('rendering', () => {
|
|
34
|
-
test('should render alignment icon', () => {
|
|
35
|
-
const editor = createEditor({ alignment: Alignments.RIGHT });
|
|
36
|
-
const wrapper = createComponent({ editor });
|
|
37
|
-
const iconWrapper = wrapper.findComponent(Icon);
|
|
38
|
-
|
|
39
|
-
expect(iconWrapper.props('name')).toBe('alignment-right');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('should render closed state', async () => {
|
|
43
|
-
const wrapper = createComponent();
|
|
44
|
-
const buttonWrapper = wrapper.findComponent(Button);
|
|
45
|
-
const modalWrapper = wrapper.findComponent(Modal);
|
|
46
|
-
|
|
47
|
-
expect(buttonWrapper.props('active')).toBe(false);
|
|
48
|
-
expect(modalWrapper.props('toggler').isOpened.value).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('should open modal', async () => {
|
|
52
|
-
const wrapper = createComponent();
|
|
53
|
-
const buttonWrapper = wrapper.findComponent(Button);
|
|
54
|
-
const modalWrapper = wrapper.findComponent(Modal);
|
|
55
|
-
|
|
56
|
-
buttonWrapper.vm.$emit('click');
|
|
57
|
-
await nextTick();
|
|
58
|
-
|
|
59
|
-
expect(buttonWrapper.props('active')).toBe(true);
|
|
60
|
-
expect(modalWrapper.props('toggler').isOpened.value).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('should close on apply value', async () => {
|
|
64
|
-
const wrapper = createComponent();
|
|
65
|
-
const buttonWrapper = wrapper.findComponent(Button);
|
|
66
|
-
const modalWrapper = wrapper.findComponent(Modal);
|
|
67
|
-
|
|
68
|
-
buttonWrapper.vm.$emit('click');
|
|
69
|
-
await nextTick();
|
|
70
|
-
|
|
71
|
-
wrapper.findComponent(AlignmentControl).vm.$emit('applied');
|
|
72
|
-
await nextTick();
|
|
73
|
-
|
|
74
|
-
expect(buttonWrapper.props('active')).toBe(false);
|
|
75
|
-
expect(modalWrapper.props('toggler').isOpened.value).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
});
|