@superblocksteam/library 2.0.59-next.2 → 2.0.59-next.4
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/{early-console-buffer-SSPd-jq2.js → early-console-buffer-oUqxIuRK.js} +31 -4
- package/dist/early-console-buffer-oUqxIuRK.js.map +1 -0
- package/dist/jsx-dev-runtime/index.d.ts.map +1 -1
- package/dist/jsx-dev-runtime/index.js +7 -282
- package/dist/jsx-dev-runtime/index.js.map +1 -1
- package/dist/{widget-wrapper-naming-DxFT8zmk.js → jsx-wrapper-Ddb528TO.js} +410 -17
- package/dist/jsx-wrapper-Ddb528TO.js.map +1 -0
- package/dist/lib/index.d.ts +498 -20
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +215 -87
- package/dist/lib/index.js.map +1 -1
- package/dist/{logs-CgCPS9qr.js → logs-CQnzO-hw.js} +2 -2
- package/dist/{logs-CgCPS9qr.js.map → logs-CQnzO-hw.js.map} +1 -1
- package/package.json +3 -3
- package/dist/early-console-buffer-SSPd-jq2.js.map +0 -1
- package/dist/widget-wrapper-naming-DxFT8zmk.js.map +0 -1
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
2
2
|
|
|
3
|
+
//#region src/lib/tracing/console-logging.ts
|
|
4
|
+
var ConsoleLogAttributes = class ConsoleLogAttributes {
|
|
5
|
+
constructor(attributes) {
|
|
6
|
+
this.attributes = attributes;
|
|
7
|
+
}
|
|
8
|
+
static create(attrs) {
|
|
9
|
+
return new ConsoleLogAttributes(attrs);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const consoleLogAttributes = (attrs) => {
|
|
13
|
+
return new ConsoleLogAttributes(attrs);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
3
17
|
//#region src/lib/tracing/early-console-buffer.ts
|
|
18
|
+
function mergeAllConsoleLogAttributes(args) {
|
|
19
|
+
if (args.length === 0) return void 0;
|
|
20
|
+
return args.reduce((merged, arg) => {
|
|
21
|
+
if (arg instanceof ConsoleLogAttributes) return {
|
|
22
|
+
...merged,
|
|
23
|
+
...arg.attributes
|
|
24
|
+
};
|
|
25
|
+
return merged;
|
|
26
|
+
}, {});
|
|
27
|
+
}
|
|
4
28
|
var LibraryEarlyConsoleBuffer = class LibraryEarlyConsoleBuffer {
|
|
5
29
|
static instance;
|
|
6
30
|
buffer = [];
|
|
@@ -70,7 +94,10 @@ var LibraryEarlyConsoleBuffer = class LibraryEarlyConsoleBuffer {
|
|
|
70
94
|
warn: SeverityNumber.WARN,
|
|
71
95
|
error: SeverityNumber.ERROR
|
|
72
96
|
};
|
|
73
|
-
const attributes = {
|
|
97
|
+
const attributes = {
|
|
98
|
+
...fromBuffer && { source: "early-console-buffer" },
|
|
99
|
+
...mergeAllConsoleLogAttributes(args)
|
|
100
|
+
};
|
|
74
101
|
this.otelLogger.emit({
|
|
75
102
|
severityNumber: severityMap[level],
|
|
76
103
|
severityText: level,
|
|
@@ -80,7 +107,7 @@ var LibraryEarlyConsoleBuffer = class LibraryEarlyConsoleBuffer {
|
|
|
80
107
|
});
|
|
81
108
|
}
|
|
82
109
|
formatConsoleArgs(args) {
|
|
83
|
-
return args.map((arg) => {
|
|
110
|
+
return args.filter((arg) => !(arg instanceof ConsoleLogAttributes)).map((arg) => {
|
|
84
111
|
if (typeof arg === "string") return arg;
|
|
85
112
|
if (arg === null) return "null";
|
|
86
113
|
if (arg === void 0) return "undefined";
|
|
@@ -105,5 +132,5 @@ var LibraryEarlyConsoleBuffer = class LibraryEarlyConsoleBuffer {
|
|
|
105
132
|
var early_console_buffer_default = LibraryEarlyConsoleBuffer;
|
|
106
133
|
|
|
107
134
|
//#endregion
|
|
108
|
-
export { early_console_buffer_default as t };
|
|
109
|
-
//# sourceMappingURL=early-console-buffer-
|
|
135
|
+
export { consoleLogAttributes as n, early_console_buffer_default as t };
|
|
136
|
+
//# sourceMappingURL=early-console-buffer-oUqxIuRK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-console-buffer-oUqxIuRK.js","names":["attributes: Record<string, any>"],"sources":["../src/lib/tracing/console-logging.ts","../src/lib/tracing/early-console-buffer.ts"],"sourcesContent":["// The attributes that should be passed to OTEL logs as part of the message context.\n// To use, use consoleLogAttributes() to create an instance of this class, and pass as an argument to console.* methods.\nexport class ConsoleLogAttributes {\n constructor(public readonly attributes: Record<string, any>) {}\n\n // Optional: Add validation or transformation\n static create(attrs: Record<string, any>): ConsoleLogAttributes {\n return new ConsoleLogAttributes(attrs);\n }\n}\n\n// Convenience factory\nexport const consoleLogAttributes = (\n attrs: Record<string, any>,\n): ConsoleLogAttributes => {\n return new ConsoleLogAttributes(attrs);\n};\n","import { SeverityNumber } from \"@opentelemetry/api-logs\";\nimport { ConsoleLogAttributes } from \"./console-logging.js\";\nimport type { Logger as OTelLogger } from \"@opentelemetry/api-logs\";\n\ninterface LogEntry {\n level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\";\n args: any[];\n timestamp: number;\n}\n\nfunction mergeAllConsoleLogAttributes(\n args: any[],\n): Record<string, any> | undefined {\n if (args.length === 0) return undefined;\n\n return args.reduce((merged, arg) => {\n if (arg instanceof ConsoleLogAttributes) {\n return { ...merged, ...arg.attributes };\n }\n return merged;\n }, {});\n}\n\nclass LibraryEarlyConsoleBuffer {\n private static instance: LibraryEarlyConsoleBuffer;\n private buffer: LogEntry[] = [];\n private maxBufferSize = 1000;\n private originalMethods: Record<string, (...args: any[]) => void> = {};\n private otelLogger?: OTelLogger = undefined;\n private isPatched = false;\n\n static getInstance(): LibraryEarlyConsoleBuffer {\n if (!LibraryEarlyConsoleBuffer.instance) {\n LibraryEarlyConsoleBuffer.instance = new LibraryEarlyConsoleBuffer();\n }\n return LibraryEarlyConsoleBuffer.instance;\n }\n\n // Patch console methods immediately with buffering\n patchEarly(): void {\n if (this.isPatched) return;\n\n // Store original methods\n this.originalMethods.log = console.log.bind(console);\n this.originalMethods.info = console.info.bind(console);\n this.originalMethods.debug = console.debug.bind(console);\n this.originalMethods.warn = console.warn.bind(console);\n this.originalMethods.error = console.error.bind(console);\n\n // Replace with buffering versions\n this.patchMethod(\"log\");\n this.patchMethod(\"info\");\n this.patchMethod(\"debug\");\n this.patchMethod(\"warn\");\n this.patchMethod(\"error\");\n\n this.isPatched = true;\n }\n\n private patchMethod(level: string): void {\n const originalMethod = this.originalMethods[level];\n\n (console as any)[level] = (...args: any[]) => {\n // Always call original method for dev experience\n originalMethod(...args);\n\n // Buffer for OpenTelemetry\n this.bufferLog(level as any, args);\n\n // Send to OpenTelemetry if available\n if (this.otelLogger) {\n this.sendToOpenTelemetry(level as any, args);\n }\n };\n }\n\n private bufferLog(level: LogEntry[\"level\"], args: any[]): void {\n if (this.buffer.length >= this.maxBufferSize) {\n this.buffer.shift(); // Remove oldest entry\n }\n\n this.buffer.push({\n level,\n args,\n timestamp: Date.now(),\n });\n }\n\n enableOpenTelemetry(otelLogger: OTelLogger): void {\n console.info(\"[EarlyConsoleBuffer] Enabling OpenTelemetry integration\");\n this.otelLogger = otelLogger;\n this.flushBuffer();\n }\n\n private flushBuffer(): void {\n if (!this.otelLogger) return;\n\n const bufferCount = this.buffer.length;\n if (bufferCount === 0) {\n console.info(\"[EarlyConsoleBuffer] No buffered logs to flush\");\n return;\n }\n\n console.info(\n `[EarlyConsoleBuffer] Flushing ${bufferCount} buffered logs to OpenTelemetry`,\n );\n\n this.buffer.forEach((entry) => {\n this.sendToOpenTelemetry(entry.level, entry.args, entry.timestamp, true); // true = from buffer\n });\n\n this.buffer = []; // Clear buffer\n console.info(\n `[EarlyConsoleBuffer] Successfully sent ${bufferCount} buffered logs to OpenTelemetry logger`,\n );\n }\n\n private sendToOpenTelemetry(\n level: LogEntry[\"level\"],\n args: any[],\n timestamp?: number,\n fromBuffer?: boolean,\n ): void {\n if (!this.otelLogger) return;\n\n const severityMap = {\n debug: SeverityNumber.DEBUG,\n log: SeverityNumber.INFO,\n info: SeverityNumber.INFO,\n warn: SeverityNumber.WARN,\n error: SeverityNumber.ERROR,\n };\n\n // Only add 'source' attribute if this log came from the buffer flush\n const attributes = {\n ...(fromBuffer && { source: \"early-console-buffer\" }),\n ...mergeAllConsoleLogAttributes(args),\n };\n\n this.otelLogger.emit({\n severityNumber: severityMap[level],\n severityText: level,\n body: this.formatConsoleArgs(args),\n timestamp: timestamp,\n attributes,\n });\n }\n\n private formatConsoleArgs(args: any[]): string {\n return args\n .filter((arg) => !(arg instanceof ConsoleLogAttributes))\n .map((arg) => {\n if (typeof arg === \"string\") return arg;\n if (arg === null) return \"null\";\n if (arg === undefined) return \"undefined\";\n if (typeof arg === \"object\") {\n try {\n return JSON.stringify(arg, null, 2);\n } catch {\n return \"[object Object]\";\n }\n }\n return String(arg);\n })\n .join(\" \");\n }\n\n // Method to check if we have buffered logs (for testing/debugging)\n getBufferSize(): number {\n return this.buffer.length;\n }\n\n // Method to check if console is patched (for testing/debugging)\n isConsolePatched(): boolean {\n return this.isPatched;\n }\n\n // Method to check if OpenTelemetry is enabled (for testing/debugging)\n isOpenTelemetryEnabled(): boolean {\n return this.otelLogger !== undefined;\n }\n}\n\nexport default LibraryEarlyConsoleBuffer;\n"],"mappings":";;;AAEA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,YAAY,AAAgBA,YAAiC;EAAjC;;CAG5B,OAAO,OAAO,OAAkD;AAC9D,SAAO,IAAI,qBAAqB,MAAM;;;AAK1C,MAAa,wBACX,UACyB;AACzB,QAAO,IAAI,qBAAqB,MAAM;;;;;ACLxC,SAAS,6BACP,MACiC;AACjC,KAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,QAAO,KAAK,QAAQ,QAAQ,QAAQ;AAClC,MAAI,eAAe,qBACjB,QAAO;GAAE,GAAG;GAAQ,GAAG,IAAI;GAAY;AAEzC,SAAO;IACN,EAAE,CAAC;;AAGR,IAAM,4BAAN,MAAM,0BAA0B;CAC9B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","../../src/jsx-dev-runtime/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/jsx-dev-runtime/jsx-dev-runtime.ts","../../src/jsx-dev-runtime/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkEgB,iBAAA,MAAA,CAAM,IAAA,EAAA,GAAA,EAAA,KAAA,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EAAA,gBAAA,EAAA,GAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA,GAAA,CAAA,EAAA,GAAA;;;cChET"}
|
|
@@ -1,287 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as api_hmr_tracker_default, _ as root_store_default, t as makeWrappedComponent } from "../jsx-wrapper-Ddb528TO.js";
|
|
2
2
|
import "../utils-AzBGeVXo.js";
|
|
3
3
|
import * as ReactJsxDevRuntime from "react/jsx-dev-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import React, { Component, useEffect, useMemo, useRef } from "react";
|
|
6
|
-
import { reaction } from "mobx";
|
|
7
|
-
import styled, { keyframes } from "styled-components";
|
|
8
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import { Observer } from "mobx-react-lite";
|
|
10
|
-
import polyfill from "@oddbird/css-anchor-positioning/fn";
|
|
4
|
+
import { SOURCE_ID_ATTRIBUTE } from "@superblocksteam/library-shared";
|
|
11
5
|
|
|
12
|
-
//#region src/lib/internal-details/css-constants.ts
|
|
13
|
-
const CSS_CLASSES = {
|
|
14
|
-
SUSPENSE_FALLBACK: "sb-suspense-fallback",
|
|
15
|
-
ANCHOR_NAME: "sb-anchor-name"
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/lib/internal-details/lib/suspense/suspense-fallback.tsx
|
|
20
|
-
const shimmerAnimation = keyframes`
|
|
21
|
-
0% {
|
|
22
|
-
background-position: -200px 0;
|
|
23
|
-
}
|
|
24
|
-
100% {
|
|
25
|
-
background-position: calc(200px + 100%) 0;
|
|
26
|
-
}
|
|
27
|
-
`;
|
|
28
|
-
const ShimmerDiv = styled.div`
|
|
29
|
-
min-height: 12px;
|
|
30
|
-
min-width: 12px;
|
|
31
|
-
background-color: ${(props) => props.$backgroundColor};
|
|
32
|
-
border-radius: ${(props) => props.$borderRadius};
|
|
33
|
-
position: relative;
|
|
34
|
-
overflow: hidden;
|
|
35
|
-
background: linear-gradient(
|
|
36
|
-
90deg,
|
|
37
|
-
${(props) => props.$backgroundColor} 25%,
|
|
38
|
-
${(props) => props.$shimmerHighlight} 50%,
|
|
39
|
-
${(props) => props.$backgroundColor} 75%
|
|
40
|
-
);
|
|
41
|
-
background-size: max(100%, 200px) 100%;
|
|
42
|
-
animation: ${shimmerAnimation} 5s infinite linear;
|
|
43
|
-
`;
|
|
44
|
-
/**
|
|
45
|
-
* Default fallback component displayed while components are suspended.
|
|
46
|
-
*/
|
|
47
|
-
function SuspenseFallback({ style, className, noBorderRadius }) {
|
|
48
|
-
const backgroundColor = "#f8f9fa";
|
|
49
|
-
const shimmerHighlight = "#ffffff";
|
|
50
|
-
const borderRadius = noBorderRadius ? "0px" : "4px";
|
|
51
|
-
const classes = useMemo(() => [CSS_CLASSES.ANCHOR_NAME, className].filter(Boolean).join(" "), [className]);
|
|
52
|
-
return /* @__PURE__ */ jsx(ShimmerDiv, {
|
|
53
|
-
$backgroundColor: backgroundColor,
|
|
54
|
-
$shimmerHighlight: shimmerHighlight,
|
|
55
|
-
$borderRadius: borderRadius,
|
|
56
|
-
style: style?.(),
|
|
57
|
-
className: classes,
|
|
58
|
-
"data-test": "suspense-fallback"
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/lib/user-facing/component-base/error-boundary.tsx
|
|
64
|
-
const ErrorBoundaryContainer = styled.div`
|
|
65
|
-
background: white;
|
|
66
|
-
padding: 10px;
|
|
67
|
-
display: flex;
|
|
68
|
-
flex-direction: column;
|
|
69
|
-
gap: 8px;
|
|
70
|
-
border: 1px solid ${colors.GREY_100};
|
|
71
|
-
border-left: 3px solid ${colors.RED_500};
|
|
72
|
-
border-radius: 4px;
|
|
73
|
-
width: 100%;
|
|
74
|
-
color: ${colors.GREY_700};
|
|
75
|
-
`;
|
|
76
|
-
const ErrorDetailsContainer = styled.div`
|
|
77
|
-
display: flex;
|
|
78
|
-
flex-direction: column;
|
|
79
|
-
gap: 8px;
|
|
80
|
-
`;
|
|
81
|
-
const ErrorActionsContainer = styled.div`
|
|
82
|
-
display: flex;
|
|
83
|
-
justify-content: flex-end;
|
|
84
|
-
align-items: center;
|
|
85
|
-
gap: 8px;
|
|
86
|
-
`;
|
|
87
|
-
var ErrorBoundary = class extends Component {
|
|
88
|
-
state = {
|
|
89
|
-
id: generateId(),
|
|
90
|
-
hasError: false
|
|
91
|
-
};
|
|
92
|
-
disposeAutoReset;
|
|
93
|
-
static getDerivedStateFromError(e) {
|
|
94
|
-
const error = e instanceof Error ? e : new Error(typeof e === "object" && e !== null ? JSON.stringify(e) : String(e));
|
|
95
|
-
return {
|
|
96
|
-
id: generateId(),
|
|
97
|
-
hasError: true,
|
|
98
|
-
error
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
componentDidCatch(error, errorInfo) {
|
|
102
|
-
console.error("Uncaught error:", error, errorInfo);
|
|
103
|
-
if (isEditMode$1()) root_store_default.editStore?.ai.handleRuntimeError({
|
|
104
|
-
id: this.state.id,
|
|
105
|
-
error: String(error),
|
|
106
|
-
errorInfo,
|
|
107
|
-
identifier: this.props.identifier
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
reset = () => {
|
|
111
|
-
if (isEditMode$1()) root_store_default.editStore?.ai.clearRuntimeError(this.state.id);
|
|
112
|
-
this.setState({
|
|
113
|
-
hasError: false,
|
|
114
|
-
error: void 0
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
componentWillUnmount() {
|
|
118
|
-
if (this.state.hasError && isEditMode$1()) root_store_default.editStore?.ai.clearRuntimeError(this.state.id);
|
|
119
|
-
this.disposeAutoReset?.();
|
|
120
|
-
}
|
|
121
|
-
handleFixWithClarkInitiated = () => {
|
|
122
|
-
const ai = root_store_default.editStore?.ai;
|
|
123
|
-
if (!ai) return;
|
|
124
|
-
this.disposeAutoReset?.();
|
|
125
|
-
this.disposeAutoReset = void 0;
|
|
126
|
-
let sawStart = ai.getIsEditing();
|
|
127
|
-
this.disposeAutoReset = reaction(() => ai.getIsEditing(), (isEditing) => {
|
|
128
|
-
if (!sawStart && isEditing) sawStart = true;
|
|
129
|
-
if (sawStart && !isEditing) {
|
|
130
|
-
this.reset();
|
|
131
|
-
this.disposeAutoReset?.();
|
|
132
|
-
this.disposeAutoReset = void 0;
|
|
133
|
-
}
|
|
134
|
-
}, {
|
|
135
|
-
fireImmediately: true,
|
|
136
|
-
name: "error-boundary-ai-auto-reset"
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
handleFixWithAi() {
|
|
140
|
-
const { identifier } = this.props;
|
|
141
|
-
if (identifier) editorBridge.addComponentToAiContext(identifier.sourceId, identifier.selectorId);
|
|
142
|
-
let prompt = `Fix this error: `;
|
|
143
|
-
if (this.state.error?.stack) {
|
|
144
|
-
const lines = this.state.error.stack.split("\n");
|
|
145
|
-
const nodeModulesIndex = lines.findIndex((line) => line.includes("node_modules"));
|
|
146
|
-
const relevantLines = nodeModulesIndex > -1 ? lines.slice(0, nodeModulesIndex) : lines;
|
|
147
|
-
prompt += relevantLines.slice(0, 5).join("\n");
|
|
148
|
-
} else prompt += this.state.error?.toString();
|
|
149
|
-
editorBridge.aiGenerate(prompt);
|
|
150
|
-
}
|
|
151
|
-
render() {
|
|
152
|
-
if (this.state.hasError) return /* @__PURE__ */ jsx(Observer, { children: () => {
|
|
153
|
-
if (root_store_default.editStore?.ai.getIsEditing() ?? false) return /* @__PURE__ */ jsx(SuspenseFallback, {});
|
|
154
|
-
return /* @__PURE__ */ jsxs(ErrorBoundaryContainer, { children: [/* @__PURE__ */ jsxs(ErrorDetailsContainer, { children: [/* @__PURE__ */ jsx("h3", { children: this.props.header || "Something went wrong." }), /* @__PURE__ */ jsxs("details", {
|
|
155
|
-
style: { fontSize: "0.8em" },
|
|
156
|
-
children: [/* @__PURE__ */ jsx("summary", {
|
|
157
|
-
style: { paddingLeft: "0.25rem" },
|
|
158
|
-
children: "Error details"
|
|
159
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
160
|
-
style: {
|
|
161
|
-
marginTop: "0.5rem",
|
|
162
|
-
maxWidth: "100%",
|
|
163
|
-
overflowX: "auto",
|
|
164
|
-
scrollbarWidth: "thin"
|
|
165
|
-
},
|
|
166
|
-
children: /* @__PURE__ */ jsx("pre", {
|
|
167
|
-
style: { color: "gray" },
|
|
168
|
-
children: /* @__PURE__ */ jsx("code", { children: this.state.error?.stack ? this.state.error.stack : this.state.error?.toString() })
|
|
169
|
-
})
|
|
170
|
-
})]
|
|
171
|
-
})] }), /* @__PURE__ */ jsxs(ErrorActionsContainer, { children: [isEditMode$1() && /* @__PURE__ */ jsx(FixWithClarkButton, {
|
|
172
|
-
onClick: this.handleFixWithClarkInitiated,
|
|
173
|
-
error: this.state.error,
|
|
174
|
-
identifier: this.props.identifier
|
|
175
|
-
}), /* @__PURE__ */ jsx(SecondaryButton, {
|
|
176
|
-
onClick: this.reset,
|
|
177
|
-
children: "Try again"
|
|
178
|
-
})] })] });
|
|
179
|
-
} });
|
|
180
|
-
return this.props.children;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
var error_boundary_default = ErrorBoundary;
|
|
184
|
-
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/edit-mode/edit-wrapper.tsx
|
|
187
|
-
if (typeof window !== "undefined" && typeof document.documentElement !== "undefined" && !("anchorName" in document.documentElement.style)) polyfill();
|
|
188
|
-
const createAnchorNameStyle = (props) => {
|
|
189
|
-
return { "--anchor-name": getWidgetAnchorName(props.selectorId) };
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region src/edit-mode/instance-tracker.ts
|
|
194
|
-
/**
|
|
195
|
-
* Tracks and recycles instance numbers for each sourceId to generate stable, unique selector IDs.
|
|
196
|
-
* When components unmount, their instance numbers are released and can be reused.
|
|
197
|
-
*/
|
|
198
|
-
var InstanceTracker = class {
|
|
199
|
-
sourceIdToUsedInstances = /* @__PURE__ */ new Map();
|
|
200
|
-
getNextAvailableInstance(sourceId) {
|
|
201
|
-
const usedInstances = this.sourceIdToUsedInstances.get(sourceId) ?? /* @__PURE__ */ new Set();
|
|
202
|
-
let instance = 0;
|
|
203
|
-
while (usedInstances.has(instance)) instance++;
|
|
204
|
-
usedInstances.add(instance);
|
|
205
|
-
this.sourceIdToUsedInstances.set(sourceId, usedInstances);
|
|
206
|
-
return instance;
|
|
207
|
-
}
|
|
208
|
-
releaseInstance(sourceId, instance) {
|
|
209
|
-
const usedInstances = this.sourceIdToUsedInstances.get(sourceId);
|
|
210
|
-
if (usedInstances) {
|
|
211
|
-
usedInstances.delete(instance);
|
|
212
|
-
if (usedInstances.size === 0) this.sourceIdToUsedInstances.delete(sourceId);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
const instanceTracker = new InstanceTracker();
|
|
217
|
-
|
|
218
|
-
//#endregion
|
|
219
|
-
//#region src/edit-mode/jsx-wrapper.tsx
|
|
220
|
-
const JSXContext = React.createContext({ selectorId: "S-<unknown>" });
|
|
221
|
-
const makeWrappedComponent = (type) => {
|
|
222
|
-
const isTag = typeof type === "string";
|
|
223
|
-
const isRegisteredSbComponent = root_store_default.componentRegistry.hasComponent(type);
|
|
224
|
-
const Component$1 = React.forwardRef((props, ref) => {
|
|
225
|
-
const { selectorId: parentSelectorId } = useJSXContext();
|
|
226
|
-
const sourceId = props[SOURCE_ID_ATTRIBUTE];
|
|
227
|
-
const noSelect = props[NO_SELECT_ATTRIBUTE];
|
|
228
|
-
const instanceNumberRef = useRef();
|
|
229
|
-
const selectorId = useRef("S-<unknown>");
|
|
230
|
-
if (selectorId.current === "S-<unknown>") {
|
|
231
|
-
instanceNumberRef.current = instanceTracker.getNextAvailableInstance(sourceId);
|
|
232
|
-
selectorId.current = `S-x-${sourceId}-${instanceNumberRef.current}`;
|
|
233
|
-
}
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
root_store_default.editStore?.runtimeTrackingStore.registerComponent(selectorId.current, {
|
|
236
|
-
sourceId,
|
|
237
|
-
type,
|
|
238
|
-
parentSelectorId,
|
|
239
|
-
isSbComponent: isRegisteredSbComponent,
|
|
240
|
-
isHtmlElement: isTag,
|
|
241
|
-
noSelect
|
|
242
|
-
});
|
|
243
|
-
return () => {
|
|
244
|
-
root_store_default.editStore?.runtimeTrackingStore.unregisterComponent(selectorId.current);
|
|
245
|
-
if (instanceNumberRef.current !== void 0) instanceTracker.releaseInstance(sourceId, instanceNumberRef.current);
|
|
246
|
-
};
|
|
247
|
-
}, []);
|
|
248
|
-
useEffect(() => {
|
|
249
|
-
root_store_default.editStore?.runtimeTrackingStore.updatePropsForComponent(selectorId.current, props);
|
|
250
|
-
}, [props]);
|
|
251
|
-
const jsxContext = useMemo(() => ({ selectorId: selectorId.current }), []);
|
|
252
|
-
const selectorProps = { [SELECTOR_ID_ATTRIBUTE]: selectorId.current };
|
|
253
|
-
if (parentSelectorId) selectorProps["data-sb-parent-selector-id"] = parentSelectorId;
|
|
254
|
-
const style = useMemo(() => {
|
|
255
|
-
return {
|
|
256
|
-
...props.style,
|
|
257
|
-
...createAnchorNameStyle({ selectorId: selectorId.current })
|
|
258
|
-
};
|
|
259
|
-
}, [props.style]);
|
|
260
|
-
const element = React.createElement(type, {
|
|
261
|
-
ref,
|
|
262
|
-
...props,
|
|
263
|
-
...selectorProps,
|
|
264
|
-
className: ["sb-anchor-name", props.className].filter(Boolean).join(" "),
|
|
265
|
-
style
|
|
266
|
-
});
|
|
267
|
-
if (!root_store_default.editStore?.isInitialized) return element;
|
|
268
|
-
return /* @__PURE__ */ jsx(JSXContext.Provider, {
|
|
269
|
-
value: jsxContext,
|
|
270
|
-
children: /* @__PURE__ */ jsx(error_boundary_default, { children: element })
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
try {
|
|
274
|
-
Component$1.displayName = typeof type === "string" ? type : type.displayName || type.name || "Component";
|
|
275
|
-
} catch (e) {
|
|
276
|
-
console.error("Error setting displayName", e);
|
|
277
|
-
}
|
|
278
|
-
return Component$1;
|
|
279
|
-
};
|
|
280
|
-
const useJSXContext = () => {
|
|
281
|
-
return React.useContext(JSXContext);
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
//#endregion
|
|
285
6
|
//#region src/jsx-dev-runtime/jsx-dev-runtime.ts
|
|
286
7
|
const reactJsxDEV = ReactJsxDevRuntime.jsxDEV;
|
|
287
8
|
function isEditMode() {
|
|
@@ -313,7 +34,11 @@ const shouldWrapTagType = (type) => {
|
|
|
313
34
|
function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
314
35
|
const sourceId = props?.[SOURCE_ID_ATTRIBUTE];
|
|
315
36
|
try {
|
|
316
|
-
if (sourceId && isEditMode() && shouldWrapTagType(type))
|
|
37
|
+
if (sourceId && isEditMode() && shouldWrapTagType(type)) {
|
|
38
|
+
const CachedWrappedComponent = getOrSetCachedWrappedComponent(type);
|
|
39
|
+
api_hmr_tracker_default.reportJSXActivity();
|
|
40
|
+
return reactJsxDEV(CachedWrappedComponent, props, `${key}-${sourceId}`, isStaticChildren, source, self);
|
|
41
|
+
}
|
|
317
42
|
} catch (e) {
|
|
318
43
|
console.error("Error during JSX wrap", e);
|
|
319
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isEditMode","rootStore","rootStore","Component","selectorProps: Record<string, string>","ErrorBoundary","rootStore"],"sources":["../../src/lib/internal-details/css-constants.ts","../../src/lib/internal-details/lib/suspense/suspense-fallback.tsx","../../src/lib/user-facing/component-base/error-boundary.tsx","../../src/edit-mode/edit-wrapper.tsx","../../src/edit-mode/instance-tracker.ts","../../src/edit-mode/jsx-wrapper.tsx","../../src/jsx-dev-runtime/jsx-dev-runtime.ts","../../src/jsx-dev-runtime/index.ts"],"sourcesContent":["export const CSS_CLASSES = {\n SUSPENSE_FALLBACK: \"sb-suspense-fallback\",\n ANCHOR_NAME: \"sb-anchor-name\",\n} as const;\n","import { useMemo, type CSSProperties, type ReactNode } from \"react\";\nimport styled, { keyframes } from \"styled-components\";\nimport { CSS_CLASSES } from \"../../css-constants.js\";\n\ninterface Props {\n children?: ReactNode;\n className?: string;\n style?: () => CSSProperties;\n noBorderRadius?: boolean;\n}\n\nconst shimmerAnimation = keyframes`\n 0% {\n background-position: -200px 0;\n }\n 100% {\n background-position: calc(200px + 100%) 0;\n }\n`;\n\nconst ShimmerDiv = styled.div<{\n $backgroundColor: string;\n $shimmerHighlight: string;\n $borderRadius: string;\n}>`\n min-height: 12px;\n min-width: 12px;\n background-color: ${(props) => props.$backgroundColor};\n border-radius: ${(props) => props.$borderRadius};\n position: relative;\n overflow: hidden;\n background: linear-gradient(\n 90deg,\n ${(props) => props.$backgroundColor} 25%,\n ${(props) => props.$shimmerHighlight} 50%,\n ${(props) => props.$backgroundColor} 75%\n );\n background-size: max(100%, 200px) 100%;\n animation: ${shimmerAnimation} 5s infinite linear;\n`;\n\n/**\n * Default fallback component displayed while components are suspended.\n */\nexport function SuspenseFallback({ style, className, noBorderRadius }: Props) {\n const backgroundColor = \"#f8f9fa\";\n const shimmerHighlight = \"#ffffff\";\n const borderRadius = noBorderRadius ? \"0px\" : \"4px\";\n\n const classes = useMemo(\n () => [CSS_CLASSES.ANCHOR_NAME, className].filter(Boolean).join(\" \"),\n [className],\n );\n\n return (\n <ShimmerDiv\n $backgroundColor={backgroundColor}\n $shimmerHighlight={shimmerHighlight}\n $borderRadius={borderRadius}\n style={style?.()}\n className={classes}\n data-test=\"suspense-fallback\"\n />\n );\n}\n","import { reaction, type IReactionDisposer } from \"mobx\";\nimport { Observer } from \"mobx-react-lite\";\nimport React, { Component } from \"react\";\nimport styled from \"styled-components\";\nimport { editorBridge } from \"../../../edit-mode/superblocks-editor-bridge.js\";\nimport { SecondaryButton } from \"../../internal-details/internal-components/common.js\";\nimport { FixWithClarkButton } from \"../../internal-details/internal-components/fix-with-clark-button.jsx\";\nimport { isEditMode } from \"../../internal-details/is-edit-mode.js\";\nimport rootStore from \"../../internal-details/lib/root-store.js\";\nimport { SuspenseFallback } from \"../../internal-details/lib/suspense/suspense-fallback.js\";\nimport { generateId } from \"../../utils/generate-id.js\";\nimport { colors } from \"../styling/colors.js\";\nimport type { IdentifierInfo } from \"../../internal-details/types.js\";\n\nimport type { ErrorInfo, ReactNode } from \"react\";\n\nconst ErrorBoundaryContainer = styled.div`\n background: white;\n padding: 10px;\n display: flex;\n flex-direction: column;\n gap: 8px;\n border: 1px solid ${colors.GREY_100};\n border-left: 3px solid ${colors.RED_500};\n border-radius: 4px;\n width: 100%;\n color: ${colors.GREY_700};\n`;\n\nconst ErrorDetailsContainer = styled.div`\n display: flex;\n flex-direction: column;\n gap: 8px;\n`;\n\nconst ErrorActionsContainer = styled.div`\n display: flex;\n justify-content: flex-end;\n align-items: center;\n gap: 8px;\n`;\n\ninterface Props {\n children: ReactNode;\n header?: string;\n identifier?: IdentifierInfo;\n}\n\ninterface State {\n id: string;\n hasError: boolean;\n error?: Error;\n}\n\nclass ErrorBoundary extends Component<Props, State> {\n state: State = {\n id: generateId(),\n hasError: false,\n };\n\n private disposeAutoReset?: IReactionDisposer;\n\n static getDerivedStateFromError(e: Error): State {\n const error =\n e instanceof Error\n ? e\n : new Error(\n typeof e === \"object\" && e !== null ? JSON.stringify(e) : String(e),\n );\n return {\n id: generateId(),\n hasError: true,\n error,\n };\n }\n\n componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n console.error(\"Uncaught error:\", error, errorInfo);\n if (isEditMode()) {\n rootStore.editStore?.ai.handleRuntimeError({\n id: this.state.id,\n error: String(error),\n errorInfo,\n identifier: this.props.identifier,\n });\n }\n }\n\n reset = () => {\n if (isEditMode()) {\n rootStore.editStore?.ai.clearRuntimeError(this.state.id);\n }\n this.setState({ hasError: false, error: undefined });\n };\n\n componentWillUnmount() {\n // Clear runtime error if component unmounts while in error state\n if (this.state.hasError && isEditMode()) {\n rootStore.editStore?.ai.clearRuntimeError(this.state.id);\n }\n // Clean up auto-reset watcher if still pending\n this.disposeAutoReset?.();\n }\n\n handleFixWithClarkInitiated = () => {\n const ai = rootStore.editStore?.ai;\n if (!ai) return;\n\n // Clean up any existing watcher\n this.disposeAutoReset?.();\n this.disposeAutoReset = undefined;\n\n // Set up one-shot watcher for AI completion\n let sawStart = ai.getIsEditing();\n this.disposeAutoReset = reaction(\n () => ai.getIsEditing(),\n (isEditing) => {\n if (!sawStart && isEditing) {\n sawStart = true;\n }\n if (sawStart && !isEditing) {\n this.reset();\n this.disposeAutoReset?.();\n this.disposeAutoReset = undefined;\n }\n },\n { fireImmediately: true, name: \"error-boundary-ai-auto-reset\" },\n );\n };\n\n handleFixWithAi() {\n const { identifier } = this.props;\n\n if (identifier) {\n editorBridge.addComponentToAiContext(\n identifier.sourceId,\n identifier.selectorId,\n );\n }\n\n let prompt = `Fix this error: `;\n\n if (this.state.error?.stack) {\n const lines = this.state.error.stack.split(\"\\n\");\n const nodeModulesIndex = lines.findIndex((line) =>\n line.includes(\"node_modules\"),\n );\n const relevantLines =\n nodeModulesIndex > -1 ? lines.slice(0, nodeModulesIndex) : lines;\n\n prompt += relevantLines.slice(0, 5).join(\"\\n\");\n } else {\n prompt += this.state.error?.toString();\n }\n\n editorBridge.aiGenerate(prompt);\n }\n\n render() {\n if (this.state.hasError) {\n return (\n <Observer>\n {() => {\n // Check if AI is currently generating\n const isAIGenerating =\n rootStore.editStore?.ai.getIsEditing() ?? false;\n\n if (isAIGenerating) {\n // During AI generation, show shimmer loader\n // Error is already reported to AI in componentDidCatch\n return <SuspenseFallback />;\n }\n\n // When AI is not generating, show full error UI\n return (\n <ErrorBoundaryContainer>\n <ErrorDetailsContainer>\n <h3>{this.props.header || \"Something went wrong.\"}</h3>\n <details style={{ fontSize: \"0.8em\" }}>\n <summary style={{ paddingLeft: \"0.25rem\" }}>\n Error details\n </summary>\n <div\n style={{\n marginTop: \"0.5rem\",\n maxWidth: \"100%\",\n overflowX: \"auto\",\n scrollbarWidth: \"thin\",\n }}\n >\n <pre\n style={{\n color: \"gray\",\n }}\n >\n <code>\n {this.state.error?.stack\n ? this.state.error.stack\n : this.state.error?.toString()}\n </code>\n </pre>\n </div>\n </details>\n </ErrorDetailsContainer>\n <ErrorActionsContainer>\n {isEditMode() && (\n <FixWithClarkButton\n onClick={this.handleFixWithClarkInitiated}\n error={this.state.error}\n identifier={this.props.identifier}\n />\n )}\n <SecondaryButton onClick={this.reset}>\n Try again\n </SecondaryButton>\n </ErrorActionsContainer>\n </ErrorBoundaryContainer>\n );\n }}\n </Observer>\n );\n }\n return this.props.children;\n }\n}\n\nexport default ErrorBoundary;\n","import polyfill from \"@oddbird/css-anchor-positioning/fn\";\n\nimport { getWidgetAnchorName } from \"../lib/utils/widget-wrapper-naming.js\";\n\nimport type { SbSelector } from \"@superblocksteam/library-shared/types\";\nimport type React from \"react\";\nimport type { CSSProperties } from \"react\";\n\nif (\n typeof window !== \"undefined\" &&\n typeof document.documentElement !== \"undefined\" &&\n !(\"anchorName\" in document.documentElement.style)\n) {\n polyfill();\n}\n\n// The variable --anchor-name is used in the CSS to set the anchor name for the widget\n// on the actual widget element.\nexport const createAnchorNameStyle = (props: {\n selectorId: SbSelector;\n}): React.CSSProperties | undefined => {\n return {\n \"--anchor-name\": getWidgetAnchorName(props.selectorId),\n } as CSSProperties;\n};\n","/**\n * Tracks and recycles instance numbers for each sourceId to generate stable, unique selector IDs.\n * When components unmount, their instance numbers are released and can be reused.\n */\nclass InstanceTracker {\n private sourceIdToUsedInstances = new Map<string, Set<number>>();\n\n getNextAvailableInstance(sourceId: string): number {\n const usedInstances =\n this.sourceIdToUsedInstances.get(sourceId) ?? new Set();\n\n // Find the smallest unused instance number\n let instance = 0;\n while (usedInstances.has(instance)) {\n instance++;\n }\n\n usedInstances.add(instance);\n this.sourceIdToUsedInstances.set(sourceId, usedInstances);\n\n return instance;\n }\n\n releaseInstance(sourceId: string, instance: number): void {\n const usedInstances = this.sourceIdToUsedInstances.get(sourceId);\n if (usedInstances) {\n usedInstances.delete(instance);\n if (usedInstances.size === 0) {\n this.sourceIdToUsedInstances.delete(sourceId);\n }\n }\n }\n}\n\nexport const instanceTracker = new InstanceTracker();\n","import {\n NO_SELECT_ATTRIBUTE,\n SELECTOR_ID_ATTRIBUTE,\n SOURCE_ID_ATTRIBUTE,\n} from \"@superblocksteam/library-shared\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport rootStore from \"../lib/internal-details/lib/root-store.js\";\nimport ErrorBoundary from \"../lib/user-facing/component-base/error-boundary.js\";\nimport { createAnchorNameStyle } from \"./edit-wrapper.js\";\nimport { instanceTracker } from \"./instance-tracker.js\";\nimport type { SbSelector } from \"@superblocksteam/library-shared/types\";\n\nexport type JSXContextType = {\n selectorId: SbSelector;\n};\n\nexport const JSXContext = React.createContext<JSXContextType>({\n selectorId: \"S-<unknown>\" satisfies SbSelector,\n});\n\nexport const makeWrappedComponent = (type: any) => {\n const isTag = typeof type === \"string\";\n const isRegisteredSbComponent =\n rootStore.componentRegistry.hasComponent(type);\n\n const Component = React.forwardRef((props: any, ref: any) => {\n const { selectorId: parentSelectorId } = useJSXContext();\n\n const sourceId = props[SOURCE_ID_ATTRIBUTE];\n const noSelect = props[NO_SELECT_ATTRIBUTE];\n\n const instanceNumberRef = useRef<number>();\n const selectorId = useRef<SbSelector>(\"S-<unknown>\" satisfies SbSelector);\n if (selectorId.current === \"S-<unknown>\") {\n instanceNumberRef.current =\n instanceTracker.getNextAvailableInstance(sourceId);\n selectorId.current =\n `S-x-${sourceId}-${instanceNumberRef.current}` as SbSelector;\n }\n\n useEffect(() => {\n rootStore.editStore?.runtimeTrackingStore.registerComponent(\n selectorId.current,\n {\n sourceId,\n type,\n parentSelectorId,\n isSbComponent: isRegisteredSbComponent,\n isHtmlElement: isTag,\n noSelect,\n },\n );\n return () => {\n rootStore.editStore?.runtimeTrackingStore.unregisterComponent(\n selectorId.current,\n );\n if (instanceNumberRef.current !== undefined) {\n instanceTracker.releaseInstance(sourceId, instanceNumberRef.current);\n }\n };\n // These deps should NOT change during the component lifecycle\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n rootStore.editStore?.runtimeTrackingStore.updatePropsForComponent(\n selectorId.current,\n props,\n );\n }, [props]);\n\n const jsxContext = useMemo(\n () =>\n ({\n selectorId: selectorId.current,\n }) satisfies JSXContextType,\n [],\n );\n\n const selectorProps: Record<string, string> = {\n [SELECTOR_ID_ATTRIBUTE]: selectorId.current,\n };\n\n if (parentSelectorId) {\n selectorProps[\"data-sb-parent-selector-id\"] = parentSelectorId;\n }\n\n const style = useMemo(() => {\n return {\n ...props.style,\n ...createAnchorNameStyle({\n selectorId: selectorId.current,\n }),\n };\n }, [props.style]);\n\n const element = React.createElement(type, {\n ref,\n ...props,\n ...selectorProps,\n className: [\"sb-anchor-name\", props.className].filter(Boolean).join(\" \"),\n style,\n });\n\n if (!rootStore.editStore?.isInitialized) {\n return element;\n }\n\n return (\n <JSXContext.Provider value={jsxContext}>\n <ErrorBoundary>{element}</ErrorBoundary>\n </JSXContext.Provider>\n );\n });\n try {\n Component.displayName =\n typeof type === \"string\"\n ? type\n : type.displayName || type.name || \"Component\";\n } catch (e) {\n console.error(\"Error setting displayName\", e);\n }\n\n return Component;\n};\n\nconst useJSXContext = () => {\n return React.useContext(JSXContext);\n};\n","import { SOURCE_ID_ATTRIBUTE } from \"@superblocksteam/library-shared\";\nimport * as ReactJsxDevRuntime from \"react/jsx-dev-runtime\";\nimport { makeWrappedComponent } from \"../edit-mode/jsx-wrapper.js\";\nimport rootStore from \"../lib/internal-details/lib/root-store.js\";\n\nconst reactJsxDEV = (ReactJsxDevRuntime as any).jsxDEV;\n\ndeclare global {\n interface Window {\n __SUPERBLOCKS_EDIT_MODE__?: boolean;\n _SB_VIEW_MODE?: string;\n }\n}\n\nfunction isEditMode(): boolean {\n if (typeof window === \"undefined\") return false;\n\n if (window.__SUPERBLOCKS_EDIT_MODE__ !== undefined) {\n return window.__SUPERBLOCKS_EDIT_MODE__;\n }\n\n const viewMode = window._SB_VIEW_MODE;\n if (viewMode === \"dev\") {\n window.__SUPERBLOCKS_EDIT_MODE__ = true;\n return true;\n }\n\n const envMode = import.meta.env?.MODE;\n const isEdit = envMode === \"local-dev\";\n window.__SUPERBLOCKS_EDIT_MODE__ = isEdit;\n return isEdit;\n}\n\nconst objTypeCache = new WeakMap<any, any>();\nconst stringTypeCache = new Map<string, any>();\n\ntype SupportedElementType = React.ElementType | string;\n\nfunction getOrSetCachedWrappedComponent(type: SupportedElementType) {\n const typeIsObject =\n (typeof type === \"object\" || typeof type === \"function\") && type !== null;\n const cachedType = typeIsObject\n ? objTypeCache.get(type)\n : stringTypeCache.get(type);\n if (cachedType) {\n return cachedType;\n }\n const newComponent = makeWrappedComponent(type);\n if (typeIsObject) {\n objTypeCache.set(type, newComponent);\n } else {\n stringTypeCache.set(type, newComponent);\n }\n return newComponent;\n}\n\nconst shouldWrapTagType = (type: unknown): type is SupportedElementType => {\n if (typeof type === \"string\") {\n return rootStore.componentRegistry.hasComponent(type);\n }\n return (\n type != null && (typeof type === \"object\" || typeof type === \"function\")\n );\n};\n\nexport function jsxDEV(\n type: any,\n props: any,\n key: any,\n isStaticChildren: any,\n source: any,\n self: any,\n) {\n const sourceId = props?.[SOURCE_ID_ATTRIBUTE];\n try {\n if (sourceId && isEditMode() && shouldWrapTagType(type)) {\n const CachedWrappedComponent = getOrSetCachedWrappedComponent(\n type satisfies SupportedElementType,\n );\n\n return reactJsxDEV(\n CachedWrappedComponent,\n props,\n `${key}-${sourceId}`,\n isStaticChildren,\n source,\n self,\n );\n }\n } catch (e) {\n console.error(\"Error during JSX wrap\", e);\n }\n return reactJsxDEV(type, props, key, isStaticChildren, source, self);\n}\n","import * as ReactJsxDevRuntime from \"react/jsx-dev-runtime\";\n\nexport const Fragment = (ReactJsxDevRuntime as any).Fragment;\nexport { jsxDEV } from \"./jsx-dev-runtime.js\";\n"],"mappings":";;;;;;;;;;;;AAAA,MAAa,cAAc;CACzB,mBAAmB;CACnB,aAAa;CACd;;;;ACQD,MAAM,mBAAmB,SAAS;;;;;;;;AASlC,MAAM,aAAa,OAAO,GAIxB;;;uBAGqB,UAAU,MAAM,iBAAiB;oBACpC,UAAU,MAAM,cAAc;;;;;OAK3C,UAAU,MAAM,iBAAiB;OACjC,UAAU,MAAM,kBAAkB;OAClC,UAAU,MAAM,iBAAiB;;;eAGzB,iBAAiB;;;;;AAMhC,SAAgB,iBAAiB,EAAE,OAAO,WAAW,kBAAyB;CAC5E,MAAM,kBAAkB;CACxB,MAAM,mBAAmB;CACzB,MAAM,eAAe,iBAAiB,QAAQ;CAE9C,MAAM,UAAU,cACR,CAAC,YAAY,aAAa,UAAU,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI,EACpE,CAAC,UAAU,CACZ;AAED,QACE,oBAAC;EACC,kBAAkB;EAClB,mBAAmB;EACnB,eAAe;EACf,OAAO,SAAS;EAChB,WAAW;EACX,aAAU;GACV;;;;;AC9CN,MAAM,yBAAyB,OAAO,GAAG;;;;;;sBAMnB,OAAO,SAAS;2BACX,OAAO,QAAQ;;;WAG/B,OAAO,SAAS;;AAG3B,MAAM,wBAAwB,OAAO,GAAG;;;;;AAMxC,MAAM,wBAAwB,OAAO,GAAG;;;;;;AAmBxC,IAAM,gBAAN,cAA4B,UAAwB;CAClD,QAAe;EACb,IAAI,YAAY;EAChB,UAAU;EACX;CAED,AAAQ;CAER,OAAO,yBAAyB,GAAiB;EAC/C,MAAM,QACJ,aAAa,QACT,IACA,IAAI,MACF,OAAO,MAAM,Y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,MAAM,eAAe,qBAAqB,KAAK;AAC/C,KAAI,aACF,cAAa,IAAI,MAAM,aAAa;KAEpC,iBAAgB,IAAI,MAAM,aAAa;AAEzC,QAAO;;AAGT,MAAM,qBAAqB,SAAgD;AACzE,KAAI,OAAO,SAAS,SAClB,QAAOG,mBAAU,kBAAkB,aAAa,KAAK;AAEvD,QACE,QAAQ,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;;AAIjE,SAAgB,OACd,MACA,OACA,KACA,kBACA,QACA,MACA;CACA,MAAM,WAAW,QAAQ;AACzB,KAAI;AACF,MAAI,YAAY,YAAY,IAAI,kBAAkB,KAAK,CAKrD,QAAO,YAJwB,+BAC7B,KACD,EAIC,OACA,GAAG,IAAI,GAAG,YACV,kBACA,QACA,KACD;UAEI,GAAG;AACV,UAAQ,MAAM,yBAAyB,EAAE;;AAE3C,QAAO,YAAY,MAAM,OAAO,KAAK,kBAAkB,QAAQ,KAAK;;;;;AC1FtE,MAAa,WAAY,mBAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["rootStore"],"sources":["../../src/jsx-dev-runtime/jsx-dev-runtime.ts","../../src/jsx-dev-runtime/index.ts"],"sourcesContent":["import { SOURCE_ID_ATTRIBUTE } from \"@superblocksteam/library-shared\";\nimport * as ReactJsxDevRuntime from \"react/jsx-dev-runtime\";\nimport { makeWrappedComponent } from \"../edit-mode/jsx-wrapper.js\";\nimport ApiHmrTracker from \"../lib/internal-details/lib/features/api-hmr-tracker.js\";\nimport rootStore from \"../lib/internal-details/lib/root-store.js\";\n\nconst reactJsxDEV = (ReactJsxDevRuntime as any).jsxDEV;\n\ndeclare global {\n interface Window {\n __SUPERBLOCKS_EDIT_MODE__?: boolean;\n _SB_VIEW_MODE?: string;\n }\n}\n\nfunction isEditMode(): boolean {\n if (typeof window === \"undefined\") return false;\n\n if (window.__SUPERBLOCKS_EDIT_MODE__ !== undefined) {\n return window.__SUPERBLOCKS_EDIT_MODE__;\n }\n\n const viewMode = window._SB_VIEW_MODE;\n if (viewMode === \"dev\") {\n window.__SUPERBLOCKS_EDIT_MODE__ = true;\n return true;\n }\n\n const envMode = import.meta.env?.MODE;\n const isEdit = envMode === \"local-dev\";\n window.__SUPERBLOCKS_EDIT_MODE__ = isEdit;\n return isEdit;\n}\n\nconst objTypeCache = new WeakMap<any, any>();\nconst stringTypeCache = new Map<string, any>();\n\ntype SupportedElementType = React.ElementType | string;\n\nfunction getOrSetCachedWrappedComponent(type: SupportedElementType) {\n const typeIsObject =\n (typeof type === \"object\" || typeof type === \"function\") && type !== null;\n const cachedType = typeIsObject\n ? objTypeCache.get(type)\n : stringTypeCache.get(type);\n if (cachedType) {\n return cachedType;\n }\n const newComponent = makeWrappedComponent(type);\n if (typeIsObject) {\n objTypeCache.set(type, newComponent);\n } else {\n stringTypeCache.set(type, newComponent);\n }\n return newComponent;\n}\n\nconst shouldWrapTagType = (type: unknown): type is SupportedElementType => {\n if (typeof type === \"string\") {\n return rootStore.componentRegistry.hasComponent(type);\n }\n return (\n type != null && (typeof type === \"object\" || typeof type === \"function\")\n );\n};\n\nexport function jsxDEV(\n type: any,\n props: any,\n key: any,\n isStaticChildren: any,\n source: any,\n self: any,\n) {\n const sourceId = props?.[SOURCE_ID_ATTRIBUTE];\n try {\n if (sourceId && isEditMode() && shouldWrapTagType(type)) {\n const CachedWrappedComponent = getOrSetCachedWrappedComponent(\n type satisfies SupportedElementType,\n );\n ApiHmrTracker.reportJSXActivity();\n return reactJsxDEV(\n CachedWrappedComponent,\n props,\n `${key}-${sourceId}`,\n isStaticChildren,\n source,\n self,\n );\n }\n } catch (e) {\n console.error(\"Error during JSX wrap\", e);\n }\n return reactJsxDEV(type, props, key, isStaticChildren, source, self);\n}\n","import * as ReactJsxDevRuntime from \"react/jsx-dev-runtime\";\n\nexport const Fragment = (ReactJsxDevRuntime as any).Fragment;\nexport { jsxDEV } from \"./jsx-dev-runtime.js\";\n"],"mappings":";;;;;;AAMA,MAAM,cAAe,mBAA2B;AAShD,SAA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