Move editor to /ts/editor
This commit is contained in:
parent
859a52ab15
commit
2ab06a6540
@ -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 = [
|
||||
|
@ -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",
|
||||
])
|
@ -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",
|
||||
|
49
ts/editor/BUILD.bazel
Normal file
49
ts/editor/BUILD.bazel
Normal file
@ -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",
|
||||
],
|
||||
),
|
||||
)
|
@ -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;
|
||||
}
|
||||
|
9
ts/editor/lib.ts
Normal file
9
ts/editor/lib.ts
Normal file
@ -0,0 +1,9 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
bridgeCommand<T>(command: string, callback?: (value: T) => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void {
|
||||
window.bridgeCommand<T>(command, callback);
|
||||
}
|
Loading…
Reference in New Issue
Block a user