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.
Files changed (241) hide show
  1. package/CONTRIBUTING.md +8 -8
  2. package/README.md +44 -49
  3. package/dist/suneditor.min.css +1 -1
  4. package/dist/suneditor.min.js +1 -1
  5. package/package.json +95 -53
  6. package/src/assets/design/color.css +2 -2
  7. package/src/assets/design/size.css +2 -0
  8. package/src/assets/icons/defaultIcons.js +16 -1
  9. package/src/assets/suneditor-contents.css +9 -8
  10. package/src/assets/suneditor.css +29 -26
  11. package/src/core/{section → base}/actives.js +20 -12
  12. package/src/core/base/history.js +4 -4
  13. package/src/core/class/char.js +10 -10
  14. package/src/core/class/component.js +146 -57
  15. package/src/core/class/format.js +94 -2458
  16. package/src/core/class/html.js +187 -129
  17. package/src/core/class/inline.js +1853 -0
  18. package/src/core/class/listFormat.js +582 -0
  19. package/src/core/class/menu.js +14 -3
  20. package/src/core/class/nodeTransform.js +9 -14
  21. package/src/core/class/offset.js +162 -197
  22. package/src/core/class/selection.js +137 -34
  23. package/src/core/class/toolbar.js +73 -52
  24. package/src/core/class/ui.js +11 -11
  25. package/src/core/class/viewer.js +56 -55
  26. package/src/core/config/context.js +122 -0
  27. package/src/core/config/frameContext.js +204 -0
  28. package/src/core/config/options.js +639 -0
  29. package/src/core/editor.js +181 -108
  30. package/src/core/event/actions/index.js +229 -0
  31. package/src/core/event/effects/common.registry.js +60 -0
  32. package/src/core/event/effects/keydown.registry.js +551 -0
  33. package/src/core/event/effects/ruleHelpers.js +145 -0
  34. package/src/core/{base → event}/eventManager.js +119 -201
  35. package/src/core/event/executor.js +21 -0
  36. package/src/core/{base/eventHandlers → event/handlers}/handler_toolbar.js +4 -4
  37. package/src/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.js +2 -2
  38. package/src/core/event/handlers/handler_ww_input.js +77 -0
  39. package/src/core/event/handlers/handler_ww_key.js +228 -0
  40. package/src/core/{base/eventHandlers → event/handlers}/handler_ww_mouse.js +3 -3
  41. package/src/core/event/ports.js +211 -0
  42. package/src/core/event/reducers/keydown.reducer.js +89 -0
  43. package/src/core/event/rules/keydown.rule.arrow.js +54 -0
  44. package/src/core/event/rules/keydown.rule.backspace.js +202 -0
  45. package/src/core/event/rules/keydown.rule.delete.js +126 -0
  46. package/src/core/event/rules/keydown.rule.enter.js +144 -0
  47. package/src/core/event/rules/keydown.rule.tab.js +29 -0
  48. package/src/core/section/constructor.js +79 -388
  49. package/src/core/section/documentType.js +47 -26
  50. package/src/core/util/instanceCheck.js +59 -0
  51. package/src/editorInjector/_classes.js +4 -0
  52. package/src/editorInjector/_core.js +17 -7
  53. package/src/editorInjector/index.js +10 -2
  54. package/src/events.js +6 -0
  55. package/src/helper/clipboard.js +24 -10
  56. package/src/helper/converter.js +17 -12
  57. package/src/helper/dom/domCheck.js +22 -3
  58. package/src/helper/dom/domQuery.js +91 -45
  59. package/src/helper/dom/domUtils.js +93 -19
  60. package/src/helper/dom/index.js +4 -0
  61. package/src/helper/env.js +11 -7
  62. package/src/helper/keyCodeMap.js +4 -3
  63. package/src/langs/ckb.js +1 -1
  64. package/src/langs/cs.js +1 -1
  65. package/src/langs/da.js +1 -1
  66. package/src/langs/de.js +1 -1
  67. package/src/langs/en.js +1 -1
  68. package/src/langs/es.js +1 -1
  69. package/src/langs/fa.js +1 -1
  70. package/src/langs/fr.js +1 -1
  71. package/src/langs/he.js +1 -1
  72. package/src/langs/hu.js +1 -1
  73. package/src/langs/it.js +1 -1
  74. package/src/langs/ja.js +1 -1
  75. package/src/langs/km.js +1 -1
  76. package/src/langs/ko.js +1 -1
  77. package/src/langs/lv.js +1 -1
  78. package/src/langs/nl.js +1 -1
  79. package/src/langs/pl.js +1 -1
  80. package/src/langs/pt_br.js +10 -10
  81. package/src/langs/ro.js +1 -1
  82. package/src/langs/ru.js +1 -1
  83. package/src/langs/se.js +1 -1
  84. package/src/langs/tr.js +1 -1
  85. package/src/langs/uk.js +1 -1
  86. package/src/langs/ur.js +1 -1
  87. package/src/langs/zh_cn.js +1 -1
  88. package/src/modules/ApiManager.js +25 -18
  89. package/src/modules/Browser.js +52 -61
  90. package/src/modules/ColorPicker.js +37 -38
  91. package/src/modules/Controller.js +85 -79
  92. package/src/modules/Figure.js +275 -187
  93. package/src/modules/FileManager.js +86 -92
  94. package/src/modules/HueSlider.js +67 -35
  95. package/src/modules/Modal.js +84 -77
  96. package/src/modules/ModalAnchorEditor.js +62 -79
  97. package/src/modules/SelectMenu.js +89 -86
  98. package/src/plugins/browser/audioGallery.js +9 -5
  99. package/src/plugins/browser/fileBrowser.js +10 -6
  100. package/src/plugins/browser/fileGallery.js +9 -5
  101. package/src/plugins/browser/imageGallery.js +9 -5
  102. package/src/plugins/browser/videoGallery.js +11 -6
  103. package/src/plugins/command/blockquote.js +1 -0
  104. package/src/plugins/command/exportPDF.js +11 -8
  105. package/src/plugins/command/fileUpload.js +41 -29
  106. package/src/plugins/command/list_bulleted.js +2 -1
  107. package/src/plugins/command/list_numbered.js +2 -1
  108. package/src/plugins/dropdown/align.js +8 -2
  109. package/src/plugins/dropdown/backgroundColor.js +19 -11
  110. package/src/plugins/dropdown/font.js +15 -9
  111. package/src/plugins/dropdown/fontColor.js +19 -11
  112. package/src/plugins/dropdown/formatBlock.js +7 -2
  113. package/src/plugins/dropdown/hr.js +7 -3
  114. package/src/plugins/dropdown/layout.js +6 -2
  115. package/src/plugins/dropdown/lineHeight.js +8 -3
  116. package/src/plugins/dropdown/list.js +2 -1
  117. package/src/plugins/dropdown/paragraphStyle.js +15 -11
  118. package/src/plugins/dropdown/{table.js → table/index.js} +514 -362
  119. package/src/plugins/dropdown/template.js +6 -2
  120. package/src/plugins/dropdown/textStyle.js +7 -3
  121. package/src/plugins/field/mention.js +33 -27
  122. package/src/plugins/input/fontSize.js +44 -37
  123. package/src/plugins/input/pageNavigator.js +3 -2
  124. package/src/plugins/modal/audio.js +90 -85
  125. package/src/plugins/modal/drawing.js +58 -66
  126. package/src/plugins/modal/embed.js +193 -180
  127. package/src/plugins/modal/image.js +441 -439
  128. package/src/plugins/modal/link.js +31 -8
  129. package/src/plugins/modal/math.js +23 -22
  130. package/src/plugins/modal/video.js +233 -230
  131. package/src/plugins/popup/anchor.js +24 -18
  132. package/src/suneditor.js +69 -24
  133. package/src/typedef.js +42 -19
  134. package/types/assets/icons/defaultIcons.d.ts +8 -0
  135. package/types/core/class/char.d.ts +1 -1
  136. package/types/core/class/component.d.ts +29 -7
  137. package/types/core/class/format.d.ts +4 -354
  138. package/types/core/class/html.d.ts +13 -4
  139. package/types/core/class/inline.d.ts +263 -0
  140. package/types/core/class/listFormat.d.ts +135 -0
  141. package/types/core/class/menu.d.ts +10 -2
  142. package/types/core/class/offset.d.ts +24 -26
  143. package/types/core/class/selection.d.ts +2 -0
  144. package/types/core/class/toolbar.d.ts +24 -11
  145. package/types/core/class/ui.d.ts +1 -1
  146. package/types/core/class/viewer.d.ts +1 -1
  147. package/types/core/config/context.d.ts +157 -0
  148. package/types/core/config/frameContext.d.ts +367 -0
  149. package/types/core/config/options.d.ts +1119 -0
  150. package/types/core/editor.d.ts +101 -66
  151. package/types/core/event/actions/index.d.ts +47 -0
  152. package/types/core/event/effects/common.registry.d.ts +50 -0
  153. package/types/core/event/effects/keydown.registry.d.ts +73 -0
  154. package/types/core/event/effects/ruleHelpers.d.ts +31 -0
  155. package/types/core/{base → event}/eventManager.d.ts +15 -46
  156. package/types/core/event/executor.d.ts +6 -0
  157. package/types/core/event/handlers/handler_ww_input.d.ts +41 -0
  158. package/types/core/{base/eventHandlers/handler_ww_key_input.d.ts → event/handlers/handler_ww_key.d.ts} +4 -6
  159. package/types/core/event/ports.d.ts +255 -0
  160. package/types/core/event/reducers/keydown.reducer.d.ts +75 -0
  161. package/types/core/event/rules/keydown.rule.arrow.d.ts +8 -0
  162. package/types/core/event/rules/keydown.rule.backspace.d.ts +9 -0
  163. package/types/core/event/rules/keydown.rule.delete.d.ts +9 -0
  164. package/types/core/event/rules/keydown.rule.enter.d.ts +9 -0
  165. package/types/core/event/rules/keydown.rule.tab.d.ts +9 -0
  166. package/types/core/section/constructor.d.ts +101 -631
  167. package/types/core/section/documentType.d.ts +14 -4
  168. package/types/core/util/instanceCheck.d.ts +50 -0
  169. package/types/editorInjector/_classes.d.ts +4 -0
  170. package/types/editorInjector/_core.d.ts +17 -7
  171. package/types/editorInjector/index.d.ts +10 -2
  172. package/types/events.d.ts +1 -0
  173. package/types/helper/clipboard.d.ts +2 -2
  174. package/types/helper/converter.d.ts +6 -9
  175. package/types/helper/dom/domCheck.d.ts +7 -0
  176. package/types/helper/dom/domQuery.d.ts +19 -8
  177. package/types/helper/dom/domUtils.d.ts +24 -2
  178. package/types/helper/dom/index.d.ts +86 -1
  179. package/types/helper/env.d.ts +6 -1
  180. package/types/helper/index.d.ts +7 -1
  181. package/types/helper/keyCodeMap.d.ts +3 -3
  182. package/types/index.d.ts +23 -117
  183. package/types/langs/index.d.ts +2 -2
  184. package/types/modules/ApiManager.d.ts +1 -8
  185. package/types/modules/Browser.d.ts +4 -62
  186. package/types/modules/ColorPicker.d.ts +4 -21
  187. package/types/modules/Controller.d.ts +8 -64
  188. package/types/modules/Figure.d.ts +54 -50
  189. package/types/modules/FileManager.d.ts +1 -13
  190. package/types/modules/HueSlider.d.ts +13 -3
  191. package/types/modules/Modal.d.ts +0 -43
  192. package/types/modules/ModalAnchorEditor.d.ts +0 -73
  193. package/types/modules/SelectMenu.d.ts +0 -85
  194. package/types/modules/index.d.ts +3 -3
  195. package/types/plugins/browser/audioGallery.d.ts +29 -18
  196. package/types/plugins/browser/fileBrowser.d.ts +38 -27
  197. package/types/plugins/browser/fileGallery.d.ts +29 -18
  198. package/types/plugins/browser/imageGallery.d.ts +24 -16
  199. package/types/plugins/browser/videoGallery.d.ts +29 -18
  200. package/types/plugins/command/blockquote.d.ts +1 -0
  201. package/types/plugins/command/exportPDF.d.ts +18 -18
  202. package/types/plugins/command/fileUpload.d.ts +65 -45
  203. package/types/plugins/command/list_bulleted.d.ts +1 -0
  204. package/types/plugins/command/list_numbered.d.ts +1 -0
  205. package/types/plugins/dropdown/align.d.ts +13 -8
  206. package/types/plugins/dropdown/backgroundColor.d.ts +30 -19
  207. package/types/plugins/dropdown/font.d.ts +13 -12
  208. package/types/plugins/dropdown/fontColor.d.ts +30 -19
  209. package/types/plugins/dropdown/formatBlock.d.ts +13 -8
  210. package/types/plugins/dropdown/hr.d.ts +15 -11
  211. package/types/plugins/dropdown/layout.d.ts +15 -11
  212. package/types/plugins/dropdown/lineHeight.d.ts +16 -11
  213. package/types/plugins/dropdown/list.d.ts +1 -0
  214. package/types/plugins/dropdown/paragraphStyle.d.ts +31 -27
  215. package/types/plugins/dropdown/table/index.d.ts +582 -0
  216. package/types/plugins/dropdown/table.d.ts +41 -86
  217. package/types/plugins/dropdown/template.d.ts +15 -11
  218. package/types/plugins/dropdown/textStyle.d.ts +19 -11
  219. package/types/plugins/field/mention.d.ts +58 -56
  220. package/types/plugins/index.d.ts +38 -38
  221. package/types/plugins/input/fontSize.d.ts +46 -50
  222. package/types/plugins/modal/audio.d.ts +26 -56
  223. package/types/plugins/modal/drawing.d.ts +0 -85
  224. package/types/plugins/modal/embed.d.ts +15 -79
  225. package/types/plugins/modal/image.d.ts +24 -136
  226. package/types/plugins/modal/link.d.ts +34 -15
  227. package/types/plugins/modal/math.d.ts +0 -16
  228. package/types/plugins/modal/video.d.ts +17 -86
  229. package/types/plugins/popup/anchor.d.ts +1 -8
  230. package/types/suneditor.d.ts +70 -19
  231. package/types/typedef.d.ts +60 -46
  232. package/src/core/base/eventHandlers/handler_ww_key_input.js +0 -1200
  233. package/src/core/section/context.js +0 -102
  234. package/types/core/section/context.d.ts +0 -45
  235. package/types/langs/_Lang.d.ts +0 -194
  236. /package/src/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.js +0 -0
  237. /package/types/core/{section → base}/actives.d.ts +0 -0
  238. /package/types/core/{base/eventHandlers → event/handlers}/handler_toolbar.d.ts +0 -0
  239. /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.d.ts +0 -0
  240. /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.d.ts +0 -0
  241. /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_mouse.d.ts +0 -0
