suneditor 3.1.3 → 3.1.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.
@@ -25,6 +25,8 @@ export namespace DEFAULTS {
25
25
  };
26
26
  let CONTENT_STYLES: string;
27
27
  let TAG_STYLES: {
28
+ '@text': string;
29
+ '@line': string;
28
30
  'table|th|td': string;
29
31
  'table|td': string;
30
32
  tr: string;
@@ -36,8 +38,6 @@ export namespace DEFAULTS {
36
38
  'img|video|iframe': string;
37
39
  hr: string;
38
40
  };
39
- let SPAN_STYLES: string;
40
- let LINE_STYLES: string;
41
41
  let RETAIN_STYLE_MODE: string[];
42
42
  }
43
43
  /**
@@ -263,7 +263,7 @@ export namespace DEFAULTS {
263
263
  * - `classFilter`: Filters disallowed CSS class names (`allowedClassName`)
264
264
  * - `textStyleTagFilter`: Filters text style tags (b, i, u, span, etc.)
265
265
  * - `attrFilter`: Filters disallowed HTML attributes (`attributeWhitelist`/`attributeBlacklist`)
266
- * - `styleFilter`: Filters disallowed inline styles (`spanStyles`/`lineStyles`/`allUsedStyles`)
266
+ * - `styleFilter`: Filters disallowed inline styles (per-tag from `tagStyles`)
267
267
  * ```js
268
268
  * // disable only attribute and style filters
269
269
  * {
@@ -339,19 +339,23 @@ export namespace DEFAULTS {
339
339
  * ```js
340
340
  * { allUsedStyles: 'color|background-color|text-shadow' }
341
341
  * ```
342
- * @property {Object<string, string>} [tagStyles={}] - Specifies allowed styles for HTML tags. Key is tag name(s), value is pipe-delimited allowed styles.
342
+ * @property {Object<string, string>} [tagStyles={}] - Specifies allowed CSS styles per HTML tag.
343
+ * - Key is a tag name, multiple tags joined with `|`, or a category sentinel (`@text`, `@line`).
344
+ * - Value is a pipe-delimited list of allowed style names.
345
+ * - Resolution order when filtering an element: explicit tag entry → `@line` (for formatLine elements) → `@text` (for textStyleTags).
346
+ * - An explicit tag entry **replaces** the category default — include category styles in the value if you want both.
347
+ * - Merged with {@link DEFAULTS.TAG_STYLES}; user-supplied keys win.
343
348
  * ```js
344
349
  * {
345
350
  * tagStyles: {
346
- * 'table|td': 'border|color|background-color',
347
- * hr: 'border-top'
351
+ * '@text': 'color|font-size|background-color', // default for span, b, i, em, ...
352
+ * '@line': 'text-align|margin|line-height', // default for p, h1-h6, div, li, ...
353
+ * 'table|td': 'border|color|background-color', // per-tag whitelist
354
+ * div: 'color', // explicit override; ignores `@line` default
355
+ * hr: 'border-top',
348
356
  * }
349
357
  * }
350
358
  * ```
351
- * @property {string} [spanStyles=CONSTANTS.SPAN_STYLES] - Specifies allowed styles for the `span` tag.
352
- * - The default follows {@link DEFAULTS.SPAN_STYLES}
353
- * @property {string} [lineStyles=CONSTANTS.LINE_STYLES] - Specifies allowed styles for the `line` element (p..).
354
- * - The default follows {@link DEFAULTS.LINE_STYLES}
355
359
  * @property {Array<string>} [fontSizeUnits=CONSTANTS.SIZE_UNITS] - Allowed font size units.
356
360
  * - The default follows {@link DEFAULTS.SIZE_UNITS}
357
361
  * @property {"repeat"|"always"|"none"} [retainStyleMode="repeat"] - Determines how inline elements (e.g. `<span>`, `<strong>`) are handled when deleting text.
@@ -570,8 +574,6 @@ export namespace DEFAULTS {
570
574
  * @property {string[]} [_reverseCommandArray] - Internal key shortcut matcher for reverse commands.
571
575
  * @property {string} [_subMode] - Sub toolbar mode (e.g., `balloon`).
572
576
  * @property {string[]} [_textStyleTags] - Tag names used for text styling, plus span/li.
573
- * @property {RegExp} [_textStylesRegExp] - Regex to match inline styles (e.g., fontSize, color).
574
- * @property {RegExp} [_lineStylesRegExp] - Regex to match line styles (e.g., text-align, padding).
575
577
  * @property {Object<string, string>} [_defaultStyleTagMap] - Mapping HTML tag => standard tag.
576
578
  * @property {Object<string, string>} [_styleCommandMap] - Mapping HTML tag => command (e.g., bold, underline).
577
579
  * @property {Object<string, string>} [_defaultTagCommand] - Mapping command => preferred tag.
@@ -985,7 +987,7 @@ export type EditorBaseOptions = {
985
987
  * - `classFilter`: Filters disallowed CSS class names (`allowedClassName`)
986
988
  * - `textStyleTagFilter`: Filters text style tags (b, i, u, span, etc.)
987
989
  * - `attrFilter`: Filters disallowed HTML attributes (`attributeWhitelist`/`attributeBlacklist`)
988
- * - `styleFilter`: Filters disallowed inline styles (`spanStyles`/`lineStyles`/`allUsedStyles`)
990
+ * - `styleFilter`: Filters disallowed inline styles (per-tag from `tagStyles`)
989
991
  * ```js
990
992
  * // disable only attribute and style filters
991
993
  * {
@@ -1106,12 +1108,20 @@ export type EditorBaseOptions = {
1106
1108
  */
