@builder.io/sdk-svelte 0.0.6 → 0.0.8
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 -3
- package/package/blocks/button/button.svelte +35 -3
- package/package/blocks/columns/columns.svelte +1 -2
- package/package/blocks/columns/component-info.js +2 -2
- package/package/blocks/embed/component-info.js +2 -2
- package/package/blocks/form/form.svelte +29 -1
- package/package/blocks/image/component-info.js +2 -2
- package/package/blocks/img/img.svelte +29 -1
- package/package/blocks/input/input.svelte +29 -1
- package/package/blocks/section/section.svelte +30 -2
- package/package/blocks/select/select.svelte +29 -1
- package/package/blocks/submit-button/submit-button.svelte +33 -2
- package/package/blocks/symbol/symbol.svelte +33 -8
- package/package/blocks/textarea/textarea.svelte +36 -2
- package/package/blocks/util.d.ts +4 -1
- package/package/blocks/util.js +13 -4
- package/package/blocks/video/video.svelte +30 -2
- package/package/components/render-block/block-styles.svelte +5 -3
- package/package/components/render-block/render-block.svelte +36 -15
- package/package/components/render-block/render-component.svelte +1 -2
- package/package/components/render-content/builder-editing.svelte +4 -0
- package/package/components/render-content/builder-editing.svelte.d.ts +14 -0
- package/package/components/render-content/render-content.svelte +6 -5
- package/package/components/render-inlined-styles.svelte +3 -3
- package/package/constants/device-sizes.d.ts +12 -1
- package/package/constants/device-sizes.js +27 -1
- package/package/functions/evaluate.d.ts +2 -1
- package/package/functions/evaluate.js +8 -5
- package/package/functions/event-handler-name.js +1 -4
- package/package/functions/get-block-actions-handler.d.ts +5 -2
- package/package/functions/get-block-actions-handler.js +7 -8
- package/package/functions/get-block-actions.js +2 -2
- package/package/functions/get-builder-search-params/index.d.ts +1 -1
- package/package/functions/get-content/index.js +5 -2
- package/package/functions/get-content/types.d.ts +4 -0
- package/package/functions/register-component.js +1 -13
- package/package/functions/track.d.ts +6 -1
- package/package/functions/track.js +4 -0
- package/package/index.d.ts +3 -1
- package/package/index.js +1 -1
- package/package/scripts/init-editing.js +6 -0
- package/package/types/builder-content.d.ts +7 -0
- package/package.json +2 -2
- package/src/blocks/button/button.svelte +41 -2
- package/src/blocks/columns/columns.svelte +1 -2
- package/src/blocks/columns/component-info.ts +2 -2
- package/src/blocks/embed/component-info.ts +2 -2
- package/src/blocks/form/form.svelte +36 -1
- package/src/blocks/image/component-info.ts +2 -2
- package/src/blocks/img/img.svelte +36 -1
- package/src/blocks/input/input.svelte +36 -1
- package/src/blocks/section/section.svelte +36 -1
- package/src/blocks/select/select.svelte +36 -1
- package/src/blocks/submit-button/submit-button.svelte +39 -1
- package/src/blocks/symbol/symbol.svelte +40 -8
- package/src/blocks/textarea/textarea.svelte +42 -1
- package/src/blocks/util.ts +18 -6
- package/src/blocks/video/video.svelte +36 -1
- package/src/components/render-block/block-styles.svelte +16 -3
- package/src/components/render-block/render-block.svelte +41 -15
- package/src/components/render-block/render-component.svelte +1 -2
- package/src/components/render-content/builder-editing.svelte +4 -0
- package/src/components/render-content/render-content.svelte +8 -5
- package/src/components/render-inlined-styles.svelte +3 -3
- package/src/constants/device-sizes.ts +39 -2
- package/src/functions/evaluate.ts +11 -6
- package/src/functions/event-handler-name.ts +1 -6
- package/src/functions/get-block-actions-handler.ts +10 -9
- package/src/functions/get-block-actions.ts +2 -2
- package/src/functions/get-builder-search-params/index.ts +1 -1
- package/src/functions/get-content/index.ts +6 -1
- package/src/functions/get-content/types.ts +5 -0
- package/src/functions/register-component.ts +1 -18
- package/src/functions/track.ts +13 -1
- package/src/index.ts +3 -1
- package/src/scripts/init-editing.ts +6 -0
- package/src/types/builder-content.ts +7 -0
- package/package/functions/mark-mutable.d.ts +0 -2
- package/package/functions/mark-mutable.js +0 -6
- package/src/functions/mark-mutable.ts +0 -7
|
@@ -34,6 +34,27 @@
|
|
|
34
34
|
import RenderComponent from "./render-component.svelte";
|
|
35
35
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
36
36
|
|
|
37
|
+
const setAttrs = (node, attrs) => {
|
|
38
|
+
const attrKeys = Object.keys(attrs);
|
|
39
|
+
|
|
40
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
41
|
+
const teardown = (attr) =>
|
|
42
|
+
node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
43
|
+
|
|
44
|
+
attrKeys.map(setup);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
update(attrs) {
|
|
48
|
+
const attrKeys = Object.keys(attrs);
|
|
49
|
+
attrKeys.map(teardown);
|
|
50
|
+
attrKeys.map(setup);
|
|
51
|
+
},
|
|
52
|
+
destroy() {
|
|
53
|
+
attrKeys.map(teardown);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
37
58
|
export let block: RenderBlockProps["block"];
|
|
38
59
|
export let context: RenderBlockProps["context"];
|
|
39
60
|
|
|
@@ -58,7 +79,7 @@
|
|
|
58
79
|
return ref;
|
|
59
80
|
}
|
|
60
81
|
};
|
|
61
|
-
$:
|
|
82
|
+
$: tag = () => {
|
|
62
83
|
return getBlockTag(useBlock());
|
|
63
84
|
};
|
|
64
85
|
$: useBlock = () => {
|
|
@@ -71,14 +92,16 @@
|
|
|
71
92
|
shouldEvaluateBindings: true,
|
|
72
93
|
});
|
|
73
94
|
};
|
|
95
|
+
$: actions = () => {
|
|
96
|
+
return getBlockActions({
|
|
97
|
+
block: useBlock(),
|
|
98
|
+
state: context.state,
|
|
99
|
+
context: context.context,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
74
102
|
$: attributes = () => {
|
|
75
103
|
return {
|
|
76
104
|
...getBlockProperties(useBlock()),
|
|
77
|
-
...getBlockActions({
|
|
78
|
-
block: useBlock(),
|
|
79
|
-
state: context.state,
|
|
80
|
-
context: context.context,
|
|
81
|
-
}),
|
|
82
105
|
...(TARGET === "reactNative"
|
|
83
106
|
? {
|
|
84
107
|
style: getReactNativeBlockStyles({
|
|
@@ -94,7 +117,7 @@
|
|
|
94
117
|
};
|
|
95
118
|
$: renderComponentProps = () => {
|
|
96
119
|
return {
|
|
97
|
-
blockChildren:
|
|
120
|
+
blockChildren: useChildren(),
|
|
98
121
|
componentRef: component?.()?.component,
|
|
99
122
|
componentOptions: {
|
|
100
123
|
...getBlockComponentOptions(useBlock()),
|
|
@@ -105,13 +128,16 @@
|
|
|
105
128
|
...(shouldWrap()
|
|
106
129
|
? {}
|
|
107
130
|
: {
|
|
108
|
-
attributes:
|
|
131
|
+
attributes: {
|
|
132
|
+
...attributes(),
|
|
133
|
+
...actions(),
|
|
134
|
+
},
|
|
109
135
|
}),
|
|
110
136
|
},
|
|
111
137
|
context: childrenContext(),
|
|
112
138
|
};
|
|
113
139
|
};
|
|
114
|
-
$:
|
|
140
|
+
$: useChildren = () => {
|
|
115
141
|
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
116
142
|
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
117
143
|
// but still receive and need to render children.
|
|
@@ -127,7 +153,7 @@
|
|
|
127
153
|
*/
|
|
128
154
|
const shouldRenderChildrenOutsideRef =
|
|
129
155
|
!component?.()?.component && !repeatItemData();
|
|
130
|
-
return shouldRenderChildrenOutsideRef ?
|
|
156
|
+
return shouldRenderChildrenOutsideRef ? useChildren() : [];
|
|
131
157
|
};
|
|
132
158
|
$: repeatItemData = () => {
|
|
133
159
|
/**
|
|
@@ -197,18 +223,18 @@
|
|
|
197
223
|
</script>
|
|
198
224
|
|
|
199
225
|
{#if shouldWrap()}
|
|
200
|
-
{#if isEmptyHtmlElement(
|
|
201
|
-
<svelte:element this={
|
|
226
|
+
{#if isEmptyHtmlElement(tag())}
|
|
227
|
+
<svelte:element this={tag()} {...attributes()} use:setAttrs={actions()} />
|
|
202
228
|
{/if}
|
|
203
229
|
|
|
204
|
-
{#if !isEmptyHtmlElement(
|
|
230
|
+
{#if !isEmptyHtmlElement(tag()) && repeatItemData()}
|
|
205
231
|
{#each repeatItemData() as data, index (index)}
|
|
206
232
|
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
207
233
|
{/each}
|
|
208
234
|
{/if}
|
|
209
235
|
|
|
210
|
-
{#if !isEmptyHtmlElement(
|
|
211
|
-
<svelte:element this={
|
|
236
|
+
{#if !isEmptyHtmlElement(tag()) && !repeatItemData()}
|
|
237
|
+
<svelte:element this={tag()} {...attributes()} use:setAttrs={actions()}>
|
|
212
238
|
<svelte:component
|
|
213
239
|
this={renderComponentTag()}
|
|
214
240
|
{...renderComponentProps()}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
<script lang="ts">
|
|
15
15
|
import BlockStyles from "./block-styles.svelte";
|
|
16
16
|
import RenderBlock from "./render-block.svelte";
|
|
17
|
-
import { markPropsMutable } from "../../functions/mark-mutable.js";
|
|
18
17
|
|
|
19
18
|
export let componentRef: RenderComponentProps["componentRef"];
|
|
20
19
|
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
</script>
|
|
24
23
|
|
|
25
24
|
{#if componentRef}
|
|
26
|
-
<svelte:component this={componentRef} {...
|
|
25
|
+
<svelte:component this={componentRef} {...componentOptions}>
|
|
27
26
|
{#each blockChildren as child ("render-block-" + child.id)}
|
|
28
27
|
<RenderBlock block={child} {context} />
|
|
29
28
|
{/each}
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
|
|
47
47
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
48
48
|
import { TARGET } from "../../constants/target.js";
|
|
49
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
50
49
|
import { evaluate } from "../../functions/evaluate.js";
|
|
51
50
|
import { getContent } from "../../functions/get-content/index.js";
|
|
52
51
|
import { getFetch } from "../../functions/get-fetch.js";
|
|
@@ -60,11 +59,11 @@
|
|
|
60
59
|
import { _track } from "../../functions/track.js";
|
|
61
60
|
import RenderBlocks from "../render-blocks.svelte";
|
|
62
61
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
62
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
63
63
|
import {
|
|
64
64
|
registerInsertMenu,
|
|
65
65
|
setupBrowserForEditing,
|
|
66
66
|
} from "../../scripts/init-editing.js";
|
|
67
|
-
import { markMutable } from "../../functions/mark-mutable.js";
|
|
68
67
|
|
|
69
68
|
export let content: RenderContentProps["content"];
|
|
70
69
|
export let data: RenderContentProps["data"];
|
|
@@ -259,10 +258,14 @@
|
|
|
259
258
|
let overrideState = {};
|
|
260
259
|
|
|
261
260
|
onMount(() => {
|
|
261
|
+
if (!apiKey) {
|
|
262
|
+
console.error(
|
|
263
|
+
"[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
264
|
+
);
|
|
265
|
+
}
|
|
262
266
|
if (isBrowser()) {
|
|
263
267
|
if (isEditing()) {
|
|
264
268
|
forceReRenderCount = forceReRenderCount + 1;
|
|
265
|
-
// QWIK-REPLACE: _useMutableProps
|
|
266
269
|
registerInsertMenu();
|
|
267
270
|
setupBrowserForEditing();
|
|
268
271
|
Object.values(allRegisteredComponents()).forEach(
|
|
@@ -316,7 +319,7 @@
|
|
|
316
319
|
function onUpdateFn_0() {
|
|
317
320
|
evaluateJsCode();
|
|
318
321
|
}
|
|
319
|
-
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
|
|
322
|
+
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode, contentState()]);
|
|
320
323
|
function onUpdateFn_1() {
|
|
321
324
|
runHttpRequests();
|
|
322
325
|
}
|
|
@@ -353,7 +356,7 @@
|
|
|
353
356
|
/>
|
|
354
357
|
{/if}
|
|
355
358
|
<RenderBlocks
|
|
356
|
-
blocks={
|
|
359
|
+
blocks={useContent?.()?.data?.blocks}
|
|
357
360
|
key={forceReRenderCount}
|
|
358
361
|
/>
|
|
359
362
|
</div>
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
export let styles: Props["styles"];
|
|
11
11
|
|
|
12
12
|
$: injectedStyleScript = () => {
|
|
13
|
-
return `<${
|
|
13
|
+
return `<${tag()}>${styles}</${tag()}>`;
|
|
14
14
|
};
|
|
15
|
-
$:
|
|
15
|
+
$: tag = () => {
|
|
16
16
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
17
17
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
18
18
|
return "sty" + "le";
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
{#if TARGET === "svelte"}
|
|
23
23
|
{@html injectedStyleScript()}
|
|
24
24
|
{:else}
|
|
25
|
-
<svelte:element this={
|
|
25
|
+
<svelte:element this={tag()}>{styles}</svelte:element>
|
|
26
26
|
{/if}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fastClone } from '../functions/fast-clone';
|
|
1
2
|
export type SizeName = 'large' | 'medium' | 'small';
|
|
2
3
|
|
|
3
4
|
interface Size {
|
|
@@ -24,5 +25,41 @@ const SIZES: Record<SizeName, Size> = {
|
|
|
24
25
|
},
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
export const getMaxWidthQueryForSize = (size: SizeName) =>
|
|
28
|
-
`@media (max-width: ${
|
|
28
|
+
export const getMaxWidthQueryForSize = (size: SizeName, sizeValues = SIZES) =>
|
|
29
|
+
`@media (max-width: ${sizeValues[size].max}px)`;
|
|
30
|
+
|
|
31
|
+
interface Breakpoints {
|
|
32
|
+
small?: number;
|
|
33
|
+
medium?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const getSizesForBreakpoints = ({ small, medium }: Breakpoints) => {
|
|
37
|
+
const newSizes = fastClone(SIZES); // Note: this helps to get a deep clone of fields like small, medium etc
|
|
38
|
+
|
|
39
|
+
if (!small || !medium) {
|
|
40
|
+
return newSizes;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const smallMin = Math.floor(small / 2);
|
|
44
|
+
newSizes.small = {
|
|
45
|
+
max: small,
|
|
46
|
+
min: smallMin,
|
|
47
|
+
default: smallMin + 1,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const mediumMin = newSizes.small.max + 1;
|
|
51
|
+
newSizes.medium = {
|
|
52
|
+
max: medium,
|
|
53
|
+
min: mediumMin,
|
|
54
|
+
default: mediumMin + 1,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const largeMin = newSizes.medium.max + 1;
|
|
58
|
+
newSizes.large = {
|
|
59
|
+
max: 2000, // TODO: decide upper limit
|
|
60
|
+
min: largeMin,
|
|
61
|
+
default: largeMin + 1,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return newSizes;
|
|
65
|
+
};
|
|
@@ -7,9 +7,11 @@ export function evaluate({
|
|
|
7
7
|
context,
|
|
8
8
|
state,
|
|
9
9
|
event,
|
|
10
|
+
isExpression = true,
|
|
10
11
|
}: {
|
|
11
12
|
code: string;
|
|
12
13
|
event?: Event;
|
|
14
|
+
isExpression?: boolean;
|
|
13
15
|
} & Pick<BuilderContextInterface, 'state' | 'context'>): any {
|
|
14
16
|
if (code === '') {
|
|
15
17
|
console.warn('Skipping evaluation of empty code block.');
|
|
@@ -24,11 +26,14 @@ export function evaluate({
|
|
|
24
26
|
|
|
25
27
|
// Be able to handle simple expressions like "state.foo" or "1 + 1"
|
|
26
28
|
// as well as full blocks like "var foo = "bar"; return foo"
|
|
27
|
-
const useReturn =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const useReturn =
|
|
30
|
+
// we disable this for cases where we definitely don't want a return
|
|
31
|
+
isExpression &&
|
|
32
|
+
!(
|
|
33
|
+
code.includes(';') ||
|
|
34
|
+
code.includes(' return ') ||
|
|
35
|
+
code.trim().startsWith('return ')
|
|
36
|
+
);
|
|
32
37
|
|
|
33
38
|
const useCode = useReturn ? `return (${code});` : code;
|
|
34
39
|
|
|
@@ -46,7 +51,7 @@ export function evaluate({
|
|
|
46
51
|
'Builder custom code error: \n While Evaluating: \n ',
|
|
47
52
|
useCode,
|
|
48
53
|
'\n',
|
|
49
|
-
|
|
54
|
+
e
|
|
50
55
|
);
|
|
51
56
|
}
|
|
52
57
|
}
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export const getEventHandlerName = (key: string) =>
|
|
6
|
-
`on${capitalizeFirstLetter(key)}`;
|
|
1
|
+
export const getEventHandlerName = (key: string) => `on:${key.toLowerCase()}`;
|
|
@@ -2,18 +2,19 @@ import type { BuilderContextInterface } from '../context/types.js';
|
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
3
|
import { evaluate } from './evaluate.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
type Options = {
|
|
6
|
+
block: BuilderBlock;
|
|
7
|
+
} & Pick<BuilderContextInterface, 'state' | 'context'>;
|
|
8
|
+
|
|
9
|
+
type EventHandler = (event: Event) => any;
|
|
10
|
+
|
|
11
|
+
export const createEventHandler =
|
|
12
|
+
(value: string, options: Options): EventHandler =>
|
|
13
|
+
(event) =>
|
|
13
14
|
evaluate({
|
|
14
15
|
code: value,
|
|
15
16
|
context: options.context,
|
|
16
17
|
state: options.state,
|
|
17
18
|
event,
|
|
19
|
+
isExpression: false,
|
|
18
20
|
});
|
|
19
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
3
|
import { getEventHandlerName } from './event-handler-name.js';
|
|
4
|
-
import {
|
|
4
|
+
import { createEventHandler } from './get-block-actions-handler.js';
|
|
5
5
|
|
|
6
6
|
type Actions = { [index: string]: (event: Event) => any };
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ export function getBlockActions(
|
|
|
19
19
|
continue;
|
|
20
20
|
}
|
|
21
21
|
const value = optionActions[key];
|
|
22
|
-
obj[getEventHandlerName(key)] =
|
|
22
|
+
obj[getEventHandlerName(key)] = createEventHandler(value, options);
|
|
23
23
|
}
|
|
24
24
|
return obj;
|
|
25
25
|
}
|
|
@@ -2,7 +2,7 @@ import { isBrowser } from '../is-browser.js';
|
|
|
2
2
|
|
|
3
3
|
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
4
4
|
|
|
5
|
-
type QueryObject = Record<string, string>;
|
|
5
|
+
type QueryObject = Record<string, string | string[]>;
|
|
6
6
|
|
|
7
7
|
export const convertSearchParamsToQueryObject = (
|
|
8
8
|
searchParams: URLSearchParams
|
|
@@ -23,10 +23,15 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
23
23
|
noTraverse = false,
|
|
24
24
|
model,
|
|
25
25
|
apiKey,
|
|
26
|
+
includeRefs = true,
|
|
26
27
|
} = options;
|
|
27
28
|
|
|
29
|
+
if (!apiKey) {
|
|
30
|
+
throw new Error('Missing API key');
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
const url = new URL(
|
|
29
|
-
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`
|
|
34
|
+
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`
|
|
30
35
|
);
|
|
31
36
|
|
|
32
37
|
const queryOptions = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { serializeFn } from '../blocks/util.js';
|
|
1
2
|
import type { RegisteredComponent } from '../context/types.js';
|
|
2
3
|
import type { ComponentInfo, Input } from '../types/components.js';
|
|
3
4
|
import { fastClone } from './fast-clone.js';
|
|
@@ -31,24 +32,6 @@ export const createRegisterComponentMessage = ({
|
|
|
31
32
|
const serializeValue = (value: object): any =>
|
|
32
33
|
typeof value === 'function' ? serializeFn(value) : fastClone(value);
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
* Input attributes that are functions must be converted to strings before being serialized to JSON.
|
|
36
|
-
*/
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
38
|
-
const serializeFn = (fnValue: Function) => {
|
|
39
|
-
const fnStr = fnValue.toString().trim();
|
|
40
|
-
// we need to account for a few different fn syntaxes:
|
|
41
|
-
// 1. `function name(args) => {code}`
|
|
42
|
-
// 2. `name(args) => {code}`
|
|
43
|
-
// 3. `(args) => {}`
|
|
44
|
-
const appendFunction =
|
|
45
|
-
!fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
46
|
-
|
|
47
|
-
return `return (${
|
|
48
|
-
appendFunction ? 'function ' : ''
|
|
49
|
-
}${fnStr}).apply(this, arguments)`;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
35
|
const prepareComponentInfoToSend = ({
|
|
53
36
|
inputs,
|
|
54
37
|
...info
|
package/src/functions/track.ts
CHANGED
|
@@ -6,7 +6,12 @@ import { isBrowser } from './is-browser.js';
|
|
|
6
6
|
import { isEditing } from './is-editing.js';
|
|
7
7
|
|
|
8
8
|
interface Event {
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The type of your event.
|
|
11
|
+
*
|
|
12
|
+
* Examples: `click`, `conversion`, `pageview`, `impression`
|
|
13
|
+
*/
|
|
14
|
+
type: string;
|
|
10
15
|
data: {
|
|
11
16
|
/**
|
|
12
17
|
* (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
|
|
@@ -95,6 +100,13 @@ const createEvent = async ({
|
|
|
95
100
|
});
|
|
96
101
|
|
|
97
102
|
export async function _track(eventProps: EventProps) {
|
|
103
|
+
if (!eventProps.apiKey) {
|
|
104
|
+
console.error(
|
|
105
|
+
'[Builder.io]: Missing API key for track call. Please provide your API key.'
|
|
106
|
+
);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
98
110
|
if (!eventProps.canTrack) {
|
|
99
111
|
return;
|
|
100
112
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './index-helpers/top-of-file.js';
|
|
2
2
|
import './scripts/init-editing.js';
|
|
3
3
|
|
|
4
4
|
export * from './index-helpers/blocks-exports.js';
|
|
@@ -11,3 +11,5 @@ export * from './functions/set-editor-settings.js';
|
|
|
11
11
|
export * from './functions/get-content/index.js';
|
|
12
12
|
export * from './functions/get-builder-search-params/index.js';
|
|
13
13
|
export { track } from './functions/track';
|
|
14
|
+
export type { RegisteredComponent } from './context/types';
|
|
15
|
+
export type { ComponentInfo } from './types/components';
|
|
@@ -23,7 +23,12 @@ export const registerInsertMenu = () => {
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
let isSetupForEditing = false;
|
|
26
27
|
export const setupBrowserForEditing = () => {
|
|
28
|
+
if (isSetupForEditing) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
isSetupForEditing = true;
|
|
27
32
|
if (isBrowser()) {
|
|
28
33
|
window.parent?.postMessage(
|
|
29
34
|
{
|
|
@@ -37,6 +42,7 @@ export const setupBrowserForEditing = () => {
|
|
|
37
42
|
// Supports builder-model="..." attribute which is needed to
|
|
38
43
|
// scope our '+ add block' button styling
|
|
39
44
|
supportsAddBlockScoping: true,
|
|
45
|
+
supportsCustomBreakpoints: true,
|
|
40
46
|
},
|
|
41
47
|
},
|
|
42
48
|
'*'
|
|
@@ -17,6 +17,13 @@ export interface BuilderContentVariation {
|
|
|
17
17
|
name?: string;
|
|
18
18
|
testRatio?: number;
|
|
19
19
|
id?: string;
|
|
20
|
+
meta?: {
|
|
21
|
+
breakpoints?: {
|
|
22
|
+
small: number;
|
|
23
|
+
medium: number;
|
|
24
|
+
};
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
// TODO: separate full and partial versions
|