@builder.io/sdk-svelte 0.0.5 → 0.0.7
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 +2 -1
- package/package/blocks/button/button.svelte +2 -2
- 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 +1 -1
- package/package/blocks/image/component-info.js +2 -2
- package/package/blocks/img/img.svelte +1 -1
- package/package/blocks/section/section.svelte +1 -1
- package/package/blocks/submit-button/submit-button.svelte +1 -1
- package/package/blocks/symbol/symbol.svelte +4 -7
- package/package/blocks/util.d.ts +4 -1
- package/package/blocks/util.js +13 -4
- package/package/blocks/video/video.svelte +1 -1
- package/package/components/render-block/block-styles.svelte +5 -3
- package/package/components/render-block/render-block.svelte +9 -9
- 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 +14 -10
- 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/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 +35 -5
- package/package/functions/track.js +5 -4
- package/package/index.d.ts +4 -1
- package/package/index.js +2 -1
- package/package/scripts/init-editing.js +6 -0
- package/package/types/builder-content.d.ts +7 -0
- package/package.json +1 -1
- package/src/blocks/button/button.svelte +2 -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 +1 -1
- package/src/blocks/image/component-info.ts +2 -2
- package/src/blocks/img/img.svelte +1 -1
- package/src/blocks/section/section.svelte +1 -1
- package/src/blocks/submit-button/submit-button.svelte +1 -1
- package/src/blocks/symbol/symbol.svelte +4 -7
- package/src/blocks/util.ts +18 -6
- package/src/blocks/video/video.svelte +1 -1
- package/src/components/render-block/block-styles.svelte +16 -3
- package/src/components/render-block/render-block.svelte +9 -9
- 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 +14 -10
- package/src/components/render-inlined-styles.svelte +3 -3
- package/src/constants/device-sizes.ts +39 -2
- 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 +45 -11
- package/src/index.ts +4 -1
- package/src/scripts/init-editing.ts +6 -0
- package/src/types/builder-content.ts +7 -0
|
@@ -21,7 +21,12 @@ export const registerInsertMenu = () => {
|
|
|
21
21
|
],
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
|
+
let isSetupForEditing = false;
|
|
24
25
|
export const setupBrowserForEditing = () => {
|
|
26
|
+
if (isSetupForEditing) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
isSetupForEditing = true;
|
|
25
30
|
if (isBrowser()) {
|
|
26
31
|
window.parent?.postMessage({
|
|
27
32
|
type: 'builder.sdkInfo',
|
|
@@ -34,6 +39,7 @@ export const setupBrowserForEditing = () => {
|
|
|
34
39
|
// Supports builder-model="..." attribute which is needed to
|
|
35
40
|
// scope our '+ add block' button styling
|
|
36
41
|
supportsAddBlockScoping: true,
|
|
42
|
+
supportsCustomBreakpoints: true,
|
|
37
43
|
},
|
|
38
44
|
}, '*');
|
|
39
45
|
window.addEventListener('message', ({ data }) => {
|
|
@@ -18,6 +18,13 @@ export interface BuilderContentVariation {
|
|
|
18
18
|
name?: string;
|
|
19
19
|
testRatio?: number;
|
|
20
20
|
id?: string;
|
|
21
|
+
meta?: {
|
|
22
|
+
breakpoints?: {
|
|
23
|
+
small: number;
|
|
24
|
+
medium: number;
|
|
25
|
+
};
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
21
28
|
}
|
|
22
29
|
export interface BuilderContent extends BuilderContentVariation {
|
|
23
30
|
'@version'?: number;
|
package/package.json
CHANGED
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
|
|
17
17
|
{#if link}
|
|
18
18
|
<a
|
|
19
|
-
{...attributes}
|
|
20
19
|
role="button"
|
|
20
|
+
{...attributes}
|
|
21
21
|
href={link}
|
|
22
22
|
target={openLinkInNewTab ? "_blank" : undefined}
|
|
23
23
|
>
|
|
24
24
|
{text}
|
|
25
25
|
</a>
|
|
26
26
|
{:else}
|
|
27
|
-
<button
|
|
27
|
+
<button class="button" {...attributes}>
|
|
28
28
|
{text}
|
|
29
29
|
</button>
|
|
30
30
|
{/if}
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
|
|
29
29
|
<script lang="ts">
|
|
30
30
|
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
31
|
-
import { markMutable } from "../../functions/mark-mutable";
|
|
32
31
|
|
|
33
32
|
export let space: ColumnProps["space"];
|
|
34
33
|
export let columns: ColumnProps["columns"];
|
|
@@ -101,7 +100,7 @@
|
|
|
101
100
|
class="builder-column div-2"
|
|
102
101
|
>
|
|
103
102
|
<RenderBlocks
|
|
104
|
-
blocks={
|
|
103
|
+
blocks={column.blocks}
|
|
105
104
|
path={`component.options.columns.${index}.blocks`}
|
|
106
105
|
parent={builderBlock.id}
|
|
107
106
|
styleProp={{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentInfo } from '../../types/components';
|
|
2
|
-
import {
|
|
2
|
+
import { serializeFn } from '../util.js';
|
|
3
3
|
|
|
4
4
|
export const componentInfo: ComponentInfo = {
|
|
5
5
|
// TODO: ways to statically preprocess JSON for references, functions, etc
|
|
@@ -194,7 +194,7 @@ export const componentInfo: ComponentInfo = {
|
|
|
194
194
|
],
|
|
195
195
|
},
|
|
196
196
|
],
|
|
197
|
-
onChange:
|
|
197
|
+
onChange: serializeFn((options: Map<string, any>) => {
|
|
198
198
|
function clearWidths() {
|
|
199
199
|
columns.forEach((col) => {
|
|
200
200
|
col.delete('width');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentInfo } from '../../types/components';
|
|
2
|
-
import {
|
|
2
|
+
import { serializeFn } from '../util.js';
|
|
3
3
|
|
|
4
4
|
export const componentInfo: ComponentInfo = {
|
|
5
5
|
name: 'Embed',
|
|
@@ -12,7 +12,7 @@ export const componentInfo: ComponentInfo = {
|
|
|
12
12
|
required: true,
|
|
13
13
|
defaultValue: '',
|
|
14
14
|
helperText: 'e.g. enter a youtube url, google map, etc',
|
|
15
|
-
onChange:
|
|
15
|
+
onChange: serializeFn((options: Map<string, any>) => {
|
|
16
16
|
const url = options.get('url');
|
|
17
17
|
if (url) {
|
|
18
18
|
options.set('content', 'Loading...');
|
|
@@ -288,7 +288,6 @@
|
|
|
288
288
|
</script>
|
|
289
289
|
|
|
290
290
|
<form
|
|
291
|
-
{...attributes}
|
|
292
291
|
{validate}
|
|
293
292
|
bind:this={formRef}
|
|
294
293
|
action={!sendWithJs && action}
|
|
@@ -297,6 +296,7 @@
|
|
|
297
296
|
on:submit={(event) => {
|
|
298
297
|
onSubmit(event);
|
|
299
298
|
}}
|
|
299
|
+
{...attributes}
|
|
300
300
|
>
|
|
301
301
|
{#if builderBlock && builderBlock.children}
|
|
302
302
|
{#each builderBlock?.children as block}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentInfo } from '../../types/components';
|
|
2
|
-
import {
|
|
2
|
+
import { serializeFn } from '../util.js';
|
|
3
3
|
|
|
4
4
|
export const componentInfo: ComponentInfo = {
|
|
5
5
|
name: 'Image',
|
|
@@ -23,7 +23,7 @@ export const componentInfo: ComponentInfo = {
|
|
|
23
23
|
required: true,
|
|
24
24
|
defaultValue:
|
|
25
25
|
'https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
|
|
26
|
-
onChange:
|
|
26
|
+
onChange: serializeFn((options: Map<string, any>) => {
|
|
27
27
|
const DEFAULT_ASPECT_RATIO = 0.7041;
|
|
28
28
|
options.delete('srcset');
|
|
29
29
|
options.delete('noWebp');
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
</script>
|
|
41
41
|
|
|
42
42
|
<img
|
|
43
|
-
{...attributes}
|
|
44
43
|
use:mitosis_styling={{
|
|
45
44
|
objectFit: backgroundSize || "cover",
|
|
46
45
|
objectPosition: backgroundPosition || "center",
|
|
@@ -48,4 +47,5 @@
|
|
|
48
47
|
key={(isEditing() && imgSrc) || "default-key"}
|
|
49
48
|
alt={altText}
|
|
50
49
|
src={imgSrc || image}
|
|
50
|
+
{...attributes}
|
|
51
51
|
/>
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
import RenderContent from "../../components/render-content/render-content.svelte";
|
|
31
31
|
import BuilderContext from "../../context/builder.context.js";
|
|
32
32
|
import { getContent } from "../../functions/get-content/index.js";
|
|
33
|
-
import { markMutable } from "../../functions/mark-mutable";
|
|
34
33
|
|
|
35
34
|
export let symbol: SymbolProps["symbol"];
|
|
36
35
|
export let attributes: SymbolProps["attributes"];
|
|
@@ -86,15 +85,13 @@
|
|
|
86
85
|
<RenderContent
|
|
87
86
|
apiKey={builderContext.apiKey}
|
|
88
87
|
context={builderContext.context}
|
|
89
|
-
customComponents={
|
|
90
|
-
|
|
91
|
-
)}
|
|
92
|
-
data={markMutable({
|
|
88
|
+
customComponents={Object.values(builderContext.registeredComponents)}
|
|
89
|
+
data={{
|
|
93
90
|
...symbol?.data,
|
|
94
91
|
...builderContext.state,
|
|
95
92
|
...symbol?.content?.data?.state,
|
|
96
|
-
}
|
|
93
|
+
}}
|
|
97
94
|
model={symbol?.model}
|
|
98
|
-
content={
|
|
95
|
+
content={contentToUse()}
|
|
99
96
|
/>
|
|
100
97
|
</div>
|
package/src/blocks/util.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Input attributes that are functions must be converted to strings before being serialized to JSON.
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
|
+
export const serializeFn = (fnValue: Function) => {
|
|
6
|
+
const fnStr = fnValue.toString().trim();
|
|
7
|
+
|
|
8
|
+
// we need to account for a few different fn syntaxes:
|
|
9
|
+
// 1. `function name(args) => {code}`
|
|
10
|
+
// 2. `name(args) => {code}`
|
|
11
|
+
// 3. `(args) => {}`
|
|
12
|
+
const appendFunction =
|
|
13
|
+
!fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
14
|
+
|
|
15
|
+
return `return (${
|
|
16
|
+
appendFunction ? 'function ' : ''
|
|
17
|
+
}${fnStr}).apply(this, arguments)`;
|
|
18
|
+
};
|
|
@@ -86,7 +86,6 @@
|
|
|
86
86
|
</script>
|
|
87
87
|
|
|
88
88
|
<video
|
|
89
|
-
{...spreadProps()}
|
|
90
89
|
use:mitosis_styling={{
|
|
91
90
|
width: "100%",
|
|
92
91
|
height: "100%",
|
|
@@ -97,6 +96,7 @@
|
|
|
97
96
|
// not have the video overflow
|
|
98
97
|
borderRadius: 1,
|
|
99
98
|
}}
|
|
99
|
+
{...spreadProps()}
|
|
100
100
|
src={video || "no-src"}
|
|
101
101
|
poster={posterImage}
|
|
102
102
|
/>
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<script lang="ts">
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
getMaxWidthQueryForSize,
|
|
15
|
+
getSizesForBreakpoints,
|
|
16
|
+
} from "../../constants/device-sizes.js";
|
|
14
17
|
import { TARGET } from "../../constants/target.js";
|
|
15
18
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
16
19
|
import { createCssClass } from "../../helpers/css.js";
|
|
@@ -29,6 +32,10 @@
|
|
|
29
32
|
};
|
|
30
33
|
$: css = () => {
|
|
31
34
|
const styles = useBlock().responsiveStyles;
|
|
35
|
+
const content = context.content;
|
|
36
|
+
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
|
|
37
|
+
content?.meta?.breakpoints || {}
|
|
38
|
+
);
|
|
32
39
|
const largeStyles = styles?.large;
|
|
33
40
|
const mediumStyles = styles?.medium;
|
|
34
41
|
const smallStyles = styles?.small;
|
|
@@ -43,14 +50,20 @@
|
|
|
43
50
|
? createCssClass({
|
|
44
51
|
className,
|
|
45
52
|
styles: mediumStyles,
|
|
46
|
-
mediaQuery: getMaxWidthQueryForSize(
|
|
53
|
+
mediaQuery: getMaxWidthQueryForSize(
|
|
54
|
+
"medium",
|
|
55
|
+
sizesWithUpdatedBreakpoints
|
|
56
|
+
),
|
|
47
57
|
})
|
|
48
58
|
: "";
|
|
49
59
|
const smallStylesClass = smallStyles
|
|
50
60
|
? createCssClass({
|
|
51
61
|
className,
|
|
52
62
|
styles: smallStyles,
|
|
53
|
-
mediaQuery: getMaxWidthQueryForSize(
|
|
63
|
+
mediaQuery: getMaxWidthQueryForSize(
|
|
64
|
+
"small",
|
|
65
|
+
sizesWithUpdatedBreakpoints
|
|
66
|
+
),
|
|
54
67
|
})
|
|
55
68
|
: "";
|
|
56
69
|
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
return ref;
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
$:
|
|
61
|
+
$: tag = () => {
|
|
62
62
|
return getBlockTag(useBlock());
|
|
63
63
|
};
|
|
64
64
|
$: useBlock = () => {
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
};
|
|
95
95
|
$: renderComponentProps = () => {
|
|
96
96
|
return {
|
|
97
|
-
blockChildren:
|
|
97
|
+
blockChildren: useChildren(),
|
|
98
98
|
componentRef: component?.()?.component,
|
|
99
99
|
componentOptions: {
|
|
100
100
|
...getBlockComponentOptions(useBlock()),
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
context: childrenContext(),
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
|
-
$:
|
|
114
|
+
$: useChildren = () => {
|
|
115
115
|
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
116
116
|
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
117
117
|
// but still receive and need to render children.
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
*/
|
|
128
128
|
const shouldRenderChildrenOutsideRef =
|
|
129
129
|
!component?.()?.component && !repeatItemData();
|
|
130
|
-
return shouldRenderChildrenOutsideRef ?
|
|
130
|
+
return shouldRenderChildrenOutsideRef ? useChildren() : [];
|
|
131
131
|
};
|
|
132
132
|
$: repeatItemData = () => {
|
|
133
133
|
/**
|
|
@@ -197,18 +197,18 @@
|
|
|
197
197
|
</script>
|
|
198
198
|
|
|
199
199
|
{#if shouldWrap()}
|
|
200
|
-
{#if isEmptyHtmlElement(
|
|
201
|
-
<svelte:element this={
|
|
200
|
+
{#if isEmptyHtmlElement(tag())}
|
|
201
|
+
<svelte:element this={tag()} {...attributes()} />
|
|
202
202
|
{/if}
|
|
203
203
|
|
|
204
|
-
{#if !isEmptyHtmlElement(
|
|
204
|
+
{#if !isEmptyHtmlElement(tag()) && repeatItemData()}
|
|
205
205
|
{#each repeatItemData() as data, index (index)}
|
|
206
206
|
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
207
207
|
{/each}
|
|
208
208
|
{/if}
|
|
209
209
|
|
|
210
|
-
{#if !isEmptyHtmlElement(
|
|
211
|
-
<svelte:element this={
|
|
210
|
+
{#if !isEmptyHtmlElement(tag()) && !repeatItemData()}
|
|
211
|
+
<svelte:element this={tag()} {...attributes()}>
|
|
212
212
|
<svelte:component
|
|
213
213
|
this={renderComponentTag()}
|
|
214
214
|
{...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}
|
|
@@ -57,14 +57,13 @@
|
|
|
57
57
|
components,
|
|
58
58
|
createRegisterComponentMessage,
|
|
59
59
|
} from "../../functions/register-component.js";
|
|
60
|
-
import {
|
|
60
|
+
import { _track } from "../../functions/track.js";
|
|
61
61
|
import RenderBlocks from "../render-blocks.svelte";
|
|
62
62
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
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"];
|
|
@@ -131,11 +130,14 @@
|
|
|
131
130
|
}
|
|
132
131
|
function onClick(_event) {
|
|
133
132
|
if (useContent()) {
|
|
134
|
-
|
|
133
|
+
const variationId = useContent?.()?.testVariationId;
|
|
134
|
+
const contentId = useContent?.()?.id;
|
|
135
|
+
_track({
|
|
135
136
|
type: "click",
|
|
136
137
|
canTrack: canTrackToUse(),
|
|
137
|
-
contentId
|
|
138
|
-
|
|
138
|
+
contentId,
|
|
139
|
+
apiKey: apiKey,
|
|
140
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
}
|
|
@@ -259,7 +261,6 @@
|
|
|
259
261
|
if (isBrowser()) {
|
|
260
262
|
if (isEditing()) {
|
|
261
263
|
forceReRenderCount = forceReRenderCount + 1;
|
|
262
|
-
// QWIK-REPLACE: _useMutableProps
|
|
263
264
|
registerInsertMenu();
|
|
264
265
|
setupBrowserForEditing();
|
|
265
266
|
Object.values(allRegisteredComponents()).forEach(
|
|
@@ -275,11 +276,14 @@
|
|
|
275
276
|
);
|
|
276
277
|
}
|
|
277
278
|
if (useContent()) {
|
|
278
|
-
|
|
279
|
+
const variationId = useContent?.()?.testVariationId;
|
|
280
|
+
const contentId = useContent?.()?.id;
|
|
281
|
+
_track({
|
|
279
282
|
type: "impression",
|
|
280
283
|
canTrack: canTrackToUse(),
|
|
281
|
-
contentId
|
|
282
|
-
|
|
284
|
+
contentId,
|
|
285
|
+
apiKey: apiKey,
|
|
286
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
283
287
|
});
|
|
284
288
|
}
|
|
285
289
|
|
|
@@ -347,7 +351,7 @@
|
|
|
347
351
|
/>
|
|
348
352
|
{/if}
|
|
349
353
|
<RenderBlocks
|
|
350
|
-
blocks={
|
|
354
|
+
blocks={useContent?.()?.data?.blocks}
|
|
351
355
|
key={forceReRenderCount}
|
|
352
356
|
/>
|
|
353
357
|
</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
|
+
};
|
|
@@ -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
|