From 2ab06a654048214a90926c1e6eec2707b80adbf3 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sun, 31 Jan 2021 14:15:03 +0100 Subject: [PATCH] Move editor to /ts/editor --- qt/aqt/data/web/js/BUILD.bazel | 20 ++------ qt/aqt/data/web/js/editor/BUILD.bazel | 16 ------ ts/BUILD.bazel | 2 +- ts/editor/BUILD.bazel | 49 +++++++++++++++++++ .../data/web/js => ts}/editor/filterHtml.ts | 0 {qt/aqt/data/web/js => ts}/editor/helpers.ts | 0 {qt/aqt/data/web/js => ts}/editor/index.ts | 11 +++-- ts/editor/lib.ts | 9 ++++ .../rollup.aqt.config.js | 0 9 files changed, 71 insertions(+), 36 deletions(-) delete mode 100644 qt/aqt/data/web/js/editor/BUILD.bazel create mode 100644 ts/editor/BUILD.bazel rename {qt/aqt/data/web/js => ts}/editor/filterHtml.ts (100%) rename {qt/aqt/data/web/js => ts}/editor/helpers.ts (100%) rename {qt/aqt/data/web/js => ts}/editor/index.ts (98%) create mode 100644 ts/editor/lib.ts rename qt/aqt/data/web/js/rollup.config.js => ts/rollup.aqt.config.js (100%) diff --git a/qt/aqt/data/web/js/BUILD.bazel b/qt/aqt/data/web/js/BUILD.bazel index 24800474f..417c1a9bb 100644 --- a/qt/aqt/data/web/js/BUILD.bazel +++ b/qt/aqt/data/web/js/BUILD.bazel @@ -1,5 +1,6 @@ load("@npm//@bazel/typescript:index.bzl", "ts_library") load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") +load("//qt/aqt/data/web/pages:defs.bzl", "copy_page") load("//ts:prettier.bzl", "prettier_test") load("//ts:eslint.bzl", "eslint_test") @@ -29,25 +30,14 @@ filegroup( output_group = "es5_sources", ) -###### aqt bundles - -rollup_bundle( +copy_page( name = "editor", - config_file = "rollup.config.js", - entry_point = "//qt/aqt/data/web/js/editor:index.ts", - format = "iife", - link_workspace_root = True, - silent = True, - sourcemap = "false", - deps = [ - "//qt/aqt/data/web/js/editor", - "@npm//@rollup/plugin-commonjs", - "@npm//@rollup/plugin-node-resolve", - "@npm//rollup-plugin-terser", + srcs = [ + "editor.js", ], + package = "//ts/editor", ) - filegroup( name = "js", srcs = [ diff --git a/qt/aqt/data/web/js/editor/BUILD.bazel b/qt/aqt/data/web/js/editor/BUILD.bazel deleted file mode 100644 index 853ea8471..000000000 --- a/qt/aqt/data/web/js/editor/BUILD.bazel +++ /dev/null @@ -1,16 +0,0 @@ -load("@npm//@bazel/typescript:index.bzl", "ts_library") - -ts_library( - name = "editor", - srcs = glob(["*.ts"]), - tsconfig = "//qt/aqt/data/web/js:tsconfig.json", - deps = [ - "//qt/aqt/data/web/js:pycmd", - "@npm//@types/jquery", - ], - visibility = ["//qt:__subpackages__"], -) - -exports_files([ - "index.ts", -]) diff --git a/ts/BUILD.bazel b/ts/BUILD.bazel index 53b97d3cd..a64f51265 100644 --- a/ts/BUILD.bazel +++ b/ts/BUILD.bazel @@ -18,9 +18,9 @@ sql_format_setup() exports_files([ "tsconfig.json", - "d3_missing.d.ts", ".prettierrc", "rollup.config.js", + "rollup.aqt.config.js", ".eslintrc.js", "licenses.json", "sql_format.ts", diff --git a/ts/editor/BUILD.bazel b/ts/editor/BUILD.bazel new file mode 100644 index 000000000..30be758e3 --- /dev/null +++ b/ts/editor/BUILD.bazel @@ -0,0 +1,49 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_library") +load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") +load("//ts:prettier.bzl", "prettier_test") +load("//ts:eslint.bzl", "eslint_test") + +ts_library( + name = "editor_ts", + srcs = glob(["*.ts"]), + tsconfig = "//qt/aqt/data/web/js:tsconfig.json", + deps = [ + "@npm//@types/jquery", + ], +) + +rollup_bundle( + name = "editor", + config_file = "//ts:rollup.aqt.config.js", + entry_point = "index.ts", + format = "iife", + link_workspace_root = True, + silent = True, + sourcemap = "false", + visibility = ["//visibility:public"], + deps = [ + "editor_ts", + "@npm//@rollup/plugin-commonjs", + "@npm//@rollup/plugin-node-resolve", + "@npm//rollup-plugin-terser", + ], +) + +# Tests +################ + +prettier_test( + name = "format_check", + srcs = glob([ + "*.ts", + ]), +) + +eslint_test( + name = "eslint", + srcs = glob( + [ + "*.ts", + ], + ), +) diff --git a/qt/aqt/data/web/js/editor/filterHtml.ts b/ts/editor/filterHtml.ts similarity index 100% rename from qt/aqt/data/web/js/editor/filterHtml.ts rename to ts/editor/filterHtml.ts diff --git a/qt/aqt/data/web/js/editor/helpers.ts b/ts/editor/helpers.ts similarity index 100% rename from qt/aqt/data/web/js/editor/helpers.ts rename to ts/editor/helpers.ts diff --git a/qt/aqt/data/web/js/editor/index.ts b/ts/editor/index.ts similarity index 98% rename from qt/aqt/data/web/js/editor/index.ts rename to ts/editor/index.ts index d38215d43..4a42373b0 100644 --- a/qt/aqt/data/web/js/editor/index.ts +++ b/ts/editor/index.ts @@ -3,6 +3,7 @@ import { filterHTML } from "./filterHtml"; import { nodeIsElement, nodeIsInline } from "./helpers"; +import { bridgeCommand } from "./lib"; let currentField: EditingArea | null = null; let changeTimer: number | null = null; @@ -198,7 +199,7 @@ function onFocus(evt: FocusEvent): void { } elem.focusEditable(); currentField = elem; - pycmd(`focus:${currentField.ord}`); + bridgeCommand(`focus:${currentField.ord}`); enableButtons(); // do this twice so that there's no flicker on newer versions caretToEnd(); @@ -245,7 +246,7 @@ export function focusIfField(x: number, y: number): boolean { } function onPaste(): void { - pycmd("paste"); + bridgeCommand("paste"); window.event.preventDefault(); } @@ -295,7 +296,9 @@ function saveField(type: "blur" | "key"): void { return; } - pycmd(`${type}:${currentField.ord}:${currentNoteId}:${currentField.fieldHTML}`); + bridgeCommand( + `${type}:${currentField.ord}:${currentNoteId}:${currentField.fieldHTML}` + ); } function wrappedExceptForWhitespace(text: string, front: string, back: string): string { @@ -361,7 +364,7 @@ function wrapInternal(front: string, back: string, plainText: boolean): void { } function onCutOrCopy(): boolean { - pycmd("cutOrCopy"); + bridgeCommand("cutOrCopy"); return true; } diff --git a/ts/editor/lib.ts b/ts/editor/lib.ts new file mode 100644 index 000000000..3797974c8 --- /dev/null +++ b/ts/editor/lib.ts @@ -0,0 +1,9 @@ +declare global { + interface Window { + bridgeCommand(command: string, callback?: (value: T) => void): void; + } +} + +export function bridgeCommand(command: string, callback?: (value: T) => void): void { + window.bridgeCommand(command, callback); +} diff --git a/qt/aqt/data/web/js/rollup.config.js b/ts/rollup.aqt.config.js similarity index 100% rename from qt/aqt/data/web/js/rollup.config.js rename to ts/rollup.aqt.config.js