@alitons/ckeditor5 0.0.7 → 0.0.9

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.7",
5
+ "version": "0.0.9",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
  "private": false,
8
8
  "main": "./build/ckeditor.js",
@@ -196,7 +196,7 @@ export default class NumberedDivList extends Plugin {
196
196
  const sealed = getNearestSealedListFromPos(pos);
197
197
  if (!sealed) return;
198
198
 
199
- const item = pos.findAncestor('numItem');
199
+ const item = pos?.findAncestor('numItem');
200
200
  if (item && isInside(item, sealed)) return; // já dentro: ok
201
201
 
202
202
  // redireciona para o primeiro item do sealed
@@ -214,79 +214,6 @@ export default class NumberedDivList extends Plugin {
214
214
  });
215
215
  });
216
216
 
217
-
218
- // não permitir que saia da lista caso exista o atributo data-block
219
- // viewDoc.on('keydown', (evt, data) => {
220
- // if (data.keyCode !== keyCodes.enter || data.shiftKey) return;
221
- // if (!editor.model.document.selection.isCollapsed) return;
222
-
223
- // if(config?.disableEnter === true) {
224
- // return;
225
- // }
226
-
227
- // const { model } = editor;
228
- // const pos = model.document.selection.getFirstPosition();
229
- // if (!pos) return;
230
-
231
- // const sealed = getNearestSealedListFromPos(pos);
232
- // if (!sealed) return; // só intercepta se estiver dentro de um sealed
233
-
234
- // data.preventDefault(); evt.stop();
235
-
236
- // model.change(writer => {
237
- // // deixa o enter nativo dividir o bloco
238
- // editor.execute('enter');
239
-
240
- // const posAfter = model.document.selection.getFirstPosition();
241
- // if (!posAfter) return;
242
- // const newBlock = posAfter.parent as any;
243
- // if (!newBlock) return;
244
-
245
- // // queremos transformar o novo bloco em um novo numItem,
246
- // // mantendo-o dentro de ALGUM numList que esteja dentro do `sealed` (o mais próximo)
247
- // // pega o numItem atual (mais próximo)
248
- // let currentItem = posAfter.findAncestor('numItem');
249
-
250
- // // se o bloco recém criado ficou fora de um numItem,
251
- // // cria um numItem irmão do atual (se existir) dentro do mesmo numList
252
- // if (!currentItem) {
253
- // const listForNew = getNearestSealedListFromPos(posAfter) || sealed;
254
- // const newItem = writer.createElement('numItem');
255
- // writer.insert(newItem, writer.createPositionAt(listForNew, 'end'));
256
- // writer.move(writer.createRangeOn(newBlock), writer.createPositionAt(newItem, 0));
257
- // writer.setSelection(ensureTypablePosInItem(writer, newItem, false));
258
- // return;
259
- // }
260
-
261
- // // garantir que este numItem pertence a um numList que está dentro do sealed mais próximo
262
- // let itsList = currentItem.parent; // deve ser um numList
263
- // if (!isInside(itsList, sealed)) {
264
- // // se por alguma razão o split empurrou pra fora, anexa de volta ao sealed
265
- // const fallback = firstItem(sealed) || null;
266
- // if (fallback) {
267
- // const newItem = writer.createElement('numItem');
268
- // writer.insert(newItem, writer.createPositionAfter(fallback));
269
- // writer.move(writer.createRangeOn(newBlock), writer.createPositionAt(newItem, 0));
270
- // writer.setSelection(ensureTypablePosInItem(writer, newItem, false));
271
- // } else {
272
- // // sealed vazio (raro): crie o primeiro item
273
- // const newItem = writer.createElement('numItem');
274
- // writer.insert(newItem, writer.createPositionAt(sealed, 0));
275
- // writer.move(writer.createRangeOn(newBlock), writer.createPositionAt(newItem, 0));
276
- // writer.setSelection(ensureTypablePosInItem(writer, newItem, false));
277
- // }
278
- // return;
279
- // }
280
-
281
- // // caso normal: cria irmão dentro do mesmo numList
282
- // const newItem = writer.createElement('numItem');
283
- // writer.insert(newItem, writer.createPositionAfter(currentItem));
284
- // writer.move(writer.createRangeOn(newBlock), writer.createPositionAt(newItem, 0));
285
- // writer.setSelection(ensureTypablePosInItem(writer, newItem, false));
286
- // });
287
- // }, { priority: 'high' });
288
-
289
- // não permitir que backspace/delete saia da lista caso exista o atributo data-block
290
217
  viewDoc.on(
291
218
  'keydown',
292
219
  (evt, data) => {
@@ -305,13 +232,13 @@ export default class NumberedDivList extends Plugin {
305
232
  // @ts-ignore
306
233
  const getPos = sel.getFirstPosition() as any;
307
234
  const blocoPos = getPos?.findAncestor('paragraph') ?? getPos?.findAncestor('numItem') ?? getPos?.findAncestor('numList') ?? null;
308
- const itemPos = blocoPos.findAncestor('numItem');
309
- const listPos = itemPos.findAncestor('numList');
235
+ const itemPos = blocoPos?.findAncestor('numItem');
236
+ const listPos = itemPos?.findAncestor('numList');
310
237
 
311
238
  // @ts-ignore
312
239
  editor.execute(isBackspace ? 'delete' : 'deleteForward', { unit: 'character', direction: isBackspace ? 'backward' : 'forward' });
313
240
 
314
- if(blocoPos.is('element', 'paragraph') && !blocoPos?.getChild(0)) {
241
+ if(blocoPos?.is('element', 'paragraph') && !blocoPos?.getChild(0)) {
315
242
  writer.remove(blocoPos);
316
243
  }
317
244
  if(itemPos && itemPos.childCount === 0) {
@@ -324,13 +251,12 @@ export default class NumberedDivList extends Plugin {
324
251
 
325
252
  });
326
253
 
327
- if(isBackspace) {
328
- model.change( async (writer: any) => {
329
- // coloca o cursor no final do bloco atual
330
- const posAfter = model.document.selection.getFirstPosition() as any;
331
- writer.setSelection(writer.createPositionAt(posAfter.parent, 'end'));
332
- });
333
- }
254
+ // if(isBackspace) {
255
+ // model.change( async (writer: any) => {
256
+ // const posAfter = model.document.selection.getFirstPosition() as any;
257
+ // writer.setSelection(writer.createPositionAt(posAfter.parent, 'end'));
258
+ // });
259
+ // }
334
260
 
335
261
  return;
336
262
 
@@ -493,7 +419,7 @@ class ToggleNumberedDivListCommand {
493
419
 
494
420
  if (existingList && value === undefined) {
495
421
  // verifica se está dentro de um numItem
496
- const isInsideNumItem = blocks[0].findAncestor('numItem') === existingItem;
422
+ const isInsideNumItem = blocks[0]?.findAncestor('numItem') === existingItem;
497
423
  let insertPos = writer.createPositionBefore(paragraphAbove);
498
424
  let numItem;
499
425
 
@@ -517,7 +443,7 @@ class ToggleNumberedDivListCommand {
517
443
  let first = true;
518
444
  for (const block of blocks) {
519
445
  // @ts-ignore
520
- const foundList = block.findAncestor('numList');
446
+ const foundList = block?.findAncestor('numList');
521
447
  if (foundList) {
522
448
  first = false;
523
449
  break;
@@ -548,7 +474,7 @@ function shiftTab(editor: any) {
548
474
 
549
475
  const selection = model.document.selection;
550
476
  const firstBlock = selection.getFirstPosition('paragraph') ?? selection.getFirstPosition('numItem');
551
- const firstPos = firstBlock.is('element', 'numItem') ? firstBlock : firstBlock.findAncestor('numItem');
477
+ const firstPos = firstBlock.is('element', 'numItem') ? firstBlock : firstBlock?.findAncestor('numItem');
552
478
  const existingList = firstPos?.findAncestor('numList');
553
479
  const selectedItemIndex = existingList ? existingList.getChildIndex(firstPos) : null;
554
480
  const numListPai = existingList ? existingList?.findAncestor('numList') : null;