cadl/packages/playground
Timothee Guerin 7aa6b682a6
Bump version for 0.62.0 release (#4980)
2024-11-05 21:33:01 +00:00
..
.storybook Custom output viewer (#3465) 2024-06-05 22:56:54 +00:00
definitions Add support for resizing panes in the playground (#2581) 2023-10-18 15:59:03 +00:00
src Fix editor dark theme (#4719) 2024-10-14 16:34:06 +00:00
stories Import openapi3 document in playground (#3750) 2024-07-08 18:20:12 +00:00
CHANGELOG.json Prepare Publish for January Release (#2816) 2024-01-24 11:14:23 -08:00
CHANGELOG.md Bump version for 0.62.0 release (#4980) 2024-11-05 21:33:01 +00:00
README.md Clean up capitalization, parentheses, and phrasing in docs (#2817) 2024-01-25 10:40:16 -08:00
package.json Bump version for 0.62.0 release (#4980) 2024-11-05 21:33:01 +00:00
tsconfig.build.json Add storybook for playground library (#3412) 2024-05-24 02:37:11 +00:00
tsconfig.config.json Vitest improvements: vitest-ui, watch mode for deps, debug config (#2791) 2024-01-22 09:56:55 -08:00
tsconfig.json Bump dependencies - Sep 2024 (#4424) 2024-09-13 15:50:22 +00:00
vite.config.ts Migrate website to astro [Step 1] (#4587) 2024-10-11 01:38:03 +00:00
vite.storybook.config.ts Custom output viewer (#3465) 2024-06-05 22:56:54 +00:00

README.md

TypeSpec Playground

Contains react components for the TypeSpec playground.

It can be used as a standalone custom playground with your own libraries or components can be used individually to customize the UI as you see fit.

Usage

Standalone

The stanalone playground provides some vite helpers to make it easy to get started.

In vite.config.ts:

import { definePlaygroundViteConfig } from "@typespec/playground/vite";

const config = definePlaygroundViteConfig({
  defaultEmitter: "@typespec/openapi3",
  libraries: [
    "@typespec/compiler",
    "@typespec/http",
    "@typespec/openapi3",

    // Add any other libraries here. Make sure those libraries are also dependencies of that package.
  ],
  samples: {
    "My sample": {
      filename: "samples/my.tsp",
      preferredEmitter: "@typespec/openapi3",
    },
  },
  links: {
    documentationUrl: "<link to your website>",
  },
});

export default config;

In src/main.tsx:

import { registerMonacoDefaultWorkersForVite } from "@typespec/playground";
import PlaygroundManifest from "@typespec/playground/manifest";
import { renderReactPlayground } from "@typespec/playground/react";
import { SwaggerUIViewer } from "@typespec/playground/react/viewers";

// Import styles
import "@typespec/playground/styles.css";

registerMonacoDefaultWorkersForVite();

await renderReactPlayground({
  ...PlaygroundManifest,
  emitterViewers: {
    "@typespec/openapi3": [SwaggerUIViewer],
  },
});

Individual components

Playground react components can be used individually. For the TypeSpec compiler to be working correctly, the following conditions need to be met: