@wangtaizong/components 1.0.6 → 1.0.7

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.
Files changed (80) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.dumirc.ts +28 -0
  4. package/.editorconfig +13 -0
  5. package/.eslintrc.js +3 -0
  6. package/.husky/commit-msg +5 -0
  7. package/.husky/pre-commit +8 -0
  8. package/.husky/pre-push +8 -0
  9. package/.prettierignore +2 -0
  10. package/.prettierrc.js +19 -0
  11. package/.stylelintrc +3 -0
  12. package/.vscode/settings.json +3 -0
  13. package/LICENSE +21 -0
  14. package/README.md +0 -52
  15. package/commitlint.config.js +21 -0
  16. package/docs/changelogs/index.md +9 -0
  17. package/docs/components/index.md +1 -0
  18. package/docs/guide/install.md +39 -0
  19. package/docs/index.md +21 -0
  20. package/docs/utils/index.md +1 -0
  21. package/lerna.json +8 -0
  22. package/package.json +66 -69
  23. package/packages/components/CHANGELOG.md +0 -0
  24. package/packages/components/package.json +48 -0
  25. package/packages/components/rollup.config.mjs +108 -0
  26. package/packages/components/src/Button/index.md +13 -0
  27. package/packages/components/src/Button/index.tsx +34 -0
  28. package/packages/components/src/Icon/index.md +81 -0
  29. package/packages/components/src/Icon/index.tsx +34 -0
  30. package/packages/components/src/Upload/index.md +209 -0
  31. package/packages/components/src/Upload/index.tsx +218 -0
  32. package/packages/components/src/antd/index.md +12 -0
  33. package/packages/components/src/antd/index.tsx +2 -0
  34. package/packages/components/src/index.md +23 -0
  35. package/packages/components/src/index.ts +5 -0
  36. package/packages/components/tsconfig.json +32 -0
  37. package/packages/utils/README.md +11 -0
  38. package/packages/utils/package.json +35 -0
  39. package/packages/utils/rollup.config.mjs +63 -0
  40. package/packages/utils/src/CHRRequest/index.md +59 -0
  41. package/packages/utils/src/CHRRequest/index.ts +94 -0
  42. package/packages/utils/src/index.ts +17 -0
  43. package/packages/utils/tsconfig.json +28 -0
  44. package/pnpm-workspace.yaml +8 -0
  45. package/public/favicon.ico +0 -0
  46. package/public/logo.webp +0 -0
  47. package/tsconfig.json +14 -0
  48. package/dist/Add.d.ts +0 -2
  49. package/dist/base-80a1f760-22b3368a.js +0 -23
  50. package/dist/components/editor/MonacoEditor.d.ts +0 -2
  51. package/dist/components/editor/WEditor.d.ts +0 -13
  52. package/dist/components/editor/sandpack-file-explorer/CreateNewNode.d.ts +0 -3
  53. package/dist/components/editor/sandpack-file-explorer/Example.d.ts +0 -4
  54. package/dist/components/editor/sandpack-file-explorer/FileTreeExplorer.d.ts +0 -1
  55. package/dist/components/editor/sandpack-file-explorer/SandpackFilesProvider.d.ts +0 -24
  56. package/dist/components/editor/sandpack-file-explorer/SingleInputForm.d.ts +0 -8
  57. package/dist/components/editor/sandpack-file-explorer/index.d.ts +0 -6
  58. package/dist/components/editor/sandpack-file-explorer/types.d.ts +0 -18
  59. package/dist/components/editor/sandpack-file-explorer/utils/arrayToObject.d.ts +0 -1
  60. package/dist/components/editor/sandpack-file-explorer/utils/buildPath.d.ts +0 -2
  61. package/dist/components/editor/sandpack-file-explorer/utils/deepMerge.d.ts +0 -2
  62. package/dist/components/editor/sandpack-file-explorer/utils/deleteKeys.d.ts +0 -4
  63. package/dist/components/editor/sandpack-file-explorer/utils/directoryFileMap.d.ts +0 -3
  64. package/dist/components/editor/sandpack-file-explorer/utils/fiindParentPath.d.ts +0 -1
  65. package/dist/components/editor/sandpack-file-explorer/utils/flattenObject.d.ts +0 -2
  66. package/dist/components/editor/sandpack-file-explorer/utils/getEntryFile.d.ts +0 -2
  67. package/dist/components/editor/sandpack-file-explorer/utils/getRemovedKeys.d.ts +0 -5
  68. package/dist/components/editor/sandpack-file-explorer/utils/index.d.ts +0 -12
  69. package/dist/components/editor/sandpack-file-explorer/utils/mergeHierarchicalArray.d.ts +0 -2
  70. package/dist/components/editor/sandpack-file-explorer/utils/removeHiddenEntries.d.ts +0 -3
  71. package/dist/components/editor/sandpack-file-explorer/utils/toHierarchicalArray.d.ts +0 -3
  72. package/dist/components/editor/utils/map.d.ts +0 -4
  73. package/dist/consoleHook-59e792cb-0fba2dba.js +0 -168
  74. package/dist/index-3417dbcd.js +0 -316
  75. package/dist/index-585bceb7-39d610b1.js +0 -8813
  76. package/dist/index-6426660e.js +0 -32172
  77. package/dist/index-a63bd288.js +0 -1104
  78. package/dist/index.d.ts +0 -2
  79. package/dist/index.es.js +0 -5
  80. package/dist/index.umd.js +0 -779
