@builder.io/sdk-svelte 1.0.11 → 1.0.12

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 (102) hide show
  1. package/lib/browser/blocks/BaseText.svelte +1 -3
  2. package/lib/browser/blocks/button/button.svelte +2 -3
  3. package/lib/browser/blocks/columns/columns.svelte +3 -5
  4. package/lib/browser/blocks/form/form/form.svelte +5 -7
  5. package/lib/browser/blocks/form/submit-button/submit-button.svelte +2 -4
  6. package/lib/browser/blocks/image/image.svelte +4 -7
  7. package/lib/browser/blocks/video/video.svelte +2 -5
  8. package/lib/browser/components/block/block.helpers.d.ts +4 -0
  9. package/lib/browser/components/block/block.helpers.js +14 -1
  10. package/lib/browser/components/block/block.svelte +4 -10
  11. package/lib/browser/components/block/components/block-wrapper.svelte +2 -4
  12. package/lib/browser/components/block/components/interactive-element.svelte +2 -4
  13. package/lib/browser/components/blocks/blocks-wrapper.svelte +1 -3
  14. package/lib/browser/components/blocks/blocks.svelte +2 -2
  15. package/lib/browser/components/content/components/enable-editor.svelte +8 -5
  16. package/lib/browser/components/content/content.svelte +3 -5
  17. package/lib/browser/components/content-variants/content-variants.svelte +0 -2
  18. package/lib/browser/components/dynamic-renderer/dynamic-renderer.svelte +4 -6
  19. package/lib/browser/constants/sdk-version.d.ts +1 -1
  20. package/lib/browser/constants/sdk-version.js +1 -1
  21. package/lib/browser/functions/evaluate/browser-runtime/browser.js +1 -1
  22. package/lib/browser/functions/evaluate/evaluate.d.ts +3 -1
  23. package/lib/browser/functions/evaluate/evaluate.js +39 -3
  24. package/lib/browser/functions/evaluate/helpers.d.ts +1 -0
  25. package/lib/browser/functions/get-block-actions-handler.js +2 -1
  26. package/lib/browser/functions/get-processed-block.js +2 -1
  27. package/lib/edge/blocks/BaseText.svelte +1 -3
  28. package/lib/edge/blocks/button/button.svelte +2 -3
  29. package/lib/edge/blocks/columns/columns.svelte +3 -5
  30. package/lib/edge/blocks/form/form/form.svelte +5 -7
  31. package/lib/edge/blocks/form/submit-button/submit-button.svelte +2 -4
  32. package/lib/edge/blocks/image/image.svelte +4 -7
  33. package/lib/edge/blocks/video/video.svelte +2 -5
  34. package/lib/edge/components/block/block.helpers.d.ts +4 -0
  35. package/lib/edge/components/block/block.helpers.js +14 -1
  36. package/lib/edge/components/block/block.svelte +4 -10
  37. package/lib/edge/components/block/components/block-wrapper.svelte +2 -4
  38. package/lib/edge/components/block/components/interactive-element.svelte +2 -4
  39. package/lib/edge/components/blocks/blocks-wrapper.svelte +1 -3
  40. package/lib/edge/components/blocks/blocks.svelte +2 -2
  41. package/lib/edge/components/content/components/enable-editor.svelte +8 -5
  42. package/lib/edge/components/content/content.svelte +3 -5
  43. package/lib/edge/components/content-variants/content-variants.svelte +0 -2
  44. package/lib/edge/components/dynamic-renderer/dynamic-renderer.svelte +4 -6
  45. package/lib/edge/constants/sdk-version.d.ts +1 -1
  46. package/lib/edge/constants/sdk-version.js +1 -1
  47. package/lib/edge/functions/evaluate/browser-runtime/browser.js +1 -1
  48. package/lib/edge/functions/evaluate/evaluate.d.ts +3 -1
  49. package/lib/edge/functions/evaluate/evaluate.js +39 -3
  50. package/lib/edge/functions/evaluate/helpers.d.ts +1 -0
  51. package/lib/edge/functions/get-block-actions-handler.js +2 -1
  52. package/lib/edge/functions/get-processed-block.js +2 -1
  53. package/lib/node/blocks/BaseText.svelte +1 -3
  54. package/lib/node/blocks/button/button.svelte +2 -3
  55. package/lib/node/blocks/columns/columns.svelte +3 -5
  56. package/lib/node/blocks/form/form/form.svelte +5 -7
  57. package/lib/node/blocks/form/submit-button/submit-button.svelte +2 -4
  58. package/lib/node/blocks/image/image.svelte +4 -7
  59. package/lib/node/blocks/video/video.svelte +2 -5
  60. package/lib/node/components/block/block.helpers.d.ts +4 -0
  61. package/lib/node/components/block/block.helpers.js +14 -1
  62. package/lib/node/components/block/block.svelte +4 -10
  63. package/lib/node/components/block/components/block-wrapper.svelte +2 -4
  64. package/lib/node/components/block/components/interactive-element.svelte +2 -4
  65. package/lib/node/components/blocks/blocks-wrapper.svelte +1 -3
  66. package/lib/node/components/blocks/blocks.svelte +2 -2
  67. package/lib/node/components/content/components/enable-editor.svelte +8 -5
  68. package/lib/node/components/content/content.svelte +3 -5
  69. package/lib/node/components/content-variants/content-variants.svelte +0 -2
  70. package/lib/node/components/dynamic-renderer/dynamic-renderer.svelte +4 -6
  71. package/lib/node/constants/sdk-version.d.ts +1 -1
  72. package/lib/node/constants/sdk-version.js +1 -1
  73. package/lib/node/functions/evaluate/browser-runtime/browser.js +1 -1
  74. package/lib/node/functions/evaluate/evaluate.d.ts +3 -1
  75. package/lib/node/functions/evaluate/evaluate.js +39 -3
  76. package/lib/node/functions/evaluate/helpers.d.ts +1 -0
  77. package/lib/node/functions/get-block-actions-handler.js +2 -1
  78. package/lib/node/functions/get-processed-block.js +2 -1
  79. package/package.json +1 -1
  80. package/src/blocks/BaseText.svelte +1 -3
  81. package/src/blocks/button/button.svelte +2 -3
  82. package/src/blocks/columns/columns.svelte +3 -5
  83. package/src/blocks/form/form/form.svelte +5 -7
  84. package/src/blocks/form/submit-button/submit-button.svelte +2 -4
  85. package/src/blocks/image/image.svelte +4 -7
  86. package/src/blocks/video/video.svelte +2 -5
  87. package/src/components/block/block.helpers.ts +20 -1
  88. package/src/components/block/block.svelte +8 -11
  89. package/src/components/block/components/block-wrapper.svelte +2 -4
  90. package/src/components/block/components/interactive-element.svelte +2 -4
  91. package/src/components/blocks/blocks-wrapper.svelte +1 -3
  92. package/src/components/blocks/blocks.svelte +2 -2
  93. package/src/components/content/components/enable-editor.svelte +21 -10
  94. package/src/components/content/content.svelte +3 -5
  95. package/src/components/content-variants/content-variants.svelte +0 -2
  96. package/src/components/dynamic-renderer/dynamic-renderer.svelte +4 -6
  97. package/src/constants/sdk-version.ts +1 -1
  98. package/src/functions/evaluate/browser-runtime/browser.ts +1 -1
  99. package/src/functions/evaluate/evaluate.ts +44 -4
  100. package/src/functions/evaluate/helpers.ts +1 -0
  101. package/src/functions/get-block-actions-handler.ts +2 -1
  102. package/src/functions/get-processed-block.ts +2 -1
