@ebl-vue/editor-full 2.31.34 → 2.31.36

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.
Files changed (97) hide show
  1. package/.postcssrc.yml +33 -0
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.mjs +183 -182
  4. package/dist/index.mjs.map +1 -0
  5. package/package.json +1 -1
  6. package/postcss.config.js +15 -0
  7. package/src/components/Editor/Editor.vue +293 -0
  8. package/src/components/index.ts +27 -0
  9. package/src/constants/index.ts +1 -0
  10. package/src/i18n/zh-cn.ts +160 -0
  11. package/src/icons/index.ts +93 -0
  12. package/src/index.ts +21 -0
  13. package/src/installer.ts +21 -0
  14. package/src/plugins/alert/index.ts +455 -0
  15. package/src/plugins/block-alignment/index.ts +117 -0
  16. package/src/plugins/block-alignment/readme.md +1 -0
  17. package/src/plugins/code/LICENSE +21 -0
  18. package/src/plugins/code/index.ts +619 -0
  19. package/src/plugins/code/utils/string.ts +34 -0
  20. package/src/plugins/color-picker/index.ts +132 -0
  21. package/src/plugins/delimiter/index.ts +121 -0
  22. package/src/plugins/drag-drop/index.css +19 -0
  23. package/src/plugins/drag-drop/index.ts +151 -0
  24. package/src/plugins/drag-drop/readme.md +1 -0
  25. package/src/plugins/header/H1.ts +404 -0
  26. package/src/plugins/header/H2.ts +403 -0
  27. package/src/plugins/header/H3.ts +404 -0
  28. package/src/plugins/header/H4.ts +404 -0
  29. package/src/plugins/header/H5.ts +403 -0
  30. package/src/plugins/header/H6.ts +404 -0
  31. package/src/plugins/header/index.ts +15 -0
  32. package/src/plugins/header/types.d.ts +46 -0
  33. package/src/plugins/imageResizeCrop/ImageTune.ts +635 -0
  34. package/src/plugins/imageResizeCrop/index.css +230 -0
  35. package/src/plugins/imageResizeCrop/index.ts +5 -0
  36. package/src/plugins/imageResizeCrop/types.d.ts +23 -0
  37. package/src/plugins/imageTool/index.ts +510 -0
  38. package/src/plugins/imageTool/types/codexteam__ajax.d.ts +89 -0
  39. package/src/plugins/imageTool/types/types.ts +236 -0
  40. package/src/plugins/imageTool/ui.ts +313 -0
  41. package/src/plugins/imageTool/uploader.ts +287 -0
  42. package/src/plugins/imageTool/utils/dom.ts +24 -0
  43. package/src/plugins/imageTool/utils/index.ts +73 -0
  44. package/src/plugins/imageTool/utils/isPromise.ts +10 -0
  45. package/src/plugins/indent/index.ts +695 -0
  46. package/src/plugins/inline-code/index.ts +203 -0
  47. package/src/plugins/list/ListRenderer/ChecklistRenderer.ts +208 -0
  48. package/src/plugins/list/ListRenderer/ListRenderer.ts +73 -0
  49. package/src/plugins/list/ListRenderer/OrderedListRenderer.ts +123 -0
  50. package/src/plugins/list/ListRenderer/UnorderedListRenderer.ts +123 -0
  51. package/src/plugins/list/ListRenderer/index.ts +6 -0
  52. package/src/plugins/list/ListTabulator/index.ts +1179 -0
  53. package/src/plugins/list/index.ts +488 -0
  54. package/src/plugins/list/styles/CssPrefix.ts +4 -0
  55. package/src/plugins/list/types/Elements.ts +14 -0
  56. package/src/plugins/list/types/ItemMeta.ts +40 -0
  57. package/src/plugins/list/types/ListParams.ts +102 -0
  58. package/src/plugins/list/types/ListRenderer.ts +6 -0
  59. package/src/plugins/list/types/OlCounterType.ts +63 -0
  60. package/src/plugins/list/types/index.ts +14 -0
  61. package/src/plugins/list/utils/focusItem.ts +18 -0
  62. package/src/plugins/list/utils/getChildItems.ts +40 -0
  63. package/src/plugins/list/utils/getItemChildWrapper.ts +10 -0
  64. package/src/plugins/list/utils/getItemContentElement.ts +10 -0
  65. package/src/plugins/list/utils/getSiblings.ts +52 -0
  66. package/src/plugins/list/utils/isLastItem.ts +9 -0
  67. package/src/plugins/list/utils/itemHasSublist.ts +10 -0
  68. package/src/plugins/list/utils/normalizeData.ts +83 -0
  69. package/src/plugins/list/utils/removeChildWrapperIfEmpty.ts +31 -0
  70. package/src/plugins/list/utils/renderToolboxInput.ts +113 -0
  71. package/src/plugins/list/utils/stripNumbers.ts +7 -0
  72. package/src/plugins/list/utils/type-guards.ts +8 -0
  73. package/src/plugins/marker/index.ts +199 -0
  74. package/src/plugins/outline/index.ts +62 -0
  75. package/src/plugins/outline/outline.css +52 -0
  76. package/src/plugins/paragraph/index.ts +384 -0
  77. package/src/plugins/paragraph/types/icons.d.ts +4 -0
  78. package/src/plugins/paragraph/utils/makeFragment.ts +17 -0
  79. package/src/plugins/quote/index.ts +203 -0
  80. package/src/plugins/table/index.ts +4 -0
  81. package/src/plugins/table/plugin.ts +255 -0
  82. package/src/plugins/table/table.ts +1202 -0
  83. package/src/plugins/table/toolbox.ts +166 -0
  84. package/src/plugins/table/utils/dom.ts +130 -0
  85. package/src/plugins/table/utils/popover.ts +185 -0
  86. package/src/plugins/table/utils/throttled.ts +22 -0
  87. package/src/plugins/underline/index.ts +214 -0
  88. package/src/plugins/undo/index.ts +526 -0
  89. package/src/plugins/undo/observer.ts +101 -0
  90. package/src/plugins/undo/vanilla-caret-js.ts +102 -0
  91. package/src/style.css +139 -0
  92. package/src/types.ts +3 -0
  93. package/src/utils/AxiosService.ts +87 -0
  94. package/src/utils/index.ts +15 -0
  95. package/src/utils/install.ts +19 -0
  96. package/tsconfig.json +37 -0
  97. package/vite.config.ts +81 -0
