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
@@ -1,6 +1,11 @@
1
1
  import EditorInjector from '../../editorInjector';
2
2
  import { dom } from '../../helper';
3
3
 
4
+ /**
5
+ * @typedef {Object} TemplatePluginOptions
6
+ * @property {Array<{name: string, html: string}>} [items] - Template list
7
+ */
8
+
4
9
  /**
5
10
  * @class
6
11
  * @description Template Plugin, Apply a template to the selection.
@@ -13,8 +18,7 @@ class Template extends EditorInjector {
13
18
  /**
14
19
  * @constructor
15
20
  * @param {__se__EditorCore} editor - The root editor instance
16
- * @param {Object} pluginOptions
17
- * @param {Array<{name: string, html: string}>} pluginOptions.items - Template list
21
+ * @param {TemplatePluginOptions} pluginOptions - Plugin options
18
22
  */
19
23
  constructor(editor, pluginOptions) {
20
24
  // plugin bisic properties
@@ -1,6 +1,11 @@
1
1
  import EditorInjector from '../../editorInjector';
2
2
  import { dom } from '../../helper';
3
3
 
4
+ /**
5
+ * @typedef {Object} TextStylePluginOptions
6
+ * @property {Array<string|{name: string, class: string, tag: string}>} items - Text style item list
7
+ */
8
+
4
9
  /**
5
10
  * @class
6
11
  * @description Text style Plugin, Applies a tag that specifies text styles to a selection.
@@ -13,8 +18,7 @@ class TextStyle extends EditorInjector {
13
18
  /**
14
19
  * @constructor
15
20
  * @param {__se__EditorCore} editor - The root editor instance
16
- * @param {Object} pluginOptions
17
- * @param {Array<{name: string, html: string}>} pluginOptions.items - Template list
21
+ * @param {TextStylePluginOptions} pluginOptions - Plugin options
18
22
  */
19
23
  constructor(editor, pluginOptions) {
20
24
  // plugin bisic properties
@@ -84,7 +88,7 @@ class TextStyle extends EditorInjector {
84
88
 
85
89
  const newNode = dom.utils.hasClass(target, 'active') ? null : tempElement.cloneNode(false);
86
90
  const removeNodes = newNode ? null : [tempElement.nodeName];
87
- this.format.applyInlineElement(newNode, { stylesToModify: checkStyles, nodesToRemove: removeNodes, strictRemove: true });
91
+ this.inline.apply(newNode, { stylesToModify: checkStyles, nodesToRemove: removeNodes, strictRemove: true });
88
92
 
89
93
  this.menu.dropdownOff();
90
94
  }
@@ -4,6 +4,19 @@ import { dom, converter } from '../../helper';
4
4
 
5
5
  const { debounce } = converter;
6
6
 
7
+ /**
8
+ * @typedef {Object} MentionPluginOptions
9
+ * @property {string} [triggerText="@"] - The character that triggers the mention list
10
+ * @property {number} [limitSize=5] - The number of items to display in the mention list
11
+ * @property {number} [searchStartLength=0] - The number of characters to start searching for the mention list
12
+ * @property {number} [delayTime=200] - The time to wait before displaying the mention list
13
+ * @property {Array<{key: string, name: string, url: string}>} [data] - Use data without using API
14
+ * @property {string} [apiUrl] - The URL to call the mention list
15
+ * @property {Object<string, string>} [apiHeaders] - The headers to send with the API call
16
+ * @property {boolean} [useCachingData=true] - Whether to cache the mention list data
17
+ * @property {boolean} [useCachingFieldData=true] - Whether to cache the mention list data in the field
18
+ */
19
+
7
20
  /**
8
21
  * @class
9
22
  * @description Mention Plugin
@@ -17,19 +30,14 @@ class Mention extends EditorInjector {
17
30
  static type = 'field';
18
31
  static className = '';
19
32
 
33
+ #lastAtPos;
34
+ #anchorOffset;
35
+ #anchorNode;
36
+
20
37
  /**
21
38
  * @constructor
22
39
  * @param {__se__EditorCore} editor - The root editor instance
23
- * @param {Object} pluginOptions
24
- * @param {string=} [pluginOptions.triggerText="@"] The character that triggers the mention list. Default is '@'.
25
- * @param {number=} [pluginOptions.limitSize=5] The number of items to display in the mention list. Default is 5.
26
- * @param {number=} [pluginOptions.searchStartLength=0] The number of characters to start searching for the mention list. Default is 0.
27
- * @param {number=} [pluginOptions.delayTime=200] The time to wait before displaying the mention list. Default is 200ms.
28
- * @param {Array<{key: string, name: string, url: string}>=} pluginOptions.data Use data without using API.
29
- * @param {string=} pluginOptions.apiUrl The URL to call the mention list. Default is ''.
30
- * @param {Object<string, string>=} pluginOptions.apiHeaders The headers to send with the API call. Default is {}.
31
- * @param {boolean=} [pluginOptions.useCachingData=true] Whether to cache the mention list data. Default is true.
32
- * @param {boolean=} [pluginOptions.useCachingFieldData=true] Whether to cache the mention list data in the field. Default is true.
40
+ * @param {MentionPluginOptions} pluginOptions
33
41
  */
34
42
  constructor(editor, pluginOptions) {
35
43
  super(editor);
@@ -44,14 +52,14 @@ class Mention extends EditorInjector {
44
52
  this.delayTime = typeof pluginOptions.delayTime === 'number' ? pluginOptions.delayTime : 200;
45
53
  this.directData = pluginOptions.data;
46
54
  this.apiUrl = pluginOptions.apiUrl?.replace(/\s/g, '').replace(/\{limitSize\}/i, String(this.limitSize)) || '';
47
- this._delay = 0;
48
- this._lastAtPos = 0;
49
- this._anchorOffset = 0;
50
- this._anchorNode = null;
51
55
  // members - api, caching
52
56
  this.apiManager = new ApiManager(this, { headers: pluginOptions.apiHeaders });
53
- this.cachingData = pluginOptions.useCachingData ?? true ? new Map() : null;
54
- this.cachingFieldData = pluginOptions.useCachingFieldData ?? true ? [] : null;
57
+ this.cachingData = (pluginOptions.useCachingData ?? true) ? new Map() : null;
58
+ this.cachingFieldData = (pluginOptions.useCachingFieldData ?? true) ? [] : null;
59
+
60
+ this.#lastAtPos = 0;
61
+ this.#anchorOffset = 0;
62
+ this.#anchorNode = null;
55
63
 
56
64
  // controller
57
65
  const controllerEl = CreateHTML_controller();
@@ -107,10 +115,10 @@ class Mention extends EditorInjector {
107
115
  }
108
116
 
109
117
  try {
110
- const result = await this._createMentionList(mentionQuery, anchorNode);
111
- this._lastAtPos = lastAtPos;
112
- this._anchorNode = anchorNode;
113
- this._anchorOffset = anchorOffset;
118
+ const result = await this.#createMentionList(mentionQuery, anchorNode);
119
+ this.#lastAtPos = lastAtPos;
120
+ this.#anchorNode = anchorNode;
121
+ this.#anchorOffset = anchorOffset;
114
122
  return !result;
115
123
  } catch (error) {
116
124
  console.warn('[SUNEDITOR.mention.api.file] ', error);
@@ -123,7 +131,6 @@ class Mention extends EditorInjector {
123
131
  }
124
132
 
125
133
  /**
126
- * @private
127
134
  * @description Generates the mention list based on user input.
128
135
  * - Fetches data from cache, direct data, or an API.
129
136
  * - Creates and opens the mention dropdown.
@@ -132,7 +139,7 @@ class Mention extends EditorInjector {
132
139
  * @param {Node} targetNode - The node where the mention is triggered.
133
140
  * @returns {Promise<boolean>} - Returns `true` if the mention list is displayed, `false` otherwise.
134
141
  */
135
- async _createMentionList(value, targetNode) {
142
+ async #createMentionList(value, targetNode) {
136
143
  const limit = this.limitSize;
137
144
  const lowerValue = value.toLowerCase();
138
145
  let response = null;
@@ -144,7 +151,7 @@ class Mention extends EditorInjector {
144
151
  if (this.directData) {
145
152
  response = this.directData.filter((item) => item.key.toLowerCase().startsWith(lowerValue)).slice(0, limit);
146
153
  } else {
147
- const xmlHttp = await this.apiManager.asyncCall({ method: 'GET', url: this._createUrl(value) });
154
+ const xmlHttp = await this.apiManager.asyncCall({ method: 'GET', url: this.#createUrl(value) });
148
155
  response = JSON.parse(xmlHttp.responseText);
149
156
  }
150
157
  }
@@ -190,12 +197,11 @@ class Mention extends EditorInjector {
190
197
  }
191
198
 
192
199
  /**
193
- * @private
194
200
  * @description Constructs the API request URL with the mention query.
195
201
  * @param {string} key - The mention query text.
196
202
  * @returns {string} - The formatted API request URL.
197
203
  */
198
- _createUrl(key) {
204
+ #createUrl(key) {
199
205
  return this.apiUrl.replace(/\{key\}/i, key);
200
206
  }
201
207
 
@@ -209,7 +215,7 @@ class Mention extends EditorInjector {
209
215
 
210
216
  let oA = null;
211
217
  const { key, name, url } = item;
212
- const anchorParent = this._anchorNode.parentNode;
218
+ const anchorParent = this.#anchorNode.parentNode;
213
219
 
214
220
  if (dom.check.isAnchor(anchorParent)) {
215
221
  oA = anchorParent;
@@ -218,7 +224,7 @@ class Mention extends EditorInjector {
218
224
  oA.setAttribute('title', name);
219
225
  oA.textContent = this.triggerText + key;
220
226
  } else {
221
- this.selection.setRange(this._anchorNode, this._lastAtPos, this._anchorNode, this._anchorOffset);
227
+ this.selection.setRange(this.#anchorNode, this.#lastAtPos, this.#anchorNode, this.#anchorOffset);
222
228
  oA = dom.utils.createElement('A', { 'data-se-mention': key, href: url, title: name, target: '_blank' }, this.triggerText + key);
223
229
  if (!this.html.insertNode(oA, { afterNode: null, skipCharCount: false })) return false;
224
230
  }
@@ -85,6 +85,17 @@ const DEFAULT_UNIT_MAP = {
85
85
  }
86
86
  };
87
87
 
88
+ /**
89
+ * @typedef {Object} FontSizePluginOptions
90
+ * @property {string} [sizeUnit='px'] - The unit for the font size.
91
+ * - Accepted values include: 'px', 'pt', 'em', 'rem', 'vw', 'vh', '%' or 'text'.
92
+ * - If 'text' is used, a text-based font size list is applied.
93
+ * @property {boolean} [showDefaultSizeLabel=true] - Determines whether the default size label is displayed in the dropdown menu.
94
+ * @property {boolean} [showIncDecControls=false] - When true, displays increase and decrease buttons for font size adjustments.
95
+ * @property {boolean} [disableInput=true] - When true, disables the direct font size input box.
96
+ * @property {Object<string, {default: number, inc: number, min: number, max: number, list: Array<number>}>} [unitMap={}] - Optional object to override or extend the default unit mapping for font sizes.
97
+ */
98
+
88
99
  /**
89
100
  * @class
90
101
  * @description FontSize Plugin
@@ -97,17 +108,12 @@ class FontSize extends EditorInjector {
97
108
  static type = 'input';
98
109
  static className = 'se-btn-select se-btn-input se-btn-tool-font-size';
99
110
 
111
+ #disableInput;
112
+
100
113
  /**
101
114
  * @constructor
102
115
  * @param {__se__EditorCore} editor - The root editor instance
103
- * @param {Object} pluginOptions - Configuration options for the FontSize plugin.
104
- * @param {string=} [pluginOptions.sizeUnit='px'] - The unit for the font size.
105
- * - Accepted values include: 'px', 'pt', 'em', 'rem', 'vw', 'vh', '%' or 'text'.
106
- * - If 'text' is used, a text-based font size list is applied.
107
- * @param {boolean=} [pluginOptions.showDefaultSizeLabel=true] - Determines whether the default size label is displayed in the dropdown menu.
108
- * @param {boolean=} [pluginOptions.showIncDecControls=false] - When true, displays increase and decrease buttons for font size adjustments.
109
- * @param {boolean=} [pluginOptions.disableInput=true] - When true, disables the direct font size input box.
110
- * @param {Object<string, {default: number, inc: number, min: number, max: number, list: Array<number>}>} [pluginOptions.unitMap={}] - Optional object to override or extend the default unit mapping for font sizes.
116
+ * @param {FontSizePluginOptions} pluginOptions - Configuration options for the FontSize plugin.
111
117
  */
112
118
  constructor(editor, pluginOptions) {
113
119
  super(editor);
@@ -120,16 +126,16 @@ class FontSize extends EditorInjector {
120
126
  const menu = CreateHTML(editor, unitMap, this.sizeUnit, pluginOptions.showDefaultSizeLabel);
121
127
 
122
128
  // plugin basic properties
123
- const showIncDec = this.sizeUnit ? pluginOptions.showIncDecControls ?? false : false;
124
- const disableInput = this.sizeUnit ? pluginOptions.disableInput ?? false : true;
129
+ const showIncDec = this.sizeUnit ? (pluginOptions.showIncDecControls ?? false) : false;
130
+ const disableInput = this.sizeUnit ? (pluginOptions.disableInput ?? false) : true;
125
131
 
126
132
  this.title = this.lang.fontSize;
127
133
  this.inner =
128
134
  disableInput && !showIncDec
129
135
  ? false
130
136
  : disableInput
131
- ? `<span class="se-txt se-not-arrow-text __se__font_size">${this.lang.fontSize}</span>`
132
- : `<input type="text" class="__se__font_size se-not-arrow-text" placeholder="${this.lang.fontSize}" />`;
137
+ ? `<span class="se-txt se-not-arrow-text __se__font_size">${this.lang.fontSize}</span>`
138
+ : `<input type="text" class="__se__font_size se-not-arrow-text" placeholder="${this.lang.fontSize}" />`;
133
139
 
134
140
  // increase, decrease buttons
135
141
  if (showIncDec) {
@@ -164,7 +170,7 @@ class FontSize extends EditorInjector {
164
170
  this.sizeList = menu.querySelectorAll('li button');
165
171
  this.hasInputFocus = false;
166
172
  this.isInputActive = false; // input target event
167
- this._disableInput = disableInput;
173
+ this.#disableInput = disableInput;
168
174
 
169
175
  // init
170
176
  this.menu.initDropdownTarget(FontSize, menu);
@@ -176,14 +182,18 @@ class FontSize extends EditorInjector {
176
182
  * @param {?HTMLElement=} element - Node element where the cursor is currently located
177
183
  * @param {?HTMLElement=} target - The plugin's toolbar button element
178
184
  * @returns {boolean} - Whether the plugin is active
185
+ * - If it returns "undefined", it will no longer be called in this scope.
179
186
  */
180
187
  active(element, target) {
181
188
  if (!dom.utils.hasClass(target, '__se__font_size')) return false;
182
189
 
190
+ let fontSize = '';
183
191
  if (!element) {
184
- this._setSize(target, this._getDefaultSize());
185
- } else if (element?.style.fontSize.length > 0) {
186
- this._setSize(target, element.style.fontSize);
192
+ this.#setSize(target, this.#getDefaultSize());
193
+ } else if (this.format.isLine(element)) {
194
+ return undefined;
195
+ } else if ((fontSize = dom.utils.getStyle(element, 'fontSize'))) {
196
+ this.#setSize(target, fontSize);
187
197
  return true;
188
198
  }
189
199
 
@@ -200,14 +210,14 @@ class FontSize extends EditorInjector {
200
210
  onInputKeyDown({ target, event }) {
201
211
  const keyCode = event.code;
202
212
 
203
- if (this._disableInput || keyCodeMap.isSpace(keyCode)) {
213
+ if (this.#disableInput || keyCodeMap.isSpace(keyCode)) {
204
214
  event.preventDefault();
205
215
  return;
206
216
  }
207
217
 
208
218
  if (!/^(38|40|13)$/.test(keyCode)) return;
209
219
 
210
- const { value, unit } = this._getSize(target);
220
+ const { value, unit } = this.#getSize(target);
211
221
  if (!value) return;
212
222
 
213
223
  const numValue = numbers.get(value);
@@ -227,11 +237,11 @@ class FontSize extends EditorInjector {
227
237
 
228
238
  try {
229
239
  this.isInputActive = true;
230
- const size = this._setSize(target, changeValue + unit);
231
- if (this._disableInput) return;
240
+ const size = this.#setSize(target, changeValue + unit);
241
+ if (this.#disableInput) return;
232
242
 
233
243
  const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + size + ';' });
234
- this.format.applyInlineElement(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
244
+ this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
235
245
 
236
246
  if (!keyCodeMap.isEnter(keyCode)) target.focus();
237
247
  } finally {
@@ -245,18 +255,18 @@ class FontSize extends EditorInjector {
245
255
  * @param {__se__PluginToolbarInputChangeEventInfo} params
246
256
  */
247
257
  onInputChange({ target, value: changeValue, event }) {
248
- if (this._disableInput) return;
258
+ if (this.#disableInput) return;
249
259
 
250
260
  try {
251
261
  this.isInputActive = true;
252
262
 
253
263
  // eslint-disable-next-line prefer-const
254
- let { value, unit } = this._getSize(changeValue);
264
+ let { value, unit } = this.#getSize(changeValue);
255
265
  const { max, min } = this.unitMap[unit];
256
266
  value = value > max ? max : value < min ? min : value;
257
267
 
258
- const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + this._setSize(target, value + unit) + ';' });
259
- this.format.applyInlineElement(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
268
+ const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + this.#setSize(target, value + unit) + ';' });
269
+ this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
260
270
  } finally {
261
271
  this.isInputActive = false;
262
272
  event.preventDefault();
@@ -270,7 +280,7 @@ class FontSize extends EditorInjector {
270
280
  * @param {HTMLElement} target Line element at the current cursor position
271
281
  */
272
282
  on(target) {
273
- const { value, unit } = this._getSize(target);
283
+ const { value, unit } = this.#getSize(target);
274
284
  const currentSize = value + unit;
275
285
 
276
286
  if (currentSize === this.currentSize) return;
@@ -297,41 +307,39 @@ class FontSize extends EditorInjector {
297
307
  const commandValue = target.getAttribute('data-command');
298
308
 
299
309
  if (commandValue === FontSize.key) {
300
- const { value, unit } = this._getSize(target);
310
+ const { value, unit } = this.#getSize(target);
301
311
  let newSize = numbers.get(value) + (target.getAttribute('data-value') === 'inc' ? 1 : -1);
302
312
  const { min, max } = this.unitMap[unit];
303
313
  newSize = newSize < min ? min : newSize > max ? max : newSize;
304
314
 
305
315
  const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + newSize + unit + ';' });
306
- this.format.applyInlineElement(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
316
+ this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
307
317
  } else if (commandValue) {
308
318
  const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + commandValue + ';' });
309
- this.format.applyInlineElement(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
319
+ this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
310
320
  } else {
311
- this.format.applyInlineElement(null, { stylesToModify: ['font-size'], nodesToRemove: ['span'], strictRemove: true });
321
+ this.inline.apply(null, { stylesToModify: ['font-size'], nodesToRemove: ['span'], strictRemove: true });
312
322
  }
313
323
 
314
324
  this.menu.dropdownOff();
315
325
  }
316
326
 
317
327
  /**
318
- * @private
319
328
  * @description Retrieves the default font size of the editor.
320
329
  * @returns {string} - The computed font size from the editor.
321
330
  */
322
- _getDefaultSize() {
323
- return this.editor.frameContext.get('wwComputedStyle').fontSize;
331
+ #getDefaultSize() {
332
+ return this.frameContext.get('wwComputedStyle').fontSize;
324
333
  }
325
334
 
326
335
  /**
327
- * @private
328
336
  * @description Extracts the font size and unit from the given element or input value.
329
337
  * @param {string|Element} target - The target input or element.
330
338
  * @returns {{ unit: string, value: number|string }} - An object containing:
331
339
  * - `unit` (string): The detected font size unit.
332
340
  * - `value` (number|string): The numeric font size value or text-based size.
333
341
  */
334
- _getSize(target) {
342
+ #getSize(target) {
335
343
  target = typeof target === 'string' ? target : target.parentElement.querySelector('.__se__font_size');
336
344
  if (!target)
337
345
  return {
@@ -355,13 +363,12 @@ class FontSize extends EditorInjector {
355
363
  }
356
364
 
357
365
  /**
358
- * @private
359
366
  * @description Sets the font size in the toolbar input field or button label.
360
367
  * @param {HTMLElement} target - The target element in the toolbar.
361
368
  * @param {string|number} value - The font size value.
362
369
  * @returns {string|number} - The applied font size.
363
370
  */
364
- _setSize(target, value) {
371
+ #setSize(target, value) {
365
372
  target = target.parentElement.querySelector('.__se__font_size');
366
373
  if (!target) return 0;
367
374
 
@@ -33,6 +33,7 @@ class PageNavigator extends EditorInjector {
33
33
  // init
34
34
  this.eventManager.addEvent(this.inner, 'change', this.#OnChangeInner.bind(this));
35
35
  }
36
+
36
37
  /**
37
38
  * @editorMethod Editor.documentType
38
39
  * @description Updates the displayed page number and total pages in the navigator.
@@ -53,13 +54,13 @@ class PageNavigator extends EditorInjector {
53
54
  * @param {InputEvent} e - Event object
54
55
  */
55
56
  #OnChangeInner(e) {
56
- if (!this.editor.frameContext.has('documentType-use-page')) return;
57
+ if (!this.frameContext.has('documentType_use_page')) return;
57
58
 
58
59
  /** @type {HTMLInputElement} */
59
60
  const eventTarget = dom.query.getEventTarget(e);
60
61
 
61
62
  const value = Number(eventTarget.value) || 1;
62
- this.editor.frameContext.get('documentType').pageGo(value);
63
+ this.frameContext.get('documentType').pageGo(value);
63
64
  }
64
65
  }
65
66