refactor: component manager usecases (#2354)
This commit is contained in:
@@ -33,7 +33,6 @@ describe('note view controller', () => {
|
||||
application.sync.sync = jest.fn().mockReturnValue(Promise.resolve())
|
||||
|
||||
componentManager = {} as jest.Mocked<SNComponentManager>
|
||||
componentManager.legacyGetDefaultEditor = jest.fn()
|
||||
Object.defineProperty(application, 'componentManager', { value: componentManager })
|
||||
|
||||
const mutator = {} as jest.Mocked<MutatorClientInterface>
|
||||
@@ -41,7 +40,7 @@ describe('note view controller', () => {
|
||||
})
|
||||
|
||||
it('should create notes with plaintext note type', async () => {
|
||||
application.geDefaultEditorIdentifier = jest.fn().mockReturnValue(FeatureIdentifier.PlainEditor)
|
||||
application.componentManager.getDefaultEditorIdentifier = jest.fn().mockReturnValue(FeatureIdentifier.PlainEditor)
|
||||
|
||||
const controller = new NoteViewController(application)
|
||||
await controller.initialize()
|
||||
@@ -54,15 +53,15 @@ describe('note view controller', () => {
|
||||
})
|
||||
|
||||
it('should create notes with markdown note type', async () => {
|
||||
componentManager.legacyGetDefaultEditor = jest.fn().mockReturnValue({
|
||||
identifier: FeatureIdentifier.MarkdownProEditor,
|
||||
} as SNComponent)
|
||||
application.items.getDisplayableComponents = jest.fn().mockReturnValue([
|
||||
{
|
||||
identifier: FeatureIdentifier.MarkdownProEditor,
|
||||
} as SNComponent,
|
||||
])
|
||||
|
||||
componentManager.componentOrNativeFeatureForIdentifier = jest.fn().mockReturnValue({
|
||||
identifier: FeatureIdentifier.MarkdownProEditor,
|
||||
} as SNComponent)
|
||||
|
||||
application.geDefaultEditorIdentifier = jest.fn().mockReturnValue(FeatureIdentifier.MarkdownProEditor)
|
||||
application.componentManager.getDefaultEditorIdentifier = jest
|
||||
.fn()
|
||||
.mockReturnValue(FeatureIdentifier.MarkdownProEditor)
|
||||
|
||||
const controller = new NoteViewController(application)
|
||||
await controller.initialize()
|
||||
@@ -75,7 +74,7 @@ describe('note view controller', () => {
|
||||
})
|
||||
|
||||
it('should add tag to note if default tag is set', async () => {
|
||||
application.geDefaultEditorIdentifier = jest.fn().mockReturnValue(FeatureIdentifier.PlainEditor)
|
||||
application.componentManager.getDefaultEditorIdentifier = jest.fn().mockReturnValue(FeatureIdentifier.PlainEditor)
|
||||
|
||||
const tag = {
|
||||
uuid: 'tag-uuid',
|
||||
|
||||
@@ -94,7 +94,7 @@ export class NoteViewController implements ItemViewControllerInterface {
|
||||
if (!this.item) {
|
||||
log(LoggingDomain.NoteView, 'Initializing as template note')
|
||||
|
||||
const editorIdentifier = this.application.geDefaultEditorIdentifier(this.defaultTag)
|
||||
const editorIdentifier = this.application.componentManager.getDefaultEditorIdentifier(this.defaultTag)
|
||||
|
||||
const noteType = noteTypeForEditorIdentifier(editorIdentifier)
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ import {
|
||||
ApplicationEvent,
|
||||
ComponentArea,
|
||||
ComponentInterface,
|
||||
ComponentOrNativeFeature,
|
||||
UIFeature,
|
||||
ComponentViewerInterface,
|
||||
ContentType,
|
||||
EditorLineWidth,
|
||||
IframeComponentFeatureDescription,
|
||||
isIframeUIFeature,
|
||||
isUIFeatureAnIframeFeature,
|
||||
isPayloadSourceInternalChange,
|
||||
isPayloadSourceRetrieved,
|
||||
NoteType,
|
||||
@@ -456,7 +456,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
||||
})
|
||||
}
|
||||
|
||||
private createComponentViewer(component: ComponentOrNativeFeature<IframeComponentFeatureDescription>) {
|
||||
private createComponentViewer(component: UIFeature<IframeComponentFeatureDescription>) {
|
||||
if (!component) {
|
||||
throw Error('Cannot create component viewer for undefined component')
|
||||
}
|
||||
@@ -516,7 +516,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
||||
const newUIFeature = this.application.componentManager.editorForNote(this.note)
|
||||
|
||||
/** Component editors cannot interact with template notes so the note must be inserted */
|
||||
if (isIframeUIFeature(newUIFeature) && this.controller.isTemplateNote) {
|
||||
if (isUIFeatureAnIframeFeature(newUIFeature) && this.controller.isTemplateNote) {
|
||||
await this.controller.insertTemplatedNote()
|
||||
}
|
||||
|
||||
@@ -529,7 +529,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
||||
}
|
||||
}
|
||||
|
||||
if (isIframeUIFeature(newUIFeature)) {
|
||||
if (isUIFeatureAnIframeFeature(newUIFeature)) {
|
||||
this.setState({
|
||||
editorComponentViewer: this.createComponentViewer(newUIFeature),
|
||||
editorStateDidLoad: true,
|
||||
@@ -767,7 +767,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
||||
for (const component of needsNewViewer) {
|
||||
newViewers.push(
|
||||
this.application.componentManager.createComponentViewer(
|
||||
new ComponentOrNativeFeature<IframeComponentFeatureDescription>(component),
|
||||
new UIFeature<IframeComponentFeatureDescription>(component),
|
||||
{
|
||||
uuid: this.note.uuid,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ContentType, NoteContent, NoteType, SNNote, classNames, isIframeUIFeature } from '@standardnotes/snjs'
|
||||
import { ContentType, NoteContent, NoteType, SNNote, classNames, isUIFeatureAnIframeFeature } from '@standardnotes/snjs'
|
||||
import { UIEventHandler, useEffect, useMemo, useRef } from 'react'
|
||||
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
|
||||
import { useApplication } from '../ApplicationProvider'
|
||||
@@ -31,7 +31,7 @@ export const ReadonlyNoteContent = ({
|
||||
|
||||
const componentViewer = useMemo(() => {
|
||||
const editorForCurrentNote = application.componentManager.editorForNote(note)
|
||||
if (!isIframeUIFeature(editorForCurrentNote)) {
|
||||
if (!isUIFeatureAnIframeFeature(editorForCurrentNote)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user