diff --git a/apps/zui/jest.config.js b/apps/zui/jest.config.js index 8cdea607b6..91dd992191 100644 --- a/apps/zui/jest.config.js +++ b/apps/zui/jest.config.js @@ -15,7 +15,7 @@ module.exports = { setupFiles: ["./src/test/unit/setup/before-env.ts"], setupFilesAfterEnv: ["./src/test/unit/setup/after-env.ts"], testEnvironmentOptions: { - testURL: "http://localhost:3000/?name=search&id=test-1", + testURL: "http://localhost:4567/?name=search&id=test-1", }, globalSetup: "./src/test/unit/setup/global.ts", modulePaths: [""], diff --git a/apps/zui/package.json b/apps/zui/package.json index d35a005f1f..0de188155c 100644 --- a/apps/zui/package.json +++ b/apps/zui/package.json @@ -14,7 +14,7 @@ "scripts": { "start": "node scripts/start", "start:main": "yarn build:main --watch", - "start:renderer": "next dev", + "start:renderer": "next dev -p 4567", "start:electron": "nodemon --watch dist ../../node_modules/electron/cli.js .", "watch-code": "run-p start:main start:renderer", "build": "run-p -l 'build:**'", diff --git a/apps/zui/src/core/zed-syntax.ts b/apps/zui/src/core/zed-syntax.ts new file mode 100644 index 0000000000..c609df183f --- /dev/null +++ b/apps/zui/src/core/zed-syntax.ts @@ -0,0 +1,185 @@ +const primitiveTypes = [ + "uint8", + "uint16", + "uint32", + "uint64", + "int8", + "int16", + "int32", + "int64", + "float16", + "float32", + "float64", + "bool", + "string", + "duration", + "time", + "bytes", + "ip", + "net", + "type", + "null", +] + +const keywords = ["this", "const", "from", "file", "func", "op", "type"] + +const builtinOps = [ + "assert", + "combine", + "cut", + "drop", + "file", + "fork", + "from", + "fuse", + "get", + "head", + "join", + "load", + "merge", + "over", + "pass", + "put", + "rename", + "sample", + "search", + "sort", + "summarize", + "switch", + "tail", + "uniq", + "where", + "yield", +] + +const builtinFuncs = [ + "abs", + "base64", + "bucket", + "cast", + "ceil", + "cidr_match", + "compare", + "coalesce", + "crop", + "error", + "every", + "fields", + "fill", + "flatten", + "floor", + "grep", + "has", + "hex", + "has_error", + "is", + "is_error", + "join", + "kind", + "ksuid", + "len", + "levenshtein", + "log", + "lower", + "missing", + "nameof", + "nest_dotted", + "network_of", + "now", + "order", + "parse_uri", + "parse_zson", + "pow", + "quiet", + "regexp", + "regexp_replace", + "replace", + "round", + "rune_len", + "shape", + "split", + "sqrt", + "trim", + "typename", + "typeof", + "typeunder", + "under", + "unflatten", + "upper", +] + +const builtinAggFuncs = [ + "AND", + "OR", + "and", + "any", + "avg", + "collect", + "count", + "dcount", + "fuse", + "map", + "max", + "min", + "or", + "sum", + "union", +] + +const operators = ["+", "-", "*", "/", ">", ">=", "<", "<=", "=", ":="] + +const symbols = /[+\-*/><=:]+/ + +const identifier = /[a-zA-Z][\w$]*/ + +const identifierRule = [ + identifier, + { + cases: { + "@keywords": "keyword", + "@builtinOps": "keyword", + "@builtinFuncs": "keyword", + "@builtinAggFuncs": "keyword", + "@primitiveTypes": "keyword", + "@operators": "operators", + "@default": "variable", + }, + }, +] + +const operatorRule = [ + symbols, + { + cases: { + "@operators": "operator", + "#default": "", + }, + }, +] + +const integerRule = [/\d+/, "number"] +const floatRule = [/\d*\.\d+/, "number.float"] +const stringRule = [/("[^"]*")|('[^']*')/, "string"] +const commentRule = [/\/\/.*/, "comment"] +const bracketRule = [/[{}()[]]/, "@brackets"] + +export const tokens = { + keywords, + operators, + primitiveTypes, + builtinAggFuncs, + builtinFuncs, + builtinOps, + symbols, + tokenizer: { + root: [ + identifierRule, + commentRule, + bracketRule, + operatorRule, + integerRule, + floatRule, + stringRule, + ] as any, + }, +} diff --git a/apps/zui/src/electron/windows/search/search.html b/apps/zui/src/electron/windows/search/search.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/apps/zui/src/electron/windows/zui-window.ts b/apps/zui/src/electron/windows/zui-window.ts index 335d4b69a1..0ea1cf8bd3 100644 --- a/apps/zui/src/electron/windows/zui-window.ts +++ b/apps/zui/src/electron/windows/zui-window.ts @@ -68,7 +68,7 @@ export abstract class ZuiWindow { load() { this.beforeLoad() const url = env.isDevelopment - ? `http://localhost:3000${this.path}?id=${this.id}&name=${this.name}` + ? `http://localhost:4567${this.path}?id=${this.id}&name=${this.name}` : `file://${this.path}.html?id=${this.id}&name=${this.name}` return this.ref.loadURL(url) } diff --git a/apps/zui/src/js/initializers/init-monaco.ts b/apps/zui/src/js/initializers/init-monaco.ts index 4430a774c0..60bc450997 100644 --- a/apps/zui/src/js/initializers/init-monaco.ts +++ b/apps/zui/src/js/initializers/init-monaco.ts @@ -1,196 +1,16 @@ +import {tokens} from "src/core/zed-syntax" import {loader} from "@monaco-editor/react" -const primitiveTypes = [ - "uint8", - "uint16", - "uint32", - "uint64", - "int8", - "int16", - "int32", - "int64", - "float16", - "float32", - "float64", - "bool", - "string", - "duration", - "time", - "bytes", - "ip", - "net", - "type", - "null", -] - -const keywords = ["this", "const", "from", "file", "func", "op", "type"] - -const builtinOps = [ - "assert", - "combine", - "cut", - "drop", - "file", - "fork", - "from", - "fuse", - "get", - "head", - "join", - "load", - "merge", - "over", - "pass", - "put", - "rename", - "sample", - "search", - "sort", - "summarize", - "switch", - "tail", - "uniq", - "where", - "yield", -] - -const builtinFuncs = [ - "abs", - "base64", - "bucket", - "cast", - "ceil", - "cidr_match", - "compare", - "coalesce", - "crop", - "error", - "every", - "fields", - "fill", - "flatten", - "floor", - "grep", - "has", - "hex", - "has_error", - "is", - "is_error", - "join", - "kind", - "ksuid", - "len", - "levenshtein", - "log", - "lower", - "missing", - "nameof", - "nest_dotted", - "network_of", - "now", - "order", - "parse_uri", - "parse_zson", - "pow", - "quiet", - "regexp", - "regexp_replace", - "replace", - "round", - "rune_len", - "shape", - "split", - "sqrt", - "trim", - "typename", - "typeof", - "typeunder", - "under", - "unflatten", - "upper", -] - -const builtinAggFuncs = [ - "AND", - "OR", - "and", - "any", - "avg", - "collect", - "count", - "dcount", - "fuse", - "map", - "max", - "min", - "or", - "sum", - "union", -] - -const operators = ["+", "-", "*", "/", ">", ">=", "<", "<=", "=", ":="] - -const symbols = /[+\-*/><=:]+/ - -const identifier = /[a-zA-Z][\w$]*/ - -const identifierRule = [ - identifier, - { - cases: { - "@keywords": "keyword", - "@builtinOps": "keyword", - "@builtinFuncs": "keyword", - "@builtinAggFuncs": "keyword", - "@primitiveTypes": "keyword", - "@operators": "operators", - "@default": "variable", - }, - }, -] - -const operatorRule = [ - symbols, - { - cases: { - "@operators": "operator", - "#default": "", - }, - }, -] - -const integerRule = [/\d+/, "number"] -const floatRule = [/\d*\.\d+/, "number.float"] -const stringRule = [/("[^"]*")|('[^']*')/, "string"] -const commentRule = [/\/\/.*/, "comment"] -const bracketRule = [/[{}()[]]/, "@brackets"] - export async function initializeMonaco() { + if (globalThis.env.isTest) return // Only works in a browser environment try { const monaco = await loader.init() monaco.languages.register({id: "zed"}) - - monaco.languages.setMonarchTokensProvider("zed", { - keywords, - operators, - primitiveTypes, - builtinAggFuncs, - builtinFuncs, - builtinOps, - symbols, - tokenizer: { - root: [ - identifierRule, - commentRule, - bracketRule, - operatorRule, - integerRule, - floatRule, - stringRule, - ], - }, + monaco.languages.setMonarchTokensProvider("zed", tokens) + document.fonts.addEventListener("loadingdone", () => { + monaco.editor.remeasureFonts() }) } catch (e) { - console.error("No window environment") + console.error("No window environment", e) } }