1107
1109
  allUsedStyles?: string;
1108
1110
  /**
1109
- * - Specifies allowed styles for HTML tags. Key is tag name(s), value is pipe-delimited allowed styles.
1111
+ * - Specifies allowed CSS styles per HTML tag.
1112
+ * - Key is a tag name, multiple tags joined with `|`, or a category sentinel (`@text`, `@line`).
1113
+ * - Value is a pipe-delimited list of allowed style names.
1114
+ * - Resolution order when filtering an element: explicit tag entry → `@line` (for formatLine elements) → `@text` (for textStyleTags).
1115
+ * - An explicit tag entry **replaces** the category default — include category styles in the value if you want both.
1116
+ * - Merged with {@link DEFAULTS.TAG_STYLES}; user-supplied keys win.
1110
1117
  * ```js
1111
1118
  * {
1112
1119
  * tagStyles: {
1113
- * 'table|td': 'border|color|background-color',
1114
- * hr: 'border-top'
1120
+ * '@text': 'color|font-size|background-color', // default for span, b, i, em, ...
1121
+ * '@line': 'text-align|margin|line-height', // default for p, h1-h6, div, li, ...
1122
+ * 'table|td': 'border|color|background-color', // per-tag whitelist
1123
+ * div: 'color', // explicit override; ignores `@line` default
1124
+ * hr: 'border-top',
1115
1125
  * }
1116
1126
  * }
1117
1127
  * ```
@@ -1119,16 +1129,6 @@ export type EditorBaseOptions = {
1119
1129
  tagStyles?: {
1120
1130
  [x: string]: string;
1121
1131
  };
1122
- /**
1123
- * - Specifies allowed styles for the `span` tag.
1124
- * - The default follows {@link DEFAULTS.SPAN_STYLES}
1125
- */
1126
- spanStyles?: string;
1127
- /**
1128
- * - Specifies allowed styles for the `line` element (p..).
1129
- * - The default follows {@link DEFAULTS.LINE_STYLES}
1130
- */
1131
- lineStyles?: string;
1132
1132
  /**
1133
1133
  * - Allowed font size units.
1134
1134
  * - The default follows {@link DEFAULTS.SIZE_UNITS}
@@ -1501,14 +1501,6 @@ export type InternalBaseOptions = {
1501
1501
  * - Tag names used for text styling, plus span/li.
1502
1502
  */
1503
1503
  _textStyleTags?: string[];
1504
- /**
1505
- * - Regex to match inline styles (e.g., fontSize, color).
1506
- */
1507
- _textStylesRegExp?: RegExp;
1508
- /**
1509
- * - Regex to match line styles (e.g., text-align, padding).
1510
- */
1511
- _lineStylesRegExp?: RegExp;
1512
1504
  /**
1513
1505
  * - Mapping HTML tag => standard tag.
1514
1506
  */
@@ -1602,7 +1594,7 @@ export type StrictModeOptions = {
1602
1594
  */
1603
1595
  attrFilter: boolean;
1604
1596
  /**
1605
- * - Filters disallowed inline styles (`spanStyles`/`lineStyles`/`allUsedStyles`)
1597
+ * - Filters disallowed inline styles (per-tag from `tagStyles`)
1606
1598
  */
1607
1599
  styleFilter: boolean;
1608
1600
  };
