From 7abc293be5711a6bb5a91fe5cdfad0dc4bc08ac5 Mon Sep 17 00:00:00 2001 From: Robin Delattre Date: Sun, 5 Jan 2025 20:36:53 +0100 Subject: [PATCH 01/18] permit to use linebreak --- src/ListTabulator/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ListTabulator/index.ts b/src/ListTabulator/index.ts index 277b018e..2b86e6b9 100644 --- a/src/ListTabulator/index.ts +++ b/src/ListTabulator/index.ts @@ -167,7 +167,9 @@ export default class ListTabulator { (event) => { switch (event.key) { case 'Enter': - this.enterPressed(event); + if (!event.shiftKey) { + this.enterPressed(event); + } break; case 'Backspace': this.backspace(event); From 6e8189a051738ab2af7ee49ae86e32755875e5bb Mon Sep 17 00:00:00 2001 From: jscastanos Date: Mon, 13 Jan 2025 18:11:59 +0800 Subject: [PATCH 02/18] feat: support optional counter type selection in ordered list --- README.md | 1 + package.json | 2 +- src/index.ts | 62 ++++++++++++++++++++++++++--------------- src/types/ListParams.ts | 7 +++++ 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 15e58564..e0233e7a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 59465f85..1f50fbd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.2", + "version": "2.0.3", "keywords": [ "codex editor", "list", diff --git a/src/index.ts b/src/index.ts index 4cb763d7..96a67717 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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,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)!), + title: this.api.i18n.t(counterTypeValue), + icon: OlCounterIconsMap.get(counterTypeValue), isActive: (this.data.meta as OrderedListItemMeta).counterType === OlCounterTypesMap.get(counterType), closeOnActivate: true, onActivate: () => { @@ -415,39 +431,39 @@ export default class EditorjsList { switch (this.listStyle) { case 'ordered': this.list = new ListTabulator({ - data: this.data, - readOnly: this.readOnly, - api: this.api, - config: this.config, - block: this.block, - }, - new OrderedListRenderer(this.readOnly, this.config) + data: this.data, + readOnly: this.readOnly, + api: this.api, + config: this.config, + block: this.block, + }, + new OrderedListRenderer(this.readOnly, this.config) ); break; case 'unordered': this.list = new ListTabulator({ - data: this.data, - readOnly: this.readOnly, - api: this.api, - config: this.config, - block: this.block, - }, - new UnorderedListRenderer(this.readOnly, this.config) + data: this.data, + readOnly: this.readOnly, + api: this.api, + config: this.config, + block: this.block, + }, + new UnorderedListRenderer(this.readOnly, this.config) ); break; case 'checklist': this.list = new ListTabulator({ - data: this.data, - readOnly: this.readOnly, - api: this.api, - config: this.config, - block: this.block, - }, - new CheckListRenderer(this.readOnly, this.config) + data: this.data, + readOnly: this.readOnly, + api: this.api, + config: this.config, + block: this.block, + }, + new CheckListRenderer(this.readOnly, this.config) ); break; diff --git a/src/types/ListParams.ts b/src/types/ListParams.ts index e377b15f..03056b02 100644 --- a/src/types/ListParams.ts +++ b/src/types/ListParams.ts @@ -1,4 +1,5 @@ import type { ItemMeta } from './ItemMeta'; +import type { OlCounterType } from './OlCounterType'; /** * list style to make list as ordered or unordered @@ -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[]; } From d52c221f455eea27da00c2d98c6e4052d141c4eb Mon Sep 17 00:00:00 2001 From: jscastanos Date: Mon, 13 Jan 2025 18:20:09 +0800 Subject: [PATCH 03/18] use counter type instead of the value --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 96a67717..60374634 100644 --- a/src/index.ts +++ b/src/index.ts @@ -359,7 +359,7 @@ export default class EditorjsList { } orderedListCountersTunes.children.items!.push({ - title: this.api.i18n.t(counterTypeValue), + title: this.api.i18n.t(counterType), icon: OlCounterIconsMap.get(counterTypeValue), isActive: (this.data.meta as OrderedListItemMeta).counterType === OlCounterTypesMap.get(counterType), closeOnActivate: true, From 134b77d961092dc37d3f7e3a50ffcf89cb2fee8e Mon Sep 17 00:00:00 2001 From: jscastanos Date: Mon, 13 Jan 2025 18:22:14 +0800 Subject: [PATCH 04/18] remove excess spacing --- src/index.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/index.ts b/src/index.ts index 60374634..e5cb07c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -431,39 +431,39 @@ export default class EditorjsList { switch (this.listStyle) { case 'ordered': this.list = new ListTabulator({ - data: this.data, - readOnly: this.readOnly, - api: this.api, - config: this.config, - block: this.block, - }, - new OrderedListRenderer(this.readOnly, this.config) + data: this.data, + readOnly: this.readOnly, + api: this.api, + config: this.config, + block: this.block, + }, + new OrderedListRenderer(this.readOnly, this.config) ); break; case 'unordered': this.list = new ListTabulator({ - data: this.data, - readOnly: this.readOnly, - api: this.api, - config: this.config, - block: this.block, - }, - new UnorderedListRenderer(this.readOnly, this.config) + data: this.data, + readOnly: this.readOnly, + api: this.api, + config: this.config, + block: this.block, + }, + new UnorderedListRenderer(this.readOnly, this.config) ); break; case 'checklist': this.list = new ListTabulator({ - data: this.data, - readOnly: this.readOnly, - api: this.api, - config: this.config, - block: this.block, - }, - new CheckListRenderer(this.readOnly, this.config) + data: this.data, + readOnly: this.readOnly, + api: this.api, + config: this.config, + block: this.block, + }, + new CheckListRenderer(this.readOnly, this.config) ); break; From e2472bae0091a590a3abf786a24a03bc84e632cb Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:04:38 +0300 Subject: [PATCH 05/18] imp(utils): improved normalize data util - now old nested list data is also normalized (requered meta field added) --- package.json | 2 +- src/types/ListParams.ts | 5 +++++ src/utils/normalizeData.ts | 25 ++++++++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2dad172b..1f50fbd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.1", + "version": "2.0.3", "keywords": [ "codex editor", "list", diff --git a/src/types/ListParams.ts b/src/types/ListParams.ts index e377b15f..56015455 100644 --- a/src/types/ListParams.ts +++ b/src/types/ListParams.ts @@ -29,6 +29,11 @@ export interface OldListData { items: string[]; } +/** + * Type that represents data of the List tool + */ +export type OldNestedListData = Omit; + /** * Interface that represents old checklist data format */ diff --git a/src/utils/normalizeData.ts b/src/utils/normalizeData.ts index 91221eff..2a4f3f21 100644 --- a/src/utils/normalizeData.ts +++ b/src/utils/normalizeData.ts @@ -1,20 +1,29 @@ -import type { OldListData, ListData, ListItem, OldChecklistData } from '../types/ListParams'; +import type { OldListData, ListData, ListItem, OldChecklistData, OldNestedListData } from '../types/ListParams'; /** * Method that checks if data is result of the Old list tool save mtehod - * @param data - data of the OldList, Checklist or Editorjs List tool + * @param data - data of the OldList, Checklist, OldNestedList or Editorjs List tool * @returns true if data related to the List tool, false otherwise */ -function instanceOfOldListData(data: ListData | OldListData | OldChecklistData): data is OldListData { +function instanceOfOldListData(data: ListData | OldListData | OldChecklistData | OldNestedListData): data is OldListData { return (typeof data.items[0] === 'string'); } +/** + * Method that checks if data is result of the Old nested list tool save method + * @param data - data of the OldList, Checklist, OldNestedList or Editorjs List tool + * @returns true if data is related to the Nested List tool, false otherwise + */ +function instanceOfOldNestedListData(data: ListData | OldListData | OldChecklistData | OldNestedListData): data is OldNestedListData { + return !('meta' in data); +} + /** * Method that checks if data is result of the Old checklist tool save method - * @param data - data of the Checklist, OldList or Editorjs List tool + * @param data - data of the Checklist, OldList, OldNestedList or Editorjs List tool * @returns true if data is related to the Checklist tool, false otherwise */ -function instanceOfChecklistData(data: ListData | OldListData | OldChecklistData): data is OldChecklistData { +function instanceOfChecklistData(data: ListData | OldListData | OldChecklistData | OldNestedListData): data is OldChecklistData { return ( typeof data.items[0] !== 'string' && 'text' in data.items[0] @@ -62,6 +71,12 @@ export default function normalizeData(data: ListData | OldListData | OldChecklis meta: {}, items: normalizedDataItems, }; + } else if (instanceOfOldNestedListData(data)) { + return { + style: data.style, + meta: {}, + items: data.items, + }; } else { return data; } From 419a3910cfe360e47cd9a7a4e6d1aceb88289381 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:24:45 +0300 Subject: [PATCH 06/18] bug(tabulator): fix backspace with selection - backspace with selection deletes selection --- src/ListTabulator/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ListTabulator/index.ts b/src/ListTabulator/index.ts index 35f0b6fe..a23236f1 100644 --- a/src/ListTabulator/index.ts +++ b/src/ListTabulator/index.ts @@ -533,6 +533,14 @@ export default class ListTabulator { return; } + /** + * Caret is at start of input in case of delete selection + * Then backspace should be handled as usual + */ + if ((isCaretAtStartOfInput(currentItem) && window.getSelection()?.isCollapsed === false)) { + return; + } + /** * Prevent Editor.js backspace handling */ From 39c87d20588bc943a9dd33b2129432529d31b253 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:31:10 +0300 Subject: [PATCH 07/18] remove redundant condition --- src/ListTabulator/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ListTabulator/index.ts b/src/ListTabulator/index.ts index a23236f1..d62acb26 100644 --- a/src/ListTabulator/index.ts +++ b/src/ListTabulator/index.ts @@ -534,10 +534,9 @@ export default class ListTabulator { } /** - * Caret is at start of input in case of delete selection - * Then backspace should be handled as usual + * If backspace is pressed with selection, it should be handled as usual */ - if ((isCaretAtStartOfInput(currentItem) && window.getSelection()?.isCollapsed === false)) { + if (window.getSelection()?.isCollapsed === false) { return; } From 416b21ca734fd861bc88603866eba9a44371e26d Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:44:42 +0300 Subject: [PATCH 08/18] chore(): bump package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2dad172b..59465f85 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.1", + "version": "2.0.2", "keywords": [ "codex editor", "list", From 256e8e77853a1b12dd58db4e0704d289e5f7e3a1 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:45:46 +0300 Subject: [PATCH 09/18] chore(): bump package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 59465f85..6bcb7eee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.2", + "version": "2.0.4", "keywords": [ "codex editor", "list", From 4d7e576df0a32992d877ab0cc13bf30cbca92b91 Mon Sep 17 00:00:00 2001 From: jscastanos Date: Mon, 10 Feb 2025 10:30:51 +0800 Subject: [PATCH 10/18] hide tune if there's no valid option --- src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e5cb07c4..93290cd5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -368,8 +368,16 @@ export default class EditorjsList { }, }); }); + + /** + * Dont show Counter type tune if there is no valid counter types + */ + if (orderedListCountersTunes.children.items!.length > 0) { + 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; From 59b6e5732197d294e91d1ba9e850a421bc7a53d3 Mon Sep 17 00:00:00 2001 From: jscastanos Date: Sat, 15 Feb 2025 17:25:47 +0800 Subject: [PATCH 11/18] get type from map and show tune for 1 type --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 93290cd5..96435b35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -218,7 +218,7 @@ export default class EditorjsList { /** * Set the default counter types for the ordered list */ - this.defaultCounterTypes = this.config?.counterTypes || ['numeric', 'upper-roman', 'lower-roman', 'upper-alpha', 'lower-alpha']; + this.defaultCounterTypes = (this.config as ListConfig).counterTypes || Array.from(OlCounterTypesMap.values()) as OlCounterType[]; const initialData = { style: this.defaultListStyle, @@ -372,7 +372,7 @@ export default class EditorjsList { /** * Dont show Counter type tune if there is no valid counter types */ - if (orderedListCountersTunes.children.items!.length > 0) { + if (orderedListCountersTunes.children.items!.length > 1) { orderedListTunes.push(orderedListCountersTunes); } From da9b6af23a8cdf23b4fcb70f20a0c5a1a96e90de Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:37:58 +0300 Subject: [PATCH 12/18] imp(example): add example of localisation --- playground/index.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/playground/index.html b/playground/index.html index c33e7015..799a9f09 100644 --- a/playground/index.html +++ b/playground/index.html @@ -104,6 +104,25 @@ } }, }, + /** + * Example of the lacalisation dictionary + */ + i18n: { + messages: { + "toolNames": { + "Ordered List": "Nummerierte Liste", + "Unordered List": "Unnummeriert Liste", + "Checklist": "Checkliste", + }, + "tools": { + "List": { + 'Unordered': 'Unnummeriert', + 'Ordered': 'Nummerierte', + 'Checklist': 'Checkliste', + } + }, + }, + }, /** * This Tool will be used as default From ae98f8fed4e8c2339700144fff2f4f2893e66f79 Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:38:13 +0300 Subject: [PATCH 13/18] imp(readme): add example of localisation --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 15e58564..ca744ff9 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,35 @@ Object `ItemMeta` for Ordered list Object `ItemMeta` for Unordered list would be empty. +## Localisation +If you want to use your language for toolbox items, you can pass i18n dictionary to the editorjs instance below the tools `block`: +```javascript +i18n: { + messages: { + "toolNames": { + "Ordered List": "Nummerierte Liste", + "Unordered List": "Unnummeriert Liste", + "Checklist": "Checkliste", + }, + "tools": { + "List": { + 'Unordered': 'Unnummeriert', + 'Ordered': 'Nummerierte', + 'Checklist': 'Checkliste', + } + }, + }, +}, +``` + +### Other supported keys for `tools.List` +- `Start with` +- `Counter type` +- `Numeric` +- `Lower Roman` +- `Upper Roman` +- `Lower Alpha` +- `Upper Alpha` ## Example of the content for `Unordered List` ```json From 2efbc18e49b74a9c7702657a1a7f4779dae68a6e Mon Sep 17 00:00:00 2001 From: e11sy <130844513+e11sy@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:59:52 +0300 Subject: [PATCH 14/18] chore(): bump package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bcb7eee..aa5ca2a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.4", + "version": "2.0.5", "keywords": [ "codex editor", "list", From b85cce633867508ccece1363188c7d89b3326ea2 Mon Sep 17 00:00:00 2001 From: jscastanos Date: Fri, 28 Feb 2025 17:35:25 +0800 Subject: [PATCH 15/18] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aa5ca2a9..a0dd2aca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.5", + "version": "2.0.6", "keywords": [ "codex editor", "list", From 993e7a63bd7fe63025b02d44e5a9d1c1df713d95 Mon Sep 17 00:00:00 2001 From: Robin Delattre Date: Wed, 5 Mar 2025 12:54:47 +0100 Subject: [PATCH 16/18] increment patch version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 59465f85..4d567601 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.2", + "version": "2.0.7", "keywords": [ "codex editor", "list", From 2bbea5157b1f91289c5c839caf7cc9a55db4300c Mon Sep 17 00:00:00 2001 From: Ilya Povarov Date: Fri, 7 Mar 2025 23:32:55 +0300 Subject: [PATCH 17/18] use clone instead of straight data --- src/utils/normalizeData.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/normalizeData.ts b/src/utils/normalizeData.ts index 2a4f3f21..e9d83c96 100644 --- a/src/utils/normalizeData.ts +++ b/src/utils/normalizeData.ts @@ -78,6 +78,6 @@ export default function normalizeData(data: ListData | OldListData | OldChecklis items: data.items, }; } else { - return data; + return structuredClone(data); } }; From ab5c7dd9bc8953998c86fa3d49b9f21f5c7c3a7f Mon Sep 17 00:00:00 2001 From: Ilya Povarov Date: Fri, 7 Mar 2025 23:33:05 +0300 Subject: [PATCH 18/18] increment version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0dd2aca..4d567601 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/list", - "version": "2.0.6", + "version": "2.0.7", "keywords": [ "codex editor", "list",