Skip to content

Commit

Permalink
add paste config
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Oct 30, 2024
1 parent e04ffe3 commit 9fa9579
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ListTabulator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class ListTabulator<Renderer extends ListRenderer> {
*/
constructor({ data, config, api, readOnly, block }: ListParams, renderer: Renderer) {
this.config = config;
this.data = data;
this.data = data as ListData;
this.readOnly = readOnly;
this.api = api;
this.block = block;
Expand Down Expand Up @@ -382,6 +382,14 @@ export default class ListTabulator<Renderer extends ListRenderer> {
items: [],
};

/**
* Set default data attributes for ordered list on paste
*/
if (style === 'ordered') {
data.counterType = 'numeric';
data.start = 1;
}

// get pasted items from the html.
const getPastedItems = (parent: Element): ListItem[] => {
// get first level li elements.
Expand Down
32 changes: 32 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { API, BlockAPI, PasteConfig, ToolboxConfig } from '@editorjs/editorjs';
import type { PasteEvent } from './types';
import type {
BlockToolConstructorOptions,
MenuConfigItem,
Expand Down Expand Up @@ -352,6 +353,37 @@ export default class NestedList {
return defaultTunes;
}

/**
* On paste callback that is fired from Editor.
* @param event - event with pasted data
* @todo - refactor and move to nested list instance
*/
public onPaste(event: PasteEvent): void {
const { tagName: tag } = event.detail.data;

switch (tag) {
case 'OL':
this.listStyle = 'ordered';
break;
case 'UL':
case 'LI':
this.listStyle = 'unordered';
}

this.list!.onPaste(event);
}

/**
* Handle UL, OL and LI tags paste and returns List data
* @param element - html element that contains whole list
* @todo - refactor and move to nested list instance
*/
public pasteHandler(element: PasteEvent['detail']['data']): ListData {
const data = this.list!.pasteHandler(element);

return data;
}

/**
* Changes ordered list counterType property value
* @param counterType - new value of the counterType value
Expand Down

0 comments on commit 9fa9579

Please sign in to comment.