@builder.io/react 3.0.7 → 3.0.8-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +25 -4
- 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 +39 -12
- 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 +28 -5
- package/src/functions/is-debug.ts +5 -0
- package/src/functions/string-to-function.ts +71 -19
- package/src/functions/try-eval.tsx +2 -5
package/src/blocks/Video.tsx
CHANGED
|
@@ -19,6 +19,7 @@ class VideoComponent extends React.Component<{
|
|
|
19
19
|
width?: number;
|
|
20
20
|
height?: number;
|
|
21
21
|
fit?: 'contain' | 'cover' | 'fill';
|
|
22
|
+
preload?: 'auto' | 'metadata' | 'none';
|
|
22
23
|
position?: string;
|
|
23
24
|
posterImage?: string;
|
|
24
25
|
lazyLoad?: boolean;
|
|
@@ -121,6 +122,7 @@ class VideoComponent extends React.Component<{
|
|
|
121
122
|
muted={this.props.muted}
|
|
122
123
|
controls={this.props.controls}
|
|
123
124
|
loop={this.props.loop}
|
|
125
|
+
preload={this.props.preload || 'metadata'}
|
|
124
126
|
className="builder-video"
|
|
125
127
|
css={{
|
|
126
128
|
width: '100%',
|
|
@@ -234,6 +236,12 @@ export const Video = Builder.registerComponent(withChildren(VideoComponent), {
|
|
|
234
236
|
defaultValue: 'cover',
|
|
235
237
|
enum: ['contain', 'cover', 'fill', 'auto'],
|
|
236
238
|
},
|
|
239
|
+
{
|
|
240
|
+
name: 'preload',
|
|
241
|
+
type: 'text',
|
|
242
|
+
defaultValue: 'metadata',
|
|
243
|
+
enum: ['auto', 'metadata', 'none'],
|
|
244
|
+
},
|
|
237
245
|
{
|
|
238
246
|
name: 'fitContent',
|
|
239
247
|
type: 'boolean',
|
|
@@ -33,6 +33,7 @@ import { BuilderMetaContext } from '../store/builder-meta';
|
|
|
33
33
|
import { tryEval } from '../functions/try-eval';
|
|
34
34
|
import { toError } from '../to-error';
|
|
35
35
|
import { getBuilderPixel } from '../functions/get-builder-pixel';
|
|
36
|
+
import { isDebug } from '../functions/is-debug';
|
|
36
37
|
|
|
37
38
|
function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K> {
|
|
38
39
|
const ret: any = {};
|
|
@@ -389,7 +390,33 @@ export class BuilderComponent extends React.Component<
|
|
|
389
390
|
|
|
390
391
|
// TODO: pass this all the way down - symbols, etc
|
|
391
392
|
// this.asServer = Boolean(props.hydrate && Builder.isBrowser)
|
|
393
|
+
if (this.inlinedContent?.data) {
|
|
394
|
+
const contentData = this.inlinedContent.data;
|
|
395
|
+
if (contentData.inputs) {
|
|
396
|
+
if (
|
|
397
|
+
contentData &&
|
|
398
|
+
contentData.inputs &&
|
|
399
|
+
Array.isArray(contentData.inputs) &&
|
|
400
|
+
contentData.inputs.length
|
|
401
|
+
) {
|
|
402
|
+
if (!contentData.state) {
|
|
403
|
+
contentData.state = {};
|
|
404
|
+
}
|
|
392
405
|
|
|
406
|
+
contentData.inputs.forEach((input: any) => {
|
|
407
|
+
if (input) {
|
|
408
|
+
if (
|
|
409
|
+
input.name &&
|
|
410
|
+
input.defaultValue !== undefined &&
|
|
411
|
+
contentData.state![input.name] === undefined
|
|
412
|
+
) {
|
|
413
|
+
contentData.state![input.name] = input.defaultValue;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
393
420
|
this.state = {
|
|
394
421
|
// TODO: should change if this prop changes
|
|
395
422
|
context: {
|
|
@@ -1389,11 +1416,7 @@ export class BuilderComponent extends React.Component<
|
|
|
1389
1416
|
error.stack
|
|
1390
1417
|
);
|
|
1391
1418
|
} else {
|
|
1392
|
-
if (
|
|
1393
|
-
typeof process !== 'undefined' &&
|
|
1394
|
-
typeof process.env !== 'undefined' &&
|
|
1395
|
-
process.env.DEBUG
|
|
1396
|
-
) {
|
|
1419
|
+
if (isDebug()) {
|
|
1397
1420
|
console.debug(
|
|
1398
1421
|
'Builder custom code error:',
|
|
1399
1422
|
error.message,
|
|
@@ -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
|
|
|
@@ -83,6 +84,7 @@ export function stringToFunction(
|
|
|
83
84
|
}
|
|
84
85
|
/* Alias */
|
|
85
86
|
var ctx = context;
|
|
87
|
+
var log = console.log.bind(console);
|
|
86
88
|
with (rootState) {
|
|
87
89
|
${useReturn ? `return (${str});` : str};
|
|
88
90
|
}
|
|
@@ -117,21 +119,35 @@ export function stringToFunction(
|
|
|
117
119
|
// browser bundler's like rollup and webpack. Our rollup plugin strips these comments only
|
|
118
120
|
// for the server build
|
|
119
121
|
// TODO: cache these for better performancs with new VmScript
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
122
|
+
const isolateContext: import('isolated-vm').Context = getIsolateContext();
|
|
123
|
+
const jail = isolateContext.global;
|
|
124
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
125
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
126
|
+
jail.setSync('global', jail.derefInto());
|
|
123
127
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
...
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
129
|
+
jail.setSync('log', function (...args: any[]) {
|
|
130
|
+
if (isDebug()) {
|
|
131
|
+
console.log(...args);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const ivm = safeDynamicRequire('isolated-vm') as typeof import('isolated-vm');
|
|
136
|
+
return isolateContext.evalClosureSync(
|
|
137
|
+
makeFn(str, useReturn),
|
|
138
|
+
args.map((arg, index) =>
|
|
139
|
+
typeof arg === 'object'
|
|
140
|
+
? new ivm.Reference(
|
|
141
|
+
index === 3
|
|
142
|
+
? {
|
|
143
|
+
...arg,
|
|
144
|
+
getUserAttributes: () => arg.getUserAttributes(''),
|
|
145
|
+
}
|
|
146
|
+
: arg
|
|
147
|
+
)
|
|
148
|
+
: null
|
|
149
|
+
)
|
|
150
|
+
);
|
|
135
151
|
}
|
|
136
152
|
} catch (error: any) {
|
|
137
153
|
if (Builder.isBrowser) {
|
|
@@ -143,11 +159,7 @@ export function stringToFunction(
|
|
|
143
159
|
error.stack || error
|
|
144
160
|
);
|
|
145
161
|
} else {
|
|
146
|
-
if (
|
|
147
|
-
typeof process !== 'undefined' &&
|
|
148
|
-
typeof process.env !== 'undefined' &&
|
|
149
|
-
process.env.DEBUG
|
|
150
|
-
) {
|
|
162
|
+
if (isDebug()) {
|
|
151
163
|
console.debug(
|
|
152
164
|
'Builder custom code error:',
|
|
153
165
|
error.message || error,
|
|
@@ -170,3 +182,43 @@ export function stringToFunction(
|
|
|
170
182
|
|
|
171
183
|
return final;
|
|
172
184
|
}
|
|
185
|
+
|
|
186
|
+
const makeFn = (code: string, useReturn: boolean) => {
|
|
187
|
+
const names = ['state', 'event', 'block', 'builder', 'Device', 'update', 'Builder', 'context'];
|
|
188
|
+
return `
|
|
189
|
+
const refToProxy = (obj) => {
|
|
190
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
191
|
+
return obj;
|
|
192
|
+
}
|
|
193
|
+
return new Proxy({}, {
|
|
194
|
+
get(target, key) {
|
|
195
|
+
const val = obj.getSync(key);
|
|
196
|
+
if (typeof val?.getSync === 'function') {
|
|
197
|
+
return refToProxy(val);
|
|
198
|
+
}
|
|
199
|
+
return val;
|
|
200
|
+
},
|
|
201
|
+
set(target, key, value) {
|
|
202
|
+
obj.setSync(key, value);
|
|
203
|
+
},
|
|
204
|
+
deleteProperty(target, key) {
|
|
205
|
+
obj.deleteSync(key);
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
`.concat(names.map((arg, index) => `var ${arg} = refToProxy($${index});`).join('\n')).concat(`
|
|
210
|
+
var ctx = context;
|
|
211
|
+
${useReturn ? `return (${code});` : code};
|
|
212
|
+
`);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const getIsolateContext = () => {
|
|
216
|
+
const _Builder = Builder as any;
|
|
217
|
+
if (_Builder.serverContext) {
|
|
218
|
+
return _Builder.serverContext;
|
|
219
|
+
}
|
|
220
|
+
const ivm = safeDynamicRequire('isolated-vm') as typeof import('isolated-vm');
|
|
221
|
+
const isolate = new ivm.Isolate({ memoryLimit: 128 });
|
|
222
|
+
_Builder.serverContext = isolate.createContextSync();
|
|
223
|
+
return _Builder.serverContext;
|
|
224
|
+
};
|
|
@@ -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
|