Skip to content

Commit 7f9e8ea

Browse files
committed
refactor(ext): create package for shared extension code
1 parent e99900f commit 7f9e8ea

File tree

21 files changed

+300
-119
lines changed

21 files changed

+300
-119
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
export const WEB_VIEW_NAME = "dblm-preview-webview";
22
export const WEB_VIEW_TITLE = "DBLM Diagram Preview";
3-
export const DIAGRAM_UPDATER_DEBOUNCE_TIME = 500;
43
export const EXTENSION_CONFIG_SESSION = "dbmlERDPreviewer";
5-
export const WEBVIEW_HTML_MARKER_FOR_DEFAULT_CONFIG = "// <%DEFAULT-SCRIPT%>";
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { commands, ExtensionContext } from "vscode";
2-
import { MainPanel } from "@/extension/views/panel";
3-
import { EXTENSION_CONFIG_SESSION } from "@/extension/constants";
1+
import { commands, type ExtensionContext } from "vscode";
42

5-
export function activate(context: ExtensionContext) {
3+
import { parseDBMLToJSON } from "dbml-to-json-table-schema";
4+
5+
import { MainPanel } from "extension-shared/extension/views/panel";
6+
import {
7+
EXTENSION_CONFIG_SESSION,
8+
WEB_VIEW_NAME,
9+
WEB_VIEW_TITLE,
10+
} from "@/extension/constants";
11+
12+
export function activate(context: ExtensionContext): void {
613
// Add command to the extension context
714
context.subscriptions.push(
815
commands.registerCommand(
@@ -14,8 +21,18 @@ export function activate(context: ExtensionContext) {
1421
);
1522
}
1623

17-
const lunchExtension = (context: ExtensionContext) => {
18-
MainPanel.render(context, EXTENSION_CONFIG_SESSION);
24+
const lunchExtension = (context: ExtensionContext): void => {
25+
MainPanel.render({
26+
context,
27+
extensionConfigSession: EXTENSION_CONFIG_SESSION,
28+
webviewConfig: {
29+
name: WEB_VIEW_NAME,
30+
title: WEB_VIEW_TITLE,
31+
},
32+
parser: parseDBMLToJSON,
33+
fileExt: "dbml",
34+
});
1935
};
2036

37+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
2138
export function deactivate() {}

packages/dbml-vs-code-extension/extension/types/defaultPageConfig.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/dbml-vs-code-extension/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
},
6666
"devDependencies": {
6767
"@tomjs/vite-plugin-vscode": "^2.2.0",
68-
"@tomjs/vscode-extension-webview": "^1.2.0",
6968
"@types/mocha": "^10.0.6",
7069
"@types/node": "18.x",
7170
"@types/react": "^18.2.75",

packages/dbml-vs-code-extension/src/globals.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
import { createRoot } from "react-dom/client";
2-
import "@tomjs/vscode-extension-webview/client";
3-
import { tableCoordsStore } from "json-table-schema-visualizer/src/stores/tableCoords";
4-
import App from "./App";
1+
import { createExtensionApp } from "extension-shared/src/index";
52

6-
// save current table position when exiting the page
7-
window.addEventListener("unload", () => {
8-
tableCoordsStore.saveCurrentStore();
9-
});
10-
11-
const View = () => {
12-
return <App />;
13-
};
14-
15-
const root = createRoot(document.getElementById("app")!);
16-
root.render(<View />);
3+
createExtensionApp();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const DIAGRAM_UPDATER_DEBOUNCE_TIME = 500;
2+
export const WEBVIEW_HTML_MARKER_FOR_DEFAULT_CONFIG = "// <%DEFAULT-SCRIPT%>";

packages/dbml-vs-code-extension/extension/helper/extensionConfigs.ts renamed to packages/extension-shared/extension/helper/extensionConfigs.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import { Theme } from "json-table-schema-visualizer/src/types/theme";
2-
import { workspace, WorkspaceConfiguration } from "vscode";
3-
import { ConfigKeys } from "@/extension/types/configKeys";
4-
import { DefaultPageConfig } from "@/extension/types/defaultPageConfig";
2+
import { workspace, type WorkspaceConfiguration } from "vscode";
3+
4+
import { ConfigKeys } from "../types/configKeys";
5+
import { type DefaultPageConfig } from "../types/defaultPageConfig";
56

67
export class ExtensionConfig {
7-
private config: WorkspaceConfiguration;
8+
private readonly config: WorkspaceConfiguration;
89

910
constructor(configSession: string) {
1011
const extensionConfigs = workspace.getConfiguration(configSession);
1112
this.config = extensionConfigs;
1213
}
1314

14-
setTheme(theme: Theme) {
15-
this.config.update(ConfigKeys.preferredTheme, theme);
15+
async setTheme(theme: Theme): Promise<void> {
16+
try {
17+
await this.config.update(ConfigKeys.preferredTheme, theme);
18+
} catch (error) {
19+
console.error("Failed to set theme preference", error);
20+
}
1621
}
1722

18-
getPreferredTheme() {
23+
getPreferredTheme(): Theme {
1924
const preferredTheme = this.config.get(ConfigKeys.preferredTheme);
2025
if (Theme.light === preferredTheme) {
2126
return preferredTheme;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { type Theme } from "json-table-schema-visualizer/src/types/theme";
2+
3+
export interface DefaultPageConfig {
4+
theme: Theme;
5+
}

0 commit comments

Comments
 (0)