@zeedhi/zd-richtext-vue 1.4.3 → 1.5.0

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/README.md CHANGED
@@ -1,74 +1,74 @@
1
- # Componente Rich Text para Zeedhi
2
- O componente de Rich Text é um editor de texto enriquecido com algumas funcionalidades.
3
-
4
- ![Alt Text](https://i.ibb.co/wCyr6jC/zd-rich-text.png)
5
-
6
- ## Instalação
7
- <code>npm i @zeedhi/zd-richtext</code>
8
- Com isso, dois pacotes serão instalados: o **@zeedhi/zd-richtext-common** e o **@zeedhi/zd-richtext-vue**.
9
-
10
- Após a instalação, é necessário que você você importe o pacote **@zeedhi/zd-richtext-vue** dentro de seu arquivo de configuração <code>zeedhi.ts</code>
11
- ```ts
12
- import { ZdRichText } from '@zeedhi/zd-richtext';
13
-
14
- Vue.component('ZdRichText', ZdRichText);
15
- ```
16
-
17
- Já o pacote **@zeedhi/zd-rich-text-common** deve ser importado no arquivo <code>controller</code> do componente.
18
-
19
- ## Uso Básico
20
- Para usar, defina a propriedade <code>component</code> como 'ZdRichText'.
21
-
22
- ```json
23
- {
24
- "name": "rich-text-example",
25
- "component": "ZdRichText"
26
- }
27
- ```
28
-
29
- ## Propriedades
30
-
31
- ### outputFormat
32
- <p>Tipo: <code>string</code></p>
33
- <p>Default: <code>json</code></p>
34
- <p>Descrição: Define o formato de saída do conteúdo digitado ('json' ou 'html')</p>
35
-
36
- ### placeholder
37
- <p>Tipo: <code>string</code></p>
38
- <p>Default: <code>''</code></p>
39
- <p>Descrição: Texto mostrado enquanto o editor estiver sem conteúdo</p>
40
-
41
- ### disabled
42
- <p>Tipo: <code>boolean</code></p>
43
- <p>Default: <code>false</code></p>
44
- <p>Descrição: Desabilita o componente</p>
45
-
46
- ### toolbarColor
47
- <p>Tipo: <code>string</code></p>
48
- <p>Default: <code>'#772583'</code></p>
49
- <p>Descrição: Define a cor da barra de tarefas</p>
50
-
51
- ### cardColor
52
- <p>Tipo: <code>string</code></p>
53
- <p>Default: <code>''</code></p>
54
- <p>Descrição: Define a cor do cartão de entrada de texto</p>
55
-
56
- ### outlined
57
- <p>Tipo: <code>boolean</code></p>
58
- <p>Default: <code>false</code></p>
59
- <p>Descrição: Remove a elevação e adiciona uma borda fina ao cartão de entrada de texto</p>
60
-
61
- ### width
62
- <p>Tipo: <code>number | string</code></p>
63
- <p>Default: <code>''</code></p>
64
- <p>Descrição: Define a largura do componente</p>
65
-
66
- ### height
67
- <p>Tipo: <code>number | string</code></p>
68
- <p>Default: <code>''</code></p>
69
- <p>Descrição: Define a altura do componente</p>
70
-
71
- ## Eventos
72
- <p>Nome: <code>onKeyDown</code></p>
73
- <p><code>{ element, component, key, content }: IEventParam</code></p>
74
- <p>Descrição: Disparado quando uma tecla é digitada no editor</p>
1
+ # Componente Rich Text para Zeedhi
2
+ O componente de Rich Text é um editor de texto enriquecido com algumas funcionalidades.
3
+
4
+ ![Alt Text](https://i.ibb.co/wCyr6jC/zd-rich-text.png)
5
+
6
+ ## Instalação
7
+ <code>npm i @zeedhi/zd-richtext</code>
8
+ Com isso, dois pacotes serão instalados: o **@zeedhi/zd-richtext-common** e o **@zeedhi/zd-richtext-vue**.
9
+
10
+ Após a instalação, é necessário que você você importe o pacote **@zeedhi/zd-richtext-vue** dentro de seu arquivo de configuração <code>zeedhi.ts</code>
11
+ ```ts
12
+ import { ZdRichText } from '@zeedhi/zd-richtext';
13
+
14
+ Vue.component('ZdRichText', ZdRichText);
15
+ ```
16
+
17
+ Já o pacote **@zeedhi/zd-rich-text-common** deve ser importado no arquivo <code>controller</code> do componente.
18
+
19
+ ## Uso Básico
20
+ Para usar, defina a propriedade <code>component</code> como 'ZdRichText'.
21
+
22
+ ```json
23
+ {
24
+ "name": "rich-text-example",
25
+ "component": "ZdRichText"
26
+ }
27
+ ```
28
+
29
+ ## Propriedades
30
+
31
+ ### outputFormat
32
+ <p>Tipo: <code>string</code></p>
33
+ <p>Default: <code>json</code></p>
34
+ <p>Descrição: Define o formato de saída do conteúdo digitado ('json' ou 'html')</p>
35
+
36
+ ### placeholder
37
+ <p>Tipo: <code>string</code></p>
38
+ <p>Default: <code>''</code></p>
39
+ <p>Descrição: Texto mostrado enquanto o editor estiver sem conteúdo</p>
40
+
41
+ ### disabled
42
+ <p>Tipo: <code>boolean</code></p>
43
+ <p>Default: <code>false</code></p>
44
+ <p>Descrição: Desabilita o componente</p>
45
+
46
+ ### toolbarColor
47
+ <p>Tipo: <code>string</code></p>
48
+ <p>Default: <code>'#772583'</code></p>
49
+ <p>Descrição: Define a cor da barra de tarefas</p>
50
+
51
+ ### cardColor
52
+ <p>Tipo: <code>string</code></p>
53
+ <p>Default: <code>''</code></p>
54
+ <p>Descrição: Define a cor do cartão de entrada de texto</p>
55
+
56
+ ### outlined
57
+ <p>Tipo: <code>boolean</code></p>
58
+ <p>Default: <code>false</code></p>
59
+ <p>Descrição: Remove a elevação e adiciona uma borda fina ao cartão de entrada de texto</p>
60
+
61
+ ### width
62
+ <p>Tipo: <code>number | string</code></p>
63
+ <p>Default: <code>''</code></p>
64
+ <p>Descrição: Define a largura do componente</p>
65
+
66
+ ### height
67
+ <p>Tipo: <code>number | string</code></p>
68
+ <p>Default: <code>''</code></p>
69
+ <p>Descrição: Define a altura do componente</p>
70
+
71
+ ## Eventos
72
+ <p>Nome: <code>onKeyDown</code></p>
73
+ <p><code>{ element, component, key, content }: IEventParam</code></p>
74
+ <p>Descrição: Disparado quando uma tecla é digitada no editor</p>
@@ -1,9 +1,9 @@
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
- import { FontFamily as FontFamily$1 } from '@tiptap/extension-font-family';
6
+ import { FontFamily as FontFamily$2 } from '@tiptap/extension-font-family';
7
7
  import { EditorContent } from '@tiptap/vue-2';
8
8
  import { RichText } from '@zeedhi/zd-richtext-common';
9
9
  import { Watch, Component as Component$1 } from 'vue-property-decorator';
@@ -35,13 +35,13 @@ function __metadata(metadataKey, metadataValue) {
35
35
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
36
36
  }
37
37
 
38
- const fonts = [
38
+ const fonts$1 = [
39
39
  { font: 'Inter', title: 'Inter' },
40
40
  { font: 'Roboto', title: 'Roboto' },
41
41
  { font: 'serif', title: 'Serif' },
42
42
  { font: 'monospace', title: 'Monospace' },
43
43
  ];
44
- let FontFamily = class FontFamily extends ZdComponentRender {
44
+ let FontFamily$1 = class FontFamily extends ZdComponentRender {
45
45
  setFontStyle(editor, font) {
46
46
  editor.chain().focus().setFontFamily(font).run();
47
47
  }
@@ -49,26 +49,31 @@ let FontFamily = class FontFamily extends ZdComponentRender {
49
49
  __decorate([
50
50
  PropWatch({ type: Object, default: '' }),
51
51
  __metadata("design:type", Object)
52
- ], FontFamily.prototype, "editor", void 0);
52
+ ], FontFamily$1.prototype, "editor", void 0);
53
53
  __decorate([
54
54
  PropWatch({ type: Object, default: '' }),
55
55
  __metadata("design:type", Object)
56
- ], FontFamily.prototype, "attrs", void 0);
56
+ ], FontFamily$1.prototype, "attrs", void 0);
57
57
  __decorate([
58
- PropWatch({ type: Array, default: () => (fonts) }),
58
+ PropWatch({ type: Array, default: () => (fonts$1) }),
59
59
  __metadata("design:type", Array)
60
- ], FontFamily.prototype, "fonts", void 0);
61
- FontFamily = __decorate([
60
+ ], FontFamily$1.prototype, "fonts", void 0);
61
+ FontFamily$1 = __decorate([
62
62
  Component
63
- ], FontFamily);
64
- var script$1 = FontFamily;
63
+ ], FontFamily$1);
64
+
65
+ let installed = false;
66
+ const setInstalled = () => {
67
+ installed = true;
68
+ };
69
+ const getInstalled = () => installed;
65
70
 
