@ebl-vue/editor-full 1.0.12 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.mjs +860 -445
  3. package/dist/index.mjs.map +1 -1
  4. package/package.json +2 -1
  5. package/src/components/Editor/Editor.vue +47 -12
  6. package/src/i18n/zh-cn.ts +6 -1
  7. package/src/icons/index.ts +15 -0
  8. package/src/installer.ts +4 -3
  9. package/src/plugins/alert/index.ts +19 -27
  10. package/src/plugins/block-alignment/index.ts +4 -3
  11. package/src/plugins/code/index.ts +3 -2
  12. package/src/plugins/color-picker/index.ts +3 -11
  13. package/src/plugins/delimiter/index.ts +5 -6
  14. package/src/plugins/header/H1.ts +1 -1
  15. package/src/plugins/header/H2.ts +1 -1
  16. package/src/plugins/header/H3.ts +1 -1
  17. package/src/plugins/header/H4.ts +1 -2
  18. package/src/plugins/header/H5.ts +1 -3
  19. package/src/plugins/header/H6.ts +1 -3
  20. package/src/plugins/imageResizeCrop/ImageTune.ts +900 -0
  21. package/src/plugins/imageResizeCrop/index.css +234 -0
  22. package/src/plugins/imageResizeCrop/index.ts +5 -0
  23. package/src/plugins/imageResizeCrop/types.d.ts +23 -0
  24. package/src/plugins/imageTool/index.css +145 -0
  25. package/src/plugins/imageTool/index.ts +538 -0
  26. package/src/plugins/imageTool/types/codexteam__ajax.d.ts +89 -0
  27. package/src/plugins/imageTool/types/types.ts +236 -0
  28. package/src/plugins/imageTool/ui.ts +313 -0
  29. package/src/plugins/imageTool/uploader.ts +268 -0
  30. package/src/plugins/imageTool/utils/dom.ts +24 -0
  31. package/src/plugins/imageTool/utils/index.ts +73 -0
  32. package/src/plugins/imageTool/utils/isPromise.ts +10 -0
  33. package/src/plugins/indent/index.ts +5 -7
  34. package/src/plugins/inline-code/index.ts +2 -5
  35. package/src/plugins/list/ListRenderer/ChecklistRenderer.ts +1 -4
  36. package/src/plugins/list/index.ts +20 -37
  37. package/src/plugins/list/types/OlCounterType.ts +1 -1
  38. package/src/plugins/marker/index.ts +28 -16
  39. package/src/plugins/paragraph/index.ts +3 -2
  40. package/src/plugins/quote/index.ts +1 -4
  41. package/src/plugins/table/plugin.ts +1 -1
  42. package/src/plugins/table/table.ts +40 -38
  43. package/src/plugins/table/toolbox.ts +5 -4
  44. package/src/plugins/table/utils/dom.ts +15 -14
  45. package/src/plugins/table/utils/popover.ts +28 -15
  46. package/src/plugins/underline/index.ts +2 -4
  47. package/src/plugins/undo/index.ts +48 -33
  48. package/src/plugins/undo/observer.ts +3 -3
  49. package/src/utils/AxiosService.ts +87 -0
  50. package/types/index.d.ts +6 -0
  51. package/vite.config.ts +3 -1
  52. package/src/plugins/list/styles/icons/index.ts +0 -10
@@ -1,5 +1,6 @@
1
1
  import VanillaCaret from "vanilla-caret-js";
2
2
  import Observer from "./observer";
3
+ import type EditorJS from '@ebl-vue/editorjs';
3
4
 
4
5
  /**
5
6
  * https://github.com/kommitters/editorjs-undo/tree/main
@@ -14,10 +15,23 @@ import Observer from "./observer";
14
15
  * @property {Object} initialItem - Initial data object.
15
16
  */
