@ebl-vue/editor-full 2.31.25 → 2.31.31

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 (114) hide show
  1. package/dist/index.d.ts +1 -28
  2. package/dist/index.mjs +549 -728
  3. package/package.json +3 -3
  4. package/types/index.d.ts +5 -1
  5. package/.postcssrc.yml +0 -33
  6. package/dist/index.mjs.map +0 -1
  7. package/postcss.config.js +0 -15
  8. package/src/components/Editor/Editor.vue +0 -293
  9. package/src/components/Editor/EditorRender.vue +0 -274
  10. package/src/components/index.ts +0 -29
  11. package/src/constants/index.ts +0 -1
  12. package/src/i18n/zh-cn.ts +0 -158
  13. package/src/icons/index.ts +0 -93
  14. package/src/index.ts +0 -22
  15. package/src/installer.ts +0 -21
  16. package/src/plugins/alert/index.css +0 -150
  17. package/src/plugins/alert/index.ts +0 -456
  18. package/src/plugins/block-alignment/index.css +0 -9
  19. package/src/plugins/block-alignment/index.ts +0 -117
  20. package/src/plugins/block-alignment/readme.md +0 -1
  21. package/src/plugins/code/LICENSE +0 -21
  22. package/src/plugins/code/index.css +0 -214
  23. package/src/plugins/code/index.ts +0 -621
  24. package/src/plugins/code/utils/string.ts +0 -34
  25. package/src/plugins/color-picker/index.ts +0 -130
  26. package/src/plugins/color-picker/styles.css +0 -27
  27. package/src/plugins/delimiter/index.css +0 -14
  28. package/src/plugins/delimiter/index.ts +0 -121
  29. package/src/plugins/drag-drop/index.css +0 -19
  30. package/src/plugins/drag-drop/index.ts +0 -151
  31. package/src/plugins/drag-drop/readme.md +0 -1
  32. package/src/plugins/header/H1.ts +0 -404
  33. package/src/plugins/header/H2.ts +0 -403
  34. package/src/plugins/header/H3.ts +0 -404
  35. package/src/plugins/header/H4.ts +0 -404
  36. package/src/plugins/header/H5.ts +0 -403
  37. package/src/plugins/header/H6.ts +0 -404
  38. package/src/plugins/header/index.css +0 -20
  39. package/src/plugins/header/index.ts +0 -15
  40. package/src/plugins/header/types.d.ts +0 -46
  41. package/src/plugins/imageResizeCrop/ImageTune.ts +0 -916
  42. package/src/plugins/imageResizeCrop/index.css +0 -230
  43. package/src/plugins/imageResizeCrop/index.ts +0 -5
  44. package/src/plugins/imageResizeCrop/types.d.ts +0 -23
  45. package/src/plugins/imageTool/index.css +0 -156
  46. package/src/plugins/imageTool/index.ts +0 -538
  47. package/src/plugins/imageTool/types/codexteam__ajax.d.ts +0 -89
  48. package/src/plugins/imageTool/types/types.ts +0 -236
  49. package/src/plugins/imageTool/ui.ts +0 -313
  50. package/src/plugins/imageTool/uploader.ts +0 -272
  51. package/src/plugins/imageTool/utils/dom.ts +0 -24
  52. package/src/plugins/imageTool/utils/index.ts +0 -73
  53. package/src/plugins/imageTool/utils/isPromise.ts +0 -10
  54. package/src/plugins/indent/index.css +0 -86
  55. package/src/plugins/indent/index.ts +0 -695
  56. package/src/plugins/inline-code/index.css +0 -11
  57. package/src/plugins/inline-code/index.ts +0 -202
  58. package/src/plugins/list/ListRenderer/ChecklistRenderer.ts +0 -208
  59. package/src/plugins/list/ListRenderer/ListRenderer.ts +0 -73
  60. package/src/plugins/list/ListRenderer/OrderedListRenderer.ts +0 -123
  61. package/src/plugins/list/ListRenderer/UnorderedListRenderer.ts +0 -123
  62. package/src/plugins/list/ListRenderer/index.ts +0 -6
  63. package/src/plugins/list/ListTabulator/index.ts +0 -1179
  64. package/src/plugins/list/index.ts +0 -480
  65. package/src/plugins/list/styles/CssPrefix.ts +0 -4
  66. package/src/plugins/list/styles/input.css +0 -36
  67. package/src/plugins/list/styles/list.css +0 -165
  68. package/src/plugins/list/types/Elements.ts +0 -14
  69. package/src/plugins/list/types/ItemMeta.ts +0 -40
  70. package/src/plugins/list/types/ListParams.ts +0 -102
  71. package/src/plugins/list/types/ListRenderer.ts +0 -6
  72. package/src/plugins/list/types/OlCounterType.ts +0 -63
  73. package/src/plugins/list/types/index.ts +0 -14
  74. package/src/plugins/list/utils/focusItem.ts +0 -18
  75. package/src/plugins/list/utils/getChildItems.ts +0 -40
  76. package/src/plugins/list/utils/getItemChildWrapper.ts +0 -10
  77. package/src/plugins/list/utils/getItemContentElement.ts +0 -10
  78. package/src/plugins/list/utils/getSiblings.ts +0 -52
  79. package/src/plugins/list/utils/isLastItem.ts +0 -9
  80. package/src/plugins/list/utils/itemHasSublist.ts +0 -10
  81. package/src/plugins/list/utils/normalizeData.ts +0 -83
  82. package/src/plugins/list/utils/removeChildWrapperIfEmpty.ts +0 -31
  83. package/src/plugins/list/utils/renderToolboxInput.ts +0 -105
  84. package/src/plugins/list/utils/stripNumbers.ts +0 -7
  85. package/src/plugins/list/utils/type-guards.ts +0 -8
  86. package/src/plugins/marker/index.css +0 -4
  87. package/src/plugins/marker/index.ts +0 -199
  88. package/src/plugins/outline/index.css +0 -52
  89. package/src/plugins/outline/index.ts +0 -63
  90. package/src/plugins/paragraph/index.css +0 -23
  91. package/src/plugins/paragraph/index.ts +0 -381
  92. package/src/plugins/paragraph/types/icons.d.ts +0 -4
  93. package/src/plugins/paragraph/utils/makeFragment.ts +0 -17
  94. package/src/plugins/quote/index.css +0 -26
  95. package/src/plugins/quote/index.ts +0 -203
  96. package/src/plugins/table/index.ts +0 -4
  97. package/src/plugins/table/plugin.ts +0 -254
  98. package/src/plugins/table/style.css +0 -388
  99. package/src/plugins/table/table.ts +0 -1195
  100. package/src/plugins/table/toolbox.ts +0 -166
  101. package/src/plugins/table/utils/dom.ts +0 -130
  102. package/src/plugins/table/utils/popover.ts +0 -185
  103. package/src/plugins/table/utils/throttled.ts +0 -22
  104. package/src/plugins/underline/index.css +0 -3
  105. package/src/plugins/underline/index.ts +0 -214
  106. package/src/plugins/undo/index.ts +0 -524
  107. package/src/plugins/undo/observer.ts +0 -101
  108. package/src/style.css +0 -114
  109. package/src/types.ts +0 -3
  110. package/src/utils/AxiosService.ts +0 -87
  111. package/src/utils/index.ts +0 -15
  112. package/src/utils/install.ts +0 -19
  113. package/tsconfig.json +0 -37
  114. package/vite.config.ts +0 -81