66
71
  let ZdRichText = class ZdRichText extends ZdComponentRender {
67
72
  constructor() {
68
73
  super(...arguments);
69
74
  this.instanceType = RichText;
70
75
  this.isMounted = false;
71
- this.extensions = [FontFamily$1];
76
+ this.extensions = [FontFamily$2];
72
77
  this.toolbar = ref([
73
78
  'bold',
74
79
  'italic',
@@ -97,7 +102,7 @@ let ZdRichText = class ZdRichText extends ZdComponentRender {
97
102
  // "outdent",
98
103
  '|',
99
104
  // "link",
100
- // "image",
105
+ 'image',
101
106
  // "video",
102
107
  // "table",
103
108
  // "blockquote",
@@ -141,6 +146,12 @@ let ZdRichText = class ZdRichText extends ZdComponentRender {
141
146
  this.instance.onChange(this.instance.content);
142
147
  }
143
148
  }
149
+ created() {
150
+ if (!getInstalled()) {
151
+ console.error('[ZdRichText]: A partir da versão 1.5.0 o componente ZdRichText deve ser instalado'
152
+ + ' usando o Vue.use() ao invés do Vue.component(). Veja a documentação para mais detalhes.');
153
+ }
154
+ }
144
155
  mounted() {
145
156
  var _a;
146
157
  if (this.$refs.tiptap.editor) {
@@ -210,7 +221,7 @@ __decorate([
210
221
  __metadata("design:type", String)
211
222
  ], ZdRichText.prototype, "cardColor", void 0);
212
223
  __decorate([
213
- PropWatch({ type: Array, default: () => (fonts) }),
224
+ PropWatch({ type: Array, default: () => (fonts$1) }),
214
225
  __metadata("design:type", Array)
215
226
  ], ZdRichText.prototype, "fonts", void 0);
216
227
  __decorate([
@@ -266,7 +277,7 @@ ZdRichText = __decorate([
266
277
  components: { EditorContent },
267
278
  })
268
279
  ], ZdRichText);
269
- var script = ZdRichText;
280
+ var script$1 = ZdRichText;
270
281
 
271
282
  function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
272
283
  if (typeof shadowMode !== 'boolean') {
@@ -397,7 +408,7 @@ function addStyle(id, css) {
397
408
  }
398
409
 
399
410
  /* script */
400
- const __vue_script__$1 = script;
411
+ const __vue_script__$1 = script$1;
401
412
 
402
413
  /* template */
403
414
  var __vue_render__$1 = function () {
@@ -504,7 +515,7 @@ __vue_render__$1._withStripped = true;
504
515
  /* style */
505
516
  const __vue_inject_styles__$1 = function (inject) {
506
517
  if (!inject) return
507
- inject("data-v-45ed460e_0", { source: ".zd-rich-text #tippy-1 {\n display: none;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--light.rounded {\n background-color: #ffffff !important;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--dark.rounded {\n background-color: #383838 !important;\n}\n.zd-rich-text .zd-rich-text--disabled .vuetify-pro-tiptap-editor__toolbar {\n pointer-events: none;\n opacity: 0.5;\n}\n.zd-rich-text .zd-rich-text--readonly {\n width: 741px;\n}\n.zd-rich-text .v-toolbar__content button.v-btn {\n color: #ffffff !important;\n}", map: undefined, media: undefined });
518
+ inject("data-v-90d68d34_0", { source: ".zd-rich-text #tippy-1 {\n display: none;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--light.rounded {\n background-color: #ffffff !important;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--dark.rounded {\n background-color: #383838 !important;\n}\n.zd-rich-text .zd-rich-text--disabled .vuetify-pro-tiptap-editor__toolbar {\n pointer-events: none;\n opacity: 0.5;\n}\n.zd-rich-text .zd-rich-text--readonly {\n width: 741px;\n}\n.zd-rich-text .v-toolbar__content button.v-btn {\n color: #ffffff !important;\n}", map: undefined, media: undefined });
508
519
 
509
520
  };
510
521
  /* scoped */
@@ -532,8 +543,36 @@ __vue_render__$1._withStripped = true;
532
543
  undefined
533
544
  );
534
545
 
546
+ const fonts = [
547
+ { font: 'Inter', title: 'Inter' },
548
+ { font: 'Roboto', title: 'Roboto' },
549
+ { font: 'serif', title: 'Serif' },
550
+ { font: 'monospace', title: 'Monospace' },
551
+ ];
552
+ let FontFamily = class FontFamily extends ZdComponentRender {
553
+ setFontStyle(editor, font) {
554
+ editor.chain().focus().setFontFamily(font).run();
555
+ }
556
+ };
557
+ __decorate([
558
+ PropWatch({ type: Object, default: '' }),
559
+ __metadata("design:type", Object)
560
+ ], FontFamily.prototype, "editor", void 0);
561
+ __decorate([
562
+ PropWatch({ type: Object, default: '' }),
563
+ __metadata("design:type", Object)
564
+ ], FontFamily.prototype, "attrs", void 0);
565
+ __decorate([
566
+ PropWatch({ type: Array, default: () => (fonts) }),
567
+ __metadata("design:type", Array)
568
+ ], FontFamily.prototype, "fonts", void 0);
569
+ FontFamily = __decorate([
570
+ Component
571
+ ], FontFamily);
572
+ var script = FontFamily;
573
+
535
574
  /* script */
536
- const __vue_script__ = script$1;
575
+ const __vue_script__ = script;
537
576
 
538
577
  /* template */
539
578
  var __vue_render__ = function () {
@@ -661,15 +700,27 @@ __vue_render__._withStripped = true;
661
700
  undefined
662
701
  );
663
702
 
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);
703
+ /**
704
+ * Function called when uploading an image to the editor
705
+ * it will read the file and return a base64 string
706
+ */
707
+ function upload(file) {
708
+ return new Promise((resolve) => {
709
+ const reader = new FileReader();
710
+ reader.onload = (event) => {
711
+ var _a;
712
+ if (typeof ((_a = event.target) === null || _a === void 0 ? void 0 : _a.result) === 'string') {
713
+ resolve(event.target.result);
714
+ }
715
+ else {
716
+ resolve('');
717
+ }
718
+ };
719
+ reader.onerror = () => resolve('');
720
+ reader.readAsDataURL(file);
721
+ });
722
+ }
723
+
673
724
  const packageContent = require('../package.json');
674
725
  VersionService.addPackageVersion(packageContent.name, packageContent.version);
675
726
  locale.setMessage('pt', {
@@ -813,6 +864,38 @@ locale.setMessage('es', {
813
864
  'editor.redo.tooltip': 'Rehacer',
814
865
  'editor.fullscreen.tooltip.fullscreen': 'Pantalla completa',
815
866
  'editor.fullscreen.tooltip.exit': 'Salir de pantalla completa',
816
- });
867
+ });
868
+ // install VuetifyProTipTap creating a new vuetify instance
869
+ // in case the user installs RichText using Vue.component()
870
+ const vuetify = new Vuetify();
871
+ const VuetifyProTipTap = createVuetifyProTipTap({
872
+ vuetify,
873
+ components: {
874
+ VuetifyTiptap,
875
+ FontFamily: __vue_component__,
876
+ },
877
+ });
878
+ Vue.use(VuetifyProTipTap);
879
+ // in case the user installs RichText using Vue.use()
880
+ // should install VuetifyProTipTap using the already existing vuetify instance
881
+ const RichTextPlugin = {
882
+ install(AppVue, options) {
883
+ setInstalled();
884
+ const ConfiguredTiptap = createVuetifyProTipTap({
885
+ vuetify: options.vuetify,
886
+ components: {
887
+ VuetifyTiptap,
888
+ FontFamily: __vue_component__,
889
+ },
890
+ config: {
891
+ image: {
892
+ upload,
893
+ },
894
+ },
895
+ });
896
+ AppVue.use(ConfiguredTiptap);
897
+ AppVue.component('ZdRichText', __vue_component__$1);
898
+ },
899
+ };
817
900
 
818
- export { __vue_component__$1 as ZdRichText };
901
+ 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
 
@@ -35,13 +35,13 @@
35
35
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
36
36
  }
37
37
 
38
- const fonts = [
38
+ const fonts$1 = [
39
39
  { font: 'Inter', title: 'Inter' },
40
40
  { font: 'Roboto', title: 'Roboto' },
41
41
  { font: 'serif', title: 'Serif' },
42
42
  { font: 'monospace', title: 'Monospace' },
43
43
  ];
44
- let FontFamily = class FontFamily extends vuetify$1.ZdComponentRender {
44
+ let FontFamily$1 = class FontFamily extends vuetify$1.ZdComponentRender {
45
45
  setFontStyle(editor, font) {
46
46
  editor.chain().focus().setFontFamily(font).run();
47
47
  }
@@ -49,19 +49,24 @@
49
49
  __decorate([
50
50
  vuetify$1.PropWatch({ type: Object, default: '' }),
51
51
  __metadata("design:type", Object)
52
- ], FontFamily.prototype, "editor", void 0);
52
+ ], FontFamily$1.prototype, "editor", void 0);
53
53
  __decorate([
54
54
  vuetify$1.PropWatch({ type: Object, default: '' }),
55
55
  __metadata("design:type", Object)
56
- ], FontFamily.prototype, "attrs", void 0);
56
+ ], FontFamily$1.prototype, "attrs", void 0);
57
57
  __decorate([
58
- vuetify$1.PropWatch({ type: Array, default: () => (fonts) }),
58
+ vuetify$1.PropWatch({ type: Array, default: () => (fonts$1) }),
59
59
  __metadata("design:type", Array)
60
- ], FontFamily.prototype, "fonts", void 0);
61
- FontFamily = __decorate([
60
+ ], FontFamily$1.prototype, "fonts", void 0);
61
+ FontFamily$1 = __decorate([
62
62
  Component__default["default"]
63
- ], FontFamily);
64
- var script$1 = FontFamily;
63
+ ], FontFamily$1);
64
+
65
+ let installed = false;
66
+ const setInstalled = () => {
67
+ installed = true;
68
+ };
69
+ const getInstalled = () => installed;
65
70
 
66
71
  let ZdRichText = class ZdRichText extends vuetify$1.ZdComponentRender {
67
72
  constructor() {
@@ -97,7 +102,7 @@
97
102
  // "outdent",
98
103
  '|',
99
104
  // "link",
100
- // "image",
105
+ 'image',
101
106
  // "video",
102
107
  // "table",
103
108
  // "blockquote",
@@ -121,7 +126,7 @@
121
126
  }
122
127
  changeLanguage() {
123
128
  const newLanguage = core.I18n.instance.language.split('-')[0];
124
- vuetifyProTiptap.locale.setLang(newLanguage);
129
+ zdVuetifyProTiptap.locale.setLang(newLanguage);
125
130
  }
126
131
  hasClass() {
127
132
  return this.isMounted && this.$el.classList.contains('zd-form-child');
@@ -141,6 +146,12 @@
141
146
  this.instance.onChange(this.instance.content);
142
147
  }
143
148
  }
149
+ created() {
150
+ if (!getInstalled()) {
151
+ console.error('[ZdRichText]: A partir da versão 1.5.0 o componente ZdRichText deve ser instalado'
152
+ + ' usando o Vue.use() ao invés do Vue.component(). Veja a documentação para mais detalhes.');
153
+ }
154
+ }
144
155
  mounted() {
145
156
  var _a;
146
157
  if (this.$refs.tiptap.editor) {
@@ -210,7 +221,7 @@
210
221
  __metadata("design:type", String)
211
222
  ], ZdRichText.prototype, "cardColor", void 0);
212
223
  __decorate([
213
- vuetify$1.PropWatch({ type: Array, default: () => (fonts) }),
224
+ vuetify$1.PropWatch({ type: Array, default: () => (fonts$1) }),
214
225
  __metadata("design:type", Array)
215
226
  ], ZdRichText.prototype, "fonts", void 0);
216
227
  __decorate([
@@ -266,7 +277,7 @@
266
277
  components: { EditorContent: vue2.EditorContent },
267
278
  })
268
279
  ], ZdRichText);
