Skip to content

Commit 6922aae

Browse files
committed
able to render screen's width and height in console
1 parent 68ac085 commit 6922aae

9 files changed

+760
-23
lines changed

package-lock.json

+686
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@
6565
"@typescript-eslint/parser": "^6.19.1",
6666
"@vscode/test-cli": "^0.0.4",
6767
"@vscode/test-electron": "^2.3.9",
68+
"autoprefixer": "^10.4.17",
6869
"d3": "^7.8.5",
6970
"eslint": "^8.56.0",
7071
"fs": "^0.0.1-security",
7172
"mini-css-extract-plugin": "^2.8.0",
7273
"path": "^0.12.7",
74+
"postcss": "^8.4.35",
75+
"postcss-loader": "^8.1.0",
7376
"svelte": "^4.2.10",
7477
"svelte-loader": "^3.1.9",
78+
"tailwindcss": "^3.4.1",
7579
"ts-loader": "^9.5.1",
7680
"typescript": "^5.3.3",
7781
"webpack": "^5.90.0",

postcss.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: [
3+
require('tailwindcss'),
4+
require('autoprefixer'),
5+
]
6+
};

src/components/Sidebar.svelte

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
<script>
2-
import { onMount } from "svelte";
3-
import Tree from "./Tree.svelte";
2+
import { onMount } from "svelte";
3+
import Tree from "./Tree.svelte";
4+
import TreeWrapper from "./TreeWrapper.svelte";
45
56
let componentStructure = [];
67
8+
79
onMount(() => {
10+
let width = 2000;
11+
let height = 2000;
12+
window.addEventListener('resize', (e)=> {
13+
width = document.querySelector('.tree-wrapper').offsetWidth;
14+
height = document.querySelector('.tree-wrapper').offsetHeight;
15+
console.log('width: ',width);
16+
console.log('height: ', height);
17+
})
18+
819
window.addEventListener("message", (event) => {
920
const structure = event.data;
1021
switch(structure.type){
@@ -20,14 +31,16 @@
2031
<main>
2132
<!-- <div class="background"> -->
2233
<h1>See your component structure below!</h1>
23-
{#if componentStructure.length > 0}
24-
<Tree {componentStructure}/>
25-
{/if}
34+
<TreeWrapper>
35+
{#if componentStructure.length > 0}
36+
<Tree {componentStructure}/>
37+
{/if}
38+
</TreeWrapper>
39+
2640
<!-- </div> -->
2741
</main>
2842

2943
<style>
30-
3144
h1 {
3245
color: #e3ae52;
3346
text-align: center;

src/components/Tree.svelte

+11-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import * as d3 from "d3";
44
55
export let componentStructure;
6+
export let width;
7+
// export let height;
8+
// export let mounted;
9+
610
// let containerHeight = 0;
711
// let containerWidth = 0;
812
// document.addEventListener("DOMContentLoaded", () => {
@@ -11,14 +15,10 @@
1115
// console.log("container: ", containerWidth);
1216
// });
1317
14-
onMount(() => {
15-
let height = 2000;
16-
let width = 2000;
17-
18-
let containerWidth = document.getElementById("tree-container").offsetWidth;
19-
let containerHeight =
20-
document.getElementById("tree-container").offsetHeight;
21-
18+
onMount(() => {
19+
let containerWidth = 2500;
20+
let containerHeight = 2000;
21+
console.log('width', width);
2222
let window = d3
2323
.select("#tree-container")
2424
.append("svg")
@@ -30,7 +30,7 @@
3030
const root = d3.hierarchy(componentStructure[0]);
3131
3232
// console.log('root test', root.data);
33-
const tree = d3.tree().size([containerHeight / 4, containerWidth / 4]);
33+
const tree = d3.tree().size([containerWidth / 4, containerHeight / 4]);
3434
3535
const treeDataTransformed = tree(root);
3636
@@ -60,7 +60,7 @@
6060
return d.data.name;
6161
})
6262
.style("fill", "antiquewhite")
63-
.attr("dy", "2em") // Move text down
63+
.attr("dx", "3em") // Move text down
6464
.attr("text-anchor", "middle");
6565
6666
let diagonal = d3
@@ -84,8 +84,5 @@
8484
<div id="tree-container"></div>
8585

8686
<style>
87-
#tree-container {
88-
width: 100%;
89-
height: 100%;
90-
}
87+
9188
</style>

src/components/TreeWrapper.svelte

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<section>
2+
<div class="tree-wrapper">
3+
<slot/>
4+
</div>
5+
</section>
6+
7+

src/extension.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function activate(context: vscode.ExtensionContext) {
3030

3131
context.subscriptions.push(
3232
vscode.commands.registerCommand('svisualize.sendUri', async () => {
33-
const folders = vscode.workspace.workspaceFolders;
34-
const rootPath = folders[0].uri.fsPath;
33+
const folders = await vscode.workspace.workspaceFolders;
34+
const rootPath = folders[0].uri.fsPath ;
3535
const result = await parseFile(rootPath);
3636
console.log(result);
3737
//we are sending a message containing result which is our final componentStructure to Svelte
@@ -41,6 +41,21 @@ export function activate(context: vscode.ExtensionContext) {
4141
});
4242
})
4343
);
44+
45+
// // Listen for changes in the webview's view state (e.g., when it's resized)
46+
// sidebarProvider._view?.webview.onDidChangeViewState(event => {
47+
// const newPanelViewState = event.webviewPanel.visible;
48+
// if (newPanelViewState) {
49+
// // The webview is now visible, resize it as needed
50+
// const panelWidth = panel.webviewView.visibleColumn * vscode.window.activeTextEditor!.options.fontInfo.typicalHalfwidthCharacterWidth;
51+
// const panelHeight = panel.webviewView.visibleRows * vscode.window.activeTextEditor!.options.fontInfo.lineHeight;
52+
// resizePanel(panelWidth, panelHeight);
53+
// }
54+
// });
55+
56+
//function that resizes panel
57+
58+
4459
}
4560

4661
//declare a function that renders webview content. render an html file

tailwind.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: [],
4+
theme: {
5+
extend: {},
6+
},
7+
plugins: [],
8+
}
9+

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const extensionConfig = {
6262
},
6363
{
6464
test: /\.css$/,
65-
use: [MiniCssExtractPlugin.loader, 'css-loader'],
65+
use: [MiniCssExtractPlugin.loader, 'css-loader', 'style-loader', 'postcss-loader'],
6666
},
6767
],
6868
},

0 commit comments

Comments
 (0)