@alitons/ckeditor5 0.0.2 → 0.0.3

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,11 @@
1
1
  import { Plugin } from '@ckeditor/ckeditor5-core';
2
2
  import 'select2/dist/js/select2.full.min';
3
+ import 'select2/dist/css/select2.css';
3
4
  export default class DocumentoModelo extends Plugin {
4
5
  options: any;
6
+ uid: string;
5
7
  init(): void;
8
+ createPopup(): void;
6
9
  openModalDocumentoModelo(): Promise<string | undefined>;
7
10
  parametrosDocumentoModeloCategoria(): {
8
11
  dropdownParent: any;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@alitons/ckeditor5",
3
3
  "author": "Aliton Silva",
4
- "description": "Ckeditor 5 Personalizado adicionados campos para atender as demandas da SEAD/AC",
5
- "version": "0.0.2",
4
+ "description": "Ckeditor 5 Personalizado adicionados campos para atender as demandas da SEAD/AC.",
5
+ "version": "0.0.3",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
  "private": false,
8
8
  "main": "./build/ckeditor.js",
package/sample/script.js CHANGED
@@ -34,32 +34,32 @@ watchdog.create( document.querySelector( '.editor' ), {
34
34
  },
35
35
  documentoModeloOptions: {
36
36
  categoria: {
37
- options: [
38
- {
39
- autotexto: 'teste 1',
40
- titulo: 'Primeiro teste'
41
- }
42
- ],
37
+ // options: [
38
+ // {
39
+ // autotexto: 'teste 1',
40
+ // titulo: 'Primeiro teste'
41
+ // }
42
+ // ],
43
43
  ajax: {
44
- url: 'http://10.10.18.10/compras/api/teste',
44
+ url: 'https://compras.test/api/documento-modelo/categoria',
45
45
  method: 'GET',
46
46
  data: {
47
47
  usuario: 'usuario',
48
48
  },
49
49
  results: {
50
- autotexto: 'autotexto',
51
- titulo: 'titulo'
50
+ id: 'id_categoria_autotexto',
51
+ value: 'descricao'
52
52
  }
53
53
  }
54
54
  },
55
- options: [
56
- {
57
- autotexto: 'teste 1',
58
- titulo: 'Primeiro teste'
59
- }
60
- ],
55
+ // options: [
56
+ // {
57
+ // autotexto: 'teste 1',
58
+ // titulo: 'Primeiro teste'
59
+ // }
60
+ // ],
61
61
  ajax: {
62
- url: 'http://10.10.18.10/compras/api/teste',
62
+ url: 'https://compras.test/api/autotexto',
63
63
  method: 'GET',
64
64
  data: {
65
65
  usuario: 'usuario',
package/src/ckeditor.ts CHANGED
@@ -88,6 +88,7 @@ import AutoTexto from './plugins/autotexto';
88
88
  import DocumentoModelo from './plugins/modelo';
89
89
  import SalvarComo from './plugins/salvarcomo';
90
90
 
91
+ import './css/custom.css';
91
92
 
92
93
  // You can read more about extending the build with additional plugins in the "Installing plugins" guide.
93
94
  // See https://ckeditor.com/docs/ckeditor5/latest/installation/plugins/installing-plugins.html for details.
@@ -0,0 +1,3 @@
1
+ .select2-container--open {
2
+ background-color: white !important;
3
+ }
@@ -2,22 +2,33 @@
2
2
  import Swal from 'sweetalert2'
3
3
  import { Plugin } from '@ckeditor/ckeditor5-core';
4
4
  import { ButtonView } from '@ckeditor/ckeditor5-ui';
5
+ import { createDropdown } from '@ckeditor/ckeditor5-ui';
5
6
  import { HtmlDataProcessor } from '@ckeditor/ckeditor5-engine';
6
7
  import $ from "jquery";
7
8
  import 'select2/dist/js/select2.full.min'
8
- import * as css from 'select2/dist/css/select2.min.css'
9
+ import 'select2/dist/css/select2.css'
10
+
11
+ window.$ = $;
12
+ window.jQuery = $;
9
13
 
10
14
  export default class DocumentoModelo extends Plugin {
11
- options = [] as any
15
+ options = [] as any;
16
+ uid = Math.random().toString(36).substring(7);
12
17
  init() {
13
- const editor = this.editor;
18
+ this.createPopup()
19
+ const toolbar = this.editor.config.get('toolbar') as any;
20
+ this.options = toolbar!.documentoModeloOptions
21
+ }
14
22
 
15
- editor.ui.componentFactory.add( 'documentoModelo', () => {
16
- const button = new ButtonView();
23
+ createPopup() {
24
+ this.editor.ui.componentFactory.add( 'documentoModelo', () => {
25
+
26
+ const dropdown = createDropdown( this.editor.locale );
17
27
 
18
- button.set( {
19
- label: 'Documento Modelo',
20
- icon: `<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="272px" height="272px" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
28
+ // Configure dropdown's button properties:
29
+ dropdown.buttonView.set( {
30
+ label: 'Modelos',
31
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="272px" height="272px" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
21
32
  viewBox="0 0 272 272"
22
33
  xmlns:xlink="http://www.w3.org/1999/xlink"
23
34
  xmlns:xodm="http://www.corel.com/coreldraw/odm/2003">
@@ -57,55 +68,113 @@ export default class DocumentoModelo extends Plugin {
57
68
  </g>
58
69
  </g>
59
70
  </svg>`,
60
- withText: true,
71
+ withText: true,
61
72
  tooltip: true
62
- });
73
+ } );
74
+
75
+ dropdown.render();
63
76
 
64
77
  //VERIFICA SE O EDITOR ESTÁ DESATIVADO
65
78
  setTimeout(() => {
66
- if(editor.isReadOnly) button.isEnabled = false
79
+ if(this.editor.isReadOnly) dropdown.isEnabled = false
67
80
  }, 500)
68
81
 
69
82
  // DESABILITA O BOTÃO QUANDO O EDITOR ESTIVER DESABILITADO OU NÃO ESTIVER ATIVO
70
- editor.model.document.on('change:data', () => {
71
- if(editor.isReadOnly) button.isEnabled = false
72
- else button.isEnabled = true
83
+ this.editor.model.document.on('change:data', () => {
84
+ if(this.editor.isReadOnly) dropdown.isEnabled = false
85
+ else dropdown.isEnabled = true
73
86
  })
74
87
 
75
- const toolbar = editor.config.get('toolbar') as any;
88
+ const toolbar = this.editor.config.get('toolbar') as any;
76
89
 
77
- if(!toolbar!.documentoModeloOptions || toolbar!.documentoModeloOptions === undefined || [null, undefined, ''].includes(toolbar!.documentoModeloOptions)) {
78
- button.isEnabled = false
90
+ if(!toolbar!.seiOptions || toolbar!.seiOptions === undefined || [null, undefined, ''].includes(toolbar!.seiOptions?.url)) {
91
+ dropdown.isEnabled = false
79
92
  }
93
+
94
+ // CRIAR O ELEMENTO IGUAL AO ELEMENTO DE BUSCA
95
+ const input = document.createElement( 'div' );
96
+ input.classList.add('documento_modelo_container')
97
+ input.innerHTML = `<div class="ck ck-reset ck-dropdown__panel ck-dropdown__panel_se ck-dropdown__panel-visible ck-dropdown__panel_documento_modelo">
98
+ <form class="ck ck-find-and-replace-form">
99
+ <div class="ck ck-form__header">
100
+ <h2 class="ck ck-form__header__label">Documento Modelo</h2>
101
+ </div>
102
+ <fieldset class="ck ck-find-and-replace-form__find" style="margin-bottom: 0px; padding-bottom: 0px;">
103
+ <div class="ck ck-labeled-field-view ck-labeled-field-view_empty">
104
+ <label>Categoria</label>
105
+ <div class="ck ck-labeled-field-view__input-wrapper">
106
+ <select class="ck ck-input ck-input-text_empty ck-input-select categoriamodeloselect" id="search-input-categoria-document-modelo-${this.uid}">
107
+ </select>
108
+ </div>
109
+ <div class="ck ck-labeled-field-view__status ck-labeled-field-view__status_error" id="search-error-sei-${this.uid}" role="alert"></div>
110
+ </div>
111
+ </fieldset>
112
+ <fieldset class="ck ck-find-and-replace-form__find">
113
+ <div class="ck ck-labeled-field-view ck-labeled-field-view_empty">
114
+ <label>Modelo</label>
115
+ <div class="ck ck-labeled-field-view__input-wrapper">
116
+ <select class="ck ck-input ck-input-text_empty ck-input-select documentomodeloselect" id="search-input-documento-modelo-${this.uid}">
117
+ </select>
118
+ </div>
119
+ <div class="ck ck-labeled-field-view__status ck-labeled-field-view__status_error" id="search-error-sei-${this.uid}" role="alert"></div>
120
+ </div>
121
+ </fieldset>
122
+ <fieldset class="ck ck-find-and-replace-form__replace" id="search-actions-documento-modelo-${this.uid}" style="display: none">
123
+ <div class="ck ck-labeled-field-view ck-disabled ck-labeled-field-view_empty" style="background: #e9ecef; border: 1px solid #ced4da; padding: 5px; height: 200px; overflow: auto; text-align: initial;">
124
+ <div class="ck" id="search-result-documento-modelo-${this.uid}"></div>
125
+ </div>
126
+ <button class="ck ck-button ck-button-save ck-off ck-button_with-text" type="button" tabindex="-1" id="search-add-documento-modelo-${this.uid}">
127
+ <svg class="ck ck-icon ck-reset_all-excluded ck-icon_inherit-color ck-button__icon" viewBox="0 0 20 20"><path d="M6.972 16.615a.997.997 0 0 1-.744-.292l-4.596-4.596a1 1 0 1 1 1.414-1.414l3.926 3.926 9.937-9.937a1 1 0 0 1 1.414 1.415L7.717 16.323a.997.997 0 0 1-.745.292z"></path></svg>
128
+ <span class="ck ck-button__label">Importar</span>
129
+ </button>
130
+ </fieldset>
131
+ </form>
132
+ </div>`;
133
+ dropdown.panelView.element.appendChild( input );
80
134
 
135
+ const self = this;
81
136
 
82
- // Execute a callback function when the button is clicked.
83
- button.on( 'execute', async () => {
84
-
85
- const toolbar = editor.config.get('toolbar') as any;
86
-
87
- if(!toolbar!.documentoModeloOptions || toolbar!.documentoModeloOptions === undefined || [null, undefined, ''].includes(toolbar!.documentoModeloOptions)) {
88
- button.isEnabled = false
89
- return Swal.fire('Erro', 'Nenhum modelo foi encontrado', 'error')
90
- }
91
-
92
- this.options = toolbar!.documentoModeloOptions
93
-
94
- let conteudo = await this.openModalDocumentoModelo() as any
137
+ // EXECUTAR APENAS QUANDO O DROPDOWN FOR ABERTO
138
+ dropdown.on( 'change:isOpen', ( evt, name, isOpen ) => {
139
+ if ( isOpen ) {
140
+ $('.categoriamodeloselect')
141
+ .select2(this.parametrosDocumentoModeloCategoria())
95
142
 
96
- if(!conteudo || ['', null, undefined].includes(conteudo)) return
143
+ $('.documentomodeloselect')
144
+ .select2(this.parametrosDocumentoModelo())
145
+ .on('select2:select', function (e) {
146
+ console.log('selecionado', $(`#search-actions-documento-modelo-${self.uid}`));
147
+ $(`#search-actions-documento-modelo-${self.uid}`).show()
148
+ $(`#search-result-documento-modelo-${self.uid}`).html(e.target.value)
149
+ })
150
+ }
151
+ });
97
152
 
153
+ $('body').on('keyup', `.ck-error`, function() {
154
+ $(this).removeClass('ck-error')
155
+ $(`#search-error-sei-${this.uid}`).html('')
156
+ });
98
157
 
99
- const viewDocument = editor.editing.view.document;
158
+ $('body').on('click', `#search-add-documento-modelo-${this.uid}`, async function() {
159
+ const conteudo = $(`#search-result-documento-modelo-${self.uid}`).html()
160
+ const viewDocument = self.editor.editing.view.document;
100
161
  const htmlDP = new HtmlDataProcessor( viewDocument );
101
162
  const viewFragment = htmlDP.toView( conteudo );
102
- const modelFragment = editor.data.toModel( viewFragment ) as any;
163
+ const modelFragment = self.editor.data.toModel( viewFragment ) as any;
164
+
165
+ self.editor.model.change(writer => {
166
+ writer.remove(writer.createRangeIn(self.editor.model.document.getRoot()));
167
+ self.editor.model.insertContent(modelFragment);
168
+ });
169
+
170
+ // LIMPA O CAMPO DE BUSCA
171
+ $(`#search-input-documento-modelo-${self.uid}`).val('')
172
+ $(`#search-actions-documento-modelo-${self.uid}`).hide()
103
173
 
104
- editor.model.insertContent( modelFragment );
105
- } );
174
+ });
106
175
 
107
- return button;
108
- } );
176
+ return dropdown;
177
+ });
109
178
  }
110
179
 
111
180
  async openModalDocumentoModelo(){
@@ -159,7 +228,7 @@ export default class DocumentoModelo extends Plugin {
159
228
  parametrosDocumentoModeloCategoria() {
160
229
  const self = this
161
230
  let parametros = {
162
- dropdownParent: $('.swal2-popup'),
231
+ dropdownParent: $('.ck-dropdown__panel_documento_modelo'),
163
232
  placeholder: this.options?.categoria?.placeholder ?? 'Selecione uma categoria',
164
233
  }
165
234
 
@@ -205,7 +274,7 @@ export default class DocumentoModelo extends Plugin {
205
274
  parametrosDocumentoModelo() {
206
275
  const self = this
207
276
  let parametros = {
208
- dropdownParent: $('.swal2-popup'),
277
+ dropdownParent: $('.ck-dropdown__panel_documento_modelo'),
209
278
  placeholder: this.options?.placeholder ?? 'Selecione uma opção',
210
279
  }
211
280