File tree Expand file tree Collapse file tree 7 files changed +84
-2
lines changed
packages/dbml-vs-code-extension Expand file tree Collapse file tree 7 files changed +84
-2
lines changed Original file line number Diff line number Diff line change 11export const WEB_VIEW_NAME = "dblm-preview-webview" ;
22export const WEB_VIEW_TITLE = "DBLM Diagram Preview" ;
33export const DIAGRAM_UPDATER_DEBOUNCE_TIME = 500 ;
4+ export const EXTENSION_CONFIG_SESSION = "dbmlERDPreviewer" ;
5+ export const WEBVIEW_HTML_MARKER_FOR_DEFAULT_CONFIG = "// <%DEFAULT-SCRIPT%>" ;
Original file line number Diff line number Diff line change 1+ import { Theme } from "json-table-schema-visualizer/src/types/theme" ;
2+ import { workspace , WorkspaceConfiguration } from "vscode" ;
3+ import { ConfigKeys } from "../types/configKeys" ;
4+ import { DefaultPageConfig } from "../types/defaultPageConfig" ;
5+
6+ export class ExtensionConfig {
7+ private config : WorkspaceConfiguration ;
8+
9+ constructor ( configSession : string ) {
10+ const extensionConfigs = workspace . getConfiguration ( configSession ) ;
11+ this . config = extensionConfigs ;
12+ }
13+
14+ setTheme ( theme : Theme ) {
15+ this . config . update ( ConfigKeys . preferredTheme , theme ) ;
16+ }
17+
18+ getPreferredTheme ( ) {
19+ const preferredTheme = this . config . get ( ConfigKeys . preferredTheme ) ;
20+ if ( Theme . light === preferredTheme ) {
21+ return preferredTheme ;
22+ }
23+
24+ return Theme . dark ;
25+ }
26+
27+ getDefaultPageConfig ( ) : DefaultPageConfig {
28+ const theme = this . getPreferredTheme ( ) ;
29+
30+ return { theme } ;
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ export enum ConfigKeys {
2+ preferredTheme = "preferredTheme" ,
3+ }
Original file line number Diff line number Diff line change 1+ import { Theme } from "json-table-schema-visualizer/src/types/theme" ;
2+
3+ export interface DefaultPageConfig {
4+ theme : Theme ;
5+ }
Original file line number Diff line number Diff line change 11import { ExtensionContext , Webview } from "vscode" ;
22
33export class WebviewHelper {
4- public static setupHtml ( webview : Webview , context : ExtensionContext ) {
5- return process . env . VITE_DEV_SERVER_URL
4+ public static setupHtml (
5+ webview : Webview ,
6+ context : ExtensionContext ,
7+ defaultConfig : DefaultPageConfig ,
8+ ) : string {
9+ const html = process . env . VITE_DEV_SERVER_URL
610 ? /* @ts -ignore */
711 /* @ts -ignore */ __getWebviewHtml__ ( process . env . VITE_DEV_SERVER_URL )
812 : __getWebviewHtml__ ( webview , context ) ;
13+
14+ return WebviewHelper . injectDefaultConfig ( html , defaultConfig ) ;
15+ }
16+
17+ public static injectDefaultConfig (
18+ html : string ,
19+ configs : DefaultPageConfig ,
20+ ) : string {
21+ return html . replace (
22+ WEBVIEW_HTML_MARKER_FOR_DEFAULT_CONFIG ,
23+ `
24+ window.EXTENSION_DEFAULT_CONFIG = ${ JSON . stringify ( configs ) } ;
25+ ` ,
26+ ) ;
27+ }
928 }
1029}
Original file line number Diff line number Diff line change 99 < body >
1010 < div id ="app "> </ div >
1111 < script type ="module " src ="/src/index.tsx "> </ script >
12+
13+ < script type ="text/javascript ">
14+ // <%DEFAULT-SCRIPT%>
15+ </ script >
1216 </ body >
1317</ html >
Original file line number Diff line number Diff line change 3030 "group" : " navigation"
3131 }
3232 ]
33+ },
34+ "configuration" : {
35+ "title" : " DBML Entity Relationship Diagram" ,
36+ "properties" : {
37+ "dbmlERDPreviewer.preferredTheme" : {
38+ "type" : " string" ,
39+ "default" : " dark" ,
40+ "enum" : [
41+ " dark" ,
42+ " light"
43+ ],
44+ "enumDescriptions" : [
45+ " To use dark mode theme colors" ,
46+ " To use light mode theme colors"
47+ ]
48+ }
49+ }
3350 }
3451 },
3552 "scripts" : {
You can’t perform that action at this time.
0 commit comments