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

Support for optional counter types for ordered list #129

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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.2",
"version": "2.0.3",
"keywords": [
"codex editor",
"list",
Expand Down
18 changes: 17 additions & 1 deletion 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?.counterTypes || ['numeric', 'upper-roman', 'lower-roman', 'upper-alpha', 'lower-alpha'];

const initialData = {
style: this.defaultListStyle,
meta: {},
Expand Down Expand Up @@ -342,9 +352,15 @@ 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: () => {
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 @@ -87,4 +88,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[];
}