@@ -16,6 +16,4 @@ function mitosis_styling(node, vars) {
16
16
  let builderContext = getContext(BuilderContext.key);
17
17
  </script>
18
18
 
19
- <span use:mitosis_styling={$builderContext.inheritedStyles}>
20
- {text}
21
- </span>
19
+ <span use:mitosis_styling={$builderContext.inheritedStyles}>{text}</span>
@@ -26,6 +26,5 @@ export let text = undefined;
26
26
  }}
27
27
  TagName={link ? builderLinkComponent || "a" : "button"}
28
28
  actionAttributes={filterAttrs(attributes, "on:", true)}
29
- >
30
- {text}
31
- </DynamicRenderer>
29
+ >{text}</DynamicRenderer
30
+ >
@@ -131,7 +131,6 @@ let flexDir = stackColumnsAt === "never"
131
131
  {#if TARGET !== "reactNative"}
132
132
  <InlinedStyles styles={columnsStyles()} />
133
133
  {/if}
134
-
135
134
  {#each columns as column, index (index)}
136
135
  <DynamicRenderer
137
136
  TagName={column.link ? builderLinkComponent || "a" : "div"}
@@ -146,8 +145,7 @@ let flexDir = stackColumnsAt === "never"
146
145
  [getClassPropName()]: "builder-column",
147
146
  style: mapStyleObjToStrIfNeeded(columnCssVars(index)),
148
147
  }}
