@depup/react-live 4.1.8-depup.0 → 5.0.0-depup.0
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/README.md +4 -11
- package/changes.json +3 -12
- package/dist/index.d.mts +166 -0
- package/dist/index.d.ts +152 -103
- package/dist/index.js +270 -381
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +244 -345
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -92
package/dist/index.mjs
CHANGED
|
@@ -1,366 +1,265 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/components/Editor/index.tsx
|
|
54
1
|
import { Highlight, themes } from "prism-react-renderer";
|
|
55
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import React, { Component, createContext, useContext, useEffect, useRef, useState } from "react";
|
|
56
3
|
import { useEditable } from "use-editable";
|
|
57
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
spellCheck: "false",
|
|
104
|
-
children: tokens.map((line, lineIndex) => /* @__PURE__ */ jsxs("span", __spreadProps(__spreadValues({}, getLineProps({ line })), { children: [
|
|
105
|
-
line.filter((token) => !token.empty).map((token, tokenIndex) => /* @__PURE__ */ jsx(
|
|
106
|
-
"span",
|
|
107
|
-
__spreadValues({}, getTokenProps({ token })),
|
|
108
|
-
`token-${tokenIndex}`
|
|
109
|
-
)),
|
|
110
|
-
"\n"
|
|
111
|
-
] }), `line-${lineIndex}`))
|
|
112
|
-
}
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
) });
|
|
5
|
+
import { transform } from "sucrase";
|
|
6
|
+
//#region src/components/Editor/index.tsx
|
|
7
|
+
const CodeEditor = (props) => {
|
|
8
|
+
const { tabMode = "indentation" } = props;
|
|
9
|
+
const editorRef = useRef(null);
|
|
10
|
+
const [code, setCode] = useState(props.code || "");
|
|
11
|
+
const { theme } = props;
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setCode(props.code);
|
|
14
|
+
}, [props.code]);
|
|
15
|
+
useEditable(editorRef, (text) => {
|
|
16
|
+
const t = text.slice(0, -1);
|
|
17
|
+
setCode(t);
|
|
18
|
+
if (props.onChange) props.onChange(t);
|
|
19
|
+
}, {
|
|
20
|
+
disabled: props.disabled,
|
|
21
|
+
indentation: tabMode === "indentation" ? 2 : void 0
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ jsx("div", {
|
|
24
|
+
className: props.className,
|
|
25
|
+
style: props.style,
|
|
26
|
+
children: /* @__PURE__ */ jsx(Highlight, {
|
|
27
|
+
code,
|
|
28
|
+
theme: props.theme || themes.nightOwl,
|
|
29
|
+
language: props.language,
|
|
30
|
+
prism: props.prism,
|
|
31
|
+
children: ({ className: _className, tokens, getLineProps, getTokenProps, style: _style }) => /* @__PURE__ */ jsx("pre", {
|
|
32
|
+
className: _className,
|
|
33
|
+
style: {
|
|
34
|
+
margin: 0,
|
|
35
|
+
outline: "none",
|
|
36
|
+
padding: 10,
|
|
37
|
+
fontFamily: "inherit",
|
|
38
|
+
...theme && typeof theme.plain === "object" ? theme.plain : {},
|
|
39
|
+
..._style
|
|
40
|
+
},
|
|
41
|
+
ref: editorRef,
|
|
42
|
+
spellCheck: "false",
|
|
43
|
+
children: tokens.map((line, lineIndex) => /* @__PURE__ */ jsxs("span", {
|
|
44
|
+
...getLineProps({ line }),
|
|
45
|
+
children: [line.filter((token) => !token.empty).map((token, tokenIndex) => /* @__PURE__ */ jsx("span", { ...getTokenProps({ token }) }, `token-${tokenIndex}`)), "\n"]
|
|
46
|
+
}, `line-${lineIndex}`))
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
});
|
|
116
50
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// src/utils/transpile/transform.ts
|
|
131
|
-
import { transform as _transform } from "sucrase";
|
|
132
|
-
var defaultTransforms = ["jsx", "imports"];
|
|
133
|
-
function transform(opts = {}) {
|
|
134
|
-
const transforms = Array.isArray(opts.transforms) ? opts.transforms.filter(Boolean) : defaultTransforms;
|
|
135
|
-
return (code) => _transform(code, { transforms }).code;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/components/Live/LiveContext.ts
|
|
53
|
+
const LiveContext = createContext({});
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/utils/transpile/transform.ts
|
|
56
|
+
const defaultTransforms = ["jsx", "imports"];
|
|
57
|
+
function transform$1(opts = {}) {
|
|
58
|
+
const transforms = Array.isArray(opts.transforms) ? opts.transforms.filter(Boolean) : defaultTransforms;
|
|
59
|
+
return (code) => transform(code, {
|
|
60
|
+
transforms,
|
|
61
|
+
production: true
|
|
62
|
+
}).code;
|
|
136
63
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/utils/transpile/errorBoundary.tsx
|
|
66
|
+
const errorBoundary = (Element, errorCallback) => {
|
|
67
|
+
return class ErrorBoundary extends Component {
|
|
68
|
+
state = { hasError: false };
|
|
69
|
+
static getDerivedStateFromError() {
|
|
70
|
+
return { hasError: true };
|
|
71
|
+
}
|
|
72
|
+
componentDidCatch(error) {
|
|
73
|
+
errorCallback(error);
|
|
74
|
+
}
|
|
75
|
+
render() {
|
|
76
|
+
if (this.state.hasError) return null;
|
|
77
|
+
return typeof Element === "function" ? /* @__PURE__ */ jsx(Element, {}) : React.isValidElement(Element) ? Element : null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
150
80
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return new Function(...scopeKeys, code)(...scopeValues);
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/utils/transpile/evalCode.ts
|
|
83
|
+
const evalCode = (code, scope) => {
|
|
84
|
+
const scopeKeys = Object.keys(scope);
|
|
85
|
+
const scopeValues = scopeKeys.map((key) => scope[key]);
|
|
86
|
+
return new Function(...scopeKeys, code)(...scopeValues);
|
|
158
87
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/utils/transpile/compose.ts
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new composite function that invokes the functions from right to left
|
|
92
|
+
*/
|
|
162
93
|
function compose(...functions) {
|
|
163
|
-
|
|
164
|
-
(acc, currentFn) => (...args) => acc(currentFn(...args))
|
|
165
|
-
);
|
|
94
|
+
return functions.reduce((acc, currentFn) => (...args) => acc(currentFn(...args)));
|
|
166
95
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)(code);
|
|
186
|
-
return errorBoundary_default(
|
|
187
|
-
evalCode_default(transformed, __spreadValues({ React: React2 }, scope)),
|
|
188
|
-
errorCallback
|
|
189
|
-
);
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/utils/transpile/index.ts
|
|
98
|
+
const trimCode = (code) => code.trim().replace(/;$/, "");
|
|
99
|
+
const wrapReturn = (code) => `return (${code})`;
|
|
100
|
+
const generateElement = ({ code = "", scope = {}, enableTypeScript = true }, errorCallback) => {
|
|
101
|
+
/**
|
|
102
|
+
* To enable TypeScript we need to transform the TS to JS code first,
|
|
103
|
+
* wrap the eval in a return statement, then transform any imports. The
|
|
104
|
+
* two-phase approach is required to do the implicit evaluation and not
|
|
105
|
+
* wrap leading Interface or Type statements in the return.
|
|
106
|
+
*/
|
|
107
|
+
const firstPassTransforms = ["jsx"];
|
|
108
|
+
if (enableTypeScript) firstPassTransforms.push("typescript");
|
|
109
|
+
const transformed = compose(transform$1({ transforms: ["imports"] }), trimCode, transform$1({ transforms: firstPassTransforms }), wrapReturn, trimCode)(code);
|
|
110
|
+
return errorBoundary(evalCode(transformed, {
|
|
111
|
+
React,
|
|
112
|
+
...scope
|
|
113
|
+
}), errorCallback);
|
|
190
114
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const transforms = ["jsx", "imports"];
|
|
205
|
-
enableTypeScript && transforms.splice(1, 0, "typescript");
|
|
206
|
-
evalCode_default(transform({ transforms })(code), __spreadProps(__spreadValues({ React: React2 }, scope), { render }));
|
|
115
|
+
const renderElementAsync = ({ code = "", scope = {}, enableTypeScript = true }, resultCallback, errorCallback) => {
|
|
116
|
+
const render = (element) => {
|
|
117
|
+
if (typeof element === "undefined") errorCallback(/* @__PURE__ */ new SyntaxError("`render` must be called with valid JSX."));
|
|
118
|
+
else resultCallback(errorBoundary(element, errorCallback));
|
|
119
|
+
};
|
|
120
|
+
if (!/render\s*\(/.test(code)) return errorCallback(/* @__PURE__ */ new SyntaxError("No-Inline evaluations must call `render`."));
|
|
121
|
+
const transforms = ["jsx", "imports"];
|
|
122
|
+
if (enableTypeScript) transforms.splice(1, 0, "typescript");
|
|
123
|
+
evalCode(transform$1({ transforms })(code), {
|
|
124
|
+
React,
|
|
125
|
+
...scope,
|
|
126
|
+
render
|
|
127
|
+
});
|
|
207
128
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
theme,
|
|
279
|
-
disabled,
|
|
280
|
-
onError,
|
|
281
|
-
onChange
|
|
282
|
-
}),
|
|
283
|
-
children
|
|
284
|
-
}
|
|
285
|
-
);
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/components/Live/LiveProvider.tsx
|
|
131
|
+
function LiveProvider({ children, code = "", language = "tsx", theme, enableTypeScript = true, disabled = false, scope, transformCode, noInline = false }) {
|
|
132
|
+
const [state, setState] = useState({
|
|
133
|
+
error: void 0,
|
|
134
|
+
element: void 0
|
|
135
|
+
});
|
|
136
|
+
async function transpileAsync(newCode) {
|
|
137
|
+
const errorCallback = (error) => {
|
|
138
|
+
setState((previousState) => ({
|
|
139
|
+
...previousState,
|
|
140
|
+
error: error.toString(),
|
|
141
|
+
element: void 0
|
|
142
|
+
}));
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
145
|
+
const transformResult = transformCode ? transformCode(newCode) : newCode;
|
|
146
|
+
try {
|
|
147
|
+
const transformedCode = await Promise.resolve(transformResult);
|
|
148
|
+
const renderElement = (element) => setState({
|
|
149
|
+
error: void 0,
|
|
150
|
+
element,
|
|
151
|
+
newCode
|
|
152
|
+
});
|
|
153
|
+
if (typeof transformedCode !== "string") throw new Error("Code failed to transform");
|
|
154
|
+
const input = {
|
|
155
|
+
code: transformedCode,
|
|
156
|
+
scope,
|
|
157
|
+
enableTypeScript
|
|
158
|
+
};
|
|
159
|
+
if (noInline) {
|
|
160
|
+
setState((previousState) => ({
|
|
161
|
+
...previousState,
|
|
162
|
+
error: void 0,
|
|
163
|
+
element: null
|
|
164
|
+
}));
|
|
165
|
+
renderElementAsync(input, renderElement, errorCallback);
|
|
166
|
+
} else renderElement(generateElement(input, errorCallback));
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return errorCallback(error);
|
|
169
|
+
}
|
|
170
|
+
} catch (e) {
|
|
171
|
+
errorCallback(e);
|
|
172
|
+
return Promise.resolve();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const onError = (error) => setState({ error: error.toString() });
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
transpileAsync(code).catch(onError);
|
|
178
|
+
}, [
|
|
179
|
+
code,
|
|
180
|
+
scope,
|
|
181
|
+
noInline,
|
|
182
|
+
transformCode
|
|
183
|
+
]);
|
|
184
|
+
const onChange = (newCode) => {
|
|
185
|
+
transpileAsync(newCode).catch(onError);
|
|
186
|
+
};
|
|
187
|
+
return /* @__PURE__ */ jsx(LiveContext.Provider, {
|
|
188
|
+
value: {
|
|
189
|
+
...state,
|
|
190
|
+
code,
|
|
191
|
+
language,
|
|
192
|
+
theme,
|
|
193
|
+
disabled,
|
|
194
|
+
onError,
|
|
195
|
+
onChange
|
|
196
|
+
},
|
|
197
|
+
children
|
|
198
|
+
});
|
|
286
199
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
// src/components/Live/LiveEditor.tsx
|
|
290
|
-
import { useContext } from "react";
|
|
291
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/components/Live/LiveEditor.tsx
|
|
292
202
|
function LiveEditor(props) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}, props)
|
|
303
|
-
);
|
|
203
|
+
const { code, language, theme, disabled, onChange } = useContext(LiveContext);
|
|
204
|
+
return /* @__PURE__ */ jsx(CodeEditor, {
|
|
205
|
+
theme,
|
|
206
|
+
code,
|
|
207
|
+
language,
|
|
208
|
+
disabled,
|
|
209
|
+
onChange,
|
|
210
|
+
...props
|
|
211
|
+
});
|
|
304
212
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
import { useContext as useContext2 } from "react";
|
|
308
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/components/Live/LiveError.tsx
|
|
309
215
|
function LiveError(props) {
|
|
310
|
-
|
|
311
|
-
|
|
216
|
+
const { error } = useContext(LiveContext);
|
|
217
|
+
return error ? /* @__PURE__ */ jsx("pre", {
|
|
218
|
+
...props,
|
|
219
|
+
children: error
|
|
220
|
+
}) : null;
|
|
312
221
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
render() {
|
|
332
|
-
if (this.state.hasError) {
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
return this.props.children;
|
|
336
|
-
}
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/components/Live/ErrorBoundary.tsx
|
|
224
|
+
var ErrorBoundary = class extends Component {
|
|
225
|
+
static getDerivedStateFromError() {
|
|
226
|
+
return { hasError: true };
|
|
227
|
+
}
|
|
228
|
+
constructor(props) {
|
|
229
|
+
super(props);
|
|
230
|
+
this.state = { hasError: false };
|
|
231
|
+
}
|
|
232
|
+
componentDidCatch(err) {
|
|
233
|
+
this.props.onError?.(err);
|
|
234
|
+
}
|
|
235
|
+
render() {
|
|
236
|
+
if (this.state.hasError) return null;
|
|
237
|
+
return this.props.children;
|
|
238
|
+
}
|
|
337
239
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/components/Live/LivePreview.tsx
|
|
242
|
+
function LivePreview({ Component = "div", ...rest }) {
|
|
243
|
+
const { element: Element, onError, newCode } = useContext(LiveContext);
|
|
244
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
245
|
+
onError,
|
|
246
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
247
|
+
...rest,
|
|
248
|
+
children: Element ? /* @__PURE__ */ jsx(Element, {}) : null
|
|
249
|
+
})
|
|
250
|
+
}, newCode);
|
|
345
251
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
// src/hoc/withLive.tsx
|
|
349
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/hoc/withLive.tsx
|
|
350
254
|
function withLive(WrappedComponent) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
255
|
+
const WithLive = (props) => /* @__PURE__ */ jsx(LiveContext.Consumer, { children: (live) => /* @__PURE__ */ jsx(WrappedComponent, {
|
|
256
|
+
live,
|
|
257
|
+
...props
|
|
258
|
+
}) });
|
|
259
|
+
WithLive.displayName = "WithLive";
|
|
260
|
+
return WithLive;
|
|
354
261
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
LiveEditor,
|
|
359
|
-
LiveError,
|
|
360
|
-
LivePreview_default as LivePreview,
|
|
361
|
-
LiveProvider_default as LiveProvider,
|
|
362
|
-
generateElement,
|
|
363
|
-
renderElementAsync,
|
|
364
|
-
withLive
|
|
365
|
-
};
|
|
262
|
+
//#endregion
|
|
263
|
+
export { CodeEditor as Editor, LiveContext, LiveEditor, LiveError, LivePreview, LiveProvider, generateElement, renderElementAsync, withLive };
|
|
264
|
+
|
|
366
265
|
//# sourceMappingURL=index.mjs.map
|