Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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.4",
"version": "2.0.5",
"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?.counterTypes || ['numeric', 'upper-roman', 'lower-roman', 'upper-alpha', 'lower-alpha'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use typeof Object.values of the OlCounterTypesMap to show, where it all goes from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that since we have the values already in the map. I pushed a change in this line.


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 > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we will have 1 counter type, than it would be information plate, not a tune, better to add tunes, when user could change smth

Suggested change
if (orderedListCountersTunes.children.items!.length > 0) {
if (orderedListCountersTunes.children.items!.length > 1) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it make sense. kindly review the PR again thanks @e11sy

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[];
}