@builder.io/sdk-qwik 0.0.8 → 0.0.11
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 +65 -2
- package/lib/index.qwik.cjs +259 -216
- package/lib/index.qwik.mjs +260 -217
- package/package.json +4 -4
- package/src/blocks/button/button.jsx +22 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/columns/columns.jsx +97 -0
- package/src/blocks/columns/component-info.js +242 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/custom-code/custom-code.jsx +71 -0
- package/src/blocks/embed/component-info.js +44 -0
- package/src/blocks/embed/embed.jsx +63 -0
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/builder-blocks.jsx +11 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/form/form.jsx +303 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.jsx +11 -0
- package/src/blocks/image/component-info.js +151 -0
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +110 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.jsx +19 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/input.jsx +21 -0
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/raw-text.jsx +12 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/section.jsx +20 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/select.jsx +24 -0
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/submit-button.jsx +11 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.jsx +77 -0
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/text.jsx +7 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/textarea.jsx +15 -0
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/video.jsx +53 -0
- package/src/components/render-block/block-styles.jsx +60 -0
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +221 -0
- package/src/components/render-block/render-component.jsx +34 -0
- package/src/components/render-block/render-repeated-block.jsx +37 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +93 -0
- package/src/components/render-content/components/render-styles.jsx +76 -0
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +351 -0
- package/src/components/render-inlined-styles.jsx +25 -0
- package/src/constants/builder-registered-components.js +48 -0
- package/src/constants/device-sizes.js +21 -0
- package/src/constants/target.js +4 -0
- package/src/context/builder.context.js +5 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/evaluate.js +28 -0
- package/src/functions/event-handler-name.js +7 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +28 -0
- package/src/functions/get-block-properties.js +29 -0
- package/src/functions/get-block-styles.js +34 -0
- package/src/functions/get-block-tag.js +6 -0
- package/src/functions/get-builder-search-params/fn.test.js +13 -0
- package/src/functions/get-builder-search-params/index.js +33 -0
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +31 -0
- package/src/functions/get-content/index.js +96 -0
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +34 -0
- package/src/functions/get-global-this.js +18 -0
- package/src/functions/get-processed-block.js +53 -0
- package/src/functions/get-processed-block.test.js +32 -0
- package/src/functions/if-target.js +15 -0
- package/src/functions/is-browser.js +6 -0
- package/src/functions/is-editing.js +7 -0
- package/src/functions/is-iframe.js +7 -0
- package/src/functions/is-previewing.js +14 -0
- package/src/functions/on-change.js +27 -0
- package/src/functions/on-change.test.js +19 -0
- package/src/functions/register-component.js +72 -0
- package/src/functions/register.js +29 -0
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/set-editor-settings.js +15 -0
- package/src/functions/set.js +11 -0
- package/src/functions/set.test.js +16 -0
- package/src/functions/track.js +22 -0
- package/src/functions/transform-block.js +6 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/index-helpers/blocks-exports.js +22 -0
- package/src/index-helpers/top-of-file.js +4 -0
- package/src/index.js +10 -0
- package/src/scripts/init-editing.js +79 -0
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/element.js +0 -0
- package/src/types/targets.js +0 -0
- package/src/types/typescript.js +0 -0
- package/types.d.ts +7 -12
- package/root.json +0 -1176
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import BlockStyles from "./block-styles";
|
|
4
|
+
import RenderBlock from "./render-block";
|
|
5
|
+
import { Fragment, h } from "@builder.io/qwik";
|
|
6
|
+
export const RenderComponent = (props) => {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
{props.componentRef ? (
|
|
10
|
+
<props.componentRef {...props.componentOptions}>
|
|
11
|
+
{(props.blockChildren || []).map((child) => {
|
|
12
|
+
return (
|
|
13
|
+
<RenderBlock
|
|
14
|
+
key={"render-block-" + child.id}
|
|
15
|
+
block={child}
|
|
16
|
+
context={props.context}
|
|
17
|
+
></RenderBlock>
|
|
18
|
+
);
|
|
19
|
+
})}
|
|
20
|
+
{(props.blockChildren || []).map((child) => {
|
|
21
|
+
return (
|
|
22
|
+
<BlockStyles
|
|
23
|
+
key={"block-style-" + child.id}
|
|
24
|
+
block={child}
|
|
25
|
+
context={props.context}
|
|
26
|
+
></BlockStyles>
|
|
27
|
+
);
|
|
28
|
+
})}
|
|
29
|
+
</props.componentRef>
|
|
30
|
+
) : null}
|
|
31
|
+
</>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
export default RenderComponent;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import BuilderContext from "../../context/builder.context";
|
|
4
|
+
import RenderBlock from "./render-block";
|
|
5
|
+
import {
|
|
6
|
+
Fragment,
|
|
7
|
+
component$,
|
|
8
|
+
h,
|
|
9
|
+
useContextProvider,
|
|
10
|
+
useStore,
|
|
11
|
+
} from "@builder.io/qwik";
|
|
12
|
+
export const RenderRepeatedBlock = component$((props) => {
|
|
13
|
+
useContextProvider(
|
|
14
|
+
BuilderContext,
|
|
15
|
+
useStore({
|
|
16
|
+
content: (() => {
|
|
17
|
+
return props.repeatContext.content;
|
|
18
|
+
})(),
|
|
19
|
+
state: (() => {
|
|
20
|
+
return props.repeatContext.state;
|
|
21
|
+
})(),
|
|
22
|
+
context: (() => {
|
|
23
|
+
return props.repeatContext.context;
|
|
24
|
+
})(),
|
|
25
|
+
apiKey: (() => {
|
|
26
|
+
return props.repeatContext.apiKey;
|
|
27
|
+
})(),
|
|
28
|
+
registeredComponents: (() => {
|
|
29
|
+
return props.repeatContext.registeredComponents;
|
|
30
|
+
})(),
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
return (
|
|
34
|
+
<RenderBlock block={props.block} context={props.context}></RenderBlock>
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
export default RenderRepeatedBlock;
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import BuilderContext from "../context/builder.context";
|
|
4
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
5
|
+
import BlockStyles from "./render-block/block-styles";
|
|
6
|
+
import RenderBlock from "./render-block/render-block";
|
|
7
|
+
import {
|
|
8
|
+
Fragment,
|
|
9
|
+
component$,
|
|
10
|
+
h,
|
|
11
|
+
useContext,
|
|
12
|
+
useStylesScoped$,
|
|
13
|
+
} from "@builder.io/qwik";
|
|
14
|
+
export const className = function className(props, state, builderContext) {
|
|
15
|
+
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
16
|
+
};
|
|
17
|
+
export const onClick = function onClick(props, state, builderContext) {
|
|
18
|
+
if (isEditing() && !props.blocks?.length) {
|
|
19
|
+
window.parent?.postMessage(
|
|
20
|
+
{
|
|
21
|
+
type: "builder.clickEmptyBlocks",
|
|
22
|
+
data: {
|
|
23
|
+
parentElementId: props.parent,
|
|
24
|
+
dataPath: props.path,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
"*"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const onMouseEnter = function onMouseEnter(
|
|
32
|
+
props,
|
|
33
|
+
state,
|
|
34
|
+
builderContext
|
|
35
|
+
) {
|
|
36
|
+
if (isEditing() && !props.blocks?.length) {
|
|
37
|
+
window.parent?.postMessage(
|
|
38
|
+
{
|
|
39
|
+
type: "builder.hoverEmptyBlocks",
|
|
40
|
+
data: {
|
|
41
|
+
parentElementId: props.parent,
|
|
42
|
+
dataPath: props.path,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"*"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const RenderBlocks = component$((props) => {
|
|
50
|
+
useStylesScoped$(STYLES);
|
|
51
|
+
const builderContext = useContext(BuilderContext);
|
|
52
|
+
const state = {};
|
|
53
|
+
return (
|
|
54
|
+
<div
|
|
55
|
+
class={className(props, state, builderContext) + " div-RenderBlocks"}
|
|
56
|
+
builder-path={props.path}
|
|
57
|
+
builder-parent-id={props.parent}
|
|
58
|
+
dataSet={{
|
|
59
|
+
class: className(props, state, builderContext),
|
|
60
|
+
}}
|
|
61
|
+
onClick$={(event) => onClick(props, state, builderContext)}
|
|
62
|
+
onMouseEnter$={(event) => onMouseEnter(props, state, builderContext)}
|
|
63
|
+
>
|
|
64
|
+
{props.blocks
|
|
65
|
+
? (props.blocks || []).map((block) => {
|
|
66
|
+
return (
|
|
67
|
+
<RenderBlock
|
|
68
|
+
key={"render-block-" + block.id}
|
|
69
|
+
block={block}
|
|
70
|
+
context={builderContext}
|
|
71
|
+
></RenderBlock>
|
|
72
|
+
);
|
|
73
|
+
})
|
|
74
|
+
: null}
|
|
75
|
+
{props.blocks
|
|
76
|
+
? (props.blocks || []).map((block) => {
|
|
77
|
+
return (
|
|
78
|
+
<BlockStyles
|
|
79
|
+
key={"block-style-" + block.id}
|
|
80
|
+
block={block}
|
|
81
|
+
context={builderContext}
|
|
82
|
+
></BlockStyles>
|
|
83
|
+
);
|
|
84
|
+
})
|
|
85
|
+
: null}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
export default RenderBlocks;
|
|
90
|
+
export const STYLES = `.div-RenderBlocks {
|
|
91
|
+
display: flex;
|
|
92
|
+
flex-direction: column;
|
|
93
|
+
align-items: stretch; }`;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import RenderInlinedStyles from "../../render-inlined-styles";
|
|
4
|
+
import { Fragment, component$, h } from "@builder.io/qwik";
|
|
5
|
+
export const getCssFromFont = function getCssFromFont(props, state, font) {
|
|
6
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
7
|
+
const family =
|
|
8
|
+
font.family +
|
|
9
|
+
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
10
|
+
const name = family.split(",")[0];
|
|
11
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
12
|
+
let str = "";
|
|
13
|
+
|
|
14
|
+
if (url && family && name) {
|
|
15
|
+
str += `
|
|
16
|
+
@font-face {
|
|
17
|
+
font-family: "${family}";
|
|
18
|
+
src: local("${name}"), url('${url}') format('woff2');
|
|
19
|
+
font-display: fallback;
|
|
20
|
+
font-weight: 400;
|
|
21
|
+
}
|
|
22
|
+
`.trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (font.files) {
|
|
26
|
+
for (const weight in font.files) {
|
|
27
|
+
const isNumber = String(Number(weight)) === weight;
|
|
28
|
+
|
|
29
|
+
if (!isNumber) {
|
|
30
|
+
continue;
|
|
31
|
+
} // TODO: maybe limit number loaded
|
|
32
|
+
|
|
33
|
+
const weightUrl = font.files[weight];
|
|
34
|
+
|
|
35
|
+
if (weightUrl && weightUrl !== url) {
|
|
36
|
+
str += `
|
|
37
|
+
@font-face {
|
|
38
|
+
font-family: "${family}";
|
|
39
|
+
src: url('${weightUrl}') format('woff2');
|
|
40
|
+
font-display: fallback;
|
|
41
|
+
font-weight: ${weight};
|
|
42
|
+
}
|
|
43
|
+
`.trim();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return str;
|
|
49
|
+
};
|
|
50
|
+
export const getFontCss = function getFontCss(props, state, { customFonts }) {
|
|
51
|
+
// TODO: flag for this
|
|
52
|
+
// if (!this.builder.allowCustomFonts) {
|
|
53
|
+
// return '';
|
|
54
|
+
// }
|
|
55
|
+
// TODO: separate internal data from external
|
|
56
|
+
return (
|
|
57
|
+
customFonts?.map((font) => getCssFromFont(props, state, font))?.join(" ") ||
|
|
58
|
+
""
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
export const injectedStyles = function injectedStyles(props, state) {
|
|
62
|
+
return `
|
|
63
|
+
${props.cssCode || ""}
|
|
64
|
+
${getFontCss(props, state, {
|
|
65
|
+
customFonts: props.customFonts,
|
|
66
|
+
})}`;
|
|
67
|
+
};
|
|
68
|
+
export const RenderContentStyles = component$((props) => {
|
|
69
|
+
const state = {};
|
|
70
|
+
return (
|
|
71
|
+
<RenderInlinedStyles
|
|
72
|
+
styles={injectedStyles(props, state)}
|
|
73
|
+
></RenderInlinedStyles>
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
export default RenderContentStyles;
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
4
|
+
import { TARGET } from "../../constants/target.js";
|
|
5
|
+
import BuilderContext from "../../context/builder.context";
|
|
6
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
7
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
8
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
9
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
10
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
11
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
12
|
+
import {
|
|
13
|
+
components,
|
|
14
|
+
createRegisterComponentMessage,
|
|
15
|
+
} from "../../functions/register-component.js";
|
|
16
|
+
import { track } from "../../functions/track.js";
|
|
17
|
+
import {
|
|
18
|
+
registerInsertMenu,
|
|
19
|
+
setupBrowserForEditing,
|
|
20
|
+
} from "../../scripts/init-editing.js";
|
|
21
|
+
import RenderBlocks from "../render-blocks";
|
|
22
|
+
import RenderContentStyles from "./components/render-styles";
|
|
23
|
+
import {
|
|
24
|
+
Fragment,
|
|
25
|
+
_useMutableProps,
|
|
26
|
+
component$,
|
|
27
|
+
h,
|
|
28
|
+
useCleanup$,
|
|
29
|
+
useClientEffect$,
|
|
30
|
+
useContextProvider,
|
|
31
|
+
useRef,
|
|
32
|
+
useStore,
|
|
33
|
+
useWatch$,
|
|
34
|
+
} from "@builder.io/qwik";
|
|
35
|
+
export const useContent = function useContent(props, state, elementRef) {
|
|
36
|
+
const mergedContent = {
|
|
37
|
+
...props.content,
|
|
38
|
+
...state.overrideContent,
|
|
39
|
+
data: {
|
|
40
|
+
...props.content?.data,
|
|
41
|
+
...props.data,
|
|
42
|
+
...state.overrideContent?.data,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
return mergedContent;
|
|
46
|
+
};
|
|
47
|
+
export const contentState = function contentState(props, state, elementRef) {
|
|
48
|
+
return {
|
|
49
|
+
...props.content?.data?.state,
|
|
50
|
+
...props.data,
|
|
51
|
+
...state.overrideState,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export const contextContext = function contextContext(
|
|
55
|
+
props,
|
|
56
|
+
state,
|
|
57
|
+
elementRef
|
|
58
|
+
) {
|
|
59
|
+
return props.context || {};
|
|
60
|
+
};
|
|
61
|
+
export const allRegisteredComponents = function allRegisteredComponents(
|
|
62
|
+
props,
|
|
63
|
+
state,
|
|
64
|
+
elementRef
|
|
65
|
+
) {
|
|
66
|
+
const allComponentsArray = [
|
|
67
|
+
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
68
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
69
|
+
// existing usage.
|
|
70
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
71
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
72
|
+
...components,
|
|
73
|
+
...(props.customComponents || []),
|
|
74
|
+
];
|
|
75
|
+
const allComponents = allComponentsArray.reduce(
|
|
76
|
+
(acc, curr) => ({ ...acc, [curr.name]: curr }),
|
|
77
|
+
{}
|
|
78
|
+
);
|
|
79
|
+
return allComponents;
|
|
80
|
+
};
|
|
81
|
+
export const processMessage = function processMessage(
|
|
82
|
+
props,
|
|
83
|
+
state,
|
|
84
|
+
elementRef,
|
|
85
|
+
event
|
|
86
|
+
) {
|
|
87
|
+
const { data } = event;
|
|
88
|
+
|
|
89
|
+
if (data) {
|
|
90
|
+
switch (data.type) {
|
|
91
|
+
case "builder.contentUpdate": {
|
|
92
|
+
const messageContent = data.data;
|
|
93
|
+
const key =
|
|
94
|
+
messageContent.key ||
|
|
95
|
+
messageContent.alias ||
|
|
96
|
+
messageContent.entry ||
|
|
97
|
+
messageContent.modelName;
|
|
98
|
+
const contentData = messageContent.data;
|
|
99
|
+
|
|
100
|
+
if (key === props.model) {
|
|
101
|
+
state.overrideContent = contentData;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
case "builder.patchUpdates": {
|
|
108
|
+
// TODO
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export const evaluateJsCode = function evaluateJsCode(
|
|
115
|
+
props,
|
|
116
|
+
state,
|
|
117
|
+
elementRef
|
|
118
|
+
) {
|
|
119
|
+
// run any dynamic JS code attached to content
|
|
120
|
+
const jsCode = useContent(props, state, elementRef)?.data?.jsCode;
|
|
121
|
+
|
|
122
|
+
if (jsCode) {
|
|
123
|
+
evaluate({
|
|
124
|
+
code: jsCode,
|
|
125
|
+
context: contextContext(props, state, elementRef),
|
|
126
|
+
state: contentState(props, state, elementRef),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export const httpReqsData = function httpReqsData(props, state, elementRef) {
|
|
131
|
+
return {};
|
|
132
|
+
};
|
|
133
|
+
export const onClick = function onClick(props, state, elementRef, _event) {
|
|
134
|
+
if (useContent(props, state, elementRef) && props.canTrack !== false) {
|
|
135
|
+
track("click", {
|
|
136
|
+
contentId: useContent(props, state, elementRef).id,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
export const evalExpression = function evalExpression(
|
|
141
|
+
props,
|
|
142
|
+
state,
|
|
143
|
+
elementRef,
|
|
144
|
+
expression
|
|
145
|
+
) {
|
|
146
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
147
|
+
evaluate({
|
|
148
|
+
code: group,
|
|
149
|
+
context: contextContext(props, state, elementRef),
|
|
150
|
+
state: contentState(props, state, elementRef),
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
export const handleRequest = function handleRequest(
|
|
155
|
+
props,
|
|
156
|
+
state,
|
|
157
|
+
elementRef,
|
|
158
|
+
{ url, key }
|
|
159
|
+
) {
|
|
160
|
+
const fetchAndSetState = async () => {
|
|
161
|
+
const fetch = await getFetch();
|
|
162
|
+
const response = await fetch(url);
|
|
163
|
+
const json = await response.json();
|
|
164
|
+
const newOverrideState = { ...state.overrideState, [key]: json };
|
|
165
|
+
state.overrideState = newOverrideState;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
fetchAndSetState();
|
|
169
|
+
};
|
|
170
|
+
export const runHttpRequests = function runHttpRequests(
|
|
171
|
+
props,
|
|
172
|
+
state,
|
|
173
|
+
elementRef
|
|
174
|
+
) {
|
|
175
|
+
const requests =
|
|
176
|
+
useContent(props, state, elementRef)?.data?.httpRequests ?? {};
|
|
177
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
178
|
+
if (url && (!httpReqsData(props, state, elementRef)[key] || isEditing())) {
|
|
179
|
+
const evaluatedUrl = evalExpression(props, state, elementRef, url);
|
|
180
|
+
handleRequest(props, state, elementRef, {
|
|
181
|
+
url: evaluatedUrl,
|
|
182
|
+
key,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
export const emitStateUpdate = function emitStateUpdate(
|
|
188
|
+
props,
|
|
189
|
+
state,
|
|
190
|
+
elementRef
|
|
191
|
+
) {
|
|
192
|
+
if (isEditing()) {
|
|
193
|
+
window.dispatchEvent(
|
|
194
|
+
new CustomEvent("builder:component:stateChange", {
|
|
195
|
+
detail: {
|
|
196
|
+
state: contentState(props, state, elementRef),
|
|
197
|
+
ref: {
|
|
198
|
+
name: props.model,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
export const shouldRenderContentStyles = function shouldRenderContentStyles(
|
|
206
|
+
props,
|
|
207
|
+
state,
|
|
208
|
+
elementRef
|
|
209
|
+
) {
|
|
210
|
+
return Boolean(
|
|
211
|
+
(useContent(props, state, elementRef)?.data?.cssCode ||
|
|
212
|
+
useContent(props, state, elementRef)?.data?.customFonts?.length) &&
|
|
213
|
+
TARGET !== "reactNative"
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
export const RenderContent = component$((props) => {
|
|
217
|
+
const elementRef = useRef();
|
|
218
|
+
const state = useStore({
|
|
219
|
+
forceReRenderCount: 0,
|
|
220
|
+
overrideContent: null,
|
|
221
|
+
update: 0,
|
|
222
|
+
overrideState: {},
|
|
223
|
+
});
|
|
224
|
+
useContextProvider(
|
|
225
|
+
BuilderContext,
|
|
226
|
+
useStore({
|
|
227
|
+
content: (() => {
|
|
228
|
+
return useContent(props, state, elementRef);
|
|
229
|
+
})(),
|
|
230
|
+
state: (() => {
|
|
231
|
+
return contentState(props, state, elementRef);
|
|
232
|
+
})(),
|
|
233
|
+
context: (() => {
|
|
234
|
+
return contextContext(props, state, elementRef);
|
|
235
|
+
})(),
|
|
236
|
+
apiKey: (() => {
|
|
237
|
+
return props.apiKey;
|
|
238
|
+
})(),
|
|
239
|
+
registeredComponents: (() => {
|
|
240
|
+
return allRegisteredComponents(props, state, elementRef);
|
|
241
|
+
})(),
|
|
242
|
+
})
|
|
243
|
+
);
|
|
244
|
+
useClientEffect$(() => {
|
|
245
|
+
if (isBrowser()) {
|
|
246
|
+
if (isEditing()) {
|
|
247
|
+
state.forceReRenderCount++;
|
|
248
|
+
_useMutableProps(elementRef.current, true);
|
|
249
|
+
|
|
250
|
+
registerInsertMenu();
|
|
251
|
+
setupBrowserForEditing();
|
|
252
|
+
Object.values(
|
|
253
|
+
allRegisteredComponents(props, state, elementRef)
|
|
254
|
+
).forEach((registeredComponent) => {
|
|
255
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
256
|
+
window.parent?.postMessage(message, "*");
|
|
257
|
+
});
|
|
258
|
+
window.addEventListener(
|
|
259
|
+
"message",
|
|
260
|
+
processMessage.bind(null, props, state, elementRef)
|
|
261
|
+
);
|
|
262
|
+
window.addEventListener(
|
|
263
|
+
"builder:component:stateChangeListenerActivated",
|
|
264
|
+
emitStateUpdate.bind(null, props, state, elementRef)
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (useContent(props, state, elementRef) && props.canTrack !== false) {
|
|
269
|
+
track("impression", {
|
|
270
|
+
contentId: useContent(props, state, elementRef).id,
|
|
271
|
+
});
|
|
272
|
+
} // override normal content in preview mode
|
|
273
|
+
|
|
274
|
+
if (isPreviewing()) {
|
|
275
|
+
const searchParams = new URL(location.href).searchParams;
|
|
276
|
+
|
|
277
|
+
if (
|
|
278
|
+
props.model &&
|
|
279
|
+
searchParams.get("builder.preview") === props.model
|
|
280
|
+
) {
|
|
281
|
+
const previewApiKey =
|
|
282
|
+
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
283
|
+
|
|
284
|
+
if (previewApiKey) {
|
|
285
|
+
getContent({
|
|
286
|
+
model: props.model,
|
|
287
|
+
apiKey: previewApiKey,
|
|
288
|
+
}).then((content) => {
|
|
289
|
+
if (content) {
|
|
290
|
+
state.overrideContent = content;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
evaluateJsCode(props, state, elementRef);
|
|
298
|
+
runHttpRequests(props, state, elementRef);
|
|
299
|
+
emitStateUpdate(props, state, elementRef);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
useWatch$(({ track }) => {
|
|
303
|
+
state.useContent?.data && track(state.useContent?.data, "jsCode");
|
|
304
|
+
evaluateJsCode(props, state, elementRef);
|
|
305
|
+
});
|
|
306
|
+
useWatch$(({ track }) => {
|
|
307
|
+
state.useContent?.data && track(state.useContent?.data, "httpRequests");
|
|
308
|
+
runHttpRequests(props, state, elementRef);
|
|
309
|
+
});
|
|
310
|
+
useWatch$(({ track }) => {
|
|
311
|
+
state && track(state, "contentState");
|
|
312
|
+
emitStateUpdate(props, state, elementRef);
|
|
313
|
+
});
|
|
314
|
+
useCleanup$(() => {
|
|
315
|
+
if (isBrowser()) {
|
|
316
|
+
window.removeEventListener(
|
|
317
|
+
"message",
|
|
318
|
+
processMessage.bind(null, props, state, elementRef)
|
|
319
|
+
);
|
|
320
|
+
window.removeEventListener(
|
|
321
|
+
"builder:component:stateChangeListenerActivated",
|
|
322
|
+
emitStateUpdate.bind(null, props, state, elementRef)
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
return (
|
|
327
|
+
<>
|
|
328
|
+
{useContent(props, state, elementRef) ? (
|
|
329
|
+
<div
|
|
330
|
+
ref={elementRef}
|
|
331
|
+
onClick$={(event) => onClick(props, state, elementRef, event)}
|
|
332
|
+
builder-content-id={useContent(props, state, elementRef)?.id}
|
|
333
|
+
>
|
|
334
|
+
{shouldRenderContentStyles(props, state, elementRef) ? (
|
|
335
|
+
<RenderContentStyles
|
|
336
|
+
cssCode={useContent(props, state, elementRef)?.data?.cssCode}
|
|
337
|
+
customFonts={
|
|
338
|
+
useContent(props, state, elementRef)?.data?.customFonts
|
|
339
|
+
}
|
|
340
|
+
></RenderContentStyles>
|
|
341
|
+
) : null}
|
|
342
|
+
<RenderBlocks
|
|
343
|
+
blocks={useContent(props, state, elementRef)?.data?.blocks}
|
|
344
|
+
key={state.forceReRenderCount}
|
|
345
|
+
></RenderBlocks>
|
|
346
|
+
</div>
|
|
347
|
+
) : null}
|
|
348
|
+
</>
|
|
349
|
+
);
|
|
350
|
+
});
|
|
351
|
+
export default RenderContent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import { TARGET } from "../constants/target.js";
|
|
4
|
+
import { Fragment, component$, h } from "@builder.io/qwik";
|
|
5
|
+
export const injectedStyleScript = function injectedStyleScript(props, state) {
|
|
6
|
+
return `<${tagName(props, state)}>${props.styles}</${tagName(props, state)}>`;
|
|
7
|
+
};
|
|
8
|
+
export const tagName = function tagName(props, state) {
|
|
9
|
+
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
10
|
+
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
11
|
+
return "sty" + "le";
|
|
12
|
+
};
|
|
13
|
+
export const RenderInlinedStyles = component$((props) => {
|
|
14
|
+
const state = {};
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
{TARGET === "svelte" ? (
|
|
18
|
+
<div dangerouslySetInnerHTML={injectedStyleScript(props, state)}></div>
|
|
19
|
+
) : (
|
|
20
|
+
<state.tagName>{props.styles}</state.tagName>
|
|
21
|
+
)}
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
export default RenderInlinedStyles;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { default as Button } from "../blocks/button/button.jsx";
|
|
18
|
+
import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
|
|
19
|
+
import { default as Columns } from "../blocks/columns/columns.jsx";
|
|
20
|
+
import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
|
|
21
|
+
import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
|
|
22
|
+
import { default as Fragment } from "../blocks/fragment/fragment.jsx";
|
|
23
|
+
import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
|
|
24
|
+
import { default as Image } from "../blocks/image/image.jsx";
|
|
25
|
+
import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
|
|
26
|
+
import { default as Section } from "../blocks/section/section.jsx";
|
|
27
|
+
import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
|
|
28
|
+
import { default as Symbol } from "../blocks/symbol/symbol.jsx";
|
|
29
|
+
import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
|
|
30
|
+
import { default as Text } from "../blocks/text/text.jsx";
|
|
31
|
+
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
|
|
32
|
+
import { default as Video } from "../blocks/video/video.jsx";
|
|
33
|
+
import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info";
|
|
34
|
+
import { default as embed } from "../blocks/embed/embed.jsx";
|
|
35
|
+
const getDefaultRegisteredComponents = () => [
|
|
36
|
+
__spreadValues({ component: Columns }, columnsComponentInfo),
|
|
37
|
+
__spreadValues({ component: Image }, imageComponentInfo),
|
|
38
|
+
__spreadValues({ component: Text }, textComponentInfo),
|
|
39
|
+
__spreadValues({ component: Video }, videoComponentInfo),
|
|
40
|
+
__spreadValues({ component: Symbol }, symbolComponentInfo),
|
|
41
|
+
__spreadValues({ component: Button }, buttonComponentInfo),
|
|
42
|
+
__spreadValues({ component: Section }, sectionComponentInfo),
|
|
43
|
+
__spreadValues({ component: Fragment }, fragmentComponentInfo),
|
|
44
|
+
__spreadValues({ component: embed }, embedComponentInfo)
|
|
45
|
+
];
|
|
46
|
+
export {
|
|
47
|
+
getDefaultRegisteredComponents
|
|
48
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const SIZES = {
|
|
2
|
+
small: {
|
|
3
|
+
min: 320,
|
|
4
|
+
default: 321,
|
|
5
|
+
max: 640
|
|
6
|
+
},
|
|
7
|
+
medium: {
|
|
8
|
+
min: 641,
|
|
9
|
+
default: 642,
|
|
10
|
+
max: 991
|
|
11
|
+
},
|
|
12
|
+
large: {
|
|
13
|
+
min: 990,
|
|
14
|
+
default: 991,
|
|
15
|
+
max: 1200
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
|
|
19
|
+
export {
|
|
20
|
+
getMaxWidthQueryForSize
|
|
21
|
+
};
|