@iconoma/studio 0.0.2 → 0.0.3
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/client/assets/base-80a1f760-CoEZcNUM.js +1 -0
- package/dist/client/assets/consoleHook-59e792cb-yZBeAxqn.js +2 -0
- package/dist/client/assets/index-599aeaf7-Cixb7nGt.js +16 -0
- package/dist/client/assets/index-BylEY29i.js +4 -0
- package/dist/client/assets/index-DNAC9YKz.js +800 -0
- package/dist/client/assets/index-F3h4OYZk.js +1 -0
- package/dist/client/assets/index-rCeq9qYz.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/assets/base-80a1f760--v78K3bW.js +40 -0
- package/dist/server/assets/consoleHook-59e792cb-KeP2TanF.js +250 -0
- package/dist/server/assets/index-599aeaf7-DI3wF-7N.js +8953 -0
- package/dist/server/assets/index-CIjBeg8V.js +1573 -0
- package/dist/server/assets/index-DXLUkVZK.js +3196 -0
- package/dist/server/entry-server.js +42472 -36676
- package/dist/server.js +1 -1
- package/package.json +5 -5
- package/dist/client/assets/base-80a1f760-DXByDNOn.js +0 -1
- package/dist/client/assets/consoleHook-59e792cb-Cc-Wa9Dv.js +0 -2
- package/dist/client/assets/index-2gul9srt.js +0 -810
- package/dist/client/assets/index-599aeaf7-CuvDGLig.js +0 -16
- package/dist/client/assets/index-B8EuJHGY.css +0 -1
- package/dist/client/assets/node-C6_XYplI.js +0 -4
- package/dist/client/assets/runtime-BL9Nzh_-.js +0 -1
- package/dist/server/assets/base-80a1f760-qtF4btYl.js +0 -31
- package/dist/server/assets/consoleHook-59e792cb-DzCtq2z9.js +0 -230
- package/dist/server/assets/index-599aeaf7-CrZ9wybV.js +0 -7378
- package/dist/server/assets/node-Cq9Cey_i.js +0 -1412
- package/dist/server/assets/runtime-Cj4RK1K3.js +0 -8158
|
@@ -0,0 +1,1573 @@
|
|
|
1
|
+
import { _ as __extends, a as __awaiter, b as __generator, c as __assign, d as createError, n as nullthrows } from "../entry-server.js";
|
|
2
|
+
import { S as SandpackClient } from "./base-80a1f760--v78K3bW.js";
|
|
3
|
+
import { g as getMessageFromError, r as readBuffer, f as findStartScriptPackageJson, w as writeBuffer, a as fromBundlerFilesToFS, b as generateRandomId, E as EventEmitter, c as consoleHook } from "./consoleHook-59e792cb-KeP2TanF.js";
|
|
4
|
+
import "react/jsx-runtime";
|
|
5
|
+
import "react";
|
|
6
|
+
import "react-dom/server";
|
|
7
|
+
import "react-router";
|
|
8
|
+
import "@tanstack/react-query";
|
|
9
|
+
import "axios";
|
|
10
|
+
import "lucide-react";
|
|
11
|
+
import "react-dom";
|
|
12
|
+
import "react-hook-form";
|
|
13
|
+
import "@hookform/resolvers/zod";
|
|
14
|
+
import "zod";
|
|
15
|
+
import "canvas-confetti";
|
|
16
|
+
import "react-dropzone";
|
|
17
|
+
var __create = Object.create;
|
|
18
|
+
var __defProp = Object.defineProperty;
|
|
19
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
20
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
21
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
22
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
23
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
24
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
25
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
36
|
+
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __publicField = (obj, key, value) => {
|
|
40
|
+
__defNormalProp(obj, key + "", value);
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
var __accessCheck = (obj, member, msg) => {
|
|
44
|
+
if (!member.has(obj))
|
|
45
|
+
throw TypeError("Cannot " + msg);
|
|
46
|
+
};
|
|
47
|
+
var __privateGet = (obj, member, getter) => {
|
|
48
|
+
__accessCheck(obj, member, "read from private field");
|
|
49
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
50
|
+
};
|
|
51
|
+
var __privateAdd = (obj, member, value) => {
|
|
52
|
+
if (member.has(obj))
|
|
53
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
54
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
55
|
+
};
|
|
56
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
57
|
+
__accessCheck(obj, member, "write to private field");
|
|
58
|
+
member.set(obj, value);
|
|
59
|
+
return value;
|
|
60
|
+
};
|
|
61
|
+
var __privateMethod = (obj, member, method) => {
|
|
62
|
+
__accessCheck(obj, member, "access private method");
|
|
63
|
+
return method;
|
|
64
|
+
};
|
|
65
|
+
var require_pad = __commonJS({
|
|
66
|
+
"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/pad.js"(exports$1, module) {
|
|
67
|
+
module.exports = function pad(num, size) {
|
|
68
|
+
var s = "000000000" + num;
|
|
69
|
+
return s.substr(s.length - size);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
var require_fingerprint_browser = __commonJS({
|
|
74
|
+
"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/fingerprint.browser.js"(exports$1, module) {
|
|
75
|
+
var pad = require_pad();
|
|
76
|
+
var env = typeof window === "object" ? window : self;
|
|
77
|
+
var globalCount = Object.keys(env).length;
|
|
78
|
+
var mimeTypesLength = navigator.mimeTypes ? navigator.mimeTypes.length : 0;
|
|
79
|
+
var clientId = pad((mimeTypesLength + navigator.userAgent.length).toString(36) + globalCount.toString(36), 4);
|
|
80
|
+
module.exports = function fingerprint() {
|
|
81
|
+
return clientId;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
var require_getRandomValue_browser = __commonJS({
|
|
86
|
+
"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/getRandomValue.browser.js"(exports$1, module) {
|
|
87
|
+
var getRandomValue;
|
|
88
|
+
var crypto = typeof window !== "undefined" && (window.crypto || window.msCrypto) || typeof self !== "undefined" && self.crypto;
|
|
89
|
+
if (crypto) {
|
|
90
|
+
lim = Math.pow(2, 32) - 1;
|
|
91
|
+
getRandomValue = function() {
|
|
92
|
+
return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0] / lim);
|
|
93
|
+
};
|
|
94
|
+
} else {
|
|
95
|
+
getRandomValue = Math.random;
|
|
96
|
+
}
|
|
97
|
+
var lim;
|
|
98
|
+
module.exports = getRandomValue;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
var require_cuid = __commonJS({
|
|
102
|
+
"../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/index.js"(exports$1, module) {
|
|
103
|
+
var fingerprint = require_fingerprint_browser();
|
|
104
|
+
var pad = require_pad();
|
|
105
|
+
var getRandomValue = require_getRandomValue_browser();
|
|
106
|
+
var c = 0;
|
|
107
|
+
var blockSize = 4;
|
|
108
|
+
var base = 36;
|
|
109
|
+
var discreteValues = Math.pow(base, blockSize);
|
|
110
|
+
function randomBlock() {
|
|
111
|
+
return pad((getRandomValue() * discreteValues << 0).toString(base), blockSize);
|
|
112
|
+
}
|
|
113
|
+
function safeCounter() {
|
|
114
|
+
c = c < discreteValues ? c : 0;
|
|
115
|
+
c++;
|
|
116
|
+
return c - 1;
|
|
117
|
+
}
|
|
118
|
+
function cuid3() {
|
|
119
|
+
var letter = "c", timestamp = (/* @__PURE__ */ new Date()).getTime().toString(base), counter = pad(safeCounter().toString(base), blockSize), print = fingerprint(), random = randomBlock() + randomBlock();
|
|
120
|
+
return letter + timestamp + counter + print + random;
|
|
121
|
+
}
|
|
122
|
+
cuid3.slug = function slug() {
|
|
123
|
+
var date = (/* @__PURE__ */ new Date()).getTime().toString(36), counter = safeCounter().toString(36).slice(-4), print = fingerprint().slice(0, 1) + fingerprint().slice(-1), random = randomBlock().slice(-2);
|
|
124
|
+
return date.slice(-2) + counter + print + random;
|
|
125
|
+
};
|
|
126
|
+
cuid3.isCuid = function isCuid(stringToCheck) {
|
|
127
|
+
if (typeof stringToCheck !== "string")
|
|
128
|
+
return false;
|
|
129
|
+
if (stringToCheck.startsWith("c"))
|
|
130
|
+
return true;
|
|
131
|
+
return false;
|
|
132
|
+
};
|
|
133
|
+
cuid3.isSlug = function isSlug(stringToCheck) {
|
|
134
|
+
if (typeof stringToCheck !== "string")
|
|
135
|
+
return false;
|
|
136
|
+
var stringLength = stringToCheck.length;
|
|
137
|
+
if (stringLength >= 7 && stringLength <= 10)
|
|
138
|
+
return true;
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
141
|
+
cuid3.fingerprint = fingerprint;
|
|
142
|
+
module.exports = cuid3;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
var require_createDeferredExecutor = __commonJS({
|
|
146
|
+
"../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/createDeferredExecutor.js"(exports$1) {
|
|
147
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
148
|
+
exports$1.createDeferredExecutor = void 0;
|
|
149
|
+
function createDeferredExecutor() {
|
|
150
|
+
const executor = (resolve, reject) => {
|
|
151
|
+
executor.state = "pending";
|
|
152
|
+
executor.resolve = (data) => {
|
|
153
|
+
if (executor.state !== "pending") {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
executor.result = data;
|
|
157
|
+
const onFulfilled = (value) => {
|
|
158
|
+
executor.state = "fulfilled";
|
|
159
|
+
return value;
|
|
160
|
+
};
|
|
161
|
+
return resolve(data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled));
|
|
162
|
+
};
|
|
163
|
+
executor.reject = (reason) => {
|
|
164
|
+
if (executor.state !== "pending") {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
queueMicrotask(() => {
|
|
168
|
+
executor.state = "rejected";
|
|
169
|
+
});
|
|
170
|
+
return reject(executor.rejectionReason = reason);
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
return executor;
|
|
174
|
+
}
|
|
175
|
+
exports$1.createDeferredExecutor = createDeferredExecutor;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
var require_DeferredPromise = __commonJS({
|
|
179
|
+
"../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/DeferredPromise.js"(exports$1) {
|
|
180
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
181
|
+
exports$1.DeferredPromise = void 0;
|
|
182
|
+
var createDeferredExecutor_1 = require_createDeferredExecutor();
|
|
183
|
+
var DeferredPromise4 = class extends Promise {
|
|
184
|
+
#executor;
|
|
185
|
+
resolve;
|
|
186
|
+
reject;
|
|
187
|
+
constructor(executor = null) {
|
|
188
|
+
const deferredExecutor = (0, createDeferredExecutor_1.createDeferredExecutor)();
|
|
189
|
+
super((originalResolve, originalReject) => {
|
|
190
|
+
deferredExecutor(originalResolve, originalReject);
|
|
191
|
+
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
192
|
+
});
|
|
193
|
+
this.#executor = deferredExecutor;
|
|
194
|
+
this.resolve = this.#executor.resolve;
|
|
195
|
+
this.reject = this.#executor.reject;
|
|
196
|
+
}
|
|
197
|
+
get state() {
|
|
198
|
+
return this.#executor.state;
|
|
199
|
+
}
|
|
200
|
+
get rejectionReason() {
|
|
201
|
+
return this.#executor.rejectionReason;
|
|
202
|
+
}
|
|
203
|
+
then(onFulfilled, onRejected) {
|
|
204
|
+
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
205
|
+
}
|
|
206
|
+
catch(onRejected) {
|
|
207
|
+
return this.#decorate(super.catch(onRejected));
|
|
208
|
+
}
|
|
209
|
+
finally(onfinally) {
|
|
210
|
+
return this.#decorate(super.finally(onfinally));
|
|
211
|
+
}
|
|
212
|
+
#decorate(promise) {
|
|
213
|
+
return Object.defineProperties(promise, {
|
|
214
|
+
resolve: { configurable: true, value: this.resolve },
|
|
215
|
+
reject: { configurable: true, value: this.reject }
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
exports$1.DeferredPromise = DeferredPromise4;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
var require_build = __commonJS({
|
|
223
|
+
"../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/index.js"(exports$1) {
|
|
224
|
+
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
225
|
+
if (k2 === void 0)
|
|
226
|
+
k2 = k;
|
|
227
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
228
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
229
|
+
desc = { enumerable: true, get: function() {
|
|
230
|
+
return m[k];
|
|
231
|
+
} };
|
|
232
|
+
}
|
|
233
|
+
Object.defineProperty(o, k2, desc);
|
|
234
|
+
} : function(o, m, k, k2) {
|
|
235
|
+
if (k2 === void 0)
|
|
236
|
+
k2 = k;
|
|
237
|
+
o[k2] = m[k];
|
|
238
|
+
});
|
|
239
|
+
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
240
|
+
for (var p in m)
|
|
241
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
242
|
+
__createBinding(exports2, m, p);
|
|
243
|
+
};
|
|
244
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
245
|
+
__exportStar(require_createDeferredExecutor(), exports$1);
|
|
246
|
+
__exportStar(require_DeferredPromise(), exports$1);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
var require_MemoryLeakError = __commonJS({
|
|
250
|
+
"../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/MemoryLeakError.js"(exports$1) {
|
|
251
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
252
|
+
exports$1.MemoryLeakError = void 0;
|
|
253
|
+
var MemoryLeakError = class extends Error {
|
|
254
|
+
emitter;
|
|
255
|
+
type;
|
|
256
|
+
count;
|
|
257
|
+
constructor(emitter, type, count) {
|
|
258
|
+
super(`Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`);
|
|
259
|
+
this.emitter = emitter;
|
|
260
|
+
this.type = type;
|
|
261
|
+
this.count = count;
|
|
262
|
+
this.name = "MaxListenersExceededWarning";
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
exports$1.MemoryLeakError = MemoryLeakError;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
var require_Emitter = __commonJS({
|
|
269
|
+
"../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/Emitter.js"(exports$1) {
|
|
270
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
271
|
+
exports$1.Emitter = void 0;
|
|
272
|
+
var MemoryLeakError_1 = require_MemoryLeakError();
|
|
273
|
+
var _events, _maxListeners, _hasWarnedAboutPotentialMemortyLeak, _getListeners, getListeners_fn, _removeListener, removeListener_fn, _wrapOnceListener, wrapOnceListener_fn, _internalEmit, internalEmit_fn;
|
|
274
|
+
var _Emitter = class {
|
|
275
|
+
constructor() {
|
|
276
|
+
__privateAdd(this, _getListeners);
|
|
277
|
+
__privateAdd(this, _removeListener);
|
|
278
|
+
__privateAdd(this, _wrapOnceListener);
|
|
279
|
+
__privateAdd(this, _internalEmit);
|
|
280
|
+
__privateAdd(this, _events, void 0);
|
|
281
|
+
__privateAdd(this, _maxListeners, void 0);
|
|
282
|
+
__privateAdd(this, _hasWarnedAboutPotentialMemortyLeak, void 0);
|
|
283
|
+
__privateSet(this, _events, /* @__PURE__ */ new Map());
|
|
284
|
+
__privateSet(this, _maxListeners, _Emitter.defaultMaxListeners);
|
|
285
|
+
__privateSet(this, _hasWarnedAboutPotentialMemortyLeak, false);
|
|
286
|
+
}
|
|
287
|
+
static listenerCount(emitter, eventName) {
|
|
288
|
+
return emitter.listenerCount(eventName);
|
|
289
|
+
}
|
|
290
|
+
setMaxListeners(maxListeners) {
|
|
291
|
+
__privateSet(this, _maxListeners, maxListeners);
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
getMaxListeners() {
|
|
295
|
+
return __privateGet(this, _maxListeners);
|
|
296
|
+
}
|
|
297
|
+
eventNames() {
|
|
298
|
+
return Array.from(__privateGet(this, _events).keys());
|
|
299
|
+
}
|
|
300
|
+
emit(eventName, ...data) {
|
|
301
|
+
const listeners = __privateMethod(this, _getListeners, getListeners_fn).call(this, eventName);
|
|
302
|
+
listeners.forEach((listener) => {
|
|
303
|
+
listener.apply(this, data);
|
|
304
|
+
});
|
|
305
|
+
return listeners.length > 0;
|
|
306
|
+
}
|
|
307
|
+
addListener(eventName, listener) {
|
|
308
|
+
__privateMethod(this, _internalEmit, internalEmit_fn).call(this, "newListener", eventName, listener);
|
|
309
|
+
const nextListeners = __privateMethod(this, _getListeners, getListeners_fn).call(this, eventName).concat(listener);
|
|
310
|
+
__privateGet(this, _events).set(eventName, nextListeners);
|
|
311
|
+
if (__privateGet(this, _maxListeners) > 0 && this.listenerCount(eventName) > __privateGet(this, _maxListeners) && !__privateGet(this, _hasWarnedAboutPotentialMemortyLeak)) {
|
|
312
|
+
__privateSet(this, _hasWarnedAboutPotentialMemortyLeak, true);
|
|
313
|
+
const memoryLeakWarning = new MemoryLeakError_1.MemoryLeakError(this, eventName, this.listenerCount(eventName));
|
|
314
|
+
console.warn(memoryLeakWarning);
|
|
315
|
+
}
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
on(eventName, listener) {
|
|
319
|
+
return this.addListener(eventName, listener);
|
|
320
|
+
}
|
|
321
|
+
once(eventName, listener) {
|
|
322
|
+
return this.addListener(eventName, __privateMethod(this, _wrapOnceListener, wrapOnceListener_fn).call(this, eventName, listener));
|
|
323
|
+
}
|
|
324
|
+
prependListener(eventName, listener) {
|
|
325
|
+
const listeners = __privateMethod(this, _getListeners, getListeners_fn).call(this, eventName);
|
|
326
|
+
if (listeners.length > 0) {
|
|
327
|
+
const nextListeners = [listener].concat(listeners);
|
|
328
|
+
__privateGet(this, _events).set(eventName, nextListeners);
|
|
329
|
+
} else {
|
|
330
|
+
__privateGet(this, _events).set(eventName, listeners.concat(listener));
|
|
331
|
+
}
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
prependOnceListener(eventName, listener) {
|
|
335
|
+
return this.prependListener(eventName, __privateMethod(this, _wrapOnceListener, wrapOnceListener_fn).call(this, eventName, listener));
|
|
336
|
+
}
|
|
337
|
+
removeListener(eventName, listener) {
|
|
338
|
+
const listeners = __privateMethod(this, _getListeners, getListeners_fn).call(this, eventName);
|
|
339
|
+
if (listeners.length > 0) {
|
|
340
|
+
__privateMethod(this, _removeListener, removeListener_fn).call(this, listeners, listener);
|
|
341
|
+
__privateGet(this, _events).set(eventName, listeners);
|
|
342
|
+
__privateMethod(this, _internalEmit, internalEmit_fn).call(this, "removeListener", eventName, listener);
|
|
343
|
+
}
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
off(eventName, listener) {
|
|
347
|
+
return this.removeListener(eventName, listener);
|
|
348
|
+
}
|
|
349
|
+
removeAllListeners(eventName) {
|
|
350
|
+
if (eventName) {
|
|
351
|
+
__privateGet(this, _events).delete(eventName);
|
|
352
|
+
} else {
|
|
353
|
+
__privateGet(this, _events).clear();
|
|
354
|
+
}
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
listeners(eventName) {
|
|
358
|
+
return Array.from(__privateMethod(this, _getListeners, getListeners_fn).call(this, eventName));
|
|
359
|
+
}
|
|
360
|
+
listenerCount(eventName) {
|
|
361
|
+
return __privateMethod(this, _getListeners, getListeners_fn).call(this, eventName).length;
|
|
362
|
+
}
|
|
363
|
+
rawListeners(eventName) {
|
|
364
|
+
return this.listeners(eventName);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var Emitter2 = _Emitter;
|
|
368
|
+
_events = /* @__PURE__ */ new WeakMap();
|
|
369
|
+
_maxListeners = /* @__PURE__ */ new WeakMap();
|
|
370
|
+
_hasWarnedAboutPotentialMemortyLeak = /* @__PURE__ */ new WeakMap();
|
|
371
|
+
_getListeners = /* @__PURE__ */ new WeakSet();
|
|
372
|
+
getListeners_fn = function(eventName) {
|
|
373
|
+
return __privateGet(this, _events).get(eventName) || [];
|
|
374
|
+
};
|
|
375
|
+
_removeListener = /* @__PURE__ */ new WeakSet();
|
|
376
|
+
removeListener_fn = function(listeners, listener) {
|
|
377
|
+
const index = listeners.indexOf(listener);
|
|
378
|
+
if (index > -1) {
|
|
379
|
+
listeners.splice(index, 1);
|
|
380
|
+
}
|
|
381
|
+
return [];
|
|
382
|
+
};
|
|
383
|
+
_wrapOnceListener = /* @__PURE__ */ new WeakSet();
|
|
384
|
+
wrapOnceListener_fn = function(eventName, listener) {
|
|
385
|
+
const onceListener = (...data) => {
|
|
386
|
+
this.removeListener(eventName, onceListener);
|
|
387
|
+
listener.apply(this, data);
|
|
388
|
+
};
|
|
389
|
+
return onceListener;
|
|
390
|
+
};
|
|
391
|
+
_internalEmit = /* @__PURE__ */ new WeakSet();
|
|
392
|
+
internalEmit_fn = function(internalEventName, eventName, listener) {
|
|
393
|
+
this.emit(
|
|
394
|
+
internalEventName,
|
|
395
|
+
...[eventName, listener]
|
|
396
|
+
);
|
|
397
|
+
};
|
|
398
|
+
__publicField(Emitter2, "defaultMaxListeners", 10);
|
|
399
|
+
exports$1.Emitter = Emitter2;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
var require_lib = __commonJS({
|
|
403
|
+
"../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/index.js"(exports$1) {
|
|
404
|
+
var __createBinding = exports$1 && exports$1.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
405
|
+
if (k2 === void 0)
|
|
406
|
+
k2 = k;
|
|
407
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
408
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
409
|
+
desc = { enumerable: true, get: function() {
|
|
410
|
+
return m[k];
|
|
411
|
+
} };
|
|
412
|
+
}
|
|
413
|
+
Object.defineProperty(o, k2, desc);
|
|
414
|
+
} : function(o, m, k, k2) {
|
|
415
|
+
if (k2 === void 0)
|
|
416
|
+
k2 = k;
|
|
417
|
+
o[k2] = m[k];
|
|
418
|
+
});
|
|
419
|
+
var __exportStar = exports$1 && exports$1.__exportStar || function(m, exports2) {
|
|
420
|
+
for (var p in m)
|
|
421
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
422
|
+
__createBinding(exports2, m, p);
|
|
423
|
+
};
|
|
424
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
425
|
+
__exportStar(require_Emitter(), exports$1);
|
|
426
|
+
__exportStar(require_MemoryLeakError(), exports$1);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
var import_cuid = __toESM(require_cuid());
|
|
430
|
+
var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
|
|
431
|
+
function serializePositional(positional, flag) {
|
|
432
|
+
switch (flag) {
|
|
433
|
+
case "s":
|
|
434
|
+
return positional;
|
|
435
|
+
case "d":
|
|
436
|
+
case "i":
|
|
437
|
+
return Number(positional);
|
|
438
|
+
case "j":
|
|
439
|
+
return JSON.stringify(positional);
|
|
440
|
+
case "o": {
|
|
441
|
+
if (typeof positional === "string") {
|
|
442
|
+
return positional;
|
|
443
|
+
}
|
|
444
|
+
const json = JSON.stringify(positional);
|
|
445
|
+
if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
|
|
446
|
+
return positional;
|
|
447
|
+
}
|
|
448
|
+
return json;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function format(message, ...positionals) {
|
|
453
|
+
if (positionals.length === 0) {
|
|
454
|
+
return message;
|
|
455
|
+
}
|
|
456
|
+
let positionalIndex = 0;
|
|
457
|
+
let formattedMessage = message.replace(
|
|
458
|
+
POSITIONALS_EXP,
|
|
459
|
+
(match, isEscaped, _, flag) => {
|
|
460
|
+
const positional = positionals[positionalIndex];
|
|
461
|
+
const value = serializePositional(positional, flag);
|
|
462
|
+
if (!isEscaped) {
|
|
463
|
+
positionalIndex++;
|
|
464
|
+
return value;
|
|
465
|
+
}
|
|
466
|
+
return match;
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
if (positionalIndex < positionals.length) {
|
|
470
|
+
formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
|
|
471
|
+
}
|
|
472
|
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
|
473
|
+
return formattedMessage;
|
|
474
|
+
}
|
|
475
|
+
var STACK_FRAMES_TO_IGNORE = 2;
|
|
476
|
+
function cleanErrorStack(error) {
|
|
477
|
+
if (!error.stack) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const nextStack = error.stack.split("\n");
|
|
481
|
+
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
|
482
|
+
error.stack = nextStack.join("\n");
|
|
483
|
+
}
|
|
484
|
+
var InvariantError = class extends Error {
|
|
485
|
+
constructor(message, ...positionals) {
|
|
486
|
+
super(message);
|
|
487
|
+
this.message = message;
|
|
488
|
+
this.name = "Invariant Violation";
|
|
489
|
+
this.message = format(message, ...positionals);
|
|
490
|
+
cleanErrorStack(this);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var invariant = (predicate, message, ...positionals) => {
|
|
494
|
+
if (!predicate) {
|
|
495
|
+
throw new InvariantError(message, ...positionals);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {
|
|
499
|
+
if (!predicate) {
|
|
500
|
+
const isConstructor = ErrorConstructor.prototype.name != null;
|
|
501
|
+
const error = isConstructor ? new ErrorConstructor(format(message, positionals)) : ErrorConstructor(format(message, positionals));
|
|
502
|
+
throw error;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
var import_deferred_promise = __toESM(require_build());
|
|
506
|
+
var FLAG = window.localStorage["CSB_EMULATOR_DEBUG"];
|
|
507
|
+
var DEFAULT = "\x1B[0m";
|
|
508
|
+
var GREEN = "\x1B[32;1m";
|
|
509
|
+
var RED = "\x1B[31m";
|
|
510
|
+
var BLUE = "\x1B[34m";
|
|
511
|
+
var YELLOW = "\x1B[33;1m";
|
|
512
|
+
var MAGENTA = "\x1B[35;1m";
|
|
513
|
+
var CYAN = "\x1B[36;1m";
|
|
514
|
+
var COLOR_SCOPE = {
|
|
515
|
+
preview: YELLOW,
|
|
516
|
+
emulator: MAGENTA,
|
|
517
|
+
runtime: CYAN,
|
|
518
|
+
bridge: BLUE,
|
|
519
|
+
"runtime:worker": CYAN
|
|
520
|
+
};
|
|
521
|
+
function createDebug(scope) {
|
|
522
|
+
return function debug3(message, ...data) {
|
|
523
|
+
if (FLAG === "true") {
|
|
524
|
+
const direction = () => {
|
|
525
|
+
if (message.includes("sender"))
|
|
526
|
+
return `${GREEN}sender`;
|
|
527
|
+
if (message.includes("receiver"))
|
|
528
|
+
return `${RED}receiver`;
|
|
529
|
+
return "";
|
|
530
|
+
};
|
|
531
|
+
const cleanMessage = message.replace(/\[.+\]:/, "");
|
|
532
|
+
console.debug(`${COLOR_SCOPE[scope]}${scope}:${direction()}${DEFAULT}:${cleanMessage}`, ...data);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
var debug = createDebug("emulator");
|
|
537
|
+
var MessageSender = class {
|
|
538
|
+
constructor(target) {
|
|
539
|
+
this.target = target;
|
|
540
|
+
this.emitter = new EventTarget();
|
|
541
|
+
this.channel = new MessageChannel();
|
|
542
|
+
this.receiverPort = this.channel.port1;
|
|
543
|
+
const receiverReadyPromise = new import_deferred_promise.DeferredPromise();
|
|
544
|
+
const handshakeListener = (message) => {
|
|
545
|
+
if (message.data.type === "internal/ready") {
|
|
546
|
+
debug("[message-sender]: runtime is ready");
|
|
547
|
+
receiverReadyPromise.resolve();
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
window.addEventListener("message", handshakeListener);
|
|
551
|
+
receiverReadyPromise.then(() => {
|
|
552
|
+
window.removeEventListener("message", handshakeListener);
|
|
553
|
+
});
|
|
554
|
+
this.receiverReadyPromise = receiverReadyPromise;
|
|
555
|
+
this.receiverPort.onmessage = (evt) => {
|
|
556
|
+
const data = evt.data;
|
|
557
|
+
if (data.type != null) {
|
|
558
|
+
debug('[message-sender]: emitting "%s" event...', data.type, data.payload);
|
|
559
|
+
this.emitter.dispatchEvent(new MessageEvent(data.type, { data: data.payload }));
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
emitter;
|
|
564
|
+
channel;
|
|
565
|
+
receiverPort;
|
|
566
|
+
receiverReadyPromise;
|
|
567
|
+
async handshake() {
|
|
568
|
+
const handshakePromise = new import_deferred_promise.DeferredPromise();
|
|
569
|
+
await this.receiverReadyPromise;
|
|
570
|
+
debug("[message-sender]: sending handshake");
|
|
571
|
+
this.target.postMessage(
|
|
572
|
+
{
|
|
573
|
+
type: "internal/handshake"
|
|
574
|
+
},
|
|
575
|
+
"*",
|
|
576
|
+
[this.channel.port2]
|
|
577
|
+
);
|
|
578
|
+
this.on("internal/handshake/done", () => {
|
|
579
|
+
handshakePromise.resolve();
|
|
580
|
+
clearTimeout(rejectionTimeout);
|
|
581
|
+
});
|
|
582
|
+
const rejectionTimeout = setTimeout(() => {
|
|
583
|
+
handshakePromise.reject(new Error("MessageSender: Handshake timeout"));
|
|
584
|
+
}, 5e3);
|
|
585
|
+
return handshakePromise;
|
|
586
|
+
}
|
|
587
|
+
on(event, listener, options) {
|
|
588
|
+
debug('[message-sender]: add listener "%s"', event);
|
|
589
|
+
this.emitter.addEventListener(
|
|
590
|
+
event,
|
|
591
|
+
(message) => {
|
|
592
|
+
if (message instanceof MessageEvent) {
|
|
593
|
+
listener(message);
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
options
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
off(event, listener, options) {
|
|
600
|
+
this.emitter.removeEventListener(event, listener, options);
|
|
601
|
+
}
|
|
602
|
+
async send(event, ...data) {
|
|
603
|
+
const operationPromise = new import_deferred_promise.DeferredPromise();
|
|
604
|
+
const operationId = (0, import_cuid.default)();
|
|
605
|
+
const payload = data[0] || {};
|
|
606
|
+
debug('[message-sender]: send "%s" (%s)', event, operationId, payload);
|
|
607
|
+
this.receiverPort.postMessage({ type: event, payload: { operationId, payload } });
|
|
608
|
+
debug('[message-sender]: adding done listener for "%s" (%s)', event, operationId);
|
|
609
|
+
const handleOperationDone = (doneEvent) => {
|
|
610
|
+
const { data: data2 } = doneEvent;
|
|
611
|
+
if (data2.operationId === operationId) {
|
|
612
|
+
const listenerPayload = data2.listenerPayload || {};
|
|
613
|
+
debug('[message-sender]: resolving "%s (%s) promise!', event, operationId);
|
|
614
|
+
operationPromise.resolve({
|
|
615
|
+
...listenerPayload,
|
|
616
|
+
operationId: data2.operationId
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
const handleOperationFailed = (failEvent) => {
|
|
621
|
+
const { data: data2 } = failEvent;
|
|
622
|
+
if (data2.operationId === operationId) {
|
|
623
|
+
debug('[message-sender]: rejecting "%s (%s) promise!', event, operationId);
|
|
624
|
+
operationPromise.reject(data2.error);
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
this.on("internal/operation/done", handleOperationDone);
|
|
628
|
+
this.on("internal/operation/failed", handleOperationFailed);
|
|
629
|
+
return operationPromise.finally(() => {
|
|
630
|
+
this.emitter.removeEventListener("internal/operation/done", handleOperationDone);
|
|
631
|
+
this.emitter.removeEventListener("internal/operation/failed", handleOperationFailed);
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
var import_deferred_promise3 = __toESM(require_build());
|
|
636
|
+
var import_cuid2 = __toESM(require_cuid());
|
|
637
|
+
var FileSystemApi = class {
|
|
638
|
+
constructor(channel) {
|
|
639
|
+
this.channel = channel;
|
|
640
|
+
}
|
|
641
|
+
async init(files) {
|
|
642
|
+
await this.channel.send("fs/init", { files });
|
|
643
|
+
}
|
|
644
|
+
async readFile(path, encoding) {
|
|
645
|
+
const response = await this.channel.send("fs/readFile", { path, encoding }).catch((error) => {
|
|
646
|
+
throw new Error(format('Failed to read file at path "%s"', path), { cause: error });
|
|
647
|
+
});
|
|
648
|
+
if (!response) {
|
|
649
|
+
throw new Error("File not found");
|
|
650
|
+
}
|
|
651
|
+
return response.data;
|
|
652
|
+
}
|
|
653
|
+
async writeFile(path, content, options) {
|
|
654
|
+
let encoding = void 0;
|
|
655
|
+
let recursive = false;
|
|
656
|
+
if (typeof options === "object") {
|
|
657
|
+
encoding = options.encoding;
|
|
658
|
+
recursive = !!options.recursive;
|
|
659
|
+
} else if (typeof options === "string") {
|
|
660
|
+
encoding = options;
|
|
661
|
+
}
|
|
662
|
+
await this.channel.send("fs/writeFile", { path, content, encoding, recursive }).catch((error) => {
|
|
663
|
+
throw new Error(format('Failed to write file at path "%s"', path), { cause: error });
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
async readdir(path) {
|
|
667
|
+
const response = await this.channel.send("fs/readdir", { path }).catch((error) => {
|
|
668
|
+
throw new Error(format('Failed to read directory at path "%s"', path), { cause: error });
|
|
669
|
+
});
|
|
670
|
+
if (!response) {
|
|
671
|
+
throw new Error("Directory not found");
|
|
672
|
+
}
|
|
673
|
+
return response.data;
|
|
674
|
+
}
|
|
675
|
+
async mkdir(path, options) {
|
|
676
|
+
const recursive = !!options?.recursive;
|
|
677
|
+
await this.channel.send("fs/mkdir", { path, recursive }).catch((error) => {
|
|
678
|
+
throw new Error(format('Failed to make directory at path "%s"', path), { cause: error });
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
async stat(path) {
|
|
682
|
+
const response = await this.channel.send("fs/stat", { path }).catch((error) => {
|
|
683
|
+
throw new Error(format('Failed to stat file at path "%s"', path), { cause: error });
|
|
684
|
+
});
|
|
685
|
+
if (!response) {
|
|
686
|
+
throw new Error("File not found");
|
|
687
|
+
}
|
|
688
|
+
return response.data;
|
|
689
|
+
}
|
|
690
|
+
async rm(path, options) {
|
|
691
|
+
const { force, recursive } = options || {};
|
|
692
|
+
await this.channel.send("fs/rm", { path, force, recursive }).catch((error) => {
|
|
693
|
+
throw new Error(format('Failed to remove file at path "%s"', path), { cause: error });
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
async watch(includes, excludes, listener) {
|
|
697
|
+
const watcherId = (0, import_cuid2.default)();
|
|
698
|
+
await this.channel.send("fs/watch", { watcherId, includes, excludes });
|
|
699
|
+
this.channel.on("fs/watch-event", ({ data }) => {
|
|
700
|
+
if (data.watcherId === watcherId && listener) {
|
|
701
|
+
const evt = { ...data };
|
|
702
|
+
delete evt.watcherId;
|
|
703
|
+
listener(evt);
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
return {
|
|
707
|
+
dispose: () => this.channel.send("fs/unwatch", { watcherId })
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
var import_strict_event_emitter = __toESM(require_lib());
|
|
712
|
+
var ShellApi = class {
|
|
713
|
+
constructor(channel) {
|
|
714
|
+
this.channel = channel;
|
|
715
|
+
}
|
|
716
|
+
create() {
|
|
717
|
+
return new ShellProcess(this.channel);
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
var ShellProcess = class {
|
|
721
|
+
constructor(channel) {
|
|
722
|
+
this.channel = channel;
|
|
723
|
+
this.state = "running";
|
|
724
|
+
this.stdout = new import_strict_event_emitter.Emitter();
|
|
725
|
+
this.stderr = new import_strict_event_emitter.Emitter();
|
|
726
|
+
this.stdin = {
|
|
727
|
+
write: (data) => {
|
|
728
|
+
if (!this.id) {
|
|
729
|
+
throw new Error("Failed to write to stdin, no process is currently running");
|
|
730
|
+
}
|
|
731
|
+
return this.channel.send("shell/stdin", { data, workerId: this.id });
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
this.forwardStdEvents();
|
|
735
|
+
}
|
|
736
|
+
id;
|
|
737
|
+
state;
|
|
738
|
+
stdout;
|
|
739
|
+
stderr;
|
|
740
|
+
stdin;
|
|
741
|
+
forwardStdEvents() {
|
|
742
|
+
this.channel.on("worker/tty", (message) => {
|
|
743
|
+
const { data } = message;
|
|
744
|
+
if (data.workerId !== this.id) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
switch (data.payload.type) {
|
|
748
|
+
case "out": {
|
|
749
|
+
this.stdout.emit("data", data.payload.data);
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
case "err": {
|
|
753
|
+
this.stderr.emit("data", data.payload.data);
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
async runCommand(command, args, options = {}) {
|
|
760
|
+
invariant(!this.id, 'Failed to run "runCommand" on a ShellProcess: there is already a process running.');
|
|
761
|
+
const shellInfo = await this.channel.send("shell/runCommand", { command, args, options });
|
|
762
|
+
invariant(shellInfo, 'Failed to run "runCommand" on a ShellProcess: was not able to retrieve a running process.');
|
|
763
|
+
this.id = shellInfo.id;
|
|
764
|
+
this.state = "running";
|
|
765
|
+
return shellInfo;
|
|
766
|
+
}
|
|
767
|
+
async on(message, listener) {
|
|
768
|
+
switch (message) {
|
|
769
|
+
case "progress": {
|
|
770
|
+
this.channel.on("worker/progress", ({ data }) => {
|
|
771
|
+
listener(data.status);
|
|
772
|
+
});
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
case "exit": {
|
|
776
|
+
this.channel.on("worker/exit", ({ data }) => {
|
|
777
|
+
if (data.workerId === this.id) {
|
|
778
|
+
listener(data.exitCode, data.error);
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
async kill() {
|
|
786
|
+
invariant(
|
|
787
|
+
this.id,
|
|
788
|
+
'Failed to run "kill" on a ShellProcess: there is no process running. Did you forget to run it?'
|
|
789
|
+
);
|
|
790
|
+
this.state = "idle";
|
|
791
|
+
await this.channel.send("shell/exit", { id: this.id }).catch((error) => {
|
|
792
|
+
throw new Error(format('Failed to kill shell with ID "%s"', this.id), { cause: error });
|
|
793
|
+
});
|
|
794
|
+
this.id = void 0;
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
var import_deferred_promise2 = __toESM(require_build());
|
|
798
|
+
var TIMEOUT = 2e4;
|
|
799
|
+
var PreviewApi = class {
|
|
800
|
+
constructor(channel) {
|
|
801
|
+
this.channel = channel;
|
|
802
|
+
}
|
|
803
|
+
async waitFor(payload, predicate, timeout = TIMEOUT) {
|
|
804
|
+
const readyPromise = new import_deferred_promise2.DeferredPromise();
|
|
805
|
+
const rejectTimeout = setTimeout(() => {
|
|
806
|
+
readyPromise.reject();
|
|
807
|
+
}, timeout);
|
|
808
|
+
const previewInformation = await this.channel.send("preview/get/info", payload).catch((error) => {
|
|
809
|
+
readyPromise.reject(
|
|
810
|
+
new Error(
|
|
811
|
+
format(
|
|
812
|
+
'Failed to look up preview information for shell ID "%s" (port: %d)',
|
|
813
|
+
payload.sourceShellId,
|
|
814
|
+
payload.port
|
|
815
|
+
)
|
|
816
|
+
)
|
|
817
|
+
);
|
|
818
|
+
});
|
|
819
|
+
const foundPreview = previewInformation && predicate(previewInformation);
|
|
820
|
+
if (foundPreview) {
|
|
821
|
+
readyPromise.resolve({
|
|
822
|
+
url: previewInformation.url,
|
|
823
|
+
port: previewInformation.port,
|
|
824
|
+
sourceShellId: previewInformation.sourceShellId
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
this.channel.on("preview/port/ready", ({ data }) => {
|
|
828
|
+
if (!foundPreview && predicate(data)) {
|
|
829
|
+
readyPromise.resolve({
|
|
830
|
+
url: data.url,
|
|
831
|
+
port: data.port,
|
|
832
|
+
sourceShellId: data.sourceShellId
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
return readyPromise.finally(() => {
|
|
837
|
+
clearTimeout(rejectTimeout);
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
async getByShellId(sourceShellId, timeout) {
|
|
841
|
+
return this.waitFor({ sourceShellId }, (data) => data.sourceShellId === sourceShellId, timeout).catch((error) => {
|
|
842
|
+
throw new Error(format('Failed to get shell by ID "%s"', sourceShellId), { cause: error });
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
async waitForPort(port, timeout) {
|
|
846
|
+
return this.waitFor({ port }, (data) => data.port === port, timeout).catch((error) => {
|
|
847
|
+
throw new Error(format("Failed to await port %d", port), { cause: error });
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
var DEFAULT_RUNTIME_URL = "https://nodebox-runtime.codesandbox.io";
|
|
852
|
+
var debug2 = createDebug("emulator");
|
|
853
|
+
var Nodebox = class {
|
|
854
|
+
constructor(options) {
|
|
855
|
+
this.options = options;
|
|
856
|
+
invariant(
|
|
857
|
+
this.options.iframe,
|
|
858
|
+
'Failed to create a Nodebox: expected "iframe" argument to be a reference to an <iframe> element but got %j',
|
|
859
|
+
this.options.iframe
|
|
860
|
+
);
|
|
861
|
+
this.url = this.options.runtimeUrl || DEFAULT_RUNTIME_URL;
|
|
862
|
+
this.isConnected = false;
|
|
863
|
+
}
|
|
864
|
+
channel = null;
|
|
865
|
+
isConnected;
|
|
866
|
+
url;
|
|
867
|
+
fileSystemApi = null;
|
|
868
|
+
shellApi = null;
|
|
869
|
+
previewApi = null;
|
|
870
|
+
async connect() {
|
|
871
|
+
const { iframe, cdnUrl } = this.options;
|
|
872
|
+
debug2("[message-sender]: Connecting to node emulator...");
|
|
873
|
+
const connectionPromise = new import_deferred_promise3.DeferredPromise();
|
|
874
|
+
if (!this.url) {
|
|
875
|
+
connectionPromise.reject(
|
|
876
|
+
new Error("Nodebox URL is missing. Did you forget to provide it when creating this Nodebox instance?")
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
invariant(
|
|
880
|
+
iframe.contentWindow,
|
|
881
|
+
"Failed to create a MessageChannel with the Nodebox iframe: no content window found"
|
|
882
|
+
);
|
|
883
|
+
this.channel = new MessageSender(iframe.contentWindow);
|
|
884
|
+
const frameLoadPromise = new import_deferred_promise3.DeferredPromise();
|
|
885
|
+
iframe.setAttribute("src", this.url);
|
|
886
|
+
iframe.addEventListener(
|
|
887
|
+
"load",
|
|
888
|
+
() => {
|
|
889
|
+
frameLoadPromise.resolve();
|
|
890
|
+
},
|
|
891
|
+
{ once: true }
|
|
892
|
+
);
|
|
893
|
+
iframe.addEventListener(
|
|
894
|
+
"error",
|
|
895
|
+
(event) => {
|
|
896
|
+
frameLoadPromise.reject(event.error);
|
|
897
|
+
},
|
|
898
|
+
{ once: true }
|
|
899
|
+
);
|
|
900
|
+
await frameLoadPromise;
|
|
901
|
+
debug2("[message-sender]: IFrame loaded...");
|
|
902
|
+
await this.channel.handshake();
|
|
903
|
+
debug2("[message-sender]: Handshake completed...");
|
|
904
|
+
this.channel.send("connect", {
|
|
905
|
+
cdnUrl
|
|
906
|
+
});
|
|
907
|
+
this.channel.on("runtime/ready", () => {
|
|
908
|
+
connectionPromise.resolve();
|
|
909
|
+
});
|
|
910
|
+
return connectionPromise.then(() => {
|
|
911
|
+
debug2("[message-sender]: Connected to runtime...");
|
|
912
|
+
this.isConnected = true;
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
get fs() {
|
|
916
|
+
invariant(
|
|
917
|
+
this.isConnected,
|
|
918
|
+
'Failed to access the File System API: consumer is not connected. Did you forget to run "connect()"?'
|
|
919
|
+
);
|
|
920
|
+
if (this.fileSystemApi) {
|
|
921
|
+
return this.fileSystemApi;
|
|
922
|
+
}
|
|
923
|
+
this.fileSystemApi = new FileSystemApi(this.channel);
|
|
924
|
+
return this.fileSystemApi;
|
|
925
|
+
}
|
|
926
|
+
get shell() {
|
|
927
|
+
invariant(
|
|
928
|
+
this.isConnected,
|
|
929
|
+
'Failed to access the Shell API: consumer is not connected. Did you forget to run "connect()"?'
|
|
930
|
+
);
|
|
931
|
+
if (this.shellApi) {
|
|
932
|
+
return this.shellApi;
|
|
933
|
+
}
|
|
934
|
+
this.shellApi = new ShellApi(this.channel);
|
|
935
|
+
return this.shellApi;
|
|
936
|
+
}
|
|
937
|
+
get preview() {
|
|
938
|
+
invariant(
|
|
939
|
+
this.isConnected,
|
|
940
|
+
'Failed to access the Preview API: consumer is not connected. Did you forget to run "connect()"?'
|
|
941
|
+
);
|
|
942
|
+
if (this.previewApi) {
|
|
943
|
+
return this.previewApi;
|
|
944
|
+
}
|
|
945
|
+
this.previewApi = new PreviewApi(this.channel);
|
|
946
|
+
return this.previewApi;
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
var INJECT_MESSAGE_TYPE = "INJECT_AND_INVOKE";
|
|
950
|
+
var PREVIEW_LOADED_MESSAGE_TYPE = "PREVIEW_LOADED";
|
|
951
|
+
function loadPreviewIframe(iframe, url) {
|
|
952
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
953
|
+
var contentWindow, TIME_OUT, MAX_MANY_TIRES, tries, timeout;
|
|
954
|
+
return __generator(this, function(_a) {
|
|
955
|
+
contentWindow = iframe.contentWindow;
|
|
956
|
+
nullthrows(contentWindow, "Failed to await preview iframe: no content window found");
|
|
957
|
+
TIME_OUT = 9e4;
|
|
958
|
+
MAX_MANY_TIRES = 20;
|
|
959
|
+
tries = 0;
|
|
960
|
+
return [2, new Promise(function(resolve, reject) {
|
|
961
|
+
var triesToSetUrl = function() {
|
|
962
|
+
var onLoadPage = function() {
|
|
963
|
+
clearTimeout(timeout);
|
|
964
|
+
tries = MAX_MANY_TIRES;
|
|
965
|
+
resolve();
|
|
966
|
+
iframe.removeEventListener("load", onLoadPage);
|
|
967
|
+
};
|
|
968
|
+
if (tries >= MAX_MANY_TIRES) {
|
|
969
|
+
reject(createError("Could not able to connect to preview."));
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
iframe.setAttribute("src", url);
|
|
973
|
+
timeout = setTimeout(function() {
|
|
974
|
+
triesToSetUrl();
|
|
975
|
+
iframe.removeEventListener("load", onLoadPage);
|
|
976
|
+
}, TIME_OUT);
|
|
977
|
+
tries = tries + 1;
|
|
978
|
+
iframe.addEventListener("load", onLoadPage);
|
|
979
|
+
};
|
|
980
|
+
iframe.addEventListener("error", function() {
|
|
981
|
+
return reject(new Error("Iframe error"));
|
|
982
|
+
});
|
|
983
|
+
iframe.addEventListener("abort", function() {
|
|
984
|
+
return reject(new Error("Aborted"));
|
|
985
|
+
});
|
|
986
|
+
triesToSetUrl();
|
|
987
|
+
})];
|
|
988
|
+
});
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
var setPreviewIframeProperties = function(iframe, options) {
|
|
992
|
+
iframe.style.border = "0";
|
|
993
|
+
iframe.style.width = options.width || "100%";
|
|
994
|
+
iframe.style.height = options.height || "100%";
|
|
995
|
+
iframe.style.overflow = "hidden";
|
|
996
|
+
iframe.allow = "cross-origin-isolated";
|
|
997
|
+
};
|
|
998
|
+
function setupHistoryListeners(_a) {
|
|
999
|
+
var scope = _a.scope;
|
|
1000
|
+
var origHistoryProto = window.history.__proto__;
|
|
1001
|
+
var historyList = [];
|
|
1002
|
+
var historyPosition = 0;
|
|
1003
|
+
var dispatchMessage = function(url) {
|
|
1004
|
+
parent.postMessage({
|
|
1005
|
+
type: "urlchange",
|
|
1006
|
+
url,
|
|
1007
|
+
back: historyPosition > 0,
|
|
1008
|
+
forward: historyPosition < historyList.length - 1,
|
|
1009
|
+
channelId: scope.channelId
|
|
1010
|
+
}, "*");
|
|
1011
|
+
};
|
|
1012
|
+
function pushHistory(url, state) {
|
|
1013
|
+
historyList.splice(historyPosition + 1);
|
|
1014
|
+
historyList.push({ url, state });
|
|
1015
|
+
historyPosition = historyList.length - 1;
|
|
1016
|
+
}
|
|
1017
|
+
Object.assign(window.history, {
|
|
1018
|
+
go: function(delta) {
|
|
1019
|
+
var newPos = historyPosition + delta;
|
|
1020
|
+
if (newPos >= 0 && newPos <= historyList.length - 1) {
|
|
1021
|
+
historyPosition = newPos;
|
|
1022
|
+
var _a2 = historyList[historyPosition], url = _a2.url, state = _a2.state;
|
|
1023
|
+
origHistoryProto.replaceState.call(window.history, state, "", url);
|
|
1024
|
+
var newURL = document.location.href;
|
|
1025
|
+
dispatchMessage(newURL);
|
|
1026
|
+
window.dispatchEvent(new PopStateEvent("popstate", { state }));
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
back: function() {
|
|
1030
|
+
window.history.go(-1);
|
|
1031
|
+
},
|
|
1032
|
+
forward: function() {
|
|
1033
|
+
window.history.go(1);
|
|
1034
|
+
},
|
|
1035
|
+
pushState: function(state, title, url) {
|
|
1036
|
+
origHistoryProto.replaceState.call(window.history, state, title, url);
|
|
1037
|
+
pushHistory(url, state);
|
|
1038
|
+
dispatchMessage(document.location.href);
|
|
1039
|
+
},
|
|
1040
|
+
replaceState: function(state, title, url) {
|
|
1041
|
+
origHistoryProto.replaceState.call(window.history, state, title, url);
|
|
1042
|
+
historyList[historyPosition] = { state, url };
|
|
1043
|
+
dispatchMessage(document.location.href);
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
function handleMessage(_a2) {
|
|
1047
|
+
var data = _a2.data;
|
|
1048
|
+
if (data.type === "urlback") {
|
|
1049
|
+
history.back();
|
|
1050
|
+
} else if (data.type === "urlforward") {
|
|
1051
|
+
history.forward();
|
|
1052
|
+
} else if (data.type === "refresh") {
|
|
1053
|
+
document.location.reload();
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
window.addEventListener("message", handleMessage);
|
|
1057
|
+
}
|
|
1058
|
+
function watchResize(_a) {
|
|
1059
|
+
var scope = _a.scope;
|
|
1060
|
+
var lastHeight = 0;
|
|
1061
|
+
function getDocumentHeight() {
|
|
1062
|
+
if (typeof window === "undefined")
|
|
1063
|
+
return 0;
|
|
1064
|
+
var body = document.body;
|
|
1065
|
+
var html = document.documentElement;
|
|
1066
|
+
return Math.max(body.scrollHeight, body.offsetHeight, html.offsetHeight);
|
|
1067
|
+
}
|
|
1068
|
+
function sendResizeEvent() {
|
|
1069
|
+
var height = getDocumentHeight();
|
|
1070
|
+
if (lastHeight !== height) {
|
|
1071
|
+
window.parent.postMessage({
|
|
1072
|
+
type: "resize",
|
|
1073
|
+
height,
|
|
1074
|
+
codesandbox: true,
|
|
1075
|
+
channelId: scope.channelId
|
|
1076
|
+
}, "*");
|
|
1077
|
+
}
|
|
1078
|
+
lastHeight = height;
|
|
1079
|
+
}
|
|
1080
|
+
sendResizeEvent();
|
|
1081
|
+
var throttle;
|
|
1082
|
+
var observer = new MutationObserver(function() {
|
|
1083
|
+
if (throttle === void 0) {
|
|
1084
|
+
sendResizeEvent();
|
|
1085
|
+
throttle = setTimeout(function() {
|
|
1086
|
+
throttle = void 0;
|
|
1087
|
+
}, 300);
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
observer.observe(document, {
|
|
1091
|
+
attributes: true,
|
|
1092
|
+
childList: true,
|
|
1093
|
+
subtree: true
|
|
1094
|
+
});
|
|
1095
|
+
setInterval(sendResizeEvent, 300);
|
|
1096
|
+
}
|
|
1097
|
+
var scripts = [
|
|
1098
|
+
{ code: setupHistoryListeners.toString(), id: "historyListener" },
|
|
1099
|
+
{
|
|
1100
|
+
code: "function consoleHook({ scope }) {" + consoleHook + "\n};",
|
|
1101
|
+
id: "consoleHook"
|
|
1102
|
+
},
|
|
1103
|
+
{ code: watchResize.toString(), id: "watchResize" }
|
|
1104
|
+
];
|
|
1105
|
+
var injectScriptToIframe = function(iframe, channelId) {
|
|
1106
|
+
scripts.forEach(function(_a) {
|
|
1107
|
+
var _b;
|
|
1108
|
+
var code = _a.code, id = _a.id;
|
|
1109
|
+
var message = {
|
|
1110
|
+
uid: id,
|
|
1111
|
+
type: INJECT_MESSAGE_TYPE,
|
|
1112
|
+
code: "exports.activate = ".concat(code),
|
|
1113
|
+
scope: { channelId }
|
|
1114
|
+
};
|
|
1115
|
+
(_b = iframe.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(message, "*");
|
|
1116
|
+
});
|
|
1117
|
+
};
|
|
1118
|
+
var SandpackNode = (
|
|
1119
|
+
/** @class */
|
|
1120
|
+
(function(_super) {
|
|
1121
|
+
__extends(SandpackNode2, _super);
|
|
1122
|
+
function SandpackNode2(selector, sandboxInfo, options) {
|
|
1123
|
+
if (options === void 0) {
|
|
1124
|
+
options = {};
|
|
1125
|
+
}
|
|
1126
|
+
var _this = _super.call(this, selector, sandboxInfo, __assign(__assign({}, options), { bundlerURL: options.bundlerURL })) || this;
|
|
1127
|
+
_this._modulesCache = /* @__PURE__ */ new Map();
|
|
1128
|
+
_this.messageChannelId = generateRandomId();
|
|
1129
|
+
_this._initPromise = null;
|
|
1130
|
+
_this.emitter = new EventEmitter();
|
|
1131
|
+
_this.manageIframes(selector);
|
|
1132
|
+
_this.emulator = new Nodebox({
|
|
1133
|
+
iframe: _this.emulatorIframe,
|
|
1134
|
+
runtimeUrl: _this.options.bundlerURL
|
|
1135
|
+
});
|
|
1136
|
+
_this.updateSandbox(sandboxInfo);
|
|
1137
|
+
return _this;
|
|
1138
|
+
}
|
|
1139
|
+
SandpackNode2.prototype._init = function(files) {
|
|
1140
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1141
|
+
return __generator(this, function(_a) {
|
|
1142
|
+
switch (_a.label) {
|
|
1143
|
+
case 0:
|
|
1144
|
+
return [4, this.emulator.connect()];
|
|
1145
|
+
case 1:
|
|
1146
|
+
_a.sent();
|
|
1147
|
+
return [4, this.emulator.fs.init(files)];
|
|
1148
|
+
case 2:
|
|
1149
|
+
_a.sent();
|
|
1150
|
+
return [4, this.globalListeners()];
|
|
1151
|
+
case 3:
|
|
1152
|
+
_a.sent();
|
|
1153
|
+
return [
|
|
1154
|
+
2
|
|
1155
|
+
/*return*/
|
|
1156
|
+
];
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
});
|
|
1160
|
+
};
|
|
1161
|
+
SandpackNode2.prototype.compile = function(files) {
|
|
1162
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1163
|
+
var shellId, err_1;
|
|
1164
|
+
return __generator(this, function(_a) {
|
|
1165
|
+
switch (_a.label) {
|
|
1166
|
+
case 0:
|
|
1167
|
+
_a.trys.push([0, 5, , 6]);
|
|
1168
|
+
this.status = "initializing";
|
|
1169
|
+
this.dispatch({ type: "start", firstLoad: true });
|
|
1170
|
+
if (!this._initPromise) {
|
|
1171
|
+
this._initPromise = this._init(files);
|
|
1172
|
+
}
|
|
1173
|
+
return [4, this._initPromise];
|
|
1174
|
+
case 1:
|
|
1175
|
+
_a.sent();
|
|
1176
|
+
this.dispatch({ type: "connected" });
|
|
1177
|
+
return [4, this.createShellProcessFromTask(files)];
|
|
1178
|
+
case 2:
|
|
1179
|
+
shellId = _a.sent().id;
|
|
1180
|
+
return [4, this.createPreviewURLFromId(shellId)];
|
|
1181
|
+
case 3:
|
|
1182
|
+
_a.sent();
|
|
1183
|
+
return [4, this.setLocationURLIntoIFrame()];
|
|
1184
|
+
case 4:
|
|
1185
|
+
_a.sent();
|
|
1186
|
+
this.dispatchDoneMessage();
|
|
1187
|
+
return [3, 6];
|
|
1188
|
+
case 5:
|
|
1189
|
+
err_1 = _a.sent();
|
|
1190
|
+
this.dispatch({
|
|
1191
|
+
type: "action",
|
|
1192
|
+
action: "notification",
|
|
1193
|
+
notificationType: "error",
|
|
1194
|
+
title: getMessageFromError(err_1)
|
|
1195
|
+
});
|
|
1196
|
+
this.dispatch({ type: "done", compilatonError: true });
|
|
1197
|
+
return [3, 6];
|
|
1198
|
+
case 6:
|
|
1199
|
+
return [
|
|
1200
|
+
2
|
|
1201
|
+
/*return*/
|
|
1202
|
+
];
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
});
|
|
1206
|
+
};
|
|
1207
|
+
SandpackNode2.prototype.createShellProcessFromTask = function(files) {
|
|
1208
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1209
|
+
var packageJsonContent;
|
|
1210
|
+
var _a;
|
|
1211
|
+
var _this = this;
|
|
1212
|
+
return __generator(this, function(_b) {
|
|
1213
|
+
switch (_b.label) {
|
|
1214
|
+
case 0:
|
|
1215
|
+
packageJsonContent = readBuffer(files["/package.json"]);
|
|
1216
|
+
this.emulatorCommand = findStartScriptPackageJson(packageJsonContent);
|
|
1217
|
+
this.emulatorShellProcess = this.emulator.shell.create();
|
|
1218
|
+
return [4, this.emulatorShellProcess.on("exit", function(exitCode) {
|
|
1219
|
+
_this.dispatch({
|
|
1220
|
+
type: "action",
|
|
1221
|
+
action: "notification",
|
|
1222
|
+
notificationType: "error",
|
|
1223
|
+
title: createError("Error: process.exit(".concat(exitCode, ") called."))
|
|
1224
|
+
});
|
|
1225
|
+
})];
|
|
1226
|
+
case 1:
|
|
1227
|
+
_b.sent();
|
|
1228
|
+
return [4, this.emulatorShellProcess.on("progress", function(data) {
|
|
1229
|
+
var _a2, _b2;
|
|
1230
|
+
if (data.state === "command_running" || data.state === "starting_command") {
|
|
1231
|
+
_this.dispatch({
|
|
1232
|
+
type: "shell/progress",
|
|
1233
|
+
data: __assign(__assign({}, data), { command: [
|
|
1234
|
+
(_a2 = _this.emulatorCommand) === null || _a2 === void 0 ? void 0 : _a2[0],
|
|
1235
|
+
(_b2 = _this.emulatorCommand) === null || _b2 === void 0 ? void 0 : _b2[1].join(" ")
|
|
1236
|
+
].join(" ") })
|
|
1237
|
+
});
|
|
1238
|
+
_this.status = "installing-dependencies";
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
_this.dispatch({ type: "shell/progress", data });
|
|
1242
|
+
})];
|
|
1243
|
+
case 2:
|
|
1244
|
+
_b.sent();
|
|
1245
|
+
this.emulatorShellProcess.stdout.on("data", function(data) {
|
|
1246
|
+
_this.dispatch({ type: "stdout", payload: { data, type: "out" } });
|
|
1247
|
+
});
|
|
1248
|
+
this.emulatorShellProcess.stderr.on("data", function(data) {
|
|
1249
|
+
_this.dispatch({ type: "stdout", payload: { data, type: "err" } });
|
|
1250
|
+
});
|
|
1251
|
+
return [4, (_a = this.emulatorShellProcess).runCommand.apply(_a, this.emulatorCommand)];
|
|
1252
|
+
case 3:
|
|
1253
|
+
return [2, _b.sent()];
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
});
|
|
1257
|
+
};
|
|
1258
|
+
SandpackNode2.prototype.createPreviewURLFromId = function(id) {
|
|
1259
|
+
var _a;
|
|
1260
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1261
|
+
var url;
|
|
1262
|
+
return __generator(this, function(_b) {
|
|
1263
|
+
switch (_b.label) {
|
|
1264
|
+
case 0:
|
|
1265
|
+
this.iframePreviewUrl = void 0;
|
|
1266
|
+
return [4, this.emulator.preview.getByShellId(id)];
|
|
1267
|
+
case 1:
|
|
1268
|
+
url = _b.sent().url;
|
|
1269
|
+
this.iframePreviewUrl = url + ((_a = this.options.startRoute) !== null && _a !== void 0 ? _a : "");
|
|
1270
|
+
return [
|
|
1271
|
+
2
|
|
1272
|
+
/*return*/
|
|
1273
|
+
];
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
});
|
|
1277
|
+
};
|
|
1278
|
+
SandpackNode2.prototype.manageIframes = function(selector) {
|
|
1279
|
+
var _a;
|
|
1280
|
+
if (typeof selector === "string") {
|
|
1281
|
+
var element = document.querySelector(selector);
|
|
1282
|
+
nullthrows(element, "The element '".concat(selector, "' was not found"));
|
|
1283
|
+
this.iframe = document.createElement("iframe");
|
|
1284
|
+
element === null || element === void 0 ? void 0 : element.appendChild(this.iframe);
|
|
1285
|
+
} else {
|
|
1286
|
+
this.iframe = selector;
|
|
1287
|
+
}
|
|
1288
|
+
setPreviewIframeProperties(this.iframe, this.options);
|
|
1289
|
+
nullthrows(this.iframe.parentNode, "The given iframe does not have a parent.");
|
|
1290
|
+
this.emulatorIframe = document.createElement("iframe");
|
|
1291
|
+
this.emulatorIframe.classList.add("sp-bridge-frame");
|
|
1292
|
+
(_a = this.iframe.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(this.emulatorIframe);
|
|
1293
|
+
};
|
|
1294
|
+
SandpackNode2.prototype.setLocationURLIntoIFrame = function() {
|
|
1295
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1296
|
+
return __generator(this, function(_a) {
|
|
1297
|
+
switch (_a.label) {
|
|
1298
|
+
case 0:
|
|
1299
|
+
if (!this.iframePreviewUrl) return [3, 2];
|
|
1300
|
+
return [4, loadPreviewIframe(this.iframe, this.iframePreviewUrl)];
|
|
1301
|
+
case 1:
|
|
1302
|
+
_a.sent();
|
|
1303
|
+
_a.label = 2;
|
|
1304
|
+
case 2:
|
|
1305
|
+
return [
|
|
1306
|
+
2
|
|
1307
|
+
/*return*/
|
|
1308
|
+
];
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
});
|
|
1312
|
+
};
|
|
1313
|
+
SandpackNode2.prototype.dispatchDoneMessage = function() {
|
|
1314
|
+
this.status = "done";
|
|
1315
|
+
this.dispatch({ type: "done", compilatonError: false });
|
|
1316
|
+
if (this.iframePreviewUrl) {
|
|
1317
|
+
this.dispatch({
|
|
1318
|
+
type: "urlchange",
|
|
1319
|
+
url: this.iframePreviewUrl,
|
|
1320
|
+
back: false,
|
|
1321
|
+
forward: false
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
SandpackNode2.prototype.globalListeners = function() {
|
|
1326
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1327
|
+
var _this = this;
|
|
1328
|
+
return __generator(this, function(_a) {
|
|
1329
|
+
switch (_a.label) {
|
|
1330
|
+
case 0:
|
|
1331
|
+
window.addEventListener("message", function(event) {
|
|
1332
|
+
if (event.data.type === PREVIEW_LOADED_MESSAGE_TYPE) {
|
|
1333
|
+
injectScriptToIframe(_this.iframe, _this.messageChannelId);
|
|
1334
|
+
}
|
|
1335
|
+
if (event.data.type === "urlchange" && event.data.channelId === _this.messageChannelId) {
|
|
1336
|
+
_this.dispatch({
|
|
1337
|
+
type: "urlchange",
|
|
1338
|
+
url: event.data.url,
|
|
1339
|
+
back: event.data.back,
|
|
1340
|
+
forward: event.data.forward
|
|
1341
|
+
});
|
|
1342
|
+
} else if (event.data.channelId === _this.messageChannelId) {
|
|
1343
|
+
_this.dispatch(event.data);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
return [4, this.emulator.fs.watch(["*"], [
|
|
1347
|
+
".next",
|
|
1348
|
+
"node_modules",
|
|
1349
|
+
"build",
|
|
1350
|
+
"dist",
|
|
1351
|
+
"vendor",
|
|
1352
|
+
".config",
|
|
1353
|
+
".vuepress"
|
|
1354
|
+
], function(message) {
|
|
1355
|
+
return __awaiter(_this, void 0, void 0, function() {
|
|
1356
|
+
var event, path, type, _a2, content, newContent, err_2;
|
|
1357
|
+
return __generator(this, function(_b) {
|
|
1358
|
+
switch (_b.label) {
|
|
1359
|
+
case 0:
|
|
1360
|
+
if (!message)
|
|
1361
|
+
return [
|
|
1362
|
+
2
|
|
1363
|
+
/*return*/
|
|
1364
|
+
];
|
|
1365
|
+
event = message;
|
|
1366
|
+
path = "newPath" in event ? event.newPath : "path" in event ? event.path : "";
|
|
1367
|
+
return [4, this.emulator.fs.stat(path)];
|
|
1368
|
+
case 1:
|
|
1369
|
+
type = _b.sent().type;
|
|
1370
|
+
if (type !== "file")
|
|
1371
|
+
return [2, null];
|
|
1372
|
+
_b.label = 2;
|
|
1373
|
+
case 2:
|
|
1374
|
+
_b.trys.push([2, 10, , 11]);
|
|
1375
|
+
_a2 = event.type;
|
|
1376
|
+
switch (_a2) {
|
|
1377
|
+
case "change":
|
|
1378
|
+
return [3, 3];
|
|
1379
|
+
case "create":
|
|
1380
|
+
return [3, 3];
|
|
1381
|
+
case "remove":
|
|
1382
|
+
return [3, 5];
|
|
1383
|
+
case "rename":
|
|
1384
|
+
return [3, 6];
|
|
1385
|
+
case "close":
|
|
1386
|
+
return [3, 8];
|
|
1387
|
+
}
|
|
1388
|
+
return [3, 9];
|
|
1389
|
+
case 3:
|
|
1390
|
+
return [4, this.emulator.fs.readFile(event.path, "utf8")];
|
|
1391
|
+
case 4:
|
|
1392
|
+
content = _b.sent();
|
|
1393
|
+
this.dispatch({
|
|
1394
|
+
type: "fs/change",
|
|
1395
|
+
path: event.path,
|
|
1396
|
+
content
|
|
1397
|
+
});
|
|
1398
|
+
this._modulesCache.set(event.path, writeBuffer(content));
|
|
1399
|
+
return [3, 9];
|
|
1400
|
+
case 5:
|
|
1401
|
+
this.dispatch({
|
|
1402
|
+
type: "fs/remove",
|
|
1403
|
+
path: event.path
|
|
1404
|
+
});
|
|
1405
|
+
this._modulesCache.delete(event.path);
|
|
1406
|
+
return [3, 9];
|
|
1407
|
+
case 6:
|
|
1408
|
+
this.dispatch({
|
|
1409
|
+
type: "fs/remove",
|
|
1410
|
+
path: event.oldPath
|
|
1411
|
+
});
|
|
1412
|
+
this._modulesCache.delete(event.oldPath);
|
|
1413
|
+
return [4, this.emulator.fs.readFile(event.newPath, "utf8")];
|
|
1414
|
+
case 7:
|
|
1415
|
+
newContent = _b.sent();
|
|
1416
|
+
this.dispatch({
|
|
1417
|
+
type: "fs/change",
|
|
1418
|
+
path: event.newPath,
|
|
1419
|
+
content: newContent
|
|
1420
|
+
});
|
|
1421
|
+
this._modulesCache.set(event.newPath, writeBuffer(newContent));
|
|
1422
|
+
return [3, 9];
|
|
1423
|
+
case 8:
|
|
1424
|
+
return [3, 9];
|
|
1425
|
+
case 9:
|
|
1426
|
+
return [3, 11];
|
|
1427
|
+
case 10:
|
|
1428
|
+
err_2 = _b.sent();
|
|
1429
|
+
this.dispatch({
|
|
1430
|
+
type: "action",
|
|
1431
|
+
action: "notification",
|
|
1432
|
+
notificationType: "error",
|
|
1433
|
+
title: getMessageFromError(err_2)
|
|
1434
|
+
});
|
|
1435
|
+
return [3, 11];
|
|
1436
|
+
case 11:
|
|
1437
|
+
return [
|
|
1438
|
+
2
|
|
1439
|
+
/*return*/
|
|
1440
|
+
];
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
});
|
|
1444
|
+
})];
|
|
1445
|
+
case 1:
|
|
1446
|
+
_a.sent();
|
|
1447
|
+
return [
|
|
1448
|
+
2
|
|
1449
|
+
/*return*/
|
|
1450
|
+
];
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
SandpackNode2.prototype.restartShellProcess = function() {
|
|
1456
|
+
var _a;
|
|
1457
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1458
|
+
return __generator(this, function(_b) {
|
|
1459
|
+
switch (_b.label) {
|
|
1460
|
+
case 0:
|
|
1461
|
+
if (!(this.emulatorShellProcess && this.emulatorCommand)) return [3, 3];
|
|
1462
|
+
this.dispatch({ type: "start", firstLoad: true });
|
|
1463
|
+
this.status = "initializing";
|
|
1464
|
+
return [4, this.emulatorShellProcess.kill()];
|
|
1465
|
+
case 1:
|
|
1466
|
+
_b.sent();
|
|
1467
|
+
(_a = this.iframe) === null || _a === void 0 ? void 0 : _a.removeAttribute("attr");
|
|
1468
|
+
this.emulator.fs.rm("/node_modules/.vite", {
|
|
1469
|
+
recursive: true,
|
|
1470
|
+
force: true
|
|
1471
|
+
});
|
|
1472
|
+
return [4, this.compile(Object.fromEntries(this._modulesCache))];
|
|
1473
|
+
case 2:
|
|
1474
|
+
_b.sent();
|
|
1475
|
+
_b.label = 3;
|
|
1476
|
+
case 3:
|
|
1477
|
+
return [
|
|
1478
|
+
2
|
|
1479
|
+
/*return*/
|
|
1480
|
+
];
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
});
|
|
1484
|
+
};
|
|
1485
|
+
SandpackNode2.prototype.updateSandbox = function(setup) {
|
|
1486
|
+
var _this = this;
|
|
1487
|
+
var _a;
|
|
1488
|
+
var modules = fromBundlerFilesToFS(setup.files);
|
|
1489
|
+
if (((_a = this.emulatorShellProcess) === null || _a === void 0 ? void 0 : _a.state) === "running") {
|
|
1490
|
+
Object.entries(modules).forEach(function(_a2) {
|
|
1491
|
+
var key = _a2[0], value = _a2[1];
|
|
1492
|
+
if (!_this._modulesCache.get(key) || readBuffer(value) !== readBuffer(_this._modulesCache.get(key))) {
|
|
1493
|
+
_this.emulator.fs.writeFile(key, value, { recursive: true });
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
this.dispatch({
|
|
1499
|
+
codesandbox: true,
|
|
1500
|
+
modules,
|
|
1501
|
+
template: setup.template,
|
|
1502
|
+
type: "compile"
|
|
1503
|
+
});
|
|
1504
|
+
Object.entries(modules).forEach(function(_a2) {
|
|
1505
|
+
var key = _a2[0], value = _a2[1];
|
|
1506
|
+
_this._modulesCache.set(key, writeBuffer(value));
|
|
1507
|
+
});
|
|
1508
|
+
};
|
|
1509
|
+
SandpackNode2.prototype.dispatch = function(message) {
|
|
1510
|
+
var _a, _b;
|
|
1511
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
1512
|
+
var _c;
|
|
1513
|
+
return __generator(this, function(_d) {
|
|
1514
|
+
switch (_d.label) {
|
|
1515
|
+
case 0:
|
|
1516
|
+
_c = message.type;
|
|
1517
|
+
switch (_c) {
|
|
1518
|
+
case "compile":
|
|
1519
|
+
return [3, 1];
|
|
1520
|
+
case "refresh":
|
|
1521
|
+
return [3, 2];
|
|
1522
|
+
case "urlback":
|
|
1523
|
+
return [3, 4];
|
|
1524
|
+
case "urlforward":
|
|
1525
|
+
return [3, 4];
|
|
1526
|
+
case "shell/restart":
|
|
1527
|
+
return [3, 5];
|
|
1528
|
+
case "shell/openPreview":
|
|
1529
|
+
return [3, 6];
|
|
1530
|
+
}
|
|
1531
|
+
return [3, 7];
|
|
1532
|
+
case 1:
|
|
1533
|
+
this.compile(message.modules);
|
|
1534
|
+
return [3, 8];
|
|
1535
|
+
case 2:
|
|
1536
|
+
return [4, this.setLocationURLIntoIFrame()];
|
|
1537
|
+
case 3:
|
|
1538
|
+
_d.sent();
|
|
1539
|
+
return [3, 8];
|
|
1540
|
+
case 4:
|
|
1541
|
+
(_b = (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(message, "*");
|
|
1542
|
+
return [3, 8];
|
|
1543
|
+
case 5:
|
|
1544
|
+
this.restartShellProcess();
|
|
1545
|
+
return [3, 8];
|
|
1546
|
+
case 6:
|
|
1547
|
+
window.open(this.iframePreviewUrl, "_blank");
|
|
1548
|
+
return [3, 8];
|
|
1549
|
+
case 7:
|
|
1550
|
+
this.emitter.dispatch(message);
|
|
1551
|
+
_d.label = 8;
|
|
1552
|
+
case 8:
|
|
1553
|
+
return [
|
|
1554
|
+
2
|
|
1555
|
+
/*return*/
|
|
1556
|
+
];
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
});
|
|
1560
|
+
};
|
|
1561
|
+
SandpackNode2.prototype.listen = function(listener) {
|
|
1562
|
+
return this.emitter.listener(listener);
|
|
1563
|
+
};
|
|
1564
|
+
SandpackNode2.prototype.destroy = function() {
|
|
1565
|
+
this.emulatorIframe.remove();
|
|
1566
|
+
this.emitter.cleanup();
|
|
1567
|
+
};
|
|
1568
|
+
return SandpackNode2;
|
|
1569
|
+
})(SandpackClient)
|
|
1570
|
+
);
|
|
1571
|
+
export {
|
|
1572
|
+
SandpackNode
|
|
1573
|
+
};
|