Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeGraph Viewer V2 #3713

Merged
merged 71 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
977d5fa
Initial migration
timotheeguerin Jun 14, 2024
d86f968
Initial tree view
timotheeguerin Jun 14, 2024
fae2b61
Extra splitpane into separate package
timotheeguerin Jun 14, 2024
009187e
navigation with split pane
timotheeguerin Jun 14, 2024
a1b6fd4
Fix console errors
timotheeguerin Jun 14, 2024
264ed2e
Compute separately
timotheeguerin Jun 15, 2024
c259c7d
Navigator
timotheeguerin Jun 15, 2024
f0b02d9
Basic list
timotheeguerin Jun 15, 2024
efdcc06
Basics
timotheeguerin Jun 15, 2024
a9161ee
Progress
timotheeguerin Jun 15, 2024
dab86b7
ADd basic type data
timotheeguerin Jun 15, 2024
5811cf1
progress
timotheeguerin Jun 15, 2024
3ef59b1
Config for all types
timotheeguerin Jun 16, 2024
b6e1623
.
timotheeguerin Jun 16, 2024
00ead6a
navigator context
timotheeguerin Jun 16, 2024
aa2ab84
Navigate
timotheeguerin Jun 16, 2024
442c3ca
rename
timotheeguerin Jun 16, 2024
0e5e77e
Nav to other types
timotheeguerin Jun 16, 2024
43ca99f
Tweaks
timotheeguerin Jun 16, 2024
829ab49
Breadcrumbs
timotheeguerin Jun 16, 2024
d29958c
Tweaks
timotheeguerin Jun 16, 2024
a767dbb
Progress
timotheeguerin Jun 16, 2024
b674fce
custom tree
timotheeguerin Jun 16, 2024
4b98678
Basic
timotheeguerin Jun 16, 2024
7c47948
Better keyboard nav
timotheeguerin Jun 16, 2024
deffd08
Fix
timotheeguerin Jun 16, 2024
303bbb5
Expand
timotheeguerin Jun 17, 2024
1d7c549
Add icons
timotheeguerin Jun 17, 2024
59b9066
fix
timotheeguerin Jun 17, 2024
5f2c03c
fix
timotheeguerin Jun 17, 2024
01a6567
fix divider type
timotheeguerin Jun 17, 2024
96f4739
Tweaks
timotheeguerin Jun 17, 2024
42f2258
Basic Search
timotheeguerin Jun 17, 2024
ad4cf52
.
timotheeguerin Jun 17, 2024
ddb88a9
Focus fix
timotheeguerin Jun 17, 2024
54d377d
fix
timotheeguerin Jun 17, 2024
9925bb7
tweak
timotheeguerin Jun 17, 2024
361b618
Search in breadcrumb
timotheeguerin Jun 18, 2024
9258af5
Remove
timotheeguerin Jun 18, 2024
bf33149
organize
timotheeguerin Jun 18, 2024
3d3d068
.
timotheeguerin Jun 18, 2024
50fdb5d
Fork react-inspector
timotheeguerin Jun 24, 2024
45e7b85
use existing tree component
timotheeguerin Jun 24, 2024
271092b
use existing styles
timotheeguerin Jun 24, 2024
d4d3754
tweaks
timotheeguerin Jun 24, 2024
76d3f78
Rename
timotheeguerin Jun 24, 2024
3d27b74
tweaks
timotheeguerin Jun 24, 2024
0144590
tweaks
timotheeguerin Jun 25, 2024
c7b03f5
hotkeys
timotheeguerin Jun 25, 2024
c8bf065
tweaks
timotheeguerin Jun 25, 2024
7387279
basic tests
timotheeguerin Jun 25, 2024
f569d07
fixes
timotheeguerin Jun 25, 2024
ca677ca
revert
timotheeguerin Jun 25, 2024
d926e1f
Move tree to react components lib
timotheeguerin Jun 26, 2024
15efc04
split pane basic tests
timotheeguerin Jun 26, 2024
4ae39b8
resize tests
timotheeguerin Jun 26, 2024
8ab8770
.
timotheeguerin Jun 26, 2024
ed6a292
tree tests
timotheeguerin Jun 26, 2024
b984ef7
html program viewer
timotheeguerin Jul 1, 2024
66c7193
FIx
timotheeguerin Jul 1, 2024
0cfca1f
Create typegraph-v2-2024-6-1-17-14-9.md
timotheeguerin Jul 1, 2024
2dbd08d
more changelogs
timotheeguerin Jul 1, 2024
ac58a9e
fix tests
timotheeguerin Jul 1, 2024
ebb1303
remove only
timotheeguerin Jul 1, 2024
f8f7da7
Merge branch 'main' of https://github.com/Microsoft/typespec into typ…
timotheeguerin Jul 3, 2024
ece2c0b
FIx
timotheeguerin Jul 3, 2024
6a13631
Fix src/
timotheeguerin Jul 3, 2024
52060a0
Fix
timotheeguerin Jul 3, 2024
44c9584
Some organization
timotheeguerin Jul 3, 2024
26f9036
Fix version mismatch
timotheeguerin Jul 3, 2024
200b5a8
Fix
timotheeguerin Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/typegraph-v2-2024-6-1-10-17-30.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/react-components"
---

