@builder.io/sdk-svelte 0.0.7 → 0.0.9-0
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.
- package/package/--package.json +2 -3
- package/package/blocks/button/button.svelte +35 -3
- package/package/blocks/form/form.svelte +29 -1
- package/package/blocks/img/img.svelte +29 -1
- package/package/blocks/input/input.svelte +29 -1
- package/package/blocks/section/section.svelte +30 -2
- package/package/blocks/select/select.svelte +29 -1
- package/package/blocks/submit-button/submit-button.svelte +33 -2
- package/package/blocks/symbol/symbol.svelte +29 -1
- package/package/blocks/textarea/textarea.svelte +36 -2
- package/package/blocks/video/video.svelte +30 -2
- package/package/components/render-block/render-block.svelte +29 -8
- package/package/components/render-content/render-content.svelte +24 -3
- package/package/components/render-content/render-content.svelte.d.ts +4 -0
- package/package/functions/evaluate.d.ts +2 -1
- package/package/functions/evaluate.js +8 -5
- package/package/functions/event-handler-name.js +1 -4
- package/package/functions/get-block-actions-handler.d.ts +5 -2
- package/package/functions/get-block-actions-handler.js +7 -8
- package/package/functions/get-block-actions.js +2 -2
- package/package/functions/get-builder-search-params/index.d.ts +1 -1
- package/package/functions/track.d.ts +6 -1
- package/package/functions/track.js +4 -0
- package/package/scripts/init-editing.d.ts +4 -1
- package/package/scripts/init-editing.js +7 -1
- package/package.json +2 -2
- package/src/blocks/button/button.svelte +41 -2
- package/src/blocks/form/form.svelte +36 -1
- package/src/blocks/img/img.svelte +36 -1
- package/src/blocks/input/input.svelte +36 -1
- package/src/blocks/section/section.svelte +36 -1
- package/src/blocks/select/select.svelte +36 -1
- package/src/blocks/submit-button/submit-button.svelte +39 -1
- package/src/blocks/symbol/symbol.svelte +36 -1
- package/src/blocks/textarea/textarea.svelte +42 -1
- package/src/blocks/video/video.svelte +36 -1
- package/src/components/render-block/render-block.svelte +34 -8
- package/src/components/render-content/render-content.svelte +28 -3
- package/src/functions/evaluate.ts +11 -6
- package/src/functions/event-handler-name.ts +1 -6
- package/src/functions/get-block-actions-handler.ts +10 -9
- package/src/functions/get-block-actions.ts +2 -2
- package/src/functions/get-builder-search-params/index.ts +1 -1
- package/src/functions/track.ts +13 -1
- package/src/scripts/init-editing.ts +16 -1
- package/package/functions/mark-mutable.d.ts +0 -2
- package/package/functions/mark-mutable.js +0 -6
- package/src/functions/mark-mutable.ts +0 -7
package/package/--package.json
CHANGED
|
@@ -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.
|
|
4
|
+
"version": "0.0.8",
|
|
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": "./
|
|
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>
|
|
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
|
|
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>
|
|
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>
|
|
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
|
|
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>
|
|
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
|
|
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>
|
|
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:
|
|
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,14 +13,17 @@ 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;
|
|
20
20
|
export let canTrack;
|
|
21
|
+
export let locale;
|
|
21
22
|
export let context;
|
|
22
23
|
export let customComponents;
|
|
23
24
|
export let model;
|
|
24
25
|
export let apiKey;
|
|
26
|
+
export let includeRefs;
|
|
25
27
|
setContext(BuilderContext.key, {
|
|
26
28
|
get content() {
|
|
27
29
|
return useContent();
|
|
@@ -155,6 +157,11 @@ $: contentState = () => {
|
|
|
155
157
|
return {
|
|
156
158
|
...content?.data?.state,
|
|
157
159
|
...data,
|
|
160
|
+
...(locale
|
|
161
|
+
? {
|
|
162
|
+
locale: locale,
|
|
163
|
+
}
|
|
164
|
+
: {}),
|
|
158
165
|
...overrideState,
|
|
159
166
|
};
|
|
160
167
|
};
|
|
@@ -192,11 +199,25 @@ let overrideContent = null;
|
|
|
192
199
|
let update = 0;
|
|
193
200
|
let overrideState = {};
|
|
194
201
|
onMount(() => {
|
|
202
|
+
if (!apiKey) {
|
|
203
|
+
console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
204
|
+
}
|
|
195
205
|
if (isBrowser()) {
|
|
196
206
|
if (isEditing()) {
|
|
197
207
|
forceReRenderCount = forceReRenderCount + 1;
|
|
198
208
|
registerInsertMenu();
|
|
199
|
-
setupBrowserForEditing(
|
|
209
|
+
setupBrowserForEditing({
|
|
210
|
+
...(locale
|
|
211
|
+
? {
|
|
212
|
+
locale: locale,
|
|
213
|
+
}
|
|
214
|
+
: {}),
|
|
215
|
+
...(includeRefs
|
|
216
|
+
? {
|
|
217
|
+
includeRefs: includeRefs,
|
|
218
|
+
}
|
|
219
|
+
: {}),
|
|
220
|
+
});
|
|
200
221
|
Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
|
|
201
222
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
202
223
|
window.parent?.postMessage(message, "*");
|
|
@@ -240,7 +261,7 @@ onMount(() => {
|
|
|
240
261
|
function onUpdateFn_0() {
|
|
241
262
|
evaluateJsCode();
|
|
242
263
|
}
|
|
243
|
-
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
|
|
264
|
+
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode, contentState()]);
|
|
244
265
|
function onUpdateFn_1() {
|
|
245
266
|
runHttpRequests();
|
|
246
267
|
}
|
|
@@ -12,16 +12,20 @@ export declare type RenderContentProps = {
|
|
|
12
12
|
apiKey: string;
|
|
13
13
|
customComponents?: RegisteredComponent[];
|
|
14
14
|
canTrack?: boolean;
|
|
15
|
+
locale?: string;
|
|
16
|
+
includeRefs?: boolean;
|
|
15
17
|
};
|
|
16
18
|
declare const __propDef: {
|
|
17
19
|
props: {
|
|
18
20
|
content: RenderContentProps["content"];
|
|
19
21
|
data: RenderContentProps["data"];
|
|
20
22
|
canTrack: RenderContentProps["canTrack"];
|
|
23
|
+
locale: RenderContentProps["locale"];
|
|
21
24
|
context: RenderContentProps["context"];
|
|
22
25
|
customComponents: RenderContentProps["customComponents"];
|
|
23
26
|
model: RenderContentProps["model"];
|
|
24
27
|
apiKey: RenderContentProps["apiKey"];
|
|
28
|
+
includeRefs: RenderContentProps["includeRefs"];
|
|
25
29
|
};
|
|
26
30
|
events: {
|
|
27
31
|
[evt: string]: CustomEvent<any>;
|
|
@@ -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;
|