Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var editor = EditorJS({
|--------------|----------|----------------------------------------------------------------|
| defaultStyle | `string` | default list style: `ordered`, `unordered` or `checklist`, default is `unordered` |
| maxLevel | `number` | maximum level of the list nesting, could be set to `1` to disable nesting, unlimited by default |
| counterTypes | `string[]` | specifies which counter types should be shown in the ordered list style, could be set to `['numeric','upper-roman']`, default is `undefined` which shows all counter types |

## Output data

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/list",
"version": "2.0.5",
"version": "2.0.6",
"keywords": [
"codex editor",
"list",
Expand Down
28 changes: 26 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export default class EditorjsList {
*/
private defaultListStyle?: ListConfig['defaultStyle'];

/**
* Default Counter type of the ordered list
*/
private defaultCounterTypes: OlCounterType[];

/**
* Tool's data
*/
Expand Down Expand Up @@ -210,6 +215,11 @@ export default class EditorjsList {
*/
this.defaultListStyle = this.config?.defaultStyle || 'unordered';

/**
* Set the default counter types for the ordered list
*/
this.defaultCounterTypes = (this.config as ListConfig).counterTypes || Array.from(OlCounterTypesMap.values()) as OlCounterType[];

const initialData = {
style: this.defaultListStyle,
meta: {},
Expand Down Expand Up @@ -342,18 +352,32 @@ export default class EditorjsList {
* For each counter type in OlCounterType create toolbox item
*/
OlCounterTypesMap.forEach((_, counterType: string) => {
const counterTypeValue = OlCounterTypesMap.get(counterType)! as OlCounterType;

if (!this.defaultCounterTypes.includes(counterTypeValue)) {
return;
}

orderedListCountersTunes.children.items!.push({
title: this.api.i18n.t(counterType),
icon: OlCounterIconsMap.get(OlCounterTypesMap.get(counterType)!),
icon: OlCounterIconsMap.get(counterTypeValue),
isActive: (this.data.meta as OrderedListItemMeta).counterType === OlCounterTypesMap.get(counterType),
closeOnActivate: true,
onActivate: () => {
this.changeCounters(OlCounterTypesMap.get(counterType) as OlCounterType);
},
});
});

/**
* Dont show Counter type tune if there is no valid counter types
*/
if (orderedListCountersTunes.children.items!.length > 1) {
orderedListTunes.push(orderedListCountersTunes);
}

// @ts-expect-error ts(2820) can not use PopoverItem enum from editor.js types
defaultTunes.push({ type: 'separator' }, ...orderedListTunes, orderedListCountersTunes);
defaultTunes.push({ type: 'separator' }, ...orderedListTunes);
}

return defaultTunes;
Expand Down
7 changes: 7 additions & 0 deletions src/types/ListParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ItemMeta } from './ItemMeta';
import type { OlCounterType } from './OlCounterType';

/**
* list style to make list as ordered or unordered
Expand Down Expand Up @@ -92,4 +93,10 @@ export interface ListConfig {
* If nesting is not needed, it could be set to 1
*/
maxLevel?: number;
/**
* Specifies which counter types should be shown in the ordered list style selector.
* @example ['numeric', 'upper-roman'] // Shows selector with these two options
* @default undefined // All counter types are available when not specified
*/
counterTypes?: OlCounterType[];
}