@@ -1,1104 +0,0 @@
1
- var ne = Object.defineProperty;
2
- var ie = (e, r, t) => r in e ? ne(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
3
- var p = (e, r, t) => (ie(e, typeof r != "symbol" ? r + "" : r, t), t), T = (e, r, t) => {
4
- if (!r.has(e))
5
- throw TypeError("Cannot " + t);
6
- };
7
- var k = (e, r, t) => (T(e, r, "read from private field"), t ? t.call(e) : r.get(e)), R = (e, r, t) => {
8
- if (r.has(e))
9
- throw TypeError("Cannot add the same private member more than once");
10
- r instanceof WeakSet ? r.add(e) : r.set(e, t);
11
- }, V = (e, r, t, n) => (T(e, r, "write to private field"), n ? n.call(e, t) : r.set(e, t), t);
12
- var F = (e, r, t) => (T(e, r, "access private method"), t);
13
- import { _ as se, a as E, b as P, c as A, d as K, n as N } from "./index-6426660e.js";
14
- import { S as oe } from "./base-80a1f760-22b3368a.js";
15
- import { c as ae, g as z, r as U, f as ce, w as W, a as de, b as le, E as ue } from "./consoleHook-59e792cb-0fba2dba.js";
16
- import "react";
17
- var he = Object.create, q = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, X = Object.getOwnPropertyNames, pe = Object.getPrototypeOf, me = Object.prototype.hasOwnProperty, ve = (e, r, t) => r in e ? q(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, b = (e, r) => function() {
18
- return r || (0, e[X(e)[0]])((r = { exports: {} }).exports, r), r.exports;
19
- }, we = (e, r, t, n) => {
20
- if (r && typeof r == "object" || typeof r == "function")
21
- for (let s of X(r))
22
- !me.call(e, s) && s !== t && q(e, s, { get: () => r[s], enumerable: !(n = fe(r, s)) || n.enumerable });
23
- return e;
24
- }, j = (e, r, t) => (t = e != null ? he(pe(e)) : {}, we(
25
- r || !e || !e.__esModule ? q(t, "default", { value: e, enumerable: !0 }) : t,
26
- e
27
- )), ge = (e, r, t) => (ve(e, typeof r != "symbol" ? r + "" : r, t), t), H = (e, r, t) => {
28
- if (!r.has(e))
29
- throw TypeError("Cannot " + t);
30
- }, y = (e, r, t) => (H(e, r, "read from private field"), t ? t.call(e) : r.get(e)), O = (e, r, t) => {
31
- if (r.has(e))
32
- throw TypeError("Cannot add the same private member more than once");
33
- r instanceof WeakSet ? r.add(e) : r.set(e, t);
34
- }, C = (e, r, t, n) => (H(e, r, "write to private field"), n ? n.call(e, t) : r.set(e, t), t), _ = (e, r, t) => (H(e, r, "access private method"), t), Q = b({
35
- "../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/pad.js"(e, r) {
36
- r.exports = function(n, s) {
37
- var i = "000000000" + n;
38
- return i.substr(i.length - s);
39
- };
40
- }
41
- }), ye = b({
42
- "../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/fingerprint.browser.js"(e, r) {
43
- var t = Q(), n = typeof window == "object" ? window : self, s = Object.keys(n).length, i = navigator.mimeTypes ? navigator.mimeTypes.length : 0, o = t((i + navigator.userAgent.length).toString(36) + s.toString(36), 4);
44
- r.exports = function() {
45
- return o;
46
- };
47
- }
48
- }), _e = b({
49
- "../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/lib/getRandomValue.browser.js"(e, r) {
50
- var t, n = typeof window < "u" && (window.crypto || window.msCrypto) || typeof self < "u" && self.crypto;
51
- n ? (s = Math.pow(2, 32) - 1, t = function() {
52
- return Math.abs(n.getRandomValues(new Uint32Array(1))[0] / s);
53
- }) : t = Math.random;
54
- var s;
55
- r.exports = t;
56
- }
57
- }), Z = b({
58
- "../../node_modules/.pnpm/cuid@2.1.8/node_modules/cuid/index.js"(e, r) {
59
- var t = ye(), n = Q(), s = _e(), i = 0, o = 4, a = 36, c = Math.pow(a, o);
60
- function l() {
61
- return n((s() * c << 0).toString(a), o);
62
- }
63
- function h() {
64
- return i = i < c ? i : 0, i++, i - 1;
65
- }
66
- function f() {
67
- var v = "c", w = (/* @__PURE__ */ new Date()).getTime().toString(a), S = n(h().toString(a), o), d = t(), u = l() + l();
68
- return v + w + S + d + u;
69
- }
70
- f.slug = function() {
71
- var w = (/* @__PURE__ */ new Date()).getTime().toString(36), S = h().toString(36).slice(-4), d = t().slice(0, 1) + t().slice(-1), u = l().slice(-2);
72
- return w.slice(-2) + S + d + u;
73
- }, f.isCuid = function(w) {
74
- return typeof w != "string" ? !1 : !!w.startsWith("c");
75
- }, f.isSlug = function(w) {
76
- if (typeof w != "string")
77
- return !1;
78
- var S = w.length;
79
- return S >= 7 && S <= 10;
80
- }, f.fingerprint = t, r.exports = f;
81
- }
82
- }), ee = b({
83
- "../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/createDeferredExecutor.js"(e) {
84
- Object.defineProperty(e, "__esModule", { value: !0 }), e.createDeferredExecutor = void 0;
85
- function r() {
86
- const t = (n, s) => {
87
- t.state = "pending", t.resolve = (i) => {
88
- if (t.state !== "pending")
89
- return;
90
- t.result = i;
91
- const o = (a) => (t.state = "fulfilled", a);
92
- return n(i instanceof Promise ? i : Promise.resolve(i).then(o));
93
- }, t.reject = (i) => {
94
- if (t.state === "pending")
95
- return queueMicrotask(() => {
96
- t.state = "rejected";
97
- }), s(t.rejectionReason = i);
98
- };
99
- };
100
- return t;
101
- }
102
- e.createDeferredExecutor = r;
103
- }
104
- }), Ee = b({
105
- "../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/DeferredPromise.js"(e) {
106
- var n, s, D, o;
107
- Object.defineProperty(e, "__esModule", { value: !0 }), e.DeferredPromise = void 0;
108
- var r = ee(), t = (o = class extends Promise {
109
- constructor(c = null) {
110
- const l = (0, r.createDeferredExecutor)();
111
- super((h, f) => {
112
- l(h, f), c == null || c(l.resolve, l.reject);
113
- });
114
- R(this, s);
115
- R(this, n, void 0);
116
- p(this, "resolve");
117
- p(this, "reject");
118
- V(this, n, l), this.resolve = k(this, n).resolve, this.reject = k(this, n).reject;
119
- }
120
- get state() {
121
- return k(this, n).state;
122
- }
123
- get rejectionReason() {
124
- return k(this, n).rejectionReason;
125
- }
126
- then(c, l) {
127
- return F(this, s, D).call(this, super.then(c, l));
128
- }
129
- catch(c) {
130
- return F(this, s, D).call(this, super.catch(c));
131
- }
132
- finally(c) {
133
- return F(this, s, D).call(this, super.finally(c));
134
- }
135
- }, n = new WeakMap(), s = new WeakSet(), D = function(c) {
136
- return Object.defineProperties(c, {
137
- resolve: { configurable: !0, value: this.resolve },
138
- reject: { configurable: !0, value: this.reject }
139
- });
140
- }, o);
141
- e.DeferredPromise = t;
142
- }
143
- }), $ = b({
144
- "../../node_modules/.pnpm/@open-draft+deferred-promise@2.1.0/node_modules/@open-draft/deferred-promise/build/index.js"(e) {
145
- var r = e && e.__createBinding || (Object.create ? function(n, s, i, o) {
146
- o === void 0 && (o = i);
147
- var a = Object.getOwnPropertyDescriptor(s, i);
148
- (!a || ("get" in a ? !s.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
149
- return s[i];
150
- } }), Object.defineProperty(n, o, a);
151
- } : function(n, s, i, o) {
152
- o === void 0 && (o = i), n[o] = s[i];
153
- }), t = e && e.__exportStar || function(n, s) {
154
- for (var i in n)
155
- i !== "default" && !Object.prototype.hasOwnProperty.call(s, i) && r(s, n, i);
156
- };
157
- Object.defineProperty(e, "__esModule", { value: !0 }), t(ee(), e), t(Ee(), e);
158
- }
159
- }), te = b({
160
- "../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/MemoryLeakError.js"(e) {
161
- Object.defineProperty(e, "__esModule", { value: !0 }), e.MemoryLeakError = void 0;
162
- var r = class extends Error {
163
- constructor(n, s, i) {
164
- super(`Possible EventEmitter memory leak detected. ${i} ${s.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`);
165
- p(this, "emitter");
166
- p(this, "type");
167
- p(this, "count");
168
- this.emitter = n, this.type = s, this.count = i, this.name = "MaxListenersExceededWarning";
169
- }
170
- };
171
- e.MemoryLeakError = r;
172
- }
173
- }), Pe = b({
174
- "../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/Emitter.js"(e) {
175
- Object.defineProperty(e, "__esModule", { value: !0 }), e.Emitter = void 0;
176
- var r = te(), t, n, s, i, o, a, c, l, h, f, v, w = class {
177
- constructor() {
178
- O(this, i), O(this, a), O(this, l), O(this, f), O(this, t, void 0), O(this, n, void 0), O(this, s, void 0), C(this, t, /* @__PURE__ */ new Map()), C(this, n, w.defaultMaxListeners), C(this, s, !1);
179
- }
180
- static listenerCount(d, u) {
181
- return d.listenerCount(u);
182
- }
183
- setMaxListeners(d) {
184
- return C(this, n, d), this;
185
- }
186
- getMaxListeners() {
187
- return y(this, n);
188
- }
189
- eventNames() {
190
- return Array.from(y(this, t).keys());
191
- }
192
- emit(d, ...u) {
193
- const m = _(this, i, o).call(this, d);
194
- return m.forEach((M) => {
195
- M.apply(this, u);
196
- }), m.length > 0;
197
- }
198
- addListener(d, u) {
199
- _(this, f, v).call(this, "newListener", d, u);
200
- const m = _(this, i, o).call(this, d).concat(u);
201
- if (y(this, t).set(d, m), y(this, n) > 0 && this.listenerCount(d) > y(this, n) && !y(this, s)) {
202
- C(this, s, !0);
203
- const M = new r.MemoryLeakError(this, d, this.listenerCount(d));
204
- console.warn(M);
205
- }
206
- return this;
207
- }
208
- on(d, u) {
209
- return this.addListener(d, u);
210
- }
211
- once(d, u) {
212
- return this.addListener(d, _(this, l, h).call(this, d, u));
213
- }
214
- prependListener(d, u) {
215
- const m = _(this, i, o).call(this, d);
216
- if (m.length > 0) {
217
- const M = [u].concat(m);
218
- y(this, t).set(d, M);
219
- } else
220
- y(this, t).set(d, m.concat(u));
221
- return this;
222
- }
223
- prependOnceListener(d, u) {
224
- return this.prependListener(d, _(this, l, h).call(this, d, u));
225
- }
226
- removeListener(d, u) {
227
- const m = _(this, i, o).call(this, d);
228
- return m.length > 0 && (_(this, a, c).call(this, m, u), y(this, t).set(d, m), _(this, f, v).call(this, "removeListener", d, u)), this;
229
- }
230
- off(d, u) {
231
- return this.removeListener(d, u);
232
- }
233
- removeAllListeners(d) {
234
- return d ? y(this, t).delete(d) : y(this, t).clear(), this;
235
- }
236
- listeners(d) {
237
- return Array.from(_(this, i, o).call(this, d));
238
- }
239
- listenerCount(d) {
240
- return _(this, i, o).call(this, d).length;
241
- }
242
- rawListeners(d) {
243
- return this.listeners(d);
244
- }
245
- }, S = w;
246
- t = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakSet(), o = function(d) {
247
- return y(this, t).get(d) || [];
248
- }, a = /* @__PURE__ */ new WeakSet(), c = function(d, u) {
249
- const m = d.indexOf(u);
250
- return m > -1 && d.splice(m, 1), [];
251
- }, l = /* @__PURE__ */ new WeakSet(), h = function(d, u) {
252
- const m = (...M) => {
253
- this.removeListener(d, m), u.apply(this, M);
254
- };
255
- return m;
256
- }, f = /* @__PURE__ */ new WeakSet(), v = function(d, u, m) {
257
- this.emit(
258
- d,
259
- u,
260
- m
261
- );
262
- }, ge(S, "defaultMaxListeners", 10), e.Emitter = S;
263
- }
264
- }), be = b({
265
- "../../node_modules/.pnpm/strict-event-emitter@0.4.3/node_modules/strict-event-emitter/lib/index.js"(e) {
266
- var r = e && e.__createBinding || (Object.create ? function(n, s, i, o) {
267
- o === void 0 && (o = i);
268
- var a = Object.getOwnPropertyDescriptor(s, i);
269
- (!a || ("get" in a ? !s.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
270
- return s[i];
271
- } }), Object.defineProperty(n, o, a);
272
- } : function(n, s, i, o) {
273
- o === void 0 && (o = i), n[o] = s[i];
274
- }), t = e && e.__exportStar || function(n, s) {
275
- for (var i in n)
276
- i !== "default" && !Object.prototype.hasOwnProperty.call(s, i) && r(s, n, i);
277
- };
278
- Object.defineProperty(e, "__esModule", { value: !0 }), t(Pe(), e), t(te(), e);
279
- }
280
- }), Se = j(Z()), Le = /(%?)(%([sdjo]))/g;
281
- function Ie(e, r) {
282
- switch (r) {
283
- case "s":
284
- return e;
285
- case "d":
286
- case "i":
287
- return Number(e);
288
- case "j":
289
- return JSON.stringify(e);
290
- case "o": {
291
- if (typeof e == "string")
292
- return e;
293
- const t = JSON.stringify(e);
294
- return t === "{}" || t === "[]" || /^\[object .+?\]$/.test(t) ? e : t;
295
- }
296
- }
297
- }
298
- function g(e, ...r) {
299
- if (r.length === 0)
300
- return e;
301
- let t = 0, n = e.replace(
302
- Le,
303
- (s, i, o, a) => {
304
- const c = r[t], l = Ie(c, a);
305
- return i ? s : (t++, l);
306
- }
307
- );
308
- return t < r.length && (n += ` ${r.slice(t).join(" ")}`), n = n.replace(/%{2,2}/g, "%"), n;
309
- }
310
- var Me = 2;
311
- function Oe(e) {
312
- if (!e.stack)
313
- return;
314
- const r = e.stack.split(`
315
- `);
316
- r.splice(1, Me), e.stack = r.join(`
317
- `);
318
- }
319
- var je = class extends Error {
320
- constructor(e, ...r) {
321
- super(e), this.message = e, this.name = "Invariant Violation", this.message = g(e, ...r), Oe(this);
322
- }
323
- }, L = (e, r, ...t) => {
324
- if (!e)
325
- throw new je(r, ...t);
326
- };
327
- L.as = (e, r, t, ...n) => {
328
- if (!r)
329
- throw e.prototype.name != null ? new e(g(t, n)) : e(g(t, n));
330
- };
331
- var B = j($()), ke = window.localStorage.CSB_EMULATOR_DEBUG, Ce = "\x1B[0m", Fe = "\x1B[32;1m", Ae = "\x1B[31m", xe = "\x1B[34m", De = "\x1B[33;1m", Te = "\x1B[35;1m", G = "\x1B[36;1m", Re = {
332
- preview: De,
333
- emulator: Te,
334
- runtime: G,
335
- bridge: xe,
336
- "runtime:worker": G
337
- };
338
- function re(e) {
339
- return function(t, ...n) {
340
- if (ke === "true") {
341
- const s = () => t.includes("sender") ? `${Fe}sender` : t.includes("receiver") ? `${Ae}receiver` : "", i = t.replace(/\[.+\]:/, "");
342
- console.debug(`${Re[e]}${e}:${s()}${Ce}:${i}`, ...n);
343
- }
344
- };
345
- }
346
- var I = re("emulator"), Ue = class {
347
- constructor(e) {
348
- p(this, "emitter");
349
- p(this, "channel");
350
- p(this, "receiverPort");
351
- p(this, "receiverReadyPromise");
352
- this.target = e, this.emitter = new EventTarget(), this.channel = new MessageChannel(), this.receiverPort = this.channel.port1;
353
- const r = new B.DeferredPromise(), t = (n) => {
354
- n.data.type === "internal/ready" && (I("[message-sender]: runtime is ready"), r.resolve());
355
- };
356
- window.addEventListener("message", t), r.then(() => {
357
- window.removeEventListener("message", t);
358
- }), this.receiverReadyPromise = r, this.receiverPort.onmessage = (n) => {
359
- const s = n.data;
360
- s.type != null && (I('[message-sender]: emitting "%s" event...', s.type, s.payload), this.emitter.dispatchEvent(new MessageEvent(s.type, { data: s.payload })));
361
- };
362
- }
363
- async handshake() {
364
- const e = new B.DeferredPromise();
365
- await this.receiverReadyPromise, I("[message-sender]: sending handshake"), this.target.postMessage(
366
- {
367
- type: "internal/handshake"
368
- },
369
- "*",
370
- [this.channel.port2]
371
- ), this.on("internal/handshake/done", () => {
372
- e.resolve(), clearTimeout(r);
373
- });
374
- const r = setTimeout(() => {
375
- e.reject(new Error("MessageSender: Handshake timeout"));
376
- }, 5e3);
377
- return e;
378
- }
379
- on(e, r, t) {
380
- I('[message-sender]: add listener "%s"', e), this.emitter.addEventListener(
381
- e,
382
- (n) => {
383
- n instanceof MessageEvent && r(n);
384
- },
385
- t
386
- );
387
- }
388
- off(e, r, t) {
389
- this.emitter.removeEventListener(e, r, t);
390
- }
391
- async send(e, ...r) {
392
- const t = new B.DeferredPromise(), n = (0, Se.default)(), s = r[0] || {};
393
- I('[message-sender]: send "%s" (%s)', e, n, s), this.receiverPort.postMessage({ type: e, payload: { operationId: n, payload: s } }), I('[message-sender]: adding done listener for "%s" (%s)', e, n);
394
- const i = (a) => {
395
- const { data: c } = a;
396
- if (c.operationId === n) {
397
- const l = c.listenerPayload || {};
398
- I('[message-sender]: resolving "%s (%s) promise!', e, n), t.resolve({
399
- ...l,
400
- operationId: c.operationId
401
- });
402
- }
403
- }, o = (a) => {
404
- const { data: c } = a;
405
- c.operationId === n && (I('[message-sender]: rejecting "%s (%s) promise!', e, n), t.reject(c.error));
406
- };
407
- return this.on("internal/operation/done", i), this.on("internal/operation/failed", o), t.finally(() => {
408
- this.emitter.removeEventListener("internal/operation/done", i), this.emitter.removeEventListener("internal/operation/failed", o);
409
- });
410
- }
411
- }, J = j($()), We = j(Z()), Be = class {
412
- constructor(e) {
413
- this.channel = e;
414
- }
415
- async init(e) {
416
- await this.channel.send("fs/init", { files: e });
417
- }
418
- async readFile(e, r) {
419
- const t = await this.channel.send("fs/readFile", { path: e, encoding: r }).catch((n) => {
420
- throw new Error(g('Failed to read file at path "%s"', e), { cause: n });
421
- });
422
- if (!t)
423
- throw new Error("File not found");
424
- return t.data;
425
- }
426
- async writeFile(e, r, t) {
427
- let n, s = !1;
428
- typeof t == "object" ? (n = t.encoding, s = !!t.recursive) : typeof t == "string" && (n = t), await this.channel.send("fs/writeFile", { path: e, content: r, encoding: n, recursive: s }).catch((i) => {
429
- throw new Error(g('Failed to write file at path "%s"', e), { cause: i });
430
- });
431
- }
432
- async readdir(e) {
433
- const r = await this.channel.send("fs/readdir", { path: e }).catch((t) => {
434
- throw new Error(g('Failed to read directory at path "%s"', e), { cause: t });
435
- });
436
- if (!r)
437
- throw new Error("Directory not found");
438
- return r.data;
439
- }
440
- async mkdir(e, r) {
441
- const t = !!(r != null && r.recursive);
442
- await this.channel.send("fs/mkdir", { path: e, recursive: t }).catch((n) => {
443
- throw new Error(g('Failed to make directory at path "%s"', e), { cause: n });
444
- });
445
- }
446
- async stat(e) {
447
- const r = await this.channel.send("fs/stat", { path: e }).catch((t) => {
448
- throw new Error(g('Failed to stat file at path "%s"', e), { cause: t });
449
- });
450
- if (!r)
451
- throw new Error("File not found");
452
- return r.data;
453
- }
454
- async rm(e, r) {
455
- const { force: t, recursive: n } = r || {};
456
- await this.channel.send("fs/rm", { path: e, force: t, recursive: n }).catch((s) => {
457
- throw new Error(g('Failed to remove file at path "%s"', e), { cause: s });
458
- });
459
- }
460
- async watch(e, r, t) {
461
- const n = (0, We.default)();
462
- return await this.channel.send("fs/watch", { watcherId: n, includes: e, excludes: r }), this.channel.on("fs/watch-event", ({ data: s }) => {
463
- if (s.watcherId === n && t) {
464
- const i = { ...s };
465
- delete i.watcherId, t(i);
466
- }
467
- }), {
468
- dispose: () => this.channel.send("fs/unwatch", { watcherId: n })
469
- };
470
- }
471
- }, Y = j(be()), Ne = class {
472
- constructor(e) {
473
- this.channel = e;
474
- }
475
- create() {
476
- return new qe(this.channel);
477
- }
478
- }, qe = class {
479
- constructor(e) {
480
- p(this, "id");
481
- p(this, "state");
482
- p(this, "stdout");
483
- p(this, "stderr");
484
- p(this, "stdin");
485
- this.channel = e, this.state = "running", this.stdout = new Y.Emitter(), this.stderr = new Y.Emitter(), this.stdin = {
486
- write: (r) => {
487
- if (!this.id)
488
- throw new Error("Failed to write to stdin, no process is currently running");
489
- return this.channel.send("shell/stdin", { data: r, workerId: this.id });
490
- }
491
- }, this.forwardStdEvents();
492
- }
493
- forwardStdEvents() {
494
- this.channel.on("worker/tty", (e) => {
495
- const { data: r } = e;
496
- if (r.workerId === this.id)
497
- switch (r.payload.type) {
498
- case "out": {
499
- this.stdout.emit("data", r.payload.data);
500
- break;
501
- }
502
- case "err": {
503
- this.stderr.emit("data", r.payload.data);
504
- break;
505
- }
506
- }
507
- });
508
- }
509
- async runCommand(e, r, t = {}) {
510
- L(!this.id, 'Failed to run "runCommand" on a ShellProcess: there is already a process running.');
511
- const n = await this.channel.send("shell/runCommand", { command: e, args: r, options: t });
512
- return L(n, 'Failed to run "runCommand" on a ShellProcess: was not able to retrieve a running process.'), this.id = n.id, this.state = "running", n;
513
- }
514
- async on(e, r) {
515
- switch (e) {
516
- case "progress": {
517
- this.channel.on("worker/progress", ({ data: t }) => {
518
- r(t.status);
519
- });
520
- return;
521
- }
522
- case "exit": {
523
- this.channel.on("worker/exit", ({ data: t }) => {
524
- t.workerId === this.id && r(t.exitCode, t.error);
525
- });
526
- return;
527
- }
528
- }
529
- }
530
- async kill() {
531
- L(
532
- this.id,
533
- 'Failed to run "kill" on a ShellProcess: there is no process running. Did you forget to run it?'
534
- ), this.state = "idle", await this.channel.send("shell/exit", { id: this.id }).catch((e) => {
535
- throw new Error(g('Failed to kill shell with ID "%s"', this.id), { cause: e });
536
- }), this.id = void 0;
537
- }
538
- }, He = j($()), $e = 2e4, Ve = class {
539
- constructor(e) {
540
- this.channel = e;
541
- }
542
- async waitFor(e, r, t = $e) {
543
- const n = new He.DeferredPromise(), s = setTimeout(() => {
544
- n.reject();
545
- }, t), i = await this.channel.send("preview/get/info", e).catch((a) => {
546
- n.reject(
547
- new Error(
548
- g(
549
- 'Failed to look up preview information for shell ID "%s" (port: %d)',
550
- e.sourceShellId,
551
- e.port
552
- )
553
- )
554
- );
555
- }), o = i && r(i);
556
- return o && n.resolve({
557
- url: i.url,
558
- port: i.port,
559
- sourceShellId: i.sourceShellId
560
- }), this.channel.on("preview/port/ready", ({ data: a }) => {
561
- !o && r(a) && n.resolve({
562
- url: a.url,
563
- port: a.port,
564
- sourceShellId: a.sourceShellId
565
- });
566
- }), n.finally(() => {
567
- clearTimeout(s);
568
- });
569
- }
570
- async getByShellId(e, r) {
571
- return this.waitFor({ sourceShellId: e }, (t) => t.sourceShellId === e, r).catch((t) => {
572
- throw new Error(g('Failed to get shell by ID "%s"', e), { cause: t });
573
- });
574
- }
575
- async waitForPort(e, r) {
576
- return this.waitFor({ port: e }, (t) => t.port === e, r).catch((t) => {
577
- throw new Error(g("Failed to await port %d", e), { cause: t });
578
- });
579
- }
580
- }, ze = "https://nodebox-runtime.codesandbox.io", x = re("emulator"), Ge = class {
581
- constructor(e) {
582
- p(this, "channel", null);
583
- p(this, "isConnected");
584
- p(this, "url");
585
- p(this, "fileSystemApi", null);
586
- p(this, "shellApi", null);
587
- p(this, "previewApi", null);
588
- this.options = e, L(
589
- this.options.iframe,
590
- 'Failed to create a Nodebox: expected "iframe" argument to be a reference to an <iframe> element but got %j',
591
- this.options.iframe
592
- ), this.url = this.options.runtimeUrl || ze, this.isConnected = !1;
593
- }
594
- async connect() {
595
- const { iframe: e, cdnUrl: r } = this.options;
596
- x("[message-sender]: Connecting to node emulator...");
597
- const t = new J.DeferredPromise();
598
- this.url || t.reject(
599
- new Error("Nodebox URL is missing. Did you forget to provide it when creating this Nodebox instance?")
600
- ), L(
601
- e.contentWindow,
602
- "Failed to create a MessageChannel with the Nodebox iframe: no content window found"
603
- ), this.channel = new Ue(e.contentWindow);
604
- const n = new J.DeferredPromise();
605
- return e.setAttribute("src", this.url), e.addEventListener(
606
- "load",
607
- () => {
608
- n.resolve();
609
- },
610
- { once: !0 }
611
- ), e.addEventListener(
612
- "error",
613
- (s) => {
614
- n.reject(s.error);
615
- },
616
- { once: !0 }
617
- ), await n, x("[message-sender]: IFrame loaded..."), await this.channel.handshake(), x("[message-sender]: Handshake completed..."), this.channel.send("connect", {
618
- cdnUrl: r
619
- }), this.channel.on("runtime/ready", () => {
620
- t.resolve();
621
- }), t.then(() => {
622
- x("[message-sender]: Connected to runtime..."), this.isConnected = !0;
623
- });
624
- }
625
- get fs() {
626
- return L(
627
- this.isConnected,
628
- 'Failed to access the File System API: consumer is not connected. Did you forget to run "connect()"?'
629
- ), this.fileSystemApi ? this.fileSystemApi : (this.fileSystemApi = new Be(this.channel), this.fileSystemApi);
630
- }
631
- get shell() {
632
- return L(
633
- this.isConnected,
634
- 'Failed to access the Shell API: consumer is not connected. Did you forget to run "connect()"?'
635
- ), this.shellApi ? this.shellApi : (this.shellApi = new Ne(this.channel), this.shellApi);
636
- }
637
- get preview() {
638
- return L(
639
- this.isConnected,
640
- 'Failed to access the Preview API: consumer is not connected. Did you forget to run "connect()"?'
641
- ), this.previewApi ? this.previewApi : (this.previewApi = new Ve(this.channel), this.previewApi);
642
- }
643
- }, Je = "INJECT_AND_INVOKE", Ye = "PREVIEW_LOADED";
644
- function Ke(e, r) {
645
- return E(this, void 0, void 0, function() {
646
- var t, n, s, i, o;
647
- return P(this, function(a) {
648
- return t = e.contentWindow, N(t, "Failed to await preview iframe: no content window found"), n = 9e4, s = 20, i = 0, [2, new Promise(function(c, l) {
649
- var h = function() {
650
- var f = function() {
651
- clearTimeout(o), i = s, c(), e.removeEventListener("load", f);
652
- };
653
- if (i >= s) {
654
- l(K("Could not able to connect to preview."));
655
- return;
656
- }
657
- e.setAttribute("src", r), o = setTimeout(function() {
658
- h(), e.removeEventListener("load", f);
659
- }, n), i = i + 1, e.addEventListener("load", f);
660
- };
661
- e.addEventListener("error", function() {
662
- return l(new Error("Iframe error"));
663
- }), e.addEventListener("abort", function() {
664
- return l(new Error("Aborted"));
665
- }), h();
666
- })];
667
- });
668
- });
669
- }
670
- var Xe = function(e, r) {
671
- e.style.border = "0", e.style.width = r.width || "100%", e.style.height = r.height || "100%", e.style.overflow = "hidden", e.allow = "cross-origin-isolated";
672
- };
673
- function Qe(e) {
674
- var r = e.scope, t = window.history.__proto__, n = [], s = 0, i = function(c) {
675
- parent.postMessage({
676
- type: "urlchange",
677
- url: c,
678
- back: s > 0,
679
- forward: s < n.length - 1,
680
- channelId: r.channelId
681
- }, "*");
682
- };
683
- function o(c, l) {
684
- n.splice(s + 1), n.push({ url: c, state: l }), s = n.length - 1;
685
- }
686
- Object.assign(window.history, {
687
- go: function(c) {
688
- var l = s + c;
689
- if (l >= 0 && l <= n.length - 1) {
690
- s = l;
691
- var h = n[s], f = h.url, v = h.state;
692
- t.replaceState.call(window.history, v, "", f);
693
- var w = document.location.href;
694
- i(w), window.dispatchEvent(new PopStateEvent("popstate", { state: v }));
695
- }
696
- },
697
- back: function() {
698
- window.history.go(-1);
699
- },
700
- forward: function() {
701
- window.history.go(1);
702
- },
703
- pushState: function(c, l, h) {
704
- t.replaceState.call(window.history, c, l, h), o(h, c), i(document.location.href);
705
- },
706
- replaceState: function(c, l, h) {
707
- t.replaceState.call(window.history, c, l, h), n[s] = { state: c, url: h }, i(document.location.href);
708
- }
709
- });
710
- function a(c) {
711
- var l = c.data;
712
- l.type === "urlback" ? history.back() : l.type === "urlforward" ? history.forward() : l.type === "refresh" && document.location.reload();
713
- }
714
- window.addEventListener("message", a);
715
- }
716
- function Ze(e) {
717
- var r = e.scope, t = 0;
718
- function n() {
719
- if (typeof window > "u")
720
- return 0;
721
- var a = document.body, c = document.documentElement;
722
- return Math.max(a.scrollHeight, a.offsetHeight, c.offsetHeight);
723
- }
724
- function s() {
725
- var a = n();
726
- t !== a && window.parent.postMessage({
727
- type: "resize",
728
- height: a,
729
- codesandbox: !0,
730
- channelId: r.channelId
731
- }, "*"), t = a;
732
- }
733
- s();
734
- var i, o = new MutationObserver(function() {
735
- i === void 0 && (s(), i = setTimeout(function() {
736
- i = void 0;
737
- }, 300));
738
- });
739
- o.observe(document, {
740
- attributes: !0,
741
- childList: !0,
742
- subtree: !0
743
- }), setInterval(s, 300);
744
- }
745
- var et = [
746
- { code: Qe.toString(), id: "historyListener" },
747
- {
748
- code: "function consoleHook({ scope }) {" + ae + `
749
- };`,
750
- id: "consoleHook"
751
- },
752
- { code: Ze.toString(), id: "watchResize" }
753
- ], tt = function(e, r) {
754
- et.forEach(function(t) {
755
- var n, s = t.code, i = t.id, o = {
756
- uid: i,
757
- type: Je,
758
- code: "exports.activate = ".concat(s),
759
- scope: { channelId: r }
760
- };
761
- (n = e.contentWindow) === null || n === void 0 || n.postMessage(o, "*");
762
- });
763
- }, at = (
764
- /** @class */
765
- function(e) {
766
- se(r, e);
767
- function r(t, n, s) {
768
- s === void 0 && (s = {});
769
- var i = e.call(this, t, n, A(A({}, s), { bundlerURL: s.bundlerURL })) || this;
770
- return i._modulesCache = /* @__PURE__ */ new Map(), i.messageChannelId = le(), i._initPromise = null, i.emitter = new ue(), i.manageIframes(t), i.emulator = new Ge({
771
- iframe: i.emulatorIframe,
772
- runtimeUrl: i.options.bundlerURL
773
- }), i.updateSandbox(n), i;
774
- }
775
- return r.prototype._init = function(t) {
776
- return E(this, void 0, void 0, function() {
777
- return P(this, function(n) {
778
- switch (n.label) {
779
- case 0:
780
- return [4, this.emulator.connect()];
781
- case 1:
782
- return n.sent(), [4, this.emulator.fs.init(t)];
783
- case 2:
784
- return n.sent(), [4, this.globalListeners()];
785
- case 3:
786
- return n.sent(), [
787
- 2
788
- /*return*/
789
- ];
790
- }
791
- });
792
- });
793
- }, r.prototype.compile = function(t) {
794
- return E(this, void 0, void 0, function() {
795
- var n, s;
796
- return P(this, function(i) {
797
- switch (i.label) {
798
- case 0:
799
- return i.trys.push([0, 5, , 6]), this.status = "initializing", this.dispatch({ type: "start", firstLoad: !0 }), this._initPromise || (this._initPromise = this._init(t)), [4, this._initPromise];
800
- case 1:
801
- return i.sent(), this.dispatch({ type: "connected" }), [4, this.createShellProcessFromTask(t)];
802
- case 2:
803
- return n = i.sent().id, [4, this.createPreviewURLFromId(n)];
804
- case 3:
805
- return i.sent(), [4, this.setLocationURLIntoIFrame()];
806
- case 4:
807
- return i.sent(), this.dispatchDoneMessage(), [3, 6];
808
- case 5:
809
- return s = i.sent(), this.dispatch({
810
- type: "action",
811
- action: "notification",
812
- notificationType: "error",
813
- title: z(s)
814
- }), this.dispatch({ type: "done", compilatonError: !0 }), [3, 6];
815
- case 6:
816
- return [
817
- 2
818
- /*return*/
819
- ];
820
- }
821
- });
822
- });
823
- }, r.prototype.createShellProcessFromTask = function(t) {
824
- return E(this, void 0, void 0, function() {
825
- var n, s, i = this;
826
- return P(this, function(o) {
827
- switch (o.label) {
828
- case 0:
829
- return n = U(t["/package.json"]), this.emulatorCommand = ce(n), this.emulatorShellProcess = this.emulator.shell.create(), [4, this.emulatorShellProcess.on("exit", function(a) {
830
- i.dispatch({
831
- type: "action",
832
- action: "notification",
833
- notificationType: "error",
834
- title: K("Error: process.exit(".concat(a, ") called."))
835
- });
836
- })];
837
- case 1:
838
- return o.sent(), [4, this.emulatorShellProcess.on("progress", function(a) {
839
- var c, l;
840
- if (a.state === "command_running" || a.state === "starting_command") {
841
- i.dispatch({
842
- type: "shell/progress",
843
- data: A(A({}, a), { command: [
844
- (c = i.emulatorCommand) === null || c === void 0 ? void 0 : c[0],
845
- (l = i.emulatorCommand) === null || l === void 0 ? void 0 : l[1].join(" ")
846
- ].join(" ") })
847
- }), i.status = "installing-dependencies";
848
- return;
849
- }
850
- i.dispatch({ type: "shell/progress", data: a });
851
- })];
852
- case 2:
853
- return o.sent(), this.emulatorShellProcess.stdout.on("data", function(a) {
854
- i.dispatch({ type: "stdout", payload: { data: a, type: "out" } });
855
- }), this.emulatorShellProcess.stderr.on("data", function(a) {
856
- i.dispatch({ type: "stdout", payload: { data: a, type: "err" } });
857
- }), [4, (s = this.emulatorShellProcess).runCommand.apply(s, this.emulatorCommand)];
858
- case 3:
859
- return [2, o.sent()];
860
- }
861
- });
862
- });
863
- }, r.prototype.createPreviewURLFromId = function(t) {
864
- var n;
865
- return E(this, void 0, void 0, function() {
866
- var s;
867
- return P(this, function(i) {
868
- switch (i.label) {
869
- case 0:
870
- return this.iframePreviewUrl = void 0, [4, this.emulator.preview.getByShellId(t)];
871
- case 1:
872
- return s = i.sent().url, this.iframePreviewUrl = s + ((n = this.options.startRoute) !== null && n !== void 0 ? n : ""), [
873
- 2
874
- /*return*/
875
- ];
876
- }
877
- });
878
- });
879
- }, r.prototype.manageIframes = function(t) {
880
- var n;
881
- if (typeof t == "string") {
882
- var s = document.querySelector(t);
883
- N(s, "The element '".concat(t, "' was not found")), this.iframe = document.createElement("iframe"), s == null || s.appendChild(this.iframe);
884
- } else
885
- this.iframe = t;
886
- Xe(this.iframe, this.options), N(this.iframe.parentNode, "The given iframe does not have a parent."), this.emulatorIframe = document.createElement("iframe"), this.emulatorIframe.classList.add("sp-bridge-frame"), (n = this.iframe.parentNode) === null || n === void 0 || n.appendChild(this.emulatorIframe);
887
- }, r.prototype.setLocationURLIntoIFrame = function() {
888
- return E(this, void 0, void 0, function() {
889
- return P(this, function(t) {
890
- switch (t.label) {
891
- case 0:
892
- return this.iframePreviewUrl ? [4, Ke(this.iframe, this.iframePreviewUrl)] : [3, 2];
893
- case 1:
894
- t.sent(), t.label = 2;
895
- case 2:
896
- return [
897
- 2
898
- /*return*/
899
- ];
900
- }
901
- });
902
- });
903
- }, r.prototype.dispatchDoneMessage = function() {
904
- this.status = "done", this.dispatch({ type: "done", compilatonError: !1 }), this.iframePreviewUrl && this.dispatch({
905
- type: "urlchange",
906
- url: this.iframePreviewUrl,
907
- back: !1,
908
- forward: !1
909
- });
910
- }, r.prototype.globalListeners = function() {
911
- return E(this, void 0, void 0, function() {
912
- var t = this;
913
- return P(this, function(n) {
914
- switch (n.label) {
915
- case 0:
916
- return window.addEventListener("message", function(s) {
917
- s.data.type === Ye && tt(t.iframe, t.messageChannelId), s.data.type === "urlchange" && s.data.channelId === t.messageChannelId ? t.dispatch({
918
- type: "urlchange",
919
- url: s.data.url,
920
- back: s.data.back,
921
- forward: s.data.forward
922
- }) : s.data.channelId === t.messageChannelId && t.dispatch(s.data);
923
- }), [4, this.emulator.fs.watch(["*"], [
924
- ".next",
925
- "node_modules",
926
- "build",
927
- "dist",
928
- "vendor",
929
- ".config",
930
- ".vuepress"
931
- ], function(s) {
932
- return E(t, void 0, void 0, function() {
933
- var i, o, a, c, l, h, f;
934
- return P(this, function(v) {
935
- switch (v.label) {
936
- case 0:
937
- return s ? (i = s, o = "newPath" in i ? i.newPath : "path" in i ? i.path : "", [4, this.emulator.fs.stat(o)]) : [
938
- 2
939
- /*return*/
940
- ];
941
- case 1:
942
- if (a = v.sent().type, a !== "file")
943
- return [2, null];
944
- v.label = 2;
945
- case 2:
946
- switch (v.trys.push([2, 10, , 11]), c = i.type, c) {
947
- case "change":
948
- return [3, 3];
949
- case "create":
950
- return [3, 3];
951
- case "remove":
952
- return [3, 5];
953
- case "rename":
954
- return [3, 6];
955
- case "close":
956
- return [3, 8];
957
- }
958
- return [3, 9];
959
- case 3:
960
- return [4, this.emulator.fs.readFile(i.path, "utf8")];
961
- case 4:
962
- return l = v.sent(), this.dispatch({
963
- type: "fs/change",
964
- path: i.path,
965
- content: l
966
- }), this._modulesCache.set(i.path, W(l)), [3, 9];
967
- case 5:
968
- return this.dispatch({
969
- type: "fs/remove",
970
- path: i.path
971
- }), this._modulesCache.delete(i.path), [3, 9];
972
- case 6:
973
- return this.dispatch({
974
- type: "fs/remove",
975
- path: i.oldPath
976
- }), this._modulesCache.delete(i.oldPath), [4, this.emulator.fs.readFile(i.newPath, "utf8")];
977
- case 7:
978
- return h = v.sent(), this.dispatch({
979
- type: "fs/change",
980
- path: i.newPath,
981
- content: h
982
- }), this._modulesCache.set(i.newPath, W(h)), [3, 9];
983
- case 8:
984
- return [3, 9];
985
- case 9:
986
- return [3, 11];
987
- case 10:
988
- return f = v.sent(), this.dispatch({
989
- type: "action",
990
- action: "notification",
991
- notificationType: "error",
992
- title: z(f)
993
- }), [3, 11];
994
- case 11:
995
- return [
996
- 2
997
- /*return*/
998
- ];
999
- }
1000
- });
1001
- });
1002
- })];
1003
- case 1:
1004
- return n.sent(), [
1005
- 2
1006
- /*return*/
1007
- ];
1008
- }
1009
- });
1010
- });
1011
- }, r.prototype.restartShellProcess = function() {
1012
- var t;
1013
- return E(this, void 0, void 0, function() {
1014
- return P(this, function(n) {
1015
- switch (n.label) {
1016
- case 0:
1017
- return this.emulatorShellProcess && this.emulatorCommand ? (this.dispatch({ type: "start", firstLoad: !0 }), this.status = "initializing", [4, this.emulatorShellProcess.kill()]) : [3, 3];
1018
- case 1:
1019
- return n.sent(), (t = this.iframe) === null || t === void 0 || t.removeAttribute("attr"), this.emulator.fs.rm("/node_modules/.vite", {
1020
- recursive: !0,
1021
- force: !0
1022
- }), [4, this.compile(Object.fromEntries(this._modulesCache))];
1023
- case 2:
1024
- n.sent(), n.label = 3;
1025
- case 3:
1026
- return [
1027
- 2
1028
- /*return*/
1029
- ];
1030
- }
1031
- });
1032
- });
1033
- }, r.prototype.updateSandbox = function(t) {
1034
- var n = this, s, i = de(t.files);
1035
- if (((s = this.emulatorShellProcess) === null || s === void 0 ? void 0 : s.state) === "running") {
1036
- Object.entries(i).forEach(function(o) {
1037
- var a = o[0], c = o[1];
1038
- (!n._modulesCache.get(a) || U(c) !== U(n._modulesCache.get(a))) && n.emulator.fs.writeFile(a, c, { recursive: !0 });
1039
- });
1040
- return;
1041
- }
1042
- this.dispatch({
1043
- codesandbox: !0,
1044
- modules: i,
1045
- template: t.template,
1046
- type: "compile"
1047
- }), Object.entries(i).forEach(function(o) {
1048
- var a = o[0], c = o[1];
1049
- n._modulesCache.set(a, W(c));
1050
- });
1051
- }, r.prototype.dispatch = function(t) {
1052
- var n, s;
1053
- return E(this, void 0, void 0, function() {
1054
- var i;
1055
- return P(this, function(o) {
1056
- switch (o.label) {
1057
- case 0:
1058
- switch (i = t.type, i) {
1059
- case "compile":
1060
- return [3, 1];
1061
- case "refresh":
1062
- return [3, 2];
1063
- case "urlback":
1064
- return [3, 4];
1065
- case "urlforward":
1066
- return [3, 4];
1067
- case "shell/restart":
1068
- return [3, 5];
1069
- case "shell/openPreview":
1070
- return [3, 6];
1071
- }
1072
- return [3, 7];
1073
- case 1:
1074
- return this.compile(t.modules), [3, 8];
1075
- case 2:
1076
- return [4, this.setLocationURLIntoIFrame()];
1077
- case 3:
1078
- return o.sent(), [3, 8];
1079
- case 4:
1080
- return (s = (n = this.iframe) === null || n === void 0 ? void 0 : n.contentWindow) === null || s === void 0 || s.postMessage(t, "*"), [3, 8];
1081
- case 5:
1082
- return this.restartShellProcess(), [3, 8];
1083
- case 6:
1084
- return window.open(this.iframePreviewUrl, "_blank"), [3, 8];
1085
- case 7:
1086
- this.emitter.dispatch(t), o.label = 8;
1087
- case 8:
1088
- return [
1089
- 2
1090
- /*return*/
1091
- ];
1092
- }
1093
- });
1094
- });
1095
- }, r.prototype.listen = function(t) {
1096
- return this.emitter.listener(t);
1097
- }, r.prototype.destroy = function() {
1098
- this.emulatorIframe.remove(), this.emitter.cleanup();
1099
- }, r;
1100
- }(oe)
1101
- );
1102
- export {
1103
- at as SandpackNode
1104
- };