Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9dcd0e

Browse files
committed
fix(play.loradb.com): inline editor theme derivation to bypass lora-query TLA
1 parent b170680 commit b9dcd0e

1 file changed

Lines changed: 58 additions & 65 deletions

File tree

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,74 @@
11
/**
2-
* `LoraQueryEditor` theme deriver. Builds a `Palette` from our
3-
* design tokens and runs it through the package's `createTheme`
4-
* helper so the editor surface, syntax tokens, popups, and diagnostic
5-
* accents all snap to the playground palette.
2+
* `LoraQueryEditor` theme deriver. Builds a flat `LoraQueryTheme`
3+
* directly from our design tokens.
64
*
7-
* Mirrors the dark/light preset construction in
8-
* `@loradb/lora-query/themes.ts`: `createTheme(palette, overrides)`
9-
* spreads typography defaults from `palettes.ts` and flattens the
10-
* popup / diagnostic groups onto the flat `LoraQueryTheme` shape.
5+
* Why we don't use `createTheme` from `@loradb/lora-query`:
6+
* the package's built ESM bundle is wrapped by
7+
* `vite-plugin-top-level-await` (the parser entry needs WASM TLA),
8+
* so every export — `createTheme` included — is gated behind an
9+
* async `__tla` chain that Webpack does not auto-await. Calling
10+
* `createTheme` synchronously from a `useMemo` during the first
11+
* render therefore throws `U is not a function` until the WASM
12+
* promise resolves. The flatten itself is trivial, so we do it
13+
* inline and skip the TLA-gated import entirely.
1114
*/
1215

13-
import {
14-
createTheme,
15-
type LoraQueryTheme,
16-
type Palette,
17-
} from "@loradb/lora-query";
16+
import type { LoraQueryTheme } from "@loradb/lora-query";
1817

1918
import type { Tokens } from "./tokens";
2019
import { hexA } from "./util";
2120

2221
/** Derive a `LoraQueryTheme` from our token set. */
2322
export function deriveEditorTheme(tokens: Tokens): LoraQueryTheme {
24-
const palette: Palette = {
25-
surface: {
26-
background: tokens.bg.editor,
27-
foreground: tokens.fg.primary,
28-
border: tokens.border.subtle,
29-
muted: tokens.fg.muted,
30-
accent: tokens.accent.primary,
31-
activeLine: hexA(tokens.fg.primary, 0.06),
32-
gutterBackground: tokens.bg.editor,
33-
gutterForeground: tokens.fg.subtle,
34-
cursor: tokens.fg.primary,
35-
selectionBackground: hexA(tokens.accent.primary, 0.28),
36-
},
37-
tokens: {
38-
keyword: tokens.syntax.keyword,
39-
variable: tokens.syntax.identifier,
40-
parameter: tokens.syntax.identifier,
41-
label: tokens.syntax.type,
42-
relType: tokens.syntax.type,
43-
property: tokens.syntax.identifier,
44-
functionName: tokens.syntax.type,
45-
namespace: tokens.syntax.type,
46-
string: tokens.syntax.string,
47-
number: tokens.syntax.number,
48-
bool: tokens.syntax.keyword,
49-
null: tokens.syntax.keyword,
50-
operator: tokens.syntax.operator,
51-
comment: tokens.syntax.comment,
52-
},
53-
popup: {
54-
background: tokens.bg.panel,
55-
foreground: tokens.fg.primary,
56-
border: tokens.border.subtle,
57-
selectedBackground: tokens.accent.primary,
58-
selectedForeground: tokens.fg.inverse,
59-
shadow: `0 6px 16px ${hexA("#000000", 0.35)}`,
60-
},
61-
diagnostic: {
62-
error: tokens.accent.danger,
63-
warning: tokens.accent.warning,
64-
info: tokens.accent.info,
65-
},
66-
scrollbar: {
67-
track: tokens.bg.editor,
68-
thumb: tokens.border.strong,
69-
thumbHover: tokens.fg.subtle,
70-
width: "auto",
71-
size: "10px",
72-
},
73-
};
23+
const keyword = tokens.syntax.keyword;
24+
const identifier = tokens.syntax.identifier;
25+
const type = tokens.syntax.type;
26+
27+
return {
28+
background: tokens.bg.editor,
29+
foreground: tokens.fg.primary,
30+
border: tokens.border.subtle,
31+
muted: tokens.fg.muted,
32+
accent: tokens.accent.primary,
33+
activeLine: hexA(tokens.fg.primary, 0.06),
34+
gutterBackground: tokens.bg.editor,
35+
gutterForeground: tokens.fg.subtle,
36+
cursor: tokens.fg.primary,
37+
selectionBackground: hexA(tokens.accent.primary, 0.28),
7438

75-
return createTheme(palette, {
7639
fontFamily: tokens.font.ui,
7740
monoFontFamily: tokens.font.mono,
7841
fontSize: "13px",
7942
popupFontSize: "12px",
80-
});
43+
44+
keyword,
45+
variable: identifier,
46+
parameter: identifier,
47+
label: type,
48+
relType: type,
49+
property: identifier,
50+
functionName: type,
51+
namespace: type,
52+
string: tokens.syntax.string,
53+
number: tokens.syntax.number,
54+
bool: keyword,
55+
null: keyword,
56+
57+
popupBackground: tokens.bg.panel,
58+
popupForeground: tokens.fg.primary,
59+
popupBorder: tokens.border.subtle,
60+
popupSelectedBackground: tokens.accent.primary,
61+
popupSelectedForeground: tokens.fg.inverse,
62+
popupShadow: `0 6px 16px ${hexA("#000000", 0.35)}`,
63+
64+
errorAccent: tokens.accent.danger,
65+
warningAccent: tokens.accent.warning,
66+
infoAccent: tokens.accent.info,
67+
68+
scrollbarTrack: tokens.bg.editor,
69+
scrollbarThumb: tokens.border.strong,
70+
scrollbarThumbHover: tokens.fg.subtle,
71+
scrollbarWidth: "auto",
72+
scrollbarSize: "10px",
73+
};
8174
}

0 commit comments

Comments
 (0)