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
package/src/langs/ko.js CHANGED
@@ -8,7 +8,7 @@
8
8
  throw new Error('SUNEDITOR_LANG a window with a document');
9
9
  }
10
10
  return factory(w);
11
- };
11
+ };
12
12
  } else {
13
13
  factory(global);
14
14
  }
package/src/langs/lv.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/nl.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/pl.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
@@ -32,7 +32,7 @@
32
32
  audioGallery: 'Galeria de áudio',
33
33
  audio_modal_file: 'Selecionar arquivos',
34
34
  audio_modal_title: 'Inserir áudio',
35
- audio_modal_url: 'URL da áudio',
35
+ audio_modal_url: 'URL do áudio',
36
36
  autoSize: 'Tamanho automático',
37
37
  backgroundColor: 'Cor de destaque',
38
38
  basic: 'Básico',
@@ -88,7 +88,7 @@
88
88
  fileUpload: 'Upload de arquivo',
89
89
  fixedColumnWidth: 'Largura fixa da coluna',
90
90
  font: 'Fonte',
91
- fontColor: 'Cor da Fonte',
91
+ fontColor: 'Cor da fonte',
92
92
  fontSize: 'Tamanho',
93
93
  formats: 'Formatos',
94
94
  fullScreen: 'Tela cheia',
@@ -120,10 +120,10 @@
120
120
  link: 'Link',
121
121
  link_modal_bookmark: 'marcar páginas',
122
122
  link_modal_downloadLinkCheck: 'Link para Download',
123
- link_modal_newWindowCheck: 'Abrir em nova guia',
124
- link_modal_text: 'Texto a mostrar',
123
+ link_modal_newWindowCheck: 'Abrir em uma nova guia',
124
+ link_modal_text: 'Texto exibido',
125
125
  link_modal_title: 'Inserir link',
126
- link_modal_url: 'URL para o link',
126
+ link_modal_url: 'Endereço do link',
127
127
  link_modal_relAttribute: 'Atributo rel',
128
128
  list: 'Lista',
129
129
  math: 'Matemática',
@@ -158,7 +158,7 @@
158
158
  ratio: 'Proporções',
159
159
  redo: 'Refazer',
160
160
  remove: 'Remover',
161
- removeFormat: 'Remover Formatação',
161
+ removeFormat: 'Remover formatação',
162
162
  replace: 'Substituir',
163
163
  replaceAll: 'Substituir todos',
164
164
  resize100: 'Zoom 100%',
@@ -178,9 +178,9 @@
178
178
  showBlocks: 'Mostrar blocos',
179
179
  size: 'Tamanho',
180
180
  splitCells: 'Dividir células',
181
- strike: 'Riscado',
181
+ strike: 'Tachado',
182
182
  submitButton: 'Enviar',
183
- subscript: 'Subescrito',
183
+ subscript: 'Subscrito',
184
184
  superscript: 'Sobrescrito',
185
185
  table: 'Tabela',
186
186
  tableHeader: 'Cabeçalho da tabela',
@@ -189,7 +189,7 @@
189
189
  tag_blockquote: 'Citar',
190
190
  tag_div: '(DIV) Normal',
191
191
  tag_h: 'Cabeçalho',
192
- tag_p: 'Paragráfo',
192
+ tag_p: 'Parágrafo',
193
193
  tag_pre: 'Código',
194
194
  template: 'Modelo',
195
195
  textStyle: 'Estilo do texto',
package/src/langs/ro.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/ru.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/se.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/tr.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/uk.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
package/src/langs/ur.js CHANGED
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
@@ -9,7 +9,7 @@
9
9
  throw new Error('SUNEDITOR_LANG a window with a document');
10
10
  }
11
11
  return factory(w);
12
- };
12
+ };
13
13
  } else {
14
14
  factory(global);
15
15
  }
@@ -16,6 +16,9 @@ import { env } from '../helper';
16
16
  * @description API Manager
17
17
  */
