markdown-text-editor 0.1.0 → 0.1.2

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.
@@ -1,20 +1,31 @@
1
- import MakeTool from '../MakeTool.js';
2
-
3
- class OLTool extends MakeTool {
4
- constructor(editor) {
5
- super(editor, '1.', 'Ordered list');
6
- this.button = this.createButton(`
7
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
8
- <path d="M10 12h11"/><path d="M10 18h11"/><path d="M10 6h11"/><path d="M4 10h2"/><path d="M4 6h1v4"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/>
9
- </svg>
10
- `);
11
- }
12
-
13
- // You can change how the syntax is applied for this specific tool:
14
- applySyntax() {
15
- super.applySyntax('start'); // Only apply strikethrough at the start
16
- }
17
- }
18
-
19
-
1
+ import MakeTool from '../MakeTool.js';
2
+
3
+ class OLTool extends MakeTool {
4
+ constructor(editor) {
5
+ super(editor, 'Ordered list');
6
+ this.button = this.createButton(`
7
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M8 4H21V6H8V4ZM5 3V6H6V7H3V6H4V4H3V3H5ZM3 14V11.5H5V11H3V10H6V12.5H4V13H6V14H3ZM5 19.5H3V18.5H5V18H3V17H6V21H3V20H5V19.5ZM8 11H21V13H8V11ZM8 18H21V20H8V18Z"></path></svg>
8
+ `);
9
+ }
10
+
11
+ applySyntax() {
12
+ const textarea = this.editor.usertextarea;
13
+ const { selectionStart, selectionEnd } = textarea;
14
+ const selectedText = textarea.value.substring(selectionStart, selectionEnd);
15
+
16
+ const syntax = '1. ';
17
+ let newText = '';
18
+ if (selectedText.startsWith(syntax)) {
19
+ // Remove the ordered syntax if it's already wrapped
20
+ newText = selectedText.slice(syntax.length);
21
+ } else {
22
+ // Apply ordered list syntax
23
+ newText = `${syntax}${selectedText || 'Ordered list'}`;
24
+ }
25
+
26
+ this.editor.insertText(newText);
27
+ }
28
+ }
29
+
30
+
20
31
  export default OLTool;
