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
package/src/langs/ko.js
CHANGED
package/src/langs/lv.js
CHANGED
package/src/langs/nl.js
CHANGED
package/src/langs/pl.js
CHANGED
package/src/langs/pt_br.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
throw new Error('SUNEDITOR_LANG a window with a document');
|
|
10
10
|
}
|
|
11
11
|
return factory(w);
|
|
12
|
-
|
|
12
|
+
};
|
|
13
13
|
} else {
|
|
14
14
|
factory(global);
|
|
15
15
|
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
audioGallery: 'Galeria de áudio',
|
|
33
33
|
audio_modal_file: 'Selecionar arquivos',
|
|
34
34
|
audio_modal_title: 'Inserir áudio',
|
|
35
|
-
audio_modal_url: 'URL
|
|
35
|
+
audio_modal_url: 'URL do áudio',
|
|
36
36
|
autoSize: 'Tamanho automático',
|
|
37
37
|
backgroundColor: 'Cor de destaque',
|
|
38
38
|
basic: 'Básico',
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
fileUpload: 'Upload de arquivo',
|
|
89
89
|
fixedColumnWidth: 'Largura fixa da coluna',
|
|
90
90
|
font: 'Fonte',
|
|
91
|
-
fontColor: 'Cor da
|
|
91
|
+
fontColor: 'Cor da fonte',
|
|
92
92
|
fontSize: 'Tamanho',
|
|
93
93
|
formats: 'Formatos',
|
|
94
94
|
fullScreen: 'Tela cheia',
|
|
@@ -120,10 +120,10 @@
|
|
|
120
120
|
link: 'Link',
|
|
121
121
|
link_modal_bookmark: 'marcar páginas',
|
|
122
122
|
link_modal_downloadLinkCheck: 'Link para Download',
|
|
123
|
-
link_modal_newWindowCheck: 'Abrir em nova guia',
|
|
124
|
-
link_modal_text: 'Texto
|
|
123
|
+
link_modal_newWindowCheck: 'Abrir em uma nova guia',
|
|
124
|
+
link_modal_text: 'Texto exibido',
|
|
125
125
|
link_modal_title: 'Inserir link',
|
|
126
|
-
link_modal_url: '
|
|
126
|
+
link_modal_url: 'Endereço do link',
|
|
127
127
|
link_modal_relAttribute: 'Atributo rel',
|
|
128
128
|
list: 'Lista',
|
|
129
129
|
math: 'Matemática',
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
ratio: 'Proporções',
|
|
159
159
|
redo: 'Refazer',
|
|
160
160
|
remove: 'Remover',
|
|
161
|
-
removeFormat: 'Remover
|
|
161
|
+
removeFormat: 'Remover formatação',
|
|
162
162
|
replace: 'Substituir',
|
|
163
163
|
replaceAll: 'Substituir todos',
|
|
164
164
|
resize100: 'Zoom 100%',
|
|
@@ -178,9 +178,9 @@
|
|
|
178
178
|
showBlocks: 'Mostrar blocos',
|
|
179
179
|
size: 'Tamanho',
|
|
180
180
|
splitCells: 'Dividir células',
|
|
181
|
-
strike: '
|
|
181
|
+
strike: 'Tachado',
|
|
182
182
|
submitButton: 'Enviar',
|
|
183
|
-
subscript: '
|
|
183
|
+
subscript: 'Subscrito',
|
|
184
184
|
superscript: 'Sobrescrito',
|
|
185
185
|
table: 'Tabela',
|
|
186
186
|
tableHeader: 'Cabeçalho da tabela',
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
tag_blockquote: 'Citar',
|
|
190
190
|
tag_div: '(DIV) Normal',
|
|
191
191
|
tag_h: 'Cabeçalho',
|
|
192
|
-
tag_p: '
|
|
192
|
+
tag_p: 'Parágrafo',
|
|
193
193
|
tag_pre: 'Código',
|
|
194
194
|
template: 'Modelo',
|
|
195
195
|
textStyle: 'Estilo do texto',
|
package/src/langs/ro.js
CHANGED
package/src/langs/ru.js
CHANGED
package/src/langs/se.js
CHANGED
package/src/langs/tr.js
CHANGED
package/src/langs/uk.js
CHANGED
package/src/langs/ur.js
CHANGED
package/src/langs/zh_cn.js
CHANGED
|
@@ -16,6 +16,9 @@ import { env } from '../helper';
|
|
|
16
16
|
* @description API Manager
|
|
17
17
|
*/
|
|
18
18
|
class ApiManager {
|
|
19
|
+
/** @type {XMLHttpRequest} */
|
|
20
|
+
#xhr;
|
|
21
|
+
|
|
19
22
|
/**
|
|
20
23
|
* @constructor
|
|
21
24
|
* @param {*} inst The instance object that called the constructor.
|
|
@@ -41,7 +44,7 @@ class ApiManager {
|
|
|
41
44
|
this.kind = inst.constructor.key || inst.constructor.name;
|
|
42
45
|
|
|
43
46
|
// members
|
|
44
|
-
this
|
|
47
|
+
this.#xhr = env.getXMLHttpRequest();
|
|
45
48
|
// members - option
|
|
46
49
|
this.method = params?.method;
|
|
47
50
|
this.url = params?.url;
|
|
@@ -59,15 +62,20 @@ class ApiManager {
|
|
|
59
62
|
call({ method, url, headers, data, callBack, errorCallBack, responseType }) {
|
|
60
63
|
this.cancel();
|
|
61
64
|
|
|
62
|
-
method
|
|
63
|
-
url = this
|
|
64
|
-
headers
|
|
65
|
-
data
|
|
66
|
-
callBack
|
|
67
|
-
errorCallBack
|
|
68
|
-
responseType
|
|
65
|
+
method ||= this.method;
|
|
66
|
+
url = this.#normalizeUrl(url || this.url);
|
|
67
|
+
headers ||= this.headers;
|
|
68
|
+
data ||= this.data;
|
|
69
|
+
callBack ||= this.callBack;
|
|
70
|
+
errorCallBack ||= this.errorCallBack;
|
|
71
|
+
responseType ||= this.responseType;
|
|
72
|
+
|
|
73
|
+
// Validate required callback parameter
|
|
74
|
+
if (typeof callBack !== 'function') {
|
|
75
|
+
throw new Error(`[SUNEDITOR.ApiManager[${this.kind}].upload.callBack.fail] callBack is not a function`);
|
|
76
|
+
}
|
|
69
77
|
|
|
70
|
-
const xhr = this
|
|
78
|
+
const xhr = this.#xhr;
|
|
71
79
|
if (responseType) xhr.responseType = responseType;
|
|
72
80
|
xhr.onreadystatechange = CallBackApi.bind(this, xhr, callBack, errorCallBack);
|
|
73
81
|
xhr.open(method, url, true);
|
|
@@ -93,13 +101,13 @@ class ApiManager {
|
|
|
93
101
|
asyncCall({ method, url, headers, data, responseType }) {
|
|
94
102
|
this.cancel();
|
|
95
103
|
|
|
96
|
-
method
|
|
97
|
-
url = this
|
|
98
|
-
headers
|
|
99
|
-
data
|
|
100
|
-
responseType
|
|
104
|
+
method ||= this.method;
|
|
105
|
+
url = this.#normalizeUrl(url || this.url);
|
|
106
|
+
headers ||= this.headers;
|
|
107
|
+
data ||= this.data;
|
|
108
|
+
responseType ||= this.responseType;
|
|
101
109
|
|
|
102
|
-
const xhr = this
|
|
110
|
+
const xhr = this.#xhr;
|
|
103
111
|
if (responseType) xhr.responseType = responseType;
|
|
104
112
|
|
|
105
113
|
return new Promise((resolve, reject) => {
|
|
@@ -138,16 +146,15 @@ class ApiManager {
|
|
|
138
146
|
* @description Cancel API (xhr.abort())
|
|
139
147
|
*/
|
|
140
148
|
cancel() {
|
|
141
|
-
if (this
|
|
149
|
+
if (this.#xhr) this.#xhr.abort();
|
|
142
150
|
}
|
|
143
151
|
|
|
144
152
|
/**
|
|
145
|
-
* @private
|
|
146
153
|
* @description Remove unnecessary slashes in API URL.
|
|
147
154
|
* @param {string} url url
|
|
148
155
|
* @returns
|
|
149
156
|
*/
|
|
150
|
-
|
|
157
|
+
#normalizeUrl(url) {
|
|
151
158
|
return url.replace(/([^:])\/+/g, '$1/').replace(/\/(\?|#|$)/, '$1');
|
|
152
159
|
}
|
|
153
160
|
}
|
package/src/modules/Browser.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import CoreInjector from '../editorInjector/_core';
|
|
2
2
|
import { dom, keyCodeMap } from '../helper';
|
|
3
|
+
import { _w } from '../helper/env';
|
|
3
4
|
import ApiManager from './ApiManager';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -39,6 +40,11 @@ import ApiManager from './ApiManager';
|
|
|
39
40
|
* @description File browser plugin
|
|
40
41
|
*/
|
|
41
42
|
class Browser extends CoreInjector {
|
|
43
|
+
#loading;
|
|
44
|
+
#closeSignal;
|
|
45
|
+
#bindClose;
|
|
46
|
+
#globalEventHandler;
|
|
47
|
+
|
|
42
48
|
/**
|
|
43
49
|
* @constructor
|
|
44
50
|
* @param {*} inst The instance object that called the constructor.
|
|
@@ -64,7 +70,7 @@ class Browser extends CoreInjector {
|
|
|
64
70
|
this.list = contentHTML.list;
|
|
65
71
|
this.side = contentHTML.side;
|
|
66
72
|
this.wrapper = contentHTML.wrapper;
|
|
67
|
-
this
|
|
73
|
+
this.#loading = contentHTML._loading;
|
|
68
74
|
|
|
69
75
|
this.title = params.title;
|
|
70
76
|
this.listClass = params.listClass || 'se-preview-list';
|
|
@@ -83,33 +89,27 @@ class Browser extends CoreInjector {
|
|
|
83
89
|
this.icon_folder_item = this.icons.side_menu_folder;
|
|
84
90
|
this.icon_item = this.icons.side_menu_item;
|
|
85
91
|
|
|
86
|
-
/**
|
|
87
|
-
* @type {Array<BrowserFile>}
|
|
88
|
-
*/
|
|
92
|
+
/** @type {Array<BrowserFile>} */
|
|
89
93
|
this.items = [];
|
|
90
|
-
/**
|
|
91
|
-
* @type {Object<string, {name: string, meta: Object<string, *>}>}
|
|
92
|
-
*/
|
|
94
|
+
/** @type {Object<string, {name: string, meta: Object<string, *>}>} */
|
|
93
95
|
this.folders = {};
|
|
94
|
-
/**
|
|
95
|
-
* @type {Object<string, {key?: string, name?: string, children?: *}>}
|
|
96
|
-
*/
|
|
96
|
+
/** @type {Object<string, {key?: string, name?: string, children?: *}>} */
|
|
97
97
|
this.tree = {};
|
|
98
|
-
/**
|
|
99
|
-
* @type {BrowserFile}
|
|
100
|
-
*/
|
|
98
|
+
/** @type {BrowserFile} */
|
|
101
99
|
this.data = {};
|
|
102
100
|
this.selectedTags = [];
|
|
103
101
|
this.keyword = '';
|
|
104
102
|
this.sideInner = null;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
103
|
+
|
|
104
|
+
// api manager
|
|
105
|
+
this.apiManager = new ApiManager(this, { method: 'GET' });
|
|
106
|
+
|
|
107
|
+
this.#closeSignal = false;
|
|
108
|
+
this.#bindClose = null;
|
|
109
|
+
this.#globalEventHandler = (e) => {
|
|
108
110
|
if (!keyCodeMap.isEsc(e.code)) return;
|
|
109
111
|
this.close();
|
|
110
112
|
};
|
|
111
|
-
// api manager
|
|
112
|
-
this.apiManager = new ApiManager(this, { method: 'GET' });
|
|
113
113
|
|
|
114
114
|
// init
|
|
115
115
|
browserFrame.appendChild(dom.utils.createElement('DIV', { class: 'se-browser-back' }));
|
|
@@ -134,9 +134,8 @@ class Browser extends CoreInjector {
|
|
|
134
134
|
* @param {string=} params.url - File server url. If not, use "this.url".
|
|
135
135
|
* @param {Object<string, string>=} params.urlHeader - File server http header. If not, use "this.urlHeader".
|
|
136
136
|
*/
|
|
137
|
-
open(params) {
|
|
138
|
-
|
|
139
|
-
this.__addGlobalEvent();
|
|
137
|
+
open(params = {}) {
|
|
138
|
+
this.#addGlobalEvent();
|
|
140
139
|
|
|
141
140
|
const listClassName = params.listClass || this.listClass;
|
|
142
141
|
if (!dom.utils.hasClass(this.list, listClassName)) {
|
|
@@ -149,10 +148,12 @@ class Browser extends CoreInjector {
|
|
|
149
148
|
this.closeArrow = this.options.get('_rtl') ? this.icons.menu_arrow_left : this.icons.menu_arrow_right;
|
|
150
149
|
|
|
151
150
|
if (this.directData) {
|
|
152
|
-
this
|
|
151
|
+
this.#drowItems(this.directData);
|
|
153
152
|
} else {
|
|
154
|
-
this
|
|
153
|
+
this.#drawFileList(params.url || this.url, params.urlHeader || this.urlHeader, false);
|
|
155
154
|
}
|
|
155
|
+
|
|
156
|
+
this.body.style.maxHeight = dom.utils.getClientSize().h - (this.editor.offset.getGlobal(this.body).top - _w.scrollY) - 20 + 'px';
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
/**
|
|
@@ -160,7 +161,7 @@ class Browser extends CoreInjector {
|
|
|
160
161
|
* - The plugin's "init" method is called.
|
|
161
162
|
*/
|
|
162
163
|
close() {
|
|
163
|
-
this
|
|
164
|
+
this.#removeGlobalEvent();
|
|
164
165
|
this.apiManager.cancel();
|
|
165
166
|
|
|
166
167
|
this.area.style.display = 'none';
|
|
@@ -184,10 +185,10 @@ class Browser extends CoreInjector {
|
|
|
184
185
|
search(keyword) {
|
|
185
186
|
if (this.searchUrl) {
|
|
186
187
|
this.keyword = keyword;
|
|
187
|
-
this
|
|
188
|
+
this.#drawFileList(this.searchUrl + '?keyword=' + keyword, this.searchUrlHeader, false);
|
|
188
189
|
} else {
|
|
189
190
|
this.keyword = keyword.toLowerCase();
|
|
190
|
-
this
|
|
191
|
+
this.#drawListItem(this.items, false);
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
|
|
@@ -205,24 +206,23 @@ class Browser extends CoreInjector {
|
|
|
205
206
|
* @description Show file browser loading box
|
|
206
207
|
*/
|
|
207
208
|
showBrowserLoading() {
|
|
208
|
-
this.
|
|
209
|
+
this.#loading.style.display = 'block';
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
/**
|
|
212
213
|
* @description Close file browser loading box
|
|
213
214
|
*/
|
|
214
215
|
closeBrowserLoading() {
|
|
215
|
-
this.
|
|
216
|
+
this.#loading.style.display = 'none';
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
/**
|
|
219
|
-
* @private
|
|
220
220
|
* @description Fetches the file list from the server.
|
|
221
221
|
* @param {string} url - The file server URL.
|
|
222
222
|
* @param {Object<string, string>} urlHeader - The HTTP headers for the request.
|
|
223
223
|
* @param {boolean} pageLoading - Indicates if this is a paginated request.
|
|
224
224
|
*/
|
|
225
|
-
|
|
225
|
+
#drawFileList(url, urlHeader, pageLoading) {
|
|
226
226
|
this.apiManager.call({ method: 'GET', url, headers: urlHeader, callBack: this.#CallBackGet.bind(this), errorCallBack: this.#CallBackError.bind(this) });
|
|
227
227
|
if (!pageLoading) {
|
|
228
228
|
this.sideOpenBtn.style.display = 'none';
|
|
@@ -231,12 +231,11 @@ class Browser extends CoreInjector {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
|
-
* @private
|
|
235
234
|
* @description Updates the displayed list of file items.
|
|
236
235
|
* @param {Array<BrowserFile>} items - The file items to display.
|
|
237
236
|
* @param {boolean} update - Whether to update the tags.
|
|
238
237
|
*/
|
|
239
|
-
|
|
238
|
+
#drawListItem(items, update) {
|
|
240
239
|
const keyword = this.keyword;
|
|
241
240
|
items = this.tagfilter(items).filter((item) => item.name.toLowerCase().indexOf(keyword) > -1);
|
|
242
241
|
|
|
@@ -281,41 +280,38 @@ class Browser extends CoreInjector {
|
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
/**
|
|
284
|
-
* @private
|
|
285
283
|
* @description Adds a global event listener for closing the browser.
|
|
286
284
|
*/
|
|
287
|
-
|
|
288
|
-
this
|
|
289
|
-
this
|
|
285
|
+
#addGlobalEvent() {
|
|
286
|
+
this.#removeGlobalEvent();
|
|
287
|
+
this.#bindClose = this.eventManager.addGlobalEvent('keydown', this.#globalEventHandler, true);
|
|
290
288
|
}
|
|
291
289
|
|
|
292
290
|
/**
|
|
293
|
-
* @private
|
|
294
291
|
* @description Removes the global event listener for closing the browser.
|
|
295
292
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
#removeGlobalEvent() {
|
|
294
|
+
this.#bindClose &&= this.eventManager.removeGlobalEvent(this.#bindClose);
|
|
298
295
|
}
|
|
299
296
|
|
|
300
297
|
/**
|
|
301
|
-
* @private
|
|
302
298
|
* @description Renders the file items or folder structure from data.
|
|
303
299
|
* @param {BrowserFile[]|BrowserFile} data - The data representing the file structure.
|
|
304
300
|
* @returns {boolean} True if rendering was successful, false otherwise.
|
|
305
301
|
*/
|
|
306
|
-
|
|
302
|
+
#drowItems(data) {
|
|
307
303
|
if (Array.isArray(data)) {
|
|
308
304
|
if (data.length > 0) {
|
|
309
|
-
this
|
|
305
|
+
this.#drawListItem(data, true);
|
|
310
306
|
}
|
|
311
307
|
return true;
|
|
312
308
|
} else if (typeof data === 'object') {
|
|
313
309
|
this.sideOpenBtn.style.display = '';
|
|
314
|
-
this
|
|
310
|
+
this.#parseFolderData(data);
|
|
315
311
|
|
|
316
312
|
this.side.innerHTML = '';
|
|
317
313
|
const sideInner = (this.sideInner = dom.utils.createElement('div', null));
|
|
318
|
-
this
|
|
314
|
+
this.#createFolderList(this.tree, sideInner);
|
|
319
315
|
this.side.appendChild(sideInner);
|
|
320
316
|
|
|
321
317
|
if (this.folderDefaultPath) {
|
|
@@ -333,12 +329,11 @@ class Browser extends CoreInjector {
|
|
|
333
329
|
}
|
|
334
330
|
|
|
335
331
|
/**
|
|
336
|
-
* @private
|
|
337
332
|
* @description Parses folder data into a structured format.
|
|
338
333
|
* @param {BrowserFile} data - The folder data.
|
|
339
334
|
* @param {string} [path] - The current path in the folder hierarchy.
|
|
340
335
|
*/
|
|
341
|
-
|
|
336
|
+
#parseFolderData(data, path) {
|
|
342
337
|
let current = this.tree;
|
|
343
338
|
|
|
344
339
|
// _data
|
|
@@ -351,9 +346,7 @@ class Browser extends CoreInjector {
|
|
|
351
346
|
const parts = path.split('/');
|
|
352
347
|
const len = parts.length - 1;
|
|
353
348
|
parts.forEach((part, index) => {
|
|
354
|
-
|
|
355
|
-
current[part] = { children: {} };
|
|
356
|
-
}
|
|
349
|
+
current[part] ||= { children: {} };
|
|
357
350
|
|
|
358
351
|
if (index === len) {
|
|
359
352
|
current[part].key = path;
|
|
@@ -378,17 +371,16 @@ class Browser extends CoreInjector {
|
|
|
378
371
|
meta: v.meta || {}
|
|
379
372
|
};
|
|
380
373
|
|
|
381
|
-
this
|
|
374
|
+
this.#parseFolderData(v, currentPath);
|
|
382
375
|
});
|
|
383
376
|
}
|
|
384
377
|
|
|
385
378
|
/**
|
|
386
|
-
* @private
|
|
387
379
|
* @description Creates a nested folder list from parsed data.
|
|
388
380
|
* @param {BrowserFile[]|BrowserFile} folderData - The structured folder data.
|
|
389
381
|
* @param {HTMLElement} parentElement - The parent element to append folder structure to.
|
|
390
382
|
*/
|
|
391
|
-
|
|
383
|
+
#createFolderList(folderData, parentElement) {
|
|
392
384
|
for (const key in folderData) {
|
|
393
385
|
const item = folderData[key];
|
|
394
386
|
if (!item) continue;
|
|
@@ -404,7 +396,7 @@ class Browser extends CoreInjector {
|
|
|
404
396
|
folderLabel.insertBefore(dom.utils.createElement('button', null, this.closeArrow), folderLabel.firstElementChild);
|
|
405
397
|
const childContainer = document.createElement('div');
|
|
406
398
|
dom.utils.addClass(childContainer, 'se-menu-child|se-menu-hidden');
|
|
407
|
-
this
|
|
399
|
+
this.#createFolderList(item.children, childContainer);
|
|
408
400
|
folderDiv.appendChild(childContainer);
|
|
409
401
|
|
|
410
402
|
parentElement.appendChild(folderDiv);
|
|
@@ -427,7 +419,7 @@ class Browser extends CoreInjector {
|
|
|
427
419
|
try {
|
|
428
420
|
const res = JSON.parse(xmlHttp.responseText);
|
|
429
421
|
const data = res.result;
|
|
430
|
-
if (this
|
|
422
|
+
if (this.#drowItems(data)) return;
|
|
431
423
|
|
|
432
424
|
if (res.nullMessage) {
|
|
433
425
|
this.list.innerHTML = res.nullMessage;
|
|
@@ -436,7 +428,6 @@ class Browser extends CoreInjector {
|
|
|
436
428
|
throw Error(`[SUNEDITOR.browser.drawList.fail] cause: "${e.message}"`);
|
|
437
429
|
} finally {
|
|
438
430
|
this.closeBrowserLoading();
|
|
439
|
-
this.body.style.maxHeight = dom.utils.getClientSize().h - this.header.offsetHeight - 50 + 'px';
|
|
440
431
|
}
|
|
441
432
|
}
|
|
442
433
|
|
|
@@ -468,7 +459,7 @@ class Browser extends CoreInjector {
|
|
|
468
459
|
dom.utils.addClass(selectTag, 'on');
|
|
469
460
|
}
|
|
470
461
|
|
|
471
|
-
this
|
|
462
|
+
this.#drawListItem(this.items, false);
|
|
472
463
|
}
|
|
473
464
|
|
|
474
465
|
/**
|
|
@@ -518,9 +509,9 @@ class Browser extends CoreInjector {
|
|
|
518
509
|
this.tagArea.innerHTML = '';
|
|
519
510
|
|
|
520
511
|
if (typeof data === 'string') {
|
|
521
|
-
this
|
|
512
|
+
this.#drawFileList(data, this.urlHeader, true);
|
|
522
513
|
} else {
|
|
523
|
-
this
|
|
514
|
+
this.#drawListItem(data, false);
|
|
524
515
|
}
|
|
525
516
|
}
|
|
526
517
|
|
|
@@ -530,9 +521,9 @@ class Browser extends CoreInjector {
|
|
|
530
521
|
#OnMouseDown_browser(e) {
|
|
531
522
|
const eventTarget = dom.query.getEventTarget(e);
|
|
532
523
|
if (/se-browser-inner/.test(eventTarget.className)) {
|
|
533
|
-
this
|
|
524
|
+
this.#closeSignal = true;
|
|
534
525
|
} else {
|
|
535
|
-
this
|
|
526
|
+
this.#closeSignal = false;
|
|
536
527
|
}
|
|
537
528
|
}
|
|
538
529
|
|
|
@@ -543,7 +534,7 @@ class Browser extends CoreInjector {
|
|
|
543
534
|
const eventTarget = dom.query.getEventTarget(e);
|
|
544
535
|
e.stopPropagation();
|
|
545
536
|
|
|
546
|
-
if (/close/.test(eventTarget.getAttribute('data-command')) || this
|
|
537
|
+
if (/close/.test(eventTarget.getAttribute('data-command')) || this.#closeSignal) {
|
|
547
538
|
this.close();
|
|
548
539
|
}
|
|
549
540
|
}
|