You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{BlockToolConstructorOptions}from'@editorjs/editorjs/types/tools';importtype{NestedListParams}from'@editorjs/nested-list';importNestedListfrom'@editorjs/nested-list';// copied from original code == start ==typeListDataStyle='ordered'|'unordered';interfaceListItem{/** * list item text content */content: string;/** * sublist items */items: ListItem[];}interfaceListData{/** * list type 'ordered' or 'unordered' */style: ListDataStyle;/** * list of first-level elements */items: ListItem[];}interfaceNestedListConfig{/** * default list style: ordered or unordered * default is unordered */defaultStyle?: ListDataStyle;}// copied from original code == end ==// this is also implemented in package but couldn't import from dist source, so I just copied itfunctionisHtmlElement(node: Node): boolean{returnnodeinstanceofHTMLElement;}// interface for config, interfaceNestedListCustomParams{maxDepth?: number;}// extending constructor paramsexporttype_NestedListParams=BlockToolConstructorOptions<ListData,NestedListConfig&NestedListCustomParams>;exportdefaultclassLimitedNestedListextendsNestedList{constructor({ data,config: _config, api, readOnly }: _NestedListParams){const{ maxDepth, ...config}=_config;// need to cast to original NestedListParams interface super({ data, config, api, readOnly }asNestedListParams);if(!maxDepth||maxDepth<1){// min : 1 (could nest like : 1.1, 1.2, 2.1, 2.2, ... )// default : 2 (could nest like : 1.1.1, 1.2.3, ... )this.maxDepth=2;return;}this.maxDepth=maxDepth;}privatemaxDepth: number;addTab(event: KeyboardEvent): void{// same as original code == start ==event.stopPropagation();event.preventDefault();constcurrentItem=this.currentItem;if(!currentItem){return;}constprevItem=currentItem.previousSibling;if(!prevItem){return;}if(!isHtmlElement(prevItem)){return;}constisFirstChild=!prevItem;if(isFirstChild){return;}// same as original code == end ==// find until element class name is : `ce-block__content`constmaxHTMLDepth=2+3*(this.maxDepth-1);// 0, 2, 5, 8, 11, ...constrootName='ce-block__content';letHTMLDepth=0;letelement: Element|null=currentItem;while(element?.className!==rootName){element=element?.parentElement||null;HTMLDepth+=1;if(HTMLDepth>maxHTMLDepth)return;}returnsuper.addTab(event);}}
I tried to make as finding root element, or
Block
by using block databut it was quite hard to override methods, and accessing private variables.
The text was updated successfully, but these errors were encountered: