@builder.io/sdk-solid 0.1.2 → 0.1.3
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/dist/sdk-solid.cjs +34 -0
- package/dist/sdk-solid.js +3937 -0
- package/package.json +5 -6
- package/src/blocks/BaseText.jsx +5 -1
- package/src/blocks/button/button.jsx +25 -7
- package/src/blocks/columns/columns.jsx +84 -38
- package/src/blocks/custom-code/custom-code.jsx +25 -3
- package/src/blocks/embed/embed.jsx +14 -2
- package/src/blocks/form/form.jsx +175 -121
- package/src/blocks/fragment/fragment.jsx +2 -1
- package/src/blocks/image/image.jsx +75 -38
- package/src/blocks/img/img.jsx +15 -5
- package/src/blocks/input/input.jsx +17 -2
- package/src/blocks/raw-text/raw-text.jsx +8 -2
- package/src/blocks/section/section.jsx +24 -14
- package/src/blocks/select/select.jsx +21 -6
- package/src/blocks/submit-button/submit-button.jsx +6 -3
- package/src/blocks/symbol/symbol.jsx +54 -15
- package/src/blocks/text/text.jsx +2 -1
- package/src/blocks/textarea/textarea.jsx +11 -2
- package/src/blocks/video/video.jsx +49 -27
- package/src/components/render-block/block-styles.jsx +45 -21
- package/src/components/render-block/render-block.helpers.js +90 -0
- package/src/components/render-block/render-block.jsx +110 -131
- package/src/components/render-block/render-component.jsx +26 -9
- package/src/components/render-block/render-repeated-block.jsx +20 -24
- package/src/components/render-blocks.jsx +70 -30
- package/src/components/render-content/builder-editing.jsx +2 -1
- package/src/components/render-content/components/render-styles.jsx +17 -8
- package/src/components/render-content/render-content.jsx +234 -148
- package/src/components/render-inlined-styles.jsx +14 -4
- package/src/functions/track/helpers.js +50 -0
- package/src/functions/{track.js → track/index.js} +10 -6
- package/src/functions/track/interaction.js +53 -0
- package/src/index.js +1 -1
- package/vite.config.ts +18 -0
- package/solid-index.jsx +0 -5
- package/src/components/render-block/render-component-with-context.jsx +0 -28
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { For } from "solid-js";
|
|
2
|
+
|
|
2
3
|
import { isEditing } from "../../functions/is-editing.js";
|
|
4
|
+
|
|
3
5
|
function SelectComponent(props) {
|
|
4
|
-
return
|
|
6
|
+
return (
|
|
7
|
+
<select
|
|
8
|
+
{...props.attributes}
|
|
9
|
+
value={props.value}
|
|
10
|
+
key={
|
|
11
|
+
isEditing() && props.defaultValue ? props.defaultValue : "default-key"
|
|
12
|
+
}
|
|
13
|
+
defaultValue={props.defaultValue}
|
|
14
|
+
name={props.name}
|
|
15
|
+
>
|
|
5
16
|
<For each={props.options}>
|
|
6
17
|
{(option, _index) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
const index = _index();
|
|
19
|
+
return (
|
|
20
|
+
<option value={option.value}>{option.name || option.value}</option>
|
|
21
|
+
);
|
|
22
|
+
}}
|
|
10
23
|
</For>
|
|
11
|
-
</select
|
|
24
|
+
</select>
|
|
25
|
+
);
|
|
12
26
|
}
|
|
13
|
-
|
|
27
|
+
|
|
28
|
+
export default SelectComponent;
|
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
import { useContext, on, createEffect, createSignal } from "solid-js";
|
|
2
|
+
|
|
2
3
|
import RenderContent from "../../components/render-content/render-content.jsx";
|
|
3
4
|
import BuilderContext from "../../context/builder.context.js";
|
|
4
5
|
import { getContent } from "../../functions/get-content/index.js";
|
|
5
6
|
import { TARGET } from "../../constants/target";
|
|
7
|
+
|
|
6
8
|
function Symbol(props) {
|
|
7
9
|
const [fetchedContent, setFetchedContent] = createSignal(null);
|
|
10
|
+
|
|
8
11
|
function className() {
|
|
9
|
-
return [
|
|
12
|
+
return [
|
|
13
|
+
...(TARGET === "vue2" || TARGET === "vue3"
|
|
14
|
+
? Object.keys(props.attributes.class)
|
|
15
|
+
: [props.attributes.class]),
|
|
16
|
+
"builder-symbol",
|
|
17
|
+
props.symbol?.inline ? "builder-inline-symbol" : undefined,
|
|
18
|
+
props.symbol?.dynamic || props.dynamic
|
|
19
|
+
? "builder-dynamic-symbol"
|
|
20
|
+
: undefined,
|
|
21
|
+
]
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.join(" ");
|
|
10
24
|
}
|
|
25
|
+
|
|
11
26
|
function contentToUse() {
|
|
12
27
|
return props.symbol?.content || fetchedContent();
|
|
13
28
|
}
|
|
29
|
+
|
|
14
30
|
const builderContext = useContext(BuilderContext);
|
|
31
|
+
|
|
15
32
|
function onUpdateFn_0() {
|
|
16
33
|
const symbolToUse = props.symbol;
|
|
17
34
|
|
|
@@ -24,27 +41,49 @@ function Symbol(props) {
|
|
|
24
41
|
*
|
|
25
42
|
* then we want to re-fetch the symbol content.
|
|
26
43
|
*/
|
|
27
|
-
if (
|
|
44
|
+
if (
|
|
45
|
+
symbolToUse &&
|
|
46
|
+
!symbolToUse.content &&
|
|
47
|
+
!fetchedContent() &&
|
|
48
|
+
symbolToUse.model &&
|
|
49
|
+
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
50
|
+
builderContext?.apiKey
|
|
51
|
+
) {
|
|
28
52
|
getContent({
|
|
29
53
|
model: symbolToUse.model,
|
|
30
54
|
apiKey: builderContext.apiKey,
|
|
31
55
|
query: {
|
|
32
|
-
id: symbolToUse.entry
|
|
33
|
-
}
|
|
34
|
-
}).then(response => {
|
|
56
|
+
id: symbolToUse.entry,
|
|
57
|
+
},
|
|
58
|
+
}).then((response) => {
|
|
35
59
|
setFetchedContent(response);
|
|
36
60
|
});
|
|
37
61
|
}
|
|
38
62
|
}
|
|
39
63
|
createEffect(on(() => [props.symbol, fetchedContent()], onUpdateFn_0));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
...props.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
class={className()}
|
|
68
|
+
{...props.attributes}
|
|
69
|
+
dataSet={{
|
|
70
|
+
class: className(),
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<RenderContent
|
|
74
|
+
apiKey={builderContext.apiKey}
|
|
75
|
+
context={builderContext.context}
|
|
76
|
+
customComponents={Object.values(builderContext.registeredComponents)}
|
|
77
|
+
data={{
|
|
78
|
+
...props.symbol?.data,
|
|
79
|
+
...builderContext.state,
|
|
80
|
+
...props.symbol?.content?.data?.state,
|
|
81
|
+
}}
|
|
82
|
+
model={props.symbol?.model}
|
|
83
|
+
content={contentToUse()}
|
|
84
|
+
></RenderContent>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
49
87
|
}
|
|
50
|
-
|
|
88
|
+
|
|
89
|
+
export default Symbol;
|
package/src/blocks/text/text.jsx
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
function Textarea(props) {
|
|
2
|
-
return
|
|
2
|
+
return (
|
|
3
|
+
<textarea
|
|
4
|
+
{...props.attributes}
|
|
5
|
+
placeholder={props.placeholder}
|
|
6
|
+
name={props.name}
|
|
7
|
+
value={props.value}
|
|
8
|
+
defaultValue={props.defaultValue}
|
|
9
|
+
></textarea>
|
|
10
|
+
);
|
|
3
11
|
}
|
|
4
|
-
|
|
12
|
+
|
|
13
|
+
export default Textarea;
|
|
@@ -1,38 +1,60 @@
|
|
|
1
|
+
import { createSignal } from "solid-js";
|
|
2
|
+
|
|
1
3
|
function Video(props) {
|
|
2
4
|
function videoProps() {
|
|
3
5
|
return {
|
|
4
|
-
...(props.autoPlay === true
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
...(props.autoPlay === true
|
|
7
|
+
? {
|
|
8
|
+
autoPlay: true,
|
|
9
|
+
}
|
|
10
|
+
: {}),
|
|
11
|
+
...(props.muted === true
|
|
12
|
+
? {
|
|
13
|
+
muted: true,
|
|
14
|
+
}
|
|
15
|
+
: {}),
|
|
16
|
+
...(props.controls === true
|
|
17
|
+
? {
|
|
18
|
+
controls: true,
|
|
19
|
+
}
|
|
20
|
+
: {}),
|
|
21
|
+
...(props.loop === true
|
|
22
|
+
? {
|
|
23
|
+
loop: true,
|
|
24
|
+
}
|
|
25
|
+
: {}),
|
|
26
|
+
...(props.playsInline === true
|
|
27
|
+
? {
|
|
28
|
+
playsInline: true,
|
|
29
|
+
}
|
|
30
|
+
: {}),
|
|
19
31
|
};
|
|
20
32
|
}
|
|
33
|
+
|
|
21
34
|
function spreadProps() {
|
|
22
35
|
return {
|
|
23
36
|
...props.attributes,
|
|
24
|
-
...videoProps()
|
|
37
|
+
...videoProps(),
|
|
25
38
|
};
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<video
|
|
43
|
+
{...spreadProps()}
|
|
44
|
+
style={{
|
|
45
|
+
width: "100%",
|
|
46
|
+
height: "100%",
|
|
47
|
+
...props.attributes?.style,
|
|
48
|
+
"object-fit": props.fit,
|
|
49
|
+
"object-position": props.position,
|
|
50
|
+
// Hack to get object fit to work as expected and
|
|
51
|
+
// not have the video overflow
|
|
52
|
+
"border-radius": 1,
|
|
53
|
+
}}
|
|
54
|
+
src={props.video || "no-src"}
|
|
55
|
+
poster={props.posterImage}
|
|
56
|
+
></video>
|
|
57
|
+
);
|
|
37
58
|
}
|
|
38
|
-
|
|
59
|
+
|
|
60
|
+
export default Video;
|
|
@@ -1,44 +1,68 @@
|
|
|
1
|
-
import { Show } from "solid-js";
|
|
2
|
-
|
|
1
|
+
import { Show, createSignal } from "solid-js";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getMaxWidthQueryForSize,
|
|
5
|
+
getSizesForBreakpoints,
|
|
6
|
+
} from "../../constants/device-sizes.js";
|
|
3
7
|
import { TARGET } from "../../constants/target.js";
|
|
4
8
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
5
9
|
import { createCssClass } from "../../helpers/css.js";
|
|
6
10
|
import RenderInlinedStyles from "../render-inlined-styles.jsx";
|
|
11
|
+
|
|
7
12
|
function BlockStyles(props) {
|
|
8
13
|
function useBlock() {
|
|
9
14
|
return getProcessedBlock({
|
|
10
15
|
block: props.block,
|
|
11
16
|
state: props.context.state,
|
|
12
17
|
context: props.context.context,
|
|
13
|
-
shouldEvaluateBindings: true
|
|
18
|
+
shouldEvaluateBindings: true,
|
|
14
19
|
});
|
|
15
20
|
}
|
|
21
|
+
|
|
16
22
|
function css() {
|
|
17
23
|
const styles = useBlock().responsiveStyles;
|
|
18
24
|
const content = props.context.content;
|
|
19
|
-
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
|
|
25
|
+
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
|
|
26
|
+
content?.meta?.breakpoints || {}
|
|
27
|
+
);
|
|
20
28
|
const largeStyles = styles?.large;
|
|
21
29
|
const mediumStyles = styles?.medium;
|
|
22
30
|
const smallStyles = styles?.small;
|
|
23
31
|
const className = useBlock().id;
|
|
24
|
-
const largeStylesClass = largeStyles
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
const largeStylesClass = largeStyles
|
|
33
|
+
? createCssClass({
|
|
34
|
+
className,
|
|
35
|
+
styles: largeStyles,
|
|
36
|
+
})
|
|
37
|
+
: "";
|
|
38
|
+
const mediumStylesClass = mediumStyles
|
|
39
|
+
? createCssClass({
|
|
40
|
+
className,
|
|
41
|
+
styles: mediumStyles,
|
|
42
|
+
mediaQuery: getMaxWidthQueryForSize(
|
|
43
|
+
"medium",
|
|
44
|
+
sizesWithUpdatedBreakpoints
|
|
45
|
+
),
|
|
46
|
+
})
|
|
47
|
+
: "";
|
|
48
|
+
const smallStylesClass = smallStyles
|
|
49
|
+
? createCssClass({
|
|
50
|
+
className,
|
|
51
|
+
styles: smallStyles,
|
|
52
|
+
mediaQuery: getMaxWidthQueryForSize(
|
|
53
|
+
"small",
|
|
54
|
+
sizesWithUpdatedBreakpoints
|
|
55
|
+
),
|
|
56
|
+
})
|
|
57
|
+
: "";
|
|
38
58
|
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
39
59
|
}
|
|
40
|
-
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Show when={TARGET !== "reactNative" && css()}>
|
|
41
63
|
<RenderInlinedStyles styles={css()}></RenderInlinedStyles>
|
|
42
|
-
</Show
|
|
64
|
+
</Show>
|
|
65
|
+
);
|
|
43
66
|
}
|
|
44
|
-
|
|
67
|
+
|
|
68
|
+
export default BlockStyles;
|
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { evaluate } from "../../functions/evaluate";
|
|
33
|
+
import { getProcessedBlock } from "../../functions/get-processed-block";
|
|
1
34
|
const EMPTY_HTML_ELEMENTS = [
|
|
2
35
|
"area",
|
|
3
36
|
"base",
|
|
@@ -18,6 +51,63 @@ const EMPTY_HTML_ELEMENTS = [
|
|
|
18
51
|
const isEmptyHtmlElement = (tagName) => {
|
|
19
52
|
return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
|
|
20
53
|
};
|
|
54
|
+
const getComponent = ({
|
|
55
|
+
block,
|
|
56
|
+
context
|
|
57
|
+
}) => {
|
|
58
|
+
var _a;
|
|
59
|
+
const componentName = (_a = getProcessedBlock({
|
|
60
|
+
block,
|
|
61
|
+
state: context.state,
|
|
62
|
+
context: context.context,
|
|
63
|
+
shouldEvaluateBindings: false
|
|
64
|
+
}).component) == null ? void 0 : _a.name;
|
|
65
|
+
if (!componentName) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const ref = context.registeredComponents[componentName];
|
|
69
|
+
if (!ref) {
|
|
70
|
+
console.warn(`
|
|
71
|
+
Could not find a registered component named "${componentName}".
|
|
72
|
+
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
73
|
+
return void 0;
|
|
74
|
+
} else {
|
|
75
|
+
return ref;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const getRepeatItemData = ({
|
|
79
|
+
block,
|
|
80
|
+
context
|
|
81
|
+
}) => {
|
|
82
|
+
const _a = block, { repeat } = _a, blockWithoutRepeat = __objRest(_a, ["repeat"]);
|
|
83
|
+
if (!(repeat == null ? void 0 : repeat.collection)) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const itemsArray = evaluate({
|
|
87
|
+
code: repeat.collection,
|
|
88
|
+
state: context.state,
|
|
89
|
+
context: context.context
|
|
90
|
+
});
|
|
91
|
+
if (!Array.isArray(itemsArray)) {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
95
|
+
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
96
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
97
|
+
context: __spreadProps(__spreadValues({}, context), {
|
|
98
|
+
state: __spreadProps(__spreadValues({}, context.state), {
|
|
99
|
+
$index: index,
|
|
100
|
+
$item: item,
|
|
101
|
+
[itemNameToUse]: item,
|
|
102
|
+
[`$${itemNameToUse}Index`]: index
|
|
103
|
+
})
|
|
104
|
+
}),
|
|
105
|
+
block: blockWithoutRepeat
|
|
106
|
+
}));
|
|
107
|
+
return repeatArray;
|
|
108
|
+
};
|
|
21
109
|
export {
|
|
110
|
+
getComponent,
|
|
111
|
+
getRepeatItemData,
|
|
22
112
|
isEmptyHtmlElement
|
|
23
113
|
};
|