goodteditor-ui 1.0.61 → 1.0.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goodteditor-ui",
3
- "version": "1.0.61",
3
+ "version": "1.0.62",
4
4
  "main": "index.js",
5
5
  "homepage": "https://goodt-ui.netlify.app/",
6
6
  "scripts": {
@@ -2,7 +2,8 @@ Simple example
2
2
  ```vue
3
3
  <template>
4
4
  <div class="pad-l5">
5
- <ui-wysiwyg-editor v-model="model" :autofocus="false" :editorContent="{ class: ['h-100', 'pad-3', 'scroll-y'] }"></ui-wysiwyg-editor>
5
+ <button class="btn" @click="toggled = !toggled">toggle</button>
6
+ <ui-wysiwyg-editor v-model="model" :autofocus="false" :editorContent="editorContent"></ui-wysiwyg-editor>
6
7
  </div>
7
8
  </template>
8
9
  <script>
@@ -10,10 +11,23 @@ import UiWysiwygEditor from './WysiwygEditor.vue';
10
11
  export default {
11
12
  components: { UiWysiwygEditor },
12
13
  data: () => ({
14
+ toggled: false,
13
15
  model: `<p>This WYSIWYG is based on
14
16
  <a target="_blank" rel="noopener noreferrer nofollow" href="https://tiptap.dev/" class="color-link">tiptap</a>
15
17
  editor framework.</p>`
16
- })
18
+ }),
19
+ computed: {
20
+ editorContent() {
21
+ if (!this.toggled) {
22
+ return {
23
+ class: ['h-100', 'pad-3', 'scroll-y']
24
+ }
25
+ }
26
+ return {
27
+ class: ['h-100', 'pad-3', 'scroll-y', 'color-red']
28
+ }
29
+ }
30
+ },
17
31
  };
18
32
  </script>
19
33
  ```
@@ -51,7 +51,7 @@ import { Editor, EditorContent } from '@tiptap/vue-2';
51
51
  import { debounce } from '../utils/Helpers';
52
52
  import { resolveExtensions } from './extensions';
53
53
  import { buildToolGroups, bindContext } from './utils';
54
- import { DefaultTools, WysiwygAutofocus } from './constants';
54
+ import { DefaultTools, WysiwygAutofocus, EMPTY_PTAG_REGEXP } from './constants';
55
55
 
56
56
  /**
57
57
  * @typedef {Omit<import('@tiptap/extension-bubble-menu').BubbleMenuOptions, 'element'>} BubbleMenuOptions
@@ -131,7 +131,8 @@ export default {
131
131
  * @return {string}
132
132
  */
133
133
  content() {
134
- return this.editor?.getHTML() ?? '';
134
+ const html = this.editor?.getHTML() ?? '';
135
+ return EMPTY_PTAG_REGEXP.test(html) ? '' : html;
135
136
  },
136
137
  /**
137
138
  * @return {{title: string, group: ITool[]}[]}
@@ -165,6 +166,16 @@ export default {
165
166
 
166
167
  this.editor.commands.setContent(value, false);
167
168
  },
169
+ editorContent() {
170
+ this.editor.setOptions({
171
+ editorProps: {
172
+ attributes: {
173
+ class: this.editorClass,
174
+ style: this.editorContent?.style ?? ''
175
+ }
176
+ }
177
+ })
178
+ }
168
179
  },
169
180
  created() {
170
181
  this.onSelectionUpdateDebounced = debounce(this.onSelectionUpdate, 300);
@@ -135,6 +135,8 @@ export type WysiwygAutofocus = Readonly<{
135
135
  DISABLED: false
136
136
  }>;
137
137
 
138
+ export const EMPTY_PTAG_REGEXP = /^<p\s*([^>]*)\s*>(\s*)<\/p\s*>$/;
139
+
138
140
  export type DefaultTools = Array<{
139
141
  title: string,
140
142
  group: Array<string|ITool>
@@ -194,6 +194,8 @@ export const WysiwygAutofocus = Object.freeze({
194
194
  DISABLED: false
195
195
  });
196
196
 
197
+ export const EMPTY_PTAG_REGEXP = /^<p\s*([^>]*)\s*>(\s*)<\/p\s*>$/;
198
+
197
199
  export const DefaultTools = [
198
200
  {
199
201
  title: 'Оформление',