@builder.io/sdk-svelte 4.1.3 → 4.2.3

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 (125) hide show
  1. package/lib/browser/blocks/form/form/form.svelte +8 -6
  2. package/lib/browser/blocks/img/component-info.js +33 -3
  3. package/lib/browser/blocks/img/img.svelte +18 -6
  4. package/lib/browser/blocks/symbol/symbol.svelte +5 -2
  5. package/lib/browser/blocks/symbol/symbol.svelte.d.ts +1 -1
  6. package/lib/browser/blocks/symbol/symbol.types.d.ts +1 -2
  7. package/lib/browser/blocks/tabs/tabs.svelte +5 -4
  8. package/lib/browser/blocks/tabs/tabs.svelte.d.ts +1 -1
  9. package/lib/browser/blocks/text/component-info.js +0 -1
  10. package/lib/browser/components/awaiter.types.d.ts +7 -0
  11. package/lib/browser/components/awaiter.types.js +1 -0
  12. package/lib/browser/components/block/block.svelte +2 -2
  13. package/lib/browser/components/block/components/component-ref/component-ref.svelte +8 -8
  14. package/lib/browser/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
  15. package/lib/browser/components/block/components/interactive-element.svelte +8 -1
  16. package/lib/browser/components/block/components/live-edit-block-styles.svelte +114 -0
  17. package/lib/browser/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
  18. package/lib/browser/components/block/components/style-wrapper.svelte +25 -0
  19. package/lib/browser/components/block/components/style-wrapper.svelte.d.ts +23 -0
  20. package/lib/browser/components/content/components/enable-editor.svelte +53 -12
  21. package/lib/browser/components/live-edit.svelte +20 -0
  22. package/lib/browser/components/live-edit.svelte.d.ts +26 -0
  23. package/lib/browser/constants/sdk-version.d.ts +1 -1
  24. package/lib/browser/constants/sdk-version.js +1 -1
  25. package/lib/browser/functions/get-content/generate-content-url.js +3 -8
  26. package/lib/browser/functions/get-content/index.js +8 -0
  27. package/lib/browser/functions/register.d.ts +18 -0
  28. package/lib/browser/functions/register.js +12 -0
  29. package/lib/browser/helpers/find-block.d.ts +18 -0
  30. package/lib/browser/helpers/find-block.js +41 -0
  31. package/lib/browser/helpers/subscribe-to-editor.d.ts +3 -2
  32. package/lib/browser/helpers/subscribe-to-editor.js +4 -2
  33. package/lib/browser/server-index.d.ts +1 -1
  34. package/lib/browser/server-index.js +1 -1
  35. package/lib/edge/blocks/form/form/form.svelte +8 -6
  36. package/lib/edge/blocks/img/component-info.js +33 -3
  37. package/lib/edge/blocks/img/img.svelte +18 -6
  38. package/lib/edge/blocks/symbol/symbol.svelte +5 -2
  39. package/lib/edge/blocks/symbol/symbol.svelte.d.ts +1 -1
  40. package/lib/edge/blocks/symbol/symbol.types.d.ts +1 -2
  41. package/lib/edge/blocks/tabs/tabs.svelte +5 -4
  42. package/lib/edge/blocks/tabs/tabs.svelte.d.ts +1 -1
  43. package/lib/edge/blocks/text/component-info.js +0 -1
  44. package/lib/edge/components/awaiter.types.d.ts +7 -0
  45. package/lib/edge/components/awaiter.types.js +1 -0
  46. package/lib/edge/components/block/block.svelte +2 -2
  47. package/lib/edge/components/block/components/component-ref/component-ref.svelte +8 -8
  48. package/lib/edge/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
  49. package/lib/edge/components/block/components/interactive-element.svelte +8 -1
  50. package/lib/edge/components/block/components/live-edit-block-styles.svelte +114 -0
  51. package/lib/edge/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
  52. package/lib/edge/components/block/components/style-wrapper.svelte +25 -0
  53. package/lib/edge/components/block/components/style-wrapper.svelte.d.ts +23 -0
  54. package/lib/edge/components/content/components/enable-editor.svelte +53 -12
  55. package/lib/edge/components/live-edit.svelte +20 -0
  56. package/lib/edge/components/live-edit.svelte.d.ts +26 -0
  57. package/lib/edge/constants/sdk-version.d.ts +1 -1
  58. package/lib/edge/constants/sdk-version.js +1 -1
  59. package/lib/edge/functions/get-content/generate-content-url.js +3 -8
  60. package/lib/edge/functions/get-content/index.js +8 -0
  61. package/lib/edge/functions/register.d.ts +18 -0
  62. package/lib/edge/functions/register.js +12 -0
  63. package/lib/edge/helpers/find-block.d.ts +18 -0
  64. package/lib/edge/helpers/find-block.js +41 -0
  65. package/lib/edge/helpers/subscribe-to-editor.d.ts +3 -2
  66. package/lib/edge/helpers/subscribe-to-editor.js +4 -2
  67. package/lib/edge/server-index.d.ts +1 -1
  68. package/lib/edge/server-index.js +1 -1
  69. package/lib/node/blocks/form/form/form.svelte +8 -6
  70. package/lib/node/blocks/img/component-info.js +33 -3
  71. package/lib/node/blocks/img/img.svelte +18 -6
  72. package/lib/node/blocks/symbol/symbol.svelte +5 -2
  73. package/lib/node/blocks/symbol/symbol.svelte.d.ts +1 -1
  74. package/lib/node/blocks/symbol/symbol.types.d.ts +1 -2
  75. package/lib/node/blocks/tabs/tabs.svelte +5 -4
  76. package/lib/node/blocks/tabs/tabs.svelte.d.ts +1 -1
  77. package/lib/node/blocks/text/component-info.js +0 -1
  78. package/lib/node/components/awaiter.types.d.ts +7 -0
  79. package/lib/node/components/awaiter.types.js +1 -0
  80. package/lib/node/components/block/block.svelte +2 -2
  81. package/lib/node/components/block/components/component-ref/component-ref.svelte +8 -8
  82. package/lib/node/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
  83. package/lib/node/components/block/components/interactive-element.svelte +8 -1
  84. package/lib/node/components/block/components/live-edit-block-styles.svelte +114 -0
  85. package/lib/node/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
  86. package/lib/node/components/block/components/style-wrapper.svelte +25 -0
  87. package/lib/node/components/block/components/style-wrapper.svelte.d.ts +23 -0
  88. package/lib/node/components/content/components/enable-editor.svelte +53 -12
  89. package/lib/node/components/live-edit.svelte +20 -0
  90. package/lib/node/components/live-edit.svelte.d.ts +26 -0
  91. package/lib/node/constants/sdk-version.d.ts +1 -1
  92. package/lib/node/constants/sdk-version.js +1 -1
  93. package/lib/node/functions/get-content/generate-content-url.js +3 -8
  94. package/lib/node/functions/get-content/index.js +8 -0
  95. package/lib/node/functions/register.d.ts +18 -0
  96. package/lib/node/functions/register.js +12 -0
  97. package/lib/node/helpers/find-block.d.ts +18 -0
  98. package/lib/node/helpers/find-block.js +41 -0
  99. package/lib/node/helpers/subscribe-to-editor.d.ts +3 -2
  100. package/lib/node/helpers/subscribe-to-editor.js +4 -2
  101. package/lib/node/server-index.d.ts +1 -1
  102. package/lib/node/server-index.js +1 -1
  103. package/package.json +1 -1
  104. package/src/blocks/form/form/form.svelte +11 -6
  105. package/src/blocks/img/component-info.ts +33 -3
  106. package/src/blocks/img/img.svelte +22 -6
  107. package/src/blocks/symbol/symbol.svelte +5 -2
  108. package/src/blocks/symbol/symbol.types.ts +1 -1
  109. package/src/blocks/tabs/tabs.svelte +5 -4
  110. package/src/blocks/text/component-info.ts +0 -1
  111. package/src/components/awaiter.types.ts +7 -0
  112. package/src/components/block/block.svelte +2 -2
  113. package/src/components/block/components/component-ref/component-ref.svelte +8 -10
  114. package/src/components/block/components/interactive-element.svelte +7 -0
  115. package/src/components/block/components/live-edit-block-styles.svelte +146 -0
  116. package/src/components/block/components/style-wrapper.svelte +41 -0
  117. package/src/components/content/components/enable-editor.svelte +113 -40
  118. package/src/components/live-edit.svelte +32 -0
  119. package/src/constants/sdk-version.ts +1 -1
  120. package/src/functions/get-content/generate-content-url.ts +3 -8
  121. package/src/functions/get-content/index.ts +8 -0
  122. package/src/functions/register.ts +29 -0
  123. package/src/helpers/find-block.ts +40 -0
  124. package/src/helpers/subscribe-to-editor.ts +7 -4
  125. package/src/server-index.ts +1 -1
