Skip to content

Commit

Permalink
ref: better naming, clearer code
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedatigui committed Dec 7, 2024
1 parent 4647648 commit 6f67206
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +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 |
| displayedEntries | `listStyle[]` | List entries allowed to be displayed `ordered`, `unordered` or `checklist` |
| styles | `listStyle[]` | List styles allowed to be displayed `ordered`, `unordered` or `checklist` |

## Output data

Expand Down
37 changes: 17 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class EditorjsList implements BlockTool {
* title - title to show in toolbox
*/
public static get toolbox(): ToolboxConfig {
const entries = [
const defaultSettings = [
{
icon: IconListBulleted,
title: 'Unordered List',
Expand All @@ -76,9 +76,9 @@ export default class EditorjsList implements BlockTool {
},
];

return this.displayedEntries ? entries.filter(
ele => this.displayedEntries?.includes(ele.data.style as ListDataStyle)
) : entries;
return EditorjsList.styles ? defaultSettings.filter(
ele => EditorjsList.styles?.includes(ele.data.style as ListDataStyle)
) : defaultSettings;
}

/**
Expand Down Expand Up @@ -176,9 +176,9 @@ export default class EditorjsList implements BlockTool {
private defaultListStyle?: ListConfig['defaultStyle'];

/**
*
* List Styles allowed to be displayed
*/
private static displayedEntries?: ListDataStyle[];
private static styles?: ListDataStyle[];

/**
* Tool's data
Expand Down Expand Up @@ -219,7 +219,7 @@ export default class EditorjsList implements BlockTool {
*/
this.defaultListStyle = this.config?.defaultStyle || 'unordered';

EditorjsList.displayedEntries = this.config?.displayedEntries;
EditorjsList.styles = this.config?.styles;

const initialData = {
style: this.defaultListStyle,
Expand Down Expand Up @@ -283,7 +283,7 @@ export default class EditorjsList implements BlockTool {
* @returns array of tune configs
*/
public renderSettings(): MenuConfigItem[] {
const defaultTunes: MenuConfigItem[] = [
let defaultTunes: MenuConfigItem[] = [
{
title: this.api.i18n.t('Unordered'),
icon: IconListBulleted,
Expand Down Expand Up @@ -313,18 +313,15 @@ export default class EditorjsList implements BlockTool {
},
];

if (EditorjsList.displayedEntries){
if (this.listStyle === 'ordered') this.addAdditionalTunes(defaultTunes);
} else if (this.listStyle === 'ordered') this.addAdditionalTunes(defaultTunes);

return EditorjsList.displayedEntries ? defaultTunes.filter(
tune => {
if ('title' in tune) {
if(tune.title === 'Start with' || tune.title === 'Counter type') return true;
else return EditorjsList.displayedEntries?.includes(tune.title!.toLowerCase() as ListDataStyle);
} else if (('type' in tune) && tune.type === 'separator') return true;
}
) : defaultTunes;
if (EditorjsList.styles) {
defaultTunes = defaultTunes.filter(
tune => (('title' in tune) && EditorjsList.styles?.includes(tune.title!.toLowerCase() as ListDataStyle))
)
}

if (this.listStyle === 'ordered') this.addAdditionalTunes(defaultTunes);

return defaultTunes;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/types/ListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface ListConfig {
maxLevel?: number;

/**
* List types allowed to be displayed
* List styles allowed to be displayed
*/
displayedEntries?: ListDataStyle[];
styles?: ListDataStyle[];
}

0 comments on commit 6f67206

Please sign in to comment.