@alitons/ckeditor5 0.0.15 → 0.0.17

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
@@ -2,7 +2,7 @@
2
2
  "name": "@alitons/ckeditor5",
3
3
  "author": "Aliton Silva",
4
4
  "description": "Ckeditor 5 Personalizado adicionados campos para atender as demandas da SEAD/AC",
5
- "version": "0.0.15",
5
+ "version": "0.0.17",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
  "private": false,
8
8
  "main": "./build/ckeditor.js",
package/sample/index.html CHANGED
@@ -20,7 +20,6 @@
20
20
  <div class="col-12 row-editor">
21
21
  <div class="editor-container">
22
22
  <div class="editor" ready="initEditorPage">
23
- <p>a</p>
24
23
  </div>
25
24
  </div>
26
25
  </div>
@@ -29,6 +28,8 @@
29
28
  </div>
30
29
  </div>
31
30
 
31
+ <p class="item1">conteudo 1</p><p class="item2">subconteudo</p>
32
+
32
33
  <div class="row">
33
34
  <div class="col-12 html">
34
35
  <h3>Conteúdo HTML gerado:</h3>
package/src/ckeditor.js CHANGED
@@ -122,7 +122,29 @@ Editor.builtinPlugins = [
122
122
  Timestamp
123
123
  ];
