@builder.io/sdk-react 0.5.1 → 0.5.4

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 (84) hide show
  1. package/README.md +4 -0
  2. package/dist/blocks/BaseText.d.ts +1 -0
  3. package/dist/blocks/button/button.d.ts +1 -0
  4. package/dist/blocks/button/button.js +2 -2
  5. package/dist/blocks/columns/columns.d.ts +1 -0
  6. package/dist/blocks/columns/columns.js +2 -2
  7. package/dist/blocks/custom-code/custom-code.d.ts +1 -0
  8. package/dist/blocks/embed/embed.d.ts +1 -0
  9. package/dist/blocks/form/form.d.ts +1 -0
  10. package/dist/blocks/fragment/fragment.d.ts +1 -0
  11. package/dist/blocks/image/image.d.ts +1 -0
  12. package/dist/blocks/img/img.d.ts +1 -0
  13. package/dist/blocks/img/img.js +1 -1
  14. package/dist/blocks/input/input.d.ts +1 -0
  15. package/dist/blocks/input/input.js +1 -1
  16. package/dist/blocks/raw-text/raw-text.d.ts +1 -0
  17. package/dist/blocks/section/section.d.ts +1 -0
  18. package/dist/blocks/section/section.js +1 -1
  19. package/dist/blocks/select/select.d.ts +1 -0
  20. package/dist/blocks/select/select.js +1 -1
  21. package/dist/blocks/submit-button/submit-button.d.ts +1 -0
  22. package/dist/blocks/submit-button/submit-button.js +1 -1
  23. package/dist/blocks/symbol/symbol.d.ts +1 -0
  24. package/dist/blocks/symbol/symbol.js +1 -1
  25. package/dist/blocks/text/text.d.ts +1 -0
  26. package/dist/blocks/text/text.js +1 -1
  27. package/dist/blocks/textarea/textarea.d.ts +1 -0
  28. package/dist/blocks/textarea/textarea.js +1 -1
  29. package/dist/blocks/video/video.d.ts +1 -0
  30. package/dist/components/block/block.d.ts +1 -0
  31. package/dist/components/block/components/block-styles.d.ts +1 -0
  32. package/dist/components/block/components/block-wrapper.d.ts +1 -0
  33. package/dist/components/block/components/component-ref/component-ref.d.ts +1 -0
  34. package/dist/components/block/components/interactive-element.d.ts +1 -0
  35. package/dist/components/block/components/repeated-block.d.ts +1 -0
  36. package/dist/components/blocks/blocks-wrapper.d.ts +1 -0
  37. package/dist/components/blocks/blocks-wrapper.js +1 -1
  38. package/dist/components/blocks/blocks.d.ts +1 -0
  39. package/dist/components/content/components/enable-editor.d.ts +1 -0
  40. package/dist/components/content/components/enable-editor.js +1 -1
  41. package/dist/components/content/components/styles.d.ts +1 -0
  42. package/dist/components/content/content.d.ts +1 -0
  43. package/dist/components/content/content.js +3 -1
  44. package/dist/components/content-variants/content-variants.d.ts +1 -0
  45. package/dist/components/content-variants/content-variants.js +12 -6
  46. package/dist/components/inlined-script.d.ts +1 -0
  47. package/dist/components/inlined-styles.d.ts +1 -0
  48. package/dist/constants/sdk-version.d.ts +1 -1
  49. package/dist/constants/sdk-version.js +1 -1
  50. package/dist/functions/{acorn_interpreter.js → evaluate/acorn-interpreter.js} +1084 -1000
  51. package/dist/functions/evaluate/evaluate.js +1 -1
  52. package/dist/functions/evaluate/non-node-runtime/index.d.ts +1 -0
  53. package/dist/functions/evaluate/non-node-runtime/index.js +2 -0
  54. package/dist/functions/evaluate/{non-node-runtime.d.ts → non-node-runtime/non-node-runtime.d.ts} +1 -1
  55. package/dist/functions/evaluate/{non-node-runtime.js → non-node-runtime/non-node-runtime.js} +3 -3
  56. package/dist/functions/evaluate/types.d.ts +1 -0
  57. package/package.json +12 -3
  58. package/dist/functions/acorn_interpreter.d.ts +0 -1
  59. package/dist/functions/apply-patch-with-mutation.test.d.ts +0 -1
  60. package/dist/functions/apply-patch-with-mutation.test.js +0 -53
  61. package/dist/functions/evaluate/acorn.d.ts +0 -0
  62. package/dist/functions/evaluate/acorn.js +0 -2432
  63. package/dist/functions/evaluate/evaluate.test.d.ts +0 -1
  64. package/dist/functions/evaluate/evaluate.test.js +0 -23
  65. package/dist/functions/evaluate/interpreter.js +0 -3853
  66. package/dist/functions/evaluate.d.ts +0 -23
  67. package/dist/functions/evaluate.js +0 -68
  68. package/dist/functions/evaluate.test.d.ts +0 -1
  69. package/dist/functions/evaluate.test.js +0 -23
  70. package/dist/functions/get-builder-search-params/fn.test.d.ts +0 -1
  71. package/dist/functions/get-builder-search-params/fn.test.js +0 -13
  72. package/dist/functions/get-content/generate-content-url.test.d.ts +0 -1
  73. package/dist/functions/get-content/generate-content-url.test.js +0 -111
  74. package/dist/functions/get-content/processCookies.d.ts +0 -2
  75. package/dist/functions/get-content/processCookies.js +0 -3
  76. package/dist/functions/get-processed-block.test.d.ts +0 -1
  77. package/dist/functions/get-processed-block.test.js +0 -35
  78. package/dist/functions/on-change.test.d.ts +0 -1
  79. package/dist/functions/on-change.test.js +0 -30
  80. package/dist/functions/set.test.d.ts +0 -1
  81. package/dist/functions/set.test.js +0 -22
  82. package/dist/helpers/url.test.d.ts +0 -1
  83. package/dist/helpers/url.test.js +0 -21
  84. /package/dist/functions/evaluate/{interpreter.d.ts → acorn-interpreter.d.ts} +0 -0
