@builder.io/sdk-svelte 0.0.7 → 0.0.8

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 (44) hide show
  1. package/package/--package.json +2 -3
  2. package/package/blocks/button/button.svelte +35 -3
  3. package/package/blocks/form/form.svelte +29 -1
  4. package/package/blocks/img/img.svelte +29 -1
  5. package/package/blocks/input/input.svelte +29 -1
  6. package/package/blocks/section/section.svelte +30 -2
  7. package/package/blocks/select/select.svelte +29 -1
  8. package/package/blocks/submit-button/submit-button.svelte +33 -2
  9. package/package/blocks/symbol/symbol.svelte +29 -1
  10. package/package/blocks/textarea/textarea.svelte +36 -2
  11. package/package/blocks/video/video.svelte +30 -2
  12. package/package/components/render-block/render-block.svelte +29 -8
  13. package/package/components/render-content/render-content.svelte +5 -2
  14. package/package/functions/evaluate.d.ts +2 -1
  15. package/package/functions/evaluate.js +8 -5
  16. package/package/functions/event-handler-name.js +1 -4
  17. package/package/functions/get-block-actions-handler.d.ts +5 -2
  18. package/package/functions/get-block-actions-handler.js +7 -8
  19. package/package/functions/get-block-actions.js +2 -2
  20. package/package/functions/get-builder-search-params/index.d.ts +1 -1
  21. package/package/functions/track.d.ts +6 -1
  22. package/package/functions/track.js +4 -0
  23. package/package.json +2 -2
  24. package/src/blocks/button/button.svelte +41 -2
  25. package/src/blocks/form/form.svelte +36 -1
  26. package/src/blocks/img/img.svelte +36 -1
  27. package/src/blocks/input/input.svelte +36 -1
  28. package/src/blocks/section/section.svelte +36 -1
  29. package/src/blocks/select/select.svelte +36 -1
  30. package/src/blocks/submit-button/submit-button.svelte +39 -1
  31. package/src/blocks/symbol/symbol.svelte +36 -1
  32. package/src/blocks/textarea/textarea.svelte +42 -1
  33. package/src/blocks/video/video.svelte +36 -1
  34. package/src/components/render-block/render-block.svelte +34 -8
  35. package/src/components/render-content/render-content.svelte +7 -2
  36. package/src/functions/evaluate.ts +11 -6
  37. package/src/functions/event-handler-name.ts +1 -6
  38. package/src/functions/get-block-actions-handler.ts +10 -9
  39. package/src/functions/get-block-actions.ts +2 -2
  40. package/src/functions/get-builder-search-params/index.ts +1 -1
  41. package/src/functions/track.ts +13 -1
  42. package/package/functions/mark-mutable.d.ts +0 -2
  43. package/package/functions/mark-mutable.js +0 -6
  44. package/src/functions/mark-mutable.ts +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "main": "./package/index.js",
17
17
  "module": "./package/index.js",