Initial
7 changes: 7 additions & 0 deletions .chronus/changes/typegraph-v2-2024-6-1-10-17-58.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/playground"
---

Extract splitpane into separate package
8 changes: 8 additions & 0 deletions .chronus/changes/typegraph-v2-2024-6-1-17-14-9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: feature
packages:
- "@typespec/html-program-viewer"
---

Complete new dynamic UI to navigate the TypeSpec type graph
37 changes: 23 additions & 14 deletions packages/html-program-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,66 @@
"typespec"
],
"type": "module",
"main": "dist/src/index.js",
"main": "dist/emitter/index.js",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
"default": "./dist/emitter/index.js"
},
"./testing": {
"types": "./dist/src/testing/index.d.ts",
"default": "./dist/src/testing/index.js"
}
"./react": {
"types": "./dist/src/react/index.d.ts",
"default": "./dist/react/index.js"
},
"./style.css": "./dist/style.css"
},
"tspMain": "dist/src/index.js",
"engines": {
"node": ">=14.0.0"
},
"scripts": {
"clean": "rimraf ./dist ./temp",
"build": "tsc -p .",
"watch": "tsc -p . --watch",
"build": "pnpm build:react && pnpm build:emitter",
"build:react": "vite build",
"build:emitter": "vite build --config vite.emitter.config.ts",
"watch": "vite build --watch",
"test": "vitest run",
"test:ui": "vitest --ui",
"test:ci": "vitest run --coverage --reporter=junit --reporter=default",
"lint": "eslint . --max-warnings=0",
"lint:fix": "eslint . --fix"
},
"files": [
"lib/*.tsp",
"dist/**",
"!dist/test/**"
],
"peerDependencies": {
"@typespec/compiler": "workspace:~"
},
"dependencies": {
"@emotion/react": "^11.11.4",
"prettier": "~3.2.5",
"@fluentui/react-components": "~9.52.0",
"@fluentui/react-icons": "^2.0.240",
"@fluentui/react-list-preview": "^0.2.8",
"react": "~18.3.1",
"react-dom": "~18.3.1",
"react-is": "~18.3.1"
"react-hotkeys-hook": "^4.5.0"
},
"devDependencies": {
"@babel/core": "^7.24.5",
"@testing-library/dom": "^10.2.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/node": "~18.11.19",
"@types/react": "~18.3.2",
"@types/react-dom": "~18.3.0",
"@typespec/compiler": "workspace:~",
"@typespec/react-components": "workspace:~",
"@vitejs/plugin-react": "~4.2.1",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/ui": "^1.6.0",
"c8": "^9.1.0",
"rimraf": "~5.0.7",
"typescript": "~5.4.5",
"vite": "^5.2.11",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.6.0"
}
}
19 changes: 0 additions & 19 deletions packages/html-program-viewer/src/color-provider.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions packages/html-program-viewer/src/common.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions packages/html-program-viewer/src/constants.ts

This file was deleted.

39 changes: 34 additions & 5 deletions packages/html-program-viewer/src/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { EmitContext, emitFile, resolvePath } from "@typespec/compiler";
import { renderProgram } from "./ui.js";