@@ -128,93 +128,6 @@ class FileManager extends CoreInjector {
128
128
  /** @type {Element} */ (element).setAttribute('data-se-file-size', size + '');
129
129
  }
130
130
 
131
- /**
132
- * @private
133
- * @description Create info object of file and add it to "infoList"
134
- * @param {HTMLMediaElement} element
135
- * @param {{name: string, size: number}|null} file File information
136
- */
137
- _setInfo(element, file) {
138
- let dataIndex = Number(GetAttr(element, 'index'));
139
- let info = null;
140
- let state = '';
141
-
142
- if (!file) {
143
- file = {
144
- name: GetAttr(element, 'file-name') || (typeof element.src === 'string' ? element.src.split('/').pop() : ''),
145
- size: Number(GetAttr(element, 'file-size')) || 0
146
- };
147
- }
148
-
149
- // create
150
- if (!dataIndex || this.editor._componentsInfoInit) {
151
- state = 'create';
152
- dataIndex = this.infoIndex++;
153
-
154
- element.setAttribute('data-se-index', dataIndex + '');
155
- element.setAttribute('data-se-file-name', file.name);
156
- element.setAttribute('data-se-file-size', file.size + '');
157
-
158
- info = {
159
- src: element.src,
160
- index: dataIndex,
161
- name: file.name,
162
- size: file.size
163
- };
164
-
165
- this.infoList.push(info);
166
- } else {
167
- // update
168
- state = 'update';
169
- dataIndex *= 1;
170
-
171
- for (let i = 0, len = this.infoList.length; i < len; i++) {
172
- if (dataIndex === this.infoList[i].index) {
173
- info = this.infoList[i];
174
- break;
175
- }
176
- }
177
-
178
- if (!info) {
179
- dataIndex = this.infoIndex++;
180
- info = {
181
- index: dataIndex
182
- };
183
- this.infoList.push(info);
184
- }
185
-
186
- info.src = element.src;
187
- info.name = GetAttr(element, 'file-name');
188
- info.size = Number(GetAttr(element, 'file-size'));
189
- }
190
-
191
- // method bind
192
- info.element = element;
193
-
194
- info.delete = function (el) {
195
- if (typeof this.inst.destroy === 'function') this.inst.destroy.call(this.inst, el);
196
- this._deleteInfo(Number(GetAttr(el, 'index')));
197
- }.bind(this, element);
198
- // se-ts-ignore
199
- void this._deleteInfo;
200
-
201
- info.select = function (el) {
202
- el.scrollIntoView(this.options.get('componentScrollToOptions'));
203
- const comp = this.component.get(el);
204
- if (comp) {
205
- this.component.select(comp.target, comp.pluginName);
206
- } else if (typeof this.inst.select === 'function') {
207
- this.inst.select(el);
208
- }
209
- }.bind(this, element);
210
-
211
- const params = { editor: this.editor, element, index: dataIndex, state, info, remainingFilesCount: --this.uploadFileLength < 0 ? 0 : this.uploadFileLength, pluginName: this.kind };
212
- if (typeof this.eventHandler === 'function') {
213
- this.eventHandler(params);
214
- }
215
- this.triggerEvent('onFileManagerAction', { ...params, pluginName: this.kind });
216
- }
217
-
218
131
  /**
219
132
  * @description Gets the sum of the sizes of the currently saved files.
220
133
  * @returns {number} Size
@@ -233,13 +146,13 @@ class FileManager extends CoreInjector {
233
146
  * @param {boolean} loaded Whether the editor is loaded
234
147
  */
