From 13131d222876dc3b65b4933cd4d517fdad47ab0d Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Mon, 8 Jul 2024 17:58:05 +0300 Subject: [PATCH] squash! Signed-off-by: Nikola Hristov --- Source/Context/Action.tsx | 80 +++++++++++++++++++++++++++++------ Source/Element/Editor.tsx | 2 +- Source/Interface/Persist.ts | 2 +- Source/Script/Monaco.ts | 42 ------------------ Target/Interface/Persist.d.ts | 2 +- 5 files changed, 69 insertions(+), 59 deletions(-) delete mode 100644 Source/Script/Monaco.ts diff --git a/Source/Context/Action.tsx b/Source/Context/Action.tsx index f98b661..5b9aae5 100644 --- a/Source/Context/Action.tsx +++ b/Source/Context/Action.tsx @@ -1,20 +1,41 @@ -import type { JSX } from "solid-js"; +self.MonacoEnvironment = { + createTrustedTypesPolicy: () => undefined, + getWorker: async (_WorkerID, Label) => { + switch (Label) { + case "css": + return new ( + await import( + // @ts-expect-error + "monaco-editor/esm/vs/language/css/css.worker.js?worker" + ) + ).default(); -import { _Function } from "@Context/Action/Context"; -import "@Script/Monaco"; -import Light from "@Script/Monaco/Theme/Active4D.json"; -import Dark from "@Script/Monaco/Theme/Amoled.json"; + case "html": + return new ( + await import( + // @ts-expect-error + "monaco-editor/esm/vs/language/html/html.worker.js?worker" + ) + ).default(); -import { editor as Monaco } from "monaco-editor"; + case "typescript": + return new ( + await import( + // @ts-expect-error + "monaco-editor/esm/vs/language/typescript/ts.worker.js?worker" + ) + ).default(); -Monaco.defineTheme("Light", Light as Monaco.IStandaloneThemeData); -Monaco.defineTheme("Dark", Dark as Monaco.IStandaloneThemeData); - -window - .matchMedia("(prefers-color-scheme: dark)") - .addEventListener("change", ({ matches }) => - Monaco.setTheme(matches ? "Dark" : "Light"), - ); + default: + return new ( + await import( + // @ts-expect-error + "monaco-editor/esm/vs/editor/editor.worker.js?worker" + ) + ).default(); + } + }, +}; export default ({ children }: { children?: JSX.Element }) => ( <_Function.Provider value={_Function.defaultValue}> @@ -30,3 +51,34 @@ export default ({ children }: { children?: JSX.Element }) => ( {children} ); + +// TODO: IMPORT AND SET ASYNC +export const { editor: Monaco, languages } = await import("monaco-editor"); + +languages.typescript.typescriptDefaults.setEagerModelSync(true); + +Monaco.defineTheme( + "Light", + (await import("@Script/Monaco/Theme/Active4D.json")) + .default as editor.IStandaloneThemeData, +); +Monaco.defineTheme( + "Dark", + (await import("@Script/Monaco/Theme/Amoled.json")) + .default as editor.IStandaloneThemeData, +); +// TODO: END IMPORT AND SET ASYNC + +// TODO: WATCH THIS ASYNC +window + .matchMedia("(prefers-color-scheme: dark)") + .addEventListener("change", ({ matches }) => + Monaco.setTheme(matches ? "Dark" : "Light"), + ); +// TODO: END WATCH THIS ASYNC + +export const { _Function } = await import("@Context/Action/Context"); + +import type { editor } from "monaco-editor"; + +import type { JSX } from "solid-js"; diff --git a/Source/Element/Editor.tsx b/Source/Element/Editor.tsx index ea7d307..441fc92 100644 --- a/Source/Element/Editor.tsx +++ b/Source/Element/Editor.tsx @@ -318,7 +318,7 @@ export default () => ({}); } }; -// @TODO: If a user logs out then logs in again, the keys are persisted in local storage, however the Access Token is no longer valid, they will either roll keys or renew. If they renew no problem. If they roll keys, their HTML gets reset. +// TODO: If a user logs out then logs in again, the keys are persisted in local storage, however the Access Token is no longer valid, they will either roll keys or renew. If they renew no problem. If they roll keys, their HTML gets reset. export const Update: SubmitHandler = ({ Content, Field }, Event) => { if (Event) { Event.preventDefault(); diff --git a/Source/Interface/Persist.ts b/Source/Interface/Persist.ts index 072647b..f1f0964 100644 --- a/Source/Interface/Persist.ts +++ b/Source/Interface/Persist.ts @@ -7,7 +7,7 @@ export default interface Interface { * The `Persist` function takes an item and a store, and saves the item to the store * using Local Storage, while also returning the store and the item as a signal. * - * // @TODO: Properly document + * TODO: Properly document * @param A signal representing the item to be persisted. * */ diff --git a/Source/Script/Monaco.ts b/Source/Script/Monaco.ts deleted file mode 100644 index 882f736..0000000 --- a/Source/Script/Monaco.ts +++ /dev/null @@ -1,42 +0,0 @@ -self.MonacoEnvironment = { - createTrustedTypesPolicy: () => undefined, - getWorker: async (_WorkerID, Label) => { - switch (Label) { - case "css": - return new ( - await import( - // @ts-expect-error - "monaco-editor/esm/vs/language/css/css.worker.js?worker" - ) - ).default(); - - case "html": - return new ( - await import( - // @ts-expect-error - "monaco-editor/esm/vs/language/html/html.worker.js?worker" - ) - ).default(); - - case "typescript": - return new ( - await import( - // @ts-expect-error - "monaco-editor/esm/vs/language/typescript/ts.worker.js?worker" - ) - ).default(); - - default: - return new ( - await import( - // @ts-expect-error - "monaco-editor/esm/vs/editor/editor.worker.js?worker" - ) - ).default(); - } - }, -}; - -export default ( - await import("monaco-editor") -).languages.typescript.typescriptDefaults.setEagerModelSync(true); diff --git a/Target/Interface/Persist.d.ts b/Target/Interface/Persist.d.ts index a14ae7f..14bc132 100644 --- a/Target/Interface/Persist.d.ts +++ b/Target/Interface/Persist.d.ts @@ -7,7 +7,7 @@ export default interface Interface { * The `Persist` function takes an item and a store, and saves the item to the store * using Local Storage, while also returning the store and the item as a signal. * - * // @TODO: Properly document + * TODO: Properly document * @param A signal representing the item to be persisted. * */