@ebl-vue/editor-full 2.31.35 → 2.31.37
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/.postcssrc.yml +33 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.mjs +184 -183
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
- package/postcss.config.js +15 -0
- package/src/components/Editor/Editor.vue +293 -0
- package/src/components/index.ts +27 -0
- package/src/constants/index.ts +1 -0
- package/src/i18n/zh-cn.ts +160 -0
- package/src/icons/index.ts +93 -0
- package/src/index.ts +21 -0
- package/src/installer.ts +21 -0
- package/src/plugins/alert/index.ts +455 -0
- package/src/plugins/block-alignment/index.ts +117 -0
- package/src/plugins/block-alignment/readme.md +1 -0
- package/src/plugins/code/LICENSE +21 -0
- package/src/plugins/code/index.ts +619 -0
- package/src/plugins/code/utils/string.ts +34 -0
- package/src/plugins/color-picker/index.ts +132 -0
- package/src/plugins/delimiter/index.ts +121 -0
- package/src/plugins/drag-drop/index.css +19 -0
- package/src/plugins/drag-drop/index.ts +151 -0
- package/src/plugins/drag-drop/readme.md +1 -0
- package/src/plugins/header/H1.ts +404 -0
- package/src/plugins/header/H2.ts +403 -0
- package/src/plugins/header/H3.ts +404 -0
- package/src/plugins/header/H4.ts +404 -0
- package/src/plugins/header/H5.ts +403 -0
- package/src/plugins/header/H6.ts +404 -0
- package/src/plugins/header/index.ts +15 -0
- package/src/plugins/header/types.d.ts +46 -0
- package/src/plugins/imageResizeCrop/ImageTune.ts +635 -0
- package/src/plugins/imageResizeCrop/index.css +230 -0
- package/src/plugins/imageResizeCrop/index.ts +5 -0
- package/src/plugins/imageResizeCrop/types.d.ts +23 -0
- package/src/plugins/imageTool/index.ts +510 -0
- package/src/plugins/imageTool/types/codexteam__ajax.d.ts +89 -0
- package/src/plugins/imageTool/types/types.ts +236 -0
- package/src/plugins/imageTool/ui.ts +313 -0
- package/src/plugins/imageTool/uploader.ts +293 -0
- package/src/plugins/imageTool/utils/dom.ts +24 -0
- package/src/plugins/imageTool/utils/index.ts +73 -0
- package/src/plugins/imageTool/utils/isPromise.ts +10 -0
- package/src/plugins/indent/index.ts +695 -0
- package/src/plugins/inline-code/index.ts +203 -0
- package/src/plugins/list/ListRenderer/ChecklistRenderer.ts +208 -0
- package/src/plugins/list/ListRenderer/ListRenderer.ts +73 -0
- package/src/plugins/list/ListRenderer/OrderedListRenderer.ts +123 -0
- package/src/plugins/list/ListRenderer/UnorderedListRenderer.ts +123 -0
- package/src/plugins/list/ListRenderer/index.ts +6 -0
- package/src/plugins/list/ListTabulator/index.ts +1179 -0
- package/src/plugins/list/index.ts +488 -0
- package/src/plugins/list/styles/CssPrefix.ts +4 -0
- package/src/plugins/list/types/Elements.ts +14 -0
- package/src/plugins/list/types/ItemMeta.ts +40 -0
- package/src/plugins/list/types/ListParams.ts +102 -0
- package/src/plugins/list/types/ListRenderer.ts +6 -0
- package/src/plugins/list/types/OlCounterType.ts +63 -0
- package/src/plugins/list/types/index.ts +14 -0
- package/src/plugins/list/utils/focusItem.ts +18 -0
- package/src/plugins/list/utils/getChildItems.ts +40 -0
- package/src/plugins/list/utils/getItemChildWrapper.ts +10 -0
- package/src/plugins/list/utils/getItemContentElement.ts +10 -0
- package/src/plugins/list/utils/getSiblings.ts +52 -0
- package/src/plugins/list/utils/isLastItem.ts +9 -0
- package/src/plugins/list/utils/itemHasSublist.ts +10 -0
- package/src/plugins/list/utils/normalizeData.ts +83 -0
- package/src/plugins/list/utils/removeChildWrapperIfEmpty.ts +31 -0
- package/src/plugins/list/utils/renderToolboxInput.ts +113 -0
- package/src/plugins/list/utils/stripNumbers.ts +7 -0
- package/src/plugins/list/utils/type-guards.ts +8 -0
- package/src/plugins/marker/index.ts +199 -0
- package/src/plugins/outline/index.ts +62 -0
- package/src/plugins/outline/outline.css +52 -0
- package/src/plugins/paragraph/index.ts +384 -0
- package/src/plugins/paragraph/types/icons.d.ts +4 -0
- package/src/plugins/paragraph/utils/makeFragment.ts +17 -0
- package/src/plugins/quote/index.ts +203 -0
- package/src/plugins/table/index.ts +4 -0
- package/src/plugins/table/plugin.ts +255 -0
- package/src/plugins/table/table.ts +1202 -0
- package/src/plugins/table/toolbox.ts +166 -0
- package/src/plugins/table/utils/dom.ts +130 -0
- package/src/plugins/table/utils/popover.ts +185 -0
- package/src/plugins/table/utils/throttled.ts +22 -0
- package/src/plugins/underline/index.ts +214 -0
- package/src/plugins/undo/index.ts +526 -0
- package/src/plugins/undo/observer.ts +101 -0
- package/src/plugins/undo/vanilla-caret-js.ts +102 -0
- package/src/style.css +139 -0
- package/src/types.ts +3 -0
- package/src/utils/AxiosService.ts +87 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/install.ts +19 -0
- package/tsconfig.json +37 -0
- package/vite.config.ts +81 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
|
|
2
|
+
import './index.css';
|
|
3
|
+
import type { BlockTune, API, BlockAPI } from '@ebl-vue/editorjs/types'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface TuneSetting {
|
|
7
|
+
name: string;
|
|
8
|
+
icon: string;
|
|
9
|
+
label: string;
|
|
10
|
+
group: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ImageToolTuneData {
|
|
14
|
+
floatLeft: boolean;
|
|
15
|
+
floatRight: boolean;
|
|
16
|
+
center: boolean;
|
|
17
|
+
sizeSmall: boolean;
|
|
18
|
+
sizeMiddle: boolean;
|
|
19
|
+
sizeLarge: boolean;
|
|
20
|
+
resize: boolean;
|
|
21
|
+
resizeSize: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ImageToolTuneConfig {
|
|
25
|
+
resize: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CustomStyles {
|
|
29
|
+
settingsButton: string;
|
|
30
|
+
settingsButtonActive: string;
|
|
31
|
+
settingsButtonModifier?: string;
|
|
32
|
+
settingsButtonModifierActive?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ImageToolTuneConstructor {
|
|
36
|
+
api: API;
|
|
37
|
+
data: ImageToolTuneData;
|
|
38
|
+
config?: ImageToolTuneConfig;
|
|
39
|
+
block: BlockAPI;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default class ImageToolTune implements BlockTune {
|
|
43
|
+
private settings: TuneSetting[];
|
|
44
|
+
private api: API;
|
|
45
|
+
private block: BlockAPI;
|
|
46
|
+
private data: ImageToolTuneData;
|
|
47
|
+
private wrapper: HTMLElement | undefined;
|
|
48
|
+
private buttons: HTMLElement[];
|
|
49
|
+
private styles: CustomStyles;
|
|
50
|
+
|
|
51
|
+
constructor({ api, data, config, block }: ImageToolTuneConstructor) {
|
|
52
|
+
this.settings = [
|
|
53
|
+
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
this.api = api;
|
|
57
|
+
this.block = block;
|
|
58
|
+
this.data = {
|
|
59
|
+
floatLeft: data?.floatLeft ?? false,
|
|
60
|
+
floatRight: data?.floatRight ?? false,
|
|
61
|
+
center: data?.center ?? false,
|
|
62
|
+
sizeSmall: data?.sizeSmall ?? false,
|
|
63
|
+
sizeMiddle: data?.sizeMiddle ?? false,
|
|
64
|
+
sizeLarge: data?.sizeLarge ?? false,
|
|
65
|
+
resize: data?.resize ?? config?.resize ?? false,
|
|
66
|
+
resizeSize: data?.resizeSize ?? 0,
|
|
67
|
+
|
|
68
|
+
};
|
|
69
|
+
this.wrapper = undefined;
|
|
70
|
+
this.buttons = [];
|
|
71
|
+
this.styles = {
|
|
72
|
+
settingsButton: 'cdx-settings-button',
|
|
73
|
+
settingsButtonActive: 'cdx-settings-button--active',
|
|
74
|
+
settingsButtonModifier: '',
|
|
75
|
+
settingsButtonModifierActive: '',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static get isTune(): boolean {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static get sanitize() {
|
|
84
|
+
return {
|
|
85
|
+
floatLeft: {},
|
|
86
|
+
floatRight: {},
|
|
87
|
+
center: {},
|
|
88
|
+
sizeSmall: {},
|
|
89
|
+
sizeMiddle: {},
|
|
90
|
+
sizeLarge: {},
|
|
91
|
+
resize: {},
|
|
92
|
+
resizeSize: {},
|
|
93
|
+
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* CSS classes
|
|
99
|
+
* @return {object}
|
|
100
|
+
* @constructor
|
|
101
|
+
* @property {string} CSS.wrapper - wrapper for buttons
|
|
102
|
+
* @property {string} CSS.button - button
|
|
103
|
+
* @property {string} CSS.buttonActive - active button
|
|
104
|
+
* @property {string} CSS.buttonModifier - button with modifier
|
|
105
|
+
* @property {string} CSS.buttonModifierActive - active button with modifier
|
|
106
|
+
*/
|
|
107
|
+
get CSS(): Record<string, string> {
|
|
108
|
+
return {
|
|
109
|
+
wrapper: 'cdx-image-tool-tune',
|
|
110
|
+
button: this.styles.settingsButton,
|
|
111
|
+
buttonActive: this.styles.settingsButtonActive,
|
|
112
|
+
buttonModifier: this.styles.settingsButtonModifier || '',
|
|
113
|
+
buttonModifierActive: this.styles.settingsButtonModifierActive || '',
|
|
114
|
+
isFloatLeft: 'cdx-image-tool-tune--floatLeft',
|
|
115
|
+
isFloatRight: 'cdx-image-tool-tune--floatRight',
|
|
116
|
+
isCenter: 'cdx-image-tool-tune--center',
|
|
117
|
+
isSizeSmall: 'cdx-image-tool-tune--sizeSmall',
|
|
118
|
+
isSizeMiddle: 'cdx-image-tool-tune--sizeMiddle',
|
|
119
|
+
isSizeLarge: 'cdx-image-tool-tune--sizeLarge',
|
|
120
|
+
isResize: 'cdx-image-tool-tune--resize',
|
|
121
|
+
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @return {HTMLElement}
|
|
128
|
+
* @public
|
|
129
|
+
* @readonly
|
|
130
|
+
* @property {HTMLElement} wrapper - tune buttons wrapper
|
|
131
|
+
*/
|
|
132
|
+
get view(): HTMLElement {
|
|
133
|
+
if (!this.wrapper) {
|
|
134
|
+
this.wrapper = this.createView();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return this.wrapper;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Clicks to one of the tunes
|
|
142
|
+
* @param {MouseEvent} e - click
|
|
143
|
+
* @param {HTMLElement} tune - clicked tune button
|
|
144
|
+
* @private
|
|
145
|
+
* @return {void}
|
|
146
|
+
* */
|
|
147
|
+
tuneClicked(e: MouseEvent, tune: HTMLElement): void {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
e.stopPropagation();
|
|
150
|
+
|
|
151
|
+
const tuneName = tune.dataset.tune || '';
|
|
152
|
+
const tuneGroup = this.settings.find(t => t.name === tuneName)?.group;
|
|
153
|
+
|
|
154
|
+
this.buttons.forEach(button => {
|
|
155
|
+
//if is the same group
|
|
156
|
+
if (
|
|
157
|
+
this.settings.find(t => t.name === button.dataset.tune)?.group ===
|
|
158
|
+
tuneGroup
|
|
159
|
+
) {
|
|
160
|
+
if (button !== tune) {
|
|
161
|
+
button.classList.remove(this.CSS.buttonActive);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
tune.classList.toggle(this.CSS.buttonActive);
|
|
167
|
+
this.setTune(tuneName);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Styles the image with a tune
|
|
172
|
+
* @param {string} tune - tune name
|
|
173
|
+
* @private
|
|
174
|
+
* @return {void}
|
|
175
|
+
* */
|
|
176
|
+
setTune(tune: string): void {
|
|
177
|
+
switch (tune) {
|
|
178
|
+
case 'floatLeft':
|
|
179
|
+
this.data.floatLeft = !this.data.floatLeft;
|
|
180
|
+
this.data.floatRight = false;
|
|
181
|
+
this.data.center = false;
|
|
182
|
+
break;
|
|
183
|
+
case 'floatRight':
|
|
184
|
+
this.data.floatLeft = false;
|
|
185
|
+
this.data.floatRight = !this.data.floatRight;
|
|
186
|
+
this.data.center = false;
|
|
187
|
+
break;
|
|
188
|
+
case 'center':
|
|
189
|
+
this.data.center = !this.data.center;
|
|
190
|
+
this.data.floatLeft = false;
|
|
191
|
+
this.data.floatRight = false;
|
|
192
|
+
break;
|
|
193
|
+
case 'sizeSmall':
|
|
194
|
+
this.data.sizeSmall = !this.data.sizeSmall;
|
|
195
|
+
this.data.sizeMiddle = false;
|
|
196
|
+
this.data.sizeLarge = false;
|
|
197
|
+
this.data.resize = false;
|
|
198
|
+
|
|
199
|
+
break;
|
|
200
|
+
case 'sizeMiddle':
|
|
201
|
+
this.data.sizeSmall = false;
|
|
202
|
+
this.data.sizeMiddle = !this.data.sizeMiddle;
|
|
203
|
+
this.data.sizeLarge = false;
|
|
204
|
+
this.data.resize = false;
|
|
205
|
+
|
|
206
|
+
break;
|
|
207
|
+
case 'sizeLarge':
|
|
208
|
+
this.data.sizeSmall = false;
|
|
209
|
+
this.data.sizeMiddle = false;
|
|
210
|
+
this.data.sizeLarge = !this.data.sizeLarge;
|
|
211
|
+
this.data.resize = false;
|
|
212
|
+
|
|
213
|
+
break;
|
|
214
|
+
case 'resize':
|
|
215
|
+
this.data.sizeSmall = false;
|
|
216
|
+
this.data.sizeMiddle = false;
|
|
217
|
+
this.data.sizeLarge = false;
|
|
218
|
+
this.data.resize = !this.data.resize;
|
|
219
|
+
|
|
220
|
+
break;
|
|
221
|
+
|
|
222
|
+
default:
|
|
223
|
+
this.data.floatLeft = false;
|
|
224
|
+
this.data.floatRight = false;
|
|
225
|
+
this.data.sizeSmall = false;
|
|
226
|
+
this.data.sizeMiddle = false;
|
|
227
|
+
this.data.sizeLarge = false;
|
|
228
|
+
this.data.resize = false;
|
|
229
|
+
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!this.data.resize) {
|
|
234
|
+
this.data.resizeSize = 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
const blockContent = this.block.holder.querySelector(
|
|
240
|
+
'.ce-block__content',
|
|
241
|
+
) as HTMLElement;
|
|
242
|
+
this.apply(blockContent);
|
|
243
|
+
this.block.dispatchChange();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Append class to block by tune data
|
|
248
|
+
* @param {HTMLElement} blockContent - wrapper for block content
|
|
249
|
+
* @public
|
|
250
|
+
* @return {void}
|
|
251
|
+
* */
|
|
252
|
+
apply(blockContent: HTMLElement): void {
|
|
253
|
+
if (this.data.floatLeft) {
|
|
254
|
+
blockContent.classList.add(this.CSS.isFloatLeft);
|
|
255
|
+
} else {
|
|
256
|
+
blockContent.classList.remove(this.CSS.isFloatLeft);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (this.data.floatRight) {
|
|
260
|
+
blockContent.classList.add(this.CSS.isFloatRight);
|
|
261
|
+
} else {
|
|
262
|
+
blockContent.classList.remove(this.CSS.isFloatRight);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (this.data.center) {
|
|
266
|
+
blockContent.classList.add(this.CSS.isCenter);
|
|
267
|
+
} else {
|
|
268
|
+
blockContent.classList.remove(this.CSS.isCenter);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (this.data.sizeSmall) {
|
|
272
|
+
blockContent.classList.add(this.CSS.isSizeSmall);
|
|
273
|
+
} else {
|
|
274
|
+
blockContent.classList.remove(this.CSS.isSizeSmall);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (this.data.sizeMiddle) {
|
|
278
|
+
blockContent.classList.add(this.CSS.isSizeMiddle);
|
|
279
|
+
} else {
|
|
280
|
+
blockContent.classList.remove(this.CSS.isSizeMiddle);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (this.data.sizeLarge) {
|
|
284
|
+
blockContent.classList.add(this.CSS.isSizeLarge);
|
|
285
|
+
} else {
|
|
286
|
+
blockContent.classList.remove(this.CSS.isSizeLarge);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (this.data.resize) {
|
|
290
|
+
blockContent.classList.add(this.CSS.isResize);
|
|
291
|
+
|
|
292
|
+
if (this.data.resizeSize > 0) {
|
|
293
|
+
const cdxBlock = blockContent.getElementsByClassName(
|
|
294
|
+
'cdx-block',
|
|
295
|
+
)[0] as HTMLElement;
|
|
296
|
+
cdxBlock.style.width = this.data.resizeSize + 'px';
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this.resize(blockContent);
|
|
300
|
+
} else {
|
|
301
|
+
blockContent.classList.remove(this.CSS.isResize);
|
|
302
|
+
this.unresize(blockContent);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Add resize handles to block
|
|
311
|
+
* @param {HTMLElement} blockContent - wrapper for block content
|
|
312
|
+
* @public
|
|
313
|
+
* @return {void}
|
|
314
|
+
* */
|
|
315
|
+
resize(blockContent: HTMLElement): void {
|
|
316
|
+
if (this.api.readOnly.isEnabled) return;
|
|
317
|
+
const resizable = document.createElement('div');
|
|
318
|
+
resizable.classList.add('resizable');
|
|
319
|
+
|
|
320
|
+
const resizers = document.createElement('div');
|
|
321
|
+
resizers.classList.add('resizers');
|
|
322
|
+
|
|
323
|
+
const resizerTopRight = document.createElement('div');
|
|
324
|
+
resizerTopRight.classList.add('resizer', 'top-right');
|
|
325
|
+
resizerTopRight.addEventListener('mousedown', e => {
|
|
326
|
+
this.resizeClick(
|
|
327
|
+
blockContent.getElementsByClassName('cdx-block')[0] as HTMLElement,
|
|
328
|
+
"right",
|
|
329
|
+
e,
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const resizerBottomRight = document.createElement('div');
|
|
334
|
+
resizerBottomRight.classList.add('resizer', 'bottom-right');
|
|
335
|
+
resizerBottomRight.addEventListener('mousedown', e => {
|
|
336
|
+
this.resizeClick(
|
|
337
|
+
blockContent.getElementsByClassName('cdx-block')[0] as HTMLElement,
|
|
338
|
+
"right",
|
|
339
|
+
e,
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const resizerTopLeft = document.createElement('div');
|
|
344
|
+
resizerTopLeft.classList.add('resizer', 'top-left');
|
|
345
|
+
resizerTopLeft.addEventListener('mousedown', e => {
|
|
346
|
+
this.resizeClick(
|
|
347
|
+
blockContent.getElementsByClassName('cdx-block')[0] as HTMLElement,
|
|
348
|
+
"left",
|
|
349
|
+
e,
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
const resizerBottomLeft = document.createElement('div');
|
|
353
|
+
resizerBottomLeft.classList.add('resizer', 'bottom-left');
|
|
354
|
+
resizerBottomLeft.addEventListener('mousedown', e => {
|
|
355
|
+
this.resizeClick(
|
|
356
|
+
blockContent.getElementsByClassName('cdx-block')[0] as HTMLElement,
|
|
357
|
+
"left",
|
|
358
|
+
e,
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
resizers.appendChild(resizerTopRight);
|
|
364
|
+
resizers.appendChild(resizerBottomRight);
|
|
365
|
+
resizers.appendChild(resizerTopLeft);
|
|
366
|
+
resizers.appendChild(resizerBottomLeft);
|
|
367
|
+
resizable.appendChild(resizers);
|
|
368
|
+
blockContent.getElementsByClassName('cdx-block')[0].appendChild(resizable);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* click event to resize handles
|
|
373
|
+
* preserve aspect ratio
|
|
374
|
+
* prevent block from moving when dragging resize handles
|
|
375
|
+
* max size = 100%
|
|
376
|
+
* min size = 50px
|
|
377
|
+
* @param {HTMLElement} blockContent - wrapper for block content
|
|
378
|
+
* @param {HTMLElement} handle - resize handle
|
|
379
|
+
* @param {MouseEvent} e - mouse event
|
|
380
|
+
* @public
|
|
381
|
+
* @return {void}
|
|
382
|
+
* */
|
|
383
|
+
resizeClick(blockContent: HTMLElement, handleDirection: String, e: MouseEvent): void {
|
|
384
|
+
const maxWidth =
|
|
385
|
+
document.getElementsByClassName('ce-block__content')[0].clientWidth;
|
|
386
|
+
let startX = 0;
|
|
387
|
+
let startWidth = 0;
|
|
388
|
+
|
|
389
|
+
const mouseMoveHandler = (e: MouseEvent) => {
|
|
390
|
+
const dx = e.clientX - startX;
|
|
391
|
+
let newWidth = startWidth;
|
|
392
|
+
if (handleDirection === "right") {
|
|
393
|
+
newWidth += dx;
|
|
394
|
+
}
|
|
395
|
+
if (handleDirection === "left") {
|
|
396
|
+
newWidth -= dx;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (newWidth > 50 && newWidth < maxWidth) {
|
|
400
|
+
(
|
|
401
|
+
blockContent as HTMLElement & { style: CSSStyleDeclaration }
|
|
402
|
+
).style.width = newWidth + 'px';
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const mouseUpHandler = () => {
|
|
407
|
+
const blockWidth = parseInt(
|
|
408
|
+
window.getComputedStyle(blockContent).width,
|
|
409
|
+
10,
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
if (blockWidth > 0) {
|
|
413
|
+
this.data.resizeSize = blockWidth;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
document.removeEventListener('mousemove', mouseMoveHandler);
|
|
417
|
+
document.removeEventListener('mouseup', mouseUpHandler);
|
|
418
|
+
|
|
419
|
+
this.block.dispatchChange();
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
document.addEventListener('mousemove', mouseMoveHandler);
|
|
423
|
+
document.addEventListener('mouseup', mouseUpHandler);
|
|
424
|
+
|
|
425
|
+
startX = e.clientX;
|
|
426
|
+
startWidth = parseInt(window.getComputedStyle(blockContent).width, 10);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Remove resize handles from block
|
|
431
|
+
* @param {HTMLElement} blockContent - wrapper for block content
|
|
432
|
+
* @public
|
|
433
|
+
* @return {void}
|
|
434
|
+
*/
|
|
435
|
+
unresize(blockContent: HTMLElement): void {
|
|
436
|
+
const unresizable = blockContent.getElementsByClassName(
|
|
437
|
+
'resizable',
|
|
438
|
+
)[0] as HTMLElement;
|
|
439
|
+
if (unresizable) {
|
|
440
|
+
blockContent
|
|
441
|
+
.getElementsByClassName('cdx-block')[0]
|
|
442
|
+
.removeChild(unresizable);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const block: HTMLElement = blockContent.getElementsByClassName(
|
|
446
|
+
'cdx-block',
|
|
447
|
+
)[0] as HTMLElement;
|
|
448
|
+
block.style.width = 'auto';
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Remove tunes from block wrapper
|
|
453
|
+
* @param {HTMLElement} blockContent - wrapper for block content
|
|
454
|
+
* @public
|
|
455
|
+
* @return {HTMLElement}
|
|
456
|
+
*/
|
|
457
|
+
unwrap(blockContent: HTMLElement): HTMLElement {
|
|
458
|
+
//remove tunes from block
|
|
459
|
+
this.buttons.forEach(button => {
|
|
460
|
+
button.classList.remove(this.CSS.buttonActive);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
//remove isFloatLeft class
|
|
464
|
+
blockContent.classList.remove(this.CSS.isFloatLeft);
|
|
465
|
+
|
|
466
|
+
//remove isFloatRight class
|
|
467
|
+
blockContent.classList.remove(this.CSS.isFloatRight);
|
|
468
|
+
|
|
469
|
+
//remove isCenter class
|
|
470
|
+
blockContent.classList.remove(this.CSS.isCenter);
|
|
471
|
+
|
|
472
|
+
//remove isSizeSmall class
|
|
473
|
+
blockContent.classList.remove(this.CSS.isSizeSmall);
|
|
474
|
+
|
|
475
|
+
//remove isSizeMiddle class
|
|
476
|
+
blockContent.classList.remove(this.CSS.isSizeMiddle);
|
|
477
|
+
|
|
478
|
+
//remove isSizeLarge class
|
|
479
|
+
blockContent.classList.remove(this.CSS.isSizeLarge);
|
|
480
|
+
|
|
481
|
+
//remove isResize class
|
|
482
|
+
blockContent.classList.remove(this.CSS.isResize);
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
const cdxBlock = blockContent.getElementsByClassName(
|
|
487
|
+
'cdx-block',
|
|
488
|
+
)[0] as HTMLElement;
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
//remove min and max width
|
|
495
|
+
cdxBlock.style.minWidth = '';
|
|
496
|
+
cdxBlock.style.maxWidth = '';
|
|
497
|
+
|
|
498
|
+
//remove image width and height
|
|
499
|
+
const imageToolImage = blockContent.getElementsByClassName(
|
|
500
|
+
'image-tool__image',
|
|
501
|
+
)[0] as HTMLElement;
|
|
502
|
+
imageToolImage.style.width = '';
|
|
503
|
+
imageToolImage.style.height = '';
|
|
504
|
+
|
|
505
|
+
//remove image left and top
|
|
506
|
+
const image = imageToolImage.getElementsByTagName(
|
|
507
|
+
'img',
|
|
508
|
+
)[0] as HTMLImageElement;
|
|
509
|
+
image.style.left = '';
|
|
510
|
+
image.style.top = '';
|
|
511
|
+
|
|
512
|
+
//remove image width and height
|
|
513
|
+
image.style.width = '';
|
|
514
|
+
image.style.height = '';
|
|
515
|
+
|
|
516
|
+
//remove resize handles
|
|
517
|
+
this.unresize(blockContent);
|
|
518
|
+
|
|
519
|
+
return blockContent;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Add tune to block data
|
|
524
|
+
* @private
|
|
525
|
+
* @return {ImageToolTuneData}
|
|
526
|
+
* */
|
|
527
|
+
save(): ImageToolTuneData {
|
|
528
|
+
return this.data;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Append tunes to block wrapper
|
|
533
|
+
* @param {HTMLElement} blockContent - wrapper for block content
|
|
534
|
+
* @public
|
|
535
|
+
* @return {HTMLElement}
|
|
536
|
+
* */
|
|
537
|
+
wrap(blockContent: HTMLElement): HTMLElement {
|
|
538
|
+
//createview if not exists
|
|
539
|
+
if (!this.wrapper) {
|
|
540
|
+
this.wrapper = this.createView();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
this.apply(blockContent);
|
|
544
|
+
return blockContent;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
private tuneNameToI18nKey(tuneName: string): string {
|
|
548
|
+
const translation: Record<string, string> = {
|
|
549
|
+
resize: 'Resize',
|
|
550
|
+
};
|
|
551
|
+
return translation[tuneName];
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Creates a view for tunes
|
|
556
|
+
* @return {HTMLElement}
|
|
557
|
+
* @private
|
|
558
|
+
* */
|
|
559
|
+
createView(): HTMLElement {
|
|
560
|
+
this.buttons = this.settings.map(tune => {
|
|
561
|
+
const el = document.createElement('div');
|
|
562
|
+
const buttonIco = document.createElement('span');
|
|
563
|
+
const buttonTxt = document.createElement('span');
|
|
564
|
+
el.classList.add(this.CSS.button);
|
|
565
|
+
buttonTxt.style.fontSize = '8px';
|
|
566
|
+
buttonIco.innerHTML = tune.icon;
|
|
567
|
+
buttonTxt.innerHTML = tune.label;
|
|
568
|
+
el.appendChild(buttonIco);
|
|
569
|
+
el.appendChild(buttonTxt);
|
|
570
|
+
el.dataset.tune = tune.name;
|
|
571
|
+
el.title = tune.label;
|
|
572
|
+
|
|
573
|
+
el.addEventListener('click', e => this.tuneClicked(e, el));
|
|
574
|
+
this.api.tooltip.onHover(
|
|
575
|
+
el,
|
|
576
|
+
this.api.i18n.t(this.tuneNameToI18nKey(tune.name)),
|
|
577
|
+
);
|
|
578
|
+
return el;
|
|
579
|
+
});
|
|
580
|
+
const wrapper = document.createElement('div');
|
|
581
|
+
this.buttons.forEach(button => {
|
|
582
|
+
wrapper.appendChild(button);
|
|
583
|
+
});
|
|
584
|
+
wrapper.classList.add(this.CSS.wrapper);
|
|
585
|
+
return wrapper;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Checks if tune is active
|
|
590
|
+
* @param {string} tune - tune name
|
|
591
|
+
* @return {boolean}
|
|
592
|
+
* @private
|
|
593
|
+
* */
|
|
594
|
+
isTuneActive(tune: string): boolean {
|
|
595
|
+
return !!this.data[tune as keyof ImageToolTuneData];
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Makes buttons with tunes
|
|
600
|
+
* @return {HTMLElement}
|
|
601
|
+
* @public
|
|
602
|
+
* */
|
|
603
|
+
render(): HTMLElement {
|
|
604
|
+
//when editor is ready
|
|
605
|
+
this.buttons.forEach(button => {
|
|
606
|
+
const tuneName = button.dataset.tune || '';
|
|
607
|
+
button.classList.toggle(
|
|
608
|
+
this.CSS.buttonActive,
|
|
609
|
+
this.isTuneActive(tuneName),
|
|
610
|
+
);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
return this.view;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Destroys the plugin
|
|
618
|
+
* @public
|
|
619
|
+
* @return {void}
|
|
620
|
+
* */
|
|
621
|
+
destroy(): void {
|
|
622
|
+
this.wrapper = undefined;
|
|
623
|
+
this.buttons = [];
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Toggle tune
|
|
628
|
+
* @param {string} tuneName - tune name
|
|
629
|
+
* @private
|
|
630
|
+
* @return {void}
|
|
631
|
+
* */
|
|
632
|
+
_toggleTune(tuneName: string): void {
|
|
633
|
+
this.setTune(tuneName);
|
|
634
|
+
}
|
|
635
|
+
}
|