@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
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils-BiVyytui.js');
|
|
4
|
+
var staticBrowserServer = require('static-browser-server');
|
|
5
|
+
var consoleHook = require('./consoleHook-znXctRzh.js');
|
|
6
|
+
var base = require('./base-DelKLlDk.js');
|
|
7
|
+
var iframeFactory = require('./iframe-factory-BcC-S_XQ.js');
|
|
8
|
+
require('outvariant');
|
|
9
|
+
require('./types-BIIEoWr6.js');
|
|
10
|
+
require('@zenfs/core');
|
|
11
|
+
require('dequal');
|
|
12
|
+
|
|
13
|
+
var insertHtmlAfterRegex = function (regex, content, insertable) {
|
|
14
|
+
var match = regex.exec(content);
|
|
15
|
+
if (match && match.length >= 1) {
|
|
16
|
+
var offset = match.index + match[0].length;
|
|
17
|
+
var prefix = content.substring(0, offset);
|
|
18
|
+
var suffix = content.substring(offset);
|
|
19
|
+
return prefix + insertable + suffix;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var readBuffer = function (content) {
|
|
23
|
+
if (typeof content === "string") {
|
|
24
|
+
return content;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return new TextDecoder().decode(content);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var validateHtml = function (content) {
|
|
31
|
+
// Make it a string
|
|
32
|
+
var contentString = readBuffer(content);
|
|
33
|
+
var domParser = new DOMParser();
|
|
34
|
+
var doc = domParser.parseFromString(contentString, "text/html");
|
|
35
|
+
if (!doc.documentElement.getAttribute("lang")) {
|
|
36
|
+
doc.documentElement.setAttribute("lang", "en");
|
|
37
|
+
}
|
|
38
|
+
var html = doc.documentElement.outerHTML;
|
|
39
|
+
return "<!DOCTYPE html>\n".concat(html);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var SandpackStatic = /** @class */ (function (_super) {
|
|
43
|
+
utils.__extends(SandpackStatic, _super);
|
|
44
|
+
function SandpackStatic(selector, sandboxSetup, options) {
|
|
45
|
+
if (options === void 0) { options = {}; }
|
|
46
|
+
var _a;
|
|
47
|
+
var _this = _super.call(this, selector, sandboxSetup, options) || this;
|
|
48
|
+
_this.status = "initializing";
|
|
49
|
+
_this.emitter = new consoleHook.EventEmitter();
|
|
50
|
+
var previewOptions = {
|
|
51
|
+
baseUrl: (_a = options.bundlerURL) !== null && _a !== void 0 ? _a : "https://preview.sandpack-static-server.codesandbox.io",
|
|
52
|
+
transformResponse: function (_a) {
|
|
53
|
+
var filepath = _a.filepath, content = _a.content;
|
|
54
|
+
if (!filepath.endsWith(".html") && !filepath.endsWith(".htm")) {
|
|
55
|
+
return readBuffer(content);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
var out = validateHtml(content);
|
|
59
|
+
out = _this.injectProtocolScript(out);
|
|
60
|
+
out = _this.injectExternalResources(out, options.externalResources);
|
|
61
|
+
out = _this.injectScriptIntoHead(out, {
|
|
62
|
+
script: consoleHook.consoleHook,
|
|
63
|
+
scope: { channelId: consoleHook.generateRandomId() },
|
|
64
|
+
});
|
|
65
|
+
return readBuffer(out);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.error("Runtime injection failed", err);
|
|
69
|
+
return readBuffer(content);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
_this.previewController = new staticBrowserServer.PreviewController(previewOptions);
|
|
74
|
+
if (typeof selector === "string") {
|
|
75
|
+
_this.selector = selector;
|
|
76
|
+
var element = document.querySelector(selector);
|
|
77
|
+
_this.element = element;
|
|
78
|
+
// Opaque-origin app iframe via the single factory (G1/T1) — untrusted
|
|
79
|
+
// preview content runs at an opaque origin (see the runtime client).
|
|
80
|
+
_this.iframe = iframeFactory.createSandboxedIframe();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
_this.element = selector;
|
|
84
|
+
_this.iframe = selector;
|
|
85
|
+
}
|
|
86
|
+
// Set-and-assert: harden a host-provided iframe; verify no allow-same-origin.
|
|
87
|
+
iframeFactory.ensureSandboxed(_this.iframe);
|
|
88
|
+
_this.eventListener = _this.eventListener.bind(_this);
|
|
89
|
+
if (typeof window !== "undefined") {
|
|
90
|
+
window.addEventListener("message", _this.eventListener);
|
|
91
|
+
}
|
|
92
|
+
// Dispatch very first compile action
|
|
93
|
+
_this.updateSandbox();
|
|
94
|
+
return _this;
|
|
95
|
+
}
|
|
96
|
+
SandpackStatic.prototype.injectContentIntoHead = function (content, contentToInsert) {
|
|
97
|
+
var _a;
|
|
98
|
+
// Make it a string
|
|
99
|
+
content = readBuffer(content);
|
|
100
|
+
// Inject script
|
|
101
|
+
content =
|
|
102
|
+
(_a = insertHtmlAfterRegex(/<head[^<>]*>/g, content, "\n" + contentToInsert)) !== null && _a !== void 0 ? _a : contentToInsert + "\n" + content;
|
|
103
|
+
return content;
|
|
104
|
+
};
|
|
105
|
+
SandpackStatic.prototype.injectProtocolScript = function (content) {
|
|
106
|
+
var scriptToInsert = "<script>\n window.addEventListener(\"message\", (message) => {\n if(message.data.type === \"refresh\") {\n window.location.reload();\n }\n })\n</script>";
|
|
107
|
+
return this.injectContentIntoHead(content, scriptToInsert);
|
|
108
|
+
};
|
|
109
|
+
SandpackStatic.prototype.injectExternalResources = function (content, externalResources) {
|
|
110
|
+
if (externalResources === void 0) { externalResources = []; }
|
|
111
|
+
var tagsToInsert = externalResources
|
|
112
|
+
.map(function (resource) {
|
|
113
|
+
var match = resource.match(/\.([^.]*)$/);
|
|
114
|
+
var fileType = match === null || match === void 0 ? void 0 : match[1];
|
|
115
|
+
if (fileType === "css" || resource.includes("fonts.googleapis")) {
|
|
116
|
+
return "<link rel=\"stylesheet\" href=\"".concat(resource, "\">");
|
|
117
|
+
}
|
|
118
|
+
if (fileType === "js") {
|
|
119
|
+
return "<script src=\"".concat(resource, "\"></script>");
|
|
120
|
+
}
|
|
121
|
+
throw new Error("Unable to determine file type for external resource: ".concat(resource));
|
|
122
|
+
})
|
|
123
|
+
.join("\n");
|
|
124
|
+
return this.injectContentIntoHead(content, tagsToInsert);
|
|
125
|
+
};
|
|
126
|
+
SandpackStatic.prototype.injectScriptIntoHead = function (content, opts) {
|
|
127
|
+
var script = opts.script, _a = opts.scope, scope = _a === void 0 ? {} : _a;
|
|
128
|
+
var scriptToInsert = "\n <script>\n const scope = ".concat(JSON.stringify(scope), ";\n ").concat(script, "\n </script>\n ").trim();
|
|
129
|
+
return this.injectContentIntoHead(content, scriptToInsert);
|
|
130
|
+
};
|
|
131
|
+
SandpackStatic.prototype.updateSandbox = function (setup, _isInitializationCompile) {
|
|
132
|
+
if (setup === void 0) { setup = this.sandboxSetup; }
|
|
133
|
+
this.sandboxSetup = utils.__assign(utils.__assign({}, this.sandboxSetup), setup);
|
|
134
|
+
void this.updateSandboxAsync(setup);
|
|
135
|
+
};
|
|
136
|
+
SandpackStatic.prototype.updateSandboxAsync = function (setup) {
|
|
137
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
138
|
+
return utils.__generator(this, function (_a) {
|
|
139
|
+
// File content is served straight from zenfs by the static preview
|
|
140
|
+
// runtime, so the compile message no longer needs to carry files.
|
|
141
|
+
this.dispatch({
|
|
142
|
+
codesandbox: true,
|
|
143
|
+
template: setup.template,
|
|
144
|
+
type: "compile",
|
|
145
|
+
});
|
|
146
|
+
return [2 /*return*/];
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
SandpackStatic.prototype.compile = function () {
|
|
151
|
+
return utils.__awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var previewUrl;
|
|
153
|
+
return utils.__generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0: return [4 /*yield*/, this.previewController.initPreview()];
|
|
156
|
+
case 1:
|
|
157
|
+
previewUrl = _a.sent();
|
|
158
|
+
this.iframe.setAttribute("src", previewUrl);
|
|
159
|
+
this.status = "done";
|
|
160
|
+
this.dispatch({ type: "done", compilatonError: false });
|
|
161
|
+
this.dispatch({
|
|
162
|
+
type: "urlchange",
|
|
163
|
+
url: previewUrl,
|
|
164
|
+
back: false,
|
|
165
|
+
forward: false,
|
|
166
|
+
});
|
|
167
|
+
return [2 /*return*/];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
// Handles message windows coming from iframes
|
|
173
|
+
SandpackStatic.prototype.eventListener = function (evt) {
|
|
174
|
+
// skip events originating from different iframes
|
|
175
|
+
if (evt.source !== this.iframe.contentWindow) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
var message = evt.data;
|
|
179
|
+
if (!message.codesandbox) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.dispatch(message);
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Bundler communication
|
|
186
|
+
*/
|
|
187
|
+
SandpackStatic.prototype.dispatch = function (message) {
|
|
188
|
+
var _a;
|
|
189
|
+
switch (message.type) {
|
|
190
|
+
case "compile":
|
|
191
|
+
this.compile();
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
(_a = this.iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, "*");
|
|
195
|
+
this.emitter.dispatch(message);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
SandpackStatic.prototype.listen = function (listener) {
|
|
199
|
+
return this.emitter.listener(listener);
|
|
200
|
+
};
|
|
201
|
+
SandpackStatic.prototype.destroy = function () {
|
|
202
|
+
this.emitter.cleanup();
|
|
203
|
+
if (typeof window !== "undefined") {
|
|
204
|
+
window.removeEventListener("message", this.eventListener);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
return SandpackStatic;
|
|
208
|
+
}(base.SandpackClient));
|
|
209
|
+
|
|
210
|
+
exports.SandpackStatic = SandpackStatic;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { g as __extends, h as __assign, _ as __awaiter, a as __generator } from './utils-DG1HA4RZ.mjs';
|
|
2
|
+
import { PreviewController } from 'static-browser-server';
|
|
3
|
+
import { E as EventEmitter, g as generateRandomId, c as consoleHook } from './consoleHook-DQVWjDRE.mjs';
|
|
4
|
+
import { S as SandpackClient } from './base-DBh7xJX9.mjs';
|
|
5
|
+
import { c as createSandboxedIframe, e as ensureSandboxed } from './iframe-factory-DybmkzJZ.mjs';
|
|
6
|
+
import 'outvariant';
|
|
7
|
+
import './types-BFONOA2L.mjs';
|
|
8
|
+
import '@zenfs/core';
|
|
9
|
+
import 'dequal';
|
|
10
|
+
|
|
11
|
+
var insertHtmlAfterRegex = function (regex, content, insertable) {
|
|
12
|
+
var match = regex.exec(content);
|
|
13
|
+
if (match && match.length >= 1) {
|
|
14
|
+
var offset = match.index + match[0].length;
|
|
15
|
+
var prefix = content.substring(0, offset);
|
|
16
|
+
var suffix = content.substring(offset);
|
|
17
|
+
return prefix + insertable + suffix;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var readBuffer = function (content) {
|
|
21
|
+
if (typeof content === "string") {
|
|
22
|
+
return content;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return new TextDecoder().decode(content);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var validateHtml = function (content) {
|
|
29
|
+
// Make it a string
|
|
30
|
+
var contentString = readBuffer(content);
|
|
31
|
+
var domParser = new DOMParser();
|
|
32
|
+
var doc = domParser.parseFromString(contentString, "text/html");
|
|
33
|
+
if (!doc.documentElement.getAttribute("lang")) {
|
|
34
|
+
doc.documentElement.setAttribute("lang", "en");
|
|
35
|
+
}
|
|
36
|
+
var html = doc.documentElement.outerHTML;
|
|
37
|
+
return "<!DOCTYPE html>\n".concat(html);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var SandpackStatic = /** @class */ (function (_super) {
|
|
41
|
+
__extends(SandpackStatic, _super);
|
|
42
|
+
function SandpackStatic(selector, sandboxSetup, options) {
|
|
43
|
+
if (options === void 0) { options = {}; }
|
|
44
|
+
var _a;
|
|
45
|
+
var _this = _super.call(this, selector, sandboxSetup, options) || this;
|
|
46
|
+
_this.status = "initializing";
|
|
47
|
+
_this.emitter = new EventEmitter();
|
|
48
|
+
var previewOptions = {
|
|
49
|
+
baseUrl: (_a = options.bundlerURL) !== null && _a !== void 0 ? _a : "https://preview.sandpack-static-server.codesandbox.io",
|
|
50
|
+
transformResponse: function (_a) {
|
|
51
|
+
var filepath = _a.filepath, content = _a.content;
|
|
52
|
+
if (!filepath.endsWith(".html") && !filepath.endsWith(".htm")) {
|
|
53
|
+
return readBuffer(content);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
var out = validateHtml(content);
|
|
57
|
+
out = _this.injectProtocolScript(out);
|
|
58
|
+
out = _this.injectExternalResources(out, options.externalResources);
|
|
59
|
+
out = _this.injectScriptIntoHead(out, {
|
|
60
|
+
script: consoleHook,
|
|
61
|
+
scope: { channelId: generateRandomId() },
|
|
62
|
+
});
|
|
63
|
+
return readBuffer(out);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error("Runtime injection failed", err);
|
|
67
|
+
return readBuffer(content);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
_this.previewController = new PreviewController(previewOptions);
|
|
72
|
+
if (typeof selector === "string") {
|
|
73
|
+
_this.selector = selector;
|
|
74
|
+
var element = document.querySelector(selector);
|
|
75
|
+
_this.element = element;
|
|
76
|
+
// Opaque-origin app iframe via the single factory (G1/T1) — untrusted
|
|
77
|
+
// preview content runs at an opaque origin (see the runtime client).
|
|
78
|
+
_this.iframe = createSandboxedIframe();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
_this.element = selector;
|
|
82
|
+
_this.iframe = selector;
|
|
83
|
+
}
|
|
84
|
+
// Set-and-assert: harden a host-provided iframe; verify no allow-same-origin.
|
|
85
|
+
ensureSandboxed(_this.iframe);
|
|
86
|
+
_this.eventListener = _this.eventListener.bind(_this);
|
|
87
|
+
if (typeof window !== "undefined") {
|
|
88
|
+
window.addEventListener("message", _this.eventListener);
|
|
89
|
+
}
|
|
90
|
+
// Dispatch very first compile action
|
|
91
|
+
_this.updateSandbox();
|
|
92
|
+
return _this;
|
|
93
|
+
}
|
|
94
|
+
SandpackStatic.prototype.injectContentIntoHead = function (content, contentToInsert) {
|
|
95
|
+
var _a;
|
|
96
|
+
// Make it a string
|
|
97
|
+
content = readBuffer(content);
|
|
98
|
+
// Inject script
|
|
99
|
+
content =
|
|
100
|
+
(_a = insertHtmlAfterRegex(/<head[^<>]*>/g, content, "\n" + contentToInsert)) !== null && _a !== void 0 ? _a : contentToInsert + "\n" + content;
|
|
101
|
+
return content;
|
|
102
|
+
};
|
|
103
|
+
SandpackStatic.prototype.injectProtocolScript = function (content) {
|
|
104
|
+
var scriptToInsert = "<script>\n window.addEventListener(\"message\", (message) => {\n if(message.data.type === \"refresh\") {\n window.location.reload();\n }\n })\n</script>";
|
|
105
|
+
return this.injectContentIntoHead(content, scriptToInsert);
|
|
106
|
+
};
|
|
107
|
+
SandpackStatic.prototype.injectExternalResources = function (content, externalResources) {
|
|
108
|
+
if (externalResources === void 0) { externalResources = []; }
|
|
109
|
+
var tagsToInsert = externalResources
|
|
110
|
+
.map(function (resource) {
|
|
111
|
+
var match = resource.match(/\.([^.]*)$/);
|
|
112
|
+
var fileType = match === null || match === void 0 ? void 0 : match[1];
|
|
113
|
+
if (fileType === "css" || resource.includes("fonts.googleapis")) {
|
|
114
|
+
return "<link rel=\"stylesheet\" href=\"".concat(resource, "\">");
|
|
115
|
+
}
|
|
116
|
+
if (fileType === "js") {
|
|
117
|
+
return "<script src=\"".concat(resource, "\"></script>");
|
|
118
|
+
}
|
|
119
|
+
throw new Error("Unable to determine file type for external resource: ".concat(resource));
|
|
120
|
+
})
|
|
121
|
+
.join("\n");
|
|
122
|
+
return this.injectContentIntoHead(content, tagsToInsert);
|
|
123
|
+
};
|
|
124
|
+
SandpackStatic.prototype.injectScriptIntoHead = function (content, opts) {
|
|
125
|
+
var script = opts.script, _a = opts.scope, scope = _a === void 0 ? {} : _a;
|
|
126
|
+
var scriptToInsert = "\n <script>\n const scope = ".concat(JSON.stringify(scope), ";\n ").concat(script, "\n </script>\n ").trim();
|
|
127
|
+
return this.injectContentIntoHead(content, scriptToInsert);
|
|
128
|
+
};
|
|
129
|
+
SandpackStatic.prototype.updateSandbox = function (setup, _isInitializationCompile) {
|
|
130
|
+
if (setup === void 0) { setup = this.sandboxSetup; }
|
|
131
|
+
this.sandboxSetup = __assign(__assign({}, this.sandboxSetup), setup);
|
|
132
|
+
void this.updateSandboxAsync(setup);
|
|
133
|
+
};
|
|
134
|
+
SandpackStatic.prototype.updateSandboxAsync = function (setup) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
// File content is served straight from zenfs by the static preview
|
|
138
|
+
// runtime, so the compile message no longer needs to carry files.
|
|
139
|
+
this.dispatch({
|
|
140
|
+
codesandbox: true,
|
|
141
|
+
template: setup.template,
|
|
142
|
+
type: "compile",
|
|
143
|
+
});
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
SandpackStatic.prototype.compile = function () {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
var previewUrl;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, this.previewController.initPreview()];
|
|
154
|
+
case 1:
|
|
155
|
+
previewUrl = _a.sent();
|
|
156
|
+
this.iframe.setAttribute("src", previewUrl);
|
|
157
|
+
this.status = "done";
|
|
158
|
+
this.dispatch({ type: "done", compilatonError: false });
|
|
159
|
+
this.dispatch({
|
|
160
|
+
type: "urlchange",
|
|
161
|
+
url: previewUrl,
|
|
162
|
+
back: false,
|
|
163
|
+
forward: false,
|
|
164
|
+
});
|
|
165
|
+
return [2 /*return*/];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
// Handles message windows coming from iframes
|
|
171
|
+
SandpackStatic.prototype.eventListener = function (evt) {
|
|
172
|
+
// skip events originating from different iframes
|
|
173
|
+
if (evt.source !== this.iframe.contentWindow) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
var message = evt.data;
|
|
177
|
+
if (!message.codesandbox) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.dispatch(message);
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Bundler communication
|
|
184
|
+
*/
|
|
185
|
+
SandpackStatic.prototype.dispatch = function (message) {
|
|
186
|
+
var _a;
|
|
187
|
+
switch (message.type) {
|
|
188
|
+
case "compile":
|
|
189
|
+
this.compile();
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
(_a = this.iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, "*");
|
|
193
|
+
this.emitter.dispatch(message);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
SandpackStatic.prototype.listen = function (listener) {
|
|
197
|
+
return this.emitter.listener(listener);
|
|
198
|
+
};
|
|
199
|
+
SandpackStatic.prototype.destroy = function () {
|
|
200
|
+
this.emitter.cleanup();
|
|
201
|
+
if (typeof window !== "undefined") {
|
|
202
|
+
window.removeEventListener("message", this.eventListener);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
return SandpackStatic;
|
|
206
|
+
}(SandpackClient));
|
|
207
|
+
|
|
208
|
+
export { SandpackStatic };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils-BiVyytui.js');
|
|
4
|
+
var types = require('./types-BIIEoWr6.js');
|
|
5
|
+
require('outvariant');
|
|
6
|
+
require('@zenfs/core');
|
|
7
|
+
|
|
8
|
+
function loadSandpackClient(iframeSelector_1, sandboxSetup_1) {
|
|
9
|
+
return utils.__awaiter(this, arguments, void 0, function (iframeSelector, sandboxSetup, options) {
|
|
10
|
+
var template, Client, _a;
|
|
11
|
+
var _b;
|
|
12
|
+
if (options === void 0) { options = {}; }
|
|
13
|
+
return utils.__generator(this, function (_c) {
|
|
14
|
+
switch (_c.label) {
|
|
15
|
+
case 0:
|
|
16
|
+
template = (_b = sandboxSetup.template) !== null && _b !== void 0 ? _b : "parcel";
|
|
17
|
+
_a = template;
|
|
18
|
+
switch (_a) {
|
|
19
|
+
case "node": return [3 /*break*/, 1];
|
|
20
|
+
case "static": return [3 /*break*/, 3];
|
|
21
|
+
}
|
|
22
|
+
return [3 /*break*/, 5];
|
|
23
|
+
case 1: return [4 /*yield*/, Promise.resolve().then(function () { return require('./clients/node/index.js'); }).then(function (m) { return m.SandpackNode; })];
|
|
24
|
+
case 2:
|
|
25
|
+
Client = _c.sent();
|
|
26
|
+
return [3 /*break*/, 7];
|
|
27
|
+
case 3: return [4 /*yield*/, Promise.resolve().then(function () { return require('./index--fILWAw8.js'); }).then(function (m) { return m.SandpackStatic; })];
|
|
28
|
+
case 4:
|
|
29
|
+
Client = _c.sent();
|
|
30
|
+
return [3 /*break*/, 7];
|
|
31
|
+
case 5: return [4 /*yield*/, Promise.resolve().then(function () { return require('./clients/runtime/index.js'); }).then(function (m) { return m.SandpackRuntime; })];
|
|
32
|
+
case 6:
|
|
33
|
+
Client = _c.sent();
|
|
34
|
+
_c.label = 7;
|
|
35
|
+
case 7: return [2 /*return*/, new Client(iframeSelector, sandboxSetup, options)];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.addPackageJSONIfNeededToMap = utils.addPackageJSONIfNeededToMap;
|
|
42
|
+
exports.createError = utils.createError;
|
|
43
|
+
exports.createPackageJSON = utils.createPackageJSON;
|
|
44
|
+
exports.extractErrorDetails = utils.extractErrorDetails;
|
|
45
|
+
exports.normalizePath = utils.normalizePath;
|
|
46
|
+
exports.nullthrows = utils.nullthrows;
|
|
47
|
+
exports.META_PATH = types.META_PATH;
|
|
48
|
+
exports.SandpackFS = types.SandpackFS;
|
|
49
|
+
Object.defineProperty(exports, "SandpackLogLevel", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return types.SandpackLogLevel; }
|
|
52
|
+
});
|
|
53
|
+
exports.loadSandpackClient = loadSandpackClient;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { _ as __awaiter, a as __generator } from './utils-DG1HA4RZ.mjs';
|
|
2
|
+
export { b as addPackageJSONIfNeededToMap, c as createError, d as createPackageJSON, e as extractErrorDetails, n as normalizePath, f as nullthrows } from './utils-DG1HA4RZ.mjs';
|
|
3
|
+
export { M as META_PATH, S as SandpackFS, a as SandpackLogLevel } from './types-BFONOA2L.mjs';
|
|
4
|
+
import 'outvariant';
|
|
5
|
+
import '@zenfs/core';
|
|
6
|
+
|
|
7
|
+
function loadSandpackClient(iframeSelector_1, sandboxSetup_1) {
|
|
8
|
+
return __awaiter(this, arguments, void 0, function (iframeSelector, sandboxSetup, options) {
|
|
9
|
+
var template, Client, _a;
|
|
10
|
+
var _b;
|
|
11
|
+
if (options === void 0) { options = {}; }
|
|
12
|
+
return __generator(this, function (_c) {
|
|
13
|
+
switch (_c.label) {
|
|
14
|
+
case 0:
|
|
15
|
+
template = (_b = sandboxSetup.template) !== null && _b !== void 0 ? _b : "parcel";
|
|
16
|
+
_a = template;
|
|
17
|
+
switch (_a) {
|
|
18
|
+
case "node": return [3 /*break*/, 1];
|
|
19
|
+
case "static": return [3 /*break*/, 3];
|
|
20
|
+
}
|
|
21
|
+
return [3 /*break*/, 5];
|
|
22
|
+
case 1: return [4 /*yield*/, import('./clients/node/index.mjs').then(function (m) { return m.SandpackNode; })];
|
|
23
|
+
case 2:
|
|
24
|
+
Client = _c.sent();
|
|
25
|
+
return [3 /*break*/, 7];
|
|
26
|
+
case 3: return [4 /*yield*/, import('./index-rbhm_KmF.mjs').then(function (m) { return m.SandpackStatic; })];
|
|
27
|
+
case 4:
|
|
28
|
+
Client = _c.sent();
|
|
29
|
+
return [3 /*break*/, 7];
|
|
30
|
+
case 5: return [4 /*yield*/, import('./clients/runtime/index.mjs').then(function (m) { return m.SandpackRuntime; })];
|
|
31
|
+
case 6:
|
|
32
|
+
Client = _c.sent();
|
|
33
|
+
_c.label = 7;
|
|
34
|
+
case 7: return [2 /*return*/, new Client(iframeSelector, sandboxSetup, options)];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { loadSandpackClient };
|