-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditorOverview.vue
More file actions
215 lines (181 loc) · 5.45 KB
/
EditorOverview.vue
File metadata and controls
215 lines (181 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<template>
<div class="overview">
<LayoutCenterContainer>
<div
class="overview__canvas"
ref="demoCanvas"
>
<div
class="fake-input"
contenteditable="true"
></div>
<template v-if="demoEnabled === false">
<img
class="overview__canvas-pic1"
src="~/assets/editor-1.jpg"
alt="Editor.js showcase: the Toolbox and the Inline Toolbar"
@click="pictureClicked"
/>
<img
class="overview__canvas-pic2"
src="~/assets/editor-2.jpg"
alt="Editor.js: the Image Tool"
@click="pictureClicked"
/>
</template>
<LazyEditorDemo v-else />
<UiButton
v-if="demoEnabled === false"
class="overview__demo-button"
type="primary"
icon="IconMarker"
text="Play With Demo"
ref="demoButton"
@click="playDemoClicked"
/>
</div>
</LayoutCenterContainer>
</div>
</template>
<script setup lang="ts">
import AnalyticEvent from "~/utils/analytics";
import { ref } from 'vue';
// declare a ref to hold the element reference
// the name must match template ref value
const demoButton = ref()
const demoCanvas = ref<HTMLElement | null>(null);
function pictureClicked() {
(demoButton.value as {shake: Function}).shake();
}
/**
* Flag responsible for Demo activation
*/
const demoEnabled = ref(false);
/**
* Access the Analytics module
*/
const { $track } = useNuxtApp();
/**
* Handler for the 'Play With Demo' button
*/
function playDemoClicked(){
demoEnabled.value = true;
/**
* Listen to DOM Mutations and wait for editorjs element to be inserted
* then scroll to it. We have to wait for the editorjs element to be inserted
* otherwise the scroll will not work
*/
const onDomChange=()=>{
if(document.getElementById('editorjs')){
smoothScrollToCenter(demoCanvas.value)
window.removeEventListener('DOMNodeInserted',onDomChange)
}
}
window.addEventListener('DOMNodeInserted',onDomChange)
const isMobile = window.matchMedia('(max-width: 710px)').matches;
if (isMobile) {
/**
* Mobile browsers does not allow to programmatically set a caret to the
* contenteditable element which is not presents on a page in a moment of button click
*
* So we use fake invisible input to focus it first, then change focus to our editor
*/
(document.querySelector('.fake-input') as HTMLElement).focus();
const block: HTMLElement | null = document.querySelector('.ce-paragraph');
if (block !== null){
block.focus()
}
}
/**
* Send analytics event
*/
$track(AnalyticEvent.PlayWithDemoClicked)
}
/**
* Scrolls to targetEle
*/
function smoothScrollToCenter(targetEle:HTMLElement|null) {
if (!targetEle) {
return;
}
const targetPosition = targetEle.getBoundingClientRect().top + window.scrollY;
const screenHeight = window.innerHeight;
const targetDivHeight=targetEle.getBoundingClientRect().height
const targetOffset = targetPosition - (screenHeight / 2)+(targetDivHeight/2);
window.scrollTo({
top: targetOffset,
behavior: 'smooth'
});
}
</script>
<style lang="postcss">
.overview {
--canvas-width: 840;
--canvas-height: 1236;
--canvas-width-px: calc(var(--canvas-width) * 1px);
--canvas-padding-top: 60px;
--canvas-radius: 20px;
--canvas-offset-top: -70px;
--canvas-offset-bottom: -100px;
@media (--small-viewport) {
--canvas-padding-top: 30px;
--canvas-offset-top: -16px;
--canvas-offset-bottom: -32px;
}
display: flex;
flex-direction: column;
background-color: var(--color-background-image-overview);
&__canvas {
margin: var(--canvas-offset-top) auto var(--canvas-offset-bottom);
background-color: #fff;
box-shadow: 0px -3px 29px -5px rgba(34, 39, 47, 0.14);
max-width: var(--canvas-width-px);
border-radius: var(--canvas-radius);
padding-top: var(--canvas-padding-top);
display: flex;
flex-direction: column;
min-height: 400px;
/* aspect-ratio: var(--canvas-width) / var(--canvas-height); */
&-pic1 {
--left-margin: 36;
--right-margin: 120;
--left-margin-percents: calc(var(--left-margin) / var(--canvas-width) * 100%);
--right-margin-percents: calc(var(--right-margin) / var(--canvas-width) * 100%);
max-width: calc(100% - var(--left-margin-percents) - var(--right-margin-percents));
margin-left: var(--left-margin-percents);
margin-right: var(--right-margin-percents);
aspect-ratio: 684 / 709;
}
&-pic2 {
margin-top: 6px;
width: 100%;
aspect-ratio: var(--canvas-width) / 450;
background: radial-gradient(120.67% 147.67% at 37.86% -9.67%, #1F1F1F 0%, #343434 59.51%, #1F1F1F 100%);
border-radius: 0 0 var(--canvas-radius) var(--canvas-radius);
}
}
&__demo-button {
margin: -20px auto -18px;
@media (--desktop) {
position: sticky;
bottom: 16px;
}
}
}
/**
* Mobile browsers does not allow to programmatically set a caret to the
* contenteditable element which is not presents on a page in a moment of button click
*
* So we use fake invisible input to focus it first, then change focus to our editor
*/
.fake-input {
display: none;
@media (--small-viewport) {
display: block;
position: absolute;
font-size: 17px;
opacity: 0.01;
background-color: transparent;
}
}
</style>