@builder.io/sdk-svelte 0.0.1-3 → 0.0.1-32
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/README.md +19 -0
- package/package.json +8 -1
- package/src/blocks/button/button.svelte +35 -48
- package/src/blocks/columns/columns.svelte +137 -103
- package/src/blocks/columns/component-info.js +26 -1
- package/src/blocks/custom-code/custom-code.svelte +58 -53
- package/src/blocks/embed/component-info.js +21 -1
- package/src/blocks/embed/embed.svelte +45 -57
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.svelte +313 -296
- package/src/blocks/fragment/fragment.svelte +9 -25
- package/src/blocks/image/component-info.js +48 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.svelte +146 -117
- package/src/blocks/img/img.svelte +48 -36
- package/src/blocks/input/input.svelte +30 -31
- package/src/blocks/raw-text/raw-text.svelte +12 -26
- package/src/blocks/section/section.svelte +30 -36
- package/src/blocks/select/select.svelte +30 -37
- package/src/blocks/submit-button/submit-button.svelte +12 -30
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.svelte +88 -53
- package/src/blocks/text/text.svelte +8 -25
- package/src/blocks/textarea/textarea.svelte +16 -29
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.svelte +88 -41
- package/src/components/render-block/block-styles.svelte +58 -51
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.svelte +204 -160
- package/src/components/render-block/render-component.svelte +30 -0
- package/src/components/render-block/render-repeated-block.svelte +45 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.svelte +88 -80
- package/src/components/render-content/components/render-styles.svelte +59 -63
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.svelte +316 -207
- package/src/components/render-inlined-styles.svelte +26 -48
- package/src/constants/builder-registered-components.js +51 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +7 -1
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +7 -4
- package/src/functions/get-builder-search-params/index.js +12 -1
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/get-content/index.js +16 -58
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +19 -8
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/track.js +71 -2
- package/src/helpers/cookie.js +59 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +26 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/index-helpers/blocks-exports.js +10 -8
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/video/index.js +0 -7
- package/src/components/error-boundary.svelte +0 -26
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Builder.io Svelte SDK (BETA)
|
|
2
|
+
|
|
3
|
+
This is the Svelte SDK. It is currently in beta.
|
|
4
|
+
|
|
5
|
+
## Mitosis
|
|
6
|
+
|
|
7
|
+
This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
|
|
8
|
+
|
|
9
|
+
## Feature Support
|
|
10
|
+
|
|
11
|
+
To check the status of the SDK, look at [these tables](../../README.md#feature-implementation).
|
|
12
|
+
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm install @builder.io/sdk-svelte@dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Take a look at [our example repo](/examples/svelte/sveltekit) for how to use this SDK.
|
package/package.json
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.0.1-
|
|
4
|
+
"version": "0.0.1-32",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"src"
|
|
8
8
|
],
|
|
9
|
+
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/BuilderIO/builder.git",
|
|
13
|
+
"directory": "packages/sdks/output/svelte"
|
|
14
|
+
},
|
|
9
15
|
"main": "./src/index.js",
|
|
10
16
|
"module": "./src/index.js",
|
|
17
|
+
"svelte": "./src/index.js",
|
|
11
18
|
"exports": {
|
|
12
19
|
".": {
|
|
13
20
|
"import": "./src/index.js",
|
|
@@ -1,49 +1,36 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export let
|
|
14
|
-
export let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{#if link }
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<a {...attributes} role="button" href={link} target={openLinkInNewTab ? '_blank' : undefined} >
|
|
38
|
-
|
|
39
|
-
{text}
|
|
40
|
-
|
|
41
|
-
</a>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface ButtonProps {
|
|
3
|
+
attributes?: any;
|
|
4
|
+
text?: string;
|
|
5
|
+
link?: string;
|
|
6
|
+
openLinkInNewTab?: boolean;
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
export let attributes: ButtonProps["attributes"];
|
|
12
|
+
export let text: ButtonProps["text"];
|
|
13
|
+
export let link: ButtonProps["link"];
|
|
14
|
+
export let openLinkInNewTab: ButtonProps["openLinkInNewTab"];
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
{#if link}
|
|
18
|
+
<a
|
|
19
|
+
{...attributes}
|
|
20
|
+
role="button"
|
|
21
|
+
href={link}
|
|
22
|
+
target={openLinkInNewTab ? "_blank" : undefined}
|
|
23
|
+
>
|
|
24
|
+
{text}
|
|
25
|
+
</a>
|
|
46
26
|
{:else}
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
27
|
+
<button {...attributes} class="button">
|
|
28
|
+
{text}
|
|
29
|
+
</button>
|
|
30
|
+
{/if}
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.button {
|
|
34
|
+
all: unset;
|
|
35
|
+
}
|
|
36
|
+
</style>
|
|
@@ -1,103 +1,137 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
type Column = {
|
|
3
|
+
blocks: any; // TODO: Implement this when support for dynamic CSS lands
|
|
4
|
+
|
|
5
|
+
width?: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type StackColumnsAt = "tablet" | "mobile" | "never";
|
|
9
|
+
|
|
10
|
+
export interface ColumnProps {
|
|
11
|
+
columns?: Column[];
|
|
12
|
+
builderBlock: BuilderBlock; // TODO: Implement this when support for dynamic CSS lands
|
|
13
|
+
|
|
14
|
+
space?: number; // TODO: Implement this when support for dynamic CSS lands
|
|
15
|
+
|
|
16
|
+
stackColumnsAt?: StackColumnsAt; // TODO: Implement this when support for dynamic CSS lands
|
|
17
|
+
|
|
18
|
+
reverseColumnsWhenStacked?: boolean;
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
24
|
+
|
|
25
|
+
export let space: ColumnProps["space"];
|
|
26
|
+
export let columns: ColumnProps["columns"];
|
|
27
|
+
export let stackColumnsAt: ColumnProps["stackColumnsAt"];
|
|
28
|
+
export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
|
|
29
|
+
export let builderBlock: ColumnProps["builderBlock"];
|
|
30
|
+
|
|
31
|
+
function mitosis_styling(node, vars) {
|
|
32
|
+
Object.entries(vars).forEach(([p, v]) => {
|
|
33
|
+
node.style[p] = v;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const getGutterSize = function getGutterSize() {
|
|
38
|
+
return typeof space === "number" ? space || 0 : 20;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getColumns = function getColumns() {
|
|
42
|
+
return columns || [];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getWidth = function getWidth(index) {
|
|
46
|
+
const columns = getColumns();
|
|
47
|
+
return columns[index]?.width || 100 / columns.length;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getColumnCssWidth = function getColumnCssWidth(index) {
|
|
51
|
+
const columns = getColumns();
|
|
52
|
+
const gutterSize = getGutterSize();
|
|
53
|
+
const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
|
|
54
|
+
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const maybeApplyForTablet = function maybeApplyForTablet(prop) {
|
|
58
|
+
const _stackColumnsAt = stackColumnsAt || "tablet";
|
|
59
|
+
|
|
60
|
+
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
61
|
+
};
|
|
62
|
+
$: columnsCssVars = () => {
|
|
63
|
+
const flexDir =
|
|
64
|
+
stackColumnsAt === "never"
|
|
65
|
+
? "inherit"
|
|
66
|
+
: reverseColumnsWhenStacked
|
|
67
|
+
? "column-reverse"
|
|
68
|
+
: "column";
|
|
69
|
+
return {
|
|
70
|
+
"--flex-dir": flexDir,
|
|
71
|
+
"--flex-dir-tablet": maybeApplyForTablet(flexDir),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
$: columnCssVars = () => {
|
|
76
|
+
const width = "100%";
|
|
77
|
+
const marginLeft = "0";
|
|
78
|
+
return {
|
|
79
|
+
"--column-width": width,
|
|
80
|
+
"--column-margin-left": marginLeft,
|
|
81
|
+
"--column-width-tablet": maybeApplyForTablet(width),
|
|
82
|
+
"--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<div use:mitosis_styling={columnsCssVars()} class="builder-columns div">
|
|
88
|
+
{#each columns as column, index (index)}
|
|
89
|
+
<div
|
|
90
|
+
use:mitosis_styling={{
|
|
91
|
+
width: getColumnCssWidth(index),
|
|
92
|
+
marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
|
|
93
|
+
...columnCssVars(),
|
|
94
|
+
}}
|
|
95
|
+
class="builder-column div-2"
|
|
96
|
+
>
|
|
97
|
+
<RenderBlocks
|
|
98
|
+
blocks={column.blocks}
|
|
99
|
+
path={`component.options.columns.${index}.blocks`}
|
|
100
|
+
parent={builderBlock.id}
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
{/each}
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<style>
|
|
107
|
+
.div {
|
|
108
|
+
display: flex;
|
|
109
|
+
align-items: stretch;
|
|
110
|
+
line-height: normal;
|
|
111
|
+
}
|
|
112
|
+
@media (max-width: 991px) {
|
|
113
|
+
.div {
|
|
114
|
+
flex-direction: var(--flex-dir-tablet);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
@media (max-width: 639px) {
|
|
118
|
+
.div {
|
|
119
|
+
flex-direction: var(--flex-dir);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
.div-2 {
|
|
123
|
+
flex-grow: 1;
|
|
124
|
+
}
|
|
125
|
+
@media (max-width: 991px) {
|
|
126
|
+
.div-2 {
|
|
127
|
+
width: var(--column-width-tablet) !important;
|
|
128
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
@media (max-width: 639px) {
|
|
132
|
+
.div-2 {
|
|
133
|
+
width: var(--column-width) !important;
|
|
134
|
+
margin-left: var(--column-margin-left) !important;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markSerializable } from "../util";
|
|
1
2
|
const componentInfo = {
|
|
2
3
|
name: "Columns",
|
|
3
4
|
builtIn: true,
|
|
@@ -186,7 +187,31 @@ const componentInfo = {
|
|
|
186
187
|
]
|
|
187
188
|
}
|
|
188
189
|
],
|
|
189
|
-
onChange:
|
|
190
|
+
onChange: markSerializable((options) => {
|
|
191
|
+
function clearWidths() {
|
|
192
|
+
columns.forEach((col) => {
|
|
193
|
+
col.delete("width");
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const columns = options.get("columns");
|
|
197
|
+
if (Array.isArray(columns)) {
|
|
198
|
+
const containsColumnWithWidth = !!columns.find((col) => col.get("width"));
|
|
199
|
+
if (containsColumnWithWidth) {
|
|
200
|
+
const containsColumnWithoutWidth = !!columns.find((col) => !col.get("width"));
|
|
201
|
+
if (containsColumnWithoutWidth) {
|
|
202
|
+
clearWidths();
|
|
203
|
+
} else {
|
|
204
|
+
const sumWidths = columns.reduce((memo, col) => {
|
|
205
|
+
return memo + col.get("width");
|
|
206
|
+
}, 0);
|
|
207
|
+
const widthsDontAddUp = sumWidths !== 100;
|
|
208
|
+
if (widthsDontAddUp) {
|
|
209
|
+
clearWidths();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
})
|
|
190
215
|
},
|
|
191
216
|
{
|
|
192
217
|
name: "space",
|
|
@@ -1,64 +1,69 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface CustomCodeProps {
|
|
3
|
+
code: string;
|
|
4
|
+
replaceNodes?: boolean;
|
|
5
|
+
}
|
|
6
|
+
</script>
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { onMount } from "svelte";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export let
|
|
14
|
-
export let code;
|
|
15
|
-
|
|
16
|
-
function findAndRunScripts() {
|
|
17
|
-
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
18
|
-
if (elem && typeof window !== 'undefined') {
|
|
19
|
-
/** @type {HTMLScriptElement[]} */
|
|
20
|
-
const scripts = elem.getElementsByTagName('script');
|
|
11
|
+
export let elem: CustomCodeProps["elem"];
|
|
12
|
+
export let replaceNodes: CustomCodeProps["replaceNodes"];
|
|
13
|
+
export let code: CustomCodeProps["code"];
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
16
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
17
|
+
if (elem && typeof window !== "undefined") {
|
|
18
|
+
const scripts = elem.getElementsByTagName("script");
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
20
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
21
|
+
const script = scripts[i];
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
if (script.src) {
|
|
24
|
+
if (scriptsInserted.includes(script.src)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
scriptsInserted.push(script.src);
|
|
29
|
+
const newScript = document.createElement("script");
|
|
30
|
+
newScript.async = true;
|
|
31
|
+
newScript.src = script.src;
|
|
32
|
+
document.head.appendChild(newScript);
|
|
33
|
+
} else if (
|
|
34
|
+
!script.type ||
|
|
35
|
+
[
|
|
36
|
+
"text/javascript",
|
|
37
|
+
"application/javascript",
|
|
38
|
+
"application/ecmascript",
|
|
39
|
+
].includes(script.type)
|
|
40
|
+
) {
|
|
41
|
+
if (scriptsRun.includes(script.innerText)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
try {
|
|
46
|
+
scriptsRun.push(script.innerText);
|
|
47
|
+
new Function(script.innerText)();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let scriptsInserted = [];
|
|
55
|
-
let scriptsRun = [];
|
|
56
|
-
|
|
57
|
-
onMount(() => { findAndRunScripts(); });
|
|
54
|
+
};
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
let scriptsInserted = [];
|
|
57
|
+
let scriptsRun = [];
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
onMount(() => {
|
|
60
|
+
findAndRunScripts();
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
<div
|
|
65
|
+
bind:this={elem}
|
|
66
|
+
class={"builder-custom-code" + (replaceNodes ? " replace-nodes" : "")}
|
|
67
|
+
>
|
|
68
|
+
{@html code}
|
|
69
|
+
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markSerializable } from "../util";
|
|
1
2
|
const componentInfo = {
|
|
2
3
|
name: "Embed",
|
|
3
4
|
static: true,
|
|
@@ -9,7 +10,26 @@ const componentInfo = {
|
|
|
9
10
|
required: true,
|
|
10
11
|
defaultValue: "",
|
|
11
12
|
helperText: "e.g. enter a youtube url, google map, etc",
|
|
12
|
-
onChange:
|
|
13
|
+
onChange: markSerializable((options) => {
|
|
14
|
+
const url = options.get("url");
|
|
15
|
+
if (url) {
|
|
16
|
+
options.set("content", "Loading...");
|
|
17
|
+
const apiKey = "ae0e60e78201a3f2b0de4b";
|
|
18
|
+
return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
|
|
19
|
+
if (options.get("url") === url) {
|
|
20
|
+
if (data.html) {
|
|
21
|
+
options.set("content", data.html);
|
|
22
|
+
} else {
|
|
23
|
+
options.set("content", "Invalid url, please try another");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}).catch((_err) => {
|
|
27
|
+
options.set("content", "There was an error embedding this URL, please try again or another URL");
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
options.delete("content");
|
|
31
|
+
}
|
|
32
|
+
})
|
|
13
33
|
},
|
|
14
34
|
{
|
|
15
35
|
name: "content",
|