@builder.io/sdk-solid 0.0.16 → 0.0.18
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 +43 -14
- 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 +38 -38
- 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,53 +1,62 @@
|
|
|
1
|
-
import { Show, For } from "solid-js";
|
|
2
|
-
import { createMutable } from "solid-js/store";
|
|
1
|
+
import { useContext, Show, For } from "solid-js";
|
|
3
2
|
import { css } from "solid-styled-components";
|
|
3
|
+
import BuilderContext from "../context/builder.context.js";
|
|
4
4
|
import { isEditing } from "../functions/is-editing.js";
|
|
5
|
-
import
|
|
5
|
+
import BlockStyles from "./render-block/block-styles.jsx";
|
|
6
|
+
import RenderBlock from "./render-block/render-block.jsx";
|
|
6
7
|
|
|
7
8
|
function RenderBlocks(props) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
9
|
+
function className() {
|
|
10
|
+
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
function onClick() {
|
|
14
|
+
if (isEditing() && !props.blocks?.length) {
|
|
15
|
+
window.parent?.postMessage({
|
|
16
|
+
type: "builder.clickEmptyBlocks",
|
|
17
|
+
data: {
|
|
18
|
+
parentElementId: props.parent,
|
|
19
|
+
dataPath: props.path
|
|
20
|
+
}
|
|
21
|
+
}, "*");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
25
|
+
function onMouseEnter() {
|
|
26
|
+
if (isEditing() && !props.blocks?.length) {
|
|
27
|
+
window.parent?.postMessage({
|
|
28
|
+
type: "builder.hoverEmptyBlocks",
|
|
29
|
+
data: {
|
|
30
|
+
parentElementId: props.parent,
|
|
31
|
+
dataPath: props.path
|
|
32
|
+
}
|
|
33
|
+
}, "*");
|
|
35
34
|
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
return <div class={
|
|
37
|
+
const builderContext = useContext(BuilderContext);
|
|
38
|
+
return <div class={className() + " " + css({
|
|
39
39
|
display: "flex",
|
|
40
40
|
flexDirection: "column",
|
|
41
41
|
alignItems: "stretch"
|
|
42
42
|
})} builder-path={props.path} builder-parent-id={props.parent} dataSet={{
|
|
43
|
-
class:
|
|
44
|
-
}} onClick={event =>
|
|
43
|
+
class: className()
|
|
44
|
+
}} style={props.style} onClick={event => onClick()} onMouseEnter={event => onMouseEnter()}>
|
|
45
|
+
<Show when={props.blocks}>
|
|
46
|
+
<For each={props.blocks}>
|
|
47
|
+
{(block, _index) => {
|
|
48
|
+
const index = _index();
|
|
49
|
+
|
|
50
|
+
return <RenderBlock key={"render-block-" + block.id} block={block} context={builderContext}></RenderBlock>;
|
|
51
|
+
}}
|
|
52
|
+
</For>
|
|
53
|
+
</Show>
|
|
45
54
|
<Show when={props.blocks}>
|
|
46
55
|
<For each={props.blocks}>
|
|
47
56
|
{(block, _index) => {
|
|
48
57
|
const index = _index();
|
|
49
58
|
|
|
50
|
-
return <
|
|
59
|
+
return <BlockStyles key={"block-style-" + block.id} block={block} context={builderContext}></BlockStyles>;
|
|
51
60
|
}}
|
|
52
61
|
</For>
|
|
53
62
|
</Show>
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import RenderInlinedStyles from "../../render-inlined-styles.js";
|
|
1
|
+
import RenderInlinedStyles from "../../render-inlined-styles.jsx";
|
|
3
2
|
|
|
4
3
|
function RenderContentStyles(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let str = "";
|
|
4
|
+
function getCssFromFont(font) {
|
|
5
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
6
|
+
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
7
|
+
const name = family.split(",")[0];
|
|
8
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
9
|
+
let str = "";
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
if (url && family && name) {
|
|
12
|
+
str += `
|
|
15
13
|
@font-face {
|
|
16
14
|
font-family: "${family}";
|
|
17
15
|
src: local("${name}"), url('${url}') format('woff2');
|
|
@@ -19,21 +17,21 @@ function RenderContentStyles(props) {
|
|
|
19
17
|
font-weight: 400;
|
|
20
18
|
}
|
|
21
19
|
`.trim();
|
|
22
|
-
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (font.files) {
|
|
23
|
+
for (const weight in font.files) {
|
|
24
|
+
const isNumber = String(Number(weight)) === weight;
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (!isNumber) {
|
|
27
|
+
continue;
|
|
28
|
+
} // TODO: maybe limit number loaded
|
|
31
29
|
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
const weightUrl = font.files[weight];
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (weightUrl && weightUrl !== url) {
|
|
34
|
+
str += `
|
|
37
35
|
@font-face {
|
|
38
36
|
font-family: "${family}";
|
|
39
37
|
src: url('${weightUrl}') format('woff2');
|
|
@@ -41,34 +39,33 @@ function RenderContentStyles(props) {
|
|
|
41
39
|
font-weight: ${weight};
|
|
42
40
|
}
|
|
43
41
|
`.trim();
|
|
44
|
-
}
|
|
45
42
|
}
|
|
46
43
|
}
|
|
44
|
+
}
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
return str;
|
|
47
|
+
}
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
function getFontCss({
|
|
50
|
+
customFonts
|
|
51
|
+
}) {
|
|
52
|
+
// TODO: flag for this
|
|
53
|
+
// if (!this.builder.allowCustomFonts) {
|
|
54
|
+
// return '';
|
|
55
|
+
// }
|
|
56
|
+
// TODO: separate internal data from external
|
|
57
|
+
return customFonts?.map(font => this.getCssFromFont(font))?.join(" ") || "";
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
function injectedStyles() {
|
|
61
|
+
return `
|
|
64
62
|
${props.cssCode || ""}
|
|
65
|
-
${
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
${getFontCss({
|
|
64
|
+
customFonts: props.customFonts
|
|
65
|
+
})}`;
|
|
66
|
+
}
|
|
69
67
|
|
|
70
|
-
}
|
|
71
|
-
return <RenderInlinedStyles styles={state.injectedStyles}></RenderInlinedStyles>;
|
|
68
|
+
return <RenderInlinedStyles styles={injectedStyles()}></RenderInlinedStyles>;
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
export default RenderContentStyles;
|
|
@@ -1,208 +1,279 @@
|
|
|
1
|
-
import { Show, onMount } from "solid-js";
|
|
1
|
+
import { Show, onMount, on, createEffect, createSignal } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import {
|
|
3
|
+
import { createStore, reconcile } from "solid-js/store";
|
|
4
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
4
5
|
import { TARGET } from "../../constants/target.js";
|
|
5
6
|
import BuilderContext from "../../context/builder.context.js";
|
|
6
7
|
import { evaluate } from "../../functions/evaluate.js";
|
|
7
|
-
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from "../../functions/get-builder-search-params/index.js";
|
|
8
8
|
import { getContent } from "../../functions/get-content/index.js";
|
|
9
9
|
import { getFetch } from "../../functions/get-fetch.js";
|
|
10
10
|
import { isBrowser } from "../../functions/is-browser.js";
|
|
11
11
|
import { isEditing } from "../../functions/is-editing.js";
|
|
12
12
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
13
|
-
import {
|
|
13
|
+
import { components, createRegisterComponentMessage } from "../../functions/register-component.js";
|
|
14
14
|
import { track } from "../../functions/track.js";
|
|
15
|
-
import RenderBlocks from "../render-blocks.
|
|
16
|
-
import RenderContentStyles from "./components/render-styles.
|
|
15
|
+
import RenderBlocks from "../render-blocks.jsx";
|
|
16
|
+
import RenderContentStyles from "./components/render-styles.jsx";
|
|
17
|
+
import { registerInsertMenu, setupBrowserForEditing } from "../../scripts/init-editing.js";
|
|
18
|
+
import { markMutable } from "../../functions/mark-mutable.js";
|
|
17
19
|
|
|
18
20
|
function RenderContent(props) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
data: { ...props.content?.data,
|
|
24
|
-
...props.data,
|
|
25
|
-
...state.overrideContent?.data
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
return mergedContent;
|
|
29
|
-
},
|
|
21
|
+
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
22
|
+
const [overrideContent, setOverrideContent] = createSignal(null);
|
|
23
|
+
const [update, setUpdate] = createSignal(0);
|
|
24
|
+
const [overrideState, setOverrideState] = createSignal({});
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
function canTrackToUse() {
|
|
27
|
+
return props.canTrack || true;
|
|
28
|
+
}
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
function contentState() {
|
|
31
|
+
return { ...props.content?.data?.state,
|
|
32
|
+
...props.data,
|
|
33
|
+
...overrideState()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
function contextContext() {
|
|
38
|
+
return props.context || {};
|
|
39
|
+
}
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (key === props.model) {
|
|
60
|
-
state.overrideContent = contentData;
|
|
61
|
-
}
|
|
41
|
+
function allRegisteredComponents() {
|
|
42
|
+
const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
43
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
44
|
+
// existing usage.
|
|
45
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
46
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
47
|
+
...components, ...(props.customComponents || [])];
|
|
48
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,
|
|
49
|
+
[curr.name]: curr
|
|
50
|
+
}), {});
|
|
51
|
+
return allComponents;
|
|
52
|
+
}
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
function processMessage(event) {
|
|
55
|
+
const {
|
|
56
|
+
data
|
|
57
|
+
} = event;
|
|
58
|
+
|
|
59
|
+
if (data) {
|
|
60
|
+
switch (data.type) {
|
|
61
|
+
case "builder.contentUpdate":
|
|
62
|
+
{
|
|
63
|
+
const messageContent = data.data;
|
|
64
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
65
|
+
const contentData = messageContent.data;
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
break;
|
|
67
|
+
if (key === props.model) {
|
|
68
|
+
setOverrideContent(contentData);
|
|
69
|
+
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
70
70
|
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const jsCode = state.useContent?.data?.jsCode;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
75
|
+
case "builder.patchUpdates":
|
|
76
|
+
{
|
|
77
|
+
// TODO
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
85
80
|
}
|
|
86
|
-
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
function evaluateJsCode() {
|
|
85
|
+
// run any dynamic JS code attached to content
|
|
86
|
+
const jsCode = useContent?.data?.jsCode;
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
code:
|
|
95
|
-
context:
|
|
96
|
-
state:
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
handleRequest({
|
|
101
|
-
url,
|
|
102
|
-
key
|
|
103
|
-
}) {
|
|
104
|
-
const fetchAndSetState = async () => {
|
|
105
|
-
const fetch = await getFetch();
|
|
106
|
-
const response = await fetch(url);
|
|
107
|
-
const json = await response.json();
|
|
108
|
-
const newOverrideState = { ...state.overrideState,
|
|
109
|
-
[key]: json
|
|
110
|
-
};
|
|
111
|
-
state.overrideState = newOverrideState;
|
|
112
|
-
};
|
|
88
|
+
if (jsCode) {
|
|
89
|
+
evaluate({
|
|
90
|
+
code: jsCode,
|
|
91
|
+
context: contextContext(),
|
|
92
|
+
state: contentState()
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
113
96
|
|
|
114
|
-
|
|
115
|
-
}
|
|
97
|
+
function httpReqsData() {
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
116
100
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
key
|
|
125
|
-
});
|
|
126
|
-
}
|
|
101
|
+
function onClick(_event) {
|
|
102
|
+
if (useContent) {
|
|
103
|
+
track({
|
|
104
|
+
type: "click",
|
|
105
|
+
canTrack: canTrackToUse(),
|
|
106
|
+
contentId: useContent?.id,
|
|
107
|
+
orgId: props.apiKey
|
|
127
108
|
});
|
|
128
|
-
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function evalExpression(expression) {
|
|
113
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
114
|
+
code: group,
|
|
115
|
+
context: contextContext(),
|
|
116
|
+
state: contentState()
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function handleRequest({
|
|
121
|
+
url,
|
|
122
|
+
key
|
|
123
|
+
}) {
|
|
124
|
+
getFetch().then(fetch => fetch(url)).then(response => response.json()).then(json => {
|
|
125
|
+
const newOverrideState = { ...overrideState(),
|
|
126
|
+
[key]: json
|
|
127
|
+
};
|
|
128
|
+
setOverrideState(newOverrideState);
|
|
129
|
+
}).catch(err => {
|
|
130
|
+
console.log("error fetching dynamic data", url, err);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function runHttpRequests() {
|
|
135
|
+
const requests = useContent?.data?.httpRequests ?? {};
|
|
136
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
137
|
+
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
138
|
+
const evaluatedUrl = evalExpression(url);
|
|
139
|
+
handleRequest({
|
|
140
|
+
url: evaluatedUrl,
|
|
141
|
+
key
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
129
146
|
|
|
130
|
-
|
|
147
|
+
function emitStateUpdate() {
|
|
148
|
+
if (isEditing()) {
|
|
131
149
|
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
132
150
|
detail: {
|
|
133
|
-
state:
|
|
151
|
+
state: contentState(),
|
|
134
152
|
ref: {
|
|
135
153
|
name: props.model
|
|
136
154
|
}
|
|
137
155
|
}
|
|
138
156
|
}));
|
|
139
157
|
}
|
|
158
|
+
}
|
|
140
159
|
|
|
141
|
-
|
|
160
|
+
function shouldRenderContentStyles() {
|
|
161
|
+
return Boolean((useContent?.data?.cssCode || useContent?.data?.customFonts?.length) && TARGET !== "reactNative");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const updateUseContent = function useContent() {
|
|
165
|
+
if (!props.content && !overrideContent()) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const mergedContent = { ...props.content,
|
|
170
|
+
...overrideContent(),
|
|
171
|
+
data: { ...props.content?.data,
|
|
172
|
+
...props.data,
|
|
173
|
+
...overrideContent()?.data
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
return mergedContent;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const [useContent, setUseContent] = createStore(updateUseContent());
|
|
180
|
+
createEffect(on(() => [overrideContent(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
|
|
181
|
+
let elementRef;
|
|
142
182
|
onMount(() => {
|
|
143
183
|
if (isBrowser()) {
|
|
144
184
|
if (isEditing()) {
|
|
145
|
-
|
|
146
|
-
|
|
185
|
+
setForceReRenderCount(forceReRenderCount() + 1); // QWIK-REPLACE: _useMutableProps
|
|
186
|
+
|
|
187
|
+
registerInsertMenu();
|
|
188
|
+
setupBrowserForEditing();
|
|
189
|
+
Object.values(allRegisteredComponents()).forEach(registeredComponent => {
|
|
190
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
191
|
+
window.parent?.postMessage(message, "*");
|
|
192
|
+
});
|
|
193
|
+
window.addEventListener("message", processMessage);
|
|
194
|
+
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
147
195
|
}
|
|
148
196
|
|
|
149
|
-
if (
|
|
150
|
-
track(
|
|
151
|
-
|
|
197
|
+
if (useContent) {
|
|
198
|
+
track({
|
|
199
|
+
type: "impression",
|
|
200
|
+
canTrack: canTrackToUse(),
|
|
201
|
+
contentId: useContent?.id,
|
|
202
|
+
orgId: props.apiKey
|
|
152
203
|
});
|
|
153
204
|
} // override normal content in preview mode
|
|
154
205
|
|
|
155
206
|
|
|
156
207
|
if (isPreviewing()) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
208
|
+
const searchParams = new URL(location.href).searchParams;
|
|
209
|
+
|
|
210
|
+
if (props.model && searchParams.get("builder.preview") === props.model) {
|
|
211
|
+
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
160
212
|
|
|
161
213
|
if (previewApiKey) {
|
|
162
214
|
getContent({
|
|
163
215
|
model: props.model,
|
|
164
|
-
apiKey: previewApiKey
|
|
165
|
-
options: getBuilderSearchParams(convertSearchParamsToQueryObject(currentUrl.searchParams))
|
|
216
|
+
apiKey: previewApiKey
|
|
166
217
|
}).then(content => {
|
|
167
218
|
if (content) {
|
|
168
|
-
|
|
219
|
+
setOverrideContent(content);
|
|
169
220
|
}
|
|
170
221
|
});
|
|
171
222
|
}
|
|
172
223
|
}
|
|
173
224
|
}
|
|
174
225
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
226
|
+
evaluateJsCode();
|
|
227
|
+
runHttpRequests();
|
|
228
|
+
emitStateUpdate();
|
|
178
229
|
}
|
|
179
230
|
});
|
|
231
|
+
|
|
232
|
+
function onUpdateFn_0() {
|
|
233
|
+
evaluateJsCode();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
createEffect(on(() => [useContent?.data?.jsCode], onUpdateFn_0));
|
|
237
|
+
|
|
238
|
+
function onUpdateFn_1() {
|
|
239
|
+
runHttpRequests();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
createEffect(on(() => [useContent?.data?.httpRequests], onUpdateFn_1));
|
|
243
|
+
|
|
244
|
+
function onUpdateFn_2() {
|
|
245
|
+
emitStateUpdate();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
createEffect(on(() => [contentState()], onUpdateFn_2));
|
|
180
249
|
return <Dynamic value={{
|
|
181
250
|
get content() {
|
|
182
|
-
return
|
|
251
|
+
return useContent;
|
|
183
252
|
},
|
|
184
253
|
|
|
185
254
|
get state() {
|
|
186
|
-
return
|
|
255
|
+
return contentState();
|
|
187
256
|
},
|
|
188
257
|
|
|
189
258
|
get context() {
|
|
190
|
-
return
|
|
259
|
+
return contextContext();
|
|
191
260
|
},
|
|
192
261
|
|
|
193
262
|
get apiKey() {
|
|
194
263
|
return props.apiKey;
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
get registeredComponents() {
|
|
267
|
+
return allRegisteredComponents();
|
|
195
268
|
}
|
|
196
269
|
|
|
197
270
|
}} component={BuilderContext.Provider}>
|
|
198
|
-
<Show when={
|
|
199
|
-
<div onClick={event =>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
<Show when={(state.useContent?.data?.cssCode || state.useContent?.data?.customFonts?.length) && TARGET !== "reactNative"}>
|
|
203
|
-
<RenderContentStyles cssCode={state.useContent.data.cssCode} customFonts={state.useContent.data.customFonts}></RenderContentStyles>
|
|
271
|
+
<Show when={useContent}>
|
|
272
|
+
<div ref={elementRef} onClick={event => onClick(event)} builder-content-id={useContent?.id}>
|
|
273
|
+
<Show when={shouldRenderContentStyles()}>
|
|
274
|
+
<RenderContentStyles cssCode={useContent?.data?.cssCode} customFonts={useContent?.data?.customFonts}></RenderContentStyles>
|
|
204
275
|
</Show>
|
|
205
|
-
<RenderBlocks blocks={
|
|
276
|
+
<RenderBlocks blocks={markMutable(useContent?.data?.blocks)} key={forceReRenderCount()}></RenderBlocks>
|
|
206
277
|
</div>
|
|
207
278
|
</Show>
|
|
208
279
|
</Dynamic>;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
import { Dynamic } from "solid-js/web";
|
|
3
|
+
import { TARGET } from "../constants/target.js";
|
|
4
|
+
|
|
5
|
+
function RenderInlinedStyles(props) {
|
|
6
|
+
function injectedStyleScript() {
|
|
7
|
+
return `<${tagName()}>${props.styles}</${tagName()}>`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function 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
|
+
|
|
16
|
+
return <Show fallback={<Dynamic component={tagName()}>{props.styles}</Dynamic>} when={TARGET === "svelte"}>
|
|
17
|
+
<div innerHTML={injectedStyleScript()}></div>
|
|
18
|
+
</Show>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default RenderInlinedStyles;
|