@@ -1,98 +1,108 @@
1
- // #components/Toolbar/tools/PreviewToggleTool.js
2
- import MakeTool from '../MakeTool.js';
3
-
4
- class PreviewTool extends MakeTool {
5
- constructor(editor) {
6
- // No markdown syntax for preview toggle, so we call the parent constructor with empty values
7
- super(editor, '', 'Preview');
8
- this.button = this.createButton(`
9
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
10
- <rect width="18" height="18" x="3" y="3" rx="2"/><path d="M12 3v18"/>
11
- </svg>
12
- `);
13
- }
14
-
15
- // Override applySyntax to handle preview toggling
16
- applySyntax() {
17
- const previewWrapper = this.editor.previewContent?.parentNode;
18
- const editorDiv = this.editor.markdownEditorDiv;
19
-
20
- if (!previewWrapper || !editorDiv) return;
21
-
22
- // Toggle the preview's visibility by switching between 'block' and 'hidden' classes
23
- if (this.editor.preview) {
24
- this.enablePreview(previewWrapper, editorDiv);
25
- } else {
26
- this.disablePreview(previewWrapper, editorDiv);
27
- }
28
- }
29
-
30
- // Method to hide the preview (disable it)
31
- disablePreview(previewWrapper, editorDiv) {
32
-
33
- this.editor.preview = true;
34
-
35
- editorDiv.parentNode.classList.toggle('fixed');
36
- editorDiv.parentNode.classList.toggle('top-0');
37
- editorDiv.parentNode.classList.toggle('inset-x-0');
38
- editorDiv.parentNode.classList.toggle('rounded-md');
39
- editorDiv.parentNode.classList.toggle('z-[999]');
40
-
41
- previewWrapper.classList.toggle('hidden');
42
-
43
- // Add grid layout and divide classes to the editor div
44
- editorDiv.classList.remove(
45
- 'md:grid',
46
- 'md:grid-cols-2',
47
- 'md:divide-x',
48
- 'rtl:md:divide-x-reverse',
49
- 'md:divide-stone-300',
50
- 'dark:md:divide-stone-700'
51
- );
52
-
53
- editorDiv.querySelector(".textarea-wrapper").classList.remove(
54
- 'h-[90lvh]',
55
- 'hidden',
56
- 'md:block'
57
- );
58
- this.editor.render(); // Re-render content in the preview
59
-
60
- editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.remove("!h-[90lvh]");
61
-
62
- document.querySelector("body").classList.remove('overflow-hidden');
63
- }
64
-
65
- // Method to show the preview (enable it)
66
- enablePreview(previewWrapper, editorDiv) {
67
-
68
- this.editor.preview = false;
69
-
70
- editorDiv.parentNode.classList.toggle('fixed');
71
- editorDiv.parentNode.classList.toggle('top-0');
72
- editorDiv.parentNode.classList.toggle('inset-x-0');
73
- editorDiv.parentNode.classList.toggle('rounded-md');
74
- editorDiv.parentNode.classList.toggle('z-[999]');
75
-
76
- previewWrapper.classList.toggle('hidden');
77
- // Remove grid layout and divide classes from the editor div
78
- editorDiv.classList.add(
79
- 'md:grid',
80
- 'md:grid-cols-2',
81
- 'md:divide-x',
82
- 'rtl:md:divide-x-reverse',
83
- 'md:divide-stone-300',
84
- 'dark:md:divide-stone-700'
85
- );
86
-
87
- editorDiv.querySelector(".textarea-wrapper").classList.add(
88
- 'h-[90lvh]',
89
- 'hidden',
90
- 'md:block'
91
- );
92
- editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.add("!h-[90lvh]");
93
-
94
- document.querySelector("body").classList.add('overflow-hidden');
95
- }
96
- }
97
-
98
- export default PreviewTool;
1
+ // #components/Toolbar/tools/PreviewToggleTool.js
2
+ import MakeTool from '../MakeTool.js';
3
+
4
+ class PreviewTool extends MakeTool {
5
+ constructor(editor) {
6
+ // No markdown syntax for preview toggle, so we call the parent constructor with empty values
7
+ super(editor, '', 'Preview');
8
+ this.button = this.createButton(`
9
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M11 5H5V19H11V5ZM13 5V19H19V5H13ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3Z"></path></svg>
10
+ `);
11
+ }
12
+
13
+ // Override applySyntax to handle preview toggling
14
+ applySyntax() {
15
+ const previewWrapper = this.editor.previewContent?.parentNode;
16
+ const editorDiv = this.editor.markdownEditorDiv;
17
+
18
+ if (!previewWrapper || !editorDiv) return;
19
+
20
+ // Toggle the preview's visibility by switching between 'block' and 'hidden' classes
21
+ if (this.editor.preview) {
22
+ this.enablePreview(previewWrapper, editorDiv);
23
+ } else {
24
+ this.disablePreview(previewWrapper, editorDiv);
25
+ }
26
+ }
27
+
28
+ // Method to hide the preview (disable it)
29
+ disablePreview(previewWrapper, editorDiv) {
30
+
31
+ this.editor.preview = true;
32
+
33
+ editorDiv.parentNode.classList.toggle('fixed');
34
+ editorDiv.parentNode.classList.toggle('top-0');
35
+ editorDiv.parentNode.classList.toggle('inset-x-0');
36
+ editorDiv.parentNode.classList.toggle('rounded-md');
37
+ editorDiv.parentNode.classList.toggle('z-[999]');
38
+
39
+ previewWrapper.classList.toggle('hidden');
40
+
41
+ // Add grid layout and divide classes to the editor div
42
+ editorDiv.classList.remove(
43
+ 'md:grid',
44
+ 'md:grid-cols-2',
45
+ 'md:divide-x',
46
+ 'rtl:md:divide-x-reverse',
47
+ 'md:divide-stone-300',
48
+ 'dark:md:divide-stone-700'
49
+ );
50
+
51
+ editorDiv.querySelector(".textarea-wrapper").classList.remove(
52
+ 'h-[90lvh]',
53
+ 'hidden',
54
+ 'md:block'
55
+ );
56
+ this.editor.render(); // Re-render content in the preview
57
+
58
+ editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.remove("!h-[90lvh]");
59
+
60
+ document.querySelector("body").classList.remove('overflow-hidden');
61
+
62
+ document.querySelectorAll('.markdown-btn').forEach(button => {
63
+ if (!button.classList.contains('preview-btn')) {
64
+ button.classList.remove('pointer-events-none', 'md:pointer-events-auto', 'opacity-25', 'md:opacity-100');
65
+ }
66
+ });
67
+ }
68
+
69
+ // Method to show the preview (enable it)
70
+ enablePreview(previewWrapper, editorDiv) {
71
+
72
+ this.editor.preview = false;
73
+
74
+ editorDiv.parentNode.classList.toggle('fixed');
75
+ editorDiv.parentNode.classList.toggle('top-0');
76
+ editorDiv.parentNode.classList.toggle('inset-x-0');
77
+ editorDiv.parentNode.classList.toggle('rounded-md');
78
+ editorDiv.parentNode.classList.toggle('z-[999]');
79
+
80
+ previewWrapper.classList.toggle('hidden');
81
+ // Remove grid layout and divide classes from the editor div
82
+ editorDiv.classList.add(
83
+ 'md:grid',
84
+ 'md:grid-cols-2',
85
+ 'md:divide-x',
86
+ 'rtl:md:divide-x-reverse',
87
+ 'md:divide-stone-300',
88
+ 'dark:md:divide-stone-700'
89
+ );
90
+
91
+ editorDiv.querySelector(".textarea-wrapper").classList.add(
92
+ 'h-[90lvh]',
93
+ 'hidden',
94
+ 'md:block'
95
+ );
96
+ editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.add("!h-[90lvh]");
97
+
98
+ document.querySelector("body").classList.add('overflow-hidden');
99
+
100
+ document.querySelectorAll('.markdown-btn').forEach(button => {
101
+ if (!button.classList.contains('preview-btn')) {
102
+ button.classList.add('pointer-events-none', 'md:pointer-events-auto', 'opacity-25', 'md:opacity-100');
103
+ }
104
+ });
105
+ }
106
+ }
107
+
108
+ export default PreviewTool;
@@ -1,16 +1,31 @@
1
- import MakeTool from '../MakeTool.js';
2
-
3
- class StrikethroughTool extends MakeTool {
4
- constructor(editor) {
5
- // Call the parent constructor with the markdown syntax for strikethrough (~~)
6
- super(editor, '~~', 'strikethrough text');
7
- this.button = this.createButton(`
8
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
9
- <path d="M16 4H9a3 3 0 0 0-2.83 4"/>
10
- <path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/>
11
- </svg>
12
- `);
13
- }
14
- }
15
-
1
+ import MakeTool from '../MakeTool.js';
2
+
3
+ class StrikethroughTool extends MakeTool {
4
+ constructor(editor) {
5
+ // Call the parent constructor with the markdown syntax for strikethrough (~~)
6
+ super(editor, 'Strikethrough');
7
+ this.button = this.createButton(`
8
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M17.1538 14C17.3846 14.5161 17.5 15.0893 17.5 15.7196C17.5 17.0625 16.9762 18.1116 15.9286 18.867C14.8809 19.6223 13.4335 20 11.5862 20C9.94674 20 8.32335 19.6185 6.71592 18.8555V16.6009C8.23538 17.4783 9.7908 17.917 11.3822 17.917C13.9333 17.917 15.2128 17.1846 15.2208 15.7196C15.2208 15.0939 15.0049 14.5598 14.5731 14.1173C14.5339 14.0772 14.4939 14.0381 14.4531 14H3V12H21V14H17.1538ZM13.076 11H7.62908C7.4566 10.8433 7.29616 10.6692 7.14776 10.4778C6.71592 9.92084 6.5 9.24559 6.5 8.45207C6.5 7.21602 6.96583 6.165 7.89749 5.299C8.82916 4.43299 10.2706 4 12.2219 4C13.6934 4 15.1009 4.32808 16.4444 4.98426V7.13591C15.2448 6.44921 13.9293 6.10587 12.4978 6.10587C10.0187 6.10587 8.77917 6.88793 8.77917 8.45207C8.77917 8.87172 8.99709 9.23796 9.43293 9.55079C9.86878 9.86362 10.4066 10.1135 11.0463 10.3004C11.6665 10.4816 12.3431 10.7148 13.076 11H13.076Z"></path></svg>
9
+ `);
10
+ }
11
+
12
+ applySyntax() {
13
+ const textarea = this.editor.usertextarea;
14
+ const { selectionStart, selectionEnd } = textarea;
15
+ const selectedText = textarea.value.substring(selectionStart, selectionEnd);
16
+
17
+ const syntax = '~';
18
+ let newText = '';
19
+ if (selectedText.startsWith(syntax) && selectedText.endsWith(syntax)) {
20
+ // Remove the strikethrough syntax if it's already wrapped
21
+ newText = selectedText.slice(syntax.length, -syntax.length);
22
+ } else {
23
+ // Apply strikethrough syntax
24
+ newText = `${syntax}${selectedText || 'Strikethrough text'}${syntax}`;
25
+ }
26
+
27
+ this.editor.insertText(newText);
28
+ }
29
+ }
30
+
16
31
  export default StrikethroughTool;