@@ -0,0 +1,287 @@
1
+
2
+
3
+ import type { UploadOptions } from './types/types';
4
+ import type { UploadResponseFormat, ImageConfig } from './types/types';
5
+ import axios, { AxiosInstance } from "axios";
6
+ import { selectFiles } from './utils/index';
7
+ /**
8
+ * Params interface for Uploader constructor
9
+ */
10
+ interface UploaderParams {
11
+ /**
12
+ * Configuration for the uploader
13
+ */
14
+ config: ImageConfig;
15
+
16
+ /**
17
+ * Handles the upload response.
18
+ * @param {UploadResponseFormat} response - Response format expected from the backend on file uploading.
19
+ * @returns {void}
20
+ */
21
+ onUpload: (response: UploadResponseFormat) => void;
22
+
23
+ /**
24
+ *
25
+ * @param error : error type
26
+ * @returns void
27
+ */
28
+ onError: (error: string) => void;
29
+ }
30
+
31
+ /**
32
+ * Module for file uploading. Handle 3 scenarios:
33
+ * 1. Select file from device and upload
34
+ * 2. Upload by pasting URL
35
+ * 3. Upload by pasting file from Clipboard or by Drag'n'Drop
36
+ */
37
+ export default class Uploader {
38
+ private config: ImageConfig;
39
+ private onUpload: (response: UploadResponseFormat) => void;
40
+ private onError: (error: string) => void;
41
+ /**
42
+ * @param params - uploader module params
43
+ * @param params.config - image tool config
44
+ * @param params.onUpload - one callback for all uploading (file, url, d-n-d, pasting)
45
+ * @param params.onError - callback for uploading errors
46
+ */
47
+ constructor({ config, onUpload, onError }: UploaderParams) {
48
+ this.config = config;
49
+ this.onUpload = onUpload;
50
+ this.onError = onError;
51
+ }
52
+
53
+ /**
54
+ * Handle clicks on the upload file button
55
+ * Fires ajax.transport()
56
+ * @param onPreview - callback fired when preview is ready
57
+ */
58
+ public async uploadSelectedFile({ onPreview, noSelectedFile }: UploadOptions) {
59
+
60
+ const preparePreview = function (file: File): void {
61
+ const reader = new FileReader();
62
+
63
+ reader.readAsDataURL(file);
64
+ reader.onload = (e) => {
65
+ onPreview((e.target as FileReader).result as string);
66
+ };
67
+ };
68
+
69
+ /**
70
+ * Custom uploading
71
+ * or default uploading
72
+ */
73
+
74
+ let cdn: string = "";
75
+ let objectKey: string = "";
76
+
77
+
78
+
79
+ //选获取上传文件的地址
80
+ const files = await selectFiles({ accept: this.config.types ?? 'image/*' });
81
+
82
+ if (files && files.length > 0) {
83
+ preparePreview(files[0]);
84
+ } else {
85
+ noSelectedFile();
86
+ return
87
+ }
88
+
89
+ const file = files[0];
90
+ const fileTypes = this.config.types?this.config!.types.split(","):[];
91
+ let suffixIndex = file.name.lastIndexOf(".");
92
+ let suffix = file.name.slice(suffixIndex);
93
+
94
+ if (!fileTypes.includes(suffix.toLowerCase())) {
95
+ this.onError("文件类型不支持");
96
+ return;
97
+ }
98
+
99
+ let headers: Record<string, string> = {};
100
+ if (this.config.userStore) {
101
+ const token = this.config.userStore.token;
102
+ const tokenName = this.config.userStore.tokenName;
103
+ const tokenPrefix = this.config.userStore.tokenPrefix;
104
+ if (token && tokenName) {
105
+ headers[tokenName] = tokenPrefix + " " + token
106
+ }
107
+ }
108
+ headers["Content-Type"] = "application/json";
109
+ const axiosInstance: AxiosInstance = axios.create({
110
+ timeout: 1800000,
111
+ headers: headers,
112
+ });
113
+
114
+ //console.log("this.config.endpoints", this.config.endpoints);
115
+ const uploadBodyRes = await axiosInstance.post(this.config.endpoints.byFile!, {
116
+ "fileName": file.name,
117
+ "contentType": file.type
118
+ })
119
+ if (uploadBodyRes.status !== 200) {
120
+ this.onError(uploadBodyRes.statusText);
121
+ return;
122
+ }
123
+ const uploadRes = uploadBodyRes.data;
124
+ if (!uploadRes.success) {
125
+ this.onError(uploadRes.message!);
126
+ return;
127
+ }
128
+ console.log(uploadRes);
129
+ cdn = uploadRes.data.cdn;
130
+ objectKey = uploadRes.data.objectKey;
131
+
132
+ //headers["Content-Type"] = file.type;
133
+
134
+ const axiosUpload: AxiosInstance = axios.create({
135
+ timeout: 1800000,
136
+ headers: { "Content-Type": file.type }
137
+ });
138
+ let upload = axiosUpload.put(uploadRes.data.presignedUrl, file);
139
+
140
+
141
+ upload.then((response) => {
142
+ let res: any = {
143
+
144
+ }
145
+ if (response.status === 200) {
146
+ res = {
147
+ success: 1,
148
+ file: { url: cdn + objectKey }
149
+ }
150
+ } else {
151
+ res = {
152
+ success: 0,
153
+ message: response.statusText
154
+ }
155
+ }
156
+ this.onUpload(res);
157
+ }).catch((error: string) => {
158
+ this.onError(error);
159
+ });
160
+ }
161
+
162
+ /**
163
+ * Handle clicks on the upload file button
164
+ * Fires ajax.post()
165
+ * @param url - image source url
166
+ */
167
+ public uploadByUrl(url: string): void {
168
+ let upload;
169
+ let headers: Record<string, string> = { "Content-Type": "application/json" };
170
+ if (this.config.userStore) {
171
+ const token = this.config.userStore.token;
172
+ const tokenName = this.config.userStore.tokenName;
173
+ const tokenPrefix = this.config.userStore.tokenPrefix;
174
+ if (token && tokenName) {
175
+ headers[tokenName] = tokenPrefix + " " + token
176
+ }
177
+ }
178
+ const axiosInstance: AxiosInstance = axios.create({
179
+ timeout: 1800000,
180
+ headers: headers,
181
+ });
182
+ upload = axiosInstance.post(this.config.endpoints.byUrl!, {
183
+ "url": url,
184
+ "accept": ".jpg,.jpeg,.gif,.png,.webp"
185
+ })
186
+
187
+
188
+
189
+
190
+ upload.then((response) => {
191
+
192
+ if(response.status !== 200||response.data.success===false){
193
+ this.onError(response.data.message!);
194
+ return;
195
+ }
196
+
197
+ let cdn = response.data.data.cdn;
198
+ let objectKey = response.data.data.objectKey;
199
+
200
+ let res = {
201
+ success: 1,
202
+ file: { url: cdn + objectKey }
203
+ };
204
+ this.onUpload(res);
205
+ }).catch((error: string) => {
206
+ this.onError(error);
207
+ });
208
+
209
+ }
210
+
211
+ /**
212
+ * Handle clicks on the upload file button
213
+ * Fires ajax.post()
214
+ * @param file - file pasted by drag-n-drop
215
+ * @param onPreview - file pasted by drag-n-drop
216
+ */
217
+ public async uploadByFile(file: Blob, { onPreview }: UploadOptions) {
218
+
219
+
220
+ const fileTypes = this.config.types?this.config!.types.split(","):[];
221
+
222
+ let suffixIndex = (file as File).name.lastIndexOf(".");
223
+ let suffix = (file as File).name.slice(suffixIndex);
224
+
225
+ if (!fileTypes.includes(suffix.toLowerCase())) {
226
+ this.onError("文件类型不支持");
227
+ return;
228
+ }
229
+
230
+
231
+
232
+ let headers: Record<string, string> = {};
233
+ if (this.config.userStore) {
234
+ const token = this.config.userStore.token;
235
+ const tokenName = this.config.userStore.tokenName;
236
+ const tokenPrefix = this.config.userStore.tokenPrefix;
237
+ if (token && tokenName) {
238
+ headers[tokenName] = tokenPrefix + " " + token
239
+ }
240
+ }
241
+ const axiosInstance: AxiosInstance = axios.create({
242
+ timeout: 1800000,
243
+ headers: headers,
244
+ });
245
+ headers["Content-Type"] = "application/json";
246
+
247
+ const uploadBodyRes = await axiosInstance.post(this.config.endpoints.byFile!, {
248
+ "fileName": (file as File).name,
249
+ "contentType": file.type
250
+ })
251
+ if (uploadBodyRes.status !== 200) {
252
+ this.onError(uploadBodyRes.statusText);
253
+ return;
254
+ }
255
+ const uploadRes = uploadBodyRes.data;
256
+ if (!uploadRes.success) {
257
+ this.onError(uploadRes.message!);
258
+ return;
259
+ }
260
+ console.log(uploadRes);
261
+ let cdn = uploadRes.data.cdn;
262
+ let objectKey = uploadRes.data.objectKey;
263
+
264
+
265
+ headers["Content-Type"] = file.type;
266
+ let upload = axiosInstance.put(uploadRes.data.presignedUrl, file);
267
+ upload.then((response) => {
268
+ let res:any = {
269
+
270
+ }
271
+ if (response.status === 200) {
272
+ res = {
273
+ success: 1,
274
+ file: { url: cdn + objectKey }
275
+ }
276
+ } else {
277
+ res = {
278
+ success: 0,
279
+ message: response.statusText
280
+ }
281
+ }
282
+ this.onUpload(res);
283
+ }).catch((error: string) => {
284
+ this.onError(error);
285
+ });
286
+ }
287
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Helper for making Elements with attributes
3
+ * @param tagName - new Element tag name
4
+ * @param classNames - list or name of CSS class
5
+ * @param attributes - any attributes
6
+ * @returns
7
+ */
8
+ export function make(tagName: string, classNames: string[] | string | null = null, attributes: { [key: string]: string | boolean } = {}): HTMLElement {
9
+ const el = document.createElement(tagName);
10
+
11
+ if (Array.isArray(classNames)) {
12
+ el.classList.add(...classNames);
13
+ } else if (classNames !== null) {
14
+ el.classList.add(classNames);
15
+ }
16
+
17
+ for (const attrName in attributes) {
18
+ if (attributes.hasOwnProperty(attrName)) {
19
+ (el as unknown as { [key: string]: string | boolean })[attrName] = attributes[attrName];
20
+ }
21
+ }
22
+
23
+ return el;
24
+ }
@@ -0,0 +1,73 @@
1
+ interface IConfig {
2
+ multiple?: boolean;
3
+ accept?: string;
4
+ }
5
+ export function selectFiles(config = {} as IConfig): Promise<any> {
6
+ let fileCancle = true;
7
+ return new Promise((resolve, reject) => {
8
+ /**
9
+ * Create a new INPUT element
10
+ * @type {HTMLElement}
11
+ */
12
+ let inputElement = document.createElement('INPUT') as HTMLInputElement;
13
+
14
+ /**
15
+ * Set a 'FILE' type for this input element
16
+ * @type {string}
17
+ */
18
+ inputElement.type = 'file';
19
+
20
+ if (config.multiple) {
21
+ inputElement.setAttribute('multiple', 'multiple');
22
+ }
23
+
24
+ if (config.accept) {
25
+ inputElement.setAttribute('accept', config.accept);
26
+ }
27
+
28
+ /**
29
+ * Do not show element
30
+ */
31
+ inputElement.style.display = 'none';
32
+
33
+ /**
34
+ * Append element to the body
35
+ * Fix using module on mobile devices
36
+ */
37
+ document.body.appendChild(inputElement);
38
+
39
+ /**
40
+ * Add onchange listener for «choose file» pop-up
41
+ */
42
+ inputElement.addEventListener('change', event => {
43
+ console.log("选中文件")
44
+ fileCancle = false;
45
+ /**
46
+ * Get files from input field
47
+ */
48
+ const files = (event.target as HTMLInputElement).files;
49
+
50
+ /**
51
+ * Return ready to be uploaded files array
52
+ */
53
+ resolve(files);
54
+
55
+ /**
56
+ * Remove element from a DOM
57
+ */
58
+ document.body.removeChild(inputElement);
59
+ }, false);
60
+ window.addEventListener("focus", () => {
61
+ setTimeout(() => {
62
+ if (fileCancle) {
63
+ console.log("取消选择文件")
64
+ resolve([]);
65
+ }
66
+ }, 1000)
67
+ },{once: true})
68
+ /**
69
+ * Fire click event on «input file» field
70
+ */
71
+ inputElement.click();
72
+ });
73
+ };
@@ -0,0 +1,10 @@
1
+ import type { UploadResponseFormat } from '../types/types';
2
+
3
+ /**
4
+ * Check if passed object is a Promise
5
+ * @param object - object to check
6
+ * @returns
7
+ */
8
+ export default function isPromise(object: Promise<UploadResponseFormat>): object is Promise<UploadResponseFormat> {
9
+ return object !== undefined && typeof object.then === 'function';
10
+ }