@zeedhi/zd-richtext-vue 1.4.3 → 1.5.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.
@@ -1,8 +1,8 @@
1
1
  import { I18n, VersionService } from '@zeedhi/core';
2
2
  import { PropWatch, ZdComponentRender, setFillHeight, Vuetify } from '@zeedhi/vuetify';
3
+ import { locale, createVuetifyProTipTap, VuetifyTiptap } from '@zeedhi/zd-vuetify-pro-tiptap';
4
+ import '@zeedhi/zd-vuetify-pro-tiptap/lib/style.css';
3
5
  import Vue, { ref } from 'vue';
4
- import { locale, createVuetifyProTipTap, VuetifyTiptap } from 'vuetify-pro-tiptap';
5
- import 'vuetify-pro-tiptap/lib/style.css';
6
6
  import { FontFamily as FontFamily$1 } from '@tiptap/extension-font-family';
7
7
  import { EditorContent } from '@tiptap/vue-2';
8
8
  import { RichText } from '@zeedhi/zd-richtext-common';
@@ -63,6 +63,12 @@ FontFamily = __decorate([
63
63
  ], FontFamily);
64
64
  var script$1 = FontFamily;
65
65
 
66
+ let installed = false;
67
+ const setInstalled = () => {
68
+ installed = true;
69
+ };
70
+ const getInstalled = () => installed;
71
+
66
72
  let ZdRichText = class ZdRichText extends ZdComponentRender {
67
73
  constructor() {
68
74
  super(...arguments);
@@ -97,7 +103,7 @@ let ZdRichText = class ZdRichText extends ZdComponentRender {
97
103
  // "outdent",
98
104
  '|',
99
105
  // "link",
100
- // "image",
106
+ 'image',
101
107
  // "video",
102
108
  // "table",
103
109
  // "blockquote",
@@ -141,6 +147,12 @@ let ZdRichText = class ZdRichText extends ZdComponentRender {
141
147
  this.instance.onChange(this.instance.content);
142
148
  }
143
149
  }
150
+ created() {
151
+ if (!getInstalled()) {
152
+ console.error('[ZdRichText]: A partir da versão 1.5.0 o componente ZdRichText deve ser instalado'
153
+ + ' usando o Vue.use() ao invés do Vue.component(). Veja a documentação para mais detalhes.');
154
+ }
155
+ }
144
156
  mounted() {
145
157
  var _a;
146
158
  if (this.$refs.tiptap.editor) {
@@ -172,7 +184,7 @@ let ZdRichText = class ZdRichText extends ZdComponentRender {
172
184
  if (editor)
173
185
  editor.setOptions({ editable: isEditable });
174
186
  }
175
- destroyed() {
187
+ beforeDestroy() {
176
188
  I18n.unregisterChangeListener(this.changeLanguage);
177
189
  this.$refs.tiptap.editor.off('focus', this.onFocus);
178
190
  this.$refs.tiptap.editor.off('blur', this.onBlur);
@@ -661,15 +673,27 @@ __vue_render__._withStripped = true;
661
673
  undefined
662
674
  );
663
675
 
664
- const vuetify = new Vuetify();
665
- const VuetifyProTipTap = createVuetifyProTipTap({
666
- vuetify,
667
- components: {
668
- VuetifyTiptap,
669
- FontFamily: __vue_component__,
670
- },
671
- });
672
- Vue.use(VuetifyProTipTap);
676
+ /**
677
+ * Function called when uploading an image to the editor
678
+ * it will read the file and return a base64 string
679
+ */
680
+ function upload(file) {
681
+ return new Promise((resolve) => {
682
+ const reader = new FileReader();
683
+ reader.onload = (event) => {
684
+ var _a;
685
+ if (typeof ((_a = event.target) === null || _a === void 0 ? void 0 : _a.result) === 'string') {
686
+ resolve(event.target.result);
687
+ }
688
+ else {
689
+ resolve('');
690
+ }
691
+ };
692
+ reader.onerror = () => resolve('');
693
+ reader.readAsDataURL(file);
694
+ });
695
+ }
696
+
673
697
  const packageContent = require('../package.json');
674
698
  VersionService.addPackageVersion(packageContent.name, packageContent.version);
675
699
  locale.setMessage('pt', {
@@ -813,6 +837,38 @@ locale.setMessage('es', {
813
837
  'editor.redo.tooltip': 'Rehacer',
814
838
  'editor.fullscreen.tooltip.fullscreen': 'Pantalla completa',
815
839
  'editor.fullscreen.tooltip.exit': 'Salir de pantalla completa',
816
- });
840
+ });
841
+ // install VuetifyProTipTap creating a new vuetify instance
842
+ // in case the user installs RichText using Vue.component()
843
+ const vuetify = new Vuetify();
844
+ const VuetifyProTipTap = createVuetifyProTipTap({
845
+ vuetify,
846
+ components: {
847
+ VuetifyTiptap,
848
+ FontFamily: __vue_component__,
849
+ },
850
+ });
851
+ Vue.use(VuetifyProTipTap);
852
+ // in case the user installs RichText using Vue.use()
853
+ // should install VuetifyProTipTap using the already existing vuetify instance
854
+ const RichTextPlugin = {
855
+ install(AppVue, options) {
856
+ setInstalled();
857
+ const ConfiguredTiptap = createVuetifyProTipTap({
858
+ vuetify: options.vuetify,
859
+ components: {
860
+ VuetifyTiptap,
861
+ FontFamily: __vue_component__,
862
+ },
863
+ config: {
864
+ image: {
865
+ upload,
866
+ },
867
+ },
868
+ });
869
+ AppVue.use(ConfiguredTiptap);
870
+ AppVue.component('ZdRichText', __vue_component__$1);
871
+ },
872
+ };
817
873
 
818
- export { __vue_component__$1 as ZdRichText };
874
+ export { RichTextPlugin, __vue_component__$1 as ZdRichText };
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@zeedhi/core'), require('@zeedhi/vuetify'), require('vue'), require('vuetify-pro-tiptap'), require('vuetify-pro-tiptap/lib/style.css'), require('@tiptap/extension-font-family'), require('@tiptap/vue-2'), require('@zeedhi/zd-richtext-common'), require('vue-property-decorator'), require('vue-class-component')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@zeedhi/core', '@zeedhi/vuetify', 'vue', 'vuetify-pro-tiptap', 'vuetify-pro-tiptap/lib/style.css', '@tiptap/extension-font-family', '@tiptap/vue-2', '@zeedhi/zd-richtext-common', 'vue-property-decorator', 'vue-class-component'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@zeedhi/zd-richtext-vue"] = {}, global.core, global["@zeedhi/vuetify"], global.vue, global["vuetify-pro-tiptap"], null, global["@tiptap/extension-font-family"], global["@tiptap/vue-2"], global["@zeedhi/zd-richtext-common"], global["vue-property-decorator"], global["vue-class-component"]));
5
- })(this, (function (exports, core, vuetify$1, Vue, vuetifyProTiptap, style_css, extensionFontFamily, vue2, zdRichtextCommon, vuePropertyDecorator, Component) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@zeedhi/core'), require('@zeedhi/vuetify'), require('@zeedhi/zd-vuetify-pro-tiptap'), require('@zeedhi/zd-vuetify-pro-tiptap/lib/style.css'), require('vue'), require('@tiptap/extension-font-family'), require('@tiptap/vue-2'), require('@zeedhi/zd-richtext-common'), require('vue-property-decorator'), require('vue-class-component')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@zeedhi/core', '@zeedhi/vuetify', '@zeedhi/zd-vuetify-pro-tiptap', '@zeedhi/zd-vuetify-pro-tiptap/lib/style.css', 'vue', '@tiptap/extension-font-family', '@tiptap/vue-2', '@zeedhi/zd-richtext-common', 'vue-property-decorator', 'vue-class-component'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@zeedhi/zd-richtext-vue"] = {}, global.core, global["@zeedhi/vuetify"], global["@zeedhi/zd-vuetify-pro-tiptap"], null, global.vue, global["@tiptap/extension-font-family"], global["@tiptap/vue-2"], global["@zeedhi/zd-richtext-common"], global["vue-property-decorator"], global["vue-class-component"]));
5
+ })(this, (function (exports, core, vuetify$1, zdVuetifyProTiptap, style_css, Vue, extensionFontFamily, vue2, zdRichtextCommon, vuePropertyDecorator, Component) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -63,6 +63,12 @@
63
63
  ], FontFamily);
64
64
  var script$1 = FontFamily;
65
65
 
66
+ let installed = false;
67
+ const setInstalled = () => {
68
+ installed = true;
69
+ };
70
+ const getInstalled = () => installed;
71
+
66
72
  let ZdRichText = class ZdRichText extends vuetify$1.ZdComponentRender {
67
73
  constructor() {
68
74
  super(...arguments);
@@ -97,7 +103,7 @@
97
103
  // "outdent",
98
104
  '|',
99
105
  // "link",
100
- // "image",
106
+ 'image',
101
107
  // "video",
102
108
  // "table",
103
109
  // "blockquote",
@@ -121,7 +127,7 @@
121
127
  }
122
128
  changeLanguage() {
123
129
  const newLanguage = core.I18n.instance.language.split('-')[0];
124
- vuetifyProTiptap.locale.setLang(newLanguage);
130
+ zdVuetifyProTiptap.locale.setLang(newLanguage);
125
131
  }
126
132
  hasClass() {
127
133
  return this.isMounted && this.$el.classList.contains('zd-form-child');
@@ -141,6 +147,12 @@
141
147
  this.instance.onChange(this.instance.content);
142
148
  }
143
149
  }
150
+ created() {
151
+ if (!getInstalled()) {
152
+ console.error('[ZdRichText]: A partir da versão 1.5.0 o componente ZdRichText deve ser instalado'
153
+ + ' usando o Vue.use() ao invés do Vue.component(). Veja a documentação para mais detalhes.');
154
+ }
155
+ }
144
156
  mounted() {
145
157
  var _a;
146
158
  if (this.$refs.tiptap.editor) {
@@ -172,7 +184,7 @@
172
184
  if (editor)
173
185
  editor.setOptions({ editable: isEditable });
174
186
  }
175
- destroyed() {
187
+ beforeDestroy() {
176
188
  core.I18n.unregisterChangeListener(this.changeLanguage);
177
189
  this.$refs.tiptap.editor.off('focus', this.onFocus);
178
190
  this.$refs.tiptap.editor.off('blur', this.onBlur);
@@ -661,18 +673,30 @@
661
673
  undefined
662
674
  );
663
675
 
664
- const vuetify = new vuetify$1.Vuetify();
665
- const VuetifyProTipTap = vuetifyProTiptap.createVuetifyProTipTap({
666
- vuetify,
667
- components: {
668
- VuetifyTiptap: vuetifyProTiptap.VuetifyTiptap,
669
- FontFamily: __vue_component__,
670
- },
671
- });
672
- Vue__default["default"].use(VuetifyProTipTap);
676
+ /**
677
+ * Function called when uploading an image to the editor
678
+ * it will read the file and return a base64 string
679
+ */
680
+ function upload(file) {
681
+ return new Promise((resolve) => {
682
+ const reader = new FileReader();
683
+ reader.onload = (event) => {
684
+ var _a;
685
+ if (typeof ((_a = event.target) === null || _a === void 0 ? void 0 : _a.result) === 'string') {
686
+ resolve(event.target.result);
687
+ }
688
+ else {
689
+ resolve('');
690
+ }
691
+ };
692
+ reader.onerror = () => resolve('');
693
+ reader.readAsDataURL(file);
694
+ });
695
+ }
696
+
673
697
  const packageContent = require('../package.json');
674
698
  core.VersionService.addPackageVersion(packageContent.name, packageContent.version);
675
- vuetifyProTiptap.locale.setMessage('pt', {
699
+ zdVuetifyProTiptap.locale.setMessage('pt', {
676
700
  'editor.words': 'PALAVRAS',
677
701
  'editor.characters': 'CARACTERES',
678
702
  'editor.bold.tooltip': 'Negrito',
@@ -743,7 +767,7 @@
743
767
  'editor.fullscreen.tooltip.fullscreen': 'Tela Cheia',
744
768
  'editor.fullscreen.tooltip.exit': 'Sair da Tela Cheia',
745
769
  });
746
- vuetifyProTiptap.locale.setMessage('es', {
770
+ zdVuetifyProTiptap.locale.setMessage('es', {
747
771
  'editor.words': 'PALABRAS',
748
772
  'editor.characters': 'CARACTERES',
749
773
  'editor.bold.tooltip': 'Negrita',
@@ -813,8 +837,41 @@
813
837
  'editor.redo.tooltip': 'Rehacer',
814
838
  'editor.fullscreen.tooltip.fullscreen': 'Pantalla completa',
815
839
  'editor.fullscreen.tooltip.exit': 'Salir de pantalla completa',
816
- });
840
+ });
841
+ // install VuetifyProTipTap creating a new vuetify instance
842
+ // in case the user installs RichText using Vue.component()
843
+ const vuetify = new vuetify$1.Vuetify();
844
+ const VuetifyProTipTap = zdVuetifyProTiptap.createVuetifyProTipTap({
845
+ vuetify,
846
+ components: {
847
+ VuetifyTiptap: zdVuetifyProTiptap.VuetifyTiptap,
848
+ FontFamily: __vue_component__,
849
+ },
850
+ });
851
+ Vue__default["default"].use(VuetifyProTipTap);
852
+ // in case the user installs RichText using Vue.use()
853
+ // should install VuetifyProTipTap using the already existing vuetify instance
854
+ const RichTextPlugin = {
855
+ install(AppVue, options) {
856
+ setInstalled();
857
+ const ConfiguredTiptap = zdVuetifyProTiptap.createVuetifyProTipTap({
858
+ vuetify: options.vuetify,
859
+ components: {
860
+ VuetifyTiptap: zdVuetifyProTiptap.VuetifyTiptap,
861
+ FontFamily: __vue_component__,
862
+ },
863
+ config: {
864
+ image: {
865
+ upload,
866
+ },
867
+ },
868
+ });
869
+ AppVue.use(ConfiguredTiptap);
870
+ AppVue.component('ZdRichText', __vue_component__$1);
871
+ },
872
+ };
817
873
 
874
+ exports.RichTextPlugin = RichTextPlugin;
818
875
  exports.ZdRichText = __vue_component__$1;
819
876
 
820
877
  Object.defineProperty(exports, '__esModule', { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/zd-richtext-vue",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
4
4
  "description": "RichTextVue by BVR",
5
5
  "main": "dist/rich-text-vue.umd.js",
6
6
  "module": "dist/rich-text-vue.esm.js",
@@ -20,9 +20,9 @@
20
20
  "@tiptap/pm": "^2.1.12",
21
21
  "@tiptap/starter-kit": "^2.1.12",
22
22
  "@tiptap/vue-2": "^2.1.12",
23
+ "@zeedhi/zd-vuetify-pro-tiptap": "1.0.*",
23
24
  "tiptap-extensions": "1.35.*",
24
- "tiptap-vuetify": "2.24.*",
25
- "vuetify-pro-tiptap": "^1.4.3"
25
+ "tiptap-vuetify": "2.24.*"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@zeedhi/vuetify": "^1.74.0",
@@ -31,5 +31,5 @@
31
31
  "vue-class-component": "7.2.*",
32
32
  "vue-property-decorator": "9.1.*"
33
33
  },
34
- "gitHead": "fdef8f2b0adf4943741b90db6b59e50f256bf705"
34
+ "gitHead": "1b3715e1a7255b053f46736ebab3b87c1ee644f5"
35
35
  }
@@ -28,7 +28,8 @@ export default class ZdRichText extends ZdComponentRender {
28
28
  onBlur(event: Event): void;
29
29
  toolbar: import("vue").Ref<any[]>;
30
30
  toolbarReadonly: import("vue").Ref<any[]>;
31
+ created(): void;
31
32
  mounted(): void;
32
33
  setEditorDisabled(): void;
33
- destroyed(): void;
34
+ beforeDestroy(): void;
34
35
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
- import 'vuetify-pro-tiptap/lib/style.css';
1
+ import { Vuetify } from '@zeedhi/vuetify';
2
+ import '@zeedhi/zd-vuetify-pro-tiptap/lib/style.css';
3
+ import type { VueConstructor } from 'vue';
2
4
  import ZdRichText from './RichText.vue';
3
- export { ZdRichText };
5
+ declare const vuetify: any;
6
+ declare const RichTextPlugin: {
7
+ install(AppVue: VueConstructor, options: {
8
+ vuetify: Vuetify;
9
+ }): void;
10
+ };
11
+ export { ZdRichText, RichTextPlugin };
@@ -0,0 +1,3 @@
1
+ declare const setInstalled: () => void;
2
+ declare const getInstalled: () => boolean;
3
+ export { setInstalled, getInstalled };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Function called when uploading an image to the editor
3
+ * it will read the file and return a base64 string
4
+ */
5
+ export default function upload(file: File): Promise<string>;