diff --git a/.babelrc b/.babelrc index 692a17bc5..a09963d4e 100644 --- a/.babelrc +++ b/.babelrc @@ -1,15 +1,9 @@ { "presets": [ "@babel/typescript", - [ - "@babel/preset-env", - { - "targets": "> 0.25%, not dead" - } - ] + "@babel/preset-env" ], "plugins": [ - "@babel/plugin-transform-runtime", "@babel/plugin-proposal-class-properties", "angularjs-annotate" ] diff --git a/.browserslistrc b/.browserslistrc new file mode 100644 index 000000000..b9145d54f --- /dev/null +++ b/.browserslistrc @@ -0,0 +1,6 @@ +chrome 80 # electron 8.2 +last 2 Firefox versions +last 2 Edge versions +last 2 Safari versions +last 2 Opera versions +Firefox ESR diff --git a/app/assets/javascripts/app.ts b/app/assets/javascripts/app.ts index a86f6d31a..64fb23e63 100644 --- a/app/assets/javascripts/app.ts +++ b/app/assets/javascripts/app.ts @@ -49,6 +49,7 @@ import { } from './directives/views'; import { trusted } from './filters'; +import { isDev } from './utils'; angular.module('app', ['ngSanitize']); @@ -109,3 +110,14 @@ angular // Services angular.module('app').service('mainApplicationGroup', ApplicationGroup); + +// Debug +if (isDev) { + Object.defineProperties(window, { + application: { + get: () => + (angular.element(document).injector().get('mainApplicationGroup') as any) + .application, + }, + }); +} diff --git a/app/assets/javascripts/ui_models/editor.ts b/app/assets/javascripts/ui_models/editor.ts index f368618e8..56b68685c 100644 --- a/app/assets/javascripts/ui_models/editor.ts +++ b/app/assets/javascripts/ui_models/editor.ts @@ -82,6 +82,10 @@ export class Editor { } } + public clearNoteChangeListener() { + this._onNoteChange = undefined; + } + /** * Register to be notified when the editor's note's values change * (and thus a new object reference is created) diff --git a/app/assets/javascripts/utils.ts b/app/assets/javascripts/utils.ts index 73562c79e..e95cd83cb 100644 --- a/app/assets/javascripts/utils.ts +++ b/app/assets/javascripts/utils.ts @@ -1,3 +1,5 @@ +export const isDev = process.env.NODE_ENV === 'development'; + export function getParameterByName(name: string, url: string) { name = name.replace(/[[\]]/g, '\\$&'); var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'); diff --git a/app/assets/javascripts/views/abstract/pure_view_ctrl.ts b/app/assets/javascripts/views/abstract/pure_view_ctrl.ts index 086a52709..4b1978dd5 100644 --- a/app/assets/javascripts/views/abstract/pure_view_ctrl.ts +++ b/app/assets/javascripts/views/abstract/pure_view_ctrl.ts @@ -17,13 +17,13 @@ export class PureViewCtrl { /* @ngInject */ constructor($timeout: ng.ITimeoutService) { this.$timeout = $timeout; - /* Allow caller constructor to finish setting instance variables */ - setImmediate(() => { - this.state = this.getInitialState(); - }); } $onInit() { + this.state = { + ...this.getInitialState(), + ...this.state, + } this.addAppEventObserver(); this.addAppStateObserver(); } @@ -33,7 +33,6 @@ export class PureViewCtrl { this.unsubState(); this.unsubApp = undefined; this.unsubState = undefined; - (this.application as any) = undefined; if (this.stateTimeout) { this.$timeout.cancel(this.stateTimeout); } @@ -141,4 +140,4 @@ export class PureViewCtrl { /** Optional override */ } -} \ No newline at end of file +} diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 5dc9cdd6d..8d8f21324 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -144,6 +144,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { } deinit() { + this.editor.clearNoteChangeListener(); this.removeTagsObserver(); this.removeComponentsObserver(); (this.removeTagsObserver as any) = undefined; diff --git a/package-lock.json b/package-lock.json index 31c8f9b93..4f2129240 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1285,18 +1285,6 @@ "@babel/helper-plugin-utils": "^7.8.3" } }, - "@babel/plugin-transform-runtime": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.8.3.tgz", - "integrity": "sha512-/vqUt5Yh+cgPZXXjmaG9NT8aVfThKk7G4OqkVhrXqwsC5soMn/qTCxs36rZ2QFhpfTJcjw4SNDIZ4RUb8OL4jQ==", - "dev": true, - "requires": { - "@babel/helper-module-imports": "^7.8.3", - "@babel/helper-plugin-utils": "^7.8.3", - "resolve": "^1.8.1", - "semver": "^5.5.1" - } - }, "@babel/plugin-transform-shorthand-properties": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.8.3.tgz", @@ -11415,6 +11403,15 @@ "uuid": "^3.3.2" } }, + "webpack-merge": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-4.2.2.tgz", + "integrity": "sha512-TUE1UGoTX2Cd42j3krGYqObZbOD+xF7u28WB7tfUordytSjbWTIjK/8V0amkBfTYN4/pB/GIDlJZZ657BGG19g==", + "dev": true, + "requires": { + "lodash": "^4.17.15" + } + }, "webpack-sources": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", diff --git a/package.json b/package.json index 64207ec14..98665beca 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,11 @@ "url": "https://github.com/standardnotes/web" }, "scripts": { - "start": "webpack-dev-server --progress", - "watch": "webpack --mode development -w", - "bundle": "webpack --mode production", + "start": "webpack-dev-server --progress --config webpack.dev.js", + "watch": "webpack -w --config webpack.dev.js", + "bundle": "webpack --config webpack.prod.js", "build": "bundle install && npm install && npm run bundle", "submodules": "git submodule update --init --force --remote", - "test": "karma start karma.conf.js --single-run", "lint": "eslint --fix app/assets/javascripts/**/*.js", "tsc": "tsc --project app/assets/javascripts/tsconfig.json" }, @@ -20,10 +19,8 @@ "@babel/cli": "^7.8.4", "@babel/core": "^7.8.7", "@babel/plugin-proposal-class-properties": "^7.8.3", - "@babel/plugin-transform-runtime": "^7.8.3", "@babel/preset-env": "^7.8.7", "@babel/preset-typescript": "^7.8.3", - "@babel/runtime": "^7.8.7", "@types/angular": "^1.7.0", "@types/chai": "^4.2.11", "@types/lodash": "^4.14.149", @@ -50,6 +47,7 @@ "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", "file-loader": "^5.1.0", + "lodash": "^4.17.15", "mini-css-extract-plugin": "^0.9.0", "mocha": "^7.1.0", "ng-cache-loader": "0.0.26", @@ -58,15 +56,15 @@ "pug-loader": "^2.4.0", "sass-loader": "^8.0.2", "serve-static": "^1.14.1", - "snjs": "github:standardnotes/snjs#0c306de70c5afffe16096424c6c3326eaa1dd4fd", "sn-stylekit": "2.0.22", + "snjs": "github:standardnotes/snjs#0c306de70c5afffe16096424c6c3326eaa1dd4fd", "ts-loader": "^6.2.2", "typescript": "^3.8.3", "typescript-eslint": "0.0.1-alpha.0", "webpack": "^4.42.0", "webpack-cli": "^3.3.11", "webpack-dev-server": "^3.10.3", - "lodash": "^4.17.15" + "webpack-merge": "^4.2.2" }, "dependencies": { "sncrypto": "github:standardnotes/sncrypto#7e76ab9977f85039d9399b935aecfe495a951edb" diff --git a/webpack.config.js b/webpack.config.js index 25a14bcbd..966ecb838 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,20 +2,12 @@ const path = require('path'); const webpack = require('webpack'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CopyPlugin = require('copy-webpack-plugin'); + module.exports = { entry: './app/assets/javascripts/index.ts', output: { filename: './javascripts/app.js' }, - devServer: { - proxy: { - '/extensions': { - target: 'http://localhost:3001', - pathRewrite: { '^/extensions': '/public/extensions' } - } - }, - port: 3001 - }, plugins: [ new webpack.DefinePlugin({ __VERSION__: JSON.stringify(require('./package.json').version) @@ -27,10 +19,9 @@ module.exports = { new MiniCssExtractPlugin({ // Options similar to the same options in webpackOptions.output filename: './stylesheets/app.css', - ignoreOrder: false // Enable to remove warnings about conflicting order + ignoreOrder: true // Enable to remove warnings about conflicting order }) ], - devtool: 'source-map', resolve: { extensions: ['.ts', '.js'], alias: { @@ -46,7 +37,7 @@ module.exports = { rules: [ { test: /\.(js|ts)$/, - exclude: /node_modules/, + exclude: /(node_modules|snjs)/, use: { loader: 'babel-loader' } diff --git a/webpack.dev.js b/webpack.dev.js new file mode 100644 index 000000000..d43339d5f --- /dev/null +++ b/webpack.dev.js @@ -0,0 +1,19 @@ +const merge = require('webpack-merge'); +const config = require('./webpack.config.js'); + +module.exports = (_env, argv) => { + const port = argv.port || 3001; + return merge(config, { + mode: 'development', + devServer: { + publicPath: '/dist/', + proxy: { + '/extensions': { + target: `http://localhost:${port}`, + pathRewrite: { '^/extensions': '/public/extensions' } + } + }, + port, + } + }); +}; diff --git a/webpack.prod.js b/webpack.prod.js new file mode 100644 index 000000000..4cfcb6189 --- /dev/null +++ b/webpack.prod.js @@ -0,0 +1,7 @@ +const merge = require('webpack-merge'); +const config = require('./webpack.config.js'); + +module.exports = merge(config, { + mode: 'production', + devtool: 'source-map', +});