@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import BuilderContext from "../../context/builder.context";
|
|
3
|
+
import RenderBlock from "./render-block.svelte";
|
|
4
|
+
|
|
5
|
+
import { getContext, setContext } from "svelte";
|
|
6
|
+
|
|
7
|
+
export let block;
|
|
8
|
+
export let repeatContext;
|
|
9
|
+
|
|
10
|
+
setContext(BuilderContext.key, {
|
|
11
|
+
get content() {
|
|
12
|
+
return repeatContext.content;
|
|
13
|
+
},
|
|
14
|
+
get state() {
|
|
15
|
+
return repeatContext.state;
|
|
16
|
+
},
|
|
17
|
+
get context() {
|
|
18
|
+
return repeatContext.context;
|
|
19
|
+
},
|
|
20
|
+
get apiKey() {
|
|
21
|
+
return repeatContext.apiKey;
|
|
22
|
+
},
|
|
23
|
+
get registeredComponents() {
|
|
24
|
+
return repeatContext.registeredComponents;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<RenderBlock {block} />
|
|
@@ -1,101 +1,77 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type: 'builder.clickEmptyBlocks',
|
|
23
|
-
data: {
|
|
24
|
-
parentElementId: parent,
|
|
25
|
-
dataPath: path
|
|
2
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
3
|
+
import BlockStyles from "./render-block/block-styles.svelte";
|
|
4
|
+
import RenderBlock from "./render-block/render-block.svelte";
|
|
5
|
+
|
|
6
|
+
export let blocks;
|
|
7
|
+
export let parent;
|
|
8
|
+
export let path;
|
|
9
|
+
|
|
10
|
+
const onClick = function onClick() {
|
|
11
|
+
if (isEditing() && !blocks?.length) {
|
|
12
|
+
window.parent?.postMessage(
|
|
13
|
+
{
|
|
14
|
+
type: "builder.clickEmptyBlocks",
|
|
15
|
+
data: {
|
|
16
|
+
parentElementId: parent,
|
|
17
|
+
dataPath: path,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
"*"
|
|
21
|
+
);
|
|
26
22
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const onMouseEnter = function onMouseEnter() {
|
|
26
|
+
if (isEditing() && !blocks?.length) {
|
|
27
|
+
window.parent?.postMessage(
|
|
28
|
+
{
|
|
29
|
+
type: "builder.hoverEmptyBlocks",
|
|
30
|
+
data: {
|
|
31
|
+
parentElementId: parent,
|
|
32
|
+
dataPath: path,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
"*"
|
|
36
|
+
);
|
|
38
37
|
}
|
|
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
|
-
{#if blocks }
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{#each blocks as block, index }
|
|
85
|
-
<BlockStyles key={'block-style-' + block.id} block={block} ></BlockStyles>
|
|
86
|
-
{/each}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{/if}
|
|
93
|
-
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
<style>
|
|
97
|
-
.div {
|
|
98
|
-
display: flex;
|
|
99
|
-
flex-direction: column;
|
|
100
|
-
align-items: stretch; }
|
|
101
|
-
</style>
|
|
38
|
+
};
|
|
39
|
+
$: className = () => {
|
|
40
|
+
return "builder-blocks" + (!blocks?.length ? " no-blocks" : "");
|
|
41
|
+
};
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<div
|
|
45
|
+
class={className() + "div"}
|
|
46
|
+
builder-path={path}
|
|
47
|
+
builder-parent-id={parent}
|
|
48
|
+
dataSet={{
|
|
49
|
+
class: className(),
|
|
50
|
+
}}
|
|
51
|
+
on:click={(event) => {
|
|
52
|
+
onClick();
|
|
53
|
+
}}
|
|
54
|
+
on:mouseenter={(event) => {
|
|
55
|
+
onMouseEnter();
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{#if blocks}
|
|
59
|
+
{#each blocks as block, undefined ("render-block-" + block.id)}
|
|
60
|
+
<RenderBlock {block} />
|
|
61
|
+
{/each}
|
|
62
|
+
{/if}
|
|
63
|
+
|
|
64
|
+
{#if blocks}
|
|
65
|
+
{#each blocks as block, undefined ("block-style-" + block.id)}
|
|
66
|
+
<BlockStyles {block} />
|
|
67
|
+
{/each}
|
|
68
|
+
{/if}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<style>
|
|
72
|
+
.div {
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
align-items: stretch;
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import RenderInlinedStyles from '../../render-inlined-styles.svelte';
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import RenderInlinedStyles from "../../render-inlined-styles.svelte";
|
|
9
3
|
|
|
10
|
-
|
|
4
|
+
export let cssCode;
|
|
5
|
+
export let customFonts;
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const url = font.fileUrl ?? font?.files?.regular;
|
|
21
|
-
let str = '';
|
|
7
|
+
const getCssFromFont = function getCssFromFont(font) {
|
|
8
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
9
|
+
const family =
|
|
10
|
+
font.family +
|
|
11
|
+
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
12
|
+
const name = family.split(",")[0];
|
|
13
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
14
|
+
let str = "";
|
|
22
15
|
|
|
23
|
-
if (url && family && name) {
|
|
24
|
-
|
|
16
|
+
if (url && family && name) {
|
|
17
|
+
str += `
|
|
25
18
|
@font-face {
|
|
26
19
|
font-family: "${family}";
|
|
27
20
|
src: local("${name}"), url('${url}') format('woff2');
|
|
@@ -29,21 +22,20 @@ if (url && family && name) {
|
|
|
29
22
|
font-weight: 400;
|
|
30
23
|
}
|
|
31
24
|
`.trim();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (font.files) {
|
|
35
|
-
for (const weight in font.files) {
|
|
36
|
-
const isNumber = String(Number(weight)) === weight;
|
|
25
|
+
}
|
|
37
26
|
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
if (font.files) {
|
|
28
|
+
for (const weight in font.files) {
|
|
29
|
+
const isNumber = String(Number(weight)) === weight;
|
|
41
30
|
|
|
31
|
+
if (!isNumber) {
|
|
32
|
+
continue;
|
|
33
|
+
} // TODO: maybe limit number loaded
|
|
42
34
|
|
|
43
|
-
|
|
35
|
+
const weightUrl = font.files[weight];
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
if (weightUrl && weightUrl !== url) {
|
|
38
|
+
str += `
|
|
47
39
|
@font-face {
|
|
48
40
|
font-family: "${family}";
|
|
49
41
|
src: url('${weightUrl}') format('woff2');
|
|
@@ -51,40 +43,28 @@ if (font.files) {
|
|
|
51
43
|
font-weight: ${weight};
|
|
52
44
|
}
|
|
53
45
|
`.trim();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
54
48
|
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
49
|
|
|
58
|
-
return str;
|
|
59
|
-
}
|
|
50
|
+
return str;
|
|
51
|
+
};
|
|
60
52
|
|
|
61
|
-
function getFontCss({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return `
|
|
73
|
-
${cssCode || ''}
|
|
53
|
+
const getFontCss = function getFontCss({ customFonts }) {
|
|
54
|
+
// TODO: flag for this
|
|
55
|
+
// if (!builder.allowCustomFonts) {
|
|
56
|
+
// return '';
|
|
57
|
+
// }
|
|
58
|
+
// TODO: separate internal data from external
|
|
59
|
+
return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
|
|
60
|
+
};
|
|
61
|
+
$: injectedStyles = () => {
|
|
62
|
+
return `
|
|
63
|
+
${cssCode || ""}
|
|
74
64
|
${getFontCss({
|
|
75
|
-
customFonts: customFonts
|
|
65
|
+
customFonts: customFonts,
|
|
76
66
|
})}`;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</script>
|
|
67
|
+
};
|
|
68
|
+
</script>
|
|
89
69
|
|
|
90
|
-
|
|
70
|
+
<RenderInlinedStyles styles={injectedStyles()} />
|