@immediately-run/sandpack-client 2.19.8
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/README.md +26 -0
- package/dist/.ir-build-stamp.json +6 -0
- package/dist/base-DBh7xJX9.mjs +48 -0
- package/dist/base-DelKLlDk.js +50 -0
- package/dist/clients/base.d.ts +34 -0
- package/dist/clients/event-emitter.d.ts +10 -0
- package/dist/clients/iframe-factory.d.ts +27 -0
- package/dist/clients/index.d.ts +4 -0
- package/dist/clients/node/client.utils.d.ts +7 -0
- package/dist/clients/node/iframe.utils.d.ts +3 -0
- package/dist/clients/node/index.d.ts +49 -0
- package/dist/clients/node/index.js +631 -0
- package/dist/clients/node/index.mjs +629 -0
- package/dist/clients/node/inject-scripts/historyListener.d.ts +5 -0
- package/dist/clients/node/inject-scripts/index.d.ts +1 -0
- package/dist/clients/node/inject-scripts/resize.d.ts +5 -0
- package/dist/clients/node/taskManager.d.ts +20 -0
- package/dist/clients/node/types.d.ts +63 -0
- package/dist/clients/runtime/file-resolver-protocol.d.ts +17 -0
- package/dist/clients/runtime/iframe-protocol.d.ts +17 -0
- package/dist/clients/runtime/immutable-fetch-protocol.d.ts +39 -0
- package/dist/clients/runtime/index.d.ts +76 -0
- package/dist/clients/runtime/index.js +1046 -0
- package/dist/clients/runtime/index.mjs +1044 -0
- package/dist/clients/runtime/mime.d.ts +1 -0
- package/dist/clients/runtime/types.d.ts +129 -0
- package/dist/clients/runtime/utils.d.ts +8 -0
- package/dist/clients/static/index.d.ts +25 -0
- package/dist/clients/static/utils.d.ts +5 -0
- package/dist/consoleHook-DQVWjDRE.mjs +230 -0
- package/dist/consoleHook-znXctRzh.js +236 -0
- package/dist/fs/SandpackFS.d.ts +116 -0
- package/dist/iframe-factory-BcC-S_XQ.js +54 -0
- package/dist/iframe-factory-DybmkzJZ.mjs +51 -0
- package/dist/index--fILWAw8.js +210 -0
- package/dist/index-rbhm_KmF.mjs +208 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +53 -0
- package/dist/index.mjs +40 -0
- package/dist/inject-scripts/consoleHook.d.ts +6 -0
- package/dist/types-BFONOA2L.mjs +531 -0
- package/dist/types-BIIEoWr6.js +534 -0
- package/dist/types.d.ts +348 -0
- package/dist/utils-BiVyytui.js +262 -0
- package/dist/utils-DG1HA4RZ.mjs +250 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +13 -0
- package/dist/utils.mjs +2 -0
- package/package.json +82 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<img style="width:100%" src="https://user-images.githubusercontent.com/4838076/143581035-ebee5ba2-9cb1-4fe8-a05b-2f44bd69bb4b.gif" alt="Component toolkit for live running code editing experiences" />
|
|
2
|
+
|
|
3
|
+
# Sandpack client
|
|
4
|
+
|
|
5
|
+
This is a small foundation package that sits on top of the bundler. It is
|
|
6
|
+
framework agnostic and facilitates the handshake between your context and the bundler iframe.
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
import { loadSandpackClient } from "@codesandbox/sandpack-client";
|
|
10
|
+
|
|
11
|
+
const main = async () => {
|
|
12
|
+
const client = await loadSandpackClient("#preview", {
|
|
13
|
+
files: {
|
|
14
|
+
"/index.js": {
|
|
15
|
+
code: `console.log(require('uuid'))`,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
entry: "/index.js",
|
|
19
|
+
dependencies: {
|
|
20
|
+
uuid: "latest",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
[Read more](https://sandpack.codesandbox.io/docs/advanced-usage/client)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { dequal } from 'dequal';
|
|
2
|
+
|
|
3
|
+
var SandpackClient = /** @class */ (function () {
|
|
4
|
+
function SandpackClient(iframeSelector, sandboxSetup, options) {
|
|
5
|
+
if (options === void 0) { options = {}; }
|
|
6
|
+
this.status = "idle";
|
|
7
|
+
this.options = options;
|
|
8
|
+
this.sandboxSetup = sandboxSetup;
|
|
9
|
+
this.iframeSelector = iframeSelector;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Clients handles
|
|
13
|
+
*/
|
|
14
|
+
SandpackClient.prototype.updateOptions = function (options) {
|
|
15
|
+
if (!dequal(this.options, options)) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.updateSandbox();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
SandpackClient.prototype.updateSandbox = function (_sandboxSetup, _isInitializationCompile) {
|
|
21
|
+
if (_sandboxSetup === void 0) { _sandboxSetup = this.sandboxSetup; }
|
|
22
|
+
throw Error("Method not implemented");
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Notify the bundler that the given paths changed in the shared filesystem.
|
|
26
|
+
* Only the runtime client needs this (its bundler can't observe parent writes
|
|
27
|
+
* itself); other clients re-bundle via {@link updateSandbox}, so this is a
|
|
28
|
+
* no-op for them.
|
|
29
|
+
*/
|
|
30
|
+
SandpackClient.prototype.notifyFilesChanged = function (_paths) {
|
|
31
|
+
// no-op by default
|
|
32
|
+
};
|
|
33
|
+
SandpackClient.prototype.destroy = function () {
|
|
34
|
+
throw Error("Method not implemented");
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Bundler communication
|
|
38
|
+
*/
|
|
39
|
+
SandpackClient.prototype.dispatch = function (_message) {
|
|
40
|
+
throw Error("Method not implemented");
|
|
41
|
+
};
|
|
42
|
+
SandpackClient.prototype.listen = function (_listener) {
|
|
43
|
+
throw Error("Method not implemented");
|
|
44
|
+
};
|
|
45
|
+
return SandpackClient;
|
|
46
|
+
}());
|
|
47
|
+
|
|
48
|
+
export { SandpackClient as S };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dequal = require('dequal');
|
|
4
|
+
|
|
5
|
+
var SandpackClient = /** @class */ (function () {
|
|
6
|
+
function SandpackClient(iframeSelector, sandboxSetup, options) {
|
|
7
|
+
if (options === void 0) { options = {}; }
|
|
8
|
+
this.status = "idle";
|
|
9
|
+
this.options = options;
|
|
10
|
+
this.sandboxSetup = sandboxSetup;
|
|
11
|
+
this.iframeSelector = iframeSelector;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Clients handles
|
|
15
|
+
*/
|
|
16
|
+
SandpackClient.prototype.updateOptions = function (options) {
|
|
17
|
+
if (!dequal.dequal(this.options, options)) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.updateSandbox();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
SandpackClient.prototype.updateSandbox = function (_sandboxSetup, _isInitializationCompile) {
|
|
23
|
+
if (_sandboxSetup === void 0) { _sandboxSetup = this.sandboxSetup; }
|
|
24
|
+
throw Error("Method not implemented");
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Notify the bundler that the given paths changed in the shared filesystem.
|
|
28
|
+
* Only the runtime client needs this (its bundler can't observe parent writes
|
|
29
|
+
* itself); other clients re-bundle via {@link updateSandbox}, so this is a
|
|
30
|
+
* no-op for them.
|
|
31
|
+
*/
|
|
32
|
+
SandpackClient.prototype.notifyFilesChanged = function (_paths) {
|
|
33
|
+
// no-op by default
|
|
34
|
+
};
|
|
35
|
+
SandpackClient.prototype.destroy = function () {
|
|
36
|
+
throw Error("Method not implemented");
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Bundler communication
|
|
40
|
+
*/
|
|
41
|
+
SandpackClient.prototype.dispatch = function (_message) {
|
|
42
|
+
throw Error("Method not implemented");
|
|
43
|
+
};
|
|
44
|
+
SandpackClient.prototype.listen = function (_listener) {
|
|
45
|
+
throw Error("Method not implemented");
|
|
46
|
+
};
|
|
47
|
+
return SandpackClient;
|
|
48
|
+
}());
|
|
49
|
+
|
|
50
|
+
exports.SandpackClient = SandpackClient;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ClientStatus } from "..";
|
|
2
|
+
import type { ClientOptions, SandboxSetup, ListenerFunction, SandpackMessage, UnsubscribeFunction } from "../types";
|
|
3
|
+
export declare class SandpackClient {
|
|
4
|
+
/**
|
|
5
|
+
* Sandbox configuration: files, setup, customizations;
|
|
6
|
+
*/
|
|
7
|
+
sandboxSetup: SandboxSetup;
|
|
8
|
+
options: ClientOptions;
|
|
9
|
+
/**
|
|
10
|
+
* DOM bindings
|
|
11
|
+
*/
|
|
12
|
+
iframe: HTMLIFrameElement;
|
|
13
|
+
iframeSelector: string | HTMLIFrameElement;
|
|
14
|
+
status: ClientStatus;
|
|
15
|
+
constructor(iframeSelector: string | HTMLIFrameElement, sandboxSetup: SandboxSetup, options?: ClientOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Clients handles
|
|
18
|
+
*/
|
|
19
|
+
updateOptions(options: ClientOptions): void;
|
|
20
|
+
updateSandbox(_sandboxSetup?: SandboxSetup, _isInitializationCompile?: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* Notify the bundler that the given paths changed in the shared filesystem.
|
|
23
|
+
* Only the runtime client needs this (its bundler can't observe parent writes
|
|
24
|
+
* itself); other clients re-bundle via {@link updateSandbox}, so this is a
|
|
25
|
+
* no-op for them.
|
|
26
|
+
*/
|
|
27
|
+
notifyFilesChanged(_paths: string[]): void;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Bundler communication
|
|
31
|
+
*/
|
|
32
|
+
dispatch(_message: SandpackMessage): void;
|
|
33
|
+
listen(_listener: ListenerFunction): UnsubscribeFunction;
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ListenerFunction, SandpackMessage, UnsubscribeFunction } from "..";
|
|
2
|
+
export declare class EventEmitter {
|
|
3
|
+
private listeners;
|
|
4
|
+
private listenersCount;
|
|
5
|
+
readonly channelId: number;
|
|
6
|
+
constructor();
|
|
7
|
+
cleanup(): void;
|
|
8
|
+
dispatch(message: SandpackMessage): void;
|
|
9
|
+
listener(listener: ListenerFunction): UnsubscribeFunction;
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single chokepoint for creating **app iframes** (UI_AS_APPS_SPEC §2 / G1 /
|
|
3
|
+
* threat T1).
|
|
4
|
+
*
|
|
5
|
+
* App iframes MUST be opaque-origin: `sandbox="allow-scripts …"` WITHOUT
|
|
6
|
+
* `allow-same-origin`. With `allow-same-origin` alongside `allow-scripts` an app
|
|
7
|
+
* could remove its own sandboxing and reach the parent — the whole capability
|
|
8
|
+
* model collapses. This is the one invariant with no defense-in-depth, so
|
|
9
|
+
* creation is centralized here and the resolved attribute is asserted. Raw
|
|
10
|
+
* `document.createElement('iframe')` for app content elsewhere is forbidden (a
|
|
11
|
+
* greppable CI check), so the verifiable invariant is "every app iframe is born
|
|
12
|
+
* in this factory."
|
|
13
|
+
*
|
|
14
|
+
* Scope: the opaque-origin app iframes (the runtime + static preview clients).
|
|
15
|
+
* The node/nodebox emulator is a different execution model and is intentionally
|
|
16
|
+
* NOT routed through here.
|
|
17
|
+
*/
|
|
18
|
+
/** Throw if the iframe would run scripts at a same-origin context (G1/T1). */
|
|
19
|
+
export declare function assertOpaqueOrigin(iframe: HTMLIFrameElement): void;
|
|
20
|
+
/** Create an opaque-origin sandboxed iframe for running untrusted app code. */
|
|
21
|
+
export declare function createSandboxedIframe(doc?: Document): HTMLIFrameElement;
|
|
22
|
+
/**
|
|
23
|
+
* Ensure a (possibly externally-provided) app iframe is opaque-origin: set the
|
|
24
|
+
* sandbox/allow attributes if absent, then assert no `allow-same-origin`. Use
|
|
25
|
+
* this for the case where a host passes in its own iframe element.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ensureSandboxed(iframe: HTMLIFrameElement): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ClientOptions, SandboxSetup } from "../types";
|
|
2
|
+
import type { SandpackClient as SandpackClientBase } from "./base";
|
|
3
|
+
export type { SandpackClient } from "./base";
|
|
4
|
+
export declare function loadSandpackClient(iframeSelector: string | HTMLIFrameElement, sandboxSetup: SandboxSetup, options?: ClientOptions): Promise<SandpackClientBase>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ShellCommandOptions } from "@codesandbox/nodebox/build/modules/shell";
|
|
2
|
+
export declare function generateRandomId(): string;
|
|
3
|
+
/**
|
|
4
|
+
* Figure out which script it must run to start a server
|
|
5
|
+
*/
|
|
6
|
+
export declare const findStartScriptPackageJson: (packageJson: string) => [string, string[], ShellCommandOptions];
|
|
7
|
+
export declare const getMessageFromError: (error: Error | string) => string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ClientOptions, ListenerFunction, SandboxSetup, UnsubscribeFunction } from "../..";
|
|
2
|
+
import { SandpackClient } from "../base";
|
|
3
|
+
import type { SandpackNodeMessage } from "./types";
|
|
4
|
+
export declare class SandpackNode extends SandpackClient {
|
|
5
|
+
private emitter;
|
|
6
|
+
private emulatorIframe;
|
|
7
|
+
private emulator;
|
|
8
|
+
private emulatorShellProcess;
|
|
9
|
+
private emulatorCommand;
|
|
10
|
+
private iframePreviewUrl;
|
|
11
|
+
private messageChannelId;
|
|
12
|
+
iframe: HTMLIFrameElement;
|
|
13
|
+
private _initPromise;
|
|
14
|
+
constructor(selector: string | HTMLIFrameElement, sandboxInfo: SandboxSetup, options?: ClientOptions);
|
|
15
|
+
private _init;
|
|
16
|
+
/**
|
|
17
|
+
* It initializes the emulator and provide it with files, template and script to run
|
|
18
|
+
*/
|
|
19
|
+
private compile;
|
|
20
|
+
/**
|
|
21
|
+
* It creates a new shell and run the starting task
|
|
22
|
+
*/
|
|
23
|
+
private createShellProcessFromTask;
|
|
24
|
+
private createPreviewURLFromId;
|
|
25
|
+
/**
|
|
26
|
+
* Nodebox needs to handle two types of iframes at the same time:
|
|
27
|
+
*
|
|
28
|
+
* 1. Runtime iframe: where the emulator process runs, which is responsible
|
|
29
|
+
* for creating the other iframes (hidden);
|
|
30
|
+
* 2. Preview iframes: any other node process that contains a PORT (public);
|
|
31
|
+
*/
|
|
32
|
+
private manageIframes;
|
|
33
|
+
private setLocationURLIntoIFrame;
|
|
34
|
+
/**
|
|
35
|
+
* Send all messages and events to tell to the
|
|
36
|
+
* consumer that the bundler is ready without any error
|
|
37
|
+
*/
|
|
38
|
+
private dispatchDoneMessage;
|
|
39
|
+
private globalListeners;
|
|
40
|
+
/**
|
|
41
|
+
* PUBLIC Methods
|
|
42
|
+
*/
|
|
43
|
+
restartShellProcess(): Promise<void>;
|
|
44
|
+
updateSandbox(setup: SandboxSetup): void;
|
|
45
|
+
private updateSandboxAsync;
|
|
46
|
+
dispatch(message: SandpackNodeMessage): Promise<void>;
|
|
47
|
+
listen(listener: ListenerFunction): UnsubscribeFunction;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|