-
Notifications
You must be signed in to change notification settings - Fork 61
Support for optional counter types for ordered list #129
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
Changes from 5 commits
6e8189a
d52c221
134b77d
4d7e576
aac05d4
59b6e57
55c07a8
b85cce6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
| */ | ||||||
|
|
@@ -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: {}, | ||||||
|
|
@@ -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) { | ||||||
|
||||||
| if (orderedListCountersTunes.children.items!.length > 0) { | |
| if (orderedListCountersTunes.children.items!.length > 1) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.