@builder.io/sdk-svelte 0.0.3 → 0.0.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 (142) hide show
  1. package/package/--package.json +159 -0
  2. package/package/blocks/BaseText.svelte +19 -0
  3. package/package/blocks/BaseText.svelte.d.ts +19 -0
  4. package/package/blocks/columns/columns.svelte +13 -4
  5. package/package/blocks/columns/columns.svelte.d.ts +1 -1
  6. package/package/blocks/custom-code/custom-code.svelte +1 -1
  7. package/package/blocks/embed/embed.svelte +2 -0
  8. package/package/blocks/form/form.svelte +7 -5
  9. package/package/blocks/image/image.svelte +48 -46
  10. package/package/blocks/image/image.svelte.d.ts +1 -1
  11. package/package/blocks/img/img.svelte +7 -2
  12. package/package/blocks/section/section.svelte +7 -2
  13. package/package/blocks/symbol/symbol.svelte +13 -13
  14. package/package/blocks/symbol/symbol.svelte.d.ts +3 -3
  15. package/package/blocks/video/video.svelte +14 -3
  16. package/package/components/render-block/block-styles.svelte +24 -19
  17. package/package/components/render-block/block-styles.svelte.d.ts +2 -2
  18. package/package/components/render-block/render-block.svelte +81 -58
  19. package/package/components/render-block/render-block.svelte.d.ts +2 -2
  20. package/package/components/render-block/render-component-with-context.svelte +32 -0
  21. package/package/components/render-block/render-component-with-context.svelte.d.ts +19 -0
  22. package/package/components/render-block/render-component.svelte +1 -3
  23. package/package/components/render-block/render-component.svelte.d.ts +2 -2
  24. package/package/components/render-block/render-repeated-block.svelte +3 -0
  25. package/package/components/render-block/types.d.ts +2 -2
  26. package/package/components/render-block/types.js +1 -2
  27. package/package/components/render-blocks.svelte +12 -1
  28. package/package/components/render-blocks.svelte.d.ts +3 -1
  29. package/package/components/render-content/components/render-styles.svelte +2 -1
  30. package/package/components/render-content/render-content.svelte +24 -8
  31. package/package/components/render-content/render-content.svelte.d.ts +2 -2
  32. package/package/constants/builder-registered-components.js +3 -0
  33. package/package/context/builder.context.d.ts +1 -0
  34. package/package/context/builder.context.js +1 -0
  35. package/package/context/types.d.ts +4 -3
  36. package/package/context/types.js +1 -3
  37. package/package/functions/extract-text-styles.d.ts +4 -0
  38. package/package/functions/extract-text-styles.js +34 -0
  39. package/package/functions/fast-clone.d.ts +4 -0
  40. package/package/functions/fast-clone.js +4 -0
  41. package/package/functions/get-block-actions-handler.d.ts +5 -0
  42. package/package/functions/get-block-actions-handler.js +9 -0
  43. package/package/functions/get-block-actions.d.ts +1 -1
  44. package/package/functions/get-block-actions.js +2 -8
  45. package/package/functions/get-block-component-options.d.ts +1 -1
  46. package/package/functions/get-block-component-options.js +0 -1
  47. package/package/functions/get-block-properties.d.ts +1 -1
  48. package/package/functions/get-block-properties.js +0 -1
  49. package/package/functions/get-block-tag.d.ts +1 -1
  50. package/package/functions/get-block-tag.js +0 -1
  51. package/package/functions/get-content/ab-testing.d.ts +5 -3
  52. package/package/functions/get-content/ab-testing.js +75 -37
  53. package/package/functions/get-content/index.d.ts +1 -1
  54. package/package/functions/get-content/index.js +4 -5
  55. package/package/functions/get-content/types.d.ts +7 -2
  56. package/package/functions/get-processed-block.d.ts +1 -1
  57. package/package/functions/get-processed-block.js +5 -4
  58. package/package/functions/get-processed-block.test.js +0 -1
  59. package/package/functions/get-react-native-block-styles.d.ts +6 -0
  60. package/package/functions/get-react-native-block-styles.js +16 -0
  61. package/package/functions/register-component.d.ts +2 -2
  62. package/package/functions/register-component.js +1 -5
  63. package/package/functions/register.d.ts +2 -2
  64. package/package/functions/register.js +0 -2
  65. package/package/functions/sanitize-react-native-block-styles.d.ts +3 -0
  66. package/package/functions/sanitize-react-native-block-styles.js +53 -0
  67. package/package/functions/track.d.ts +1 -1
  68. package/package/functions/track.js +5 -6
  69. package/package/functions/transform-block.d.ts +1 -1
  70. package/package/functions/transform-block.js +0 -1
  71. package/package/helpers/ab-tests.d.ts +8 -0
  72. package/package/helpers/ab-tests.js +5 -0
  73. package/package/helpers/cookie.d.ts +9 -3
  74. package/package/helpers/cookie.js +8 -3
  75. package/package/helpers/css.d.ts +5 -1
  76. package/package/helpers/css.js +14 -1
  77. package/package/helpers/localStorage.d.ts +3 -4
  78. package/package/helpers/sessionId.d.ts +3 -4
  79. package/package/helpers/sessionId.js +5 -3
  80. package/package/helpers/visitorId.d.ts +3 -5
  81. package/package/scripts/init-editing.js +42 -38
  82. package/package/types/builder-content.d.ts +1 -1
  83. package/package/types/builder-content.js +1 -1
  84. package/package/types/targets.d.ts +1 -1
  85. package/package/types/typescript.d.ts +1 -0
  86. package/package.json +8 -3
  87. package/package/blocks/button/button.lite.d.ts +0 -0
  88. package/package/blocks/button/button.lite.tsx +0 -36
  89. package/package/blocks/columns/columns.lite.d.ts +0 -0
  90. package/package/blocks/columns/columns.lite.tsx +0 -139
  91. package/package/blocks/custom-code/custom-code.lite.d.ts +0 -0
  92. package/package/blocks/custom-code/custom-code.lite.tsx +0 -70
  93. package/package/blocks/embed/embed.lite.d.ts +0 -0
  94. package/package/blocks/embed/embed.lite.tsx +0 -52
  95. package/package/blocks/form/form.lite.d.ts +0 -0
  96. package/package/blocks/form/form.lite.tsx +0 -351
  97. package/package/blocks/fragment/fragment.lite.d.ts +0 -0
  98. package/package/blocks/fragment/fragment.lite.tsx +0 -12
  99. package/package/blocks/image/image.lite.d.ts +0 -0
  100. package/package/blocks/image/image.lite.tsx +0 -148
  101. package/package/blocks/img/img.lite.d.ts +0 -0
  102. package/package/blocks/img/img.lite.tsx +0 -48
  103. package/package/blocks/input/input.lite.d.ts +0 -0
  104. package/package/blocks/input/input.lite.tsx +0 -34
  105. package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
  106. package/package/blocks/raw-text/raw-text.lite.tsx +0 -15
  107. package/package/blocks/section/section.lite.d.ts +0 -0
  108. package/package/blocks/section/section.lite.tsx +0 -30
  109. package/package/blocks/select/select.lite.d.ts +0 -0
  110. package/package/blocks/select/select.lite.tsx +0 -34
  111. package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
  112. package/package/blocks/submit-button/submit-button.lite.tsx +0 -15
  113. package/package/blocks/symbol/symbol.lite.d.ts +0 -0
  114. package/package/blocks/symbol/symbol.lite.tsx +0 -92
  115. package/package/blocks/text/text.lite.d.ts +0 -0
  116. package/package/blocks/text/text.lite.tsx +0 -11
  117. package/package/blocks/textarea/textarea.lite.d.ts +0 -0
  118. package/package/blocks/textarea/textarea.lite.tsx +0 -19
  119. package/package/blocks/video/video.lite.d.ts +0 -0
  120. package/package/blocks/video/video.lite.tsx +0 -92
  121. package/package/components/render-block/block-styles.lite.d.ts +0 -0
  122. package/package/components/render-block/block-styles.lite.tsx +0 -60
  123. package/package/components/render-block/render-block.lite.d.ts +0 -0
  124. package/package/components/render-block/render-block.lite.tsx +0 -216
  125. package/package/components/render-block/render-component.lite.d.ts +0 -0
  126. package/package/components/render-block/render-component.lite.tsx +0 -33
  127. package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
  128. package/package/components/render-block/render-repeated-block.lite.tsx +0 -49
  129. package/package/components/render-blocks.lite.d.ts +0 -0
  130. package/package/components/render-blocks.lite.tsx +0 -91
  131. package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
  132. package/package/components/render-content/components/render-styles.lite.tsx +0 -86
  133. package/package/components/render-content/render-content.lite.d.ts +0 -0
  134. package/package/components/render-content/render-content.lite.tsx +0 -356
  135. package/package/components/render-inlined-styles.lite.d.ts +0 -0
  136. package/package/components/render-inlined-styles.lite.tsx +0 -27
  137. package/package/functions/convert-style-object.d.ts +0 -1
  138. package/package/functions/convert-style-object.js +0 -3
  139. package/package/functions/get-block-styles.d.ts +0 -2
  140. package/package/functions/get-block-styles.js +0 -21
  141. package/package/functions/sanitize-styles.d.ts +0 -4
  142. package/package/functions/sanitize-styles.js +0 -6
