@depup/react-live 4.1.8-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/LICENSE +20 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +408 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +366 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +121 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @depup/react-live
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [react-live](https://www.npmjs.com/package/react-live)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/react-live
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [react-live](https://www.npmjs.com/package/react-live) @ 4.1.8 |
|
|
17
|
+
| Processed | 2026-03-18 |
|
|
18
|
+
| Smoke test | failed |
|
|
19
|
+
| Deps updated | 2 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| prism-react-renderer | ^2.4.0 | ^2.4.1 |
|
|
26
|
+
| sucrase | ^3.35.0 | ^3.35.1 |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/react-live
|
|
31
|
+
|
|
32
|
+
License inherited from the original package.
|
package/changes.json
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Prism, themes } from 'prism-react-renderer';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import React__default, { CSSProperties, PropsWithChildren, ComponentType } from 'react';
|
|
4
|
+
|
|
5
|
+
type Props$3 = {
|
|
6
|
+
className?: string;
|
|
7
|
+
code: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
language: string;
|
|
10
|
+
prism?: typeof Prism;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
tabMode?: "focus" | "indentation";
|
|
13
|
+
theme?: typeof themes.nightOwl;
|
|
14
|
+
onChange?(value: string): void;
|
|
15
|
+
};
|
|
16
|
+
declare const CodeEditor: (props: Props$3) => JSX.Element;
|
|
17
|
+
|
|
18
|
+
type Props$2 = {
|
|
19
|
+
code?: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
enableTypeScript?: boolean;
|
|
22
|
+
language?: string;
|
|
23
|
+
noInline?: boolean;
|
|
24
|
+
scope?: Record<string, unknown>;
|
|
25
|
+
theme?: typeof themes.nightOwl;
|
|
26
|
+
transformCode?(code: string): void;
|
|
27
|
+
};
|
|
28
|
+
declare function LiveProvider({ children, code, language, theme, enableTypeScript, disabled, scope, transformCode, noInline, }: PropsWithChildren<Props$2>): JSX.Element;
|
|
29
|
+
|
|
30
|
+
declare function LiveEditor(props: Partial<Props$3>): JSX.Element;
|
|
31
|
+
|
|
32
|
+
declare function LiveError<T extends Record<string, unknown>>(props: T): JSX.Element | null;
|
|
33
|
+
|
|
34
|
+
type Props$1<T extends React__default.ElementType = React__default.ElementType> = {
|
|
35
|
+
Component?: T;
|
|
36
|
+
} & React__default.ComponentPropsWithoutRef<T>;
|
|
37
|
+
declare function LivePreview<T extends keyof JSX.IntrinsicElements>(props: Props$1<T>): JSX.Element;
|
|
38
|
+
declare function LivePreview<T extends React__default.ElementType>(props: Props$1<T>): JSX.Element;
|
|
39
|
+
|
|
40
|
+
type ContextValue = {
|
|
41
|
+
error?: string;
|
|
42
|
+
element?: ComponentType | null;
|
|
43
|
+
code: string;
|
|
44
|
+
newCode?: string;
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
language: string;
|
|
47
|
+
theme?: typeof themes.nightOwl;
|
|
48
|
+
onError(error: Error): void;
|
|
49
|
+
onChange(value: string): void;
|
|
50
|
+
};
|
|
51
|
+
declare const LiveContext: React.Context<ContextValue>;
|
|
52
|
+
|
|
53
|
+
type Props = {
|
|
54
|
+
live: Record<string, unknown>;
|
|
55
|
+
};
|
|
56
|
+
declare function withLive<T>(WrappedComponent: ComponentType<T & Props>): {
|
|
57
|
+
(props: T): JSX.Element;
|
|
58
|
+
displayName: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type GenerateOptions = {
|
|
62
|
+
code: string;
|
|
63
|
+
scope?: Record<string, unknown>;
|
|
64
|
+
enableTypeScript: boolean;
|
|
65
|
+
};
|
|
66
|
+
declare const generateElement: ({ code, scope, enableTypeScript }: GenerateOptions, errorCallback: (error: Error) => void) => {
|
|
67
|
+
new (props: {} | Readonly<{}>): {
|
|
68
|
+
componentDidCatch(error: Error): void;
|
|
69
|
+
render(): JSX.Element | null;
|
|
70
|
+
context: unknown;
|
|
71
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
72
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
73
|
+
readonly props: Readonly<{}>;
|
|
74
|
+
state: Readonly<{}>;
|
|
75
|
+
refs: {
|
|
76
|
+
[key: string]: React__default.ReactInstance;
|
|
77
|
+
};
|
|
78
|
+
componentDidMount?(): void;
|
|
79
|
+
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
80
|
+
componentWillUnmount?(): void;
|
|
81
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any;
|
|
82
|
+
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void;
|
|
83
|
+
componentWillMount?(): void;
|
|
84
|
+
UNSAFE_componentWillMount?(): void;
|
|
85
|
+
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
86
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
87
|
+
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
88
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
89
|
+
};
|
|
90
|
+
new (props: {}, context: any): {
|
|
91
|
+
componentDidCatch(error: Error): void;
|
|
92
|
+
render(): JSX.Element | null;
|
|
93
|
+
context: unknown;
|
|
94
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
95
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
96
|
+
readonly props: Readonly<{}>;
|
|
97
|
+
state: Readonly<{}>;
|
|
98
|
+
refs: {
|
|
99
|
+
[key: string]: React__default.ReactInstance;
|
|
100
|
+
};
|
|
101
|
+
componentDidMount?(): void;
|
|
102
|
+
shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
103
|
+
componentWillUnmount?(): void;
|
|
104
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any;
|
|
105
|
+
componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void;
|
|
106
|
+
componentWillMount?(): void;
|
|
107
|
+
UNSAFE_componentWillMount?(): void;
|
|
108
|
+
componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
109
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
|
|
110
|
+
componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
111
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
|
|
112
|
+
};
|
|
113
|
+
contextType?: React__default.Context<any> | undefined;
|
|
114
|
+
};
|
|
115
|
+
declare const renderElementAsync: ({ code, scope, enableTypeScript }: GenerateOptions, resultCallback: (sender: ComponentType) => void, errorCallback: (error: Error) => void) => void;
|
|
116
|
+
|
|
117
|
+
export { CodeEditor as Editor, LiveContext, LiveEditor, LiveError, LivePreview, LiveProvider, generateElement, renderElementAsync, withLive };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
var __async = (__this, __arguments, generator) => {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
var fulfilled = (value) => {
|
|
61
|
+
try {
|
|
62
|
+
step(generator.next(value));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
reject(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var rejected = (value) => {
|
|
68
|
+
try {
|
|
69
|
+
step(generator.throw(value));
|
|
70
|
+
} catch (e) {
|
|
71
|
+
reject(e);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/index.ts
|
|
80
|
+
var src_exports = {};
|
|
81
|
+
__export(src_exports, {
|
|
82
|
+
Editor: () => Editor_default,
|
|
83
|
+
LiveContext: () => LiveContext_default,
|
|
84
|
+
LiveEditor: () => LiveEditor,
|
|
85
|
+
LiveError: () => LiveError,
|
|
86
|
+
LivePreview: () => LivePreview_default,
|
|
87
|
+
LiveProvider: () => LiveProvider_default,
|
|
88
|
+
generateElement: () => generateElement,
|
|
89
|
+
renderElementAsync: () => renderElementAsync,
|
|
90
|
+
withLive: () => withLive
|
|
91
|
+
});
|
|
92
|
+
module.exports = __toCommonJS(src_exports);
|
|
93
|
+
|
|
94
|
+
// src/components/Editor/index.tsx
|
|
95
|
+
var import_prism_react_renderer = require("prism-react-renderer");
|
|
96
|
+
var import_react = require("react");
|
|
97
|
+
var import_use_editable = require("use-editable");
|
|
98
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
99
|
+
var CodeEditor = (props) => {
|
|
100
|
+
const { tabMode = "indentation" } = props;
|
|
101
|
+
const editorRef = (0, import_react.useRef)(null);
|
|
102
|
+
const [code, setCode] = (0, import_react.useState)(props.code || "");
|
|
103
|
+
const { theme } = props;
|
|
104
|
+
(0, import_react.useEffect)(() => {
|
|
105
|
+
setCode(props.code);
|
|
106
|
+
}, [props.code]);
|
|
107
|
+
(0, import_use_editable.useEditable)(
|
|
108
|
+
editorRef,
|
|
109
|
+
(text) => {
|
|
110
|
+
const t = text.slice(0, -1);
|
|
111
|
+
setCode(t);
|
|
112
|
+
if (props.onChange) {
|
|
113
|
+
props.onChange(t);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
disabled: props.disabled,
|
|
118
|
+
indentation: tabMode === "indentation" ? 2 : void 0
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: props.className, style: props.style, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
122
|
+
import_prism_react_renderer.Highlight,
|
|
123
|
+
{
|
|
124
|
+
code,
|
|
125
|
+
theme: props.theme || import_prism_react_renderer.themes.nightOwl,
|
|
126
|
+
language: props.language,
|
|
127
|
+
children: ({
|
|
128
|
+
className: _className,
|
|
129
|
+
tokens,
|
|
130
|
+
getLineProps,
|
|
131
|
+
getTokenProps,
|
|
132
|
+
style: _style
|
|
133
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
134
|
+
"pre",
|
|
135
|
+
{
|
|
136
|
+
className: _className,
|
|
137
|
+
style: __spreadValues(__spreadValues({
|
|
138
|
+
margin: 0,
|
|
139
|
+
outline: "none",
|
|
140
|
+
padding: 10,
|
|
141
|
+
fontFamily: "inherit"
|
|
142
|
+
}, theme && typeof theme.plain === "object" ? theme.plain : {}), _style),
|
|
143
|
+
ref: editorRef,
|
|
144
|
+
spellCheck: "false",
|
|
145
|
+
children: tokens.map((line, lineIndex) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", __spreadProps(__spreadValues({}, getLineProps({ line })), { children: [
|
|
146
|
+
line.filter((token) => !token.empty).map((token, tokenIndex) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
147
|
+
"span",
|
|
148
|
+
__spreadValues({}, getTokenProps({ token })),
|
|
149
|
+
`token-${tokenIndex}`
|
|
150
|
+
)),
|
|
151
|
+
"\n"
|
|
152
|
+
] }), `line-${lineIndex}`))
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
) });
|
|
157
|
+
};
|
|
158
|
+
var Editor_default = CodeEditor;
|
|
159
|
+
|
|
160
|
+
// src/components/Live/LiveProvider.tsx
|
|
161
|
+
var import_react5 = require("react");
|
|
162
|
+
|
|
163
|
+
// src/components/Live/LiveContext.ts
|
|
164
|
+
var import_react2 = require("react");
|
|
165
|
+
var LiveContext = (0, import_react2.createContext)({});
|
|
166
|
+
var LiveContext_default = LiveContext;
|
|
167
|
+
|
|
168
|
+
// src/utils/transpile/index.ts
|
|
169
|
+
var import_react4 = __toESM(require("react"));
|
|
170
|
+
|
|
171
|
+
// src/utils/transpile/transform.ts
|
|
172
|
+
var import_sucrase = require("sucrase");
|
|
173
|
+
var defaultTransforms = ["jsx", "imports"];
|
|
174
|
+
function transform(opts = {}) {
|
|
175
|
+
const transforms = Array.isArray(opts.transforms) ? opts.transforms.filter(Boolean) : defaultTransforms;
|
|
176
|
+
return (code) => (0, import_sucrase.transform)(code, { transforms }).code;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/utils/transpile/errorBoundary.tsx
|
|
180
|
+
var import_react3 = __toESM(require("react"));
|
|
181
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
182
|
+
var errorBoundary = (Element, errorCallback) => {
|
|
183
|
+
return class ErrorBoundary extends import_react3.Component {
|
|
184
|
+
componentDidCatch(error) {
|
|
185
|
+
errorCallback(error);
|
|
186
|
+
}
|
|
187
|
+
render() {
|
|
188
|
+
return typeof Element === "function" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Element, {}) : import_react3.default.isValidElement(Element) ? Element : null;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
var errorBoundary_default = errorBoundary;
|
|
193
|
+
|
|
194
|
+
// src/utils/transpile/evalCode.ts
|
|
195
|
+
var evalCode = (code, scope) => {
|
|
196
|
+
const scopeKeys = Object.keys(scope);
|
|
197
|
+
const scopeValues = scopeKeys.map((key) => scope[key]);
|
|
198
|
+
return new Function(...scopeKeys, code)(...scopeValues);
|
|
199
|
+
};
|
|
200
|
+
var evalCode_default = evalCode;
|
|
201
|
+
|
|
202
|
+
// src/utils/transpile/compose.ts
|
|
203
|
+
function compose(...functions) {
|
|
204
|
+
return functions.reduce(
|
|
205
|
+
(acc, currentFn) => (...args) => acc(currentFn(...args))
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/utils/transpile/index.ts
|
|
210
|
+
var jsxConst = 'const _jsxFileName = "";';
|
|
211
|
+
var trimCode = (code) => code.trim().replace(/;$/, "");
|
|
212
|
+
var spliceJsxConst = (code) => code.replace(jsxConst, "").trim();
|
|
213
|
+
var addJsxConst = (code) => jsxConst + code;
|
|
214
|
+
var wrapReturn = (code) => `return (${code})`;
|
|
215
|
+
var generateElement = ({ code = "", scope = {}, enableTypeScript = true }, errorCallback) => {
|
|
216
|
+
const firstPassTransforms = ["jsx"];
|
|
217
|
+
enableTypeScript && firstPassTransforms.push("typescript");
|
|
218
|
+
const transformed = compose(
|
|
219
|
+
addJsxConst,
|
|
220
|
+
transform({ transforms: ["imports"] }),
|
|
221
|
+
spliceJsxConst,
|
|
222
|
+
trimCode,
|
|
223
|
+
transform({ transforms: firstPassTransforms }),
|
|
224
|
+
wrapReturn,
|
|
225
|
+
trimCode
|
|
226
|
+
)(code);
|
|
227
|
+
return errorBoundary_default(
|
|
228
|
+
evalCode_default(transformed, __spreadValues({ React: import_react4.default }, scope)),
|
|
229
|
+
errorCallback
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
var renderElementAsync = ({ code = "", scope = {}, enableTypeScript = true }, resultCallback, errorCallback) => {
|
|
233
|
+
const render = (element) => {
|
|
234
|
+
if (typeof element === "undefined") {
|
|
235
|
+
errorCallback(new SyntaxError("`render` must be called with valid JSX."));
|
|
236
|
+
} else {
|
|
237
|
+
resultCallback(errorBoundary_default(element, errorCallback));
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
if (!/render\s*\(/.test(code)) {
|
|
241
|
+
return errorCallback(
|
|
242
|
+
new SyntaxError("No-Inline evaluations must call `render`.")
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const transforms = ["jsx", "imports"];
|
|
246
|
+
enableTypeScript && transforms.splice(1, 0, "typescript");
|
|
247
|
+
evalCode_default(transform({ transforms })(code), __spreadProps(__spreadValues({ React: import_react4.default }, scope), { render }));
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// src/components/Live/LiveProvider.tsx
|
|
251
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
252
|
+
function LiveProvider({
|
|
253
|
+
children,
|
|
254
|
+
code = "",
|
|
255
|
+
language = "tsx",
|
|
256
|
+
theme,
|
|
257
|
+
enableTypeScript = true,
|
|
258
|
+
disabled = false,
|
|
259
|
+
scope,
|
|
260
|
+
transformCode,
|
|
261
|
+
noInline = false
|
|
262
|
+
}) {
|
|
263
|
+
const [state, setState] = (0, import_react5.useState)({
|
|
264
|
+
error: void 0,
|
|
265
|
+
element: void 0
|
|
266
|
+
});
|
|
267
|
+
function transpileAsync(newCode) {
|
|
268
|
+
return __async(this, null, function* () {
|
|
269
|
+
const errorCallback = (error) => {
|
|
270
|
+
setState((previousState) => __spreadProps(__spreadValues({}, previousState), {
|
|
271
|
+
error: error.toString(),
|
|
272
|
+
element: void 0
|
|
273
|
+
}));
|
|
274
|
+
};
|
|
275
|
+
try {
|
|
276
|
+
const transformResult = transformCode ? transformCode(newCode) : newCode;
|
|
277
|
+
try {
|
|
278
|
+
const transformedCode = yield Promise.resolve(transformResult);
|
|
279
|
+
const renderElement = (element) => setState({ error: void 0, element, newCode });
|
|
280
|
+
if (typeof transformedCode !== "string") {
|
|
281
|
+
throw new Error("Code failed to transform");
|
|
282
|
+
}
|
|
283
|
+
const input = {
|
|
284
|
+
code: transformedCode,
|
|
285
|
+
scope,
|
|
286
|
+
enableTypeScript
|
|
287
|
+
};
|
|
288
|
+
if (noInline) {
|
|
289
|
+
setState((previousState) => __spreadProps(__spreadValues({}, previousState), {
|
|
290
|
+
error: void 0,
|
|
291
|
+
element: null
|
|
292
|
+
}));
|
|
293
|
+
renderElementAsync(input, renderElement, errorCallback);
|
|
294
|
+
} else {
|
|
295
|
+
renderElement(generateElement(input, errorCallback));
|
|
296
|
+
}
|
|
297
|
+
} catch (error) {
|
|
298
|
+
return errorCallback(error);
|
|
299
|
+
}
|
|
300
|
+
} catch (e) {
|
|
301
|
+
errorCallback(e);
|
|
302
|
+
return Promise.resolve();
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
const onError = (error) => setState({ error: error.toString() });
|
|
307
|
+
(0, import_react5.useEffect)(() => {
|
|
308
|
+
transpileAsync(code).catch(onError);
|
|
309
|
+
}, [code, scope, noInline, transformCode]);
|
|
310
|
+
const onChange = (newCode) => {
|
|
311
|
+
transpileAsync(newCode).catch(onError);
|
|
312
|
+
};
|
|
313
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
314
|
+
LiveContext_default.Provider,
|
|
315
|
+
{
|
|
316
|
+
value: __spreadProps(__spreadValues({}, state), {
|
|
317
|
+
code,
|
|
318
|
+
language,
|
|
319
|
+
theme,
|
|
320
|
+
disabled,
|
|
321
|
+
onError,
|
|
322
|
+
onChange
|
|
323
|
+
}),
|
|
324
|
+
children
|
|
325
|
+
}
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
var LiveProvider_default = LiveProvider;
|
|
329
|
+
|
|
330
|
+
// src/components/Live/LiveEditor.tsx
|
|
331
|
+
var import_react6 = require("react");
|
|
332
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
333
|
+
function LiveEditor(props) {
|
|
334
|
+
const { code, language, theme, disabled, onChange } = (0, import_react6.useContext)(LiveContext_default);
|
|
335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
336
|
+
Editor_default,
|
|
337
|
+
__spreadValues({
|
|
338
|
+
theme,
|
|
339
|
+
code,
|
|
340
|
+
language,
|
|
341
|
+
disabled,
|
|
342
|
+
onChange
|
|
343
|
+
}, props)
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/components/Live/LiveError.tsx
|
|
348
|
+
var import_react7 = require("react");
|
|
349
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
350
|
+
function LiveError(props) {
|
|
351
|
+
const { error } = (0, import_react7.useContext)(LiveContext_default);
|
|
352
|
+
return error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", __spreadProps(__spreadValues({}, props), { children: error })) : null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/components/Live/LivePreview.tsx
|
|
356
|
+
var import_react9 = require("react");
|
|
357
|
+
|
|
358
|
+
// src/components/Live/ErrorBoundary.tsx
|
|
359
|
+
var import_react8 = require("react");
|
|
360
|
+
var ErrorBoundary = class extends import_react8.Component {
|
|
361
|
+
static getDerivedStateFromError() {
|
|
362
|
+
return { hasError: true };
|
|
363
|
+
}
|
|
364
|
+
constructor(props) {
|
|
365
|
+
super(props);
|
|
366
|
+
this.state = { hasError: false };
|
|
367
|
+
}
|
|
368
|
+
componentDidCatch(err) {
|
|
369
|
+
var _a, _b;
|
|
370
|
+
(_b = (_a = this.props).onError) == null ? void 0 : _b.call(_a, err);
|
|
371
|
+
}
|
|
372
|
+
render() {
|
|
373
|
+
if (this.state.hasError) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return this.props.children;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// src/components/Live/LivePreview.tsx
|
|
381
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
382
|
+
function LivePreview(_a) {
|
|
383
|
+
var _b = _a, { Component: Component3 = "div" } = _b, rest = __objRest(_b, ["Component"]);
|
|
384
|
+
const { element: Element, onError, newCode } = (0, import_react9.useContext)(LiveContext_default);
|
|
385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Component3, __spreadProps(__spreadValues({}, rest), { children: Element ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Element, {}) : null })) }, newCode);
|
|
386
|
+
}
|
|
387
|
+
var LivePreview_default = LivePreview;
|
|
388
|
+
|
|
389
|
+
// src/hoc/withLive.tsx
|
|
390
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
391
|
+
function withLive(WrappedComponent) {
|
|
392
|
+
const WithLive = (props) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LiveContext_default.Consumer, { children: (live) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(WrappedComponent, __spreadValues({ live }, props)) });
|
|
393
|
+
WithLive.displayName = "WithLive";
|
|
394
|
+
return WithLive;
|
|
395
|
+
}
|
|
396
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
397
|
+
0 && (module.exports = {
|
|
398
|
+
Editor,
|
|
399
|
+
LiveContext,
|
|
400
|
+
LiveEditor,
|
|
401
|
+
LiveError,
|
|
402
|
+
LivePreview,
|
|
403
|
+
LiveProvider,
|
|
404
|
+
generateElement,
|
|
405
|
+
renderElementAsync,
|
|
406
|
+
withLive
|
|
407
|
+
});
|
|
408
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/Editor/index.tsx","../src/components/Live/LiveProvider.tsx","../src/components/Live/LiveContext.ts","../src/utils/transpile/index.ts","../src/utils/transpile/transform.ts","../src/utils/transpile/errorBoundary.tsx","../src/utils/transpile/evalCode.ts","../src/utils/transpile/compose.ts","../src/components/Live/LiveEditor.tsx","../src/components/Live/LiveError.tsx","../src/components/Live/LivePreview.tsx","../src/components/Live/ErrorBoundary.tsx","../src/hoc/withLive.tsx"],"sourcesContent":["import Editor from \"./components/Editor\";\n\nimport LiveProvider from \"./components/Live/LiveProvider\";\nimport LiveEditor from \"./components/Live/LiveEditor\";\nimport LiveError from \"./components/Live/LiveError\";\nimport LivePreview from \"./components/Live/LivePreview\";\nimport LiveContext from \"./components/Live/LiveContext\";\n\nimport withLive from \"./hoc/withLive\";\n\nexport * from \"./utils/transpile\";\n\nexport {\n Editor,\n // Main exports:\n LiveProvider,\n LiveEditor,\n LiveError,\n LivePreview,\n LiveContext,\n withLive,\n};\n","import { Highlight, Prism, themes } from \"prism-react-renderer\";\nimport { CSSProperties, useEffect, useRef, useState } from \"react\";\nimport { useEditable } from \"use-editable\";\n\nexport type Props = {\n className?: string;\n code: string;\n disabled?: boolean;\n language: string;\n prism?: typeof Prism;\n style?: CSSProperties;\n tabMode?: \"focus\" | \"indentation\";\n theme?: typeof themes.nightOwl;\n onChange?(value: string): void;\n};\n\nconst CodeEditor = (props: Props) => {\n const { tabMode = \"indentation\" } = props;\n const editorRef = useRef(null);\n const [code, setCode] = useState(props.code || \"\");\n const { theme } = props;\n\n useEffect(() => {\n setCode(props.code);\n }, [props.code]);\n\n useEditable(\n editorRef,\n (text) => {\n const t = text.slice(0, -1);\n setCode(t);\n\n if (props.onChange) {\n props.onChange(t);\n }\n },\n {\n disabled: props.disabled,\n indentation: tabMode === \"indentation\" ? 2 : undefined,\n }\n );\n\n return (\n <div className={props.className} style={props.style}>\n <Highlight\n code={code}\n theme={props.theme || themes.nightOwl}\n language={props.language}\n >\n {({\n className: _className,\n tokens,\n getLineProps,\n getTokenProps,\n style: _style,\n }) => (\n <pre\n className={_className}\n style={{\n margin: 0,\n outline: \"none\",\n padding: 10,\n fontFamily: \"inherit\",\n ...(theme && typeof theme.plain === \"object\" ? theme.plain : {}),\n ..._style,\n }}\n ref={editorRef}\n spellCheck=\"false\"\n >\n {tokens.map((line, lineIndex) => (\n <span key={`line-${lineIndex}`} {...getLineProps({ line })}>\n {line\n .filter((token) => !token.empty)\n .map((token, tokenIndex) => (\n <span\n key={`token-${tokenIndex}`}\n {...getTokenProps({ token })}\n />\n ))}\n {\"\\n\"}\n </span>\n ))}\n </pre>\n )}\n </Highlight>\n </div>\n );\n};\n\nexport default CodeEditor;\n","import { useEffect, useState, ComponentType, PropsWithChildren } from \"react\";\nimport LiveContext from \"./LiveContext\";\nimport { generateElement, renderElementAsync } from \"../../utils/transpile\";\nimport { themes } from \"prism-react-renderer\";\n\ntype ProviderState = {\n element?: ComponentType | null;\n error?: string;\n newCode?: string;\n};\n\ntype Props = {\n code?: string;\n disabled?: boolean;\n enableTypeScript?: boolean;\n language?: string;\n noInline?: boolean;\n scope?: Record<string, unknown>;\n theme?: typeof themes.nightOwl;\n transformCode?(code: string): void;\n};\n\nfunction LiveProvider({\n children,\n code = \"\",\n language = \"tsx\",\n theme,\n enableTypeScript = true,\n disabled = false,\n scope,\n transformCode,\n noInline = false,\n}: PropsWithChildren<Props>) {\n const [state, setState] = useState<ProviderState>({\n error: undefined,\n element: undefined,\n });\n\n async function transpileAsync(newCode: string) {\n const errorCallback = (error: Error) => {\n setState((previousState) => ({\n ...previousState,\n error: error.toString(),\n element: undefined,\n }));\n };\n\n // - transformCode may be synchronous or asynchronous.\n // - transformCode may throw an exception or return a rejected promise, e.g.\n // if newCode is invalid and cannot be transformed.\n // - Not using async-await to since it requires targeting ES 2017 or\n // importing regenerator-runtime... in the next major version of\n // react-live, should target ES 2017+\n try {\n const transformResult = transformCode ? transformCode(newCode) : newCode;\n try {\n const transformedCode = await Promise.resolve(transformResult);\n const renderElement = (element: ComponentType) =>\n setState({ error: undefined, element, newCode });\n\n if (typeof transformedCode !== \"string\") {\n throw new Error(\"Code failed to transform\");\n }\n\n // Transpilation arguments\n const input = {\n code: transformedCode,\n scope,\n enableTypeScript,\n };\n\n if (noInline) {\n setState((previousState) => ({\n ...previousState,\n error: undefined,\n element: null,\n })); // Reset output for async (no inline) evaluation\n renderElementAsync(input, renderElement, errorCallback);\n } else {\n renderElement(generateElement(input, errorCallback));\n }\n } catch (error) {\n return errorCallback(error as Error);\n }\n } catch (e) {\n errorCallback(e as Error);\n return Promise.resolve();\n }\n }\n\n const onError = (error: Error) => setState({ error: error.toString() });\n\n useEffect(() => {\n transpileAsync(code).catch(onError);\n }, [code, scope, noInline, transformCode]);\n\n const onChange = (newCode: string) => {\n transpileAsync(newCode).catch(onError);\n };\n\n return (\n <LiveContext.Provider\n value={{\n ...state,\n code,\n language,\n theme,\n disabled,\n onError,\n onChange,\n }}\n >\n {children}\n </LiveContext.Provider>\n );\n}\n\nexport default LiveProvider;\n","import { themes } from \"prism-react-renderer\";\nimport { ComponentType, createContext } from \"react\";\n\ntype ContextValue = {\n error?: string;\n element?: ComponentType | null;\n code: string;\n newCode?: string;\n disabled: boolean;\n language: string;\n theme?: typeof themes.nightOwl;\n onError(error: Error): void;\n onChange(value: string): void;\n};\n\nconst LiveContext = createContext<ContextValue>({} as ContextValue);\n\nexport default LiveContext;\n","import React, { ComponentType } from \"react\";\nimport transform from \"./transform\";\nimport errorBoundary from \"./errorBoundary\";\nimport evalCode from \"./evalCode\";\nimport compose from \"./compose\";\nimport { Transform } from \"sucrase\";\n\nconst jsxConst = 'const _jsxFileName = \"\";';\nconst trimCode = (code: string) => code.trim().replace(/;$/, \"\");\nconst spliceJsxConst = (code: string) => code.replace(jsxConst, \"\").trim();\nconst addJsxConst = (code: string) => jsxConst + code;\nconst wrapReturn = (code: string) => `return (${code})`;\n\ntype GenerateOptions = {\n code: string;\n scope?: Record<string, unknown>;\n enableTypeScript: boolean;\n};\n\nexport const generateElement = (\n { code = \"\", scope = {}, enableTypeScript = true }: GenerateOptions,\n errorCallback: (error: Error) => void\n) => {\n /**\n * To enable TypeScript we need to transform the TS to JS code first,\n * splice off the JSX const, wrap the eval in a return statement, then\n * transform any imports. The two-phase approach is required to do\n * the implicit evaluation and not wrap leading Interface or Type\n * statements in the return.\n */\n\n const firstPassTransforms: Transform[] = [\"jsx\"];\n enableTypeScript && firstPassTransforms.push(\"typescript\");\n\n const transformed = compose<string>(\n addJsxConst,\n transform({ transforms: [\"imports\"] }),\n spliceJsxConst,\n trimCode,\n transform({ transforms: firstPassTransforms }),\n wrapReturn,\n trimCode\n )(code);\n\n return errorBoundary(\n evalCode(transformed, { React, ...scope }),\n errorCallback\n );\n};\n\nexport const renderElementAsync = (\n { code = \"\", scope = {}, enableTypeScript = true }: GenerateOptions,\n resultCallback: (sender: ComponentType) => void,\n errorCallback: (error: Error) => void\n // eslint-disable-next-line consistent-return\n) => {\n const render = (element: ComponentType) => {\n if (typeof element === \"undefined\") {\n errorCallback(new SyntaxError(\"`render` must be called with valid JSX.\"));\n } else {\n resultCallback(errorBoundary(element, errorCallback));\n }\n };\n\n if (!/render\\s*\\(/.test(code)) {\n return errorCallback(\n new SyntaxError(\"No-Inline evaluations must call `render`.\")\n );\n }\n\n const transforms: Transform[] = [\"jsx\", \"imports\"];\n enableTypeScript && transforms.splice(1, 0, \"typescript\");\n\n evalCode(transform({ transforms })(code), { React, ...scope, render });\n};\n","import { transform as _transform, Transform } from \"sucrase\";\n\nconst defaultTransforms: Transform[] = [\"jsx\", \"imports\"];\n\ntype Options = {\n transforms?: Transform[];\n};\n\nexport default function transform(opts: Options = {}) {\n const transforms = Array.isArray(opts.transforms)\n ? opts.transforms.filter(Boolean)\n : defaultTransforms;\n\n return (code: string) => _transform(code, { transforms }).code;\n}\n","import React, { ComponentType, Component } from \"react\";\n\nconst errorBoundary = (\n Element: ComponentType,\n errorCallback: (error: Error) => void\n) => {\n return class ErrorBoundary extends Component {\n componentDidCatch(error: Error) {\n errorCallback(error);\n }\n\n render() {\n return typeof Element === \"function\" ? (\n <Element />\n ) : React.isValidElement(Element) ? (\n Element\n ) : null;\n }\n };\n};\n\nexport default errorBoundary;\n","import type { ComponentType } from \"react\";\n\nconst evalCode = (\n code: string,\n scope: Record<string, unknown>\n): ComponentType => {\n const scopeKeys = Object.keys(scope);\n const scopeValues = scopeKeys.map((key) => scope[key]);\n return new Function(...scopeKeys, code)(...scopeValues);\n};\n\nexport default evalCode;\n","/**\n * Creates a new composite function that invokes the functions from right to left\n */\n\nexport default function compose<T>(...functions: ((...args: T[]) => T)[]) {\n return functions.reduce(\n (acc, currentFn) =>\n (...args: T[]) =>\n acc(currentFn(...args))\n );\n}\n","import React, { useContext } from \"react\";\nimport LiveContext from \"./LiveContext\";\nimport Editor, { Props as EditorProps } from \"../Editor\";\n\nexport default function LiveEditor(props: Partial<EditorProps>) {\n const { code, language, theme, disabled, onChange } = useContext(LiveContext);\n\n return (\n <Editor\n theme={theme}\n code={code}\n language={language}\n disabled={disabled}\n onChange={onChange}\n {...props}\n />\n );\n}\n","import React, { useContext } from \"react\";\nimport LiveContext from \"./LiveContext\";\n\nexport default function LiveError<T extends Record<string, unknown>>(props: T) {\n const { error } = useContext(LiveContext);\n return error ? <pre {...props}>{error}</pre> : null;\n}\n","import React, { useContext } from \"react\";\n\nimport { ErrorBoundary } from \"./ErrorBoundary\";\nimport LiveContext from \"./LiveContext\";\n\ntype Props<T extends React.ElementType = React.ElementType> = {\n Component?: T;\n} & React.ComponentPropsWithoutRef<T>;\n\nfunction LivePreview<T extends keyof JSX.IntrinsicElements>(\n props: Props<T>\n): JSX.Element;\nfunction LivePreview<T extends React.ElementType>(props: Props<T>): JSX.Element;\n\nfunction LivePreview({ Component = \"div\", ...rest }: Props): JSX.Element {\n const { element: Element, onError, newCode } = useContext(LiveContext);\n\n return (\n <ErrorBoundary key={newCode} onError={onError}>\n <Component {...rest}>{Element ? <Element /> : null}</Component>\n </ErrorBoundary>\n );\n}\nexport default LivePreview;\n","import { Component, ReactNode } from \"react\";\n\ntype Props = {\n children: ReactNode;\n onError?: (error: Error) => void;\n};\n\ntype State = {\n hasError: boolean;\n};\n\nexport class ErrorBoundary extends Component<Props, State> {\n static getDerivedStateFromError() {\n return { hasError: true };\n }\n\n constructor(props: Props) {\n super(props);\n this.state = { hasError: false };\n }\n\n componentDidCatch(err: Error): void {\n this.props.onError?.(err);\n }\n\n render() {\n if (this.state.hasError) {\n return null;\n }\n\n return this.props.children;\n }\n}\n","import React, { ComponentType } from \"react\";\nimport LiveContext from \"../components/Live/LiveContext\";\n\ntype Props = {\n live: Record<string, unknown>;\n};\n\nexport default function withLive<T>(\n WrappedComponent: ComponentType<T & Props>\n) {\n const WithLive = (props: T) => (\n <LiveContext.Consumer>\n {(live) => <WrappedComponent live={live} {...props} />}\n </LiveContext.Consumer>\n );\n\n WithLive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,gBAAN,cAA4B,wBAAwB;AAAA,EACzD,OAAO,2BAA2B;AAChC,WAAO,EAAE,UAAU,KAAK;AAAA,EAC1B;AAAA,EAEA,YAAY,OAAc;AACxB,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,UAAU,MAAM;AAAA,EACjC;AAAA,EAEA,kBAAkB,KAAkB;AArBtC;AAsBI,qBAAK,OAAM,YAAX,4BAAqB;AAAA,EACvB;AAAA,EAEA,SAAS;AACP,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO;AAAA,IACT;AAEA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;;;ADbsC,IAAAC,sBAAA;AALtC,SAAS,YAAY,IAAoD;AAApD,eAAE,aAAAC,aAAY,MAdnC,IAcqB,IAAwB,iBAAxB,IAAwB,CAAtB;AACrB,QAAM,EAAE,SAAS,SAAS,SAAS,QAAQ,QAAI,0BAAW,mBAAW;AAErE,SACE,6CAAC,iBAA4B,SAC3B,uDAACA,YAAA,iCAAc,OAAd,EAAqB,oBAAU,6CAAC,WAAQ,IAAK,OAAK,KADjC,OAEpB;AAEJ;AACA,IAAO,sBAAQ;;;AEXE,IAAAC,sBAAA;AALF,SAAR,SACL,kBACA;AACA,QAAM,WAAW,CAAC,UAChB,6CAAC,oBAAY,UAAZ,EACE,WAAC,SAAS,6CAAC,mCAAiB,QAAgB,MAAO,GACtD;AAGF,WAAS,cAAc;AACvB,SAAO;AACT;","names":["import_react","import_react","import_react","_transform","import_react","import_jsx_runtime","React","React","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_react","import_jsx_runtime","Component","import_jsx_runtime"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
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
|
+
import { Highlight, themes } from "prism-react-renderer";
|
|
55
|
+
import { useEffect, useRef, useState } from "react";
|
|
56
|
+
import { useEditable } from "use-editable";
|
|
57
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
58
|
+
var CodeEditor = (props) => {
|
|
59
|
+
const { tabMode = "indentation" } = props;
|
|
60
|
+
const editorRef = useRef(null);
|
|
61
|
+
const [code, setCode] = useState(props.code || "");
|
|
62
|
+
const { theme } = props;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
setCode(props.code);
|
|
65
|
+
}, [props.code]);
|
|
66
|
+
useEditable(
|
|
67
|
+
editorRef,
|
|
68
|
+
(text) => {
|
|
69
|
+
const t = text.slice(0, -1);
|
|
70
|
+
setCode(t);
|
|
71
|
+
if (props.onChange) {
|
|
72
|
+
props.onChange(t);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
disabled: props.disabled,
|
|
77
|
+
indentation: tabMode === "indentation" ? 2 : void 0
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
return /* @__PURE__ */ jsx("div", { className: props.className, style: props.style, children: /* @__PURE__ */ jsx(
|
|
81
|
+
Highlight,
|
|
82
|
+
{
|
|
83
|
+
code,
|
|
84
|
+
theme: props.theme || themes.nightOwl,
|
|
85
|
+
language: props.language,
|
|
86
|
+
children: ({
|
|
87
|
+
className: _className,
|
|
88
|
+
tokens,
|
|
89
|
+
getLineProps,
|
|
90
|
+
getTokenProps,
|
|
91
|
+
style: _style
|
|
92
|
+
}) => /* @__PURE__ */ jsx(
|
|
93
|
+
"pre",
|
|
94
|
+
{
|
|
95
|
+
className: _className,
|
|
96
|
+
style: __spreadValues(__spreadValues({
|
|
97
|
+
margin: 0,
|
|
98
|
+
outline: "none",
|
|
99
|
+
padding: 10,
|
|
100
|
+
fontFamily: "inherit"
|
|
101
|
+
}, theme && typeof theme.plain === "object" ? theme.plain : {}), _style),
|
|
102
|
+
ref: editorRef,
|
|
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
|
+
) });
|
|
116
|
+
};
|
|
117
|
+
var Editor_default = CodeEditor;
|
|
118
|
+
|
|
119
|
+
// src/components/Live/LiveProvider.tsx
|
|
120
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
121
|
+
|
|
122
|
+
// src/components/Live/LiveContext.ts
|
|
123
|
+
import { createContext } from "react";
|
|
124
|
+
var LiveContext = createContext({});
|
|
125
|
+
var LiveContext_default = LiveContext;
|
|
126
|
+
|
|
127
|
+
// src/utils/transpile/index.ts
|
|
128
|
+
import React2 from "react";
|
|
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;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/utils/transpile/errorBoundary.tsx
|
|
139
|
+
import React, { Component } from "react";
|
|
140
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
141
|
+
var errorBoundary = (Element, errorCallback) => {
|
|
142
|
+
return class ErrorBoundary extends Component {
|
|
143
|
+
componentDidCatch(error) {
|
|
144
|
+
errorCallback(error);
|
|
145
|
+
}
|
|
146
|
+
render() {
|
|
147
|
+
return typeof Element === "function" ? /* @__PURE__ */ jsx2(Element, {}) : React.isValidElement(Element) ? Element : null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
var errorBoundary_default = errorBoundary;
|
|
152
|
+
|
|
153
|
+
// src/utils/transpile/evalCode.ts
|
|
154
|
+
var evalCode = (code, scope) => {
|
|
155
|
+
const scopeKeys = Object.keys(scope);
|
|
156
|
+
const scopeValues = scopeKeys.map((key) => scope[key]);
|
|
157
|
+
return new Function(...scopeKeys, code)(...scopeValues);
|
|
158
|
+
};
|
|
159
|
+
var evalCode_default = evalCode;
|
|
160
|
+
|
|
161
|
+
// src/utils/transpile/compose.ts
|
|
162
|
+
function compose(...functions) {
|
|
163
|
+
return functions.reduce(
|
|
164
|
+
(acc, currentFn) => (...args) => acc(currentFn(...args))
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/utils/transpile/index.ts
|
|
169
|
+
var jsxConst = 'const _jsxFileName = "";';
|
|
170
|
+
var trimCode = (code) => code.trim().replace(/;$/, "");
|
|
171
|
+
var spliceJsxConst = (code) => code.replace(jsxConst, "").trim();
|
|
172
|
+
var addJsxConst = (code) => jsxConst + code;
|
|
173
|
+
var wrapReturn = (code) => `return (${code})`;
|
|
174
|
+
var generateElement = ({ code = "", scope = {}, enableTypeScript = true }, errorCallback) => {
|
|
175
|
+
const firstPassTransforms = ["jsx"];
|
|
176
|
+
enableTypeScript && firstPassTransforms.push("typescript");
|
|
177
|
+
const transformed = compose(
|
|
178
|
+
addJsxConst,
|
|
179
|
+
transform({ transforms: ["imports"] }),
|
|
180
|
+
spliceJsxConst,
|
|
181
|
+
trimCode,
|
|
182
|
+
transform({ transforms: firstPassTransforms }),
|
|
183
|
+
wrapReturn,
|
|
184
|
+
trimCode
|
|
185
|
+
)(code);
|
|
186
|
+
return errorBoundary_default(
|
|
187
|
+
evalCode_default(transformed, __spreadValues({ React: React2 }, scope)),
|
|
188
|
+
errorCallback
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
var renderElementAsync = ({ code = "", scope = {}, enableTypeScript = true }, resultCallback, errorCallback) => {
|
|
192
|
+
const render = (element) => {
|
|
193
|
+
if (typeof element === "undefined") {
|
|
194
|
+
errorCallback(new SyntaxError("`render` must be called with valid JSX."));
|
|
195
|
+
} else {
|
|
196
|
+
resultCallback(errorBoundary_default(element, errorCallback));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
if (!/render\s*\(/.test(code)) {
|
|
200
|
+
return errorCallback(
|
|
201
|
+
new SyntaxError("No-Inline evaluations must call `render`.")
|
|
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 }));
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/components/Live/LiveProvider.tsx
|
|
210
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
211
|
+
function LiveProvider({
|
|
212
|
+
children,
|
|
213
|
+
code = "",
|
|
214
|
+
language = "tsx",
|
|
215
|
+
theme,
|
|
216
|
+
enableTypeScript = true,
|
|
217
|
+
disabled = false,
|
|
218
|
+
scope,
|
|
219
|
+
transformCode,
|
|
220
|
+
noInline = false
|
|
221
|
+
}) {
|
|
222
|
+
const [state, setState] = useState2({
|
|
223
|
+
error: void 0,
|
|
224
|
+
element: void 0
|
|
225
|
+
});
|
|
226
|
+
function transpileAsync(newCode) {
|
|
227
|
+
return __async(this, null, function* () {
|
|
228
|
+
const errorCallback = (error) => {
|
|
229
|
+
setState((previousState) => __spreadProps(__spreadValues({}, previousState), {
|
|
230
|
+
error: error.toString(),
|
|
231
|
+
element: void 0
|
|
232
|
+
}));
|
|
233
|
+
};
|
|
234
|
+
try {
|
|
235
|
+
const transformResult = transformCode ? transformCode(newCode) : newCode;
|
|
236
|
+
try {
|
|
237
|
+
const transformedCode = yield Promise.resolve(transformResult);
|
|
238
|
+
const renderElement = (element) => setState({ error: void 0, element, newCode });
|
|
239
|
+
if (typeof transformedCode !== "string") {
|
|
240
|
+
throw new Error("Code failed to transform");
|
|
241
|
+
}
|
|
242
|
+
const input = {
|
|
243
|
+
code: transformedCode,
|
|
244
|
+
scope,
|
|
245
|
+
enableTypeScript
|
|
246
|
+
};
|
|
247
|
+
if (noInline) {
|
|
248
|
+
setState((previousState) => __spreadProps(__spreadValues({}, previousState), {
|
|
249
|
+
error: void 0,
|
|
250
|
+
element: null
|
|
251
|
+
}));
|
|
252
|
+
renderElementAsync(input, renderElement, errorCallback);
|
|
253
|
+
} else {
|
|
254
|
+
renderElement(generateElement(input, errorCallback));
|
|
255
|
+
}
|
|
256
|
+
} catch (error) {
|
|
257
|
+
return errorCallback(error);
|
|
258
|
+
}
|
|
259
|
+
} catch (e) {
|
|
260
|
+
errorCallback(e);
|
|
261
|
+
return Promise.resolve();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
const onError = (error) => setState({ error: error.toString() });
|
|
266
|
+
useEffect2(() => {
|
|
267
|
+
transpileAsync(code).catch(onError);
|
|
268
|
+
}, [code, scope, noInline, transformCode]);
|
|
269
|
+
const onChange = (newCode) => {
|
|
270
|
+
transpileAsync(newCode).catch(onError);
|
|
271
|
+
};
|
|
272
|
+
return /* @__PURE__ */ jsx3(
|
|
273
|
+
LiveContext_default.Provider,
|
|
274
|
+
{
|
|
275
|
+
value: __spreadProps(__spreadValues({}, state), {
|
|
276
|
+
code,
|
|
277
|
+
language,
|
|
278
|
+
theme,
|
|
279
|
+
disabled,
|
|
280
|
+
onError,
|
|
281
|
+
onChange
|
|
282
|
+
}),
|
|
283
|
+
children
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
var LiveProvider_default = LiveProvider;
|
|
288
|
+
|
|
289
|
+
// src/components/Live/LiveEditor.tsx
|
|
290
|
+
import { useContext } from "react";
|
|
291
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
292
|
+
function LiveEditor(props) {
|
|
293
|
+
const { code, language, theme, disabled, onChange } = useContext(LiveContext_default);
|
|
294
|
+
return /* @__PURE__ */ jsx4(
|
|
295
|
+
Editor_default,
|
|
296
|
+
__spreadValues({
|
|
297
|
+
theme,
|
|
298
|
+
code,
|
|
299
|
+
language,
|
|
300
|
+
disabled,
|
|
301
|
+
onChange
|
|
302
|
+
}, props)
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/components/Live/LiveError.tsx
|
|
307
|
+
import { useContext as useContext2 } from "react";
|
|
308
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
309
|
+
function LiveError(props) {
|
|
310
|
+
const { error } = useContext2(LiveContext_default);
|
|
311
|
+
return error ? /* @__PURE__ */ jsx5("pre", __spreadProps(__spreadValues({}, props), { children: error })) : null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/components/Live/LivePreview.tsx
|
|
315
|
+
import { useContext as useContext3 } from "react";
|
|
316
|
+
|
|
317
|
+
// src/components/Live/ErrorBoundary.tsx
|
|
318
|
+
import { Component as Component2 } from "react";
|
|
319
|
+
var ErrorBoundary = class extends Component2 {
|
|
320
|
+
static getDerivedStateFromError() {
|
|
321
|
+
return { hasError: true };
|
|
322
|
+
}
|
|
323
|
+
constructor(props) {
|
|
324
|
+
super(props);
|
|
325
|
+
this.state = { hasError: false };
|
|
326
|
+
}
|
|
327
|
+
componentDidCatch(err) {
|
|
328
|
+
var _a, _b;
|
|
329
|
+
(_b = (_a = this.props).onError) == null ? void 0 : _b.call(_a, err);
|
|
330
|
+
}
|
|
331
|
+
render() {
|
|
332
|
+
if (this.state.hasError) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
return this.props.children;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// src/components/Live/LivePreview.tsx
|
|
340
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
341
|
+
function LivePreview(_a) {
|
|
342
|
+
var _b = _a, { Component: Component3 = "div" } = _b, rest = __objRest(_b, ["Component"]);
|
|
343
|
+
const { element: Element, onError, newCode } = useContext3(LiveContext_default);
|
|
344
|
+
return /* @__PURE__ */ jsx6(ErrorBoundary, { onError, children: /* @__PURE__ */ jsx6(Component3, __spreadProps(__spreadValues({}, rest), { children: Element ? /* @__PURE__ */ jsx6(Element, {}) : null })) }, newCode);
|
|
345
|
+
}
|
|
346
|
+
var LivePreview_default = LivePreview;
|
|
347
|
+
|
|
348
|
+
// src/hoc/withLive.tsx
|
|
349
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
350
|
+
function withLive(WrappedComponent) {
|
|
351
|
+
const WithLive = (props) => /* @__PURE__ */ jsx7(LiveContext_default.Consumer, { children: (live) => /* @__PURE__ */ jsx7(WrappedComponent, __spreadValues({ live }, props)) });
|
|
352
|
+
WithLive.displayName = "WithLive";
|
|
353
|
+
return WithLive;
|
|
354
|
+
}
|
|
355
|
+
export {
|
|
356
|
+
Editor_default as Editor,
|
|
357
|
+
LiveContext_default as LiveContext,
|
|
358
|
+
LiveEditor,
|
|
359
|
+
LiveError,
|
|
360
|
+
LivePreview_default as LivePreview,
|
|
361
|
+
LiveProvider_default as LiveProvider,
|
|
362
|
+
generateElement,
|
|
363
|
+
renderElementAsync,
|
|
364
|
+
withLive
|
|
365
|
+
};
|
|
366
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Editor/index.tsx","../src/components/Live/LiveProvider.tsx","../src/components/Live/LiveContext.ts","../src/utils/transpile/index.ts","../src/utils/transpile/transform.ts","../src/utils/transpile/errorBoundary.tsx","../src/utils/transpile/evalCode.ts","../src/utils/transpile/compose.ts","../src/components/Live/LiveEditor.tsx","../src/components/Live/LiveError.tsx","../src/components/Live/LivePreview.tsx","../src/components/Live/ErrorBoundary.tsx","../src/hoc/withLive.tsx"],"sourcesContent":["import { Highlight, Prism, themes } from \"prism-react-renderer\";\nimport { CSSProperties, useEffect, useRef, useState } from \"react\";\nimport { useEditable } from \"use-editable\";\n\nexport type Props = {\n className?: string;\n code: string;\n disabled?: boolean;\n language: string;\n prism?: typeof Prism;\n style?: CSSProperties;\n tabMode?: \"focus\" | \"indentation\";\n theme?: typeof themes.nightOwl;\n onChange?(value: string): void;\n};\n\nconst CodeEditor = (props: Props) => {\n const { tabMode = \"indentation\" } = props;\n const editorRef = useRef(null);\n const [code, setCode] = useState(props.code || \"\");\n const { theme } = props;\n\n useEffect(() => {\n setCode(props.code);\n }, [props.code]);\n\n useEditable(\n editorRef,\n (text) => {\n const t = text.slice(0, -1);\n setCode(t);\n\n if (props.onChange) {\n props.onChange(t);\n }\n },\n {\n disabled: props.disabled,\n indentation: tabMode === \"indentation\" ? 2 : undefined,\n }\n );\n\n return (\n <div className={props.className} style={props.style}>\n <Highlight\n code={code}\n theme={props.theme || themes.nightOwl}\n language={props.language}\n >\n {({\n className: _className,\n tokens,\n getLineProps,\n getTokenProps,\n style: _style,\n }) => (\n <pre\n className={_className}\n style={{\n margin: 0,\n outline: \"none\",\n padding: 10,\n fontFamily: \"inherit\",\n ...(theme && typeof theme.plain === \"object\" ? theme.plain : {}),\n ..._style,\n }}\n ref={editorRef}\n spellCheck=\"false\"\n >\n {tokens.map((line, lineIndex) => (\n <span key={`line-${lineIndex}`} {...getLineProps({ line })}>\n {line\n .filter((token) => !token.empty)\n .map((token, tokenIndex) => (\n <span\n key={`token-${tokenIndex}`}\n {...getTokenProps({ token })}\n />\n ))}\n {\"\\n\"}\n </span>\n ))}\n </pre>\n )}\n </Highlight>\n </div>\n );\n};\n\nexport default CodeEditor;\n","import { useEffect, useState, ComponentType, PropsWithChildren } from \"react\";\nimport LiveContext from \"./LiveContext\";\nimport { generateElement, renderElementAsync } from \"../../utils/transpile\";\nimport { themes } from \"prism-react-renderer\";\n\ntype ProviderState = {\n element?: ComponentType | null;\n error?: string;\n newCode?: string;\n};\n\ntype Props = {\n code?: string;\n disabled?: boolean;\n enableTypeScript?: boolean;\n language?: string;\n noInline?: boolean;\n scope?: Record<string, unknown>;\n theme?: typeof themes.nightOwl;\n transformCode?(code: string): void;\n};\n\nfunction LiveProvider({\n children,\n code = \"\",\n language = \"tsx\",\n theme,\n enableTypeScript = true,\n disabled = false,\n scope,\n transformCode,\n noInline = false,\n}: PropsWithChildren<Props>) {\n const [state, setState] = useState<ProviderState>({\n error: undefined,\n element: undefined,\n });\n\n async function transpileAsync(newCode: string) {\n const errorCallback = (error: Error) => {\n setState((previousState) => ({\n ...previousState,\n error: error.toString(),\n element: undefined,\n }));\n };\n\n // - transformCode may be synchronous or asynchronous.\n // - transformCode may throw an exception or return a rejected promise, e.g.\n // if newCode is invalid and cannot be transformed.\n // - Not using async-await to since it requires targeting ES 2017 or\n // importing regenerator-runtime... in the next major version of\n // react-live, should target ES 2017+\n try {\n const transformResult = transformCode ? transformCode(newCode) : newCode;\n try {\n const transformedCode = await Promise.resolve(transformResult);\n const renderElement = (element: ComponentType) =>\n setState({ error: undefined, element, newCode });\n\n if (typeof transformedCode !== \"string\") {\n throw new Error(\"Code failed to transform\");\n }\n\n // Transpilation arguments\n const input = {\n code: transformedCode,\n scope,\n enableTypeScript,\n };\n\n if (noInline) {\n setState((previousState) => ({\n ...previousState,\n error: undefined,\n element: null,\n })); // Reset output for async (no inline) evaluation\n renderElementAsync(input, renderElement, errorCallback);\n } else {\n renderElement(generateElement(input, errorCallback));\n }\n } catch (error) {\n return errorCallback(error as Error);\n }\n } catch (e) {\n errorCallback(e as Error);\n return Promise.resolve();\n }\n }\n\n const onError = (error: Error) => setState({ error: error.toString() });\n\n useEffect(() => {\n transpileAsync(code).catch(onError);\n }, [code, scope, noInline, transformCode]);\n\n const onChange = (newCode: string) => {\n transpileAsync(newCode).catch(onError);\n };\n\n return (\n <LiveContext.Provider\n value={{\n ...state,\n code,\n language,\n theme,\n disabled,\n onError,\n onChange,\n }}\n >\n {children}\n </LiveContext.Provider>\n );\n}\n\nexport default LiveProvider;\n","import { themes } from \"prism-react-renderer\";\nimport { ComponentType, createContext } from \"react\";\n\ntype ContextValue = {\n error?: string;\n element?: ComponentType | null;\n code: string;\n newCode?: string;\n disabled: boolean;\n language: string;\n theme?: typeof themes.nightOwl;\n onError(error: Error): void;\n onChange(value: string): void;\n};\n\nconst LiveContext = createContext<ContextValue>({} as ContextValue);\n\nexport default LiveContext;\n","import React, { ComponentType } from \"react\";\nimport transform from \"./transform\";\nimport errorBoundary from \"./errorBoundary\";\nimport evalCode from \"./evalCode\";\nimport compose from \"./compose\";\nimport { Transform } from \"sucrase\";\n\nconst jsxConst = 'const _jsxFileName = \"\";';\nconst trimCode = (code: string) => code.trim().replace(/;$/, \"\");\nconst spliceJsxConst = (code: string) => code.replace(jsxConst, \"\").trim();\nconst addJsxConst = (code: string) => jsxConst + code;\nconst wrapReturn = (code: string) => `return (${code})`;\n\ntype GenerateOptions = {\n code: string;\n scope?: Record<string, unknown>;\n enableTypeScript: boolean;\n};\n\nexport const generateElement = (\n { code = \"\", scope = {}, enableTypeScript = true }: GenerateOptions,\n errorCallback: (error: Error) => void\n) => {\n /**\n * To enable TypeScript we need to transform the TS to JS code first,\n * splice off the JSX const, wrap the eval in a return statement, then\n * transform any imports. The two-phase approach is required to do\n * the implicit evaluation and not wrap leading Interface or Type\n * statements in the return.\n */\n\n const firstPassTransforms: Transform[] = [\"jsx\"];\n enableTypeScript && firstPassTransforms.push(\"typescript\");\n\n const transformed = compose<string>(\n addJsxConst,\n transform({ transforms: [\"imports\"] }),\n spliceJsxConst,\n trimCode,\n transform({ transforms: firstPassTransforms }),\n wrapReturn,\n trimCode\n )(code);\n\n return errorBoundary(\n evalCode(transformed, { React, ...scope }),\n errorCallback\n );\n};\n\nexport const renderElementAsync = (\n { code = \"\", scope = {}, enableTypeScript = true }: GenerateOptions,\n resultCallback: (sender: ComponentType) => void,\n errorCallback: (error: Error) => void\n // eslint-disable-next-line consistent-return\n) => {\n const render = (element: ComponentType) => {\n if (typeof element === \"undefined\") {\n errorCallback(new SyntaxError(\"`render` must be called with valid JSX.\"));\n } else {\n resultCallback(errorBoundary(element, errorCallback));\n }\n };\n\n if (!/render\\s*\\(/.test(code)) {\n return errorCallback(\n new SyntaxError(\"No-Inline evaluations must call `render`.\")\n );\n }\n\n const transforms: Transform[] = [\"jsx\", \"imports\"];\n enableTypeScript && transforms.splice(1, 0, \"typescript\");\n\n evalCode(transform({ transforms })(code), { React, ...scope, render });\n};\n","import { transform as _transform, Transform } from \"sucrase\";\n\nconst defaultTransforms: Transform[] = [\"jsx\", \"imports\"];\n\ntype Options = {\n transforms?: Transform[];\n};\n\nexport default function transform(opts: Options = {}) {\n const transforms = Array.isArray(opts.transforms)\n ? opts.transforms.filter(Boolean)\n : defaultTransforms;\n\n return (code: string) => _transform(code, { transforms }).code;\n}\n","import React, { ComponentType, Component } from \"react\";\n\nconst errorBoundary = (\n Element: ComponentType,\n errorCallback: (error: Error) => void\n) => {\n return class ErrorBoundary extends Component {\n componentDidCatch(error: Error) {\n errorCallback(error);\n }\n\n render() {\n return typeof Element === \"function\" ? (\n <Element />\n ) : React.isValidElement(Element) ? (\n Element\n ) : null;\n }\n };\n};\n\nexport default errorBoundary;\n","import type { ComponentType } from \"react\";\n\nconst evalCode = (\n code: string,\n scope: Record<string, unknown>\n): ComponentType => {\n const scopeKeys = Object.keys(scope);\n const scopeValues = scopeKeys.map((key) => scope[key]);\n return new Function(...scopeKeys, code)(...scopeValues);\n};\n\nexport default evalCode;\n","/**\n * Creates a new composite function that invokes the functions from right to left\n */\n\nexport default function compose<T>(...functions: ((...args: T[]) => T)[]) {\n return functions.reduce(\n (acc, currentFn) =>\n (...args: T[]) =>\n acc(currentFn(...args))\n );\n}\n","import React, { useContext } from \"react\";\nimport LiveContext from \"./LiveContext\";\nimport Editor, { Props as EditorProps } from \"../Editor\";\n\nexport default function LiveEditor(props: Partial<EditorProps>) {\n const { code, language, theme, disabled, onChange } = useContext(LiveContext);\n\n return (\n <Editor\n theme={theme}\n code={code}\n language={language}\n disabled={disabled}\n onChange={onChange}\n {...props}\n />\n );\n}\n","import React, { useContext } from \"react\";\nimport LiveContext from \"./LiveContext\";\n\nexport default function LiveError<T extends Record<string, unknown>>(props: T) {\n const { error } = useContext(LiveContext);\n return error ? <pre {...props}>{error}</pre> : null;\n}\n","import React, { useContext } from \"react\";\n\nimport { ErrorBoundary } from \"./ErrorBoundary\";\nimport LiveContext from \"./LiveContext\";\n\ntype Props<T extends React.ElementType = React.ElementType> = {\n Component?: T;\n} & React.ComponentPropsWithoutRef<T>;\n\nfunction LivePreview<T extends keyof JSX.IntrinsicElements>(\n props: Props<T>\n): JSX.Element;\nfunction LivePreview<T extends React.ElementType>(props: Props<T>): JSX.Element;\n\nfunction LivePreview({ Component = \"div\", ...rest }: Props): JSX.Element {\n const { element: Element, onError, newCode } = useContext(LiveContext);\n\n return (\n <ErrorBoundary key={newCode} onError={onError}>\n <Component {...rest}>{Element ? <Element /> : null}</Component>\n </ErrorBoundary>\n );\n}\nexport default LivePreview;\n","import { Component, ReactNode } from \"react\";\n\ntype Props = {\n children: ReactNode;\n onError?: (error: Error) => void;\n};\n\ntype State = {\n hasError: boolean;\n};\n\nexport class ErrorBoundary extends Component<Props, State> {\n static getDerivedStateFromError() {\n return { hasError: true };\n }\n\n constructor(props: Props) {\n super(props);\n this.state = { hasError: false };\n }\n\n componentDidCatch(err: Error): void {\n this.props.onError?.(err);\n }\n\n render() {\n if (this.state.hasError) {\n return null;\n }\n\n return this.props.children;\n }\n}\n","import React, { ComponentType } from \"react\";\nimport LiveContext from \"../components/Live/LiveContext\";\n\ntype Props = {\n live: Record<string, unknown>;\n};\n\nexport default function withLive<T>(\n WrappedComponent: ComponentType<T & Props>\n) {\n const WithLive = (props: T) => (\n <LiveContext.Consumer>\n {(live) => <WrappedComponent live={live} {...props} />}\n </LiveContext.Consumer>\n );\n\n WithLive.displayName = \"WithLive\";\n return WithLive;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAkB,cAAc;AACzC,SAAwB,WAAW,QAAQ,gBAAgB;AAC3D,SAAS,mBAAmB;AAoEd,SAIM,KAJN;AAtDd,IAAM,aAAa,CAAC,UAAiB;AACnC,QAAM,EAAE,UAAU,cAAc,IAAI;AACpC,QAAM,YAAY,OAAO,IAAI;AAC7B,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,MAAM,QAAQ,EAAE;AACjD,QAAM,EAAE,MAAM,IAAI;AAElB,YAAU,MAAM;AACd,YAAQ,MAAM,IAAI;AAAA,EACpB,GAAG,CAAC,MAAM,IAAI,CAAC;AAEf;AAAA,IACE;AAAA,IACA,CAAC,SAAS;AACR,YAAM,IAAI,KAAK,MAAM,GAAG,EAAE;AAC1B,cAAQ,CAAC;AAET,UAAI,MAAM,UAAU;AAClB,cAAM,SAAS,CAAC;AAAA,MAClB;AAAA,IACF;AAAA,IACA;AAAA,MACE,UAAU,MAAM;AAAA,MAChB,aAAa,YAAY,gBAAgB,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,SACE,oBAAC,SAAI,WAAW,MAAM,WAAW,OAAO,MAAM,OAC5C;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO,MAAM,SAAS,OAAO;AAAA,MAC7B,UAAU,MAAM;AAAA,MAEf,WAAC;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO;AAAA,MACT,MACE;AAAA,QAAC;AAAA;AAAA,UACC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R,UAA8D,OAAU;AAC7E,QAAM,EAAE,MAAM,IAAIC,YAAW,mBAAW;AACxC,SAAO,QAAQ,gBAAAD,KAAC,wCAAQ,QAAR,EAAgB,kBAAM,IAAS;AACjD;;;ACNA,SAAgB,cAAAE,mBAAkB;;;ACAlC,SAAS,aAAAC,kBAA4B;AAW9B,IAAM,gBAAN,cAA4BA,WAAwB;AAAA,EACzD,OAAO,2BAA2B;AAChC,WAAO,EAAE,UAAU,KAAK;AAAA,EAC1B;AAAA,EAEA,YAAY,OAAc;AACxB,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,UAAU,MAAM;AAAA,EACjC;AAAA,EAEA,kBAAkB,KAAkB;AArBtC;AAsBI,qBAAK,OAAM,YAAX,4BAAqB;AAAA,EACvB;AAAA,EAEA,SAAS;AACP,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO;AAAA,IACT;AAEA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;;;ADbsC,gBAAAC,YAAA;AALtC,SAAS,YAAY,IAAoD;AAApD,eAAE,aAAAC,aAAY,MAdnC,IAcqB,IAAwB,iBAAxB,IAAwB,CAAtB;AACrB,QAAM,EAAE,SAAS,SAAS,SAAS,QAAQ,IAAIC,YAAW,mBAAW;AAErE,SACE,gBAAAF,KAAC,iBAA4B,SAC3B,0BAAAA,KAACC,YAAA,iCAAc,OAAd,EAAqB,oBAAU,gBAAAD,KAAC,WAAQ,IAAK,OAAK,KADjC,OAEpB;AAEJ;AACA,IAAO,sBAAQ;;;AEXE,gBAAAG,YAAA;AALF,SAAR,SACL,kBACA;AACA,QAAM,WAAW,CAAC,UAChB,gBAAAA,KAAC,oBAAY,UAAZ,EACE,WAAC,SAAS,gBAAAA,KAAC,mCAAiB,QAAgB,MAAO,GACtD;AAGF,WAAS,cAAc;AACvB,SAAO;AACT;","names":["useEffect","useState","React","jsx","React","jsx","useState","useEffect","jsx","useContext","jsx","useContext","useContext","Component","jsx","Component","useContext","jsx"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/react-live",
|
|
3
|
+
"version": "4.1.8-depup.0",
|
|
4
|
+
"description": "A production-focused playground for live editing React code (with updated dependencies)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"jsnext:main": "dist/index.mjs",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"prism-react-renderer": "^2.4.1",
|
|
12
|
+
"sucrase": "^3.35.1",
|
|
13
|
+
"use-editable": "^2.3.3"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": ">=18.0.0",
|
|
17
|
+
"react-dom": ">=18.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"shx": "^0.3.4",
|
|
21
|
+
"@babel/core": "^7.15.0",
|
|
22
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
23
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
|
|
24
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
|
25
|
+
"@babel/preset-env": "^7.15.0",
|
|
26
|
+
"@babel/preset-react": "^7.14.5",
|
|
27
|
+
"@babel/preset-typescript": "^7.21.0",
|
|
28
|
+
"@storybook/addon-controls": "^6.4.13",
|
|
29
|
+
"@storybook/builder-webpack5": "^6.5.16",
|
|
30
|
+
"@storybook/manager-webpack5": "^6.5.16",
|
|
31
|
+
"@storybook/react": "^6.4.13",
|
|
32
|
+
"@types/prismjs": "^1.26.0",
|
|
33
|
+
"@types/react": "^18.0.31",
|
|
34
|
+
"@types/styled-components": "^5.1.26",
|
|
35
|
+
"babel-jest": "^27.0.6",
|
|
36
|
+
"babel-loader": "^8.2.2",
|
|
37
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
38
|
+
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
|
39
|
+
"jest": "^27.0.6",
|
|
40
|
+
"prismjs": "^1.26.0",
|
|
41
|
+
"prop-types": "^15.7.2",
|
|
42
|
+
"react": "^18.2.0",
|
|
43
|
+
"react-docgen-typescript": "^2.2.2",
|
|
44
|
+
"react-dom": "^18.2.0",
|
|
45
|
+
"react-test-renderer": "^17.0.2",
|
|
46
|
+
"styled-components": "^4.0.0-beta.8",
|
|
47
|
+
"tsup": "^6.7.0",
|
|
48
|
+
"typescript": "^4.9.5",
|
|
49
|
+
"typings-tester": "^0.3.1",
|
|
50
|
+
"webpack": "^5.76.3"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"packages/react-live/src",
|
|
54
|
+
"lib",
|
|
55
|
+
"dist",
|
|
56
|
+
"react-live.css",
|
|
57
|
+
"typings/react-live.d.ts",
|
|
58
|
+
"changes.json",
|
|
59
|
+
"README.md"
|
|
60
|
+
],
|
|
61
|
+
"author": "@FormidableLabs",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/philpl/react-live/issues"
|
|
64
|
+
},
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/FormidableLabs/react-live"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"npm": ">= 2.0.0",
|
|
71
|
+
"node": ">= 0.12.0"
|
|
72
|
+
},
|
|
73
|
+
"keywords": [
|
|
74
|
+
"react-live",
|
|
75
|
+
"depup",
|
|
76
|
+
"updated-dependencies",
|
|
77
|
+
"security",
|
|
78
|
+
"latest",
|
|
79
|
+
"patched",
|
|
80
|
+
"react",
|
|
81
|
+
"live",
|
|
82
|
+
"live edit",
|
|
83
|
+
"component playground",
|
|
84
|
+
"react live"
|
|
85
|
+
],
|
|
86
|
+
"jest": {
|
|
87
|
+
"testEnvironment": "jsdom",
|
|
88
|
+
"resetMocks": true,
|
|
89
|
+
"rootDir": "./src",
|
|
90
|
+
"testURL": "http://localhost/"
|
|
91
|
+
},
|
|
92
|
+
"sideEffects": false,
|
|
93
|
+
"scripts": {
|
|
94
|
+
"storybook": "start-storybook -p 9001",
|
|
95
|
+
"storybook:build": "build-storybook -o .out",
|
|
96
|
+
"build": "tsup",
|
|
97
|
+
"build:watch": "tsup --watch",
|
|
98
|
+
"test": "jest",
|
|
99
|
+
"test:typings": "typings-tester --dir typings",
|
|
100
|
+
"typecheck": "tsc --noEmit",
|
|
101
|
+
"lint": "eslint --ext .js,.ts,.tsx src",
|
|
102
|
+
"lint:fix": "eslint --ext .js,.ts,.tsx src --fix"
|
|
103
|
+
},
|
|
104
|
+
"depup": {
|
|
105
|
+
"changes": {
|
|
106
|
+
"prism-react-renderer": {
|
|
107
|
+
"from": "^2.4.0",
|
|
108
|
+
"to": "^2.4.1"
|
|
109
|
+
},
|
|
110
|
+
"sucrase": {
|
|
111
|
+
"from": "^3.35.0",
|
|
112
|
+
"to": "^3.35.1"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"depsUpdated": 2,
|
|
116
|
+
"originalPackage": "react-live",
|
|
117
|
+
"originalVersion": "4.1.8",
|
|
118
|
+
"processedAt": "2026-03-18T23:31:21.447Z",
|
|
119
|
+
"smokeTest": "failed"
|
|
120
|
+
}
|
|
121
|
+
}
|