From 5ec8aaa31d0bf832a4359f232be0e3b5dc657b3f Mon Sep 17 00:00:00 2001 From: Christian Authmann <8371862+cauthmann@users.noreply.github.com> Date: Mon, 20 Dec 2021 07:37:19 +0100 Subject: [PATCH] Rework wasm initialization and reduce global state (#379) * wasm: do the async initialization only once This allows the rest of the app to access wasm synchronously. This allows removing of a global. * provide the wasm via vue provide/inject. There's still code directly accessing the wasm. That will be changed later. * MenuBarInput: use injected wasm instead of the global instance * Let the App handle event listeners * move stateful modules into state/ * state/fullscreen: create per instance * App: load the initial document list on mount. This got lost a few commits ago. Now it's back. * state/dialog: create per instance * util/input: remove dependency on global dialog instance * state/documents: create per instance * reponse-handler: move into EditorWasm * comingSoon: move into dialog * wasm: allow instantiating multiple editors * input handlers: do not look at canvases outside the mounted App * input: listen on the container instead of the window when possible * - removed proxy from wasm-loader - integrated with js-dispatcher - state functions to classes - integrated some upstream changes * fix errors caused by merge * Getting closer: - added global state to track all instances - fix fullscreen close trigger - wasm-loader is statefull - panic across instanes * - fix outline while using editor - removed circular import rule - added editorInstance to js message constructor * - changed input handler to a class - still need a better way of handeling it in App.vue * - fixed single instance of inputManager to weakmap * - fix no-explicit-any in a few places - removed global state from input.ts * simplified two long lines * removed global state * removed $data from App * add mut self to functions in api.rs * Update Workspace.vue remove outdated import * fixed missing import * Changes throughout code review; note this causes some bugs to be fixed in a later commit * PR review round 1 * - fix coming soon bugs - changed folder structure * moved declaration to .d.ts * - changed from classes to functions - moved decs back to app.vue * removed need to export js function to rust * changed folder structure * fixed indentation breaking multiline strings * Fix eslint rule to whitelist @/../ * Simplify strip-indents implementation * replace type assertions with better annotations or proper runtime checks * Small tweaks and code rearranging improvements after second code review pass * maybe fix mouse events * Add back preventDefault for mouse scroll * code review round 2 * Comment improvements * -removed runtime checks - fixed layers not showing * - extened proxy to cover classes - stopped multiple panics from logging - Stop wasm-bindgen from mut ref counting our struct * cleaned up messageConstructors exports * Fix input and fullscreen regressions Co-authored-by: Max Fisher Co-authored-by: mfish33 <32677537+mfish33@users.noreply.github.com> Co-authored-by: Keavon Chambers --- Cargo.lock | 1 + editor/src/document/layer_panel.rs | 4 +- frontend/.eslintrc.js | 1 + frontend/public/index.html | 3 +- frontend/src/App.vue | 56 +- frontend/src/TwoViewTest.vue | 20 + frontend/src/components/panels/Document.vue | 125 ++- frontend/src/components/panels/LayerTree.vue | 23 +- .../widgets/floating-menus/DialogModal.vue | 16 +- .../widgets/floating-menus/MenuList.vue | 5 +- .../widgets/inputs/MenuBarInput.vue | 199 +++-- .../widgets/inputs/SwatchPairInput.vue | 13 +- .../widgets/options/ToolOptions.vue | 22 +- .../components/window/title-bar/TitleBar.vue | 7 +- .../window/title-bar/WindowButtonsWeb.vue | 14 +- frontend/src/components/workspace/Panel.vue | 11 +- .../src/components/workspace/Workspace.vue | 11 +- frontend/src/dispatcher/js-dispatcher.ts | 58 ++ .../{utilities => dispatcher}/js-messages.ts | 51 +- frontend/src/lifetime/errors.ts | 140 +++ frontend/src/lifetime/input.ts | 178 ++++ frontend/src/main.ts | 33 +- frontend/src/state/dialog.ts | 118 +++ frontend/src/state/documents.ts | 136 +++ frontend/src/state/fullscreen.ts | 47 + frontend/src/state/wasm-loader.ts | 76 ++ frontend/src/utilities/dialog.ts | 37 - frontend/src/utilities/dialogs.ts | 49 -- frontend/src/utilities/documents.ts | 127 --- frontend/src/utilities/errors.ts | 157 ---- frontend/src/utilities/fullscreen.ts | 37 - frontend/src/utilities/input.ts | 145 --- .../js-message-dispatcher-binding.ts | 4 - .../src/utilities/js-message-dispatcher.ts | 95 -- frontend/src/utilities/panic-proxy.ts | 32 - frontend/src/utilities/strip-indents.ts | 12 + frontend/wasm/Cargo.toml | 1 + frontend/wasm/src/api.rs | 823 +++++++++--------- frontend/wasm/src/lib.rs | 49 +- 39 files changed, 1524 insertions(+), 1412 deletions(-) create mode 100644 frontend/src/TwoViewTest.vue create mode 100644 frontend/src/dispatcher/js-dispatcher.ts rename frontend/src/{utilities => dispatcher}/js-messages.ts (79%) create mode 100644 frontend/src/lifetime/errors.ts create mode 100644 frontend/src/lifetime/input.ts create mode 100644 frontend/src/state/dialog.ts create mode 100644 frontend/src/state/documents.ts create mode 100644 frontend/src/state/fullscreen.ts create mode 100644 frontend/src/state/wasm-loader.ts delete mode 100644 frontend/src/utilities/dialog.ts delete mode 100644 frontend/src/utilities/dialogs.ts delete mode 100644 frontend/src/utilities/documents.ts delete mode 100644 frontend/src/utilities/errors.ts delete mode 100644 frontend/src/utilities/fullscreen.ts delete mode 100644 frontend/src/utilities/input.ts delete mode 100644 frontend/src/utilities/js-message-dispatcher-binding.ts delete mode 100644 frontend/src/utilities/js-message-dispatcher.ts delete mode 100644 frontend/src/utilities/panic-proxy.ts create mode 100644 frontend/src/utilities/strip-indents.ts diff --git a/Cargo.lock b/Cargo.lock index 5843d923..82f2eb93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,6 +126,7 @@ version = "0.1.0" dependencies = [ "graphite-editor", "graphite-graphene", + "js-sys", "log", "serde", "wasm-bindgen", diff --git a/editor/src/document/layer_panel.rs b/editor/src/document/layer_panel.rs index ad1e5693..b4300713 100644 --- a/editor/src/document/layer_panel.rs +++ b/editor/src/document/layer_panel.rs @@ -141,8 +141,8 @@ impl Serialize for RawBuffer { S: serde::Serializer, { let mut buffer = serializer.serialize_struct("Buffer", 2)?; - buffer.serialize_field("ptr", &(self.0.as_ptr() as usize))?; - buffer.serialize_field("len", &(self.0.len()))?; + buffer.serialize_field("pointer", &(self.0.as_ptr() as usize))?; + buffer.serialize_field("length", &(self.0.len()))?; buffer.end() } } diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index dbba170e..12285f52 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -65,6 +65,7 @@ module.exports = { "no-bitwise": "off", "no-shadow": "off", "no-use-before-define": "off", + "no-restricted-imports": ["error", { patterns: [".*", "!@/*"] }], // TypeScript plugin config "@typescript-eslint/indent": ["error", "tab", { SwitchCase: 1 }], diff --git a/frontend/public/index.html b/frontend/public/index.html index 070dff8f..2b1e8eb7 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -17,7 +17,8 @@ -
+ +
diff --git a/frontend/src/App.vue b/frontend/src/App.vue index fd8aa014..ffeafc50 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -71,6 +71,7 @@ body, background: var(--color-2-mildblack); user-select: none; overscroll-behavior: none; + outline: none; } html, @@ -220,23 +221,52 @@ img { diff --git a/frontend/src/TwoViewTest.vue b/frontend/src/TwoViewTest.vue new file mode 100644 index 00000000..9c3a0659 --- /dev/null +++ b/frontend/src/TwoViewTest.vue @@ -0,0 +1,20 @@ + + + diff --git a/frontend/src/components/panels/Document.vue b/frontend/src/components/panels/Document.vue index 68a4d17f..97444b89 100644 --- a/frontend/src/components/panels/Document.vue +++ b/frontend/src/components/panels/Document.vue @@ -18,7 +18,7 @@ - +

Grid

The contents of this popover menu are coming soon

@@ -26,7 +26,7 @@ - +

Overlays

The contents of this popover menu are coming soon

@@ -70,31 +70,31 @@
- - + + - + - + - - - - - - + + + + + + - - + + @@ -238,11 +238,8 @@