Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7abc293
permit to use linebreak
RobinDev Jan 5, 2025
6e8189a
feat: support optional counter type selection in ordered list
jscastanos Jan 13, 2025
d52c221
use counter type instead of the value
jscastanos Jan 13, 2025
134b77d
remove excess spacing
jscastanos Jan 13, 2025
e2472ba
imp(utils): improved normalize data util
e11sy Jan 18, 2025
7ba9701
Merge branch 'main' into improve-normalize-data-util
e11sy Jan 18, 2025
ca0357c
Merge pull request #131 from editor-js/improve-normalize-data-util
e11sy Jan 18, 2025
419a391
bug(tabulator): fix backspace with selection
e11sy Jan 24, 2025
39c87d2
remove redundant condition
e11sy Jan 24, 2025
416b21c
chore(): bump package version
e11sy Jan 24, 2025
256e8e7
chore(): bump package version
e11sy Jan 24, 2025
3a1b309
Merge branch 'main' into fix-backspace-with-selection
e11sy Jan 24, 2025
0b83f3f
Merge pull request #132 from editor-js/fix-backspace-with-selection
e11sy Jan 24, 2025
4d7e576
hide tune if there's no valid option
jscastanos Feb 10, 2025
aac05d4
Merge branch 'main' into feat/ordered-list-optional-config
jscastanos Feb 10, 2025
59b6e57
get type from map and show tune for 1 type
jscastanos Feb 15, 2025
da9b6af
imp(example): add example of localisation
e11sy Feb 27, 2025
ae98f8f
imp(readme): add example of localisation
e11sy Feb 27, 2025
2efbc18
chore(): bump package version
e11sy Feb 27, 2025
6b7fee9
Merge pull request #136 from editor-js/update-docs-for-localisation
e11sy Feb 27, 2025
55c07a8
Merge branch 'main' into feat/ordered-list-optional-config
jscastanos Feb 28, 2025
b85cce6
bump version
jscastanos Feb 28, 2025
0f1cfd6
Merge pull request #129 from jscastanos/feat/ordered-list-optional-co…
e11sy Feb 28, 2025
993e7a6
increment patch version
RobinDev Mar 5, 2025
a1e735d
Merge branch 'main' into linebreak
RobinDev Mar 5, 2025
2bbea51
use clone instead of straight data
holybobrius Mar 7, 2025
ab5c7dd
increment version
holybobrius Mar 7, 2025
e757f33
Merge pull request #138 from holybobrius/fix-read-only-meta-bug
e11sy May 4, 2025
d743918
Merge branch 'main' into linebreak
e11sy May 4, 2025
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
30 changes: 30 additions & 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 Expand Up @@ -97,6 +98,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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/list",
"version": "2.0.2",
"name": "@editorjs/list",
"version": "2.0.8",
"keywords": [
"codex editor",
"list",
Expand Down
19 changes: 19 additions & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/ListTabulator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export default class ListTabulator<Renderer extends ListRenderer> {
(event) => {
switch (event.key) {
case 'Enter':
this.enterPressed(event);
if (!event.shiftKey) {
this.enterPressed(event);
}
break;
case 'Backspace':
this.backspace(event);
Expand Down Expand Up @@ -533,6 +535,13 @@ export default class ListTabulator<Renderer extends ListRenderer> {
return;
}

/**
* If backspace is pressed with selection, it should be handled as usual
*/
if (window.getSelection()?.isCollapsed === false) {
return;
}

/**
* Prevent Editor.js backspace handling
*/
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 as ListConfig).counterTypes || Array.from(OlCounterTypesMap.values()) as OlCounterType[];

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 > 1) {
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
12 changes: 12 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 @@ -29,6 +30,11 @@ export interface OldListData {
items: string[];
}

/**
* Type that represents data of the List tool
*/
export type OldNestedListData = Omit<ListData, 'meta'>;

/**
* Interface that represents old checklist data format
*/
Expand Down Expand Up @@ -87,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[];
}
27 changes: 21 additions & 6 deletions src/utils/normalizeData.ts
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -62,7 +71,13 @@ 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;
return structuredClone(data);
}
};