@builder.io/sdk-svelte 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/--package.json +3 -2
- package/package/CHANGELOG.md +6 -0
- package/package/blocks/columns/columns.svelte +20 -23
- package/package/blocks/columns/columns.svelte.d.ts +1 -1
- package/package/blocks/image/image.svelte +1 -2
- package/package/blocks/image/image.svelte.d.ts +2 -2
- package/package/blocks/symbol/symbol.svelte +2 -3
- package/package/blocks/symbol/symbol.svelte.d.ts +2 -2
- package/package/components/render-block/block-styles.svelte +0 -2
- package/package/components/render-block/block-styles.svelte.d.ts +2 -2
- package/package/components/render-block/render-block.svelte +3 -7
- package/package/components/render-block/render-block.svelte.d.ts +2 -2
- 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 +1 -2
- package/package/components/render-block/render-repeated-block.svelte.d.ts +2 -2
- package/package/components/render-blocks.svelte +0 -1
- package/package/components/render-blocks.svelte.d.ts +1 -1
- package/package/components/render-content/components/render-styles.svelte +8 -9
- package/package/components/render-content/components/render-styles.svelte.d.ts +1 -1
- package/package/components/render-content/render-content.svelte +11 -10
- package/package/components/render-content/render-content.svelte.d.ts +1 -1
- package/package/functions/get-block-properties.d.ts +1 -0
- package/package/functions/get-block-properties.js +31 -0
- package/package/functions/get-content/index.d.ts +1 -1
- package/package/functions/get-content/index.js +24 -17
- package/package/functions/track/index.js +2 -1
- package/package/helpers/logger.d.ts +5 -0
- package/package/helpers/logger.js +6 -0
- package/package/index.d.ts +1 -0
- package/package/types/builder-content.d.ts +1 -1
- package/package/types/components.d.ts +1 -72
- package/package/types/input.d.ts +4 -0
- package/package.json +2 -2
- package/src/blocks/columns/columns.svelte +25 -25
- package/src/blocks/image/image.svelte +3 -3
- package/src/blocks/symbol/symbol.svelte +4 -3
- package/src/components/render-block/block-styles.svelte +2 -2
- package/src/components/render-block/render-block.svelte +5 -6
- package/src/components/render-block/render-component.svelte +2 -2
- package/src/components/render-block/render-repeated-block.svelte +3 -2
- package/src/components/render-blocks.svelte +1 -1
- package/src/components/render-content/components/render-styles.svelte +9 -9
- package/src/components/render-content/render-content.svelte +23 -11
- package/src/functions/get-block-properties.ts +34 -0
- package/src/functions/get-content/index.ts +28 -22
- package/src/functions/register-component.ts +10 -10
- package/src/functions/track/index.ts +3 -2
- package/src/helpers/logger.ts +6 -0
- package/src/index.ts +1 -0
- package/src/types/builder-content.ts +1 -1
- package/src/types/components.ts +1 -68
- package/src/types/input.ts +5 -0
package/package/--package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -128,6 +128,7 @@
|
|
|
128
128
|
"./helpers/css": "./helpers/css.js",
|
|
129
129
|
"./helpers/flatten": "./helpers/flatten.js",
|
|
130
130
|
"./helpers/localStorage": "./helpers/localStorage.js",
|
|
131
|
+
"./helpers/logger": "./helpers/logger.js",
|
|
131
132
|
"./helpers/nullable": "./helpers/nullable.js",
|
|
132
133
|
"./helpers/sessionId": "./helpers/sessionId.js",
|
|
133
134
|
"./helpers/time": "./helpers/time.js",
|
|
@@ -152,7 +153,7 @@
|
|
|
152
153
|
"types": "./package/index.d.ts",
|
|
153
154
|
"devDependencies": {
|
|
154
155
|
"@sveltejs/adapter-auto": "1.0.0-next.71",
|
|
155
|
-
"@sveltejs/kit": "1.
|
|
156
|
+
"@sveltejs/kit": "^1.15.2",
|
|
156
157
|
"@sveltejs/package": "1.0.0-next.1",
|
|
157
158
|
"svelte": "^3.44.0",
|
|
158
159
|
"svelte-check": "^2.7.1",
|
package/package/CHANGELOG.md
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import { getContext } from "svelte";
|
|
4
4
|
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
5
|
-
import "../../types/builder-block";
|
|
6
5
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
7
|
-
import "../../constants/device-sizes";
|
|
8
6
|
import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
|
|
9
7
|
import { TARGET } from "../../constants/target.js";
|
|
10
8
|
import BuilderContext from "../../context/builder.context.js";
|
|
11
|
-
import "../../types/typescript";
|
|
12
9
|
export let space;
|
|
13
10
|
export let columns;
|
|
14
11
|
export let stackColumnsAt;
|
|
@@ -90,30 +87,30 @@ $: columnsCssVars = () => {
|
|
|
90
87
|
};
|
|
91
88
|
$: columnsStyles = () => {
|
|
92
89
|
return `
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
91
|
+
.${builderBlock.id}-breakpoints {
|
|
92
|
+
flex-direction: var(--flex-dir-tablet);
|
|
93
|
+
align-items: stretch;
|
|
94
|
+
}
|
|
98
95
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
.${builderBlock.id}-breakpoints > .builder-column {
|
|
97
|
+
width: var(--column-width-tablet) !important;
|
|
98
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
99
|
+
}
|
|
102
100
|
}
|
|
103
|
-
}
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
103
|
+
.${builderBlock.id}-breakpoints {
|
|
104
|
+
flex-direction: var(--flex-dir);
|
|
105
|
+
align-items: stretch;
|
|
106
|
+
}
|
|
110
107
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
108
|
+
.${builderBlock.id}-breakpoints > .builder-column {
|
|
109
|
+
width: var(--column-width-mobile) !important;
|
|
110
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
`;
|
|
117
114
|
};
|
|
118
115
|
let gutterSize = typeof space === "number" ? space || 0 : 20;
|
|
119
116
|
let cols = columns || [];
|
|
@@ -11,7 +11,7 @@ export interface ColumnProps {
|
|
|
11
11
|
stackColumnsAt?: StackColumnsAt;
|
|
12
12
|
reverseColumnsWhenStacked?: boolean;
|
|
13
13
|
}
|
|
14
|
-
import { BuilderBlock } from "../../types/builder-block";
|
|
14
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
15
15
|
declare const __propDef: {
|
|
16
16
|
props: {
|
|
17
17
|
space: ColumnProps["space"];
|
|
@@ -8,7 +8,7 @@ export interface ImageProps {
|
|
|
8
8
|
height?: number;
|
|
9
9
|
width?: number;
|
|
10
10
|
altText?: string;
|
|
11
|
-
backgroundSize?:
|
|
11
|
+
backgroundSize?: "cover" | "contain";
|
|
12
12
|
backgroundPosition?: string;
|
|
13
13
|
srcset?: string;
|
|
14
14
|
aspectRatio?: number;
|
|
@@ -18,7 +18,7 @@ export interface ImageProps {
|
|
|
18
18
|
noWebp?: boolean;
|
|
19
19
|
src?: string;
|
|
20
20
|
}
|
|
21
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
21
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
22
22
|
declare const __propDef: {
|
|
23
23
|
props: {
|
|
24
24
|
image: ImageProps["image"];
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
import RenderContent from "../../components/render-content/render-content.svelte";
|
|
5
5
|
import BuilderContext from "../../context/builder.context.js";
|
|
6
6
|
import { getContent } from "../../functions/get-content/index.js";
|
|
7
|
-
import "../../types/builder-content.js";
|
|
8
|
-
import "../../types/builder-block.js";
|
|
9
7
|
import { TARGET } from "../../constants/target";
|
|
8
|
+
import { logger } from "../../helpers/logger";
|
|
10
9
|
const isEvent = (attr) => attr.startsWith("on:");
|
|
11
10
|
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
12
11
|
const filterAttrs = (attrs = {}, filter) => {
|
|
@@ -66,7 +65,7 @@ function fetchContent() {
|
|
|
66
65
|
}
|
|
67
66
|
})
|
|
68
67
|
.catch((err) => {
|
|
69
|
-
|
|
68
|
+
logger.error("Could not fetch symbol content: ", err);
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
71
|
}
|
|
@@ -15,8 +15,8 @@ export interface SymbolProps {
|
|
|
15
15
|
attributes?: any;
|
|
16
16
|
inheritState?: boolean;
|
|
17
17
|
}
|
|
18
|
-
import { BuilderContent } from "../../types/builder-content.js";
|
|
19
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
+
import type { BuilderContent } from "../../types/builder-content.js";
|
|
19
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
20
20
|
declare const __propDef: {
|
|
21
21
|
props: {
|
|
22
22
|
attributes: SymbolProps["attributes"];
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../constants/device-sizes.js";
|
|
4
4
|
import { TARGET } from "../../constants/target.js";
|
|
5
|
-
import "../../context/types.js";
|
|
6
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
7
6
|
import { createCssClass } from "../../helpers/css.js";
|
|
8
7
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
9
|
-
import "../../types/builder-block.js";
|
|
10
8
|
import RenderInlinedStyles from "../render-inlined-styles.svelte";
|
|
11
9
|
export let block;
|
|
12
10
|
export let context;
|
|
@@ -3,8 +3,8 @@ export type BlockStylesProps = {
|
|
|
3
3
|
block: BuilderBlock;
|
|
4
4
|
context: BuilderContextInterface;
|
|
5
5
|
};
|
|
6
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
7
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
6
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
7
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
8
8
|
declare const __propDef: {
|
|
9
9
|
props: {
|
|
10
10
|
block: BlockStylesProps["block"];
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>import "../../
|
|
4
|
-
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
3
|
+
<script>import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
5
4
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
6
5
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
7
6
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
8
|
-
import "../../types/builder-block.js";
|
|
9
7
|
import BlockStyles from "./block-styles.svelte";
|
|
10
8
|
import { getComponent, getProxyState, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
|
|
11
|
-
import "./render-component.svelte";
|
|
12
9
|
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
13
10
|
import { TARGET } from "../../constants/target.js";
|
|
14
11
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
15
12
|
import RenderComponent from "./render-component.svelte";
|
|
16
13
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
17
|
-
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
18
14
|
const setAttrs = (node, attrs = {}) => {
|
|
19
15
|
const attrKeys = Object.keys(attrs);
|
|
20
16
|
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
@@ -44,10 +40,10 @@ $: useBlock = () => {
|
|
|
44
40
|
});
|
|
45
41
|
};
|
|
46
42
|
$: canShowBlock = () => {
|
|
47
|
-
if (
|
|
43
|
+
if ("hide" in useBlock()) {
|
|
48
44
|
return !useBlock().hide;
|
|
49
45
|
}
|
|
50
|
-
if (
|
|
46
|
+
if ("show" in useBlock()) {
|
|
51
47
|
return useBlock().show;
|
|
52
48
|
}
|
|
53
49
|
return true;
|
|
@@ -3,8 +3,8 @@ export type RenderBlockProps = {
|
|
|
3
3
|
block: BuilderBlock;
|
|
4
4
|
context: BuilderContextInterface;
|
|
5
5
|
};
|
|
6
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
7
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
6
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
7
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
8
8
|
declare const __propDef: {
|
|
9
9
|
props: {
|
|
10
10
|
block: RenderBlockProps["block"];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>import "
|
|
4
|
-
import BlockStyles from "./block-styles.svelte";
|
|
3
|
+
<script>import BlockStyles from "./block-styles.svelte";
|
|
5
4
|
import RenderBlock from "./render-block.svelte";
|
|
6
|
-
import "../../context/types.js";
|
|
7
5
|
export let componentRef;
|
|
8
6
|
export let componentOptions;
|
|
9
7
|
export let blockChildren;
|
|
@@ -11,8 +11,8 @@ export interface RenderComponentProps {
|
|
|
11
11
|
blockChildren: BuilderBlock[];
|
|
12
12
|
context: BuilderContextInterface;
|
|
13
13
|
}
|
|
14
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
15
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
14
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
16
16
|
declare const __propDef: {
|
|
17
17
|
props: {
|
|
18
18
|
componentRef: RenderComponentProps["componentRef"];
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
<script>import { setContext } from "svelte";
|
|
13
13
|
import BuilderContext from "../../context/builder.context.js";
|
|
14
|
-
import "../../context/types.js";
|
|
15
|
-
import "../../types/builder-block";
|
|
16
14
|
import RenderBlock from "./render-block.svelte";
|
|
17
15
|
export let block;
|
|
18
16
|
export let repeatContext;
|
|
@@ -24,6 +22,7 @@ setContext(BuilderContext.key, {
|
|
|
24
22
|
apiKey: repeatContext.apiKey,
|
|
25
23
|
registeredComponents: repeatContext.registeredComponents,
|
|
26
24
|
inheritedStyles: repeatContext.inheritedStyles,
|
|
25
|
+
apiVersion: repeatContext.apiVersion,
|
|
27
26
|
});
|
|
28
27
|
</script>
|
|
29
28
|
|
|
@@ -3,8 +3,8 @@ type Props = {
|
|
|
3
3
|
block: BuilderBlock;
|
|
4
4
|
repeatContext: BuilderContextInterface;
|
|
5
5
|
};
|
|
6
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
7
|
-
import { BuilderBlock } from "../../types/builder-block";
|
|
6
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
7
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
8
8
|
declare const __propDef: {
|
|
9
9
|
props: {
|
|
10
10
|
block: Props["block"];
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
<script>import { getContext } from "svelte";
|
|
4
4
|
import BuilderContext from "../context/builder.context.js";
|
|
5
5
|
import { isEditing } from "../functions/is-editing.js";
|
|
6
|
-
import "../types/builder-block.js";
|
|
7
6
|
import BlockStyles from "./render-block/block-styles.svelte";
|
|
8
7
|
import RenderBlock from "./render-block/render-block.svelte";
|
|
9
8
|
export let blocks;
|
|
@@ -5,7 +5,7 @@ export type RenderBlockProps = {
|
|
|
5
5
|
path?: string;
|
|
6
6
|
styleProp?: Record<string, any>;
|
|
7
7
|
};
|
|
8
|
-
import { BuilderBlock } from "../types/builder-block.js";
|
|
8
|
+
import type { BuilderBlock } from "../types/builder-block.js";
|
|
9
9
|
declare const __propDef: {
|
|
10
10
|
props: {
|
|
11
11
|
blocks: RenderBlockProps["blocks"];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import RenderInlinedStyles from "../../render-inlined-styles.svelte";
|
|
4
|
-
import "./render-styles.helpers";
|
|
5
4
|
import { getCss } from "./render-styles.helpers";
|
|
6
5
|
import { getFontCss } from "./render-styles.helpers";
|
|
7
6
|
export let cssCode;
|
|
@@ -17,16 +16,16 @@ ${getFontCss({
|
|
|
17
16
|
})}
|
|
18
17
|
|
|
19
18
|
.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
|
|
20
|
-
margin: 0;
|
|
19
|
+
margin: 0;
|
|
21
20
|
}
|
|
22
21
|
.builder-text > p, .builder-text > .builder-paragraph {
|
|
23
|
-
color: inherit;
|
|
24
|
-
line-height: inherit;
|
|
25
|
-
letter-spacing: inherit;
|
|
26
|
-
font-weight: inherit;
|
|
27
|
-
font-size: inherit;
|
|
28
|
-
text-align: inherit;
|
|
29
|
-
font-family: inherit;
|
|
22
|
+
color: inherit;
|
|
23
|
+
line-height: inherit;
|
|
24
|
+
letter-spacing: inherit;
|
|
25
|
+
font-weight: inherit;
|
|
26
|
+
font-size: inherit;
|
|
27
|
+
text-align: inherit;
|
|
28
|
+
font-family: inherit;
|
|
30
29
|
}
|
|
31
30
|
`;
|
|
32
31
|
</script>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>import { onDestroy, onMount, setContext } from "svelte";
|
|
2
2
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
3
|
-
import "../../context/types.js";
|
|
4
3
|
import { evaluate } from "../../functions/evaluate.js";
|
|
5
4
|
import { getContent } from "../../functions/get-content/index.js";
|
|
6
5
|
import { fetch } from "../../functions/get-fetch.js";
|
|
@@ -9,17 +8,15 @@ import { isEditing } from "../../functions/is-editing.js";
|
|
|
9
8
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
10
9
|
import { components, createRegisterComponentMessage, } from "../../functions/register-component.js";
|
|
11
10
|
import { _track } from "../../functions/track/index.js";
|
|
12
|
-
import "../../types/builder-content.js";
|
|
13
|
-
import "../../types/typescript.js";
|
|
14
11
|
import RenderBlocks from "../render-blocks.svelte";
|
|
15
12
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
16
13
|
import builderContext from "../../context/builder.context.js";
|
|
17
14
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
|
|
18
15
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
19
16
|
import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
|
|
20
|
-
import "./render-content.types.js";
|
|
21
17
|
import { getContentInitialValue, getContextStateInitialValue, } from "./render-content.helpers.js";
|
|
22
18
|
import { TARGET } from "../../constants/target.js";
|
|
19
|
+
import { logger } from "../../helpers/logger.js";
|
|
23
20
|
export let content;
|
|
24
21
|
export let data;
|
|
25
22
|
export let canTrack;
|
|
@@ -198,7 +195,7 @@ let httpReqsData = {};
|
|
|
198
195
|
let clicked = false;
|
|
199
196
|
onMount(() => {
|
|
200
197
|
if (!apiKey) {
|
|
201
|
-
|
|
198
|
+
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
202
199
|
}
|
|
203
200
|
if (isBrowser()) {
|
|
204
201
|
if (isEditing()) {
|
|
@@ -237,20 +234,21 @@ onMount(() => {
|
|
|
237
234
|
// override normal content in preview mode
|
|
238
235
|
if (isPreviewing()) {
|
|
239
236
|
const searchParams = new URL(location.href).searchParams;
|
|
240
|
-
const
|
|
237
|
+
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
238
|
+
const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
|
|
241
239
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
242
240
|
/**
|
|
243
241
|
* Make sure that:
|
|
244
242
|
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
|
|
245
243
|
* at the same time, e.g. header/page/footer.
|
|
246
244
|
* - the API key is the same, since we don't want to preview content from other organizations.
|
|
247
|
-
*
|
|
248
|
-
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
249
|
-
* this break scenarios where the item is not published yet?
|
|
245
|
+
* - if there is content, that the preview ID is the same as that of the one we receive.
|
|
250
246
|
*
|
|
251
247
|
* TO-DO: should we only update the state when there is a change?
|
|
252
248
|
**/
|
|
253
|
-
if (
|
|
249
|
+
if (searchParamPreviewModel === model &&
|
|
250
|
+
previewApiKey === apiKey &&
|
|
251
|
+
(!content || searchParamPreviewId === content.id)) {
|
|
254
252
|
getContent({
|
|
255
253
|
model: model,
|
|
256
254
|
apiKey: apiKey,
|
|
@@ -307,6 +305,9 @@ setContext(builderContext.key, {
|
|
|
307
305
|
get registeredComponents() {
|
|
308
306
|
return allRegisteredComponents;
|
|
309
307
|
},
|
|
308
|
+
get inheritedStyles() {
|
|
309
|
+
return {};
|
|
310
|
+
},
|
|
310
311
|
});
|
|
311
312
|
onDestroy(() => {
|
|
312
313
|
if (isBrowser()) {
|
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target.js';
|
|
2
2
|
import { convertStyleMapToCSSArray } from '../helpers/css.js';
|
|
3
3
|
import { transformBlockProperties } from './transform-block-properties.js';
|
|
4
|
+
const extractRelevantRootBlockProperties = (block) => {
|
|
5
|
+
// currently we are only spreading the `href` property
|
|
6
|
+
// TO-DO: potentially spread all properties from block, but only if they are not already defined by BuilderBlock
|
|
7
|
+
// const {
|
|
8
|
+
// '@type': _type,
|
|
9
|
+
// '@version': _version,
|
|
10
|
+
// id: _id,
|
|
11
|
+
// tagName: _tagName,
|
|
12
|
+
// layerName: _layerName,
|
|
13
|
+
// groupLocked: _groupLocked,
|
|
14
|
+
// layerLocked: _layerLocked,
|
|
15
|
+
// class: _class,
|
|
16
|
+
// children: _children,
|
|
17
|
+
// responsiveStyles: _responsiveStyles,
|
|
18
|
+
// component: _component,
|
|
19
|
+
// bindings: _bindings,
|
|
20
|
+
// meta: _meta,
|
|
21
|
+
// actions: _actions,
|
|
22
|
+
// properties: _properties,
|
|
23
|
+
// code: _code,
|
|
24
|
+
// repeat: _repeat,
|
|
25
|
+
// animations: _animations,
|
|
26
|
+
// style: _style,
|
|
27
|
+
// hide: _hide,
|
|
28
|
+
// show: _show,
|
|
29
|
+
// // anything set by dynamic bindings outside of predefined `BuilderBlock` properties
|
|
30
|
+
// ...remainingBlockProperties
|
|
31
|
+
// } = block;
|
|
32
|
+
return { href: block.href };
|
|
33
|
+
};
|
|
4
34
|
export function getBlockProperties(block) {
|
|
5
35
|
const properties = {
|
|
36
|
+
...extractRelevantRootBlockProperties(block),
|
|
6
37
|
...block.properties,
|
|
7
38
|
'builder-id': block.id,
|
|
8
39
|
style: getStyleAttribute(block.style),
|
|
@@ -7,5 +7,5 @@ type ContentResponse = {
|
|
|
7
7
|
status: number;
|
|
8
8
|
message: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function getAllContent(options: GetContentOptions): Promise<ContentResponse>;
|
|
10
|
+
export declare function getAllContent(options: GetContentOptions): Promise<ContentResponse | null>;
|
|
11
11
|
export {};
|
|
@@ -1,33 +1,40 @@
|
|
|
1
|
+
import { logger } from '../../helpers/logger.js';
|
|
1
2
|
import { fetch } from '../get-fetch.js';
|
|
2
3
|
import { handleABTesting } from './ab-testing.js';
|
|
3
4
|
import { generateContentUrl } from './generate-content-url.js';
|
|
4
5
|
export async function getContent(options) {
|
|
5
6
|
const allContent = await getAllContent({ ...options, limit: 1 });
|
|
6
|
-
if ('results' in allContent) {
|
|
7
|
+
if (allContent && 'results' in allContent) {
|
|
7
8
|
return allContent?.results[0] || null;
|
|
8
9
|
}
|
|
9
10
|
return null;
|
|
10
11
|
}
|
|
11
12
|
export async function getAllContent(options) {
|
|
12
|
-
const url = generateContentUrl(options);
|
|
13
|
-
const res = await fetch(url.href);
|
|
14
|
-
const content = await res.json();
|
|
15
|
-
if ('status' in content && !('results' in content)) {
|
|
16
|
-
console.error('[Builder.io]: Error fetching data. ', content, options);
|
|
17
|
-
return content;
|
|
18
|
-
}
|
|
19
|
-
const canTrack = options.canTrack !== false;
|
|
20
13
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
const url = generateContentUrl(options);
|
|
15
|
+
const res = await fetch(url.href);
|
|
16
|
+
const content = await res.json();
|
|
17
|
+
if ('status' in content && !('results' in content)) {
|
|
18
|
+
logger.error('Error fetching data. ', { url, content, options });
|
|
19
|
+
return content;
|
|
20
|
+
}
|
|
21
|
+
const canTrack = options.canTrack !== false;
|
|
22
|
+
try {
|
|
23
|
+
if (canTrack &&
|
|
24
|
+
// This makes sure we have a non-error response with the results array.
|
|
25
|
+
Array.isArray(content.results)) {
|
|
26
|
+
for (const item of content.results) {
|
|
27
|
+
await handleABTesting({ item, canTrack });
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
logger.error('Could not setup A/B testing. ', e);
|
|
33
|
+
}
|
|
34
|
+
return content;
|
|
28
35
|
}
|
|
29
|
-
catch (
|
|
30
|
-
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger.error('Error fetching data. ', error);
|
|
38
|
+
return null;
|
|
31
39
|
}
|
|
32
|
-
return content;
|
|
33
40
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TARGET } from '../../constants/target.js';
|
|
2
|
+
import { logger } from '../../helpers/logger.js';
|
|
2
3
|
import { getSessionId } from '../../helpers/sessionId.js';
|
|
3
4
|
import { getVisitorId } from '../../helpers/visitorId.js';
|
|
4
5
|
import { isBrowser } from '../is-browser.js';
|
|
@@ -30,7 +31,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
|
|
|
30
31
|
});
|
|
31
32
|
export async function _track(eventProps) {
|
|
32
33
|
if (!eventProps.apiKey) {
|
|
33
|
-
|
|
34
|
+
logger.error('Missing API key for track call. Please provide your API key.');
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
37
|
if (!eventProps.canTrack) {
|
package/package/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export * from './functions/get-builder-search-params/index.js';
|
|
|
10
10
|
export { track } from './functions/track/index.js';
|
|
11
11
|
export type { RegisteredComponent } from './context/types';
|
|
12
12
|
export type { ComponentInfo } from './types/components';
|
|
13
|
+
export type { RenderContentProps } from './components/render-content/render-content.types.js';
|