149
- >
150
- <Blocks
148
+ ><Blocks
151
149
  path={`component.options.columns.${index}.blocks`}
152
150
  parent={builderBlock.id}
153
151
  styleProp={{
@@ -157,8 +155,8 @@ let flexDir = stackColumnsAt === "never"
157
155
  registeredComponents={builderComponents}
158
156
  linkComponent={builderLinkComponent}
159
157
  blocks={column.blocks}
160
- />
161
- </DynamicRenderer>
158
+ /></DynamicRenderer
159
+ >
162
160
  {/each}
163
161
  </div>
164
162
 
@@ -261,7 +261,6 @@ let formErrorMessage = "";
261
261
  />
262
262
  {/each}
263
263
  {/if}
264
-
265
264
  {#if submissionState() === "error"}
266
265
  <Blocks
267
266
  path="errorMessage"
@@ -269,7 +268,6 @@ let formErrorMessage = "";
269
268
  context={builderContext}
270
269
  />
271
270
  {/if}
272
-
273
271
  {#if submissionState() === "sending"}
274
272
  <Blocks
275
273
  path="sendingMessage"
@@ -277,13 +275,13 @@ let formErrorMessage = "";
277
275
  context={builderContext}
278
276
  />
279
277
  {/if}
280
-
281
278
  {#if submissionState() === "error" && responseData}
282
- <pre class="builder-form-error-text pre">
283
- {JSON.stringify(responseData, null, 2)}
284
- </pre>
279
+ <pre class="builder-form-error-text pre">{JSON.stringify(
280
+ responseData,
281
+ null,
282
+ 2
283
+ )}</pre>
285
284
  {/if}
286
-
287
285
  {#if submissionState() === "success"}
288
286
  <Blocks
289
287
  path="successMessage"
@@ -12,7 +12,5 @@ export let text = undefined;
12
12
  <button
13
13
  type="submit"
14
14
  {...filterAttrs(attributes, "on:", false)}
15
- use:setAttrs={filterAttrs(attributes, "on:", true)}
16
- >
17
- {text}
18
- </button>
15
+ use:setAttrs={filterAttrs(attributes, "on:", true)}>{text}</button
16
+ >
@@ -65,8 +65,7 @@ $: aspectRatioCss = () => {
65
65
  <picture>
66
66
  {#if webpSrcSet()}
67
67
  <source type="image/webp" srcset={webpSrcSet()} />
68
- {/if}
69
- <img
68
+ {/if}<img
70
69
  use:mitosis_styling={{
71
70
  objectPosition: backgroundPosition || "center",
72
71
  objectFit: backgroundSize || "cover",
@@ -79,8 +78,8 @@ $: aspectRatioCss = () => {
79
78
  src={image}
80
79
  srcset={srcSetToUse()}
81
80
  {sizes}
82
- />
83
- </picture>
81
+ /></picture
82
+ >
84
83
 
85
84
  {#if aspectRatio && !(builderBlock?.children?.length && fitContent)}
86
85
  <div
@@ -96,9 +95,7 @@ $: aspectRatioCss = () => {
96
95
  {/if}
97
96
 
98
97
  {#if !fitContent && $$slots.default}
99
- <div class="div-2">
100
- <slot />
101
- </div>
98
+ <div class="div-2"><slot /></div>
102
99
  {/if}
103
100
 
104
101
  <style>
@@ -89,9 +89,8 @@ $: spreadProps = () => {
89
89
  >
90
90
  {#if !lazyLoad}
91
91
  <source type="video/mp4" src={video} />
92
- {/if}
93
- </video>
94
-
92
+ {/if}</video
93
+ >
95
94
  {#if aspectRatio && !(fitContent && builderBlock?.children?.length)}
96
95
  <div
97
96
  use:mitosis_styling={{
@@ -102,7 +101,6 @@ $: spreadProps = () => {
102
101
  }}
103
102
  />
104
103
  {/if}
105
-
106
104
  {#if builderBlock?.children?.length && fitContent}
107
105
  <div
108
106
  use:mitosis_styling={{
@@ -114,7 +112,6 @@ $: spreadProps = () => {
114
112
  <slot />
115
113
  </div>
116
114
  {/if}
117
-
118
115
  {#if builderBlock?.children?.length && !fitContent}
119
116
  <div
120
117
  use:mitosis_styling={{
@@ -10,3 +10,7 @@ export declare const getRepeatItemData: ({ block, context }: {
10
10
  block: BuilderBlock;
11
11
  context: BuilderContextInterface;
12
12
  }) => RepeatData[] | undefined;
13
+ export declare const getInheritedStyles: ({ block, context }: {
14
+ block: BuilderBlock;
15
+ context: BuilderContextInterface;
16
+ }) => Partial<CSSStyleDeclaration>;
@@ -1,5 +1,7 @@
1
1
  import { evaluate } from '../../functions/evaluate/index.js';
2
+ import { extractTextStyles } from '../../functions/extract-text-styles.js';
2
3
  import { getProcessedBlock } from '../../functions/get-processed-block.js';
4
+ import { getStyle } from '../../functions/get-style.js';
3
5
  export const getComponent = ({ block, context, registeredComponents }) => {
4
6
  const componentName = getProcessedBlock({
5
7
  block,
@@ -38,7 +40,8 @@ export const getRepeatItemData = ({ block, context }) => {
38
40
  localState: context.localState,
39
41
  rootState: context.rootState,
40
42
  rootSetState: context.rootSetState,
41
- context: context.context
43
+ context: context.context,
44
+ enableCache: true
42
45
  });
43
46
  if (!Array.isArray(itemsArray)) {
44
47
  return undefined;
@@ -60,3 +63,13 @@ export const getRepeatItemData = ({ block, context }) => {
60
63
  }));
61
64
  return repeatArray;
62
65
  };
66
+ export const getInheritedStyles = ({ block, context }) => {
67
+ const style = getStyle({
68
+ block,
69
+ context
70
+ });
71
+ if (!style) {
72
+ return {};
73
+ }
74
+ return extractTextStyles(style);
75
+ };
@@ -1,13 +1,10 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { onMount } from "svelte";
4
- import { writable } from "svelte/store";
5
- import "../../functions/extract-text-styles.js";
6
4
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
7
5
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
8
- import "../../functions/get-style.js";
9
6
  import { bindAnimations } from "./animator.js";
10
- import { getComponent, getRepeatItemData } from "./block.helpers.js";
7
+ import { getComponent, getRepeatItemData, } from "./block.helpers.js";
11
8
  import BlockStyles from "./components/block-styles.svelte";
12
9
  import BlockWrapper from "./components/block-wrapper.svelte";
13
10
  import ComponentRef from "./components/component-ref/component-ref.svelte";
@@ -95,7 +92,7 @@ $: componentRefProps = () => {
95
92
  }
96
93
  : {}),
97
94
  },
98
- context: childrenContext,
95
+ context: context,
99
96
  linkComponent: linkComponent,
100
97
  registeredComponents: registeredComponents,
101
98
  builderBlock: processedBlock(),
@@ -103,7 +100,6 @@ $: componentRefProps = () => {
103
100
  isInteractive: !blockComponent?.()?.isRSC,
104
101
  };
105
102
  };
106
- let childrenContext = writable($context);
107
103
  onMount(() => {
108
104
  const blockId = processedBlock().id;
109
105
  const animations = processedBlock().animations;
@@ -128,8 +124,7 @@ onMount(() => {
128
124
  block={processedBlock()}
129
125
  {context}
130
126
  {linkComponent}
131
- >
132
- <ComponentRef
127
+ ><ComponentRef
133
128
  componentRef={componentRefProps().componentRef}
134
129
  componentOptions={componentRefProps().componentOptions}
135
130
  blockChildren={componentRefProps().blockChildren}
@@ -140,13 +135,12 @@ onMount(() => {
140
135
  includeBlockProps={componentRefProps().includeBlockProps}
141
136
  isInteractive={componentRefProps().isInteractive}
142
137
  />
143
-
144
138
  {#each childrenWithoutParentComponent() as child (child.id)}
145
139
  <svelte:self
146
140
  block={child}
147
- context={childrenContext}
148
141
  {registeredComponents}
149
142
  {linkComponent}
143
+ {context}
150
144
  />
151
145
  {/each}
152
146
  </BlockWrapper>
@@ -24,7 +24,5 @@ export let context;
24
24
  localState: $context.localState,
25
25
  context: $context.context,
26
26
  stripPrefix: true,
27
- })}
28
- >
29
- <slot />
30
- </DynamicRenderer>
27
+ })}><slot /></DynamicRenderer
28
+ >
@@ -26,7 +26,5 @@ export let context;
26
26
  context: $context.context,
27
27
  }),
28
28
  }
29
- : {}}
30
- >
31
- <slot />
32
- </svelte:component>
29
+ : {}}><slot /></svelte:component
30
+ >
@@ -60,10 +60,8 @@ $: className = () => {
60
60
  on:keypress={(event) => {
61
61
  onClick();
62
62
  }}
63
- {...BlocksWrapperProps}
63
+ {...BlocksWrapperProps}><slot /></svelte:element
64
64
  >
65
- <slot />
66
- </svelte:element>
67
65
 
68
66
  <style>
69
67
  .svelte-element {
@@ -33,5 +33,5 @@ let componentsContext = getContext(ComponentsContext.key);
33
33
  componentsContext.registeredComponents}
34
34
  />
35
35
  {/each}
36
- {/if}
37
- </BlocksWrapper>
36
+ {/if}</BlocksWrapper
37
+ >
@@ -99,6 +99,10 @@ function evaluateJsCode() {
99
99
  localState: undefined,
100
100
  rootState: $builderContextSignal.rootState,
101
101
  rootSetState: $builderContextSignal.rootSetState,
102
+ /**
103
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
104
+ */
105
+ enableCache: false,
102
106
  });
103
107
  }
104
108
  }
@@ -121,13 +125,14 @@ function onClick(event) {
121
125
  }
122
126
  }
123
127
  function evalExpression(expression) {
124
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
128
+ return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
125
129
  code: group,
126
130
  context: context || {},
127
131
  localState: undefined,
128
132
  rootState: $builderContextSignal.rootState,
129
133
  rootSetState: $builderContextSignal.rootSetState,
130
- }));
134
+ enableCache: true,
135
+ })));
131
136
  }
132
137
  function handleRequest({ url, key }) {
133
138
  fetch(url)
@@ -341,8 +346,6 @@ onDestroy(() => {
341
346
  }}
342
347
  on:initpreviewingbldr={(event) => {
343
348
  elementRef_onInitpreviewingbldr(event);
344
- }}
349
+ }}><slot /></svelte:element
345
350
  >
346
- <slot />
347
- </svelte:element>
348
351
  {/if}
@@ -99,18 +99,16 @@ setContext(ComponentsContext.key, {
99
99
  {#if isSsrAbTest}
100
100
  <InlinedScript {scriptStr} />
101
101
  {/if}
102
-
103
102
  {#if TARGET !== "reactNative"}
104
103
  <ContentStyles
105
104
  contentId={$builderContextSignal.content?.id}
106
105
  cssCode={$builderContextSignal.content?.data?.cssCode}
107
106
  customFonts={$builderContextSignal.content?.data?.customFonts}
108
107
  />
109
- {/if}
110
- <Blocks
108
+ {/if}<Blocks
111
109
  blocks={$builderContextSignal.content?.data?.blocks}
112
110
  context={builderContextSignal}
113
111
  {registeredComponents}
114
112
  {linkComponent}
115
- />
116
- </EnableEditor>
113
+ /></EnableEditor
114
+ >
@@ -68,7 +68,6 @@ onMount(() => {
68
68
  id={`variants-styles-${content?.id}`}
69
69
  styles={hideVariantsStyleString()}
70
70
  />
71
-
72
71
  <InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
73
72
 
74
73
  {#each getVariants(content) as variant (variant.testVariationId)}
@@ -94,7 +93,6 @@ onMount(() => {
94
93
  />
95
94
  {/each}
96
95
  {/if}
97
-
98
96
  <ContentComponent
99
97
  {...{}}
100
98
  content={defaultContent()}
@@ -12,14 +12,12 @@ export let actionAttributes;
12
12
  <svelte:element
13
13
  this={TagName}
14
14
  {...attributes}
15
- use:setAttrs={actionAttributes}
15
+ use:setAttrs={actionAttributes}><slot /></svelte:element
16
16
  >
17
- <slot />
18
- </svelte:element>
19
17
  {:else}
20
- <svelte:component this={TagName} {...attributes} {...actionAttributes}>
21
- <slot />
22
- </svelte:component>
18
+ <svelte:component this={TagName} {...attributes} {...actionAttributes}
19
+ ><slot /></svelte:component
20
+ >
23
21
  {/if}
24
22
  {:else}
25
23
  <svelte:element
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.11";
1
+ export declare const SDK_VERSION = "1.0.12";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.11";
1
+ export const SDK_VERSION = "1.0.12";
@@ -19,7 +19,7 @@ export function flattenState({ rootState, localState, rootSetState }) {
19
19
  return localState[prop];
20
20
  }
21
21
  const val = target[prop];
22
- if (typeof val === 'object') {
22
+ if (typeof val === 'object' && val !== null) {
23
23
  return flattenState({
24
24
  rootState: val,
25
25
  localState: undefined,
@@ -1,2 +1,4 @@
1
1
  import type { EvaluatorArgs } from './helpers.js';
2
- export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: EvaluatorArgs): any;
2
+ type EvalValue = unknown;
3
+ export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, enableCache }: EvaluatorArgs): EvalValue;
4
+ export {};
@@ -1,10 +1,34 @@
1
1
  import { logger } from '../../helpers/logger.js';
2
2
  import { chooseBrowserOrServerEval } from './choose-eval.js';
3
3
  import { getBuilderGlobals, parseCode } from './helpers.js';
4
- export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
4
+ class EvalCache {
5
+ static cacheLimit = 20;
6
+ static cache = new Map();
7
+ static getCacheKey(args) {
8
+ return JSON.stringify({
9
+ ...args,
10
+ // replace the event with a random number to break cache
11
+ // thats because we can't serialize the event object due to circular refs in DOM node refs.
12
+ event: args.event ? Math.random() : undefined
13
+ });
14
+ }
15
+ static getCachedValue(key) {
16
+ const cachedVal = EvalCache.cache.get(key);
17
+ return cachedVal;
18
+ }
19
+ static setCachedValue(key, value) {
20
+ if (EvalCache.cache.size > 20) {
21
+ EvalCache.cache.delete(EvalCache.cache.keys().next().value);
22
+ }
23
+ EvalCache.cache.set(key, {
24
+ value
25
+ });
26
+ }
27
+ }
28
+ export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
5
29
  if (code === '') {
6
30
  logger.warn('Skipping evaluation of empty code block.');
7
- return;
31
+ return undefined;
8
32
  }
9
33
  const args = {
10
34
  code: parseCode(code, {
@@ -17,8 +41,20 @@ export function evaluate({ code, context, localState, rootState, rootSetState, e
17
41
  rootState,
18
42
  localState
19
43
  };
44
+ if (enableCache) {
45
+ const cacheKey = EvalCache.getCacheKey(args);
46
+ const cachedValue = EvalCache.getCachedValue(cacheKey);
47
+ if (cachedValue) {
48
+ return cachedValue.value;
49
+ }
50
+ }
20
51
  try {
21
- return chooseBrowserOrServerEval(args);
52
+ const newEval = chooseBrowserOrServerEval(args);
53
+ if (enableCache) {
54
+ const cacheKey = EvalCache.getCacheKey(args);
55
+ EvalCache.setCachedValue(cacheKey, newEval);
56
+ }
57
+ return newEval;
22
58
  }
23
59
  catch (e) {
24
60
  logger.error('Failed code evaluation: ' + e.message, {
@@ -3,6 +3,7 @@ import { getUserAttributes } from '../track/helpers.js';
3
3
  export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
4
4
  event?: Event;
5
5
  isExpression?: boolean;
6
+ enableCache: boolean;
6
7
  };
7
8
  export type BuilderGlobals = {
8
9
  isEditing: boolean | undefined;
@@ -6,5 +6,6 @@ export const createEventHandler = (value, options) => event => evaluate({
6
6
  rootState: options.rootState,
7
7
  rootSetState: options.rootSetState,
8
8
  event,
9
- isExpression: false
9
+ isExpression: false,
10
+ enableCache: true
10
11
  });
@@ -23,7 +23,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
23
23
  localState,
24
24
  rootState,
25
25
  rootSetState,
26
- context
26
+ context,
27
+ enableCache: true
27
28
  });
28
29
  set(copied, binding, value);
29
30
  }
@@ -16,6 +16,4 @@ function mitosis_styling(node, vars) {
16
16
  let builderContext = getContext(BuilderContext.key);
17
17
  </script>
18
18
 
19
- <span use:mitosis_styling={$builderContext.inheritedStyles}>
20
- {text}
21
- </span>
19
+ <span use:mitosis_styling={$builderContext.inheritedStyles}>{text}</span>
@@ -26,6 +26,5 @@ export let text = undefined;
26
26
  }}
27
27
  TagName={link ? builderLinkComponent || "a" : "button"}
28
28
  actionAttributes={filterAttrs(attributes, "on:", true)}
29
- >
30
- {text}
31
- </DynamicRenderer>
29
+ >{text}</DynamicRenderer
30
+ >
@@ -131,7 +131,6 @@ let flexDir = stackColumnsAt === "never"
131
131
  {#if TARGET !== "reactNative"}
132
132
  <InlinedStyles styles={columnsStyles()} />
133
133
  {/if}
134
-
135
134
  {#each columns as column, index (index)}
136
135
  <DynamicRenderer
137
136
  TagName={column.link ? builderLinkComponent || "a" : "div"}
@@ -146,8 +145,7 @@ let flexDir = stackColumnsAt === "never"
146
145
  [getClassPropName()]: "builder-column",
147
146
  style: mapStyleObjToStrIfNeeded(columnCssVars(index)),
148
147
  }}
149
- >
150
- <Blocks
148
+ ><Blocks
151
149
  path={`component.options.columns.${index}.blocks`}
152
150
  parent={builderBlock.id}
153
151
  styleProp={{
@@ -157,8 +155,8 @@ let flexDir = stackColumnsAt === "never"
157
155
  registeredComponents={builderComponents}
158
156
  linkComponent={builderLinkComponent}
159
157
  blocks={column.blocks}
160
- />
161
- </DynamicRenderer>
158
+ /></DynamicRenderer
159
+ >
162
160
  {/each}
163
161
  </div>
164
162
 
@@ -261,7 +261,6 @@ let formErrorMessage = "";
261
261
  />
262
262
  {/each}
263
263
  {/if}
264
-
265
264
  {#if submissionState() === "error"}
266
265
  <Blocks
267
266
  path="errorMessage"
@@ -269,7 +268,6 @@ let formErrorMessage = "";
269
268
  context={builderContext}
270
269
  />
271
270
  {/if}
272
-
273
271
  {#if submissionState() === "sending"}
274
272
  <Blocks
275
273
  path="sendingMessage"
@@ -277,13 +275,13 @@ let formErrorMessage = "";
277
275
  context={builderContext}
278
276
  />
279
277
  {/if}
280
-
281
278
  {#if submissionState() === "error" && responseData}
282
- <pre class="builder-form-error-text pre">
283
- {JSON.stringify(responseData, null, 2)}
284
- </pre>
279
+ <pre class="builder-form-error-text pre">{JSON.stringify(
280
+ responseData,
281
+ null,
282
+ 2
283
+ )}</pre>
285
284
  {/if}
286
-
287
285
  {#if submissionState() === "success"}
288
286
  <Blocks
289
287
  path="successMessage"
@@ -12,7 +12,5 @@ export let text = undefined;
12
12
  <button
13
13
  type="submit"
14
14
  {...filterAttrs(attributes, "on:", false)}
15
- use:setAttrs={filterAttrs(attributes, "on:", true)}
16
- >
17
- {text}
18
- </button>
15
+ use:setAttrs={filterAttrs(attributes, "on:", true)}>{text}</button
16
+ >
@@ -65,8 +65,7 @@ $: aspectRatioCss = () => {
65
65
  <picture>
66
66
  {#if webpSrcSet()}
67
67
  <source type="image/webp" srcset={webpSrcSet()} />
68
- {/if}
69
- <img
68
+ {/if}<img
70
69
  use:mitosis_styling={{
71
70
  objectPosition: backgroundPosition || "center",
72
71
  objectFit: backgroundSize || "cover",
@@ -79,8 +78,8 @@ $: aspectRatioCss = () => {
79
78
  src={image}
80
79
  srcset={srcSetToUse()}
81
80
  {sizes}
82
- />
83
- </picture>
81
+ /></picture
82
+ >
84
83
 
85
84
  {#if aspectRatio && !(builderBlock?.children?.length && fitContent)}
86
85
  <div
@@ -96,9 +95,7 @@ $: aspectRatioCss = () => {
96
95
  {/if}
97
96
 
98
97
  {#if !fitContent && $$slots.default}
99
- <div class="div-2">
100
- <slot />
101
- </div>
98
+ <div class="div-2"><slot /></div>
102
99
  {/if}
103
100
 
104
101
  <style>
@@ -89,9 +89,8 @@ $: spreadProps = () => {
89
89
  >
90
90
  {#if !lazyLoad}
91
91
  <source type="video/mp4" src={video} />
92
- {/if}
93
- </video>
94
-
92
+ {/if}</video
93
+ >
95
94
  {#if aspectRatio && !(fitContent && builderBlock?.children?.length)}
96
95
  <div
97
96
  use:mitosis_styling={{
@@ -102,7 +101,6 @@ $: spreadProps = () => {
102
101
  }}
103
102
  />
104
103
  {/if}
105
-
106
104
  {#if builderBlock?.children?.length && fitContent}
107
105
  <div
108
106
  use:mitosis_styling={{
@@ -114,7 +112,6 @@ $: spreadProps = () => {
114
112
  <slot />
115
113
  </div>
116
114
  {/if}
117
-
118
115
  {#if builderBlock?.children?.length && !fitContent}
119
116
  <div
120
117
  use:mitosis_styling={{