diff --git a/src/ListTabulator/index.ts b/src/ListTabulator/index.ts index ef60628..c43b16d 100644 --- a/src/ListTabulator/index.ts +++ b/src/ListTabulator/index.ts @@ -129,7 +129,7 @@ export default class ListTabulator { */ 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; @@ -382,6 +382,14 @@ export default class ListTabulator { items: [], }; + /** + * Set default ordered list atributes if style is ordered + */ + 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. diff --git a/src/index.ts b/src/index.ts index a2cc370..19a80ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ import './styles/list.pcss'; import './styles/input.pcss'; import stripNumbers from './utils/stripNumbers'; import normalizeData from './utils/normalizeData'; +import type { PasteEvent } from './types'; /** * Constructor Params for Nested List Tool, use to pass initial data and settings @@ -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