@@ -1,18 +1,31 @@
1
- import MakeTool from '../MakeTool.js';
2
-
3
- class ULTool extends MakeTool {
4
- constructor(editor) {
5
- super(editor, '-', 'Unordered list');
6
- this.button = this.createButton(`
7
- <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h.01"/><path d="M3 18h.01"/><path d="M3 6h.01"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M8 6h13"/></svg>
8
- `);
9
- }
10
-
11
- // You can change how the syntax is applied for this specific tool:
12
- applySyntax() {
13
- super.applySyntax('start'); // Only apply strikethrough at the start
14
- }
15
- }
16
-
17
-
1
+ import MakeTool from '../MakeTool.js';
2
+
3
+ class ULTool extends MakeTool {
4
+ constructor(editor) {
5
+ super(editor, 'Unordered list');
6
+ this.button = this.createButton(`
7
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M8 4H21V6H8V4ZM4.5 6.5C3.67157 6.5 3 5.82843 3 5C3 4.17157 3.67157 3.5 4.5 3.5C5.32843 3.5 6 4.17157 6 5C6 5.82843 5.32843 6.5 4.5 6.5ZM4.5 13.5C3.67157 13.5 3 12.8284 3 12C3 11.1716 3.67157 10.5 4.5 10.5C5.32843 10.5 6 11.1716 6 12C6 12.8284 5.32843 13.5 4.5 13.5ZM4.5 20.4C3.67157 20.4 3 19.7284 3 18.9C3 18.0716 3.67157 17.4 4.5 17.4C5.32843 17.4 6 18.0716 6 18.9C6 19.7284 5.32843 20.4 4.5 20.4ZM8 11H21V13H8V11ZM8 18H21V20H8V18Z"></path></svg>
8
+ `);
9
+ }
10
+
11
+ applySyntax() {
12
+ const textarea = this.editor.usertextarea;
13
+ const { selectionStart, selectionEnd } = textarea;
14
+ const selectedText = textarea.value.substring(selectionStart, selectionEnd);
15
+
16
+ const syntax = '- ';
17
+ let newText = '';
18
+ if (selectedText.startsWith(syntax)) {
19
+ // Remove the Unordered syntax if it's already wrapped
20
+ newText = selectedText.slice(syntax.length);
21
+ } else {
22
+ // Apply Unordered list syntax
23
+ newText = `${syntax}${selectedText || 'Unordered list'}`;
24
+ }
25
+
26
+ this.editor.insertText(newText);
27
+ }
28
+ }
29
+
30
+
18
31
  export default ULTool;