@builder.io/react 2.0.0 → 2.0.2-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.
Files changed (40) hide show
  1. package/README.md +47 -51
  2. package/dist/builder-react-lite.cjs.js +2 -2
  3. package/dist/builder-react-lite.cjs.js.map +1 -1
  4. package/dist/builder-react-lite.esm.js +2 -2
  5. package/dist/builder-react-lite.esm.js.map +1 -1
  6. package/dist/builder-react.browser.js +2 -2
  7. package/dist/builder-react.browser.js.map +1 -1
  8. package/dist/builder-react.cjs.js +2 -2
  9. package/dist/builder-react.cjs.js.map +1 -1
  10. package/dist/builder-react.es5.js +2 -2
  11. package/dist/builder-react.es5.js.map +1 -1
  12. package/dist/builder-react.unpkg.js +2 -2
  13. package/dist/builder-react.unpkg.js.map +1 -1
  14. package/dist/lib/package.json +1 -1
  15. package/dist/lib/src/blocks/Text.js +5 -1
  16. package/dist/lib/src/blocks/Text.js.map +1 -1
  17. package/dist/lib/src/builder-react-lite.js +3 -3
  18. package/dist/lib/src/builder-react-lite.js.map +1 -1
  19. package/dist/lib/src/builder-react.js +3 -3
  20. package/dist/lib/src/builder-react.js.map +1 -1
  21. package/dist/lib/src/components/builder-component.component.js +3 -63
  22. package/dist/lib/src/components/builder-component.component.js.map +1 -1
  23. package/dist/lib/src/functions/try-eval.js +78 -0
  24. package/dist/lib/src/functions/try-eval.js.map +1 -0
  25. package/dist/lib/src/hooks/{isPreviewing.js → useIsPreviewing.js} +4 -4
  26. package/dist/lib/src/hooks/useIsPreviewing.js.map +1 -0
  27. package/dist/types/src/builder-react-lite.d.ts +1 -1
  28. package/dist/types/src/builder-react.d.ts +1 -1
  29. package/dist/types/src/functions/try-eval.d.ts +1 -0
  30. package/dist/types/src/hooks/useIsPreviewing.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/src/blocks/Text.tsx +10 -1
  33. package/src/builder-react-lite.ts +1 -1
  34. package/src/builder-react.ts +1 -1
  35. package/src/components/builder-component.component.tsx +1 -79
  36. package/src/functions/try-eval.tsx +80 -0
  37. package/src/hooks/{isPreviewing.ts → useIsPreviewing.ts} +1 -1
  38. package/=16.8 +0 -15
  39. package/dist/lib/src/hooks/isPreviewing.js.map +0 -1
  40. package/dist/types/src/hooks/isPreviewing.d.ts +0 -1