@@ -2,10 +2,8 @@
2
2
 
3
3
  <script>import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
4
4
  import { TARGET } from "../../constants/target.js";
5
- import "../../context/types.js";
6
5
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
7
- import { convertStyleMaptoCSS } from "../../helpers/css.js";
8
- import "../../types/builder-block.js";
6
+ import { createCssClass } from "../../helpers/css.js";
9
7
  import RenderInlinedStyles from "../render-inlined-styles.svelte";
10
8
  export let block;
11
9
  export let context;
@@ -22,24 +20,31 @@ $: css = () => {
22
20
  const largeStyles = styles?.large;
23
21
  const mediumStyles = styles?.medium;
24
22
  const smallStyles = styles?.small;
25
- return `
26
- ${largeStyles
27
- ? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}`
28
- : ""}
29
- ${mediumStyles
30
- ? `${getMaxWidthQueryForSize("medium")} {
31
- .${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
32
- }`
33
- : ""}
34
- ${smallStyles
35
- ? `${getMaxWidthQueryForSize("small")} {
36
- .${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
37
- }`
38
- : ""}
39
- }`;
23
+ const className = useBlock().id;
24
+ const largeStylesClass = largeStyles
25
+ ? createCssClass({
26
+ className,
27
+ styles: largeStyles,
28
+ })
29
+ : "";
30
+ const mediumStylesClass = mediumStyles
31
+ ? createCssClass({
32
+ className,
33
+ styles: mediumStyles,
34
+ mediaQuery: getMaxWidthQueryForSize("medium"),
35
+ })
36
+ : "";
37
+ const smallStylesClass = smallStyles
38
+ ? createCssClass({
39
+ className,
40
+ styles: smallStyles,
41
+ mediaQuery: getMaxWidthQueryForSize("small"),
42
+ })
43
+ : "";
44
+ return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
40
45
  };
41
46
  </script>
42
47
 
43
- {#if TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}
48
+ {#if TARGET !== "reactNative" && css()}
44
49
  <RenderInlinedStyles styles={css()} />
45
50
  {/if}
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { BuilderContextInterface } from "../../context/types.js";
3
+ import type { BuilderBlock } from "../../types/builder-block.js";
2
4
  export declare type BlockStylesProps = {
3
5
  block: BuilderBlock;
4
6
  context: BuilderContextInterface;
5
7
  };
6
- import { BuilderContextInterface } from "../../context/types.js";
7
- import { BuilderBlock } from "../../types/builder-block.js";
8
8
  declare const __propDef: {
9
9
  props: {
10
10
  block: BlockStylesProps["block"];
@@ -1,20 +1,19 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import "../../context/types.js";
4
- import { getBlockActions } from "../../functions/get-block-actions.js";
3
+ <script>import { getBlockActions } from "../../functions/get-block-actions.js";
5
4
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
6
5
  import { getBlockProperties } from "../../functions/get-block-properties.js";
7
- import { getBlockStyles } from "../../functions/get-block-styles.js";
8
6
  import { getBlockTag } from "../../functions/get-block-tag.js";
9
7
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
10
- import "../../types/builder-block.js";
11
- import "../../types/typescript.js";
12
8
  import { evaluate } from "../../functions/evaluate.js";
13
9
  import BlockStyles from "./block-styles.svelte";
14
10
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
15
- import RenderComponent from "./render-component.svelte";
16
- import "./types.js";
17
11
  import RenderRepeatedBlock from "./render-repeated-block.svelte";
12
+ import { TARGET } from "../../constants/target.js";
13
+ import { extractTextStyles } from "../../functions/extract-text-styles.js";
14
+ import RenderComponentWithContext from "./render-component-with-context.svelte";
15
+ import RenderComponent from "./render-component.svelte";
16
+ import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
18
17
  export let block;
19
18
  export let context;
20
19
  $: component = () => {
@@ -39,18 +38,6 @@ $: component = () => {
39
38
  return ref;
40
39
  }
41
40
  };
42
- $: componentInfo = () => {
43
- if (component()) {
44
- const { component: _, ...info } = component();
45
- return info;
46
- }
47
- else {
48
- return undefined;
49
- }
50
- };
51
- $: componentRef = () => {
52
- return component?.()?.component;
53
- };
54
41
  $: tagName = () => {
55
42
  return getBlockTag(useBlock());
56
43
  };
@@ -72,39 +59,43 @@ $: attributes = () => {
72
59
  state: context.state,
73
60
  context: context.context,
74
61
  }),
75
- style: getBlockStyles(useBlock()),
62
+ ...(TARGET === "reactNative"
63
+ ? {
64
+ style: getReactNativeBlockStyles({
65
+ block: useBlock(),
66
+ context: context,
67
+ }),
68
+ }
69
+ : {}),
76
70
  };
77
71
  };
78
72
  $: shouldWrap = () => {
79
- return !componentInfo?.()?.noWrap;
80
- };
81
- $: componentOptions = () => {
82
- return {
83
- ...getBlockComponentOptions(useBlock()),
84
- /**
85
- * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
86
- * they are provided to the component itself directly.
87
- */
88
- ...(shouldWrap()
89
- ? {}
90
- : {
91
- attributes: attributes(),
92
- }),
93
- };
73
+ return !component?.()?.noWrap;
94
74
  };
95
75
  $: renderComponentProps = () => {
96
76
  return {
97
77
  blockChildren: children(),
98
- componentRef: componentRef(),
99
- componentOptions: componentOptions(),
100
- context: context,
78
+ componentRef: component?.()?.component,
79
+ componentOptions: {
80
+ ...getBlockComponentOptions(useBlock()),
81
+ /**
82
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
83
+ * they are provided to the component itself directly.
84
+ */
85
+ ...(shouldWrap()
86
+ ? {}
87
+ : {
88
+ attributes: attributes(),
89
+ }),
90
+ },
91
+ context: childrenContext(),
101
92
  };
102
93
  };
103
94
  $: children = () => {
104
95
  // TO-DO: When should `canHaveChildren` dictate rendering?
105
96
  // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
106
97
  // but still receive and need to render children.
107
- // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
98
+ // return componentInfo?.canHaveChildren ? useBlock().children : [];
108
99
  return useBlock().children ?? [];
109
100
  };
110
101
  $: childrenWithoutParentComponent = () => {
@@ -114,7 +105,7 @@ $: childrenWithoutParentComponent = () => {
114
105
  * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
115
106
  * blocks, and the children will be repeated within those blocks.
116
107
  */
117
- const shouldRenderChildrenOutsideRef = !componentRef() && !repeatItemData();
108
+ const shouldRenderChildrenOutsideRef = !component?.()?.component && !repeatItemData();
118
109
  return shouldRenderChildrenOutsideRef ? children() : [];
119
110
  };
120
111
  $: repeatItemData = () => {
@@ -151,35 +142,67 @@ $: repeatItemData = () => {
151
142
  }));
152
143
  return repeatArray;
153
144
  };
145
+ $: inheritedTextStyles = () => {
146
+ if (TARGET !== "reactNative") {
147
+ return {};
148
+ }
149
+ const styles = getReactNativeBlockStyles({
150
+ block: useBlock(),
151
+ context: context,
152
+ });
153
+ return extractTextStyles(styles);
154
+ };
155
+ $: childrenContext = () => {
156
+ return {
157
+ apiKey: context.apiKey,
158
+ state: context.state,
159
+ content: context.content,
160
+ context: context.context,
161
+ registeredComponents: context.registeredComponents,
162
+ inheritedStyles: inheritedTextStyles(),
163
+ };
164
+ };
165
+ $: renderComponentTag = () => {
166
+ if (TARGET === "reactNative") {
167
+ return RenderComponentWithContext;
168
+ }
169
+ else if (TARGET === "vue3") {
170
+ // vue3 expects a string for the component tag
171
+ return "RenderComponent";
172
+ }
173
+ else {
174
+ return RenderComponent;
175
+ }
176
+ };
154
177
  </script>
155
178
 
156
179
  {#if shouldWrap()}
157
- {#if !isEmptyHtmlElement(tagName())}
158
- <svelte:element this={tagName()} {...attributes()}>
159
- {#if repeatItemData()}
160
- {#each repeatItemData() as data, index (index)}
161
- <RenderRepeatedBlock
162
- repeatContext={data.context}
163
- block={data.block}
164
- />
165
- {/each}
166
- {/if}
180
+ {#if isEmptyHtmlElement(tagName())}
181
+ <svelte:element this={tagName()} {...attributes()} />
182
+ {/if}
167
183
 
168
- {#if !repeatItemData()}
169
- <RenderComponent {...renderComponentProps()} />
170
- {/if}
184
+ {#if !isEmptyHtmlElement(tagName()) && repeatItemData()}
185
+ {#each repeatItemData() as data, index (index)}
186
+ <RenderRepeatedBlock repeatContext={data.context} block={data.block} />
187
+ {/each}
188
+ {/if}
189
+
190
+ {#if !isEmptyHtmlElement(tagName()) && !repeatItemData()}
191
+ <svelte:element this={tagName()} {...attributes()}>
192
+ <svelte:component
193
+ this={renderComponentTag()}
194
+ {...renderComponentProps()}
195
+ />
171
196
 
172
197
  {#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
173
- <svelte:self block={child} {context} />
198
+ <svelte:self block={child} context={childrenContext()} />
174
199
  {/each}
175
200
 
176
201
  {#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
177
- <BlockStyles block={child} {context} />
202
+ <BlockStyles block={child} context={childrenContext()} />
178
203
  {/each}
179
204
  </svelte:element>
180
- {:else}
181
- <svelte:element this={tagName()} {...attributes()} />
182
205
  {/if}
183
206
  {:else}
184
- <RenderComponent {...renderComponentProps()} {context} />
207
+ <svelte:component this={renderComponentTag()} {...renderComponentProps()} />
185
208
  {/if}
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { BuilderContextInterface } from "../../context/types.js";
3
+ import type { BuilderBlock } from "../../types/builder-block.js";
2
4
  export declare type RenderBlockProps = {
3
5
  block: BuilderBlock;
4
6
  context: BuilderContextInterface;
5
7
  };
6
- import { BuilderContextInterface } from "../../context/types.js";
7
- import { BuilderBlock } from "../../types/builder-block.js";
8
8
  declare const __propDef: {
9
9
  props: {
10
10
  block: RenderBlockProps["block"];
@@ -0,0 +1,32 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import { setContext } from "svelte";
4
+ import BuilderContext from "../../context/builder.context.js";
5
+ import RenderComponent from "./render-component.svelte";
6
+ export let componentRef;
7
+ export let componentOptions;
8
+ export let blockChildren;
9
+ export let context;
10
+ setContext(BuilderContext.key, {
11
+ get content() {
12
+ return context.content;
13
+ },
14
+ get state() {
15
+ return context.state;
16
+ },
17
+ get context() {
18
+ return context.context;
19
+ },
20
+ get apiKey() {
21
+ return context.apiKey;
22
+ },
23
+ get registeredComponents() {
24
+ return context.registeredComponents;
25
+ },
26
+ get inheritedStyles() {
27
+ return context.inheritedStyles;
28
+ },
29
+ });
30
+ </script>
31
+
32
+ <RenderComponent {componentRef} {componentOptions} {blockChildren} {context} />
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ componentRef: RenderComponentProps;
5
+ componentOptions: RenderComponentProps;
6
+ blockChildren: RenderComponentProps;
7
+ context: RenderComponentProps;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {};
13
+ };
14
+ export declare type RenderComponentWithContextProps = typeof __propDef.props;
15
+ export declare type RenderComponentWithContextEvents = typeof __propDef.events;
16
+ export declare type RenderComponentWithContextSlots = typeof __propDef.slots;
17
+ export default class RenderComponentWithContext extends SvelteComponentTyped<RenderComponentWithContextProps, RenderComponentWithContextEvents, RenderComponentWithContextSlots> {
18
+ }
19
+ export {};
@@ -1,9 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import "../../types/builder-block.js";
4
- import BlockStyles from "./block-styles.svelte";
3
+ <script>import BlockStyles from "./block-styles.svelte";
5
4
  import RenderBlock from "./render-block.svelte";
6
- import "../../context/types.js";
7
5
  import { markPropsMutable } from "../../functions/mark-mutable.js";
8
6
  export let componentRef;
9
7
  export let componentOptions;
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { BuilderBlock } from "../../types/builder-block.js";
3
+ import type { BuilderContextInterface } from "../../context/types.js";
2
4
  export interface RenderComponentProps {
3
5
  componentRef: any;
4
6
  componentOptions: any;
5
7
  blockChildren: BuilderBlock[];
6
8
  context: BuilderContextInterface;
7
9
  }
8
- import { BuilderBlock } from "../../types/builder-block.js";
9
- import { BuilderContextInterface } from "../../context/types.js";
10
10
  declare const __propDef: {
11
11
  props: {
12
12
  componentRef: RenderComponentProps["componentRef"];
@@ -30,6 +30,9 @@ setContext(BuilderContext.key, {
30
30
  get registeredComponents() {
31
31
  return repeatContext.registeredComponents;
32
32
  },
33
+ get inheritedStyles() {
34
+ return repeatContext.inheritedStyles;
35
+ },
33
36
  });
34
37
  </script>
35
38
 
@@ -1,5 +1,5 @@
1
- import { BuilderContextInterface } from '../../context/types.js';
2
- import { BuilderBlock } from '../../types/builder-block.js';
1
+ import type { BuilderContextInterface } from '../../context/types.js';
2
+ import type { BuilderBlock } from '../../types/builder-block.js';
3
3
  export interface RepeatData {
4
4
  block: BuilderBlock;
5
5
  context: BuilderContextInterface;
@@ -1,2 +1 @@
1
- import '../../context/types.js';
2
- import '../../types/builder-block.js';
1
+ export {};
@@ -3,12 +3,22 @@
3
3
  <script>import { getContext } from "svelte";
4
4
  import BuilderContext from "../context/builder.context.js";
5
5
  import { isEditing } from "../functions/is-editing.js";
6
- import "../types/builder-block.js";
7
6
  import BlockStyles from "./render-block/block-styles.svelte";
8
7
  import RenderBlock from "./render-block/render-block.svelte";
9
8
  export let blocks;
10
9
  export let parent;
11
10
  export let path;
11
+ export let styleProp;
12
+ function mitosis_styling(node, vars) {
13
+ Object.entries(vars || {}).forEach(([p, v]) => {
14
+ if (p.startsWith("--")) {
15
+ node.style.setProperty(p, v);
16
+ }
17
+ else {
18
+ node.style[p] = v;
19
+ }
20
+ });
21
+ }
12
22
  let builderContext = getContext(BuilderContext.key);
13
23
  function onClick() {
14
24
  if (isEditing() && !blocks?.length) {
@@ -38,6 +48,7 @@ $: className = () => {
38
48
  </script>
39
49
 
40
50
  <div
51
+ use:mitosis_styling={styleProp}
41
52
  class={className() + " div"}
42
53
  builder-path={path}
43
54
  builder-parent-id={parent}
@@ -1,15 +1,17 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { BuilderBlock } from "../types/builder-block.js";
2
3
  export declare type RenderBlockProps = {
3
4
  blocks?: BuilderBlock[];
4
5
  parent?: string;
5
6
  path?: string;
7
+ styleProp?: Record<string, any>;
6
8
  };
7
- import { BuilderBlock } from "../types/builder-block.js";
8
9
  declare const __propDef: {
9
10
  props: {
10
11
  blocks: RenderBlockProps["blocks"];
11
12
  parent: RenderBlockProps["parent"];
12
13
  path: RenderBlockProps["path"];
14
+ styleProp: RenderBlockProps["styleProp"];
13
15
  };
14
16
  events: {
15
17
  [evt: string]: CustomEvent<any>;
@@ -25,7 +25,8 @@ function getCssFromFont(font) {
25
25
  const isNumber = String(Number(weight)) === weight;
26
26
  if (!isNumber) {
27
27
  continue;
28
- } // TODO: maybe limit number loaded
28
+ }
29
+ // TODO: maybe limit number loaded
29
30
  const weightUrl = font.files[weight];
30
31
  if (weightUrl && weightUrl !== url) {
31
32
  str += `
