@builder.io/sdk-solid 0.0.16 → 0.0.17
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/README.md +5 -1
- package/package.json +17 -5
- package/solid-index.jsx +5 -0
- package/src/blocks/BaseText.jsx +9 -0
- package/src/blocks/button/button.jsx +9 -6
- package/src/blocks/columns/columns.jsx +54 -52
- package/src/blocks/columns/component-info.js +26 -1
- package/src/blocks/custom-code/custom-code.jsx +35 -38
- package/src/blocks/embed/component-info.js +21 -1
- package/src/blocks/embed/embed.jsx +37 -42
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.jsx +175 -176
- package/src/blocks/image/component-info.js +48 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +44 -13
- package/src/blocks/img/img.jsx +1 -1
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.jsx +39 -12
- package/src/blocks/text/text.jsx +1 -1
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.jsx +21 -2
- package/src/components/render-block/block-styles.jsx +41 -31
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +205 -90
- package/src/components/render-block/render-component-with-context.jsx +36 -0
- package/src/components/render-block/render-component.jsx +28 -0
- package/src/components/render-block/render-repeated-block.jsx +36 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +42 -33
- package/src/components/render-content/components/render-styles.jsx +39 -42
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +199 -128
- package/src/components/render-inlined-styles.jsx +21 -5
- package/src/constants/builder-registered-components.js +54 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +3 -1
- package/src/context/types.js +0 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +14 -0
- package/src/functions/evaluate.js +1 -1
- package/src/functions/extract-text-styles.js +22 -0
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-actions-handler.js +12 -0
- package/src/functions/get-block-actions.js +2 -7
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +27 -19
- package/src/functions/get-builder-search-params/index.js +17 -2
- package/src/functions/get-content/ab-testing.js +99 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/get-content/index.js +20 -62
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +24 -11
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/mark-mutable.js +10 -0
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +4 -0
- package/src/functions/track.js +108 -13
- package/src/helpers/ab-tests.js +16 -0
- package/src/helpers/cookie.js +79 -0
- package/src/helpers/css.js +28 -0
- package/src/helpers/flatten.js +34 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +49 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/index-helpers/blocks-exports.js +11 -9
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/button.lite.tsx +0 -20
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/columns.lite.tsx +0 -102
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/custom-code.lite.tsx +0 -67
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/embed.lite.tsx +0 -59
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/form.lite.tsx +0 -293
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/fragment.lite.tsx +0 -5
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/image.lite.tsx +0 -83
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/img.lite.tsx +0 -18
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/input/input.lite.tsx +0 -20
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/section/section.lite.tsx +0 -18
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/select/select.lite.tsx +0 -28
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/symbol/symbol.lite.tsx +0 -39
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/text/text.lite.tsx +0 -5
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/textarea/textarea.lite.tsx +0 -13
- package/src/blocks/video/index.js +0 -7
- package/src/blocks/video/video.lite.tsx +0 -26
- package/src/components/error-boundary.jsx +0 -5
- package/src/components/error-boundary.lite.tsx +0 -5
- package/src/components/render-block/block-styles.lite.tsx +0 -38
- package/src/components/render-block/render-block.lite.tsx +0 -119
- package/src/components/render-blocks.lite.tsx +0 -75
- package/src/components/render-content/components/render-styles.lite.tsx +0 -76
- package/src/components/render-content/render-content.lite.tsx +0 -232
- package/src/components/render-inlined-styles.lite.tsx +0 -5
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
|
@@ -1,23 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import RenderContent from "../../components/render-content/render-content.
|
|
1
|
+
import { useContext, onMount, on, createEffect, createSignal } from "solid-js";
|
|
2
|
+
import RenderContent from "../../components/render-content/render-content.jsx";
|
|
3
3
|
import BuilderContext from "../../context/builder.context.js";
|
|
4
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
5
|
+
import { markMutable } from "../../functions/mark-mutable";
|
|
4
6
|
|
|
5
7
|
function Symbol(props) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
content: null
|
|
9
|
-
});
|
|
8
|
+
const [className, setClassName] = createSignal("builder-symbol");
|
|
9
|
+
const [content, setContent] = createSignal(null);
|
|
10
10
|
const builderContext = useContext(BuilderContext);
|
|
11
11
|
onMount(() => {
|
|
12
|
-
|
|
12
|
+
setContent(props.symbol?.content);
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
function onUpdateFn_0() {
|
|
16
|
+
const symbolToUse = props.symbol;
|
|
17
|
+
/**
|
|
18
|
+
* If:
|
|
19
|
+
* - we have a symbol prop
|
|
20
|
+
* - yet it does not have any content
|
|
21
|
+
* - and we have not already stored content from before
|
|
22
|
+
* - and it has a model name
|
|
23
|
+
*
|
|
24
|
+
* then we want to re-fetch the symbol content.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
if (symbolToUse && !symbolToUse.content && !content() && symbolToUse.model) {
|
|
28
|
+
getContent({
|
|
29
|
+
model: symbolToUse.model,
|
|
30
|
+
apiKey: builderContext.apiKey,
|
|
31
|
+
query: {
|
|
32
|
+
id: symbolToUse.entry
|
|
33
|
+
}
|
|
34
|
+
}).then(response => {
|
|
35
|
+
setContent(response);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
createEffect(on(() => [props.symbol, content()], onUpdateFn_0));
|
|
41
|
+
return <div class={className()} {...props.attributes} dataSet={{
|
|
42
|
+
class: className()
|
|
16
43
|
}}>
|
|
17
|
-
<RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...props.symbol?.data,
|
|
44
|
+
<RenderContent apiKey={builderContext.apiKey} context={builderContext.context} customComponents={markMutable(Object.values(builderContext.registeredComponents))} data={markMutable({ ...props.symbol?.data,
|
|
18
45
|
...builderContext.state,
|
|
19
|
-
...props.symbol?.
|
|
20
|
-
}} model={props.symbol?.model} content={
|
|
46
|
+
...props.symbol?.content?.data?.state
|
|
47
|
+
})} model={props.symbol?.model} content={markMutable(content())}></RenderContent>
|
|
21
48
|
</div>;
|
|
22
49
|
}
|
|
23
50
|
|
package/src/blocks/text/text.jsx
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
function Video(props) {
|
|
2
|
-
|
|
2
|
+
function videoProps() {
|
|
3
|
+
return { ...(props.autoPlay === true ? {
|
|
4
|
+
autoPlay: true
|
|
5
|
+
} : {}),
|
|
6
|
+
...(props.muted === true ? {
|
|
7
|
+
muted: true
|
|
8
|
+
} : {}),
|
|
9
|
+
...(props.controls === true ? {
|
|
10
|
+
controls: true
|
|
11
|
+
} : {}),
|
|
12
|
+
...(props.loop === true ? {
|
|
13
|
+
loop: true
|
|
14
|
+
} : {}),
|
|
15
|
+
...(props.playsInline === true ? {
|
|
16
|
+
playsInline: true
|
|
17
|
+
} : {})
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return <video {...videoProps()} style={{
|
|
3
22
|
width: "100%",
|
|
4
23
|
height: "100%",
|
|
5
24
|
...props.attributes?.style,
|
|
@@ -8,7 +27,7 @@ function Video(props) {
|
|
|
8
27
|
// Hack to get object fit to work as expected and
|
|
9
28
|
// not have the video overflow
|
|
10
29
|
"border-radius": 1
|
|
11
|
-
}}
|
|
30
|
+
}} src={props.video || "no-src"} poster={props.posterImage}></video>;
|
|
12
31
|
}
|
|
13
32
|
|
|
14
33
|
export default Video;
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
3
|
+
import { TARGET } from "../../constants/target.js";
|
|
4
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
5
|
+
import { createCssClass } from "../../helpers/css.js";
|
|
6
|
+
import RenderInlinedStyles from "../render-inlined-styles.jsx";
|
|
3
7
|
|
|
4
8
|
function BlockStyles(props) {
|
|
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
|
-
|
|
9
|
+
function useBlock() {
|
|
10
|
+
return getProcessedBlock({
|
|
11
|
+
block: props.block,
|
|
12
|
+
state: props.context.state,
|
|
13
|
+
context: props.context.context,
|
|
14
|
+
shouldEvaluateBindings: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function css() {
|
|
19
|
+
const styles = useBlock().responsiveStyles;
|
|
20
|
+
const largeStyles = styles?.large;
|
|
21
|
+
const mediumStyles = styles?.medium;
|
|
22
|
+
const smallStyles = styles?.small;
|
|
23
|
+
const className = useBlock().id;
|
|
24
|
+
const largeStylesClass = largeStyles ? createCssClass({
|
|
25
|
+
className,
|
|
26
|
+
styles: largeStyles
|
|
27
|
+
}) : "";
|
|
28
|
+
const mediumStylesClass = mediumStyles ? createCssClass({
|
|
29
|
+
className,
|
|
30
|
+
styles: mediumStyles,
|
|
31
|
+
mediaQuery: getMaxWidthQueryForSize("medium")
|
|
32
|
+
}) : "";
|
|
33
|
+
const smallStylesClass = smallStyles ? createCssClass({
|
|
34
|
+
className,
|
|
35
|
+
styles: smallStyles,
|
|
36
|
+
mediaQuery: getMaxWidthQueryForSize("small")
|
|
37
|
+
}) : "";
|
|
38
|
+
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return <Show when={TARGET !== "reactNative" && css()}>
|
|
42
|
+
<RenderInlinedStyles styles={css()}></RenderInlinedStyles>
|
|
43
|
+
</Show>;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
export default BlockStyles;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const EMPTY_HTML_ELEMENTS = [
|
|
2
|
+
"area",
|
|
3
|
+
"base",
|
|
4
|
+
"br",
|
|
5
|
+
"col",
|
|
6
|
+
"embed",
|
|
7
|
+
"hr",
|
|
8
|
+
"img",
|
|
9
|
+
"input",
|
|
10
|
+
"keygen",
|
|
11
|
+
"link",
|
|
12
|
+
"meta",
|
|
13
|
+
"param",
|
|
14
|
+
"source",
|
|
15
|
+
"track",
|
|
16
|
+
"wbr"
|
|
17
|
+
];
|
|
18
|
+
const isEmptyHtmlElement = (tagName) => {
|
|
19
|
+
return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
isEmptyHtmlElement
|
|
23
|
+
};
|
|
@@ -1,117 +1,232 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Show, For } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
import { TARGET } from "../../constants/target.js";
|
|
5
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
6
3
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
7
4
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
8
5
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
9
6
|
import { getBlockStyles } from "../../functions/get-block-styles.js";
|
|
10
7
|
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
11
8
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
12
|
-
import {
|
|
13
|
-
import BlockStyles from "./block-styles.
|
|
9
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
10
|
+
import BlockStyles from "./block-styles.jsx";
|
|
11
|
+
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
12
|
+
import RenderRepeatedBlock from "./render-repeated-block.jsx";
|
|
13
|
+
import { TARGET } from "../../constants/target.js";
|
|
14
|
+
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
15
|
+
import RenderComponentWithContext from "./render-component-with-context.jsx";
|
|
16
|
+
import RenderComponent from "./render-component.jsx";
|
|
14
17
|
|
|
15
18
|
function RenderBlock(props) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
function component() {
|
|
20
|
+
const componentName = getProcessedBlock({
|
|
21
|
+
block: props.block,
|
|
22
|
+
state: props.context.state,
|
|
23
|
+
context: props.context.context,
|
|
24
|
+
shouldEvaluateBindings: false
|
|
25
|
+
}).component?.name;
|
|
26
|
+
|
|
27
|
+
if (!componentName) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
23
30
|
|
|
24
|
-
|
|
31
|
+
const ref = props.context.registeredComponents[componentName];
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if (!ref) {
|
|
34
|
+
// TODO: Public doc page with more info about this message
|
|
35
|
+
console.warn(`
|
|
29
36
|
Could not find a registered component named "${componentName}".
|
|
30
37
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
return undefined;
|
|
39
|
+
} else {
|
|
33
40
|
return ref;
|
|
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
|
-
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function tagName() {
|
|
45
|
+
return getBlockTag(useBlock());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function useBlock() {
|
|
49
|
+
return repeatItemData() ? props.block : getProcessedBlock({
|
|
50
|
+
block: props.block,
|
|
51
|
+
state: props.context.state,
|
|
52
|
+
context: props.context.context,
|
|
53
|
+
shouldEvaluateBindings: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function attributes() {
|
|
58
|
+
return { ...getBlockProperties(useBlock()),
|
|
59
|
+
...getBlockActions({
|
|
60
|
+
block: useBlock(),
|
|
61
|
+
state: props.context.state,
|
|
62
|
+
context: props.context.context
|
|
63
|
+
}),
|
|
64
|
+
style: getBlockStyles({
|
|
65
|
+
block: useBlock(),
|
|
66
|
+
context: props.context
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function shouldWrap() {
|
|
72
|
+
return !component()?.noWrap;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function renderComponentProps() {
|
|
76
|
+
return {
|
|
77
|
+
blockChildren: children(),
|
|
78
|
+
componentRef: component()?.component,
|
|
79
|
+
componentOptions: { ...getBlockComponentOptions(useBlock()),
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
83
|
+
* they are provided to the component itself directly.
|
|
84
|
+
*/
|
|
85
|
+
...(shouldWrap() ? {} : {
|
|
86
|
+
attributes: attributes()
|
|
62
87
|
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
},
|
|
89
|
+
context: childrenContext()
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function children() {
|
|
94
|
+
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
95
|
+
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
96
|
+
// but still receive and need to render children.
|
|
97
|
+
// return componentInfo?.canHaveChildren ? useBlock().children : [];
|
|
98
|
+
return useBlock().children ?? [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function childrenWithoutParentComponent() {
|
|
102
|
+
/**
|
|
103
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
104
|
+
* we render them outside of `componentRef`.
|
|
105
|
+
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
106
|
+
* blocks, and the children will be repeated within those blocks.
|
|
107
|
+
*/
|
|
108
|
+
const shouldRenderChildrenOutsideRef = !component()?.component && !repeatItemData();
|
|
109
|
+
return shouldRenderChildrenOutsideRef ? children() : [];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function repeatItemData() {
|
|
113
|
+
/**
|
|
114
|
+
* we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
|
|
115
|
+
* which will not work if there is a repeat.
|
|
116
|
+
*/
|
|
117
|
+
const {
|
|
118
|
+
repeat,
|
|
119
|
+
...blockWithoutRepeat
|
|
120
|
+
} = props.block;
|
|
121
|
+
|
|
122
|
+
if (!repeat?.collection) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const itemsArray = evaluate({
|
|
127
|
+
code: repeat.collection,
|
|
128
|
+
state: props.context.state,
|
|
129
|
+
context: props.context.context
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (!Array.isArray(itemsArray)) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
137
|
+
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
138
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
139
|
+
context: { ...props.context,
|
|
140
|
+
state: { ...props.context.state,
|
|
141
|
+
$index: index,
|
|
142
|
+
$item: item,
|
|
143
|
+
[itemNameToUse]: item,
|
|
144
|
+
[`$${itemNameToUse}Index`]: index
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
block: blockWithoutRepeat
|
|
148
|
+
}));
|
|
149
|
+
return repeatArray;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function inheritedTextStyles() {
|
|
153
|
+
if (TARGET !== "reactNative") {
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const styles = getBlockStyles({
|
|
158
|
+
block: useBlock(),
|
|
159
|
+
context: props.context
|
|
160
|
+
});
|
|
161
|
+
return extractTextStyles(styles);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function childrenContext() {
|
|
165
|
+
return {
|
|
166
|
+
apiKey: props.context.apiKey,
|
|
167
|
+
state: props.context.state,
|
|
168
|
+
content: props.context.content,
|
|
169
|
+
context: props.context.context,
|
|
170
|
+
registeredComponents: props.context.registeredComponents,
|
|
171
|
+
inheritedStyles: inheritedTextStyles()
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderComponentTag() {
|
|
176
|
+
if (TARGET === "reactNative") {
|
|
177
|
+
return RenderComponentWithContext;
|
|
178
|
+
} else if (TARGET === "vue3") {
|
|
179
|
+
// vue3 expects a string for the component tag
|
|
180
|
+
return "RenderComponent";
|
|
181
|
+
} else {
|
|
182
|
+
return RenderComponent;
|
|
84
183
|
}
|
|
184
|
+
}
|
|
85
185
|
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
186
|
+
return <Show fallback={<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>} when={shouldWrap()}>
|
|
187
|
+
<Show when={isEmptyHtmlElement(tagName())}>
|
|
188
|
+
<Dynamic {...attributes()} component={tagName()}></Dynamic>
|
|
189
|
+
</Show>
|
|
190
|
+
<Show when={!isEmptyHtmlElement(tagName()) && TARGET === "vue2" && repeatItemData()}>
|
|
191
|
+
<div class="vue2-root-element-workaround">
|
|
192
|
+
<For each={repeatItemData()}>
|
|
193
|
+
{(data, _index) => {
|
|
194
|
+
const index = _index();
|
|
195
|
+
|
|
196
|
+
return <RenderRepeatedBlock key={index} repeatContext={data.context} block={data.block}></RenderRepeatedBlock>;
|
|
197
|
+
}}
|
|
198
|
+
</For>
|
|
199
|
+
</div>
|
|
200
|
+
</Show>
|
|
201
|
+
<Show when={!isEmptyHtmlElement(tagName()) && TARGET !== "vue2" && repeatItemData()}>
|
|
202
|
+
<For each={repeatItemData()}>
|
|
203
|
+
{(data, _index) => {
|
|
204
|
+
const index = _index();
|
|
205
|
+
|
|
206
|
+
return <RenderRepeatedBlock key={index} repeatContext={data.context} block={data.block}></RenderRepeatedBlock>;
|
|
207
|
+
}}
|
|
208
|
+
</For>
|
|
209
|
+
</Show>
|
|
210
|
+
<Show when={!isEmptyHtmlElement(tagName()) && !repeatItemData()}>
|
|
211
|
+
<Dynamic {...attributes()} component={tagName()}>
|
|
212
|
+
<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>
|
|
213
|
+
<For each={childrenWithoutParentComponent()}>
|
|
214
|
+
{(child, _index) => {
|
|
215
|
+
const index = _index();
|
|
216
|
+
|
|
217
|
+
return <RenderBlock key={"render-block-" + child.id} block={child} context={childrenContext()}></RenderBlock>;
|
|
218
|
+
}}
|
|
219
|
+
</For>
|
|
220
|
+
<For each={childrenWithoutParentComponent()}>
|
|
106
221
|
{(child, _index) => {
|
|
107
222
|
const index = _index();
|
|
108
223
|
|
|
109
|
-
return <
|
|
224
|
+
return <BlockStyles key={"block-style-" + child.id} block={child} context={childrenContext()}></BlockStyles>;
|
|
110
225
|
}}
|
|
111
226
|
</For>
|
|
112
227
|
</Dynamic>
|
|
113
228
|
</Show>
|
|
114
|
-
|
|
229
|
+
</Show>;
|
|
115
230
|
}
|
|
116
231
|
|
|
117
232
|
export default RenderBlock;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Dynamic } from "solid-js/web";
|
|
2
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
3
|
+
import RenderComponent from "./render-component.jsx";
|
|
4
|
+
|
|
5
|
+
function RenderComponentWithContext(props) {
|
|
6
|
+
return <Dynamic value={{
|
|
7
|
+
get content() {
|
|
8
|
+
return props.context.content;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
get state() {
|
|
12
|
+
return props.context.state;
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
get context() {
|
|
16
|
+
return props.context.context;
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
get apiKey() {
|
|
20
|
+
return props.context.apiKey;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
get registeredComponents() {
|
|
24
|
+
return props.context.registeredComponents;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
get inheritedStyles() {
|
|
28
|
+
return props.context.inheritedStyles;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}} component={BuilderContext.Provider}>
|
|
32
|
+
<RenderComponent {...props}></RenderComponent>
|
|
33
|
+
</Dynamic>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default RenderComponentWithContext;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Show, For } from "solid-js";
|
|
2
|
+
import { Dynamic } from "solid-js/web";
|
|
3
|
+
import BlockStyles from "./block-styles.jsx";
|
|
4
|
+
import RenderBlock from "./render-block.jsx";
|
|
5
|
+
import { markPropsMutable } from "../../functions/mark-mutable.js";
|
|
6
|
+
|
|
7
|
+
function RenderComponent(props) {
|
|
8
|
+
return <Show when={props.componentRef}>
|
|
9
|
+
<Dynamic {...markPropsMutable(props.componentOptions)} component={props.componentRef}>
|
|
10
|
+
<For each={props.blockChildren}>
|
|
11
|
+
{(child, _index) => {
|
|
12
|
+
const index = _index();
|
|
13
|
+
|
|
14
|
+
return <RenderBlock key={"render-block-" + child.id} block={child} context={props.context}></RenderBlock>;
|
|
15
|
+
}}
|
|
16
|
+
</For>
|
|
17
|
+
<For each={props.blockChildren}>
|
|
18
|
+
{(child, _index) => {
|
|
19
|
+
const index = _index();
|
|
20
|
+
|
|
21
|
+
return <BlockStyles key={"block-style-" + child.id} block={child} context={props.context}></BlockStyles>;
|
|
22
|
+
}}
|
|
23
|
+
</For>
|
|
24
|
+
</Dynamic>
|
|
25
|
+
</Show>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default RenderComponent;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Dynamic } from "solid-js/web";
|
|
2
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
3
|
+
import RenderBlock from "./render-block.jsx";
|
|
4
|
+
|
|
5
|
+
function RenderRepeatedBlock(props) {
|
|
6
|
+
return <Dynamic value={{
|
|
7
|
+
get content() {
|
|
8
|
+
return props.repeatContext.content;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
get state() {
|
|
12
|
+
return props.repeatContext.state;
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
get context() {
|
|
16
|
+
return props.repeatContext.context;
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
get apiKey() {
|
|
20
|
+
return props.repeatContext.apiKey;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
get registeredComponents() {
|
|
24
|
+
return props.repeatContext.registeredComponents;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
get inheritedStyles() {
|
|
28
|
+
return props.repeatContext.inheritedStyles;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}} component={BuilderContext.Provider}>
|
|
32
|
+
<RenderBlock block={props.block} context={props.repeatContext}></RenderBlock>
|
|
33
|
+
</Dynamic>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default RenderRepeatedBlock;
|
|
File without changes
|