/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */ import { Element , Traverse , Replication , Attr , Node } from '@ephox/sugar' ; import { Arr , Option } from '@ephox/katamari' ; import { hasLastChildList , ListType } from './Util' ; export interface Entry { depth : number ; content : Element [ ] ; isSelected : boolean ; listType : ListType ; listAttributes : Record < string , any > ; itemAttributes : Record < string , any > ; } const isIndented = ( entry ) => { return entry . depth > 0 ; } ; const isSelected = ( entry ) => { return entry . isSelected ; } ; const cloneItemContent = ( li ) : Element [ ] => { const children = Traverse . children ( li ) ; const content = hasLastChildList ( li ) ? children . slice ( 0 , - 1 ) : children ; return Arr . map ( content , Replication . deep ) ; } ; const createEntry = ( li , depth , isSelected ) : 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 } ; } ) ; } ; export { createEntry , isIndented , isSelected } ;