This commit is contained in:
Mo Bitar
2020-01-31 11:26:14 -06:00
parent 05fd5e7756
commit a9d2d519f4
9 changed files with 194 additions and 211 deletions

View File

@@ -7,7 +7,8 @@ import template from '%/editor.pug';
import { PureCtrl } from '@Controllers'; import { PureCtrl } from '@Controllers';
import { import {
APP_STATE_EVENT_NOTE_CHANGED, APP_STATE_EVENT_NOTE_CHANGED,
APP_STATE_EVENT_PREFERENCES_CHANGED APP_STATE_EVENT_PREFERENCES_CHANGED,
EVENT_SOURCE_SCRIPT
} from '@/state'; } from '@/state';
import { import {
STRING_DELETED_NOTE, STRING_DELETED_NOTE,
@@ -237,11 +238,11 @@ class EditorCtrl extends PureCtrl {
if (eventName === 'sync:taking-too-long') { if (eventName === 'sync:taking-too-long') {
this.setState({ this.setState({
syncTakingTooLong: true syncTakingTooLong: true
}) });
} else if (eventName === 'sync:completed') { } else if (eventName === 'sync:completed') {
this.setState({ this.setState({
syncTakingTooLong: false syncTakingTooLong: false
}) });
if (this.state.note.dirty) { if (this.state.note.dirty) {
/** if we're still dirty, don't change status, a sync is likely upcoming. */ /** if we're still dirty, don't change status, a sync is likely upcoming. */
} else { } else {
@@ -263,7 +264,7 @@ class EditorCtrl extends PureCtrl {
this.showErrorStatus(); this.showErrorStatus();
} }
} }
}) });
} }
addSyncStatusObserver() { addSyncStatusObserver() {
@@ -359,25 +360,6 @@ class EditorCtrl extends PureCtrl {
return this.actionsManager.extensionsInContextOfItem(this.state.note).length > 0; return this.actionsManager.extensionsInContextOfItem(this.state.note).length > 0;
} }
focusEditor({ delay } = {}) {
setTimeout(() => {
const element = document.getElementById(ELEMENT_ID_NOTE_TEXT_EDITOR);
if (element) {
element.focus();
}
}, delay);
}
focusTitle(delay) {
setTimeout(function () {
document.getElementById(ELEMENT_ID_NOTE_TITLE_EDITOR).focus();
}, delay);
}
clickedTextArea() {
this.setMenuState('showOptionsMenu', false);
}
saveNote({ saveNote({
bypassDebouncer, bypassDebouncer,
updateClientModified, updateClientModified,
@@ -429,8 +411,8 @@ class EditorCtrl extends PureCtrl {
text: STRING_GENERIC_SAVE_ERROR text: STRING_GENERIC_SAVE_ERROR
}); });
} }
}) });
}, syncDebouceMs) }, syncDebouceMs);
} }
showSavingStatus() { showSavingStatus() {
@@ -444,7 +426,7 @@ class EditorCtrl extends PureCtrl {
this.setState({ this.setState({
saveError: false, saveError: false,
syncTakingTooLong: false syncTakingTooLong: false
}) });
let status = "All changes saved"; let status = "All changes saved";
if (this.authManager.offline()) { if (this.authManager.offline()) {
status += " (offline)"; status += " (offline)";
@@ -459,12 +441,12 @@ class EditorCtrl extends PureCtrl {
error = { error = {
message: "Sync Unreachable", message: "Sync Unreachable",
desc: "Changes saved offline" desc: "Changes saved offline"
} };
} }
this.setState({ this.setState({
saveError: true, saveError: true,
syncTakingTooLong: false syncTakingTooLong: false
}) });
this.setStatus(error); this.setStatus(error);
} }
@@ -485,8 +467,8 @@ class EditorCtrl extends PureCtrl {
status.date = new Date(); status.date = new Date();
this.setState({ this.setState({
noteStatus: status noteStatus: status
}) });
}, waitForMs) }, waitForMs);
} }
contentChanged() { contentChanged() {
@@ -508,12 +490,29 @@ class EditorCtrl extends PureCtrl {
}); });
} }
focusEditor() {
const element = document.getElementById(ELEMENT_ID_NOTE_TEXT_EDITOR);
if (element) {
this.lastEditorFocusEventSource = EVENT_SOURCE_SCRIPT;
element.focus();
}
}
focusTitle() {
document.getElementById(ELEMENT_ID_NOTE_TITLE_EDITOR).focus();
}
clickedTextArea() {
this.setMenuState('showOptionsMenu', false);
}
onNameFocus() { onNameFocus() {
this.editingName = true; this.editingName = true;
} }
onContentFocus() { onContentFocus() {
this.appState.editorDidFocus(); this.appState.editorDidFocus(this.lastEditorFocusEventSource);
this.lastEditorFocusEventSource = null;
} }
onNameBlur() { onNameBlur() {
@@ -585,24 +584,13 @@ class EditorCtrl extends PureCtrl {
if (note === this.state.note) { if (note === this.state.note) {
this.setState({ this.setState({
note: null note: null
}) });
} }
if (note.dummy) { if (note.dummy) {
this.modelManager.removeItemLocally(note); this.modelManager.removeItemLocally(note);
return; return;
} }
this.syncManager.sync();
this.syncManager.sync().then(() => {
if (this.authManager.offline()) {
/**
* When deleting items while ofline, we need
* to explictly tell angular to refresh UI
*/
setTimeout(function () {
this.$rootScope.safeApply();
}, 50);
}
});
} }
restoreTrashedNote() { restoreTrashedNote() {

View File

@@ -4,7 +4,8 @@ import template from '%/footer.pug';
import { import {
APP_STATE_EVENT_EDITOR_FOCUSED, APP_STATE_EVENT_EDITOR_FOCUSED,
APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD, APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD,
APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD,
EVENT_SOURCE_USER_INTERACTION
} from '@/state'; } from '@/state';
import { import {
STRING_GENERIC_SYNC_ERROR, STRING_GENERIC_SYNC_ERROR,
@@ -55,33 +56,35 @@ class FooterCtrl {
this.authManager.checkForSecurityUpdate().then((available) => { this.authManager.checkForSecurityUpdate().then((available) => {
this.securityUpdateAvailable = available; this.securityUpdateAvailable = available;
}) });
this.statusManager.addStatusObserver((string) => { this.statusManager.addStatusObserver((string) => {
this.$timeout(() => { this.$timeout(() => {
this.arbitraryStatusMessage = string; this.arbitraryStatusMessage = string;
}) });
}) });
} }
addRootScopeListeners() { addRootScopeListeners() {
this.$rootScope.$on("security-update-status-changed", () => { this.$rootScope.$on("security-update-status-changed", () => {
this.securityUpdateAvailable = this.authManager.securityUpdateAvailable; this.securityUpdateAvailable = this.authManager.securityUpdateAvailable;
}) });
this.$rootScope.$on("reload-ext-data", () => { this.$rootScope.$on("reload-ext-data", () => {
this.reloadExtendedData(); this.reloadExtendedData();
}); });
this.$rootScope.$on("new-update-available", () => { this.$rootScope.$on("new-update-available", () => {
this.$timeout(() => { this.$timeout(() => {
this.onNewUpdateAvailable(); this.onNewUpdateAvailable();
}) });
}) });
} }
addAppStateObserver() { addAppStateObserver() {
this.appState.addObserver((eventName, data) => { this.appState.addObserver((eventName, data) => {
if(eventName === APP_STATE_EVENT_EDITOR_FOCUSED) { if(eventName === APP_STATE_EVENT_EDITOR_FOCUSED) {
this.closeAllRooms(); if (data.eventSource === EVENT_SOURCE_USER_INTERACTION) {
this.closeAccountMenu(); this.closeAllRooms();
this.closeAccountMenu();
}
} else if(eventName === APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD) { } else if(eventName === APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD) {
this.backupStatus = this.statusManager.addStatusFromString( this.backupStatus = this.statusManager.addStatusFromString(
"Saving local backup..." "Saving local backup..."
@@ -98,12 +101,11 @@ class FooterCtrl {
"Unable to save local backup." "Unable to save local backup."
); );
} }
this.$timeout(() => { this.$timeout(() => {
this.backupStatus = this.statusManager.removeStatus(this.backupStatus); this.backupStatus = this.statusManager.removeStatus(this.backupStatus);
}, 2000) }, 2000);
} }
}) });
} }
addSyncEventHandler() { addSyncEventHandler() {

View File

@@ -113,7 +113,7 @@ class NotesCtrl extends PureCtrl {
} else if (eventName === APP_STATE_EVENT_EDITOR_FOCUSED) { } else if (eventName === APP_STATE_EVENT_EDITOR_FOCUSED) {
this.setShowMenuFalse(); this.setShowMenuFalse();
} }
}) });
} }
addSignInObserver() { addSignInObserver() {

View File

@@ -61,14 +61,10 @@ class RootCtrl {
} }
defineRootScopeFunctions() { defineRootScopeFunctions() {
this.$rootScope.sync = () => {
this.syncManager.sync();
}
this.$rootScope.lockApplication = () => { this.$rootScope.lockApplication = () => {
/** Reloading wipes current objects from memory */ /** Reloading wipes current objects from memory */
window.location.reload(); window.location.reload();
} };
this.$rootScope.safeApply = (fn) => { this.$rootScope.safeApply = (fn) => {
const phase = this.$scope.$root.$$phase; const phase = this.$scope.$root.$$phase;
@@ -93,12 +89,12 @@ class RootCtrl {
this.$timeout(() => { this.$timeout(() => {
this.$scope.needsUnlock = false; this.$scope.needsUnlock = false;
this.loadAfterUnlock(); this.loadAfterUnlock();
}) });
} };
this.$scope.onUpdateAvailable = () => { this.$scope.onUpdateAvailable = () => {
this.$rootScope.$broadcast('new-update-available'); this.$rootScope.$broadcast('new-update-available');
} };
} }
initializeStorageManager() { initializeStorageManager() {
@@ -173,13 +169,13 @@ class RootCtrl {
this.uploadSyncStatus = this.statusManager.replaceStatusWithString( this.uploadSyncStatus = this.statusManager.replaceStatusWithString(
this.uploadSyncStatus, this.uploadSyncStatus,
`Syncing ${status.current}/${status.total} items...` `Syncing ${status.current}/${status.total} items...`
) );
} else if(this.uploadSyncStatus) { } else if(this.uploadSyncStatus) {
this.uploadSyncStatus = this.statusManager.removeStatus( this.uploadSyncStatus = this.statusManager.removeStatus(
this.uploadSyncStatus this.uploadSyncStatus
); );
} }
}) });
} }
configureKeyRequestHandler() { configureKeyRequestHandler() {
@@ -197,7 +193,7 @@ class RootCtrl {
keys: keys, keys: keys,
offline: offline, offline: offline,
auth_params: authParams auth_params: authParams
} };
}); });
} }
@@ -258,7 +254,7 @@ class RootCtrl {
setInterval(() => { setInterval(() => {
this.syncManager.sync(); this.syncManager.sync();
}, AUTO_SYNC_INTERVAL); }, AUTO_SYNC_INTERVAL);
}) });
}); });
} }
@@ -268,31 +264,35 @@ class RootCtrl {
this.modelManager.handleSignout(); this.modelManager.handleSignout();
this.syncManager.handleSignout(); this.syncManager.handleSignout();
} }
}) });
} }
addDragDropHandlers() { addDragDropHandlers() {
/** /**
* Disable dragging and dropping of files into main SN interface. * Disable dragging and dropping of files (but allow text) into main SN interface.
* both 'dragover' and 'drop' are required to prevent dropping of files. * both 'dragover' and 'drop' are required to prevent dropping of files.
* This will not prevent extensions from receiving drop events. * This will not prevent extensions from receiving drop events.
*/ */
window.addEventListener('dragover', (event) => { window.addEventListener('dragover', (event) => {
event.preventDefault(); if (event.dataTransfer.files.length > 0) {
}, false) event.preventDefault();
}
}, false);
window.addEventListener('drop', (event) => { window.addEventListener('drop', (event) => {
event.preventDefault(); if(event.dataTransfer.files.length > 0) {
this.alertManager.alert({ event.preventDefault();
text: STRING_DEFAULT_FILE_ERROR this.alertManager.alert({
}) text: STRING_DEFAULT_FILE_ERROR
}, false) });
}
}, false);
} }
handleAutoSignInFromParams() { handleAutoSignInFromParams() {
const urlParam = (key) => { const urlParam = (key) => {
return this.$location.search()[key]; return this.$location.search()[key];
} };
const autoSignInFromParams = async () => { const autoSignInFromParams = async () => {
const server = urlParam('server'); const server = urlParam('server');

View File

@@ -227,7 +227,8 @@ class TagsPanelCtrl extends PureCtrl {
this.editingOriginalName = null; this.editingOriginalName = null;
const matchingTag = this.modelManager.findTag(tag.title); const matchingTag = this.modelManager.findTag(tag.title);
if (this.state.newTag === tag && matchingTag) { const alreadyExists = matchingTag && matchingTag !== tag;
if (this.state.newTag === tag && alreadyExists) {
this.alertManager.alert({ this.alertManager.alert({
text: "A tag with this name already exists." text: "A tag with this name already exists."
}); });
@@ -264,9 +265,7 @@ class TagsPanelCtrl extends PureCtrl {
destructive: true, destructive: true,
onConfirm: () => { onConfirm: () => {
this.modelManager.setItemToBeDeleted(tag); this.modelManager.setItemToBeDeleted(tag);
this.syncManager.sync().then(() => { this.syncManager.sync();
this.$rootScope.safeApply();
});
} }
}); });
} }

View File

@@ -190,18 +190,18 @@ export class PasscodeManager {
} else { } else {
// tab visibility listener, web only // tab visibility listener, web only
document.addEventListener('visibilitychange', (e) => { document.addEventListener('visibilitychange', (e) => {
let visible = document.visibilityState == "visible"; const visible = document.visibilityState === "visible";
this.documentVisibilityChanged(visible); this.documentVisibilityChanged(visible);
}); });
// verify document is in focus every so often as visibilitychange event is not triggered // 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 // on a typical window blur event but rather on tab changes
this.pollFocusTimeout = setInterval(() => { this.pollFocusTimeout = setInterval(() => {
let hasFocus = document.hasFocus(); const hasFocus = document.hasFocus();
if(hasFocus && this.lastFocusState == "hidden") { if(hasFocus && this.lastFocusState === "hidden") {
this.documentVisibilityChanged(true); this.documentVisibilityChanged(true);
} else if(!hasFocus && this.lastFocusState == "visible") { } else if(!hasFocus && this.lastFocusState === "visible") {
this.documentVisibilityChanged(false); this.documentVisibilityChanged(false);
} }

View File

@@ -9,6 +9,9 @@ export const APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD = 6;
export const APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD = 7; export const APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD = 7;
export const APP_STATE_EVENT_DESKTOP_EXTS_READY = 8; export const APP_STATE_EVENT_DESKTOP_EXTS_READY = 8;
export const EVENT_SOURCE_USER_INTERACTION = 1;
export const EVENT_SOURCE_SCRIPT = 2;
export class AppState { export class AppState {
/* @ngInject */ /* @ngInject */
@@ -34,8 +37,8 @@ export class AppState {
await callback(eventName, data); await callback(eventName, data);
} }
resolve(); resolve();
}) });
}) });
} }
setSelectedTag(tag) { setSelectedTag(tag) {
@@ -58,7 +61,7 @@ export class AppState {
APP_STATE_EVENT_NOTE_CHANGED, APP_STATE_EVENT_NOTE_CHANGED,
{ previousNote: previousNote } { previousNote: previousNote }
); );
} };
if (note && note.content.protected && if (note && note.content.protected &&
await this.privilegesManager.actionRequiresPrivilege( await this.privilegesManager.actionRequiresPrivilege(
PrivilegesManager.ActionViewProtectedNotes PrivilegesManager.ActionViewProtectedNotes
@@ -94,12 +97,13 @@ export class AppState {
panel: name, panel: name,
collapsed: collapsed collapsed: collapsed
} }
) );
} }
editorDidFocus() { editorDidFocus(eventSource) {
this.notifyEvent( this.notifyEvent(
APP_STATE_EVENT_EDITOR_FOCUSED APP_STATE_EVENT_EDITOR_FOCUSED,
{eventSource: eventSource}
); );
} }

