Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getSmartOrderedList(
styleList: string[]
): GenericContentEditFeature {
return {
keys: [Keys.CONTENTCHANGED], // Triggered by ContentChangedEvent
shouldHandleEvent: (event, editor) => event.data instanceof HTMLOListElement,
handleEvent: (event, editor) => {
let ol = event.data as HTMLOListElement;
let parentOl = editor.getElementAtCursor('OL', ol.parentNode) as HTMLOListElement;
if (parentOl) {
// The style list must has at least one value. If no value is passed in, fallback to decimal
let styles = styleList && styleList.length > 0 ? styleList : ['decimal'];
ol.style.listStyle =
styles[(styles.indexOf(parentOl.style.listStyle) + 1) % styles.length];
}
},
};
}