From 366a697b3a85a135dcea15a5f9dce6918812790a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 3 Apr 2022 23:37:35 +1000 Subject: [PATCH] Add a runtime proof of concept The API extractor integration isn't set up properly yet, so I had to manually generate the d.ts bundle and copy it into the add-on: cd ts/runtime bazel run extract_api cp ../../.bazel/bin/ts/runtime/extract_api.sh.runfiles/ankidesktop/ts/runtime/dist/anki.d.ts \ $c/anki_new_format_pack/ts/anki-dts/runtime.d.ts --- ts/editor/BUILD.bazel | 4 + ts/editor/NoteEditor.svelte | 15 +- ts/editor/index_browser.ts | 5 + ts/editor/index_creator.ts | 5 + ts/editor/index_reviewer.ts | 5 + ts/lib/runtime-require.ts | 1 + ts/runtime/BUILD.bazel | 42 ++++ ts/runtime/api-extractor.json | 364 ++++++++++++++++++++++++++++++++++ ts/runtime/index.ts | 31 +++ ts/runtime/tsconfig.json | 5 + 10 files changed, 473 insertions(+), 4 deletions(-) create mode 100644 ts/runtime/BUILD.bazel create mode 100644 ts/runtime/api-extractor.json create mode 100644 ts/runtime/index.ts create mode 100644 ts/runtime/tsconfig.json diff --git a/ts/editor/BUILD.bazel b/ts/editor/BUILD.bazel index ca17ca28c..833996e2b 100644 --- a/ts/editor/BUILD.bazel +++ b/ts/editor/BUILD.bazel @@ -49,12 +49,14 @@ _esbuild_deps = [ "@npm//bootstrap-icons", "//ts/icons", "@npm//protobufjs", + "//ts/runtime", ] esbuild( name = "browser_editor", args = { "loader": {".svg": "text"}, + "external": ["anki"], }, entry_point = "index_browser.ts", output_css = "browser_editor.css", @@ -66,6 +68,7 @@ esbuild( name = "reviewer_editor", args = { "loader": {".svg": "text"}, + "external": ["anki"], }, entry_point = "index_reviewer.ts", output_css = "reviewer_editor.css", @@ -77,6 +80,7 @@ esbuild( name = "note_creator", args = { "loader": {".svg": "text"}, + "external": ["anki"], }, entry_point = "index_creator.ts", output_css = "note_creator.css", diff --git a/ts/editor/NoteEditor.svelte b/ts/editor/NoteEditor.svelte index 957b07616..9f5672910 100644 --- a/ts/editor/NoteEditor.svelte +++ b/ts/editor/NoteEditor.svelte @@ -17,8 +17,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } import { registerPackage } from "../lib/runtime-require"; - import contextProperty from "../sveltelib/context-property"; - import lifecycleHooks from "../sveltelib/lifecycle-hooks"; + import contextProperty, { ContextProperty } from "../sveltelib/context-property"; + import lifecycleHooks, { LifecycleHooks } from "../sveltelib/lifecycle-hooks"; const key = Symbol("noteEditor"); const [context, setContextProperty] = contextProperty(key); @@ -26,11 +26,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export { context }; - registerPackage("anki/NoteEditor", { + /** anki/NoteEditor */ + export interface NoteEditorPackage { + context: ContextProperty; + lifecycle: LifecycleHooks; + instances: NoteEditorAPI[]; + } + export const noteEditorPackage: NoteEditorPackage = { context, lifecycle, instances, - }); + }; + registerPackage("anki/NoteEditor", noteEditorPackage as any);