suneditor 3.0.2 → 3.0.4

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.
@@ -37,6 +37,8 @@ import type {} from '../../typedef';
37
37
  * @property {HTMLElement} navigation - Navigation element (e.g., for outline or bookmarks).
38
38
  * @property {HTMLElement} charWrapper - Wrapper for the character counter element.
39
39
  * @property {HTMLElement} charCounter - Element showing the character counter.
40
+ * @property {HTMLElement} wordWrapper - Wrapper for the word counter element.
41
+ * @property {HTMLElement} wordCounter - Element showing the word counter.
40
42
  * @property {Window} [_ww] - The window object of the WYSIWYG frame (iframe window).
41
43
  * @property {Document} [_wd] - The document object of the WYSIWYG frame (iframe document).
42
44
  *
@@ -215,6 +217,14 @@ export type FrameContextStore = {
215
217
  * - Element showing the character counter.
216
218
  */
217
219
  charCounter: HTMLElement;
220
+ /**
221
+ * - Wrapper for the word counter element.
222
+ */
223
+ wordWrapper: HTMLElement;
224
+ /**
225
+ * - Element showing the word counter.
226
+ */
227
+ wordCounter: HTMLElement;
218
228
  /**
219
229
  * - The window object of the WYSIWYG frame (iframe window).
220
230
  */
@@ -105,6 +105,13 @@ export namespace DEFAULTS {
105
105
  * - `char`: Characters length.
106
106
  * - `byte`: Binary data size of characters.
107
107
  * - `byte-html`: Binary data size of the full HTML string.
108
+ *
109
+ * === Word Counter ===
110
+ * @property {boolean} [wordCounter=false] - Shows the number of words in the editor.
111
+ * @property {?string} [wordCounter_label=null] - Text to be displayed in the `wordCounter` area of the bottom bar.
112
+ * ```js
113
+ * { wordCounter_label: 'Words :' }
114
+ * ```
108
115
  */
109
116
  /** ================================================================================================================================ */
110
117
  /**
@@ -406,7 +413,22 @@ export namespace DEFAULTS {
406
413
  * @property {boolean} [tabDisable=false] - Disables tab key input.
407
414
  * @property {string} [toolbar_width="auto"] - Toolbar width.
408
415
  * @property {?HTMLElement} [toolbar_container] - Container element for the toolbar.
409
- * @property {number} [toolbar_sticky=0] - Enables sticky toolbar with optional offset.
416
+ * @property {number|{top: number, offset: number}} [toolbar_sticky=0] - Enables sticky toolbar.
417
+ * - `number`: Sets the sticky top position (px). Use `-1` to disable sticky.
418
+ * - `{top, offset}`: `top` is the sticky position when the page header is visible.
419
+ * - `offset` is the sticky position when a virtual keyboard shifts the viewport (e.g., on tablets, touch devices).
420
+ * - When the virtual keyboard is active, `offset` replaces `top` so the toolbar doesn't leave a gap
421
+ * - for a page header that has scrolled out of view. Default `offset` is `0`.
422
+ * ```js
423
+ * // Basic usage — sticky at top with 0px offset
424
+ * toolbar_sticky: 0
425
+ *
426
+ * // Account for a 92px fixed/sticky site header
427
+ * toolbar_sticky: 92
428
+ *
429
+ * // 92px header on desktop, but 0px when virtual keyboard pushes the viewport
430
+ * toolbar_sticky: { top: 92, offset: 0 }
431
+ * ```
410
432
  * @property {boolean} [toolbar_hide=false] - Hides toolbar initially.
411
433
  * @property {Object} [subToolbar={}] - Sub-toolbar configuration. A secondary toolbar that appears on text selection.
412
434
  * @property {SunEditor.UI.ButtonList} [subToolbar.buttonList] - List of Sub-toolbar buttons, grouped by sub-arrays.
@@ -714,8 +736,21 @@ export type EditorFrameOptions = {
714
736
  * - `char`: Characters length.
715
737
  * - `byte`: Binary data size of characters.
716
738
  * - `byte-html`: Binary data size of the full HTML string.
739
+ *
740
+ * === Word Counter ===
717
741
  */
718
742
  charCounter_type?: 'char' | 'byte' | 'byte-html';
743
+ /**
744
+ * - Shows the number of words in the editor.
745
+ */
746
+ wordCounter?: boolean;
747
+ /**
748
+ * - Text to be displayed in the `wordCounter` area of the bottom bar.
749
+ * ```js
750
+ * { wordCounter_label: 'Words :' }
751
+ * ```
752
+ */
753
+ wordCounter_label?: string | null;
719
754
  };
720
755
  export type OptionStyleResult = {
721
756
  /**
@@ -1201,9 +1236,29 @@ export type EditorBaseOptions = {
1201
1236
  */
1202
1237
  toolbar_container?: HTMLElement | null;
1203
1238
  /**
1204
- * - Enables sticky toolbar with optional offset.
1239
+ * - Enables sticky toolbar.
1240
+ * - `number`: Sets the sticky top position (px). Use `-1` to disable sticky.
1241
+ * - `{top, offset}`: `top` is the sticky position when the page header is visible.
1242
+ * - `offset` is the sticky position when a virtual keyboard shifts the viewport (e.g., on tablets, touch devices).
1243
+ * - When the virtual keyboard is active, `offset` replaces `top` so the toolbar doesn't leave a gap
1244
+ * - for a page header that has scrolled out of view. Default `offset` is `0`.
1245
+ * ```js
1246
+ * // Basic usage — sticky at top with 0px offset
1247
+ * toolbar_sticky: 0
1248
+ *
1249
+ * // Account for a 92px fixed/sticky site header
1250
+ * toolbar_sticky: 92
1251
+ *
1252
+ * // 92px header on desktop, but 0px when virtual keyboard pushes the viewport
1253
+ * toolbar_sticky: { top: 92, offset: 0 }
1254
+ * ```
1205
1255
  */
1206
- toolbar_sticky?: number;
1256
+ toolbar_sticky?:
1257
+ | number
1258
+ | {
1259
+ top: number;
1260
+ offset: number;
1261
+ };
1207
1262
  /**
1208
1263
  * - Hides toolbar initially.
1209
1264
  */
@@ -1513,7 +1568,18 @@ export type InternalBaseOptions = {
1513
1568
  };
1514
1569
  export type EditorInitOptions = EditorBaseOptions & PrivateBaseOptions & EditorFrameOptions;
1515
1570
  export type AllBaseOptions = EditorBaseOptions & PrivateBaseOptions & InternalBaseOptions;
1516
- export type TransformedOptionKeys = 'formatClosureBrLine' | 'formatBrLine' | 'formatLine' | 'formatClosureBlock' | 'formatBlock' | 'toolbar_width' | 'toolbar_container' | 'toolbar_sticky' | 'strictMode' | 'lineAttrReset';
1571
+ export type TransformedOptionKeys =
1572
+ | 'formatClosureBrLine'
1573
+ | 'formatBrLine'
1574
+ | 'formatLine'
1575
+ | 'formatClosureBlock'
1576
+ | 'formatBlock'
1577
+ | 'toolbar_width'
1578
+ | 'toolbar_container'
1579
+ | '_toolbar_sticky'
1580
+ | '_toolbar_sticky_offset'
1581
+ | 'strictMode'
1582
+ | 'lineAttrReset';
1517
1583
  export type StrictModeOptions = {
1518
1584
  /**
1519
1585
  * - Filters disallowed HTML tags (`elementWhitelist`/`elementBlacklist`)
@@ -1563,7 +1629,8 @@ export type TransformedOptions = {
1563
1629
  };
1564
1630
  toolbar_width: string;
1565
1631
  toolbar_container: HTMLElement | null;
1566
- toolbar_sticky: number;
1632
+ _toolbar_sticky: number;
1633
+ _toolbar_sticky_offset: number;
1567
1634
  strictMode: StrictModeOptions;
1568
1635
  lineAttrReset: string[];
1569
1636
  };
@@ -42,7 +42,7 @@ export function InitOptions(
42
42
  * @description Create a context object for the editor frame.
43
43
  * @param {SunEditor.FrameOptions} targetOptions - `editor.frameOptions`
44
44
  * @param {HTMLElement} statusbar - statusbar element
45
- * @returns {{statusbar: HTMLElement, navigation: HTMLElement, charWrapper: HTMLElement, charCounter: HTMLElement}}
45
+ * @returns {{statusbar: HTMLElement, navigation: HTMLElement, charWrapper: HTMLElement, charCounter: HTMLElement, wordWrapper: HTMLElement, wordCounter: HTMLElement}}
46
46
  */
47
47
  export function CreateStatusbar(
48
48
  targetOptions: SunEditor.FrameOptions,
@@ -52,6 +52,8 @@ export function CreateStatusbar(
52
52
  navigation: HTMLElement;
53
53
  charWrapper: HTMLElement;
54
54
  charCounter: HTMLElement;
55
+ wordWrapper: HTMLElement;
56
+ wordCounter: HTMLElement;
55
57
  };
56
58
  /**
57
59
  * @description Update a button state, attributes, and icons