@builder.io/sdk-svelte 0.0.4 → 0.0.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 +3 -2
- package/package.json +3 -2
- package/src/blocks/BaseText.svelte +27 -0
- package/src/blocks/button/button.svelte +36 -0
- package/src/blocks/button/component-info.ts +42 -0
- package/src/blocks/columns/columns.svelte +148 -0
- package/src/blocks/columns/component-info.ts +254 -0
- package/src/blocks/custom-code/component-info.ts +31 -0
- package/src/blocks/custom-code/custom-code.svelte +66 -0
- package/src/blocks/embed/component-info.ts +53 -0
- package/src/blocks/embed/embed.svelte +51 -0
- package/src/blocks/embed/helpers.ts +8 -0
- package/src/blocks/form/component-info.ts +282 -0
- package/src/blocks/form/form.svelte +332 -0
- package/src/blocks/fragment/component-info.ts +10 -0
- package/src/blocks/fragment/fragment.svelte +12 -0
- package/src/blocks/image/component-info.ts +170 -0
- package/src/blocks/image/image.helpers.ts +75 -0
- package/src/blocks/image/image.svelte +145 -0
- package/src/blocks/img/component-info.ts +21 -0
- package/src/blocks/img/img.svelte +51 -0
- package/src/blocks/input/component-info.ts +78 -0
- package/src/blocks/input/input.svelte +34 -0
- package/src/blocks/raw-text/component-info.ts +15 -0
- package/src/blocks/raw-text/raw-text.svelte +16 -0
- package/src/blocks/section/component-info.ts +50 -0
- package/src/blocks/section/section.svelte +34 -0
- package/src/blocks/select/component-info.ts +61 -0
- package/src/blocks/select/select.svelte +34 -0
- package/src/blocks/submit-button/component-info.ts +32 -0
- package/src/blocks/submit-button/submit-button.svelte +15 -0
- package/src/blocks/symbol/component-info.ts +43 -0
- package/src/blocks/symbol/symbol.svelte +100 -0
- package/src/blocks/text/component-info.ts +24 -0
- package/src/blocks/text/text.svelte +11 -0
- package/src/blocks/textarea/component-info.ts +48 -0
- package/src/blocks/textarea/textarea.svelte +19 -0
- package/src/blocks/util.ts +6 -0
- package/src/blocks/video/component-info.ts +109 -0
- package/src/blocks/video/video.svelte +102 -0
- package/src/components/render-block/block-styles.svelte +62 -0
- package/src/components/render-block/render-block.helpers.ts +27 -0
- package/src/components/render-block/render-block.svelte +228 -0
- package/src/components/render-block/render-component-with-context.svelte +38 -0
- package/src/components/render-block/render-component.svelte +35 -0
- package/src/components/render-block/render-repeated-block.svelte +53 -0
- package/src/components/render-block/types.ts +7 -0
- package/src/components/render-blocks.svelte +104 -0
- package/src/components/render-content/components/render-styles.svelte +80 -0
- package/src/components/render-content/index.ts +1 -0
- package/src/components/render-content/render-content.svelte +354 -0
- package/src/components/render-inlined-styles.svelte +26 -0
- package/src/constants/builder-registered-components.ts +42 -0
- package/src/constants/device-sizes.ts +28 -0
- package/src/constants/target.ts +2 -0
- package/src/context/builder.context.ts +13 -0
- package/src/context/types.ts +23 -0
- package/src/functions/camel-to-kebab-case.ts +2 -0
- package/src/functions/evaluate.ts +52 -0
- package/src/functions/event-handler-name.ts +6 -0
- package/src/functions/extract-text-styles.ts +39 -0
- package/src/functions/fast-clone.ts +5 -0
- package/src/functions/get-block-actions-handler.ts +19 -0
- package/src/functions/get-block-actions.ts +25 -0
- package/src/functions/get-block-component-options.ts +12 -0
- package/src/functions/get-block-properties.ts +11 -0
- package/src/functions/get-block-tag.ts +7 -0
- package/src/functions/get-builder-search-params/fn.test.ts +19 -0
- package/src/functions/get-builder-search-params/index.ts +48 -0
- package/src/functions/get-content/ab-testing.ts +132 -0
- package/src/functions/get-content/fn.test.ts +35 -0
- package/src/functions/get-content/index.ts +77 -0
- package/src/functions/get-content/types.ts +36 -0
- package/src/functions/get-fetch.ts +14 -0
- package/src/functions/get-global-this.ts +15 -0
- package/src/functions/get-processed-block.test.ts +33 -0
- package/src/functions/get-processed-block.ts +54 -0
- package/src/functions/get-react-native-block-styles.ts +30 -0
- package/src/functions/if-target.ts +20 -0
- package/src/functions/is-browser.ts +3 -0
- package/src/functions/is-editing.ts +7 -0
- package/src/functions/is-iframe.ts +5 -0
- package/src/functions/is-previewing.ts +14 -0
- package/src/functions/mark-mutable.ts +7 -0
- package/src/functions/on-change.test.ts +23 -0
- package/src/functions/on-change.ts +29 -0
- package/src/functions/register-component.ts +67 -0
- package/src/functions/register.ts +46 -0
- package/src/functions/sanitize-react-native-block-styles.ts +65 -0
- package/src/functions/set-editor-settings.ts +16 -0
- package/src/functions/set.test.ts +19 -0
- package/src/functions/set.ts +26 -0
- package/src/functions/track.ts +90 -0
- package/src/functions/transform-block.ts +6 -0
- package/src/helpers/ab-tests.ts +22 -0
- package/src/helpers/cookie.ts +102 -0
- package/src/helpers/css.ts +33 -0
- package/src/helpers/flatten.ts +24 -0
- package/src/helpers/localStorage.ts +38 -0
- package/src/helpers/nullable.ts +4 -0
- package/src/helpers/sessionId.ts +34 -0
- package/src/helpers/time.ts +4 -0
- package/src/helpers/url.test.ts +16 -0
- package/src/helpers/url.ts +12 -0
- package/src/helpers/uuid.ts +17 -0
- package/src/helpers/visitorId.ts +38 -0
- package/src/index-helpers/blocks-exports.ts +10 -0
- package/src/index-helpers/top-of-file.ts +4 -0
- package/src/index.ts +12 -0
- package/src/scripts/init-editing.ts +102 -0
- package/src/types/builder-block.ts +58 -0
- package/src/types/builder-content.ts +39 -0
- package/src/types/can-track.ts +3 -0
- package/src/types/components.ts +188 -0
- package/src/types/deep-partial.ts +7 -0
- package/src/types/element.ts +60 -0
- package/src/types/targets.ts +6 -0
- package/src/types/typescript.ts +7 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
|
3
|
+
*/
|
|
4
|
+
const EMPTY_HTML_ELEMENTS = [
|
|
5
|
+
'area',
|
|
6
|
+
'base',
|
|
7
|
+
'br',
|
|
8
|
+
'col',
|
|
9
|
+
'embed',
|
|
10
|
+
'hr',
|
|
11
|
+
'img',
|
|
12
|
+
'input',
|
|
13
|
+
'keygen',
|
|
14
|
+
'link',
|
|
15
|
+
'meta',
|
|
16
|
+
'param',
|
|
17
|
+
'source',
|
|
18
|
+
'track',
|
|
19
|
+
'wbr',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export const isEmptyHtmlElement = (tagName: unknown) => {
|
|
23
|
+
return (
|
|
24
|
+
typeof tagName === 'string' &&
|
|
25
|
+
EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase())
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
BuilderContextInterface,
|
|
4
|
+
RegisteredComponent,
|
|
5
|
+
} from "../../context/types.js";
|
|
6
|
+
|
|
7
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
8
|
+
|
|
9
|
+
import type { Nullable } from "../../types/typescript.js";
|
|
10
|
+
|
|
11
|
+
import type { RenderComponentProps } from "./render-component";
|
|
12
|
+
|
|
13
|
+
import type { RepeatData } from "./types.js";
|
|
14
|
+
|
|
15
|
+
export type RenderBlockProps = {
|
|
16
|
+
block: BuilderBlock;
|
|
17
|
+
context: BuilderContextInterface;
|
|
18
|
+
};
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
23
|
+
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
24
|
+
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
25
|
+
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
26
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
27
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
28
|
+
import BlockStyles from "./block-styles.svelte";
|
|
29
|
+
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
30
|
+
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
31
|
+
import { TARGET } from "../../constants/target.js";
|
|
32
|
+
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
33
|
+
import RenderComponentWithContext from "./render-component-with-context.svelte";
|
|
34
|
+
import RenderComponent from "./render-component.svelte";
|
|
35
|
+
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
36
|
+
|
|
37
|
+
export let block: RenderBlockProps["block"];
|
|
38
|
+
export let context: RenderBlockProps["context"];
|
|
39
|
+
|
|
40
|
+
$: component = () => {
|
|
41
|
+
const componentName = getProcessedBlock({
|
|
42
|
+
block: block,
|
|
43
|
+
state: context.state,
|
|
44
|
+
context: context.context,
|
|
45
|
+
shouldEvaluateBindings: false,
|
|
46
|
+
}).component?.name;
|
|
47
|
+
if (!componentName) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const ref = context.registeredComponents[componentName];
|
|
51
|
+
if (!ref) {
|
|
52
|
+
// TODO: Public doc page with more info about this message
|
|
53
|
+
console.warn(`
|
|
54
|
+
Could not find a registered component named "${componentName}".
|
|
55
|
+
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
56
|
+
return undefined;
|
|
57
|
+
} else {
|
|
58
|
+
return ref;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
$: tagName = () => {
|
|
62
|
+
return getBlockTag(useBlock());
|
|
63
|
+
};
|
|
64
|
+
$: useBlock = () => {
|
|
65
|
+
return repeatItemData()
|
|
66
|
+
? block
|
|
67
|
+
: getProcessedBlock({
|
|
68
|
+
block: block,
|
|
69
|
+
state: context.state,
|
|
70
|
+
context: context.context,
|
|
71
|
+
shouldEvaluateBindings: true,
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
$: attributes = () => {
|
|
75
|
+
return {
|
|
76
|
+
...getBlockProperties(useBlock()),
|
|
77
|
+
...getBlockActions({
|
|
78
|
+
block: useBlock(),
|
|
79
|
+
state: context.state,
|
|
80
|
+
context: context.context,
|
|
81
|
+
}),
|
|
82
|
+
...(TARGET === "reactNative"
|
|
83
|
+
? {
|
|
84
|
+
style: getReactNativeBlockStyles({
|
|
85
|
+
block: useBlock(),
|
|
86
|
+
context: context,
|
|
87
|
+
}),
|
|
88
|
+
}
|
|
89
|
+
: {}),
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
$: shouldWrap = () => {
|
|
93
|
+
return !component?.()?.noWrap;
|
|
94
|
+
};
|
|
95
|
+
$: renderComponentProps = () => {
|
|
96
|
+
return {
|
|
97
|
+
blockChildren: children(),
|
|
98
|
+
componentRef: component?.()?.component,
|
|
99
|
+
componentOptions: {
|
|
100
|
+
...getBlockComponentOptions(useBlock()),
|
|
101
|
+
/**
|
|
102
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
103
|
+
* they are provided to the component itself directly.
|
|
104
|
+
*/
|
|
105
|
+
...(shouldWrap()
|
|
106
|
+
? {}
|
|
107
|
+
: {
|
|
108
|
+
attributes: attributes(),
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
context: childrenContext(),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
$: children = () => {
|
|
115
|
+
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
116
|
+
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
117
|
+
// but still receive and need to render children.
|
|
118
|
+
// return componentInfo?.canHaveChildren ? useBlock().children : [];
|
|
119
|
+
return useBlock().children ?? [];
|
|
120
|
+
};
|
|
121
|
+
$: childrenWithoutParentComponent = () => {
|
|
122
|
+
/**
|
|
123
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
124
|
+
* we render them outside of `componentRef`.
|
|
125
|
+
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
126
|
+
* blocks, and the children will be repeated within those blocks.
|
|
127
|
+
*/
|
|
128
|
+
const shouldRenderChildrenOutsideRef =
|
|
129
|
+
!component?.()?.component && !repeatItemData();
|
|
130
|
+
return shouldRenderChildrenOutsideRef ? children() : [];
|
|
131
|
+
};
|
|
132
|
+
$: repeatItemData = () => {
|
|
133
|
+
/**
|
|
134
|
+
* we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
|
|
135
|
+
* which will not work if there is a repeat.
|
|
136
|
+
*/
|
|
137
|
+
const { repeat, ...blockWithoutRepeat } = block;
|
|
138
|
+
if (!repeat?.collection) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const itemsArray = evaluate({
|
|
142
|
+
code: repeat.collection,
|
|
143
|
+
state: context.state,
|
|
144
|
+
context: context.context,
|
|
145
|
+
});
|
|
146
|
+
if (!Array.isArray(itemsArray)) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
150
|
+
const itemNameToUse =
|
|
151
|
+
repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
152
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
153
|
+
context: {
|
|
154
|
+
...context,
|
|
155
|
+
state: {
|
|
156
|
+
...context.state,
|
|
157
|
+
$index: index,
|
|
158
|
+
$item: item,
|
|
159
|
+
[itemNameToUse]: item,
|
|
160
|
+
[`$${itemNameToUse}Index`]: index,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
block: blockWithoutRepeat,
|
|
164
|
+
}));
|
|
165
|
+
return repeatArray;
|
|
166
|
+
};
|
|
167
|
+
$: inheritedTextStyles = () => {
|
|
168
|
+
if (TARGET !== "reactNative") {
|
|
169
|
+
return {};
|
|
170
|
+
}
|
|
171
|
+
const styles = getReactNativeBlockStyles({
|
|
172
|
+
block: useBlock(),
|
|
173
|
+
context: context,
|
|
174
|
+
});
|
|
175
|
+
return extractTextStyles(styles);
|
|
176
|
+
};
|
|
177
|
+
$: childrenContext = () => {
|
|
178
|
+
return {
|
|
179
|
+
apiKey: context.apiKey,
|
|
180
|
+
state: context.state,
|
|
181
|
+
content: context.content,
|
|
182
|
+
context: context.context,
|
|
183
|
+
registeredComponents: context.registeredComponents,
|
|
184
|
+
inheritedStyles: inheritedTextStyles(),
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
$: renderComponentTag = () => {
|
|
188
|
+
if (TARGET === "reactNative") {
|
|
189
|
+
return RenderComponentWithContext;
|
|
190
|
+
} else if (TARGET === "vue3") {
|
|
191
|
+
// vue3 expects a string for the component tag
|
|
192
|
+
return "RenderComponent";
|
|
193
|
+
} else {
|
|
194
|
+
return RenderComponent;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
</script>
|
|
198
|
+
|
|
199
|
+
{#if shouldWrap()}
|
|
200
|
+
{#if isEmptyHtmlElement(tagName())}
|
|
201
|
+
<svelte:element this={tagName()} {...attributes()} />
|
|
202
|
+
{/if}
|
|
203
|
+
|
|
204
|
+
{#if !isEmptyHtmlElement(tagName()) && repeatItemData()}
|
|
205
|
+
{#each repeatItemData() as data, index (index)}
|
|
206
|
+
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
207
|
+
{/each}
|
|
208
|
+
{/if}
|
|
209
|
+
|
|
210
|
+
{#if !isEmptyHtmlElement(tagName()) && !repeatItemData()}
|
|
211
|
+
<svelte:element this={tagName()} {...attributes()}>
|
|
212
|
+
<svelte:component
|
|
213
|
+
this={renderComponentTag()}
|
|
214
|
+
{...renderComponentProps()}
|
|
215
|
+
/>
|
|
216
|
+
|
|
217
|
+
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
218
|
+
<svelte:self block={child} context={childrenContext()} />
|
|
219
|
+
{/each}
|
|
220
|
+
|
|
221
|
+
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
222
|
+
<BlockStyles block={child} context={childrenContext()} />
|
|
223
|
+
{/each}
|
|
224
|
+
</svelte:element>
|
|
225
|
+
{/if}
|
|
226
|
+
{:else}
|
|
227
|
+
<svelte:component this={renderComponentTag()} {...renderComponentProps()} />
|
|
228
|
+
{/if}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type { RenderComponentProps } from "./render-component";
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { getContext, setContext } from "svelte";
|
|
7
|
+
|
|
8
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
9
|
+
import RenderComponent from "./render-component.svelte";
|
|
10
|
+
|
|
11
|
+
export let componentRef: RenderComponentProps["componentRef"];
|
|
12
|
+
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
13
|
+
export let blockChildren: RenderComponentProps["blockChildren"];
|
|
14
|
+
export let context: RenderComponentProps["context"];
|
|
15
|
+
|
|
16
|
+
setContext(BuilderContext.key, {
|
|
17
|
+
get content() {
|
|
18
|
+
return context.content;
|
|
19
|
+
},
|
|
20
|
+
get state() {
|
|
21
|
+
return context.state;
|
|
22
|
+
},
|
|
23
|
+
get context() {
|
|
24
|
+
return context.context;
|
|
25
|
+
},
|
|
26
|
+
get apiKey() {
|
|
27
|
+
return context.apiKey;
|
|
28
|
+
},
|
|
29
|
+
get registeredComponents() {
|
|
30
|
+
return context.registeredComponents;
|
|
31
|
+
},
|
|
32
|
+
get inheritedStyles() {
|
|
33
|
+
return context.inheritedStyles;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<RenderComponent {componentRef} {componentOptions} {blockChildren} {context} />
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
3
|
+
|
|
4
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
5
|
+
|
|
6
|
+
export interface RenderComponentProps {
|
|
7
|
+
componentRef: any;
|
|
8
|
+
componentOptions: any;
|
|
9
|
+
blockChildren: BuilderBlock[];
|
|
10
|
+
context: BuilderContextInterface;
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import BlockStyles from "./block-styles.svelte";
|
|
16
|
+
import RenderBlock from "./render-block.svelte";
|
|
17
|
+
import { markPropsMutable } from "../../functions/mark-mutable.js";
|
|
18
|
+
|
|
19
|
+
export let componentRef: RenderComponentProps["componentRef"];
|
|
20
|
+
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
21
|
+
export let blockChildren: RenderComponentProps["blockChildren"];
|
|
22
|
+
export let context: RenderComponentProps["context"];
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
{#if componentRef}
|
|
26
|
+
<svelte:component this={componentRef} {...markPropsMutable(componentOptions)}>
|
|
27
|
+
{#each blockChildren as child ("render-block-" + child.id)}
|
|
28
|
+
<RenderBlock block={child} {context} />
|
|
29
|
+
{/each}
|
|
30
|
+
|
|
31
|
+
{#each blockChildren as child ("block-style-" + child.id)}
|
|
32
|
+
<BlockStyles block={child} {context} />
|
|
33
|
+
{/each}
|
|
34
|
+
</svelte:component>
|
|
35
|
+
{/if}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
3
|
+
|
|
4
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
block: BuilderBlock;
|
|
8
|
+
repeatContext: BuilderContextInterface;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
|
|
13
|
+
*
|
|
14
|
+
* ```vue
|
|
15
|
+
* <template>
|
|
16
|
+
* <slot></slot>
|
|
17
|
+
* </template>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { getContext, setContext } from "svelte";
|
|
24
|
+
|
|
25
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
26
|
+
import RenderBlock from "./render-block.svelte";
|
|
27
|
+
|
|
28
|
+
export let block: Props["block"];
|
|
29
|
+
export let repeatContext: Props["repeatContext"];
|
|
30
|
+
|
|
31
|
+
setContext(BuilderContext.key, {
|
|
32
|
+
get content() {
|
|
33
|
+
return repeatContext.content;
|
|
34
|
+
},
|
|
35
|
+
get state() {
|
|
36
|
+
return repeatContext.state;
|
|
37
|
+
},
|
|
38
|
+
get context() {
|
|
39
|
+
return repeatContext.context;
|
|
40
|
+
},
|
|
41
|
+
get apiKey() {
|
|
42
|
+
return repeatContext.apiKey;
|
|
43
|
+
},
|
|
44
|
+
get registeredComponents() {
|
|
45
|
+
return repeatContext.registeredComponents;
|
|
46
|
+
},
|
|
47
|
+
get inheritedStyles() {
|
|
48
|
+
return repeatContext.inheritedStyles;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<RenderBlock {block} context={repeatContext} />
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type { BuilderBlock } from "../types/builder-block.js";
|
|
3
|
+
|
|
4
|
+
export type RenderBlockProps = {
|
|
5
|
+
blocks?: BuilderBlock[];
|
|
6
|
+
parent?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
styleProp?: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { getContext, setContext } from "svelte";
|
|
14
|
+
|
|
15
|
+
import BuilderContext from "../context/builder.context.js";
|
|
16
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
17
|
+
import BlockStyles from "./render-block/block-styles.svelte";
|
|
18
|
+
import RenderBlock from "./render-block/render-block.svelte";
|
|
19
|
+
|
|
20
|
+
export let blocks: RenderBlockProps["blocks"];
|
|
21
|
+
export let parent: RenderBlockProps["parent"];
|
|
22
|
+
export let path: RenderBlockProps["path"];
|
|
23
|
+
export let styleProp: RenderBlockProps["styleProp"];
|
|
24
|
+
|
|
25
|
+
function mitosis_styling(node, vars) {
|
|
26
|
+
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
27
|
+
if (p.startsWith("--")) {
|
|
28
|
+
node.style.setProperty(p, v);
|
|
29
|
+
} else {
|
|
30
|
+
node.style[p] = v;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let builderContext = getContext(BuilderContext.key);
|
|
36
|
+
|
|
37
|
+
function onClick() {
|
|
38
|
+
if (isEditing() && !blocks?.length) {
|
|
39
|
+
window.parent?.postMessage(
|
|
40
|
+
{
|
|
41
|
+
type: "builder.clickEmptyBlocks",
|
|
42
|
+
data: {
|
|
43
|
+
parentElementId: parent,
|
|
44
|
+
dataPath: path,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
"*"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function onMouseEnter() {
|
|
52
|
+
if (isEditing() && !blocks?.length) {
|
|
53
|
+
window.parent?.postMessage(
|
|
54
|
+
{
|
|
55
|
+
type: "builder.hoverEmptyBlocks",
|
|
56
|
+
data: {
|
|
57
|
+
parentElementId: parent,
|
|
58
|
+
dataPath: path,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
"*"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
$: className = () => {
|
|
66
|
+
return "builder-blocks" + (!blocks?.length ? " no-blocks" : "");
|
|
67
|
+
};
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div
|
|
71
|
+
use:mitosis_styling={styleProp}
|
|
72
|
+
class={className() + " div"}
|
|
73
|
+
builder-path={path}
|
|
74
|
+
builder-parent-id={parent}
|
|
75
|
+
dataSet={{
|
|
76
|
+
class: className(),
|
|
77
|
+
}}
|
|
78
|
+
on:click={(event) => {
|
|
79
|
+
onClick();
|
|
80
|
+
}}
|
|
81
|
+
on:mouseenter={(event) => {
|
|
82
|
+
onMouseEnter();
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{#if blocks}
|
|
86
|
+
{#each blocks as block ("render-block-" + block.id)}
|
|
87
|
+
<RenderBlock {block} context={builderContext} />
|
|
88
|
+
{/each}
|
|
89
|
+
{/if}
|
|
90
|
+
|
|
91
|
+
{#if blocks}
|
|
92
|
+
{#each blocks as block ("block-style-" + block.id)}
|
|
93
|
+
<BlockStyles {block} context={builderContext} />
|
|
94
|
+
{/each}
|
|
95
|
+
{/if}
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<style>
|
|
99
|
+
.div {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-direction: column;
|
|
102
|
+
align-items: stretch;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
interface CustomFont {
|
|
3
|
+
family?: string;
|
|
4
|
+
kind?: string;
|
|
5
|
+
fileUrl?: string;
|
|
6
|
+
files?: {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
cssCode?: string;
|
|
13
|
+
customFonts?: CustomFont[];
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import RenderInlinedStyles from "../../render-inlined-styles.svelte";
|
|
19
|
+
|
|
20
|
+
export let cssCode: Props["cssCode"];
|
|
21
|
+
export let customFonts: Props["customFonts"];
|
|
22
|
+
|
|
23
|
+
function getCssFromFont(font) {
|
|
24
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
25
|
+
const family =
|
|
26
|
+
font.family +
|
|
27
|
+
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
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 (!builder.allowCustomFonts) {
|
|
66
|
+
// return '';
|
|
67
|
+
// }
|
|
68
|
+
// TODO: separate internal data from external
|
|
69
|
+
return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
|
|
70
|
+
}
|
|
71
|
+
$: injectedStyles = () => {
|
|
72
|
+
return `
|
|
73
|
+
${cssCode || ""}
|
|
74
|
+
${getFontCss({
|
|
75
|
+
customFonts: customFonts,
|
|
76
|
+
})}`;
|
|
77
|
+
};
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<RenderInlinedStyles styles={injectedStyles()} />
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './render-content.svelte';
|