@builder.io/sdk-solid 0.0.8-21 → 0.0.8-24
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.json +1 -1
- package/src/blocks/button/button.jsx +6 -1
- package/src/blocks/columns/columns.jsx +44 -47
- package/src/blocks/columns/component-info.js +3 -2
- package/src/blocks/custom-code/custom-code.jsx +34 -37
- package/src/blocks/embed/component-info.js +3 -2
- package/src/blocks/embed/embed.jsx +28 -31
- package/src/blocks/form/form.jsx +172 -173
- package/src/blocks/image/component-info.js +3 -2
- package/src/blocks/image/image.jsx +26 -29
- package/src/blocks/img/img.jsx +1 -1
- package/src/blocks/symbol/symbol.jsx +10 -13
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.jsx +19 -23
- package/src/components/render-block/block-styles.jsx +22 -27
- package/src/components/render-block/render-block.jsx +155 -159
- package/src/components/render-block/render-component.jsx +2 -2
- package/src/components/render-block/render-repeated-block.jsx +1 -1
- package/src/components/render-blocks.jsx +32 -33
- package/src/components/render-content/components/render-styles.jsx +38 -41
- package/src/components/render-content/render-content.jsx +170 -156
- package/src/components/render-inlined-styles.jsx +10 -13
- package/src/constants/builder-registered-components.js +3 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +10 -6
- package/src/functions/get-processed-block.test.js +1 -1
- package/src/functions/track.js +71 -2
- package/src/helpers/cookie.js +59 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +26 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
3
3
|
import { TARGET } from "../../constants/target.js";
|
|
4
|
-
import BuilderContext from "../../context/builder.context";
|
|
5
4
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
6
|
-
import RenderInlinedStyles from "../render-inlined-styles.jsx";
|
|
7
5
|
import { convertStyleMaptoCSS } from "../../helpers/css.js";
|
|
8
|
-
import
|
|
6
|
+
import RenderInlinedStyles from "../render-inlined-styles.jsx";
|
|
9
7
|
|
|
10
8
|
function BlockStyles(props) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
9
|
+
function useBlock() {
|
|
10
|
+
return getProcessedBlock({
|
|
11
|
+
block: props.block,
|
|
12
|
+
state: props.context.state,
|
|
13
|
+
context: props.context.context,
|
|
14
|
+
shouldEvaluateBindings: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
${largeStyles ? `.${
|
|
18
|
+
function css() {
|
|
19
|
+
const styles = useBlock().responsiveStyles;
|
|
20
|
+
const largeStyles = styles?.large;
|
|
21
|
+
const mediumStyles = styles?.medium;
|
|
22
|
+
const smallStyles = styles?.small;
|
|
23
|
+
return `
|
|
24
|
+
${largeStyles ? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}` : ""}
|
|
28
25
|
${mediumStyles ? `${getMaxWidthQueryForSize("medium")} {
|
|
29
|
-
.${
|
|
26
|
+
.${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
|
|
30
27
|
}` : ""}
|
|
31
28
|
${smallStyles ? `${getMaxWidthQueryForSize("small")} {
|
|
32
|
-
.${
|
|
29
|
+
.${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
|
|
33
30
|
}` : ""}
|
|
34
31
|
}`;
|
|
35
|
-
|
|
32
|
+
}
|
|
36
33
|
|
|
37
|
-
});
|
|
38
|
-
const builderContext = useContext(BuilderContext);
|
|
39
34
|
return <Show when={TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}>
|
|
40
|
-
<RenderInlinedStyles styles={
|
|
35
|
+
<RenderInlinedStyles styles={css()}></RenderInlinedStyles>
|
|
41
36
|
</Show>;
|
|
42
37
|
}
|
|
43
38
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Show, For } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
import BuilderContext from "../../context/builder.context";
|
|
5
3
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
6
4
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
7
5
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
@@ -15,163 +13,161 @@ import RenderComponent from "./render-component.jsx";
|
|
|
15
13
|
import RenderRepeatedBlock from "./render-repeated-block.jsx";
|
|
16
14
|
|
|
17
15
|
function RenderBlock(props) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.warn(`
|
|
16
|
+
function component() {
|
|
17
|
+
const componentName = getProcessedBlock({
|
|
18
|
+
block: props.block,
|
|
19
|
+
state: props.context.state,
|
|
20
|
+
context: props.context.context,
|
|
21
|
+
shouldEvaluateBindings: false
|
|
22
|
+
}).component?.name;
|
|
23
|
+
|
|
24
|
+
if (!componentName) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ref = props.context.registeredComponents[componentName];
|
|
29
|
+
|
|
30
|
+
if (!ref) {
|
|
31
|
+
// TODO: Public doc page with more info about this message
|
|
32
|
+
console.warn(`
|
|
36
33
|
Could not find a registered component named "${componentName}".
|
|
37
34
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
93
|
-
* they are provided to the component itself directly.
|
|
94
|
-
*/
|
|
95
|
-
...(state.shouldWrap ? {} : {
|
|
96
|
-
attributes: state.attributes
|
|
97
|
-
})
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
get renderComponentProps() {
|
|
102
|
-
return {
|
|
103
|
-
blockChildren: state.children,
|
|
104
|
-
componentRef: state.componentRef,
|
|
105
|
-
componentOptions: state.componentOptions
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
get children() {
|
|
110
|
-
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
111
|
-
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
112
|
-
// but still receive and need to render children.
|
|
113
|
-
// return state.componentInfo?.canHaveChildren ? state.useBlock.children : [];
|
|
114
|
-
return state.useBlock.children ?? [];
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
get childrenWithoutParentComponent() {
|
|
118
|
-
/**
|
|
119
|
-
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
120
|
-
* we render them outside of `componentRef`.
|
|
121
|
-
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
122
|
-
* blocks, and the children will be repeated within those blocks.
|
|
123
|
-
*/
|
|
124
|
-
const shouldRenderChildrenOutsideRef = !state.componentRef && !state.repeatItemData;
|
|
125
|
-
return shouldRenderChildrenOutsideRef ? state.children : [];
|
|
126
|
-
},
|
|
35
|
+
return undefined;
|
|
36
|
+
} else {
|
|
37
|
+
return ref;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function componentInfo() {
|
|
42
|
+
if (component()) {
|
|
43
|
+
const {
|
|
44
|
+
component: _,
|
|
45
|
+
...info
|
|
46
|
+
} = component();
|
|
47
|
+
return info;
|
|
48
|
+
} else {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function componentRef() {
|
|
54
|
+
return component()?.component;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function tagName() {
|
|
58
|
+
return getBlockTag(useBlock());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function useBlock() {
|
|
62
|
+
return repeatItemData() ? props.block : getProcessedBlock({
|
|
63
|
+
block: props.block,
|
|
64
|
+
state: props.context.state,
|
|
65
|
+
context: props.context.context,
|
|
66
|
+
shouldEvaluateBindings: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function attributes() {
|
|
71
|
+
return { ...getBlockProperties(useBlock()),
|
|
72
|
+
...getBlockActions({
|
|
73
|
+
block: useBlock(),
|
|
74
|
+
state: props.context.state,
|
|
75
|
+
context: props.context.context
|
|
76
|
+
}),
|
|
77
|
+
style: getBlockStyles(useBlock())
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function shouldWrap() {
|
|
82
|
+
return !componentInfo()?.noWrap;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function componentOptions() {
|
|
86
|
+
return { ...getBlockComponentOptions(useBlock()),
|
|
127
87
|
|
|
128
|
-
get repeatItemData() {
|
|
129
88
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
89
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
90
|
+
* they are provided to the component itself directly.
|
|
132
91
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
92
|
+
...(shouldWrap() ? {} : {
|
|
93
|
+
attributes: attributes()
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function renderComponentProps() {
|
|
99
|
+
return {
|
|
100
|
+
blockChildren: children(),
|
|
101
|
+
componentRef: componentRef(),
|
|
102
|
+
componentOptions: componentOptions(),
|
|
103
|
+
context: props.context
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function children() {
|
|
108
|
+
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
109
|
+
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
110
|
+
// but still receive and need to render children.
|
|
111
|
+
// return componentInfo()?.canHaveChildren ? useBlock().children : [];
|
|
112
|
+
return useBlock().children ?? [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function childrenWithoutParentComponent() {
|
|
116
|
+
/**
|
|
117
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
118
|
+
* we render them outside of `componentRef`.
|
|
119
|
+
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
120
|
+
* blocks, and the children will be repeated within those blocks.
|
|
121
|
+
*/
|
|
122
|
+
const shouldRenderChildrenOutsideRef = !componentRef() && !repeatItemData();
|
|
123
|
+
return shouldRenderChildrenOutsideRef ? children() : [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function repeatItemData() {
|
|
127
|
+
/**
|
|
128
|
+
* we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
|
|
129
|
+
* which will not work if there is a repeat.
|
|
130
|
+
*/
|
|
131
|
+
const {
|
|
132
|
+
repeat,
|
|
133
|
+
...blockWithoutRepeat
|
|
134
|
+
} = props.block;
|
|
135
|
+
|
|
136
|
+
if (!repeat?.collection) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const itemsArray = evaluate({
|
|
141
|
+
code: repeat.collection,
|
|
142
|
+
state: props.context.state,
|
|
143
|
+
context: props.context.context
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (!Array.isArray(itemsArray)) {
|
|
147
|
+
return undefined;
|
|
166
148
|
}
|
|
167
149
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
150
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
151
|
+
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
152
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
153
|
+
context: { ...props.context,
|
|
154
|
+
state: { ...props.context.state,
|
|
155
|
+
$index: index,
|
|
156
|
+
$item: item,
|
|
157
|
+
[itemNameToUse]: item,
|
|
158
|
+
[`$${itemNameToUse}Index`]: index
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
block: blockWithoutRepeat
|
|
162
|
+
}));
|
|
163
|
+
return repeatArray;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return <Show fallback={<RenderComponent {...renderComponentProps()} context={props.context}></RenderComponent>} when={shouldWrap()}>
|
|
167
|
+
<Show fallback={<Dynamic {...attributes()} component={tagName()}></Dynamic>} when={!isEmptyHtmlElement(tagName())}>
|
|
168
|
+
<Dynamic {...attributes()} component={tagName()}>
|
|
169
|
+
<Show when={repeatItemData()}>
|
|
170
|
+
<For each={repeatItemData()}>
|
|
175
171
|
{(data, _index) => {
|
|
176
172
|
const index = _index();
|
|
177
173
|
|
|
@@ -179,21 +175,21 @@ function RenderBlock(props) {
|
|
|
179
175
|
}}
|
|
180
176
|
</For>
|
|
181
177
|
</Show>
|
|
182
|
-
<Show when={!
|
|
183
|
-
<RenderComponent {...
|
|
178
|
+
<Show when={!repeatItemData()}>
|
|
179
|
+
<RenderComponent {...renderComponentProps()}></RenderComponent>
|
|
184
180
|
</Show>
|
|
185
|
-
<For each={
|
|
181
|
+
<For each={childrenWithoutParentComponent()}>
|
|
186
182
|
{(child, _index) => {
|
|
187
183
|
const index = _index();
|
|
188
184
|
|
|
189
|
-
return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
|
|
185
|
+
return <RenderBlock key={"render-block-" + child.id} block={child} context={props.context}></RenderBlock>;
|
|
190
186
|
}}
|
|
191
187
|
</For>
|
|
192
|
-
<For each={
|
|
188
|
+
<For each={childrenWithoutParentComponent()}>
|
|
193
189
|
{(child, _index) => {
|
|
194
190
|
const index = _index();
|
|
195
191
|
|
|
196
|
-
return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
|
|
192
|
+
return <BlockStyles key={"block-style-" + child.id} block={child} context={props.context}></BlockStyles>;
|
|
197
193
|
}}
|
|
198
194
|
</For>
|
|
199
195
|
</Dynamic>
|
|
@@ -10,14 +10,14 @@ function RenderComponent(props) {
|
|
|
10
10
|
{(child, _index) => {
|
|
11
11
|
const index = _index();
|
|
12
12
|
|
|
13
|
-
return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
|
|
13
|
+
return <RenderBlock key={"render-block-" + child.id} block={child} context={props.context}></RenderBlock>;
|
|
14
14
|
}}
|
|
15
15
|
</For>
|
|
16
16
|
<For each={props.blockChildren}>
|
|
17
17
|
{(child, _index) => {
|
|
18
18
|
const index = _index();
|
|
19
19
|
|
|
20
|
-
return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
|
|
20
|
+
return <BlockStyles key={"block-style-" + child.id} block={child} context={props.context}></BlockStyles>;
|
|
21
21
|
}}
|
|
22
22
|
</For>
|
|
23
23
|
</Dynamic>
|
|
@@ -1,54 +1,53 @@
|
|
|
1
|
-
import { Show, For } from "solid-js";
|
|
2
|
-
import { createMutable } from "solid-js/store";
|
|
1
|
+
import { useContext, Show, For } from "solid-js";
|
|
3
2
|
import { css } from "solid-styled-components";
|
|
3
|
+
import BuilderContext from "../context/builder.context";
|
|
4
4
|
import { isEditing } from "../functions/is-editing.js";
|
|
5
5
|
import BlockStyles from "./render-block/block-styles.jsx";
|
|
6
6
|
import RenderBlock from "./render-block/render-block.jsx";
|
|
7
7
|
|
|
8
8
|
function RenderBlocks(props) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
9
|
+
function className() {
|
|
10
|
+
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
function onClick() {
|
|
14
|
+
if (isEditing() && !props.blocks?.length) {
|
|
15
|
+
window.parent?.postMessage({
|
|
16
|
+
type: "builder.clickEmptyBlocks",
|
|
17
|
+
data: {
|
|
18
|
+
parentElementId: props.parent,
|
|
19
|
+
dataPath: props.path
|
|
20
|
+
}
|
|
21
|
+
}, "*");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
25
|
+
function onMouseEnter() {
|
|
26
|
+
if (isEditing() && !props.blocks?.length) {
|
|
27
|
+
window.parent?.postMessage({
|
|
28
|
+
type: "builder.hoverEmptyBlocks",
|
|
29
|
+
data: {
|
|
30
|
+
parentElementId: props.parent,
|
|
31
|
+
dataPath: props.path
|
|
32
|
+
}
|
|
33
|
+
}, "*");
|
|
36
34
|
}
|
|
35
|
+
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
return <div class={
|
|
37
|
+
const builderContext = useContext(BuilderContext);
|
|
38
|
+
return <div class={className() + " " + css({
|
|
40
39
|
display: "flex",
|
|
41
40
|
flexDirection: "column",
|
|
42
41
|
alignItems: "stretch"
|
|
43
42
|
})} builder-path={props.path} builder-parent-id={props.parent} dataSet={{
|
|
44
|
-
class:
|
|
45
|
-
}} onClick={event =>
|
|
43
|
+
class: className()
|
|
44
|
+
}} onClick={event => onClick()} onMouseEnter={event => onMouseEnter()}>
|
|
46
45
|
<Show when={props.blocks}>
|
|
47
46
|
<For each={props.blocks}>
|
|
48
47
|
{(block, _index) => {
|
|
49
48
|
const index = _index();
|
|
50
49
|
|
|
51
|
-
return <RenderBlock key={"render-block-" + block.id} block={block}></RenderBlock>;
|
|
50
|
+
return <RenderBlock key={"render-block-" + block.id} block={block} context={builderContext}></RenderBlock>;
|
|
52
51
|
}}
|
|
53
52
|
</For>
|
|
54
53
|
</Show>
|
|
@@ -57,7 +56,7 @@ function RenderBlocks(props) {
|
|
|
57
56
|
{(block, _index) => {
|
|
58
57
|
const index = _index();
|
|
59
58
|
|
|
60
|
-
return <BlockStyles key={"block-style-" + block.id} block={block}></BlockStyles>;
|
|
59
|
+
return <BlockStyles key={"block-style-" + block.id} block={block} context={builderContext}></BlockStyles>;
|
|
61
60
|
}}
|
|
62
61
|
</For>
|
|
63
62
|
</Show>
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { createMutable } from "solid-js/store";
|
|
2
1
|
import RenderInlinedStyles from "../../render-inlined-styles.jsx";
|
|
3
2
|
|
|
4
3
|
function RenderContentStyles(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let str = "";
|
|
4
|
+
function getCssFromFont(font) {
|
|
5
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
6
|
+
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
7
|
+
const name = family.split(",")[0];
|
|
8
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
9
|
+
let str = "";
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
if (url && family && name) {
|
|
12
|
+
str += `
|
|
15
13
|
@font-face {
|
|
16
14
|
font-family: "${family}";
|
|
17
15
|
src: local("${name}"), url('${url}') format('woff2');
|
|
@@ -19,21 +17,21 @@ function RenderContentStyles(props) {
|
|
|
19
17
|
font-weight: 400;
|
|
20
18
|
}
|
|
21
19
|
`.trim();
|
|
22
|
-
|
|
20
|
+
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (font.files) {
|
|
23
|
+
for (const weight in font.files) {
|
|
24
|
+
const isNumber = String(Number(weight)) === weight;
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (!isNumber) {
|
|
27
|
+
continue;
|
|
28
|
+
} // TODO: maybe limit number loaded
|
|
31
29
|
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
const weightUrl = font.files[weight];
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (weightUrl && weightUrl !== url) {
|
|
34
|
+
str += `
|
|
37
35
|
@font-face {
|
|
38
36
|
font-family: "${family}";
|
|
39
37
|
src: url('${weightUrl}') format('woff2');
|
|
@@ -41,34 +39,33 @@ function RenderContentStyles(props) {
|
|
|
41
39
|
font-weight: ${weight};
|
|
42
40
|
}
|
|
43
41
|
`.trim();
|
|
44
|
-
}
|
|
45
42
|
}
|
|
46
43
|
}
|
|
44
|
+
}
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
return str;
|
|
47
|
+
}
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
function getFontCss({
|
|
50
|
+
customFonts
|
|
51
|
+
}) {
|
|
52
|
+
// TODO: flag for this
|
|
53
|
+
// if (!this.builder.allowCustomFonts) {
|
|
54
|
+
// return '';
|
|
55
|
+
// }
|
|
56
|
+
// TODO: separate internal data from external
|
|
57
|
+
return customFonts?.map(font => this.getCssFromFont(font))?.join(" ") || "";
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
function injectedStyles() {
|
|
61
|
+
return `
|
|
64
62
|
${props.cssCode || ""}
|
|
65
|
-
${
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
${getFontCss({
|
|
64
|
+
customFonts: props.customFonts
|
|
65
|
+
})}`;
|
|
66
|
+
}
|
|
69
67
|
|
|
70
|
-
}
|
|
71
|
-
return <RenderInlinedStyles styles={state.injectedStyles}></RenderInlinedStyles>;
|
|
68
|
+
return <RenderInlinedStyles styles={injectedStyles()}></RenderInlinedStyles>;
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
export default RenderContentStyles;
|