@@ -0,0 +1 @@
1
+ export {};
@@ -8,10 +8,10 @@ import "../../server-index";
8
8
  import "../dynamic-div.svelte";
9
9
  import { bindAnimations } from "./animator";
10
10
  import { generateKey, getComponent, getRepeatItemData, provideBuilderBlock, provideBuilderContext, provideLinkComponent, provideRegisteredComponents, } from "./block.helpers";
11
- import BlockStyles from "./components/block-styles.svelte";
12
11
  import BlockWrapper from "./components/block-wrapper.svelte";
13
12
  import ComponentRef from "./components/component-ref/component-ref.svelte";
14
13
  import RepeatedBlock from "./components/repeated-block.svelte";
14
+ import StyleWrapper from "./components/style-wrapper.svelte";
15
15
  export let block;
16
16
  export let context;
17
17
  export let registeredComponents;
@@ -109,7 +109,7 @@ afterUpdate(() => { });
109
109
  </script>
110
110
 
111
111
  {#if canShowBlock()}
112
- <BlockStyles block={processedBlock()} context={$context} />
112
+ <StyleWrapper block={processedBlock()} context={$context} id={block.id} />
113
113
 
114
114
  {#if !blockComponent?.()?.noWrap}
115
115
  {#if !repeatItem()}
@@ -2,19 +2,17 @@
2
2
  import Block from "../../block.svelte";
3
3
  import InteractiveElement from "../interactive-element.svelte";
4
4
  import { getWrapperProps } from "./component-ref.helpers";
5
- export let componentOptions;
6
- export let blockChildren;
7
5
  export let isInteractive;
8
6
  export let componentRef;
7
+ export let componentOptions;
9
8
  export let builderBlock;
10
9
  export let context;
11
10
  export let linkComponent;
12
11
  export let includeBlockProps;
12
+ export let blockChildren;
13
13
  export let registeredComponents;
14
14
  let shouldUpdate = false;
15
15
  let Wrapper = isInteractive ? InteractiveElement : componentRef;
16
- function onUpdateFn_0(..._args) { }
17
- $: onUpdateFn_0(...[componentOptions, blockChildren]);
18
16
  </script>
19
17
 
20
18
  {#if componentRef}
@@ -31,8 +29,10 @@ $: onUpdateFn_0(...[componentOptions, blockChildren]);
31
29
  contextValue: $context,
32
30
  })}
33
31
  >
34
- {#each blockChildren as child (child.id)}
35
- <Block block={child} {context} {registeredComponents} {linkComponent} />
36
- {/each}
37
- </svelte:component>
32
+ {#if componentRef}
33
+ {#each blockChildren as child (child.id)}
34
+ <Block block={child} {context} {registeredComponents} {linkComponent} />
35
+ {/each}
36
+ {/if}</svelte:component
37
+ >
38
38
  {/if}
@@ -2,14 +2,14 @@ import { SvelteComponent } from "svelte";
2
2
  import type { ComponentProps } from "./component-ref.helpers";
3
3
  declare const __propDef: {
4
4
  props: {
5
- componentOptions: ComponentProps["componentOptions"];
6
- blockChildren: ComponentProps["blockChildren"];
7
5
  isInteractive: ComponentProps["isInteractive"];
8
6
  componentRef: ComponentProps["componentRef"];
7
+ componentOptions: ComponentProps["componentOptions"];
9
8
  builderBlock: ComponentProps["builderBlock"];
10
9
  context: ComponentProps["context"];
11
10
  linkComponent: ComponentProps["linkComponent"];
12
11
  includeBlockProps: ComponentProps["includeBlockProps"];
12
+ blockChildren: ComponentProps["blockChildren"];
13
13
  registeredComponents: ComponentProps["registeredComponents"];
14
14
  };
15
15
  events: {
@@ -1,8 +1,11 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { getBlockActions } from "../../../functions/get-block-actions";
3
+ <script>import { TARGET } from "../../../constants/target";
4
+ import { getBlockActions } from "../../../functions/get-block-actions";
4
5
  import { getBlockProperties } from "../../../functions/get-block-properties";
6
+ import { isEditing } from "../../../server-index";
5
7
  import Awaiter from "../../awaiter.svelte";
8
+ import LiveEdit from "../../live-edit.svelte";
6
9
  export let wrapperProps;
7
10
  export let block;
8
11
  export let includeBlockProps;
@@ -40,6 +43,10 @@ $: onUpdateFn_0(...[wrapperProps, block?.component?.options]);
40
43
  props={wrapperProps}
41
44
  attributes={attributes()}><slot /></Awaiter
42
45
  >
46
+ {:else if TARGET === "rsc" && isEditing()}
47
+ <LiveEdit {Wrapper} id={block.id || ""} attributes={attributes()}
48
+ ><slot /></LiveEdit
49
+ >
43
50
  {:else}
44
51
  <svelte:component
45
52
  this={Wrapper}
@@ -0,0 +1,114 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../../constants/device-sizes";
4
+ import { TARGET } from "../../../constants/target";
5
+ import { camelToKebabCase } from "../../../functions/camel-to-kebab-case";
6
+ import { getProcessedBlock } from "../../../functions/get-processed-block";
7
+ import { createCssClass } from "../../../helpers/css";
8
+ import { findBlockById } from "../../../helpers/find-block";
9
+ import { checkIsDefined } from "../../../helpers/nullable";
10
+ import InlinedStyles from "../../inlined-styles.svelte";
11
+ export let contextProvider;
12
+ export let id = undefined;
13
+ $: block = () => {
14
+ return findBlockById(contextProvider.content, id);
15
+ };
16
+ $: processedBlock = () => {
17
+ const foundBlock = block();
18
+ if (!foundBlock) {
19
+ return null;
20
+ }
21
+ const blockToUse = foundBlock.repeat?.collection
22
+ ? foundBlock
23
+ : getProcessedBlock({
24
+ block: foundBlock,
25
+ localState: contextProvider.localState,
26
+ rootState: contextProvider.rootState,
27
+ rootSetState: contextProvider.rootSetState,
28
+ context: contextProvider.context,
29
+ });
30
+ return blockToUse;
31
+ };
32
+ $: canShowBlock = () => {
33
+ if (checkIsDefined(processedBlock?.()?.hide)) {
34
+ return !processedBlock?.()?.hide;
35
+ }
36
+ if (checkIsDefined(processedBlock?.()?.show)) {
37
+ return processedBlock?.()?.show;
38
+ }
39
+ return true;
40
+ };
41
+ $: css = () => {
42
+ const styles = processedBlock?.()?.responsiveStyles;
43
+ const content = contextProvider.content;
44
+ const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
45
+ const contentHasXSmallBreakpoint = Boolean(content?.meta?.breakpoints?.xsmall);
46
+ const largeStyles = styles?.large;
47
+ const mediumStyles = styles?.medium;
48
+ const smallStyles = styles?.small;
49
+ const xsmallStyles = styles?.xsmall;
50
+ const className = processedBlock?.()?.id;
51
+ if (!className) {
52
+ return "";
53
+ }
54
+ const largeStylesClass = largeStyles
55
+ ? createCssClass({
56
+ className,
57
+ styles: largeStyles,
58
+ })
59
+ : "";
60
+ const mediumStylesClass = mediumStyles
61
+ ? createCssClass({
62
+ className,
63
+ styles: mediumStyles,
64
+ mediaQuery: getMaxWidthQueryForSize("medium", sizesWithUpdatedBreakpoints),
65
+ })
66
+ : "";
67
+ const smallStylesClass = smallStyles
68
+ ? createCssClass({
69
+ className,
70
+ styles: smallStyles,
71
+ mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
72
+ })
73
+ : "";
74
+ const xsmallStylesClass = xsmallStyles && contentHasXSmallBreakpoint
75
+ ? createCssClass({
76
+ className,
77
+ styles: xsmallStyles,
78
+ mediaQuery: getMaxWidthQueryForSize("xsmall", sizesWithUpdatedBreakpoints),
79
+ })
80
+ : "";
81
+ const hoverAnimation = processedBlock().animations &&
82
+ processedBlock().animations.find((item) => item.trigger === "hover");
83
+ let hoverStylesClass = "";
84
+ if (hoverAnimation) {
85
+ const hoverStyles = hoverAnimation.steps?.[1]?.styles || {};
86
+ hoverStylesClass =
87
+ createCssClass({
88
+ className: `${className}:hover`,
89
+ styles: {
90
+ ...hoverStyles,
91
+ transition: `all ${hoverAnimation.duration}s ${camelToKebabCase(hoverAnimation.easing)}`,
92
+ transitionDelay: hoverAnimation.delay
93
+ ? `${hoverAnimation.delay}s`
94
+ : "0s",
95
+ },
96
+ }) || "";
97
+ }
98
+ return [
99
+ largeStylesClass,
100
+ mediumStylesClass,
101
+ smallStylesClass,
102
+ xsmallStylesClass,
103
+ hoverStylesClass,
104
+ ].join(" ");
105
+ };
106
+ </script>
107
+
108
+ {#if TARGET === "rsc" && css() && canShowBlock()}
109
+ <InlinedStyles
110
+ id="builderio-block"
111
+ styles={css()}
112
+ nonce={contextProvider.nonce}
113
+ />
114
+ {/if}
@@ -0,0 +1,22 @@
1
+ import { SvelteComponent } from "svelte";
2
+ type LiveEditBlockStylesProps = {
3
+ id?: any;
4
+ contextProvider: BuilderContextInterface;
5
+ };
6
+ import type { BuilderContextInterface } from "../../../server-index";
7
+ declare const __propDef: {
8
+ props: {
9
+ contextProvider: LiveEditBlockStylesProps["contextProvider"];
10
+ id?: LiveEditBlockStylesProps["id"];
11
+ };
12
+ events: {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {};
16
+ };
17
+ type LiveEditBlockStylesProps_ = typeof __propDef.props;
18
+ export { LiveEditBlockStylesProps_ as LiveEditBlockStylesProps };
19
+ export type LiveEditBlockStylesEvents = typeof __propDef.events;
20
+ export type LiveEditBlockStylesSlots = typeof __propDef.slots;
21
+ export default class LiveEditBlockStyles extends SvelteComponent<LiveEditBlockStylesProps, LiveEditBlockStylesEvents, LiveEditBlockStylesSlots> {
22
+ }
@@ -0,0 +1,25 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import { getContext, onMount } from "svelte";
4
+ import { TARGET } from "../../../constants/target";
5
+ import { BuilderContext } from "../../../context/index";
6
+ import "../../../server-index";
7
+ import BlockStyles from "./block-styles.svelte";
8
+ import LiveEditBlockStyles from "./live-edit-block-styles.svelte";
9
+ export let block;
10
+ export let context;
11
+ let contextProvider = getContext(BuilderContext.key);
12
+ let isClientEditing = false;
13
+ let isHydrated = false;
14
+ onMount(() => { });
15
+ </script>
16
+
17
+ {#if isHydrated}
18
+ {#if TARGET === "rsc" && isClientEditing}
19
+ <LiveEditBlockStyles id={block.id} contextProvider={$contextProvider} />
20
+ {:else}
21
+ <BlockStyles {block} {context} />
22
+ {/if}
23
+ {:else}
24
+ <BlockStyles {block} {context} />
25
+ {/if}
@@ -0,0 +1,23 @@
1
+ import { SvelteComponent } from "svelte";
2
+ type StyleWrapperProps = {
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ id?: string;
6
+ };
7
+ import { BuilderBlock, BuilderContextInterface } from "../../../server-index";
8
+ declare const __propDef: {
9
+ props: {
10
+ block: StyleWrapperProps["block"];
11
+ context: StyleWrapperProps["context"];
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {};
17
+ };
18
+ type StyleWrapperProps_ = typeof __propDef.props;
19
+ export { StyleWrapperProps_ as StyleWrapperProps };
20
+ export type StyleWrapperEvents = typeof __propDef.events;
21
+ export type StyleWrapperSlots = typeof __propDef.slots;
22
+ export default class StyleWrapper extends SvelteComponent<StyleWrapperProps, StyleWrapperEvents, StyleWrapperSlots> {
23
+ }
@@ -15,7 +15,7 @@ import { getInteractionPropertiesForEvent } from "../../../functions/track/inter
15
15
  import { getDefaultCanTrack } from "../../../helpers/canTrack";
16
16
  import { getCookieSync } from "../../../helpers/cookie";
17
17
  import "../../../helpers/preview-lru-cache/set";
18
- import { createEditorListener } from "../../../helpers/subscribe-to-editor";
18
+ import { createEditorListener, } from "../../../helpers/subscribe-to-editor";
19
19
  import { setupBrowserForEditing } from "../../../scripts/init-editing";
20
20
  import { triggerAnimation } from "../../block/animator";
21
21
  import "../../dynamic-div.svelte";
@@ -46,7 +46,7 @@ function stringifyStyles(stylesObj) {
46
46
  }
47
47
  return styles;
48
48
  }
49
- function mergeNewRootState(newData) {
49
+ function mergeNewRootState(newData, editType) {
50
50
  const combinedState = {
51
51
  ...$builderContextSignal.rootState,
52
52
  ...newData,
@@ -57,8 +57,14 @@ function mergeNewRootState(newData) {
57
57
  else {
58
58
  $builderContextSignal.rootState = combinedState;
59
59
  }
60
+ if ($builderContextSignal.rootSetState) {
61
+ $builderContextSignal.rootSetState(combinedState);
62
+ }
63
+ else {
64
+ $builderContextSignal.rootState = combinedState;
65
+ }
60
66
  }
61
- function mergeNewContent(newContent) {
67
+ function mergeNewContent(newContent, editType) {
62
68
  const newContentValue = {
63
69
  ...$builderContextSignal.content,
64
70
  ...newContent,
@@ -96,11 +102,11 @@ function processMessage(event) {
96
102
  animation: (animation) => {
97
103
  triggerAnimation(animation);
98
104
  },
99
- contentUpdate: (newContent) => {
100
- mergeNewContent(newContent);
105
+ contentUpdate: (newContent, editType) => {
106
+ mergeNewContent(newContent, editType);
101
107
  },
102
- stateUpdate: (newState) => {
103
- mergeNewRootState(newState);
108
+ stateUpdate: (newState, editType) => {
109
+ mergeNewRootState(newState, editType);
104
110
  },
105
111
  },
106
112
  })(event);
@@ -126,15 +132,20 @@ function onClick(event) {
126
132
  }
127
133
  function runHttpRequests() {
128
134
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
129
- Object.entries(requests).forEach(([key, url]) => {
130
- if (!url)
135
+ Object.entries(requests).forEach(([key, httpRequest]) => {
136
+ if (!httpRequest)
131
137
  return;
138
+ const isCoreRequest = typeof httpRequest === "object" &&
139
+ httpRequest["@type"] === "@builder.io/core:Request";
132
140
  // request already in progress
133
141
  if (httpReqsPending[key])
134
142
  return;
135
143
  // request already completed, and not in edit mode
136
144
  if (httpReqsData[key] && !isEditing())
137
145
  return;
146
+ const url = isCoreRequest
147
+ ? httpRequest.request.url
148
+ : httpRequest;
138
149
  httpReqsPending[key] = true;
139
150
  const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
140
151
  code: group,
@@ -143,8 +154,27 @@ function runHttpRequests() {
143
154
  rootState: $builderContextSignal.rootState,
144
155
  rootSetState: $builderContextSignal.rootSetState,
145
156
  })));
146
- logFetch(evaluatedUrl);
147
- fetch(evaluatedUrl)
157
+ const fetchRequestObj = isCoreRequest
158
+ ? {
159
+ url: evaluatedUrl,
160
+ method: httpRequest.request.method,
161
+ headers: httpRequest.request.headers,
162
+ body: httpRequest.request.body,
163
+ }
164
+ : {
165
+ url: evaluatedUrl,
166
+ method: "GET",
167
+ };
168
+ logFetch(JSON.stringify(fetchRequestObj));
169
+ const fetchOptions = {
170
+ method: fetchRequestObj.method,
171
+ headers: fetchRequestObj.headers,
172
+ body: fetchRequestObj.body,
173
+ };
174
+ if (fetchRequestObj.method === "GET") {
175
+ delete fetchOptions.body;
176
+ }
177
+ fetch(fetchRequestObj.url, fetchOptions)
148
178
  .then((response) => response.json())
149
179
  .then((json) => {
150
180
  mergeNewRootState({
@@ -153,7 +183,7 @@ function runHttpRequests() {
153
183
  httpReqsData[key] = true;
154
184
  })
155
185
  .catch((err) => {
156
- console.error("error fetching dynamic data", url, err);
186
+ console.error("error fetching dynamic data", JSON.stringify(httpRequest), err);
157
187
  })
158
188
  .finally(() => {
159
189
  httpReqsPending[key] = false;
@@ -248,6 +278,9 @@ $: showContentProps = () => {
248
278
  };
249
279
  let elementRef;
250
280
  let hasExecuted = false;
281
+ let contextValue = $builderContextSignal;
282
+ let prevData = null;
283
+ let prevLocale = "";
251
284
  let ContentWrapper = contentWrapper || "div";
252
285
  let httpReqsData = {};
253
286
  let httpReqsPending = {};
@@ -304,15 +337,23 @@ $: onUpdateFn_1_builderContextSignal_rootState =
304
337
  $: onUpdateFn_1(...[onUpdateFn_1_builderContextSignal_rootState]);
305
338
  function onUpdateFn_2(..._args) {
306
339
  if (data) {
340
+ if (prevData === data) {
341
+ return;
342
+ }
307
343
  mergeNewRootState(data);
344
+ prevData = data;
308
345
  }
309
346
  }
310
347
  $: onUpdateFn_2(...[data]);
311
348
  function onUpdateFn_3(..._args) {
312
349
  if (locale) {
350
+ if (prevLocale === locale) {
351
+ return;
352
+ }
313
353
  mergeNewRootState({
314
354
  locale: locale,
315
355
  });
356
+ prevLocale = locale;
316
357
  }
317
358
  }
318
359
  $: onUpdateFn_3(...[locale]);
@@ -0,0 +1,20 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import { getContext } from "svelte";
4
+ import { BuilderContext } from "../context/index";
5
+ import { findBlockById } from "../helpers/find-block";
6
+ export let id = undefined;
7
+ export let attributes = undefined;
8
+ export let Wrapper = undefined;
9
+ let context = getContext(BuilderContext.key);
10
+ $: block = () => {
11
+ return findBlockById($context.content, id);
12
+ };
13
+ $: options = () => {
14
+ return block?.()?.component?.options || {};
15
+ };
16
+ </script>
17
+
18
+ <svelte:component this={Wrapper} {...options()} {attributes}
19
+ ><slot /></svelte:component
20
+ >
@@ -0,0 +1,26 @@
1
+ import { SvelteComponent } from "svelte";
2
+ type LiveEditProps = {
3
+ children?: any;
4
+ id?: any;
5
+ Wrapper?: any;
6
+ attributes?: any;
7
+ };
8
+ declare const __propDef: {
9
+ props: {
10
+ id?: LiveEditProps["id"];
11
+ attributes?: LiveEditProps["attributes"];
12
+ Wrapper?: LiveEditProps["Wrapper"];
13
+ };
14
+ events: {
15
+ [evt: string]: CustomEvent<any>;
16
+ };
17
+ slots: {
18
+ default: {};
19
+ };
20
+ };
21
+ type LiveEditProps_ = typeof __propDef.props;
22
+ export { LiveEditProps_ as LiveEditProps };
23
+ export type LiveEditEvents = typeof __propDef.events;
24
+ export type LiveEditSlots = typeof __propDef.slots;
25
+ export default class LiveEdit extends SvelteComponent<LiveEditProps, LiveEditEvents, LiveEditSlots> {
26
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "4.1.3";
1
+ export declare const SDK_VERSION = "4.2.3";
@@ -1 +1 @@
1
- export const SDK_VERSION = "4.1.3";
1
+ export const SDK_VERSION = "4.2.3";
@@ -20,15 +20,10 @@ export const generateContentUrl = (options) => {
20
20
  url.searchParams.set('limit', String(limit));
21
21
  url.searchParams.set('noTraverse', String(noTraverse));
22
22
  url.searchParams.set('includeRefs', String(true));
23
- const finalLocale = locale || userAttributes?.locale;
24
- let finalUserAttributes = userAttributes || {};
25
- if (finalLocale) {
26
- url.searchParams.set('locale', finalLocale);
27
- finalUserAttributes = {
28
- locale: finalLocale,
29
- ...finalUserAttributes
30
- };
23
+ if (locale) {
24
+ url.searchParams.set('locale', locale);
31
25
  }
26
+ let finalUserAttributes = userAttributes || {};
32
27
  if (enrich)
33
28
  url.searchParams.set('enrich', String(enrich));
34
29
  url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
@@ -12,6 +12,14 @@ const checkContentHasResults = (content) => 'results' in content;
12
12
  * Returns the first content entry that matches the given options.
13
13
  */
14
14
  export async function fetchOneEntry(options) {
15
+ const finalLocale = options.locale || options.userAttributes?.locale;
16
+ if (finalLocale) {
17
+ options.locale = finalLocale;
18
+ options.userAttributes = {
19
+ locale: finalLocale,
20
+ ...options.userAttributes
21
+ };
22
+ }
15
23
  const allContent = await fetchEntries({
16
24
  ...options,
17
25
  limit: 1
@@ -1,5 +1,22 @@
1
1
  import type { BuilderBlock } from '../types/builder-block';
2
2
  import type { DeepPartial } from '../types/deep-partial';
3
+ import type { Input } from '../types/input';
4
+ export interface Action {
5
+ name: string;
6
+ inputs?: readonly Input[];
7
+ returnType?: Input;
8
+ action: (options: Record<string, any>) => string;
9
+ /**
10
+ * Is an action for expression (e.g. calculating a binding like a formula
11
+ * to fill a value based on locale) or a function (e.g. something to trigger
12
+ * on an event like add to cart) or either (e.g. a custom code block)
13
+ */
14
+ kind: 'expression' | 'function' | 'any';
15
+ /**
16
+ * Globally unique ID for an action, e.g. "@builder.io:setState"
17
+ */
18
+ id: string;
19
+ }
3
20
  export interface InsertMenuItem {
4
21
  name: string;
5
22
  icon?: string;
@@ -14,3 +31,4 @@ export interface InsertMenuConfig {
14
31
  }
15
32
  export declare function register(type: 'insertMenu', info: InsertMenuConfig): void;
16
33
  export declare function register(type: string, info: any): void;
34
+ export declare function registerAction(action: Action): void;
@@ -29,3 +29,15 @@ export function register(type, info) {
29
29
  }
30
30
  }
31
31
  }
32
+ export function registerAction(action) {
33
+ if (isBrowser()) {
34
+ const actionClone = JSON.parse(JSON.stringify(action));
35
+ if (action.action) {
36
+ actionClone.action = action.action.toString();
37
+ }
38
+ window.parent?.postMessage({
39
+ type: 'builder.registerAction',
40
+ data: actionClone
41
+ }, '*');
42
+ }
43
+ }
@@ -0,0 +1,18 @@
1
+ import type { BuilderBlock, BuilderContent } from '../server-index';
2
+ /**
3
+ * Recursively searches for a block by ID.
4
+ *
5
+ * @param content The Builder content to search through.
6
+ * @param id The ID of the block to search for.
7
+ * @returns The block if found, otherwise null.
8
+ */
9
+ export declare const findBlockById: (content: BuilderContent, id: string) => BuilderBlock | null;
10
+ /**
11
+ * Helper function to recursively search through block tree.
12
+ *
13
+ * @param blocks The blocks to search through.
14
+ * @param id The ID of the block to search for.
15
+ * @returns The block if found, otherwise null.
16
+ * @private This is an internal implementation detail.
17
+ */
18
+ export declare const findBlockInTree: (blocks: BuilderBlock[] | undefined, id: string) => BuilderBlock | null;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Recursively searches for a block by ID.
3
+ *
4
+ * @param content The Builder content to search through.
5
+ * @param id The ID of the block to search for.
6
+ * @returns The block if found, otherwise null.
7
+ */
8
+ export const findBlockById = (content, id) => {
9
+ return findBlockInTree(content.data?.blocks, id);
10
+ };
11
+ /**
12
+ * Helper function to recursively search through block tree.
13
+ *
14
+ * @param blocks The blocks to search through.
15
+ * @param id The ID of the block to search for.
16
+ * @returns The block if found, otherwise null.
17
+ * @private This is an internal implementation detail.
18
+ */
19
+ export const findBlockInTree = (blocks, id) => {
20
+ if (!blocks)
21
+ return null;
22
+ for (const block of blocks) {
23
+ if (block.id === id)
24
+ return block;
25
+ if (block.children) {
26
+ const child = findBlockInTree(block.children, id);
27
+ if (child)
28
+ return child;
29
+ }
30
+ if (block.component?.name === 'Columns' && block.component?.options?.columns) {
31
+ for (const column of block.component.options.columns) {
32
+ if (column.blocks) {
33
+ const child = findBlockInTree(column.blocks, id);
34
+ if (child)
35
+ return child;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ return null;
41
+ };
@@ -2,10 +2,11 @@ import type { ContentProps } from '../components/content/content.types';
2
2
  import type { BuilderAnimation } from '../types/builder-block';
3
3
  import type { BuilderContent } from '../types/builder-content';
4
4
  import type { Dictionary } from '../types/typescript';
5
+ export type EditType = 'client' | 'server' | undefined;
5
6
  type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
6
7
  callbacks: {
7
- contentUpdate: (updatedContent: BuilderContent) => void;
8
- stateUpdate: (newState: Dictionary<string>) => void;
8
+ contentUpdate: (updatedContent: BuilderContent, editType?: EditType) => void;
9
+ stateUpdate: (newState: Dictionary<string>, editType?: EditType) => void;
9
10
  animation: (updatedContent: BuilderAnimation) => void;
10
11
  configureSdk: (updatedContent: any) => void;
11
12
  };