@builder.io/sdk-svelte 0.0.1-20 → 0.0.1-23
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/columns/component-info.js +25 -1
- package/src/blocks/custom-code/custom-code.svelte +59 -61
- package/src/blocks/embed/component-info.js +20 -1
- package/src/blocks/embed/embed.svelte +38 -56
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.svelte +264 -294
- package/src/blocks/fragment/fragment.svelte +1 -26
- package/src/blocks/image/component-info.js +47 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.svelte +121 -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 +57 -57
- 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 +252 -241
- package/src/components/render-inlined-styles.svelte +15 -45
- package/src/constants/builder-registered-components.js +4 -1
- 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/register-component.js +10 -18
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/fast-clone.js +0 -4
|
@@ -1,51 +1,21 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { TARGET } from '../constants/target.js';
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { TARGET } from "../constants/target.js";
|
|
9
3
|
|
|
10
|
-
|
|
4
|
+
export let styles;
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
$: injectedStyleScript = () => {
|
|
17
|
-
return `<${tagName()}>${styles}</${tagName()}>`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
$: tagName = () => {
|
|
21
|
-
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
22
|
-
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
23
|
-
return 'sty' + 'le';
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{#if TARGET === 'svelte' }
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
{@html injectedStyleScript()}
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
$: injectedStyleScript = () => {
|
|
7
|
+
return `<${tagName()}>${styles}</${tagName()}>`;
|
|
8
|
+
};
|
|
46
9
|
|
|
10
|
+
$: tagName = () => {
|
|
11
|
+
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
12
|
+
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
13
|
+
return "sty" + "le";
|
|
14
|
+
};
|
|
15
|
+
</script>
|
|
47
16
|
|
|
17
|
+
{#if TARGET === "svelte"}
|
|
18
|
+
{@html injectedStyleScript()}
|
|
48
19
|
{:else}
|
|
49
|
-
<svelte:component
|
|
50
|
-
|
|
51
|
-
{/if}
|
|
20
|
+
<svelte:component this={tagName()}>{styles}</svelte:component>
|
|
21
|
+
{/if}
|
|
@@ -30,6 +30,8 @@ import { componentInfo as textComponentInfo } from "../blocks/text/component-inf
|
|
|
30
30
|
import { default as Text } from "../blocks/text/text.svelte";
|
|
31
31
|
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
|
|
32
32
|
import { default as Video } from "../blocks/video/video.svelte";
|
|
33
|
+
import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info";
|
|
34
|
+
import { default as embed } from "../blocks/embed/embed.svelte";
|
|
33
35
|
const getDefaultRegisteredComponents = () => [
|
|
34
36
|
__spreadValues({ component: Columns }, columnsComponentInfo),
|
|
35
37
|
__spreadValues({ component: Image }, imageComponentInfo),
|
|
@@ -38,7 +40,8 @@ const getDefaultRegisteredComponents = () => [
|
|
|
38
40
|
__spreadValues({ component: Symbol }, symbolComponentInfo),
|
|
39
41
|
__spreadValues({ component: Button }, buttonComponentInfo),
|
|
40
42
|
__spreadValues({ component: Section }, sectionComponentInfo),
|
|
41
|
-
__spreadValues({ component: Fragment }, fragmentComponentInfo)
|
|
43
|
+
__spreadValues({ component: Fragment }, fragmentComponentInfo),
|
|
44
|
+
__spreadValues({ component: embed }, embedComponentInfo)
|
|
42
45
|
];
|
|
43
46
|
export {
|
|
44
47
|
getDefaultRegisteredComponents
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
const key = Symbol();
|
|
2
2
|
var stdin_default = {
|
|
3
|
-
Builder: {
|
|
3
|
+
Builder: {
|
|
4
|
+
content: null,
|
|
5
|
+
context: {},
|
|
6
|
+
state: {},
|
|
7
|
+
apiKey: null,
|
|
8
|
+
registeredComponents: {}
|
|
9
|
+
},
|
|
4
10
|
key
|
|
5
11
|
};
|
|
6
12
|
export {
|
|
@@ -15,15 +15,18 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
17
|
import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
|
|
18
|
+
import { convertStyleObject } from "./convert-style-object.js";
|
|
19
|
+
import { sanitizeBlockStyles } from "./sanitize-styles.js";
|
|
18
20
|
function getBlockStyles(block) {
|
|
19
21
|
var _a, _b, _c, _d, _e;
|
|
20
|
-
const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
|
|
22
|
+
const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
|
|
21
23
|
if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
|
|
22
|
-
styles[getMaxWidthQueryForSize("medium")] = (_c = block.responsiveStyles) == null ? void 0 : _c.medium;
|
|
24
|
+
styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
|
|
23
25
|
}
|
|
24
26
|
if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
|
|
25
|
-
styles[getMaxWidthQueryForSize("small")] = (_e = block.responsiveStyles) == null ? void 0 : _e.small;
|
|
27
|
+
styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
|
|
26
28
|
}
|
|
29
|
+
sanitizeBlockStyles(styles);
|
|
27
30
|
return styles;
|
|
28
31
|
}
|
|
29
32
|
export {
|
|
@@ -20,9 +20,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { evaluate } from "./evaluate.js";
|
|
21
21
|
import { set } from "./set.js";
|
|
22
22
|
import { transformBlock } from "./transform-block.js";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const evaluateBindings = ({
|
|
24
|
+
block,
|
|
25
|
+
context,
|
|
26
|
+
state
|
|
27
|
+
}) => {
|
|
26
28
|
if (!block.bindings) {
|
|
27
29
|
return block;
|
|
28
30
|
}
|
|
@@ -32,14 +34,19 @@ function getProcessedBlock(options) {
|
|
|
32
34
|
});
|
|
33
35
|
for (const binding in block.bindings) {
|
|
34
36
|
const expression = block.bindings[binding];
|
|
35
|
-
const value = evaluate({
|
|
36
|
-
code: expression,
|
|
37
|
-
state,
|
|
38
|
-
context
|
|
39
|
-
});
|
|
37
|
+
const value = evaluate({ code: expression, state, context });
|
|
40
38
|
set(copied, binding, value);
|
|
41
39
|
}
|
|
42
40
|
return copied;
|
|
41
|
+
};
|
|
42
|
+
function getProcessedBlock(options) {
|
|
43
|
+
const { state, context } = options;
|
|
44
|
+
const block = transformBlock(options.block);
|
|
45
|
+
if (evaluateBindings) {
|
|
46
|
+
return evaluateBindings({ block, state, context });
|
|
47
|
+
} else {
|
|
48
|
+
return block;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
export {
|
|
45
52
|
getProcessedBlock
|
|
@@ -20,7 +20,8 @@ test("Can process bindings", () => {
|
|
|
20
20
|
const processed = getProcessedBlock({
|
|
21
21
|
block,
|
|
22
22
|
context: {},
|
|
23
|
-
state: { test: "hello" }
|
|
23
|
+
state: { test: "hello" },
|
|
24
|
+
evaluateBindings: true
|
|
24
25
|
});
|
|
25
26
|
expect(processed).not.toEqual(block);
|
|
26
27
|
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|
|
@@ -29,7 +29,6 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import { fastClone } from "./fast-clone.js";
|
|
33
32
|
const components = [];
|
|
34
33
|
function registerComponent(component, info) {
|
|
35
34
|
components.push(__spreadValues({ component }, info));
|
|
@@ -38,31 +37,24 @@ function registerComponent(component, info) {
|
|
|
38
37
|
}
|
|
39
38
|
const createRegisterComponentMessage = (_a) => {
|
|
40
39
|
var _b = _a, {
|
|
41
|
-
component
|
|
40
|
+
component: _
|
|
42
41
|
} = _b, info = __objRest(_b, [
|
|
43
42
|
"component"
|
|
44
43
|
]);
|
|
45
44
|
return {
|
|
46
45
|
type: "builder.registerComponent",
|
|
47
|
-
data: prepareComponentInfoToSend(
|
|
46
|
+
data: prepareComponentInfoToSend(info)
|
|
48
47
|
};
|
|
49
48
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
input = __spreadProps(__spreadValues({}, input), {
|
|
58
|
-
[key]: `return (${fn.toString()}).apply(this, arguments)`
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return input;
|
|
63
|
-
})
|
|
49
|
+
const serializeFn = (fn) => `return (${fn.toString()}).apply(this, arguments)`;
|
|
50
|
+
const prepareComponentInfoToSend = (info) => {
|
|
51
|
+
var _a;
|
|
52
|
+
return __spreadProps(__spreadValues({}, info), {
|
|
53
|
+
inputs: (_a = info.inputs) == null ? void 0 : _a.map((input) => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
|
|
54
|
+
[key]: typeof value === "function" ? serializeFn(value) : value
|
|
55
|
+
}), {}))
|
|
64
56
|
});
|
|
65
|
-
}
|
|
57
|
+
};
|
|
66
58
|
export {
|
|
67
59
|
components,
|
|
68
60
|
createRegisterComponentMessage,
|