18
- "svelte": "./src/index.ts",
18
+ "svelte": "./package/index.js",
19
19
  "exports": {
20
20
  "./package.json": "./package.json",
21
21
  "./src": {
@@ -108,7 +108,6 @@
108
108
  "./functions/is-editing": "./functions/is-editing.js",
109
109
  "./functions/is-iframe": "./functions/is-iframe.js",
110
110
  "./functions/is-previewing": "./functions/is-previewing.js",
111
- "./functions/mark-mutable": "./functions/mark-mutable.js",
112
111
  "./functions/on-change.test": "./functions/on-change.test.js",
113
112
  "./functions/on-change": "./functions/on-change.js",
114
113
  "./functions/register-component": "./functions/register-component.js",
@@ -1,6 +1,33 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>export let attributes;
3
+ <script>const isEvent = (attr) => attr.startsWith("on:");
4
+ const isNonEvent = (attr) => !attr.startsWith("on:");
5
+ const filterAttrs = (attrs, filter) => {
6
+ const validAttr = {};
7
+ Object.keys(attrs).forEach((attr) => {
8
+ if (filter(attr)) {
9
+ validAttr[attr] = attrs[attr];
10
+ }
11
+ });
12
+ return validAttr;
13
+ };
14
+ const setAttrs = (node, attrs) => {
15
+ const attrKeys = Object.keys(attrs);
16
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
17
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
18
+ attrKeys.map(setup);
19
+ return {
20
+ update(attrs) {
21
+ const attrKeys = Object.keys(attrs);
22
+ attrKeys.map(teardown);
23
+ attrKeys.map(setup);
24
+ },
25
+ destroy() {
26
+ attrKeys.map(teardown);
27
+ },
28
+ };
29
+ };
30
+ export let attributes;
4
31
  export let text;
5
32
  export let link;
6
33
  export let openLinkInNewTab;
@@ -9,14 +36,19 @@ export let openLinkInNewTab;
9
36
  {#if link}
10
37
  <a
11
38
  role="button"
12
- {...attributes}
39
+ {...filterAttrs(attributes, isNonEvent)}
13
40
  href={link}
14
41
  target={openLinkInNewTab ? "_blank" : undefined}
42
+ use:setAttrs={filterAttrs(attributes, isEvent)}
15
43
  >
16
44
  {text}
17
45
  </a>
18
46
  {:else}
19
- <button class="button" {...attributes}>
47
+ <button
48
+ class="button"
49
+ {...filterAttrs(attributes, isNonEvent)}
50
+ use:setAttrs={filterAttrs(attributes, isEvent)}
51
+ >
20
52
  {text}
21
53
  </button>
22
54
  {/if}
@@ -6,6 +6,33 @@
6
6
  import RenderBlock from "../../components/render-block/render-block.svelte";
7
7
  import BuilderBlocks from "../../components/render-blocks.svelte";
8
8
  import { isEditing } from "../../functions/is-editing.js";
9
+ const isEvent = (attr) => attr.startsWith("on:");
10
+ const isNonEvent = (attr) => !attr.startsWith("on:");
11
+ const filterAttrs = (attrs, filter) => {
12
+ const validAttr = {};
13
+ Object.keys(attrs).forEach((attr) => {
14
+ if (filter(attr)) {
15
+ validAttr[attr] = attrs[attr];
16
+ }
17
+ });
18
+ return validAttr;
19
+ };
20
+ const setAttrs = (node, attrs) => {
21
+ const attrKeys = Object.keys(attrs);
22
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
23
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
24
+ attrKeys.map(setup);
25
+ return {
26
+ update(attrs) {
27
+ const attrKeys = Object.keys(attrs);
28
+ attrKeys.map(teardown);
29
+ attrKeys.map(setup);
30
+ },
31
+ destroy() {
32
+ attrKeys.map(teardown);
33
+ },
34
+ };
35
+ };
9
36
  export let previewState;
10
37
  export let sendWithJs;
11
38
  export let sendSubmissionsTo;
@@ -225,7 +252,8 @@ let formErrorMessage = "";
225
252
  on:submit={(event) => {
226
253
  onSubmit(event);
227
254
  }}
228
- {...attributes}
255
+ {...filterAttrs(attributes, isNonEvent)}
256
+ use:setAttrs={filterAttrs(attributes, isEvent)}
229
257
  >
230
258
  {#if builderBlock && builderBlock.children}
231
259
  {#each builderBlock?.children as block}
@@ -1,6 +1,33 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { isEditing } from "../../functions/is-editing.js";
4
+ const isEvent = (attr) => attr.startsWith("on:");
5
+ const isNonEvent = (attr) => !attr.startsWith("on:");
6
+ const filterAttrs = (attrs, filter) => {
7
+ const validAttr = {};
8
+ Object.keys(attrs).forEach((attr) => {
9
+ if (filter(attr)) {
10
+ validAttr[attr] = attrs[attr];
11
+ }
12
+ });
13
+ return validAttr;
14
+ };
15
+ const setAttrs = (node, attrs) => {
16
+ const attrKeys = Object.keys(attrs);
17
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
18
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
19
+ attrKeys.map(setup);
20
+ return {
21
+ update(attrs) {
22
+ const attrKeys = Object.keys(attrs);
23
+ attrKeys.map(teardown);
24
+ attrKeys.map(setup);
25
+ },
26
+ destroy() {
27
+ attrKeys.map(teardown);
28
+ },
29
+ };
30
+ };
4
31
  export let backgroundSize;
5
32
  export let backgroundPosition;
6
33
  export let imgSrc;
@@ -27,5 +54,6 @@ function mitosis_styling(node, vars) {
27
54
  key={(isEditing() && imgSrc) || "default-key"}
28
55
  alt={altText}
29
56
  src={imgSrc || image}
30
- {...attributes}
57
+ {...filterAttrs(attributes, isNonEvent)}
58
+ use:setAttrs={filterAttrs(attributes, isEvent)}
31
59
  />
@@ -1,6 +1,33 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { isEditing } from "../../functions/is-editing.js";
4
+ const isEvent = (attr) => attr.startsWith("on:");
5
+ const isNonEvent = (attr) => !attr.startsWith("on:");
6
+ const filterAttrs = (attrs, filter) => {
7
+ const validAttr = {};
8
+ Object.keys(attrs).forEach((attr) => {
9
+ if (filter(attr)) {
10
+ validAttr[attr] = attrs[attr];
11
+ }
12
+ });
13
+ return validAttr;
14
+ };
15
+ const setAttrs = (node, attrs) => {
16
+ const attrKeys = Object.keys(attrs);
17
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
18
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
19
+ attrKeys.map(setup);
20
+ return {
21
+ update(attrs) {
22
+ const attrKeys = Object.keys(attrs);
23
+ attrKeys.map(teardown);
24
+ attrKeys.map(setup);
25
+ },
26
+ destroy() {
27
+ attrKeys.map(teardown);
28
+ },
29
+ };
30
+ };
4
31
  export let attributes;
5
32
  export let defaultValue;
6
33
  export let placeholder;
@@ -11,7 +38,7 @@ export let required;
11
38
  </script>
12
39
 
13
40
  <input
14
- {...attributes}
41
+ {...filterAttrs(attributes, isNonEvent)}
15
42
  key={isEditing() && defaultValue ? defaultValue : "default-key"}
16
43
  {placeholder}
17
44
  {type}
@@ -19,4 +46,5 @@ export let required;
19
46
  {value}
20
47
  {defaultValue}
21
48
  {required}
49
+ use:setAttrs={filterAttrs(attributes, isEvent)}
22
50
  />
@@ -1,6 +1,33 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>export let attributes;
3
+ <script>const isEvent = (attr) => attr.startsWith("on:");
4
+ const isNonEvent = (attr) => !attr.startsWith("on:");
5
+ const filterAttrs = (attrs, filter) => {
6
+ const validAttr = {};
7
+ Object.keys(attrs).forEach((attr) => {
8
+ if (filter(attr)) {
9
+ validAttr[attr] = attrs[attr];
10
+ }
11
+ });
12
+ return validAttr;
13
+ };
14
+ const setAttrs = (node, attrs) => {
15
+ const attrKeys = Object.keys(attrs);
16
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
17
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
18
+ attrKeys.map(setup);
19
+ return {
20
+ update(attrs) {
21
+ const attrKeys = Object.keys(attrs);
22
+ attrKeys.map(teardown);
23
+ attrKeys.map(setup);
24
+ },
25
+ destroy() {
26
+ attrKeys.map(teardown);
27
+ },
28
+ };
29
+ };
30
+ export let attributes;
4
31
  export let maxWidth;
5
32
  function mitosis_styling(node, vars) {
6
33
  Object.entries(vars || {}).forEach(([p, v]) => {
@@ -20,7 +47,8 @@ function mitosis_styling(node, vars) {
20
47
  maxWidth: maxWidth,
21
48
  }
22
49
  : undefined}
23
- {...attributes}
50
+ {...filterAttrs(attributes, isNonEvent)}
51
+ use:setAttrs={filterAttrs(attributes, isEvent)}
24
52
  >
25
53
  <slot />
26
54
  </section>
@@ -1,6 +1,33 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import { isEditing } from "../../functions/is-editing.js";
4
+ const isEvent = (attr) => attr.startsWith("on:");
5
+ const isNonEvent = (attr) => !attr.startsWith("on:");
6
+ const filterAttrs = (attrs, filter) => {
7
+ const validAttr = {};
8
+ Object.keys(attrs).forEach((attr) => {
9
+ if (filter(attr)) {
10
+ validAttr[attr] = attrs[attr];
11
+ }
12
+ });
13
+ return validAttr;
14
+ };
15
+ const setAttrs = (node, attrs) => {
16
+ const attrKeys = Object.keys(attrs);
17
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
18
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
19
+ attrKeys.map(setup);
20
+ return {
21
+ update(attrs) {
22
+ const attrKeys = Object.keys(attrs);
23
+ attrKeys.map(teardown);
24
+ attrKeys.map(setup);
25
+ },
26
+ destroy() {
27
+ attrKeys.map(teardown);
28
+ },
29
+ };
30
+ };
4
31
  export let attributes;
5
32
  export let value;
6
33
  export let defaultValue;
@@ -9,11 +36,12 @@ export let options;
9
36
  </script>
10
37
 
11
38
  <select
12
- {...attributes}
39
+ {...filterAttrs(attributes, isNonEvent)}
13
40
  {value}
14
41
  key={isEditing() && defaultValue ? defaultValue : "default-key"}
15
42
  {defaultValue}
16
43
  {name}
44
+ use:setAttrs={filterAttrs(attributes, isEvent)}
17
45
  >
18
46
  {#each options as option}
19
47
  <option value={option.value}>{option.name || option.value}</option>
@@ -1,9 +1,40 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>export let attributes;
3
+ <script>const isEvent = (attr) => attr.startsWith("on:");
4
+ const isNonEvent = (attr) => !attr.startsWith("on:");
5
+ const filterAttrs = (attrs, filter) => {
6
+ const validAttr = {};
7
+ Object.keys(attrs).forEach((attr) => {
8
+ if (filter(attr)) {
9
+ validAttr[attr] = attrs[attr];
10
+ }
11
+ });
12
+ return validAttr;
13
+ };
14
+ const setAttrs = (node, attrs) => {
15
+ const attrKeys = Object.keys(attrs);
16
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
17
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
18
+ attrKeys.map(setup);
19
+ return {
20
+ update(attrs) {
21
+ const attrKeys = Object.keys(attrs);
22
+ attrKeys.map(teardown);
23
+ attrKeys.map(setup);
24
+ },
25
+ destroy() {
26
+ attrKeys.map(teardown);
27
+ },
28
+ };
29
+ };
30
+ export let attributes;
4
31
  export let text;
5
32
  </script>
6
33
 
7
- <button type="submit" {...attributes}>
34
+ <button
35
+ type="submit"
36
+ {...filterAttrs(attributes, isNonEvent)}
37
+ use:setAttrs={filterAttrs(attributes, isEvent)}
38
+ >
8
39
  {text}
9
40
  </button>
@@ -4,6 +4,33 @@
4
4
  import RenderContent from "../../components/render-content/render-content.svelte";
5
5
  import BuilderContext from "../../context/builder.context.js";
6
6
  import { getContent } from "../../functions/get-content/index.js";
7
+ const isEvent = (attr) => attr.startsWith("on:");
8
+ const isNonEvent = (attr) => !attr.startsWith("on:");
9
+ const filterAttrs = (attrs, filter) => {
10
+ const validAttr = {};
11
+ Object.keys(attrs).forEach((attr) => {
12
+ if (filter(attr)) {
13
+ validAttr[attr] = attrs[attr];
14
+ }
15
+ });
16
+ return validAttr;
17
+ };
18
+ const setAttrs = (node, attrs) => {
19
+ const attrKeys = Object.keys(attrs);
20
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
21
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
22
+ attrKeys.map(setup);
23
+ return {
24
+ update(attrs) {
25
+ const attrKeys = Object.keys(attrs);
26
+ attrKeys.map(teardown);
27
+ attrKeys.map(setup);
28
+ },
29
+ destroy() {
30
+ attrKeys.map(teardown);
31
+ },
32
+ };
33
+ };
7
34
  export let symbol;
8
35
  export let attributes;
9
36
  let builderContext = getContext(BuilderContext.key);
@@ -42,11 +69,12 @@ $: onUpdateFn_0(...[symbol, fetchedContent]);
42
69
  </script>
43
70
 
44
71
  <div
45
- {...attributes}
72
+ {...filterAttrs(attributes, isNonEvent)}
46
73
  dataSet={{
47
74
  class: className,
48
75
  }}
49
76
  class={className}
77
+ use:setAttrs={filterAttrs(attributes, isEvent)}
50
78
  >
51
79
  <RenderContent
52
80
  apiKey={builderContext.apiKey}
@@ -1,10 +1,44 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>export let attributes;
3
+ <script>const isEvent = (attr) => attr.startsWith("on:");
4
+ const isNonEvent = (attr) => !attr.startsWith("on:");
5
+ const filterAttrs = (attrs, filter) => {
6
+ const validAttr = {};
7
+ Object.keys(attrs).forEach((attr) => {
8
+ if (filter(attr)) {
9
+ validAttr[attr] = attrs[attr];
10
+ }
11
+ });
12
+ return validAttr;
13
+ };
14
+ const setAttrs = (node, attrs) => {
15
+ const attrKeys = Object.keys(attrs);
16
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
17
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
18
+ attrKeys.map(setup);
19
+ return {
20
+ update(attrs) {
21
+ const attrKeys = Object.keys(attrs);
22
+ attrKeys.map(teardown);
23
+ attrKeys.map(setup);
24
+ },
25
+ destroy() {
26
+ attrKeys.map(teardown);
27
+ },
28
+ };
29
+ };
30
+ export let attributes;
4
31
  export let placeholder;
5
32
  export let name;
6
33
  export let value;
7
34
  export let defaultValue;
8
35
  </script>
9
36
 
10
- <textarea {...attributes} {placeholder} {name} {value} {defaultValue} />
37
+ <textarea
38
+ {...filterAttrs(attributes, isNonEvent)}
39
+ {placeholder}
40
+ {name}
41
+ {value}
42
+ {defaultValue}
43
+ use:setAttrs={filterAttrs(attributes, isEvent)}
44
+ />
@@ -1,6 +1,33 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>export let autoPlay;
3
+ <script>const isEvent = (attr) => attr.startsWith("on:");
4
+ const isNonEvent = (attr) => !attr.startsWith("on:");
5
+ const filterAttrs = (attrs, filter) => {
6
+ const validAttr = {};
7
+ Object.keys(attrs).forEach((attr) => {
8
+ if (filter(attr)) {
9
+ validAttr[attr] = attrs[attr];
10
+ }
11
+ });
12
+ return validAttr;
13
+ };
14
+ const setAttrs = (node, attrs) => {
15
+ const attrKeys = Object.keys(attrs);
16
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
17
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
18
+ attrKeys.map(setup);
19
+ return {
20
+ update(attrs) {
21
+ const attrKeys = Object.keys(attrs);
22
+ attrKeys.map(teardown);
23
+ attrKeys.map(setup);
24
+ },
25
+ destroy() {
26
+ attrKeys.map(teardown);
27
+ },
28
+ };
29
+ };
30
+ export let autoPlay;
4
31
  export let muted;
5
32
  export let controls;
6
33
  export let loop;
@@ -68,7 +95,8 @@ $: spreadProps = () => {
68
95
  // not have the video overflow
69
96
  borderRadius: 1,
70
97
  }}
71
- {...spreadProps()}
98
+ {...filterAttrs(spreadProps(), isNonEvent)}
72
99
  src={video || "no-src"}
73
100
  poster={posterImage}
101
+ use:setAttrs={filterAttrs(spreadProps(), isEvent)}
74
102
  />
@@ -14,6 +14,22 @@ import { extractTextStyles } from "../../functions/extract-text-styles.js";
14
14
  import RenderComponentWithContext from "./render-component-with-context.svelte";
15
15
  import RenderComponent from "./render-component.svelte";
16
16
  import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
17
+ const setAttrs = (node, attrs) => {
18
+ const attrKeys = Object.keys(attrs);
19
+ const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
20
+ const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
21
+ attrKeys.map(setup);
22
+ return {
23
+ update(attrs) {
24
+ const attrKeys = Object.keys(attrs);
25
+ attrKeys.map(teardown);
26
+ attrKeys.map(setup);
27
+ },
28
+ destroy() {
29
+ attrKeys.map(teardown);
30
+ },
31
+ };
32
+ };
17
33
  export let block;
18
34
  export let context;
19
35
  $: component = () => {
@@ -51,14 +67,16 @@ $: useBlock = () => {
51
67
  shouldEvaluateBindings: true,
52
68
  });
53
69
  };
70
+ $: actions = () => {
71
+ return getBlockActions({
72
+ block: useBlock(),
73
+ state: context.state,
74
+ context: context.context,
75
+ });
76
+ };
54
77
  $: attributes = () => {
55
78
  return {
56
79
  ...getBlockProperties(useBlock()),
57
- ...getBlockActions({
58
- block: useBlock(),
59
- state: context.state,
60
- context: context.context,
61
- }),
62
80
  ...(TARGET === "reactNative"
63
81
  ? {
64
82
  style: getReactNativeBlockStyles({
@@ -85,7 +103,10 @@ $: renderComponentProps = () => {
85
103
  ...(shouldWrap()
86
104
  ? {}
87
105
  : {
88
- attributes: attributes(),
106
+ attributes: {
107
+ ...attributes(),
108
+ ...actions(),
109
+ },
89
110
  }),
90
111
  },
91
112
  context: childrenContext(),
@@ -178,7 +199,7 @@ $: renderComponentTag = () => {
178
199
 
179
200
  {#if shouldWrap()}
180
201
  {#if isEmptyHtmlElement(tag())}
181
- <svelte:element this={tag()} {...attributes()} />
202
+ <svelte:element this={tag()} {...attributes()} use:setAttrs={actions()} />
182
203
  {/if}
183
204
 
184
205
  {#if !isEmptyHtmlElement(tag()) && repeatItemData()}
@@ -188,7 +209,7 @@ $: renderComponentTag = () => {
188
209
  {/if}
189
210
 
190
211
  {#if !isEmptyHtmlElement(tag()) && !repeatItemData()}
191
- <svelte:element this={tag()} {...attributes()}>
212
+ <svelte:element this={tag()} {...attributes()} use:setAttrs={actions()}>
192
213
  <svelte:component
193
214
  this={renderComponentTag()}
194
215
  {...renderComponentProps()}
@@ -3,7 +3,6 @@
3
3
  <script>import { onDestroy, onMount, setContext, } from "svelte";
4
4
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
5
5
  import { TARGET } from "../../constants/target.js";
6
- import BuilderContext from "../../context/builder.context.js";
7
6
  import { evaluate } from "../../functions/evaluate.js";
8
7
  import { getContent } from "../../functions/get-content/index.js";
9
8
  import { getFetch } from "../../functions/get-fetch.js";
@@ -14,6 +13,7 @@ import { components, createRegisterComponentMessage, } from "../../functions/reg
14
13
  import { _track } from "../../functions/track.js";
15
14
  import RenderBlocks from "../render-blocks.svelte";
16
15
  import RenderContentStyles from "./components/render-styles.svelte";
16
+ import BuilderContext from "../../context/builder.context.js";
17
17
  import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
18
18
  export let content;
19
19
  export let data;
@@ -192,6 +192,9 @@ let overrideContent = null;
192
192
  let update = 0;
193
193
  let overrideState = {};
194
194
  onMount(() => {
195
+ if (!apiKey) {
196
+ console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
197
+ }
195
198
  if (isBrowser()) {
196
199
  if (isEditing()) {
197
200
  forceReRenderCount = forceReRenderCount + 1;
@@ -240,7 +243,7 @@ onMount(() => {
240
243
  function onUpdateFn_0() {
241
244
  evaluateJsCode();
242
245
  }
243
- $: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
246
+ $: onUpdateFn_0(...[useContent?.()?.data?.jsCode, contentState()]);
244
247
  function onUpdateFn_1() {
245
248
  runHttpRequests();
246
249
  }
@@ -1,5 +1,6 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
- export declare function evaluate({ code, context, state, event, }: {
2
+ export declare function evaluate({ code, context, state, event, isExpression, }: {
3
3
  code: string;
4
4
  event?: Event;
5
+ isExpression?: boolean;
5
6
  } & Pick<BuilderContextInterface, 'state' | 'context'>): any;
@@ -1,6 +1,6 @@
1
1
  import { isBrowser } from './is-browser.js';
2
2
  import { isEditing } from './is-editing.js';
3
- export function evaluate({ code, context, state, event, }) {
3
+ export function evaluate({ code, context, state, event, isExpression = true, }) {
4
4
  if (code === '') {
5
5
  console.warn('Skipping evaluation of empty code block.');
6
6
  return;
@@ -12,14 +12,17 @@ export function evaluate({ code, context, state, event, }) {
12
12
  };
13
13
  // Be able to handle simple expressions like "state.foo" or "1 + 1"
14
14
  // as well as full blocks like "var foo = "bar"; return foo"
15
- const useReturn = !(code.includes(';') ||
16
- code.includes(' return ') ||
17
- code.trim().startsWith('return '));
15
+ const useReturn =
16
+ // we disable this for cases where we definitely don't want a return
17
+ isExpression &&
18
+ !(code.includes(';') ||
19
+ code.includes(' return ') ||
20
+ code.trim().startsWith('return '));
18
21
  const useCode = useReturn ? `return (${code});` : code;
19
22
  try {
20
23
  return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, state, context, event);
21
24
  }
22
25
  catch (e) {
23
- console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e.message || e);
26
+ console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
24
27
  }
25
28
  }
@@ -1,4 +1 @@
1
- function capitalizeFirstLetter(string) {
2
- return string.charAt(0).toUpperCase() + string.slice(1);
3
- }
4
- export const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
1
+ export const getEventHandlerName = (key) => `on:${key.toLowerCase()}`;
@@ -1,5 +1,8 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
- export declare function crateEventHandler(value: string, options: {
3
+ declare type Options = {
4
4
  block: BuilderBlock;
5
- } & Pick<BuilderContextInterface, 'state' | 'context'>): (event: Event) => any;
5
+ } & Pick<BuilderContextInterface, 'state' | 'context'>;
6
+ declare type EventHandler = (event: Event) => any;
7
+ export declare const createEventHandler: (value: string, options: Options) => EventHandler;
8
+ export {};
@@ -1,9 +1,8 @@
1
1
  import { evaluate } from './evaluate.js';
2
- export function crateEventHandler(value, options) {
3
- return (event) => evaluate({
4
- code: value,
5
- context: options.context,
6
- state: options.state,
7
- event,
8
- });
9
- }
2
+ export const createEventHandler = (value, options) => (event) => evaluate({
3
+ code: value,
4
+ context: options.context,
5
+ state: options.state,
6
+ event,
7
+ isExpression: false,
8
+ });