@builder.io/react 3.0.7 → 3.0.8-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/dist/builder-react-lite.cjs.js +1 -1
- package/dist/builder-react-lite.cjs.js.map +1 -1
- package/dist/builder-react-lite.esm.js +1 -1
- package/dist/builder-react-lite.esm.js.map +1 -1
- package/dist/builder-react.browser.js +2 -2
- package/dist/builder-react.browser.js.map +1 -1
- package/dist/builder-react.cjs.js +1 -1
- package/dist/builder-react.cjs.js.map +1 -1
- package/dist/builder-react.es5.js +1 -1
- package/dist/builder-react.es5.js.map +1 -1
- package/dist/builder-react.unpkg.js +2 -2
- package/dist/builder-react.unpkg.js.map +1 -1
- package/dist/lib/package.json +3 -3
- package/dist/lib/rollup.config.js +2 -2
- package/dist/lib/rollup.config.js.map +1 -1
- package/dist/lib/src/blocks/Video.js +7 -1
- package/dist/lib/src/blocks/Video.js.map +1 -1
- package/dist/lib/src/components/builder-component.component.js +2 -3
- package/dist/lib/src/components/builder-component.component.js.map +1 -1
- package/dist/lib/src/functions/is-debug.js +8 -0
- package/dist/lib/src/functions/is-debug.js.map +1 -0
- package/dist/lib/src/functions/string-to-function.js +19 -22
- package/dist/lib/src/functions/string-to-function.js.map +1 -1
- package/dist/lib/src/functions/try-eval.js +2 -3
- package/dist/lib/src/functions/try-eval.js.map +1 -1
- package/dist/types/src/components/builder-content.component.d.ts +0 -67
- package/dist/types/src/functions/is-debug.d.ts +1 -0
- package/package.json +5 -4
- package/rollup.config.ts +2 -2
- package/src/blocks/Video.tsx +8 -0
- package/src/components/builder-component.component.tsx +2 -5
- package/src/functions/is-debug.ts +5 -0
- package/src/functions/string-to-function.ts +48 -20
- package/src/functions/try-eval.tsx +2 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Builder, builder } from '@builder.io/sdk';
|
|
2
2
|
import { safeDynamicRequire } from './safe-dynamic-require';
|
|
3
|
+
import { isDebug } from './is-debug';
|
|
3
4
|
|
|
4
5
|
const fnCache: { [key: string]: BuilderEvanFunction | undefined } = {};
|
|
5
6
|
|
|
@@ -117,21 +118,12 @@ export function stringToFunction(
|
|
|
117
118
|
// browser bundler's like rollup and webpack. Our rollup plugin strips these comments only
|
|
118
119
|
// for the server build
|
|
119
120
|
// TODO: cache these for better performancs with new VmScript
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
sandbox: {
|
|
127
|
-
...state,
|
|
128
|
-
...{ state },
|
|
129
|
-
...{ context },
|
|
130
|
-
...{ builder: api },
|
|
131
|
-
event,
|
|
132
|
-
},
|
|
133
|
-
}).run(str.replace(/(^|;)return /, '$1'));
|
|
134
|
-
// tslint:enable:comment-format
|
|
121
|
+
const isolateContext = getIsolateContext();
|
|
122
|
+
const ivm = safeDynamicRequire('isolated-vm') as typeof import('isolated-vm');
|
|
123
|
+
return isolateContext.evalClosureSync(
|
|
124
|
+
makeFn(str, useReturn),
|
|
125
|
+
args.map(arg => (typeof arg === 'object' ? new ivm.Reference(arg) : null))
|
|
126
|
+
);
|
|
135
127
|
}
|
|
136
128
|
} catch (error: any) {
|
|
137
129
|
if (Builder.isBrowser) {
|
|
@@ -143,11 +135,7 @@ export function stringToFunction(
|
|
|
143
135
|
error.stack || error
|
|
144
136
|
);
|
|
145
137
|
} else {
|
|
146
|
-
if (
|
|
147
|
-
typeof process !== 'undefined' &&
|
|
148
|
-
typeof process.env !== 'undefined' &&
|
|
149
|
-
process.env.DEBUG
|
|
150
|
-
) {
|
|
138
|
+
if (isDebug()) {
|
|
151
139
|
console.debug(
|
|
152
140
|
'Builder custom code error:',
|
|
153
141
|
error.message || error,
|
|
@@ -170,3 +158,43 @@ export function stringToFunction(
|
|
|
170
158
|
|
|
171
159
|
return final;
|
|
172
160
|
}
|
|
161
|
+
|
|
162
|
+
const makeFn = (code: string, useReturn: boolean) => {
|
|
163
|
+
const names = ['state', 'event', 'block', 'builder', 'Device', 'update', 'Builder', 'context'];
|
|
164
|
+
return `
|
|
165
|
+
const refToProxy = (obj) => {
|
|
166
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
167
|
+
return obj;
|
|
168
|
+
}
|
|
169
|
+
return new Proxy({}, {
|
|
170
|
+
get(target, key) {
|
|
171
|
+
const val = obj.getSync(key);
|
|
172
|
+
if (typeof val?.getSync === 'function') {
|
|
173
|
+
return refToProxy(val);
|
|
174
|
+
}
|
|
175
|
+
return val;
|
|
176
|
+
},
|
|
177
|
+
set(target, key, value) {
|
|
178
|
+
obj.setSync(key, value);
|
|
179
|
+
},
|
|
180
|
+
deleteProperty(target, key) {
|
|
181
|
+
obj.deleteSync(key);
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
`.concat(names.map((arg, index) => `var ${arg} = refToProxy($${index});`).join('\n')).concat(`
|
|
186
|
+
var ctx = context;
|
|
187
|
+
${useReturn ? `return (${code});` : code};
|
|
188
|
+
`);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const getIsolateContext = () => {
|
|
192
|
+
const _Builder = Builder as any;
|
|
193
|
+
if (_Builder.serverContext) {
|
|
194
|
+
return _Builder.serverContext;
|
|
195
|
+
}
|
|
196
|
+
const ivm = safeDynamicRequire('isolated-vm') as typeof import('isolated-vm');
|
|
197
|
+
const isolate = new ivm.Isolate({ memoryLimit: 128 });
|
|
198
|
+
_Builder.serverContext = isolate.createContextSync();
|
|
199
|
+
return _Builder.serverContext;
|
|
200
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Builder } from '@builder.io/sdk';
|
|
3
3
|
import { safeDynamicRequire } from './safe-dynamic-require';
|
|
4
|
+
import { isDebug } from './is-debug';
|
|
4
5
|
|
|
5
6
|
export const tryEval = (str?: string, data: any = {}, errors?: Error[]): any => {
|
|
6
7
|
const value = str;
|
|
@@ -70,11 +71,7 @@ export const tryEval = (str?: string, data: any = {}, errors?: Error[]): any =>
|
|
|
70
71
|
if (Builder.isBrowser) {
|
|
71
72
|
console.warn('Builder custom code error:', error.message, 'in', str, error.stack);
|
|
72
73
|
} else {
|
|
73
|
-
if (
|
|
74
|
-
typeof process !== 'undefined' &&
|
|
75
|
-
typeof process.env !== 'undefined' &&
|
|
76
|
-
process.env.DEBUG
|
|
77
|
-
) {
|
|
74
|
+
if (isDebug()) {
|
|
78
75
|
console.debug('Builder custom code error:', error.message, 'in', str, error.stack);
|
|
79
76
|
}
|
|
80
77
|
// Add to req.options.errors to return to client
|