Skip to content

Commit e6511b9

Browse files
authored
fix: creating list definitions with null ids (#804)
* fix: creating list definitions with null ids * fix: checking for NaN
1 parent 4186627 commit e6511b9

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/super-editor/src/core/helpers/list-numbering-helpers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export const getNewListId = (editor, grouping = 'definitions') => {
176176
*/
177177
export const getListDefinitionDetails = ({ numId, level, listType, editor, tries = 0 }) => {
178178
const { definitions, abstracts } = editor.converter.numbering;
179+
if (!numId) return {};
180+
179181
const numDef = definitions[numId];
180182

181183
// Generate new definition if needed

packages/super-editor/src/core/migrations/0.14-listsv2/listsv2migration.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ function flattenListCompletely(listNode, editor, baseLevel = 0, sharedNumId = nu
9494
const currentListType = listNode.type.name;
9595

9696
const needsMigration = shouldMigrateList(listNode);
97-
const needsDefinition = checkValidDefinition(listNode, editor);
97+
const hasValidDefinition = checkValidDefinition(listNode, editor);
9898
log('Needs migration?', needsMigration);
9999
if (!needsMigration) {
100-
if (needsDefinition) {
100+
if (!hasValidDefinition) {
101101
return generateMissingListDefinition(listNode, editor);
102102
} else {
103103
return result;
@@ -106,6 +106,7 @@ function flattenListCompletely(listNode, editor, baseLevel = 0, sharedNumId = nu
106106

107107
let numId = parseInt(listNode.attrs?.listId);
108108
log('LIST ID', numId, 'SHARED NUM ID', sharedNumId);
109+
if (!numId || Number.isNaN(numId)) numId = ListHelpers.getNewListId(editor);
109110
const listHasDef = ListHelpers.getListDefinitionDetails({ numId, level: baseLevel, editor });
110111
if (!listHasDef || (!sharedNumId && !numId)) {
111112
// In some legacy cases, we might not find any list ID at all but we can infer
@@ -245,7 +246,7 @@ const checkValidDefinition = (listNode, editor) => {
245246
const listDef = ListHelpers.getListDefinitionDetails({ numId, level, listType, editor });
246247
const { abstract } = listDef || {};
247248

248-
if (!abstract) return true;
249+
if (abstract) return true;
249250
return false;
250251
};
251252

0 commit comments

Comments
 (0)