create-interview-cockpit 0.17.0 → 0.17.1
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/package.json
CHANGED
|
@@ -406,11 +406,14 @@ function useATA(monacoRef: React.MutableRefObject<Monaco | null>) {
|
|
|
406
406
|
return { initATA, acquireTypes };
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
+
let monacoSandboxTypeLibsInjected = false;
|
|
410
|
+
|
|
409
411
|
function MonacoEditorWrapper({
|
|
410
412
|
value,
|
|
411
413
|
onChange,
|
|
412
414
|
onCtrlEnter,
|
|
413
415
|
language,
|
|
416
|
+
path,
|
|
414
417
|
placeholder,
|
|
415
418
|
autoFocus = false,
|
|
416
419
|
fontSize = "12px",
|
|
@@ -419,6 +422,7 @@ function MonacoEditorWrapper({
|
|
|
419
422
|
onChange: (val: string) => void;
|
|
420
423
|
onCtrlEnter?: () => void;
|
|
421
424
|
language: string;
|
|
425
|
+
path?: string;
|
|
422
426
|
placeholder?: string;
|
|
423
427
|
autoFocus?: boolean;
|
|
424
428
|
fontSize?: string;
|
|
@@ -438,7 +442,10 @@ function MonacoEditorWrapper({
|
|
|
438
442
|
target: tsLang.ScriptTarget.ESNext,
|
|
439
443
|
module: tsLang.ModuleKind.ESNext,
|
|
440
444
|
moduleResolution: tsLang.ModuleResolutionKind.Bundler,
|
|
441
|
-
|
|
445
|
+
// Prefer modern automatic JSX runtime; keep a fallback for older Monaco TS builds.
|
|
446
|
+
jsx: tsLang.JsxEmit.ReactJSX ?? tsLang.JsxEmit.Preserve,
|
|
447
|
+
jsxImportSource: "react",
|
|
448
|
+
allowJs: true,
|
|
442
449
|
strict: true,
|
|
443
450
|
esModuleInterop: true,
|
|
444
451
|
allowSyntheticDefaultImports: true,
|
|
@@ -460,6 +467,9 @@ function MonacoEditorWrapper({
|
|
|
460
467
|
tsLang.typescriptDefaults.setEagerModelSync(true);
|
|
461
468
|
tsLang.javascriptDefaults.setEagerModelSync(true);
|
|
462
469
|
|
|
470
|
+
// Keep these custom libs stable: ATA may load overlapping package paths later.
|
|
471
|
+
if (monacoSandboxTypeLibsInjected) return;
|
|
472
|
+
|
|
463
473
|
// Stub Node.js globals (process, Buffer, etc.) so sandbox code using them doesn't error
|
|
464
474
|
const nodeGlobals = `
|
|
465
475
|
declare var process: {
|
|
@@ -487,11 +497,69 @@ declare var __filename: string;
|
|
|
487
497
|
`;
|
|
488
498
|
tsLang.typescriptDefaults.addExtraLib(
|
|
489
499
|
nodeGlobals,
|
|
490
|
-
"file:///
|
|
500
|
+
"file:///__sandbox-types/node-globals.d.ts",
|
|
491
501
|
);
|
|
492
502
|
tsLang.javascriptDefaults.addExtraLib(
|
|
493
503
|
nodeGlobals,
|
|
494
|
-
"file:///
|
|
504
|
+
"file:///__sandbox-types/node-globals.d.ts",
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
// Pre-seed React + JSX ambient types so TSX has intrinsic element typing.
|
|
508
|
+
const reactTypes = `
|
|
509
|
+
declare module 'react' {
|
|
510
|
+
export type ReactNode = any;
|
|
511
|
+
export type ReactElement = any;
|
|
512
|
+
export type CSSProperties = Record<string, string | number>;
|
|
513
|
+
export interface FC<P = {}> {
|
|
514
|
+
(props: P): ReactElement | null;
|
|
515
|
+
}
|
|
516
|
+
export interface AnchorHTMLAttributes<T> extends Record<string, unknown> {}
|
|
517
|
+
export function useEffect(
|
|
518
|
+
effect: () => void | (() => void),
|
|
519
|
+
deps?: readonly unknown[],
|
|
520
|
+
): void;
|
|
521
|
+
export function useState<S>(
|
|
522
|
+
initialState: S | (() => S),
|
|
523
|
+
): [S, (value: S | ((prev: S) => S)) => void];
|
|
524
|
+
export function useMemo<T>(factory: () => T, deps: readonly unknown[]): T;
|
|
525
|
+
export function useCallback<T extends (...args: any[]) => any>(
|
|
526
|
+
callback: T,
|
|
527
|
+
deps: readonly unknown[],
|
|
528
|
+
): T;
|
|
529
|
+
export function useRef<T>(initialValue: T): { current: T };
|
|
530
|
+
const React: {
|
|
531
|
+
createElement: (...args: any[]) => ReactElement;
|
|
532
|
+
Fragment: any;
|
|
533
|
+
};
|
|
534
|
+
export default React;
|
|
535
|
+
}
|
|
536
|
+
declare module 'react/jsx-runtime' {
|
|
537
|
+
export const Fragment: any;
|
|
538
|
+
export function jsx(type: any, props: any, key?: any): any;
|
|
539
|
+
export function jsxs(type: any, props: any, key?: any): any;
|
|
540
|
+
export function jsxDEV(
|
|
541
|
+
type: any,
|
|
542
|
+
props: any,
|
|
543
|
+
key: any,
|
|
544
|
+
isStaticChildren: boolean,
|
|
545
|
+
source: any,
|
|
546
|
+
self: any,
|
|
547
|
+
): any;
|
|
548
|
+
}
|
|
549
|
+
declare namespace JSX {
|
|
550
|
+
interface Element {}
|
|
551
|
+
interface IntrinsicElements {
|
|
552
|
+
[elemName: string]: any;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
`;
|
|
556
|
+
tsLang.typescriptDefaults.addExtraLib(
|
|
557
|
+
reactTypes,
|
|
558
|
+
"file:///__sandbox-types/react-jsx.d.ts",
|
|
559
|
+
);
|
|
560
|
+
tsLang.javascriptDefaults.addExtraLib(
|
|
561
|
+
reactTypes,
|
|
562
|
+
"file:///__sandbox-types/react-jsx.d.ts",
|
|
495
563
|
);
|
|
496
564
|
|
|
497
565
|
// Pre-seed Next.js type stubs. ATA cannot resolve `next` because Next uses a
|
|
@@ -566,12 +634,14 @@ declare module 'next/server' {
|
|
|
566
634
|
`;
|
|
567
635
|
tsLang.typescriptDefaults.addExtraLib(
|
|
568
636
|
nextTypes,
|
|
569
|
-
"file:///
|
|
637
|
+
"file:///__sandbox-types/next.d.ts",
|
|
570
638
|
);
|
|
571
639
|
tsLang.javascriptDefaults.addExtraLib(
|
|
572
640
|
nextTypes,
|
|
573
|
-
"file:///
|
|
641
|
+
"file:///__sandbox-types/next.d.ts",
|
|
574
642
|
);
|
|
643
|
+
|
|
644
|
+
monacoSandboxTypeLibsInjected = true;
|
|
575
645
|
};
|
|
576
646
|
|
|
577
647
|
const handleMount: OnMount = (editor, monaco) => {
|
|
@@ -592,12 +662,21 @@ declare module 'next/server' {
|
|
|
592
662
|
acquireTypes(value);
|
|
593
663
|
}, [value, acquireTypes]);
|
|
594
664
|
|
|
665
|
+
const modelPath =
|
|
666
|
+
path && path.length
|
|
667
|
+
? path.startsWith("file://")
|
|
668
|
+
? path
|
|
669
|
+
: `file:///${path.replace(/^\/+/, "")}`
|
|
670
|
+
: undefined;
|
|
671
|
+
|
|
595
672
|
return (
|
|
596
673
|
<div className="absolute inset-0">
|
|
597
674
|
<MonacoEditorLib
|
|
675
|
+
key={modelPath ?? language}
|
|
598
676
|
height="100%"
|
|
599
677
|
width="100%"
|
|
600
|
-
language={language
|
|
678
|
+
language={language.includes("typescript") ? "typescript" : "javascript"}
|
|
679
|
+
path={modelPath}
|
|
601
680
|
theme="vs-dark"
|
|
602
681
|
value={value}
|
|
603
682
|
onChange={(val) => onChange(val ?? "")}
|
|
@@ -942,7 +1021,7 @@ export default function CodeRunnerModal() {
|
|
|
942
1021
|
);
|
|
943
1022
|
|
|
944
1023
|
// ── Editor mode ───────────────────────────────────────────
|
|
945
|
-
const [useMonacoEditor, setUseMonacoEditor] = useState(
|
|
1024
|
+
const [useMonacoEditor, setUseMonacoEditor] = useState(true);
|
|
946
1025
|
|
|
947
1026
|
// ── Sandbox state ─────────────────────────────────────────
|
|
948
1027
|
const [mode, setMode] = useState<"script" | "sandbox">("script");
|
|
@@ -3750,7 +3829,7 @@ export default function CodeRunnerModal() {
|
|
|
3750
3829
|
title={
|
|
3751
3830
|
useMonacoEditor
|
|
3752
3831
|
? "Switch to simple editor"
|
|
3753
|
-
: "Switch to Monaco
|
|
3832
|
+
: "Switch to Monaco editor"
|
|
3754
3833
|
}
|
|
3755
3834
|
>
|
|
3756
3835
|
<Code2 className="w-3 h-3" />
|
|
@@ -3790,6 +3869,9 @@ export default function CodeRunnerModal() {
|
|
|
3790
3869
|
onChange={setCode}
|
|
3791
3870
|
onCtrlEnter={() => void runCode()}
|
|
3792
3871
|
language={lang}
|
|
3872
|
+
path={
|
|
3873
|
+
lang === "typescript" ? "sandbox/main.ts" : "sandbox/main.js"
|
|
3874
|
+
}
|
|
3793
3875
|
autoFocus
|
|
3794
3876
|
fontSize="13px"
|
|
3795
3877
|
placeholder={`// TypeScript / JavaScript\n// Ctrl+Enter to run\n\nconst res = await fetch('https://jsonplaceholder.typicode.com/todos/1');\nconst data = await res.json();\nconsole.log(data);`}
|
|
@@ -3966,6 +4048,11 @@ export default function CodeRunnerModal() {
|
|
|
3966
4048
|
onChange={setServerCode}
|
|
3967
4049
|
onCtrlEnter={() => void startServer()}
|
|
3968
4050
|
language={serverLang}
|
|
4051
|
+
path={
|
|
4052
|
+
serverLang === "typescript"
|
|
4053
|
+
? "sandbox/server.ts"
|
|
4054
|
+
: "sandbox/server.js"
|
|
4055
|
+
}
|
|
3969
4056
|
fontSize="12px"
|
|
3970
4057
|
placeholder={
|
|
3971
4058
|
"import express from 'express';\n// process.env.PORT is auto-injected\n// Ctrl+Enter to start"
|
|
@@ -4723,6 +4810,11 @@ export default function CodeRunnerModal() {
|
|
|
4723
4810
|
if (serverRunning) void runClient();
|
|
4724
4811
|
}}
|
|
4725
4812
|
language={clientLang}
|
|
4813
|
+
path={
|
|
4814
|
+
clientLang === "typescript"
|
|
4815
|
+
? "sandbox/client.ts"
|
|
4816
|
+
: "sandbox/client.js"
|
|
4817
|
+
}
|
|
4726
4818
|
fontSize="12px"
|
|
4727
4819
|
placeholder={
|
|
4728
4820
|
"// SANDBOX_URL is injected automatically\n// Start the server first, then Ctrl+Enter to run"
|
|
@@ -4781,6 +4873,7 @@ export default function CodeRunnerModal() {
|
|
|
4781
4873
|
? "typescript"
|
|
4782
4874
|
: "javascript"
|
|
4783
4875
|
}
|
|
4876
|
+
path={reactActiveFile}
|
|
4784
4877
|
fontSize="12px"
|
|
4785
4878
|
placeholder={`// ${reactActiveFile}\n`}
|
|
4786
4879
|
/>
|
|
@@ -4795,10 +4888,13 @@ export default function CodeRunnerModal() {
|
|
|
4795
4888
|
}))
|
|
4796
4889
|
}
|
|
4797
4890
|
language={
|
|
4798
|
-
reactActiveFile.endsWith(".ts") ||
|
|
4799
4891
|
reactActiveFile.endsWith(".tsx")
|
|
4800
|
-
? "
|
|
4801
|
-
: "
|
|
4892
|
+
? "typescriptreact"
|
|
4893
|
+
: reactActiveFile.endsWith(".ts")
|
|
4894
|
+
? "typescript"
|
|
4895
|
+
: reactActiveFile.endsWith(".jsx")
|
|
4896
|
+
? "javascriptreact"
|
|
4897
|
+
: "javascript"
|
|
4802
4898
|
}
|
|
4803
4899
|
fontSize="12px"
|
|
4804
4900
|
focusRingClass="ring-cyan-500/30"
|