@builder.io/sdk-svelte 0.0.1-19 → 0.0.1-21
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.json +1 -1
- package/src/blocks/button/button.svelte +17 -48
- package/src/blocks/columns/columns.svelte +110 -102
- package/src/blocks/custom-code/custom-code.svelte +59 -61
- package/src/blocks/embed/embed.svelte +50 -57
- package/src/blocks/form/form.svelte +264 -294
- package/src/blocks/fragment/fragment.svelte +1 -26
- package/src/blocks/image/image.svelte +85 -117
- package/src/blocks/img/img.svelte +22 -32
- package/src/blocks/input/input.svelte +17 -30
- package/src/blocks/raw-text/raw-text.svelte +4 -26
- package/src/blocks/section/section.svelte +20 -36
- package/src/blocks/select/select.svelte +16 -36
- package/src/blocks/submit-button/submit-button.svelte +4 -30
- package/src/blocks/symbol/symbol.svelte +64 -52
- package/src/blocks/text/text.svelte +1 -25
- package/src/blocks/textarea/textarea.svelte +5 -29
- package/src/blocks/video/video.svelte +35 -43
- package/src/components/render-block/block-styles.svelte +49 -59
- package/src/components/render-block/render-block.svelte +197 -167
- package/src/components/render-block/render-component.svelte +13 -51
- package/src/components/render-block/render-repeated-block.svelte +29 -0
- package/src/components/render-blocks.svelte +74 -98
- package/src/components/render-content/components/render-styles.svelte +42 -62
- package/src/components/render-content/render-content.svelte +257 -231
- package/src/components/render-inlined-styles.svelte +15 -45
- package/src/context/builder.context.js +7 -1
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/get-block-styles.js +6 -3
- package/src/functions/get-processed-block.js +15 -8
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/sanitize-styles.js +5 -0
package/package.json
CHANGED
|
@@ -1,50 +1,19 @@
|
|
|
1
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
|
-
</script>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{#if link }
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<a {...attributes} role="button" href={link} target={openLinkInNewTab ? '_blank' : undefined} >
|
|
39
|
-
|
|
40
|
-
{text}
|
|
41
|
-
|
|
42
|
-
</a>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
2
|
+
export let attributes;
|
|
3
|
+
export let text;
|
|
4
|
+
export let link;
|
|
5
|
+
export let openLinkInNewTab;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
{#if link}
|
|
9
|
+
<a
|
|
10
|
+
{...attributes}
|
|
11
|
+
role="button"
|
|
12
|
+
href={link}
|
|
13
|
+
target={openLinkInNewTab ? "_blank" : undefined}
|
|
14
|
+
>
|
|
15
|
+
{text}
|
|
16
|
+
</a>
|
|
47
17
|
{:else}
|
|
48
|
-
<span {...attributes}>{text}</span>
|
|
49
|
-
|
|
50
|
-
{/if}
|
|
18
|
+
<span {...attributes}>{text}</span>
|
|
19
|
+
{/if}
|
|
@@ -1,103 +1,111 @@
|
|
|
1
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
.div {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
flex-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
width: var(--column-width) !important;
|
|
102
|
-
margin-left: var(--column-margin-left) !important;
|
|
103
|
-
|
|
2
|
+
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
3
|
+
|
|
4
|
+
export let space;
|
|
5
|
+
export let columns;
|
|
6
|
+
export let stackColumnsAt;
|
|
7
|
+
export let reverseColumnsWhenStacked;
|
|
8
|
+
|
|
9
|
+
function mitosis_styling(node, vars) {
|
|
10
|
+
Object.entries(vars).forEach(([p, v]) => {
|
|
11
|
+
node.style[p] = v;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const getGutterSize = function getGutterSize() {
|
|
16
|
+
return typeof space === "number" ? space || 0 : 20;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getColumns = function getColumns() {
|
|
20
|
+
return columns || [];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getWidth = function getWidth(index) {
|
|
24
|
+
const columns = getColumns();
|
|
25
|
+
return columns[index]?.width || 100 / columns.length;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getColumnCssWidth = function getColumnCssWidth(index) {
|
|
29
|
+
const columns = getColumns();
|
|
30
|
+
const gutterSize = getGutterSize();
|
|
31
|
+
const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
|
|
32
|
+
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const maybeApplyForTablet = function maybeApplyForTablet(prop) {
|
|
36
|
+
const _stackColumnsAt = stackColumnsAt || "tablet";
|
|
37
|
+
|
|
38
|
+
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
39
|
+
};
|
|
40
|
+
$: columnsCssVars = () => {
|
|
41
|
+
const flexDir =
|
|
42
|
+
stackColumnsAt === "never"
|
|
43
|
+
? "inherit"
|
|
44
|
+
: reverseColumnsWhenStacked
|
|
45
|
+
? "column-reverse"
|
|
46
|
+
: "column";
|
|
47
|
+
return {
|
|
48
|
+
"--flex-dir": flexDir,
|
|
49
|
+
"--flex-dir-tablet": maybeApplyForTablet(flexDir),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
$: columnCssVars = () => {
|
|
54
|
+
const width = "100%";
|
|
55
|
+
const marginLeft = "0";
|
|
56
|
+
return {
|
|
57
|
+
"--column-width": width,
|
|
58
|
+
"--column-margin-left": marginLeft,
|
|
59
|
+
"--column-width-tablet": maybeApplyForTablet(width),
|
|
60
|
+
"--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<div use:mitosis_styling={columnsCssVars()} class="builder-columns div">
|
|
66
|
+
{#each columns as column, index (index)}
|
|
67
|
+
<div
|
|
68
|
+
use:mitosis_styling={{
|
|
69
|
+
width: getColumnCssWidth(index),
|
|
70
|
+
marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
|
|
71
|
+
...columnCssVars(),
|
|
72
|
+
}}
|
|
73
|
+
class="builder-column div-2"
|
|
74
|
+
>
|
|
75
|
+
<RenderBlocks blocks={column.blocks} />
|
|
76
|
+
</div>
|
|
77
|
+
{/each}
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<style>
|
|
81
|
+
.div {
|
|
82
|
+
display: flex;
|
|
83
|
+
align-items: stretch;
|
|
84
|
+
line-height: normal;
|
|
85
|
+
}
|
|
86
|
+
@media (max-width: 999px) {
|
|
87
|
+
.div {
|
|
88
|
+
flex-direction: var(--flex-dir-tablet);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
@media (max-width: 639px) {
|
|
92
|
+
.div {
|
|
93
|
+
flex-direction: var(--flex-dir);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
.div-2 {
|
|
97
|
+
flex-grow: 1;
|
|
98
|
+
}
|
|
99
|
+
@media (max-width: 999px) {
|
|
100
|
+
.div-2 {
|
|
101
|
+
width: var(--column-width-tablet) !important;
|
|
102
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
@media (max-width: 639px) {
|
|
106
|
+
.div-2 {
|
|
107
|
+
width: var(--column-width) !important;
|
|
108
|
+
margin-left: var(--column-margin-left) !important;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
@@ -1,64 +1,62 @@
|
|
|
1
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
|
|
4
|
+
export let elem;
|
|
5
|
+
export let replaceNodes;
|
|
6
|
+
export let code;
|
|
7
|
+
|
|
8
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
9
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
10
|
+
if (elem && typeof window !== "undefined") {
|
|
11
|
+
const scripts = elem.getElementsByTagName("script");
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
14
|
+
const script = scripts[i];
|
|
15
|
+
|
|
16
|
+
if (script.src) {
|
|
17
|
+
if (scriptsInserted.includes(script.src)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
scriptsInserted.push(script.src);
|
|
22
|
+
const newScript = document.createElement("script");
|
|
23
|
+
newScript.async = true;
|
|
24
|
+
newScript.src = script.src;
|
|
25
|
+
document.head.appendChild(newScript);
|
|
26
|
+
} else if (
|
|
27
|
+
!script.type ||
|
|
28
|
+
[
|
|
29
|
+
"text/javascript",
|
|
30
|
+
"application/javascript",
|
|
31
|
+
"application/ecmascript",
|
|
32
|
+
].includes(script.type)
|
|
33
|
+
) {
|
|
34
|
+
if (scriptsRun.includes(script.innerText)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
scriptsRun.push(script.innerText);
|
|
40
|
+
new Function(script.innerText)();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<div bind:this={elem} class={'builder-custom-code' + (replaceNodes ? ' replace-nodes' : '')} >{@html code}</div>
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let scriptsInserted = [];
|
|
50
|
+
let scriptsRun = [];
|
|
51
|
+
|
|
52
|
+
onMount(() => {
|
|
53
|
+
findAndRunScripts();
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<div
|
|
58
|
+
bind:this={elem}
|
|
59
|
+
class={"builder-custom-code" + (replaceNodes ? " replace-nodes" : "")}
|
|
60
|
+
>
|
|
61
|
+
{@html code}
|
|
62
|
+
</div>
|
|
@@ -1,63 +1,56 @@
|
|
|
1
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
|
|
4
|
+
export let elem;
|
|
5
|
+
export let content;
|
|
6
|
+
|
|
7
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
8
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
9
|
+
if (elem && typeof window !== "undefined") {
|
|
10
|
+
const scripts = elem.getElementsByTagName("script");
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
13
|
+
const script = scripts[i];
|
|
14
|
+
|
|
15
|
+
if (script.src) {
|
|
16
|
+
if (scriptsInserted.includes(script.src)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
scriptsInserted.push(script.src);
|
|
21
|
+
const newScript = document.createElement("script");
|
|
22
|
+
newScript.async = true;
|
|
23
|
+
newScript.src = script.src;
|
|
24
|
+
document.head.appendChild(newScript);
|
|
25
|
+
} else if (
|
|
26
|
+
!script.type ||
|
|
27
|
+
[
|
|
28
|
+
"text/javascript",
|
|
29
|
+
"application/javascript",
|
|
30
|
+
"application/ecmascript",
|
|
31
|
+
].includes(script.type)
|
|
32
|
+
) {
|
|
33
|
+
if (scriptsRun.includes(script.innerText)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
scriptsRun.push(script.innerText);
|
|
39
|
+
new Function(script.innerText)();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.warn("`Embed`: Error running script:", error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let scriptsInserted = [];
|
|
54
|
-
let scriptsRun = [];
|
|
55
|
-
|
|
56
|
-
onMount(() => { findAndRunScripts(); });
|
|
46
|
+
};
|
|
57
47
|
|
|
58
|
-
|
|
48
|
+
let scriptsInserted = [];
|
|
49
|
+
let scriptsRun = [];
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
onMount(() => {
|
|
52
|
+
findAndRunScripts();
|
|
53
|
+
});
|
|
54
|
+
</script>
|
|
62
55
|
|
|
63
|
-
|
|
56
|
+
<div class="builder-embed" bind:this={elem}>{@html content}</div>
|