@@ -1,23 +0,0 @@
1
- import type { BuilderContextInterface, BuilderRenderContext, BuilderRenderState } from '../context/types.js';
2
- export declare const isNode: () => boolean;
3
- export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: {
4
- code: string;
5
- event?: Event;
6
- isExpression?: boolean;
7
- } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
8
- type ExecutorArgs = {
9
- useCode: string;
10
- builder: {
11
- isEditing: boolean | undefined;
12
- isBrowser: boolean | undefined;
13
- isServer: boolean | undefined;
14
- };
15
- state: BuilderRenderState;
16
- context: BuilderRenderContext;
17
- event: Event | undefined;
18
- };
19
- export declare const runInBrowser: ({ useCode, builder, state, context, event }: ExecutorArgs) => any;
20
- export declare const runInNonNode: ({ useCode, builder, state, context, event }: ExecutorArgs) => void;
21
- export declare const runInNode: (args: ExecutorArgs) => any;
22
- export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
23
- export {};
@@ -1,68 +0,0 @@
1
- import { isBrowser } from './is-browser.js';
2
- import { isEditing } from './is-editing.js';
3
- export const isNode = () => {
4
- return typeof window === 'undefined';
5
- };
6
- export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
7
- if (code === '') {
8
- console.warn('Skipping evaluation of empty code block.');
9
- return;
10
- }
11
- const builder = {
12
- isEditing: isEditing(),
13
- isBrowser: isBrowser(),
14
- isServer: !isBrowser()
15
- };
16
- // Be able to handle simple expressions like "state.foo" or "1 + 1"
17
- // as well as full blocks like "var foo = "bar"; return foo"
18
- const useReturn =
19
- // we disable this for cases where we definitely don't want a return
20
- isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
21
- const useCode = useReturn ? `return (${code});` : code;
22
- const state = flattenState(rootState, localState, rootSetState);
23
- const args = {
24
- useCode,
25
- builder,
26
- state,
27
- context,
28
- event
29
- };
30
- if (isBrowser())
31
- return runInBrowser(args);
32
- if (isNode())
33
- return runInNode(args);
34
- return runInBrowser(args);
35
- }
36
- export const runInBrowser = ({ useCode, builder, state, context, event }) => {
37
- try {
38
- return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, state, context, event);
39
- }
40
- catch (e) {
41
- console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
42
- }
43
- };
44
- export const runInNonNode = ({ useCode, builder, state, context, event }) => { };
45
- export const runInNode = (args) => {
46
- return runInBrowser(args);
47
- };
48
- export function flattenState(rootState, localState, rootSetState) {
49
- if (rootState === localState) {
50
- throw new Error('rootState === localState');
51
- }
52
- return new Proxy(rootState, {
53
- get: (_, prop) => {
54
- if (localState && prop in localState) {
55
- return localState[prop];
56
- }
57
- return rootState[prop];
58
- },
59
- set: (_, prop, value) => {
60
- if (localState && prop in localState) {
61
- throw new Error('Writing to local state is not allowed as it is read-only.');
62
- }
63
- rootState[prop] = value;
64
- rootSetState?.(rootState);
65
- return true;
66
- }
67
- });
68
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,23 +0,0 @@
1
- import { flattenState } from './evaluate.js';
2
- describe('flatten state', () => {
3
- it('should behave normally when no PROTO_STATE', () => {
4
- const localState = {};
5
- const rootState = {
6
- foo: 'bar'
7
- };
8
- const flattened = flattenState(rootState, localState, undefined);
9
- expect(flattened.foo).toEqual('bar');
10
- flattened.foo = 'baz';
11
- expect(rootState.foo).toEqual('baz');
12
- });
13
- it('should shadow write ', () => {
14
- const rootState = {
15
- foo: 'foo'
16
- };
17
- const localState = {
18
- foo: 'baz'
19
- };
20
- const flattened = flattenState(rootState, localState, undefined);
21
- expect(() => flattened.foo = 'bar').toThrow('Writing to local state is not allowed as it is read-only.');
22
- });
23
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { convertSearchParamsToQueryObject, getBuilderSearchParams } from './index.js';
2
- const querystring = 'someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017';
3
- const url = new URL(`localhost:3000/about-us?${querystring}`);
4
- describe('Get Builder SearchParams', () => {
5
- test('correctly converts URLSearchParams to object', () => {
6
- const output = convertSearchParamsToQueryObject(url.searchParams);
7
- expect(output).toMatchSnapshot();
8
- });
9
- test('correctly extracts all builder params from a query object', () => {
10
- const output = getBuilderSearchParams(convertSearchParamsToQueryObject(url.searchParams));
11
- expect(output).toMatchSnapshot();
12
- });
13
- });
@@ -1,111 +0,0 @@
1
- import { generateContentUrl } from './generate-content-url.js';
2
- const testKey = 'YJIGb4i01jvw0SRdL5Bt';
3
- const testModel = 'page';
4
- const testId = 'c1b81bab59704599b997574eb0736def';
5
- const options = {
6
- cachebust: 'true',
7
- noCache: 'true',
8
- 'overrides.037948e52eaf4743afed464f02c70da4': '037948e52eaf4743afed464f02c70da4',
9
- 'overrides.page': '037948e52eaf4743afed464f02c70da4',
10
- 'overrides.page:/': '037948e52eaf4743afed464f02c70da4',
11
- preview: 'page'
12
- };
13
- describe('Generate Content URL', () => {
14
- test('generates the proper value for a simple query', () => {
15
- const output = generateContentUrl({
16
- apiKey: testKey,
17
- model: testModel,
18
- query: {
19
- id: testId
20
- }
21
- });
22
- expect(output).toMatchSnapshot();
23
- });
24
- test('Handles overrides correctly', () => {
25
- const output = generateContentUrl({
26
- apiKey: testKey,
27
- model: testModel,
28
- query: {
29
- id: testId
30
- },
31
- options
32
- });
33
- expect(output).toMatchSnapshot();
34
- });
35
- test('generate content url with apiVersion as default', () => {
36
- const output = generateContentUrl({
37
- apiKey: testKey,
38
- model: testModel,
39
- query: {
40
- id: testId
41
- },
42
- options
43
- });
44
- expect(output).toMatchSnapshot();
45
- });
46
- test('generate content url with apiVersion as v2', () => {
47
- const output = generateContentUrl({
48
- apiKey: testKey,
49
- model: testModel,
50
- query: {
51
- id: testId
52
- },
53
- options,
54
- apiVersion: 'v2'
55
- });
56
- expect(output).toMatchSnapshot();
57
- });
58
- test('generate content url with apiVersion as v3', () => {
59
- const output = generateContentUrl({
60
- apiKey: testKey,
61
- model: testModel,
62
- query: {
63
- id: testId
64
- },
65
- options,
66
- apiVersion: 'v3'
67
- });
68
- expect(output).toMatchSnapshot();
69
- });
70
- test('throw error when trying to generate content url with apiVersion as v1', () => {
71
- expect(() => {
72
- generateContentUrl({
73
- apiKey: testKey,
74
- model: testModel,
75
- query: {
76
- id: testId
77
- },
78
- options,
79
- apiVersion: 'v1'
80
- });
81
- }).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'v1'`);
82
- });
83
- test('throw error when trying to generate content url with an invalid apiVersion value', () => {
84
- expect(() => {
85
- generateContentUrl({
86
- apiKey: testKey,
87
- model: testModel,
88
- query: {
89
- id: testId
90
- },
91
- options,
92
- apiVersion: 'INVALID_API_VERSION'
93
- });
94
- }).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`);
95
- });
96
- test('generate content url with enrich option true', () => {
97
- const output = generateContentUrl({
98
- apiKey: testKey,
99
- model: testModel,
100
- enrich: true
101
- });
102
- expect(output).toMatchSnapshot();
103
- });
104
- test('generate content url with enrich option not present', () => {
105
- const output = generateContentUrl({
106
- apiKey: testKey,
107
- model: testModel
108
- });
109
- expect(output).toMatchSnapshot();
110
- });
111
- });
@@ -1,2 +0,0 @@
1
- import type { BuilderContent } from '../../types/builder-content.js';
2
- export declare const processCookies: (content: BuilderContent) => BuilderContent;
@@ -1,3 +0,0 @@
1
- export const processCookies = (content) => {
2
- return content;
3
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,35 +0,0 @@
1
- import { getProcessedBlock } from './get-processed-block.js';
2
- test('Can process bindings', () => {
3
- const block = {
4
- '@type': '@builder.io/sdk:Element',
5
- properties: {
6
- foo: 'bar'
7
- },
8
- bindings: {
9
- 'properties.foo': '"baz"',
10
- 'responsiveStyles.large.zIndex': '1 + 1',
11
- 'properties.test': 'state.test',
12
- 'properties.block': `
13
- var foo = 'bar';
14
- return foo;
15
- `,
16
- 'properties.isEditing': 'builder.isEditing'
17
- }
18
- };
19
- const processed = getProcessedBlock({
20
- block,
21
- context: {},
22
- rootState: {
23
- test: 'hello'
24
- },
25
- rootSetState: undefined,
26
- localState: undefined,
27
- shouldEvaluateBindings: true
28
- });
29
- expect(processed).not.toEqual(block);
30
- expect(processed.properties?.foo).toEqual('baz');
31
- expect(processed.properties?.test).toEqual('hello');
32
- expect(processed.properties?.block).toEqual('bar');
33
- expect(processed.properties?.isEditing).toEqual(false);
34
- expect(processed.responsiveStyles?.large?.zIndex).toEqual(2);
35
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import { onChange } from './on-change.js';
2
- test('onChange can observe a shallow change', () => {
3
- let changeHappend = false;
4
- const obj = onChange({
5
- foo: 'hi'
6
- }, () => changeHappend = true);
7
- obj.foo = 'yo';
8
- expect(changeHappend).toBe(true);
9
- });
10
- test('onChange can observe a deep change', () => {
11
- let changeHappend = false;
12
- const obj = onChange({
13
- foo: {
14
- bar: 'hi'
15
- }
16
- }, () => changeHappend = true);
17
- obj.foo.bar = 'yo';
18
- expect(changeHappend).toBe(true);
19
- });
20
- test('Smoke test: callback is not fired if no properties updated', () => {
21
- let changeHappend = false;
22
- const obj = onChange({
23
- foo: {
24
- bar: 'hi'
25
- }
26
- }, () => changeHappend = true);
27
- // Access some properties
28
- obj.foo.bar;
29
- expect(changeHappend).toBe(false);
30
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import { set } from './set.js';
2
- test('can shallow set a property', () => {
3
- const obj = {
4
- foo: 'bar'
5
- };
6
- set(obj, 'foo', 'baz');
7
- expect(obj.foo).toBe('baz');
8
- });
9
- test('can deeply set a property', () => {
10
- const obj = {
11
- foo: 'bar'
12
- };
13
- set(obj, 'foo.bar', 'baz');
14
- expect(obj.foo.bar).toBe('baz');
15
- });
16
- test('can deeply create arrays', () => {
17
- const obj = {
18
- foo: 'bar'
19
- };
20
- set(obj, 'foo.bar.0', 'hi');
21
- expect(obj.foo.bar).toEqual(['hi']);
22
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import { getTopLevelDomain } from './url.js';
2
- describe('getTopLevelDomain', () => {
3
- test('handles root domain', () => {
4
- const output = getTopLevelDomain('example.com');
5
- expect(output).toBe('example.com');
6
- });
7
- test('handles subdomain', () => {
8
- const output = getTopLevelDomain('wwww.example.com');
9
- expect(output).toBe('example.com');
10
- });
11
- test('handles subdomain with long suffix', () => {
12
- const output = getTopLevelDomain('www.example.co.uk');
13
- expect(output).toBe('example.co.uk');
14
- });
15
- test('handles localhost', () => {
16
- const output = getTopLevelDomain('localhost');
17
- expect(output).toBe('localhost');
18
- const output2 = getTopLevelDomain('127.0.0.1');
19
- expect(output2).toBe('127.0.0.1');
20
- });
21
- });