Skip to content

Commit 1cd38e2

Browse files
committed
feat: add json support for instruments
1 parent 362c3cf commit 1cd38e2

File tree

10 files changed

+26
-5
lines changed

10 files changed

+26
-5
lines changed

apps/playground/src/components/Editor/Editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const Editor = () => {
145145
/>
146146
<FileUploadDialog
147147
accept={{
148+
'application/json': ['.json'],
148149
'image/jpeg': ['.jpg', '.jpeg'],
149150
'image/png': ['.png'],
150151
'image/webp': ['.webp'],

apps/playground/src/components/Editor/EditorFileIcon.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ export const EditorFileIcon = ({ filename }: EditorFileIconProps) => {
108108
/>
109109
</svg>
110110
))
111+
.with('.json', () => (
112+
<svg viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg">
113+
<path
114+
d="M560-160v-80h120q17 0 28.5-11.5T720-280v-80q0-38 22-69t58-44v-14q-36-13-58-44t-22-69v-80q0-17-11.5-28.5T680-720H560v-80h120q50 0 85 35t35 85v80q0 17 11.5 28.5T840-560h40v160h-40q-17 0-28.5 11.5T800-360v80q0 50-35 85t-85 35zm-280 0q-50 0-85-35t-35-85v-80q0-17-11.5-28.5T120-400H80v-160h40q17 0 28.5-11.5T160-600v-80q0-50 35-85t85-35h120v80H280q-17 0-28.5 11.5T240-680v80q0 38-22 69t-58 44v14q36 13 58 44t22 69v80q0 17 11.5 28.5T280-240h120v80z"
115+
fill="#f9a825"
116+
/>
117+
</svg>
118+
))
111119
.otherwise(() => (
112120
<FileIcon />
113121
))}

apps/playground/src/components/Editor/EditorPane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const EditorPane = React.forwardRef<EditorPaneRef, EditorPaneProps>(funct
136136
return (
137137
<MonacoEditor
138138
className="h-full min-h-[576px]"
139-
defaultLanguage={fileType satisfies 'css' | 'html' | 'javascript' | 'typescript'}
139+
defaultLanguage={fileType satisfies 'css' | 'html' | 'javascript' | 'json' | 'typescript'}
140140
defaultValue={defaultFile.content}
141141
keepCurrentModel={true}
142142
key={defaultFile.id}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"timeLimit": 15
3+
}

apps/playground/src/instruments/examples/interactive/Interactive-With-Embedded-Video/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { createRoot } from '/runtime/v1/[email protected]/client.js';
44
import { z } from '/runtime/v1/[email protected]';
55

66
import catVideo from './cat-video.mp4';
7+
import config from './config.json';
78

89
const Task: React.FC<{ done: (data: { success: boolean }) => void }> = ({ done }) => {
9-
const [secondsRemaining, setSecondsRemaining] = useState(15);
10+
const [secondsRemaining, setSecondsRemaining] = useState<number>(config.timeLimit);
1011
const [value, setValue] = useState('');
1112

1213
useEffect(() => {

apps/playground/src/instruments/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { loadAssetAsBase64 } from '@/utils/load';
77
// Instruments in development
88
const EXCLUDED_LABELS: string[] = [];
99

10-
const textFiles: { [key: string]: string } = import.meta.glob('./**/*.{css,js,jsx,ts,tsx,svg}', {
10+
const textFiles: { [key: string]: string } = import.meta.glob('./**/*.{css,js,jsx,json,ts,tsx,svg}', {
1111
eager: true,
1212
import: 'default',
1313
query: '?raw'

apps/playground/src/utils/file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { match, P } from 'ts-pattern';
44

55
import type { EditorFile } from '@/models/editor-file.model';
66

7-
export type FileType = 'asset' | 'css' | 'html' | 'javascript' | 'typescript';
7+
export type FileType = 'asset' | 'css' | 'html' | 'javascript' | 'json' | 'typescript';
88

99
export function inferFileType(filename: string): FileType | null {
1010
return match(extractInputFileExtension(filename))
@@ -13,6 +13,7 @@ export function inferFileType(filename: string): FileType | null {
1313
.with(P.union('.ts', '.tsx'), () => 'typescript' as const)
1414
.with(P.union('.jpeg', '.jpg', '.png', '.webp', '.mp4'), () => 'asset' as const)
1515
.with(P.union('.html', '.svg'), () => 'html' as const)
16+
.with('.json', () => 'json' as const)
1617
.with(null, () => null)
1718
.exhaustive();
1819
}

packages/instrument-bundler/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type BundlerInputFileExtension =
44
| '.jpeg'
55
| '.jpg'
66
| '.js'
7+
| '.json'
78
| '.jsx'
89
| '.mp4'
910
| '.png'

packages/instrument-bundler/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { BundlerInputFileExtension } from './types.js';
66
import type { Loader } from './vendor/esbuild.js';
77

88
export function extractInputFileExtension(filename: string) {
9-
const ext = /\.(css|html|jpeg|jpg|js|jsx|mp4|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
9+
const ext = /\.(css|html|jpeg|jpg|js|jsx|json|mp4|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
1010
return (ext ?? null) as BundlerInputFileExtension | null;
1111
}
1212

@@ -16,6 +16,7 @@ export function inferLoader(filename: string): Loader {
1616
.with('.html', () => 'text' as const)
1717
.with('.js', () => 'js' as const)
1818
.with('.jsx', () => 'jsx' as const)
19+
.with('.json', () => 'json' as const)
1920
.with('.ts', () => 'ts' as const)
2021
.with('.tsx', () => 'tsx' as const)
2122
.with(P.union('.jpeg', '.jpg', '.png', '.svg', '.webp', '.mp4'), () => 'dataurl' as const)

runtime/v1/env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ declare module '*.mp4' {
3333
export default src;
3434
}
3535

36+
declare module '*.json' {
37+
const src: any;
38+
export default src;
39+
}
40+
3641
declare module 'react/jsx-runtime' {
3742
export * from '/runtime/v1/[email protected]/jsx-runtime';
3843
}

0 commit comments

Comments
 (0)