@@ -102,7 +102,7 @@ export type BrowserParams = {
102
102
  /**
103
103
  * - File server search http header. Optional. Can be overridden in browser.
104
104
  */
105
- searchUrlHeader?: {
105
+ searchHeaders?: {
106
106
  [x: string]: string;
107
107
  };
108
108
  /**
@@ -172,7 +172,7 @@ export type BrowserParams = {
172
172
  * ]
173
173
  * }
174
174
  * ```
175
- * @property {Object<string, string>} [searchUrlHeader] - File server search http header. Optional. Can be overridden in browser.
175
+ * @property {Object<string, string>} [searchHeaders] - File server search http header. Optional. Can be overridden in browser.
176
176
  * @property {string} [listClass] - Class name of list div. Required. Can be overridden in browser.
177
177
  * @property {(item: BrowserFile) => string} [drawItemHandler] - Function that returns HTML string for rendering each file item. Required. Can be overridden in browser.
178
178
  * ```js
@@ -227,11 +227,11 @@ declare class Browser {
227
227
  [x: string]: any;
228
228
  };
229
229
  url: string;
230
- urlHeader: {
230
+ headers: {
231
231
  [x: string]: string;
232
232
  };
233
233
  searchUrl: string;
234
- searchUrlHeader: {
234
+ searchHeaders: {
235
235
  [x: string]: string;
236
236
  };
237
237
  drawItemHandler: any;
@@ -276,7 +276,7 @@ declare class Browser {
276
276
  * @param {string} [params.listClass] - Class name of list div. If not, use `this.listClass`.
277
277
  * @param {string} [params.title] - File browser window title. If not, use `this.title`.
278
278
  * @param {string} [params.url] - File server url. If not, use `this.url`.
279
- * @param {Object<string, string>} [params.urlHeader] - File server http header. If not, use `this.urlHeader`.
279
+ * @param {Object<string, string>} [params.headers] - File server http header. If not, use `this.headers`.
280
280
  * @example
281
281
  * // Open with default settings (configured at construction):
282
282
  * this.browser.open();
@@ -285,14 +285,14 @@ declare class Browser {
285
285
  * this.browser.open({
286
286
  * title: 'Select a video',
287
287
  * url: '/api/videos',
288
- * urlHeader: { Authorization: 'Bearer token' },
288
+ * headers: { Authorization: 'Bearer token' },
289
289
  * });
290
290
  */
291
291
  open(params?: {
292
292
  listClass?: string;
293
293
  title?: string;
294
294
  url?: string;
295
- urlHeader?: {
295
+ headers?: {
296
296
  [x: string]: string;
297
297
  };
298
298
  }): void;
@@ -196,6 +196,8 @@ declare class ModalAnchorEditor {
196
196
  /**
197
197
  * @description Creates an anchor (`<a>`) element with the specified attributes.
198
198
  * @param {boolean} notText - If `true`, the anchor will not contain text content.
199
+ * @param {?string} [urlOverride] - Fallback URL used when the modal's `linkValue` is empty
200
+ * - (e.g., when called outside the modal lifecycle such as from `retainFormat`)
199
201
  * @returns {HTMLElement|null} - The newly created anchor element, or `null` if the URL is empty.
200
202
  * @example
201
203
  * // In a link plugin — create anchor with text content:
@@ -208,8 +210,11 @@ declare class ModalAnchorEditor {
208
210
  * if (anchor) {
209
211
  * anchor.appendChild(imgElement);
210
212
  * }
213
+ *
214
+ * // Preserve an existing parent anchor's href when rebuilding outside the modal:
215
+ * const anchor = this.anchor.create(true, parentAnchor.href);
211
216
  */
212
- create(notText: boolean): HTMLElement | null;
217
+ create(notText: boolean, urlOverride?: string | null): HTMLElement | null;
213
218
  /**
214
219
  * @description Resets the ModalAnchorEditor to its initial state.
215
220
  */
@@ -28,6 +28,18 @@ export type AudioGalleryPluginOptions = {
28
28
  headers?: {
29
29
  [x: string]: string;
30
30
  };
31
+ /**
32
+ * - Server-side search URL. When set, the keyword is sent to this URL
33
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
34
+ * already-loaded items locally.
35
+ */
36
+ searchUrl?: string;
37
+ /**
38
+ * - Server-side search request headers
39
+ */
40
+ searchHeaders?: {
41
+ [x: string]: string;
42
+ };
31
43
  /**
32
44
  * - Default thumbnail
33
45
  */
@@ -51,6 +63,10 @@ export type AudioGalleryPluginOptions = {
51
63
  * }
52
64
  * ```
53
65
  * @property {Object<string, string>} [headers] - Server request headers
66
+ * @property {string} [searchUrl] - Server-side search URL. When set, the keyword is sent to this URL
67
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
68
+ * already-loaded items locally.
69
+ * @property {Object<string, string>} [searchHeaders] - Server-side search request headers
54
70
  * @property {string|((item: SunEditor.Module.Browser.File) => string)} [thumbnail] - Default thumbnail
55
71
  */
56
72
  /**
@@ -39,6 +39,18 @@ export type FileBrowserPluginOptions = {
39
39
  headers?: {
40
40
  [x: string]: string;
41
41
  };
42
+ /**
43
+ * - Server-side search URL. When set, the keyword is sent to this URL
44
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
45
+ * already-loaded items locally.
46
+ */
47
+ searchUrl?: string;
48
+ /**
49
+ * - Server-side search request headers
50
+ */
51
+ searchHeaders?: {
52
+ [x: string]: string;
53
+ };
42
54
  /**
43
55
  * - Default thumbnail URL or a function that returns a thumbnail URL per item.
44
56
  */
@@ -80,6 +92,10 @@ export type FileBrowserPluginOptions = {
80
92
  * }
81
93
  * ```
82
94
  * @property {Object<string, string>} [headers] - Server request headers
95
+ * @property {string} [searchUrl] - Server-side search URL. When set, the keyword is sent to this URL
96
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
97
+ * already-loaded items locally.
98
+ * @property {Object<string, string>} [searchHeaders] - Server-side search request headers
83
99
  * @property {string|((item: SunEditor.Module.Browser.File) => string)} [thumbnail] - Default thumbnail URL or a function that returns a thumbnail URL per item.
84
100
  * @property {number} [expand=1] - Initial folder expand depth. `1` expands the first level, `Infinity` expands all. Default: `1`.
85
101
  * @property {Array<string>} [props] - Additional tag names
@@ -29,6 +29,18 @@ export type FileGalleryPluginOptions = {
29
29
  headers?: {
30
30
  [x: string]: string;
31
31
  };
32
+ /**
33
+ * - Server-side search URL. When set, the keyword is sent to this URL
34
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
35
+ * already-loaded items locally.
36
+ */
37
+ searchUrl?: string;
38
+ /**
39
+ * - Server-side search request headers
40
+ */
41
+ searchHeaders?: {
42
+ [x: string]: string;
43
+ };
32
44
  /**
33
45
  * - Default thumbnail
34
46
  */
@@ -53,6 +65,10 @@ export type FileGalleryPluginOptions = {
53
65
  * }
54
66
  * ```
55
67
  * @property {Object<string, string>} [headers] - Server request headers
68
+ * @property {string} [searchUrl] - Server-side search URL. When set, the keyword is sent to this URL
69
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
70
+ * already-loaded items locally.
71
+ * @property {Object<string, string>} [searchHeaders] - Server-side search request headers
56
72
  * @property {string|((item: SunEditor.Module.Browser.File) => string)} [thumbnail] - Default thumbnail
57
73
  */
58
74
  /**
@@ -29,6 +29,18 @@ export type ImageGalleryPluginOptions = {
29
29
  headers?: {
30
30
  [x: string]: string;
31
31
  };
32
+ /**
33
+ * - Server-side search URL. When set, the keyword is sent to this URL
34
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
35
+ * already-loaded items locally.
36
+ */
37
+ searchUrl?: string;
38
+ /**
39
+ * - Server-side search request headers
40
+ */
41
+ searchHeaders?: {
42
+ [x: string]: string;
43
+ };
32
44
  };
33
45
  /**
34
46
  * @typedef ImageGalleryPluginOptions
@@ -49,6 +61,10 @@ export type ImageGalleryPluginOptions = {
49
61
  * }
50
62
  * ```
51
63
  * @property {Object<string, string>} [headers] - Server request headers
64
+ * @property {string} [searchUrl] - Server-side search URL. When set, the keyword is sent to this URL
65
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
66
+ * already-loaded items locally.
67
+ * @property {Object<string, string>} [searchHeaders] - Server-side search request headers
52
68
  */
53
69
  /**
54
70
  * @class
@@ -29,6 +29,18 @@ export type VideoGalleryPluginOptions = {
29
29
  headers?: {
30
30
  [x: string]: string;
31
31
  };
32
+ /**
33
+ * - Server-side search URL. When set, the keyword is sent to this URL
34
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
35
+ * already-loaded items locally.
36
+ */
37
+ searchUrl?: string;
38
+ /**
39
+ * - Server-side search request headers
40
+ */
41
+ searchHeaders?: {
42
+ [x: string]: string;
43
+ };
32
44
  /**
33
45
  * - Default thumbnail
34
46
  */
@@ -53,6 +65,10 @@ export type VideoGalleryPluginOptions = {
53
65
  * }
54
66
  * ```
55
67
  * @property {Object<string, string>} [headers] - Server request headers
68
+ * @property {string} [searchUrl] - Server-side search URL. When set, the keyword is sent to this URL
69
+ * as `?keyword=<value>` and the server response replaces the list. When not set, search filters the
70
+ * already-loaded items locally.
71
+ * @property {Object<string, string>} [searchHeaders] - Server-side search request headers
56
72
  * @property {string|((item: SunEditor.Module.Browser.File) => string)} [thumbnail] - Default thumbnail
57
73
  */
58
74
  /**
@@ -78,6 +78,20 @@ export type EmbedPluginOptions = {
78
78
  * - Additional URL patterns to recognize as embeddable content.
79
79
  */
80
80
  urlPatterns?: Array<RegExp>;
81
+ /**
82
+ * - Allowed `<script src=...>` patterns for raw embed HTML
83
+ * - (e.g. Twitter blockquote + `widgets.js`). Each entry is a `RegExp` (tested against the full src) or a `string` (matched via `startsWith`).
84
+ * - Defaults to `[]` — all script tags are rejected.** Inline scripts (no `src`) are always rejected.
85
+ * ```js
86
+ * {
87
+ * scriptSrcWhitelist: [
88
+ * /^https:\/\/platform\.x\.com\/widgets\.js$/,
89
+ * /^https:\/\/www\.instagram\.com\/embed\.js$/,
90
+ * ]
91
+ * }
92
+ * ```
93
+ */
94
+ scriptSrcWhitelist?: Array<RegExp | string>;
81
95
  /**
82
96
  * - Custom embed service definitions.
83
97
  * Each key is a service name, with `pattern` to match the URL, `action` to transform it into an embed URL, and `tag` for the output element.
@@ -150,6 +164,17 @@ export type EmbedPluginOptions = {
150
164
  * { query_vimeo: 'autoplay=1' }
151
165
  * ```
152
166
  * @property {Array<RegExp>} [urlPatterns] - Additional URL patterns to recognize as embeddable content.
167
+ * @property {Array<RegExp|string>} [scriptSrcWhitelist] - Allowed `<script src=...>` patterns for raw embed HTML
168
+ * - (e.g. Twitter blockquote + `widgets.js`). Each entry is a `RegExp` (tested against the full src) or a `string` (matched via `startsWith`).
169
+ * - Defaults to `[]` — all script tags are rejected.** Inline scripts (no `src`) are always rejected.
170
+ * ```js
171
+ * {
172
+ * scriptSrcWhitelist: [
173
+ * /^https:\/\/platform\.x\.com\/widgets\.js$/,
174
+ * /^https:\/\/www\.instagram\.com\/embed\.js$/,
175
+ * ]
176
+ * }
177
+ * ```
153
178
  * @property {Object<string, {pattern: RegExp, action: (url: string) => string, tag: string}>} [embedQuery] - Custom embed service definitions.
154
179
  * Each key is a service name, with `pattern` to match the URL, `action` to transform it into an embed URL, and `tag` for the output element.
155
180
  * ```js
@@ -189,6 +214,14 @@ declare class Embed extends PluginModal {
189
214
  * @returns {boolean} `true` if the URL matches a known pattern; otherwise, `false`.
190
215
  */
191
216
  static #checkContentType(url: string): boolean;
217
+ /**
218
+ * @description Validate a `<script src>` against the configured whitelist for raw embed HTML.
219
+ * Inline scripts (no `src`) are always rejected.
220
+ * @param {string} src
221
+ * @param {Array<RegExp|string>} whitelist
222
+ * @returns {boolean}
223
+ */
224
+ static #isAllowedScriptSrc(src: string, whitelist: Array<RegExp | string>): boolean;
192
225
  /** @type {Array<RegExp>} */
193
226
  static #urlPatterns: Array<RegExp>;
194
227
  /**
@@ -215,6 +248,7 @@ declare class Embed extends PluginModal {
215
248
  };
216
249
  query_youtube: string;
217
250
  query_vimeo: string;
251
+ scriptSrcWhitelist: (string | RegExp)[];
218
252
  insertBehavior: SunEditor.ComponentInsertType;
219
253
  };
220
254
  modal: Modal;