269
- var script = ZdRichText;
280
+ var script$1 = ZdRichText;
270
281
 
271
282
  function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
272
283
  if (typeof shadowMode !== 'boolean') {
@@ -397,7 +408,7 @@
397
408
  }
398
409
 
399
410
  /* script */
400
- const __vue_script__$1 = script;
411
+ const __vue_script__$1 = script$1;
401
412
 
402
413
  /* template */
403
414
  var __vue_render__$1 = function () {
@@ -504,7 +515,7 @@
504
515
  /* style */
505
516
  const __vue_inject_styles__$1 = function (inject) {
506
517
  if (!inject) return
507
- inject("data-v-45ed460e_0", { source: ".zd-rich-text #tippy-1 {\n display: none;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--light.rounded {\n background-color: #ffffff !important;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--dark.rounded {\n background-color: #383838 !important;\n}\n.zd-rich-text .zd-rich-text--disabled .vuetify-pro-tiptap-editor__toolbar {\n pointer-events: none;\n opacity: 0.5;\n}\n.zd-rich-text .zd-rich-text--readonly {\n width: 741px;\n}\n.zd-rich-text .v-toolbar__content button.v-btn {\n color: #ffffff !important;\n}", map: undefined, media: undefined });
518
+ inject("data-v-90d68d34_0", { source: ".zd-rich-text #tippy-1 {\n display: none;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--light.rounded {\n background-color: #ffffff !important;\n}\n.zd-rich-text .vuetify-pro-tiptap-editor.v-card.v-card--flat.v-sheet.theme--dark.rounded {\n background-color: #383838 !important;\n}\n.zd-rich-text .zd-rich-text--disabled .vuetify-pro-tiptap-editor__toolbar {\n pointer-events: none;\n opacity: 0.5;\n}\n.zd-rich-text .zd-rich-text--readonly {\n width: 741px;\n}\n.zd-rich-text .v-toolbar__content button.v-btn {\n color: #ffffff !important;\n}", map: undefined, media: undefined });
508
519
 
509
520
  };
510
521
  /* scoped */
@@ -532,8 +543,36 @@
532
543
  undefined
533
544
  );