16
17
  export default class Undo {
18
+ editor: EditorJS | null;
19
+ holder: any;
20
+ defaultBlock: any;
21
+ blocks: any;
22
+ caret: any;
23
+ shouldSaveHistory: boolean;
24
+ readOnly: any;
25
+ maxLength: any;
26
+ onUpdate: any;
27
+ config: { debounceTimer: any; shortcuts: { undo: any; redo: any; }; };
28
+ initialItem: any;
29
+ stack: any;
30
+ position: number=0;
17
31
  /**
18
32
  * @param options — Plugin custom options.
19
33
  */
20
- constructor({ editor, config = {}, onUpdate, maxLength }) {
34
+ constructor({ editor, config = {}, onUpdate, maxLength }:{ editor: EditorJS, config?: any, onUpdate?: any, maxLength?: any }) {
21
35
  const defaultOptions = {
22
36
  maxLength: 30,
23
37
  onUpdate() {},
@@ -80,7 +94,7 @@ export default class Undo {
80
94
  * @param {Object} stack Changes history stack.
81
95
  * @param {Number} stack Limit of changes recorded by the history stack.
82
96
  */
83
- truncate(stack, limit) {
97
+ truncate(stack: any, limit: number) {
84
98
  while (stack.length > limit) {
85
99
  stack.shift();
86
100
  }
@@ -91,7 +105,7 @@ export default class Undo {
91
105
  *
92
106
  * @param {Object} initialItem Initial data provided by the user.
93
107
  */
94
- initialize(initialItem) {
108
+ initialize(initialItem: any) {
95
109
  const initialData =
96
110
  "blocks" in initialItem ? initialItem.blocks : initialItem;
97
111
  const initialIndex = initialData.length - 1;
@@ -142,7 +156,7 @@ export default class Undo {
142
156
  * @param {Object} newData New data to be saved in the history stack.
143
157
  * @returns {Boolean}
144
158
  */
145
- editorDidUpdate(newData) {
159
+ editorDidUpdate(newData: any) {
146
160
  const { state } = this.stack[this.position];
147
161
  if (!newData.length) return false;
148
162
  if (newData.length !== state.length) return true;
@@ -153,7 +167,7 @@ export default class Undo {
153
167
  /**
154
168
  * Adds the saved data in the history stack and updates current position.
155
169
  */
156
- save(state) {
170
+ save(state: any) {
157
171
  if (this.position >= this.maxLength) {
158
172
  this.truncate(this.stack, this.maxLength);
159
173
  }
@@ -182,7 +196,7 @@ export default class Undo {
182
196
  * @param {Number} index is the block index
183
197
  * @returns The caret position
184
198
  */
185
- getCaretIndex(index) {
199
+ getCaretIndex(index: number) {
186
200
  const blocks = this.holder.getElementsByClassName("ce-block__content");
187
201
  const caretBlock = new VanillaCaret(blocks[index].firstChild);
188
202
 
@@ -195,7 +209,7 @@ export default class Undo {
195
209
  * @param {Array} compState is the state to compare and know the deleted block.
196
210
  * @param {Number} index is the block index in state.
197
211
  */
198
- insertDeletedBlock(state, compState, index) {
212
+ insertDeletedBlock(state: any, compState: any, index: number) {
199
213
  for (let i = 0; i < state.length; i += 1) {
200
214
  if (!compState[i] || state[i].id !== compState[i].id) {
201
215
  this.blocks.insert(state[i].type, state[i].data, {}, i, true);
@@ -211,9 +225,9 @@ export default class Undo {
211
225
  * @param {Array} compState is the state to compare and know the dropped block.
212
226
  * @returns {Boolean} true if the block was dropped
213
227
  */
214
- blockWasDropped(state, compState) {
228
+ blockWasDropped(state: any, compState: any) {
215
229
  if (state.length === compState.length) {
216
- return state.some((block, i) => block.id !== compState[i].id);
230
+ return state.some((block: any, i: number) => block.id !== compState[i].id);
217
231
  }
218
232
  return false;
219
233
  }
@@ -224,7 +238,7 @@ export default class Undo {
224
238
  * @param {Array} compState is the state to compare if there was a deleted block.
225
239
  * @returns {Boolean} true if a block was inserted previously.
226
240
  */
227
- blockWasSkipped(state, compState) {
241
+ blockWasSkipped(state: any, compState: any) {
228
242
  return state.length !== compState.length;
229
243
  }
230
244
 
@@ -234,7 +248,7 @@ export default class Undo {
234
248
  * @param {Number} compIndex is the index to compare and know if the block was inserted previously
235
249
  * @returns true if the content in a block without the focus was modified.
236
250
  */
237
- contentChangedInNoFocusBlock(index, compIndex) {
251
+ contentChangedInNoFocusBlock(index: number, compIndex: number) {
238
252
  return index !== compIndex;
239
253
  }
240
254
 
@@ -244,7 +258,7 @@ export default class Undo {
244
258
  * @param {Array} compState is the state to compare and know if a block was deleted.
245
259
  * @returns {Boolean} true if a block was deleted previously.
246
260
  */
247
- blockWasDeleted(state, compState) {
261
+ blockWasDeleted(state: any, compState: any) {
248
262
  return state.length > compState.length;
249
263
  }
250
264
 
@@ -255,7 +269,7 @@ export default class Undo {
255
269
  * @param {Number} index is the block index in state.
256
270
  * @returns {Boolean} true if a block was deleted previously.
257
271
  */
258
- contentWasCopied(state, compState, index) {
272
+ contentWasCopied(state: any, compState: any, index: number) {
259
273
  return Object.keys(state[index].data).length === 0
260
274
  && JSON.stringify(compState[index + 1]) !== JSON.stringify(state[index + 1]);
261
275
  }
@@ -315,7 +329,7 @@ export default class Undo {
315
329
  * @param {Number} caretIndex is the caret position
316
330
  * @param {Array} state is the current state according to this.position.
317
331
  */
318
- setCaretIndex(index, caretIndex) {
332
+ setCaretIndex(index: number, caretIndex: number) {
319
333
  if (caretIndex && caretIndex !== -1) {
320
334
  const blocks = this.holder.getElementsByClassName("ce-block__content");
321
335
  const caretBlock = new VanillaCaret(blocks[index].firstChild);
@@ -330,7 +344,7 @@ export default class Undo {
330
344
  * @param {Array} state is the current state according to this.position.
331
345
  * @param {Number} index is the block index
332
346
  */
333
- async insertBlock(state, index) {
347
+ async insertBlock(state: any, index: number) {
334
348
  await this.blocks.insert(
335
349
  state[index].type,
336
350
  state[index].data,
@@ -346,7 +360,7 @@ export default class Undo {
346
360
  * @param {Array} state is the current state according to this.position.
347
361
  * @param {Number} index is the block index.
348
362
  */
349
- async insertSkippedBlocks(prevState, state, index) {
363
+ async insertSkippedBlocks(prevState: any, state: any, index: number) {
350
364
  for (let i = prevState.length; i < state.length; i += 1) {
351
365
  this.insertBlock(state, i);
352
366
  }
@@ -361,9 +375,9 @@ export default class Undo {
361
375
  * @param {Array} state is the current state according to this.position.
362
376
  * @param {Number} index is the block index.
363
377
  */
364
- async updateModifiedBlock(state, index) {
378
+ async updateModifiedBlock(state: any, index: number) {
365
379
  const block = state[index - 1];
366
- if (this.editor.blocks.getById(block.id)) return this.blocks.update(block.id, block.data);
380
+ if (this.editor!.blocks.getById(block.id)) return this.blocks.update(block.id, block.data);
367
381
  return this.blocks.render({ blocks: state });
368
382
  }
369
383
 
@@ -375,7 +389,7 @@ export default class Undo {
375
389
  this.position += 1;
376
390
  this.shouldSaveHistory = false;
377
391
  const { index, state, caretIndex } = this.stack[(this.position)];
378
- const { index: prevIndex, state: prevState } =
392
+ const { index:prevIndex, state: prevState } =
379
393
  this.stack[this.position - 1];
380
394
 
381
395
  if (this.blockWasDeleted(prevState, state)) {
@@ -432,8 +446,8 @@ export default class Undo {
432
446
  * @returns {Array}
433
447
  */
434
448
 
435
- parseKeys(keys) {
436
- const specialKeys = {
449
+ parseKeys(keys: string[]) {
450
+ const specialKeys: any = {
437
451
  CMD: /(Mac)/i.test(navigator.platform) ? "metaKey" : "ctrlKey",
438
452
  ALT: "altKey",
439
453
  SHIFT: "shiftKey",
@@ -457,23 +471,24 @@ export default class Undo {
457
471
  const { holder } = this;
458
472
  const { shortcuts } = this.config;
459
473
  const { undo, redo } = shortcuts;
460
- const keysUndo = undo.map((undoShortcut) => undoShortcut.replace(/ /g, "").split("+"));
461
- const keysRedo = redo.map((redoShortcut) => redoShortcut.replace(/ /g, "").split("+"));
474
+ const keysUndo = undo.map((undoShortcut: string) => undoShortcut.replace(/ /g, "").split("+"));
475
+ const keysRedo = redo.map((redoShortcut: string) => redoShortcut.replace(/ /g, "").split("+"));
462
476
 
463
477
  const keysUndoParsed = keysUndo.map((keys: string[]) => this.parseKeys(keys));
464
478
  const keysRedoParsed = keysRedo.map((keys: string[]) => this.parseKeys(keys));
465
479
 
466
- const twoKeysPressed = (e: KeyboardEvent, keys: string[]) =>
467
- keys.length === 2 && e[keys[0]] && (e.key.toLowerCase() === keys[1]);
468
- const threeKeysPressed = (e: KeyboardEvent, keys: string[]) =>
469
- keys.length === 3 && e[keys[0]] && e[keys[1]] && (e.key.toLowerCase() === keys[2]);
470
-
471
- const verifyListTwoKeysPressed = (e: KeyboardEvent, keysList) =>
472
- keysList.reduce((result, keys) => result || twoKeysPressed(e, keys), false);
473
- const verifyListThreeKeysPressed = (e: KeyboardEvent, keysList) =>
480
+ const twoKeysPressed = (e: any, keys: any) => {
481
+ return keys.length === 2 && e[keys[0]] && (e.key.toLowerCase() === keys[1]);
482
+ }
483
+ const threeKeysPressed = (e: any, keys: any) => {
484
+ return keys.length === 3 && e[keys[0]] && e[keys[1]] && (e.key.toLowerCase() === keys[2]);
485
+ }
486
+ const verifyListTwoKeysPressed = (e: KeyboardEvent, keysList:string[]) =>
487
+ keysList.reduce((result, keys:string) => result || twoKeysPressed(e, keys), false);
488
+ const verifyListThreeKeysPressed = (e: KeyboardEvent, keysList:string[]) =>
474
489
  keysList.reduce((result, keys) => result || threeKeysPressed(e, keys), false);
475
490
 
476
- const pressedKeys = (e: KeyboardEvent, keys, compKeys) => {
491
+ const pressedKeys = (e: KeyboardEvent, keys: string[], compKeys: string[]) => {
477
492
  if (verifyListTwoKeysPressed(e, keys) && !verifyListThreeKeysPressed(e, compKeys)) {
478
493
  return true;
479
494
  }
@@ -483,7 +498,7 @@ export default class Undo {
483
498
  return false;
484
499
  };
485
500
 
486
- const handleUndo = (e) => {
501
+ const handleUndo = (e: KeyboardEvent) => {
487
502
  if (pressedKeys(e, keysUndoParsed, keysRedoParsed)) {
488
503
  e.preventDefault();
489
504
  this.undo();
@@ -10,14 +10,14 @@ export default class Observer {
10
10
  private observer: MutationObserver | null;
11
11
  private debounceTimer: number;
12
12
  private mutationDebouncer: Function;
13
- private holder: string;
13
+ private holder: HTMLElement;
14
14
  /**
15
15
  * Creates a new instance of the Observer object.
16
16
  * @param {Function} registerChange - Function that register a change in the history stack.
17
17
  * @param {String} holder - Editor.js holder id.
18
18
  * @param {Number} debounceTimer Delay time for the debouncer.
19
19
  */
20
- constructor(registerChange: Function, holder: string, debounceTimer: number) {
20
+ constructor(registerChange: Function, holder: HTMLElement, debounceTimer: number) {
21
21
 
22
22
  this.holder = holder;
23
23
  this.observer = null;
@@ -39,7 +39,7 @@ export default class Observer {
39
39
  characterDataOldValue: true,
40
40
  };
41
41
 
42
- const target = this.holder.querySelector('.codex-editor__redactor');
42
+ const target = this.holder.querySelector('.codex-editor__redactor') as HTMLElement;
43
43
 
44
44
  this.observer = new MutationObserver((mutationList) => {
45
45
  this.mutationHandler(mutationList);
@@ -0,0 +1,87 @@
1
+ import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse } from "axios";
2
+ import { ElMessage } from "element-plus"
3
+
4
+
5
+ interface IAxiosServiceConstructorParams{
6
+ appBaseApi?: string,
7
+ timeout?:number,
8
+ eblStoreUser?: any|undefined
9
+ }
10
+
11
+ class AxiosService {
12
+ appBaseApi: string = "";
13
+ timeout: number = 30000;
14
+ eblStoreUser: any|undefined;
15
+ axiosInstance: AxiosInstance | undefined;
16
+
17
+ constructor(params?: IAxiosServiceConstructorParams | undefined ) {
18
+ if (typeof params !== "undefined") {
19
+ if (params.appBaseApi) {
20
+ this.appBaseApi = params.appBaseApi;
21
+ }
22
+
23
+ if (params.timeout) {
24
+ this.timeout = params.timeout;
25
+ }
26
+ if (params.eblStoreUser) {
27
+ this.eblStoreUser = params.eblStoreUser;
28
+ }
29
+
30
+
31
+ }
32
+ }
33
+ createAxios():AxiosInstance {
34
+ //创建实例
35
+ this.axiosInstance = axios.create({
36
+ baseURL: this.appBaseApi,
37
+ timeout: this.timeout,
38
+ headers: { "Content-Type": "application/json;charset=utf-8" },
39
+ });
40
+ //请求拦截
41
+ this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
42
+
43
+ if (this.eblStoreUser) {
44
+ const token = this.eblStoreUser.token;
45
+ const tokenName = this.eblStoreUser.tokenName;
46
+ const tokenPrefix = this.eblStoreUser.tokenPrefix;
47
+ if (token && tokenName) {
48
+ config.headers[tokenName] = tokenPrefix + " " + token;
49
+ }
50
+ }
51
+ return config;
52
+ }, (error: any) => {
53
+ return Promise.reject(error);
54
+ });
55
+
56
+ // 响应拦截器
57
+ this.axiosInstance.interceptors.response.use((response: AxiosResponse) => {
58
+ const { code, message } = response.data;
59
+ if (code === 1) {
60
+ return response.data;
61
+ }
62
+ ElMessage.error(message || "系统出错");
63
+ return response.data;
64
+ }, (error: any) => {
65
+ if (error) {
66
+ const { message } = error;
67
+ ElMessage.error(message || "系统出错");
68
+ }
69
+ return Promise.reject(error.message);
70
+ });
71
+ return this.axiosInstance;
72
+ }
73
+
74
+ static instance(appBaseApi: string|undefined, timeout: number, eblStoreUser?: any) {
75
+ let options:any = { appBaseApi: appBaseApi, timeout: timeout };
76
+ if (eblStoreUser) {
77
+ options.eblStoreUser = eblStoreUser;
78
+ }
79
+ let service = new AxiosService(options);
80
+ return service.createAxios();
81
+ }
82
+
83
+
84
+ }
85
+ export default AxiosService;
86
+ type IAxiosService = InstanceType<typeof AxiosService>;
87
+ export { IAxiosService }
package/types/index.d.ts CHANGED
@@ -11,3 +11,9 @@ declare module 'vue' {
11
11
 
12
12
  };
13
13
 
14
+
15
+ export interface IEblEditorSettings{
16
+ fileUploadEndpoint: string;
17
+ urlUploadEndpoint: string;
18
+ userStore: any;
19
+ }
package/vite.config.ts CHANGED
@@ -61,7 +61,9 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
61
61
  'shiki',
62
62
  '@editorjs/caret',
63
63
  '@editorjs/dom',
64
- 'vanilla-caret-js'
64
+ 'vanilla-caret-js',
65
+ '@codexteam/ajax',
66
+ 'axios'
65
67
 
66
68
  ],
67
69
  output: [
@@ -1,10 +0,0 @@
1
- /**
2
- * This file exports icons needed for Editorjs List plugin, but this icons are not released yet
3
- * @todo remove this file and use icons from codex-team/icons package, when version with this icons will be released
4
- */
5
- export const IconNumber = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10 14.2L10 7.4135C10 7.32872 9.90111 7.28241 9.83598 7.33668L7 9.7" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M13.2087 14.2H13.2" stroke="black" stroke-width="1.6" stroke-linecap="round"/></svg>';
6
- export const IconLowerRoman = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.2087 14.2H13.2" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M10 14.2L10 9.5" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M10 7.01L10 7" stroke="black" stroke-width="1.8" stroke-linecap="round"/></svg>';
7
- export const IconUpperRoman = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.2087 14.2H13.2" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M10 14.2L10 7.2" stroke="black" stroke-width="1.6" stroke-linecap="round"/></svg>';
8
- export const IconUpperAlpha = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16.0087 14.2H16" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M7 14.2L7.78865 12M13 14.2L12.1377 12M7.78865 12C7.78865 12 9.68362 7 10 7C10.3065 7 12.1377 12 12.1377 12M7.78865 12L12.1377 12" stroke="black" stroke-width="1.6" stroke-linecap="round"/></svg>';
9
- export const IconLowerAlpha = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14.2087 14.2H14.2" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M11.5 14.5C11.5 14.5 11 13.281 11 12.5M7 9.5C7 9.5 7.5 8.5 9 8.5C10.5 8.5 11 9.5 11 10.5L11 11.5M11 11.5L11 12.5M11 11.5C11 11.5 7 11 7 13C7 15.3031 11 15 11 12.5" stroke="black" stroke-width="1.6" stroke-linecap="round"/></svg>';
10
- export const IconStartWith = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8 14.2L8 7.4135C8 7.32872 7.90111 7.28241 7.83598 7.33668L5 9.7" stroke="black" stroke-width="1.6" stroke-linecap="round"/><path d="M14 13L16.4167 10.7778M16.4167 10.7778L14 8.5M16.4167 10.7778H11.6562" stroke="black" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>';