const cloneItemContent = (li: Element): Element[] => { const children = Traverse.children(li); const content = hasLastChildList(li) ? children.slice(0, -1) : children; return Arr.map(content, Replication.deep); }
const outdentedComposer = (editor: Editor, entries: Entry[]): Element[] => { return Arr.map(entries, (entry) => { const content = Fragment.fromElements(entry.content); return Element.fromDom(createTextBlock(editor, content.dom())); }); }
const listIndentation = (editor: Editor, lists: Element[], indentation: Indentation) => { const entrySets: EntrySet[] = parseLists(lists, getItemSelection(editor)); Arr.each(entrySets, (entrySet) => { indentSelectedEntries(entrySet.entries, indentation); const composedLists = composeEntries(editor, entrySet.entries); Arr.each(composedLists, (composedList) => { fireListEvent(editor, indentation === Indentation.Indent ? ListAction.IndentList : ListAction.OutdentList, composedList.dom()); }); InsertAll.before(entrySet.sourceList, composedLists); Remove.remove(entrySet.sourceList); }); }
const populateSegments = (segments: Segment[], entry: Entry): void => { for (let i = 0; i < segments.length - 1; i++) { Css.set(segments[i].item, 'list-style-type', 'none'); } Arr.last(segments).each((segment) => { Attr.setAll(segment.list, entry.listAttributes); Attr.setAll(segment.item, entry.itemAttributes); InsertAll.append(segment.item, entry.content); }); }
const getItemSelection = (editor: Editor): Option<ItemSelection> => { const selectedListItems = Arr.map(Selection.getSelectedListItems(editor), Element.fromDom); return Options.lift2( Arr.find(selectedListItems, Fun.not(hasFirstChildList)), Arr.find(Arr.reverse(selectedListItems), Fun.not(hasFirstChildList)), (start, end) => ({ start, end })); }
const createEntry = (li: Element, depth: number, isSelected: boolean): Option<Entry> => { return Traverse.parent(li).filter(Node.isElement).map((list) => { return { depth, isSelected, content: cloneItemContent(li), itemAttributes: Attr.clone(li), listAttributes: Attr.clone(list), listType: Node.name(list) as ListType }; }); }
const indentDlItem = (item: Element): void => { if (Compare.is(item, 'dt')) { Replication.mutate(item, 'dd'); } }
const selectionIndentation = (editor: Editor, indentation: Indentation): boolean => { const lists = Arr.map(Selection.getSelectedListRoots(editor), Element.fromDom); const dlItems = Arr.map(Selection.getSelectedDlItems(editor), Element.fromDom); let isHandled = false; if (lists.length || dlItems.length) { const bookmark = editor.selection.getBookmark(); listIndentation(editor, lists, indentation); dlIndentation(editor, indentation, dlItems); editor.selection.moveToBookmark(bookmark); editor.selection.setRng(Range.normalizeRange(editor.selection.getRng())); editor.nodeChanged(); isHandled = true; } return isHandled; }