@@ -4,7 +4,6 @@
4
4
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
5
5
  import { TARGET } from "../../constants/target.js";
6
6
  import BuilderContext from "../../context/builder.context.js";
7
- import "../../context/types.js";
8
7
  import { evaluate } from "../../functions/evaluate.js";
9
8
  import { getContent } from "../../functions/get-content/index.js";
10
9
  import { getFetch } from "../../functions/get-fetch.js";
@@ -13,7 +12,6 @@ import { isEditing } from "../../functions/is-editing.js";
13
12
  import { isPreviewing } from "../../functions/is-previewing.js";
14
13
  import { components, createRegisterComponentMessage, } from "../../functions/register-component.js";
15
14
  import { track } from "../../functions/track.js";
16
- import "../../types/builder-content.js";
17
15
  import RenderBlocks from "../render-blocks.svelte";
18
16
  import RenderContentStyles from "./components/render-styles.svelte";
19
17
  import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
@@ -99,7 +97,10 @@ function handleRequest({ url, key }) {
99
97
  .then((fetch) => fetch(url))
100
98
  .then((response) => response.json())
101
99
  .then((json) => {
102
- const newOverrideState = { ...overrideState, [key]: json };
100
+ const newOverrideState = {
101
+ ...overrideState,
102
+ [key]: json,
103
+ };
103
104
  overrideState = newOverrideState;
104
105
  })
105
106
  .catch((err) => {
@@ -137,7 +138,11 @@ $: useContent = () => {
137
138
  const mergedContent = {
138
139
  ...content,
139
140
  ...overrideContent,
140
- data: { ...content?.data, ...data, ...overrideContent?.data },
141
+ data: {
142
+ ...content?.data,
143
+ ...data,
144
+ ...overrideContent?.data,
145
+ },
141
146
  };
142
147
  return mergedContent;
143
148
  };
@@ -145,7 +150,11 @@ $: canTrackToUse = () => {
145
150
  return canTrack || true;
146
151
  };
147
152
  $: contentState = () => {
148
- return { ...content?.data?.state, ...data, ...overrideState };
153
+ return {
154
+ ...content?.data?.state,
155
+ ...data,
156
+ ...overrideState,
157
+ };
149
158
  };
150
159
  $: contextContext = () => {
151
160
  return context || {};
@@ -153,6 +162,7 @@ $: contextContext = () => {
153
162
  $: allRegisteredComponents = () => {
154
163
  const allComponentsArray = [
155
164
  ...getDefaultRegisteredComponents(),
165
+ // While this `components` object is deprecated, we must maintain support for it.
156
166
  // Since users are able to override our default components, we need to make sure that we do not break such
157
167
  // existing usage.
158
168
  // This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
@@ -160,7 +170,10 @@ $: allRegisteredComponents = () => {
160
170
  ...components,
161
171
  ...(customComponents || []),
162
172
  ];
163
- const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc, [curr.name]: curr }), {});
173
+ const allComponents = allComponentsArray.reduce((acc, curr) => ({
174
+ ...acc,
175
+ [curr.name]: curr,
176
+ }), {});
164
177
  return allComponents;
165
178
  };
166
179
  $: httpReqsData = () => {
@@ -179,7 +192,8 @@ let overrideState = {};
179
192
  onMount(() => {
180
193
  if (isBrowser()) {
181
194
  if (isEditing()) {
182
- forceReRenderCount = forceReRenderCount + 1; // QWIK-REPLACE: _useMutableProps
195
+ forceReRenderCount = forceReRenderCount + 1;
196
+ // QWIK-REPLACE: _useMutableProps
183
197
  registerInsertMenu();
184
198
  setupBrowserForEditing();
185
199
  Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
@@ -196,7 +210,8 @@ onMount(() => {
196
210
  contentId: useContent?.()?.id,
197
211
  orgId: apiKey,
198
212
  });
199
- } // override normal content in preview mode
213
+ }
214
+ // override normal content in preview mode
200
215
  if (isPreviewing()) {
201
216
  const searchParams = new URL(location.href).searchParams;
202
217
  if (model && searchParams.get("builder.preview") === model) {
@@ -245,6 +260,7 @@ onDestroy(() => {
245
260
  onClick(event);
246
261
  }}
247
262
  builder-content-id={useContent?.()?.id}
263
+ builder-model={model}
248
264
  >
249
265
  {#if shouldRenderContentStyles()}
250
266
  <RenderContentStyles
@@ -1,4 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { BuilderRenderContext, RegisteredComponent } from "../../context/types.js";
3
+ import type { BuilderContent } from "../../types/builder-content.js";
2
4
  import type { Nullable } from "../../types/typescript.js";
3
5
  export declare type RenderContentProps = {
4
6
  content?: Nullable<BuilderContent>;
@@ -11,8 +13,6 @@ export declare type RenderContentProps = {
11
13
  customComponents?: RegisteredComponent[];
12
14
  canTrack?: boolean;
13
15
  };
14
- import { BuilderRenderContext, RegisteredComponent } from "../../context/types.js";
15
- import { BuilderContent } from "../../types/builder-content.js";
16
16
  declare const __propDef: {
17
17
  props: {
18
18
  content: RenderContentProps["content"];
@@ -18,6 +18,8 @@ import { componentInfo as embedComponentInfo } from '../blocks/embed/component-i
18
18
  import { default as embed } from '../blocks/embed/embed.svelte';
19
19
  import { default as Img } from '../blocks/img/img.svelte';
20
20
  import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.js';
21
+ import { default as customCode } from '../blocks/custom-code/custom-code.svelte';
22
+ import { componentInfo as customCodeInfo } from '../blocks/custom-code/component-info.js';
21
23
  /**
22
24
  * Returns a list of all registered components.
23
25
  * NOTE: This needs to be a function to work around ESM circular dependencies.
@@ -33,4 +35,5 @@ export const getDefaultRegisteredComponents = () => [
33
35
  { component: Section, ...sectionComponentInfo },
34
36
  { component: Fragment, ...fragmentComponentInfo },
35
37
  { component: embed, ...embedComponentInfo },
38
+ { component: customCode, ...customCodeInfo },
36
39
  ];
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  state: {};
6
6
  apiKey: null;
7
7
  registeredComponents: {};
8
+ inheritedStyles: {};
8
9
  };
9
10
  key: symbol;
10
11
  };
@@ -6,6 +6,7 @@ export default {
6
6
  state: {},
7
7
  apiKey: null,
8
8
  registeredComponents: {},
9
+ inheritedStyles: {},
9
10
  },
10
11
  key,
11
12
  };
@@ -1,6 +1,6 @@
1
- import { BuilderContent } from '../types/builder-content.js';
2
- import { ComponentInfo } from '../types/components.js';
3
- import { Dictionary, Nullable } from '../types/typescript.js';
1
+ import type { BuilderContent } from '../types/builder-content.js';
2
+ import type { ComponentInfo } from '../types/components.js';
3
+ import type { Dictionary, Nullable } from '../types/typescript.js';
4
4
  export declare type RegisteredComponent = ComponentInfo & {
5
5
  component: any;
6
6
  };
@@ -13,4 +13,5 @@ export interface BuilderContextInterface {
13
13
  state: BuilderRenderState;
14
14
  apiKey: string | null;
15
15
  registeredComponents: RegisteredComponents;
16
+ inheritedStyles: Record<string, unknown>;
16
17
  }
@@ -1,3 +1 @@
1
- import '../types/builder-content.js';
2
- import '../types/components.js';
3
- import '../types/typescript.js';
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Extract styles that apply to text from a style object.
3
+ */
4
+ export declare const extractTextStyles: (styles: Partial<CSSStyleDeclaration>) => Partial<CSSStyleDeclaration>;