235
148
  _checkInfo(loaded) {
236
- const tags = [].slice.call(this.editor.frameContext.get('wysiwyg').querySelectorAll(this.query));
149
+ const tags = [].slice.call(this.frameContext.get('wysiwyg').querySelectorAll(this.query));
237
150
  const infoList = this.infoList;
238
151
  if (tags.length === infoList.length) {
239
152
  // reset
240
153
  if (this.editor._componentsInfoReset) {
241
154
  for (let i = 0, len = tags.length; i < len; i++) {
242
- this._setInfo(tags[i], null);
155
+ this.#setInfo(tags[i], null);
243
156
  }
244
157
  return;
245
158
  } else {
@@ -274,7 +187,7 @@ class FileManager extends CoreInjector {
274
187
  if (!GetAttr(tag, 'index') || !infoIndex.includes(Number(GetAttr(tag, 'index')))) {
275
188
  currentTags.push(this.infoIndex);
276
189
  tag.removeAttribute('data-se-index');
277
- this._setInfo(tag, null);
190
+ this.#setInfo(tag, null);
278
191
  } else {
279
192
  currentTags.push(Number(GetAttr(tag, 'index')));
280
193
  }
@@ -319,11 +232,10 @@ class FileManager extends CoreInjector {
319
232
  }
320
233
 
321
234
  /**
322
- * @private
323
235
  * @description Delete info object at "infoList"
324
236
  * @param {number} index index of info object infoList[].index)
325
237
  */
326
- _deleteInfo(index) {
238
+ #deleteInfo(index) {
327
239
  if (index >= 0) {
328
240
  for (let i = 0, len = this.infoList.length; i < len; i++) {
329
241
  if (index === this.infoList[i].index) {
@@ -336,6 +248,88 @@ class FileManager extends CoreInjector {
336
248
  }
337
249
  }
338
250
  }
251
+
252
+ /**
253
+ * @description Create info object of file and add it to "infoList"
254
+ * @param {HTMLMediaElement} element
255
+ * @param {{name: string, size: number}|null} file File information
256
+ */
257
+ #setInfo(element, file) {
258
+ let dataIndex = Number(GetAttr(element, 'index'));
259
+ let info = null;
260
+ let state = '';
261
+
262
+ file ||= {
263
+ name: GetAttr(element, 'file-name') || (typeof element.src === 'string' ? element.src.split('/').pop() : ''),
264
+ size: Number(GetAttr(element, 'file-size')) || 0
265
+ };
266
+
267
+ // create
268
+ if (!dataIndex || this.editor._componentsInfoInit) {
269
+ state = 'create';
270
+ dataIndex = this.infoIndex++;
271
+
272
+ element.setAttribute('data-se-index', dataIndex + '');
273
+ element.setAttribute('data-se-file-name', file.name);
274
+ element.setAttribute('data-se-file-size', file.size + '');
275
+
276
+ info = {
277
+ src: element.src,
278
+ index: dataIndex,
279
+ name: file.name,
280
+ size: file.size
281
+ };
282
+
283
+ this.infoList.push(info);
284
+ } else {
285
+ // update
286
+ state = 'update';
287
+ dataIndex *= 1;
288
+
289
+ for (let i = 0, len = this.infoList.length; i < len; i++) {
290
+ if (dataIndex === this.infoList[i].index) {
291
+ info = this.infoList[i];
292
+ break;
293
+ }
294
+ }
295
+
296
+ if (!info) {
297
+ dataIndex = this.infoIndex++;
298
+ info = {
299
+ index: dataIndex
300
+ };
301
+ this.infoList.push(info);
302
+ }
303
+
304
+ info.src = element.src;
305
+ info.name = GetAttr(element, 'file-name');
306
+ info.size = Number(GetAttr(element, 'file-size'));
307
+ }
308
+
309
+ // method bind
310
+ info.element = element;
311
+
312
+ info.delete = function (deleteCallback, el) {
313
+ if (typeof this.inst.destroy === 'function') this.inst.destroy.call(this.inst, el);
314
+ deleteCallback(Number(GetAttr(el, 'index')));
315
+ }.bind(this, this.#deleteInfo.bind(this), element);
316
+
317
+ info.select = function (el) {
318
+ el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
319
+ const comp = this.component.get(el);
320
+ if (comp) {
321
+ this.component.select(comp.target, comp.pluginName);
322
+ } else if (typeof this.inst.select === 'function') {
323
+ this.inst.select(el);
324
+ }
325
+ }.bind(this, element);
326
+
327
+ const params = { editor: this.editor, element, index: dataIndex, state, info, remainingFilesCount: --this.uploadFileLength < 0 ? 0 : this.uploadFileLength, pluginName: this.kind };
328
+ if (typeof this.eventHandler === 'function') {
329
+ this.eventHandler(params);
330
+ }
331
+ this.triggerEvent('onFileManagerAction', { ...params, pluginName: this.kind });
332
+ }
339
333
  }
340
334
 
341
335
  /**
@@ -5,7 +5,7 @@
5
5
  import { dom, env } from '../helper';
6
6
  import Controller from './Controller';
7
7
 
8
- const { isMobile } = env;
8
+ const { isTouchDevice } = env;
9
9
 
10
10
  const SIZE = 240;
11
11
  const BAR_H = 28;
@@ -25,6 +25,8 @@ let wheelY = SIZE / 2;
25
25
  let finalColor = DEFAULT_COLOR_VALUE;
26
26
  let ctx;
27
27
 
28
+ let _bootstrapped = false;
29
+
28
30
  function CreateSliderCtx() {
29
31
  const offscreenCanvas = document.createElement('canvas');
30
32
  offscreenCanvas.width = SIZE;
@@ -93,15 +95,20 @@ function CreateSliderCtx() {
93
95
  * It must be called every time it is used.
94
96
  */
95
97
  class HueSlider {
98
+ #globalMouseDown;
99
+ #globalTouchMove;
100
+ #globalMouseUp;
101
+ #globalMouseMove;
102
+ #globalTouchStart;
103
+ #globalTouchEnd;
104
+
96
105
  /**
97
106
  * @constructor
98
107
  * @param {*} inst The instance object that called the constructor.
99
108
  * @param {HueSliderParams} [params={}] Hue slider options
100
109
  * @param {string} [className=""] The class name of the hue slider.
101
110
  */
102
- constructor(inst, params, className) {
103
- if (!params) params = {};
104
-
111
+ constructor(inst, params = {}, className = '') {
105
112
  this.editor = inst.editor;
106
113
  this.eventManager = inst.eventManager;
107
114
  this.inst = inst;
@@ -119,9 +126,13 @@ class HueSlider {
119
126
  };
120
127
  this.isOpen = false;
121
128
  this.controlle = null;
122
- this.__globalMouseDown = null;
123
- this.__globalMouseMove = null;
124
- this.__globalMouseUp = null;
129
+
130
+ this.#globalMouseDown = null;
131
+ this.#globalTouchMove = null;
132
+ this.#globalMouseUp = null;
133
+ this.#globalMouseMove = null;
134
+ this.#globalTouchStart = null;
135
+ this.#globalTouchEnd = null;
125
136
 
126
137
  // init default controller
127
138
  if (!params.isNewForm) {
@@ -189,6 +200,8 @@ class HueSlider {
189
200
  * @param {?Node=} form The element to attach the hue slider.
190
201
  */
191
202
  attach(form) {
203
+ if (!_bootstrapped) InitRender();
204
+
192
205
  // drow
193
206
  this.init();
194
207
  (form || this.form).appendChild(slider);
@@ -206,30 +219,34 @@ class HueSlider {
206
219
  createGradientBar(getDefaultColor());
207
220
  }
208
221
 
209
- // event
210
- const downEvent = { name: 'mousedown', func: OnMousedown };
211
- const moveEvent = { name: 'mousemove', func: OnMousemove, option: true };
212
- const upEvent = {
213
- name: 'mouseup',
214
- func: () => {
215
- isWheelragging = false;
216
- isBarDragging = false;
217
- }
218
- };
219
-
220
- if (isMobile) {
222
+ // touch event
223
+ if (isTouchDevice) {
221
224
  // mobile name
222
- downEvent.name = 'touchstart';
223
- moveEvent.name = 'touchmove';
224
- upEvent.name = 'touchend';
225
- // mobile func
226
- downEvent.func = OnTouchstart;
227
- moveEvent.func = OnTouchmove;
225
+ this.#globalTouchStart = this.eventManager.addGlobalEvent('touchstart', OnTouchstart, { passive: false, capture: true });
226
+ this.#globalTouchMove = this.eventManager.addGlobalEvent('touchmove', OnTouchmove, true);
227
+ this.#globalTouchEnd = this.eventManager.addGlobalEvent(
228
+ 'touchend',
229
+ () => {
230
+ isWheelragging = false;
231
+ isBarDragging = false;
232
+ },
233
+ true
234
+ );
228
235
  }
229
236
 
230
- this.__globalMouseDown = this.eventManager.addGlobalEvent(downEvent.name, downEvent.func, { passive: false, capture: true });
231
- this.__globalMouseMove = this.eventManager.addGlobalEvent(moveEvent.name, moveEvent.func, true);
232
- this.__globalMouseUp = this.eventManager.addGlobalEvent(upEvent.name, upEvent.func, true);
237
+ // mouse event
238
+ this.#globalMouseDown = this.eventManager.addGlobalEvent('mousedown', OnMousedown, { passive: false, capture: true });
239
+ this.#globalMouseMove = this.eventManager.addGlobalEvent('mousemove', OnMousemove, true);
240
+ this.#globalMouseUp = this.eventManager.addGlobalEvent(
241
+ 'mouseup',
242
+ () => {
243
+ isWheelragging = false;
244
+ isBarDragging = false;
245
+ },
246
+ true
247
+ );
248
+
249
+ // open
233
250
  this.isOpen = true;
234
251
  }
235
252
 
@@ -240,9 +257,14 @@ class HueSlider {
240
257
  this.isOpen = false;
241
258
  isWheelragging = false;
242
259
  isBarDragging = false;
243
- if (this.__globalMouseDown) this.__globalMouseDown = this.eventManager.removeGlobalEvent(this.__globalMouseDown);
244
- if (this.__globalMouseMove) this.__globalMouseMove = this.eventManager.removeGlobalEvent(this.__globalMouseMove);
245
- if (this.__globalMouseUp) this.__globalMouseUp = this.eventManager.removeGlobalEvent(this.__globalMouseUp);
260
+
261
+ this.#globalMouseDown &&= this.eventManager.removeGlobalEvent(this.#globalMouseDown);
262
+ this.#globalMouseMove &&= this.eventManager.removeGlobalEvent(this.#globalMouseMove);
263
+ this.#globalMouseUp &&= this.eventManager.removeGlobalEvent(this.#globalMouseUp);
264
+
265
+ this.#globalTouchStart &&= this.eventManager.removeGlobalEvent(this.#globalTouchStart);
266
+ this.#globalTouchMove &&= this.eventManager.removeGlobalEvent(this.#globalTouchMove);
267
+ this.#globalTouchEnd &&= this.eventManager.removeGlobalEvent(this.#globalTouchEnd);
246
268
  }
247
269
  }
248
270
 
@@ -439,7 +461,10 @@ function drawWheelGradient() {
439
461
  }
440
462
 
441
463
  function drawColorWheelToContext(context) {
442
- if (!context) throw new Error('Context not found.');
464
+ if (!context) {
465
+ console.warn('[HueSlider.fail] Context not found.');
466
+ return;
467
+ }
443
468
 
444
469
  const fixedSaturation = SATURATION * 100;
445
470
 
@@ -458,6 +483,8 @@ function drawColorWheelToContext(context) {
458
483
  context.fill();
459
484
  }
460
485
  }
486
+
487
+ _bootstrapped = true;
461
488
  }
462
489
 
463
490
  function degreeToRadian(deg) {
@@ -542,9 +569,13 @@ function roundNumber(num) {
542
569
  return Math.round(num * factor) / factor;
543
570
  }
544
571
 
545
- // create
546
- drawColorWheelToContext(offscreenCtx);
547
- drawColorWheel();
572
+ function InitRender() {
573
+ // create
574
+ drawColorWheelToContext(offscreenCtx);
575
+ if (_bootstrapped) drawColorWheel();
576
+ }
577
+
578
+ InitRender();
548
579
 
549
580
  function CreateHTML_basicControllerForm({ lang, icons }, className) {
550
581
  const hueController = dom.utils.createElement(
@@ -562,4 +593,5 @@ function CreateHTML_basicControllerForm({ lang, icons }, className) {
562
593
  return hueController;
563
594
  }
564
595
 
596
+ export { CreateSliderCtx };
565
597
  export default HueSlider;