suneditor 3.0.0-beta.2 → 3.0.0-beta.20
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 +186 -184
- package/LICENSE +21 -21
- package/README.md +157 -180
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +126 -123
- package/src/assets/design/color.css +131 -121
- package/src/assets/design/index.css +3 -3
- package/src/assets/design/size.css +37 -35
- package/src/assets/design/typography.css +37 -37
- package/src/assets/icons/defaultIcons.js +247 -232
- package/src/assets/suneditor-contents.css +779 -778
- package/src/assets/suneditor.css +43 -35
- package/src/core/base/eventHandlers/handler_toolbar.js +135 -135
- package/src/core/base/eventHandlers/handler_ww_clipboard.js +56 -56
- package/src/core/base/eventHandlers/handler_ww_dragDrop.js +115 -113
- package/src/core/base/eventHandlers/handler_ww_key_input.js +1200 -1200
- package/src/core/base/eventHandlers/handler_ww_mouse.js +194 -194
- package/src/core/base/eventManager.js +1550 -1484
- package/src/core/base/history.js +355 -355
- package/src/core/class/char.js +163 -162
- package/src/core/class/component.js +856 -842
- package/src/core/class/format.js +3433 -3422
- package/src/core/class/html.js +1927 -1890
- package/src/core/class/menu.js +357 -346
- package/src/core/class/nodeTransform.js +424 -424
- package/src/core/class/offset.js +858 -891
- package/src/core/class/selection.js +710 -620
- package/src/core/class/shortcuts.js +98 -98
- package/src/core/class/toolbar.js +438 -430
- package/src/core/class/ui.js +424 -422
- package/src/core/class/viewer.js +750 -750
- package/src/core/editor.js +1810 -1708
- package/src/core/section/actives.js +268 -241
- package/src/core/section/constructor.js +1348 -1661
- package/src/core/section/context.js +102 -102
- package/src/core/section/documentType.js +582 -561
- package/src/core/section/options.js +367 -0
- package/src/core/util/instanceCheck.js +59 -0
- package/src/editorInjector/_classes.js +36 -36
- package/src/editorInjector/_core.js +92 -92
- package/src/editorInjector/index.js +75 -75
- package/src/events.js +634 -622
- package/src/helper/clipboard.js +59 -59
- package/src/helper/converter.js +586 -564
- package/src/helper/dom/domCheck.js +304 -304
- package/src/helper/dom/domQuery.js +677 -669
- package/src/helper/dom/domUtils.js +618 -557
- package/src/helper/dom/index.js +12 -12
- package/src/helper/env.js +249 -240
- package/src/helper/index.js +25 -25
- package/src/helper/keyCodeMap.js +183 -183
- package/src/helper/numbers.js +72 -72
- package/src/helper/unicode.js +47 -47
- package/src/langs/ckb.js +231 -231
- package/src/langs/cs.js +231 -231
- package/src/langs/da.js +231 -231
- package/src/langs/de.js +231 -231
- package/src/langs/en.js +230 -230
- package/src/langs/es.js +231 -231
- package/src/langs/fa.js +231 -231
- package/src/langs/fr.js +231 -231
- package/src/langs/he.js +231 -231
- package/src/langs/hu.js +230 -230
- package/src/langs/index.js +28 -28
- package/src/langs/it.js +231 -231
- package/src/langs/ja.js +230 -230
- package/src/langs/km.js +230 -230
- package/src/langs/ko.js +230 -230
- package/src/langs/lv.js +231 -231
- package/src/langs/nl.js +231 -231
- package/src/langs/pl.js +231 -231
- package/src/langs/pt_br.js +231 -231
- package/src/langs/ro.js +231 -231
- package/src/langs/ru.js +231 -231
- package/src/langs/se.js +231 -231
- package/src/langs/tr.js +231 -231
- package/src/langs/uk.js +231 -231
- package/src/langs/ur.js +231 -231
- package/src/langs/zh_cn.js +231 -231
- package/src/modules/ApiManager.js +191 -191
- package/src/modules/Browser.js +669 -667
- package/src/modules/ColorPicker.js +364 -362
- package/src/modules/Controller.js +474 -454
- package/src/modules/Figure.js +1620 -1617
- package/src/modules/FileManager.js +359 -359
- package/src/modules/HueSlider.js +577 -565
- package/src/modules/Modal.js +346 -346
- package/src/modules/ModalAnchorEditor.js +643 -643
- package/src/modules/SelectMenu.js +549 -549
- package/src/modules/_DragHandle.js +17 -17
- package/src/modules/index.js +14 -14
- package/src/plugins/browser/audioGallery.js +83 -83
- package/src/plugins/browser/fileBrowser.js +103 -103
- package/src/plugins/browser/fileGallery.js +83 -83
- package/src/plugins/browser/imageGallery.js +81 -81
- package/src/plugins/browser/videoGallery.js +103 -103
- package/src/plugins/command/blockquote.js +61 -60
- package/src/plugins/command/exportPDF.js +134 -134
- package/src/plugins/command/fileUpload.js +456 -456
- package/src/plugins/command/list_bulleted.js +149 -148
- package/src/plugins/command/list_numbered.js +152 -151
- package/src/plugins/dropdown/align.js +157 -155
- package/src/plugins/dropdown/backgroundColor.js +108 -104
- package/src/plugins/dropdown/font.js +141 -137
- package/src/plugins/dropdown/fontColor.js +109 -105
- package/src/plugins/dropdown/formatBlock.js +170 -178
- package/src/plugins/dropdown/hr.js +152 -152
- package/src/plugins/dropdown/layout.js +83 -83
- package/src/plugins/dropdown/lineHeight.js +131 -130
- package/src/plugins/dropdown/list.js +123 -122
- package/src/plugins/dropdown/paragraphStyle.js +138 -138
- package/src/plugins/dropdown/table.js +4110 -4000
- package/src/plugins/dropdown/template.js +83 -83
- package/src/plugins/dropdown/textStyle.js +149 -149
- package/src/plugins/field/mention.js +242 -242
- package/src/plugins/index.js +120 -120
- package/src/plugins/input/fontSize.js +414 -410
- package/src/plugins/input/pageNavigator.js +71 -70
- package/src/plugins/modal/audio.js +677 -677
- package/src/plugins/modal/drawing.js +537 -531
- package/src/plugins/modal/embed.js +886 -886
- package/src/plugins/modal/image.js +1377 -1376
- package/src/plugins/modal/link.js +248 -240
- package/src/plugins/modal/math.js +563 -563
- package/src/plugins/modal/video.js +1226 -1226
- package/src/plugins/popup/anchor.js +224 -222
- package/src/suneditor.js +114 -107
- package/src/themes/dark.css +132 -122
- package/src/typedef.js +132 -130
- package/types/assets/icons/defaultIcons.d.ts +8 -0
- package/types/core/base/eventManager.d.ts +29 -4
- package/types/core/class/char.d.ts +2 -1
- package/types/core/class/component.d.ts +1 -2
- package/types/core/class/format.d.ts +8 -1
- package/types/core/class/html.d.ts +8 -0
- package/types/core/class/menu.d.ts +8 -0
- 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 +6 -0
- package/types/core/class/ui.d.ts +1 -1
- package/types/core/editor.d.ts +34 -12
- package/types/core/section/constructor.d.ts +5 -638
- package/types/core/section/documentType.d.ts +12 -2
- package/types/core/section/options.d.ts +740 -0
- package/types/core/util/instanceCheck.d.ts +50 -0
- package/types/editorInjector/_core.d.ts +5 -5
- package/types/editorInjector/index.d.ts +2 -2
- package/types/events.d.ts +2 -0
- package/types/helper/converter.d.ts +9 -0
- package/types/helper/dom/domQuery.d.ts +5 -5
- package/types/helper/dom/domUtils.d.ts +8 -0
- package/types/helper/env.d.ts +6 -1
- package/types/helper/index.d.ts +4 -1
- package/types/index.d.ts +122 -120
- package/types/langs/_Lang.d.ts +194 -194
- package/types/modules/ColorPicker.d.ts +5 -1
- package/types/modules/Controller.d.ts +8 -4
- package/types/modules/Figure.d.ts +2 -1
- package/types/modules/HueSlider.d.ts +4 -1
- package/types/modules/SelectMenu.d.ts +1 -1
- package/types/plugins/command/blockquote.d.ts +1 -0
- 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 +1 -0
- package/types/plugins/dropdown/backgroundColor.d.ts +1 -0
- package/types/plugins/dropdown/font.d.ts +1 -0
- package/types/plugins/dropdown/fontColor.d.ts +1 -0
- package/types/plugins/dropdown/formatBlock.d.ts +3 -2
- package/types/plugins/dropdown/lineHeight.d.ts +1 -0
- package/types/plugins/dropdown/list.d.ts +1 -0
- package/types/plugins/dropdown/table.d.ts +6 -0
- package/types/plugins/input/fontSize.d.ts +1 -0
- package/types/plugins/modal/drawing.d.ts +4 -0
- package/types/plugins/modal/link.d.ts +32 -15
- package/types/suneditor.d.ts +13 -9
- package/types/typedef.d.ts +8 -0
|
@@ -1,362 +1,364 @@
|
|
|
1
|
-
import { dom, converter } from '../helper';
|
|
2
|
-
import { isElement } from '../helper/dom/domCheck';
|
|
3
|
-
import CoreInjector from '../editorInjector/_core';
|
|
4
|
-
import { HueSlider } from '../modules';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_COLOR_LIST = [
|
|
7
|
-
'#ff0000',
|
|
8
|
-
'#ff5e00',
|
|
9
|
-
'#ffe400',
|
|
10
|
-
'#abf200',
|
|
11
|
-
'#00d8ff',
|
|
12
|
-
'#0055ff',
|
|
13
|
-
'#6600ff',
|
|
14
|
-
'#ff00dd',
|
|
15
|
-
'#000000',
|
|
16
|
-
'#ffd8d8',
|
|
17
|
-
'#fae0d4',
|
|
18
|
-
'#faf4c0',
|
|
19
|
-
'#e4f7ba',
|
|
20
|
-
'#d4f4fa',
|
|
21
|
-
'#d9e5ff',
|
|
22
|
-
'#e8d9ff',
|
|
23
|
-
'#ffd9fa',
|
|
24
|
-
'#f1f1f1',
|
|
25
|
-
'#ffa7a7',
|
|
26
|
-
'#ffc19e',
|
|
27
|
-
'#faed7d',
|
|
28
|
-
'#cef279',
|
|
29
|
-
'#b2ebf4',
|
|
30
|
-
'#b2ccff',
|
|
31
|
-
'#d1b2ff',
|
|
32
|
-
'#ffb2f5',
|
|
33
|
-
'#bdbdbd',
|
|
34
|
-
'#f15f5f',
|
|
35
|
-
'#f29661',
|
|
36
|
-
'#e5d85c',
|
|
37
|
-
'#bce55c',
|
|
38
|
-
'#5cd1e5',
|
|
39
|
-
'#6699ff',
|
|
40
|
-
'#a366ff',
|
|
41
|
-
'#f261df',
|
|
42
|
-
'#8c8c8c',
|
|
43
|
-
'#980000',
|
|
44
|
-
'#993800',
|
|
45
|
-
'#998a00',
|
|
46
|
-
'#6b9900',
|
|
47
|
-
'#008299',
|
|
48
|
-
'#003399',
|
|
49
|
-
'#3d0099',
|
|
50
|
-
'#990085',
|
|
51
|
-
'#353535',
|
|
52
|
-
'#670000',
|
|
53
|
-
'#662500',
|
|
54
|
-
'#665c00',
|
|
55
|
-
'#476600',
|
|
56
|
-
'#005766',
|
|
57
|
-
'#002266',
|
|
58
|
-
'#290066',
|
|
59
|
-
'#660058',
|
|
60
|
-
'#222222'
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
const DEFAULLT_COLOR_SPLITNUM = 9;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @typedef {import('./HueSlider').HueSliderParams} HueSliderParams_colorPicker
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @typedef {import('./HueSlider').HueSliderColor} HueSliderColor_colorPicker
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @typedef {Object} ColorPickerParams
|
|
75
|
-
* @property {Array<string|{value: string, name: string}>=} [colorList=[]] color list
|
|
76
|
-
* @property {number=} [splitNum=0] Number of colors to be displayed in one line
|
|
77
|
-
* @property {string=} [defaultColor] Default color
|
|
78
|
-
* @property {boolean=} [disableHEXInput=false] Disable HEX input
|
|
79
|
-
* @property {boolean=} [disableRemove=false] Disable remove button
|
|
80
|
-
* @property {HueSliderParams_colorPicker=} [hueSliderOptions] hue slider options
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @class
|
|
85
|
-
* @description Create a color picker element and register for related events. (this.target)
|
|
86
|
-
* - When calling the color selection, "submit", and "remove" buttons, the "action" method of the instance is called with the "color" value as an argument.
|
|
87
|
-
*/
|
|
88
|
-
class ColorPicker extends CoreInjector {
|
|
89
|
-
/**
|
|
90
|
-
* @constructor
|
|
91
|
-
* @param {*} inst The instance object that called the constructor.
|
|
92
|
-
* @param {string} styles style property ("color", "backgroundColor"..)
|
|
93
|
-
* @param {ColorPickerParams} params Color picker options
|
|
94
|
-
*/
|
|
95
|
-
constructor(inst, styles, params) {
|
|
96
|
-
const editor = inst.editor;
|
|
97
|
-
super(editor);
|
|
98
|
-
|
|
99
|
-
// members
|
|
100
|
-
this.kind = inst.constructor.key || inst.constructor.name;
|
|
101
|
-
this.inst = inst;
|
|
102
|
-
this.target = CreateHTML(editor, params);
|
|
103
|
-
this.targetButton = null;
|
|
104
|
-
this.inputElement = /** @type {HTMLInputElement} */ (this.target.querySelector('.se-color-input'));
|
|
105
|
-
this.styleProperties = styles;
|
|
106
|
-
this.splitNum = params.splitNum || 0;
|
|
107
|
-
this.defaultColor = params.defaultColor;
|
|
108
|
-
this.hueSliderOptions = params.hueSliderOptions;
|
|
109
|
-
this.parentDisplay = '';
|
|
110
|
-
this.currentColor = '';
|
|
111
|
-
this.parentForm = null;
|
|
112
|
-
this.colorList = this.target.querySelectorAll('li button') || [];
|
|
113
|
-
this.hueSlider = null;
|
|
114
|
-
|
|
115
|
-
// check icon
|
|
116
|
-
const parser = new DOMParser();
|
|
117
|
-
const svgDoc = parser.parseFromString(this.icons.color_checked, 'image/svg+xml');
|
|
118
|
-
this.checkedIcon = svgDoc.documentElement;
|
|
119
|
-
|
|
120
|
-
// modules - hex, hue slider
|
|
121
|
-
if (!params.disableHEXInput) {
|
|
122
|
-
this.hueSlider = new HueSlider(this, params.hueSliderOptions, 'se-dropdown');
|
|
123
|
-
this.parentFormDisplay = [];
|
|
124
|
-
this.parentForm = params.hueSliderOptions?.controllerOptions?.parents?.length > 0 && !params.hueSliderOptions?.controllerOptions?.isInsideForm ? params.hueSliderOptions.controllerOptions.parents : null;
|
|
125
|
-
// hue open
|
|
126
|
-
this.eventManager.addEvent(this.target.querySelector('.
|
|
127
|
-
this.eventManager.addEvent(this.inputElement, 'input', this.#OnChangeInput.bind(this));
|
|
128
|
-
this.eventManager.addEvent(this.target.querySelector('form'), 'submit', this.#Submit.bind(this));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// remove style
|
|
132
|
-
if (!params.disableRemove) {
|
|
133
|
-
this.eventManager.addEvent(this.target.querySelector('.__se_remove'), 'click', this.#Remove.bind(this));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
this.eventManager.addEvent(this.target, 'click', this.#OnClickColor.bind(this));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @description Displays or resets the currently selected color at color list.
|
|
141
|
-
* @param {Node|string} nodeOrColor Current Selected node
|
|
142
|
-
* @param {Node} target target
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
fillColor =
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
* @
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
* @
|
|
187
|
-
* @
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
* @
|
|
198
|
-
* @
|
|
199
|
-
* @
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
* @
|
|
217
|
-
* @returns
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
* @
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
* @
|
|
302
|
-
* @
|
|
303
|
-
* @
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
${disableHEXInput ? '' : `<button type="
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
1
|
+
import { dom, converter } from '../helper';
|
|
2
|
+
import { isElement } from '../helper/dom/domCheck';
|
|
3
|
+
import CoreInjector from '../editorInjector/_core';
|
|
4
|
+
import { HueSlider } from '../modules';
|
|
5
|
+
|
|
6
|
+
const DEFAULT_COLOR_LIST = [
|
|
7
|
+
'#ff0000',
|
|
8
|
+
'#ff5e00',
|
|
9
|
+
'#ffe400',
|
|
10
|
+
'#abf200',
|
|
11
|
+
'#00d8ff',
|
|
12
|
+
'#0055ff',
|
|
13
|
+
'#6600ff',
|
|
14
|
+
'#ff00dd',
|
|
15
|
+
'#000000',
|
|
16
|
+
'#ffd8d8',
|
|
17
|
+
'#fae0d4',
|
|
18
|
+
'#faf4c0',
|
|
19
|
+
'#e4f7ba',
|
|
20
|
+
'#d4f4fa',
|
|
21
|
+
'#d9e5ff',
|
|
22
|
+
'#e8d9ff',
|
|
23
|
+
'#ffd9fa',
|
|
24
|
+
'#f1f1f1',
|
|
25
|
+
'#ffa7a7',
|
|
26
|
+
'#ffc19e',
|
|
27
|
+
'#faed7d',
|
|
28
|
+
'#cef279',
|
|
29
|
+
'#b2ebf4',
|
|
30
|
+
'#b2ccff',
|
|
31
|
+
'#d1b2ff',
|
|
32
|
+
'#ffb2f5',
|
|
33
|
+
'#bdbdbd',
|
|
34
|
+
'#f15f5f',
|
|
35
|
+
'#f29661',
|
|
36
|
+
'#e5d85c',
|
|
37
|
+
'#bce55c',
|
|
38
|
+
'#5cd1e5',
|
|
39
|
+
'#6699ff',
|
|
40
|
+
'#a366ff',
|
|
41
|
+
'#f261df',
|
|
42
|
+
'#8c8c8c',
|
|
43
|
+
'#980000',
|
|
44
|
+
'#993800',
|
|
45
|
+
'#998a00',
|
|
46
|
+
'#6b9900',
|
|
47
|
+
'#008299',
|
|
48
|
+
'#003399',
|
|
49
|
+
'#3d0099',
|
|
50
|
+
'#990085',
|
|
51
|
+
'#353535',
|
|
52
|
+
'#670000',
|
|
53
|
+
'#662500',
|
|
54
|
+
'#665c00',
|
|
55
|
+
'#476600',
|
|
56
|
+
'#005766',
|
|
57
|
+
'#002266',
|
|
58
|
+
'#290066',
|
|
59
|
+
'#660058',
|
|
60
|
+
'#222222'
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const DEFAULLT_COLOR_SPLITNUM = 9;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @typedef {import('./HueSlider').HueSliderParams} HueSliderParams_colorPicker
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @typedef {import('./HueSlider').HueSliderColor} HueSliderColor_colorPicker
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @typedef {Object} ColorPickerParams
|
|
75
|
+
* @property {Array<string|{value: string, name: string}>=} [colorList=[]] color list
|
|
76
|
+
* @property {number=} [splitNum=0] Number of colors to be displayed in one line
|
|
77
|
+
* @property {string=} [defaultColor] Default color
|
|
78
|
+
* @property {boolean=} [disableHEXInput=false] Disable HEX input
|
|
79
|
+
* @property {boolean=} [disableRemove=false] Disable remove button
|
|
80
|
+
* @property {HueSliderParams_colorPicker=} [hueSliderOptions] hue slider options
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @class
|
|
85
|
+
* @description Create a color picker element and register for related events. (this.target)
|
|
86
|
+
* - When calling the color selection, "submit", and "remove" buttons, the "action" method of the instance is called with the "color" value as an argument.
|
|
87
|
+
*/
|
|
88
|
+
class ColorPicker extends CoreInjector {
|
|
89
|
+
/**
|
|
90
|
+
* @constructor
|
|
91
|
+
* @param {*} inst The instance object that called the constructor.
|
|
92
|
+
* @param {string} styles style property ("color", "backgroundColor"..)
|
|
93
|
+
* @param {ColorPickerParams} params Color picker options
|
|
94
|
+
*/
|
|
95
|
+
constructor(inst, styles, params) {
|
|
96
|
+
const editor = inst.editor;
|
|
97
|
+
super(editor);
|
|
98
|
+
|
|
99
|
+
// members
|
|
100
|
+
this.kind = inst.constructor.key || inst.constructor.name;
|
|
101
|
+
this.inst = inst;
|
|
102
|
+
this.target = CreateHTML(editor, params);
|
|
103
|
+
this.targetButton = null;
|
|
104
|
+
this.inputElement = /** @type {HTMLInputElement} */ (this.target.querySelector('.se-color-input'));
|
|
105
|
+
this.styleProperties = styles;
|
|
106
|
+
this.splitNum = params.splitNum || 0;
|
|
107
|
+
this.defaultColor = params.defaultColor || '';
|
|
108
|
+
this.hueSliderOptions = params.hueSliderOptions;
|
|
109
|
+
this.parentDisplay = '';
|
|
110
|
+
this.currentColor = '';
|
|
111
|
+
this.parentForm = null;
|
|
112
|
+
this.colorList = this.target.querySelectorAll('li button') || [];
|
|
113
|
+
this.hueSlider = null;
|
|
114
|
+
|
|
115
|
+
// check icon
|
|
116
|
+
const parser = new DOMParser();
|
|
117
|
+
const svgDoc = parser.parseFromString(this.icons.color_checked, 'image/svg+xml');
|
|
118
|
+
this.checkedIcon = svgDoc.documentElement;
|
|
119
|
+
|
|
120
|
+
// modules - hex, hue slider
|
|
121
|
+
if (!params.disableHEXInput) {
|
|
122
|
+
this.hueSlider = new HueSlider(this, params.hueSliderOptions, 'se-dropdown');
|
|
123
|
+
this.parentFormDisplay = [];
|
|
124
|
+
this.parentForm = params.hueSliderOptions?.controllerOptions?.parents?.length > 0 && !params.hueSliderOptions?.controllerOptions?.isInsideForm ? params.hueSliderOptions.controllerOptions.parents : null;
|
|
125
|
+
// hue open
|
|
126
|
+
this.eventManager.addEvent(this.target.querySelector('.__se_hue'), 'click', this.#OnColorPalette.bind(this));
|
|
127
|
+
this.eventManager.addEvent(this.inputElement, 'input', this.#OnChangeInput.bind(this));
|
|
128
|
+
this.eventManager.addEvent(this.target.querySelector('form'), 'submit', this.#Submit.bind(this));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// remove style
|
|
132
|
+
if (!params.disableRemove) {
|
|
133
|
+
this.eventManager.addEvent(this.target.querySelector('.__se_remove'), 'click', this.#Remove.bind(this));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this.eventManager.addEvent(this.target, 'click', this.#OnClickColor.bind(this));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @description Displays or resets the currently selected color at color list.
|
|
141
|
+
* @param {Node|string} nodeOrColor Current Selected node
|
|
142
|
+
* @param {Node} target target
|
|
143
|
+
* @param {?((current: Node) => boolean)=} stopCondition - A function used to stop traversing parent nodes while finding the color.
|
|
144
|
+
* - When this function returns true, the traversal ends at that node.
|
|
145
|
+
* - e.g., `(node) => this.format.isLine(node)` stops at line-level elements like <p>, <div>.
|
|
146
|
+
*/
|
|
147
|
+
init(nodeOrColor, target, stopCondition) {
|
|
148
|
+
this.targetButton = target;
|
|
149
|
+
if (typeof stopCondition !== 'function') stopCondition = () => false;
|
|
150
|
+
|
|
151
|
+
let fillColor = (typeof nodeOrColor === 'string' ? nodeOrColor : this._getColorInNode(nodeOrColor, stopCondition)) || this.defaultColor;
|
|
152
|
+
fillColor = converter.isHexColor(fillColor) ? fillColor : converter.rgb2hex(fillColor) || fillColor || '';
|
|
153
|
+
|
|
154
|
+
const colorList = this.colorList;
|
|
155
|
+
for (let i = 0, len = colorList.length, c; i < len; i++) {
|
|
156
|
+
c = colorList[i];
|
|
157
|
+
if (fillColor.toLowerCase() === c.getAttribute('data-value').toLowerCase()) {
|
|
158
|
+
c.appendChild(this.checkedIcon);
|
|
159
|
+
dom.utils.addClass(c, 'active');
|
|
160
|
+
} else {
|
|
161
|
+
dom.utils.removeClass(c, 'active');
|
|
162
|
+
if (c.contains(this.checkedIcon)) dom.utils.removeItem(this.checkedIcon);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this._setInputText(this._colorName2hex(fillColor));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @description Store color values
|
|
171
|
+
* @param {string} hexColorStr Hax color value
|
|
172
|
+
*/
|
|
173
|
+
setHexColor(hexColorStr) {
|
|
174
|
+
this.currentColor = hexColorStr;
|
|
175
|
+
this.inputElement.style.borderColor = hexColorStr;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @description Close hue slider
|
|
180
|
+
*/
|
|
181
|
+
hueSliderClose() {
|
|
182
|
+
this.hueSlider.off();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @private
|
|
187
|
+
* @description Set color at input element
|
|
188
|
+
* @param {string} hexColorStr Hax color value
|
|
189
|
+
*/
|
|
190
|
+
_setInputText(hexColorStr) {
|
|
191
|
+
hexColorStr = !hexColorStr || /^#/.test(hexColorStr) ? hexColorStr : '#' + hexColorStr;
|
|
192
|
+
this.inputElement.value = hexColorStr;
|
|
193
|
+
this.setHexColor.call(this, hexColorStr);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @private
|
|
198
|
+
* @description Gets color value at color property of node
|
|
199
|
+
* @param {Node} node Selected node
|
|
200
|
+
* @param {(current: Node) => boolean} stopCondition - A function used to stop traversing parent nodes while finding the color.
|
|
201
|
+
* @returns {string}
|
|
202
|
+
*/
|
|
203
|
+
_getColorInNode(node, stopCondition) {
|
|
204
|
+
let findColor = '';
|
|
205
|
+
const sp = this.styleProperties;
|
|
206
|
+
|
|
207
|
+
while (node && !stopCondition(node) && !dom.check.isWysiwygFrame(node) && findColor.length === 0) {
|
|
208
|
+
if (isElement(node) && node.style[sp]) findColor = node.style[sp];
|
|
209
|
+
node = node.parentNode;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return findColor;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @private
|
|
217
|
+
* @description Converts color values of other formats to hex color values and returns.
|
|
218
|
+
* @param {string} colorName Color value
|
|
219
|
+
* @returns {string}
|
|
220
|
+
*/
|
|
221
|
+
_colorName2hex(colorName) {
|
|
222
|
+
if (!colorName || /^#/.test(colorName)) return colorName;
|
|
223
|
+
const temp = dom.utils.createElement('div', { style: 'display: none; color: ' + colorName });
|
|
224
|
+
const colors = this._w
|
|
225
|
+
.getComputedStyle(this._d.body.appendChild(temp))
|
|
226
|
+
.color.match(/\d+/g)
|
|
227
|
+
.map(function (a) {
|
|
228
|
+
return parseInt(a, 10);
|
|
229
|
+
});
|
|
230
|
+
dom.utils.removeItem(temp);
|
|
231
|
+
return colors.length >= 3 ? '#' + ((1 << 24) + (colors[0] << 16) + (colors[1] << 8) + colors[2]).toString(16).substring(1) : '';
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @editorMethod Modules.HueSlider
|
|
236
|
+
* @description This method is called when the color is selected in the hue slider.
|
|
237
|
+
* @param {HueSliderColor_colorPicker} color - Color object
|
|
238
|
+
*/
|
|
239
|
+
hueSliderAction(color) {
|
|
240
|
+
this._setInputText(color.hex);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @editorMethod Modules.HueSlider
|
|
245
|
+
* @description This method is called when the hue slider is closed.
|
|
246
|
+
*/
|
|
247
|
+
hueSliderCancelAction() {
|
|
248
|
+
if (this.parentForm?.length > 0) {
|
|
249
|
+
this.parentFormDisplay.forEach((e) => (e[0].style.display = e[1]));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
#OnColorPalette() {
|
|
254
|
+
if (this.parentForm?.length > 0) {
|
|
255
|
+
this.parentForm.forEach((e) => {
|
|
256
|
+
this.parentFormDisplay.push([e, e.style.display]);
|
|
257
|
+
e.style.display = 'none';
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
this.hueSlider.open(this.targetButton);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @param {SubmitEvent} e Event object
|
|
265
|
+
*/
|
|
266
|
+
#Submit(e) {
|
|
267
|
+
e.preventDefault();
|
|
268
|
+
|
|
269
|
+
if (typeof this.inst.colorPickerAction !== 'function') return;
|
|
270
|
+
this.inst.colorPickerAction(this.currentColor);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @param {MouseEvent} e Event object
|
|
275
|
+
*/
|
|
276
|
+
#OnClickColor(e) {
|
|
277
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
278
|
+
const color = eventTarget.getAttribute('data-value');
|
|
279
|
+
if (!color) return;
|
|
280
|
+
|
|
281
|
+
if (typeof this.inst.colorPickerAction !== 'function') return;
|
|
282
|
+
this.inst.colorPickerAction(color);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
#Remove() {
|
|
286
|
+
if (typeof this.inst.colorPickerAction !== 'function') return;
|
|
287
|
+
this.inst.colorPickerAction(null);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @param {InputEvent} e Event object
|
|
292
|
+
*/
|
|
293
|
+
#OnChangeInput(e) {
|
|
294
|
+
/** @type {HTMLInputElement} */
|
|
295
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
296
|
+
this.setHexColor(eventTarget.value);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @private
|
|
302
|
+
* @description Create a color picker element
|
|
303
|
+
* @param {*} param0
|
|
304
|
+
* @param {*} param1
|
|
305
|
+
* @returns
|
|
306
|
+
*/
|
|
307
|
+
function CreateHTML({ lang, icons }, { colorList, disableHEXInput, disableRemove, splitNum }) {
|
|
308
|
+
colorList = colorList || DEFAULT_COLOR_LIST;
|
|
309
|
+
splitNum = colorList === DEFAULT_COLOR_LIST ? DEFAULLT_COLOR_SPLITNUM : splitNum;
|
|
310
|
+
|
|
311
|
+
let list = '';
|
|
312
|
+
for (let i = 0, len = colorList.length, colorArr = [], color; i < len; i++) {
|
|
313
|
+
color = colorList[i];
|
|
314
|
+
if (!color) continue;
|
|
315
|
+
|
|
316
|
+
if (typeof color === 'string' || color.value) {
|
|
317
|
+
colorArr.push(color);
|
|
318
|
+
if (i < len - 1) continue;
|
|
319
|
+
}
|
|
320
|
+
if (colorArr.length > 0) {
|
|
321
|
+
list += `<div class="se-selector-color">${_makeColor(colorArr, splitNum)}</div>`;
|
|
322
|
+
colorArr = [];
|
|
323
|
+
}
|
|
324
|
+
if (typeof color === 'object') {
|
|
325
|
+
list += `<div class="se-selector-color">${_makeColor(color, splitNum)}</div>`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
list += /*html*/ `
|
|
329
|
+
<form class="se-form-group se-form-w0">
|
|
330
|
+
${disableHEXInput ? '' : `<button type="button" class="se-btn __se_hue" title="${lang.colorPicker}" aria-label="${lang.colorPicker}">${icons.color_palette}</button>`}
|
|
331
|
+
<input type="text" class="se-color-input" ${disableHEXInput ? 'readonly' : ''} placeholder="${lang.color}" />
|
|
332
|
+
${disableHEXInput ? '' : `<button type="submit" class="se-btn se-btn-success" title="${lang.submitButton}" aria-label="${lang.submitButton}">${icons.checked}</button>`}
|
|
333
|
+
${disableRemove ? '' : `<button type="button" class="se-btn __se_remove" title="${lang.remove}" aria-label="${lang.remove}">${icons.remove_color}</button>`}
|
|
334
|
+
</form>`;
|
|
335
|
+
|
|
336
|
+
return dom.utils.createElement('DIV', { class: 'se-list-inner' }, list);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function _makeColor(colorList, splitNum) {
|
|
340
|
+
const ulHTML = `<ul class="se-color-pallet${splitNum ? ' se-list-horizontal' : ''}">`;
|
|
341
|
+
|
|
342
|
+
let list = ulHTML;
|
|
343
|
+
for (let i = 0, len = colorList.length, color, v, n; i < len; i++) {
|
|
344
|
+
color = colorList[i];
|
|
345
|
+
if (typeof color === 'string') {
|
|
346
|
+
v = color;
|
|
347
|
+
n = color;
|
|
348
|
+
} else if (typeof color === 'object') {
|
|
349
|
+
v = color.value;
|
|
350
|
+
n = color.name || v;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (i > 0 && i % splitNum === 0) {
|
|
354
|
+
list += `</ul>${ulHTML}`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
list += /*html*/ `<li><button type="button" data-value="${v}" title="${n}" aria-label="${n}" style="background-color:${v};"></button></li>`;
|
|
358
|
+
}
|
|
359
|
+
list += '</ul>';
|
|
360
|
+
|
|
361
|
+
return list;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export default ColorPicker;
|