suneditor 3.1.4 → 3.2.0

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 (216) hide show
  1. package/dist/suneditor-contents.min.css +1 -1
  2. package/dist/suneditor.min.css +28 -1
  3. package/dist/suneditor.min.js +1 -1
  4. package/package.json +2 -1
  5. package/src/assets/design/color.css +12 -0
  6. package/src/assets/design/size.css +9 -2
  7. package/src/assets/icons/defaultIcons.js +96 -47
  8. package/src/assets/suneditor-contents.css +3 -2
  9. package/src/assets/suneditor.css +480 -31
  10. package/src/core/config/contextProvider.js +2 -1
  11. package/src/core/config/eventManager.js +41 -2
  12. package/src/core/config/optionProvider.js +23 -2
  13. package/src/core/editor.js +32 -14
  14. package/src/core/event/actions/index.js +76 -9
  15. package/src/core/event/effects/common.registry.js +2 -1
  16. package/src/core/event/effects/keydown.registry.js +169 -33
  17. package/src/core/event/effects/ruleHelpers.js +20 -6
  18. package/src/core/event/eventOrchestrator.js +136 -23
  19. package/src/core/event/handlers/handler_toolbar.js +4 -2
  20. package/src/core/event/handlers/handler_ww_dragDrop.js +10 -0
  21. package/src/core/event/handlers/handler_ww_input.js +9 -2
  22. package/src/core/event/handlers/handler_ww_key.js +86 -17
  23. package/src/core/event/handlers/handler_ww_mouse.js +45 -8
  24. package/src/core/event/ports.js +23 -5
  25. package/src/core/event/reducers/keydown.reducer.js +15 -2
  26. package/src/core/event/rules/keydown.rule.arrow.js +12 -2
  27. package/src/core/event/rules/keydown.rule.backspace.js +110 -15
  28. package/src/core/event/rules/keydown.rule.delete.js +62 -7
  29. package/src/core/event/rules/keydown.rule.enter.js +62 -31
  30. package/src/core/event/support/defaultLineManager.js +9 -2
  31. package/src/core/event/support/selectionState.js +13 -3
  32. package/src/core/kernel/coreKernel.js +1 -0
  33. package/src/core/logic/dom/char.js +13 -3
  34. package/src/core/logic/dom/format.js +171 -39
  35. package/src/core/logic/dom/html.js +350 -72
  36. package/src/core/logic/dom/inline.js +229 -34
  37. package/src/core/logic/dom/listFormat.js +111 -20
  38. package/src/core/logic/dom/nodeTransform.js +36 -11
  39. package/src/core/logic/dom/offset.js +116 -31
  40. package/src/core/logic/dom/selection.js +147 -29
  41. package/src/core/logic/panel/blockHandle.js +785 -0
  42. package/src/core/logic/panel/blockResolver.js +278 -0
  43. package/src/core/logic/panel/finder.js +16 -6
  44. package/src/core/logic/panel/menu.js +119 -18
  45. package/src/core/logic/panel/toolbar.js +75 -19
  46. package/src/core/logic/panel/viewer.js +76 -20
  47. package/src/core/logic/shell/_commandExecutor.js +44 -9
  48. package/src/core/logic/shell/commandDispatcher.js +46 -4
  49. package/src/core/logic/shell/component.js +102 -25
  50. package/src/core/logic/shell/focusManager.js +13 -3
  51. package/src/core/logic/shell/history.js +21 -6
  52. package/src/core/logic/shell/pluginManager.js +21 -13
  53. package/src/core/logic/shell/shortcuts.js +9 -1
  54. package/src/core/logic/shell/ui.js +139 -37
  55. package/src/core/schema/frameContext.js +34 -3
  56. package/src/core/schema/options.js +46 -4
  57. package/src/core/section/constructor.js +537 -93
  58. package/src/core/section/documentType.js +35 -6
  59. package/src/helper/converter.js +24 -7
  60. package/src/helper/dom/domCheck.js +25 -5
  61. package/src/helper/dom/domQuery.js +2 -1
  62. package/src/helper/dom/domUtils.js +17 -4
  63. package/src/helper/env.js +11 -2
  64. package/src/helper/keyCodeMap.js +6 -2
  65. package/src/helper/markdown.js +24 -5
  66. package/src/helper/msOffice.js +9 -2
  67. package/src/interfaces/plugins.js +1 -1
  68. package/src/langs/ckb.js +0 -1
  69. package/src/langs/cs.js +0 -1
  70. package/src/langs/da.js +0 -1
  71. package/src/langs/de.js +0 -1
  72. package/src/langs/en.js +0 -1
  73. package/src/langs/es.js +0 -1
  74. package/src/langs/fa.js +0 -1
  75. package/src/langs/fr.js +0 -1
  76. package/src/langs/he.js +0 -1
  77. package/src/langs/hu.js +0 -1
  78. package/src/langs/index.js +27 -1
  79. package/src/langs/it.js +0 -1
  80. package/src/langs/ja.js +0 -1
  81. package/src/langs/km.js +0 -1
  82. package/src/langs/ko.js +0 -1
  83. package/src/langs/lv.js +0 -1
  84. package/src/langs/nl.js +0 -1
  85. package/src/langs/pl.js +0 -1
  86. package/src/langs/pt_br.js +0 -1
  87. package/src/langs/ro.js +0 -1
  88. package/src/langs/ru.js +0 -1
  89. package/src/langs/se.js +0 -1
  90. package/src/langs/tr.js +0 -1
  91. package/src/langs/uk.js +0 -1
  92. package/src/langs/ur.js +0 -1
  93. package/src/langs/zh_cn.js +0 -1
  94. package/src/modules/contract/Browser.js +58 -14
  95. package/src/modules/contract/ColorPicker.js +12 -4
  96. package/src/modules/contract/Controller.js +37 -7
  97. package/src/modules/contract/Figure.js +156 -36
  98. package/src/modules/contract/HueSlider.js +27 -4
  99. package/src/modules/contract/Modal.js +50 -10
  100. package/src/modules/manager/FileManager.js +50 -8
  101. package/src/modules/ui/CommandMenu.js +597 -0
  102. package/src/modules/ui/ModalAnchorEditor.js +33 -6
  103. package/src/modules/ui/SelectMenu.js +481 -36
  104. package/src/modules/ui/index.js +1 -0
  105. package/src/plugins/browser/audioGallery.js +2 -1
  106. package/src/plugins/browser/fileBrowser.js +9 -2
  107. package/src/plugins/browser/fileGallery.js +2 -1
  108. package/src/plugins/browser/imageGallery.js +18 -3
  109. package/src/plugins/browser/videoGallery.js +13 -4
  110. package/src/plugins/command/blockquote.js +6 -1
  111. package/src/plugins/command/codeBlock.js +43 -5
  112. package/src/plugins/command/exportPDF.js +20 -4
  113. package/src/plugins/command/fileUpload.js +46 -11
  114. package/src/plugins/command/list_bulleted.js +6 -1
  115. package/src/plugins/command/list_numbered.js +6 -1
  116. package/src/plugins/dropdown/align.js +21 -33
  117. package/src/plugins/dropdown/backgroundColor.js +10 -2
  118. package/src/plugins/dropdown/blockStyle.js +17 -22
  119. package/src/plugins/dropdown/font.js +34 -34
  120. package/src/plugins/dropdown/hr.js +15 -43
  121. package/src/plugins/dropdown/layout.js +10 -27
  122. package/src/plugins/dropdown/lineHeight.js +10 -33
  123. package/src/plugins/dropdown/list.js +19 -25
  124. package/src/plugins/dropdown/paragraphStyle.js +16 -24
  125. package/src/plugins/dropdown/table/index.js +72 -17
  126. package/src/plugins/dropdown/table/render/table.html.js +3 -1
  127. package/src/plugins/dropdown/table/services/table.cell.js +33 -7
  128. package/src/plugins/dropdown/table/services/table.clipboard.js +5 -1
  129. package/src/plugins/dropdown/table/services/table.grid.js +40 -9
  130. package/src/plugins/dropdown/table/services/table.resize.js +55 -11
  131. package/src/plugins/dropdown/table/services/table.selection.js +27 -7
  132. package/src/plugins/dropdown/table/services/table.style.js +120 -20
  133. package/src/plugins/dropdown/template.js +13 -29
  134. package/src/plugins/dropdown/textStyle.js +22 -35
  135. package/src/plugins/field/autocomplete.js +8 -4
  136. package/src/plugins/field/slashCommand.js +297 -0
  137. package/src/plugins/index.js +3 -0
  138. package/src/plugins/input/fontSize.js +37 -8
  139. package/src/plugins/input/pageNavigator.js +7 -1
  140. package/src/plugins/modal/audio.js +71 -17
  141. package/src/plugins/modal/drawing.js +41 -11
  142. package/src/plugins/modal/embed.js +92 -22
  143. package/src/plugins/modal/image/index.js +114 -28
  144. package/src/plugins/modal/image/services/image.size.js +9 -2
  145. package/src/plugins/modal/image/services/image.upload.js +38 -4
  146. package/src/plugins/modal/link.js +9 -2
  147. package/src/plugins/modal/math.js +10 -2
  148. package/src/plugins/modal/video/index.js +112 -26
  149. package/src/plugins/modal/video/render/video.html.js +4 -1
  150. package/src/plugins/modal/video/services/video.size.js +15 -4
  151. package/src/plugins/modal/video/services/video.upload.js +10 -2
  152. package/src/plugins/popup/anchor.js +14 -2
  153. package/src/suneditor.js +8 -2
  154. package/src/themes/cobalt.css +12 -0
  155. package/src/themes/cream.css +12 -0
  156. package/src/themes/dark.css +12 -0
  157. package/src/themes/midnight.css +12 -0
  158. package/src/typedef.js +32 -21
  159. package/types/assets/icons/defaultIcons.d.ts +1 -0
  160. package/types/core/config/contextProvider.d.ts +7 -1
  161. package/types/core/config/eventManager.d.ts +37 -4
  162. package/types/core/config/optionProvider.d.ts +5 -1
  163. package/types/core/event/actions/index.d.ts +44 -6
  164. package/types/core/event/effects/keydown.registry.d.ts +37 -7
  165. package/types/core/event/effects/ruleHelpers.d.ts +6 -1
  166. package/types/core/event/eventOrchestrator.d.ts +6 -1
  167. package/types/core/event/handlers/handler_ww_clipboard.d.ts +15 -3
  168. package/types/core/event/handlers/handler_ww_dragDrop.d.ts +14 -2
  169. package/types/core/event/handlers/handler_ww_input.d.ts +10 -2
  170. package/types/core/event/handlers/handler_ww_key.d.ts +10 -2
  171. package/types/core/event/handlers/handler_ww_mouse.d.ts +25 -5
  172. package/types/core/event/ports.d.ts +7 -2
  173. package/types/core/event/rules/keydown.rule.backspace.d.ts +6 -1
  174. package/types/core/kernel/store.d.ts +4 -1
  175. package/types/core/logic/dom/format.d.ts +32 -14
  176. package/types/core/logic/dom/html.d.ts +11 -3
  177. package/types/core/logic/dom/nodeTransform.d.ts +6 -6
  178. package/types/core/logic/panel/blockHandle.d.ts +64 -0
  179. package/types/core/logic/panel/blockResolver.d.ts +50 -0
  180. package/types/core/logic/panel/menu.d.ts +72 -3
  181. package/types/core/logic/shell/commandDispatcher.d.ts +8 -0
  182. package/types/core/logic/shell/component.d.ts +5 -3
  183. package/types/core/logic/shell/shortcuts.d.ts +10 -1
  184. package/types/core/logic/shell/ui.d.ts +7 -1
  185. package/types/core/schema/context.d.ts +7 -1
  186. package/types/core/schema/frameContext.d.ts +36 -4
  187. package/types/core/schema/options.d.ts +83 -2
  188. package/types/core/section/constructor.d.ts +38 -1
  189. package/types/events.d.ts +208 -32
  190. package/types/helper/converter.d.ts +4 -2
  191. package/types/helper/dom/domCheck.d.ts +12 -2
  192. package/types/helper/dom/domQuery.d.ts +35 -7
  193. package/types/helper/dom/domUtils.d.ts +4 -1
  194. package/types/interfaces/plugins.d.ts +2 -2
  195. package/types/langs/_Lang.d.ts +0 -1
  196. package/types/modules/contract/ColorPicker.d.ts +2 -2
  197. package/types/modules/contract/Controller.d.ts +7 -0
  198. package/types/modules/contract/Figure.d.ts +31 -4
  199. package/types/modules/ui/CommandMenu.d.ts +262 -0
  200. package/types/modules/ui/SelectMenu.d.ts +56 -3
  201. package/types/modules/ui/index.d.ts +1 -0
  202. package/types/plugins/browser/audioGallery.d.ts +1 -1
  203. package/types/plugins/browser/fileBrowser.d.ts +1 -1
  204. package/types/plugins/browser/fileGallery.d.ts +1 -1
  205. package/types/plugins/browser/imageGallery.d.ts +1 -1
  206. package/types/plugins/browser/videoGallery.d.ts +1 -1
  207. package/types/plugins/dropdown/align.d.ts +1 -1
  208. package/types/plugins/dropdown/blockStyle.d.ts +3 -1
  209. package/types/plugins/dropdown/table/index.d.ts +4 -1
  210. package/types/plugins/dropdown/table/services/table.clipboard.d.ts +5 -1
  211. package/types/plugins/dropdown/table/services/table.grid.d.ts +10 -2
  212. package/types/plugins/field/autocomplete.d.ts +0 -1
  213. package/types/plugins/field/slashCommand.d.ts +165 -0
  214. package/types/plugins/index.d.ts +3 -0
  215. package/types/plugins/modal/link.d.ts +4 -1
  216. package/types/typedef.d.ts +48 -23