import { createTypeSpecLibrary, JSONSchemaType } from "@typespec/compiler";
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
import {
createTypeSpecLibrary,
emitFile,
getDirectoryPath,
resolvePath,
type EmitContext,
type JSONSchemaType,
type Program,
} from "@typespec/compiler";
import { readFile } from "fs/promises";
import { createElement } from "react";
import ReactDOMServer from "react-dom/server";
import { fileURLToPath } from "url";
import { InspectType } from "./react/inspect-type/inspect-type.js";

export interface HtmlProgramViewerOptions {
/**
Expand All @@ -19,8 +30,18 @@ const EmitterOptionsSchema: JSONSchemaType<HtmlProgramViewerOptions> = {
required: [],
};

export function renderProgram(program: Program) {
const html = ReactDOMServer.renderToString(
createElement(FluentProvider, {
theme: webLightTheme,
children: createElement(InspectType, { entity: program.getGlobalNamespaceType() }),
}) // [1
);
return html;
}

export const libDef = {
name: "@typespec/openapi3",
name: "@typespec/html-program-viewer",
diagnostics: {},
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
emitter: {
options: EmitterOptionsSchema as JSONSchemaType<HtmlProgramViewerOptions>,
Expand All @@ -37,4 +58,12 @@ export async function $onEmit(context: EmitContext<HtmlProgramViewerOptions>) {
path: htmlPath,
content: `<!DOCTYPE html><html lang="en"><link rel="stylesheet" href="style.css"><body>${html}</body></html>`,
});

const css = await readFile(
resolvePath(getDirectoryPath(fileURLToPath(import.meta.url)), "style.css")
);
await emitFile(context.program, {
path: resolvePath(outputDir, "style.css"),
content: css.toString(),
});
}
3 changes: 0 additions & 3 deletions packages/html-program-viewer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export { ColorProvider, ColorProviderProps } from "./color-provider.js";
export type { ColorPalette } from "./constants.js";
export * from "./emitter.js";
export { TypeSpecProgramViewer } from "./ui.js";
57 changes: 0 additions & 57 deletions packages/html-program-viewer/src/inspect.ts

This file was deleted.

26 changes: 26 additions & 0 deletions packages/html-program-viewer/src/react/common.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.mono {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.literal {
color: var(--colorPaletteLightGreenForeground2);
}

.type-kind {
color: var(--colorPaletteBerryForeground2);
}
.type-kind-tag {
color: white;
background-color: var(--colorPaletteBerryForeground2);
border-radius: 2px;
}
.type-kind-tag-small {
height: 16px;
line-height: 16px;
font-size: 10px;
padding: 0 3px;
}

.type-kind-tag-auto {
padding: 1px 5px;
}
24 changes: 24 additions & 0 deletions packages/html-program-viewer/src/react/common.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mergeClasses } from "@fluentui/react-components";
import type { Type } from "@typespec/compiler";
import type { FunctionComponent } from "react";
import style from "./common.module.css";

export const Mono = ({ children, className }: { children: any; className?: string }) => (
<span className={mergeClasses(style["mono"], className)}>{children}</span>
);

export const Literal: FunctionComponent<{ children: any }> = ({ children }) => (
<Mono className={style["literal"]}>{children}</Mono>
);

export const TypeKind = ({ type }: { type: Type }) => {
return <span className={style["type-kind"]}>{type.kind}</span>;
};

export const TypeKindTag = ({ type, size = "auto" }: { type: Type; size?: "small" | "auto" }) => {
return (
<Mono className={mergeClasses(style["type-kind-tag"], style[`type-kind-tag-${size}`])}>
{type.kind}
</Mono>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.current-path {
overflow-y: auto;
border: 1px solid var(--colorNeutralStroke1);
}

.current-path.focus {
border-bottom: 1px solid var(--colorBrandForeground1);
}
.breadcrumb-search {
width: 100%;
border-radius: 0 !important;
border: none !important;
}

.breadcrumb-search::after {
border: none !important;
}

.option {
padding: 2px 4px !important;
}

.option .doc {
color: var(--colorNeutralForeground4);
text-overflow: ellipsis;
text-wrap: nowrap;
min-width: 0;
flex: 0 1 auto;
overflow: hidden;
}

.flex-gap {
flex: 1;
}

.search-placeholder {
color: var(--colorNeutralForeground4);
font-size: 12px;
margin: 5px;
text-wrap: nowrap;
}
Loading
Loading