@@ -1,621 +0,0 @@
1
- //https://github.com/yudaapratama/editorjs-shiki
2
- import './index.css';
3
- import type { API, BlockTool, BlockToolConstructorOptions, BlockToolData, PasteConfig, PasteEvent, SanitizerConfig, ToolboxConfig } from '@ebl-vue/editorjs';
4
- import { codeToHtml, bundledLanguagesInfo as languages } from 'shiki'
5
- import { getLineStartPosition } from './utils/string';
6
- import { IconCode ,IconCopy} from "../../icons";
7
-
8
- /**
9
- * CodeTool for Editor.js
10
- * @version 1.0.0
11
- * @license MIT
12
- */
13
-
14
- /**
15
- * Data structure for CodeTool's data
16
- */
17
- export type CodeData = BlockToolData<{
18
- /**
19
- * The code content input by the user
20
- */
21
- code: string;
22
- lang: string;
23
- theme: string;
24
- resizeSize: number;
25
- }>;
26
-
27
- /**
28
- * Configuration options for the CodeTool provided by the user
29
- */
30
- export interface CodeConfig {
31
- /**
32
- * Placeholder text to display in the input field when it's empty
33
- */
34
- placeholder: string;
35
- }
36
-
37
- /**
38
- * Defines the CSS class names used by CodeTool for styling its elements
39
- */
40
- interface CodeToolCSS {
41
- /** Block Styling from Editor.js API */
42
- baseClass: string;
43
- /** Input Styling from Editor.js API */
44
- input: string;
45
- /** Wrapper styling */
46
- wrapper: string;
47
- /** Textarea styling */
48
- textarea: string;
49
- /** Span styling */
50
- span: string;
51
- /** Selector Language styling */
52
- selectorLanguage: string;
53
- /** Selector Theme styling */
54
- selectorTheme: string;
55
- }
56
-
57
- /**
58
- * Holds references to the DOM elements used by CodeTool
59
- */
60
- interface CodeToolNodes {
61
- /** Main container or Wrapper for CodeTool */
62
- holder: HTMLDivElement | null;
63
- /** Textarea where user inputs their code */
64
- textarea: HTMLTextAreaElement | null;
65
- }
66
-
67
- /**
68
- * Options passed to the constructor of a block tool
69
- */
70
- export type CodeToolConstructorOptions = BlockToolConstructorOptions<CodeData>;
71
-
72
- /**
73
- * Code Tool for the Editor.js allows to include code examples in your articles.
74
- */
75
- export default class CodeTool implements BlockTool {
76
- /**
77
- * API provided by Editor.js for interacting with the editor's core functionality
78
- */
79
- private api: API;
80
- /**
81
- * Indicates whether the editor is in read-only mode, preventing modifications
82
- */
83
- private readOnly: boolean;
84
- /**
85
- * Placeholder text displayed when there is no code content
86
- */
87
- private placeholder: string;
88
- /**
89
- * Collection of CSS class names used by CodeTool for styling its elements
90
- */
91
- private CSS: CodeToolCSS;
92
- /**
93
- * DOM nodes related to the CodeTool, including containers and other elements
94
- */
95
- private nodes: CodeToolNodes;
96
- /**
97
- * Stores the current data (code and other related properties) for the CodeTool
98
- */
99
- private _data!: CodeData;
100
- /**
101
- * Default language for the CodeTool
102
- */
103
- private _selectorLanguage: string = '';
104
- /**
105
- * Default theme for the CodeTool
106
- */
107
- private _selectorTheme: string = '';
108
- /**
109
- * Notify core that read-only mode is supported
110
- * @returns true if read-only mode is supported
111
- */
112
- public static get isReadOnlySupported(): boolean {
113
- return true;
114
- }
115
-
116
- /**
117
- * Allows pressing Enter key to create line breaks inside the CodeTool textarea
118
- * This enables multi-line input within the code editor.
119
- * @returns true if line breaks are allowed in the textarea
120
- */
121
- public static get enableLineBreaks(): boolean {
122
- return true;
123
- }
124
-
125
- /**
126
- * Render plugin`s main Element and fill it with saved data
127
- * @param options - tool constricting options
128
- * @param options.data — previously saved plugin code
129
- * @param options.config - user config for Tool
130
- * @param options.api - Editor.js API
131
- * @param options.readOnly - read only mode flag
132
- */
133
- constructor({ data, config, api, readOnly }: CodeToolConstructorOptions) {
134
- this.api = api;
135
- this.readOnly = readOnly;
136
-
137
- this.placeholder = this.api.i18n.t(config.placeholder as string || CodeTool.DEFAULT_PLACEHOLDER);
138
-
139
- this._selectorLanguage = data.lang || config.lang || CodeTool.DEFAULT_LANGUAGE
140
- this._selectorTheme = data.theme || config.theme || CodeTool.DEFAULT_THEME
141
-
142
- this.CSS = {
143
- baseClass: this.api.styles.block,
144
- input: this.api.styles.input,
145
- wrapper: 'ce-editorjs-x-shiki',
146
- textarea: 'ce-editorjs-x-shiki__textarea',
147
- span: 'ce-editorjs-x-shiki__span',
148
- selectorLanguage: 'ce-editorjs-x-shiki__selector-language',
149
- selectorTheme: 'ce-editorjs-x-shiki__selector-theme',
150
- };
151
-
152
- this.nodes = {
153
- holder: null,
154
- textarea: null,
155
- };
156
-
157
- this.data = {
158
- code: data.code ?? '',
159
- lang: this._selectorLanguage,
160
- theme: this._selectorTheme,
161
- resizeSize: data.resizeSize || 0
162
- };
163
-
164
- this.nodes.holder = this.drawView()
165
- }
166
-
167
- /**
168
- * Return Tool's view
169
- * @returns this.nodes.holder - Code's wrapper
170
- */
171
- public render(): HTMLDivElement {
172
- return this.nodes.holder!;
173
- }
174
-
175
- /**
176
- * Extract Tool's data from the view
177
- * @param codeWrapper - CodeTool's wrapper, containing textarea with code
178
- * @returns - saved plugin code
179
- */
180
- public save(codeWrapper: HTMLDivElement): CodeData {
181
- return {
182
- code: codeWrapper.querySelector('textarea')!.value,
183
- lang: this._selectorLanguage,
184
- theme: this._selectorTheme,
185
- resizeSize: this.data.resizeSize || 0
186
- };
187
- }
188
-
189
- /**
190
- * onPaste callback fired from Editor`s core
191
- * @param event - event with pasted content
192
- */
193
- public onPaste(event: PasteEvent): void {
194
- const detail = event.detail;
195
-
196
- if ('data' in detail) {
197
- const content = detail.data as string;
198
-
199
- this.data = {
200
- code: content || '',
201
- lang: this._selectorLanguage,
202
- theme: this._selectorTheme
203
- };
204
- }
205
- }
206
-
207
- /**
208
- * Returns Tool`s data from private property
209
- * @returns
210
- */
211
- public get data(): CodeData {
212
- return this._data;
213
- }
214
-
215
- /**
216
- * Set Tool`s data to private property and update view
217
- * @param data - saved tool data
218
- */
219
- public set data(data: CodeData) {
220
- this._data = data;
221
-
222
- if (this.nodes.textarea) {
223
- this.nodes.textarea.value = data.code;
224
- }
225
- }
226
-
227
- /**
228
- * Get Tool toolbox settings.
229
- * Provides the icon and title to display in the toolbox for the CodeTool.
230
- * @returns An object containing:
231
- * - icon: SVG representation of the Tool's icon
232
- * - title: Title to show in the toolbox
233
- */
234
- public static get toolbox(): ToolboxConfig {
235
- return {
236
- icon: IconCode,
237
- title: 'Code',
238
- };
239
- }
240
-
241
- /**
242
- * Default placeholder for CodeTool's textarea
243
- * @returns
244
- */
245
- public static get DEFAULT_PLACEHOLDER(): string {
246
- return 'Enter your code';
247
- }
248
-
249
- /**
250
- * Default language for CodeTool's textarea
251
- * @returns
252
- */
253
- public static get DEFAULT_LANGUAGE(): string {
254
- return 'javascript';
255
- }
256
-
257
- /**
258
- * Default theme for CodeTool's textarea
259
- * @returns
260
- */
261
- public static get DEFAULT_THEME(): string {
262
- return 'vitesse-dark';
263
- }
264
-
265
- /**
266
- * Used by Editor.js paste handling API.
267
- * Provides configuration to handle CODE tag.
268
- * @returns
269
- */
270
- public static get pasteConfig(): PasteConfig {
271
- return {
272
- tags: ['pre'],
273
- };
274
- }
275
-
276
- /**
277
- * Automatic sanitize config
278
- * @returns
279
- */
280
- public static get sanitize(): SanitizerConfig {
281
- return {
282
- code: true, // Allow HTML tags
283
- };
284
- }
285
-
286
- /**
287
- * Handles Tab key pressing (adds/removes indentations)
288
- * @param event - keydown
289
- */
290
- private tabHandler(event: KeyboardEvent): void {
291
- /**
292
- * Prevent editor.js tab handler
293
- */
294
- event.stopPropagation();
295
-
296
- /**
297
- * Prevent native tab behaviour
298
- */
299
- event.preventDefault();
300
-
301
- const textarea = event.target as HTMLTextAreaElement;
302
- const isShiftPressed = event.shiftKey;
303
- const caretPosition = textarea.selectionStart;
304
- const value = textarea.value;
305
- const indentation = ' ';
306
-
307
- let newCaretPosition;
308
-
309
- /**
310
- * For Tab pressing, just add an indentation to the caret position
311
- */
312
- if (!isShiftPressed) {
313
- newCaretPosition = caretPosition + indentation.length;
314
-
315
- textarea.value = value.substring(0, caretPosition) + indentation + value.substring(caretPosition);
316
- } else {
317
- /**
318
- * For Shift+Tab pressing, remove an indentation from the start of line
319
- */
320
- const currentLineStart = getLineStartPosition(value, caretPosition);
321
- const firstLineChars = value.substr(currentLineStart, indentation.length);
322
-
323
- if (firstLineChars !== indentation) {
324
- return;
325
- }
326
-
327
- /**
328
- * Trim the first two chars from the start of line
329
- */
330
- textarea.value = value.substring(0, currentLineStart) + value.substring(currentLineStart + indentation.length);
331
- newCaretPosition = caretPosition - indentation.length;
332
- }
333
-
334
- /**
335
- * Restore the caret
336
- */
337
- textarea.setSelectionRange(newCaretPosition, newCaretPosition);
338
- }
339
-
340
- /**
341
- * Create Tool's view
342
- * @returns
343
- */
344
- private drawView(): HTMLDivElement {
345
- const wrapper = document.createElement('div');
346
- const wrapperHolder = document.createElement('div');
347
- const wrapperSelectorHolder = document.createElement('div');
348
- const wrapperLang = document.createElement('div');
349
- const wrapperCopy = document.createElement('div');
350
- const wrapperCopyTip = document.createElement('div');
351
-
352
-
353
- const selectorLanguage = document.createElement('select');
354
- const selectorTheme = document.createElement('select');
355
- const span = document.createElement('span');
356
- const textarea = document.createElement('textarea');
357
- const dragHandle = document.createElement('div');
358
- dragHandle.classList.add('ce-editorjs-x-shiki__code__dragHandler');
359
- wrapper.classList.add(this.CSS.baseClass, this.CSS.wrapper);
360
- if(this.readOnly){
361
- wrapper.classList.add('read-only');
362
- }else{
363
- wrapper.classList.add('editable');
364
- }
365
- wrapperHolder.classList.add('ce-editorjs-x-shiki__code');
366
- wrapperSelectorHolder.classList.add('ce-editorjs-x-shiki__selector');
367
- wrapperLang.classList.add('ce-editorjs-x-shiki__lang');
368
- wrapperCopy.classList.add('ce-editorjs-x-shiki__copy');
369
- wrapperCopyTip.classList.add('ce-editorjs-x-shiki__copy_tip');
370
-
371
- selectorLanguage.classList.add(this.CSS.selectorLanguage);
372
- //selectorTheme.classList.add(this.CSS.selectorTheme);
373
- textarea.classList.add(this.CSS.textarea, this.CSS.input);
374
-
375
- wrapperLang.innerHTML = this.data.lang
376
- wrapperCopy.innerHTML = IconCopy;
377
- wrapperCopyTip.innerText = this.api.i18n.t('Copied');
378
-
379
-
380
-
381
- languages.forEach((lang) => {
382
- const option = document.createElement('option');
383
- option.value = lang.id;
384
- option.text = lang.name;
385
- selectorLanguage.appendChild(option);
386
- });
387
- selectorLanguage.value = this.data.lang
388
-
389
- // themes.forEach((theme) => {
390
- // const option = document.createElement('option');
391
- // option.value = theme.id;
392
- // option.text = theme.displayName;
393
- // selectorTheme.appendChild(option);
394
- // });
395
- // selectorTheme.value = this.data.theme
396
-
397
- textarea.value = this.data.code;
398
- textarea.placeholder = this.placeholder;
399
- textarea.spellcheck = false;
400
- textarea.autocomplete = "off"
401
- textarea.autocapitalize = "off"
402
-
403
- if (this.readOnly) {
404
- textarea.disabled = true;
405
- }
406
-
407
- wrapperHolder.appendChild(span);
408
- wrapperHolder.appendChild(textarea);
409
- wrapper.appendChild(dragHandle);
410
-
411
-
412
- if(this.data.resizeSize>0){
413
- wrapperHolder.style.height = this.data.resizeSize + 'px';
414
- }
415
-
416
- if (!this.readOnly) {
417
- wrapperSelectorHolder.appendChild(selectorLanguage);
418
- //wrapperSelectorHolder.appendChild(selectorTheme);
419
-
420
- } else {
421
- wrapperSelectorHolder.appendChild(wrapperLang);
422
-
423
- }
424
- wrapperCopy.appendChild(wrapperCopyTip);
425
-
426
- wrapperSelectorHolder.appendChild(wrapperCopy);
427
- wrapper.appendChild(wrapperSelectorHolder);
428
-
429
- wrapper.appendChild(wrapperHolder);
430
- //wrapper.appendChild(wrapperLang);
431
-
432
- this.runShiki().then(({ html, preStyle }) => {
433
-
434
- span.innerHTML = html
435
- wrapper?.setAttribute('style', preStyle)
436
- selectorLanguage.setAttribute('style', preStyle)
437
- selectorTheme.setAttribute('style', preStyle)
438
- })
439
-
440
- selectorLanguage.addEventListener('change', (event: Event) => {
441
- const lang = (event.target as HTMLSelectElement).value
442
- this._selectorLanguage = lang
443
- this.runShiki().then(({ html, preStyle }) => {
444
- span.innerHTML = html
445
- wrapperLang.innerHTML = lang
446
- })
447
- })
448
-
449
- selectorTheme.addEventListener('change', (event: Event) => {
450
- const theme = (event.target as HTMLSelectElement).value
451
- this._selectorTheme = theme
452
- this.runShiki().then(({ html, preStyle }) => {
453
- span.innerHTML = html
454
- wrapper?.setAttribute('style', preStyle)
455
- selectorLanguage.setAttribute('style', preStyle)
456
- selectorTheme.setAttribute('style', preStyle)
457
- })
458
- })
459
-
460
- textarea.addEventListener('input', () => {
461
- this.data.code = textarea.value
462
- this.runShiki().then(({ html, preStyle }) => {
463
- span.innerHTML = html
464
- wrapper?.setAttribute('style', preStyle)
465
- selectorLanguage.setAttribute('style', preStyle)
466
- selectorTheme.setAttribute('style', preStyle)
467
- })
468
- })
469
-
470
- /**
471
- * Enable keydown handlers
472
- */
473
- textarea.addEventListener('keydown', (event) => {
474
- switch (event.code) {
475
- case 'Tab':
476
- this.tabHandler(event);
477
- this.data.code = textarea.value
478
- this.runShiki().then(({ html, preStyle }) => {
479
- span.innerHTML = html
480
- })
481
- break;
482
- }
483
- });
484
- textarea.addEventListener('scroll', () => {
485
- //span.scrollTop = textarea.scrollTop
486
- span.style=`display:block;transform: translateY(-${textarea.scrollTop}px)`
487
- })
488
- wrapperCopy.addEventListener('click', (event: MouseEvent) => {
489
- this.copyCode(this.data.code, event);
490
- });
491
- //调整窗口大小
492
- dragHandle.addEventListener('mousedown', (event: MouseEvent) => {
493
- this.resizeClick(wrapperHolder, event);
494
- });
495
- this.nodes.textarea = textarea;
496
-
497
- return wrapper;
498
- }
499
- private resizeClick(codeElement: HTMLElement, event: MouseEvent) {
500
-
501
- let startY = event.clientY;
502
- let startHeight = parseInt(window.getComputedStyle(codeElement).height, 10);
503
- const mouseMoveHandler = (e: MouseEvent) => {
504
- const dY = e.clientY - startY;
505
- let newHeight = startHeight + dY;
506
-
507
-
508
- if (newHeight < 100) {
509
- newHeight = 100;
510
- }
511
- codeElement.style.height = newHeight + 'px';
512
- };
513
- const mouseUpHandler = () => {
514
- const blockHeight = parseInt(
515
- window.getComputedStyle(codeElement).height,
516
- 10,
517
- );
518
- this.data.resizeSize = blockHeight;
519
- document.removeEventListener('mousemove', mouseMoveHandler);
520
- document.removeEventListener('mouseup', mouseUpHandler);
521
- };
522
-
523
- document.addEventListener('mousemove', mouseMoveHandler);
524
- document.addEventListener('mouseup', mouseUpHandler);
525
- }
526
- private async runShiki(): Promise<{ html: string, preStyle: string }> {
527
- let preStyle = ''
528
-
529
- const html = await codeToHtml(this.data.code, {
530
- lang: this._selectorLanguage,
531
- theme: this._selectorTheme,
532
-
533
- transformers: [
534
- {
535
- preprocess(code) {
536
- // if (code.endsWith('\n'))
537
- return `${code}\n`
538
- },
539
- pre(node) {
540
- this.addClassToHast(node, 'ce-editorjs-x-shiki__span')
541
- preStyle = node.properties?.style as string || ''
542
- },
543
- line(node, line) {
544
- node.properties = node.properties || {};
545
- node.properties['data-line'] = line;
546
-
547
- }
548
-
549
- }
550
- ]
551
- })
552
-
553
- return {
554
- html,
555
- preStyle
556
- }
557
-
558
- }
559
- private showCopyTip(msg: string,event: MouseEvent) {
560
- const tip = this.api.i18n.t(msg);
561
- if (event.target) {
562
- const parentEle = (event.target as HTMLElement).parentElement;
563
- if (parentEle) {
564
- const tooltip = parentEle.lastChild as HTMLElement;
565
- if (tooltip) {
566
- tooltip.innerHTML = tip;
567
- tooltip.classList.add('visible');
568
- setTimeout(() => {
569
- tooltip.classList.remove('visible');
570
-
571
- }, 2000);
572
- }
573
- }
574
- }
575
- }
576
- private copyCode(code: string, event: MouseEvent) {
577
- if (this.data.code) {
578
- if (navigator.clipboard && window.isSecureContext) {
579
- try {
580
- navigator.clipboard.writeText(code).then(() => {
581
- this.showCopyTip('Copied',event);
582
- }).catch((err) => {
583
- console.error(err);
584
- this.showCopyTip('Unable to copy',event);
585
- });
586
-
587
- } catch (err) {
588
- this.showCopyTip('Unable to copy',event);
589
- }
590
- } else {
591
- // 传统方法:使用 textarea 和 execCommand
592
-
593
- const textArea = document.createElement('textarea');
594
- textArea.value = code;
595
-
596
- // 避免滚动到底部
597
- textArea.style.top = '0';
598
- textArea.style.left = '0';
599
- textArea.style.position = 'fixed';
600
- textArea.style.opacity = '0';
601
- textArea.style.pointerEvents = 'none';
602
- textArea.style.zIndex = '-1000';
603
-
604
- document.body.appendChild(textArea);
605
- textArea.focus();
606
- textArea.select();
607
- try {
608
- document.execCommand('copy');
609
- document.body.removeChild(textArea);
610
- this.showCopyTip('Copied',event);
611
- } catch (err) {
612
- this.showCopyTip('Unable to copy',event);
613
- document.body.removeChild(textArea);
614
-
615
- }
616
-
617
- }
618
- }
619
-
620
- }
621
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Return the position of line starting from passed point
3
- *
4
- * ┌───────────────┐
5
- * │1234\n │
6
- * │2eda | dadd\n │ <-- returns 5
7
- * └───────────────┘
8
- * @param string - string to process
9
- * @param position - search starting position
10
- * @returns
11
- */
12
- export function getLineStartPosition(string: string, position: number): number {
13
- const charLength = 1;
14
- let char = '';
15
-
16
- /**
17
- * Iterate through all the chars before the position till the
18
- * - end of line (\n)
19
- * - or start of string (position === 0)
20
- */
21
- while (char !== '\n' && position > 0) {
22
- position = position - charLength;
23
- char = string.substr(position, charLength);
24
- }
25
-
26
- /**
27
- * Do not count the linebreak symbol because it is related to the previous line
28
- */
29
- if (char === '\n') {
30
- position += 1;
31
- }
32
-
33
- return position;
34
- }