Skip to content

Commit aa9d36b

Browse files
committed
feat: support html in instruments
1 parent 01214f9 commit aa9d36b

7 files changed

Lines changed: 45 additions & 5 deletions

File tree

apps/playground/src/instruments/index.ts

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

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

packages/react-core/src/components/InteractiveContent/InteractiveContent.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,19 @@ export const InteractiveContent = React.memo<InteractiveContentProps>(function I
121121
lang={resolvedLanguage}
122122
name="interactive-instrument"
123123
ref={iFrameRef}
124-
srcDoc={`<script type="module">${bootstrapScript}</script>`}
124+
srcDoc={[
125+
`<!DOCTYPE html>`,
126+
`<html>`,
127+
`<head>`,
128+
`<meta charset="UTF-8">`,
129+
`<meta name="viewport" content="width=device-width, initial-scale=1.0">`,
130+
`<title>Document</title>`,
131+
`<script type="module">${bootstrapScript}</script>`,
132+
`</head>`,
133+
`<body>`,
134+
`</body>`,
135+
`</html>`
136+
].join('')}
125137
style={{ backgroundColor: 'white', height: dimensions, scale: `${scale}%`, width: dimensions }}
126138
title="Open Data Capture - Interactive Instrument"
127139
/>

packages/runtime-bundler/src/bundler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33

44
import esbuild from 'esbuild';
55

6-
import { dtsPlugin } from './plugin.js';
6+
import { dtsPlugin, htmlPlugin } from './plugin.js';
77
import { Resolver } from './resolver.js';
88

99
import type { BundlerOptions, EntryPoint, ExportCondition, ResolvedPackage } from './types.js';
@@ -44,7 +44,8 @@ export class Bundler {
4444
entryPoints,
4545
outdir: this.options.outdir,
4646
packages
47-
})
47+
}),
48+
htmlPlugin()
4849
],
4950
sourcemap: 'linked',
5051
sourcesContent: true,

packages/runtime-bundler/src/plugin.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,24 @@ export function dtsPlugin(options: DtsPluginOptions): Plugin {
126126
}
127127
};
128128
}
129+
130+
export function htmlPlugin(): Plugin {
131+
return {
132+
name: 'html-plugin',
133+
setup(build) {
134+
const namespace = 'html';
135+
build.onResolve({ filter: /.+\.html$/ }, (args) => {
136+
return {
137+
namespace,
138+
path: args.path
139+
};
140+
});
141+
build.onLoad({ filter: /.*/, namespace }, async (args) => {
142+
return {
143+
contents: await fs.readFile(args.path, 'utf-8'),
144+
loader: 'copy'
145+
};
146+
});
147+
}
148+
};
149+
}

packages/runtime-bundler/src/resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,6 @@ export class Resolver {
152152
}
153153

154154
private resolveSourceExport(exp: string, packageRoot: string): string {
155-
return this.resolveExportFilepath(exp, packageRoot, ['.css', '.json', '.js', '.mjs']);
155+
return this.resolveExportFilepath(exp, packageRoot, ['.css', '.json', '.js', '.mjs', '.html']);
156156
}
157157
}

packages/runtime-core/src/types/instrument.interactive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ declare type InteractiveInstrument<
2525
/** base64 encoded css */
2626
readonly style?: string;
2727
};
28+
html?: string;
29+
meta?: {
30+
[name: string]: string;
31+
};
2832
render: (done: (data: TData) => void) => Promisable<void>;
2933
};
3034
kind: 'INTERACTIVE';

packages/schemas/src/instrument/instrument.interactive.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const $InteractiveInstrument = $ScalarInstrument.extend({
1313
})
1414
.optional()
1515
.readonly(),
16+
html: z.string().optional(),
17+
meta: z.record(z.string(), z.string()).optional(),
1618
render: $AnyFunction
1719
}),
1820
details: $InstrumentDetails,

0 commit comments

Comments
 (0)