suneditor 3.0.6 → 3.1.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.
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +1 -1
- package/src/assets/suneditor.css +2 -2
- package/src/core/editor.js +20 -3
- package/src/core/event/eventOrchestrator.js +2 -1
- package/src/core/event/handlers/handler_ww_key.js +2 -2
- package/src/core/event/rules/keydown.rule.enter.js +2 -2
- package/src/core/logic/dom/format.js +5 -1
- package/src/core/logic/dom/html.js +23 -1
- package/src/core/logic/dom/offset.js +24 -1
- package/src/core/logic/panel/menu.js +74 -3
- package/src/core/logic/panel/viewer.js +6 -4
- package/src/core/logic/shell/shortcuts.js +1 -1
- package/src/core/schema/options.js +1 -1
- package/src/core/section/constructor.js +2 -2
- package/src/helper/index.js +3 -0
- package/src/helper/msOffice.js +849 -0
- package/src/interfaces/plugins.js +1 -1
- package/src/langs/ckb.js +1 -0
- package/src/langs/cs.js +1 -0
- package/src/langs/da.js +1 -0
- package/src/langs/de.js +1 -0
- package/src/langs/en.js +1 -1
- package/src/langs/es.js +1 -0
- package/src/langs/fa.js +1 -0
- package/src/langs/fr.js +1 -0
- package/src/langs/he.js +1 -0
- package/src/langs/hu.js +1 -0
- package/src/langs/it.js +1 -0
- package/src/langs/ja.js +1 -0
- package/src/langs/km.js +1 -0
- package/src/langs/ko.js +1 -0
- package/src/langs/lv.js +1 -0
- package/src/langs/nl.js +1 -0
- package/src/langs/pl.js +1 -0
- package/src/langs/pt_br.js +1 -0
- package/src/langs/ro.js +1 -0
- package/src/langs/ru.js +1 -0
- package/src/langs/se.js +1 -0
- package/src/langs/tr.js +1 -0
- package/src/langs/uk.js +1 -0
- package/src/langs/ur.js +1 -0
- package/src/langs/zh_cn.js +1 -0
- package/src/modules/contract/Browser.js +1 -0
- package/src/plugins/dropdown/layout.js +1 -1
- package/src/plugins/dropdown/template.js +2 -1
- package/src/plugins/field/autocomplete.js +383 -0
- package/src/plugins/index.js +3 -3
- package/src/typedef.js +1 -1
- package/types/core/logic/shell/shortcuts.d.ts +2 -2
- package/types/core/schema/options.d.ts +2 -2
- package/types/helper/index.d.ts +4 -0
- package/types/helper/msOffice.d.ts +11 -0
- package/types/interfaces/plugins.d.ts +1 -1
- package/types/langs/_Lang.d.ts +1 -2
- package/types/plugins/field/autocomplete.d.ts +251 -0
- package/types/plugins/index.d.ts +3 -3
- package/types/typedef.d.ts +1 -1
- package/src/plugins/field/mention.js +0 -251
- package/types/plugins/field/mention.d.ts +0 -104
package/src/plugins/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import list_bulleted from './command/list_bulleted';
|
|
|
7
7
|
import list_numbered from './command/list_numbered';
|
|
8
8
|
|
|
9
9
|
// field
|
|
10
|
-
import
|
|
10
|
+
import autocomplete from './field/autocomplete';
|
|
11
11
|
|
|
12
12
|
// dropdown
|
|
13
13
|
import align from './dropdown/align';
|
|
@@ -54,7 +54,7 @@ export {
|
|
|
54
54
|
fileUpload,
|
|
55
55
|
list_bulleted,
|
|
56
56
|
list_numbered,
|
|
57
|
-
|
|
57
|
+
autocomplete,
|
|
58
58
|
align,
|
|
59
59
|
font,
|
|
60
60
|
fontColor,
|
|
@@ -91,7 +91,7 @@ export default {
|
|
|
91
91
|
fileUpload,
|
|
92
92
|
list_bulleted,
|
|
93
93
|
list_numbered,
|
|
94
|
-
|
|
94
|
+
autocomplete,
|
|
95
95
|
align,
|
|
96
96
|
font,
|
|
97
97
|
fontColor,
|
package/src/typedef.js
CHANGED
|
@@ -268,7 +268,7 @@
|
|
|
268
268
|
* @typedef {"bold"|"underline"|"italic"|"strike"|"subscript"|"superscript"|"removeFormat"|"copyFormat"|"indent"|"outdent"|"fullScreen"|"showBlocks"|"codeView"|"markdownView"|"undo"|"redo"|"preview"|"print"|"copy"|"dir"|"dir_ltr"|"dir_rtl"|"finder"|"save"|"newDocument"|"selectAll"|"pageBreak"|"pageUp"|"pageDown"|"pageNavigator"} SunEditor.UI.ButtonCommand
|
|
269
269
|
*
|
|
270
270
|
* Plugin buttons available in the toolbar
|
|
271
|
-
* @typedef {"blockquote"|"codeBlock"|"exportPDF"|"fileUpload"|"list_bulleted"|"list_numbered"|"
|
|
271
|
+
* @typedef {"blockquote"|"codeBlock"|"exportPDF"|"fileUpload"|"list_bulleted"|"list_numbered"|"autocomplete"|"align"|"font"|"fontColor"|"backgroundColor"|"list"|"table"|"blockStyle"|"hr"|"layout"|"lineHeight"|"template"|"paragraphStyle"|"textStyle"|"link"|"image"|"video"|"audio"|"embed"|"math"|"drawing"|"imageGallery"|"videoGallery"|"audioGallery"|"fileGallery"|"fileBrowser"|"fontSize"|"pageNavigator"|"anchor"} SunEditor.UI.ButtonPlugin
|
|
272
272
|
*
|
|
273
273
|
* Single button item in the toolbar (includes special controls and custom strings)
|
|
274
274
|
* @typedef {SunEditor.UI.ButtonCommand|SunEditor.UI.ButtonPlugin|SunEditor.UI.ButtonSpecial|string} SunEditor.UI.ButtonItem
|
|
@@ -54,7 +54,7 @@ export type ShortcutInfo = {
|
|
|
54
54
|
*/
|
|
55
55
|
r: Array<string>;
|
|
56
56
|
/**
|
|
57
|
-
* - Whether the event was triggered by a text input (e.g.,
|
|
57
|
+
* - Whether the event was triggered by a text input (e.g., autocomplete like
|
|
58
58
|
*/
|
|
59
59
|
textTrigger: string;
|
|
60
60
|
};
|
|
@@ -73,7 +73,7 @@ export type ShortcutInfo = {
|
|
|
73
73
|
* @property {string} type - Plugin's type. (`command`, `dropdown`, `modal`, `browser`, `input`, `field`, `popup`).
|
|
74
74
|
* @property {Node} button - The plugin command button.
|
|
75
75
|
* @property {Array<string>} r - An array of key codes generated with the reverseButtons option, used to reverse the action for a specific key combination.
|
|
76
|
-
* @property {string} textTrigger - Whether the event was triggered by a text input (e.g.,
|
|
76
|
+
* @property {string} textTrigger - Whether the event was triggered by a text input (e.g., autocomplete like @ab).
|
|
77
77
|
*/
|
|
78
78
|
/**
|
|
79
79
|
* @description Shortcuts class
|
|
@@ -525,6 +525,7 @@ export namespace DEFAULTS {
|
|
|
525
525
|
* @property {import('../../plugins/dropdown/align.js').AlignPluginOptions} [align]
|
|
526
526
|
* @property {import('../../plugins/modal/audio.js').AudioPluginOptions} [audio]
|
|
527
527
|
* @property {import('../../plugins/browser/audioGallery.js').AudioGalleryPluginOptions} [audioGallery]
|
|
528
|
+
* @property {import('../../plugins/field/autocomplete.js').AutocompletePluginOptions} [autocomplete]
|
|
528
529
|
* @property {import('../../plugins/dropdown/backgroundColor.js').BackgroundColorPluginOptions} [backgroundColor]
|
|
529
530
|
* @property {import('../../plugins/dropdown/blockStyle.js').BlockStylePluginOptions} [blockStyle]
|
|
530
531
|
* @property {import('../../plugins/command/codeBlock.js').CodeBlockPluginOptions} [codeBlock]
|
|
@@ -544,7 +545,6 @@ export namespace DEFAULTS {
|
|
|
544
545
|
* @property {import('../../plugins/dropdown/lineHeight.js').LineHeightPluginOptions} [lineHeight]
|
|
545
546
|
* @property {import('../../plugins/modal/link.js').LinkPluginOptions} [link]
|
|
546
547
|
* @property {import('../../plugins/modal/math.js').MathPluginOptions} [math]
|
|
547
|
-
* @property {import('../../plugins/field/mention.js').MentionPluginOptions} [mention]
|
|
548
548
|
* @property {import('../../plugins/dropdown/paragraphStyle.js').ParagraphStylePluginOptions} [paragraphStyle]
|
|
549
549
|
* @property {import('../../plugins/dropdown/table/index.js').TablePluginOptions} [table]
|
|
550
550
|
* @property {import('../../plugins/dropdown/template.js').TemplatePluginOptions} [template]
|
|
@@ -1429,6 +1429,7 @@ export type EditorBaseOptions = {
|
|
|
1429
1429
|
align?: import('../../plugins/dropdown/align.js').AlignPluginOptions;
|
|
1430
1430
|
audio?: import('../../plugins/modal/audio.js').AudioPluginOptions;
|
|
1431
1431
|
audioGallery?: import('../../plugins/browser/audioGallery.js').AudioGalleryPluginOptions;
|
|
1432
|
+
autocomplete?: import('../../plugins/field/autocomplete.js').AutocompletePluginOptions;
|
|
1432
1433
|
backgroundColor?: import('../../plugins/dropdown/backgroundColor.js').BackgroundColorPluginOptions;
|
|
1433
1434
|
blockStyle?: import('../../plugins/dropdown/blockStyle.js').BlockStylePluginOptions;
|
|
1434
1435
|
codeBlock?: import('../../plugins/command/codeBlock.js').CodeBlockPluginOptions;
|
|
@@ -1448,7 +1449,6 @@ export type EditorBaseOptions = {
|
|
|
1448
1449
|
lineHeight?: import('../../plugins/dropdown/lineHeight.js').LineHeightPluginOptions;
|
|
1449
1450
|
link?: import('../../plugins/modal/link.js').LinkPluginOptions;
|
|
1450
1451
|
math?: import('../../plugins/modal/math.js').MathPluginOptions;
|
|
1451
|
-
mention?: import('../../plugins/field/mention.js').MentionPluginOptions;
|
|
1452
1452
|
paragraphStyle?: import('../../plugins/dropdown/paragraphStyle.js').ParagraphStylePluginOptions;
|
|
1453
1453
|
table?: import('../../plugins/dropdown/table/index.js').TablePluginOptions;
|
|
1454
1454
|
template?: import('../../plugins/dropdown/template.js').TemplatePluginOptions;
|
package/types/helper/index.d.ts
CHANGED
|
@@ -174,6 +174,9 @@ export const markdown: {
|
|
|
174
174
|
jsonToMarkdown: typeof import('./markdown').jsonToMarkdown;
|
|
175
175
|
markdownToHtml: typeof import('./markdown').markdownToHtml;
|
|
176
176
|
};
|
|
177
|
+
export const msOffice: {
|
|
178
|
+
cleanHTML: typeof import('./msOffice').cleanHTML;
|
|
179
|
+
};
|
|
177
180
|
declare namespace _default {
|
|
178
181
|
export { env };
|
|
179
182
|
export { unicode };
|
|
@@ -183,5 +186,6 @@ declare namespace _default {
|
|
|
183
186
|
export { keyCodeMap };
|
|
184
187
|
export { clipboard };
|
|
185
188
|
export { markdown };
|
|
189
|
+
export { msOffice };
|
|
186
190
|
}
|
|
187
191
|
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {} from '../typedef';
|
|
2
|
+
/**
|
|
3
|
+
* @description Converts MS Word/Excel/OneNote HTML clipboard data to clean, standards-compliant HTML.
|
|
4
|
+
* @param {string} html Raw HTML string from MS Office clipboard
|
|
5
|
+
* @returns {string} Cleaned HTML string
|
|
6
|
+
*/
|
|
7
|
+
export function cleanHTML(html: string): string;
|
|
8
|
+
declare namespace _default {
|
|
9
|
+
export { cleanHTML };
|
|
10
|
+
}
|
|
11
|
+
export default _default;
|
|
@@ -92,7 +92,7 @@ export class PluginDropdownFree extends Base {
|
|
|
92
92
|
* These plugins typically respond to input events in the wysiwyg area
|
|
93
93
|
*
|
|
94
94
|
* **Commonly used hooks:**
|
|
95
|
-
* - `onInput()` - Responds to input events in the editor (See: `
|
|
95
|
+
* - `onInput()` - Responds to input events in the editor (See: `autocomplete` plugin)
|
|
96
96
|
* - Other event hooks can be used as needed (`onKeydown`, `onClick`, etc.)
|
|
97
97
|
*
|
|
98
98
|
* Child classes MAY optionally implement event hook methods
|
package/types/langs/_Lang.d.ts
CHANGED
|
@@ -38,7 +38,6 @@ export type _Lang = {
|
|
|
38
38
|
caption: string;
|
|
39
39
|
cellProperties: string;
|
|
40
40
|
center: string;
|
|
41
|
-
clear: string;
|
|
42
41
|
close: string;
|
|
43
42
|
codeView: string;
|
|
44
43
|
color: string;
|
|
@@ -119,7 +118,7 @@ export type _Lang = {
|
|
|
119
118
|
math_modal_title: string;
|
|
120
119
|
maxSize: string;
|
|
121
120
|
mediaGallery: string;
|
|
122
|
-
|
|
121
|
+
autocomplete: string;
|
|
123
122
|
menu_bordered: string;
|
|
124
123
|
menu_code: string;
|
|
125
124
|
menu_neon: string;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import type {} from '../../typedef';
|
|
2
|
+
export default Autocomplete;
|
|
3
|
+
export type AutocompleteTriggerConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* - Static data array. Each item must have a `key` field. Mutually exclusive with `apiUrl`.
|
|
6
|
+
* ```js
|
|
7
|
+
* // data
|
|
8
|
+
* [{ key: 'john', name: 'John Doe', url: '/users/john' }]
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
data?: Array<{
|
|
12
|
+
key: string;
|
|
13
|
+
[x: string]: any;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* - API endpoint URL. Supports `{key}` and `{limitSize}` placeholders. Mutually exclusive with `data`.
|
|
17
|
+
*/
|
|
18
|
+
apiUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* - HTTP headers for the API request.
|
|
21
|
+
*/
|
|
22
|
+
apiHeaders?: {
|
|
23
|
+
[x: string]: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* - Transforms parsed JSON response into an array of data items.
|
|
27
|
+
*/
|
|
28
|
+
transformResponse?: (
|
|
29
|
+
arg0: any,
|
|
30
|
+
arg1: XMLHttpRequest,
|
|
31
|
+
) => Array<{
|
|
32
|
+
key: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* - Override global `limitSize` for this trigger.
|
|
36
|
+
*/
|
|
37
|
+
limitSize?: number;
|
|
38
|
+
/**
|
|
39
|
+
* - Override global `searchStartLength` for this trigger.
|
|
40
|
+
*/
|
|
41
|
+
searchStartLength?: number;
|
|
42
|
+
/**
|
|
43
|
+
* - Override global `useCachingData` for this trigger.
|
|
44
|
+
*/
|
|
45
|
+
useCachingData?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* - Override global `useCachingFieldData` for this trigger.
|
|
48
|
+
*/
|
|
49
|
+
useCachingFieldData?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* - Custom dropdown item renderer. Receives `(item, triggerText)`, returns HTML string.
|
|
52
|
+
*/
|
|
53
|
+
renderItem?: (
|
|
54
|
+
arg0: {
|
|
55
|
+
key: string;
|
|
56
|
+
[x: string]: any;
|
|
57
|
+
},
|
|
58
|
+
arg1: string,
|
|
59
|
+
) => string;
|
|
60
|
+
/**
|
|
61
|
+
* - Custom selection handler. Returns:
|
|
62
|
+
* - `string`: inserted as text node
|
|
63
|
+
* - `Element`: inserted as-is
|
|
64
|
+
* - `{tag, attrs, text}`: creates element via `dom.utils.createElement`
|
|
65
|
+
*/
|
|
66
|
+
onSelect?: (
|
|
67
|
+
arg0: {
|
|
68
|
+
key: string;
|
|
69
|
+
[x: string]: any;
|
|
70
|
+
},
|
|
71
|
+
arg1: string,
|
|
72
|
+
) =>
|
|
73
|
+
| string
|
|
74
|
+
| Element
|
|
75
|
+
| {
|
|
76
|
+
tag: string;
|
|
77
|
+
attrs?: any;
|
|
78
|
+
text?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export type AutocompletePluginOptions = {
|
|
82
|
+
/**
|
|
83
|
+
* - Debounce delay in ms before processing input.
|
|
84
|
+
*/
|
|
85
|
+
delayTime?: number;
|
|
86
|
+
/**
|
|
87
|
+
* - Maximum number of items to display in the dropdown.
|
|
88
|
+
*/
|
|
89
|
+
limitSize?: number;
|
|
90
|
+
/**
|
|
91
|
+
* - Minimum input length before triggering search.
|
|
92
|
+
*/
|
|
93
|
+
searchStartLength?: number;
|
|
94
|
+
/**
|
|
95
|
+
* - Whether to cache query responses per trigger.
|
|
96
|
+
*/
|
|
97
|
+
useCachingData?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* - Whether to cache selected items for priority display.
|
|
100
|
+
*/
|
|
101
|
+
useCachingFieldData?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* - Per-trigger configurations keyed by trigger character.
|
|
104
|
+
* ```js
|
|
105
|
+
* // Basic usage with static data — mention trigger
|
|
106
|
+
* const editor = SUNEDITOR.create('#editor', {
|
|
107
|
+
* plugins: [autocomplete],
|
|
108
|
+
* autocomplete: {
|
|
109
|
+
* triggers: {
|
|
110
|
+
* '@': {
|
|
111
|
+
* data: [
|
|
112
|
+
* { key: 'john', name: 'John Doe' },
|
|
113
|
+
* { key: 'jane', name: 'Jane Smith' },
|
|
114
|
+
* ],
|
|
115
|
+
* },
|
|
116
|
+
* },
|
|
117
|
+
* },
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // API-based trigger with custom rendering and selection
|
|
121
|
+
* const editor = SUNEDITOR.create('#editor', {
|
|
122
|
+
* plugins: [autocomplete],
|
|
123
|
+
* autocomplete: {
|
|
124
|
+
* delayTime: 200,
|
|
125
|
+
* limitSize: 10,
|
|
126
|
+
* triggers: {
|
|
127
|
+
* '@': {
|
|
128
|
+
* apiUrl: '/api/users?q={key}&limit={limitSize}',
|
|
129
|
+
* apiHeaders: { Authorization: 'Bearer TOKEN' },
|
|
130
|
+
* transformResponse: (json) => json.data.map((u) => ({ key: u.username, name: u.displayName, id: u.id })),
|
|
131
|
+
* renderItem: (item) => `<div class="user-item"><strong>${item.key}</strong> <span>${item.name}</span></div>`,
|
|
132
|
+
* onSelect: (item, trigger) => ({
|
|
133
|
+
* tag: 'a',
|
|
134
|
+
* attrs: { href: `/users/${item.id}`, 'data-se-autocomplete': trigger + item.key },
|
|
135
|
+
* text: trigger + item.key,
|
|
136
|
+
* }),
|
|
137
|
+
* },
|
|
138
|
+
* '#': {
|
|
139
|
+
* apiUrl: '/api/tags?q={key}',
|
|
140
|
+
* transformResponse: (json) => json.tags,
|
|
141
|
+
* searchStartLength: 2,
|
|
142
|
+
* useCachingData: false,
|
|
143
|
+
* },
|
|
144
|
+
* },
|
|
145
|
+
* },
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
triggers: {
|
|
150
|
+
[x: string]: AutocompleteTriggerConfig;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* @typedef {Object} AutocompleteTriggerConfig
|
|
155
|
+
* @property {Array<{key: string, [x: string]: any}>} [data] - Static data array. Each item must have a `key` field. Mutually exclusive with `apiUrl`.
|
|
156
|
+
* ```js
|
|
157
|
+
* // data
|
|
158
|
+
* [{ key: 'john', name: 'John Doe', url: '/users/john' }]
|
|
159
|
+
* ```
|
|
160
|
+
* @property {string} [apiUrl] - API endpoint URL. Supports `{key}` and `{limitSize}` placeholders. Mutually exclusive with `data`.
|
|
161
|
+
* @property {Object<string, string>} [apiHeaders] - HTTP headers for the API request.
|
|
162
|
+
* @property {function(Object, XMLHttpRequest): Array<{key: string}>} [transformResponse] - Transforms parsed JSON response into an array of data items.
|
|
163
|
+
* @property {number} [limitSize] - Override global `limitSize` for this trigger.
|
|
164
|
+
* @property {number} [searchStartLength] - Override global `searchStartLength` for this trigger.
|
|
165
|
+
* @property {boolean} [useCachingData] - Override global `useCachingData` for this trigger.
|
|
166
|
+
* @property {boolean} [useCachingFieldData] - Override global `useCachingFieldData` for this trigger.
|
|
167
|
+
* @property {function({key: string, [x: string]: any}, string): string} [renderItem] - Custom dropdown item renderer. Receives `(item, triggerText)`, returns HTML string.
|
|
168
|
+
* @property {function({key: string, [x: string]: any}, string): (string|Element|{tag: string, attrs?: Object, text?: string})} [onSelect] - Custom selection handler. Returns:
|
|
169
|
+
* - `string`: inserted as text node
|
|
170
|
+
* - `Element`: inserted as-is
|
|
171
|
+
* - `{tag, attrs, text}`: creates element via `dom.utils.createElement`
|
|
172
|
+
*/
|
|
173
|
+
/**
|
|
174
|
+
* @typedef {Object} AutocompletePluginOptions
|
|
175
|
+
* @property {number} [delayTime=120] - Debounce delay in ms before processing input.
|
|
176
|
+
* @property {number} [limitSize=5] - Maximum number of items to display in the dropdown.
|
|
177
|
+
* @property {number} [searchStartLength=0] - Minimum input length before triggering search.
|
|
178
|
+
* @property {boolean} [useCachingData=true] - Whether to cache query responses per trigger.
|
|
179
|
+
* @property {boolean} [useCachingFieldData=true] - Whether to cache selected items for priority display.
|
|
180
|
+
* @property {Object<string, AutocompleteTriggerConfig>} triggers - Per-trigger configurations keyed by trigger character.
|
|
181
|
+
* ```js
|
|
182
|
+
* // Basic usage with static data — mention trigger
|
|
183
|
+
* const editor = SUNEDITOR.create('#editor', {
|
|
184
|
+
* plugins: [autocomplete],
|
|
185
|
+
* autocomplete: {
|
|
186
|
+
* triggers: {
|
|
187
|
+
* '@': {
|
|
188
|
+
* data: [
|
|
189
|
+
* { key: 'john', name: 'John Doe' },
|
|
190
|
+
* { key: 'jane', name: 'Jane Smith' },
|
|
191
|
+
* ],
|
|
192
|
+
* },
|
|
193
|
+
* },
|
|
194
|
+
* },
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // API-based trigger with custom rendering and selection
|
|
198
|
+
* const editor = SUNEDITOR.create('#editor', {
|
|
199
|
+
* plugins: [autocomplete],
|
|
200
|
+
* autocomplete: {
|
|
201
|
+
* delayTime: 200,
|
|
202
|
+
* limitSize: 10,
|
|
203
|
+
* triggers: {
|
|
204
|
+
* '@': {
|
|
205
|
+
* apiUrl: '/api/users?q={key}&limit={limitSize}',
|
|
206
|
+
* apiHeaders: { Authorization: 'Bearer TOKEN' },
|
|
207
|
+
* transformResponse: (json) => json.data.map((u) => ({ key: u.username, name: u.displayName, id: u.id })),
|
|
208
|
+
* renderItem: (item) => `<div class="user-item"><strong>${item.key}</strong> <span>${item.name}</span></div>`,
|
|
209
|
+
* onSelect: (item, trigger) => ({
|
|
210
|
+
* tag: 'a',
|
|
211
|
+
* attrs: { href: `/users/${item.id}`, 'data-se-autocomplete': trigger + item.key },
|
|
212
|
+
* text: trigger + item.key,
|
|
213
|
+
* }),
|
|
214
|
+
* },
|
|
215
|
+
* '#': {
|
|
216
|
+
* apiUrl: '/api/tags?q={key}',
|
|
217
|
+
* transformResponse: (json) => json.tags,
|
|
218
|
+
* searchStartLength: 2,
|
|
219
|
+
* useCachingData: false,
|
|
220
|
+
* },
|
|
221
|
+
* },
|
|
222
|
+
* },
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
/**
|
|
227
|
+
* @class
|
|
228
|
+
* @description Autocomplete Plugin
|
|
229
|
+
* - A generic autocomplete plugin supporting multiple trigger characters.
|
|
230
|
+
* - Each trigger can have its own data source, rendering, and selection behavior.
|
|
231
|
+
* - Supports static data arrays and API-based data fetching.
|
|
232
|
+
* - Uses per-trigger caching for optimized performance.
|
|
233
|
+
*/
|
|
234
|
+
declare class Autocomplete extends PluginField {
|
|
235
|
+
/**
|
|
236
|
+
* @constructor
|
|
237
|
+
* @param {SunEditor.Kernel} kernel - The Kernel instance
|
|
238
|
+
* @param {AutocompletePluginOptions} pluginOptions
|
|
239
|
+
*/
|
|
240
|
+
constructor(kernel: SunEditor.Kernel, pluginOptions: AutocompletePluginOptions);
|
|
241
|
+
title: any;
|
|
242
|
+
triggerContexts: Map<any, any>;
|
|
243
|
+
sortedTriggers: any[];
|
|
244
|
+
selectMenu: SelectMenu;
|
|
245
|
+
controller: Controller;
|
|
246
|
+
onInput(params: SunEditor.HookParams.InputWithData): Promise<void>;
|
|
247
|
+
#private;
|
|
248
|
+
}
|
|
249
|
+
import { PluginField } from '../../interfaces';
|
|
250
|
+
import { Controller } from '../../modules/contract';
|
|
251
|
+
import { SelectMenu } from '../../modules/ui';
|
package/types/plugins/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare namespace _default {
|
|
|
6
6
|
export { fileUpload };
|
|
7
7
|
export { list_bulleted };
|
|
8
8
|
export { list_numbered };
|
|
9
|
-
export {
|
|
9
|
+
export { autocomplete };
|
|
10
10
|
export { align };
|
|
11
11
|
export { font };
|
|
12
12
|
export { fontColor };
|
|
@@ -61,7 +61,7 @@ import paragraphStyle from './dropdown/paragraphStyle';
|
|
|
61
61
|
import table from './dropdown/table';
|
|
62
62
|
import template from './dropdown/template';
|
|
63
63
|
import textStyle from './dropdown/textStyle';
|
|
64
|
-
import
|
|
64
|
+
import autocomplete from './field/autocomplete';
|
|
65
65
|
import fontSize from './input/fontSize';
|
|
66
66
|
import pageNavigator from './input/pageNavigator';
|
|
67
67
|
import audio from './modal/audio';
|
|
@@ -77,6 +77,7 @@ export {
|
|
|
77
77
|
anchor,
|
|
78
78
|
audio,
|
|
79
79
|
audioGallery,
|
|
80
|
+
autocomplete,
|
|
80
81
|
backgroundColor,
|
|
81
82
|
blockquote,
|
|
82
83
|
blockStyle,
|
|
@@ -100,7 +101,6 @@ export {
|
|
|
100
101
|
list_bulleted,
|
|
101
102
|
list_numbered,
|
|
102
103
|
math,
|
|
103
|
-
mention,
|
|
104
104
|
pageNavigator,
|
|
105
105
|
paragraphStyle,
|
|
106
106
|
table,
|