@@ -36,7 +36,8 @@ class NodeTransform {
36
36
  * const splitResult = editor.nodeTransform.split(parentNode, childNode, 1);
37
37
  */
38
38
  split(baseNode, offset, depth) {
39
- if (dom.check.isWysiwygFrame(baseNode) || this.#$.component.is(baseNode) || !baseNode) return /** @type {T} */ (baseNode);
39
+ if (dom.check.isWysiwygFrame(baseNode) || this.#$.component.is(baseNode) || !baseNode)
40
+ return /** @type {T} */ (baseNode);
40
41
 
41
42
  if (offset && !numbers.is(offset)) {
42
43
  const children = baseNode.childNodes;
@@ -53,7 +54,8 @@ class NodeTransform {
53
54
  }
54
55
 
55
56
  if (prev.childNodes.length > 0) baseNode.parentNode.insertBefore(prev, baseNode);
56
- if (next.childNodes.length > 0) baseNode.parentNode.insertBefore(next, /** @type {HTMLElement|Text} */ (baseNode).nextElementSibling);
57
+ if (next.childNodes.length > 0)
58
+ baseNode.parentNode.insertBefore(next, /** @type {HTMLElement|Text} */ (baseNode).nextElementSibling);
57
59
 
58
60
  return /** @type {T} */ (baseNode);
59
61
  }
@@ -117,7 +119,8 @@ class NodeTransform {
117
119
  }
118
120
  }
119
121
 
120
- if (depthEl.nodeType === 1 && depthEl.childNodes.length <= 1 && !depthEl.firstChild?.textContent?.length) /** @type {HTMLElement} */ (depthEl).innerHTML = '<br>';
122
+ if (depthEl.nodeType === 1 && depthEl.childNodes.length <= 1 && !depthEl.firstChild?.textContent?.length)
123
+ /** @type {HTMLElement} */ (depthEl).innerHTML = '<br>';
121
124
 
122
125
  const pElement = depthEl.parentNode;
123
126
  if (next) depthEl = depthEl.nextSibling;
@@ -175,7 +178,13 @@ class NodeTransform {
175
178
  next = /** @type {HTMLElement} */ (children[i + 1]);
176
179
  if (!child) break;
177
180
  if (dom.check.isBreak(child) || dom.check.isMedia(child) || dom.check.isInputElement(child)) continue;
178
- if ((onlyText && this.#$.inline._isIgnoreNodeChange(child)) || (!onlyText && (dom.check.isTableElements(child) || dom.check.isListCell(child) || (this.#$.format.isLine(child) && !this.#$.format.isBrLine(child))))) {
181
+ if (
182
+ (onlyText && this.#$.inline._isIgnoreNodeChange(child)) ||
183
+ (!onlyText &&
184
+ (dom.check.isTableElements(child) ||
185
+ dom.check.isListCell(child) ||
186
+ (this.#$.format.isLine(child) && !this.#$.format.isBrLine(child))))
187
+ ) {
179
188
  if (dom.check.isTableElements(child) || dom.check.isListCell(child)) {
180
189
  recursionFunc(child, depth + 1, i);
181
190
  }
@@ -220,7 +229,11 @@ class NodeTransform {
220
229
  break;
221
230
  }
222
231
 
223
- if (child.nodeName === next.nodeName && dom.check.isSameAttributes(child, next) && child.getAttribute?.('href') === next.getAttribute?.('href')) {
232
+ if (
233
+ child.nodeName === next.nodeName &&
234
+ dom.check.isSameAttributes(child, next) &&
235
+ child.getAttribute?.('href') === next.getAttribute?.('href')
236
+ ) {
224
237
  const childs = child.childNodes;
225
238
  let childLength = 0;
226
239
  for (let n = 0, nLen = childs.length; n < nLen; n++) {
@@ -239,7 +252,13 @@ class NodeTransform {
239
252
  tempL = tempL.previousSibling;
240
253
  }
241
254
 
242
- if (childLength > 0 && l.nodeType === 3 && r.nodeType === 3 && (l.textContent.length > 0 || r.textContent.length > 0)) childLength--;
255
+ if (
256
+ childLength > 0 &&
257
+ l.nodeType === 3 &&
258
+ r.nodeType === 3 &&
259
+ (l.textContent.length > 0 || r.textContent.length > 0)
260
+ )
261
+ childLength--;
243
262
 
244
263
  if (nodePathLen) {
245
264
  let path = null;
@@ -300,7 +319,7 @@ class NodeTransform {
300
319
  /**
301
320
  * @description Remove nested tags without other child nodes.
302
321
  * @param {Node} element Element object
303
- * @param {?(((current: Node) => boolean)|string)} [validation] Validation function / String(`tag1|tag2..`) / If `null`, all tags are applicable.
322
+ * @param {?(((current: *) => boolean)|string)} [validation] Validation function / String(`tag1|tag2..`) / If `null`, all tags are applicable.
304
323
  * @example
305
324
  * editor.$.nodeTransform.mergeNestedTags(parentElement, (current) => current.nodeName === 'SPAN');
306
325
  */
@@ -333,7 +352,7 @@ class NodeTransform {
333
352
  * @description Delete itself and all parent nodes that match the condition.
334
353
  * - Returns an {sc: previousSibling, ec: nextSibling}(the deleted node reference) or `null`.
335
354
  * @param {Node} item Node to be remove
336
- * @param {?(current: Node) => boolean} [validation] Validation function. default(Deleted if it only have `breakLine` and blanks)
355
+ * @param {?(current: *) => boolean} [validation] Validation function. default(Deleted if it only have `breakLine` and blanks)
337
356
  * @param {?Node} [stopParent] Stop when the parent node reaches `stopParent`
338
357
  * @returns {{sc: Node|null, ec: Node|null}|null} {sc: previousSibling, ec: nextSibling} (the deleted node reference) or `null`.
339
358
  * @example
@@ -389,8 +408,14 @@ class NodeTransform {
389
408
  notRemoveNode &&= dom.query.getParentElement(notRemoveNode, (current) => element === current.parentElement);
390
409
 
391
410
  const recursionFunc = (current) => {
392
- if (this.#$.format._isNotTextNode(current) || current === notRemoveNode || dom.check.isNonEditable(current)) return 0;
393
- if (current !== element && dom.check.isZeroWidth(current.textContent) && (!current.firstChild || !dom.check.isBreak(current.firstChild)) && !current.querySelector(allowedEmptyTags)) {
411
+ if (this.#$.format._isNotTextNode(current) || current === notRemoveNode || dom.check.isNonEditable(current))
412
+ return 0;
413
+ if (
414
+ current !== element &&
415
+ dom.check.isZeroWidth(current.textContent) &&
416
+ (!current.firstChild || !dom.check.isBreak(current.firstChild)) &&
417
+ !current.querySelector(allowedEmptyTags)
418
+ ) {
394
419
  if (current.parentNode) {
395
420
  current.parentNode.removeChild(current);
396
421
  return -1;
@@ -419,7 +444,7 @@ class NodeTransform {
419
444
  /**
420
445
  * @description Creates a nested node structure from the given array of nodes.
421
446
  * @param {SunEditor.NodeCollection} nodeArray An array of nodes to clone. The first node in the array will be the top-level parent.
422
- * @param {?(current: Node) => boolean} [validate] A validate function.
447
+ * @param {?(current: *) => boolean} [validate] A validate function.
423
448
  * @returns {{ parent: Node, inner: Node }} An object containing the top-level parent node and the innermost child node.
424
449
  * @example
425
450
  * // [div, span, em] → <div><span><em></em></span></div> (cloned)
@@ -241,7 +241,9 @@ class Offset {
241
241
  y += el.offsetTop;
242
242
  }
243
243
  if (el.scrollHeight >= el.clientHeight) {
244
- oh = /^html$/i.test(el.nodeName) ? oh || el.clientHeight : el.clientHeight + (ohel ? -ohel.clientTop : 0);
244
+ oh = /^html$/i.test(el.nodeName)
245
+ ? oh || el.clientHeight
246
+ : el.clientHeight + (ohel ? -ohel.clientTop : 0);
245
247
  ohOffsetEl = ohel || ohOffsetEl || el;
246
248
  ohel = el;
247
249
  }
@@ -249,7 +251,9 @@ class Offset {
249
251
  x += el.offsetLeft;
250
252
  }
251
253
  if (el.scrollWidth >= el.clientWidth) {
252
- ow = /^html$/i.test(el.nodeName) ? ow || el.clientWidth : el.clientWidth + (owel ? -owel.clientLeft : 0);
254
+ ow = /^html$/i.test(el.nodeName)
255
+ ? ow || el.clientWidth
256
+ : el.clientWidth + (owel ? -owel.clientLeft : 0);
253
257
  owOffsetEl = owel || owOffsetEl || el;
254
258
  owel = el;
255
259
  }
@@ -268,14 +272,18 @@ class Offset {
268
272
  y += el.offsetTop;
269
273
  }
270
274
  if (el.scrollHeight >= el.clientHeight) {
271
- oh = /^html$/i.test(el.nodeName) ? oh || el.clientHeight : el.clientHeight + (ohel ? -ohel.clientTop : 0);
275
+ oh = /^html$/i.test(el.nodeName)
276
+ ? oh || el.clientHeight
277
+ : el.clientHeight + (ohel ? -ohel.clientTop : 0);
272
278
  ohel = el;
273
279
  }
274
280
  if (el.scrollLeft > 0) {
275
281
  x += el.offsetLeft;
276
282
  }
277
283
  if (el.scrollWidth >= el.clientWidth) {
278
- ow = /^html$/i.test(el.nodeName) ? ow || el.clientWidth : el.clientWidth + (owel ? -owel.clientLeft : 0);
284
+ ow = /^html$/i.test(el.nodeName)
285
+ ? ow || el.clientWidth
286
+ : el.clientWidth + (owel ? -owel.clientLeft : 0);
279
287
  owel = el;
280
288
  }
281
289
  el = el.parentElement;
@@ -293,14 +301,18 @@ class Offset {
293
301
  y += el.offsetTop;
294
302
  }
295
303
  if (el.scrollHeight >= el.clientHeight) {
296
- oh = /^html$/i.test(el.nodeName) ? oh || el.clientHeight : el.clientHeight + (ohel ? -ohel.clientTop : 0);
304
+ oh = /^html$/i.test(el.nodeName)
305
+ ? oh || el.clientHeight
306
+ : el.clientHeight + (ohel ? -ohel.clientTop : 0);
297
307
  ohel = el;
298
308
  }
299
309
  if (el.scrollLeft > 0) {
300
310
  x += el.offsetLeft;
301
311
  }
302
312
  if (el.scrollWidth >= el.clientWidth) {
303
- ow = /^html$/i.test(el.nodeName) ? ow || el.clientWidth : el.clientWidth + (owel ? -owel.clientLeft : 0);
313
+ ow = /^html$/i.test(el.nodeName)
314
+ ? ow || el.clientWidth
315
+ : el.clientWidth + (owel ? -owel.clientLeft : 0);
304
316
  owel = el;
305
317
  }
306
318
  el = el.parentElement;
@@ -310,8 +322,14 @@ class Offset {
310
322
  const widthEditorRefer = topArea.contains(owOffsetEl);
311
323
  ohOffsetEl = heightEditorRefer ? topArea : ohOffsetEl;
312
324
  owOffsetEl = widthEditorRefer ? topArea : owOffsetEl;
313
- const ts = !ohOffsetEl ? 0 : ohOffsetEl.getBoundingClientRect().top + (!ohOffsetEl.parentElement || /^html$/i.test(ohOffsetEl.parentElement.nodeName) ? _w.scrollY : 0);
314
- const ls = !owOffsetEl ? 0 : owOffsetEl.getBoundingClientRect().left + (!owOffsetEl.parentElement || /^html$/i.test(owOffsetEl.parentElement.nodeName) ? _w.scrollX : 0);
325
+ const ts = !ohOffsetEl
326
+ ? 0
327
+ : ohOffsetEl.getBoundingClientRect().top +
328
+ (!ohOffsetEl.parentElement || /^html$/i.test(ohOffsetEl.parentElement.nodeName) ? _w.scrollY : 0);
329
+ const ls = !owOffsetEl
330
+ ? 0
331
+ : owOffsetEl.getBoundingClientRect().left +
332
+ (!owOffsetEl.parentElement || /^html$/i.test(owOffsetEl.parentElement.nodeName) ? _w.scrollX : 0);
315
333
 
316
334
  oh = heightEditorRefer ? topArea.clientHeight : oh;
317
335
  ow = widthEditorRefer ? topArea.clientWidth : ow;
@@ -388,7 +406,8 @@ class Offset {
388
406
  const menuHeight_top = containerTop - scrollTop + bt;
389
407
  if (menuHeight_top < elHeight) {
390
408
  // Not enough space above — try below
391
- const menuHeight_bottom = getClientSize(_d).h - (containerTop - scrollTop + bt + target.offsetHeight);
409
+ const menuHeight_bottom =
410
+ getClientSize(_d).h - (containerTop - scrollTop + bt + target.offsetHeight);
392
411
  if (menuHeight_bottom >= elHeight) {
393
412
  element.style.top = `${bt + target.offsetHeight}px`;
394
413
  } else if (menuHeight_bottom > menuHeight_top) {
@@ -425,20 +444,28 @@ class Offset {
425
444
 
426
445
  // left
427
446
  const ew = element.offsetWidth;
428
- const tw = target.offsetWidth;
429
447
  const tl = tGlobal.left;
430
448
  const tcleft = this.getGlobal(t_container).left;
431
449
 
432
450
  if (this.#options.get('_rtl')) {
433
- const rtlW = ew > tw ? ew - tw : 0;
434
- const rtlL = rtlW > 0 ? 0 : tw - ew;
435
- element.style.left = `${tl - rtlW + rtlL}px`;
436
- if (tcleft > this.getGlobal(element).left) {
437
- element.style.left = tcleft + 'px';
451
+ const targetRect = target.getBoundingClientRect();
452
+ const vpW = _w.innerWidth;
453
+ let rightPx = vpW - targetRect.right;
454
+
455
+ if (ew > 0) {
456
+ const tcRect = t_container.getBoundingClientRect();
457
+ const menuLeftVP = vpW - rightPx - ew;
458
+ if (menuLeftVP < tcRect.left) {
459
+ rightPx = vpW - tcRect.left - ew;
460
+ }
438
461
  }
462
+
463
+ element.style.left = 'auto';
464
+ element.style.right = `${Math.max(0, rightPx)}px`;
439
465
  } else {
440
466
  const cw = t_container.offsetWidth + tcleft;
441
467
  const overLeft = cw <= ew ? 0 : cw - (tl + ew);
468
+ element.style.right = '';
442
469
  if (overLeft < 0) {
443
470
  element.style.left = `${tl + overLeft}px`;
444
471
  } else {
@@ -479,7 +506,10 @@ class Offset {
479
506
  }
480
507
 
481
508
  const isIframe = this.#frameOptions.get('iframe');
482
- const isWWTarget = this.#frameContext.get('wrapper').contains(target) || params.isWWTarget || (isIframe ? this.#frameContext.get('wysiwyg').contains(target) : false);
509
+ const isWWTarget =
510
+ this.#frameContext.get('wrapper').contains(target) ||
511
+ params.isWWTarget ||
512
+ (isIframe ? this.#frameContext.get('wysiwyg').contains(target) : false);
483
513
  const isToolbarTarget = Boolean(getParentElement(target, '.se-toolbar'));
484
514
  const isElTarget = target.nodeType === 1;
485
515
 
@@ -487,9 +517,14 @@ class Offset {
487
517
  const isInlineTarget = isElTarget && /inline/.test(_w.getComputedStyle(target).display);
488
518
  const clientSize = getClientSize(_d);
489
519
  const wwScroll = isTextSelection ? this.getWWScroll() : this.#getWindowScroll();
490
- const targetRect = !isWWTarget || (!isIframe && isElTarget) ? target.getBoundingClientRect() : this.#$.selection.getRects(target, 'start').rects;
520
+ const targetRect =
521
+ !isWWTarget || (!isIframe && isElTarget)
522
+ ? target.getBoundingClientRect()
523
+ : this.#$.selection.getRects(target, 'start').rects;
491
524
  const targetOffset = this.getGlobal(target);
492
- const arrow = /** @type {HTMLElement} */ (hasClass(element.firstElementChild, 'se-arrow') ? element.firstElementChild : null);
525
+ const arrow = /** @type {HTMLElement} */ (
526
+ hasClass(element.firstElementChild, 'se-arrow') ? element.firstElementChild : null
527
+ );
493
528
 
494
529
  // top ----------------------------------------------------------------------------------------------------
495
530
  const siblingH = params.sibling?.offsetHeight || 0;
@@ -504,16 +539,38 @@ class Offset {
504
539
  const th = this.#context.get('toolbar_main').offsetHeight;
505
540
  const containerToolbar = this.#options.get('toolbar_container');
506
541
  const headLess = this.#store.mode.isBalloon || this.#store.mode.isInline || containerToolbar;
507
- const toolbarH = (containerToolbar && globalTop - wScrollY - th > 0) || (!this.#$.toolbar.isSticky && headLess) ? 0 : th + (this.#$.toolbar.isSticky ? this.#options.get('_toolbar_sticky') : 0);
542
+ const toolbarH =
543
+ (containerToolbar && globalTop - wScrollY - th > 0) || (!this.#$.toolbar.isSticky && headLess)
544
+ ? 0
545
+ : th + (this.#$.toolbar.isSticky ? this.#options.get('_toolbar_sticky') : 0);
508
546
  const statusBarH = this.#frameContext.get('statusbar')?.offsetHeight || 0;
509
547
 
510
548
  // check margin
511
- const { rmt, rmb, bMargin, rt } = this.#getVMargin(tmtw, tmbw, toolbarH, clientSize, targetRect, isTextSelection, isToolbarTarget);
512
- if ((isWWTarget && (rmb - statusBarH + targetH <= 0 || rmt + rt + targetH - (this.#$.toolbar.isSticky && isInlineTarget ? toolbarH : 0) <= 0)) || rmt + targetH < 0) return;
549
+ const { rmt, rmb, bMargin, rt } = this.#getVMargin(
550
+ tmtw,
551
+ tmbw,
552
+ toolbarH,
553
+ clientSize,
554
+ targetRect,
555
+ isTextSelection,
556
+ isToolbarTarget,
557
+ );
558
+ if (
559
+ (isWWTarget &&
560
+ (rmb - statusBarH + targetH <= 0 ||
561
+ rmt + rt + targetH - (this.#$.toolbar.isSticky && isInlineTarget ? toolbarH : 0) <= 0)) ||
562
+ rmt + targetH < 0
563
+ )
564
+ return;
513
565
 
514
566
  const topAreaRect = this.#frameContext.get('topArea').getBoundingClientRect();
515
- const isStickyVisible = this.#store.mode.isBottom ? topAreaRect.bottom >= _w.innerHeight - th : topAreaRect.top <= th;
516
- const isSticky = this.#$.toolbar.isSticky && this.#context.get('toolbar_main').style.display !== 'none' && (!headLess || isStickyVisible);
567
+ const isStickyVisible = this.#store.mode.isBottom
568
+ ? topAreaRect.bottom >= _w.innerHeight - th
569
+ : topAreaRect.top <= th;
570
+ const isSticky =
571
+ this.#$.toolbar.isSticky &&
572
+ this.#context.get('toolbar_main').style.display !== 'none' &&
573
+ (!headLess || isStickyVisible);
517
574
  let t = addOffset.top;
518
575
  let y = 0;
519
576
  let arrowDir = '';
@@ -571,7 +628,13 @@ class Offset {
571
628
  arrow.style.right = '';
572
629
  }
573
630
 
574
- let l = addOffset.left || (addOffset.right ? (isLTR ? addOffset.right - element.offsetWidth : element.offsetWidth - addOffset.right) : 0);
631
+ let l =
632
+ addOffset.left ||
633
+ (addOffset.right
634
+ ? isLTR
635
+ ? addOffset.right - element.offsetWidth
636
+ : element.offsetWidth - addOffset.right
637
+ : 0);
575
638
  let x = 0;
576
639
  let ax = 0;
577
640
  let awLimit = 0;
@@ -690,7 +753,10 @@ class Offset {
690
753
  const targetH = rects.height;
691
754
  const tmtw = rects.top;
692
755
  const tmbw = clientSize.h - rects.bottom;
693
- const toolbarH = !this.#$.toolbar.isSticky && (this.#store.mode.isBalloon || this.#store.mode.isInline) ? 0 : this.#context.get('toolbar_main').offsetHeight;
756
+ const toolbarH =
757
+ !this.#$.toolbar.isSticky && (this.#store.mode.isBalloon || this.#store.mode.isInline)
758
+ ? 0
759
+ : this.#context.get('toolbar_main').offsetHeight;
694
760
 
695
761
  const { rmt, rmb, rt } = this.#getVMargin(tmtw, tmbw, toolbarH, clientSize, rects, isTextSelection, false);
696
762
  if (rmb + targetH <= 0 || rmt + rt + targetH <= 0) return;
@@ -723,11 +789,18 @@ class Offset {
723
789
  const absoluteLeft = (isDirTop ? rects.left : rects.right) - editorLeft - elW / 2 + scrollLeft;
724
790
  const overRight = absoluteLeft + elW - editorWidth;
725
791
 
726
- let t = (isDirTop ? rects.top - elH - arrowMargin : rects.bottom + arrowMargin) - (rects.noText ? 0 : addTop) + scrollTop;
792
+ let t =
793
+ (isDirTop ? rects.top - elH - arrowMargin : rects.bottom + arrowMargin) -
794
+ (rects.noText ? 0 : addTop) +
795
+ scrollTop;
727
796
  const l = absoluteLeft < 0 ? padding : overRight < 0 ? absoluteLeft : absoluteLeft - overRight - padding - 1;
728
797
 
729
798
  let resetTop = false;
730
- const space = t + (isDirTop ? this.getGlobal(this.#frameContext.get('topArea')).top : element.offsetHeight - this.#frameContext.get('wysiwyg').offsetHeight);
799
+ const space =
800
+ t +
801
+ (isDirTop
802
+ ? this.getGlobal(this.#frameContext.get('topArea')).top
803
+ : element.offsetHeight - this.#frameContext.get('wysiwyg').offsetHeight);
731
804
  if (!isDirTop && space > 0 && this.#getPageBottomSpace() < space) {
732
805
  isDirTop = true;
733
806
  resetTop = true;
@@ -736,7 +809,11 @@ class Offset {
736
809
  resetTop = true;
737
810
  }
738
811
 
739
- if (resetTop) t = (isDirTop ? rects.top - elH - arrowMargin : rects.bottom + arrowMargin) - (rects.noText ? 0 : addTop) + scrollTop;
812
+ if (resetTop)
813
+ t =
814
+ (isDirTop ? rects.top - elH - arrowMargin : rects.bottom + arrowMargin) -
815
+ (rects.noText ? 0 : addTop) +
816
+ scrollTop;
740
817
 
741
818
  element.style.left = Math.floor(l) + 'px';
742
819
  element.style.top = Math.floor(t) + 'px';
@@ -750,7 +827,12 @@ class Offset {
750
827
  }
751
828
 
752
829
  const arrow_left = Math.floor(elW / 2 + (absoluteLeft - l));
753
- arrow.style.left = (arrow_left + arrowMargin > element.offsetWidth ? element.offsetWidth - arrowMargin : arrow_left < arrowMargin ? arrowMargin : arrow_left) + 'px';
830
+ arrow.style.left =
831
+ (arrow_left + arrowMargin > element.offsetWidth
832
+ ? element.offsetWidth - arrowMargin
833
+ : arrow_left < arrowMargin
834
+ ? arrowMargin
835
+ : arrow_left) + 'px';
754
836
  }
755
837
 
756
838
  /**
@@ -807,9 +889,12 @@ class Offset {
807
889
  rmb = bMargin - (emb > 0 ? emb : 0);
808
890
  }
809
891
  } else {
810
- rt = !isToolbarTarget && !this.#$.toolbar.isSticky && !this.#options.get('toolbar_container') ? toolbarH : 0;
892
+ rt =
893
+ !isToolbarTarget && !this.#$.toolbar.isSticky && !this.#options.get('toolbar_container') ? toolbarH : 0;
811
894
  const wst = !isIframe ? editorOffset.top - _w.scrollY + rt : 0;
812
- const wsb = !isIframe ? this.#store.get('currentViewportHeight') - (editorOffset.top + editorOffset.height - _w.scrollY) : 0;
895
+ const wsb = !isIframe
896
+ ? this.#store.get('currentViewportHeight') - (editorOffset.top + editorOffset.height - _w.scrollY)
897
+ : 0;
813
898
  let st = wst;
814
899
  let sb = wsb;
815
900
  if (isBottom) {