@codespark/react 1.0.2 → 1.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/index.js +5 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -57,16 +57,6 @@ function useLatest(value) {
|
|
|
57
57
|
ref.current = value;
|
|
58
58
|
return ref;
|
|
59
59
|
}
|
|
60
|
-
function useUpdateEffect(effect, deps) {
|
|
61
|
-
const mounted = useRef(false);
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
if (!mounted.current) {
|
|
64
|
-
mounted.current = true;
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
return effect();
|
|
68
|
-
}, deps);
|
|
69
|
-
}
|
|
70
60
|
function getLanguageFromFile(name) {
|
|
71
61
|
const ext = name.split(".").pop()?.toLowerCase();
|
|
72
62
|
return ext ? {
|
|
@@ -1317,8 +1307,6 @@ var PreviewProxy = class {
|
|
|
1317
1307
|
script.type = "importmap";
|
|
1318
1308
|
script.textContent = JSON.stringify({ imports: imports || {} });
|
|
1319
1309
|
doc.head.insertBefore(script, doc.head.firstChild);
|
|
1320
|
-
console.log(doc.querySelector("html").outerHTML);
|
|
1321
|
-
this.iframe.src = URL.createObjectURL(new Blob([doc.querySelector("html").outerHTML], { type: "text/html" }));
|
|
1322
1310
|
}
|
|
1323
1311
|
};
|
|
1324
1312
|
function usePreview(options) {
|
|
@@ -1327,7 +1315,6 @@ function usePreview(options) {
|
|
|
1327
1315
|
const proxyRef = useRef(void 0);
|
|
1328
1316
|
const iframeRef = useRef(null);
|
|
1329
1317
|
const readyRef = useRef(Promise.withResolvers());
|
|
1330
|
-
const isFirst = useRef(true);
|
|
1331
1318
|
const preview = async (...code) => {
|
|
1332
1319
|
try {
|
|
1333
1320
|
setRunning(true);
|
|
@@ -1335,23 +1322,13 @@ function usePreview(options) {
|
|
|
1335
1322
|
await proxyRef.current?.eval(code);
|
|
1336
1323
|
} catch (error) {
|
|
1337
1324
|
onError?.(error);
|
|
1338
|
-
} finally {
|
|
1339
|
-
isFirst.current = false;
|
|
1340
1325
|
}
|
|
1341
1326
|
};
|
|
1342
|
-
useUpdateEffect(() => {
|
|
1343
|
-
if (isFirst.current) return;
|
|
1344
|
-
readyRef.current.promise.then(() => {
|
|
1345
|
-
proxyRef.current?.setImportMap(imports);
|
|
1346
|
-
});
|
|
1347
|
-
}, [JSON.stringify(imports)]);
|
|
1348
1327
|
useEffect(() => {
|
|
1349
1328
|
if (iframeRef.current) {
|
|
1350
1329
|
const proxy = new PreviewProxy({
|
|
1351
1330
|
root: iframeRef.current,
|
|
1352
1331
|
defaultTheme: theme,
|
|
1353
|
-
defaultImports: imports,
|
|
1354
|
-
defaultPresets: presets,
|
|
1355
1332
|
handlers: {
|
|
1356
1333
|
on_console: onConsole,
|
|
1357
1334
|
on_fetch_progress: onFetchProgress,
|
|
@@ -1385,6 +1362,11 @@ function usePreview(options) {
|
|
|
1385
1362
|
proxyRef.current?.injectTags(presets);
|
|
1386
1363
|
});
|
|
1387
1364
|
}, [presets?.join("\n")]);
|
|
1365
|
+
useEffect(() => {
|
|
1366
|
+
readyRef.current.promise.then(() => {
|
|
1367
|
+
proxyRef.current?.setImportMap(imports);
|
|
1368
|
+
});
|
|
1369
|
+
}, [JSON.stringify(imports)]);
|
|
1388
1370
|
return {
|
|
1389
1371
|
iframeRef,
|
|
1390
1372
|
proxyRef,
|