@windwalker-io/unicorn-next 0.1.7 → 0.1.9
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/.editorconfig +18 -18
- package/.gulp.json +7 -7
- package/bin/release.mjs +47 -47
- package/dist/chunks/button-radio.js.map +1 -1
- package/dist/chunks/checkboxes-multi-select.js.map +1 -1
- package/dist/chunks/field-cascade-select.js +2 -2
- package/dist/chunks/field-cascade-select.js.map +1 -1
- package/dist/chunks/field-file-drag.js.map +1 -1
- package/dist/chunks/field-flatpickr.js.map +1 -1
- package/dist/chunks/field-modal-select.js.map +1 -1
- package/dist/chunks/field-modal-tree.js +2 -2
- package/dist/chunks/field-modal-tree.js.map +1 -1
- package/dist/chunks/field-multi-uploader.js.map +1 -1
- package/dist/chunks/field-repeatable.js.map +1 -1
- package/dist/chunks/field-single-image-drag.js.map +1 -1
- package/dist/chunks/form.js.map +1 -1
- package/dist/chunks/grid.js.map +1 -1
- package/dist/chunks/http-client.js.map +1 -1
- package/dist/chunks/iframe-modal.js.map +1 -1
- package/dist/chunks/index.js +1 -15
- package/dist/chunks/index.js.map +1 -1
- package/dist/chunks/keep-tab.js +2 -2
- package/dist/chunks/keep-tab.js.map +1 -1
- package/dist/chunks/legacy.js +3 -3
- package/dist/chunks/legacy.js.map +1 -1
- package/dist/chunks/list-dependent.js.map +1 -1
- package/dist/chunks/s3-multipart-uploader.js +23 -2
- package/dist/chunks/s3-multipart-uploader.js.map +1 -1
- package/dist/chunks/s3-uploader.js.map +1 -1
- package/dist/chunks/show-on.js +2 -2
- package/dist/chunks/show-on.js.map +1 -1
- package/dist/chunks/tinymce.js.map +1 -1
- package/dist/chunks/ui-bootstrap5.js.map +1 -1
- package/dist/chunks/unicorn.js +108 -89
- package/dist/chunks/unicorn.js.map +1 -1
- package/dist/chunks/validation.js.map +1 -1
- package/dist/index.d.ts +28 -6
- package/dist/unicorn.js +43 -41
- package/fusionfile.mjs +155 -155
- package/package.json +104 -104
- package/scss/bootstrap/multi-level-menu.scss +121 -121
- package/scss/editor.scss +116 -116
- package/scss/field/file-drag.scss +102 -102
- package/scss/field/single-image-drag.scss +88 -88
- package/scss/field/vue-drag-uploader.scss +160 -160
- package/scss/switcher.scss +156 -156
- package/src/app.ts +128 -128
- package/src/bootstrap/button-radio.ts +208 -208
- package/src/bootstrap/keep-tab.ts +155 -155
- package/src/composable/index.ts +22 -22
- package/src/composable/useCheckboxesMultiSelect.ts +22 -22
- package/src/composable/useFieldCascadeSelect.ts +9 -9
- package/src/composable/useFieldFileDrag.ts +9 -9
- package/src/composable/useFieldFlatpickr.ts +3 -3
- package/src/composable/useFieldModalSelect.ts +6 -6
- package/src/composable/useFieldModalTree.ts +3 -3
- package/src/composable/useFieldMultiUploader.ts +9 -9
- package/src/composable/useFieldRepeatable.ts +9 -9
- package/src/composable/useFieldSingleImageDrag.ts +9 -9
- package/src/composable/useForm.ts +43 -43
- package/src/composable/useGrid.ts +57 -57
- package/src/composable/useHttp.ts +9 -9
- package/src/composable/useIframeModal.ts +10 -10
- package/src/composable/useListDependent.ts +26 -26
- package/src/composable/useQueue.ts +13 -13
- package/src/composable/useS3Uploader.ts +32 -32
- package/src/composable/useShowOn.ts +9 -9
- package/src/composable/useStack.ts +13 -13
- package/src/composable/useTinymce.ts +29 -29
- package/src/composable/useTomSelect.ts +72 -72
- package/src/composable/useUIBootstrap5.ts +48 -48
- package/src/composable/useUniDirective.ts +43 -43
- package/src/composable/useValidation.ts +50 -50
- package/src/data.ts +34 -34
- package/src/events.ts +82 -82
- package/src/legacy/legacy.ts +190 -190
- package/src/legacy/loader.ts +125 -125
- package/src/module/checkboxes-multi-select.ts +54 -54
- package/src/module/field-cascade-select.ts +292 -292
- package/src/module/field-file-drag.ts +295 -295
- package/src/module/field-flatpickr.ts +130 -130
- package/src/module/field-modal-select.ts +179 -179
- package/src/module/field-modal-tree.ts +31 -31
- package/src/module/field-multi-uploader.ts +368 -368
- package/src/module/field-repeatable.ts +202 -202
- package/src/module/field-single-image-drag.ts +477 -477
- package/src/module/form.ts +223 -223
- package/src/module/grid.ts +479 -479
- package/src/module/http-client.ts +248 -248
- package/src/module/iframe-modal.ts +170 -170
- package/src/module/list-dependent.ts +321 -321
- package/src/module/s3-multipart-uploader.ts +330 -300
- package/src/module/s3-uploader.ts +234 -234
- package/src/module/show-on.ts +175 -175
- package/src/module/tinymce.ts +276 -276
- package/src/module/ui-bootstrap5.ts +116 -116
- package/src/module/validation.ts +1046 -1046
- package/src/plugin/index.ts +1 -1
- package/src/plugin/php-adapter.ts +72 -72
- package/src/polyfill/form-request-submit.ts +31 -31
- package/src/polyfill/index.ts +9 -9
- package/src/service/animate.ts +58 -58
- package/src/service/crypto.ts +27 -27
- package/src/service/dom-watcher.ts +62 -62
- package/src/service/dom.ts +291 -265
- package/src/service/helper.ts +52 -48
- package/src/service/index.ts +10 -10
- package/src/service/lang.ts +122 -122
- package/src/service/loader.ts +152 -152
- package/src/service/router.ts +118 -118
- package/src/service/ui.ts +525 -525
- package/src/service/uri.ts +106 -106
- package/src/types/base.ts +9 -9
- package/src/types/index.ts +4 -4
- package/src/types/modal-tree.ts +12 -12
- package/src/types/plugin.ts +6 -6
- package/src/types/shims.d.ts +18 -18
- package/src/types/ui.ts +6 -6
- package/src/unicorn.ts +79 -79
- package/src/utilities/arr.ts +25 -25
- package/src/utilities/base.ts +9 -9
- package/src/utilities/data.ts +48 -48
- package/src/utilities/index.ts +5 -5
- package/src/utilities/tree.ts +20 -20
- package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -175
- package/src/vue/components/ModalTree/TreeItem.vue +262 -262
- package/src/vue/components/ModalTree/TreeModal.vue +225 -225
- package/tests/test.js +4 -4
- package/tsconfig.js.json +25 -25
- package/tsconfig.json +17 -17
- package/vite.assets.config.ts +61 -61
- package/vite.config.test.ts +36 -36
- package/vite.config.ts +112 -112
package/src/module/tinymce.ts
CHANGED
|
@@ -1,276 +1,276 @@
|
|
|
1
|
-
import type { Editor, EditorOptions, TinyMCE } from 'tinymce';
|
|
2
|
-
import { useHttpClient, useStack } from '../composable';
|
|
3
|
-
import { useImport, useScriptImport } from '../service';
|
|
4
|
-
import { Dictionary, MaybePromise } from '../types';
|
|
5
|
-
import { mergeDeep } from '../utilities';
|
|
6
|
-
|
|
7
|
-
const instances: Dictionary<TinymceController> = {};
|
|
8
|
-
let hooks: ((tinymce: TinyMCE) => MaybePromise<any>)[] = [];
|
|
9
|
-
let imported: Promise<TinyMCE>;
|
|
10
|
-
|
|
11
|
-
declare type UploadHandlerParams = Parameters<NonNullable<EditorOptions['images_upload_handler']>>;
|
|
12
|
-
|
|
13
|
-
export async function get(
|
|
14
|
-
selector: string,
|
|
15
|
-
options: Record<string, any> = {}
|
|
16
|
-
): Promise<TinymceController> {
|
|
17
|
-
return instances[selector] ??= await create(document.querySelector<HTMLElement>(selector)!, options);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function create(
|
|
21
|
-
selector: string | HTMLElement,
|
|
22
|
-
options: Record<string, any> = {}
|
|
23
|
-
): Promise<TinymceController> {
|
|
24
|
-
const tinymce = await loadTinymce();
|
|
25
|
-
let el: HTMLElement;
|
|
26
|
-
|
|
27
|
-
if (typeof selector === 'string') {
|
|
28
|
-
el = document.querySelector<HTMLElement>(selector)!;
|
|
29
|
-
} else {
|
|
30
|
-
el = selector;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return new TinymceController(tinymce, el, options);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function destroy(selector: string): void {
|
|
37
|
-
delete instances[selector];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function addHook(handler: ((tinymce: TinyMCE) => MaybePromise<any>)) {
|
|
41
|
-
hooks.push(handler);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function clearHooks() {
|
|
45
|
-
hooks = [];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function loadTinymce(): Promise<TinyMCE> {
|
|
49
|
-
return imported ??= new Promise((resolve) => {
|
|
50
|
-
useScriptImport('@tinymce').then(() => {
|
|
51
|
-
for (const hook of hooks) {
|
|
52
|
-
hook(tinymce);
|
|
53
|
-
}
|
|
54
|
-
registerDragPlugin(tinymce).then(() => {
|
|
55
|
-
resolve(tinymce);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const defaultOptions: Record<string, any> = {};
|
|
62
|
-
|
|
63
|
-
export class TinymceController {
|
|
64
|
-
editor?: Editor;
|
|
65
|
-
options: Record<string, any> = {};
|
|
66
|
-
|
|
67
|
-
constructor(protected tinymce: TinyMCE, public element: HTMLElement, options: Record<string, any>) {
|
|
68
|
-
this.options = mergeDeep(
|
|
69
|
-
{
|
|
70
|
-
unicorn: {
|
|
71
|
-
stack_name: 'uploading'
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
defaultOptions,
|
|
75
|
-
this.prepareOptions(options, tinymce.majorVersion),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
this.options.target = element;
|
|
79
|
-
|
|
80
|
-
tinymce.init(this.options).then((editor) => {
|
|
81
|
-
this.editor = editor[0];
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
prepareOptions(options: Record<string, any>, version = '6') {
|
|
86
|
-
const defaults: Partial<EditorOptions> = {};
|
|
87
|
-
|
|
88
|
-
if (options.images_upload_url) {
|
|
89
|
-
defaults.paste_data_images = true;
|
|
90
|
-
defaults.remove_script_host = false;
|
|
91
|
-
defaults.relative_urls = false;
|
|
92
|
-
|
|
93
|
-
if (Number(version) >= 6) {
|
|
94
|
-
defaults.images_upload_handler = (blobInfo, progress) =>
|
|
95
|
-
this.imageUploadHandler(blobInfo, progress);
|
|
96
|
-
} else {
|
|
97
|
-
options.plugins.push('paste');
|
|
98
|
-
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
defaults.images_upload_handler = (blobInfo, success, failure, progress) =>
|
|
101
|
-
this.imageUploadHandler(blobInfo, progress)
|
|
102
|
-
.then((url) => {
|
|
103
|
-
success(url);
|
|
104
|
-
return url;
|
|
105
|
-
})
|
|
106
|
-
.catch((e) => {
|
|
107
|
-
failure(e.message, { remove: true });
|
|
108
|
-
throw e;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// defaults.file_picker_callback = (...args) => this.filePickerCallback(...args);
|
|
114
|
-
|
|
115
|
-
defaults.plugins = defaults.plugins || [];
|
|
116
|
-
|
|
117
|
-
defaults.setup = (editor) => {
|
|
118
|
-
editor.on('change', () => {
|
|
119
|
-
this.tinymce.triggerSave();
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
options = mergeDeep({}, defaults, options);
|
|
124
|
-
|
|
125
|
-
if (options.plugins.indexOf('unicorndragdrop') === -1) {
|
|
126
|
-
options.plugins.push('unicorndragdrop');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return options;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
insert(text: string) {
|
|
133
|
-
this.editor?.insertContent(text);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
getValue(): string {
|
|
137
|
-
return this.editor?.getContent() ?? '';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
setValue(text: string): void {
|
|
141
|
-
this.editor?.setContent(text);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// filePickerCallback(callback, value, meta) {
|
|
145
|
-
// const input = document.createElement('input');
|
|
146
|
-
// input.setAttribute('type', 'file');
|
|
147
|
-
// input.style.display = 'none';
|
|
148
|
-
//
|
|
149
|
-
// if (meta.filetype === 'image') {
|
|
150
|
-
// input.setAttribute('accept', `image/\*`);
|
|
151
|
-
// }
|
|
152
|
-
//
|
|
153
|
-
// document.body.appendChild(input);
|
|
154
|
-
//
|
|
155
|
-
// input.onchange = function () {
|
|
156
|
-
// const file = this.files[0];
|
|
157
|
-
//
|
|
158
|
-
// const reader = new FileReader();
|
|
159
|
-
// reader.onload = function () {
|
|
160
|
-
// const id = 'blobid' + (new Date()).getTime();
|
|
161
|
-
// const blobCache = tinymce.activeEditor.editorUpload.blobCache;
|
|
162
|
-
// const base64 = reader.result.split(',')[1];
|
|
163
|
-
// const blobInfo = blobCache.create(id, file, base64);
|
|
164
|
-
// blobCache.add(blobInfo);
|
|
165
|
-
//
|
|
166
|
-
// /* call the callback and populate the Title field with the file name */
|
|
167
|
-
// callback(blobInfo.blobUri(), { title: file.name, text: file.name });
|
|
168
|
-
// };
|
|
169
|
-
// reader.readAsDataURL(file);
|
|
170
|
-
// input.remove();
|
|
171
|
-
// };
|
|
172
|
-
//
|
|
173
|
-
// input.click();
|
|
174
|
-
// }
|
|
175
|
-
|
|
176
|
-
async imageUploadHandler(blobInfo: UploadHandlerParams[0], progress: UploadHandlerParams[1]) {
|
|
177
|
-
const element = this.element;
|
|
178
|
-
|
|
179
|
-
element.dispatchEvent(new CustomEvent('upload-start'));
|
|
180
|
-
|
|
181
|
-
const formData = new FormData();
|
|
182
|
-
formData.append('file', blobInfo.blob(), blobInfo.filename());
|
|
183
|
-
|
|
184
|
-
const stack = useStack(this.options.unicorn.stack_name);
|
|
185
|
-
stack.push(true);
|
|
186
|
-
|
|
187
|
-
const { post, isAxiosError } = await useHttpClient();
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
let res = await post(
|
|
191
|
-
this.options.images_upload_url,
|
|
192
|
-
formData,
|
|
193
|
-
{
|
|
194
|
-
withCredentials: false,
|
|
195
|
-
onUploadProgress: (e) => {
|
|
196
|
-
progress(e.loaded / e.total! * 100);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
element.dispatchEvent(new CustomEvent('upload-success'));
|
|
201
|
-
|
|
202
|
-
return res.data.data.url;
|
|
203
|
-
} catch (err) {
|
|
204
|
-
if (isAxiosError(err)) {
|
|
205
|
-
const message = err?.response?.data?.message || err.message;
|
|
206
|
-
console.error(err?.response?.data?.message || err.message, err);
|
|
207
|
-
element.dispatchEvent(new CustomEvent('upload-error', { detail: err }));
|
|
208
|
-
|
|
209
|
-
return Promise.reject({ message, remove: true });
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
throw err;
|
|
213
|
-
} finally {
|
|
214
|
-
element.dispatchEvent(new CustomEvent('upload-complete'));
|
|
215
|
-
stack.pop();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function registerDragPlugin(tinymce: TinyMCE) {
|
|
221
|
-
tinymce.PluginManager.add('unicorndragdrop', function (editor) {
|
|
222
|
-
// Reset the drop area border
|
|
223
|
-
tinymce.DOM.bind(document, 'dragleave', function (e) {
|
|
224
|
-
e.stopPropagation();
|
|
225
|
-
e.preventDefault();
|
|
226
|
-
|
|
227
|
-
if (tinymce.activeEditor) {
|
|
228
|
-
tinymce.activeEditor.contentAreaContainer.style.transition = 'all .3s';
|
|
229
|
-
tinymce.activeEditor.contentAreaContainer.style.borderWidth = '';
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return false;
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
if (typeof FormData !== 'undefined') {
|
|
236
|
-
|
|
237
|
-
// Fix for Chrome
|
|
238
|
-
editor.on('dragenter', e => {
|
|
239
|
-
e.stopPropagation();
|
|
240
|
-
return false;
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// Notify user when file is over the drop area
|
|
244
|
-
editor.on('dragover', e => {
|
|
245
|
-
e.preventDefault();
|
|
246
|
-
|
|
247
|
-
if (tinymce.activeEditor) {
|
|
248
|
-
tinymce.activeEditor.contentAreaContainer.style.transition = 'all .3s';
|
|
249
|
-
tinymce.activeEditor.contentAreaContainer.style.border = '3px dashed rgba(0, 0, 0, .35)';
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return false;
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
editor.on('drop', e => {
|
|
256
|
-
editor.contentAreaContainer.style.borderWidth = '';
|
|
257
|
-
editor.contentAreaContainer.style.borderWidth = '';
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
return Promise.resolve();
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export interface TinymceModule {
|
|
266
|
-
get: typeof get;
|
|
267
|
-
create: typeof create;
|
|
268
|
-
destroy: typeof destroy;
|
|
269
|
-
addHook: typeof addHook;
|
|
270
|
-
clearHooks: typeof clearHooks;
|
|
271
|
-
TinymceController: typeof TinymceController;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
declare global {
|
|
275
|
-
var tinymce: TinyMCE;
|
|
276
|
-
}
|
|
1
|
+
import type { Editor, EditorOptions, TinyMCE } from 'tinymce';
|
|
2
|
+
import { useHttpClient, useStack } from '../composable';
|
|
3
|
+
import { useImport, useScriptImport } from '../service';
|
|
4
|
+
import { Dictionary, MaybePromise } from '../types';
|
|
5
|
+
import { mergeDeep } from '../utilities';
|
|
6
|
+
|
|
7
|
+
const instances: Dictionary<TinymceController> = {};
|
|
8
|
+
let hooks: ((tinymce: TinyMCE) => MaybePromise<any>)[] = [];
|
|
9
|
+
let imported: Promise<TinyMCE>;
|
|
10
|
+
|
|
11
|
+
declare type UploadHandlerParams = Parameters<NonNullable<EditorOptions['images_upload_handler']>>;
|
|
12
|
+
|
|
13
|
+
export async function get(
|
|
14
|
+
selector: string,
|
|
15
|
+
options: Record<string, any> = {}
|
|
16
|
+
): Promise<TinymceController> {
|
|
17
|
+
return instances[selector] ??= await create(document.querySelector<HTMLElement>(selector)!, options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function create(
|
|
21
|
+
selector: string | HTMLElement,
|
|
22
|
+
options: Record<string, any> = {}
|
|
23
|
+
): Promise<TinymceController> {
|
|
24
|
+
const tinymce = await loadTinymce();
|
|
25
|
+
let el: HTMLElement;
|
|
26
|
+
|
|
27
|
+
if (typeof selector === 'string') {
|
|
28
|
+
el = document.querySelector<HTMLElement>(selector)!;
|
|
29
|
+
} else {
|
|
30
|
+
el = selector;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return new TinymceController(tinymce, el, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function destroy(selector: string): void {
|
|
37
|
+
delete instances[selector];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function addHook(handler: ((tinymce: TinyMCE) => MaybePromise<any>)) {
|
|
41
|
+
hooks.push(handler);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function clearHooks() {
|
|
45
|
+
hooks = [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function loadTinymce(): Promise<TinyMCE> {
|
|
49
|
+
return imported ??= new Promise((resolve) => {
|
|
50
|
+
useScriptImport('@tinymce').then(() => {
|
|
51
|
+
for (const hook of hooks) {
|
|
52
|
+
hook(tinymce);
|
|
53
|
+
}
|
|
54
|
+
registerDragPlugin(tinymce).then(() => {
|
|
55
|
+
resolve(tinymce);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const defaultOptions: Record<string, any> = {};
|
|
62
|
+
|
|
63
|
+
export class TinymceController {
|
|
64
|
+
editor?: Editor;
|
|
65
|
+
options: Record<string, any> = {};
|
|
66
|
+
|
|
67
|
+
constructor(protected tinymce: TinyMCE, public element: HTMLElement, options: Record<string, any>) {
|
|
68
|
+
this.options = mergeDeep(
|
|
69
|
+
{
|
|
70
|
+
unicorn: {
|
|
71
|
+
stack_name: 'uploading'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
defaultOptions,
|
|
75
|
+
this.prepareOptions(options, tinymce.majorVersion),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
this.options.target = element;
|
|
79
|
+
|
|
80
|
+
tinymce.init(this.options).then((editor) => {
|
|
81
|
+
this.editor = editor[0];
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
prepareOptions(options: Record<string, any>, version = '6') {
|
|
86
|
+
const defaults: Partial<EditorOptions> = {};
|
|
87
|
+
|
|
88
|
+
if (options.images_upload_url) {
|
|
89
|
+
defaults.paste_data_images = true;
|
|
90
|
+
defaults.remove_script_host = false;
|
|
91
|
+
defaults.relative_urls = false;
|
|
92
|
+
|
|
93
|
+
if (Number(version) >= 6) {
|
|
94
|
+
defaults.images_upload_handler = (blobInfo, progress) =>
|
|
95
|
+
this.imageUploadHandler(blobInfo, progress);
|
|
96
|
+
} else {
|
|
97
|
+
options.plugins.push('paste');
|
|
98
|
+
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
defaults.images_upload_handler = (blobInfo, success, failure, progress) =>
|
|
101
|
+
this.imageUploadHandler(blobInfo, progress)
|
|
102
|
+
.then((url) => {
|
|
103
|
+
success(url);
|
|
104
|
+
return url;
|
|
105
|
+
})
|
|
106
|
+
.catch((e) => {
|
|
107
|
+
failure(e.message, { remove: true });
|
|
108
|
+
throw e;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// defaults.file_picker_callback = (...args) => this.filePickerCallback(...args);
|
|
114
|
+
|
|
115
|
+
defaults.plugins = defaults.plugins || [];
|
|
116
|
+
|
|
117
|
+
defaults.setup = (editor) => {
|
|
118
|
+
editor.on('change', () => {
|
|
119
|
+
this.tinymce.triggerSave();
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
options = mergeDeep({}, defaults, options);
|
|
124
|
+
|
|
125
|
+
if (options.plugins.indexOf('unicorndragdrop') === -1) {
|
|
126
|
+
options.plugins.push('unicorndragdrop');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return options;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
insert(text: string) {
|
|
133
|
+
this.editor?.insertContent(text);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getValue(): string {
|
|
137
|
+
return this.editor?.getContent() ?? '';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
setValue(text: string): void {
|
|
141
|
+
this.editor?.setContent(text);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// filePickerCallback(callback, value, meta) {
|
|
145
|
+
// const input = document.createElement('input');
|
|
146
|
+
// input.setAttribute('type', 'file');
|
|
147
|
+
// input.style.display = 'none';
|
|
148
|
+
//
|
|
149
|
+
// if (meta.filetype === 'image') {
|
|
150
|
+
// input.setAttribute('accept', `image/\*`);
|
|
151
|
+
// }
|
|
152
|
+
//
|
|
153
|
+
// document.body.appendChild(input);
|
|
154
|
+
//
|
|
155
|
+
// input.onchange = function () {
|
|
156
|
+
// const file = this.files[0];
|
|
157
|
+
//
|
|
158
|
+
// const reader = new FileReader();
|
|
159
|
+
// reader.onload = function () {
|
|
160
|
+
// const id = 'blobid' + (new Date()).getTime();
|
|
161
|
+
// const blobCache = tinymce.activeEditor.editorUpload.blobCache;
|
|
162
|
+
// const base64 = reader.result.split(',')[1];
|
|
163
|
+
// const blobInfo = blobCache.create(id, file, base64);
|
|
164
|
+
// blobCache.add(blobInfo);
|
|
165
|
+
//
|
|
166
|
+
// /* call the callback and populate the Title field with the file name */
|
|
167
|
+
// callback(blobInfo.blobUri(), { title: file.name, text: file.name });
|
|
168
|
+
// };
|
|
169
|
+
// reader.readAsDataURL(file);
|
|
170
|
+
// input.remove();
|
|
171
|
+
// };
|
|
172
|
+
//
|
|
173
|
+
// input.click();
|
|
174
|
+
// }
|
|
175
|
+
|
|
176
|
+
async imageUploadHandler(blobInfo: UploadHandlerParams[0], progress: UploadHandlerParams[1]) {
|
|
177
|
+
const element = this.element;
|
|
178
|
+
|
|
179
|
+
element.dispatchEvent(new CustomEvent('upload-start'));
|
|
180
|
+
|
|
181
|
+
const formData = new FormData();
|
|
182
|
+
formData.append('file', blobInfo.blob(), blobInfo.filename());
|
|
183
|
+
|
|
184
|
+
const stack = useStack(this.options.unicorn.stack_name);
|
|
185
|
+
stack.push(true);
|
|
186
|
+
|
|
187
|
+
const { post, isAxiosError } = await useHttpClient();
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
let res = await post(
|
|
191
|
+
this.options.images_upload_url,
|
|
192
|
+
formData,
|
|
193
|
+
{
|
|
194
|
+
withCredentials: false,
|
|
195
|
+
onUploadProgress: (e) => {
|
|
196
|
+
progress(e.loaded / e.total! * 100);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
element.dispatchEvent(new CustomEvent('upload-success'));
|
|
201
|
+
|
|
202
|
+
return res.data.data.url;
|
|
203
|
+
} catch (err) {
|
|
204
|
+
if (isAxiosError(err)) {
|
|
205
|
+
const message = err?.response?.data?.message || err.message;
|
|
206
|
+
console.error(err?.response?.data?.message || err.message, err);
|
|
207
|
+
element.dispatchEvent(new CustomEvent('upload-error', { detail: err }));
|
|
208
|
+
|
|
209
|
+
return Promise.reject({ message, remove: true });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
throw err;
|
|
213
|
+
} finally {
|
|
214
|
+
element.dispatchEvent(new CustomEvent('upload-complete'));
|
|
215
|
+
stack.pop();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function registerDragPlugin(tinymce: TinyMCE) {
|
|
221
|
+
tinymce.PluginManager.add('unicorndragdrop', function (editor) {
|
|
222
|
+
// Reset the drop area border
|
|
223
|
+
tinymce.DOM.bind(document, 'dragleave', function (e) {
|
|
224
|
+
e.stopPropagation();
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
|
|
227
|
+
if (tinymce.activeEditor) {
|
|
228
|
+
tinymce.activeEditor.contentAreaContainer.style.transition = 'all .3s';
|
|
229
|
+
tinymce.activeEditor.contentAreaContainer.style.borderWidth = '';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return false;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
if (typeof FormData !== 'undefined') {
|
|
236
|
+
|
|
237
|
+
// Fix for Chrome
|
|
238
|
+
editor.on('dragenter', e => {
|
|
239
|
+
e.stopPropagation();
|
|
240
|
+
return false;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Notify user when file is over the drop area
|
|
244
|
+
editor.on('dragover', e => {
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
|
|
247
|
+
if (tinymce.activeEditor) {
|
|
248
|
+
tinymce.activeEditor.contentAreaContainer.style.transition = 'all .3s';
|
|
249
|
+
tinymce.activeEditor.contentAreaContainer.style.border = '3px dashed rgba(0, 0, 0, .35)';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return false;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
editor.on('drop', e => {
|
|
256
|
+
editor.contentAreaContainer.style.borderWidth = '';
|
|
257
|
+
editor.contentAreaContainer.style.borderWidth = '';
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
return Promise.resolve();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface TinymceModule {
|
|
266
|
+
get: typeof get;
|
|
267
|
+
create: typeof create;
|
|
268
|
+
destroy: typeof destroy;
|
|
269
|
+
addHook: typeof addHook;
|
|
270
|
+
clearHooks: typeof clearHooks;
|
|
271
|
+
TinymceController: typeof TinymceController;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare global {
|
|
275
|
+
var tinymce: TinyMCE;
|
|
276
|
+
}
|