18
18
  class ApiManager {
19
+ /** @type {XMLHttpRequest} */
20
+ #xhr;
21
+
19
22
  /**
20
23
  * @constructor
21
24
  * @param {*} inst The instance object that called the constructor.
@@ -41,7 +44,7 @@ class ApiManager {
41
44
  this.kind = inst.constructor.key || inst.constructor.name;
42
45
 
43
46
  // members
44
- this._xhr = env.getXMLHttpRequest();
47
+ this.#xhr = env.getXMLHttpRequest();
45
48
  // members - option
46
49
  this.method = params?.method;
47
50
  this.url = params?.url;
@@ -59,15 +62,20 @@ class ApiManager {
59
62
  call({ method, url, headers, data, callBack, errorCallBack, responseType }) {
60
63
  this.cancel();
61
64
 
62
- method = method || this.method;
63
- url = this._normalizeUrl(url || this.url);
64
- headers = headers || this.headers;
65
- data = data || this.data;
66
- callBack = callBack || this.callBack;
67
- errorCallBack = errorCallBack || this.errorCallBack;
68
- responseType = responseType || this.responseType;
65
+ method ||= this.method;
66
+ url = this.#normalizeUrl(url || this.url);
67
+ headers ||= this.headers;
68
+ data ||= this.data;
69
+ callBack ||= this.callBack;
70
+ errorCallBack ||= this.errorCallBack;
71
+ responseType ||= this.responseType;
72
+
73
+ // Validate required callback parameter
74
+ if (typeof callBack !== 'function') {
75
+ throw new Error(`[SUNEDITOR.ApiManager[${this.kind}].upload.callBack.fail] callBack is not a function`);
76
+ }
69
77
 
70
- const xhr = this._xhr;
78
+ const xhr = this.#xhr;
71
79
  if (responseType) xhr.responseType = responseType;
72
80
  xhr.onreadystatechange = CallBackApi.bind(this, xhr, callBack, errorCallBack);
73
81
  xhr.open(method, url, true);
@@ -93,13 +101,13 @@ class ApiManager {
93
101
  asyncCall({ method, url, headers, data, responseType }) {
94
102
  this.cancel();
95
103
 
96
- method = method || this.method;
97
- url = this._normalizeUrl(url || this.url);
98
- headers = headers || this.headers;
99
- data = data || this.data;
100
- responseType = responseType || this.responseType;
104
+ method ||= this.method;
105
+ url = this.#normalizeUrl(url || this.url);
106
+ headers ||= this.headers;
107
+ data ||= this.data;
108
+ responseType ||= this.responseType;
101
109
 
102
- const xhr = this._xhr;
110
+ const xhr = this.#xhr;
103
111
  if (responseType) xhr.responseType = responseType;
104
112
 
105
113
  return new Promise((resolve, reject) => {
@@ -138,16 +146,15 @@ class ApiManager {
138
146
  * @description Cancel API (xhr.abort())
139
147
  */
140
148
  cancel() {
141
- if (this._xhr) this._xhr.abort();
149
+ if (this.#xhr) this.#xhr.abort();
142
150
  }
143
151
 
144
152
  /**
145
- * @private
146
153
  * @description Remove unnecessary slashes in API URL.
147
154
  * @param {string} url url
148
155
  * @returns
149
156
  */
150
- _normalizeUrl(url) {
157
+ #normalizeUrl(url) {
151
158
  return url.replace(/([^:])\/+/g, '$1/').replace(/\/(\?|#|$)/, '$1');
152
159
  }
153
160
  }
@@ -1,5 +1,6 @@
1
1
  import CoreInjector from '../editorInjector/_core';
2
2
  import { dom, keyCodeMap } from '../helper';
3
+ import { _w } from '../helper/env';
3
4
  import ApiManager from './ApiManager';
4
5
 
5
6
  /**
@@ -39,6 +40,11 @@ import ApiManager from './ApiManager';
39
40
  * @description File browser plugin
40
41
  */
41
42
  class Browser extends CoreInjector {
43
+ #loading;
44
+ #closeSignal;
45
+ #bindClose;
46
+ #globalEventHandler;
47
+
42
48
  /**
43
49
  * @constructor
44
50
  * @param {*} inst The instance object that called the constructor.
@@ -64,7 +70,7 @@ class Browser extends CoreInjector {
64
70
  this.list = contentHTML.list;
65
71
  this.side = contentHTML.side;
66
72
  this.wrapper = contentHTML.wrapper;
67
- this._loading = contentHTML._loading;
73
+ this.#loading = contentHTML._loading;
68
74
 
69
75
  this.title = params.title;
70
76
  this.listClass = params.listClass || 'se-preview-list';
@@ -83,33 +89,27 @@ class Browser extends CoreInjector {
83
89
  this.icon_folder_item = this.icons.side_menu_folder;
84
90
  this.icon_item = this.icons.side_menu_item;
85
91
 
86
- /**
87
- * @type {Array<BrowserFile>}
88
- */
92
+ /** @type {Array<BrowserFile>} */
89
93
  this.items = [];
90
- /**
91
- * @type {Object<string, {name: string, meta: Object<string, *>}>}
92
- */
94
+ /** @type {Object<string, {name: string, meta: Object<string, *>}>} */
93
95
  this.folders = {};
94
- /**
95
- * @type {Object<string, {key?: string, name?: string, children?: *}>}
96
- */
96
+ /** @type {Object<string, {key?: string, name?: string, children?: *}>} */
97
97
  this.tree = {};
98
- /**
99
- * @type {BrowserFile}
100
- */
98
+ /** @type {BrowserFile} */
101
99
  this.data = {};
102
100
  this.selectedTags = [];
103
101
  this.keyword = '';
104
102
  this.sideInner = null;
105
- this._closeSignal = false;
106
- this._bindClose = null;
107
- this.__globalEventHandler = (e) => {
103
+
104
+ // api manager
105
+ this.apiManager = new ApiManager(this, { method: 'GET' });
106
+
107
+ this.#closeSignal = false;
108
+ this.#bindClose = null;
109
+ this.#globalEventHandler = (e) => {
108
110
  if (!keyCodeMap.isEsc(e.code)) return;
109
111
  this.close();
110
112
  };
111
- // api manager
112
- this.apiManager = new ApiManager(this, { method: 'GET' });
113
113
 
114
114
  // init
115
115
  browserFrame.appendChild(dom.utils.createElement('DIV', { class: 'se-browser-back' }));
@@ -134,9 +134,8 @@ class Browser extends CoreInjector {
134
134
  * @param {string=} params.url - File server url. If not, use "this.url".
135
135
  * @param {Object<string, string>=} params.urlHeader - File server http header. If not, use "this.urlHeader".
136
136
  */
137
- open(params) {
138
- if (!params) params = {};
139
- this.__addGlobalEvent();
137
+ open(params = {}) {
138
+ this.#addGlobalEvent();
140
139
 
141
140
  const listClassName = params.listClass || this.listClass;
142
141
  if (!dom.utils.hasClass(this.list, listClassName)) {
@@ -149,10 +148,12 @@ class Browser extends CoreInjector {
149
148
  this.closeArrow = this.options.get('_rtl') ? this.icons.menu_arrow_left : this.icons.menu_arrow_right;
150
149
 
151
150
  if (this.directData) {
152
- this.__drowItems(this.directData);
151
+ this.#drowItems(this.directData);
153
152
  } else {
154
- this._drawFileList(params.url || this.url, params.urlHeader || this.urlHeader, false);
153
+ this.#drawFileList(params.url || this.url, params.urlHeader || this.urlHeader, false);
155
154
  }
155
+
156
+ this.body.style.maxHeight = dom.utils.getClientSize().h - (this.editor.offset.getGlobal(this.body).top - _w.scrollY) - 20 + 'px';
156
157
  }
157
158
 
158
159
  /**
@@ -160,7 +161,7 @@ class Browser extends CoreInjector {
160
161
  * - The plugin's "init" method is called.
161
162
  */
162
163
  close() {
163
- this.__removeGlobalEvent();
164
+ this.#removeGlobalEvent();
164
165
  this.apiManager.cancel();
165
166
 
166
167
  this.area.style.display = 'none';
@@ -184,10 +185,10 @@ class Browser extends CoreInjector {
184
185
  search(keyword) {
185
186
  if (this.searchUrl) {
186
187
  this.keyword = keyword;
187
- this._drawFileList(this.searchUrl + '?keyword=' + keyword, this.searchUrlHeader, false);
188
+ this.#drawFileList(this.searchUrl + '?keyword=' + keyword, this.searchUrlHeader, false);
188
189
  } else {
189
190
  this.keyword = keyword.toLowerCase();
190
- this._drawListItem(this.items, false);
191
+ this.#drawListItem(this.items, false);
191
192
  }
192
193
  }
193
194
 
@@ -205,24 +206,23 @@ class Browser extends CoreInjector {
205
206
  * @description Show file browser loading box
206
207
  */
207
208
  showBrowserLoading() {
208
- this._loading.style.display = 'block';
209
+ this.#loading.style.display = 'block';
209
210
  }
210
211
 
211
212
  /**
212
213
  * @description Close file browser loading box
213
214
  */
214
215
  closeBrowserLoading() {
215
- this._loading.style.display = 'none';
216
+ this.#loading.style.display = 'none';
216
217
  }
217
218
 
218
219
  /**
219
- * @private
220
220
  * @description Fetches the file list from the server.
221
221
  * @param {string} url - The file server URL.
222
222
  * @param {Object<string, string>} urlHeader - The HTTP headers for the request.
223
223
  * @param {boolean} pageLoading - Indicates if this is a paginated request.
224
224
  */
225
- _drawFileList(url, urlHeader, pageLoading) {
225
+ #drawFileList(url, urlHeader, pageLoading) {
226
226
  this.apiManager.call({ method: 'GET', url, headers: urlHeader, callBack: this.#CallBackGet.bind(this), errorCallBack: this.#CallBackError.bind(this) });
227
227
  if (!pageLoading) {
228
228
  this.sideOpenBtn.style.display = 'none';
@@ -231,12 +231,11 @@ class Browser extends CoreInjector {
231
231
  }
232
232
 
233
233
  /**
234
- * @private
235
234
  * @description Updates the displayed list of file items.
236
235
  * @param {Array<BrowserFile>} items - The file items to display.
237
236
  * @param {boolean} update - Whether to update the tags.
238
237
  */
239
- _drawListItem(items, update) {
238
+ #drawListItem(items, update) {
240
239
  const keyword = this.keyword;
241
240
  items = this.tagfilter(items).filter((item) => item.name.toLowerCase().indexOf(keyword) > -1);
242
241
 
@@ -281,41 +280,38 @@ class Browser extends CoreInjector {
281
280
  }
282
281
 
283
282
  /**
284
- * @private
285
283
  * @description Adds a global event listener for closing the browser.
286
284
  */
287
- __addGlobalEvent() {
288
- this.__removeGlobalEvent();
289
- this._bindClose = this.eventManager.addGlobalEvent('keydown', this.__globalEventHandler, true);
285
+ #addGlobalEvent() {
286
+ this.#removeGlobalEvent();
287
+ this.#bindClose = this.eventManager.addGlobalEvent('keydown', this.#globalEventHandler, true);
290
288
  }
291
289
 
292
290
  /**
293
- * @private
294
291
  * @description Removes the global event listener for closing the browser.
295
292
  */
296
- __removeGlobalEvent() {
297
- if (this._bindClose) this._bindClose = this.eventManager.removeGlobalEvent(this._bindClose);
293
+ #removeGlobalEvent() {
294
+ this.#bindClose &&= this.eventManager.removeGlobalEvent(this.#bindClose);
298
295
  }
299
296
 
300
297
  /**
301
- * @private
302
298
  * @description Renders the file items or folder structure from data.
303
299
  * @param {BrowserFile[]|BrowserFile} data - The data representing the file structure.
304
300
  * @returns {boolean} True if rendering was successful, false otherwise.
305
301
  */
306
- __drowItems(data) {
302
+ #drowItems(data) {
307
303
  if (Array.isArray(data)) {
308
304
  if (data.length > 0) {
309
- this._drawListItem(data, true);
305
+ this.#drawListItem(data, true);
310
306
  }
311
307
  return true;
312
308
  } else if (typeof data === 'object') {
313
309
  this.sideOpenBtn.style.display = '';
314
- this.__parseFolderData(data);
310
+ this.#parseFolderData(data);
315
311
 
316
312
  this.side.innerHTML = '';
317
313
  const sideInner = (this.sideInner = dom.utils.createElement('div', null));
318
- this.__createFolderList(this.tree, sideInner);
314
+ this.#createFolderList(this.tree, sideInner);
319
315
  this.side.appendChild(sideInner);
320
316
 
321
317
  if (this.folderDefaultPath) {
@@ -333,12 +329,11 @@ class Browser extends CoreInjector {
333
329
  }
334
330
 
335
331
  /**
336
- * @private
337
332
  * @description Parses folder data into a structured format.
338
333
  * @param {BrowserFile} data - The folder data.
339
334
  * @param {string} [path] - The current path in the folder hierarchy.
340
335
  */
341
- __parseFolderData(data, path) {
336
+ #parseFolderData(data, path) {
342
337
  let current = this.tree;
343
338
 
344
339
  // _data
@@ -351,9 +346,7 @@ class Browser extends CoreInjector {
351
346
  const parts = path.split('/');
352
347
  const len = parts.length - 1;
353
348
  parts.forEach((part, index) => {
354
- if (!current[part]) {
355
- current[part] = { children: {} };
356
- }
349
+ current[part] ||= { children: {} };
357
350
 
358
351
  if (index === len) {
359
352
  current[part].key = path;
@@ -378,17 +371,16 @@ class Browser extends CoreInjector {
378
371
  meta: v.meta || {}
379
372
  };
380
373
 
381
- this.__parseFolderData(v, currentPath);
374
+ this.#parseFolderData(v, currentPath);
382
375
  });
383
376
  }
384
377
 
385
378
  /**
386
- * @private
387
379
  * @description Creates a nested folder list from parsed data.
388
380
  * @param {BrowserFile[]|BrowserFile} folderData - The structured folder data.
389
381
  * @param {HTMLElement} parentElement - The parent element to append folder structure to.
390
382
  */
391
- __createFolderList(folderData, parentElement) {
383
+ #createFolderList(folderData, parentElement) {
392
384
  for (const key in folderData) {
393
385
  const item = folderData[key];
394
386
  if (!item) continue;
@@ -404,7 +396,7 @@ class Browser extends CoreInjector {
404
396
  folderLabel.insertBefore(dom.utils.createElement('button', null, this.closeArrow), folderLabel.firstElementChild);
405
397
  const childContainer = document.createElement('div');
406
398
  dom.utils.addClass(childContainer, 'se-menu-child|se-menu-hidden');
407
- this.__createFolderList(item.children, childContainer);
399
+ this.#createFolderList(item.children, childContainer);
408
400
  folderDiv.appendChild(childContainer);
409
401
 
410
402
  parentElement.appendChild(folderDiv);
@@ -427,7 +419,7 @@ class Browser extends CoreInjector {
427
419
  try {
428
420
  const res = JSON.parse(xmlHttp.responseText);
429
421
  const data = res.result;
430
- if (this.__drowItems(data)) return;
422
+ if (this.#drowItems(data)) return;
431
423
 
432
424
  if (res.nullMessage) {
433
425
  this.list.innerHTML = res.nullMessage;
@@ -436,7 +428,6 @@ class Browser extends CoreInjector {
436
428
  throw Error(`[SUNEDITOR.browser.drawList.fail] cause: "${e.message}"`);
437
429
  } finally {
438
430
  this.closeBrowserLoading();
439
- this.body.style.maxHeight = dom.utils.getClientSize().h - this.header.offsetHeight - 50 + 'px';
440
431
  }
441
432
  }
442
433
 
@@ -468,7 +459,7 @@ class Browser extends CoreInjector {
468
459
  dom.utils.addClass(selectTag, 'on');
469
460
  }
470
461
 
471
- this._drawListItem(this.items, false);
462
+ this.#drawListItem(this.items, false);
472
463
  }
473
464
 
474
465
  /**
@@ -518,9 +509,9 @@ class Browser extends CoreInjector {
518
509
  this.tagArea.innerHTML = '';
519
510
 
520
511
  if (typeof data === 'string') {
521
- this._drawFileList(data, this.urlHeader, true);
512
+ this.#drawFileList(data, this.urlHeader, true);
522
513
  } else {
523
- this._drawListItem(data, false);
514
+ this.#drawListItem(data, false);
524
515
  }
525
516
  }
526
517
 
@@ -530,9 +521,9 @@ class Browser extends CoreInjector {
530
521
  #OnMouseDown_browser(e) {
531
522
  const eventTarget = dom.query.getEventTarget(e);
532
523
  if (/se-browser-inner/.test(eventTarget.className)) {
533
- this._closeSignal = true;
524
+ this.#closeSignal = true;
534
525
  } else {
535
- this._closeSignal = false;
526
+ this.#closeSignal = false;
536
527
  }
537
528
  }
538
529
 
@@ -543,7 +534,7 @@ class Browser extends CoreInjector {
543
534
  const eventTarget = dom.query.getEventTarget(e);
544
535
  e.stopPropagation();
545
536
 
546
- if (/close/.test(eventTarget.getAttribute('data-command')) || this._closeSignal) {
537
+ if (/close/.test(eventTarget.getAttribute('data-command')) || this.#closeSignal) {
547
538
  this.close();
548
539
  }
549
540
  }