@builder.io/sdk-svelte 0.1.4 → 0.1.5
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/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/input.d.ts +117 -0
- package/package/types/input.js +1 -0
- package/package.json +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/input.ts +120 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BuilderRenderContext, RegisteredComponent, BuilderRenderState } from '../../context/types';
|
|
2
|
+
import type { BuilderContent } from '../../types/builder-content';
|
|
3
|
+
import type { Nullable } from '../../types/typescript';
|
|
4
|
+
export declare type RenderContentProps = {
|
|
5
|
+
content?: Nullable<BuilderContent>;
|
|
6
|
+
model?: string;
|
|
7
|
+
data?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
context?: BuilderRenderContext;
|
|
11
|
+
apiKey: string;
|
|
12
|
+
customComponents?: RegisteredComponent[];
|
|
13
|
+
canTrack?: boolean;
|
|
14
|
+
locale?: string;
|
|
15
|
+
includeRefs?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export interface BuilderComponentStateChange {
|
|
18
|
+
state: BuilderRenderState;
|
|
19
|
+
ref: {
|
|
20
|
+
name?: string;
|
|
21
|
+
props?: {
|
|
22
|
+
builderBlock?: {
|
|
23
|
+
id?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -25,15 +25,15 @@ import { componentInfo as customCodeInfo } from '../blocks/custom-code/component
|
|
|
25
25
|
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
26
26
|
*/
|
|
27
27
|
export const getDefaultRegisteredComponents = () => [
|
|
28
|
+
{ component: Button, ...buttonComponentInfo },
|
|
28
29
|
{ component: Columns, ...columnsComponentInfo },
|
|
30
|
+
{ component: customCode, ...customCodeInfo },
|
|
31
|
+
{ component: embed, ...embedComponentInfo },
|
|
32
|
+
{ component: Fragment, ...fragmentComponentInfo },
|
|
29
33
|
{ component: Image, ...imageComponentInfo },
|
|
30
34
|
{ component: Img, ...imgComponentInfo },
|
|
35
|
+
{ component: Section, ...sectionComponentInfo },
|
|
36
|
+
{ component: Symbol, ...symbolComponentInfo },
|
|
31
37
|
{ component: Text, ...textComponentInfo },
|
|
32
38
|
{ component: Video, ...videoComponentInfo },
|
|
33
|
-
{ component: Symbol, ...symbolComponentInfo },
|
|
34
|
-
{ component: Button, ...buttonComponentInfo },
|
|
35
|
-
{ component: Section, ...sectionComponentInfo },
|
|
36
|
-
{ component: Fragment, ...fragmentComponentInfo },
|
|
37
|
-
{ component: embed, ...embedComponentInfo },
|
|
38
|
-
{ component: customCode, ...customCodeInfo },
|
|
39
39
|
];
|
|
@@ -11,6 +11,7 @@ export interface BuilderContextInterface {
|
|
|
11
11
|
content: Nullable<BuilderContent>;
|
|
12
12
|
context: BuilderRenderContext;
|
|
13
13
|
state: BuilderRenderState;
|
|
14
|
+
setState?: (state: BuilderRenderState) => void;
|
|
14
15
|
apiKey: string | null;
|
|
15
16
|
registeredComponents: RegisteredComponents;
|
|
16
17
|
inheritedStyles: Record<string, unknown>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export { default as Button } from '../blocks/button/button.svelte';
|
|
1
2
|
export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
3
|
+
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
2
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
|
+
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
|
6
|
+
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
7
|
+
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
|
+
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
3
9
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
4
10
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
5
|
-
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
6
|
-
export { default as Button } from '../blocks/button/button.svelte';
|
|
7
|
-
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
|
-
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
9
|
-
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
10
|
-
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export { default as Button } from '../blocks/button/button.svelte';
|
|
1
2
|
export { default as Columns } from '../blocks/columns/columns.svelte';
|
|
3
|
+
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
2
4
|
export { default as Image } from '../blocks/image/image.svelte';
|
|
5
|
+
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
|
6
|
+
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
7
|
+
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
|
+
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
3
9
|
export { default as Text } from '../blocks/text/text.svelte';
|
|
4
10
|
export { default as Video } from '../blocks/video/video.svelte';
|
|
5
|
-
export { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
6
|
-
export { default as Button } from '../blocks/button/button.svelte';
|
|
7
|
-
export { default as Section } from '../blocks/section/section.svelte';
|
|
8
|
-
export { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
9
|
-
export { default as RenderContent } from '../components/render-content/render-content.svelte';
|
|
10
|
-
export { default as RenderBlocks } from '../components/render-blocks.svelte';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderBlock } from './builder-block.js';
|
|
2
|
+
import type { Input } from './components.js';
|
|
2
3
|
import type { Nullable } from './typescript.js';
|
|
3
|
-
declare type Input = any;
|
|
4
4
|
export interface Breakpoints {
|
|
5
5
|
small: number;
|
|
6
6
|
medium: number;
|
|
@@ -44,4 +44,3 @@ export interface BuilderContent extends BuilderContentVariation {
|
|
|
44
44
|
testVariationId?: string;
|
|
45
45
|
testVariationName?: string;
|
|
46
46
|
}
|
|
47
|
-
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export interface Input {
|
|
2
|
+
/** This is the name of the component prop this input represents */
|
|
3
|
+
name: string;
|
|
4
|
+
/** A friendlier name to show in the UI if the component prop name is not ideal for end users */
|
|
5
|
+
friendlyName?: string;
|
|
6
|
+
/** @hidden @deprecated */
|
|
7
|
+
description?: string;
|
|
8
|
+
/** A default value to use */
|
|
9
|
+
defaultValue?: any;
|
|
10
|
+
/**
|
|
11
|
+
* The type of input to use, such as 'text'
|
|
12
|
+
*
|
|
13
|
+
* See all available inputs [here](https://www.builder.io/c/docs/custom-react-components#input-types)
|
|
14
|
+
* and you can create your own custom input types and associated editor UIs with [plugins](https://www.builder.io/c/docs/extending/plugins)
|
|
15
|
+
*/
|
|
16
|
+
type: string;
|
|
17
|
+
/** Is this input mandatory or not */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
/** @hidden */
|
|
20
|
+
autoFocus?: boolean;
|
|
21
|
+
subFields?: Input[];
|
|
22
|
+
/**
|
|
23
|
+
* Additional text to render in the UI to give guidance on how to use this
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* helperText: 'Be sure to use a proper URL, starting with "https://"'
|
|
28
|
+
* 111
|
|
29
|
+
*/
|
|
30
|
+
helperText?: string;
|
|
31
|
+
/** @hidden */
|
|
32
|
+
allowedFileTypes?: string[];
|
|
33
|
+
/** @hidden */
|
|
34
|
+
imageHeight?: number;
|
|
35
|
+
/** @hidden */
|
|
36
|
+
imageWidth?: number;
|
|
37
|
+
/** @hidden */
|
|
38
|
+
mediaHeight?: number;
|
|
39
|
+
/** @hidden */
|
|
40
|
+
mediaWidth?: number;
|
|
41
|
+
/** @hidden */
|
|
42
|
+
hideFromUI?: boolean;
|
|
43
|
+
/** @hidden */
|
|
44
|
+
modelId?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Number field type validation maximum accepted input
|
|
47
|
+
*/
|
|
48
|
+
max?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Number field type validation minimum accepted input
|
|
51
|
+
*/
|
|
52
|
+
min?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Number field type step size when using arrows
|
|
55
|
+
*/
|
|
56
|
+
step?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Set this to `true` to show the editor for this input when
|
|
59
|
+
* children of this component are selected. This is useful for things
|
|
60
|
+
* like Tabs, such that users may not always select the Tabs component
|
|
61
|
+
* directly but will still be looking for how to add additional tabs
|
|
62
|
+
*/
|
|
63
|
+
broadcast?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Set this to `true` to show the editor for this input when
|
|
66
|
+
* group locked parents of this component are selected. This is useful
|
|
67
|
+
* to bubble up important inputs for locked groups, like text and images
|
|
68
|
+
*/
|
|
69
|
+
bubble?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Set this to `true` if you want this component to be translatable
|
|
72
|
+
*/
|
|
73
|
+
localized?: boolean;
|
|
74
|
+
/** @hidden */
|
|
75
|
+
options?: {
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* For "text" input type, specifying an enum will show a dropdown of options instead
|
|
80
|
+
*/
|
|
81
|
+
enum?: string[] | {
|
|
82
|
+
label: string;
|
|
83
|
+
value: any;
|
|
84
|
+
helperText?: string;
|
|
85
|
+
}[];
|
|
86
|
+
/** Regex field validation for all string types (text, longText, html, url, etc) */
|
|
87
|
+
regex?: {
|
|
88
|
+
/** pattern to test, like "^\/[a-z]$" */
|
|
89
|
+
pattern: string;
|
|
90
|
+
/** flags for the RegExp constructor, e.g. "gi" */
|
|
91
|
+
options?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Friendly message to display to end-users if the regex fails, e.g.
|
|
94
|
+
* "You must use a relative url starting with '/...' "
|
|
95
|
+
*/
|
|
96
|
+
message: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Set this to `true` to put this under the "show more" section of
|
|
100
|
+
* the options editor. Useful for things that are more advanced
|
|
101
|
+
* or more rarely used and don't need to be too prominent
|
|
102
|
+
*/
|
|
103
|
+
advanced?: boolean;
|
|
104
|
+
/** @hidden */
|
|
105
|
+
/** @hidden */
|
|
106
|
+
code?: boolean;
|
|
107
|
+
/** @hidden */
|
|
108
|
+
richText?: boolean;
|
|
109
|
+
/** @hidden */
|
|
110
|
+
showIf?: ((options: Map<string, any>) => boolean) | string;
|
|
111
|
+
/** @hidden */
|
|
112
|
+
copyOnAdd?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Use optionally with inputs of type `reference`. Restricts the content entry picker to a specific model by name.
|
|
115
|
+
*/
|
|
116
|
+
model?: string;
|
|
117
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -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
|
+
};
|