@stainless-api/playgrounds 0.0.1-beta.2 → 0.0.1-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +151 -0
- package/eslint.config.js +1 -1
- package/package.json +15 -13
- package/src/build-py-types.ts +2 -2
- package/src/codemirror/comlink.ts +1 -4
- package/src/codemirror/fix-lsp-markdown.ts +1 -2
- package/src/codemirror/python.ts +5 -7
- package/src/codemirror/react.tsx +4 -13
- package/src/codemirror/shiki.ts +1 -2
- package/src/codemirror/typescript/worker.ts +1 -1
- package/src/codemirror/typescript.tsx +6 -8
- package/src/config.ts +43 -0
- package/src/create.tsx +11 -6
- package/src/virtual-module.d.ts +0 -41
- package/test/stl-starlight-virtual-module-assertions.ts +26 -0
- package/test/vite-env.d.ts +1 -0
- package/tsconfig.json +2 -1
- package/tsconfig.test.json +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,156 @@
|
|
|
1
1
|
# @stainless-api/playgrounds
|
|
2
2
|
|
|
3
|
+
## 0.0.1-beta.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3411ffe]
|
|
8
|
+
- Updated dependencies [7439be7]
|
|
9
|
+
- @stainless-api/docs-ui@0.1.0-beta.64
|
|
10
|
+
- @stainless/sdk-json@0.1.0-beta.4
|
|
11
|
+
|
|
12
|
+
## 0.0.1-beta.19
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [274cefc]
|
|
17
|
+
- @stainless-api/docs-ui@0.1.0-beta.63
|
|
18
|
+
|
|
19
|
+
## 0.0.1-beta.18
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [6ef241e]
|
|
24
|
+
- Updated dependencies [d3a85b5]
|
|
25
|
+
- Updated dependencies [d3a85b5]
|
|
26
|
+
- Updated dependencies [2dcb5fb]
|
|
27
|
+
- @stainless-api/docs-ui@0.1.0-beta.62
|
|
28
|
+
|
|
29
|
+
## 0.0.1-beta.17
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [3037a19]
|
|
34
|
+
- @stainless-api/ui-primitives@0.1.0-beta.45
|
|
35
|
+
- @stainless-api/docs-ui@0.1.0-beta.61
|
|
36
|
+
|
|
37
|
+
## 0.0.1-beta.16
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [b4b51f7]
|
|
42
|
+
- @stainless-api/ui-primitives@0.1.0-beta.44
|
|
43
|
+
- @stainless-api/docs-ui@0.1.0-beta.60
|
|
44
|
+
|
|
45
|
+
## 0.0.1-beta.15
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [32b2c88]
|
|
50
|
+
- Updated dependencies [6fd3625]
|
|
51
|
+
- Updated dependencies [98166fd]
|
|
52
|
+
- @stainless-api/docs-ui@0.1.0-beta.59
|
|
53
|
+
- @stainless/sdk-json@0.1.0-beta.3
|
|
54
|
+
|
|
55
|
+
## 0.0.1-beta.14
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [1b04416]
|
|
60
|
+
- Updated dependencies [905cdac]
|
|
61
|
+
- @stainless-api/docs-ui@0.1.0-beta.58
|
|
62
|
+
|
|
63
|
+
## 0.0.1-beta.13
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [6eb6d38]
|
|
68
|
+
- Updated dependencies [7bc8f4e]
|
|
69
|
+
- Updated dependencies [2f6b86d]
|
|
70
|
+
- @stainless-api/docs-ui@0.1.0-beta.57
|
|
71
|
+
- @stainless-api/ui-primitives@0.1.0-beta.43
|
|
72
|
+
|
|
73
|
+
## 0.0.1-beta.12
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Updated dependencies [2d82e2e]
|
|
78
|
+
- @stainless-api/ui-primitives@0.1.0-beta.42
|
|
79
|
+
- @stainless-api/docs-ui@0.1.0-beta.56
|
|
80
|
+
|
|
81
|
+
## 0.0.1-beta.11
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Updated dependencies [750c348]
|
|
86
|
+
- @stainless-api/ui-primitives@0.1.0-beta.41
|
|
87
|
+
- @stainless-api/docs-ui@0.1.0-beta.55
|
|
88
|
+
|
|
89
|
+
## 0.0.1-beta.10
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- Updated dependencies [67aa6b5]
|
|
94
|
+
- @stainless-api/docs-ui@0.1.0-beta.54
|
|
95
|
+
|
|
96
|
+
## 0.0.1-beta.9
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- Updated dependencies [e9567b0]
|
|
101
|
+
- @stainless-api/ui-primitives@0.1.0-beta.40
|
|
102
|
+
- @stainless-api/docs-ui@0.1.0-beta.53
|
|
103
|
+
|
|
104
|
+
## 0.0.1-beta.8
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- Updated dependencies [5d6e5fa]
|
|
109
|
+
- @stainless-api/ui-primitives@0.1.0-beta.39
|
|
110
|
+
- @stainless-api/docs-ui@0.1.0-beta.52
|
|
111
|
+
|
|
112
|
+
## 0.0.1-beta.7
|
|
113
|
+
|
|
114
|
+
### Patch Changes
|
|
115
|
+
|
|
116
|
+
- Updated dependencies [2a79bae]
|
|
117
|
+
- @stainless-api/ui-primitives@0.1.0-beta.38
|
|
118
|
+
- @stainless-api/docs-ui@0.1.0-beta.51
|
|
119
|
+
|
|
120
|
+
## 0.0.1-beta.6
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- Updated dependencies [2d00f0d]
|
|
125
|
+
- @stainless-api/docs-ui@0.1.0-beta.50
|
|
126
|
+
- @stainless-api/ui-primitives@0.1.0-beta.37
|
|
127
|
+
|
|
128
|
+
## 0.0.1-beta.5
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- Updated dependencies [af090c3]
|
|
133
|
+
- Updated dependencies [4cf4aa5]
|
|
134
|
+
- Updated dependencies [8886c7c]
|
|
135
|
+
- @stainless-api/docs-ui@0.1.0-beta.49
|
|
136
|
+
- @stainless-api/ui-primitives@0.1.0-beta.36
|
|
137
|
+
|
|
138
|
+
## 0.0.1-beta.4
|
|
139
|
+
|
|
140
|
+
### Patch Changes
|
|
141
|
+
|
|
142
|
+
- Updated dependencies [ada37ee]
|
|
143
|
+
- @stainless-api/docs-ui@0.1.0-beta.48
|
|
144
|
+
|
|
145
|
+
## 0.0.1-beta.3
|
|
146
|
+
|
|
147
|
+
### Patch Changes
|
|
148
|
+
|
|
149
|
+
- Updated dependencies [d75a72f]
|
|
150
|
+
- Updated dependencies [2464347]
|
|
151
|
+
- @stainless/sdk-json@0.1.0-beta.2
|
|
152
|
+
- @stainless-api/docs-ui@0.1.0-beta.47
|
|
153
|
+
|
|
3
154
|
## 0.0.1-beta.2
|
|
4
155
|
|
|
5
156
|
### Patch Changes
|
package/eslint.config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { config } from '@stainless/eslint-config/
|
|
1
|
+
import { config } from '@stainless/eslint-config/base';
|
|
2
2
|
export default config;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stainless-api/playgrounds",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./src/index.ts",
|
|
10
|
+
"./build": "./src/build.ts",
|
|
10
11
|
"./package.json": "./package.json"
|
|
11
12
|
},
|
|
12
13
|
"peerDependencies": {
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"@codemirror/view": "^6.38.2",
|
|
30
31
|
"@preact/signals-core": "^1.12.1",
|
|
31
32
|
"@replit/codemirror-vscode-keymap": "^6.0.2",
|
|
32
|
-
"@shikijs/types": "^3.
|
|
33
|
+
"@shikijs/types": "^3.21.0",
|
|
33
34
|
"@stainless-api/codemirror-ts": "^3.0.1",
|
|
34
35
|
"@typescript/vfs": "^1.6.1",
|
|
35
36
|
"clsx": "^2.1.1",
|
|
@@ -37,33 +38,34 @@
|
|
|
37
38
|
"dompurify": "^3.2.6",
|
|
38
39
|
"js-tokens": "^9.0.1",
|
|
39
40
|
"lines-and-columns": "^2.0.4",
|
|
40
|
-
"lucide-react": "^0.
|
|
41
|
-
"marked": "^
|
|
42
|
-
"shiki": "^3.
|
|
41
|
+
"lucide-react": "^0.562.0",
|
|
42
|
+
"marked": "^17.0.1",
|
|
43
|
+
"shiki": "^3.21.0",
|
|
43
44
|
"source-map": "^0.7.6",
|
|
44
45
|
"type-fest": "^5.3.0",
|
|
45
46
|
"unenv": "^1.10.0",
|
|
46
47
|
"vite-plugin-prebundle-workers": "^0.2.0",
|
|
47
48
|
"vscode-languageserver-protocol": "^3.17.5",
|
|
48
|
-
"@stainless-api/docs-ui": "0.1.0-beta.
|
|
49
|
-
"@stainless-api/ui-primitives": "0.1.0-beta.
|
|
50
|
-
"@stainless/sdk-json": "^0.1.0-beta.
|
|
49
|
+
"@stainless-api/docs-ui": "0.1.0-beta.64",
|
|
50
|
+
"@stainless-api/ui-primitives": "0.1.0-beta.45",
|
|
51
|
+
"@stainless/sdk-json": "^0.1.0-beta.4"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@types/
|
|
54
|
+
"@types/is-callable": "^1.1.2",
|
|
55
|
+
"@types/node": "24.10.9",
|
|
54
56
|
"@types/react": "19.2.7",
|
|
55
57
|
"@types/react-dom": "^19.2.3",
|
|
56
58
|
"is-callable": "^1.2.7",
|
|
57
59
|
"pyodide": "^0.28.2",
|
|
58
|
-
"react": "^19.2.
|
|
59
|
-
"react-dom": "^19.2.
|
|
60
|
+
"react": "^19.2.3",
|
|
61
|
+
"react-dom": "^19.2.3",
|
|
60
62
|
"typescript": "5.9.3",
|
|
61
63
|
"vite": "^6.4.1",
|
|
62
|
-
"@stainless/eslint-config": "0.1.0-beta.
|
|
64
|
+
"@stainless/eslint-config": "0.1.0-beta.1"
|
|
63
65
|
},
|
|
64
66
|
"scripts": {
|
|
65
67
|
"lint": "eslint .",
|
|
66
|
-
"check:types": "tsc --noEmit",
|
|
68
|
+
"check:types": "tsc --noEmit && tsc -p ./tsconfig.test.json",
|
|
67
69
|
"test": "node --test"
|
|
68
70
|
}
|
|
69
71
|
}
|
package/src/build-py-types.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { promises as fs, globSync } from 'fs';
|
|
|
2
2
|
import path, { dirname, resolve } from 'path';
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import { glob, readdir, realpath, writeFile } from 'fs/promises';
|
|
5
|
-
import type
|
|
5
|
+
import { type pyTypes } from './config';
|
|
6
6
|
import { execCommand } from './util';
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
|
|
@@ -143,7 +143,7 @@ export async function buildPythonTypes(typesPath: string, installPackage: string
|
|
|
143
143
|
JSON.stringify({
|
|
144
144
|
files: files,
|
|
145
145
|
wheel: wheelPath,
|
|
146
|
-
} satisfies typeof
|
|
146
|
+
} satisfies typeof pyTypes),
|
|
147
147
|
),
|
|
148
148
|
]);
|
|
149
149
|
} finally {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-misused-new */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-misused-new, @typescript-eslint/no-explicit-any */
|
|
5
2
|
/**
|
|
6
3
|
* @license
|
|
7
4
|
* Copyright 2019 Google LLC
|
|
@@ -2,8 +2,7 @@ import { LSPPlugin } from '@codemirror/lsp-client';
|
|
|
2
2
|
import { Marked } from 'marked';
|
|
3
3
|
import { sanitizeHTML } from './sanitize-html';
|
|
4
4
|
import { highlighter } from './shiki';
|
|
5
|
-
|
|
6
|
-
import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
|
|
5
|
+
import { HIGHLIGHT_THEMES } from '../config';
|
|
7
6
|
type MarkupKind = 'plaintext' | 'markdown';
|
|
8
7
|
interface MarkupContent {
|
|
9
8
|
/**
|
package/src/codemirror/python.ts
CHANGED
|
@@ -5,17 +5,15 @@ import type { Language } from './react';
|
|
|
5
5
|
import { proxy, releaseProxy, type Remote, wrap } from './comlink';
|
|
6
6
|
import type { API } from './python/pyodide';
|
|
7
7
|
import type { Logger } from '../Logs';
|
|
8
|
-
import wheelUrl from '
|
|
9
|
-
import pyTypes from 'virtual:stl-playground/python.json';
|
|
10
|
-
|
|
11
|
-
if (!pyTypes) {
|
|
12
|
-
throw new Error('Python playgrounds failed to build.');
|
|
13
|
-
}
|
|
8
|
+
import { pyTypes, wheelUrl } from '../config.js';
|
|
14
9
|
|
|
15
10
|
const pyrightWorkerURL = 'https://cdn.jsdelivr.net/npm/browser-basedpyright@1.33.0/dist/pyright.worker.js';
|
|
16
11
|
|
|
17
|
-
const wheelBlobPromise = fetch(wheelUrl).then((e) => e.blob());
|
|
18
12
|
export async function createPyright(signal: AbortSignal, doc: string): Promise<Language> {
|
|
13
|
+
const wheelBlobPromise = fetch(wheelUrl).then((e) => e.blob());
|
|
14
|
+
if (!pyTypes) {
|
|
15
|
+
throw new Error('Python playgrounds failed to build.');
|
|
16
|
+
}
|
|
19
17
|
const { SandboxWorker } = await import('../sandbox-worker/index.js');
|
|
20
18
|
let pyodideWorker: Worker;
|
|
21
19
|
let pyodideAPI: Remote<API>;
|
package/src/codemirror/react.tsx
CHANGED
|
@@ -13,17 +13,11 @@ import type { Completion } from '@codemirror/autocomplete';
|
|
|
13
13
|
import { Button, Dropdown } from '@stainless-api/ui-primitives';
|
|
14
14
|
import { PlaygroundIcon } from '../icon.tsx';
|
|
15
15
|
import { initDropdown } from '@stainless-api/ui-primitives/scripts';
|
|
16
|
-
// @ts-expect-error TODO: make independent from stl-starlight
|
|
17
|
-
import { navigate } from 'astro:transitions/client';
|
|
18
|
-
// @ts-expect-error TODO: make independent from stl-starlight
|
|
19
|
-
import { updateSelectedLanguage } from 'virtual:stl-playground/unstable-update-language';
|
|
20
|
-
// @ts-expect-error TODO: make independent from stl-starlight
|
|
21
|
-
import { BASE_PATH } from 'virtual:stl-starlight-virtual-module';
|
|
22
|
-
import authData from 'virtual:stl-playground/auth.json';
|
|
23
16
|
import { Panel } from '../Panel.tsx';
|
|
24
17
|
import { PlaygroundPanelWrapper } from '../PlaygroundPanelWrapper.tsx';
|
|
25
18
|
import { MaskedInput } from '@stainless-api/docs-ui/components/MaskedInput';
|
|
26
19
|
import useStorage from '../use-storage.ts';
|
|
20
|
+
import { authData } from '../config.ts';
|
|
27
21
|
|
|
28
22
|
let codeMirrorPromise: Promise<typeof import('./deps.ts')>;
|
|
29
23
|
function loadCodeMirror(): Promise<typeof import('./deps.ts')> {
|
|
@@ -347,12 +341,14 @@ export const Editor = ({
|
|
|
347
341
|
container,
|
|
348
342
|
onLoad,
|
|
349
343
|
unmount,
|
|
344
|
+
onLanguageSelect,
|
|
350
345
|
}: {
|
|
351
346
|
lang: PlaygroundLanguage;
|
|
352
347
|
doc: string;
|
|
353
348
|
container: HTMLElement;
|
|
354
349
|
onLoad: (onShow: () => void) => void;
|
|
355
350
|
unmount: () => void;
|
|
351
|
+
onLanguageSelect: ((value: string) => void) | undefined;
|
|
356
352
|
}) => {
|
|
357
353
|
const titleNode = useMemo(
|
|
358
354
|
() => container.querySelector('.stldocs-snippet-request-title-method')!.cloneNode(true),
|
|
@@ -366,12 +362,7 @@ export const Editor = ({
|
|
|
366
362
|
prefixIds(clone, idPrefix);
|
|
367
363
|
initDropdown({
|
|
368
364
|
root: clone.querySelector('#' + idPrefix + 'stldocs-snippet-select')!,
|
|
369
|
-
onSelect:
|
|
370
|
-
const originalLanguage = document.getElementById(idPrefix + 'stldocs-snippet-select')?.dataset
|
|
371
|
-
.currentValue;
|
|
372
|
-
const path: string = updateSelectedLanguage(BASE_PATH, originalLanguage, value);
|
|
373
|
-
navigate(path.replace(/(\?.+)?($|#)/, (_, str, end) => (str ? str + '&play' : '?play') + end));
|
|
374
|
-
},
|
|
365
|
+
onSelect: onLanguageSelect,
|
|
375
366
|
});
|
|
376
367
|
return clone;
|
|
377
368
|
}, [container]);
|
package/src/codemirror/shiki.ts
CHANGED
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
} from '@codemirror/view';
|
|
10
10
|
import { SupportedLanguageSyntaxes } from '@stainless-api/docs-ui/routing';
|
|
11
11
|
import { createHighlighter } from 'shiki';
|
|
12
|
-
|
|
13
|
-
import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
|
|
12
|
+
import { HIGHLIGHT_THEMES } from '../config';
|
|
14
13
|
export const highlighter = await createHighlighter({
|
|
15
14
|
themes: [HIGHLIGHT_THEMES?.dark ?? 'github-dark', HIGHLIGHT_THEMES?.light ?? 'github-light'],
|
|
16
15
|
langs: SupportedLanguageSyntaxes,
|
|
@@ -8,7 +8,7 @@ import estree from 'prettier/plugins/estree';
|
|
|
8
8
|
import { SourceMapConsumer } from 'source-map';
|
|
9
9
|
import { LinesAndColumns } from 'lines-and-columns';
|
|
10
10
|
|
|
11
|
-
type TypescriptTypes = NonNullable<typeof import('
|
|
11
|
+
type TypescriptTypes = NonNullable<typeof import('../../config').tsTypes>;
|
|
12
12
|
|
|
13
13
|
// @ts-expect-error this is kinda awful but it makes ts autocomplete work without source patching
|
|
14
14
|
Object.prototype.keepLegacyLimitationForAutocompletionSymbols = false;
|
|
@@ -10,15 +10,10 @@ import type { Language } from './react';
|
|
|
10
10
|
import { proxy, type Remote } from './comlink';
|
|
11
11
|
import type { Logger } from '../Logs';
|
|
12
12
|
import type { RunnerAPI } from './typescript/runner';
|
|
13
|
-
import typescriptTypes from 'virtual:stl-playground/typescript.json';
|
|
14
|
-
import authData from 'virtual:stl-playground/auth.json';
|
|
15
13
|
import { docToHTML } from './fix-lsp-markdown';
|
|
16
14
|
import { API } from './typescript/worker';
|
|
17
15
|
import { EditorView } from '@codemirror/view';
|
|
18
|
-
|
|
19
|
-
if (!typescriptTypes) {
|
|
20
|
-
throw new Error('TypeScript playgrounds failed to build.');
|
|
21
|
-
}
|
|
16
|
+
import { authData, tsTypes } from '../config.js';
|
|
22
17
|
|
|
23
18
|
function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string {
|
|
24
19
|
if (displayParts) {
|
|
@@ -53,7 +48,7 @@ const useMeta = /iPad|iPhone|iPod|Mac/.test(navigator.userAgent);
|
|
|
53
48
|
type GoToOptions = {
|
|
54
49
|
gotoHandler?: (currentPath: string, hoverData: HoverInfo, view: EditorView) => true | undefined;
|
|
55
50
|
};
|
|
56
|
-
|
|
51
|
+
function tsGoto(opts: GoToOptions = {}) {
|
|
57
52
|
return EditorView.domEventHandlers({
|
|
58
53
|
mousedown: (event, view) => {
|
|
59
54
|
const config = view.state.facet(tsFacet);
|
|
@@ -87,12 +82,15 @@ export function tsGoto(opts: GoToOptions = {}) {
|
|
|
87
82
|
}
|
|
88
83
|
|
|
89
84
|
export async function createTypescript(signal: AbortSignal, doc: string): Promise<Language> {
|
|
85
|
+
if (!tsTypes) {
|
|
86
|
+
throw new Error('TypeScript playgrounds failed to build.');
|
|
87
|
+
}
|
|
90
88
|
const { SandboxWorker } = await import('../sandbox-worker/index.js');
|
|
91
89
|
const innerWorker: Worker = new SandboxWorker(tsWorkerURL, { name: 'typescript' });
|
|
92
90
|
signal.addEventListener('abort', () => innerWorker.terminate());
|
|
93
91
|
const worker = Comlink.wrap<API>(innerWorker);
|
|
94
92
|
await worker.stlInit({
|
|
95
|
-
typescriptTypes:
|
|
93
|
+
typescriptTypes: tsTypes,
|
|
96
94
|
suggestedEnv: authData!
|
|
97
95
|
.flatMap((e) => e.opts)
|
|
98
96
|
.map((e) => e.read_env)
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// having global state is icky but it's the fastest path rn
|
|
2
|
+
export let wheelUrl: string;
|
|
3
|
+
export let pyTypes: { files: Record<string, string>; wheel: string } | null;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
export let HIGHLIGHT_THEMES: any;
|
|
6
|
+
export let tsTypes: {
|
|
7
|
+
links: [string, string][];
|
|
8
|
+
files: [string, string][];
|
|
9
|
+
} | null;
|
|
10
|
+
export let authData:
|
|
11
|
+
| ({
|
|
12
|
+
type: 'http_bearer' | 'query' | 'header' | 'oauth2' | 'http_basic' | 'http_digest';
|
|
13
|
+
description?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
title: string;
|
|
16
|
+
header: string | undefined;
|
|
17
|
+
example: string | undefined;
|
|
18
|
+
} & {
|
|
19
|
+
opts: {
|
|
20
|
+
name: string;
|
|
21
|
+
type: 'string' | 'number' | 'boolean' | 'null' | 'integer';
|
|
22
|
+
nullable: boolean;
|
|
23
|
+
description?: string | undefined;
|
|
24
|
+
example?: unknown;
|
|
25
|
+
default?: unknown;
|
|
26
|
+
read_env?: string | undefined;
|
|
27
|
+
auth?:
|
|
28
|
+
| {
|
|
29
|
+
security_scheme: string;
|
|
30
|
+
role?: 'value' | 'password' | 'username' | 'client_id' | 'client_secret' | undefined;
|
|
31
|
+
}
|
|
32
|
+
| undefined;
|
|
33
|
+
}[];
|
|
34
|
+
})[]
|
|
35
|
+
| null;
|
|
36
|
+
export type Config = Omit<typeof import('./config'), 'configure'>;
|
|
37
|
+
export function configure(options: Config): void {
|
|
38
|
+
HIGHLIGHT_THEMES = options.HIGHLIGHT_THEMES;
|
|
39
|
+
authData = options.authData;
|
|
40
|
+
pyTypes = options.pyTypes;
|
|
41
|
+
tsTypes = options.tsTypes;
|
|
42
|
+
wheelUrl = options.wheelUrl;
|
|
43
|
+
}
|
package/src/create.tsx
CHANGED
|
@@ -4,15 +4,20 @@ import { signal } from '@preact/signals-core';
|
|
|
4
4
|
import { Editor } from './codemirror/react';
|
|
5
5
|
import { LogsContext } from './logs-context';
|
|
6
6
|
import './playground.css';
|
|
7
|
+
import { Config, configure } from './config';
|
|
7
8
|
|
|
8
9
|
export type PlaygroundLanguage = 'python' | 'typescript' | 'http';
|
|
9
10
|
|
|
10
|
-
export function createPlayground(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export function createPlayground(
|
|
12
|
+
props: {
|
|
13
|
+
lang: PlaygroundLanguage;
|
|
14
|
+
doc: string;
|
|
15
|
+
/** div.stl-snippet-request-container */
|
|
16
|
+
container: HTMLElement;
|
|
17
|
+
onLanguageSelect: (value: string) => void;
|
|
18
|
+
} & Config,
|
|
19
|
+
): () => Promise<void> {
|
|
20
|
+
configure(props);
|
|
16
21
|
const ready = new Promise<{ element: HTMLDivElement; onShow(): void }>((resolve) => {
|
|
17
22
|
const element = document.createElement('div');
|
|
18
23
|
const root = createRoot(element);
|
package/src/virtual-module.d.ts
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
type CreatePlayground = typeof import('./create').createPlayground;
|
|
2
1
|
type ComlinkRemote<T> = import('./codemirror/comlink').Remote<T>;
|
|
3
|
-
declare module 'virtual:stl-playground/typescript.json' {
|
|
4
|
-
const data: {
|
|
5
|
-
links: [string, string][];
|
|
6
|
-
files: [string, string][];
|
|
7
|
-
} | null;
|
|
8
|
-
export { data as default };
|
|
9
|
-
}
|
|
10
|
-
declare module 'virtual:stl-playground/python.json' {
|
|
11
|
-
const data: { files: Record<string, string>; wheel: string } | null;
|
|
12
|
-
export { data as default };
|
|
13
|
-
}
|
|
14
|
-
declare module 'virtual:stl-playground/auth.json' {
|
|
15
|
-
const data:
|
|
16
|
-
| ({
|
|
17
|
-
type: 'http_bearer' | 'query' | 'header' | 'oauth2' | 'http_basic' | 'http_digest';
|
|
18
|
-
description?: string;
|
|
19
|
-
name: string;
|
|
20
|
-
title: string;
|
|
21
|
-
header: string | undefined;
|
|
22
|
-
example: string | undefined;
|
|
23
|
-
} & {
|
|
24
|
-
opts: {
|
|
25
|
-
name: string;
|
|
26
|
-
type: 'string' | 'number' | 'boolean' | 'null' | 'integer';
|
|
27
|
-
nullable: boolean;
|
|
28
|
-
description?: string | undefined;
|
|
29
|
-
example?: unknown;
|
|
30
|
-
default?: unknown;
|
|
31
|
-
read_env?: string | undefined;
|
|
32
|
-
auth?:
|
|
33
|
-
| {
|
|
34
|
-
security_scheme: string;
|
|
35
|
-
role?: 'value' | 'password' | 'username' | 'client_id' | 'client_secret' | undefined;
|
|
36
|
-
}
|
|
37
|
-
| undefined;
|
|
38
|
-
}[];
|
|
39
|
-
})[]
|
|
40
|
-
| null;
|
|
41
|
-
export { data as default };
|
|
42
|
-
}
|
|
43
2
|
declare module 'comlink' {
|
|
44
3
|
type Remote<T> = ComlinkRemote<T>;
|
|
45
4
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/// <reference types="../../stl-starlight/virtual-module" />
|
|
3
|
+
type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
|
|
4
|
+
type Equal<T, U> =
|
|
5
|
+
IsAny<T> extends true ? IsAny<U> : [T] extends [U] ? ([U] extends [T] ? true : false) : false;
|
|
6
|
+
type Assert<T extends true> = T;
|
|
7
|
+
|
|
8
|
+
type _1 = Assert<Equal<typeof import('virtual:stl-playground/create'), typeof import('../src/create')>>;
|
|
9
|
+
type _2 = Assert<
|
|
10
|
+
Equal<
|
|
11
|
+
(typeof import('virtual:stl-playground/create'))['createPlayground'],
|
|
12
|
+
(typeof import('../src/create'))['createPlayground']
|
|
13
|
+
>
|
|
14
|
+
>;
|
|
15
|
+
type _3 = Assert<
|
|
16
|
+
Equal<
|
|
17
|
+
Parameters<(typeof import('virtual:stl-playground/create'))['createPlayground']>,
|
|
18
|
+
Parameters<(typeof import('../src/create'))['createPlayground']>
|
|
19
|
+
>
|
|
20
|
+
>;
|
|
21
|
+
type _4 = Assert<
|
|
22
|
+
Equal<
|
|
23
|
+
ReturnType<(typeof import('virtual:stl-playground/create'))['createPlayground']>,
|
|
24
|
+
ReturnType<(typeof import('../src/create'))['createPlayground']>
|
|
25
|
+
>
|
|
26
|
+
>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"types": ["node"],
|
|
4
5
|
"noEmit": false,
|
|
5
6
|
"declaration": true,
|
|
6
7
|
"declarationDir": "dist",
|
|
7
8
|
"outDir": "dist",
|
|
8
9
|
"jsx": "react-jsx"
|
|
9
10
|
},
|
|
10
|
-
"include": ["src"]
|
|
11
|
+
"include": ["src", "*.config.*"]
|
|
11
12
|
}
|