@typespec/playground 0.9.0-dev.4 → 0.9.0
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/dist/react/index.js +254 -84
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/output-view/output-view.d.ts +16 -0
- package/dist/src/react/output-view/output-view.d.ts.map +1 -1
- package/dist/src/react/output-view/type-graph-viewer.d.ts.map +1 -1
- package/dist/src/react/playground.d.ts +60 -25
- package/dist/src/react/playground.d.ts.map +1 -1
- package/dist/src/react/standalone.d.ts.map +1 -1
- package/dist/src/react/types.d.ts +4 -0
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/use-playground-state.d.ts +53 -0
- package/dist/src/react/use-playground-state.d.ts.map +1 -0
- package/package.json +12 -13
package/dist/react/index.js
CHANGED
|
@@ -2393,8 +2393,29 @@ function createFileViewer(fileViewers) {
|
|
|
2393
2393
|
};
|
|
2394
2394
|
}
|
|
2395
2395
|
|
|
2396
|
-
const TypeGraphViewerComponent = ({
|
|
2397
|
-
|
|
2396
|
+
const TypeGraphViewerComponent = ({
|
|
2397
|
+
program,
|
|
2398
|
+
viewerState,
|
|
2399
|
+
onViewerStateChange
|
|
2400
|
+
}) => {
|
|
2401
|
+
const currentPath = viewerState?.["type-graph:path"] || "";
|
|
2402
|
+
const handleNavigationChange = useCallback(
|
|
2403
|
+
(path) => {
|
|
2404
|
+
onViewerStateChange?.({
|
|
2405
|
+
...viewerState,
|
|
2406
|
+
"type-graph:path": path
|
|
2407
|
+
});
|
|
2408
|
+
},
|
|
2409
|
+
[viewerState, onViewerStateChange]
|
|
2410
|
+
);
|
|
2411
|
+
return /* @__PURE__ */ jsx("div", { className: style$4["type-graph-viewer"], children: /* @__PURE__ */ jsx(
|
|
2412
|
+
TypeGraph,
|
|
2413
|
+
{
|
|
2414
|
+
program,
|
|
2415
|
+
currentPath,
|
|
2416
|
+
onNavigationChange: handleNavigationChange
|
|
2417
|
+
}
|
|
2418
|
+
) });
|
|
2398
2419
|
};
|
|
2399
2420
|
const TypeGraphViewer = {
|
|
2400
2421
|
key: "type-graph",
|
|
@@ -2407,7 +2428,10 @@ const OutputView = ({
|
|
|
2407
2428
|
compilationState,
|
|
2408
2429
|
viewers,
|
|
2409
2430
|
fileViewers,
|
|
2410
|
-
|
|
2431
|
+
selectedViewer,
|
|
2432
|
+
onViewerChange,
|
|
2433
|
+
viewerState,
|
|
2434
|
+
onViewerStateChange
|
|
2411
2435
|
}) => {
|
|
2412
2436
|
const resolvedViewers = useMemo(
|
|
2413
2437
|
() => resolveViewers(viewers, fileViewers),
|
|
@@ -2424,7 +2448,10 @@ const OutputView = ({
|
|
|
2424
2448
|
{
|
|
2425
2449
|
compilationResult: compilationState,
|
|
2426
2450
|
viewers: resolvedViewers,
|
|
2427
|
-
|
|
2451
|
+
selectedViewer,
|
|
2452
|
+
onViewerChange,
|
|
2453
|
+
viewerState,
|
|
2454
|
+
onViewerStateChange
|
|
2428
2455
|
}
|
|
2429
2456
|
);
|
|
2430
2457
|
};
|
|
@@ -2441,12 +2468,24 @@ function resolveViewers(viewers, fileViewers) {
|
|
|
2441
2468
|
}
|
|
2442
2469
|
return output;
|
|
2443
2470
|
}
|
|
2444
|
-
const OutputViewInternal = ({
|
|
2471
|
+
const OutputViewInternal = ({
|
|
2472
|
+
compilationResult,
|
|
2473
|
+
viewers,
|
|
2474
|
+
selectedViewer,
|
|
2475
|
+
onViewerChange,
|
|
2476
|
+
viewerState,
|
|
2477
|
+
onViewerStateChange
|
|
2478
|
+
}) => {
|
|
2445
2479
|
const viewerList = Object.values(viewers.programViewers);
|
|
2446
|
-
const [
|
|
2480
|
+
const [internalSelected, setInternalSelected] = useState(viewerList[0].key);
|
|
2481
|
+
const selected = selectedViewer ?? internalSelected;
|
|
2447
2482
|
const onTabSelect = useCallback(
|
|
2448
|
-
(_, data) =>
|
|
2449
|
-
|
|
2483
|
+
(_, data) => {
|
|
2484
|
+
const newSelection = data.value;
|
|
2485
|
+
setInternalSelected(newSelection);
|
|
2486
|
+
onViewerChange?.(newSelection);
|
|
2487
|
+
},
|
|
2488
|
+
[onViewerChange]
|
|
2450
2489
|
);
|
|
2451
2490
|
const viewer = useMemo(() => {
|
|
2452
2491
|
return viewers.programViewers[selected];
|
|
@@ -2456,7 +2495,9 @@ const OutputViewInternal = ({ compilationResult, viewers, editorOptions }) => {
|
|
|
2456
2495
|
viewer.render,
|
|
2457
2496
|
{
|
|
2458
2497
|
program: compilationResult.program,
|
|
2459
|
-
outputFiles: compilationResult.outputFiles
|
|
2498
|
+
outputFiles: compilationResult.outputFiles,
|
|
2499
|
+
viewerState,
|
|
2500
|
+
onViewerStateChange
|
|
2460
2501
|
}
|
|
2461
2502
|
) }) }),
|
|
2462
2503
|
/* @__PURE__ */ jsx("div", { className: style$4["viewer-tabs-container"], children: /* @__PURE__ */ jsx(
|
|
@@ -2670,41 +2711,159 @@ const ProblemPaneContent = ({
|
|
|
2670
2711
|
return diagnostics.length === 0 ? /* @__PURE__ */ jsx("div", { className: style["no-problems"], children: " No problems" }) : /* @__PURE__ */ jsx(DiagnosticList, { diagnostics, onDiagnosticSelected });
|
|
2671
2712
|
};
|
|
2672
2713
|
|
|
2714
|
+
function usePlaygroundState({
|
|
2715
|
+
libraries,
|
|
2716
|
+
samples,
|
|
2717
|
+
playgroundState: controlledPlaygroundState,
|
|
2718
|
+
defaultPlaygroundState,
|
|
2719
|
+
onPlaygroundStateChange,
|
|
2720
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
2721
|
+
defaultEmitter,
|
|
2722
|
+
defaultContent
|
|
2723
|
+
}) {
|
|
2724
|
+
const effectiveDefaultState = useMemo(() => {
|
|
2725
|
+
const baseDefault = defaultPlaygroundState ?? {};
|
|
2726
|
+
if (!baseDefault.emitter) {
|
|
2727
|
+
if (defaultEmitter) {
|
|
2728
|
+
return { ...baseDefault, emitter: defaultEmitter, content: defaultContent };
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
return { ...baseDefault, content: baseDefault.content ?? defaultContent };
|
|
2732
|
+
}, [defaultPlaygroundState, defaultEmitter, libraries, defaultContent]);
|
|
2733
|
+
const [playgroundState, setPlaygroundState] = useControllableValue(
|
|
2734
|
+
controlledPlaygroundState,
|
|
2735
|
+
effectiveDefaultState,
|
|
2736
|
+
onPlaygroundStateChange
|
|
2737
|
+
);
|
|
2738
|
+
const selectedEmitter = playgroundState.emitter;
|
|
2739
|
+
const compilerOptions = useMemo(
|
|
2740
|
+
() => playgroundState.compilerOptions ?? {},
|
|
2741
|
+
[playgroundState.compilerOptions]
|
|
2742
|
+
);
|
|
2743
|
+
const selectedSampleName = playgroundState.sampleName ?? "";
|
|
2744
|
+
const selectedViewer = playgroundState.selectedViewer;
|
|
2745
|
+
const content = playgroundState.content ?? "";
|
|
2746
|
+
const updateState = useCallback(
|
|
2747
|
+
(updates) => {
|
|
2748
|
+
setPlaygroundState({ ...playgroundState, ...updates });
|
|
2749
|
+
},
|
|
2750
|
+
[playgroundState, setPlaygroundState]
|
|
2751
|
+
);
|
|
2752
|
+
const onSelectedEmitterChange = useCallback(
|
|
2753
|
+
(emitter) => updateState({ emitter }),
|
|
2754
|
+
[updateState]
|
|
2755
|
+
);
|
|
2756
|
+
const onCompilerOptionsChange = useCallback(
|
|
2757
|
+
(compilerOptions2) => updateState({ compilerOptions: compilerOptions2 }),
|
|
2758
|
+
[updateState]
|
|
2759
|
+
);
|
|
2760
|
+
const onSelectedSampleNameChange = useCallback(
|
|
2761
|
+
(sampleName) => updateState({ sampleName }),
|
|
2762
|
+
[updateState]
|
|
2763
|
+
);
|
|
2764
|
+
const onSelectedViewerChange = useCallback(
|
|
2765
|
+
(selectedViewer2) => updateState({ selectedViewer: selectedViewer2 }),
|
|
2766
|
+
[updateState]
|
|
2767
|
+
);
|
|
2768
|
+
const onViewerStateChange = useCallback(
|
|
2769
|
+
(viewerState) => updateState({ viewerState }),
|
|
2770
|
+
[updateState]
|
|
2771
|
+
);
|
|
2772
|
+
const onContentChange = useCallback((content2) => updateState({ content: content2 }), [updateState]);
|
|
2773
|
+
const lastProcessedSample = useRef("");
|
|
2774
|
+
useEffect(() => {
|
|
2775
|
+
if (selectedSampleName && samples && selectedSampleName !== lastProcessedSample.current) {
|
|
2776
|
+
const config = samples[selectedSampleName];
|
|
2777
|
+
if (config?.content) {
|
|
2778
|
+
lastProcessedSample.current = selectedSampleName;
|
|
2779
|
+
const updates = { content: config.content };
|
|
2780
|
+
if (config.preferredEmitter) {
|
|
2781
|
+
updates.emitter = config.preferredEmitter;
|
|
2782
|
+
}
|
|
2783
|
+
if (config.compilerOptions) {
|
|
2784
|
+
updates.compilerOptions = config.compilerOptions;
|
|
2785
|
+
}
|
|
2786
|
+
updateState(updates);
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
}, [selectedSampleName, samples, updateState]);
|
|
2790
|
+
return {
|
|
2791
|
+
// State values
|
|
2792
|
+
selectedEmitter,
|
|
2793
|
+
compilerOptions,
|
|
2794
|
+
selectedSampleName,
|
|
2795
|
+
selectedViewer,
|
|
2796
|
+
viewerState: playgroundState.viewerState ?? {},
|
|
2797
|
+
content,
|
|
2798
|
+
// State setters
|
|
2799
|
+
onSelectedEmitterChange,
|
|
2800
|
+
onCompilerOptionsChange,
|
|
2801
|
+
onSelectedSampleNameChange,
|
|
2802
|
+
onSelectedViewerChange,
|
|
2803
|
+
onViewerStateChange,
|
|
2804
|
+
onContentChange,
|
|
2805
|
+
// Full state management
|
|
2806
|
+
playgroundState,
|
|
2807
|
+
setPlaygroundState
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2673
2811
|
const Playground = (props) => {
|
|
2674
2812
|
const { host, onSave } = props;
|
|
2675
2813
|
const editorRef = useRef(void 0);
|
|
2676
2814
|
useEffect(() => {
|
|
2677
2815
|
editor.setTheme(props.editorOptions?.theme ?? "typespec");
|
|
2678
2816
|
}, [props.editorOptions?.theme]);
|
|
2679
|
-
const
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
props.
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
props.
|
|
2686
|
-
props.
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2817
|
+
const typespecModel = useMonacoModel("inmemory://test/main.tsp", "typespec");
|
|
2818
|
+
const [compilationState, setCompilationState] = useState(void 0);
|
|
2819
|
+
const state = usePlaygroundState({
|
|
2820
|
+
libraries: props.libraries,
|
|
2821
|
+
samples: props.samples,
|
|
2822
|
+
playgroundState: props.playgroundState,
|
|
2823
|
+
defaultPlaygroundState: props.defaultPlaygroundState,
|
|
2824
|
+
onPlaygroundStateChange: props.onPlaygroundStateChange,
|
|
2825
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
2826
|
+
defaultEmitter: props.defaultEmitter,
|
|
2827
|
+
defaultContent: props.defaultContent
|
|
2828
|
+
});
|
|
2829
|
+
const {
|
|
2830
|
+
selectedEmitter,
|
|
2831
|
+
compilerOptions,
|
|
2832
|
+
selectedSampleName,
|
|
2833
|
+
selectedViewer,
|
|
2834
|
+
viewerState,
|
|
2835
|
+
content,
|
|
2836
|
+
onSelectedEmitterChange,
|
|
2837
|
+
onCompilerOptionsChange,
|
|
2838
|
+
onSelectedSampleNameChange,
|
|
2839
|
+
onSelectedViewerChange,
|
|
2840
|
+
onViewerStateChange,
|
|
2841
|
+
onContentChange
|
|
2842
|
+
} = state;
|
|
2843
|
+
useEffect(() => {
|
|
2844
|
+
if (typespecModel.getValue() !== (content ?? "")) {
|
|
2845
|
+
typespecModel.setValue(content ?? "");
|
|
2846
|
+
}
|
|
2847
|
+
}, [content, typespecModel]);
|
|
2848
|
+
useEffect(() => {
|
|
2849
|
+
const disposable = typespecModel.onDidChangeContent(() => {
|
|
2850
|
+
const newContent = typespecModel.getValue();
|
|
2851
|
+
if (newContent !== content) {
|
|
2852
|
+
onContentChange(newContent);
|
|
2853
|
+
}
|
|
2854
|
+
});
|
|
2855
|
+
return () => disposable.dispose();
|
|
2856
|
+
}, [typespecModel, content, onContentChange]);
|
|
2695
2857
|
const isSampleUntouched = useMemo(() => {
|
|
2696
2858
|
return Boolean(selectedSampleName && content === props.samples?.[selectedSampleName]?.content);
|
|
2697
2859
|
}, [content, selectedSampleName, props.samples]);
|
|
2698
|
-
const typespecModel = useMonacoModel("inmemory://test/main.tsp", "typespec");
|
|
2699
|
-
const [compilationState, setCompilationState] = useState(void 0);
|
|
2700
2860
|
const doCompile = useCallback(async () => {
|
|
2701
|
-
const
|
|
2702
|
-
setContent(content2);
|
|
2861
|
+
const currentContent = typespecModel.getValue();
|
|
2703
2862
|
const typespecCompiler = host.compiler;
|
|
2704
|
-
const
|
|
2705
|
-
setCompilationState(
|
|
2706
|
-
if ("program" in
|
|
2707
|
-
const markers =
|
|
2863
|
+
const state2 = await compile(host, currentContent, selectedEmitter, compilerOptions);
|
|
2864
|
+
setCompilationState(state2);
|
|
2865
|
+
if ("program" in state2) {
|
|
2866
|
+
const markers = state2.program.diagnostics.map((diag) => ({
|
|
2708
2867
|
...getMonacoRange(typespecCompiler, diag.target),
|
|
2709
2868
|
message: diag.message,
|
|
2710
2869
|
severity: diag.severity === "error" ? MarkerSeverity.Error : MarkerSeverity.Warning,
|
|
@@ -2714,38 +2873,7 @@ const Playground = (props) => {
|
|
|
2714
2873
|
} else {
|
|
2715
2874
|
editor.setModelMarkers(typespecModel, "owner", []);
|
|
2716
2875
|
}
|
|
2717
|
-
}, [host, selectedEmitter, compilerOptions, typespecModel
|
|
2718
|
-
const updateTypeSpec = useCallback(
|
|
2719
|
-
(value) => {
|
|
2720
|
-
if (typespecModel.getValue() !== value) {
|
|
2721
|
-
typespecModel.setValue(value);
|
|
2722
|
-
}
|
|
2723
|
-
},
|
|
2724
|
-
[typespecModel]
|
|
2725
|
-
);
|
|
2726
|
-
useEffect(() => {
|
|
2727
|
-
updateTypeSpec(props.defaultContent ?? "");
|
|
2728
|
-
}, [props.defaultContent, updateTypeSpec]);
|
|
2729
|
-
useEffect(() => {
|
|
2730
|
-
if (selectedSampleName && props.samples) {
|
|
2731
|
-
const config = props.samples[selectedSampleName];
|
|
2732
|
-
if (config.content) {
|
|
2733
|
-
updateTypeSpec(config.content);
|
|
2734
|
-
if (config.preferredEmitter) {
|
|
2735
|
-
onSelectedEmitterChange(config.preferredEmitter);
|
|
2736
|
-
}
|
|
2737
|
-
if (config.compilerOptions) {
|
|
2738
|
-
onCompilerOptionsChange(config.compilerOptions);
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
}, [
|
|
2743
|
-
updateTypeSpec,
|
|
2744
|
-
selectedSampleName,
|
|
2745
|
-
props.samples,
|
|
2746
|
-
onSelectedEmitterChange,
|
|
2747
|
-
onCompilerOptionsChange
|
|
2748
|
-
]);
|
|
2876
|
+
}, [host, selectedEmitter, compilerOptions, typespecModel]);
|
|
2749
2877
|
useEffect(() => {
|
|
2750
2878
|
const debouncer = debounce(() => doCompile(), 200);
|
|
2751
2879
|
const disposable = typespecModel.onDidChangeContent(debouncer);
|
|
@@ -2760,19 +2888,23 @@ const Playground = (props) => {
|
|
|
2760
2888
|
const saveCode = useCallback(() => {
|
|
2761
2889
|
if (onSave) {
|
|
2762
2890
|
onSave({
|
|
2763
|
-
content:
|
|
2891
|
+
content: content ?? "",
|
|
2764
2892
|
emitter: selectedEmitter,
|
|
2765
|
-
|
|
2766
|
-
sampleName: isSampleUntouched ? selectedSampleName : void 0
|
|
2893
|
+
compilerOptions,
|
|
2894
|
+
sampleName: isSampleUntouched ? selectedSampleName : void 0,
|
|
2895
|
+
selectedViewer,
|
|
2896
|
+
viewerState
|
|
2767
2897
|
});
|
|
2768
2898
|
}
|
|
2769
2899
|
}, [
|
|
2770
|
-
|
|
2900
|
+
content,
|
|
2771
2901
|
onSave,
|
|
2772
2902
|
selectedEmitter,
|
|
2773
2903
|
compilerOptions,
|
|
2774
2904
|
selectedSampleName,
|
|
2775
|
-
isSampleUntouched
|
|
2905
|
+
isSampleUntouched,
|
|
2906
|
+
selectedViewer,
|
|
2907
|
+
viewerState
|
|
2776
2908
|
]);
|
|
2777
2909
|
const formatCode = useCallback(() => {
|
|
2778
2910
|
void editorRef.current?.getAction("editor.action.formatDocument")?.run();
|
|
@@ -2818,10 +2950,10 @@ const Playground = (props) => {
|
|
|
2818
2950
|
host,
|
|
2819
2951
|
setContent: (val) => {
|
|
2820
2952
|
typespecModel.setValue(val);
|
|
2821
|
-
|
|
2953
|
+
onContentChange(val);
|
|
2822
2954
|
}
|
|
2823
2955
|
};
|
|
2824
|
-
}, [host,
|
|
2956
|
+
}, [host, typespecModel, onContentChange]);
|
|
2825
2957
|
return /* @__PURE__ */ jsx(PlaygroundContextProvider, { value: playgroundContext, children: /* @__PURE__ */ jsxs("div", { className: style$3["layout"], children: [
|
|
2826
2958
|
/* @__PURE__ */ jsxs(SplitPane, { sizes: verticalPaneSizes, onChange: onVerticalPaneSizeChange, split: "horizontal", children: [
|
|
2827
2959
|
/* @__PURE__ */ jsx(Pane, { children: /* @__PURE__ */ jsxs(SplitPane, { initialSizes: ["50%", "50%"], children: [
|
|
@@ -2860,7 +2992,11 @@ const Playground = (props) => {
|
|
|
2860
2992
|
compilationState,
|
|
2861
2993
|
editorOptions: props.editorOptions,
|
|
2862
2994
|
viewers: props.viewers,
|
|
2863
|
-
fileViewers: props.emitterViewers?.[selectedEmitter]
|
|
2995
|
+
fileViewers: selectedEmitter ? props.emitterViewers?.[selectedEmitter] : void 0,
|
|
2996
|
+
selectedViewer,
|
|
2997
|
+
onViewerChange: onSelectedViewerChange,
|
|
2998
|
+
viewerState,
|
|
2999
|
+
onViewerStateChange
|
|
2864
3000
|
}
|
|
2865
3001
|
) })
|
|
2866
3002
|
] }) }),
|
|
@@ -2953,12 +3089,20 @@ const StandalonePlayground = (config) => {
|
|
|
2953
3089
|
const context = useStandalonePlaygroundContext(config);
|
|
2954
3090
|
const toasterId = useId$1();
|
|
2955
3091
|
const { dispatchToast } = useToastController(toasterId);
|
|
2956
|
-
const
|
|
3092
|
+
const [lastSavedData, setLastSavedData] = useState(null);
|
|
3093
|
+
const saveToStorage = useCallback(
|
|
2957
3094
|
(value) => {
|
|
2958
3095
|
if (!context) {
|
|
2959
3096
|
return;
|
|
2960
3097
|
}
|
|
2961
3098
|
context.stateStorage.save(value);
|
|
3099
|
+
setLastSavedData(value);
|
|
3100
|
+
},
|
|
3101
|
+
[context]
|
|
3102
|
+
);
|
|
3103
|
+
const onSave = useCallback(
|
|
3104
|
+
(value) => {
|
|
3105
|
+
saveToStorage(value);
|
|
2962
3106
|
void navigator.clipboard.writeText(window.location.toString());
|
|
2963
3107
|
dispatchToast(
|
|
2964
3108
|
/* @__PURE__ */ jsxs(Toast, { children: [
|
|
@@ -2968,18 +3112,36 @@ const StandalonePlayground = (config) => {
|
|
|
2968
3112
|
{ intent: "success" }
|
|
2969
3113
|
);
|
|
2970
3114
|
},
|
|
2971
|
-
[dispatchToast,
|
|
3115
|
+
[dispatchToast, saveToStorage]
|
|
3116
|
+
);
|
|
3117
|
+
const onPlaygroundStateChange = useCallback(
|
|
3118
|
+
(newState) => {
|
|
3119
|
+
const saveData = {
|
|
3120
|
+
content: lastSavedData?.content || "",
|
|
3121
|
+
emitter: newState.emitter || "",
|
|
3122
|
+
compilerOptions: newState.compilerOptions,
|
|
3123
|
+
sampleName: newState.sampleName,
|
|
3124
|
+
selectedViewer: newState.selectedViewer,
|
|
3125
|
+
viewerState: newState.viewerState
|
|
3126
|
+
};
|
|
3127
|
+
saveToStorage(saveData);
|
|
3128
|
+
},
|
|
3129
|
+
[lastSavedData?.content, saveToStorage]
|
|
2972
3130
|
);
|
|
2973
3131
|
const fixedOptions = useMemo(
|
|
2974
3132
|
() => context && {
|
|
2975
3133
|
host: context.host,
|
|
2976
3134
|
libraries: config.libraries,
|
|
2977
3135
|
defaultContent: context.initialState.content,
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
3136
|
+
defaultPlaygroundState: {
|
|
3137
|
+
emitter: context.initialState.emitter ?? config.defaultPlaygroundState?.emitter,
|
|
3138
|
+
compilerOptions: context.initialState.compilerOptions ?? config.defaultPlaygroundState?.compilerOptions,
|
|
3139
|
+
sampleName: context.initialState.sampleName ?? config.defaultPlaygroundState?.sampleName,
|
|
3140
|
+
selectedViewer: context.initialState.selectedViewer ?? config.defaultPlaygroundState?.selectedViewer,
|
|
3141
|
+
viewerState: context.initialState.viewerState ?? config.defaultPlaygroundState?.viewerState
|
|
3142
|
+
}
|
|
2981
3143
|
},
|
|
2982
|
-
[config.
|
|
3144
|
+
[config.defaultPlaygroundState, config.libraries, context]
|
|
2983
3145
|
);
|
|
2984
3146
|
if (context === void 0 || fixedOptions === void 0) {
|
|
2985
3147
|
return config.fallback;
|
|
@@ -2987,11 +3149,12 @@ const StandalonePlayground = (config) => {
|
|
|
2987
3149
|
const options = {
|
|
2988
3150
|
...config,
|
|
2989
3151
|
...fixedOptions,
|
|
2990
|
-
onSave
|
|
3152
|
+
onSave,
|
|
3153
|
+
onPlaygroundStateChange
|
|
2991
3154
|
};
|
|
2992
3155
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2993
3156
|
/* @__PURE__ */ jsx(Toaster, { toasterId }),
|
|
2994
|
-
|
|
3157
|
+
/* @__PURE__ */ jsx(Playground, { ...options })
|
|
2995
3158
|
] });
|
|
2996
3159
|
};
|
|
2997
3160
|
async function createReactPlayground(config) {
|
|
@@ -3013,12 +3176,19 @@ function createStandalonePlaygroundStateStorage() {
|
|
|
3013
3176
|
emitter: {
|
|
3014
3177
|
queryParam: "e"
|
|
3015
3178
|
},
|
|
3016
|
-
|
|
3179
|
+
compilerOptions: {
|
|
3017
3180
|
type: "object",
|
|
3018
3181
|
queryParam: "options"
|
|
3019
3182
|
},
|
|
3020
3183
|
sampleName: {
|
|
3021
3184
|
queryParam: "sample"
|
|
3185
|
+
},
|
|
3186
|
+
selectedViewer: {
|
|
3187
|
+
queryParam: "v"
|
|
3188
|
+
},
|
|
3189
|
+
viewerState: {
|
|
3190
|
+
type: "object",
|
|
3191
|
+
queryParam: "vs"
|
|
3022
3192
|
}
|
|
3023
3193
|
});
|
|
3024
3194
|
return {
|
|
@@ -3026,10 +3196,10 @@ function createStandalonePlaygroundStateStorage() {
|
|
|
3026
3196
|
resolveSearchParams: stateStorage.resolveSearchParams,
|
|
3027
3197
|
save(data) {
|
|
3028
3198
|
stateStorage.save(
|
|
3029
|
-
data.sampleName ? {
|
|
3199
|
+
data.sampleName ? { ...data, content: void 0, emitter: void 0, sampleName: data.sampleName } : data
|
|
3030
3200
|
);
|
|
3031
3201
|
}
|
|
3032
3202
|
};
|
|
3033
3203
|
}
|
|
3034
3204
|
|
|
3035
|
-
export { Editor, Footer, FooterItem, FooterVersionItem, Playground, StandalonePlayground, createReactPlayground, createStandalonePlaygroundStateStorage, renderReactPlayground, useMonacoModel, usePlaygroundContext };
|
|
3205
|
+
export { Editor, Footer, FooterItem, FooterVersionItem, Playground, StandalonePlayground, createReactPlayground, createStandalonePlaygroundStateStorage, renderReactPlayground, useMonacoModel, usePlaygroundContext, usePlaygroundState };
|
|
@@ -5,4 +5,5 @@ export { Playground } from './playground.js';
|
|
|
5
5
|
export type { PlaygroundProps, PlaygroundSaveData } from './playground.js';
|
|
6
6
|
export { StandalonePlayground, createReactPlayground, createStandalonePlaygroundStateStorage, renderReactPlayground, } from './standalone.js';
|
|
7
7
|
export type * from './types.js';
|
|
8
|
+
export { usePlaygroundState, type PlaygroundState } from './use-playground-state.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,sCAAsC,EACtC,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,mBAAmB,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,sCAAsC,EACtC,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,mBAAmB,YAAY,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -9,6 +9,22 @@ export interface OutputViewProps {
|
|
|
9
9
|
*/
|
|
10
10
|
viewers?: ProgramViewer[];
|
|
11
11
|
fileViewers?: FileOutputViewer[];
|
|
12
|
+
/**
|
|
13
|
+
* The currently selected viewer key.
|
|
14
|
+
*/
|
|
15
|
+
selectedViewer?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Callback when the selected viewer changes.
|
|
18
|
+
*/
|
|
19
|
+
onViewerChange?: (viewerKey: string) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Current viewer state for viewers that have internal state.
|
|
22
|
+
*/
|
|
23
|
+
viewerState?: Record<string, any>;
|
|
24
|
+
/**
|
|
25
|
+
* Callback when viewer state changes.
|
|
26
|
+
*/
|
|
27
|
+
onViewerStateChange?: (state: Record<string, any>) => void;
|
|
12
28
|
}
|
|
13
29
|
export declare const OutputView: FunctionComponent<OutputViewProps>;
|
|
14
30
|
//# sourceMappingURL=output-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-view.d.ts","sourceRoot":"","sources":["../../../../src/react/output-view/output-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAiB,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMpG,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC/C,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACzC;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"output-view.d.ts","sourceRoot":"","sources":["../../../../src/react/output-view/output-view.tsx"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAiB,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMpG,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC/C,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACzC;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACjC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;CAC5D;AAED,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,CA8BzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-graph-viewer.d.ts","sourceRoot":"","sources":["../../../../src/react/output-view/type-graph-viewer.tsx"],"names":[],"mappings":"AAEA,OAAO,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"type-graph-viewer.d.ts","sourceRoot":"","sources":["../../../../src/react/output-view/type-graph-viewer.tsx"],"names":[],"mappings":"AAEA,OAAO,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,aAAa,CAAC;AAgCpE,eAAO,MAAM,eAAe,EAAE,aAK7B,CAAC"}
|
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
import { CompilerOptions } from '@typespec/compiler';
|
|
2
1
|
import { FunctionComponent, ReactNode } from 'react';
|
|
3
2
|
import { BrowserHost, PlaygroundSample } from '../types.js';
|
|
4
3
|
import { FileOutputViewer, ProgramViewer } from './types.js';
|
|
4
|
+
import { PlaygroundState } from './use-playground-state.js';
|
|
5
|
+
export type { PlaygroundState };
|
|
5
6
|
export interface PlaygroundProps {
|
|
6
7
|
host: BrowserHost;
|
|
7
|
-
/** Default
|
|
8
|
+
/** Default content if leaving this unmanaged. */
|
|
8
9
|
defaultContent?: string;
|
|
9
10
|
/** List of available libraries */
|
|
10
11
|
readonly libraries: readonly string[];
|
|
11
|
-
/** Emitter to use */
|
|
12
|
-
emitter?: string;
|
|
13
|
-
/** Default emitter if leaving this unmanaged. */
|
|
14
|
-
defaultEmitter?: string;
|
|
15
|
-
/** Callback when emitter change */
|
|
16
|
-
onEmitterChange?: (emitter: string) => void;
|
|
17
|
-
/** Emitter options */
|
|
18
|
-
compilerOptions?: CompilerOptions;
|
|
19
|
-
/** Default emitter options if leaving this unmanaged. */
|
|
20
|
-
defaultCompilerOptions?: CompilerOptions;
|
|
21
|
-
/** Callback when emitter options change */
|
|
22
|
-
onCompilerOptionsChange?: (emitter: CompilerOptions) => void;
|
|
23
12
|
/** Samples available */
|
|
24
13
|
samples?: Record<string, PlaygroundSample>;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/** Default
|
|
28
|
-
|
|
29
|
-
/** Callback when
|
|
30
|
-
|
|
14
|
+
/** Playground state (controlled) */
|
|
15
|
+
playgroundState?: PlaygroundState;
|
|
16
|
+
/** Default playground state if leaving this unmanaged */
|
|
17
|
+
defaultPlaygroundState?: PlaygroundState;
|
|
18
|
+
/** Callback when playground state changes */
|
|
19
|
+
onPlaygroundStateChange?: (state: PlaygroundState) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Default emitter to use if not provided in defaultPlaygroundState.
|
|
22
|
+
* @deprecated Use defaultPlaygroundState.emitter instead
|
|
23
|
+
*/
|
|
24
|
+
defaultEmitter?: string;
|
|
31
25
|
onFileBug?: () => void;
|
|
32
26
|
/** Additional buttons to show up in the command bar */
|
|
33
27
|
commandBarButtons?: ReactNode;
|
|
@@ -47,19 +41,60 @@ export interface PlaygroundProps {
|
|
|
47
41
|
export interface PlaygroundEditorsOptions {
|
|
48
42
|
theme?: string;
|
|
49
43
|
}
|
|
50
|
-
export interface PlaygroundSaveData {
|
|
44
|
+
export interface PlaygroundSaveData extends PlaygroundState {
|
|
51
45
|
/** Current content of the playground. */
|
|
52
46
|
content: string;
|
|
53
47
|
/** Emitter name. */
|
|
54
48
|
emitter: string;
|
|
55
|
-
/** Emitter options. */
|
|
56
|
-
options?: CompilerOptions;
|
|
57
|
-
/** If a sample is selected and the content hasn't changed since. */
|
|
58
|
-
sampleName?: string;
|
|
59
49
|
}
|
|
60
50
|
export interface PlaygroundLinks {
|
|
61
51
|
/** Link to documentation */
|
|
62
52
|
documentationUrl?: string;
|
|
63
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Playground component for TypeSpec with consolidated state management.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const [playgroundState, setPlaygroundState] = useState<PlaygroundState>({
|
|
60
|
+
* emitter: 'openapi3',
|
|
61
|
+
* compilerOptions: {},
|
|
62
|
+
* sampleName: 'basic',
|
|
63
|
+
* selectedViewer: 'openapi',
|
|
64
|
+
* viewerState: {}
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* <Playground
|
|
68
|
+
* host={host}
|
|
69
|
+
* playgroundState={playgroundState}
|
|
70
|
+
* onPlaygroundStateChange={setPlaygroundState}
|
|
71
|
+
* samples={samples}
|
|
72
|
+
* viewers={viewers}
|
|
73
|
+
* />
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* For uncontrolled usage, use defaultPlaygroundState:
|
|
77
|
+
* ```tsx
|
|
78
|
+
* <Playground
|
|
79
|
+
* host={host}
|
|
80
|
+
* defaultPlaygroundState={{
|
|
81
|
+
* emitter: 'openapi3',
|
|
82
|
+
* compilerOptions: {},
|
|
83
|
+
* }}
|
|
84
|
+
* samples={samples}
|
|
85
|
+
* viewers={viewers}
|
|
86
|
+
* />
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* For backward compatibility, you can also use the deprecated defaultEmitter prop:
|
|
90
|
+
* ```tsx
|
|
91
|
+
* <Playground
|
|
92
|
+
* host={host}
|
|
93
|
+
* defaultEmitter="openapi3"
|
|
94
|
+
* samples={samples}
|
|
95
|
+
* viewers={viewers}
|
|
96
|
+
* />
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
64
99
|
export declare const Playground: FunctionComponent<PlaygroundProps>;
|
|
65
100
|
//# sourceMappingURL=playground.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/react/playground.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/react/playground.tsx"],"names":[],"mappings":"AAEA,OAAO,sCAAsC,CAAC;AAG9C,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAOjE,OAAO,KAAK,EAAoB,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpF,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAGrF,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,CAAC;IAElB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE3C,oCAAoC;IACp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B,EACtB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,
|
|
1
|
+
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../../src/react/standalone.tsx"],"names":[],"mappings":"AASA,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,qBAAsB,SAAQ,OAAO,CAAC,eAAe,CAAC;IACrE,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IAC7C,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B;AAyBD,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,qBAAqB,CAuFzE,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,oDAExE;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,iBASxE;AAED,wBAAgB,sCAAsC,IAAI,eAAe,CAAC,kBAAkB,CAAC,CAoC5F"}
|
|
@@ -13,6 +13,10 @@ export interface OutputViewerProps {
|
|
|
13
13
|
readonly program: Program;
|
|
14
14
|
/** Files emitted */
|
|
15
15
|
readonly outputFiles: string[];
|
|
16
|
+
/** Current viewer state (for viewers that have internal state) */
|
|
17
|
+
readonly viewerState?: Record<string, any>;
|
|
18
|
+
/** Callback to update viewer state */
|
|
19
|
+
readonly onViewerStateChange?: (state: Record<string, any>) => void;
|
|
16
20
|
}
|
|
17
21
|
export interface ProgramViewer {
|
|
18
22
|
readonly key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,kBAAkB,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,oBAAoB;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,C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interface PlaygroundState {
|
|
4
|
+
/** Emitter to use */
|
|
5
|
+
emitter?: string;
|
|
6
|
+
/** Emitter options */
|
|
7
|
+
compilerOptions?: CompilerOptions;
|
|
8
|
+
/** Sample to use */
|
|
9
|
+
sampleName?: string;
|
|
10
|
+
/** Selected viewer */
|
|
11
|
+
selectedViewer?: string;
|
|
12
|
+
/** Internal state of viewers */
|
|
13
|
+
viewerState?: Record<string, any>;
|
|
14
|
+
/** TypeSpec content */
|
|
15
|
+
content?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface UsePlaygroundStateProps {
|
|
18
|
+
/** List of available libraries */
|
|
19
|
+
readonly libraries: readonly string[];
|
|
20
|
+
/** Samples available */
|
|
21
|
+
samples?: Record<string, PlaygroundSample>;
|
|
22
|
+
/** Playground state (controlled) */
|
|
23
|
+
playgroundState?: PlaygroundState;
|
|
24
|
+
/** Default playground state if leaving this unmanaged */
|
|
25
|
+
defaultPlaygroundState?: PlaygroundState;
|
|
26
|
+
/** Callback when playground state changes */
|
|
27
|
+
onPlaygroundStateChange?: (state: PlaygroundState) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Default emitter to use if not provided in defaultPlaygroundState.
|
|
30
|
+
* @deprecated Use defaultPlaygroundState.emitter instead
|
|
31
|
+
*/
|
|
32
|
+
defaultEmitter?: string;
|
|
33
|
+
/** Default content if not provided in defaultPlaygroundState */
|
|
34
|
+
defaultContent?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PlaygroundStateResult {
|
|
37
|
+
selectedEmitter: string;
|
|
38
|
+
compilerOptions: CompilerOptions;
|
|
39
|
+
selectedSampleName: string;
|
|
40
|
+
selectedViewer?: string;
|
|
41
|
+
viewerState: Record<string, any>;
|
|
42
|
+
content: string;
|
|
43
|
+
onSelectedEmitterChange: (emitter: string) => void;
|
|
44
|
+
onCompilerOptionsChange: (compilerOptions: CompilerOptions) => void;
|
|
45
|
+
onSelectedSampleNameChange: (sampleName: string) => void;
|
|
46
|
+
onSelectedViewerChange: (selectedViewer: string) => void;
|
|
47
|
+
onViewerStateChange: (viewerState: Record<string, any>) => void;
|
|
48
|
+
onContentChange: (content: string) => void;
|
|
49
|
+
playgroundState: PlaygroundState;
|
|
50
|
+
setPlaygroundState: (state: PlaygroundState) => void;
|
|
51
|
+
}
|
|
52
|
+
export declare function usePlaygroundState({ libraries, samples, playgroundState: controlledPlaygroundState, defaultPlaygroundState, onPlaygroundStateChange, defaultEmitter, defaultContent, }: UsePlaygroundStateProps): PlaygroundStateResult;
|
|
53
|
+
//# sourceMappingURL=use-playground-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-playground-state.d.ts","sourceRoot":"","sources":["../../../src/react/use-playground-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,qBAAqB;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE3C,oCAAoC;IACpC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,yDAAyD;IACzD,sBAAsB,CAAC,EAAE,eAAe,CAAC;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
+
"version": "0.9.0",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec playground UI components.",
|
|
6
6
|
"homepage": "https://typespec.io",
|
|
@@ -61,15 +61,6 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@fluentui/react-components": "~9.66.1",
|
|
63
63
|
"@fluentui/react-icons": "^2.0.292",
|
|
64
|
-
"@typespec/bundler": "^0.4.1 || >=0.5.0-dev <0.5.0",
|
|
65
|
-
"@typespec/compiler": "^1.1.0",
|
|
66
|
-
"@typespec/html-program-viewer": "^0.71.0 || >=0.72.0-dev <0.72.0",
|
|
67
|
-
"@typespec/http": "^1.1.0",
|
|
68
|
-
"@typespec/openapi": "^1.1.0",
|
|
69
|
-
"@typespec/openapi3": "^1.1.0",
|
|
70
|
-
"@typespec/protobuf": "^0.71.0 || >=0.72.0-dev <0.72.0",
|
|
71
|
-
"@typespec/rest": "^0.71.0 || >=0.72.0-dev <0.72.0",
|
|
72
|
-
"@typespec/versioning": "^0.71.0 || >=0.72.0-dev <0.72.0",
|
|
73
64
|
"clsx": "^2.1.1",
|
|
74
65
|
"debounce": "~2.2.0",
|
|
75
66
|
"lzutf8": "0.6.3",
|
|
@@ -79,7 +70,16 @@
|
|
|
79
70
|
"react-error-boundary": "^6.0.0",
|
|
80
71
|
"swagger-ui-dist": "^5.20.1",
|
|
81
72
|
"vscode-languageserver": "~9.0.1",
|
|
82
|
-
"vscode-languageserver-textdocument": "~1.0.12"
|
|
73
|
+
"vscode-languageserver-textdocument": "~1.0.12",
|
|
74
|
+
"@typespec/bundler": "^0.4.2",
|
|
75
|
+
"@typespec/compiler": "^1.2.0",
|
|
76
|
+
"@typespec/http": "^1.2.0",
|
|
77
|
+
"@typespec/html-program-viewer": "^0.72.0",
|
|
78
|
+
"@typespec/openapi": "^1.2.0",
|
|
79
|
+
"@typespec/protobuf": "^0.72.0",
|
|
80
|
+
"@typespec/rest": "^0.72.0",
|
|
81
|
+
"@typespec/versioning": "^0.72.0",
|
|
82
|
+
"@typespec/openapi3": "^1.2.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@babel/core": "^7.26.10",
|
|
@@ -91,7 +91,6 @@
|
|
|
91
91
|
"@types/react": "~18.3.11",
|
|
92
92
|
"@types/react-dom": "~18.3.0",
|
|
93
93
|
"@types/swagger-ui-dist": "~3.30.5",
|
|
94
|
-
"@typespec/bundler": "^0.4.1 || >=0.5.0-dev <0.5.0",
|
|
95
94
|
"@vitejs/plugin-react": "~4.4.1",
|
|
96
95
|
"c8": "^10.1.3",
|
|
97
96
|
"cross-env": "~7.0.3",
|
|
@@ -102,9 +101,9 @@
|
|
|
102
101
|
"vite": "^6.2.7",
|
|
103
102
|
"vite-plugin-checker": "^0.9.1",
|
|
104
103
|
"vite-plugin-dts": "4.5.4",
|
|
104
|
+
"@typespec/bundler": "^0.4.2",
|
|
105
105
|
"@typespec/react-components": "^0.57.0"
|
|
106
106
|
},
|
|
107
|
-
"peerDependencies": {},
|
|
108
107
|
"scripts": {
|
|
109
108
|
"clean": "rimraf ./dist ./dist-dev ./temp ./typespecContents.json",
|
|
110
109
|
"build": "vite build",
|