suneditor 3.0.0-beta.3 → 3.0.0-beta.30
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/CONTRIBUTING.md +8 -8
- package/README.md +44 -49
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +95 -53
- package/src/assets/design/color.css +2 -2
- package/src/assets/design/size.css +2 -0
- package/src/assets/icons/defaultIcons.js +16 -1
- package/src/assets/suneditor-contents.css +9 -8
- package/src/assets/suneditor.css +29 -26
- package/src/core/{section → base}/actives.js +20 -12
- package/src/core/base/history.js +4 -4
- package/src/core/class/char.js +10 -10
- package/src/core/class/component.js +146 -57
- package/src/core/class/format.js +94 -2458
- package/src/core/class/html.js +187 -129
- package/src/core/class/inline.js +1853 -0
- package/src/core/class/listFormat.js +582 -0
- package/src/core/class/menu.js +14 -3
- package/src/core/class/nodeTransform.js +9 -14
- package/src/core/class/offset.js +162 -197
- package/src/core/class/selection.js +137 -34
- package/src/core/class/toolbar.js +73 -52
- package/src/core/class/ui.js +11 -11
- package/src/core/class/viewer.js +56 -55
- package/src/core/config/context.js +122 -0
- package/src/core/config/frameContext.js +204 -0
- package/src/core/config/options.js +639 -0
- package/src/core/editor.js +181 -108
- package/src/core/event/actions/index.js +229 -0
- package/src/core/event/effects/common.registry.js +60 -0
- package/src/core/event/effects/keydown.registry.js +551 -0
- package/src/core/event/effects/ruleHelpers.js +145 -0
- package/src/core/{base → event}/eventManager.js +119 -201
- package/src/core/event/executor.js +21 -0
- package/src/core/{base/eventHandlers → event/handlers}/handler_toolbar.js +4 -4
- package/src/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.js +2 -2
- package/src/core/event/handlers/handler_ww_input.js +77 -0
- package/src/core/event/handlers/handler_ww_key.js +228 -0
- package/src/core/{base/eventHandlers → event/handlers}/handler_ww_mouse.js +3 -3
- package/src/core/event/ports.js +211 -0
- package/src/core/event/reducers/keydown.reducer.js +89 -0
- package/src/core/event/rules/keydown.rule.arrow.js +54 -0
- package/src/core/event/rules/keydown.rule.backspace.js +202 -0
- package/src/core/event/rules/keydown.rule.delete.js +126 -0
- package/src/core/event/rules/keydown.rule.enter.js +144 -0
- package/src/core/event/rules/keydown.rule.tab.js +29 -0
- package/src/core/section/constructor.js +79 -388
- package/src/core/section/documentType.js +47 -26
- package/src/core/util/instanceCheck.js +59 -0
- package/src/editorInjector/_classes.js +4 -0
- package/src/editorInjector/_core.js +17 -7
- package/src/editorInjector/index.js +10 -2
- package/src/events.js +6 -0
- package/src/helper/clipboard.js +24 -10
- package/src/helper/converter.js +17 -12
- package/src/helper/dom/domCheck.js +22 -3
- package/src/helper/dom/domQuery.js +91 -45
- package/src/helper/dom/domUtils.js +93 -19
- package/src/helper/dom/index.js +4 -0
- package/src/helper/env.js +11 -7
- package/src/helper/keyCodeMap.js +4 -3
- package/src/langs/ckb.js +1 -1
- package/src/langs/cs.js +1 -1
- package/src/langs/da.js +1 -1
- package/src/langs/de.js +1 -1
- package/src/langs/en.js +1 -1
- package/src/langs/es.js +1 -1
- package/src/langs/fa.js +1 -1
- package/src/langs/fr.js +1 -1
- package/src/langs/he.js +1 -1
- package/src/langs/hu.js +1 -1
- package/src/langs/it.js +1 -1
- package/src/langs/ja.js +1 -1
- package/src/langs/km.js +1 -1
- package/src/langs/ko.js +1 -1
- package/src/langs/lv.js +1 -1
- package/src/langs/nl.js +1 -1
- package/src/langs/pl.js +1 -1
- package/src/langs/pt_br.js +10 -10
- package/src/langs/ro.js +1 -1
- package/src/langs/ru.js +1 -1
- package/src/langs/se.js +1 -1
- package/src/langs/tr.js +1 -1
- package/src/langs/uk.js +1 -1
- package/src/langs/ur.js +1 -1
- package/src/langs/zh_cn.js +1 -1
- package/src/modules/ApiManager.js +25 -18
- package/src/modules/Browser.js +52 -61
- package/src/modules/ColorPicker.js +37 -38
- package/src/modules/Controller.js +85 -79
- package/src/modules/Figure.js +275 -187
- package/src/modules/FileManager.js +86 -92
- package/src/modules/HueSlider.js +67 -35
- package/src/modules/Modal.js +84 -77
- package/src/modules/ModalAnchorEditor.js +62 -79
- package/src/modules/SelectMenu.js +89 -86
- package/src/plugins/browser/audioGallery.js +9 -5
- package/src/plugins/browser/fileBrowser.js +10 -6
- package/src/plugins/browser/fileGallery.js +9 -5
- package/src/plugins/browser/imageGallery.js +9 -5
- package/src/plugins/browser/videoGallery.js +11 -6
- package/src/plugins/command/blockquote.js +1 -0
- package/src/plugins/command/exportPDF.js +11 -8
- package/src/plugins/command/fileUpload.js +41 -29
- package/src/plugins/command/list_bulleted.js +2 -1
- package/src/plugins/command/list_numbered.js +2 -1
- package/src/plugins/dropdown/align.js +8 -2
- package/src/plugins/dropdown/backgroundColor.js +19 -11
- package/src/plugins/dropdown/font.js +15 -9
- package/src/plugins/dropdown/fontColor.js +19 -11
- package/src/plugins/dropdown/formatBlock.js +7 -2
- package/src/plugins/dropdown/hr.js +7 -3
- package/src/plugins/dropdown/layout.js +6 -2
- package/src/plugins/dropdown/lineHeight.js +8 -3
- package/src/plugins/dropdown/list.js +2 -1
- package/src/plugins/dropdown/paragraphStyle.js +15 -11
- package/src/plugins/dropdown/{table.js → table/index.js} +514 -362
- package/src/plugins/dropdown/template.js +6 -2
- package/src/plugins/dropdown/textStyle.js +7 -3
- package/src/plugins/field/mention.js +33 -27
- package/src/plugins/input/fontSize.js +44 -37
- package/src/plugins/input/pageNavigator.js +3 -2
- package/src/plugins/modal/audio.js +90 -85
- package/src/plugins/modal/drawing.js +58 -66
- package/src/plugins/modal/embed.js +193 -180
- package/src/plugins/modal/image.js +441 -439
- package/src/plugins/modal/link.js +31 -8
- package/src/plugins/modal/math.js +23 -22
- package/src/plugins/modal/video.js +233 -230
- package/src/plugins/popup/anchor.js +24 -18
- package/src/suneditor.js +69 -24
- package/src/typedef.js +42 -19
- package/types/assets/icons/defaultIcons.d.ts +8 -0
- package/types/core/class/char.d.ts +1 -1
- package/types/core/class/component.d.ts +29 -7
- package/types/core/class/format.d.ts +4 -354
- package/types/core/class/html.d.ts +13 -4
- package/types/core/class/inline.d.ts +263 -0
- package/types/core/class/listFormat.d.ts +135 -0
- package/types/core/class/menu.d.ts +10 -2
- package/types/core/class/offset.d.ts +24 -26
- package/types/core/class/selection.d.ts +2 -0
- package/types/core/class/toolbar.d.ts +24 -11
- package/types/core/class/ui.d.ts +1 -1
- package/types/core/class/viewer.d.ts +1 -1
- package/types/core/config/context.d.ts +157 -0
- package/types/core/config/frameContext.d.ts +367 -0
- package/types/core/config/options.d.ts +1119 -0
- package/types/core/editor.d.ts +101 -66
- package/types/core/event/actions/index.d.ts +47 -0
- package/types/core/event/effects/common.registry.d.ts +50 -0
- package/types/core/event/effects/keydown.registry.d.ts +73 -0
- package/types/core/event/effects/ruleHelpers.d.ts +31 -0
- package/types/core/{base → event}/eventManager.d.ts +15 -46
- package/types/core/event/executor.d.ts +6 -0
- package/types/core/event/handlers/handler_ww_input.d.ts +41 -0
- package/types/core/{base/eventHandlers/handler_ww_key_input.d.ts → event/handlers/handler_ww_key.d.ts} +4 -6
- package/types/core/event/ports.d.ts +255 -0
- package/types/core/event/reducers/keydown.reducer.d.ts +75 -0
- package/types/core/event/rules/keydown.rule.arrow.d.ts +8 -0
- package/types/core/event/rules/keydown.rule.backspace.d.ts +9 -0
- package/types/core/event/rules/keydown.rule.delete.d.ts +9 -0
- package/types/core/event/rules/keydown.rule.enter.d.ts +9 -0
- package/types/core/event/rules/keydown.rule.tab.d.ts +9 -0
- package/types/core/section/constructor.d.ts +101 -631
- package/types/core/section/documentType.d.ts +14 -4
- package/types/core/util/instanceCheck.d.ts +50 -0
- package/types/editorInjector/_classes.d.ts +4 -0
- package/types/editorInjector/_core.d.ts +17 -7
- package/types/editorInjector/index.d.ts +10 -2
- package/types/events.d.ts +1 -0
- package/types/helper/clipboard.d.ts +2 -2
- package/types/helper/converter.d.ts +6 -9
- package/types/helper/dom/domCheck.d.ts +7 -0
- package/types/helper/dom/domQuery.d.ts +19 -8
- package/types/helper/dom/domUtils.d.ts +24 -2
- package/types/helper/dom/index.d.ts +86 -1
- package/types/helper/env.d.ts +6 -1
- package/types/helper/index.d.ts +7 -1
- package/types/helper/keyCodeMap.d.ts +3 -3
- package/types/index.d.ts +23 -117
- package/types/langs/index.d.ts +2 -2
- package/types/modules/ApiManager.d.ts +1 -8
- package/types/modules/Browser.d.ts +4 -62
- package/types/modules/ColorPicker.d.ts +4 -21
- package/types/modules/Controller.d.ts +8 -64
- package/types/modules/Figure.d.ts +54 -50
- package/types/modules/FileManager.d.ts +1 -13
- package/types/modules/HueSlider.d.ts +13 -3
- package/types/modules/Modal.d.ts +0 -43
- package/types/modules/ModalAnchorEditor.d.ts +0 -73
- package/types/modules/SelectMenu.d.ts +0 -85
- package/types/modules/index.d.ts +3 -3
- package/types/plugins/browser/audioGallery.d.ts +29 -18
- package/types/plugins/browser/fileBrowser.d.ts +38 -27
- package/types/plugins/browser/fileGallery.d.ts +29 -18
- package/types/plugins/browser/imageGallery.d.ts +24 -16
- package/types/plugins/browser/videoGallery.d.ts +29 -18
- package/types/plugins/command/blockquote.d.ts +1 -0
- package/types/plugins/command/exportPDF.d.ts +18 -18
- package/types/plugins/command/fileUpload.d.ts +65 -45
- package/types/plugins/command/list_bulleted.d.ts +1 -0
- package/types/plugins/command/list_numbered.d.ts +1 -0
- package/types/plugins/dropdown/align.d.ts +13 -8
- package/types/plugins/dropdown/backgroundColor.d.ts +30 -19
- package/types/plugins/dropdown/font.d.ts +13 -12
- package/types/plugins/dropdown/fontColor.d.ts +30 -19
- package/types/plugins/dropdown/formatBlock.d.ts +13 -8
- package/types/plugins/dropdown/hr.d.ts +15 -11
- package/types/plugins/dropdown/layout.d.ts +15 -11
- package/types/plugins/dropdown/lineHeight.d.ts +16 -11
- package/types/plugins/dropdown/list.d.ts +1 -0
- package/types/plugins/dropdown/paragraphStyle.d.ts +31 -27
- package/types/plugins/dropdown/table/index.d.ts +582 -0
- package/types/plugins/dropdown/table.d.ts +41 -86
- package/types/plugins/dropdown/template.d.ts +15 -11
- package/types/plugins/dropdown/textStyle.d.ts +19 -11
- package/types/plugins/field/mention.d.ts +58 -56
- package/types/plugins/index.d.ts +38 -38
- package/types/plugins/input/fontSize.d.ts +46 -50
- package/types/plugins/modal/audio.d.ts +26 -56
- package/types/plugins/modal/drawing.d.ts +0 -85
- package/types/plugins/modal/embed.d.ts +15 -79
- package/types/plugins/modal/image.d.ts +24 -136
- package/types/plugins/modal/link.d.ts +34 -15
- package/types/plugins/modal/math.d.ts +0 -16
- package/types/plugins/modal/video.d.ts +17 -86
- package/types/plugins/popup/anchor.d.ts +1 -8
- package/types/suneditor.d.ts +70 -19
- package/types/typedef.d.ts +60 -46
- package/src/core/base/eventHandlers/handler_ww_key_input.js +0 -1200
- package/src/core/section/context.js +0 -102
- package/types/core/section/context.d.ts +0 -45
- package/types/langs/_Lang.d.ts +0 -194
- /package/src/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.js +0 -0
- /package/types/core/{section → base}/actives.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_toolbar.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_mouse.d.ts +0 -0
|
@@ -2,7 +2,7 @@ import EditorInjector from '../../editorInjector';
|
|
|
2
2
|
import { Modal } from '../../modules';
|
|
3
3
|
import { dom, env } from '../../helper';
|
|
4
4
|
|
|
5
|
-
const { _w
|
|
5
|
+
const { _w } = env;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {Object} DrawingPluginOptions
|
|
@@ -34,6 +34,9 @@ class Drawing extends EditorInjector {
|
|
|
34
34
|
static type = 'modal';
|
|
35
35
|
static className = '';
|
|
36
36
|
|
|
37
|
+
#events;
|
|
38
|
+
#eventsRegister;
|
|
39
|
+
|
|
37
40
|
/**
|
|
38
41
|
* @constructor
|
|
39
42
|
* @param {__se__EditorCore} editor - The root editor instance
|
|
@@ -96,27 +99,25 @@ class Drawing extends EditorInjector {
|
|
|
96
99
|
this.points = [];
|
|
97
100
|
this.paths = [];
|
|
98
101
|
this.resizeObserver = null;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
|
|
103
|
+
this.#events = {
|
|
104
|
+
touchstart: this.#OnCanvasTouchStart.bind(this),
|
|
105
|
+
touchmove: this.#OnCanvasTouchMove.bind(this),
|
|
106
|
+
mousedown: this.#OnCanvasMouseDown.bind(this),
|
|
107
|
+
mousemove: this.#OnCanvasMouseMove.bind(this),
|
|
102
108
|
mouseup: this.#OnCanvasMouseUp.bind(this),
|
|
103
109
|
mouseleave: this.#OnCanvasMouseLeave.bind(this),
|
|
104
110
|
mouseenter: this.#OnCanvasMouseEnter.bind(this)
|
|
105
111
|
};
|
|
106
|
-
this
|
|
112
|
+
this.#eventsRegister = {
|
|
113
|
+
touchstart: null,
|
|
114
|
+
touchmove: null,
|
|
107
115
|
mousedown: null,
|
|
108
116
|
mousemove: null,
|
|
109
117
|
mouseup: null,
|
|
110
118
|
mouseleave: null,
|
|
111
119
|
mouseenter: null
|
|
112
120
|
};
|
|
113
|
-
this.__eventNameMap = {
|
|
114
|
-
mousedown: isMobile ? 'touchstart' : 'mousedown',
|
|
115
|
-
mousemove: isMobile ? 'touchmove' : 'mousemove',
|
|
116
|
-
mouseup: isMobile ? 'touchend' : 'mouseup',
|
|
117
|
-
mouseleave: 'mouseleave',
|
|
118
|
-
mouseenter: 'mouseenter'
|
|
119
|
-
};
|
|
120
121
|
|
|
121
122
|
// init
|
|
122
123
|
this.eventManager.addEvent(modalEl.querySelector('[data-command="remove"]'), 'click', this.#OnRemove.bind(this));
|
|
@@ -128,10 +129,10 @@ class Drawing extends EditorInjector {
|
|
|
128
129
|
*/
|
|
129
130
|
open() {
|
|
130
131
|
if (this.pluginOptions.useFormatType) {
|
|
131
|
-
this
|
|
132
|
+
this.#activeAsInline((this.pluginOptions.keepFormatType ? this.as : this.pluginOptions.defaultFormatType) === 'inline');
|
|
132
133
|
}
|
|
133
134
|
this.modal.open();
|
|
134
|
-
this
|
|
135
|
+
this.#initDrawing();
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
/**
|
|
@@ -139,7 +140,7 @@ class Drawing extends EditorInjector {
|
|
|
139
140
|
* @description Executes the method that is called when a plugin's "modal" is closed.
|
|
140
141
|
*/
|
|
141
142
|
off() {
|
|
142
|
-
this
|
|
143
|
+
this.#destroyDrawing();
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
/**
|
|
@@ -149,7 +150,7 @@ class Drawing extends EditorInjector {
|
|
|
149
150
|
*/
|
|
150
151
|
modalAction() {
|
|
151
152
|
if (this.pluginOptions.outputFormat === 'svg') {
|
|
152
|
-
const files = this
|
|
153
|
+
const files = this.#getSVGFileList();
|
|
153
154
|
this.plugins.image.init();
|
|
154
155
|
this.plugins.image.submitFile(files);
|
|
155
156
|
} else {
|
|
@@ -168,10 +169,9 @@ class Drawing extends EditorInjector {
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
/**
|
|
171
|
-
* @private
|
|
172
172
|
* @description Initializes the drawing canvas, sets up event listeners, and configures resize handling.
|
|
173
173
|
*/
|
|
174
|
-
|
|
174
|
+
#initDrawing() {
|
|
175
175
|
const canvas = (this.canvas = this.modal.form.querySelector('.se-drawing-canvas'));
|
|
176
176
|
this.ctx = canvas.getContext('2d');
|
|
177
177
|
canvas.width = canvas.offsetWidth;
|
|
@@ -180,13 +180,15 @@ class Drawing extends EditorInjector {
|
|
|
180
180
|
this.points = [];
|
|
181
181
|
this.paths = [];
|
|
182
182
|
|
|
183
|
-
this
|
|
183
|
+
this.#setCtx();
|
|
184
184
|
|
|
185
|
-
this.
|
|
186
|
-
this.
|
|
187
|
-
this.
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
185
|
+
this.#eventsRegister.touchstart = this.eventManager.addEvent(canvas, 'touchstart', this.#events.touchstart, { passive: false, capture: true });
|
|
186
|
+
this.#eventsRegister.touchmove = this.eventManager.addEvent(canvas, 'touchmove', this.#events.touchmove, true);
|
|
187
|
+
this.#eventsRegister.mousedown = this.eventManager.addEvent(canvas, 'mousedown', this.#events.mousedown, { passive: false, capture: true });
|
|
188
|
+
this.#eventsRegister.mousemove = this.eventManager.addEvent(canvas, 'mousemove', this.#events.mousemove, true);
|
|
189
|
+
this.#eventsRegister.mouseup = this.eventManager.addEvent(canvas, 'mouseup', this.#events.mouseup, true);
|
|
190
|
+
this.#eventsRegister.mouseleave = this.eventManager.addEvent(canvas, 'mouseleave', this.#events.mouseleave);
|
|
191
|
+
this.#eventsRegister.mouseenter = this.eventManager.addEvent(canvas, 'mouseenter', this.#events.mouseenter);
|
|
190
192
|
|
|
191
193
|
if (this.resizeObserver) {
|
|
192
194
|
this.resizeObserver.disconnect();
|
|
@@ -202,8 +204,8 @@ class Drawing extends EditorInjector {
|
|
|
202
204
|
canvas.width = newWidth;
|
|
203
205
|
canvas.height = newHeight;
|
|
204
206
|
if (prevWidth !== canvas.width || prevHeight !== canvas.height) {
|
|
205
|
-
if (this.pluginOptions.maintainRatio) this
|
|
206
|
-
this
|
|
207
|
+
if (this.pluginOptions.maintainRatio) this.#adjustPathsToNewDimensions(prevWidth, prevHeight, newWidth, newHeight);
|
|
208
|
+
this.#drawAll();
|
|
207
209
|
}
|
|
208
210
|
});
|
|
209
211
|
|
|
@@ -212,21 +214,20 @@ class Drawing extends EditorInjector {
|
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
/**
|
|
215
|
-
* @private
|
|
216
217
|
* @description Destroys the drawing canvas, removes event listeners, and clears stored drawing data.
|
|
217
218
|
*/
|
|
218
|
-
|
|
219
|
+
#destroyDrawing() {
|
|
219
220
|
if (this.resizeObserver) {
|
|
220
221
|
this.resizeObserver.disconnect();
|
|
221
222
|
this.resizeObserver = null;
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
if (this.canvas) {
|
|
225
|
-
this.eventManager.removeEvent(this.
|
|
226
|
-
this.eventManager.removeEvent(this.
|
|
227
|
-
this.eventManager.removeEvent(this.
|
|
228
|
-
this.eventManager.removeEvent(this.
|
|
229
|
-
this.eventManager.removeEvent(this.
|
|
226
|
+
this.eventManager.removeEvent(this.#eventsRegister.mousedown);
|
|
227
|
+
this.eventManager.removeEvent(this.#eventsRegister.mousemove);
|
|
228
|
+
this.eventManager.removeEvent(this.#eventsRegister.mouseup);
|
|
229
|
+
this.eventManager.removeEvent(this.#eventsRegister.mouseleave);
|
|
230
|
+
this.eventManager.removeEvent(this.#eventsRegister.mouseenter);
|
|
230
231
|
}
|
|
231
232
|
|
|
232
233
|
this.canvas = null;
|
|
@@ -237,21 +238,19 @@ class Drawing extends EditorInjector {
|
|
|
237
238
|
}
|
|
238
239
|
|
|
239
240
|
/**
|
|
240
|
-
* @private
|
|
241
241
|
* @description Configures the drawing context (canvas settings like line width, color, etc.).
|
|
242
242
|
*/
|
|
243
|
-
|
|
243
|
+
#setCtx() {
|
|
244
244
|
this.ctx.lineWidth = this.pluginOptions.lineWidth;
|
|
245
245
|
this.ctx.lineCap = this.pluginOptions.lineCap;
|
|
246
246
|
this.ctx.strokeStyle = this.pluginOptions.lineColor || _w.getComputedStyle(this.carrierWrapper).color;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
|
-
* @private
|
|
251
250
|
* @description Draws the current stroke based on collected points.
|
|
252
251
|
*/
|
|
253
|
-
|
|
254
|
-
this
|
|
252
|
+
#draw() {
|
|
253
|
+
this.#setCtx();
|
|
255
254
|
this.ctx.beginPath();
|
|
256
255
|
this.points.forEach(([x, y], i) => {
|
|
257
256
|
if (i === 0) {
|
|
@@ -264,28 +263,26 @@ class Drawing extends EditorInjector {
|
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
/**
|
|
267
|
-
* @private
|
|
268
266
|
* @description Redraws all stored paths onto the canvas.
|
|
269
267
|
*/
|
|
270
|
-
|
|
271
|
-
this
|
|
268
|
+
#drawAll() {
|
|
269
|
+
this.#setCtx();
|
|
272
270
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
273
271
|
this.paths.forEach((path) => {
|
|
274
272
|
this.points = path;
|
|
275
|
-
this
|
|
273
|
+
this.#draw();
|
|
276
274
|
});
|
|
277
275
|
this.points = [];
|
|
278
276
|
}
|
|
279
277
|
|
|
280
278
|
/**
|
|
281
|
-
* @private
|
|
282
279
|
* @description Adjusts all stored paths to fit new canvas dimensions after a resize event.
|
|
283
280
|
* @param {number} prevWidth - The previous width of the canvas.
|
|
284
281
|
* @param {number} prevHeight - The previous height of the canvas.
|
|
285
282
|
* @param {number} newWidth - The new width of the canvas.
|
|
286
283
|
* @param {number} newHeight - The new height of the canvas.
|
|
287
284
|
*/
|
|
288
|
-
|
|
285
|
+
#adjustPathsToNewDimensions(prevWidth, prevHeight, newWidth, newHeight) {
|
|
289
286
|
const xRatio = newWidth / prevWidth;
|
|
290
287
|
const yRatio = newHeight / prevHeight;
|
|
291
288
|
|
|
@@ -293,21 +290,19 @@ class Drawing extends EditorInjector {
|
|
|
293
290
|
}
|
|
294
291
|
|
|
295
292
|
/**
|
|
296
|
-
* @private
|
|
297
293
|
* @description Clears the canvas and resets stored drawing paths.
|
|
298
294
|
*/
|
|
299
|
-
|
|
295
|
+
#clearCanvas() {
|
|
300
296
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
301
297
|
this.points = [];
|
|
302
298
|
this.paths = [];
|
|
303
299
|
}
|
|
304
300
|
|
|
305
301
|
/**
|
|
306
|
-
* @private
|
|
307
302
|
* @description Generates an SVG representation of the drawn content.
|
|
308
303
|
* @returns {*} The generated SVG element.
|
|
309
304
|
*/
|
|
310
|
-
|
|
305
|
+
#getSVG() {
|
|
311
306
|
const svgNS = 'http://www.w3.org/2000/svg';
|
|
312
307
|
const svg = document.createElementNS(svgNS, 'svg');
|
|
313
308
|
svg.setAttribute('width', this.canvas.width + '');
|
|
@@ -331,12 +326,11 @@ class Drawing extends EditorInjector {
|
|
|
331
326
|
}
|
|
332
327
|
|
|
333
328
|
/**
|
|
334
|
-
* @private
|
|
335
329
|
* @description Converts the SVG element into a downloadable file.
|
|
336
330
|
* @returns {FileList} A FileList containing the generated SVG file.
|
|
337
331
|
*/
|
|
338
|
-
|
|
339
|
-
const svgElement = this
|
|
332
|
+
#getSVGFileList() {
|
|
333
|
+
const svgElement = this.#getSVG();
|
|
340
334
|
const serializer = new XMLSerializer();
|
|
341
335
|
const svgString = serializer.serializeToString(svgElement);
|
|
342
336
|
const blob = new Blob([svgString], { type: 'image/svg+xml' });
|
|
@@ -350,12 +344,11 @@ class Drawing extends EditorInjector {
|
|
|
350
344
|
}
|
|
351
345
|
|
|
352
346
|
/**
|
|
353
|
-
* @private
|
|
354
347
|
* @description Retrieves touch coordinates relative to the canvas.
|
|
355
348
|
* @param {TouchEvent} e - The touch event.
|
|
356
349
|
* @returns {{x: number, y: number}} An object containing the x and y coordinates.
|
|
357
350
|
*/
|
|
358
|
-
|
|
351
|
+
#getCanvasTouchPointer(e) {
|
|
359
352
|
const { touches } = e;
|
|
360
353
|
const rect = this.canvas.getBoundingClientRect();
|
|
361
354
|
const x = touches[0].clientX - rect.left;
|
|
@@ -364,11 +357,10 @@ class Drawing extends EditorInjector {
|
|
|
364
357
|
}
|
|
365
358
|
|
|
366
359
|
/**
|
|
367
|
-
* @private
|
|
368
360
|
* @description Activates either block or inline format mode for inserted drawings.
|
|
369
361
|
* @param {boolean} isInline - Whether the drawing should be inserted as an inline element.
|
|
370
362
|
*/
|
|
371
|
-
|
|
363
|
+
#activeAsInline(isInline) {
|
|
372
364
|
if (isInline) {
|
|
373
365
|
dom.utils.addClass(this.asInline, 'on');
|
|
374
366
|
dom.utils.removeClass(this.asBlock, 'on');
|
|
@@ -387,7 +379,7 @@ class Drawing extends EditorInjector {
|
|
|
387
379
|
e.preventDefault();
|
|
388
380
|
this.isDrawing = true;
|
|
389
381
|
this.points.push([e.offsetX, e.offsetY]);
|
|
390
|
-
this
|
|
382
|
+
this.#draw();
|
|
391
383
|
}
|
|
392
384
|
|
|
393
385
|
/**
|
|
@@ -397,7 +389,7 @@ class Drawing extends EditorInjector {
|
|
|
397
389
|
e.preventDefault();
|
|
398
390
|
if (!this.isDrawing) return;
|
|
399
391
|
this.points.push([e.offsetX, e.offsetY]);
|
|
400
|
-
this
|
|
392
|
+
this.#draw();
|
|
401
393
|
}
|
|
402
394
|
|
|
403
395
|
/**
|
|
@@ -405,10 +397,10 @@ class Drawing extends EditorInjector {
|
|
|
405
397
|
*/
|
|
406
398
|
#OnCanvasTouchStart(e) {
|
|
407
399
|
e.preventDefault();
|
|
408
|
-
const { x, y } = this
|
|
400
|
+
const { x, y } = this.#getCanvasTouchPointer(e);
|
|
409
401
|
this.isDrawing = true;
|
|
410
402
|
this.points.push([x, y]);
|
|
411
|
-
this
|
|
403
|
+
this.#draw();
|
|
412
404
|
}
|
|
413
405
|
|
|
414
406
|
/**
|
|
@@ -416,10 +408,10 @@ class Drawing extends EditorInjector {
|
|
|
416
408
|
*/
|
|
417
409
|
#OnCanvasTouchMove(e) {
|
|
418
410
|
e.preventDefault();
|
|
419
|
-
const { x, y } = this
|
|
411
|
+
const { x, y } = this.#getCanvasTouchPointer(e);
|
|
420
412
|
if (!this.isDrawing) return;
|
|
421
413
|
this.points.push([x, y]);
|
|
422
|
-
this
|
|
414
|
+
this.#draw();
|
|
423
415
|
}
|
|
424
416
|
|
|
425
417
|
#OnCanvasMouseUp() {
|
|
@@ -449,24 +441,24 @@ class Drawing extends EditorInjector {
|
|
|
449
441
|
if (!this.pluginOptions.lineReconnect) {
|
|
450
442
|
this.points.push([e.offsetX, e.offsetY]);
|
|
451
443
|
} else {
|
|
452
|
-
const lastPath = this.paths
|
|
453
|
-
const lastPoint = lastPath
|
|
444
|
+
const lastPath = this.paths.at(-1);
|
|
445
|
+
const lastPoint = lastPath.at(-1);
|
|
454
446
|
this.points.push([lastPoint[0], lastPoint[1]]);
|
|
455
447
|
this.points.push([e.offsetX, e.offsetY]);
|
|
456
448
|
}
|
|
457
|
-
this
|
|
449
|
+
this.#draw();
|
|
458
450
|
}
|
|
459
451
|
}
|
|
460
452
|
|
|
461
453
|
#OnRemove() {
|
|
462
|
-
this
|
|
454
|
+
this.#clearCanvas();
|
|
463
455
|
}
|
|
464
456
|
|
|
465
457
|
/**
|
|
466
458
|
* @param {MouseEvent} e - Event object
|
|
467
459
|
*/
|
|
468
460
|
#OnClickAsButton(e) {
|
|
469
|
-
this
|
|
461
|
+
this.#activeAsInline(dom.query.getEventTarget(e).getAttribute('data-command') === 'asInline');
|
|
470
462
|
}
|
|
471
463
|
}
|
|
472
464
|
|