@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
|
@@ -1,76 +1,5 @@
|
|
|
1
1
|
import type { BuilderElement } from './element';
|
|
2
|
-
|
|
3
|
-
name: string;
|
|
4
|
-
friendlyName?: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
defaultValue?: any;
|
|
7
|
-
type: string;
|
|
8
|
-
valueType?: {
|
|
9
|
-
type?: string;
|
|
10
|
-
};
|
|
11
|
-
required?: boolean;
|
|
12
|
-
autoFocus?: boolean;
|
|
13
|
-
subFields?: Input[];
|
|
14
|
-
helperText?: string;
|
|
15
|
-
allowedFileTypes?: string[];
|
|
16
|
-
imageHeight?: number;
|
|
17
|
-
imageWidth?: number;
|
|
18
|
-
mediaHeight?: number;
|
|
19
|
-
mediaWidth?: number;
|
|
20
|
-
hideFromUI?: boolean;
|
|
21
|
-
modelId?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Number field type validation maximum accepted input
|
|
24
|
-
*/
|
|
25
|
-
max?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Number field type validation minimum accepted input
|
|
28
|
-
*/
|
|
29
|
-
min?: number;
|
|
30
|
-
/**
|
|
31
|
-
* Number field type step size when using arrows
|
|
32
|
-
*/
|
|
33
|
-
step?: number;
|
|
34
|
-
/**
|
|
35
|
-
* Set this to `true` to show the editor for this input when
|
|
36
|
-
* children of this component are selected. This is useful for things
|
|
37
|
-
* like Tabs, such that users may not always select the Tabs component
|
|
38
|
-
* directly but will still be looking for how to add additional tabs
|
|
39
|
-
*/
|
|
40
|
-
broadcast?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Set this to `true` to show the editor for this input when
|
|
43
|
-
* group locked parents of this component are selected. This is useful
|
|
44
|
-
* to bubble up important inputs for locked groups, like text and images
|
|
45
|
-
*/
|
|
46
|
-
bubble?: boolean;
|
|
47
|
-
options?: {
|
|
48
|
-
[key: string]: any;
|
|
49
|
-
};
|
|
50
|
-
enum?: string[] | {
|
|
51
|
-
label: string;
|
|
52
|
-
value: any;
|
|
53
|
-
helperText?: string;
|
|
54
|
-
}[];
|
|
55
|
-
/** Regex field validation for all string types (text, longText, html, url, etc) */
|
|
56
|
-
regex?: {
|
|
57
|
-
/** pattern to test, like "^\/[a-z]$" */
|
|
58
|
-
pattern: string;
|
|
59
|
-
/** flags for the RegExp constructor, e.g. "gi" */
|
|
60
|
-
options?: string;
|
|
61
|
-
/**
|
|
62
|
-
* Friendly message to display to end-users if the regex fails, e.g.
|
|
63
|
-
* "You must use a relative url starting with '/...' "
|
|
64
|
-
*/
|
|
65
|
-
message: string;
|
|
66
|
-
};
|
|
67
|
-
advanced?: boolean;
|
|
68
|
-
onChange?: ((options: Map<string, any>) => void | Promise<void>) | string;
|
|
69
|
-
code?: boolean;
|
|
70
|
-
richText?: boolean;
|
|
71
|
-
showIf?: ((options: Map<string, any>) => boolean) | string;
|
|
72
|
-
copyOnAdd?: boolean;
|
|
73
|
-
}
|
|
2
|
+
import type { Input } from './input';
|
|
74
3
|
export interface ComponentInfo {
|
|
75
4
|
/**
|
|
76
5
|
* Name your component something unique, e.g. 'MyButton'. You can override built-in components
|
package/package/types/input.d.ts
CHANGED
|
@@ -114,4 +114,8 @@ export interface Input {
|
|
|
114
114
|
* Use optionally with inputs of type `reference`. Restricts the content entry picker to a specific model by name.
|
|
115
115
|
*/
|
|
116
116
|
model?: string;
|
|
117
|
+
valueType?: {
|
|
118
|
+
type?: string;
|
|
119
|
+
};
|
|
120
|
+
onChange?: ((options: Map<string, any>) => void | Promise<void>) | string;
|
|
117
121
|
}
|
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.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@sveltejs/adapter-auto": "1.0.0-next.71",
|
|
42
|
-
"@sveltejs/kit": "1.
|
|
42
|
+
"@sveltejs/kit": "^1.15.2",
|
|
43
43
|
"@sveltejs/package": "1.0.0-next.1",
|
|
44
44
|
"svelte": "^3.44.0",
|
|
45
45
|
"svelte-check": "^2.7.1",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
import { getContext } from "svelte";
|
|
26
26
|
|
|
27
27
|
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
28
|
-
import { BuilderBlock } from "../../types/builder-block";
|
|
28
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
29
29
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
30
|
-
import { SizeName } from "../../constants/device-sizes";
|
|
30
|
+
import type { SizeName } from "../../constants/device-sizes";
|
|
31
31
|
import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
|
|
32
32
|
import { TARGET } from "../../constants/target.js";
|
|
33
33
|
import BuilderContext from "../../context/builder.context.js";
|
|
34
|
-
import { Dictionary } from "../../types/typescript";
|
|
34
|
+
import type { Dictionary } from "../../types/typescript";
|
|
35
35
|
|
|
36
36
|
export let space: ColumnProps["space"];
|
|
37
37
|
export let columns: ColumnProps["columns"];
|
|
@@ -130,30 +130,30 @@
|
|
|
130
130
|
};
|
|
131
131
|
$: columnsStyles = () => {
|
|
132
132
|
return `
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
134
|
+
.${builderBlock.id}-breakpoints {
|
|
135
|
+
flex-direction: var(--flex-dir-tablet);
|
|
136
|
+
align-items: stretch;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.${builderBlock.id}-breakpoints > .builder-column {
|
|
140
|
+
width: var(--column-width-tablet) !important;
|
|
141
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.${builderBlock.id}-breakpoints > .builder-column {
|
|
152
|
-
width: var(--column-width-mobile) !important;
|
|
153
|
-
margin-left: var(--column-margin-left-mobile) !important;
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
`;
|
|
145
|
+
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
146
|
+
.${builderBlock.id}-breakpoints {
|
|
147
|
+
flex-direction: var(--flex-dir);
|
|
148
|
+
align-items: stretch;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.${builderBlock.id}-breakpoints > .builder-column {
|
|
152
|
+
width: var(--column-width-mobile) !important;
|
|
153
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
`;
|
|
157
157
|
};
|
|
158
158
|
|
|
159
159
|
let gutterSize = typeof space === "number" ? space || 0 : 20;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
height?: number;
|
|
8
8
|
width?: number;
|
|
9
9
|
altText?: string;
|
|
10
|
-
backgroundSize?:
|
|
10
|
+
backgroundSize?: "cover" | "contain";
|
|
11
11
|
backgroundPosition?: string;
|
|
12
12
|
srcset?: string;
|
|
13
13
|
aspectRatio?: number;
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
</script>
|
|
21
21
|
|
|
22
22
|
<script lang="ts">
|
|
23
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
23
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
24
24
|
import { getSrcSet } from "./image.helpers.js";
|
|
25
25
|
|
|
26
26
|
export let image: ImageProps["image"];
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
width: "100%",
|
|
82
82
|
left: "0px",
|
|
83
83
|
top: "0px",
|
|
84
|
-
};
|
|
84
|
+
} as const;
|
|
85
85
|
const out = aspectRatio ? aspectRatioStyles : undefined;
|
|
86
86
|
return out;
|
|
87
87
|
};
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
import RenderContent from "../../components/render-content/render-content.svelte";
|
|
25
25
|
import BuilderContext from "../../context/builder.context.js";
|
|
26
26
|
import { getContent } from "../../functions/get-content/index.js";
|
|
27
|
-
import { BuilderContent } from "../../types/builder-content.js";
|
|
28
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
27
|
+
import type { BuilderContent } from "../../types/builder-content.js";
|
|
28
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
29
29
|
import { TARGET } from "../../constants/target";
|
|
30
|
+
import { logger } from "../../helpers/logger";
|
|
30
31
|
|
|
31
32
|
const isEvent = (attr) => attr.startsWith("on:");
|
|
32
33
|
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
@@ -93,7 +94,7 @@
|
|
|
93
94
|
}
|
|
94
95
|
})
|
|
95
96
|
.catch((err) => {
|
|
96
|
-
|
|
97
|
+
logger.error("Could not fetch symbol content: ", err);
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
}
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
getSizesForBreakpoints,
|
|
12
12
|
} from "../../constants/device-sizes.js";
|
|
13
13
|
import { TARGET } from "../../constants/target.js";
|
|
14
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
14
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
15
15
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
16
16
|
import { createCssClass } from "../../helpers/css.js";
|
|
17
17
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
18
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
19
19
|
import RenderInlinedStyles from "../render-inlined-styles.svelte";
|
|
20
20
|
|
|
21
21
|
export let block: BlockStylesProps["block"];
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
9
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
10
10
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
11
11
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
12
12
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
13
13
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
14
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
14
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
15
|
import BlockStyles from "./block-styles.svelte";
|
|
16
16
|
import {
|
|
17
17
|
getComponent,
|
|
@@ -19,13 +19,12 @@
|
|
|
19
19
|
getRepeatItemData,
|
|
20
20
|
isEmptyHtmlElement,
|
|
21
21
|
} from "./render-block.helpers.js";
|
|
22
|
-
import { RenderComponentProps } from "./render-component.svelte";
|
|
22
|
+
import type { RenderComponentProps } from "./render-component.svelte";
|
|
23
23
|
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
24
24
|
import { TARGET } from "../../constants/target.js";
|
|
25
25
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
26
26
|
import RenderComponent from "./render-component.svelte";
|
|
27
27
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
28
|
-
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
29
28
|
|
|
30
29
|
const setAttrs = (node, attrs = {}) => {
|
|
31
30
|
const attrKeys = Object.keys(attrs);
|
|
@@ -59,10 +58,10 @@
|
|
|
59
58
|
});
|
|
60
59
|
};
|
|
61
60
|
$: canShowBlock = () => {
|
|
62
|
-
if (
|
|
61
|
+
if ("hide" in useBlock()) {
|
|
63
62
|
return !useBlock().hide;
|
|
64
63
|
}
|
|
65
|
-
if (
|
|
64
|
+
if ("show" in useBlock()) {
|
|
66
65
|
return useBlock().show;
|
|
67
66
|
}
|
|
68
67
|
return true;
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
19
19
|
import BlockStyles from "./block-styles.svelte";
|
|
20
20
|
import RenderBlock from "./render-block.svelte";
|
|
21
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
21
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
22
22
|
|
|
23
23
|
export let componentRef: RenderComponentProps["componentRef"];
|
|
24
24
|
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
import { setContext } from "svelte";
|
|
20
20
|
|
|
21
21
|
import BuilderContext from "../../context/builder.context.js";
|
|
22
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
23
|
-
import { BuilderBlock } from "../../types/builder-block";
|
|
22
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
23
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
24
24
|
import RenderBlock from "./render-block.svelte";
|
|
25
25
|
|
|
26
26
|
export let block: Props["block"];
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
apiKey: repeatContext.apiKey,
|
|
35
35
|
registeredComponents: repeatContext.registeredComponents,
|
|
36
36
|
inheritedStyles: repeatContext.inheritedStyles,
|
|
37
|
+
apiVersion: repeatContext.apiVersion,
|
|
37
38
|
});
|
|
38
39
|
</script>
|
|
39
40
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import BuilderContext from "../context/builder.context.js";
|
|
14
14
|
import { isEditing } from "../functions/is-editing.js";
|
|
15
|
-
import { BuilderBlock } from "../types/builder-block.js";
|
|
15
|
+
import type { BuilderBlock } from "../types/builder-block.js";
|
|
16
16
|
import BlockStyles from "./render-block/block-styles.svelte";
|
|
17
17
|
import RenderBlock from "./render-block/render-block.svelte";
|
|
18
18
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
<script lang="ts">
|
|
10
10
|
import RenderInlinedStyles from "../../render-inlined-styles.svelte";
|
|
11
|
-
import { CustomFont } from "./render-styles.helpers";
|
|
11
|
+
import type { CustomFont } from "./render-styles.helpers";
|
|
12
12
|
import { getCss } from "./render-styles.helpers";
|
|
13
13
|
import { getFontCss } from "./render-styles.helpers";
|
|
14
14
|
|
|
@@ -26,16 +26,16 @@ ${getFontCss({
|
|
|
26
26
|
})}
|
|
27
27
|
|
|
28
28
|
.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
|
|
29
|
-
margin: 0;
|
|
29
|
+
margin: 0;
|
|
30
30
|
}
|
|
31
31
|
.builder-text > p, .builder-text > .builder-paragraph {
|
|
32
|
-
color: inherit;
|
|
33
|
-
line-height: inherit;
|
|
34
|
-
letter-spacing: inherit;
|
|
35
|
-
font-weight: inherit;
|
|
36
|
-
font-size: inherit;
|
|
37
|
-
text-align: inherit;
|
|
38
|
-
font-family: inherit;
|
|
32
|
+
color: inherit;
|
|
33
|
+
line-height: inherit;
|
|
34
|
+
letter-spacing: inherit;
|
|
35
|
+
font-weight: inherit;
|
|
36
|
+
font-size: inherit;
|
|
37
|
+
text-align: inherit;
|
|
38
|
+
font-family: inherit;
|
|
39
39
|
}
|
|
40
40
|
`;
|
|
41
41
|
</script>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { onDestroy, onMount, setContext } from "svelte";
|
|
3
3
|
|
|
4
4
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
6
|
BuilderRenderState,
|
|
7
7
|
RegisteredComponent,
|
|
8
8
|
RegisteredComponents,
|
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
createRegisterComponentMessage,
|
|
19
19
|
} from "../../functions/register-component.js";
|
|
20
20
|
import { _track } from "../../functions/track/index.js";
|
|
21
|
-
import {
|
|
22
|
-
|
|
21
|
+
import type {
|
|
22
|
+
Breakpoints,
|
|
23
|
+
BuilderContent,
|
|
24
|
+
} from "../../types/builder-content.js";
|
|
25
|
+
import type { Nullable } from "../../types/typescript.js";
|
|
23
26
|
import RenderBlocks from "../render-blocks.svelte";
|
|
24
27
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
25
28
|
import builderContext from "../../context/builder.context.js";
|
|
@@ -29,7 +32,7 @@
|
|
|
29
32
|
} from "../../scripts/init-editing.js";
|
|
30
33
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
31
34
|
import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
|
|
32
|
-
import {
|
|
35
|
+
import type {
|
|
33
36
|
RenderContentProps,
|
|
34
37
|
BuilderComponentStateChange,
|
|
35
38
|
} from "./render-content.types.js";
|
|
@@ -38,6 +41,7 @@
|
|
|
38
41
|
getContextStateInitialValue,
|
|
39
42
|
} from "./render-content.helpers.js";
|
|
40
43
|
import { TARGET } from "../../constants/target.js";
|
|
44
|
+
import { logger } from "../../helpers/logger.js";
|
|
41
45
|
|
|
42
46
|
export let content: RenderContentProps["content"];
|
|
43
47
|
export let data: RenderContentProps["data"];
|
|
@@ -236,8 +240,8 @@
|
|
|
236
240
|
|
|
237
241
|
onMount(() => {
|
|
238
242
|
if (!apiKey) {
|
|
239
|
-
|
|
240
|
-
"
|
|
243
|
+
logger.error(
|
|
244
|
+
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
241
245
|
);
|
|
242
246
|
}
|
|
243
247
|
if (isBrowser()) {
|
|
@@ -283,7 +287,10 @@
|
|
|
283
287
|
// override normal content in preview mode
|
|
284
288
|
if (isPreviewing()) {
|
|
285
289
|
const searchParams = new URL(location.href).searchParams;
|
|
286
|
-
const
|
|
290
|
+
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
291
|
+
const searchParamPreviewId = searchParams.get(
|
|
292
|
+
`builder.preview.${searchParamPreviewModel}`
|
|
293
|
+
);
|
|
287
294
|
const previewApiKey =
|
|
288
295
|
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
289
296
|
|
|
@@ -292,13 +299,15 @@
|
|
|
292
299
|
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
|
|
293
300
|
* at the same time, e.g. header/page/footer.
|
|
294
301
|
* - the API key is the same, since we don't want to preview content from other organizations.
|
|
295
|
-
*
|
|
296
|
-
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
297
|
-
* this break scenarios where the item is not published yet?
|
|
302
|
+
* - if there is content, that the preview ID is the same as that of the one we receive.
|
|
298
303
|
*
|
|
299
304
|
* TO-DO: should we only update the state when there is a change?
|
|
300
305
|
**/
|
|
301
|
-
if (
|
|
306
|
+
if (
|
|
307
|
+
searchParamPreviewModel === model &&
|
|
308
|
+
previewApiKey === apiKey &&
|
|
309
|
+
(!content || searchParamPreviewId === content.id)
|
|
310
|
+
) {
|
|
302
311
|
getContent({
|
|
303
312
|
model: model,
|
|
304
313
|
apiKey: apiKey,
|
|
@@ -357,6 +366,9 @@
|
|
|
357
366
|
get registeredComponents() {
|
|
358
367
|
return allRegisteredComponents;
|
|
359
368
|
},
|
|
369
|
+
get inheritedStyles() {
|
|
370
|
+
return {};
|
|
371
|
+
},
|
|
360
372
|
});
|
|
361
373
|
|
|
362
374
|
onDestroy(() => {
|
|
@@ -3,8 +3,42 @@ import { convertStyleMapToCSSArray } from '../helpers/css.js';
|
|
|
3
3
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
4
4
|
import { transformBlockProperties } from './transform-block-properties.js';
|
|
5
5
|
|
|
6
|
+
const extractRelevantRootBlockProperties = (block: BuilderBlock) => {
|
|
7
|
+
// currently we are only spreading the `href` property
|
|
8
|
+
// TO-DO: potentially spread all properties from block, but only if they are not already defined by BuilderBlock
|
|
9
|
+
|
|
10
|
+
// const {
|
|
11
|
+
// '@type': _type,
|
|
12
|
+
// '@version': _version,
|
|
13
|
+
// id: _id,
|
|
14
|
+
// tagName: _tagName,
|
|
15
|
+
// layerName: _layerName,
|
|
16
|
+
// groupLocked: _groupLocked,
|
|
17
|
+
// layerLocked: _layerLocked,
|
|
18
|
+
// class: _class,
|
|
19
|
+
// children: _children,
|
|
20
|
+
// responsiveStyles: _responsiveStyles,
|
|
21
|
+
// component: _component,
|
|
22
|
+
// bindings: _bindings,
|
|
23
|
+
// meta: _meta,
|
|
24
|
+
// actions: _actions,
|
|
25
|
+
// properties: _properties,
|
|
26
|
+
// code: _code,
|
|
27
|
+
// repeat: _repeat,
|
|
28
|
+
// animations: _animations,
|
|
29
|
+
// style: _style,
|
|
30
|
+
// hide: _hide,
|
|
31
|
+
// show: _show,
|
|
32
|
+
// // anything set by dynamic bindings outside of predefined `BuilderBlock` properties
|
|
33
|
+
// ...remainingBlockProperties
|
|
34
|
+
// } = block;
|
|
35
|
+
|
|
36
|
+
return { href: (block as any).href };
|
|
37
|
+
};
|
|
38
|
+
|
|
6
39
|
export function getBlockProperties(block: BuilderBlock) {
|
|
7
40
|
const properties = {
|
|
41
|
+
...extractRelevantRootBlockProperties(block),
|
|
8
42
|
...block.properties,
|
|
9
43
|
'builder-id': block.id,
|
|
10
44
|
style: getStyleAttribute(block.style),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from '../../helpers/logger.js';
|
|
1
2
|
import type { BuilderContent } from '../../types/builder-content.js';
|
|
2
3
|
import { fetch } from '../get-fetch.js';
|
|
3
4
|
import { handleABTesting } from './ab-testing.js';
|
|
@@ -8,7 +9,7 @@ export async function getContent(
|
|
|
8
9
|
options: GetContentOptions
|
|
9
10
|
): Promise<BuilderContent | null> {
|
|
10
11
|
const allContent = await getAllContent({ ...options, limit: 1 });
|
|
11
|
-
if ('results' in allContent) {
|
|
12
|
+
if (allContent && 'results' in allContent) {
|
|
12
13
|
return allContent?.results[0] || null;
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -26,31 +27,36 @@ type ContentResponse =
|
|
|
26
27
|
|
|
27
28
|
export async function getAllContent(
|
|
28
29
|
options: GetContentOptions
|
|
29
|
-
): Promise<ContentResponse> {
|
|
30
|
-
|
|
30
|
+
): Promise<ContentResponse | null> {
|
|
31
|
+
try {
|
|
32
|
+
const url = generateContentUrl(options);
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
const res = await fetch(url.href);
|
|
35
|
+
const content = await (res.json() as Promise<ContentResponse>);
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if ('status' in content && !('results' in content)) {
|
|
38
|
+
logger.error('Error fetching data. ', { url, content, options });
|
|
39
|
+
return content;
|
|
40
|
+
}
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
const canTrack = options.canTrack !== false;
|
|
43
|
+
try {
|
|
44
|
+
if (
|
|
45
|
+
canTrack &&
|
|
46
|
+
// This makes sure we have a non-error response with the results array.
|
|
47
|
+
Array.isArray(content.results)
|
|
48
|
+
) {
|
|
49
|
+
for (const item of content.results) {
|
|
50
|
+
await handleABTesting({ item, canTrack });
|
|
51
|
+
}
|
|
49
52
|
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
logger.error('Could not setup A/B testing. ', e);
|
|
50
55
|
}
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error('[Builder.io]: Could not setup A/B testing. ', e);
|
|
53
|
-
}
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
return content;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logger.error('Error fetching data. ', error);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
56
62
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { serializeFn } from '../blocks/util.js';
|
|
2
2
|
import type { RegisteredComponent } from '../context/types.js';
|
|
3
|
-
import type { ComponentInfo
|
|
3
|
+
import type { ComponentInfo } from '../types/components.js';
|
|
4
|
+
import type { Input } from '../types/input.js';
|
|
4
5
|
import { fastClone } from './fast-clone.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -37,14 +38,13 @@ const prepareComponentInfoToSend = ({
|
|
|
37
38
|
...info
|
|
38
39
|
}: ComponentInfo): ComponentInfo => ({
|
|
39
40
|
...fastClone(info),
|
|
40
|
-
inputs: inputs?.map(
|
|
41
|
-
(input)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
41
|
+
inputs: inputs?.map((input) =>
|
|
42
|
+
Object.entries(input).reduce(
|
|
43
|
+
(acc, [key, value]) => ({
|
|
44
|
+
...acc,
|
|
45
|
+
[key]: serializeValue(value),
|
|
46
|
+
}),
|
|
47
|
+
{} as Input
|
|
48
|
+
)
|
|
49
49
|
),
|
|
50
50
|
});
|
|
@@ -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 type { CanTrack } from '../../types/can-track.js';
|
|
@@ -100,8 +101,8 @@ const createEvent = async ({
|
|
|
100
101
|
|
|
101
102
|
export async function _track(eventProps: EventProps) {
|
|
102
103
|
if (!eventProps.apiKey) {
|
|
103
|
-
|
|
104
|
-
'
|
|
104
|
+
logger.error(
|
|
105
|
+
'Missing API key for track call. Please provide your API key.'
|
|
105
106
|
);
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const MSG_PREFIX = '[Builder.io]: ';
|
|
2
|
+
export const logger = {
|
|
3
|
+
log: (...message: any[]) => console.log(MSG_PREFIX, ...message),
|
|
4
|
+
error: (...message: any[]) => console.error(MSG_PREFIX, ...message),
|
|
5
|
+
warn: (...message: any[]) => console.warn(MSG_PREFIX, ...message),
|
|
6
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -12,3 +12,4 @@ export * from './functions/get-builder-search-params/index.js';
|
|
|
12
12
|
export { track } from './functions/track/index.js';
|
|
13
13
|
export type { RegisteredComponent } from './context/types';
|
|
14
14
|
export type { ComponentInfo } from './types/components';
|
|
15
|
+
export type { RenderContentProps } from './components/render-content/render-content.types.js';
|