@builder.io/sdk-svelte 2.0.9 → 2.0.14

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 (61) hide show
  1. package/README.md +1 -1
  2. package/lib/browser/blocks/slot/component-info.js +2 -1
  3. package/lib/browser/blocks/slot/slot.svelte +2 -0
  4. package/lib/browser/blocks/slot/slot.svelte.d.ts +3 -2
  5. package/lib/browser/components/block/block.helpers.d.ts +1 -2
  6. package/lib/browser/components/block/block.helpers.js +2 -10
  7. package/lib/browser/components/block/block.svelte +26 -11
  8. package/lib/browser/components/block/components/block-styles.svelte +2 -17
  9. package/lib/browser/components/blocks/blocks-wrapper.svelte +5 -1
  10. package/lib/browser/constants/sdk-version.d.ts +1 -1
  11. package/lib/browser/constants/sdk-version.js +1 -1
  12. package/lib/browser/functions/evaluate/evaluate.js +14 -1
  13. package/lib/browser/functions/evaluate/node-runtime/init.d.ts +1 -0
  14. package/lib/browser/functions/evaluate/node-runtime/init.js +1 -0
  15. package/lib/browser/functions/evaluate/node-runtime/node-runtime.js +2 -2
  16. package/lib/browser/functions/get-processed-block.d.ts +1 -0
  17. package/lib/browser/functions/get-processed-block.js +52 -10
  18. package/lib/edge/blocks/slot/component-info.js +2 -1
  19. package/lib/edge/blocks/slot/slot.svelte +2 -0
  20. package/lib/edge/blocks/slot/slot.svelte.d.ts +3 -2
  21. package/lib/edge/components/block/block.helpers.d.ts +1 -2
  22. package/lib/edge/components/block/block.helpers.js +2 -10
  23. package/lib/edge/components/block/block.svelte +26 -11
  24. package/lib/edge/components/block/components/block-styles.svelte +2 -17
  25. package/lib/edge/components/blocks/blocks-wrapper.svelte +5 -1
  26. package/lib/edge/constants/sdk-version.d.ts +1 -1
  27. package/lib/edge/constants/sdk-version.js +1 -1
  28. package/lib/edge/functions/evaluate/evaluate.js +14 -1
  29. package/lib/edge/functions/evaluate/node-runtime/init.d.ts +1 -0
  30. package/lib/edge/functions/evaluate/node-runtime/init.js +1 -0
  31. package/lib/edge/functions/evaluate/node-runtime/node-runtime.js +2 -2
  32. package/lib/edge/functions/get-processed-block.d.ts +1 -0
  33. package/lib/edge/functions/get-processed-block.js +52 -10
  34. package/lib/node/blocks/slot/component-info.js +2 -1
  35. package/lib/node/blocks/slot/slot.svelte +2 -0
  36. package/lib/node/blocks/slot/slot.svelte.d.ts +3 -2
  37. package/lib/node/components/block/block.helpers.d.ts +1 -2
  38. package/lib/node/components/block/block.helpers.js +2 -10
  39. package/lib/node/components/block/block.svelte +26 -11
  40. package/lib/node/components/block/components/block-styles.svelte +2 -17
  41. package/lib/node/components/blocks/blocks-wrapper.svelte +5 -1
  42. package/lib/node/constants/sdk-version.d.ts +1 -1
  43. package/lib/node/constants/sdk-version.js +1 -1
  44. package/lib/node/functions/evaluate/evaluate.js +14 -1
  45. package/lib/node/functions/evaluate/node-runtime/init.d.ts +1 -0
  46. package/lib/node/functions/evaluate/node-runtime/init.js +1 -0
  47. package/lib/node/functions/evaluate/node-runtime/node-runtime.js +2 -2
  48. package/lib/node/functions/get-processed-block.d.ts +1 -0
  49. package/lib/node/functions/get-processed-block.js +52 -10
  50. package/package.json +5 -4
  51. package/src/blocks/slot/component-info.ts +2 -1
  52. package/src/blocks/slot/slot.svelte +11 -5
  53. package/src/components/block/block.helpers.ts +1 -11
  54. package/src/components/block/block.svelte +28 -11
  55. package/src/components/block/components/block-styles.svelte +2 -17
  56. package/src/components/blocks/blocks-wrapper.svelte +7 -0
  57. package/src/constants/sdk-version.ts +1 -1
  58. package/src/functions/evaluate/evaluate.ts +15 -1
  59. package/src/functions/evaluate/node-runtime/init.ts +1 -0
  60. package/src/functions/evaluate/node-runtime/node-runtime.ts +2 -2
  61. package/src/functions/get-processed-block.ts +52 -10
