@zipify/wysiwyg 1.0.0-dev.16 → 1.0.0-dev.17
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/wysiwyg.css +15 -0
- package/dist/wysiwyg.js +1 -1
- package/lib/Wysiwyg.vue +2 -3
- package/lib/components/base/index.js +1 -1
- package/lib/components/toolbar/Toolbar.vue +47 -7
- package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
- package/lib/composables/useToolbar.js +15 -19
- package/package.json +1 -1
package/lib/Wysiwyg.vue
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="zw-wysiwyg" ref="wysiwygRef">
|
|
3
3
|
<Toolbar
|
|
4
|
-
|
|
5
|
-
:editor="editor"
|
|
4
|
+
:toolbar="toolbar"
|
|
6
5
|
:device="device"
|
|
7
6
|
ref="toolbarRef"
|
|
8
7
|
/>
|
|
8
|
+
|
|
9
9
|
<EditorContent :editor="editor" />
|
|
10
10
|
</div>
|
|
11
11
|
</template>
|
|
@@ -115,7 +115,6 @@ export default {
|
|
|
115
115
|
|
|
116
116
|
const toolbar = useToolbar({
|
|
117
117
|
wrapperRef: wysiwygRef,
|
|
118
|
-
popperRef: toolbarRef,
|
|
119
118
|
isActiveRef: toRef(props, 'active'),
|
|
120
119
|
offsets: props.toolbarOffsets
|
|
121
120
|
});
|
|
@@ -6,6 +6,6 @@ export { default as FieldLabel } from './FieldLabel';
|
|
|
6
6
|
export { default as Range } from './Range';
|
|
7
7
|
export { default as NumberField } from './NumberField';
|
|
8
8
|
export { default as Modal } from './Modal';
|
|
9
|
-
export { useModalToggler } from './composables';
|
|
9
|
+
export { useModalToggler, useElementRef } from './composables';
|
|
10
10
|
export * from './dropdown';
|
|
11
11
|
export * from './colorPicker';
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
<transition name="zw-toolbar-" :duration="150">
|
|
3
|
+
<keep-alive>
|
|
4
|
+
<div class="zw-toolbar" :style="toolbarStyles" ref="toolbarRef" v-if="isVisible">
|
|
5
|
+
<component :is="toolbarComponent" />
|
|
6
|
+
</div>
|
|
7
|
+
</keep-alive>
|
|
8
|
+
</transition>
|
|
7
9
|
</template>
|
|
8
10
|
|
|
9
11
|
<script>
|
|
10
|
-
import { computed } from '@vue/composition-api';
|
|
12
|
+
import { computed, ref, watch } from '@vue/composition-api';
|
|
11
13
|
import { Devices } from '../../enums';
|
|
12
14
|
import ToolbarFull from './ToolbarFull';
|
|
13
15
|
import ToolbarDevice from './ToolbarDevice';
|
|
@@ -19,6 +21,11 @@ export default {
|
|
|
19
21
|
device: {
|
|
20
22
|
type: String,
|
|
21
23
|
required: true
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
toolbar: {
|
|
27
|
+
type: Object,
|
|
28
|
+
required: true
|
|
22
29
|
}
|
|
23
30
|
},
|
|
24
31
|
|
|
@@ -26,8 +33,23 @@ export default {
|
|
|
26
33
|
const toolbarComponent = computed(() => {
|
|
27
34
|
return props.device === Devices.DESKTOP ? ToolbarFull : ToolbarDevice;
|
|
28
35
|
});
|
|
36
|
+
const isVisible = computed(() => props.toolbar.isActiveRef.value);
|
|
37
|
+
const toolbarRef = ref(null);
|
|
38
|
+
|
|
39
|
+
watch(toolbarRef, (toolbarEl) => {
|
|
40
|
+
toolbarEl && props.toolbar.mount(toolbarEl);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const toolbarStyles = computed(() => ({
|
|
44
|
+
'--zw-toolbar-offset-y': `${props.toolbar.offsets[1]}px`
|
|
45
|
+
}));
|
|
29
46
|
|
|
30
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
toolbarComponent,
|
|
49
|
+
isVisible,
|
|
50
|
+
toolbarRef,
|
|
51
|
+
toolbarStyles
|
|
52
|
+
};
|
|
31
53
|
}
|
|
32
54
|
};
|
|
33
55
|
</script>
|
|
@@ -40,6 +62,24 @@ export default {
|
|
|
40
62
|
z-index: 999999;
|
|
41
63
|
}
|
|
42
64
|
|
|
65
|
+
.zw-toolbar::before,
|
|
66
|
+
.zw-toolbar::after {
|
|
67
|
+
content: "";
|
|
68
|
+
display: block;
|
|
69
|
+
width: 100%;
|
|
70
|
+
height: calc(var(--zw-toolbar-offset-y) + 4px);
|
|
71
|
+
position: absolute;
|
|
72
|
+
--zw-toolbar-safe-zone: calc(-1 * var(--zw-toolbar-offset-y));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.zw-toolbar::before {
|
|
76
|
+
top: var(--zw-toolbar-safe-zone);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.zw-toolbar::after {
|
|
80
|
+
bottom: var(--zw-toolbar-safe-zone);
|
|
81
|
+
}
|
|
82
|
+
|
|
43
83
|
.zw-toolbar--enter-active,
|
|
44
84
|
.zw-toolbar--leave-active {
|
|
45
85
|
transition: opacity 0.15s ease-out;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
2
3
|
import { Devices } from '../../../enums';
|
|
3
4
|
import Toolbar from '../Toolbar';
|
|
4
5
|
import ToolbarFull from '../ToolbarFull';
|
|
@@ -7,6 +8,11 @@ import ToolbarDevice from '../ToolbarDevice';
|
|
|
7
8
|
function createComponent({ device }) {
|
|
8
9
|
return shallowMount(Toolbar, {
|
|
9
10
|
propsData: {
|
|
11
|
+
toolbar: {
|
|
12
|
+
mount: jest.fn(),
|
|
13
|
+
isActiveRef: ref(true),
|
|
14
|
+
offsets: [0, 8]
|
|
15
|
+
},
|
|
10
16
|
device: device ?? Devices.DESKTOP
|
|
11
17
|
}
|
|
12
18
|
});
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { createPopper } from '@popperjs/core';
|
|
2
|
-
import {
|
|
3
|
-
import { useElementRef } from '../components/base/composables';
|
|
2
|
+
import { useElementRef } from '../components/base';
|
|
4
3
|
|
|
5
|
-
export function useToolbar({ wrapperRef,
|
|
4
|
+
export function useToolbar({ wrapperRef, offsets, isActiveRef }) {
|
|
5
|
+
const wrapperEl = useElementRef(wrapperRef);
|
|
6
6
|
let toolbar;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const toolbarEl = useElementRef(popperRef).value;
|
|
11
|
-
|
|
12
|
-
toolbar = createPopper(wrapperEl, toolbarEl, {
|
|
8
|
+
function mount(element) {
|
|
9
|
+
toolbar = createPopper(wrapperEl.value, element, {
|
|
13
10
|
placement: 'top-start',
|
|
14
11
|
modifiers: [
|
|
15
12
|
{
|
|
16
13
|
name: 'offset',
|
|
17
|
-
options: {
|
|
18
|
-
offset: offsets
|
|
19
|
-
}
|
|
14
|
+
options: { offset: offsets }
|
|
20
15
|
}
|
|
21
16
|
]
|
|
22
17
|
});
|
|
23
|
-
}
|
|
24
|
-
const update = () => toolbar.update();
|
|
25
|
-
|
|
26
|
-
watch(isActiveRef, () => {
|
|
27
|
-
if (isActiveRef.value) update();
|
|
28
|
-
});
|
|
18
|
+
}
|
|
29
19
|
|
|
30
|
-
|
|
20
|
+
const update = () => toolbar?.update();
|
|
31
21
|
|
|
32
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
toolbar,
|
|
24
|
+
update,
|
|
25
|
+
mount,
|
|
26
|
+
isActiveRef,
|
|
27
|
+
offsets
|
|
28
|
+
};
|
|
33
29
|
}
|