@builder.io/sdk-svelte 0.0.1-18 → 0.0.1-20
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/columns/columns.svelte +10 -10
- package/src/blocks/custom-code/custom-code.svelte +2 -2
- package/src/blocks/embed/embed.svelte +2 -2
- package/src/blocks/form/form.svelte +2 -2
- package/src/blocks/symbol/symbol.svelte +7 -2
- package/src/components/render-blocks.svelte +4 -4
- package/src/components/render-content/components/render-styles.svelte +4 -4
- package/src/components/render-content/render-content.svelte +28 -13
package/package.json
CHANGED
|
@@ -15,31 +15,31 @@ export let columns;
|
|
|
15
15
|
export let stackColumnsAt;
|
|
16
16
|
export let reverseColumnsWhenStacked;
|
|
17
17
|
|
|
18
|
-
function getGutterSize() {
|
|
18
|
+
const getGutterSize = function getGutterSize() {
|
|
19
19
|
return typeof space === 'number' ? space || 0 : 20;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
|
|
22
|
-
function getColumns() {
|
|
22
|
+
const getColumns = function getColumns() {
|
|
23
23
|
return columns || [];
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
|
|
26
|
-
function getWidth(index) {
|
|
26
|
+
const getWidth = function getWidth(index) {
|
|
27
27
|
const columns = getColumns();
|
|
28
28
|
return columns[index]?.width || 100 / columns.length;
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
function getColumnCssWidth(index) {
|
|
31
|
+
const getColumnCssWidth = function getColumnCssWidth(index) {
|
|
32
32
|
const columns = getColumns();
|
|
33
33
|
const gutterSize = getGutterSize();
|
|
34
34
|
const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
|
|
35
35
|
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
|
-
function maybeApplyForTablet(prop) {
|
|
38
|
+
const maybeApplyForTablet = function maybeApplyForTablet(prop) {
|
|
39
39
|
const _stackColumnsAt = stackColumnsAt || 'tablet';
|
|
40
40
|
|
|
41
41
|
return _stackColumnsAt === 'tablet' ? prop : 'inherit';
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
$: columnsCssVars = () => {
|
|
44
44
|
const flexDir = stackColumnsAt === 'never' ? 'inherit' : reverseColumnsWhenStacked ? 'column-reverse' : 'column';
|
|
45
45
|
return {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
export let replaceNodes;
|
|
15
15
|
export let code;
|
|
16
16
|
|
|
17
|
-
function findAndRunScripts() {
|
|
17
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
18
18
|
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
19
19
|
if (elem && typeof window !== 'undefined') {
|
|
20
20
|
const scripts = elem.getElementsByTagName('script');
|
|
@@ -46,7 +46,7 @@ if (elem && typeof window !== 'undefined') {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
export let elem;
|
|
14
14
|
export let content;
|
|
15
15
|
|
|
16
|
-
function findAndRunScripts() {
|
|
16
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
17
17
|
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
18
18
|
if (elem && typeof window !== 'undefined') {
|
|
19
19
|
const scripts = elem.getElementsByTagName('script');
|
|
@@ -45,7 +45,7 @@ if (elem && typeof window !== 'undefined') {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
|
|
@@ -31,7 +31,7 @@ export let errorMessage;
|
|
|
31
31
|
export let sendingMessage;
|
|
32
32
|
export let successMessage;
|
|
33
33
|
|
|
34
|
-
function onSubmit(event) {
|
|
34
|
+
const onSubmit = function onSubmit(event) {
|
|
35
35
|
const sendWithJs = sendWithJs || sendSubmissionsTo === 'email';
|
|
36
36
|
|
|
37
37
|
if (sendSubmissionsTo === 'zapier') {
|
|
@@ -232,7 +232,7 @@ if (sendSubmissionsTo === 'zapier') {
|
|
|
232
232
|
formState = 'error';
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
|
-
}
|
|
235
|
+
};
|
|
236
236
|
$: submissionState = () => {
|
|
237
237
|
return isEditing() && previewState || formState;
|
|
238
238
|
};
|
|
@@ -25,7 +25,9 @@ let content = null;
|
|
|
25
25
|
|
|
26
26
|
onMount(() => { content = symbol?.content; });
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
function onUpdateFn_0() {
|
|
30
|
+
const symbolToUse = symbol;
|
|
29
31
|
|
|
30
32
|
if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
|
|
31
33
|
getContent({
|
|
@@ -37,7 +39,10 @@ getContent({
|
|
|
37
39
|
}).then(response => {
|
|
38
40
|
content = response;
|
|
39
41
|
});
|
|
40
|
-
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
$: onUpdateFn_0(...[props.symbol?.content, props.symbol?.model, props.symbol?.entry, state.content])
|
|
45
|
+
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
</script>
|
|
@@ -16,7 +16,7 @@ import RenderBlock from './render-block/render-block.svelte';
|
|
|
16
16
|
export let parent;
|
|
17
17
|
export let path;
|
|
18
18
|
|
|
19
|
-
function onClick() {
|
|
19
|
+
const onClick = function onClick() {
|
|
20
20
|
if (isEditing() && !blocks?.length) {
|
|
21
21
|
window.parent?.postMessage({
|
|
22
22
|
type: 'builder.clickEmptyBlocks',
|
|
@@ -26,9 +26,9 @@ if (isEditing() && !blocks?.length) {
|
|
|
26
26
|
}
|
|
27
27
|
}, '*');
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
function onMouseEnter() {
|
|
31
|
+
const onMouseEnter = function onMouseEnter() {
|
|
32
32
|
if (isEditing() && !blocks?.length) {
|
|
33
33
|
window.parent?.postMessage({
|
|
34
34
|
type: 'builder.hoverEmptyBlocks',
|
|
@@ -38,7 +38,7 @@ if (isEditing() && !blocks?.length) {
|
|
|
38
38
|
}
|
|
39
39
|
}, '*');
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
42
|
$: className = () => {
|
|
43
43
|
return 'builder-blocks' + (!blocks?.length ? ' no-blocks' : '');
|
|
44
44
|
};
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
export let cssCode;
|
|
14
14
|
export let customFonts;
|
|
15
15
|
|
|
16
|
-
function getCssFromFont(font) {
|
|
16
|
+
const getCssFromFont = function getCssFromFont(font) {
|
|
17
17
|
// TODO: compute what font sizes are used and only load those.......
|
|
18
18
|
const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
|
|
19
19
|
const name = family.split(',')[0];
|
|
@@ -56,9 +56,9 @@ if (font.files) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return str;
|
|
59
|
-
}
|
|
59
|
+
};
|
|
60
60
|
|
|
61
|
-
function getFontCss({
|
|
61
|
+
const getFontCss = function getFontCss({
|
|
62
62
|
customFonts
|
|
63
63
|
}) {
|
|
64
64
|
// TODO: flag for this
|
|
@@ -67,7 +67,7 @@ customFonts
|
|
|
67
67
|
// }
|
|
68
68
|
// TODO: separate internal data from external
|
|
69
69
|
return customFonts?.map(font => getCssFromFont(font))?.join(' ') || '';
|
|
70
|
-
}
|
|
70
|
+
};
|
|
71
71
|
$: injectedStyles = () => {
|
|
72
72
|
return `
|
|
73
73
|
${cssCode || ''}
|
|
@@ -30,7 +30,7 @@ export let customComponents;
|
|
|
30
30
|
export let model;
|
|
31
31
|
export let apiKey;
|
|
32
32
|
|
|
33
|
-
function processMessage(event) {
|
|
33
|
+
const processMessage = function processMessage(event) {
|
|
34
34
|
const {
|
|
35
35
|
data
|
|
36
36
|
} = event;
|
|
@@ -57,9 +57,9 @@ if (data) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
}
|
|
60
|
+
};
|
|
61
61
|
|
|
62
|
-
function evaluateJsCode() {
|
|
62
|
+
const evaluateJsCode = function evaluateJsCode() {
|
|
63
63
|
// run any dynamic JS code attached to content
|
|
64
64
|
const jsCode = useContent?.()?.data?.jsCode;
|
|
65
65
|
|
|
@@ -70,17 +70,17 @@ if (jsCode) {
|
|
|
70
70
|
state: contentState()
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
}
|
|
73
|
+
};
|
|
74
74
|
|
|
75
|
-
function evalExpression(expression) {
|
|
75
|
+
const evalExpression = function evalExpression(expression) {
|
|
76
76
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
77
77
|
code: group,
|
|
78
78
|
context: context(),
|
|
79
79
|
state: contentState()
|
|
80
80
|
}));
|
|
81
|
-
}
|
|
81
|
+
};
|
|
82
82
|
|
|
83
|
-
function handleRequest({
|
|
83
|
+
const handleRequest = function handleRequest({
|
|
84
84
|
url,
|
|
85
85
|
key
|
|
86
86
|
}) {
|
|
@@ -95,9 +95,9 @@ const fetchAndSetState = async () => {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
fetchAndSetState();
|
|
98
|
-
}
|
|
98
|
+
};
|
|
99
99
|
|
|
100
|
-
function runHttpRequests() {
|
|
100
|
+
const runHttpRequests = function runHttpRequests() {
|
|
101
101
|
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
102
102
|
Object.entries(requests).forEach(([key, url]) => {
|
|
103
103
|
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
@@ -108,9 +108,9 @@ Object.entries(requests).forEach(([key, url]) => {
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
|
-
}
|
|
111
|
+
};
|
|
112
112
|
|
|
113
|
-
function emitStateUpdate() {
|
|
113
|
+
const emitStateUpdate = function emitStateUpdate() {
|
|
114
114
|
if (isEditing()) {
|
|
115
115
|
window.dispatchEvent(new CustomEvent('builder:component:stateChange', {
|
|
116
116
|
detail: {
|
|
@@ -121,7 +121,7 @@ if (isEditing()) {
|
|
|
121
121
|
}
|
|
122
122
|
}));
|
|
123
123
|
}
|
|
124
|
-
}
|
|
124
|
+
};
|
|
125
125
|
$: useContent = () => {
|
|
126
126
|
const mergedContent = { ...content,
|
|
127
127
|
...overrideContent,
|
|
@@ -218,7 +218,22 @@ runHttpRequests();
|
|
|
218
218
|
emitStateUpdate();
|
|
219
219
|
} });
|
|
220
220
|
|
|
221
|
-
|
|
221
|
+
|
|
222
|
+
function onUpdateFn_0() {
|
|
223
|
+
evaluateJsCode();
|
|
224
|
+
}
|
|
225
|
+
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode])
|
|
226
|
+
;
|
|
227
|
+
function onUpdateFn_1() {
|
|
228
|
+
runHttpRequests();
|
|
229
|
+
}
|
|
230
|
+
$: onUpdateFn_1(...[useContent?.()?.data?.httpRequests])
|
|
231
|
+
;
|
|
232
|
+
function onUpdateFn_2() {
|
|
233
|
+
emitStateUpdate();
|
|
234
|
+
}
|
|
235
|
+
$: onUpdateFn_2(...[contentState()])
|
|
236
|
+
|
|
222
237
|
|
|
223
238
|
onDestroy(() => { if (isBrowser()) {
|
|
224
239
|
window.removeEventListener('message', processMessage);
|