@@ -28,8 +28,8 @@ import {
28
28
  import { Url } from 'url';
29
29
  import { debounceNextTick } from '../functions/debonce-next-tick';
30
30
  import { throttle } from '../functions/throttle';
31
- import { safeDynamicRequire } from '../functions/safe-dynamic-require';
32
31
  import { BuilderMetaContext } from '../store/builder-meta';
32
+ import { tryEval } from '../functions/try-eval';
33
33
 
34
34
  function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K> {
35
35
  const ret: any = {};
@@ -309,84 +309,6 @@ export interface BuilderComponentState {
309
309
  key: number;
310
310
  }
311
311
 
312
- const tryEval = (str?: string, data: any = {}, errors?: Error[]): any => {
313
- const value = str;
314
- if (!(typeof value === 'string' && value.trim())) {
315
- return;
316
- }
317
- const useReturn = !(value.includes(';') || value.includes(' return '));
318
- let fn: Function = () => {
319
- /* Intentionally empty */
320
- };
321
- try {
322
- if (Builder.isBrowser) {
323
- // tslint:disable-next-line:no-function-constructor-with-string-args
324
- // TODO: VM in node......
325
- fn = new Function(
326
- 'state',
327
- // TODO: remove the with () {} - make a page v3 that doesn't use this
328
- `var rootState = state;
329
- if (typeof Proxy !== 'undefined') {
330
- rootState = new Proxy(rootState, {
331
- set: function () {
332
- return false;
333
- },
334
- get: function (target, key) {
335
- if (key === 'state') {
336
- return state;
337
- }
338
- return target[key]
339
- }
340
- });
341
- }
342
- with (rootState) {
343
- ${useReturn ? `return (${str});` : str};
344
- }`
345
- );
346
- }
347
- } catch (error) {
348
- if (Builder.isBrowser) {
349
- console.warn('Could not compile javascript', error);
350
- } else {
351
- // Add to req.options.errors to return to client
352
- }
353
- }
354
- try {
355
- if (Builder.isBrowser) {
356
- return fn(data || {});
357
- } else {
358
- // Below is a hack to get certain code to *only* load in the server build, to not screw with
359
- // browser bundler's like rollup and webpack. Our rollup plugin strips these comments only
360
- // for the server build
361
- // tslint:disable:comment-format
362
- const { VM } = safeDynamicRequire('vm2');
363
- return new VM({
364
- sandbox: {
365
- ...data,
366
- ...{ state: data },
367
- },
368
- // TODO: convert reutrn to module.exports on server
369
- }).run(value.replace(/(^|;)return /, '$1'));
370
- // tslint:enable:comment-format
371
- }
372
- } catch (error: any) {
373
- if (errors) {
374
- errors.push(error);
375
- }
376
-
377
- if (Builder.isBrowser) {
378
- console.warn('Builder custom code error:', error.message, 'in', str, error.stack);
379
- } else {
380
- if (process.env.DEBUG) {
381
- console.debug('Builder custom code error:', error.message, 'in', str, error.stack);
382
- }
383
- // Add to req.options.errors to return to client
384
- }
385
- }
386
-
387
- return;
388
- };
389
-
390
312
  function searchToObject(location: Location | Url) {
391
313
  const pairs = (location.search || '').substring(1).split('&');
392
314
  const obj: { [key: string]: string } = {};
@@ -0,0 +1,80 @@
1
+ import { Builder } from '@builder.io/sdk';
2
+ import { safeDynamicRequire } from './safe-dynamic-require';
3
+
4
+ export const tryEval = (str?: string, data: any = {}, errors?: Error[]): any => {
5
+ const value = str;
6
+ if (!(typeof value === 'string' && value.trim())) {
7
+ return;
8
+ }
9
+ const useReturn = !(value.includes(';') || value.includes(' return '));
10
+ let fn: Function = () => {
11
+ /* Intentionally empty */
12
+ };
13
+ try {
14
+ if (Builder.isBrowser) {
15
+ // tslint:disable-next-line:no-function-constructor-with-string-args
16
+ // TODO: VM in node......
17
+ fn = new Function(
18
+ 'state',
19
+ // TODO: remove the with () {} - make a page v3 that doesn't use this
20
+ `var rootState = state;
21
+ if (typeof Proxy !== 'undefined') {
22
+ rootState = new Proxy(rootState, {
23
+ set: function () {
24
+ return false;
25
+ },
26
+ get: function (target, key) {
27
+ if (key === 'state') {
28
+ return state;
29
+ }
30
+ return target[key]
31
+ }
32
+ });
33
+ }
34
+ with (rootState) {
35
+ ${useReturn ? `return (${str});` : str};
36
+ }`
37
+ );
38
+ }
39
+ } catch (error) {
40
+ if (Builder.isBrowser) {
41
+ console.warn('Could not compile javascript', error);
42
+ } else {
43
+ // Add to req.options.errors to return to client
44
+ }
45
+ }
46
+ try {
47
+ if (Builder.isBrowser) {
48
+ return fn(data || {});
49
+ } else {
50
+ // Below is a hack to get certain code to *only* load in the server build, to not screw with
51
+ // browser bundler's like rollup and webpack. Our rollup plugin strips these comments only
52
+ // for the server build
53
+ // tslint:disable:comment-format
54
+ const { VM } = safeDynamicRequire('vm2');
55
+ return new VM({
56
+ sandbox: {
57
+ ...data,
58
+ ...{ state: data },
59
+ },
60
+ // TODO: convert reutrn to module.exports on server
61
+ }).run(value.replace(/(^|;)return /, '$1'));
62
+ // tslint:enable:comment-format
63
+ }
64
+ } catch (error: any) {
65
+ if (errors) {
66
+ errors.push(error);
67
+ }
68
+
69
+ if (Builder.isBrowser) {
70
+ console.warn('Builder custom code error:', error.message, 'in', str, error.stack);
71
+ } else {
72
+ if (process.env.DEBUG) {
73
+ console.debug('Builder custom code error:', error.message, 'in', str, error.stack);
74
+ }
75
+ // Add to req.options.errors to return to client
76
+ }
77
+ }
78
+
79
+ return;
80
+ };
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Builder } from '@builder.io/sdk';
3
3
 
4
- export function isPreviewing() {
4
+ export function useIsPreviewing() {
5
5
  const [isPreviewing, setIsPreviewing] = useState(false);
6
6
 
7
7
  useEffect(() => {
package/=16.8 DELETED
@@ -1,15 +0,0 @@
1
-
2
- up to date, audited 1914 packages in 4s
3
-
4
- 46 packages are looking for funding
5
- run `npm fund` for details
6
-
7
- 39 vulnerabilities (15 moderate, 21 high, 3 critical)
8
-
9
- To address issues that do not require attention, run:
10
- npm audit fix
11
-
12
- To address all issues (including breaking changes), run:
13
- npm audit fix --force
14
-
15
- Run `npm audit` for details.
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPreviewing.js","sourceRoot":"","sources":["../../../../src/hooks/isPreviewing.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAC5C,uCAA0C;AAE1C,SAAgB,YAAY;IACpB,IAAA,KAAkC,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAhD,YAAY,QAAA,EAAE,eAAe,QAAmB,CAAC;IAExD,IAAA,iBAAS,EAAC;QACR,IAAI,aAAO,CAAC,SAAS,IAAI,aAAO,CAAC,YAAY,EAAE;YAC7C,eAAe,CAAC,IAAI,CAAC,CAAC;SACvB;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,YAAY,CAAC;AACtB,CAAC;AAVD,oCAUC"}
@@ -1 +0,0 @@
1
- export declare function isPreviewing(): boolean;