534
545
 
546
+ const fonts = [
547
+ { font: 'Inter', title: 'Inter' },
548
+ { font: 'Roboto', title: 'Roboto' },
549
+ { font: 'serif', title: 'Serif' },
550
+ { font: 'monospace', title: 'Monospace' },
551
+ ];
552
+ let FontFamily = class FontFamily extends vuetify$1.ZdComponentRender {
553
+ setFontStyle(editor, font) {
554
+ editor.chain().focus().setFontFamily(font).run();
555
+ }
556
+ };
557
+ __decorate([
558
+ vuetify$1.PropWatch({ type: Object, default: '' }),
559
+ __metadata("design:type", Object)
560
+ ], FontFamily.prototype, "editor", void 0);
561
+ __decorate([
562
+ vuetify$1.PropWatch({ type: Object, default: '' }),
563
+ __metadata("design:type", Object)
564
+ ], FontFamily.prototype, "attrs", void 0);
565
+ __decorate([
566
+ vuetify$1.PropWatch({ type: Array, default: () => (fonts) }),
567
+ __metadata("design:type", Array)
568
+ ], FontFamily.prototype, "fonts", void 0);
569
+ FontFamily = __decorate([
570
+ Component__default["default"]
571
+ ], FontFamily);
572
+ var script = FontFamily;
573
+
535
574
  /* script */
