Merge branch 'develop' into feature/desktop-integration

This commit is contained in:
Baptiste Grob
2020-11-17 11:47:37 +01:00
107 changed files with 130 additions and 1653 deletions

View File

@@ -4,11 +4,11 @@
"module": "commonjs",
"moduleResolution": "node",
"allowJs": true,
"noEmit": true,
"strict": true,
"isolatedModules": true,
"esModuleInterop": true,
"declaration": true,
"emitDeclarationOnly": true,
"newLine": "lf",
"declarationDir": "../../../dist/@types",
"baseUrl": ".",

View File

@@ -152,10 +152,20 @@ export class AppState {
*/
async createEditor(title?: string) {
const activeEditor = this.getActiveEditor();
const activeTagUuid = this.selectedTag
? this.selectedTag.isSmartTag()
? undefined
: this.selectedTag.uuid
: undefined;
if (!activeEditor || this.multiEditorEnabled) {
this.application.editorGroup.createEditor(undefined, title);
this.application.editorGroup.createEditor(
undefined,
title,
activeTagUuid
);
} else {
await activeEditor.reset(title);
await activeEditor.reset(title, activeTagUuid);
}
}

View File

@@ -1,4 +1,4 @@
import { SNNote, ContentType, PayloadSource } from 'snjs';
import { SNNote, ContentType, PayloadSource, UuidString, TagMutator } from 'snjs';
import { WebApplication } from './application';
export class Editor {
@@ -12,15 +12,16 @@ export class Editor {
constructor(
application: WebApplication,
noteUuid?: string,
noteTitle?: string
noteUuid: string | undefined,
noteTitle: string | undefined,
noteTag: UuidString | undefined
) {
this.application = application;
if (noteUuid) {
this.note = application.findItem(noteUuid) as SNNote;
this.streamItems();
} else {
this.reset(noteTitle)
this.reset(noteTitle, noteTag)
.then(() => this.streamItems())
.catch(console.error);
}
@@ -65,7 +66,10 @@ export class Editor {
* Reverts the editor to a blank state, removing any existing note from view,
* and creating a placeholder note.
*/
async reset(noteTitle = '') {
async reset(
noteTitle = '',
noteTag?: UuidString,
) {
const note = await this.application.createTemplateItem(
ContentType.Note,
{
@@ -74,6 +78,11 @@ export class Editor {
references: []
}
) as SNNote;
if (noteTag) {
await this.application.changeItem<TagMutator>(noteTag, (m) => {
m.addItemAsRelationship(note);
});
}
if (!this.isTemplateNote || this.note.title !== note.title) {
this.setNote(note as SNNote, true);
}

View File

@@ -1,4 +1,4 @@
import { removeFromArray } from 'snjs';
import { removeFromArray, UuidString } from 'snjs';
import { Editor } from './editor';
import { WebApplication } from './application';
@@ -21,8 +21,12 @@ export class EditorGroup {
}
}
createEditor(noteUuid?: string, noteTitle?: string) {
const editor = new Editor(this.application, noteUuid, noteTitle);
createEditor(
noteUuid?: string,
noteTitle?: string,
noteTag?: UuidString
) {
const editor = new Editor(this.application, noteUuid, noteTitle, noteTag);
this.editors.push(editor);
this.notifyObservers();
}
@@ -72,4 +76,4 @@ export class EditorGroup {
observer();
}
}
}
}

View File

@@ -76,7 +76,7 @@ class ApplicationViewCtrl extends PureViewCtrl {
async onAppLaunch() {
super.onAppLaunch();
this.setState({ needsUnlock: false });
this.handleAutoSignInFromParams();
this.handleDemoSignInFromParams();
}
onUpdateAvailable() {
@@ -142,28 +142,19 @@ class ApplicationViewCtrl extends PureViewCtrl {
}
}
async handleAutoSignInFromParams() {
const params = this.$location!.search();
const server = params.server;
const email = params.email;
const password = params.pw;
if (!server || !email || !password) return;
const user = this.application!.getUser();
if (user) {
if (user.email === email && await this.application!.getHost() === server) {
/** Already signed in, return */
return;
} else {
/** Sign out */
await this.application!.signOut();
}
async handleDemoSignInFromParams() {
if (
this.$location!.search().demo === 'true' &&
!this.application.hasAccount()
) {
await this.application!.setHost(
'https://syncing-server-demo.standardnotes.org'
);
this.application!.signIn(
'demo@standardnotes.org',
'password',
);
}
await this.application!.setHost(server);
this.application!.signIn(
email,
password,
);
}
}

View File

@@ -593,7 +593,7 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
}
focusTitle() {
document.getElementById(ElementIds.NoteTitleEditor)!.focus();
document.getElementById(ElementIds.NoteTitleEditor)?.focus();
}
clickedTextArea() {

View File

@@ -2,4 +2,4 @@ editor-view(
ng-repeat='editor in self.editors'
application='self.application'
editor='editor'
)
)