Skip to content

Commit bb714f1

Browse files
committed
fix: definition possibly missing name key, add jsdoc
1 parent 48ba12b commit bb714f1

File tree

1 file changed

+12
-7
lines changed
  • packages/super-editor/src/extensions/linked-styles

1 file changed

+12
-7
lines changed

packages/super-editor/src/extensions/linked-styles/helpers.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,20 @@ export const getMarksStyle = (attrs) => {
6666
return styles.trim();
6767
};
6868

69+
/**
70+
* Get a sorted list of paragraph quick-format styles from the editor.
71+
* @param {import('../../core/Editor.js').Editor} editor - The editor instance.
72+
* @returns {Array} Sorted list of styles.
73+
*/
6974
export const getQuickFormatList = (editor) => {
70-
if (!editor?.converter) return [];
71-
const styles = editor.converter.linkedStyles || [];
72-
return styles
73-
.filter((style) => {
74-
return style.type === 'paragraph' && style.definition.attrs;
75-
})
75+
if (!editor?.converter?.linkedStyles) return [];
76+
77+
return editor.converter.linkedStyles
78+
.filter((style) => style.type === 'paragraph' && style.definition?.attrs)
7679
.sort((a, b) => {
77-
return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
80+
const nameA = a.definition.attrs?.name ?? '';
81+
const nameB = b.definition.attrs?.name ?? '';
82+
return nameA.localeCompare(nameB);
7883
});
7984
};
8085

0 commit comments

Comments
 (0)