suneditor 3.3.0 → 3.3.1

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.
@@ -16,9 +16,10 @@ const MENU_MIN_HEIGHT = 38;
16
16
  * @property {number} [splitNum=0] Optional split number for horizontal positioning; defines how many items per row
17
17
  * @property {() => void} [openMethod] Optional method to call when the menu is opened
18
18
  * @property {() => void} [closeMethod] Optional method to call when the menu is closed
19
- * @property {() => boolean} [subEscMethod] Optional owner hook invoked on ESC before the menu closes.
20
- * Return `true` if it dismissed an owner-managed sub-panel (e.g. CommandMenu's flyout), so ESC only
21
- * closes that sub-panel and keeps the menu open.
19
+ * @property {() => boolean} [subEscMethod] Optional owner hook that dismisses an owner-managed sub-panel (e.g. CommandMenu's dropdown-free flyout) and puts the cursor back on its row.
20
+ * Return `true` when a sub-panel was actually dismissed.
21
+ * @property {(index: number) => boolean} [subCheckMethod] Optional owner hook answering "does the row at `index` own a sub-panel?".
22
+ * - A query only — it must not open anything.
22
23
  * @property {string} [maxHeight] Optional max-height CSS value (e.g. `"200px"`). Enables scrolling when items exceed this height.
23
24
  * @property {string} [minWidth] Optional min-width CSS value (e.g. `"130px"`).
24
25
  * @property {*} [keydownTarget] Optional override for the keyboard navigation target. By default `on()` listens
@@ -41,6 +42,7 @@ class SelectMenu {
41
42
  #eventHandlers;
42
43
  #globalEventHandlers;
43
44
 
45
+ #listInner = null;
44
46
  #refer = null;
45
47
  #keydownTarget = null;
46
48
  #keydownTargetOverride = null;
@@ -86,6 +88,7 @@ class SelectMenu {
86
88
  this.openMethod = params.openMethod;
87
89
  this.closeMethod = params.closeMethod;
88
90
  this.subEscMethod = params.subEscMethod || null;
91
+ this.subCheckMethod = params.subCheckMethod || null;
89
92
  this.maxHeight = params.maxHeight || '';
90
93
  this.minWidth = params.minWidth || '';
91
94
  this.#keydownTargetOverride = params.keydownTarget || null;
@@ -135,7 +138,7 @@ class SelectMenu {
135
138
  * );
136
139
  */
137
140
  create(items, menus) {
138
- this.form.firstElementChild.innerHTML = '';
141
+ this.#listInner.innerHTML = '';
139
142
 
140
143
  // remove existing submenu elements from form
141
144
  for (const [, data] of this.#submenuData) {
@@ -228,6 +231,8 @@ class SelectMenu {
228
231
  '<div class="se-list-inner"' + (innerStyle ? ' style="' + innerStyle + '"' : '') + '></div>',
229
232
  );
230
233
 
234
+ this.#listInner = /** @type {HTMLElement} */ (this.form.firstElementChild);
235
+
231
236
  referElement.parentNode.insertBefore(this.form, referElement);
232
237
  }
233
238
 
@@ -247,7 +252,7 @@ class SelectMenu {
247
252
  * selectMenu.open('', '[data-command="' + this.align + '"]');
248
253
  */
249
254
  open(position, onItemQuerySelector) {
250
- this.#$.ui.selectMenuOn = true;
255
+ this.#$.ui.setSelectMenuOpen(this, true);
251
256
 
252
257
  this.openMethod?.();
253
258
 
@@ -298,10 +303,11 @@ class SelectMenu {
298
303
  * @description Select menu close
299
304
  */
300
305
  close() {
301
- this.#$.ui.selectMenuOn = false;
306
+ this.#$.ui.setSelectMenuOpen(this, false);
302
307
  dom.utils.removeClass(this.#refer, 'on');
303
308
  this.#init();
304
309
  this.form?.removeAttribute('style');
310
+ if (this.#listInner) this.#resetClamp();
305
311
  this.isOpen = false;
306
312
 
307
313
  this.closeMethod?.();
@@ -521,7 +527,7 @@ class SelectMenu {
521
527
  * @param {string} html - The HTML string representing the menu items.
522
528
  */
523
529
  #createFormat(html) {
524
- this.form.firstElementChild.innerHTML += `<ul class="se-list-basic se-list-checked${this.horizontal ? ' se-list-horizontal' : ''}">${html}</ul>`;
530
+ this.#listInner.innerHTML += `<ul class="se-list-basic se-list-checked${this.horizontal ? ' se-list-horizontal' : ''}">${html}</ul>`;
525
531
  }
526
532
 
527
533
  /**
@@ -551,6 +557,44 @@ class SelectMenu {
551
557
  this.#selectItem(selectIndex);
552
558
  }
553
559
 
560
+ /**
561
+ * @description Restores the list box to its `maxHeight` param, dropping any previous viewport clamp.
562
+ * - `#setPosition` may run twice (the `_re` retry), so the clamp must not accumulate.
563
+ */
564
+ #resetClamp() {
565
+ this.form.style.height = '';
566
+ this.#listInner.style.maxHeight = this.maxHeight;
567
+ this.#listInner.style.overflowY = this.maxHeight ? 'auto' : '';
568
+ }
569
+
570
+ /**
571
+ * @description Clamps the menu to `h` when it doesn't fit the viewport.
572
+ * @param {number} h - Target form height in px.
573
+ */
574
+ #clampHeight(h) {
575
+ const chrome = this.form.offsetHeight - this.#listInner.offsetHeight; // padding + border
576
+ this.form.style.height = h + 'px';
577
+ this.#listInner.style.maxHeight = (h - chrome > 0 ? h - chrome : 0) + 'px';
578
+ this.#listInner.style.overflowY = 'auto';
579
+ }
580
+
581
+ /**
582
+ * @description Scrolls the list so the given item is fully visible.
583
+ * @param {Element} item - The item element to reveal.
584
+ */
585
+ #scrollToItem(item) {
586
+ if (!item) return;
587
+
588
+ const list = this.#listInner;
589
+ if (!list.style.maxHeight) return;
590
+ const top = list.getBoundingClientRect().top + list.clientTop;
591
+ const bottom = top + list.clientHeight;
592
+ const { top: itemTop, bottom: itemBottom } = item.getBoundingClientRect();
593
+
594
+ if (itemTop < top) list.scrollTop -= top - itemTop;
595
+ else if (itemBottom > bottom) list.scrollTop += itemBottom - bottom;
596
+ }
597
+
554
598
  /**
555
599
  * @description Highlights and selects an item by index.
556
600
  * @param {number} selectIndex - The index of the item to select.
@@ -569,6 +613,7 @@ class SelectMenu {
569
613
 
570
614
  this.index = selectIndex;
571
615
  this.item = this.items[selectIndex];
616
+ this.#scrollToItem(this.menus[selectIndex]);
572
617
  }
573
618
 
574
619
  /**
@@ -584,7 +629,8 @@ class SelectMenu {
584
629
  const target = this.#refer;
585
630
  form.style.visibility = 'hidden';
586
631
  form.style.display = 'block';
587
- dom.utils.removeClass(form, 'se-select-menu-scroll');
632
+
633
+ this.#resetClamp();
588
634
  dom.utils.addClass(target, 'on');
589
635
 
590
636
  const formW = form.offsetWidth;
@@ -635,7 +681,7 @@ class SelectMenu {
635
681
  h += formT - 4;
636
682
  t -= formT - 4;
637
683
  }
638
- form.style.height = h + 'px';
684
+ this.#clampHeight(h);
639
685
  break;
640
686
  }
641
687
  case 'top':
@@ -645,7 +691,7 @@ class SelectMenu {
645
691
  break;
646
692
  }
647
693
  overH = targetGlobalTop - 4 + sideAddH;
648
- if (overH >= MENU_MIN_HEIGHT) form.style.height = overH + 'px';
694
+ if (overH >= MENU_MIN_HEIGHT) this.#clampHeight(overH);
649
695
  }
650
696
  t = targetOffsetTop - form.offsetHeight + sideAddH;
651
697
  break;
@@ -656,7 +702,7 @@ class SelectMenu {
656
702
  break;
657
703
  }
658
704
  overH = wbottom - 4 + sideAddH;
659
- if (overH >= MENU_MIN_HEIGHT) form.style.height = overH + 'px';
705
+ if (overH >= MENU_MIN_HEIGHT) this.#clampHeight(overH);
660
706
  }
661
707
  t = targetOffsetTop + (side ? 0 : targetHeight);
662
708
  break;
@@ -708,7 +754,7 @@ class SelectMenu {
708
754
  }
709
755
 
710
756
  if (onItemQuerySelector) {
711
- const item = form.firstElementChild.querySelector(onItemQuerySelector);
757
+ const item = this.#listInner.querySelector(onItemQuerySelector);
712
758
  if (item) {
713
759
  this._onItem = item;
714
760
  dom.utils.addClass(item, 'se-select-on');
@@ -794,22 +840,18 @@ class SelectMenu {
794
840
  this.#moveSubmenuItem(1);
795
841
  return;
796
842
  case 'ArrowLeft':
843
+ case 'ArrowRight': {
797
844
  e.preventDefault();
798
845
  e.stopPropagation();
799
- // exit submenu back to parent
800
- this.#inSubmenu = false;
801
- this.#submenuItemIndex = -1;
802
- {
803
- const subData = this.#submenuData.get(this.#activeSubmenuIndex);
804
- if (subData?.element)
805
- dom.utils.removeClass(
806
- subData.element.querySelectorAll('.se-select-item'),
807
- 'se-select-cursor',
808
- );
809
- }
846
+ // Close the submenu and put the cursor back on its trigger row — the same thing ESC
847
+ // does. Either direction closes, so the gesture reads the same in LTR and RTL and
848
+ // there is no writing-direction branch to keep in sync.
849
+ const parentIndex = this.#activeSubmenuIndex;
850
+ this.#closeSubmenu();
851
+ if (parentIndex > -1) this.#selectItem(parentIndex);
810
852
  return;
853
+ }
811
854
  case 'Enter':
812
- case 'Space':
813
855
  if (this.#submenuItemIndex > -1) {
814
856
  e.preventDefault();
815
857
  e.stopPropagation();
@@ -841,24 +883,40 @@ class SelectMenu {
841
883
  moveIndex = 1;
842
884
  }
843
885
  break;
844
- case 'ArrowLeft': // left
845
- e.preventDefault();
846
- e.stopPropagation();
847
- moveIndex = -1;
848
- break;
849
- case 'ArrowRight': // right — enter submenu if available
886
+ case 'ArrowLeft':
887
+ case 'ArrowRight':
850
888
  e.preventDefault();
851
889
  e.stopPropagation();
852
- if (this.index > -1 && this.#submenuData.has(this.index)) {
853
- this.#openSubmenu(this.index);
854
- this.#inSubmenu = true;
855
- this.#moveSubmenuItem(1);
890
+
891
+ if (this.#activeSubmenuIndex > -1) {
892
+ const parentIndex = this.#activeSubmenuIndex;
893
+ this.#closeSubmenu();
894
+ this.#selectItem(parentIndex);
856
895
  return;
857
896
  }
858
- moveIndex = 1;
897
+
898
+ if (this.subEscMethod?.()) return;
899
+
900
+ if (this.index > -1) {
901
+ if (this.#submenuData.has(this.index)) {
902
+ this.#openSubmenu(this.index);
903
+ this.#inSubmenu = true;
904
+ this.#moveSubmenuItem(1);
905
+ return;
906
+ }
907
+
908
+ if (this.subCheckMethod?.(this.index)) {
909
+ this.#select(this.index);
910
+ return;
911
+ }
912
+ }
913
+
914
+ if (!this.horizontal) return;
915
+
916
+ moveIndex = e.code === 'ArrowLeft' ? -1 : 1;
917
+
859
918
  break;
860
919
  case 'Enter':
861
- case 'Space': // enter, space
862
920
  if (this.index > -1) {
863
921
  e.preventDefault();
864
922
  e.stopPropagation();
@@ -875,6 +933,9 @@ class SelectMenu {
875
933
 
876
934
  if (moveIndex) {
877
935
  this.#closeSubmenu();
936
+ // Moving off a row must take its sub-panel with it, otherwise the flyout stays open while the
937
+ // cursor is somewhere else entirely.
938
+ this.subEscMethod?.();
878
939
  this.#moveItem(moveIndex);
879
940
  }
880
941
  }
@@ -924,9 +924,24 @@ class Table extends PluginDropdownFree {
924
924
  * @description Executes the selected action when the table picker is clicked.
925
925
  */
926
926
  #OnClickTablePicker() {
927
+ this.insert(this.#tableXY[0], this.#tableXY[1]);
928
+ }
929
+
930
+ /**
931
+ * @description Insert a table of the given size at the caret and place the caret in its first cell.
932
+ * @param {number} [cols=3] - Column count
933
+ * @param {number} [rows=3] - Row count
934
+ * @returns {boolean} `true` when the table was inserted
935
+ * @example
936
+ * // insert a 3x3 table without going through the size picker
937
+ * editor.plugins.table.insert();
938
+ * editor.plugins.table.insert(4, 2);
939
+ */
940
+ insert(cols, rows) {
941
+ const x = cols > 0 ? cols : Constants.DEFAULT_SIZE[0];
942
+ const y = rows > 0 ? rows : Constants.DEFAULT_SIZE[1];
943
+
927
944
  const oTable = dom.utils.createElement('TABLE');
928
- const x = this.#tableXY[0];
929
- const y = this.#tableXY[1];
930
945
 
931
946
  const body = `<tbody>${`<tr>${CreateCellsString('td', x)}</tr>`.repeat(y)}</tbody>`;
932
947
  const colGroup = `<colgroup>${`<col style="width: ${numbers.get(100 / x, Constants.CELL_DECIMAL_END)}%;">`.repeat(x)}</colgroup>`;
@@ -945,12 +960,14 @@ class Table extends PluginDropdownFree {
945
960
  figure.appendChild(oTable);
946
961
  this.#maxWidth = true;
947
962
 
948
- if (this.$.component.insert(figure, { insertBehavior: 'none' })) {
949
- this.#resetTablePicker();
950
- this.$.menu.dropdownOff();
951
- const target = oTable.querySelector('td div');
952
- this.$.selection.setRange(target, 0, target, 0);
953
- }
963
+ if (!this.$.component.insert(figure, { insertBehavior: 'none' })) return false;
964
+
965
+ this.#resetTablePicker();
966
+ this.$.menu.dropdownOff();
967
+ const target = oTable.querySelector('td div');
968
+ this.$.selection.setRange(target, 0, target, 0);
969
+
970
+ return true;
954
971
  }
955
972
 
956
973
  /**
@@ -2,6 +2,8 @@ export const ROW_SELECT_MARGIN = 6;
2
2
  export const CELL_SELECT_MARGIN = 6;
3
3
  export const CELL_DECIMAL_END = 0;
4
4
 
5
+ export const DEFAULT_SIZE = [3, 3];
6
+
5
7
  export const RESIZE_CELL_CLASS = '.se-table-resize-line';
6
8
  export const RESIZE_CELL_PREV_CLASS = '.se-table-resize-line-prev';
7
9
  export const RESIZE_ROW_CLASS = '.se-table-resize-row';
@@ -31,7 +31,10 @@ const { debounce } = converter;
31
31
  * (plugin names, built-in commands like `'bold'`); objects are custom items with their own `action`.
32
32
  * Required.
33
33
  * @property {number} [delayTime=120] - Debounce delay (ms) before the input is inspected for the trigger.
34
- * @property {number} [limitSize=10] - Maximum number of items shown in the dropdown.
34
+ * @property {number} [limitSize=0] - Maximum number of items kept after filtering. `0` (default) keeps every match
35
+ * - the list scrolls within `maxHeight`, so a cap only hides matches the user can no longer reach.
36
+ * @property {string} [maxHeight='320px'] - Max height of the menu list. Any CSS length; the list scrolls past it.
37
+ * @property {string} [minWidth='200px'] - Min width of the menu.
35
38
  * @property {string} [emptyMessage] - Message shown when no items match the query. If unset, the menu closes on no match.
36
39
  * @property {function(SlashCommandItem, { icons: Object }): string} [renderItem] - Custom item HTML renderer.
37
40
  * Applied only to custom item objects; plugin-name entries always render with the canonical BlockHandle row.
@@ -64,6 +67,15 @@ const { debounce } = converter;
64
67
  * // A container block (BLOCKQUOTE, DIV…): `applyBlock` WRAPS the selected lines → `<blockquote>…</blockquote>`.
65
68
  * action: ($) => $.format.applyBlock(document.createElement('BLOCKQUOTE')),
66
69
  * },
70
+ * {
71
+ * key: 'table',
72
+ * title: 'Table',
73
+ * icon: 'table',
74
+ * // A plugin-name entry (`'table'`) opens that plugin's own UI — for table, the size picker,
75
+ * // which is driven by the pointer. A custom item skips it and inserts straight away, which
76
+ * // keeps the whole gesture on the keyboard: type the trigger, press Enter, done.
77
+ * action: ($) => $.plugins.table.insert(3, 3),
78
+ * },
67
79
  * 'bold',
68
80
  * 'image',
69
81
  * 'blockStyle',
@@ -111,7 +123,9 @@ class SlashCommand extends PluginField {
111
123
  ? pluginOptions.triggerChar
112
124
  : '/';
113
125
  this.#limitSize =
114
- typeof pluginOptions.limitSize === 'number' && pluginOptions.limitSize > 0 ? pluginOptions.limitSize : 10;
126
+ typeof pluginOptions.limitSize === 'number' && pluginOptions.limitSize > 0
127
+ ? pluginOptions.limitSize
128
+ : Infinity;
115
129
  this.#emptyMessage = typeof pluginOptions.emptyMessage === 'string' ? pluginOptions.emptyMessage : '';
116
130
  const delayTime = typeof pluginOptions.delayTime === 'number' ? pluginOptions.delayTime : 120;
117
131
 
@@ -119,11 +133,12 @@ class SlashCommand extends PluginField {
119
133
  items: Array.isArray(pluginOptions.items) ? pluginOptions.items : [],
120
134
  resolveButton: ResolveButton,
121
135
  renderCustomItem: typeof pluginOptions.renderItem === 'function' ? pluginOptions.renderItem : null,
136
+ prepareCommit: () => this.#removeTrigger(),
122
137
  selectMenuParams: {
123
138
  position: 'bottom-left',
124
139
  dir: 'ltr',
125
- minWidth: '200px',
126
- maxHeight: '320px',
140
+ minWidth: typeof pluginOptions.minWidth === 'string' ? pluginOptions.minWidth : '200px',
141
+ maxHeight: typeof pluginOptions.maxHeight === 'string' ? pluginOptions.maxHeight : '320px',
127
142
  closeMethod: () => this.#onMenuClose(),
128
143
  },
129
144
  });
@@ -219,6 +234,32 @@ class SlashCommand extends PluginField {
219
234
  this.#cacheAnchor(anchorNode, lastPos, anchorOffset);
220
235
  }
221
236
 
237
+ /**
238
+ * @description Open the command menu programmatically, with no trigger character typed and the full tem list shown.
239
+ * - Intended for host UI that wants the same menu without the `/` shortcut — e.g. the
240
+ * - block handle's plus button:
241
+ * ```js
242
+ * blockHandle: { onPlusClick: ($, { block }) => $.plugins.slashCommand.open(block) }
243
+ * ```
244
+ * @param {Node} anchorNode - Node the menu anchors to (typically the line the caret sits on).
245
+ * @returns {boolean} `true` if the menu was opened
246
+ */
247
+ open(anchorNode) {
248
+ if (!anchorNode) return false;
249
+
250
+ const filtered = this.#menu.filter('', this.#limitSize);
251
+ if (filtered.length === 0) return false;
252
+
253
+ this.controller.open(anchorNode, null, { isWWTarget: true, initMethod: null, addOffset: null });
254
+ this.#menu.createRows(filtered);
255
+ this.#menu.open();
256
+ this.#menu.setItem(0);
257
+
258
+ this.#cacheAnchor(anchorNode, 0, 0);
259
+
260
+ return true;
261
+ }
262
+
222
263
  /**
223
264
  * @description Close the menu from the plugin itself (invalid query, or after a selection). Flags
224
265
  * the close as internal so `#onMenuClose` does not treat it as a user dismiss.
@@ -289,17 +330,23 @@ class SlashCommand extends PluginField {
289
330
  if (!anchorNode) return false;
290
331
 
291
332
  const triggerChar = this.#triggerChar;
292
- const query = anchorNode.textContent.substring(this.#lastTriggerPos + triggerChar.length, this.#anchorOffset);
293
-
294
- // Remove the trigger + query, leaving the caret at the trigger position so the action
295
- // (insert block, run command, etc.) operates from a clean cursor.
296
- this.$.selection.setRange(anchorNode, this.#lastTriggerPos, anchorNode, this.#anchorOffset);
297
- const range = this.$.selection.getRange();
298
- if (range && !range.collapsed) this.$.html.remove();
333
+ const query = (anchorNode.textContent || '').substring(
334
+ this.#lastTriggerPos + triggerChar.length,
335
+ this.#anchorOffset,
336
+ );
299
337
 
300
- this.#closeMenu();
338
+ if (item.kind !== 'dropdownFree') {
339
+ this.#removeTrigger();
340
+ this.#closeMenu();
341
+ this.#menu.dispatch(item, { triggerChar, query, item: item.raw });
342
+ return;
343
+ }
301
344
 
345
+ // `dispatch` toggles, so picking the row whose flyout is already up (hovered, then picked) closes
346
+ // it and keeps the menu — as BlockHandle does. Only a flyout that never opened leaves nothing to show.
347
+ const hadSubPanel = this.#menu.hasOpenSubPanel();
302
348
  this.#menu.dispatch(item, { triggerChar, query, item: item.raw });
349
+ if (!hadSubPanel && !this.#menu.hasOpenSubPanel()) this.#closeMenu();
303
350
  }
304
351
  }
305
352
 
@@ -12,9 +12,8 @@ declare class BlockHandle {
12
12
  * @param {HTMLElement} blockHandle - Handle group (.se-block-handle)
13
13
  * @param {HTMLElement} blockHandlePlus - Plus button
14
14
  * @param {HTMLElement} blockHandleDrag - Drag button
15
- * @param {Array<string | { title: string, icon?: string, action: function(SunEditor.Deps, { block: HTMLElement }): void }>|null} menuConfig
16
- * Menu entries. Strings resolve via `ResolveButton` (plugin names, built-in commands). Objects
17
- * define a custom row whose `action` is invoked with the Deps bag and the current block element.
15
+ * @param {Object|Array<*>|null} blockHandleOptions - The `blockHandle` option object (`{ menu, onPlusClick, maxHeight, minWidth }`).
16
+ * - An array is accepted as a shorthand for `{ menu: [...] }`.
18
17
  */
19
18
  constructor(
20
19
  $: SunEditor.Deps,
@@ -22,19 +21,7 @@ declare class BlockHandle {
22
21
  blockHandle: HTMLElement,
23
22
  blockHandlePlus: HTMLElement,
24
23
  blockHandleDrag: HTMLElement,
25
- menuConfig: Array<
26
- | string
27
- | {
28
- title: string;
29
- icon?: string;
30
- action: (
31
- arg0: SunEditor.Deps,
32
- arg1: {
33
- block: HTMLElement;
34
- },
35
- ) => void;
36
- }
37
- > | null,
24
+ blockHandleOptions: any | Array<any> | null,
38
25
  );
39
26
  /**
40
27
  * @description Position the block handle for the given mouse target. Uses rAF throttle.
@@ -15,11 +15,6 @@ declare class UIManager {
15
15
  toastPopup: HTMLElement;
16
16
  toastContainer: Element;
17
17
  toastMessage: HTMLSpanElement;
18
- /**
19
- * @description Whether `SelectMenu` is open
20
- * @type {boolean}
21
- */
22
- selectMenuOn: boolean;
23
18
  /**
24
19
  * @description Currently open `Controller` info array
25
20
  * @type {Array<SunEditor.Module.Controller.Info>}
@@ -36,6 +31,20 @@ declare class UIManager {
36
31
  * @type {?HTMLElement}
37
32
  */
38
33
  _figureContainer: HTMLElement | null;
34
+ /**
35
+ * @description Whether any `SelectMenu` is currently open.
36
+ * - Read-only: a menu announces itself through {@link setSelectMenuOpen}. Derived from the set of
37
+ * open instances so an unrelated menu closing cannot clear the flag for a menu that is still open.
38
+ * @returns {boolean}
39
+ */
40
+ get selectMenuOn(): boolean;
41
+ /**
42
+ * @internal
43
+ * @description `SelectMenu` open-state notification. Called by `SelectMenu.open()` / `.close()`.
44
+ * @param {*} instance The `SelectMenu` instance changing state
45
+ * @param {boolean} open `true` on open, `false` on close
46
+ */
47
+ setSelectMenuOpen(instance: any, open: boolean): void;
39
48
  /**
40
49
  * @description Set editor frame styles.
41
50
  * - Define the style of the edit area
@@ -270,9 +270,25 @@ export namespace DEFAULTS {
270
270
  * menu: [
271
271
  * 'p', 'heading', 'blockStyle',
272
272
  * { title: 'Duplicate', icon: 'copy', action: ($, { block }) => block.after(block.cloneNode(true)) },
273
+ * // `'table'` as a string opens the size picker; a custom item inserts a default table directly
274
+ * { title: 'Table', icon: 'table', action: ($) => $.plugins.table.insert(3, 3) },
273
275
  * ],
274
276
  * }
275
277
  * ```
278
+ * @property {string} [blockHandle.maxHeight=""] - Max height of the menu list. Any CSS length; the list scrolls past it.
279
+ * - Unset by default: the menu grows with its items and is only clamped when it would overflow the viewport.
280
+ * @property {string} [blockHandle.minWidth="200px"] - Min width of the menu.
281
+ * @property {function(SunEditor.Deps, { block: HTMLElement, openMenu: function(): void }): void} [blockHandle.onPlusClick] - Runs after the plus button inserted a new line.
282
+ * - Adding the line is fixed behavior; this hook decides what happens next. Nothing does by default.
283
+ * - `block` is the new line, already focused. `openMenu()` opens the block handle's own `menu`.
284
+ * ```js
285
+ * blockHandle: {
286
+ * // open the block handle menu
287
+ * onPlusClick: ($, { openMenu }) => openMenu(),
288
+ * // ...or the slash command menu
289
+ * onPlusClick: ($, { block }) => $.plugins.slashCommand.open(block),
290
+ * }
291
+ * ```
276
292
  * @property {string} [type=""] - Editor type. Use `"document"` for a document-style layout, with optional sub-types after `:`.
277
293
  * ```js
278
294
  * // type
@@ -1056,6 +1072,15 @@ export type EditorBaseOptions = {
1056
1072
  ) => void;
1057
1073
  }
1058
1074
  >;
1075
+ maxHeight?: string;
1076
+ minWidth?: string;
1077
+ onPlusClick?: (
1078
+ arg0: SunEditor.Deps,
1079
+ arg1: {
1080
+ block: HTMLElement;
1081
+ openMenu: () => void;
1082
+ },
1083
+ ) => void;
1059
1084
  };
1060
1085
  /**
1061
1086
  * - Editor type. Use `"document"` for a document-style layout, with optional sub-types after `:`.
@@ -111,6 +111,13 @@ export type CommandMenuParams = {
111
111
  icons: any;
112
112
  },
113
113
  ) => string;
114
+ /**
115
+ * - Optional owner hook run once,
116
+ * - immediately before the user commits inside a dropdown-free flyout (SlashCommand uses it to delete the typed `/query`).
117
+ * - A native submenu gets this for free — its commit routes back through `SelectMenu`'s select callback —
118
+ * - but a flyout is the plugin's own DOM, so the moment has to be intercepted.
119
+ */
120
+ prepareCommit?: () => void;
114
121
  };
115
122
  /**
116
123
  * @typedef {Object} CommandMenuItem
@@ -148,6 +155,10 @@ export type CommandMenuParams = {
148
155
  * @property {Object} selectMenuParams - Base SelectMenu params (`position`, `minWidth`, `keydownTarget`, etc.).
149
156
  * @property {function(CommandMenuItem, { icons: Object }): string} [renderCustomItem] - Optional renderer
150
157
  * applied to custom (object) items only. Plugin-string items always render with `buildRowHTML`.
158
+ * @property {function(): void} [prepareCommit] - Optional owner hook run once,
159
+ * - immediately before the user commits inside a dropdown-free flyout (SlashCommand uses it to delete the typed `/query`).
160
+ * - A native submenu gets this for free — its commit routes back through `SelectMenu`'s select callback —
161
+ * - but a flyout is the plugin's own DOM, so the moment has to be intercepted.
151
162
  */
152
163
  /**
153
164
  * @class
@@ -31,11 +31,15 @@ export type SelectMenuParams = {
31
31
  */
32
32
  closeMethod?: () => void;
33
33
  /**
34
- * Optional owner hook invoked on ESC before the menu closes.
35
- * Return `true` if it dismissed an owner-managed sub-panel (e.g. CommandMenu's flyout), so ESC only
36
- * closes that sub-panel and keeps the menu open.
34
+ * Optional owner hook that dismisses an owner-managed sub-panel (e.g. CommandMenu's dropdown-free flyout) and puts the cursor back on its row.
35
+ * Return `true` when a sub-panel was actually dismissed.
37
36
  */
38
37
  subEscMethod?: () => boolean;
38
+ /**
39
+ * Optional owner hook answering "does the row at `index` own a sub-panel?".
40
+ * - A query only — it must not open anything.
41
+ */
42
+ subCheckMethod?: (index: number) => boolean;
39
43
  /**
40
44
  * Optional max-height CSS value (e.g. `"200px"`). Enables scrolling when items exceed this height.
41
45
  */
@@ -66,9 +70,10 @@ export type SelectMenuParams = {
66
70
  * @property {number} [splitNum=0] Optional split number for horizontal positioning; defines how many items per row
67
71
  * @property {() => void} [openMethod] Optional method to call when the menu is opened
68
72
  * @property {() => void} [closeMethod] Optional method to call when the menu is closed
69
- * @property {() => boolean} [subEscMethod] Optional owner hook invoked on ESC before the menu closes.
70
- * Return `true` if it dismissed an owner-managed sub-panel (e.g. CommandMenu's flyout), so ESC only
71
- * closes that sub-panel and keeps the menu open.
73
+ * @property {() => boolean} [subEscMethod] Optional owner hook that dismisses an owner-managed sub-panel (e.g. CommandMenu's dropdown-free flyout) and puts the cursor back on its row.
74
+ * Return `true` when a sub-panel was actually dismissed.
75
+ * @property {(index: number) => boolean} [subCheckMethod] Optional owner hook answering "does the row at `index` own a sub-panel?".
76
+ * - A query only — it must not open anything.
72
77
  * @property {string} [maxHeight] Optional max-height CSS value (e.g. `"200px"`). Enables scrolling when items exceed this height.
73
78
  * @property {string} [minWidth] Optional min-width CSS value (e.g. `"130px"`).
74
79
  * @property {*} [keydownTarget] Optional override for the keyboard navigation target. By default `on()` listens
@@ -104,6 +109,7 @@ declare class SelectMenu {
104
109
  openMethod: () => void;
105
110
  closeMethod: () => void;
106
111
  subEscMethod: () => boolean;
112
+ subCheckMethod: (index: number) => boolean;
107
113
  maxHeight: string;
108
114
  minWidth: string;
109
115
  /**
@@ -193,6 +199,6 @@ declare class SelectMenu {
193
199
  * @returns {boolean}
194
200
  */
195
201
  hasOpenSubmenu(): boolean;
196
- _onItem: Element;
202
+ _onItem: any;
197
203
  #private;
198
204
  }
@@ -153,6 +153,17 @@ declare class Table extends PluginDropdownFree {
153
153
  * @description Closes table-related controllers and table figure
154
154
  */
155
155
  _closeTableSelectInfo(): void;
156
+ /**
157
+ * @description Insert a table of the given size at the caret and place the caret in its first cell.
158
+ * @param {number} [cols=3] - Column count
159
+ * @param {number} [rows=3] - Row count
160
+ * @returns {boolean} `true` when the table was inserted
161
+ * @example
162
+ * // insert a 3x3 table without going through the size picker
163
+ * editor.plugins.table.insert();
164
+ * editor.plugins.table.insert(4, 2);
165
+ */
166
+ insert(cols?: number, rows?: number): boolean;
156
167
  #private;
157
168
  }
158
169
  import { PluginDropdownFree } from '../../../interfaces';
@@ -2,6 +2,7 @@ import type {} from '../../../../typedef';
2
2
  export const ROW_SELECT_MARGIN: 6;
3
3
  export const CELL_SELECT_MARGIN: 6;
4
4
  export const CELL_DECIMAL_END: 0;
5
+ export const DEFAULT_SIZE: number[];
5
6
  export const RESIZE_CELL_CLASS: '.se-table-resize-line';
6
7
  export const RESIZE_CELL_PREV_CLASS: '.se-table-resize-line-prev';
7
8
  export const RESIZE_ROW_CLASS: '.se-table-resize-row';