Files
standardnotes-app-web/packages/snjs/lib/Services/ComponentManager/UseCase/GetDefaultEditorIdentifier.ts
Mo 4a29e2a24c chore: upgrade eslint and prettier (#2376)
* chore: upgrade eslint and prettier

* chore: add restrict-template-expressions
2023-07-27 14:36:05 -05:00

40 lines
1.4 KiB
TypeScript

import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
import { ComponentArea, NativeFeatureIdentifier } from '@standardnotes/features'
import { ComponentInterface, PrefKey, SNTag } from '@standardnotes/models'
import { ItemManagerInterface, PreferenceServiceInterface } from '@standardnotes/services'
export class GetDefaultEditorIdentifier implements SyncUseCaseInterface<string> {
constructor(
private preferences: PreferenceServiceInterface,
private items: ItemManagerInterface,
) {}
execute(currentTag?: SNTag): Result<string> {
if (currentTag) {
const editorIdentifier = currentTag?.preferences?.editorIdentifier
if (editorIdentifier) {
return Result.ok(editorIdentifier)
}
}
const preferenceValue = this.preferences.getValue(PrefKey.DefaultEditorIdentifier)
if (preferenceValue) {
return Result.ok(preferenceValue)
}
const editors = this.thirdPartyComponentsForArea(ComponentArea.Editor)
const matchingEditor = editors.filter((e) => e.legacyIsDefaultEditor())[0]
if (matchingEditor) {
return Result.ok(matchingEditor.identifier)
}
return Result.ok(NativeFeatureIdentifier.TYPES.PlainEditor)
}
thirdPartyComponentsForArea(area: ComponentArea): ComponentInterface[] {
return this.items.getDisplayableComponents().filter((component) => {
return component.area === area
})
}
}