@builder.io/sdk-svelte 0.1.4 → 0.1.6
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 +5 -1
- package/package/CHANGELOG.md +8 -0
- package/package/blocks/button/component-info.js +0 -1
- package/package/blocks/columns/component-info.js +0 -1
- package/package/blocks/custom-code/component-info.js +0 -1
- package/package/blocks/embed/component-info.js +0 -1
- package/package/blocks/form/component-info.js +0 -1
- package/package/blocks/fragment/component-info.js +0 -1
- package/package/blocks/image/component-info.js +0 -1
- package/package/blocks/img/component-info.js +0 -1
- package/package/blocks/input/component-info.js +0 -1
- package/package/blocks/raw-text/component-info.js +0 -1
- package/package/blocks/section/component-info.js +0 -1
- package/package/blocks/select/component-info.js +0 -1
- package/package/blocks/submit-button/component-info.js +0 -1
- package/package/blocks/symbol/component-info.js +0 -1
- package/package/blocks/text/component-info.js +0 -1
- package/package/blocks/textarea/component-info.js +0 -1
- package/package/blocks/video/component-info.js +0 -1
- package/package/components/render-block/render-block.helpers.js +1 -1
- package/package/components/render-block/render-block.svelte +18 -1
- package/package/components/render-block/render-component.svelte.d.ts +8 -1
- package/package/components/render-block/render-repeated-block.svelte +1 -0
- package/package/components/render-content/components/render-styles.helpers.d.ts +15 -0
- package/package/components/render-content/components/render-styles.helpers.js +59 -0
- package/package/components/render-content/components/render-styles.svelte +12 -54
- package/package/components/render-content/components/render-styles.svelte.d.ts +3 -8
- package/package/components/render-content/render-content.helpers.d.ts +7 -0
- package/package/components/render-content/render-content.helpers.js +30 -0
- package/package/components/render-content/render-content.svelte +90 -87
- package/package/components/render-content/render-content.svelte.d.ts +2 -17
- package/package/components/render-content/render-content.types.d.ts +27 -0
- package/package/components/render-content/render-content.types.js +1 -0
- package/package/constants/builder-registered-components.js +6 -6
- package/package/context/builder.context.d.ts +1 -0
- package/package/context/builder.context.js +1 -0
- package/package/context/types.d.ts +1 -0
- package/package/index-helpers/blocks-exports.d.ts +6 -6
- package/package/index-helpers/blocks-exports.js +6 -6
- package/package/types/builder-content.d.ts +1 -2
- package/package/types/components.d.ts +0 -1
- package/package/types/input.d.ts +117 -0
- package/package/types/input.js +1 -0
- package/package.json +1 -1
- package/src/blocks/button/component-info.ts +1 -1
- package/src/blocks/columns/component-info.ts +1 -1
- package/src/blocks/custom-code/component-info.ts +1 -1
- package/src/blocks/embed/component-info.ts +1 -1
- package/src/blocks/form/component-info.ts +1 -1
- package/src/blocks/fragment/component-info.ts +1 -1
- package/src/blocks/image/component-info.ts +1 -1
- package/src/blocks/img/component-info.ts +1 -1
- package/src/blocks/input/component-info.ts +1 -1
- package/src/blocks/raw-text/component-info.ts +1 -1
- package/src/blocks/section/component-info.ts +1 -1
- package/src/blocks/select/component-info.ts +1 -1
- package/src/blocks/submit-button/component-info.ts +1 -1
- package/src/blocks/symbol/component-info.ts +1 -1
- package/src/blocks/text/component-info.ts +1 -1
- package/src/blocks/textarea/component-info.ts +1 -1
- package/src/blocks/video/component-info.ts +1 -1
- package/src/components/render-block/render-block.helpers.ts +1 -1
- package/src/components/render-block/render-block.svelte +25 -2
- package/src/components/render-block/render-component.svelte +9 -1
- package/src/components/render-block/render-repeated-block.svelte +1 -0
- package/src/components/render-content/components/render-styles.helpers.ts +79 -0
- package/src/components/render-content/components/render-styles.svelte +13 -64
- package/src/components/render-content/render-content.helpers.ts +48 -0
- package/src/components/render-content/render-content.svelte +99 -115
- package/src/components/render-content/render-content.types.ts +31 -0
- package/src/constants/builder-registered-components.ts +6 -6
- package/src/context/builder.context.ts +1 -0
- package/src/context/types.ts +1 -0
- package/src/index-helpers/blocks-exports.ts +6 -6
- package/src/types/builder-content.ts +1 -3
- package/src/types/components.ts +0 -4
- package/src/types/input.ts +120 -0
|
@@ -4,7 +4,7 @@ import { serializeFn } from '../util.js';
|
|
|
4
4
|
export const componentInfo: ComponentInfo = {
|
|
5
5
|
name: 'Image',
|
|
6
6
|
static: true,
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
image:
|
|
9
9
|
'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4',
|
|
10
10
|
defaultStyles: {
|
|
@@ -4,7 +4,7 @@ export const componentInfo: ComponentInfo = {
|
|
|
4
4
|
// friendlyName?
|
|
5
5
|
name: 'Raw:Img',
|
|
6
6
|
hideFromInsertMenu: true,
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
image:
|
|
9
9
|
'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4',
|
|
10
10
|
inputs: [
|
|
@@ -2,7 +2,7 @@ import type { ComponentInfo } from '../../types/components';
|
|
|
2
2
|
|
|
3
3
|
export const componentInfo: ComponentInfo = {
|
|
4
4
|
name: 'Form:Input',
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
image:
|
|
7
7
|
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca',
|
|
8
8
|
inputs: [
|
|
@@ -3,7 +3,7 @@ import type { ComponentInfo } from '../../types/components';
|
|
|
3
3
|
export const componentInfo: ComponentInfo = {
|
|
4
4
|
name: 'Core:Section',
|
|
5
5
|
static: true,
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
image:
|
|
8
8
|
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F682efef23ace49afac61748dd305c70a',
|
|
9
9
|
inputs: [
|
|
@@ -2,7 +2,7 @@ import type { ComponentInfo } from '../../types/components';
|
|
|
2
2
|
|
|
3
3
|
export const componentInfo: ComponentInfo = {
|
|
4
4
|
name: 'Form:Select',
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
image:
|
|
7
7
|
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F83acca093fb24aaf94dee136e9a4b045',
|
|
8
8
|
defaultStyles: {
|
|
@@ -2,7 +2,7 @@ import type { ComponentInfo } from '../../types/components';
|
|
|
2
2
|
|
|
3
3
|
export const componentInfo: ComponentInfo = {
|
|
4
4
|
name: 'Form:SubmitButton',
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
image:
|
|
7
7
|
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98',
|
|
8
8
|
defaultStyles: {
|
|
@@ -3,7 +3,7 @@ import type { ComponentInfo } from '../../types/components';
|
|
|
3
3
|
export const componentInfo: ComponentInfo = {
|
|
4
4
|
name: 'Text',
|
|
5
5
|
static: true,
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
image:
|
|
8
8
|
'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929',
|
|
9
9
|
inputs: [
|
|
@@ -2,7 +2,7 @@ import type { ComponentInfo } from '../../types/components';
|
|
|
2
2
|
|
|
3
3
|
export const componentInfo: ComponentInfo = {
|
|
4
4
|
name: 'Form:TextArea',
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
image:
|
|
7
7
|
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Ff74a2f3de58c4c3e939204e5b6b8f6c3',
|
|
8
8
|
inputs: [
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
BuilderContextInterface,
|
|
4
|
+
BuilderRenderState,
|
|
5
|
+
} from "../../context/types.js";
|
|
3
6
|
|
|
4
7
|
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
5
8
|
|
|
@@ -63,10 +66,29 @@
|
|
|
63
66
|
shouldEvaluateBindings: true,
|
|
64
67
|
});
|
|
65
68
|
};
|
|
69
|
+
$: proxyState = () => {
|
|
70
|
+
if (typeof Proxy === "undefined") {
|
|
71
|
+
console.error(
|
|
72
|
+
"no Proxy available in this environment, cannot proxy state."
|
|
73
|
+
);
|
|
74
|
+
return context.state;
|
|
75
|
+
}
|
|
76
|
+
const useState = new Proxy(context.state, {
|
|
77
|
+
set: (obj, prop, value) => {
|
|
78
|
+
// set the value on the state object, so that the event handler instantly gets the update.
|
|
79
|
+
obj[prop] = value;
|
|
80
|
+
|
|
81
|
+
// set the value in the context, so that the rest of the app gets the update.
|
|
82
|
+
context.setState?.(obj);
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return useState;
|
|
87
|
+
};
|
|
66
88
|
$: actions = () => {
|
|
67
89
|
return getBlockActions({
|
|
68
90
|
block: useBlock(),
|
|
69
|
-
state:
|
|
91
|
+
state: proxyState(),
|
|
70
92
|
context: context.context,
|
|
71
93
|
});
|
|
72
94
|
};
|
|
@@ -137,6 +159,7 @@
|
|
|
137
159
|
state: context.state,
|
|
138
160
|
content: context.content,
|
|
139
161
|
context: context.context,
|
|
162
|
+
setState: context.setState,
|
|
140
163
|
registeredComponents: context.registeredComponents,
|
|
141
164
|
inheritedStyles: getInheritedTextStyles(),
|
|
142
165
|
};
|
|
@@ -5,9 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
import type { Breakpoints } from "../../types/builder-content.js";
|
|
7
7
|
|
|
8
|
+
type ComponentOptions = {
|
|
9
|
+
[index: string]: any;
|
|
10
|
+
customBreakpoints?: Breakpoints;
|
|
11
|
+
attributes?: {
|
|
12
|
+
[index: string]: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
8
16
|
export interface RenderComponentProps {
|
|
9
17
|
componentRef: any;
|
|
10
|
-
componentOptions:
|
|
18
|
+
componentOptions: ComponentOptions;
|
|
11
19
|
blockChildren: BuilderBlock[];
|
|
12
20
|
context: BuilderContextInterface;
|
|
13
21
|
customBreakpoints?: Breakpoints;
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
setContext(BuilderContext.key, {
|
|
32
32
|
content: repeatContext.content,
|
|
33
33
|
state: repeatContext.state,
|
|
34
|
+
setState: repeatContext.setState,
|
|
34
35
|
context: repeatContext.context,
|
|
35
36
|
apiKey: repeatContext.apiKey,
|
|
36
37
|
registeredComponents: repeatContext.registeredComponents,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export interface CustomFont {
|
|
2
|
+
family?: string;
|
|
3
|
+
kind?: string;
|
|
4
|
+
fileUrl?: string;
|
|
5
|
+
files?: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const getCssFromFont = (font: CustomFont) => {
|
|
11
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
12
|
+
const family =
|
|
13
|
+
font.family +
|
|
14
|
+
(font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
|
|
15
|
+
const name = family.split(',')[0];
|
|
16
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
17
|
+
let str = '';
|
|
18
|
+
if (url && family && name) {
|
|
19
|
+
str += `
|
|
20
|
+
@font-face {
|
|
21
|
+
font-family: "${family}";
|
|
22
|
+
src: local("${name}"), url('${url}') format('woff2');
|
|
23
|
+
font-display: fallback;
|
|
24
|
+
font-weight: 400;
|
|
25
|
+
}
|
|
26
|
+
`.trim();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (font.files) {
|
|
30
|
+
for (const weight in font.files) {
|
|
31
|
+
const isNumber = String(Number(weight)) === weight;
|
|
32
|
+
if (!isNumber) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// TODO: maybe limit number loaded
|
|
36
|
+
const weightUrl = font.files[weight];
|
|
37
|
+
if (weightUrl && weightUrl !== url) {
|
|
38
|
+
str += `
|
|
39
|
+
@font-face {
|
|
40
|
+
font-family: "${family}";
|
|
41
|
+
src: url('${weightUrl}') format('woff2');
|
|
42
|
+
font-display: fallback;
|
|
43
|
+
font-weight: ${weight};
|
|
44
|
+
}
|
|
45
|
+
`.trim();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return str;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getFontCss = ({ customFonts }: { customFonts?: CustomFont[] }) => {
|
|
53
|
+
// TODO: flag for this
|
|
54
|
+
// if (!this.builder.allowCustomFonts) {
|
|
55
|
+
// return '';
|
|
56
|
+
// }
|
|
57
|
+
// TODO: separate internal data from external
|
|
58
|
+
return customFonts?.map((font) => getCssFromFont(font))?.join(' ') || '';
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const getCss = ({
|
|
62
|
+
cssCode,
|
|
63
|
+
contentId,
|
|
64
|
+
}: {
|
|
65
|
+
cssCode?: string;
|
|
66
|
+
contentId?: string;
|
|
67
|
+
}) => {
|
|
68
|
+
if (!cssCode) {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
if (!contentId) {
|
|
72
|
+
return cssCode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Allow using `&` in custom CSS code like @emotion
|
|
76
|
+
// E.g. `& .foobar { ... }` to scope CSS
|
|
77
|
+
// TODO: handle if '&' is within a string like `content: "&"`
|
|
78
|
+
return cssCode?.replace(/&/g, `div[builder-content-id="${contentId}"]`) || '';
|
|
79
|
+
};
|
|
@@ -1,82 +1,31 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
|
-
|
|
3
|
-
family?: string;
|
|
4
|
-
kind?: string;
|
|
5
|
-
fileUrl?: string;
|
|
6
|
-
files?: {
|
|
7
|
-
[key: string]: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
2
|
+
import type { CustomFont } from "./render-styles.helpers";
|
|
10
3
|
|
|
11
4
|
interface Props {
|
|
12
5
|
cssCode?: string;
|
|
13
6
|
customFonts?: CustomFont[];
|
|
7
|
+
contentId?: string;
|
|
14
8
|
}
|
|
15
9
|
</script>
|
|
16
10
|
|
|
17
11
|
<script lang="ts">
|
|
18
12
|
import RenderInlinedStyles from "../../render-inlined-styles.svelte";
|
|
13
|
+
import { getCss } from "./render-styles.helpers";
|
|
14
|
+
import { getFontCss } from "./render-styles.helpers";
|
|
19
15
|
|
|
20
16
|
export let cssCode: Props["cssCode"];
|
|
17
|
+
export let contentId: Props["contentId"];
|
|
21
18
|
export let customFonts: Props["customFonts"];
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const name = family.split(",")[0];
|
|
29
|
-
const url = font.fileUrl ?? font?.files?.regular;
|
|
30
|
-
let str = "";
|
|
31
|
-
if (url && family && name) {
|
|
32
|
-
str += `
|
|
33
|
-
@font-face {
|
|
34
|
-
font-family: "${family}";
|
|
35
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
36
|
-
font-display: fallback;
|
|
37
|
-
font-weight: 400;
|
|
38
|
-
}
|
|
39
|
-
`.trim();
|
|
40
|
-
}
|
|
41
|
-
if (font.files) {
|
|
42
|
-
for (const weight in font.files) {
|
|
43
|
-
const isNumber = String(Number(weight)) === weight;
|
|
44
|
-
if (!isNumber) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
// TODO: maybe limit number loaded
|
|
48
|
-
const weightUrl = font.files[weight];
|
|
49
|
-
if (weightUrl && weightUrl !== url) {
|
|
50
|
-
str += `
|
|
51
|
-
@font-face {
|
|
52
|
-
font-family: "${family}";
|
|
53
|
-
src: url('${weightUrl}') format('woff2');
|
|
54
|
-
font-display: fallback;
|
|
55
|
-
font-weight: ${weight};
|
|
56
|
-
}
|
|
57
|
-
`.trim();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return str;
|
|
62
|
-
}
|
|
63
|
-
function getFontCss({ customFonts }) {
|
|
64
|
-
// TODO: flag for this
|
|
65
|
-
// if (!this.builder.allowCustomFonts) {
|
|
66
|
-
// return '';
|
|
67
|
-
// }
|
|
68
|
-
// TODO: separate internal data from external
|
|
69
|
-
return (
|
|
70
|
-
customFonts?.map((font) => this.getCssFromFont(font))?.join(" ") || ""
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
$: injectedStyles = () => {
|
|
74
|
-
return `
|
|
75
|
-
${cssCode || ""}
|
|
20
|
+
let injectedStyles = `
|
|
21
|
+
${getCss({
|
|
22
|
+
cssCode: cssCode,
|
|
23
|
+
contentId: contentId,
|
|
24
|
+
})}
|
|
76
25
|
${getFontCss({
|
|
77
26
|
customFonts: customFonts,
|
|
78
|
-
})}
|
|
79
|
-
|
|
27
|
+
})}
|
|
28
|
+
`;
|
|
80
29
|
</script>
|
|
81
30
|
|
|
82
|
-
<RenderInlinedStyles styles={injectedStyles
|
|
31
|
+
<RenderInlinedStyles styles={injectedStyles} />
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { BuilderRenderState } from '../../context/types';
|
|
2
|
+
import type { BuilderContent } from '../../types/builder-content';
|
|
3
|
+
import type { Nullable } from '../../types/typescript';
|
|
4
|
+
import type { RenderContentProps } from './render-content.types';
|
|
5
|
+
|
|
6
|
+
export const getContextStateInitialValue = ({
|
|
7
|
+
content,
|
|
8
|
+
data,
|
|
9
|
+
locale,
|
|
10
|
+
}: Pick<RenderContentProps, 'content' | 'data' | 'locale'>) => {
|
|
11
|
+
const defaultValues: BuilderRenderState = {};
|
|
12
|
+
|
|
13
|
+
// set default values for content state inputs
|
|
14
|
+
content?.data?.inputs?.forEach((input) => {
|
|
15
|
+
if (
|
|
16
|
+
input.name &&
|
|
17
|
+
input.defaultValue !== undefined &&
|
|
18
|
+
content?.data?.state &&
|
|
19
|
+
content.data.state[input.name] === undefined
|
|
20
|
+
) {
|
|
21
|
+
defaultValues[input.name] = input.defaultValue;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const stateToUse: BuilderRenderState = {
|
|
26
|
+
...content?.data?.state,
|
|
27
|
+
...data,
|
|
28
|
+
...(locale ? { locale } : {}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return { ...defaultValues, ...stateToUse };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const getContentInitialValue = ({
|
|
35
|
+
content,
|
|
36
|
+
data,
|
|
37
|
+
}: Pick<RenderContentProps, 'content' | 'data'>): Nullable<BuilderContent> => {
|
|
38
|
+
return !content
|
|
39
|
+
? undefined
|
|
40
|
+
: {
|
|
41
|
+
...content,
|
|
42
|
+
data: {
|
|
43
|
+
...content?.data,
|
|
44
|
+
...data,
|
|
45
|
+
},
|
|
46
|
+
meta: content?.meta,
|
|
47
|
+
};
|
|
48
|
+
};
|