From c6357c2d43b8950524a8a82c2293f842f6287a1c Mon Sep 17 00:00:00 2001 From: Hatem Hosny Date: Sun, 22 Dec 2024 12:12:42 +0200 Subject: [PATCH 1/4] update LiveCodes and add `themeColor` --- components/playgroundEditor/LiveCodes.tsx | 3 ++- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/playgroundEditor/LiveCodes.tsx b/components/playgroundEditor/LiveCodes.tsx index 493922a8..1f376af7 100644 --- a/components/playgroundEditor/LiveCodes.tsx +++ b/components/playgroundEditor/LiveCodes.tsx @@ -42,6 +42,7 @@ export default function LiveCodes({ active: "console", status: "full", }, + themeColor: "hsl(205, 17%, 50%)", // the original theme color is "#3a4852" which is "hsl(205, 17%, 27%)" }; const getJSTSConfig = ( @@ -223,7 +224,7 @@ ${test.replace(pattern, "\n")}`.trimStart(); return ( Date: Sun, 22 Dec 2024 12:16:35 +0200 Subject: [PATCH 2/4] add i18n support in LiveCodes --- components/playgroundEditor/LiveCodes.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/playgroundEditor/LiveCodes.tsx b/components/playgroundEditor/LiveCodes.tsx index 1f376af7..5efc4f56 100644 --- a/components/playgroundEditor/LiveCodes.tsx +++ b/components/playgroundEditor/LiveCodes.tsx @@ -3,6 +3,7 @@ import type { Config, Playground } from "livecodes"; import LiveCodesPlayground from "livecodes/react"; import { luaTestRunner, type Language } from "lib/playground/livecodes"; import { useDarkTheme } from "hooks/darkTheme"; +import { useRouter } from "next/router"; export default function LiveCodes({ language, @@ -15,6 +16,14 @@ export default function LiveCodes({ }) { const [playground, setPlayground] = useState(); const [darkTheme] = useDarkTheme(); + const { locale } = useRouter(); + + const getLanguageFromLocale = (locale_: string | undefined) => + !locale_ + ? "en" + : locale_ === "zh_Hans" + ? "zh-CN" + : (locale_.split("_")[0] as Config["appLanguage"]); const onReady = (sdk: Playground) => { setPlayground(sdk); @@ -31,6 +40,7 @@ export default function LiveCodes({ }, [playground, darkTheme]); const baseConfig: Partial = { + appLanguage: getLanguageFromLocale(locale), autoupdate: true, languages: [language === "jupyter" ? "python-wasm" : language], script: { @@ -224,7 +234,7 @@ ${test.replace(pattern, "\n")}`.trimStart(); return ( Date: Sun, 22 Dec 2024 12:26:52 +0200 Subject: [PATCH 3/4] upgrade livecodes SDK --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2d624b4b..00b18eb6 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "highlight.js": "^11.5.1", "iframe-resizer-react": "^1.1.0", "katex": "^0.13.24", - "livecodes": "0.7.1", + "livecodes": "0.7.2", "marked": "^4.0.17", "next": "^12.1.0", "next-i18next": "^8.10.0", diff --git a/yarn.lock b/yarn.lock index f91fcef3..53bb9310 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2996,10 +2996,10 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -livecodes@0.7.1: - version "0.7.1" - resolved "https://registry.yarnpkg.com/livecodes/-/livecodes-0.7.1.tgz#cac585d84935cbb94e47894285ad32dc1114acca" - integrity sha512-YHks/nvcgHPa1YmK7l1LWnaCOQZAlsour1nrUpk3ZGpXOHmkh0V4MbNB8pW+m3u8mGMON3xlhtWEq2+0KYYs0w== +livecodes@0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/livecodes/-/livecodes-0.7.2.tgz#117bea6a171e677a49958dc52d21e96ca6aa8bea" + integrity sha512-9u8s+/mOztX6Ll1ru1Tpv2V8Ctb5TRprxXxyhl4U71nUPQIgaGt5ZiwTdRg4HofPiEKsdC1drTnAi9gNL3XRhA== locate-path@^2.0.0: version "2.0.0" From e894545322760a3631a8ba7d6958487cb30ae8c1 Mon Sep 17 00:00:00 2001 From: Hatem Hosny Date: Sun, 22 Dec 2024 14:41:19 +0200 Subject: [PATCH 4/4] upgrade LiveCodes to v39 --- components/playgroundEditor/LiveCodes.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/playgroundEditor/LiveCodes.tsx b/components/playgroundEditor/LiveCodes.tsx index 5efc4f56..5ab6d757 100644 --- a/components/playgroundEditor/LiveCodes.tsx +++ b/components/playgroundEditor/LiveCodes.tsx @@ -234,7 +234,7 @@ ${test.replace(pattern, "\n")}`.trimStart(); return (