suneditor 3.1.3 → 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.
- package/dist/suneditor-contents.min.css +1 -1
- package/dist/suneditor.min.css +28 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +2 -1
- package/src/assets/design/color.css +12 -0
- package/src/assets/design/size.css +9 -2
- package/src/assets/icons/defaultIcons.js +96 -47
- package/src/assets/suneditor-contents.css +3 -2
- package/src/assets/suneditor.css +480 -31
- package/src/core/config/contextProvider.js +2 -1
- package/src/core/config/eventManager.js +41 -2
- package/src/core/config/optionProvider.js +23 -2
- package/src/core/editor.js +32 -14
- package/src/core/event/actions/index.js +76 -9
- package/src/core/event/effects/common.registry.js +2 -1
- package/src/core/event/effects/keydown.registry.js +169 -33
- package/src/core/event/effects/ruleHelpers.js +20 -6
- package/src/core/event/eventOrchestrator.js +136 -23
- package/src/core/event/handlers/handler_toolbar.js +4 -2
- package/src/core/event/handlers/handler_ww_dragDrop.js +10 -0
- package/src/core/event/handlers/handler_ww_input.js +9 -2
- package/src/core/event/handlers/handler_ww_key.js +86 -17
- package/src/core/event/handlers/handler_ww_mouse.js +45 -8
- package/src/core/event/ports.js +23 -5
- package/src/core/event/reducers/keydown.reducer.js +15 -2
- package/src/core/event/rules/keydown.rule.arrow.js +12 -2
- package/src/core/event/rules/keydown.rule.backspace.js +110 -15
- package/src/core/event/rules/keydown.rule.delete.js +62 -7
- package/src/core/event/rules/keydown.rule.enter.js +62 -31
- package/src/core/event/support/defaultLineManager.js +9 -2
- package/src/core/event/support/selectionState.js +13 -3
- package/src/core/kernel/coreKernel.js +1 -0
- package/src/core/logic/dom/char.js +13 -3
- package/src/core/logic/dom/format.js +171 -39
- package/src/core/logic/dom/html.js +357 -87
- package/src/core/logic/dom/inline.js +229 -34
- package/src/core/logic/dom/listFormat.js +111 -20
- package/src/core/logic/dom/nodeTransform.js +36 -11
- package/src/core/logic/dom/offset.js +116 -31
- package/src/core/logic/dom/selection.js +147 -29
- package/src/core/logic/panel/blockHandle.js +785 -0
- package/src/core/logic/panel/blockResolver.js +278 -0
- package/src/core/logic/panel/finder.js +16 -6
- package/src/core/logic/panel/menu.js +119 -18
- package/src/core/logic/panel/toolbar.js +75 -19
- package/src/core/logic/panel/viewer.js +76 -20
- package/src/core/logic/shell/_commandExecutor.js +44 -9
- package/src/core/logic/shell/commandDispatcher.js +46 -4
- package/src/core/logic/shell/component.js +102 -25
- package/src/core/logic/shell/focusManager.js +13 -3
- package/src/core/logic/shell/history.js +21 -6
- package/src/core/logic/shell/pluginManager.js +21 -13
- package/src/core/logic/shell/shortcuts.js +9 -1
- package/src/core/logic/shell/ui.js +139 -37
- package/src/core/schema/frameContext.js +34 -3
- package/src/core/schema/options.js +61 -19
- package/src/core/section/constructor.js +537 -103
- package/src/core/section/documentType.js +35 -6
- package/src/helper/converter.js +24 -7
- package/src/helper/dom/domCheck.js +25 -5
- package/src/helper/dom/domQuery.js +2 -1
- package/src/helper/dom/domUtils.js +17 -4
- package/src/helper/env.js +11 -2
- package/src/helper/keyCodeMap.js +6 -2
- package/src/helper/markdown.js +24 -5
- package/src/helper/msOffice.js +9 -2
- package/src/interfaces/plugins.js +1 -1
- package/src/langs/ckb.js +0 -1
- package/src/langs/cs.js +0 -1
- package/src/langs/da.js +0 -1
- package/src/langs/de.js +0 -1
- package/src/langs/en.js +0 -1
- package/src/langs/es.js +0 -1
- package/src/langs/fa.js +0 -1
- package/src/langs/fr.js +0 -1
- package/src/langs/he.js +0 -1
- package/src/langs/hu.js +0 -1
- package/src/langs/index.js +27 -1
- package/src/langs/it.js +0 -1
- package/src/langs/ja.js +0 -1
- package/src/langs/km.js +0 -1
- package/src/langs/ko.js +0 -1
- package/src/langs/lv.js +0 -1
- package/src/langs/nl.js +0 -1
- package/src/langs/pl.js +0 -1
- package/src/langs/pt_br.js +0 -1
- package/src/langs/ro.js +0 -1
- package/src/langs/ru.js +0 -1
- package/src/langs/se.js +0 -1
- package/src/langs/tr.js +0 -1
- package/src/langs/uk.js +0 -1
- package/src/langs/ur.js +0 -1
- package/src/langs/zh_cn.js +0 -1
- package/src/modules/contract/Browser.js +68 -23
- package/src/modules/contract/ColorPicker.js +12 -4
- package/src/modules/contract/Controller.js +37 -7
- package/src/modules/contract/Figure.js +159 -36
- package/src/modules/contract/HueSlider.js +27 -4
- package/src/modules/contract/Modal.js +62 -11
- package/src/modules/manager/FileManager.js +50 -8
- package/src/modules/ui/CommandMenu.js +597 -0
- package/src/modules/ui/ModalAnchorEditor.js +41 -9
- package/src/modules/ui/SelectMenu.js +481 -36
- package/src/modules/ui/index.js +1 -0
- package/src/plugins/browser/audioGallery.js +8 -1
- package/src/plugins/browser/fileBrowser.js +15 -2
- package/src/plugins/browser/fileGallery.js +8 -1
- package/src/plugins/browser/imageGallery.js +24 -3
- package/src/plugins/browser/videoGallery.js +19 -4
- package/src/plugins/command/blockquote.js +6 -1
- package/src/plugins/command/codeBlock.js +43 -5
- package/src/plugins/command/exportPDF.js +20 -4
- package/src/plugins/command/fileUpload.js +46 -11
- package/src/plugins/command/list_bulleted.js +6 -1
- package/src/plugins/command/list_numbered.js +6 -1
- package/src/plugins/dropdown/align.js +21 -33
- package/src/plugins/dropdown/backgroundColor.js +10 -2
- package/src/plugins/dropdown/blockStyle.js +17 -22
- package/src/plugins/dropdown/font.js +34 -34
- package/src/plugins/dropdown/hr.js +15 -43
- package/src/plugins/dropdown/layout.js +10 -27
- package/src/plugins/dropdown/lineHeight.js +10 -33
- package/src/plugins/dropdown/list.js +19 -25
- package/src/plugins/dropdown/paragraphStyle.js +16 -24
- package/src/plugins/dropdown/table/index.js +72 -17
- package/src/plugins/dropdown/table/render/table.html.js +3 -1
- package/src/plugins/dropdown/table/services/table.cell.js +33 -7
- package/src/plugins/dropdown/table/services/table.clipboard.js +5 -1
- package/src/plugins/dropdown/table/services/table.grid.js +40 -9
- package/src/plugins/dropdown/table/services/table.resize.js +55 -11
- package/src/plugins/dropdown/table/services/table.selection.js +27 -7
- package/src/plugins/dropdown/table/services/table.style.js +120 -20
- package/src/plugins/dropdown/template.js +13 -29
- package/src/plugins/dropdown/textStyle.js +22 -35
- package/src/plugins/field/autocomplete.js +8 -4
- package/src/plugins/field/slashCommand.js +297 -0
- package/src/plugins/index.js +3 -0
- package/src/plugins/input/fontSize.js +37 -8
- package/src/plugins/input/pageNavigator.js +7 -1
- package/src/plugins/modal/audio.js +71 -17
- package/src/plugins/modal/drawing.js +41 -11
- package/src/plugins/modal/embed.js +132 -22
- package/src/plugins/modal/image/index.js +115 -28
- package/src/plugins/modal/image/services/image.size.js +9 -2
- package/src/plugins/modal/image/services/image.upload.js +38 -4
- package/src/plugins/modal/link.js +9 -2
- package/src/plugins/modal/math.js +10 -2
- package/src/plugins/modal/video/index.js +112 -26
- package/src/plugins/modal/video/render/video.html.js +4 -1
- package/src/plugins/modal/video/services/video.size.js +15 -4
- package/src/plugins/modal/video/services/video.upload.js +10 -2
- package/src/plugins/popup/anchor.js +14 -2
- package/src/suneditor.js +8 -2
- package/src/themes/cobalt.css +12 -0
- package/src/themes/cream.css +12 -0
- package/src/themes/dark.css +12 -0
- package/src/themes/midnight.css +12 -0
- package/src/typedef.js +32 -21
- package/types/assets/icons/defaultIcons.d.ts +1 -0
- package/types/core/config/contextProvider.d.ts +7 -1
- package/types/core/config/eventManager.d.ts +37 -4
- package/types/core/config/optionProvider.d.ts +5 -1
- package/types/core/event/actions/index.d.ts +44 -6
- package/types/core/event/effects/keydown.registry.d.ts +37 -7
- package/types/core/event/effects/ruleHelpers.d.ts +6 -1
- package/types/core/event/eventOrchestrator.d.ts +6 -1
- package/types/core/event/handlers/handler_ww_clipboard.d.ts +15 -3
- package/types/core/event/handlers/handler_ww_dragDrop.d.ts +14 -2
- package/types/core/event/handlers/handler_ww_input.d.ts +10 -2
- package/types/core/event/handlers/handler_ww_key.d.ts +10 -2
- package/types/core/event/handlers/handler_ww_mouse.d.ts +25 -5
- package/types/core/event/ports.d.ts +7 -2
- package/types/core/event/rules/keydown.rule.backspace.d.ts +6 -1
- package/types/core/kernel/store.d.ts +4 -1
- package/types/core/logic/dom/format.d.ts +32 -14
- package/types/core/logic/dom/html.d.ts +11 -3
- package/types/core/logic/dom/nodeTransform.d.ts +6 -6
- package/types/core/logic/panel/blockHandle.d.ts +64 -0
- package/types/core/logic/panel/blockResolver.d.ts +50 -0
- package/types/core/logic/panel/menu.d.ts +72 -3
- package/types/core/logic/shell/commandDispatcher.d.ts +8 -0
- package/types/core/logic/shell/component.d.ts +5 -3
- package/types/core/logic/shell/shortcuts.d.ts +10 -1
- package/types/core/logic/shell/ui.d.ts +7 -1
- package/types/core/schema/context.d.ts +7 -1
- package/types/core/schema/frameContext.d.ts +36 -4
- package/types/core/schema/options.d.ts +110 -37
- package/types/core/section/constructor.d.ts +38 -1
- package/types/events.d.ts +208 -32
- package/types/helper/converter.d.ts +4 -2
- package/types/helper/dom/domCheck.d.ts +12 -2
- package/types/helper/dom/domQuery.d.ts +35 -7
- package/types/helper/dom/domUtils.d.ts +4 -1
- package/types/interfaces/plugins.d.ts +2 -2
- package/types/langs/_Lang.d.ts +0 -1
- package/types/modules/contract/Browser.d.ts +7 -7
- package/types/modules/contract/ColorPicker.d.ts +2 -2
- package/types/modules/contract/Controller.d.ts +7 -0
- package/types/modules/contract/Figure.d.ts +31 -4
- package/types/modules/ui/CommandMenu.d.ts +262 -0
- package/types/modules/ui/ModalAnchorEditor.d.ts +6 -1
- package/types/modules/ui/SelectMenu.d.ts +56 -3
- package/types/modules/ui/index.d.ts +1 -0
- package/types/plugins/browser/audioGallery.d.ts +17 -1
- package/types/plugins/browser/fileBrowser.d.ts +17 -1
- package/types/plugins/browser/fileGallery.d.ts +17 -1
- package/types/plugins/browser/imageGallery.d.ts +17 -1
- package/types/plugins/browser/videoGallery.d.ts +17 -1
- package/types/plugins/dropdown/align.d.ts +1 -1
- package/types/plugins/dropdown/blockStyle.d.ts +3 -1
- package/types/plugins/dropdown/table/index.d.ts +4 -1
- package/types/plugins/dropdown/table/services/table.clipboard.d.ts +5 -1
- package/types/plugins/dropdown/table/services/table.grid.d.ts +10 -2
- package/types/plugins/field/autocomplete.d.ts +0 -1
- package/types/plugins/field/slashCommand.d.ts +165 -0
- package/types/plugins/index.d.ts +3 -0
- package/types/plugins/modal/embed.d.ts +34 -0
- package/types/plugins/modal/link.d.ts +4 -1
- package/types/typedef.d.ts +48 -23
|
@@ -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
|
|
@@ -62,7 +78,7 @@ declare class ImageGallery extends PluginBrowser {
|
|
|
62
78
|
*/
|
|
63
79
|
constructor(kernel: SunEditor.Kernel, pluginOptions: ImageGalleryPluginOptions);
|
|
64
80
|
title: any;
|
|
65
|
-
onSelectfunction: (target:
|
|
81
|
+
onSelectfunction: (target: any) => any;
|
|
66
82
|
browser: Browser;
|
|
67
83
|
width: any;
|
|
68
84
|
height: any;
|
|
@@ -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
|
/**
|
|
@@ -67,7 +83,7 @@ declare class VideoGallery extends PluginBrowser {
|
|
|
67
83
|
*/
|
|
68
84
|
constructor(kernel: SunEditor.Kernel, pluginOptions: VideoGalleryPluginOptions);
|
|
69
85
|
title: any;
|
|
70
|
-
onSelectfunction: (target:
|
|
86
|
+
onSelectfunction: (target: any) => any;
|
|
71
87
|
browser: Browser;
|
|
72
88
|
width: any;
|
|
73
89
|
height: any;
|
|
@@ -21,7 +21,6 @@ declare class Align extends PluginDropdown {
|
|
|
21
21
|
*/
|
|
22
22
|
constructor(kernel: SunEditor.Kernel, pluginOptions: AlignPluginOptions);
|
|
23
23
|
title: any;
|
|
24
|
-
_itemMenu: HTMLUListElement;
|
|
25
24
|
defaultDir: string;
|
|
26
25
|
alignIcons: {
|
|
27
26
|
justify: any;
|
|
@@ -29,6 +28,7 @@ declare class Align extends PluginDropdown {
|
|
|
29
28
|
right: any;
|
|
30
29
|
center: any;
|
|
31
30
|
};
|
|
31
|
+
_itemMenu: HTMLUListElement;
|
|
32
32
|
alignList: NodeListOf<Element>;
|
|
33
33
|
active(element: HTMLElement | null, target: HTMLElement | null): boolean | void;
|
|
34
34
|
setDir(dir: string): void;
|
|
@@ -16,7 +16,9 @@ export type BlockStylePluginOptions = {
|
|
|
16
16
|
* ['p', 'h1', 'h2', 'blockquote', { tag: 'div', command: 'block', name: 'Custom Block', class: 'my-block' }]
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
items?: Array<
|
|
19
|
+
items?: Array<
|
|
20
|
+
'p' | 'div' | 'blockquote' | 'pre' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | string | BlockStyleItem
|
|
21
|
+
>;
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* @typedef {{tag: string, command: "line"|"br-line"|"block", name?: string, class?: string}} BlockStyleItem
|
|
@@ -79,7 +79,10 @@ declare class Table extends PluginDropdownFree {
|
|
|
79
79
|
* @param {K} key
|
|
80
80
|
* @param {import('./shared/table.constants').TableState[K]} value
|
|
81
81
|
*/
|
|
82
|
-
setState<K extends keyof import('./shared/table.constants').TableState>(
|
|
82
|
+
setState<K extends keyof import('./shared/table.constants').TableState>(
|
|
83
|
+
key: K,
|
|
84
|
+
value: import('./shared/table.constants').TableState[K],
|
|
85
|
+
): void;
|
|
83
86
|
componentSelect(target: HTMLElement): void | boolean;
|
|
84
87
|
componentDeselect(target: HTMLElement): void;
|
|
85
88
|
componentDestroy(target: HTMLElement): Promise<void>;
|
|
@@ -13,7 +13,11 @@ export class TableClipboardService {
|
|
|
13
13
|
* @param {HTMLElement} container - The container element
|
|
14
14
|
* @param {NodeListOf<HTMLTableCellElement>} selectedCells - The selected table cells
|
|
15
15
|
*/
|
|
16
|
-
copySelectedTableCells(
|
|
16
|
+
copySelectedTableCells(
|
|
17
|
+
e: ClipboardEvent,
|
|
18
|
+
container: HTMLElement,
|
|
19
|
+
selectedCells: NodeListOf<HTMLTableCellElement>,
|
|
20
|
+
): void;
|
|
17
21
|
/**
|
|
18
22
|
* @description Updates the target table's cells with the data from the copied table.
|
|
19
23
|
* @param {HTMLTableElement} copyTable The table containing the copied data.
|
|
@@ -52,7 +52,11 @@ export class TableGridService {
|
|
|
52
52
|
* @param {?HTMLTableCellElement} [positionResetElement] The element to reset the position of (optional). This can be the cell that triggered the column edit.
|
|
53
53
|
* @returns {HTMLTableCellElement} Target table cell
|
|
54
54
|
*/
|
|
55
|
-
editColumn(
|
|
55
|
+
editColumn(
|
|
56
|
+
option: string | null,
|
|
57
|
+
targetCell?: HTMLTableCellElement | null,
|
|
58
|
+
positionResetElement?: HTMLTableCellElement | null,
|
|
59
|
+
): HTMLTableCellElement;
|
|
56
60
|
/**
|
|
57
61
|
* @description Edits a table row, either adding, removing, the row
|
|
58
62
|
* @param {?string} option The action to perform on the row (`up`|`down`|`null`)
|
|
@@ -62,7 +66,11 @@ export class TableGridService {
|
|
|
62
66
|
* @param {?HTMLTableCellElement} [targetCell] Target cell, (default: current selected cell)
|
|
63
67
|
* @param {?HTMLTableCellElement} [positionResetElement] The element to reset the position of (optional). This can be the cell that triggered the row edit.
|
|
64
68
|
*/
|
|
65
|
-
editRow(
|
|
69
|
+
editRow(
|
|
70
|
+
option: string | null,
|
|
71
|
+
targetCell?: HTMLTableCellElement | null,
|
|
72
|
+
positionResetElement?: HTMLTableCellElement | null,
|
|
73
|
+
): void;
|
|
66
74
|
/**
|
|
67
75
|
* @description Inserts a new row into the table at the specified index to it.
|
|
68
76
|
* @param {HTMLTableElement} table The table element to insert the row into.
|
|
@@ -238,7 +238,6 @@ declare class Autocomplete extends PluginField {
|
|
|
238
238
|
* @param {AutocompletePluginOptions} pluginOptions
|
|
239
239
|
*/
|
|
240
240
|
constructor(kernel: SunEditor.Kernel, pluginOptions: AutocompletePluginOptions);
|
|
241
|
-
title: any;
|
|
242
241
|
triggerContexts: Map<any, any>;
|
|
243
242
|
sortedTriggers: any[];
|
|
244
243
|
selectMenu: SelectMenu;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type {} from '../../typedef';
|
|
2
|
+
export default SlashCommand;
|
|
3
|
+
export type SlashCommandItem = {
|
|
4
|
+
/**
|
|
5
|
+
* - Unique identifier for the item.
|
|
6
|
+
*/
|
|
7
|
+
key: string;
|
|
8
|
+
/**
|
|
9
|
+
* - Display label.
|
|
10
|
+
*/
|
|
11
|
+
title: string;
|
|
12
|
+
/**
|
|
13
|
+
* - Icon key from `$.icons` (e.g. `'h1'`) or a raw HTML string (e.g. `'<svg>...</svg>'`).
|
|
14
|
+
*/
|
|
15
|
+
icon?: string;
|
|
16
|
+
/**
|
|
17
|
+
* - Extra search terms used in addition to the title.
|
|
18
|
+
*/
|
|
19
|
+
keywords?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* - Invoked when the item is selected.
|
|
22
|
+
* The trigger string (e.g. `/hea`) is already removed from the editor and the caret restored to that position before `action` runs.
|
|
23
|
+
* The action owns its history entry — calling an L3 wrapper (`$.html.*`, `$.format.*`, `$.inline.apply`) auto-pushes; otherwise call `$.history.push(false)` manually.
|
|
24
|
+
*/
|
|
25
|
+
action: (arg0: SunEditor.Deps, arg1: SlashCommandActionContext) => void | Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
export type SlashCommandActionContext = {
|
|
28
|
+
/**
|
|
29
|
+
* - The configured trigger character (e.g. `'/'`).
|
|
30
|
+
*/
|
|
31
|
+
triggerChar: string;
|
|
32
|
+
/**
|
|
33
|
+
* - The text the user typed after the trigger (e.g. `'hea'`).
|
|
34
|
+
*/
|
|
35
|
+
query: string;
|
|
36
|
+
/**
|
|
37
|
+
* - The selected item.
|
|
38
|
+
*/
|
|
39
|
+
item: SlashCommandItem;
|
|
40
|
+
};
|
|
41
|
+
export type SlashCommandPluginOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* - Character that opens the command menu. Single character recommended.
|
|
44
|
+
*/
|
|
45
|
+
triggerChar?: string;
|
|
46
|
+
/**
|
|
47
|
+
* - Menu entries. Strings resolve via `ResolveButton`
|
|
48
|
+
* (plugin names, built-in commands like `'bold'`); objects are custom items with their own `action`.
|
|
49
|
+
* Required.
|
|
50
|
+
*/
|
|
51
|
+
items: Array<SlashCommandItem | string>;
|
|
52
|
+
/**
|
|
53
|
+
* - Debounce delay (ms) before the input is inspected for the trigger.
|
|
54
|
+
*/
|
|
55
|
+
delayTime?: number;
|
|
56
|
+
/**
|
|
57
|
+
* - Maximum number of items shown in the dropdown.
|
|
58
|
+
*/
|
|
59
|
+
limitSize?: number;
|
|
60
|
+
/**
|
|
61
|
+
* - Message shown when no items match the query. If unset, the menu closes on no match.
|
|
62
|
+
*/
|
|
63
|
+
emptyMessage?: string;
|
|
64
|
+
/**
|
|
65
|
+
* - Custom item HTML renderer.
|
|
66
|
+
* Applied only to custom item objects; plugin-name entries always render with the canonical BlockHandle row.
|
|
67
|
+
* ```js
|
|
68
|
+
* SUNEDITOR.create('#editor', {
|
|
69
|
+
* plugins: [slashCommand],
|
|
70
|
+
* slashCommand: {
|
|
71
|
+
* triggerChar: '/',
|
|
72
|
+
* items: [
|
|
73
|
+
* {
|
|
74
|
+
* key: 'h1',
|
|
75
|
+
* title: 'Heading 1',
|
|
76
|
+
* icon: 'h1',
|
|
77
|
+
* keywords: ['header', 'title'],
|
|
78
|
+
* action: ($) => $.format.applyBlock(document.createElement('H1')),
|
|
79
|
+
* },
|
|
80
|
+
* 'bold',
|
|
81
|
+
* 'image',
|
|
82
|
+
* 'blockStyle',
|
|
83
|
+
* ],
|
|
84
|
+
* },
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
renderItem?: (
|
|
89
|
+
arg0: SlashCommandItem,
|
|
90
|
+
arg1: {
|
|
91
|
+
icons: any;
|
|
92
|
+
},
|
|
93
|
+
) => string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* @typedef {Object} SlashCommandItem
|
|
97
|
+
* @property {string} key - Unique identifier for the item.
|
|
98
|
+
* @property {string} title - Display label.
|
|
99
|
+
* @property {string} [icon] - Icon key from `$.icons` (e.g. `'h1'`) or a raw HTML string (e.g. `'<svg>...</svg>'`).
|
|
100
|
+
* @property {string[]} [keywords] - Extra search terms used in addition to the title.
|
|
101
|
+
* @property {function(SunEditor.Deps, SlashCommandActionContext): void | Promise<void>} action - Invoked when the item is selected.
|
|
102
|
+
* The trigger string (e.g. `/hea`) is already removed from the editor and the caret restored to that position before `action` runs.
|
|
103
|
+
* The action owns its history entry — calling an L3 wrapper (`$.html.*`, `$.format.*`, `$.inline.apply`) auto-pushes; otherwise call `$.history.push(false)` manually.
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* @typedef {Object} SlashCommandActionContext
|
|
107
|
+
* @property {string} triggerChar - The configured trigger character (e.g. `'/'`).
|
|
108
|
+
* @property {string} query - The text the user typed after the trigger (e.g. `'hea'`).
|
|
109
|
+
* @property {SlashCommandItem} item - The selected item.
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* @typedef {Object} SlashCommandPluginOptions
|
|
113
|
+
* @property {string} [triggerChar='/'] - Character that opens the command menu. Single character recommended.
|
|
114
|
+
* @property {Array<SlashCommandItem | string>} items - Menu entries. Strings resolve via `ResolveButton`
|
|
115
|
+
* (plugin names, built-in commands like `'bold'`); objects are custom items with their own `action`.
|
|
116
|
+
* Required.
|
|
117
|
+
* @property {number} [delayTime=120] - Debounce delay (ms) before the input is inspected for the trigger.
|
|
118
|
+
* @property {number} [limitSize=10] - Maximum number of items shown in the dropdown.
|
|
119
|
+
* @property {string} [emptyMessage] - Message shown when no items match the query. If unset, the menu closes on no match.
|
|
120
|
+
* @property {function(SlashCommandItem, { icons: Object }): string} [renderItem] - Custom item HTML renderer.
|
|
121
|
+
* Applied only to custom item objects; plugin-name entries always render with the canonical BlockHandle row.
|
|
122
|
+
* ```js
|
|
123
|
+
* SUNEDITOR.create('#editor', {
|
|
124
|
+
* plugins: [slashCommand],
|
|
125
|
+
* slashCommand: {
|
|
126
|
+
* triggerChar: '/',
|
|
127
|
+
* items: [
|
|
128
|
+
* {
|
|
129
|
+
* key: 'h1',
|
|
130
|
+
* title: 'Heading 1',
|
|
131
|
+
* icon: 'h1',
|
|
132
|
+
* keywords: ['header', 'title'],
|
|
133
|
+
* action: ($) => $.format.applyBlock(document.createElement('H1')),
|
|
134
|
+
* },
|
|
135
|
+
* 'bold',
|
|
136
|
+
* 'image',
|
|
137
|
+
* 'blockStyle',
|
|
138
|
+
* ],
|
|
139
|
+
* },
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* @class
|
|
145
|
+
* @description Slash Command plugin
|
|
146
|
+
* - Notion / Tiptap style "/" command menu. Triggered by the configured character (default `'/'`).
|
|
147
|
+
* - Menu rendering + dispatch is delegated to {@link CommandMenu}, which is also used by BlockHandle's
|
|
148
|
+
* action menu — both menus share the exact same row HTML and dispatch behavior.
|
|
149
|
+
* - SlashCommand-specific concerns kept here: input watching, debounce, trigger detection,
|
|
150
|
+
* trigger text deletion before dispatch, empty-state row.
|
|
151
|
+
*/
|
|
152
|
+
declare class SlashCommand extends PluginField {
|
|
153
|
+
/**
|
|
154
|
+
* @constructor
|
|
155
|
+
* @param {SunEditor.Kernel} kernel
|
|
156
|
+
* @param {SlashCommandPluginOptions} pluginOptions
|
|
157
|
+
*/
|
|
158
|
+
constructor(kernel: SunEditor.Kernel, pluginOptions: SlashCommandPluginOptions);
|
|
159
|
+
controller: Controller;
|
|
160
|
+
onInput(params: SunEditor.HookParams.InputWithData): void;
|
|
161
|
+
onKeyDown(params: SunEditor.HookParams.KeyEvent): void | boolean;
|
|
162
|
+
#private;
|
|
163
|
+
}
|
|
164
|
+
import { PluginField } from '../../interfaces';
|
|
165
|
+
import { Controller } from '../../modules/contract';
|
package/types/plugins/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ declare namespace _default {
|
|
|
7
7
|
export { list_bulleted };
|
|
8
8
|
export { list_numbered };
|
|
9
9
|
export { autocomplete };
|
|
10
|
+
export { slashCommand };
|
|
10
11
|
export { align };
|
|
11
12
|
export { font };
|
|
12
13
|
export { fontColor };
|
|
@@ -62,6 +63,7 @@ import table from './dropdown/table';
|
|
|
62
63
|
import template from './dropdown/template';
|
|
63
64
|
import textStyle from './dropdown/textStyle';
|
|
64
65
|
import autocomplete from './field/autocomplete';
|
|
66
|
+
import slashCommand from './field/slashCommand';
|
|
65
67
|
import fontSize from './input/fontSize';
|
|
66
68
|
import pageNavigator from './input/pageNavigator';
|
|
67
69
|
import audio from './modal/audio';
|
|
@@ -103,6 +105,7 @@ export {
|
|
|
103
105
|
math,
|
|
104
106
|
pageNavigator,
|
|
105
107
|
paragraphStyle,
|
|
108
|
+
slashCommand,
|
|
106
109
|
table,
|
|
107
110
|
template,
|
|
108
111
|
textStyle,
|
|
@@ -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;
|
|
@@ -36,7 +36,10 @@ export type LinkOptions = {
|
|
|
36
36
|
*/
|
|
37
37
|
acceptedFormats?: string;
|
|
38
38
|
};
|
|
39
|
-
export type LinkPluginOptions = Omit<
|
|
39
|
+
export type LinkPluginOptions = Omit<
|
|
40
|
+
LinkOptions & import('../../modules/ui/ModalAnchorEditor').ModalAnchorEditorParams,
|
|
41
|
+
''
|
|
42
|
+
>;
|
|
40
43
|
/**
|
|
41
44
|
* @typedef {Object} LinkOptions
|
|
42
45
|
* @property {string} [uploadUrl] - The URL endpoint for file uploads.
|
package/types/typedef.d.ts
CHANGED
|
@@ -17,6 +17,20 @@ declare global {
|
|
|
17
17
|
type EventWysiwyg = HTMLElement & Window;
|
|
18
18
|
type WysiwygFrame = HTMLElement & HTMLIFrameElement;
|
|
19
19
|
type GlobalWindow = Window & typeof globalThis;
|
|
20
|
+
type ComponentLauncher = {
|
|
21
|
+
/**
|
|
22
|
+
* - Delete hook (invoked by the selected-component keydown handler).
|
|
23
|
+
*/
|
|
24
|
+
componentDestroy?: (target: any) => void | Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* - Optional select hook.
|
|
27
|
+
*/
|
|
28
|
+
componentSelect?: (target: any) => boolean | void;
|
|
29
|
+
/**
|
|
30
|
+
* - Optional deselect hook.
|
|
31
|
+
*/
|
|
32
|
+
componentDeselect?: (target: any) => void;
|
|
33
|
+
};
|
|
20
34
|
type ComponentInfo = {
|
|
21
35
|
/**
|
|
22
36
|
* - The target element associated with the component.
|
|
@@ -53,9 +67,9 @@ declare global {
|
|
|
53
67
|
*/
|
|
54
68
|
isFile: boolean;
|
|
55
69
|
/**
|
|
56
|
-
* -
|
|
70
|
+
* - Hook object for non-plugin components (e.g. `pageBreak`), if applicable.
|
|
57
71
|
*/
|
|
58
|
-
launcher:
|
|
72
|
+
launcher: SunEditor.ComponentLauncher | null;
|
|
59
73
|
/**
|
|
60
74
|
* - Whether the component is an input component (e.g., table).
|
|
61
75
|
*/
|
|
@@ -117,35 +131,35 @@ declare global {
|
|
|
117
131
|
type Init = typeof import('./hooks/base').Core.Init;
|
|
118
132
|
}
|
|
119
133
|
namespace Component {
|
|
120
|
-
type Select =
|
|
121
|
-
type Deselect =
|
|
122
|
-
type Edit =
|
|
123
|
-
type Destroy =
|
|
124
|
-
type Copy =
|
|
134
|
+
type Select = import('./interfaces/contracts').EditorComponent['componentSelect'];
|
|
135
|
+
type Deselect = import('./interfaces/contracts').EditorComponent['componentDeselect'];
|
|
136
|
+
type Edit = import('./interfaces/contracts').EditorComponent['componentEdit'];
|
|
137
|
+
type Destroy = import('./interfaces/contracts').EditorComponent['componentDestroy'];
|
|
138
|
+
type Copy = import('./interfaces/contracts').EditorComponent['componentCopy'];
|
|
125
139
|
}
|
|
126
140
|
namespace Modal {
|
|
127
|
-
type Action =
|
|
128
|
-
type On =
|
|
129
|
-
type Init =
|
|
130
|
-
type Off =
|
|
131
|
-
type Resize =
|
|
141
|
+
type Action = import('./interfaces/contracts').ModuleModal['modalAction'];
|
|
142
|
+
type On = import('./interfaces/contracts').ModuleModal['modalOn'];
|
|
143
|
+
type Init = import('./interfaces/contracts').ModuleModal['modalInit'];
|
|
144
|
+
type Off = import('./interfaces/contracts').ModuleModal['modalOff'];
|
|
145
|
+
type Resize = import('./interfaces/contracts').ModuleModal['modalResize'];
|
|
132
146
|
}
|
|
133
147
|
namespace Controller {
|
|
134
|
-
type Action =
|
|
135
|
-
type On =
|
|
136
|
-
type Close =
|
|
148
|
+
type Action = import('./interfaces/contracts').ModuleController['controllerAction'];
|
|
149
|
+
type On = import('./interfaces/contracts').ModuleController['controllerOn'];
|
|
150
|
+
type Close = import('./interfaces/contracts').ModuleController['controllerClose'];
|
|
137
151
|
}
|
|
138
152
|
namespace Browser {
|
|
139
|
-
type Init =
|
|
153
|
+
type Init = import('./interfaces/contracts').ModuleBrowser['browserInit'];
|
|
140
154
|
}
|
|
141
155
|
namespace ColorPicker {
|
|
142
|
-
type Action =
|
|
143
|
-
type HueSliderOpen =
|
|
144
|
-
type HueSliderClose =
|
|
156
|
+
type Action = import('./interfaces/contracts').ModuleColorPicker['colorPickerAction'];
|
|
157
|
+
type HueSliderOpen = import('./interfaces/contracts').ModuleColorPicker['colorPickerHueSliderOpen'];
|
|
158
|
+
type HueSliderClose = import('./interfaces/contracts').ModuleColorPicker['colorPickerHueSliderClose'];
|
|
145
159
|
}
|
|
146
160
|
namespace HueSlider {
|
|
147
|
-
type Action =
|
|
148
|
-
type CancelAction =
|
|
161
|
+
type Action = import('./interfaces/contracts').ModuleHueSlider['hueSliderAction'];
|
|
162
|
+
type CancelAction = import('./interfaces/contracts').ModuleHueSlider['hueSliderCancelAction'];
|
|
149
163
|
}
|
|
150
164
|
}
|
|
151
165
|
export namespace HookParams {
|
|
@@ -261,7 +275,13 @@ declare global {
|
|
|
261
275
|
* - `"#fix"`: RTL direction fix
|
|
262
276
|
* - `"%100"|"%50"`: Responsive breakpoint (percentage)
|
|
263
277
|
*/
|
|
264
|
-
type ButtonSpecial =
|
|
278
|
+
type ButtonSpecial =
|
|
279
|
+
| '|'
|
|
280
|
+
| '/'
|
|
281
|
+
| `-${'left' | 'right' | 'center'}`
|
|
282
|
+
| '#fix'
|
|
283
|
+
| `:${string}-${string}`
|
|
284
|
+
| `%${number}`;
|
|
265
285
|
/**
|
|
266
286
|
* Plugin buttons available in the toolbar
|
|
267
287
|
*/
|
|
@@ -307,6 +327,7 @@ declare global {
|
|
|
307
327
|
| 'list_bulleted'
|
|
308
328
|
| 'list_numbered'
|
|
309
329
|
| 'autocomplete'
|
|
330
|
+
| 'slashCommand'
|
|
310
331
|
| 'align'
|
|
311
332
|
| 'font'
|
|
312
333
|
| 'fontColor'
|
|
@@ -339,7 +360,11 @@ declare global {
|
|
|
339
360
|
* Button list configuration for the toolbar
|
|
340
361
|
* Supports nested arrays, special controls, and responsive breakpoint configurations
|
|
341
362
|
*/
|
|
342
|
-
type ButtonItem =
|
|
363
|
+
type ButtonItem =
|
|
364
|
+
| SunEditor.UI.ButtonCommand
|
|
365
|
+
| SunEditor.UI.ButtonPlugin
|
|
366
|
+
| SunEditor.UI.ButtonSpecial
|
|
367
|
+
| string;
|
|
343
368
|
/**
|
|
344
369
|
* ///
|
|
345
370
|
* ---[ End of auto-generated button types ]---
|