124
124
  Editor.defaultConfig = {
125
- extraAllowedContent: 'div[dir,id,lang,title](*){*}',
125
+ extraAllowedContent: 'div[dir,id,lang,title](*){*};p[dir,id,lang,title](*){*}',
126
+ htmlSupport: {
127
+ allow: [
128
+ {
129
+ name: 'p',
130
+ classes: true,
131
+ attributes: true,
132
+ styles: true
133
+ },
134
+ {
135
+ name: 'div',
136
+ classes: true,
137
+ attributes: true,
138
+ styles: true
139
+ },
140
+ {
141
+ name: 'span',
142
+ classes: true,
143
+ attributes: true,
144
+ styles: true
145
+ }
146
+ ]
147
+ },
126
148
  toolbar: {
127
149
  items: [
128
150
  'fontSize',
package/src/ckeditor.ts CHANGED
@@ -91,6 +91,7 @@ import NumberedDivList from './plugins/listaNumerada';
91
91
  import NumberedDivListSplit from './plugins/NumberedDivListSplit';
92
92
 
93
93
  import './css/custom.css';
94
+ import './css/sei.css';
94
95
 
95
96
  // You can read more about extending the build with additional plugins in the "Installing plugins" guide.
96
97
  // See https://ckeditor.com/docs/ckeditor5/latest/installation/plugins/installing-plugins.html for details.
@@ -177,6 +178,17 @@ class Editor extends DecoupledEditor {
177
178
  ];
178
179
 
179
180
  public static override defaultConfig = {
181
+ extraAllowedContent: 'div[dir,id,lang,title](*){*};p[dir,id,lang,title](*){*}',
182
+ htmlSupport: {
183
+ allow: [
184
+ {
185
+ name: 'p',
186
+ classes: true, // permite todas as classes em <p>
187
+ attributes: true, // permite todos os atributos
188
+ styles: true // permite todos os estilos
189
+ }
190
+ ]
191
+ },
180
192
  toolbar: {
181
193
  items: [
182
194
  'undo',
@@ -0,0 +1,7 @@
1
+ figure {
2
+ max-width: 100%;
3
+ }
4
+
5
+ table p {
6
+ margin: 0;
7
+ }
@@ -129,7 +129,6 @@ export default class NumberedDivListSplit extends Plugin {
129
129
 
130
130
  // Limpeza
131
131
  split.on('destroy', () => {
132
- try { panel.destroy(); } catch {}
133
132
  // @ts-ignore
134
133
  window.removeEventListener('scroll', onScrollOrResize, true);
135
134
  // @ts-ignore
@@ -8,6 +8,7 @@ export default class NumberedDivList extends Plugin {
8
8
  }
9
9
 
10
10
  init() {
11
+
11
12
  const editor = this.editor;
12
13
  const toolbar = editor.config.get('toolbar') as any;
13
14
  const config = toolbar!.listaNumeradaOptions || {};
@@ -21,7 +22,8 @@ export default class NumberedDivList extends Plugin {
21
22
  });
22
23
 
23
24
  editor.model.schema.register('numItem', {
24
- allowIn: 'numList',
25
+ // allowIn: 'numList',
26
+ allowWhere: '$block',
25
27
  allowContentOf: '$root',
26
28
  allowAttributesOf: '$block',
27
29
  isLimit: true,
@@ -128,6 +130,67 @@ export default class NumberedDivList extends Plugin {
128
130
  model: (viewElement, { writer }) => writer.createElement('numItem')
129
131
  });
130
132
 
133
+ let firstConversion = true;
134
+ let nivelAtual = 1;
135
+ let lastItemAdded = {} as any;
136
+ editor.conversion.for('upcast').add( dispatcher => {
137
+ dispatcher.on( 'element:p', async ( evt, data, conversionApi ) => {
138
+ const viewElement = data.viewItem;
139
+ const classAttr = viewElement.getAttribute('class');
140
+ const {
141
+ consumable,
142
+ writer,
143
+ safeInsert,
144
+ convertChildren,
145
+ updateConversionResult
146
+ } = conversionApi;
147
+ const { viewItem } = data;
148
+
149
+ if(classAttr && (classAttr.match(/Item_Nivel(\d+)/) || classAttr.match(/Paragrafo_Numerado_Nivel(\d+)/))) {
150
+ const nivelLocal = parseInt(classAttr.replace(/\D/g, '') ?? 0);
151
+ console.log(nivelLocal);
152
+
153
+ if ( !consumable.test( viewItem, { name: true } ) ) {
154
+ return;
155
+ }
156
+ evt.stop();
157
+
158
+ consumable.consume( viewItem, { name: true } );
159
+
160
+ if(!config?.forceList || nivelLocal > nivelAtual) {
161
+ const numList = writer.createElement('numList', { 'dataBlock': 'true' });
162
+ let children = null;
163
+
164
+ if(nivelLocal > 2) {
165
+ children = lastItemAdded[nivelLocal - 1].parent ?? null;
166
+ }
167
+
168
+ const numItem = writer.createElement('numItem');
169
+ writer.insert( numItem, writer.createPositionAt( numList, 'end' ) );
170
+ safeInsert( numList, !firstConversion ? writer.createPositionAt(children ?? data.modelCursor.parent, 'end') : data.modelCursor );
171
+ convertChildren( viewItem, numItem );
172
+ updateConversionResult( numList, data );
173
+
174
+ firstConversion = false;
175
+ nivelAtual = nivelLocal;
176
+ lastItemAdded[nivelLocal] = numItem;
177
+
178
+ } else {
179
+ console.log(data.modelCursor);
180
+ const numItem = writer.createElement('numItem');
181
+ safeInsert( numItem, lastItemAdded[nivelLocal]?.parent ? writer.createPositionAt(lastItemAdded[nivelLocal]?.parent, 'end') : data.modelCursor );
182
+ convertChildren( viewItem, numItem );
183
+ updateConversionResult( numItem, data );
184
+
185
+ nivelAtual = nivelLocal;
186
+ lastItemAdded[nivelLocal] = numItem;
187
+ }
188
+
189
+ }
190
+ }, { priority: 'high' } );
191
+ });
192
+
193
+
131
194
  const viewDoc = editor.editing.view.document;
132
195
 
133
196
  const selectionSpansBlocks = (model: any) => {
@@ -217,6 +280,9 @@ export default class NumberedDivList extends Plugin {
217
280
  viewDoc.on(
218
281
  'keydown',
219
282
  (evt, data) => {
283
+ firstConversion = true;
284
+ nivelAtual = 1;
285
+ lastItemAdded = {} as any;
220
286
  const isBackspace = data.keyCode === keyCodes.backspace;
221
287
  const isDelete = data.keyCode === keyCodes.delete;
222
288
  if (!isBackspace && !isDelete) return;
@@ -306,10 +372,10 @@ export default class NumberedDivList extends Plugin {
306
372
  },
307
373
  { priority: 'high' }
308
374
  );
309
-
310
375
 
311
376
  editor.model.document.on('change:data', () => {
312
- executeForceList(editor, config);
377
+ // ajusteSeiContent(editor);
378
+ executeForceList(editor, config);
313
379
  });
314
380
 
315
381
 
@@ -501,18 +567,16 @@ function executeForceList(editor: any, config: any) {
501
567
  const model = editor.model;
502
568
  const firstElement = editor.model.document.getRoot().getChild(0) as any;
503
569
  if(config?.forceList && firstElement && firstElement.name !== 'numList') {
504
- const numList = model.change( (writer: any) => {
505
- const insertPos = writer.createPositionAt(model.document.getRoot(), 0);
570
+ // cria um num list e move todo o conteudo para dento dele
571
+ model.change( (writer: any) => {
572
+ const root = model.document.getRoot();
506
573
  const numList = writer.createElement('numList', {
507
574
  'data-block': 'true',
508
575
  'start': config?.forceList ? config.forceList + 1 : null
509
576
  });
510
- writer.insert(numList, insertPos);
511
- return numList;
512
- });
513
-
514
- model.change( (writer: any) => {
515
- const root = model.document.getRoot();
577
+ writer.insert(numList, writer.createPositionAt(root, 0));
578
+ const secondNumList = writer.createElement('numList');
579
+ writer.insert(secondNumList, writer.createPositionAt(numList, 0));
516
580
  const itemsToMove = [];
517
581
  for ( const child of root.getChildren() ) {
518
582
  if ( child !== numList ) {
@@ -520,10 +584,35 @@ function executeForceList(editor: any, config: any) {
520
584
  }
521
585
  }
522
586
  for ( const item of itemsToMove ) {
523
- const numItem = writer.createElement('numList');
524
- writer.insert( numItem, writer.createPositionAt( numList, 'end' ) );
525
- writer.move( writer.createRangeOn( item ), writer.createPositionAt( numItem, 0 ) );
587
+ writer.move( writer.createRangeOn( item ), writer.createPositionAt( secondNumList, 0 ) );
526
588
  }
527
589
  });
590
+
591
+
592
+
593
+ // const numList = model.change( (writer: any) => {
594
+ // const insertPos = writer.createPositionAt(model.document.getRoot(), 0);
595
+ // const numList = writer.createElement('numList', {
596
+ // 'data-block': 'true',
597
+ // 'start': config?.forceList ? config.forceList + 1 : null
598
+ // });
599
+ // writer.insert(numList, insertPos);
600
+ // return numList;
601
+ // });
602
+
603
+ // model.change( (writer: any) => {
604
+ // const root = model.document.getRoot();
605
+ // const itemsToMove = [];
606
+ // for ( const child of root.getChildren() ) {
607
+ // if ( child !== numList ) {
608
+ // itemsToMove.push(child);
609
+ // }
610
+ // }
611
+ // for ( const item of itemsToMove ) {
612
+ // const numItem = writer.createElement('numList');
613
+ // writer.insert( numItem, writer.createPositionAt( numList, 'end' ) );
614
+ // writer.move( writer.createRangeOn( item ), writer.createPositionAt( numItem, 0 ) );
615
+ // }
616
+ // });
528
617
  }
529
618
  }