@superblocksteam/library 2.0.69 → 2.0.70-next.1
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/{devtools-consolidated-CfCo1nXs.js → devtools-consolidated-zKLoNTKB.js} +2 -2
- package/dist/{devtools-consolidated-CfCo1nXs.js.map → devtools-consolidated-zKLoNTKB.js.map} +1 -1
- package/dist/{early-console-buffer-T4skeGWJ.js → early-console-buffer-D4wVuyBf.js} +5 -5
- package/dist/early-console-buffer-D4wVuyBf.js.map +1 -0
- package/dist/jsx-dev-runtime/index.js +1 -1
- package/dist/{jsx-wrapper-CuenCDCW.js → jsx-wrapper-DrDoDS8j.js} +185 -26
- package/dist/jsx-wrapper-DrDoDS8j.js.map +1 -0
- package/dist/lib/index.d.ts +30 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +343 -66
- package/dist/lib/index.js.map +1 -1
- package/dist/{logs-VIMbIbT8.js → logs-hyzhDMp7.js} +2 -2
- package/dist/{logs-VIMbIbT8.js.map → logs-hyzhDMp7.js.map} +1 -1
- package/package.json +5 -4
- package/dist/early-console-buffer-T4skeGWJ.js.map +0 -1
- package/dist/jsx-wrapper-CuenCDCW.js.map +0 -1
package/dist/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as consoleLogAttributes, t as early_console_buffer_default } from "../early-console-buffer-
|
|
2
|
-
import { A as
|
|
1
|
+
import { n as consoleLogAttributes, t as early_console_buffer_default } from "../early-console-buffer-D4wVuyBf.js";
|
|
2
|
+
import { A as useSuperblocksProfiles, B as PropsCategory, C as apiActivityTracker, D as getAppMode, E as SuperblocksContextProvider, F as iframeMessageHandler, H as createPropertiesPanelDefinition, I as isEmbeddedBySuperblocksFirstParty, L as isEditMode, M as sendNotification, N as colors$1, O as useSuperblocksContext, P as editorBridge, R as createManagedPropsList, S as api_hmr_tracker_default, T as resolveById, U as getEditStore, V as Section, _ as root_store_default, a as FixWithClarkButton, b as createIframeSpan, c as ErrorContent, d as ErrorMessage, f as ErrorStack, g as StyledClarkIcon, h as SecondaryButton, i as getWidgetRectAnchorName, j as useSuperblocksUser, k as useSuperblocksGroups, l as ErrorDetails, m as ErrorTitle, n as useJSXContext, o as ActionsContainer, p as ErrorSummary, r as getWidgetAnchorName, s as ErrorContainer, u as ErrorIconContainer, v as startEditorSync, w as rejectById, x as getContextFromTraceHeaders, y as generateId, z as Prop } from "../jsx-wrapper-DrDoDS8j.js";
|
|
3
3
|
import { n as initTracerProviderWithOrigin } from "../utils-Clb3lSiX.js";
|
|
4
4
|
import { action, autorun, computed, makeAutoObservable, makeObservable, observable, reaction, when } from "mobx";
|
|
5
5
|
import { Dim, NATIVE_COMPONENT_TYPES, NO_SELECT_ATTRIBUTE, Property, Property as Property$1, SELECTOR_ID_ATTRIBUTE, SOURCE_ID_ATTRIBUTE, generateSourceId, getBindingIdentifier } from "@superblocksteam/library-shared";
|
|
@@ -776,6 +776,31 @@ function registerHtmlElements() {
|
|
|
776
776
|
registerComponent("meta", htmlTagSectionsTemplate({ hasChildren: false }));
|
|
777
777
|
}
|
|
778
778
|
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/lib/internal-details/handle-bootstrap-response.ts
|
|
781
|
+
const handleBootstrapResponse = (event) => {
|
|
782
|
+
root_store_default.applicationId = event.data.payload.appId;
|
|
783
|
+
root_store_default.userId = event.data.payload.userId;
|
|
784
|
+
root_store_default.apis.agentUrls = event.data.payload.agentUrls ?? (event.data.payload.agentUrl ? [event.data.payload.agentUrl] : []);
|
|
785
|
+
root_store_default.apis.setTokens(event.data.payload.token, event.data.payload.accessToken);
|
|
786
|
+
root_store_default.apis.notifyBootstrapComplete();
|
|
787
|
+
root_store_default.windowOriginUrl = event.data.payload.logContext.superblocks_window_origin_url;
|
|
788
|
+
if (root_store_default.windowOriginUrl) import("../utils-BmTdixWt.js").then(({ initTracerProviderWithOrigin: initTracerProviderWithOrigin$1 }) => {
|
|
789
|
+
initTracerProviderWithOrigin$1(root_store_default.windowOriginUrl);
|
|
790
|
+
import("../logs-hyzhDMp7.js").then(({ initLibraryLoggerProvider }) => {
|
|
791
|
+
initLibraryLoggerProvider({
|
|
792
|
+
windowOriginUrl: root_store_default.windowOriginUrl,
|
|
793
|
+
appId: event.data.payload.appId,
|
|
794
|
+
userId: event.data.payload.logContext.superblocks_user_id,
|
|
795
|
+
userEmail: event.data.payload.logContext.superblocks_user_email,
|
|
796
|
+
orgId: event.data.payload.logContext.superblocks_org_id,
|
|
797
|
+
orgName: event.data.payload.logContext.superblocks_org_name,
|
|
798
|
+
environment: event.data.payload.logContext.superblocks_env
|
|
799
|
+
});
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
|
|
779
804
|
//#endregion
|
|
780
805
|
//#region src/lib/internal-details/internal-components/spinner.tsx
|
|
781
806
|
const Spinner = styled.span`
|
|
@@ -1406,8 +1431,8 @@ var OperationAPI = class {
|
|
|
1406
1431
|
updateAuthorization(newAuthorization) {
|
|
1407
1432
|
if (this.isocket) {
|
|
1408
1433
|
this.isocket.setAuthorization(newAuthorization);
|
|
1409
|
-
console.log("Updated iframe socket authorization token");
|
|
1410
|
-
} else console.warn("Cannot update authorization: socket not yet initialized");
|
|
1434
|
+
console.log("[internal] [OperationAPI] Updated iframe socket authorization token");
|
|
1435
|
+
} else console.warn("[internal] [OperationAPI] Cannot update authorization: socket not yet initialized");
|
|
1411
1436
|
}
|
|
1412
1437
|
handleSocketClose({ peerId, userId, authorization, applicationId }) {
|
|
1413
1438
|
return async (event) => {
|
|
@@ -1421,7 +1446,7 @@ var OperationAPI = class {
|
|
|
1421
1446
|
root_store_default.editStore?.connectionManager.disconnect();
|
|
1422
1447
|
return;
|
|
1423
1448
|
}
|
|
1424
|
-
console.info(`App<>Dev box Socket closed, retrying attempt ${this.retryAttempts + 1}...`);
|
|
1449
|
+
console.info(`[internal] [OperationAPI] App<>Dev box Socket closed, retrying attempt ${this.retryAttempts + 1}...`);
|
|
1425
1450
|
root_store_default.editStore?.connectionManager.disconnect();
|
|
1426
1451
|
await this.retryConnection({
|
|
1427
1452
|
peerId,
|
|
@@ -1441,7 +1466,7 @@ var OperationAPI = class {
|
|
|
1441
1466
|
applicationId
|
|
1442
1467
|
});
|
|
1443
1468
|
else {
|
|
1444
|
-
console.info(`App<>Dev box Socket closed, failed to reconnect after 3 attempts. Throwing error.`);
|
|
1469
|
+
console.info(`[internal] [OperationAPI] App<>Dev box Socket closed, failed to reconnect after 3 attempts. Throwing error.`);
|
|
1445
1470
|
throw new Error("Failed to reconnect after 3 attempts");
|
|
1446
1471
|
}
|
|
1447
1472
|
}
|
|
@@ -1456,9 +1481,9 @@ function startSocketHeartbeat(socket) {
|
|
|
1456
1481
|
timeoutId = setTimeout(async () => {
|
|
1457
1482
|
try {
|
|
1458
1483
|
await socket.call.editor.ping();
|
|
1459
|
-
console.debug("Pinged library socket");
|
|
1484
|
+
console.debug("[internal] [OperationAPI] Pinged library socket");
|
|
1460
1485
|
} catch (e) {
|
|
1461
|
-
console.warn("Ping library socket error", e);
|
|
1486
|
+
console.warn("[internal] [OperationAPI] Ping library socket error", e);
|
|
1462
1487
|
}
|
|
1463
1488
|
loop();
|
|
1464
1489
|
}, PING_INTERVAL_MS);
|
|
@@ -1485,7 +1510,7 @@ async function connectSocket(serverUrl, { peerId, userId, applicationId, authori
|
|
|
1485
1510
|
application_id: applicationId
|
|
1486
1511
|
}, parentContext);
|
|
1487
1512
|
const wsStartTime = Date.now();
|
|
1488
|
-
console.log("Dev server connection app websocket starting", consoleLogAttributes({
|
|
1513
|
+
console.log("[internal] [OperationAPI] Dev server connection app websocket starting", consoleLogAttributes({
|
|
1489
1514
|
url: wsUrl.toString(),
|
|
1490
1515
|
connectionSource: "app",
|
|
1491
1516
|
connectionType: connectionType || "initial",
|
|
@@ -1527,7 +1552,7 @@ async function connectSocket(serverUrl, { peerId, userId, applicationId, authori
|
|
|
1527
1552
|
stopSocketHeartbeat?.();
|
|
1528
1553
|
stopSocketHeartbeat = void 0;
|
|
1529
1554
|
onClose(event);
|
|
1530
|
-
console.log("Dev server connection app websocket closed", consoleLogAttributes({
|
|
1555
|
+
console.log("[internal] [OperationAPI] Dev server connection app websocket closed", consoleLogAttributes({
|
|
1531
1556
|
connectionSource: "app",
|
|
1532
1557
|
connectionType: connectionType || "initial",
|
|
1533
1558
|
connectionTarget: connectionTarget || "default"
|
|
@@ -1541,7 +1566,7 @@ async function connectSocket(serverUrl, { peerId, userId, applicationId, authori
|
|
|
1541
1566
|
});
|
|
1542
1567
|
const socket = createISocketClient(isocket);
|
|
1543
1568
|
const wsDuration = Date.now() - wsStartTime;
|
|
1544
|
-
console.log("Dev server connection app websocket succeeded", consoleLogAttributes({
|
|
1569
|
+
console.log("[internal] [OperationAPI] Dev server connection app websocket succeeded", consoleLogAttributes({
|
|
1545
1570
|
connectionSource: "app",
|
|
1546
1571
|
connectionType: connectionType || "initial",
|
|
1547
1572
|
connectionTarget: connectionTarget || "default",
|
|
@@ -1563,7 +1588,7 @@ async function connectSocket(serverUrl, { peerId, userId, applicationId, authori
|
|
|
1563
1588
|
};
|
|
1564
1589
|
} catch (error) {
|
|
1565
1590
|
const wsDuration = Date.now() - wsStartTime;
|
|
1566
|
-
console.error("Dev server connection app websocket failed", consoleLogAttributes({
|
|
1591
|
+
console.error("[internal] [OperationAPI] Dev server connection app websocket failed", consoleLogAttributes({
|
|
1567
1592
|
connectionSource: "app",
|
|
1568
1593
|
connectionType: connectionType || "initial",
|
|
1569
1594
|
connectionTarget: connectionTarget || "default",
|
|
@@ -1854,10 +1879,10 @@ var PropertiesPanelManager = class {
|
|
|
1854
1879
|
this.propertiesDefinitions.set(widgetType, propertiesDefinition$1);
|
|
1855
1880
|
}
|
|
1856
1881
|
updatePropertiesDefinitionForType(type) {
|
|
1857
|
-
console.log("[NOOP] updatePropertiesDefinitionForType: ", type);
|
|
1882
|
+
console.log("[internal] [NOOP] updatePropertiesDefinitionForType: ", type);
|
|
1858
1883
|
}
|
|
1859
1884
|
computeAndApplySideEffectsForPropertyUpdate(payload) {
|
|
1860
|
-
console.log("[NOOP] computeAndApplySideEffectsForPropertyUpdate");
|
|
1885
|
+
console.log("[internal] [NOOP] computeAndApplySideEffectsForPropertyUpdate");
|
|
1861
1886
|
return { [payload.sourceId]: payload.updates };
|
|
1862
1887
|
}
|
|
1863
1888
|
/**
|
|
@@ -2583,18 +2608,34 @@ function useEditorHotkeys(keys, callback, options, deps) {
|
|
|
2583
2608
|
//#region src/lib/hooks/use-key-pressed.ts
|
|
2584
2609
|
function useKeyPressed(key, callback, options) {
|
|
2585
2610
|
const timeoutRef = useRef(null);
|
|
2611
|
+
const isKeyDownRef = useRef(false);
|
|
2586
2612
|
useEffect(() => {
|
|
2587
2613
|
const handleKeyDown = (e) => {
|
|
2588
2614
|
if (e.key === key && !e.repeat) {
|
|
2589
|
-
if ((e.ctrlKey && key.toLowerCase() !== "ctrl" || e.metaKey && key.toLowerCase() !== "meta" || e.altKey && key.toLowerCase() !== "alt" || e.shiftKey && key.toLowerCase() !== "shift") && !options?.allowMultipleKeys)
|
|
2615
|
+
if ((e.ctrlKey && key.toLowerCase() !== "ctrl" || e.metaKey && key.toLowerCase() !== "meta" || e.altKey && key.toLowerCase() !== "alt" || e.shiftKey && key.toLowerCase() !== "shift") && !options?.allowMultipleKeys) {
|
|
2616
|
+
if (timeoutRef.current) {
|
|
2617
|
+
clearTimeout(timeoutRef.current);
|
|
2618
|
+
timeoutRef.current = null;
|
|
2619
|
+
}
|
|
2620
|
+
isKeyDownRef.current = false;
|
|
2621
|
+
callback(false);
|
|
2622
|
+
return;
|
|
2623
|
+
}
|
|
2624
|
+
isKeyDownRef.current = true;
|
|
2590
2625
|
if (options?.pressDelay && options.pressDelay > 0) {
|
|
2591
2626
|
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
2592
2627
|
timeoutRef.current = setTimeout(() => {
|
|
2593
2628
|
callback(true);
|
|
2594
2629
|
}, options.pressDelay);
|
|
2595
2630
|
} else callback(true);
|
|
2631
|
+
} else if (e.key !== key && isKeyDownRef.current && options?.allowMultipleKeys === false) {
|
|
2632
|
+
if (timeoutRef.current) {
|
|
2633
|
+
clearTimeout(timeoutRef.current);
|
|
2634
|
+
timeoutRef.current = null;
|
|
2635
|
+
}
|
|
2636
|
+
callback(false);
|
|
2637
|
+
isKeyDownRef.current = false;
|
|
2596
2638
|
}
|
|
2597
|
-
if (e.key !== key && options?.allowMultipleKeys === false) callback(false);
|
|
2598
2639
|
};
|
|
2599
2640
|
const handleKeyUp = (e) => {
|
|
2600
2641
|
if (e.key === key) {
|
|
@@ -2602,13 +2643,18 @@ function useKeyPressed(key, callback, options) {
|
|
|
2602
2643
|
clearTimeout(timeoutRef.current);
|
|
2603
2644
|
timeoutRef.current = null;
|
|
2604
2645
|
}
|
|
2646
|
+
isKeyDownRef.current = false;
|
|
2605
2647
|
callback(false);
|
|
2606
2648
|
}
|
|
2607
2649
|
};
|
|
2608
2650
|
const handleVisibilityChange = () => {
|
|
2609
|
-
if (document.hidden)
|
|
2651
|
+
if (document.hidden) {
|
|
2652
|
+
isKeyDownRef.current = false;
|
|
2653
|
+
callback(false);
|
|
2654
|
+
}
|
|
2610
2655
|
};
|
|
2611
2656
|
const handleBlur = () => {
|
|
2657
|
+
isKeyDownRef.current = false;
|
|
2612
2658
|
callback(false);
|
|
2613
2659
|
};
|
|
2614
2660
|
document.addEventListener("keydown", handleKeyDown);
|
|
@@ -3111,10 +3157,75 @@ function EditorHotkeys({ children }) {
|
|
|
3111
3157
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
3112
3158
|
}
|
|
3113
3159
|
|
|
3160
|
+
//#endregion
|
|
3161
|
+
//#region src/edit-mode/screenshot-handler.ts
|
|
3162
|
+
/** Timeout for waiting for APIs to become idle before capturing screenshot */
|
|
3163
|
+
const WAIT_FOR_APIS_TIMEOUT_MS = 1e4;
|
|
3164
|
+
/**
|
|
3165
|
+
* Handles screenshot capture requests from the parent editor.
|
|
3166
|
+
* Only available in edit mode - modern-screenshot is not bundled in deployed apps.
|
|
3167
|
+
*/
|
|
3168
|
+
function initializeScreenshotHandler() {
|
|
3169
|
+
if (!isEditMode()) return;
|
|
3170
|
+
const handleCaptureScreenshot = async ({ data }) => {
|
|
3171
|
+
const { callbackId, captureLoadingState } = data.payload;
|
|
3172
|
+
try {
|
|
3173
|
+
if (captureLoadingState) console.log("[Library Screenshot Handler] captureLoadingState=true, skipping API wait and capturing immediately...");
|
|
3174
|
+
else {
|
|
3175
|
+
console.log("[Library Screenshot Handler] Screenshot capture requested, waiting for APIs to become idle...");
|
|
3176
|
+
const { timedOut } = await apiActivityTracker.waitForIdle(WAIT_FOR_APIS_TIMEOUT_MS);
|
|
3177
|
+
if (timedOut) console.warn("[Library Screenshot Handler] Proceeding with screenshot capture despite pending API requests (skipping extra delay)");
|
|
3178
|
+
else {
|
|
3179
|
+
console.log("[Library Screenshot Handler] APIs are idle, waiting 1s for UI to settle...");
|
|
3180
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
3181
|
+
console.log("[Library Screenshot Handler] 1s delay complete, proceeding with screenshot capture");
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
const { domToWebp } = await import("modern-screenshot");
|
|
3185
|
+
console.log("[Library Screenshot Handler] Capturing screenshot now...");
|
|
3186
|
+
const rootElement = document.getElementById("root");
|
|
3187
|
+
if (!rootElement) throw new Error("Root element not found");
|
|
3188
|
+
const dataUrl = await domToWebp(rootElement, { backgroundColor: "#ffffff" });
|
|
3189
|
+
console.log("[Library Screenshot Handler] Screenshot captured successfully");
|
|
3190
|
+
editorBridge.sendCaptureScreenshotResponse(callbackId, dataUrl);
|
|
3191
|
+
} catch (error) {
|
|
3192
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3193
|
+
console.error("[Library Screenshot Handler] Error capturing screenshot:", errorMessage, error);
|
|
3194
|
+
editorBridge.sendCaptureScreenshotResponse(callbackId, void 0, errorMessage);
|
|
3195
|
+
}
|
|
3196
|
+
};
|
|
3197
|
+
iframeMessageHandler.addEventListener("capture-screenshot", handleCaptureScreenshot);
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3114
3200
|
//#endregion
|
|
3115
3201
|
//#region src/edit-mode/iframe-wrappers.tsx
|
|
3116
|
-
|
|
3117
|
-
|
|
3202
|
+
let _setReloadKey;
|
|
3203
|
+
/**
|
|
3204
|
+
* Triggers an HMR-style reload by incrementing the reload key.
|
|
3205
|
+
* This causes React to remount all children without a full page reload.
|
|
3206
|
+
* @param sendReadyAfter - If true, sends sb-ready after the remount completes
|
|
3207
|
+
*/
|
|
3208
|
+
function triggerHmrReload(sendReadyAfter = false) {
|
|
3209
|
+
api_hmr_tracker_default.dontSkipUntilNextReload();
|
|
3210
|
+
_setReloadKey((currentKey) => currentKey + 1);
|
|
3211
|
+
if (sendReadyAfter) requestAnimationFrame(() => {
|
|
3212
|
+
requestAnimationFrame(() => {
|
|
3213
|
+
editorBridge.sendReady();
|
|
3214
|
+
});
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3217
|
+
if (import.meta.hot) {
|
|
3218
|
+
import.meta.hot.on("sb:force-remount-after-reload", () => {
|
|
3219
|
+
api_hmr_tracker_default.dontSkipUntilNextReload();
|
|
3220
|
+
_setReloadKey?.((currentKey) => currentKey + 1);
|
|
3221
|
+
});
|
|
3222
|
+
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
3223
|
+
if (!isEmbeddedBySuperblocksFirstParty()) return;
|
|
3224
|
+
editorBridge.sendAppFrameWillReload();
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
if (isEditMode()) {
|
|
3228
|
+
const setupInitializer = () => {
|
|
3118
3229
|
if (!isEmbeddedBySuperblocksFirstParty()) return;
|
|
3119
3230
|
const handleInit = async ({ data }) => {
|
|
3120
3231
|
if (data.payload.windowOriginUrl) initTracerProviderWithOrigin(data.payload.windowOriginUrl);
|
|
@@ -3123,6 +3234,7 @@ const IframeConnected = observer(function IframeConnected$1(props) {
|
|
|
3123
3234
|
editorBridge.connected();
|
|
3124
3235
|
root_store_default.setEditStore(editStore);
|
|
3125
3236
|
root_store_default.notifyEditorRegistered();
|
|
3237
|
+
initializeScreenshotHandler();
|
|
3126
3238
|
const { aiState, interactionMode } = data.payload;
|
|
3127
3239
|
if (aiState?.generationState && (aiState.generationState === AiGenerationState.GENERATING || aiState.generationState === AiGenerationState.DEBUGGING)) {
|
|
3128
3240
|
editStore.ai.startEditing();
|
|
@@ -3157,11 +3269,14 @@ const IframeConnected = observer(function IframeConnected$1(props) {
|
|
|
3157
3269
|
};
|
|
3158
3270
|
iframeMessageHandler.addEventListener("sb-init", handleInit);
|
|
3159
3271
|
iframeMessageHandler.addEventListener("sb-update-token", handleTokenUpdate);
|
|
3272
|
+
};
|
|
3273
|
+
requestIdleCallback(setupInitializer);
|
|
3274
|
+
}
|
|
3275
|
+
const IframeConnected = observer(function IframeConnected$1(props) {
|
|
3276
|
+
const [reloadKey, setReloadKey] = useState(0);
|
|
3277
|
+
_setReloadKey = setReloadKey;
|
|
3278
|
+
useEffect(() => {
|
|
3160
3279
|
editorBridge.sendReady();
|
|
3161
|
-
return () => {
|
|
3162
|
-
iframeMessageHandler.removeEventListener("sb-init", handleInit);
|
|
3163
|
-
iframeMessageHandler.removeEventListener("sb-update-token", handleTokenUpdate);
|
|
3164
|
-
};
|
|
3165
3280
|
}, []);
|
|
3166
3281
|
useEffect(() => {
|
|
3167
3282
|
const handleDragStart = () => {};
|
|
@@ -3170,15 +3285,171 @@ const IframeConnected = observer(function IframeConnected$1(props) {
|
|
|
3170
3285
|
iframeMessageHandler.removeEventListener("dragstart", handleDragStart);
|
|
3171
3286
|
};
|
|
3172
3287
|
}, []);
|
|
3288
|
+
useEffect(() => {
|
|
3289
|
+
if (!isEmbeddedBySuperblocksFirstParty()) return;
|
|
3290
|
+
const originalConsole = {
|
|
3291
|
+
warn: console.warn,
|
|
3292
|
+
error: console.error,
|
|
3293
|
+
debug: console.debug,
|
|
3294
|
+
info: console.info,
|
|
3295
|
+
log: console.log
|
|
3296
|
+
};
|
|
3297
|
+
const pendingLogs = [];
|
|
3298
|
+
let flushTimer = null;
|
|
3299
|
+
const serializeArg = (arg, maxLength = 5e3) => {
|
|
3300
|
+
if (arg === null) return "null";
|
|
3301
|
+
if (arg === void 0) return "undefined";
|
|
3302
|
+
const type = typeof arg;
|
|
3303
|
+
if (type === "string") return arg;
|
|
3304
|
+
if (type === "number" || type === "boolean") return String(arg);
|
|
3305
|
+
if (type === "function") return `[Function: ${arg.name || "anonymous"}]`;
|
|
3306
|
+
if (type === "symbol") return arg.toString();
|
|
3307
|
+
try {
|
|
3308
|
+
const result = JSON.stringify(arg, (_key, value) => {
|
|
3309
|
+
if (value instanceof Error) return `Error: ${value.message}`;
|
|
3310
|
+
if (value instanceof Date) return value.toISOString();
|
|
3311
|
+
if (value instanceof RegExp) return value.toString();
|
|
3312
|
+
if (typeof value === "function") return `[Function: ${value.name || "anonymous"}]`;
|
|
3313
|
+
return value;
|
|
3314
|
+
});
|
|
3315
|
+
if (result.length > maxLength) return result.substring(0, maxLength) + "... [truncated]";
|
|
3316
|
+
return result;
|
|
3317
|
+
} catch {
|
|
3318
|
+
return "[Circular or non-serializable object]";
|
|
3319
|
+
}
|
|
3320
|
+
};
|
|
3321
|
+
const isFrameworkStack = (stack) => {
|
|
3322
|
+
if (!stack) return false;
|
|
3323
|
+
const frameworkStackPatterns = [/\/node_modules\//i, /\/packages\/library\//i];
|
|
3324
|
+
const frames = stack.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
3325
|
+
if (frames.length === 0) return false;
|
|
3326
|
+
const isFrameworkFrame = (frame) => frameworkStackPatterns.some((pattern) => pattern.test(frame));
|
|
3327
|
+
return frames.every(isFrameworkFrame);
|
|
3328
|
+
};
|
|
3329
|
+
const isFrameworkLog = (message, stack) => {
|
|
3330
|
+
if ([
|
|
3331
|
+
/^\[vite\]/i,
|
|
3332
|
+
/^Pinged library socket/i,
|
|
3333
|
+
/^\[HMR\]/i,
|
|
3334
|
+
/^Download the React DevTools/i,
|
|
3335
|
+
/^\[internal\]/i
|
|
3336
|
+
].some((pattern) => pattern.test(message))) return true;
|
|
3337
|
+
return isFrameworkStack(stack);
|
|
3338
|
+
};
|
|
3339
|
+
const flushLogs = () => {
|
|
3340
|
+
if (pendingLogs.length === 0) return;
|
|
3341
|
+
const logsToSend = pendingLogs.splice(0);
|
|
3342
|
+
flushTimer = null;
|
|
3343
|
+
logsToSend.forEach(({ level, args, stack }) => {
|
|
3344
|
+
try {
|
|
3345
|
+
const message = args.map(serializeArg).join(" ");
|
|
3346
|
+
if (isFrameworkLog(message, stack)) return;
|
|
3347
|
+
const logEntry = {
|
|
3348
|
+
id: generateId(),
|
|
3349
|
+
timestamp: Date.now(),
|
|
3350
|
+
level,
|
|
3351
|
+
message,
|
|
3352
|
+
stack
|
|
3353
|
+
};
|
|
3354
|
+
editorBridge.sendConsoleLog(logEntry);
|
|
3355
|
+
} catch {}
|
|
3356
|
+
});
|
|
3357
|
+
};
|
|
3358
|
+
const queueConsoleLog = (level, args) => {
|
|
3359
|
+
let stack;
|
|
3360
|
+
const rawStack = (/* @__PURE__ */ new Error()).stack;
|
|
3361
|
+
if (rawStack) {
|
|
3362
|
+
const lines = rawStack.split("\n");
|
|
3363
|
+
stack = lines.length > 3 ? lines.slice(3).join("\n") : void 0;
|
|
3364
|
+
}
|
|
3365
|
+
pendingLogs.push({
|
|
3366
|
+
level,
|
|
3367
|
+
args,
|
|
3368
|
+
stack
|
|
3369
|
+
});
|
|
3370
|
+
if (!flushTimer) flushTimer = setTimeout(flushLogs, 100);
|
|
3371
|
+
};
|
|
3372
|
+
console.warn = (...args) => {
|
|
3373
|
+
originalConsole.warn(...args);
|
|
3374
|
+
queueConsoleLog("warn", args);
|
|
3375
|
+
};
|
|
3376
|
+
console.error = (...args) => {
|
|
3377
|
+
originalConsole.error(...args);
|
|
3378
|
+
queueConsoleLog("error", args);
|
|
3379
|
+
};
|
|
3380
|
+
console.debug = (...args) => {
|
|
3381
|
+
originalConsole.debug(...args);
|
|
3382
|
+
queueConsoleLog("debug", args);
|
|
3383
|
+
};
|
|
3384
|
+
console.info = (...args) => {
|
|
3385
|
+
originalConsole.info(...args);
|
|
3386
|
+
queueConsoleLog("info", args);
|
|
3387
|
+
};
|
|
3388
|
+
console.log = (...args) => {
|
|
3389
|
+
originalConsole.log(...args);
|
|
3390
|
+
queueConsoleLog("log", args);
|
|
3391
|
+
};
|
|
3392
|
+
const serializeError = (error) => {
|
|
3393
|
+
if (!error) return "Unknown error";
|
|
3394
|
+
if (typeof error === "string") return error;
|
|
3395
|
+
const strValue = error.toString?.();
|
|
3396
|
+
if (strValue && strValue !== "[object Object]") return strValue;
|
|
3397
|
+
try {
|
|
3398
|
+
return JSON.stringify(error);
|
|
3399
|
+
} catch {
|
|
3400
|
+
return String(error);
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
const handleGlobalError = (event) => {
|
|
3404
|
+
const errorData = {
|
|
3405
|
+
id: generateId(),
|
|
3406
|
+
timestamp: Date.now(),
|
|
3407
|
+
error: serializeError(event.error) || event.message,
|
|
3408
|
+
errorInfo: { componentStack: event.error?.stack || "" },
|
|
3409
|
+
identifier: void 0
|
|
3410
|
+
};
|
|
3411
|
+
if (!root_store_default.editStore?.ai) {
|
|
3412
|
+
originalConsole.error("[Lost runtime error - store not ready]", errorData);
|
|
3413
|
+
return;
|
|
3414
|
+
}
|
|
3415
|
+
root_store_default.editStore.ai.handleRuntimeError(errorData);
|
|
3416
|
+
};
|
|
3417
|
+
const handleUnhandledRejection = (event) => {
|
|
3418
|
+
const errorData = {
|
|
3419
|
+
id: generateId(),
|
|
3420
|
+
timestamp: Date.now(),
|
|
3421
|
+
error: serializeError(event.reason) || "Unhandled promise rejection",
|
|
3422
|
+
errorInfo: { componentStack: event.reason?.stack || "" },
|
|
3423
|
+
identifier: void 0
|
|
3424
|
+
};
|
|
3425
|
+
if (!root_store_default.editStore?.ai) {
|
|
3426
|
+
originalConsole.error("[Lost runtime error - store not ready]", errorData);
|
|
3427
|
+
return;
|
|
3428
|
+
}
|
|
3429
|
+
root_store_default.editStore.ai.handleRuntimeError(errorData);
|
|
3430
|
+
};
|
|
3431
|
+
window.addEventListener("error", handleGlobalError);
|
|
3432
|
+
window.addEventListener("unhandledrejection", handleUnhandledRejection);
|
|
3433
|
+
return () => {
|
|
3434
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
3435
|
+
console.warn = originalConsole.warn;
|
|
3436
|
+
console.error = originalConsole.error;
|
|
3437
|
+
console.debug = originalConsole.debug;
|
|
3438
|
+
console.info = originalConsole.info;
|
|
3439
|
+
console.log = originalConsole.log;
|
|
3440
|
+
window.removeEventListener("error", handleGlobalError);
|
|
3441
|
+
window.removeEventListener("unhandledrejection", handleUnhandledRejection);
|
|
3442
|
+
};
|
|
3443
|
+
}, []);
|
|
3173
3444
|
const isPossiblyEditor = useMemo(isEmbeddedBySuperblocksFirstParty, []);
|
|
3174
3445
|
const connectionStatus = root_store_default.editStore?.connectionManager.connectionStatus;
|
|
3175
3446
|
if (connectionStatus === "pre-init" || connectionStatus === "connecting") return /* @__PURE__ */ jsx(FullPageSpinner, {});
|
|
3176
|
-
if (isPossiblyEditor && root_store_default.editStore?.isInitialized && typeof window !== "undefined") return props.children;
|
|
3447
|
+
if (isPossiblyEditor && root_store_default.editStore?.isInitialized && typeof window !== "undefined") return /* @__PURE__ */ jsx(React.Fragment, { children: props.children }, reloadKey);
|
|
3177
3448
|
if (isEditMode()) {
|
|
3178
3449
|
console.log("In edit mode, but editor has not initialized yet");
|
|
3179
3450
|
return null;
|
|
3180
3451
|
}
|
|
3181
|
-
return /* @__PURE__ */ jsx(React.Fragment, { children: props.children });
|
|
3452
|
+
return /* @__PURE__ */ jsx(React.Fragment, { children: props.children }, reloadKey);
|
|
3182
3453
|
});
|
|
3183
3454
|
const WithUserWrapper$1 = (props) => {
|
|
3184
3455
|
const { data: currentUser, isLoading } = useGetCurrentUserQuery();
|
|
@@ -3213,25 +3484,7 @@ const EmbedWrapper = (props) => {
|
|
|
3213
3484
|
useEffect(() => {
|
|
3214
3485
|
const bootstrapResponseListener = (event) => {
|
|
3215
3486
|
try {
|
|
3216
|
-
|
|
3217
|
-
root_store_default.userId = event.data.payload.userId;
|
|
3218
|
-
root_store_default.apis.agentUrls = event.data.payload.agentUrls ?? (event.data.payload.agentUrl ? [event.data.payload.agentUrl] : []);
|
|
3219
|
-
root_store_default.apis.setTokens(event.data.payload.token, event.data.payload.accessToken);
|
|
3220
|
-
root_store_default.windowOriginUrl = event.data.payload.logContext.superblocks_window_origin_url;
|
|
3221
|
-
if (root_store_default.windowOriginUrl) import("../utils-BmTdixWt.js").then(({ initTracerProviderWithOrigin: initTracerProviderWithOrigin$1 }) => {
|
|
3222
|
-
initTracerProviderWithOrigin$1(root_store_default.windowOriginUrl);
|
|
3223
|
-
import("../logs-VIMbIbT8.js").then(({ initLibraryLoggerProvider }) => {
|
|
3224
|
-
initLibraryLoggerProvider({
|
|
3225
|
-
windowOriginUrl: root_store_default.windowOriginUrl,
|
|
3226
|
-
appId: event.data.payload.appId,
|
|
3227
|
-
userId: event.data.payload.logContext.superblocks_user_id,
|
|
3228
|
-
userEmail: event.data.payload.logContext.superblocks_user_email,
|
|
3229
|
-
orgId: event.data.payload.logContext.superblocks_org_id,
|
|
3230
|
-
orgName: event.data.payload.logContext.superblocks_org_name,
|
|
3231
|
-
environment: event.data.payload.logContext.superblocks_env
|
|
3232
|
-
});
|
|
3233
|
-
});
|
|
3234
|
-
});
|
|
3487
|
+
handleBootstrapResponse(event);
|
|
3235
3488
|
setIsLoaded(true);
|
|
3236
3489
|
iframeMessageHandler.removeEventListener("sb-bootstrap-response", bootstrapResponseListener);
|
|
3237
3490
|
} catch (e) {
|
|
@@ -3341,6 +3594,10 @@ const EmbedWrapper = (props) => {
|
|
|
3341
3594
|
}
|
|
3342
3595
|
};
|
|
3343
3596
|
iframeMessageHandler.addEventListener("ai-updates", aiUpdatesListener);
|
|
3597
|
+
const hmrReloadListener = () => {
|
|
3598
|
+
triggerHmrReload(true);
|
|
3599
|
+
};
|
|
3600
|
+
iframeMessageHandler.addEventListener("hmr-reload-request", hmrReloadListener);
|
|
3344
3601
|
return () => {
|
|
3345
3602
|
iframeMessageHandler.removeEventListener("sb-bootstrap-response", bootstrapResponseListener);
|
|
3346
3603
|
iframeMessageHandler.removeEventListener("sb-update-active-agents", updateActiveAgentsListener);
|
|
@@ -3351,6 +3608,7 @@ const EmbedWrapper = (props) => {
|
|
|
3351
3608
|
iframeMessageHandler.removeEventListener("sb-global-sync", globalSyncListener);
|
|
3352
3609
|
iframeMessageHandler.removeEventListener("route-change", navigateToListener);
|
|
3353
3610
|
iframeMessageHandler.removeEventListener("ai-updates", aiUpdatesListener);
|
|
3611
|
+
iframeMessageHandler.removeEventListener("hmr-reload-request", hmrReloadListener);
|
|
3354
3612
|
try {
|
|
3355
3613
|
getEditStore().runtimeSubscriptionsStore.clearAll();
|
|
3356
3614
|
} catch {}
|
|
@@ -3749,7 +4007,7 @@ function useWidgetClick() {
|
|
|
3749
4007
|
if (!selectorId) return;
|
|
3750
4008
|
const component = editStore.runtimeTrackingStore.getComponent(selectorId);
|
|
3751
4009
|
if (!component) {
|
|
3752
|
-
console.log("[useWidgetClick] No component found for selectorId");
|
|
4010
|
+
console.log("[internal] [useWidgetClick] No component found for selectorId");
|
|
3753
4011
|
return;
|
|
3754
4012
|
}
|
|
3755
4013
|
const sourceId = component.sourceId;
|
|
@@ -3760,7 +4018,7 @@ function useWidgetClick() {
|
|
|
3760
4018
|
event.stopPropagation();
|
|
3761
4019
|
}
|
|
3762
4020
|
if (isTargettingComponent) {
|
|
3763
|
-
console.log("[useWidgetClick] Toggling component in AI context");
|
|
4021
|
+
console.log("[internal] [useWidgetClick] Toggling component in AI context");
|
|
3764
4022
|
editorBridge.toggleComponentInAiContext(sourceId, selectorId, displayName);
|
|
3765
4023
|
return;
|
|
3766
4024
|
}
|
|
@@ -3952,24 +4210,7 @@ const EmbedWrapper$1 = (props) => {
|
|
|
3952
4210
|
useEffect(() => {
|
|
3953
4211
|
const bootstrapResponseListener = (event) => {
|
|
3954
4212
|
try {
|
|
3955
|
-
|
|
3956
|
-
root_store_default.apis.agentUrls = event.data.payload.agentUrls ?? (event.data.payload.agentUrl ? [event.data.payload.agentUrl] : []);
|
|
3957
|
-
root_store_default.apis.setTokens(event.data.payload.token, event.data.payload.accessToken);
|
|
3958
|
-
root_store_default.windowOriginUrl = event.data.payload.logContext.superblocks_window_origin_url;
|
|
3959
|
-
if (root_store_default.windowOriginUrl) import("../utils-BmTdixWt.js").then(({ initTracerProviderWithOrigin: initTracerProviderWithOrigin$1 }) => {
|
|
3960
|
-
initTracerProviderWithOrigin$1(root_store_default.windowOriginUrl);
|
|
3961
|
-
import("../logs-VIMbIbT8.js").then(({ initLibraryLoggerProvider }) => {
|
|
3962
|
-
initLibraryLoggerProvider({
|
|
3963
|
-
windowOriginUrl: root_store_default.windowOriginUrl,
|
|
3964
|
-
appId: event.data.payload.appId,
|
|
3965
|
-
userId: event.data.payload.logContext.superblocks_user_id,
|
|
3966
|
-
userEmail: event.data.payload.logContext.superblocks_user_email,
|
|
3967
|
-
orgId: event.data.payload.logContext.superblocks_org_id,
|
|
3968
|
-
orgName: event.data.payload.logContext.superblocks_org_name,
|
|
3969
|
-
environment: event.data.payload.logContext.superblocks_env
|
|
3970
|
-
});
|
|
3971
|
-
});
|
|
3972
|
-
});
|
|
4213
|
+
handleBootstrapResponse(event);
|
|
3973
4214
|
setIsLoaded(true);
|
|
3974
4215
|
iframeMessageHandler.removeEventListener("sb-bootstrap-response", bootstrapResponseListener);
|
|
3975
4216
|
} catch (e) {
|
|
@@ -4065,7 +4306,7 @@ var InternalErrorBoundary = class extends React.Component {
|
|
|
4065
4306
|
//#region src/lib/internal-details/lib/devtools/index.tsx
|
|
4066
4307
|
const SUPPORTED_MODES = ["local-dev"];
|
|
4067
4308
|
const DevToolsInternal = React.lazy(() => {
|
|
4068
|
-
return import("../devtools-consolidated-
|
|
4309
|
+
return import("../devtools-consolidated-zKLoNTKB.js").then((module) => ({ default: module.CustomDevTools }));
|
|
4069
4310
|
});
|
|
4070
4311
|
const DevTools = () => {
|
|
4071
4312
|
if (!SUPPORTED_MODES.includes("production")) return null;
|
|
@@ -4099,6 +4340,39 @@ function useTrackRouteChange() {
|
|
|
4099
4340
|
]);
|
|
4100
4341
|
}
|
|
4101
4342
|
|
|
4343
|
+
//#endregion
|
|
4344
|
+
//#region src/lib/user-facing/sb-provider-tracker.ts
|
|
4345
|
+
let sbProviderRendered = false;
|
|
4346
|
+
const reportSbProviderRenderedEditMode = () => {
|
|
4347
|
+
sbProviderRendered = true;
|
|
4348
|
+
};
|
|
4349
|
+
const ERROR_ID = "base-app-not-rendered";
|
|
4350
|
+
if (isEditMode()) setTimeout(() => {
|
|
4351
|
+
if (!root_store_default.editStore) console.error("Edit store not initialized.");
|
|
4352
|
+
if (sbProviderRendered) {
|
|
4353
|
+
editorBridge.sendClearRuntimeError(ERROR_ID, true);
|
|
4354
|
+
return;
|
|
4355
|
+
}
|
|
4356
|
+
const errorMessage = `AppProvider not rendered in time.
|
|
4357
|
+
Please ensure that 'App' from @superblocksteam/library is always rendered.
|
|
4358
|
+
API executions and editor features will be unavailable.
|
|
4359
|
+
`;
|
|
4360
|
+
console.error(errorMessage);
|
|
4361
|
+
editorBridge.sendRuntimeError({
|
|
4362
|
+
id: ERROR_ID,
|
|
4363
|
+
error: errorMessage,
|
|
4364
|
+
errorInfo: {}
|
|
4365
|
+
}, true);
|
|
4366
|
+
editorBridge.sendLoadError(errorMessage);
|
|
4367
|
+
const intervalId = setInterval(() => {
|
|
4368
|
+
if (sbProviderRendered) {
|
|
4369
|
+
clearInterval(intervalId);
|
|
4370
|
+
editorBridge.sendClearRuntimeError(ERROR_ID, true);
|
|
4371
|
+
return;
|
|
4372
|
+
}
|
|
4373
|
+
}, 1e3);
|
|
4374
|
+
}, 1e4);
|
|
4375
|
+
|
|
4102
4376
|
//#endregion
|
|
4103
4377
|
//#region src/lib/user-facing/styling/styles.ts
|
|
4104
4378
|
const VARIABLES = { primaryColor: "--primary-color" };
|
|
@@ -4177,7 +4451,10 @@ const SbProvider = function SbProvider$1({ name = "codemode", children, classNam
|
|
|
4177
4451
|
initializeStyles(name);
|
|
4178
4452
|
}, [name]);
|
|
4179
4453
|
useEffect(() => {
|
|
4180
|
-
if (isEditMode())
|
|
4454
|
+
if (isEditMode()) {
|
|
4455
|
+
initializeCSSVariables();
|
|
4456
|
+
reportSbProviderRenderedEditMode();
|
|
4457
|
+
}
|
|
4181
4458
|
}, []);
|
|
4182
4459
|
if (!isApisInitialized) return /* @__PURE__ */ jsx(FullPageSpinner, {});
|
|
4183
4460
|
return /* @__PURE__ */ jsxs("div", {
|