Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore (Nested List): add paste config #97

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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.
Expand Down
32 changes: 32 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Loading