import { Node , Config , Global } from '~/core' ; export class NodeHelper { static isSource ( node ) { if ( node . type === 'record' ) return node . locale === Config . sourceLanguage ; return false ; } static hasFilepath ( node ) { if ( node . type === 'record' ) return ! ! node . filepath ; return false ; } static notShadowOrHasFilepath ( node ) { return ! node . shadow || this . hasFilepath ( node ) ; } static isTranslatable ( node ) { if ( Config . readonly || node . readonly || node . type === 'tree' ) return false ; if ( Config . translatePromptSource ) return true ; return ! this . isSource ( node ) ; } static isOpenable ( node ) { return node . type !== 'tree' && this . notShadowOrHasFilepath ( node ) ; } static isEditable ( node ) { return ! Config . readonly && ! node . readonly && node . type !== 'tree' ; } static splitKeypath ( keypath ) { if ( Config . disablePathParsing ) return [ keypath ] ; return keypath . replace ( /\[(.*?)\]/g , '.$1' ) . split ( '.' ) ; } static getPathWithoutNamespace ( keypath , node ? , namespace ? ) { if ( Global . namespaceEnabled ) { namespace = node ?. meta ?. namespace || namespace ; if ( namespace ) return keypath . slice ( namespace . length + 1 ) ; } return keypath ; } }