suneditor 3.0.0-beta.3 → 3.0.0-beta.30
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/CONTRIBUTING.md +8 -8
- package/README.md +44 -49
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +95 -53
- package/src/assets/design/color.css +2 -2
- package/src/assets/design/size.css +2 -0
- package/src/assets/icons/defaultIcons.js +16 -1
- package/src/assets/suneditor-contents.css +9 -8
- package/src/assets/suneditor.css +29 -26
- package/src/core/{section → base}/actives.js +20 -12
- package/src/core/base/history.js +4 -4
- package/src/core/class/char.js +10 -10
- package/src/core/class/component.js +146 -57
- package/src/core/class/format.js +94 -2458
- package/src/core/class/html.js +187 -129
- package/src/core/class/inline.js +1853 -0
- package/src/core/class/listFormat.js +582 -0
- package/src/core/class/menu.js +14 -3
- package/src/core/class/nodeTransform.js +9 -14
- package/src/core/class/offset.js +162 -197
- package/src/core/class/selection.js +137 -34
- package/src/core/class/toolbar.js +73 -52
- package/src/core/class/ui.js +11 -11
- package/src/core/class/viewer.js +56 -55
- package/src/core/config/context.js +122 -0
- package/src/core/config/frameContext.js +204 -0
- package/src/core/config/options.js +639 -0
- package/src/core/editor.js +181 -108
- package/src/core/event/actions/index.js +229 -0
- package/src/core/event/effects/common.registry.js +60 -0
- package/src/core/event/effects/keydown.registry.js +551 -0
- package/src/core/event/effects/ruleHelpers.js +145 -0
- package/src/core/{base → event}/eventManager.js +119 -201
- package/src/core/event/executor.js +21 -0
- package/src/core/{base/eventHandlers → event/handlers}/handler_toolbar.js +4 -4
- package/src/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.js +2 -2
- package/src/core/event/handlers/handler_ww_input.js +77 -0
- package/src/core/event/handlers/handler_ww_key.js +228 -0
- package/src/core/{base/eventHandlers → event/handlers}/handler_ww_mouse.js +3 -3
- package/src/core/event/ports.js +211 -0
- package/src/core/event/reducers/keydown.reducer.js +89 -0
- package/src/core/event/rules/keydown.rule.arrow.js +54 -0
- package/src/core/event/rules/keydown.rule.backspace.js +202 -0
- package/src/core/event/rules/keydown.rule.delete.js +126 -0
- package/src/core/event/rules/keydown.rule.enter.js +144 -0
- package/src/core/event/rules/keydown.rule.tab.js +29 -0
- package/src/core/section/constructor.js +79 -388
- package/src/core/section/documentType.js +47 -26
- package/src/core/util/instanceCheck.js +59 -0
- package/src/editorInjector/_classes.js +4 -0
- package/src/editorInjector/_core.js +17 -7
- package/src/editorInjector/index.js +10 -2
- package/src/events.js +6 -0
- package/src/helper/clipboard.js +24 -10
- package/src/helper/converter.js +17 -12
- package/src/helper/dom/domCheck.js +22 -3
- package/src/helper/dom/domQuery.js +91 -45
- package/src/helper/dom/domUtils.js +93 -19
- package/src/helper/dom/index.js +4 -0
- package/src/helper/env.js +11 -7
- package/src/helper/keyCodeMap.js +4 -3
- package/src/langs/ckb.js +1 -1
- package/src/langs/cs.js +1 -1
- package/src/langs/da.js +1 -1
- package/src/langs/de.js +1 -1
- package/src/langs/en.js +1 -1
- package/src/langs/es.js +1 -1
- package/src/langs/fa.js +1 -1
- package/src/langs/fr.js +1 -1
- package/src/langs/he.js +1 -1
- package/src/langs/hu.js +1 -1
- package/src/langs/it.js +1 -1
- package/src/langs/ja.js +1 -1
- package/src/langs/km.js +1 -1
- package/src/langs/ko.js +1 -1
- package/src/langs/lv.js +1 -1
- package/src/langs/nl.js +1 -1
- package/src/langs/pl.js +1 -1
- package/src/langs/pt_br.js +10 -10
- package/src/langs/ro.js +1 -1
- package/src/langs/ru.js +1 -1
- package/src/langs/se.js +1 -1
- package/src/langs/tr.js +1 -1
- package/src/langs/uk.js +1 -1
- package/src/langs/ur.js +1 -1
- package/src/langs/zh_cn.js +1 -1
- package/src/modules/ApiManager.js +25 -18
- package/src/modules/Browser.js +52 -61
- package/src/modules/ColorPicker.js +37 -38
- package/src/modules/Controller.js +85 -79
- package/src/modules/Figure.js +275 -187
- package/src/modules/FileManager.js +86 -92
- package/src/modules/HueSlider.js +67 -35
- package/src/modules/Modal.js +84 -77
- package/src/modules/ModalAnchorEditor.js +62 -79
- package/src/modules/SelectMenu.js +89 -86
- package/src/plugins/browser/audioGallery.js +9 -5
- package/src/plugins/browser/fileBrowser.js +10 -6
- package/src/plugins/browser/fileGallery.js +9 -5
- package/src/plugins/browser/imageGallery.js +9 -5
- package/src/plugins/browser/videoGallery.js +11 -6
- package/src/plugins/command/blockquote.js +1 -0
- package/src/plugins/command/exportPDF.js +11 -8
- package/src/plugins/command/fileUpload.js +41 -29
- package/src/plugins/command/list_bulleted.js +2 -1
- package/src/plugins/command/list_numbered.js +2 -1
- package/src/plugins/dropdown/align.js +8 -2
- package/src/plugins/dropdown/backgroundColor.js +19 -11
- package/src/plugins/dropdown/font.js +15 -9
- package/src/plugins/dropdown/fontColor.js +19 -11
- package/src/plugins/dropdown/formatBlock.js +7 -2
- package/src/plugins/dropdown/hr.js +7 -3
- package/src/plugins/dropdown/layout.js +6 -2
- package/src/plugins/dropdown/lineHeight.js +8 -3
- package/src/plugins/dropdown/list.js +2 -1
- package/src/plugins/dropdown/paragraphStyle.js +15 -11
- package/src/plugins/dropdown/{table.js → table/index.js} +514 -362
- package/src/plugins/dropdown/template.js +6 -2
- package/src/plugins/dropdown/textStyle.js +7 -3
- package/src/plugins/field/mention.js +33 -27
- package/src/plugins/input/fontSize.js +44 -37
- package/src/plugins/input/pageNavigator.js +3 -2
- package/src/plugins/modal/audio.js +90 -85
- package/src/plugins/modal/drawing.js +58 -66
- package/src/plugins/modal/embed.js +193 -180
- package/src/plugins/modal/image.js +441 -439
- package/src/plugins/modal/link.js +31 -8
- package/src/plugins/modal/math.js +23 -22
- package/src/plugins/modal/video.js +233 -230
- package/src/plugins/popup/anchor.js +24 -18
- package/src/suneditor.js +69 -24
- package/src/typedef.js +42 -19
- package/types/assets/icons/defaultIcons.d.ts +8 -0
- package/types/core/class/char.d.ts +1 -1
- package/types/core/class/component.d.ts +29 -7
- package/types/core/class/format.d.ts +4 -354
- package/types/core/class/html.d.ts +13 -4
- package/types/core/class/inline.d.ts +263 -0
- package/types/core/class/listFormat.d.ts +135 -0
- package/types/core/class/menu.d.ts +10 -2
- package/types/core/class/offset.d.ts +24 -26
- package/types/core/class/selection.d.ts +2 -0
- package/types/core/class/toolbar.d.ts +24 -11
- package/types/core/class/ui.d.ts +1 -1
- package/types/core/class/viewer.d.ts +1 -1
- package/types/core/config/context.d.ts +157 -0
- package/types/core/config/frameContext.d.ts +367 -0
- package/types/core/config/options.d.ts +1119 -0
- package/types/core/editor.d.ts +101 -66
- package/types/core/event/actions/index.d.ts +47 -0
- package/types/core/event/effects/common.registry.d.ts +50 -0
- package/types/core/event/effects/keydown.registry.d.ts +73 -0
- package/types/core/event/effects/ruleHelpers.d.ts +31 -0
- package/types/core/{base → event}/eventManager.d.ts +15 -46
- package/types/core/event/executor.d.ts +6 -0
- package/types/core/event/handlers/handler_ww_input.d.ts +41 -0
- package/types/core/{base/eventHandlers/handler_ww_key_input.d.ts → event/handlers/handler_ww_key.d.ts} +4 -6
- package/types/core/event/ports.d.ts +255 -0
- package/types/core/event/reducers/keydown.reducer.d.ts +75 -0
- package/types/core/event/rules/keydown.rule.arrow.d.ts +8 -0
- package/types/core/event/rules/keydown.rule.backspace.d.ts +9 -0
- package/types/core/event/rules/keydown.rule.delete.d.ts +9 -0
- package/types/core/event/rules/keydown.rule.enter.d.ts +9 -0
- package/types/core/event/rules/keydown.rule.tab.d.ts +9 -0
- package/types/core/section/constructor.d.ts +101 -631
- package/types/core/section/documentType.d.ts +14 -4
- package/types/core/util/instanceCheck.d.ts +50 -0
- package/types/editorInjector/_classes.d.ts +4 -0
- package/types/editorInjector/_core.d.ts +17 -7
- package/types/editorInjector/index.d.ts +10 -2
- package/types/events.d.ts +1 -0
- package/types/helper/clipboard.d.ts +2 -2
- package/types/helper/converter.d.ts +6 -9
- package/types/helper/dom/domCheck.d.ts +7 -0
- package/types/helper/dom/domQuery.d.ts +19 -8
- package/types/helper/dom/domUtils.d.ts +24 -2
- package/types/helper/dom/index.d.ts +86 -1
- package/types/helper/env.d.ts +6 -1
- package/types/helper/index.d.ts +7 -1
- package/types/helper/keyCodeMap.d.ts +3 -3
- package/types/index.d.ts +23 -117
- package/types/langs/index.d.ts +2 -2
- package/types/modules/ApiManager.d.ts +1 -8
- package/types/modules/Browser.d.ts +4 -62
- package/types/modules/ColorPicker.d.ts +4 -21
- package/types/modules/Controller.d.ts +8 -64
- package/types/modules/Figure.d.ts +54 -50
- package/types/modules/FileManager.d.ts +1 -13
- package/types/modules/HueSlider.d.ts +13 -3
- package/types/modules/Modal.d.ts +0 -43
- package/types/modules/ModalAnchorEditor.d.ts +0 -73
- package/types/modules/SelectMenu.d.ts +0 -85
- package/types/modules/index.d.ts +3 -3
- package/types/plugins/browser/audioGallery.d.ts +29 -18
- package/types/plugins/browser/fileBrowser.d.ts +38 -27
- package/types/plugins/browser/fileGallery.d.ts +29 -18
- package/types/plugins/browser/imageGallery.d.ts +24 -16
- package/types/plugins/browser/videoGallery.d.ts +29 -18
- package/types/plugins/command/blockquote.d.ts +1 -0
- package/types/plugins/command/exportPDF.d.ts +18 -18
- package/types/plugins/command/fileUpload.d.ts +65 -45
- package/types/plugins/command/list_bulleted.d.ts +1 -0
- package/types/plugins/command/list_numbered.d.ts +1 -0
- package/types/plugins/dropdown/align.d.ts +13 -8
- package/types/plugins/dropdown/backgroundColor.d.ts +30 -19
- package/types/plugins/dropdown/font.d.ts +13 -12
- package/types/plugins/dropdown/fontColor.d.ts +30 -19
- package/types/plugins/dropdown/formatBlock.d.ts +13 -8
- package/types/plugins/dropdown/hr.d.ts +15 -11
- package/types/plugins/dropdown/layout.d.ts +15 -11
- package/types/plugins/dropdown/lineHeight.d.ts +16 -11
- package/types/plugins/dropdown/list.d.ts +1 -0
- package/types/plugins/dropdown/paragraphStyle.d.ts +31 -27
- package/types/plugins/dropdown/table/index.d.ts +582 -0
- package/types/plugins/dropdown/table.d.ts +41 -86
- package/types/plugins/dropdown/template.d.ts +15 -11
- package/types/plugins/dropdown/textStyle.d.ts +19 -11
- package/types/plugins/field/mention.d.ts +58 -56
- package/types/plugins/index.d.ts +38 -38
- package/types/plugins/input/fontSize.d.ts +46 -50
- package/types/plugins/modal/audio.d.ts +26 -56
- package/types/plugins/modal/drawing.d.ts +0 -85
- package/types/plugins/modal/embed.d.ts +15 -79
- package/types/plugins/modal/image.d.ts +24 -136
- package/types/plugins/modal/link.d.ts +34 -15
- package/types/plugins/modal/math.d.ts +0 -16
- package/types/plugins/modal/video.d.ts +17 -86
- package/types/plugins/popup/anchor.d.ts +1 -8
- package/types/suneditor.d.ts +70 -19
- package/types/typedef.d.ts +60 -46
- package/src/core/base/eventHandlers/handler_ww_key_input.js +0 -1200
- package/src/core/section/context.js +0 -102
- package/types/core/section/context.d.ts +0 -45
- package/types/langs/_Lang.d.ts +0 -194
- /package/src/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.js +0 -0
- /package/types/core/{section → base}/actives.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_toolbar.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_clipboard.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_dragDrop.d.ts +0 -0
- /package/types/core/{base/eventHandlers → event/handlers}/handler_ww_mouse.d.ts +0 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import EditorInjector from '../../editorInjector';
|
|
2
2
|
import { dom } from '../../helper';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} TemplatePluginOptions
|
|
6
|
+
* @property {Array<{name: string, html: string}>} [items] - Template list
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* @class
|
|
6
11
|
* @description Template Plugin, Apply a template to the selection.
|
|
@@ -13,8 +18,7 @@ class Template extends EditorInjector {
|
|
|
13
18
|
/**
|
|
14
19
|
* @constructor
|
|
15
20
|
* @param {__se__EditorCore} editor - The root editor instance
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {Array<{name: string, html: string}>} pluginOptions.items - Template list
|
|
21
|
+
* @param {TemplatePluginOptions} pluginOptions - Plugin options
|
|
18
22
|
*/
|
|
19
23
|
constructor(editor, pluginOptions) {
|
|
20
24
|
// plugin bisic properties
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import EditorInjector from '../../editorInjector';
|
|
2
2
|
import { dom } from '../../helper';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} TextStylePluginOptions
|
|
6
|
+
* @property {Array<string|{name: string, class: string, tag: string}>} items - Text style item list
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* @class
|
|
6
11
|
* @description Text style Plugin, Applies a tag that specifies text styles to a selection.
|
|
@@ -13,8 +18,7 @@ class TextStyle extends EditorInjector {
|
|
|
13
18
|
/**
|
|
14
19
|
* @constructor
|
|
15
20
|
* @param {__se__EditorCore} editor - The root editor instance
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {Array<{name: string, html: string}>} pluginOptions.items - Template list
|
|
21
|
+
* @param {TextStylePluginOptions} pluginOptions - Plugin options
|
|
18
22
|
*/
|
|
19
23
|
constructor(editor, pluginOptions) {
|
|
20
24
|
// plugin bisic properties
|
|
@@ -84,7 +88,7 @@ class TextStyle extends EditorInjector {
|
|
|
84
88
|
|
|
85
89
|
const newNode = dom.utils.hasClass(target, 'active') ? null : tempElement.cloneNode(false);
|
|
86
90
|
const removeNodes = newNode ? null : [tempElement.nodeName];
|
|
87
|
-
this.
|
|
91
|
+
this.inline.apply(newNode, { stylesToModify: checkStyles, nodesToRemove: removeNodes, strictRemove: true });
|
|
88
92
|
|
|
89
93
|
this.menu.dropdownOff();
|
|
90
94
|
}
|
|
@@ -4,6 +4,19 @@ import { dom, converter } from '../../helper';
|
|
|
4
4
|
|
|
5
5
|
const { debounce } = converter;
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} MentionPluginOptions
|
|
9
|
+
* @property {string} [triggerText="@"] - The character that triggers the mention list
|
|
10
|
+
* @property {number} [limitSize=5] - The number of items to display in the mention list
|
|
11
|
+
* @property {number} [searchStartLength=0] - The number of characters to start searching for the mention list
|
|
12
|
+
* @property {number} [delayTime=200] - The time to wait before displaying the mention list
|
|
13
|
+
* @property {Array<{key: string, name: string, url: string}>} [data] - Use data without using API
|
|
14
|
+
* @property {string} [apiUrl] - The URL to call the mention list
|
|
15
|
+
* @property {Object<string, string>} [apiHeaders] - The headers to send with the API call
|
|
16
|
+
* @property {boolean} [useCachingData=true] - Whether to cache the mention list data
|
|
17
|
+
* @property {boolean} [useCachingFieldData=true] - Whether to cache the mention list data in the field
|
|
18
|
+
*/
|
|
19
|
+
|
|
7
20
|
/**
|
|
8
21
|
* @class
|
|
9
22
|
* @description Mention Plugin
|
|
@@ -17,19 +30,14 @@ class Mention extends EditorInjector {
|
|
|
17
30
|
static type = 'field';
|
|
18
31
|
static className = '';
|
|
19
32
|
|
|
33
|
+
#lastAtPos;
|
|
34
|
+
#anchorOffset;
|
|
35
|
+
#anchorNode;
|
|
36
|
+
|
|
20
37
|
/**
|
|
21
38
|
* @constructor
|
|
22
39
|
* @param {__se__EditorCore} editor - The root editor instance
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {string=} [pluginOptions.triggerText="@"] The character that triggers the mention list. Default is '@'.
|
|
25
|
-
* @param {number=} [pluginOptions.limitSize=5] The number of items to display in the mention list. Default is 5.
|
|
26
|
-
* @param {number=} [pluginOptions.searchStartLength=0] The number of characters to start searching for the mention list. Default is 0.
|
|
27
|
-
* @param {number=} [pluginOptions.delayTime=200] The time to wait before displaying the mention list. Default is 200ms.
|
|
28
|
-
* @param {Array<{key: string, name: string, url: string}>=} pluginOptions.data Use data without using API.
|
|
29
|
-
* @param {string=} pluginOptions.apiUrl The URL to call the mention list. Default is ''.
|
|
30
|
-
* @param {Object<string, string>=} pluginOptions.apiHeaders The headers to send with the API call. Default is {}.
|
|
31
|
-
* @param {boolean=} [pluginOptions.useCachingData=true] Whether to cache the mention list data. Default is true.
|
|
32
|
-
* @param {boolean=} [pluginOptions.useCachingFieldData=true] Whether to cache the mention list data in the field. Default is true.
|
|
40
|
+
* @param {MentionPluginOptions} pluginOptions
|
|
33
41
|
*/
|
|
34
42
|
constructor(editor, pluginOptions) {
|
|
35
43
|
super(editor);
|
|
@@ -44,14 +52,14 @@ class Mention extends EditorInjector {
|
|
|
44
52
|
this.delayTime = typeof pluginOptions.delayTime === 'number' ? pluginOptions.delayTime : 200;
|
|
45
53
|
this.directData = pluginOptions.data;
|
|
46
54
|
this.apiUrl = pluginOptions.apiUrl?.replace(/\s/g, '').replace(/\{limitSize\}/i, String(this.limitSize)) || '';
|
|
47
|
-
this._delay = 0;
|
|
48
|
-
this._lastAtPos = 0;
|
|
49
|
-
this._anchorOffset = 0;
|
|
50
|
-
this._anchorNode = null;
|
|
51
55
|
// members - api, caching
|
|
52
56
|
this.apiManager = new ApiManager(this, { headers: pluginOptions.apiHeaders });
|
|
53
|
-
this.cachingData = pluginOptions.useCachingData ?? true ? new Map() : null;
|
|
54
|
-
this.cachingFieldData = pluginOptions.useCachingFieldData ?? true ? [] : null;
|
|
57
|
+
this.cachingData = (pluginOptions.useCachingData ?? true) ? new Map() : null;
|
|
58
|
+
this.cachingFieldData = (pluginOptions.useCachingFieldData ?? true) ? [] : null;
|
|
59
|
+
|
|
60
|
+
this.#lastAtPos = 0;
|
|
61
|
+
this.#anchorOffset = 0;
|
|
62
|
+
this.#anchorNode = null;
|
|
55
63
|
|
|
56
64
|
// controller
|
|
57
65
|
const controllerEl = CreateHTML_controller();
|
|
@@ -107,10 +115,10 @@ class Mention extends EditorInjector {
|
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
try {
|
|
110
|
-
const result = await this
|
|
111
|
-
this
|
|
112
|
-
this
|
|
113
|
-
this
|
|
118
|
+
const result = await this.#createMentionList(mentionQuery, anchorNode);
|
|
119
|
+
this.#lastAtPos = lastAtPos;
|
|
120
|
+
this.#anchorNode = anchorNode;
|
|
121
|
+
this.#anchorOffset = anchorOffset;
|
|
114
122
|
return !result;
|
|
115
123
|
} catch (error) {
|
|
116
124
|
console.warn('[SUNEDITOR.mention.api.file] ', error);
|
|
@@ -123,7 +131,6 @@ class Mention extends EditorInjector {
|
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
/**
|
|
126
|
-
* @private
|
|
127
134
|
* @description Generates the mention list based on user input.
|
|
128
135
|
* - Fetches data from cache, direct data, or an API.
|
|
129
136
|
* - Creates and opens the mention dropdown.
|
|
@@ -132,7 +139,7 @@ class Mention extends EditorInjector {
|
|
|
132
139
|
* @param {Node} targetNode - The node where the mention is triggered.
|
|
133
140
|
* @returns {Promise<boolean>} - Returns `true` if the mention list is displayed, `false` otherwise.
|
|
134
141
|
*/
|
|
135
|
-
async
|
|
142
|
+
async #createMentionList(value, targetNode) {
|
|
136
143
|
const limit = this.limitSize;
|
|
137
144
|
const lowerValue = value.toLowerCase();
|
|
138
145
|
let response = null;
|
|
@@ -144,7 +151,7 @@ class Mention extends EditorInjector {
|
|
|
144
151
|
if (this.directData) {
|
|
145
152
|
response = this.directData.filter((item) => item.key.toLowerCase().startsWith(lowerValue)).slice(0, limit);
|
|
146
153
|
} else {
|
|
147
|
-
const xmlHttp = await this.apiManager.asyncCall({ method: 'GET', url: this
|
|
154
|
+
const xmlHttp = await this.apiManager.asyncCall({ method: 'GET', url: this.#createUrl(value) });
|
|
148
155
|
response = JSON.parse(xmlHttp.responseText);
|
|
149
156
|
}
|
|
150
157
|
}
|
|
@@ -190,12 +197,11 @@ class Mention extends EditorInjector {
|
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
/**
|
|
193
|
-
* @private
|
|
194
200
|
* @description Constructs the API request URL with the mention query.
|
|
195
201
|
* @param {string} key - The mention query text.
|
|
196
202
|
* @returns {string} - The formatted API request URL.
|
|
197
203
|
*/
|
|
198
|
-
|
|
204
|
+
#createUrl(key) {
|
|
199
205
|
return this.apiUrl.replace(/\{key\}/i, key);
|
|
200
206
|
}
|
|
201
207
|
|
|
@@ -209,7 +215,7 @@ class Mention extends EditorInjector {
|
|
|
209
215
|
|
|
210
216
|
let oA = null;
|
|
211
217
|
const { key, name, url } = item;
|
|
212
|
-
const anchorParent = this.
|
|
218
|
+
const anchorParent = this.#anchorNode.parentNode;
|
|
213
219
|
|
|
214
220
|
if (dom.check.isAnchor(anchorParent)) {
|
|
215
221
|
oA = anchorParent;
|
|
@@ -218,7 +224,7 @@ class Mention extends EditorInjector {
|
|
|
218
224
|
oA.setAttribute('title', name);
|
|
219
225
|
oA.textContent = this.triggerText + key;
|
|
220
226
|
} else {
|
|
221
|
-
this.selection.setRange(this
|
|
227
|
+
this.selection.setRange(this.#anchorNode, this.#lastAtPos, this.#anchorNode, this.#anchorOffset);
|
|
222
228
|
oA = dom.utils.createElement('A', { 'data-se-mention': key, href: url, title: name, target: '_blank' }, this.triggerText + key);
|
|
223
229
|
if (!this.html.insertNode(oA, { afterNode: null, skipCharCount: false })) return false;
|
|
224
230
|
}
|
|
@@ -85,6 +85,17 @@ const DEFAULT_UNIT_MAP = {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* @typedef {Object} FontSizePluginOptions
|
|
90
|
+
* @property {string} [sizeUnit='px'] - The unit for the font size.
|
|
91
|
+
* - Accepted values include: 'px', 'pt', 'em', 'rem', 'vw', 'vh', '%' or 'text'.
|
|
92
|
+
* - If 'text' is used, a text-based font size list is applied.
|
|
93
|
+
* @property {boolean} [showDefaultSizeLabel=true] - Determines whether the default size label is displayed in the dropdown menu.
|
|
94
|
+
* @property {boolean} [showIncDecControls=false] - When true, displays increase and decrease buttons for font size adjustments.
|
|
95
|
+
* @property {boolean} [disableInput=true] - When true, disables the direct font size input box.
|
|
96
|
+
* @property {Object<string, {default: number, inc: number, min: number, max: number, list: Array<number>}>} [unitMap={}] - Optional object to override or extend the default unit mapping for font sizes.
|
|
97
|
+
*/
|
|
98
|
+
|
|
88
99
|
/**
|
|
89
100
|
* @class
|
|
90
101
|
* @description FontSize Plugin
|
|
@@ -97,17 +108,12 @@ class FontSize extends EditorInjector {
|
|
|
97
108
|
static type = 'input';
|
|
98
109
|
static className = 'se-btn-select se-btn-input se-btn-tool-font-size';
|
|
99
110
|
|
|
111
|
+
#disableInput;
|
|
112
|
+
|
|
100
113
|
/**
|
|
101
114
|
* @constructor
|
|
102
115
|
* @param {__se__EditorCore} editor - The root editor instance
|
|
103
|
-
* @param {
|
|
104
|
-
* @param {string=} [pluginOptions.sizeUnit='px'] - The unit for the font size.
|
|
105
|
-
* - Accepted values include: 'px', 'pt', 'em', 'rem', 'vw', 'vh', '%' or 'text'.
|
|
106
|
-
* - If 'text' is used, a text-based font size list is applied.
|
|
107
|
-
* @param {boolean=} [pluginOptions.showDefaultSizeLabel=true] - Determines whether the default size label is displayed in the dropdown menu.
|
|
108
|
-
* @param {boolean=} [pluginOptions.showIncDecControls=false] - When true, displays increase and decrease buttons for font size adjustments.
|
|
109
|
-
* @param {boolean=} [pluginOptions.disableInput=true] - When true, disables the direct font size input box.
|
|
110
|
-
* @param {Object<string, {default: number, inc: number, min: number, max: number, list: Array<number>}>} [pluginOptions.unitMap={}] - Optional object to override or extend the default unit mapping for font sizes.
|
|
116
|
+
* @param {FontSizePluginOptions} pluginOptions - Configuration options for the FontSize plugin.
|
|
111
117
|
*/
|
|
112
118
|
constructor(editor, pluginOptions) {
|
|
113
119
|
super(editor);
|
|
@@ -120,16 +126,16 @@ class FontSize extends EditorInjector {
|
|
|
120
126
|
const menu = CreateHTML(editor, unitMap, this.sizeUnit, pluginOptions.showDefaultSizeLabel);
|
|
121
127
|
|
|
122
128
|
// plugin basic properties
|
|
123
|
-
const showIncDec = this.sizeUnit ? pluginOptions.showIncDecControls ?? false : false;
|
|
124
|
-
const disableInput = this.sizeUnit ? pluginOptions.disableInput ?? false : true;
|
|
129
|
+
const showIncDec = this.sizeUnit ? (pluginOptions.showIncDecControls ?? false) : false;
|
|
130
|
+
const disableInput = this.sizeUnit ? (pluginOptions.disableInput ?? false) : true;
|
|
125
131
|
|
|
126
132
|
this.title = this.lang.fontSize;
|
|
127
133
|
this.inner =
|
|
128
134
|
disableInput && !showIncDec
|
|
129
135
|
? false
|
|
130
136
|
: disableInput
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
? `<span class="se-txt se-not-arrow-text __se__font_size">${this.lang.fontSize}</span>`
|
|
138
|
+
: `<input type="text" class="__se__font_size se-not-arrow-text" placeholder="${this.lang.fontSize}" />`;
|
|
133
139
|
|
|
134
140
|
// increase, decrease buttons
|
|
135
141
|
if (showIncDec) {
|
|
@@ -164,7 +170,7 @@ class FontSize extends EditorInjector {
|
|
|
164
170
|
this.sizeList = menu.querySelectorAll('li button');
|
|
165
171
|
this.hasInputFocus = false;
|
|
166
172
|
this.isInputActive = false; // input target event
|
|
167
|
-
this
|
|
173
|
+
this.#disableInput = disableInput;
|
|
168
174
|
|
|
169
175
|
// init
|
|
170
176
|
this.menu.initDropdownTarget(FontSize, menu);
|
|
@@ -176,14 +182,18 @@ class FontSize extends EditorInjector {
|
|
|
176
182
|
* @param {?HTMLElement=} element - Node element where the cursor is currently located
|
|
177
183
|
* @param {?HTMLElement=} target - The plugin's toolbar button element
|
|
178
184
|
* @returns {boolean} - Whether the plugin is active
|
|
185
|
+
* - If it returns "undefined", it will no longer be called in this scope.
|
|
179
186
|
*/
|
|
180
187
|
active(element, target) {
|
|
181
188
|
if (!dom.utils.hasClass(target, '__se__font_size')) return false;
|
|
182
189
|
|
|
190
|
+
let fontSize = '';
|
|
183
191
|
if (!element) {
|
|
184
|
-
this
|
|
185
|
-
} else if (
|
|
186
|
-
|
|
192
|
+
this.#setSize(target, this.#getDefaultSize());
|
|
193
|
+
} else if (this.format.isLine(element)) {
|
|
194
|
+
return undefined;
|
|
195
|
+
} else if ((fontSize = dom.utils.getStyle(element, 'fontSize'))) {
|
|
196
|
+
this.#setSize(target, fontSize);
|
|
187
197
|
return true;
|
|
188
198
|
}
|
|
189
199
|
|
|
@@ -200,14 +210,14 @@ class FontSize extends EditorInjector {
|
|
|
200
210
|
onInputKeyDown({ target, event }) {
|
|
201
211
|
const keyCode = event.code;
|
|
202
212
|
|
|
203
|
-
if (this
|
|
213
|
+
if (this.#disableInput || keyCodeMap.isSpace(keyCode)) {
|
|
204
214
|
event.preventDefault();
|
|
205
215
|
return;
|
|
206
216
|
}
|
|
207
217
|
|
|
208
218
|
if (!/^(38|40|13)$/.test(keyCode)) return;
|
|
209
219
|
|
|
210
|
-
const { value, unit } = this
|
|
220
|
+
const { value, unit } = this.#getSize(target);
|
|
211
221
|
if (!value) return;
|
|
212
222
|
|
|
213
223
|
const numValue = numbers.get(value);
|
|
@@ -227,11 +237,11 @@ class FontSize extends EditorInjector {
|
|
|
227
237
|
|
|
228
238
|
try {
|
|
229
239
|
this.isInputActive = true;
|
|
230
|
-
const size = this
|
|
231
|
-
if (this
|
|
240
|
+
const size = this.#setSize(target, changeValue + unit);
|
|
241
|
+
if (this.#disableInput) return;
|
|
232
242
|
|
|
233
243
|
const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + size + ';' });
|
|
234
|
-
this.
|
|
244
|
+
this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
|
|
235
245
|
|
|
236
246
|
if (!keyCodeMap.isEnter(keyCode)) target.focus();
|
|
237
247
|
} finally {
|
|
@@ -245,18 +255,18 @@ class FontSize extends EditorInjector {
|
|
|
245
255
|
* @param {__se__PluginToolbarInputChangeEventInfo} params
|
|
246
256
|
*/
|
|
247
257
|
onInputChange({ target, value: changeValue, event }) {
|
|
248
|
-
if (this
|
|
258
|
+
if (this.#disableInput) return;
|
|
249
259
|
|
|
250
260
|
try {
|
|
251
261
|
this.isInputActive = true;
|
|
252
262
|
|
|
253
263
|
// eslint-disable-next-line prefer-const
|
|
254
|
-
let { value, unit } = this
|
|
264
|
+
let { value, unit } = this.#getSize(changeValue);
|
|
255
265
|
const { max, min } = this.unitMap[unit];
|
|
256
266
|
value = value > max ? max : value < min ? min : value;
|
|
257
267
|
|
|
258
|
-
const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + this
|
|
259
|
-
this.
|
|
268
|
+
const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + this.#setSize(target, value + unit) + ';' });
|
|
269
|
+
this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
|
|
260
270
|
} finally {
|
|
261
271
|
this.isInputActive = false;
|
|
262
272
|
event.preventDefault();
|
|
@@ -270,7 +280,7 @@ class FontSize extends EditorInjector {
|
|
|
270
280
|
* @param {HTMLElement} target Line element at the current cursor position
|
|
271
281
|
*/
|
|
272
282
|
on(target) {
|
|
273
|
-
const { value, unit } = this
|
|
283
|
+
const { value, unit } = this.#getSize(target);
|
|
274
284
|
const currentSize = value + unit;
|
|
275
285
|
|
|
276
286
|
if (currentSize === this.currentSize) return;
|
|
@@ -297,41 +307,39 @@ class FontSize extends EditorInjector {
|
|
|
297
307
|
const commandValue = target.getAttribute('data-command');
|
|
298
308
|
|
|
299
309
|
if (commandValue === FontSize.key) {
|
|
300
|
-
const { value, unit } = this
|
|
310
|
+
const { value, unit } = this.#getSize(target);
|
|
301
311
|
let newSize = numbers.get(value) + (target.getAttribute('data-value') === 'inc' ? 1 : -1);
|
|
302
312
|
const { min, max } = this.unitMap[unit];
|
|
303
313
|
newSize = newSize < min ? min : newSize > max ? max : newSize;
|
|
304
314
|
|
|
305
315
|
const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + newSize + unit + ';' });
|
|
306
|
-
this.
|
|
316
|
+
this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
|
|
307
317
|
} else if (commandValue) {
|
|
308
318
|
const newNode = dom.utils.createElement('SPAN', { style: 'font-size: ' + commandValue + ';' });
|
|
309
|
-
this.
|
|
319
|
+
this.inline.apply(newNode, { stylesToModify: ['font-size'], nodesToRemove: null, strictRemove: null });
|
|
310
320
|
} else {
|
|
311
|
-
this.
|
|
321
|
+
this.inline.apply(null, { stylesToModify: ['font-size'], nodesToRemove: ['span'], strictRemove: true });
|
|
312
322
|
}
|
|
313
323
|
|
|
314
324
|
this.menu.dropdownOff();
|
|
315
325
|
}
|
|
316
326
|
|
|
317
327
|
/**
|
|
318
|
-
* @private
|
|
319
328
|
* @description Retrieves the default font size of the editor.
|
|
320
329
|
* @returns {string} - The computed font size from the editor.
|
|
321
330
|
*/
|
|
322
|
-
|
|
323
|
-
return this.
|
|
331
|
+
#getDefaultSize() {
|
|
332
|
+
return this.frameContext.get('wwComputedStyle').fontSize;
|
|
324
333
|
}
|
|
325
334
|
|
|
326
335
|
/**
|
|
327
|
-
* @private
|
|
328
336
|
* @description Extracts the font size and unit from the given element or input value.
|
|
329
337
|
* @param {string|Element} target - The target input or element.
|
|
330
338
|
* @returns {{ unit: string, value: number|string }} - An object containing:
|
|
331
339
|
* - `unit` (string): The detected font size unit.
|
|
332
340
|
* - `value` (number|string): The numeric font size value or text-based size.
|
|
333
341
|
*/
|
|
334
|
-
|
|
342
|
+
#getSize(target) {
|
|
335
343
|
target = typeof target === 'string' ? target : target.parentElement.querySelector('.__se__font_size');
|
|
336
344
|
if (!target)
|
|
337
345
|
return {
|
|
@@ -355,13 +363,12 @@ class FontSize extends EditorInjector {
|
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
/**
|
|
358
|
-
* @private
|
|
359
366
|
* @description Sets the font size in the toolbar input field or button label.
|
|
360
367
|
* @param {HTMLElement} target - The target element in the toolbar.
|
|
361
368
|
* @param {string|number} value - The font size value.
|
|
362
369
|
* @returns {string|number} - The applied font size.
|
|
363
370
|
*/
|
|
364
|
-
|
|
371
|
+
#setSize(target, value) {
|
|
365
372
|
target = target.parentElement.querySelector('.__se__font_size');
|
|
366
373
|
if (!target) return 0;
|
|
367
374
|
|
|
@@ -33,6 +33,7 @@ class PageNavigator extends EditorInjector {
|
|
|
33
33
|
// init
|
|
34
34
|
this.eventManager.addEvent(this.inner, 'change', this.#OnChangeInner.bind(this));
|
|
35
35
|
}
|
|
36
|
+
|
|
36
37
|
/**
|
|
37
38
|
* @editorMethod Editor.documentType
|
|
38
39
|
* @description Updates the displayed page number and total pages in the navigator.
|
|
@@ -53,13 +54,13 @@ class PageNavigator extends EditorInjector {
|
|
|
53
54
|
* @param {InputEvent} e - Event object
|
|
54
55
|
*/
|
|
55
56
|
#OnChangeInner(e) {
|
|
56
|
-
if (!this.
|
|
57
|
+
if (!this.frameContext.has('documentType_use_page')) return;
|
|
57
58
|
|
|
58
59
|
/** @type {HTMLInputElement} */
|
|
59
60
|
const eventTarget = dom.query.getEventTarget(e);
|
|
60
61
|
|
|
61
62
|
const value = Number(eventTarget.value) || 1;
|
|
62
|
-
this.
|
|
63
|
+
this.frameContext.get('documentType').pageGo(value);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|