package/README.md CHANGED
@@ -13,7 +13,7 @@ To check the status of the SDK, look at [these tables](../../README.md#feature-i
13
13
  ## Getting Started
14
14
 
15
15
  ```
16
- npm install @builder.io/sdk-svelte@dev
16
+ npm install @builder.io/sdk-svelte
17
17
  ```
18
18
 
19
19
  Take a look at [our example repo](/examples/svelte/sveltekit) for how to use this SDK.
@@ -12,6 +12,7 @@ export const componentInfo = {
12
12
  defaultValue: 'children'
13
13
  }],
14
14
  shouldReceiveBuilderProps: {
15
- builderContext: true
15
+ builderContext: true,
16
+ builderComponents: true
16
17
  }
17
18
  };
@@ -4,6 +4,7 @@
4
4
  import "../../functions/deopt";
5
5
  export let builderContext;
6
6
  export let name;
7
+ export let builderComponents;
7
8
  function stringifyStyles(stylesObj) {
8
9
  let styles = "";
9
10
  for (let key in stylesObj) {
@@ -28,6 +29,7 @@ function stringifyStyles(stylesObj) {
28
29
  parent={$builderContext.context?.symbolId}
29
30
  path={`symbol.data.${name}`}
30
31
  context={builderContext}
32
+ registeredComponents={builderComponents}
31
33
  blocks={$builderContext.rootState?.[name]}
32
34
  />
33
35
  </div>
@@ -1,13 +1,14 @@
1
1
  import { SvelteComponent } from "svelte";
2
- export type DropzoneProps = BuilderDataProps & {
2
+ export type DropzoneProps = BuilderDataProps & BuilderComponentsProp & {
3
3
  name: string;
4
4
  attributes: any;
5
5
  };
6
- import type { BuilderDataProps } from "../../types/builder-props";
6
+ import type { BuilderComponentsProp, BuilderDataProps } from "../../types/builder-props";
7
7
  declare const __propDef: {
8
8
  props: {
9
9
  builderContext: DropzoneProps["builderContext"];
10
10
  name: DropzoneProps["name"];
11
+ builderComponents: DropzoneProps["builderComponents"];
11
12
  };
12
13
  events: {
13
14
  [evt: string]: CustomEvent<any>;
@@ -3,9 +3,8 @@ import type { Writable } from "svelte/store";
3
3
  import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
4
4
  import type { BuilderBlock } from '../../types/builder-block';
5
5
  import type { RepeatData } from './types';
6
- export declare const getComponent: ({ block, context, registeredComponents }: {
6
+ export declare const getComponent: ({ block, registeredComponents }: {
7
7
  block: BuilderBlock;
8
- context: BuilderContextInterface;
9
8
  registeredComponents: RegisteredComponents;
10
9
  }) => RegisteredComponent | null | undefined;
11
10
  export declare const getRepeatItemData: ({ block, context }: {
@@ -1,16 +1,8 @@
1
1
  import { evaluate } from '../../functions/evaluate/index';
2
2
  import { extractTextStyles } from '../../functions/extract-text-styles';
3
- import { getProcessedBlock } from '../../functions/get-processed-block';
4
3
  import { getStyle } from '../../functions/get-style';
5
- export const getComponent = ({ block, context, registeredComponents }) => {
6
- const componentName = getProcessedBlock({
7
- block,
8
- localState: context.localState,
9
- rootState: context.rootState,
10
- rootSetState: context.rootSetState,
11
- context: context.context,
12
- shouldEvaluateBindings: false
13
- }).component?.name;
4
+ export const getComponent = ({ block, registeredComponents }) => {
5
+ const componentName = block.component?.name;
14
6
  if (!componentName) {
15
7
  return null;
16
8
  }
@@ -1,9 +1,10 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { onMount } from "svelte";
3
+ <script>import { afterUpdate, onMount } from "svelte";
4
4
  import { TARGET } from "../../constants/target";
5
5
  import { getBlockComponentOptions } from "../../functions/get-block-component-options";
6
6
  import { getProcessedBlock } from "../../functions/get-processed-block";
7
+ import "../../server-index";
7
8
  import "../dynamic-div.svelte";
8
9
  import { bindAnimations } from "./animator";
9
10
  import { getComponent, getRepeatItemData, provideBuilderBlock, provideBuilderContext, provideLinkComponent, provideRegisteredComponents, } from "./block.helpers";
@@ -15,13 +16,6 @@ export let block;
15
16
  export let context;
16
17
  export let registeredComponents;
17
18
  export let linkComponent;
18
- $: blockComponent = () => {
19
- return getComponent({
20
- block: block,
21
- context: $context,
22
- registeredComponents: registeredComponents,
23
- });
24
- };
25
19
  $: repeatItem = () => {
26
20
  return getRepeatItemData({
27
21
  block: block,
@@ -29,7 +23,7 @@ $: repeatItem = () => {
29
23
  });
30
24
  };
31
25
  $: processedBlock = () => {
32
- return block.repeat?.collection
26
+ const blockToUse = block.repeat?.collection
33
27
  ? block
34
28
  : getProcessedBlock({
35
29
  block: block,
@@ -39,6 +33,13 @@ $: processedBlock = () => {
39
33
  context: $context.context,
40
34
  shouldEvaluateBindings: true,
41
35
  });
36
+ return blockToUse;
37
+ };
38
+ $: blockComponent = () => {
39
+ return getComponent({
40
+ block: processedBlock(),
41
+ registeredComponents: registeredComponents,
42
+ });
42
43
  };
43
44
  $: Tag = () => {
44
45
  const shouldUseLink = block.tagName === "a" ||
@@ -90,6 +91,10 @@ $: componentRefProps = () => {
90
91
  isInteractive: !(blockComponent?.()?.isRSC && TARGET === "rsc"),
91
92
  };
92
93
  };
94
+ let _processedBlock = {
95
+ value: null,
96
+ update: false,
97
+ };
93
98
  onMount(() => {
94
99
  const blockId = processedBlock().id;
95
100
  const animations = processedBlock().animations;
@@ -100,10 +105,11 @@ onMount(() => {
100
105
  })));
101
106
  }
102
107
  });
108
+ afterUpdate(() => { });
103
109
  </script>
104
110
 
105
111
  {#if canShowBlock()}
106
- <BlockStyles {block} context={$context} />
112
+ <BlockStyles block={processedBlock()} context={$context} />
107
113
 
108
114
  {#if !blockComponent?.()?.noWrap}
109
115
  {#if !repeatItem()}
@@ -138,7 +144,7 @@ onMount(() => {
138
144
  />
139
145
  {/each}
140
146
  {/if}
141
- {:else}
147
+ {:else if !repeatItem()}
142
148
  <ComponentRef
143
149
  componentRef={componentRefProps().componentRef}
144
150
  componentOptions={componentRefProps().componentOptions}
@@ -150,5 +156,14 @@ onMount(() => {
150
156
  includeBlockProps={componentRefProps().includeBlockProps}
151
157
  isInteractive={componentRefProps().isInteractive}
152
158
  />
159
+ {:else}
160
+ {#each repeatItem() as data, index (index)}
161
+ <RepeatedBlock
162
+ repeatContext={data.context}
163
+ block={data.block}
164
+ {registeredComponents}
165
+ {linkComponent}
166
+ />
167
+ {/each}
153
168
  {/if}
154
169
  {/if}
@@ -3,21 +3,13 @@
3
3
  <script>import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../../constants/device-sizes";
4
4
  import { TARGET } from "../../../constants/target";
5
5
  import { camelToKebabCase } from "../../../functions/camel-to-kebab-case";
6
- import { getProcessedBlock } from "../../../functions/get-processed-block";
7
6
  import { createCssClass } from "../../../helpers/css";
8
7
  import { checkIsDefined } from "../../../helpers/nullable";
9
8
  import InlinedStyles from "../../inlined-styles.svelte";
10
9
  export let block;
11
10
  export let context;
12
11
  $: canShowBlock = () => {
13
- const processedBlock = getProcessedBlock({
14
- block: block,
15
- localState: context.localState,
16
- rootState: context.rootState,
17
- rootSetState: context.rootSetState,
18
- context: context.context,
19
- shouldEvaluateBindings: true,
20
- });
12
+ const processedBlock = block;
21
13
  // only render styles for blocks that are visible
22
14
  if (checkIsDefined(processedBlock.hide)) {
23
15
  return !processedBlock.hide;
@@ -28,14 +20,7 @@ $: canShowBlock = () => {
28
20
  return true;
29
21
  };
30
22
  $: css = () => {
31
- const processedBlock = getProcessedBlock({
32
- block: block,
33
- localState: context.localState,
34
- rootState: context.rootState,
35
- rootSetState: context.rootSetState,
36
- context: context.context,
37
- shouldEvaluateBindings: true,
38
- });
23
+ const processedBlock = block;
39
24
  const styles = processedBlock.responsiveStyles;
40
25
  const content = context.content;
41
26
  const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { isEditing } from "../../functions/is-editing";
3
+ <script>import { onMount } from "svelte";
4
+ import { isEditing } from "../../functions/is-editing";
4
5
  export let blocks;
5
6
  export let parent;
6
7
  export let path;
@@ -42,11 +43,14 @@ function onMouseEnter() {
42
43
  $: className = () => {
43
44
  return "builder-blocks" + (!blocks?.length ? " no-blocks" : "");
44
45
  };
46
+ let blocksWrapperRef;
47
+ onMount(() => { });
45
48
  </script>
46
49
 
47
50
  <svelte:element
48
51
  this={BlocksWrapper}
49
52
  style={stringifyStyles(styleProp)}
53
+ bind:this={blocksWrapperRef}
50
54
  class={className() + " svelte-element"}
51
55
  builder-path={path}
52
56
  builder-parent-id={parent}
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.0.9";
1
+ export declare const SDK_VERSION = "2.0.14";
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.9";
1
+ export const SDK_VERSION = "2.0.14";
@@ -1,6 +1,19 @@
1
1
  import { logger } from '../../helpers/logger';
2
2
  import { chooseBrowserOrServerEval } from './choose-eval';
3
3
  import { getBuilderGlobals, parseCode } from './helpers';
4
+ // Caching is dangerous for several reasons
5
+ // - JSON.stringify is not safe to run on things like `context`
6
+ // because anything can be passed, including non-stringifiable objects,
7
+ // circiular references, etc.
8
+ // - JSON.stringify is expensive to run as a cache key
9
+ // - This likely only helped because we were running processBlock multiple times
10
+ // but that is not fixed, and this will cause bugs and issues if enabled
11
+ //
12
+ // Perhaps the best approach is to allow users to configure if caching is enabled or not
13
+ // for instance on edge runtimes with slower evaluation times via the interpreter
14
+ // That said, the repeat processBLock calls was making any evaluation time 10x+ slower
15
+ // which is now fixed, so this still may not be necessary
16
+ const DISABLE_CACHE = true;
4
17
  class EvalCache {
5
18
  static cacheLimit = 20;
6
19
  static cache = new Map();
@@ -40,7 +53,7 @@ export function evaluate({ code, context, localState, rootState, rootSetState, e
40
53
  rootState,
41
54
  localState
42
55
  };
43
- if (enableCache) {
56
+ if (enableCache && !DISABLE_CACHE) {
44
57
  const cacheKey = EvalCache.getCacheKey(args);
45
58
  const cachedValue = EvalCache.getCachedValue(cacheKey);
46
59
  if (cachedValue) {
@@ -7,6 +7,7 @@ import type { IsolateOptions } from 'isolated-vm';
7
7
  * from a server-only location, such as:
8
8
  * - The NextJS Pages router's `_document.tsx`
9
9
  * - Your Remix route's `loader`
10
+ * - Qwik's `entry.ssr.tsx` file
10
11
  */
11
12
  export declare const initializeNodeRuntime: (args?: {
12
13
  ivmIsolateOptions?: IsolateOptions;
@@ -20,6 +20,7 @@ import { setIvm } from './node-runtime';
20
20
  * from a server-only location, such as:
21
21
  * - The NextJS Pages router's `_document.tsx`
22
22
  * - Your Remix route's `loader`
23
+ * - Qwik's `entry.ssr.tsx` file
23
24
  */
24
25
  export const initializeNodeRuntime = (args) => {
25
26
  const { ivmIsolateOptions } = args || {};
@@ -67,7 +67,7 @@ export const setIvm = (ivm, options = {}) => {
67
67
  setIsolateContext(options);
68
68
  };
69
69
  // only mention the script for SDKs that have it.
70
- const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react';
70
+ const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik';
71
71
  const getIvm = () => {
72
72
  try {
73
73
  if (IVM_INSTANCE)
@@ -83,7 +83,7 @@ const getIvm = () => {
83
83
 
84
84
  SOLUTION: In a server-only execution path within your application, do one of the following:
85
85
 
86
- ${SHOULD_MENTION_INITIALIZE_SCRIPT ? '- import and call `initializeNodeRuntime()` from "${SDK_NAME}/node/init".' : ''}
86
+ ${SHOULD_MENTION_INITIALIZE_SCRIPT ? `- import and call \`initializeNodeRuntime()\` from "${SDK_NAME}/node/init".` : ''}
87
87
  - add the following import: \`await import('isolated-vm')\`.
88
88
 
89
89
  For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
@@ -1,5 +1,6 @@
1
1
  import type { BuilderContextInterface } from '../context/types';
2
2
  import type { BuilderBlock } from '../types/builder-block';
3
+ export declare function deepCloneWithConditions<T = any>(obj: T): T;
3
4
  export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }: {
4
5
  block: BuilderBlock;
5
6
  /**
@@ -1,21 +1,63 @@
1
+ import { TARGET } from '../constants/target';
2
+ import { omit } from '../helpers/omit';
1
3
  import { evaluate } from './evaluate/index';
2
4
  import { fastClone } from './fast-clone';
3
5
  import { set } from './set';
4
6
  import { transformBlock } from './transform-block';
7
+ // Deep clone a block but without cloning any child blocks
8
+ export function deepCloneWithConditions(obj) {
9
+ if (obj === null || typeof obj !== 'object') {
10
+ return obj;
11
+ }
12
+ if (Array.isArray(obj)) {
13
+ return obj.map((item) => deepCloneWithConditions(item));
14
+ }
15
+ if (obj['@type'] === '@builder.io/sdk:Element') {
16
+ return obj;
17
+ }
18
+ const clonedObj = {};
19
+ for (const key in obj) {
20
+ if (key !== 'meta' && Object.prototype.hasOwnProperty.call(obj, key)) {
21
+ clonedObj[key] = deepCloneWithConditions(obj[key]);
22
+ }
23
+ }
24
+ return clonedObj;
25
+ }
26
+ const IS_SDK_WITHOUT_CACHED_PROCESSED_BLOCK = ['svelte', 'vue', 'angular', 'qwik', 'solid'].includes(TARGET);
27
+ const getCopy = (block) => {
28
+ if (IS_SDK_WITHOUT_CACHED_PROCESSED_BLOCK) {
29
+ const copy = fastClone(block);
30
+ const copied = {
31
+ ...copy,
32
+ properties: {
33
+ ...copy.properties
34
+ },
35
+ actions: {
36
+ ...copy.actions
37
+ }
38
+ };
39
+ return copied;
40
+ }
41
+ else {
42
+ const copy = deepCloneWithConditions(omit(block, 'children', 'meta'));
43
+ return {
44
+ ...copy,
45
+ properties: {
46
+ ...copy.properties
47
+ },
48
+ actions: {
49
+ ...copy.actions
50
+ },
51
+ children: block.children,
52
+ meta: block.meta
53
+ };
54
+ }
55
+ };
5
56
  const evaluateBindings = ({ block, context, localState, rootState, rootSetState }) => {
6
57
  if (!block.bindings) {
7
58
  return block;
8
59
  }
9
- const copy = fastClone(block);
10
- const copied = {
11
- ...copy,
12
- properties: {
13
- ...copy.properties
14
- },
15
- actions: {
16
- ...copy.actions
17
- }
18
- };
60
+ const copied = getCopy(block);
19
61
  for (const binding in block.bindings) {
20
62
  const expression = block.bindings[binding];
21
63
  const value = evaluate({
@@ -12,6 +12,7 @@ export const componentInfo = {
12
12
  defaultValue: 'children'
13
13
  }],
14
14
  shouldReceiveBuilderProps: {
15
- builderContext: true
15
+ builderContext: true,
16
+ builderComponents: true
16
17
  }
17
18
  };
@@ -4,6 +4,7 @@
4
4
  import "../../functions/deopt";
5
5
  export let builderContext;
6
6
  export let name;
7
+ export let builderComponents;
7
8
  function stringifyStyles(stylesObj) {
8
9
  let styles = "";
9
10
  for (let key in stylesObj) {
@@ -28,6 +29,7 @@ function stringifyStyles(stylesObj) {
28
29
  parent={$builderContext.context?.symbolId}
29
30
  path={`symbol.data.${name}`}
30
31
  context={builderContext}
32
+ registeredComponents={builderComponents}
31
33
  blocks={$builderContext.rootState?.[name]}
32
34
  />
33
35
  </div>
@@ -1,13 +1,14 @@
1
1
  import { SvelteComponent } from "svelte";
2
- export type DropzoneProps = BuilderDataProps & {
2
+ export type DropzoneProps = BuilderDataProps & BuilderComponentsProp & {
3
3
  name: string;
4
4
  attributes: any;
5
5
  };
6
- import type { BuilderDataProps } from "../../types/builder-props";
6
+ import type { BuilderComponentsProp, BuilderDataProps } from "../../types/builder-props";
7
7
  declare const __propDef: {
8
8
  props: {
9
9
  builderContext: DropzoneProps["builderContext"];
10
10
  name: DropzoneProps["name"];
11
+ builderComponents: DropzoneProps["builderComponents"];
11
12
  };
12
13
  events: {
13
14
  [evt: string]: CustomEvent<any>;
@@ -3,9 +3,8 @@ import type { Writable } from "svelte/store";
3
3
  import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
4
4
  import type { BuilderBlock } from '../../types/builder-block';
5
5
  import type { RepeatData } from './types';
6
- export declare const getComponent: ({ block, context, registeredComponents }: {
6
+ export declare const getComponent: ({ block, registeredComponents }: {
7
7
  block: BuilderBlock;
8
- context: BuilderContextInterface;
9
8
  registeredComponents: RegisteredComponents;
10
9
  }) => RegisteredComponent | null | undefined;
11
10
  export declare const getRepeatItemData: ({ block, context }: {
@@ -1,16 +1,8 @@
1
1
  import { evaluate } from '../../functions/evaluate/index';
2
2
  import { extractTextStyles } from '../../functions/extract-text-styles';
3
- import { getProcessedBlock } from '../../functions/get-processed-block';
4
3
  import { getStyle } from '../../functions/get-style';
5
- export const getComponent = ({ block, context, registeredComponents }) => {
6
- const componentName = getProcessedBlock({
7
- block,
8
- localState: context.localState,
9
- rootState: context.rootState,
10
- rootSetState: context.rootSetState,
11
- context: context.context,
12
- shouldEvaluateBindings: false
13
- }).component?.name;
4
+ export const getComponent = ({ block, registeredComponents }) => {
5
+ const componentName = block.component?.name;
14
6
  if (!componentName) {
15
7
  return null;
16
8
  }
@@ -1,9 +1,10 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { onMount } from "svelte";
3
+ <script>import { afterUpdate, onMount } from "svelte";
4
4
  import { TARGET } from "../../constants/target";
5
5
  import { getBlockComponentOptions } from "../../functions/get-block-component-options";
6
6
  import { getProcessedBlock } from "../../functions/get-processed-block";
7
+ import "../../server-index";
7
8
  import "../dynamic-div.svelte";
8
9
  import { bindAnimations } from "./animator";
9
10
  import { getComponent, getRepeatItemData, provideBuilderBlock, provideBuilderContext, provideLinkComponent, provideRegisteredComponents, } from "./block.helpers";
@@ -15,13 +16,6 @@ export let block;
15
16
  export let context;
16
17
  export let registeredComponents;
17
18
  export let linkComponent;
18
- $: blockComponent = () => {
19
- return getComponent({
20
- block: block,
21
- context: $context,
22
- registeredComponents: registeredComponents,
23
- });
24
- };
25
19
  $: repeatItem = () => {
26
20
  return getRepeatItemData({
27
21
  block: block,
@@ -29,7 +23,7 @@ $: repeatItem = () => {
29
23
  });
30
24
  };
31
25
  $: processedBlock = () => {
32
- return block.repeat?.collection
26
+ const blockToUse = block.repeat?.collection
33
27
  ? block
34
28
  : getProcessedBlock({
35
29
  block: block,
@@ -39,6 +33,13 @@ $: processedBlock = () => {
39
33
  context: $context.context,
40
34
  shouldEvaluateBindings: true,
41
35
  });
36
+ return blockToUse;
37
+ };
38
+ $: blockComponent = () => {
39
+ return getComponent({
40
+ block: processedBlock(),
41
+ registeredComponents: registeredComponents,
42
+ });
42
43
  };
43
44
  $: Tag = () => {
44
45
  const shouldUseLink = block.tagName === "a" ||
@@ -90,6 +91,10 @@ $: componentRefProps = () => {
90
91
  isInteractive: !(blockComponent?.()?.isRSC && TARGET === "rsc"),
91
92
  };
92
93
  };
94
+ let _processedBlock = {
95
+ value: null,
96
+ update: false,
97
+ };
93
98
  onMount(() => {
94
99
  const blockId = processedBlock().id;
95
100
  const animations = processedBlock().animations;
@@ -100,10 +105,11 @@ onMount(() => {
100
105
  })));
101
106
  }
102
107
  });
108
+ afterUpdate(() => { });
103
109
  </script>
104
110
 
105
111
  {#if canShowBlock()}
106
- <BlockStyles {block} context={$context} />
112
+ <BlockStyles block={processedBlock()} context={$context} />
107
113
 
108
114
  {#if !blockComponent?.()?.noWrap}
109
115
  {#if !repeatItem()}
@@ -138,7 +144,7 @@ onMount(() => {
138
144
  />
139
145
  {/each}
140
146
  {/if}
141
- {:else}
147
+ {:else if !repeatItem()}
142
148
  <ComponentRef
143
149
  componentRef={componentRefProps().componentRef}
144
150
  componentOptions={componentRefProps().componentOptions}
@@ -150,5 +156,14 @@ onMount(() => {
150
156
  includeBlockProps={componentRefProps().includeBlockProps}
151
157
  isInteractive={componentRefProps().isInteractive}
152
158
  />
159
+ {:else}
160
+ {#each repeatItem() as data, index (index)}
161
+ <RepeatedBlock
162
+ repeatContext={data.context}
163
+ block={data.block}
164
+ {registeredComponents}
165
+ {linkComponent}
166
+ />
167
+ {/each}
153
168
  {/if}
154
169
  {/if}
@@ -3,21 +3,13 @@
3
3
  <script>import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../../constants/device-sizes";
4
4
  import { TARGET } from "../../../constants/target";
5
5
  import { camelToKebabCase } from "../../../functions/camel-to-kebab-case";
6
- import { getProcessedBlock } from "../../../functions/get-processed-block";
7
6
  import { createCssClass } from "../../../helpers/css";
8
7
  import { checkIsDefined } from "../../../helpers/nullable";
9
8
  import InlinedStyles from "../../inlined-styles.svelte";
10
9
  export let block;
11
10
  export let context;
12
11
  $: canShowBlock = () => {
13
- const processedBlock = getProcessedBlock({
14
- block: block,
15
- localState: context.localState,
16
- rootState: context.rootState,
17
- rootSetState: context.rootSetState,
18
- context: context.context,
19
- shouldEvaluateBindings: true,
20
- });
12
+ const processedBlock = block;
21
13
  // only render styles for blocks that are visible
22
14
  if (checkIsDefined(processedBlock.hide)) {
23
15
  return !processedBlock.hide;
@@ -28,14 +20,7 @@ $: canShowBlock = () => {
28
20
  return true;
29
21
  };
30
22
  $: css = () => {
31
- const processedBlock = getProcessedBlock({
32
- block: block,
33
- localState: context.localState,
34
- rootState: context.rootState,
35
- rootSetState: context.rootSetState,
36
- context: context.context,
37
- shouldEvaluateBindings: true,
38
- });
23
+ const processedBlock = block;
39
24
  const styles = processedBlock.responsiveStyles;
40
25
  const content = context.content;
41
26
  const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { isEditing } from "../../functions/is-editing";
3
+ <script>import { onMount } from "svelte";
4
+ import { isEditing } from "../../functions/is-editing";
4
5
  export let blocks;
5
6
  export let parent;
6
7
  export let path;
@@ -42,11 +43,14 @@ function onMouseEnter() {
42
43
  $: className = () => {
43
44
  return "builder-blocks" + (!blocks?.length ? " no-blocks" : "");
44
45
  };
46
+ let blocksWrapperRef;
47
+ onMount(() => { });
45
48
  </script>
46
49
 
47
50
  <svelte:element
48
51
  this={BlocksWrapper}
49
52
  style={stringifyStyles(styleProp)}
53
+ bind:this={blocksWrapperRef}
50
54
  class={className() + " svelte-element"}
51
55
  builder-path={path}
52
56
  builder-parent-id={parent}
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.0.9";
1
+ export declare const SDK_VERSION = "2.0.14";
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.9";
1
+ export const SDK_VERSION = "2.0.14";