fix: simplify component logic
This commit is contained in:
@@ -55,17 +55,18 @@ class ComponentViewCtrl implements ComponentViewScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$onDestroy() {
|
$onDestroy() {
|
||||||
|
this.application.componentManager.onComponentIframeDestroyed(this.component.uuid);
|
||||||
|
if(this.liveComponent) {
|
||||||
|
this.liveComponent.deinit();
|
||||||
|
} else {
|
||||||
|
this.application.componentManager.removeTemporaryTemplateComponent(this.templateComponent);
|
||||||
|
}
|
||||||
this.cleanUpOn();
|
this.cleanUpOn();
|
||||||
(this.cleanUpOn as any) = undefined;
|
(this.cleanUpOn as any) = undefined;
|
||||||
this.unregisterComponentHandler();
|
this.unregisterComponentHandler();
|
||||||
(this.unregisterComponentHandler as any) = undefined;
|
(this.unregisterComponentHandler as any) = undefined;
|
||||||
this.unregisterDesktopObserver();
|
this.unregisterDesktopObserver();
|
||||||
(this.unregisterDesktopObserver as any) = undefined;
|
(this.unregisterDesktopObserver as any) = undefined;
|
||||||
if(this.liveComponent) {
|
|
||||||
this.liveComponent.deinit();
|
|
||||||
} else {
|
|
||||||
this.application.componentManager.removeTemporaryTemplateComponent(this.templateComponent);
|
|
||||||
}
|
|
||||||
(this.templateComponent as any) = undefined;
|
(this.templateComponent as any) = undefined;
|
||||||
(this.liveComponent as any) = undefined;
|
(this.liveComponent as any) = undefined;
|
||||||
(this.application as any) = undefined;
|
(this.application as any) = undefined;
|
||||||
@@ -91,6 +92,7 @@ class ComponentViewCtrl implements ComponentViewScope {
|
|||||||
return this.templateComponent || this.liveComponent?.item;
|
return this.templateComponent || this.liveComponent?.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @template */
|
||||||
public onIframeInit() {
|
public onIframeInit() {
|
||||||
/** Perform in timeout required so that dynamic iframe id is set (based on ctrl values) */
|
/** Perform in timeout required so that dynamic iframe id is set (based on ctrl values) */
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
SNTheme,
|
SNTheme,
|
||||||
ComponentArea,
|
ComponentArea,
|
||||||
removeFromArray,
|
removeFromArray,
|
||||||
ApplicationEvent
|
ApplicationEvent, ContentType
|
||||||
} from 'snjs';
|
} from 'snjs';
|
||||||
import { AppStateEvent } from '@/ui_models/app_state';
|
import { AppStateEvent } from '@/ui_models/app_state';
|
||||||
|
|
||||||
@@ -17,24 +17,16 @@ export class ThemeManager extends ApplicationService {
|
|||||||
private activeThemes: string[] = []
|
private activeThemes: string[] = []
|
||||||
private unsubState?: () => void
|
private unsubState?: () => void
|
||||||
private unregisterDesktop!: () => void
|
private unregisterDesktop!: () => void
|
||||||
private unregisterComponent!: () => void
|
private unregisterStream!: () => void
|
||||||
|
|
||||||
/** @override */
|
async onAppEvent(event: ApplicationEvent) {
|
||||||
async onAppLaunch() {
|
|
||||||
super.onAppLaunch();
|
|
||||||
this.unsubState = this.webApplication.getAppState().addObserver(
|
|
||||||
async (eventName) => {
|
|
||||||
if (eventName === AppStateEvent.DesktopExtsReady) {
|
|
||||||
this.activateCachedThemes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
onAppEvent(event: ApplicationEvent) {
|
|
||||||
super.onAppEvent(event);
|
super.onAppEvent(event);
|
||||||
if (event === ApplicationEvent.SignedOut) {
|
if (event === ApplicationEvent.SignedOut) {
|
||||||
this.deactivateAllThemes();
|
this.deactivateAllThemes();
|
||||||
|
} else if (event === ApplicationEvent.StorageReady) {
|
||||||
|
if (!this.webApplication.getDesktopService().isDesktop) {
|
||||||
|
await this.activateCachedThemes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +39,9 @@ export class ThemeManager extends ApplicationService {
|
|||||||
(this.unsubState as any) = undefined;
|
(this.unsubState as any) = undefined;
|
||||||
this.activeThemes.length = 0;
|
this.activeThemes.length = 0;
|
||||||
this.unregisterDesktop();
|
this.unregisterDesktop();
|
||||||
this.unregisterComponent();
|
this.unregisterStream();
|
||||||
(this.unregisterDesktop as any) = undefined;
|
(this.unregisterDesktop as any) = undefined;
|
||||||
(this.unregisterComponent as any) = undefined;
|
(this.unregisterStream as any) = undefined;
|
||||||
super.deinit();
|
super.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,9 +49,13 @@ export class ThemeManager extends ApplicationService {
|
|||||||
async onAppStart() {
|
async onAppStart() {
|
||||||
super.onAppStart();
|
super.onAppStart();
|
||||||
this.registerObservers();
|
this.registerObservers();
|
||||||
if (!this.webApplication.getDesktopService().isDesktop) {
|
this.unsubState = this.webApplication.getAppState().addObserver(
|
||||||
this.activateCachedThemes();
|
async (eventName) => {
|
||||||
}
|
if (eventName === AppStateEvent.DesktopExtsReady) {
|
||||||
|
this.activateCachedThemes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async activateCachedThemes() {
|
private async activateCachedThemes() {
|
||||||
@@ -81,17 +77,16 @@ export class ThemeManager extends ApplicationService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.unregisterComponent = this.application!.componentManager!.registerHandler({
|
this.unregisterStream = this.application.streamItems(ContentType.Theme, (items) => {
|
||||||
identifier: 'themeManager',
|
const themes = items as SNTheme[];
|
||||||
areas: [ComponentArea.Themes],
|
for (const theme of themes) {
|
||||||
activationHandler: (uuid, component) => {
|
if (theme.active) {
|
||||||
if (component?.active) {
|
this.activateTheme(theme);
|
||||||
this.activateTheme(component as SNTheme);
|
|
||||||
} else {
|
} else {
|
||||||
this.deactivateTheme(uuid);
|
this.deactivateTheme(theme.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private deactivateAllThemes() {
|
private deactivateAllThemes() {
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ export class PureViewCtrl<P = CtrlProps, S = CtrlState> {
|
|||||||
this.onAppFullSync();
|
this.onAppFullSync();
|
||||||
} else if (eventName === ApplicationEvent.KeyStatusChanged) {
|
} else if (eventName === ApplicationEvent.KeyStatusChanged) {
|
||||||
this.onAppKeyChange();
|
this.onAppKeyChange();
|
||||||
|
} else if (eventName === ApplicationEvent.LocalDataLoaded) {
|
||||||
|
this.onLocalDataLoaded();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -137,6 +139,10 @@ export class PureViewCtrl<P = CtrlProps, S = CtrlState> {
|
|||||||
await this.resetState();
|
await this.resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLocalDataLoaded() {
|
||||||
|
/** Optional override */
|
||||||
|
}
|
||||||
|
|
||||||
async onAppLaunch() {
|
async onAppLaunch() {
|
||||||
/** Optional override */
|
/** Optional override */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import angular from 'angular';
|
|||||||
import {
|
import {
|
||||||
ApplicationEvent,
|
ApplicationEvent,
|
||||||
isPayloadSourceRetrieved,
|
isPayloadSourceRetrieved,
|
||||||
|
isPayloadSourceInternalChange,
|
||||||
ContentType,
|
ContentType,
|
||||||
ProtectedAction,
|
ProtectedAction,
|
||||||
SNComponent,
|
SNComponent,
|
||||||
@@ -209,12 +210,6 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$onDestroy() {
|
|
||||||
if (this.state.tagsComponent) {
|
|
||||||
this.application.componentManager!.deregisterComponent(this.state.tagsComponent.uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return {
|
return {
|
||||||
@@ -337,7 +332,10 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
|
|
||||||
this.removeComponentsObserver = this.application.streamItems(
|
this.removeComponentsObserver = this.application.streamItems(
|
||||||
ContentType.Component,
|
ContentType.Component,
|
||||||
async () => {
|
async (_items, source) => {
|
||||||
|
if (isPayloadSourceInternalChange(source!)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.note) return;
|
if (!this.note) return;
|
||||||
this.reloadStackComponents();
|
this.reloadStackComponents();
|
||||||
this.reloadNoteTagsComponent();
|
this.reloadNoteTagsComponent();
|
||||||
@@ -350,25 +348,15 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
const newEditor = this.application.componentManager!.editorForNote(this.note);
|
const newEditor = this.application.componentManager!.editorForNote(this.note);
|
||||||
const currentEditor = this.state.editorComponent;
|
const currentEditor = this.state.editorComponent;
|
||||||
if (currentEditor?.uuid !== newEditor?.uuid) {
|
if (currentEditor?.uuid !== newEditor?.uuid) {
|
||||||
const unloading = this.setState({
|
await this.setState({
|
||||||
/** Unload current component view so that we create a new one */
|
/** Unload current component view so that we create a new one */
|
||||||
editorUnloading: true
|
editorUnloading: true
|
||||||
});
|
});
|
||||||
if (newEditor) {
|
await this.setState({
|
||||||
/** Register this new editor while the editor view is reloading */
|
|
||||||
this.application.componentManager!.registerComponent(newEditor.uuid);
|
|
||||||
}
|
|
||||||
await unloading;
|
|
||||||
const reloading = this.setState({
|
|
||||||
/** Reload component view */
|
/** Reload component view */
|
||||||
editorComponent: newEditor,
|
editorComponent: newEditor,
|
||||||
editorUnloading: false,
|
editorUnloading: false,
|
||||||
});
|
});
|
||||||
if (currentEditor) {
|
|
||||||
/** Deregister the current (previous) editor while the editor view is reloading */
|
|
||||||
this.application.componentManager!.deregisterComponent(currentEditor.uuid);
|
|
||||||
}
|
|
||||||
await reloading;
|
|
||||||
this.reloadFont();
|
this.reloadFont();
|
||||||
}
|
}
|
||||||
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
|
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
|
||||||
@@ -1066,15 +1054,6 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
reloadNoteTagsComponent() {
|
reloadNoteTagsComponent() {
|
||||||
const [tagsComponent] =
|
const [tagsComponent] =
|
||||||
this.application.componentManager!.componentsForArea(ComponentArea.NoteTags);
|
this.application.componentManager!.componentsForArea(ComponentArea.NoteTags);
|
||||||
if (tagsComponent?.uuid !== this.state.tagsComponent?.uuid) {
|
|
||||||
if (tagsComponent) {
|
|
||||||
if (tagsComponent.active) {
|
|
||||||
this.application.componentManager!.registerComponent(tagsComponent.uuid);
|
|
||||||
} else {
|
|
||||||
this.application.componentManager!.deregisterComponent(tagsComponent.uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.setState({
|
this.setState({
|
||||||
tagsComponent: tagsComponent?.active ? tagsComponent : undefined
|
tagsComponent: tagsComponent?.active ? tagsComponent : undefined
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
private editingOriginalName?: string
|
private editingOriginalName?: string
|
||||||
formData: { tagTitle?: string } = {}
|
formData: { tagTitle?: string } = {}
|
||||||
titles: Partial<Record<UuidString, string>> = {}
|
titles: Partial<Record<UuidString, string>> = {}
|
||||||
private removeTagsObserver?: () => void
|
private removeTagsObserver!: () => void
|
||||||
|
private removeFoldersObserver!: () => void
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
@@ -60,7 +61,8 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
|
|
||||||
deinit() {
|
deinit() {
|
||||||
this.removeTagsObserver?.();
|
this.removeTagsObserver?.();
|
||||||
this.removeTagsObserver = undefined;
|
(this.removeTagsObserver as any) = undefined;
|
||||||
|
(this.removeFoldersObserver as any) = undefined;
|
||||||
this.unregisterComponent();
|
this.unregisterComponent();
|
||||||
this.unregisterComponent = undefined;
|
this.unregisterComponent = undefined;
|
||||||
super.deinit();
|
super.deinit();
|
||||||
@@ -112,6 +114,13 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beginStreamingItems() {
|
beginStreamingItems() {
|
||||||
|
this.removeFoldersObserver = this.application.streamItems(
|
||||||
|
[ContentType.Component],
|
||||||
|
async (_items) => {
|
||||||
|
this.component = this.application.componentManager
|
||||||
|
.componentsForArea(ComponentArea.TagsList)[0];
|
||||||
|
});
|
||||||
|
|
||||||
this.removeTagsObserver = this.application.streamItems(
|
this.removeTagsObserver = this.application.streamItems(
|
||||||
[ContentType.Tag, ContentType.SmartTag],
|
[ContentType.Tag, ContentType.SmartTag],
|
||||||
async (items) => {
|
async (items) => {
|
||||||
@@ -218,8 +227,8 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
|
|
||||||
onPanelResize = (
|
onPanelResize = (
|
||||||
newWidth: number,
|
newWidth: number,
|
||||||
lastLeft: number,
|
_lastLeft: number,
|
||||||
isAtMaxWidth: boolean,
|
_isAtMaxWidth: boolean,
|
||||||
isCollapsed: boolean
|
isCollapsed: boolean
|
||||||
) => {
|
) => {
|
||||||
this.application.getPrefsService().setUserPrefValue(
|
this.application.getPrefsService().setUserPrefValue(
|
||||||
@@ -237,12 +246,6 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
this.unregisterComponent = this.application.componentManager!.registerHandler({
|
this.unregisterComponent = this.application.componentManager!.registerHandler({
|
||||||
identifier: 'tags',
|
identifier: 'tags',
|
||||||
areas: [ComponentArea.TagsList],
|
areas: [ComponentArea.TagsList],
|
||||||
activationHandler: (_, component) => {
|
|
||||||
this.component = component;
|
|
||||||
},
|
|
||||||
contextRequestHandler: () => {
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
actionHandler: (_, action, data) => {
|
actionHandler: (_, action, data) => {
|
||||||
if (action === ComponentAction.SelectItem) {
|
if (action === ComponentAction.SelectItem) {
|
||||||
if (data.item.content_type === ContentType.Tag) {
|
if (data.item.content_type === ContentType.Tag) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
.sk-p
|
.sk-p
|
||||||
| Extensions are in a read-only state.
|
| Extensions are in a read-only state.
|
||||||
.right
|
.right
|
||||||
.sk-app-bar-item(ng-click='ctrl.reloadComponent()')
|
.sk-app-bar-item(ng-click='ctrl.reloadIframe()')
|
||||||
.sk-button.info
|
.sk-button.info
|
||||||
.sk-label Reload
|
.sk-label Reload
|
||||||
.sk-app-bar-item
|
.sk-app-bar-item
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export declare class AutolockService extends ApplicationService {
|
|||||||
private lockApplication;
|
private lockApplication;
|
||||||
setAutoLockInterval(interval: number): Promise<void>;
|
setAutoLockInterval(interval: number): Promise<void>;
|
||||||
getAutoLockInterval(): Promise<any>;
|
getAutoLockInterval(): Promise<any>;
|
||||||
|
deleteAutolockPreference(): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Verify document is in focus every so often as visibilitychange event is
|
* Verify document is in focus every so often as visibilitychange event is
|
||||||
* not triggered on a typical window blur event but rather on tab changes.
|
* not triggered on a typical window blur event but rather on tab changes.
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ export declare class ThemeManager extends ApplicationService {
|
|||||||
private activeThemes;
|
private activeThemes;
|
||||||
private unsubState?;
|
private unsubState?;
|
||||||
private unregisterDesktop;
|
private unregisterDesktop;
|
||||||
private unregisterComponent;
|
private unregisterStream;
|
||||||
/** @override */
|
onAppEvent(event: ApplicationEvent): Promise<void>;
|
||||||
onAppLaunch(): Promise<void>;
|
|
||||||
onAppEvent(event: ApplicationEvent): void;
|
|
||||||
get webApplication(): WebApplication;
|
get webApplication(): WebApplication;
|
||||||
deinit(): void;
|
deinit(): void;
|
||||||
/** @override */
|
/** @override */
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export declare class PureViewCtrl<P = CtrlProps, S = CtrlState> {
|
|||||||
onAppEvent(eventName: ApplicationEvent): void;
|
onAppEvent(eventName: ApplicationEvent): void;
|
||||||
/** @override */
|
/** @override */
|
||||||
onAppStart(): Promise<void>;
|
onAppStart(): Promise<void>;
|
||||||
|
onLocalDataLoaded(): void;
|
||||||
onAppLaunch(): Promise<void>;
|
onAppLaunch(): Promise<void>;
|
||||||
onAppKeyChange(): Promise<void>;
|
onAppKeyChange(): Promise<void>;
|
||||||
onAppIncrementalSync(): void;
|
onAppIncrementalSync(): void;
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -10956,8 +10956,8 @@
|
|||||||
"from": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad"
|
"from": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad"
|
||||||
},
|
},
|
||||||
"snjs": {
|
"snjs": {
|
||||||
"version": "github:standardnotes/snjs#7abfb3eb46db1409dbcb152b3d9d14ee0453c4a6",
|
"version": "github:standardnotes/snjs#30520edbd80564d584c4b00a09b552d89d1c9e26",
|
||||||
"from": "github:standardnotes/snjs#7abfb3eb46db1409dbcb152b3d9d14ee0453c4a6"
|
"from": "github:standardnotes/snjs#30520edbd80564d584c4b00a09b552d89d1c9e26"
|
||||||
},
|
},
|
||||||
"sockjs": {
|
"sockjs": {
|
||||||
"version": "0.3.20",
|
"version": "0.3.20",
|
||||||
|
|||||||
@@ -68,6 +68,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad",
|
"sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad",
|
||||||
"snjs": "github:standardnotes/snjs#7abfb3eb46db1409dbcb152b3d9d14ee0453c4a6"
|
"snjs": "github:standardnotes/snjs#30520edbd80564d584c4b00a09b552d89d1c9e26"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user