View File

@@ -741,40 +741,14 @@ function (_PureCtrl) {
value: function hasAvailableExtensions() { value: function hasAvailableExtensions() {
return this.actionsManager.extensionsInContextOfItem(this.state.note).length > 0; return this.actionsManager.extensionsInContextOfItem(this.state.note).length > 0;
} }
}, {
key: "focusEditor",
value: function focusEditor() {
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
delay = _ref2.delay;
setTimeout(function () {
var element = document.getElementById(ELEMENT_ID_NOTE_TEXT_EDITOR);
if (element) {
element.focus();
}
}, delay);
}
}, {
key: "focusTitle",
value: function focusTitle(delay) {
setTimeout(function () {
document.getElementById(ELEMENT_ID_NOTE_TITLE_EDITOR).focus();
}, delay);
}
}, {
key: "clickedTextArea",
value: function clickedTextArea() {
this.setMenuState('showOptionsMenu', false);
}
}, { }, {
key: "saveNote", key: "saveNote",
value: function saveNote(_ref3) { value: function saveNote(_ref2) {
var _this6 = this; var _this6 = this;
var bypassDebouncer = _ref3.bypassDebouncer, var bypassDebouncer = _ref2.bypassDebouncer,
updateClientModified = _ref3.updateClientModified, updateClientModified = _ref2.updateClientModified,
dontUpdatePreviews = _ref3.dontUpdatePreviews; dontUpdatePreviews = _ref2.dontUpdatePreviews;
var note = this.state.note; var note = this.state.note;
note.dummy = false; note.dummy = false;
@@ -915,6 +889,26 @@ function (_PureCtrl) {
updateClientModified: true updateClientModified: true
}); });
} }
}, {
key: "focusEditor",
value: function focusEditor() {
var element = document.getElementById(ELEMENT_ID_NOTE_TEXT_EDITOR);
if (element) {
this.lastEditorFocusEventSource = _state__WEBPACK_IMPORTED_MODULE_15__["EVENT_SOURCE_SCRIPT"];
element.focus();
}
}
}, {
key: "focusTitle",
value: function focusTitle() {
document.getElementById(ELEMENT_ID_NOTE_TITLE_EDITOR).focus();
}
}, {
key: "clickedTextArea",
value: function clickedTextArea() {
this.setMenuState('showOptionsMenu', false);
}
}, { }, {
key: "onNameFocus", key: "onNameFocus",
value: function onNameFocus() { value: function onNameFocus() {
@@ -923,7 +917,8 @@ function (_PureCtrl) {
}, { }, {
key: "onContentFocus", key: "onContentFocus",
value: function onContentFocus() { value: function onContentFocus() {
this.appState.editorDidFocus(); this.appState.editorDidFocus(this.lastEditorFocusEventSource);
this.lastEditorFocusEventSource = null;
} }
}, { }, {
key: "onNameBlur", key: "onNameBlur",
@@ -1019,8 +1014,6 @@ function (_PureCtrl) {
}, { }, {
key: "performNoteDeletion", key: "performNoteDeletion",
value: function performNoteDeletion(note) { value: function performNoteDeletion(note) {
var _this9 = this;
this.modelManager.setItemToBeDeleted(note); this.modelManager.setItemToBeDeleted(note);
if (note === this.state.note) { if (note === this.state.note) {
@@ -1034,17 +1027,7 @@ function (_PureCtrl) {
return; return;
} }
this.syncManager.sync().then(function () { this.syncManager.sync();
if (_this9.authManager.offline()) {
/**
* When deleting items while ofline, we need
* to explictly tell angular to refresh UI
*/
setTimeout(function () {
this.$rootScope.safeApply();
}, 50);
}
});
} }
}, { }, {
key: "restoreTrashedNote", key: "restoreTrashedNote",
@@ -1069,7 +1052,7 @@ function (_PureCtrl) {
}, { }, {
key: "emptyTrash", key: "emptyTrash",
value: function emptyTrash() { value: function emptyTrash() {
var _this10 = this; var _this9 = this;
var count = this.getTrashCount(); var count = this.getTrashCount();
this.alertManager.confirm({ this.alertManager.confirm({
@@ -1078,9 +1061,9 @@ function (_PureCtrl) {
}), }),
destructive: true, destructive: true,
onConfirm: function onConfirm() { onConfirm: function onConfirm() {
_this10.modelManager.emptyTrash(); _this9.modelManager.emptyTrash();
_this10.syncManager.sync(); _this9.syncManager.sync();
} }
}); });
} }
@@ -1105,7 +1088,7 @@ function (_PureCtrl) {
}, { }, {
key: "toggleProtectNote", key: "toggleProtectNote",
value: function toggleProtectNote() { value: function toggleProtectNote() {
var _this11 = this; var _this10 = this;
this.state.note.content.protected = !this.state.note.content.protected; this.state.note.content.protected = !this.state.note.content.protected;
this.saveNote({ this.saveNote({
@@ -1116,7 +1099,7 @@ function (_PureCtrl) {
this.privilegesManager.actionHasPrivilegesConfigured(_services_privilegesManager__WEBPACK_IMPORTED_MODULE_12__["PrivilegesManager"].ActionViewProtectedNotes).then(function (configured) { this.privilegesManager.actionHasPrivilegesConfigured(_services_privilegesManager__WEBPACK_IMPORTED_MODULE_12__["PrivilegesManager"].ActionViewProtectedNotes).then(function (configured) {
if (!configured) { if (!configured) {
_this11.privilegesManager.presentPrivilegesManagementModal(); _this10.privilegesManager.presentPrivilegesManagementModal();
} }
}); });
} }
@@ -1316,7 +1299,7 @@ function (_PureCtrl) {
}, { }, {
key: "toggleKey", key: "toggleKey",
value: function toggleKey(key) { value: function toggleKey(key) {
var _this12 = this; var _this11 = this;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.async(function toggleKey$(_context3) { return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.async(function toggleKey$(_context3) {
while (1) { while (1) {
@@ -1347,9 +1330,9 @@ function (_PureCtrl) {
case 10: case 10:
if (key === _services_preferencesManager__WEBPACK_IMPORTED_MODULE_17__["PREF_EDITOR_RESIZERS_ENABLED"] && this[key] === true) { if (key === _services_preferencesManager__WEBPACK_IMPORTED_MODULE_17__["PREF_EDITOR_RESIZERS_ENABLED"] && this[key] === true) {
this.$timeout(function () { this.$timeout(function () {
_this12.leftResizeControl.flash(); _this11.leftResizeControl.flash();
_this12.rightResizeControl.flash(); _this11.rightResizeControl.flash();
}); });
} }
@@ -1365,34 +1348,34 @@ function (_PureCtrl) {
}, { }, {
key: "registerComponentHandler", key: "registerComponentHandler",
value: function registerComponentHandler() { value: function registerComponentHandler() {
var _this13 = this; var _this12 = this;
this.componentManager.registerHandler({ this.componentManager.registerHandler({
identifier: 'editor', identifier: 'editor',
areas: ['note-tags', 'editor-stack', 'editor-editor'], areas: ['note-tags', 'editor-stack', 'editor-editor'],
activationHandler: function activationHandler(component) { activationHandler: function activationHandler(component) {
if (component.area === 'note-tags') { if (component.area === 'note-tags') {
_this13.setState({ _this12.setState({
tagsComponent: component.active ? component : null tagsComponent: component.active ? component : null
}); });
} else if (component.area === 'editor-editor') { } else if (component.area === 'editor-editor') {
if (component === _this13.state.selectedEditor && !component.active) { if (component === _this12.state.selectedEditor && !component.active) {
_this13.setState({ _this12.setState({
selectedEditor: null selectedEditor: null
}); });
} else if (_this13.state.selectedEditor) { } else if (_this12.state.selectedEditor) {
if (_this13.state.selectedEditor.active && _this13.state.note) { if (_this12.state.selectedEditor.active && _this12.state.note) {
if (component.isExplicitlyEnabledForItem(_this13.state.note) && !_this13.state.selectedEditor.isExplicitlyEnabledForItem(_this13.state.note)) { if (component.isExplicitlyEnabledForItem(_this12.state.note) && !_this12.state.selectedEditor.isExplicitlyEnabledForItem(_this12.state.note)) {
_this13.setState({ _this12.setState({
selectedEditor: component selectedEditor: component
}); });
} }
} }
} else if (_this13.state.note) { } else if (_this12.state.note) {
var enableable = component.isExplicitlyEnabledForItem(_this13.state.note) || component.isDefaultEditor(); var enableable = component.isExplicitlyEnabledForItem(_this12.state.note) || component.isDefaultEditor();
if (component.active && enableable) { if (component.active && enableable) {
_this13.setState({ _this12.setState({
selectedEditor: component selectedEditor: component
}); });
} else { } else {
@@ -1400,23 +1383,23 @@ function (_PureCtrl) {
* Not a candidate, and no qualified editor. * Not a candidate, and no qualified editor.
* Disable the current editor. * Disable the current editor.
*/ */
_this13.setState({ _this12.setState({
selectedEditor: null selectedEditor: null
}); });
} }
} }
} else if (component.area === 'editor-stack') { } else if (component.area === 'editor-stack') {
_this13.reloadComponentContext(); _this12.reloadComponentContext();
} }
}, },
contextRequestHandler: function contextRequestHandler(component) { contextRequestHandler: function contextRequestHandler(component) {
if (component === _this13.state.selectedEditor || component === _this13.state.tagsComponent || _this13.state.componentStack.includes(component)) { if (component === _this12.state.selectedEditor || component === _this12.state.tagsComponent || _this12.state.componentStack.includes(component)) {
return _this13.state.note; return _this12.state.note;
} }
}, },
focusHandler: function focusHandler(component, focused) { focusHandler: function focusHandler(component, focused) {
if (component.isEditor() && focused) { if (component.isEditor() && focused) {
_this13.closeAllMenus(); _this12.closeAllMenus();
} }
}, },
actionHandler: function actionHandler(component, action, data) { actionHandler: function actionHandler(component, action, data) {
@@ -1435,21 +1418,21 @@ function (_PureCtrl) {
} }
} else if (action === 'associate-item') { } else if (action === 'associate-item') {
if (data.item.content_type === 'Tag') { if (data.item.content_type === 'Tag') {
var tag = _this13.modelManager.findItem(data.item.uuid); var tag = _this12.modelManager.findItem(data.item.uuid);
_this13.addTag(tag); _this12.addTag(tag);
} }
} else if (action === 'deassociate-item') { } else if (action === 'deassociate-item') {
var _tag2 = _this13.modelManager.findItem(data.item.uuid); var _tag2 = _this12.modelManager.findItem(data.item.uuid);
_this13.removeTag(_tag2); _this12.removeTag(_tag2);
} else if (action === 'save-items') { } else if (action === 'save-items') {
var includesNote = data.items.map(function (item) { var includesNote = data.items.map(function (item) {
return item.uuid; return item.uuid;
}).includes(_this13.state.note.uuid); }).includes(_this12.state.note.uuid);
if (includesNote) { if (includesNote) {
_this13.showSavingStatus(); _this12.showSavingStatus();
} }
} }
} }
@@ -1523,10 +1506,10 @@ function (_PureCtrl) {
}, { }, {
key: "disassociateComponentWithCurrentNote", key: "disassociateComponentWithCurrentNote",
value: function disassociateComponentWithCurrentNote(component) { value: function disassociateComponentWithCurrentNote(component) {
var _this14 = this; var _this13 = this;
component.associatedItemIds = component.associatedItemIds.filter(function (id) { component.associatedItemIds = component.associatedItemIds.filter(function (id) {
return id !== _this14.state.note.uuid; return id !== _this13.state.note.uuid;
}); });
if (!component.disassociatedItemIds.includes(this.state.note.uuid)) { if (!component.disassociatedItemIds.includes(this.state.note.uuid)) {
@@ -1539,10 +1522,10 @@ function (_PureCtrl) {
}, { }, {
key: "associateComponentWithCurrentNote", key: "associateComponentWithCurrentNote",
value: function associateComponentWithCurrentNote(component) { value: function associateComponentWithCurrentNote(component) {
var _this15 = this; var _this14 = this;
component.disassociatedItemIds = component.disassociatedItemIds.filter(function (id) { component.disassociatedItemIds = component.disassociatedItemIds.filter(function (id) {
return id !== _this15.state.note.uuid; return id !== _this14.state.note.uuid;
}); });
if (!component.associatedItemIds.includes(this.state.note.uuid)) { if (!component.associatedItemIds.includes(this.state.note.uuid)) {
@@ -1555,17 +1538,17 @@ function (_PureCtrl) {
}, { }, {
key: "registerKeyboardShortcuts", key: "registerKeyboardShortcuts",
value: function registerKeyboardShortcuts() { value: function registerKeyboardShortcuts() {
var _this16 = this; var _this15 = this;
this.altKeyObserver = this.keyboardManager.addKeyObserver({ this.altKeyObserver = this.keyboardManager.addKeyObserver({
modifiers: [_services_keyboardManager__WEBPACK_IMPORTED_MODULE_11__["KeyboardManager"].KeyModifierAlt], modifiers: [_services_keyboardManager__WEBPACK_IMPORTED_MODULE_11__["KeyboardManager"].KeyModifierAlt],
onKeyDown: function onKeyDown() { onKeyDown: function onKeyDown() {
_this16.setState({ _this15.setState({
altKeyDown: true altKeyDown: true
}); });
}, },
onKeyUp: function onKeyUp() { onKeyUp: function onKeyUp() {
_this16.setState({ _this15.setState({
altKeyDown: false altKeyDown: false
}); });
} }
@@ -1575,7 +1558,7 @@ function (_PureCtrl) {
notElementIds: [ELEMENT_ID_NOTE_TEXT_EDITOR, ELEMENT_ID_NOTE_TITLE_EDITOR], notElementIds: [ELEMENT_ID_NOTE_TEXT_EDITOR, ELEMENT_ID_NOTE_TITLE_EDITOR],
modifiers: [_services_keyboardManager__WEBPACK_IMPORTED_MODULE_11__["KeyboardManager"].KeyModifierMeta], modifiers: [_services_keyboardManager__WEBPACK_IMPORTED_MODULE_11__["KeyboardManager"].KeyModifierMeta],
onKeyDown: function onKeyDown() { onKeyDown: function onKeyDown() {
_this16.deleteNote(); _this15.deleteNote();
} }
}); });
this.deleteKeyObserver = this.keyboardManager.addKeyObserver({ this.deleteKeyObserver = this.keyboardManager.addKeyObserver({
@@ -1584,14 +1567,14 @@ function (_PureCtrl) {
onKeyDown: function onKeyDown(event) { onKeyDown: function onKeyDown(event) {
event.preventDefault(); event.preventDefault();
_this16.deleteNote(true); _this15.deleteNote(true);
} }
}); });
} }
}, { }, {
key: "onSystemEditorLoad", key: "onSystemEditorLoad",
value: function onSystemEditorLoad() { value: function onSystemEditorLoad() {
var _this17 = this; var _this16 = this;
if (this.loadedTabListener) { if (this.loadedTabListener) {
return; return;
@@ -1610,7 +1593,7 @@ function (_PureCtrl) {
element: editor, element: editor,
key: _services_keyboardManager__WEBPACK_IMPORTED_MODULE_11__["KeyboardManager"].KeyTab, key: _services_keyboardManager__WEBPACK_IMPORTED_MODULE_11__["KeyboardManager"].KeyTab,
onKeyDown: function onKeyDown(event) { onKeyDown: function onKeyDown(event) {
if (_this17.state.note.locked || event.shiftKey) { if (_this16.state.note.locked || event.shiftKey) {
return; return;
} }
@@ -1632,14 +1615,14 @@ function (_PureCtrl) {
editor.selectionStart = editor.selectionEnd = start + 4; editor.selectionStart = editor.selectionEnd = start + 4;
} }
var note = _this17.state.note; var note = _this16.state.note;
note.text = editor.value; note.text = editor.value;
_this17.setState({ _this16.setState({
note: note note: note
}); });
_this17.saveNote({ _this16.saveNote({
bypassDebouncer: true bypassDebouncer: true
}); });
} }
@@ -1650,10 +1633,10 @@ function (_PureCtrl) {
*/ */
angular__WEBPACK_IMPORTED_MODULE_8___default.a.element(editor).on('$destroy', function () { angular__WEBPACK_IMPORTED_MODULE_8___default.a.element(editor).on('$destroy', function () {
if (_this17.tabObserver) { if (_this16.tabObserver) {
_this17.keyboardManager.removeKeyObserver(_this17.tabObserver); _this16.keyboardManager.removeKeyObserver(_this16.tabObserver);
_this17.loadedTabListener = false; _this16.loadedTabListener = false;
} }
}); });
} }
@@ -1785,9 +1768,11 @@ function () {
this.appState.addObserver(function (eventName, data) { this.appState.addObserver(function (eventName, data) {
if (eventName === _state__WEBPACK_IMPORTED_MODULE_7__["APP_STATE_EVENT_EDITOR_FOCUSED"]) { if (eventName === _state__WEBPACK_IMPORTED_MODULE_7__["APP_STATE_EVENT_EDITOR_FOCUSED"]) {
_this3.closeAllRooms(); if (data.eventSource === _state__WEBPACK_IMPORTED_MODULE_7__["EVENT_SOURCE_USER_INTERACTION"]) {
_this3.closeAllRooms();
_this3.closeAccountMenu(); _this3.closeAccountMenu();
}
} else if (eventName === _state__WEBPACK_IMPORTED_MODULE_7__["APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD"]) { } else if (eventName === _state__WEBPACK_IMPORTED_MODULE_7__["APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD"]) {
_this3.backupStatus = _this3.statusManager.addStatusFromString("Saving local backup..."); _this3.backupStatus = _this3.statusManager.addStatusFromString("Saving local backup...");
} else if (eventName === _state__WEBPACK_IMPORTED_MODULE_7__["APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD"]) { } else if (eventName === _state__WEBPACK_IMPORTED_MODULE_7__["APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD"]) {
@@ -3671,10 +3656,6 @@ function () {
value: function defineRootScopeFunctions() { value: function defineRootScopeFunctions() {
var _this = this; var _this = this;
this.$rootScope.sync = function () {
_this.syncManager.sync();
};
this.$rootScope.lockApplication = function () { this.$rootScope.lockApplication = function () {
/** Reloading wipes current objects from memory */ /** Reloading wipes current objects from memory */
window.location.reload(); window.location.reload();
@@ -3949,19 +3930,23 @@ function () {
var _this10 = this; var _this10 = this;
/** /**
* Disable dragging and dropping of files into main SN interface. * Disable dragging and dropping of files (but allow text) into main SN interface.
* both 'dragover' and 'drop' are required to prevent dropping of files. * both 'dragover' and 'drop' are required to prevent dropping of files.
* This will not prevent extensions from receiving drop events. * This will not prevent extensions from receiving drop events.
*/ */
window.addEventListener('dragover', function (event) { window.addEventListener('dragover', function (event) {
event.preventDefault(); if (event.dataTransfer.files.length > 0) {
event.preventDefault();
}
}, false); }, false);
window.addEventListener('drop', function (event) { window.addEventListener('drop', function (event) {
event.preventDefault(); if (event.dataTransfer.files.length > 0) {
event.preventDefault();
_this10.alertManager.alert({ _this10.alertManager.alert({
text: _strings__WEBPACK_IMPORTED_MODULE_9__["STRING_DEFAULT_FILE_ERROR"] text: _strings__WEBPACK_IMPORTED_MODULE_9__["STRING_DEFAULT_FILE_ERROR"]
}); });
}
}, false); }, false);
} }
}, { }, {
@@ -4382,7 +4367,7 @@ function (_PureCtrl) {
}, { }, {
key: "saveTag", key: "saveTag",
value: function saveTag($event, tag) { value: function saveTag($event, tag) {
var matchingTag; var matchingTag, alreadyExists;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.async(function saveTag$(_context3) { return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.async(function saveTag$(_context3) {
while (1) { while (1) {
switch (_context3.prev = _context3.next) { switch (_context3.prev = _context3.next) {
@@ -4417,9 +4402,10 @@ function (_PureCtrl) {
case 7: case 7:
this.editingOriginalName = null; this.editingOriginalName = null;
matchingTag = this.modelManager.findTag(tag.title); matchingTag = this.modelManager.findTag(tag.title);
alreadyExists = matchingTag && matchingTag !== tag;
if (!(this.state.newTag === tag && matchingTag)) { if (!(this.state.newTag === tag && alreadyExists)) {
_context3.next = 14; _context3.next = 15;
break; break;
} }
@@ -4432,7 +4418,7 @@ function (_PureCtrl) {
}); });
return _context3.abrupt("return"); return _context3.abrupt("return");
case 14: case 15:
this.modelManager.setItemDirty(tag); this.modelManager.setItemDirty(tag);
this.syncManager.sync(); this.syncManager.sync();
this.modelManager.resortTag(tag); this.modelManager.resortTag(tag);
@@ -4441,7 +4427,7 @@ function (_PureCtrl) {
newTag: null newTag: null
}); });
case 19: case 20:
case "end": case "end":
return _context3.stop(); return _context3.stop();
} }
@@ -4488,9 +4474,7 @@ function (_PureCtrl) {
onConfirm: function onConfirm() { onConfirm: function onConfirm() {
_this7.modelManager.setItemToBeDeleted(tag); _this7.modelManager.setItemToBeDeleted(tag);
_this7.syncManager.sync().then(function () { _this7.syncManager.sync();
_this7.$rootScope.safeApply();
});
} }
}); });
} }
@@ -13419,7 +13403,7 @@ function () {
} else { } else {
// tab visibility listener, web only // tab visibility listener, web only
document.addEventListener('visibilitychange', function (e) { document.addEventListener('visibilitychange', function (e) {
var visible = document.visibilityState == "visible"; var visible = document.visibilityState === "visible";
_this4.documentVisibilityChanged(visible); _this4.documentVisibilityChanged(visible);
}); // verify document is in focus every so often as visibilitychange event is not triggered }); // verify document is in focus every so often as visibilitychange event is not triggered
@@ -13428,9 +13412,9 @@ function () {
this.pollFocusTimeout = setInterval(function () { this.pollFocusTimeout = setInterval(function () {
var hasFocus = document.hasFocus(); var hasFocus = document.hasFocus();
if (hasFocus && _this4.lastFocusState == "hidden") { if (hasFocus && _this4.lastFocusState === "hidden") {
_this4.documentVisibilityChanged(true); _this4.documentVisibilityChanged(true);
} else if (!hasFocus && _this4.lastFocusState == "visible") { } else if (!hasFocus && _this4.lastFocusState === "visible") {
_this4.documentVisibilityChanged(false); _this4.documentVisibilityChanged(false);
} // save this to compare against next time around } // save this to compare against next time around
@@ -15042,7 +15026,7 @@ function () {
/*!*****************************************!*\ /*!*****************************************!*\
!*** ./app/assets/javascripts/state.js ***! !*** ./app/assets/javascripts/state.js ***!
\*****************************************/ \*****************************************/
/*! exports provided: APP_STATE_EVENT_TAG_CHANGED, APP_STATE_EVENT_NOTE_CHANGED, APP_STATE_EVENT_PREFERENCES_CHANGED, APP_STATE_EVENT_PANEL_RESIZED, APP_STATE_EVENT_EDITOR_FOCUSED, APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD, APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD, APP_STATE_EVENT_DESKTOP_EXTS_READY, AppState */ /*! exports provided: APP_STATE_EVENT_TAG_CHANGED, APP_STATE_EVENT_NOTE_CHANGED, APP_STATE_EVENT_PREFERENCES_CHANGED, APP_STATE_EVENT_PANEL_RESIZED, APP_STATE_EVENT_EDITOR_FOCUSED, APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD, APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD, APP_STATE_EVENT_DESKTOP_EXTS_READY, EVENT_SOURCE_USER_INTERACTION, EVENT_SOURCE_SCRIPT, AppState */
/***/ (function(module, __webpack_exports__, __webpack_require__) { /***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict"; "use strict";
@@ -15055,6 +15039,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD", function() { return APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD", function() { return APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD", function() { return APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD", function() { return APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "APP_STATE_EVENT_DESKTOP_EXTS_READY", function() { return APP_STATE_EVENT_DESKTOP_EXTS_READY; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "APP_STATE_EVENT_DESKTOP_EXTS_READY", function() { return APP_STATE_EVENT_DESKTOP_EXTS_READY; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EVENT_SOURCE_USER_INTERACTION", function() { return EVENT_SOURCE_USER_INTERACTION; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EVENT_SOURCE_SCRIPT", function() { return EVENT_SOURCE_SCRIPT; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AppState", function() { return AppState; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AppState", function() { return AppState; });
/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js");
/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__);
@@ -15075,6 +15061,8 @@ var APP_STATE_EVENT_EDITOR_FOCUSED = 5;
var APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD = 6; var APP_STATE_EVENT_BEGAN_BACKUP_DOWNLOAD = 6;
var APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD = 7; var APP_STATE_EVENT_ENDED_BACKUP_DOWNLOAD = 7;
var APP_STATE_EVENT_DESKTOP_EXTS_READY = 8; var APP_STATE_EVENT_DESKTOP_EXTS_READY = 8;
var EVENT_SOURCE_USER_INTERACTION = 1;
var EVENT_SOURCE_SCRIPT = 2;
var AppState = var AppState =
/*#__PURE__*/ /*#__PURE__*/
function () { function () {
@@ -15291,8 +15279,10 @@ function () {
} }
}, { }, {
key: "editorDidFocus", key: "editorDidFocus",
value: function editorDidFocus() { value: function editorDidFocus(eventSource) {
this.notifyEvent(APP_STATE_EVENT_EDITOR_FOCUSED); this.notifyEvent(APP_STATE_EVENT_EDITOR_FOCUSED, {
eventSource: eventSource
});
} }
}, { }, {
key: "beganBackupDownload", key: "beganBackupDownload",

File diff suppressed because one or more lines are too long