536
- const __vue_script__ = script$1;
575
+ const __vue_script__ = script;
537
576
 
538
577
  /* template */
539
578
  var __vue_render__ = function () {
@@ -661,18 +700,30 @@
661
700
  undefined
662
701
  );
663
702
 
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);
703
+ /**
704
+ * Function called when uploading an image to the editor
705
+ * it will read the file and return a base64 string
706
+ */
707
+ function upload(file) {
708
+ return new Promise((resolve) => {
709
+ const reader = new FileReader();
710
+ reader.onload = (event) => {
711
+ var _a;
712
+ if (typeof ((_a = event.target) === null || _a === void 0 ? void 0 : _a.result) === 'string') {
713
+ resolve(event.target.result);
714
+ }
715
+ else {
716
+ resolve('');
717
+ }
718
+ };
719
+ reader.onerror = () => resolve('');
720
+ reader.readAsDataURL(file);
721
+ });
722
+ }
723
+
673
724
  const packageContent = require('../package.json');
674
725
  core.VersionService.addPackageVersion(packageContent.name, packageContent.version);
675
- vuetifyProTiptap.locale.setMessage('pt', {
726
+ zdVuetifyProTiptap.locale.setMessage('pt', {
676
727
  'editor.words': 'PALAVRAS',
677
728
  'editor.characters': 'CARACTERES',
678
729
  'editor.bold.tooltip': 'Negrito',
@@ -743,7 +794,7 @@
743
794
  'editor.fullscreen.tooltip.fullscreen': 'Tela Cheia',
744
795
  'editor.fullscreen.tooltip.exit': 'Sair da Tela Cheia',
745
796
  });
746
- vuetifyProTiptap.locale.setMessage('es', {
797
+ zdVuetifyProTiptap.locale.setMessage('es', {
747
798
  'editor.words': 'PALABRAS',
748
799
  'editor.characters': 'CARACTERES',
749
800
  'editor.bold.tooltip': 'Negrita',
@@ -813,8 +864,41 @@
813
864
  'editor.redo.tooltip': 'Rehacer',
814
865
  'editor.fullscreen.tooltip.fullscreen': 'Pantalla completa',
815
866
  'editor.fullscreen.tooltip.exit': 'Salir de pantalla completa',
816
- });
867
+ });
868
+ // install VuetifyProTipTap creating a new vuetify instance
869
+ // in case the user installs RichText using Vue.component()
870
+ const vuetify = new vuetify$1.Vuetify();
871
+ const VuetifyProTipTap = zdVuetifyProTiptap.createVuetifyProTipTap({
872
+ vuetify,
873
+ components: {
874
+ VuetifyTiptap: zdVuetifyProTiptap.VuetifyTiptap,
875
+ FontFamily: __vue_component__,
876
+ },
877
+ });
878
+ Vue__default["default"].use(VuetifyProTipTap);
879
+ // in case the user installs RichText using Vue.use()
880
+ // should install VuetifyProTipTap using the already existing vuetify instance
881
+ const RichTextPlugin = {
882
+ install(AppVue, options) {
883
+ setInstalled();
884
+ const ConfiguredTiptap = zdVuetifyProTiptap.createVuetifyProTipTap({
885
+ vuetify: options.vuetify,
886
+ components: {
887
+ VuetifyTiptap: zdVuetifyProTiptap.VuetifyTiptap,
888
+ FontFamily: __vue_component__,
889
+ },
890
+ config: {
891
+ image: {
892
+ upload,
893
+ },
894
+ },
895
+ });
896
+ AppVue.use(ConfiguredTiptap);
897
+ AppVue.component('ZdRichText', __vue_component__$1);
898
+ },
899
+ };
817
900
 
901
+ exports.RichTextPlugin = RichTextPlugin;
818
902
  exports.ZdRichText = __vue_component__$1;
819
903
 
820
904
  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.0",
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": "92f5ac1c3c2438c8c5053154993c204a51de59a0"
35
35
  }
@@ -28,6 +28,7 @@ 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
34
  destroyed(): void;
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>;