@builder.io/sdk-svelte 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/--package.json +159 -0
- package/package/blocks/BaseText.svelte +19 -0
- package/package/blocks/BaseText.svelte.d.ts +19 -0
- package/package/blocks/columns/columns.svelte +13 -4
- package/package/blocks/columns/columns.svelte.d.ts +1 -1
- package/package/blocks/custom-code/custom-code.svelte +1 -1
- package/package/blocks/embed/embed.svelte +2 -0
- package/package/blocks/form/form.svelte +7 -5
- package/package/blocks/image/image.svelte +48 -46
- package/package/blocks/image/image.svelte.d.ts +1 -1
- package/package/blocks/img/img.svelte +7 -2
- package/package/blocks/section/section.svelte +7 -2
- package/package/blocks/symbol/symbol.svelte +13 -13
- package/package/blocks/symbol/symbol.svelte.d.ts +3 -3
- package/package/blocks/video/video.svelte +14 -3
- package/package/components/render-block/block-styles.svelte +24 -19
- package/package/components/render-block/block-styles.svelte.d.ts +2 -2
- package/package/components/render-block/render-block.svelte +81 -58
- package/package/components/render-block/render-block.svelte.d.ts +2 -2
- package/package/components/render-block/render-component-with-context.svelte +32 -0
- package/package/components/render-block/render-component-with-context.svelte.d.ts +19 -0
- package/package/components/render-block/render-component.svelte +1 -3
- package/package/components/render-block/render-component.svelte.d.ts +2 -2
- package/package/components/render-block/render-repeated-block.svelte +3 -0
- package/package/components/render-block/types.d.ts +2 -2
- package/package/components/render-block/types.js +1 -2
- package/package/components/render-blocks.svelte +12 -1
- package/package/components/render-blocks.svelte.d.ts +3 -1
- package/package/components/render-content/components/render-styles.svelte +2 -1
- package/package/components/render-content/render-content.svelte +24 -8
- package/package/components/render-content/render-content.svelte.d.ts +2 -2
- package/package/constants/builder-registered-components.js +3 -0
- package/package/context/builder.context.d.ts +1 -0
- package/package/context/builder.context.js +1 -0
- package/package/context/types.d.ts +4 -3
- package/package/context/types.js +1 -3
- package/package/functions/extract-text-styles.d.ts +4 -0
- package/package/functions/extract-text-styles.js +34 -0
- package/package/functions/fast-clone.d.ts +4 -0
- package/package/functions/fast-clone.js +4 -0
- package/package/functions/get-block-actions-handler.d.ts +5 -0
- package/package/functions/get-block-actions-handler.js +9 -0
- package/package/functions/get-block-actions.d.ts +1 -1
- package/package/functions/get-block-actions.js +2 -8
- package/package/functions/get-block-component-options.d.ts +1 -1
- package/package/functions/get-block-component-options.js +0 -1
- package/package/functions/get-block-properties.d.ts +1 -1
- package/package/functions/get-block-properties.js +0 -1
- package/package/functions/get-block-tag.d.ts +1 -1
- package/package/functions/get-block-tag.js +0 -1
- package/package/functions/get-builder-search-params/index.d.ts +1 -1
- package/package/functions/get-builder-search-params/index.js +6 -2
- package/package/functions/get-content/ab-testing.d.ts +5 -3
- package/package/functions/get-content/ab-testing.js +75 -37
- package/package/functions/get-content/index.d.ts +1 -1
- package/package/functions/get-content/index.js +4 -5
- package/package/functions/get-content/types.d.ts +7 -2
- package/package/functions/get-processed-block.d.ts +1 -1
- package/package/functions/get-processed-block.js +5 -4
- package/package/functions/get-processed-block.test.js +0 -1
- package/package/functions/get-react-native-block-styles.d.ts +6 -0
- package/package/functions/get-react-native-block-styles.js +16 -0
- package/package/functions/register-component.d.ts +2 -2
- package/package/functions/register-component.js +1 -5
- package/package/functions/register.d.ts +2 -2
- package/package/functions/register.js +0 -2
- package/package/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/package/functions/sanitize-react-native-block-styles.js +53 -0
- package/package/functions/track.d.ts +1 -1
- package/package/functions/track.js +5 -6
- package/package/functions/transform-block.d.ts +1 -1
- package/package/functions/transform-block.js +0 -1
- package/package/helpers/ab-tests.d.ts +8 -0
- package/package/helpers/ab-tests.js +5 -0
- package/package/helpers/cookie.d.ts +9 -3
- package/package/helpers/cookie.js +8 -3
- package/package/helpers/css.d.ts +5 -1
- package/package/helpers/css.js +14 -1
- package/package/helpers/localStorage.d.ts +3 -4
- package/package/helpers/sessionId.d.ts +3 -4
- package/package/helpers/sessionId.js +5 -3
- package/package/helpers/visitorId.d.ts +3 -5
- package/package/scripts/init-editing.js +42 -38
- package/package/types/builder-content.d.ts +1 -1
- package/package/types/builder-content.js +1 -1
- package/package/types/targets.d.ts +1 -1
- package/package/types/typescript.d.ts +1 -0
- package/package.json +8 -3
- package/package/blocks/button/button.lite.d.ts +0 -0
- package/package/blocks/button/button.lite.tsx +0 -36
- package/package/blocks/columns/columns.lite.d.ts +0 -0
- package/package/blocks/columns/columns.lite.tsx +0 -139
- package/package/blocks/custom-code/custom-code.lite.d.ts +0 -0
- package/package/blocks/custom-code/custom-code.lite.tsx +0 -70
- package/package/blocks/embed/embed.lite.d.ts +0 -0
- package/package/blocks/embed/embed.lite.tsx +0 -52
- package/package/blocks/form/form.lite.d.ts +0 -0
- package/package/blocks/form/form.lite.tsx +0 -351
- package/package/blocks/fragment/fragment.lite.d.ts +0 -0
- package/package/blocks/fragment/fragment.lite.tsx +0 -12
- package/package/blocks/image/image.lite.d.ts +0 -0
- package/package/blocks/image/image.lite.tsx +0 -148
- package/package/blocks/img/img.lite.d.ts +0 -0
- package/package/blocks/img/img.lite.tsx +0 -48
- package/package/blocks/input/input.lite.d.ts +0 -0
- package/package/blocks/input/input.lite.tsx +0 -34
- package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
- package/package/blocks/raw-text/raw-text.lite.tsx +0 -15
- package/package/blocks/section/section.lite.d.ts +0 -0
- package/package/blocks/section/section.lite.tsx +0 -30
- package/package/blocks/select/select.lite.d.ts +0 -0
- package/package/blocks/select/select.lite.tsx +0 -34
- package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
- package/package/blocks/submit-button/submit-button.lite.tsx +0 -15
- package/package/blocks/symbol/symbol.lite.d.ts +0 -0
- package/package/blocks/symbol/symbol.lite.tsx +0 -92
- package/package/blocks/text/text.lite.d.ts +0 -0
- package/package/blocks/text/text.lite.tsx +0 -11
- package/package/blocks/textarea/textarea.lite.d.ts +0 -0
- package/package/blocks/textarea/textarea.lite.tsx +0 -19
- package/package/blocks/video/video.lite.d.ts +0 -0
- package/package/blocks/video/video.lite.tsx +0 -92
- package/package/components/render-block/block-styles.lite.d.ts +0 -0
- package/package/components/render-block/block-styles.lite.tsx +0 -60
- package/package/components/render-block/render-block.lite.d.ts +0 -0
- package/package/components/render-block/render-block.lite.tsx +0 -216
- package/package/components/render-block/render-component.lite.d.ts +0 -0
- package/package/components/render-block/render-component.lite.tsx +0 -33
- package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
- package/package/components/render-block/render-repeated-block.lite.tsx +0 -49
- package/package/components/render-blocks.lite.d.ts +0 -0
- package/package/components/render-blocks.lite.tsx +0 -91
- package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
- package/package/components/render-content/components/render-styles.lite.tsx +0 -86
- package/package/components/render-content/render-content.lite.d.ts +0 -0
- package/package/components/render-content/render-content.lite.tsx +0 -356
- package/package/components/render-inlined-styles.lite.d.ts +0 -0
- package/package/components/render-inlined-styles.lite.tsx +0 -27
- package/package/functions/convert-style-object.d.ts +0 -1
- package/package/functions/convert-style-object.js +0 -3
- package/package/functions/get-block-styles.d.ts +0 -2
- package/package/functions/get-block-styles.js +0 -21
- package/package/functions/sanitize-styles.d.ts +0 -4
- package/package/functions/sanitize-styles.js +0 -6
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export type RenderBlockProps = {
|
|
3
|
-
blocks?: BuilderBlock[];
|
|
4
|
-
parent?: string;
|
|
5
|
-
path?: string;
|
|
6
|
-
};
|
|
7
|
-
</script>
|
|
8
|
-
|
|
9
|
-
<script lang="ts">
|
|
10
|
-
import { getContext, setContext } from "svelte";
|
|
11
|
-
|
|
12
|
-
import BuilderContext from "../context/builder.context.js";
|
|
13
|
-
import { isEditing } from "../functions/is-editing.js";
|
|
14
|
-
import { BuilderBlock } from "../types/builder-block.js";
|
|
15
|
-
import BlockStyles from "./render-block/block-styles.svelte";
|
|
16
|
-
import RenderBlock from "./render-block/render-block.svelte";
|
|
17
|
-
|
|
18
|
-
export let blocks: RenderBlockProps["blocks"];
|
|
19
|
-
export let parent: RenderBlockProps["parent"];
|
|
20
|
-
export let path: RenderBlockProps["path"];
|
|
21
|
-
|
|
22
|
-
let builderContext = getContext(BuilderContext.key);
|
|
23
|
-
|
|
24
|
-
function onClick() {
|
|
25
|
-
if (isEditing() && !blocks?.length) {
|
|
26
|
-
window.parent?.postMessage(
|
|
27
|
-
{
|
|
28
|
-
type: "builder.clickEmptyBlocks",
|
|
29
|
-
data: {
|
|
30
|
-
parentElementId: parent,
|
|
31
|
-
dataPath: path,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
"*"
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function onMouseEnter() {
|
|
40
|
-
if (isEditing() && !blocks?.length) {
|
|
41
|
-
window.parent?.postMessage(
|
|
42
|
-
{
|
|
43
|
-
type: "builder.hoverEmptyBlocks",
|
|
44
|
-
data: {
|
|
45
|
-
parentElementId: parent,
|
|
46
|
-
dataPath: path,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
"*"
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
$: className = () => {
|
|
54
|
-
return "builder-blocks" + (!blocks?.length ? " no-blocks" : "");
|
|
55
|
-
};
|
|
56
|
-
</script>
|
|
57
|
-
|
|
58
|
-
<div
|
|
59
|
-
class={className() + " div"}
|
|
60
|
-
builder-path={path}
|
|
61
|
-
builder-parent-id={parent}
|
|
62
|
-
dataSet={{
|
|
63
|
-
class: className(),
|
|
64
|
-
}}
|
|
65
|
-
on:click={(event) => {
|
|
66
|
-
onClick();
|
|
67
|
-
}}
|
|
68
|
-
on:mouseenter={(event) => {
|
|
69
|
-
onMouseEnter();
|
|
70
|
-
}}
|
|
71
|
-
>
|
|
72
|
-
{#if blocks}
|
|
73
|
-
{#each blocks as block ("render-block-" + block.id)}
|
|
74
|
-
<RenderBlock {block} context={builderContext} />
|
|
75
|
-
{/each}
|
|
76
|
-
{/if}
|
|
77
|
-
|
|
78
|
-
{#if blocks}
|
|
79
|
-
{#each blocks as block ("block-style-" + block.id)}
|
|
80
|
-
<BlockStyles {block} context={builderContext} />
|
|
81
|
-
{/each}
|
|
82
|
-
{/if}
|
|
83
|
-
</div>
|
|
84
|
-
|
|
85
|
-
<style>
|
|
86
|
-
.div {
|
|
87
|
-
display: flex;
|
|
88
|
-
flex-direction: column;
|
|
89
|
-
align-items: stretch;
|
|
90
|
-
}
|
|
91
|
-
</style>
|
|
File without changes
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
interface CustomFont {
|
|
3
|
-
family?: string;
|
|
4
|
-
kind?: string;
|
|
5
|
-
fileUrl?: string;
|
|
6
|
-
files?: {
|
|
7
|
-
[key: string]: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
cssCode?: string;
|
|
13
|
-
customFonts?: CustomFont[];
|
|
14
|
-
}
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<script lang="ts">
|
|
18
|
-
import RenderInlinedStyles from "../../render-inlined-styles.svelte";
|
|
19
|
-
|
|
20
|
-
export let cssCode: Props["cssCode"];
|
|
21
|
-
export let customFonts: Props["customFonts"];
|
|
22
|
-
|
|
23
|
-
function getCssFromFont(font) {
|
|
24
|
-
// TODO: compute what font sizes are used and only load those.......
|
|
25
|
-
const family =
|
|
26
|
-
font.family +
|
|
27
|
-
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
28
|
-
const name = family.split(",")[0];
|
|
29
|
-
const url = font.fileUrl ?? font?.files?.regular;
|
|
30
|
-
let str = "";
|
|
31
|
-
|
|
32
|
-
if (url && family && name) {
|
|
33
|
-
str += `
|
|
34
|
-
@font-face {
|
|
35
|
-
font-family: "${family}";
|
|
36
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
37
|
-
font-display: fallback;
|
|
38
|
-
font-weight: 400;
|
|
39
|
-
}
|
|
40
|
-
`.trim();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (font.files) {
|
|
44
|
-
for (const weight in font.files) {
|
|
45
|
-
const isNumber = String(Number(weight)) === weight;
|
|
46
|
-
|
|
47
|
-
if (!isNumber) {
|
|
48
|
-
continue;
|
|
49
|
-
} // TODO: maybe limit number loaded
|
|
50
|
-
|
|
51
|
-
const weightUrl = font.files[weight];
|
|
52
|
-
|
|
53
|
-
if (weightUrl && weightUrl !== url) {
|
|
54
|
-
str += `
|
|
55
|
-
@font-face {
|
|
56
|
-
font-family: "${family}";
|
|
57
|
-
src: url('${weightUrl}') format('woff2');
|
|
58
|
-
font-display: fallback;
|
|
59
|
-
font-weight: ${weight};
|
|
60
|
-
}
|
|
61
|
-
`.trim();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return str;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function getFontCss({ customFonts }) {
|
|
70
|
-
// TODO: flag for this
|
|
71
|
-
// if (!builder.allowCustomFonts) {
|
|
72
|
-
// return '';
|
|
73
|
-
// }
|
|
74
|
-
// TODO: separate internal data from external
|
|
75
|
-
return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
|
|
76
|
-
}
|
|
77
|
-
$: injectedStyles = () => {
|
|
78
|
-
return `
|
|
79
|
-
${cssCode || ""}
|
|
80
|
-
${getFontCss({
|
|
81
|
-
customFonts: customFonts,
|
|
82
|
-
})}`;
|
|
83
|
-
};
|
|
84
|
-
</script>
|
|
85
|
-
|
|
86
|
-
<RenderInlinedStyles styles={injectedStyles()} />
|
|
File without changes
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
import type { Dictionary, Nullable } from "../../types/typescript.js";
|
|
3
|
-
|
|
4
|
-
export type RenderContentProps = {
|
|
5
|
-
content?: Nullable<BuilderContent>;
|
|
6
|
-
model?: string;
|
|
7
|
-
data?: {
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
};
|
|
10
|
-
context?: BuilderRenderContext;
|
|
11
|
-
apiKey: string;
|
|
12
|
-
customComponents?: RegisteredComponent[];
|
|
13
|
-
canTrack?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
interface BuilderComponentStateChange {
|
|
17
|
-
state: BuilderRenderState;
|
|
18
|
-
ref: {
|
|
19
|
-
name?: string;
|
|
20
|
-
props?: {
|
|
21
|
-
builderBlock?: {
|
|
22
|
-
id?: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<script lang="ts">
|
|
30
|
-
import {
|
|
31
|
-
afterUpdate,
|
|
32
|
-
getContext,
|
|
33
|
-
onDestroy,
|
|
34
|
-
onMount,
|
|
35
|
-
setContext,
|
|
36
|
-
} from "svelte";
|
|
37
|
-
|
|
38
|
-
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
39
|
-
import { TARGET } from "../../constants/target.js";
|
|
40
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
41
|
-
import {
|
|
42
|
-
BuilderRenderContext,
|
|
43
|
-
BuilderRenderState,
|
|
44
|
-
RegisteredComponent,
|
|
45
|
-
RegisteredComponents,
|
|
46
|
-
} from "../../context/types.js";
|
|
47
|
-
import { evaluate } from "../../functions/evaluate.js";
|
|
48
|
-
import { getContent } from "../../functions/get-content/index.js";
|
|
49
|
-
import { getFetch } from "../../functions/get-fetch.js";
|
|
50
|
-
import { isBrowser } from "../../functions/is-browser.js";
|
|
51
|
-
import { isEditing } from "../../functions/is-editing.js";
|
|
52
|
-
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
53
|
-
import {
|
|
54
|
-
components,
|
|
55
|
-
createRegisterComponentMessage,
|
|
56
|
-
} from "../../functions/register-component.js";
|
|
57
|
-
import { track } from "../../functions/track.js";
|
|
58
|
-
import { BuilderContent } from "../../types/builder-content.js";
|
|
59
|
-
import RenderBlocks from "../render-blocks.svelte";
|
|
60
|
-
import RenderContentStyles from "./components/render-styles.svelte";
|
|
61
|
-
import {
|
|
62
|
-
registerInsertMenu,
|
|
63
|
-
setupBrowserForEditing,
|
|
64
|
-
} from "../../scripts/init-editing.js";
|
|
65
|
-
import { markMutable } from "../../functions/mark-mutable.js";
|
|
66
|
-
|
|
67
|
-
export let content: RenderContentProps["content"];
|
|
68
|
-
export let data: RenderContentProps["data"];
|
|
69
|
-
export let canTrack: RenderContentProps["canTrack"];
|
|
70
|
-
export let context: RenderContentProps["context"];
|
|
71
|
-
export let customComponents: RenderContentProps["customComponents"];
|
|
72
|
-
export let model: RenderContentProps["model"];
|
|
73
|
-
export let apiKey: RenderContentProps["apiKey"];
|
|
74
|
-
|
|
75
|
-
setContext(BuilderContext.key, {
|
|
76
|
-
get content() {
|
|
77
|
-
return useContent();
|
|
78
|
-
},
|
|
79
|
-
get state() {
|
|
80
|
-
return contentState();
|
|
81
|
-
},
|
|
82
|
-
get context() {
|
|
83
|
-
return contextContext();
|
|
84
|
-
},
|
|
85
|
-
get apiKey() {
|
|
86
|
-
return apiKey;
|
|
87
|
-
},
|
|
88
|
-
get registeredComponents() {
|
|
89
|
-
return allRegisteredComponents();
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
function processMessage(event) {
|
|
94
|
-
const { data } = event;
|
|
95
|
-
|
|
96
|
-
if (data) {
|
|
97
|
-
switch (data.type) {
|
|
98
|
-
case "builder.contentUpdate": {
|
|
99
|
-
const messageContent = data.data;
|
|
100
|
-
const key =
|
|
101
|
-
messageContent.key ||
|
|
102
|
-
messageContent.alias ||
|
|
103
|
-
messageContent.entry ||
|
|
104
|
-
messageContent.modelName;
|
|
105
|
-
const contentData = messageContent.data;
|
|
106
|
-
|
|
107
|
-
if (key === model) {
|
|
108
|
-
overrideContent = contentData;
|
|
109
|
-
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
case "builder.patchUpdates": {
|
|
116
|
-
// TODO
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function evaluateJsCode() {
|
|
124
|
-
// run any dynamic JS code attached to content
|
|
125
|
-
const jsCode = useContent?.()?.data?.jsCode;
|
|
126
|
-
|
|
127
|
-
if (jsCode) {
|
|
128
|
-
evaluate({
|
|
129
|
-
code: jsCode,
|
|
130
|
-
context: contextContext(),
|
|
131
|
-
state: contentState(),
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function onClick(_event) {
|
|
137
|
-
if (useContent()) {
|
|
138
|
-
track({
|
|
139
|
-
type: "click",
|
|
140
|
-
canTrack: canTrackToUse(),
|
|
141
|
-
contentId: useContent?.()?.id,
|
|
142
|
-
orgId: apiKey,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function evalExpression(expression) {
|
|
148
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
149
|
-
evaluate({
|
|
150
|
-
code: group,
|
|
151
|
-
context: contextContext(),
|
|
152
|
-
state: contentState(),
|
|
153
|
-
})
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function handleRequest({ url, key }) {
|
|
158
|
-
getFetch()
|
|
159
|
-
.then((fetch) => fetch(url))
|
|
160
|
-
.then((response) => response.json())
|
|
161
|
-
.then((json) => {
|
|
162
|
-
const newOverrideState = { ...overrideState, [key]: json };
|
|
163
|
-
overrideState = newOverrideState;
|
|
164
|
-
})
|
|
165
|
-
.catch((err) => {
|
|
166
|
-
console.log("error fetching dynamic data", url, err);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function runHttpRequests() {
|
|
171
|
-
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
172
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
173
|
-
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
174
|
-
const evaluatedUrl = evalExpression(url);
|
|
175
|
-
handleRequest({
|
|
176
|
-
url: evaluatedUrl,
|
|
177
|
-
key,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function emitStateUpdate() {
|
|
184
|
-
if (isEditing()) {
|
|
185
|
-
window.dispatchEvent(
|
|
186
|
-
new CustomEvent("builder:component:stateChange", {
|
|
187
|
-
detail: {
|
|
188
|
-
state: contentState(),
|
|
189
|
-
ref: {
|
|
190
|
-
name: model,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
$: useContent = () => {
|
|
198
|
-
if (!content && !overrideContent) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const mergedContent = {
|
|
203
|
-
...content,
|
|
204
|
-
...overrideContent,
|
|
205
|
-
data: { ...content?.data, ...data, ...overrideContent?.data },
|
|
206
|
-
};
|
|
207
|
-
return mergedContent;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
$: canTrackToUse = () => {
|
|
211
|
-
return canTrack || true;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
$: contentState = () => {
|
|
215
|
-
return { ...content?.data?.state, ...data, ...overrideState };
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
$: contextContext = () => {
|
|
219
|
-
return context || {};
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
$: allRegisteredComponents = () => {
|
|
223
|
-
const allComponentsArray = [
|
|
224
|
-
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
225
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
226
|
-
// existing usage.
|
|
227
|
-
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
228
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
229
|
-
...components,
|
|
230
|
-
...(customComponents || []),
|
|
231
|
-
];
|
|
232
|
-
const allComponents = allComponentsArray.reduce(
|
|
233
|
-
(acc, curr) => ({ ...acc, [curr.name]: curr }),
|
|
234
|
-
{}
|
|
235
|
-
);
|
|
236
|
-
return allComponents;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
$: httpReqsData = () => {
|
|
240
|
-
return {};
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
$: shouldRenderContentStyles = () => {
|
|
244
|
-
return Boolean(
|
|
245
|
-
(useContent?.()?.data?.cssCode ||
|
|
246
|
-
useContent?.()?.data?.customFonts?.length) &&
|
|
247
|
-
TARGET !== "reactNative"
|
|
248
|
-
);
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
let elementRef;
|
|
252
|
-
|
|
253
|
-
let forceReRenderCount = 0;
|
|
254
|
-
let overrideContent = null;
|
|
255
|
-
let update = 0;
|
|
256
|
-
let overrideState = {};
|
|
257
|
-
|
|
258
|
-
onMount(() => {
|
|
259
|
-
if (isBrowser()) {
|
|
260
|
-
if (isEditing()) {
|
|
261
|
-
forceReRenderCount = forceReRenderCount + 1; // QWIK-REPLACE: _useMutableProps
|
|
262
|
-
|
|
263
|
-
registerInsertMenu();
|
|
264
|
-
setupBrowserForEditing();
|
|
265
|
-
Object.values(allRegisteredComponents()).forEach(
|
|
266
|
-
(registeredComponent) => {
|
|
267
|
-
const message = createRegisterComponentMessage(registeredComponent);
|
|
268
|
-
window.parent?.postMessage(message, "*");
|
|
269
|
-
}
|
|
270
|
-
);
|
|
271
|
-
window.addEventListener("message", processMessage);
|
|
272
|
-
window.addEventListener(
|
|
273
|
-
"builder:component:stateChangeListenerActivated",
|
|
274
|
-
emitStateUpdate
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (useContent()) {
|
|
279
|
-
track({
|
|
280
|
-
type: "impression",
|
|
281
|
-
canTrack: canTrackToUse(),
|
|
282
|
-
contentId: useContent?.()?.id,
|
|
283
|
-
orgId: apiKey,
|
|
284
|
-
});
|
|
285
|
-
} // override normal content in preview mode
|
|
286
|
-
|
|
287
|
-
if (isPreviewing()) {
|
|
288
|
-
const searchParams = new URL(location.href).searchParams;
|
|
289
|
-
|
|
290
|
-
if (model && searchParams.get("builder.preview") === model) {
|
|
291
|
-
const previewApiKey =
|
|
292
|
-
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
293
|
-
|
|
294
|
-
if (previewApiKey) {
|
|
295
|
-
getContent({
|
|
296
|
-
model: model,
|
|
297
|
-
apiKey: previewApiKey,
|
|
298
|
-
}).then((content) => {
|
|
299
|
-
if (content) {
|
|
300
|
-
overrideContent = content;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
evaluateJsCode();
|
|
308
|
-
runHttpRequests();
|
|
309
|
-
emitStateUpdate();
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
function onUpdateFn_0() {
|
|
314
|
-
evaluateJsCode();
|
|
315
|
-
}
|
|
316
|
-
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
|
|
317
|
-
function onUpdateFn_1() {
|
|
318
|
-
runHttpRequests();
|
|
319
|
-
}
|
|
320
|
-
$: onUpdateFn_1(...[useContent?.()?.data?.httpRequests]);
|
|
321
|
-
function onUpdateFn_2() {
|
|
322
|
-
emitStateUpdate();
|
|
323
|
-
}
|
|
324
|
-
$: onUpdateFn_2(...[contentState()]);
|
|
325
|
-
|
|
326
|
-
onDestroy(() => {
|
|
327
|
-
if (isBrowser()) {
|
|
328
|
-
window.removeEventListener("message", processMessage);
|
|
329
|
-
window.removeEventListener(
|
|
330
|
-
"builder:component:stateChangeListenerActivated",
|
|
331
|
-
emitStateUpdate
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
</script>
|
|
336
|
-
|
|
337
|
-
{#if useContent()}
|
|
338
|
-
<div
|
|
339
|
-
bind:this={elementRef}
|
|
340
|
-
on:click={(event) => {
|
|
341
|
-
onClick(event);
|
|
342
|
-
}}
|
|
343
|
-
builder-content-id={useContent?.()?.id}
|
|
344
|
-
>
|
|
345
|
-
{#if shouldRenderContentStyles()}
|
|
346
|
-
<RenderContentStyles
|
|
347
|
-
cssCode={useContent?.()?.data?.cssCode}
|
|
348
|
-
customFonts={useContent?.()?.data?.customFonts}
|
|
349
|
-
/>
|
|
350
|
-
{/if}
|
|
351
|
-
<RenderBlocks
|
|
352
|
-
blocks={markMutable(useContent?.()?.data?.blocks)}
|
|
353
|
-
key={forceReRenderCount}
|
|
354
|
-
/>
|
|
355
|
-
</div>
|
|
356
|
-
{/if}
|
|
File without changes
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
interface Props {
|
|
3
|
-
styles: string;
|
|
4
|
-
}
|
|
5
|
-
</script>
|
|
6
|
-
|
|
7
|
-
<script lang="ts">
|
|
8
|
-
import { TARGET } from "../constants/target.js";
|
|
9
|
-
|
|
10
|
-
export let styles: Props["styles"];
|
|
11
|
-
|
|
12
|
-
$: injectedStyleScript = () => {
|
|
13
|
-
return `<${tagName()}>${styles}</${tagName()}>`;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
$: tagName = () => {
|
|
17
|
-
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
18
|
-
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
19
|
-
return "sty" + "le";
|
|
20
|
-
};
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
{#if TARGET === "svelte"}
|
|
24
|
-
{@html injectedStyleScript()}
|
|
25
|
-
{:else}
|
|
26
|
-
<svelte:element this={tagName()}>{styles}</svelte:element>
|
|
27
|
-
{/if}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const convertStyleObject: (obj?: Partial<CSSStyleDeclaration>) => Partial<CSSStyleDeclaration> | undefined;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getMaxWidthQueryForSize } from '../constants/device-sizes.js';
|
|
2
|
-
import '../types/builder-block.js';
|
|
3
|
-
import { convertStyleObject } from './convert-style-object.js';
|
|
4
|
-
import { sanitizeBlockStyles } from './sanitize-styles.js';
|
|
5
|
-
export function getBlockStyles(block) {
|
|
6
|
-
const styles = {
|
|
7
|
-
...convertStyleObject(block.responsiveStyles?.large),
|
|
8
|
-
/**
|
|
9
|
-
* TO-DO: remove?
|
|
10
|
-
*/
|
|
11
|
-
...block.styles,
|
|
12
|
-
};
|
|
13
|
-
if (block.responsiveStyles?.medium) {
|
|
14
|
-
styles[getMaxWidthQueryForSize('medium')] = convertStyleObject(block.responsiveStyles?.medium);
|
|
15
|
-
}
|
|
16
|
-
if (block.responsiveStyles?.small) {
|
|
17
|
-
styles[getMaxWidthQueryForSize('small')] = convertStyleObject(block.responsiveStyles?.small);
|
|
18
|
-
}
|
|
19
|
-
sanitizeBlockStyles(styles);
|
|
20
|
-
return styles;
|
|
21
|
-
}
|