@builder.io/sdk-svelte 0.0.3 → 0.0.4
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 +159 -0
- package/package/blocks/BaseText.svelte +19 -0
- package/package/blocks/BaseText.svelte.d.ts +19 -0
- package/package/blocks/columns/columns.svelte +13 -4
- package/package/blocks/columns/columns.svelte.d.ts +1 -1
- package/package/blocks/custom-code/custom-code.svelte +1 -1
- package/package/blocks/embed/embed.svelte +2 -0
- package/package/blocks/form/form.svelte +7 -5
- package/package/blocks/image/image.svelte +48 -46
- package/package/blocks/image/image.svelte.d.ts +1 -1
- package/package/blocks/img/img.svelte +7 -2
- package/package/blocks/section/section.svelte +7 -2
- package/package/blocks/symbol/symbol.svelte +13 -13
- package/package/blocks/symbol/symbol.svelte.d.ts +3 -3
- package/package/blocks/video/video.svelte +14 -3
- package/package/components/render-block/block-styles.svelte +24 -19
- package/package/components/render-block/block-styles.svelte.d.ts +2 -2
- package/package/components/render-block/render-block.svelte +81 -58
- package/package/components/render-block/render-block.svelte.d.ts +2 -2
- package/package/components/render-block/render-component-with-context.svelte +32 -0
- package/package/components/render-block/render-component-with-context.svelte.d.ts +19 -0
- package/package/components/render-block/render-component.svelte +1 -3
- package/package/components/render-block/render-component.svelte.d.ts +2 -2
- package/package/components/render-block/render-repeated-block.svelte +3 -0
- package/package/components/render-block/types.d.ts +2 -2
- package/package/components/render-block/types.js +1 -2
- package/package/components/render-blocks.svelte +12 -1
- package/package/components/render-blocks.svelte.d.ts +3 -1
- package/package/components/render-content/components/render-styles.svelte +2 -1
- package/package/components/render-content/render-content.svelte +24 -8
- package/package/components/render-content/render-content.svelte.d.ts +2 -2
- package/package/constants/builder-registered-components.js +3 -0
- package/package/context/builder.context.d.ts +1 -0
- package/package/context/builder.context.js +1 -0
- package/package/context/types.d.ts +4 -3
- package/package/context/types.js +1 -3
- package/package/functions/extract-text-styles.d.ts +4 -0
- package/package/functions/extract-text-styles.js +34 -0
- package/package/functions/fast-clone.d.ts +4 -0
- package/package/functions/fast-clone.js +4 -0
- package/package/functions/get-block-actions-handler.d.ts +5 -0
- package/package/functions/get-block-actions-handler.js +9 -0
- package/package/functions/get-block-actions.d.ts +1 -1
- package/package/functions/get-block-actions.js +2 -8
- package/package/functions/get-block-component-options.d.ts +1 -1
- package/package/functions/get-block-component-options.js +0 -1
- package/package/functions/get-block-properties.d.ts +1 -1
- package/package/functions/get-block-properties.js +0 -1
- package/package/functions/get-block-tag.d.ts +1 -1
- package/package/functions/get-block-tag.js +0 -1
- package/package/functions/get-content/ab-testing.d.ts +5 -3
- package/package/functions/get-content/ab-testing.js +75 -37
- package/package/functions/get-content/index.d.ts +1 -1
- package/package/functions/get-content/index.js +4 -5
- package/package/functions/get-content/types.d.ts +7 -2
- package/package/functions/get-processed-block.d.ts +1 -1
- package/package/functions/get-processed-block.js +5 -4
- package/package/functions/get-processed-block.test.js +0 -1
- package/package/functions/get-react-native-block-styles.d.ts +6 -0
- package/package/functions/get-react-native-block-styles.js +16 -0
- package/package/functions/register-component.d.ts +2 -2
- package/package/functions/register-component.js +1 -5
- package/package/functions/register.d.ts +2 -2
- package/package/functions/register.js +0 -2
- package/package/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/package/functions/sanitize-react-native-block-styles.js +53 -0
- package/package/functions/track.d.ts +1 -1
- package/package/functions/track.js +5 -6
- package/package/functions/transform-block.d.ts +1 -1
- package/package/functions/transform-block.js +0 -1
- package/package/helpers/ab-tests.d.ts +8 -0
- package/package/helpers/ab-tests.js +5 -0
- package/package/helpers/cookie.d.ts +9 -3
- package/package/helpers/cookie.js +8 -3
- package/package/helpers/css.d.ts +5 -1
- package/package/helpers/css.js +14 -1
- package/package/helpers/localStorage.d.ts +3 -4
- package/package/helpers/sessionId.d.ts +3 -4
- package/package/helpers/sessionId.js +5 -3
- package/package/helpers/visitorId.d.ts +3 -5
- package/package/scripts/init-editing.js +42 -38
- package/package/types/builder-content.d.ts +1 -1
- package/package/types/builder-content.js +1 -1
- package/package/types/targets.d.ts +1 -1
- package/package/types/typescript.d.ts +1 -0
- package/package.json +8 -3
- package/package/blocks/button/button.lite.d.ts +0 -0
- package/package/blocks/button/button.lite.tsx +0 -36
- package/package/blocks/columns/columns.lite.d.ts +0 -0
- package/package/blocks/columns/columns.lite.tsx +0 -139
- package/package/blocks/custom-code/custom-code.lite.d.ts +0 -0
- package/package/blocks/custom-code/custom-code.lite.tsx +0 -70
- package/package/blocks/embed/embed.lite.d.ts +0 -0
- package/package/blocks/embed/embed.lite.tsx +0 -52
- package/package/blocks/form/form.lite.d.ts +0 -0
- package/package/blocks/form/form.lite.tsx +0 -351
- package/package/blocks/fragment/fragment.lite.d.ts +0 -0
- package/package/blocks/fragment/fragment.lite.tsx +0 -12
- package/package/blocks/image/image.lite.d.ts +0 -0
- package/package/blocks/image/image.lite.tsx +0 -148
- package/package/blocks/img/img.lite.d.ts +0 -0
- package/package/blocks/img/img.lite.tsx +0 -48
- package/package/blocks/input/input.lite.d.ts +0 -0
- package/package/blocks/input/input.lite.tsx +0 -34
- package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
- package/package/blocks/raw-text/raw-text.lite.tsx +0 -15
- package/package/blocks/section/section.lite.d.ts +0 -0
- package/package/blocks/section/section.lite.tsx +0 -30
- package/package/blocks/select/select.lite.d.ts +0 -0
- package/package/blocks/select/select.lite.tsx +0 -34
- package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
- package/package/blocks/submit-button/submit-button.lite.tsx +0 -15
- package/package/blocks/symbol/symbol.lite.d.ts +0 -0
- package/package/blocks/symbol/symbol.lite.tsx +0 -92
- package/package/blocks/text/text.lite.d.ts +0 -0
- package/package/blocks/text/text.lite.tsx +0 -11
- package/package/blocks/textarea/textarea.lite.d.ts +0 -0
- package/package/blocks/textarea/textarea.lite.tsx +0 -19
- package/package/blocks/video/video.lite.d.ts +0 -0
- package/package/blocks/video/video.lite.tsx +0 -92
- package/package/components/render-block/block-styles.lite.d.ts +0 -0
- package/package/components/render-block/block-styles.lite.tsx +0 -60
- package/package/components/render-block/render-block.lite.d.ts +0 -0
- package/package/components/render-block/render-block.lite.tsx +0 -216
- package/package/components/render-block/render-component.lite.d.ts +0 -0
- package/package/components/render-block/render-component.lite.tsx +0 -33
- package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
- package/package/components/render-block/render-repeated-block.lite.tsx +0 -49
- package/package/components/render-blocks.lite.d.ts +0 -0
- package/package/components/render-blocks.lite.tsx +0 -91
- package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
- package/package/components/render-content/components/render-styles.lite.tsx +0 -86
- package/package/components/render-content/render-content.lite.d.ts +0 -0
- package/package/components/render-content/render-content.lite.tsx +0 -356
- package/package/components/render-inlined-styles.lite.d.ts +0 -0
- package/package/components/render-inlined-styles.lite.tsx +0 -27
- package/package/functions/convert-style-object.d.ts +0 -1
- package/package/functions/convert-style-object.js +0 -3
- package/package/functions/get-block-styles.d.ts +0 -2
- package/package/functions/get-block-styles.js +0 -21
- package/package/functions/sanitize-styles.d.ts +0 -4
- package/package/functions/sanitize-styles.js +0 -6
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export interface ButtonProps {
|
|
3
|
-
attributes?: any;
|
|
4
|
-
text?: string;
|
|
5
|
-
}
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
export let attributes: ButtonProps["attributes"];
|
|
10
|
-
export let text: ButtonProps["text"];
|
|
11
|
-
</script>
|
|
12
|
-
|
|
13
|
-
<button {...attributes} type="submit">
|
|
14
|
-
{text}
|
|
15
|
-
</button>
|
|
File without changes
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export interface SymbolInfo {
|
|
3
|
-
model?: string;
|
|
4
|
-
entry?: string;
|
|
5
|
-
data?: any;
|
|
6
|
-
content?: BuilderContent;
|
|
7
|
-
inline?: boolean;
|
|
8
|
-
dynamic?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface SymbolProps {
|
|
12
|
-
symbol?: SymbolInfo;
|
|
13
|
-
dataOnly?: boolean;
|
|
14
|
-
dynamic?: boolean;
|
|
15
|
-
builderBlock?: BuilderBlock;
|
|
16
|
-
attributes?: any;
|
|
17
|
-
inheritState?: boolean;
|
|
18
|
-
}
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<script lang="ts">
|
|
22
|
-
import { afterUpdate, getContext, onMount, setContext } from "svelte";
|
|
23
|
-
|
|
24
|
-
import RenderContent from "../../components/render-content/render-content.svelte";
|
|
25
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
26
|
-
import { getContent } from "../../functions/get-content/index.js";
|
|
27
|
-
import { BuilderContent } from "../../types/builder-content.js";
|
|
28
|
-
import { Nullable } from "../../types/typescript.js";
|
|
29
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
30
|
-
import { markMutable } from "../../functions/mark-mutable";
|
|
31
|
-
|
|
32
|
-
export let attributes: SymbolProps["attributes"];
|
|
33
|
-
export let symbol: SymbolProps["symbol"];
|
|
34
|
-
|
|
35
|
-
let builderContext = getContext(BuilderContext.key);
|
|
36
|
-
|
|
37
|
-
let className = "builder-symbol";
|
|
38
|
-
let content = null;
|
|
39
|
-
|
|
40
|
-
onMount(() => {
|
|
41
|
-
content = symbol?.content;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
function onUpdateFn_0() {
|
|
45
|
-
const symbolToUse = symbol;
|
|
46
|
-
/**
|
|
47
|
-
* If:
|
|
48
|
-
* - we have a symbol prop
|
|
49
|
-
* - yet it does not have any content
|
|
50
|
-
* - and we have not already stored content from before
|
|
51
|
-
* - and it has a model name
|
|
52
|
-
*
|
|
53
|
-
* then we want to re-fetch the symbol content.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
|
|
57
|
-
getContent({
|
|
58
|
-
model: symbolToUse.model,
|
|
59
|
-
apiKey: builderContext.apiKey,
|
|
60
|
-
query: {
|
|
61
|
-
id: symbolToUse.entry,
|
|
62
|
-
},
|
|
63
|
-
}).then((response) => {
|
|
64
|
-
content = response;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
$: onUpdateFn_0(...[symbol, content]);
|
|
69
|
-
</script>
|
|
70
|
-
|
|
71
|
-
<div
|
|
72
|
-
{...attributes}
|
|
73
|
-
dataSet={{
|
|
74
|
-
class: className,
|
|
75
|
-
}}
|
|
76
|
-
class={className}
|
|
77
|
-
>
|
|
78
|
-
<RenderContent
|
|
79
|
-
apiKey={builderContext.apiKey}
|
|
80
|
-
context={builderContext.context}
|
|
81
|
-
customComponents={markMutable(
|
|
82
|
-
Object.values(builderContext.registeredComponents)
|
|
83
|
-
)}
|
|
84
|
-
data={markMutable({
|
|
85
|
-
...symbol?.data,
|
|
86
|
-
...builderContext.state,
|
|
87
|
-
...symbol?.content?.data?.state,
|
|
88
|
-
})}
|
|
89
|
-
model={symbol?.model}
|
|
90
|
-
content={markMutable(content)}
|
|
91
|
-
/>
|
|
92
|
-
</div>
|
|
File without changes
|
|
File without changes
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export interface TextareaProps {
|
|
3
|
-
attributes?: any;
|
|
4
|
-
name?: string;
|
|
5
|
-
value?: string;
|
|
6
|
-
defaultValue?: string;
|
|
7
|
-
placeholder?: string;
|
|
8
|
-
}
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<script lang="ts">
|
|
12
|
-
export let attributes: TextareaProps["attributes"];
|
|
13
|
-
export let placeholder: TextareaProps["placeholder"];
|
|
14
|
-
export let name: TextareaProps["name"];
|
|
15
|
-
export let value: TextareaProps["value"];
|
|
16
|
-
export let defaultValue: TextareaProps["defaultValue"];
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
<textarea {...attributes} {placeholder} {name} {value} {defaultValue} />
|
|
File without changes
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export interface VideoProps {
|
|
3
|
-
attributes?: any;
|
|
4
|
-
video?: string;
|
|
5
|
-
autoPlay?: boolean;
|
|
6
|
-
controls?: boolean;
|
|
7
|
-
muted?: boolean;
|
|
8
|
-
loop?: boolean;
|
|
9
|
-
playsInline?: boolean;
|
|
10
|
-
aspectRatio?: number;
|
|
11
|
-
width?: number;
|
|
12
|
-
height?: number;
|
|
13
|
-
fit?: "contain" | "cover" | "fill";
|
|
14
|
-
position?:
|
|
15
|
-
| "center"
|
|
16
|
-
| "top"
|
|
17
|
-
| "left"
|
|
18
|
-
| "right"
|
|
19
|
-
| "bottom"
|
|
20
|
-
| "top left"
|
|
21
|
-
| "top right"
|
|
22
|
-
| "bottom left"
|
|
23
|
-
| "bottom right";
|
|
24
|
-
posterImage?: string;
|
|
25
|
-
lazyLoad?: boolean;
|
|
26
|
-
}
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
<script lang="ts">
|
|
30
|
-
export let autoPlay: VideoProps["autoPlay"];
|
|
31
|
-
export let muted: VideoProps["muted"];
|
|
32
|
-
export let controls: VideoProps["controls"];
|
|
33
|
-
export let loop: VideoProps["loop"];
|
|
34
|
-
export let playsInline: VideoProps["playsInline"];
|
|
35
|
-
export let attributes: VideoProps["attributes"];
|
|
36
|
-
export let fit: VideoProps["fit"];
|
|
37
|
-
export let position: VideoProps["position"];
|
|
38
|
-
export let video: VideoProps["video"];
|
|
39
|
-
export let posterImage: VideoProps["posterImage"];
|
|
40
|
-
|
|
41
|
-
function mitosis_styling(node, vars) {
|
|
42
|
-
Object.entries(vars).forEach(([p, v]) => {
|
|
43
|
-
node.style[p] = v;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
$: videoProps = () => {
|
|
48
|
-
return {
|
|
49
|
-
...(autoPlay === true
|
|
50
|
-
? {
|
|
51
|
-
autoPlay: true,
|
|
52
|
-
}
|
|
53
|
-
: {}),
|
|
54
|
-
...(muted === true
|
|
55
|
-
? {
|
|
56
|
-
muted: true,
|
|
57
|
-
}
|
|
58
|
-
: {}),
|
|
59
|
-
...(controls === true
|
|
60
|
-
? {
|
|
61
|
-
controls: true,
|
|
62
|
-
}
|
|
63
|
-
: {}),
|
|
64
|
-
...(loop === true
|
|
65
|
-
? {
|
|
66
|
-
loop: true,
|
|
67
|
-
}
|
|
68
|
-
: {}),
|
|
69
|
-
...(playsInline === true
|
|
70
|
-
? {
|
|
71
|
-
playsInline: true,
|
|
72
|
-
}
|
|
73
|
-
: {}),
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
</script>
|
|
77
|
-
|
|
78
|
-
<video
|
|
79
|
-
{...videoProps()}
|
|
80
|
-
use:mitosis_styling={{
|
|
81
|
-
width: "100%",
|
|
82
|
-
height: "100%",
|
|
83
|
-
...attributes?.style,
|
|
84
|
-
objectFit: fit,
|
|
85
|
-
objectPosition: position,
|
|
86
|
-
// Hack to get object fit to work as expected and
|
|
87
|
-
// not have the video overflow
|
|
88
|
-
borderRadius: 1,
|
|
89
|
-
}}
|
|
90
|
-
src={video || "no-src"}
|
|
91
|
-
poster={posterImage}
|
|
92
|
-
/>
|
|
File without changes
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export type BlockStylesProps = {
|
|
3
|
-
block: BuilderBlock;
|
|
4
|
-
context: BuilderContextInterface;
|
|
5
|
-
};
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
10
|
-
import { TARGET } from "../../constants/target.js";
|
|
11
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
12
|
-
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
13
|
-
import { convertStyleMaptoCSS } from "../../helpers/css.js";
|
|
14
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
15
|
-
import RenderInlinedStyles from "../render-inlined-styles.svelte";
|
|
16
|
-
|
|
17
|
-
export let block: BlockStylesProps["block"];
|
|
18
|
-
export let context: BlockStylesProps["context"];
|
|
19
|
-
|
|
20
|
-
$: useBlock = () => {
|
|
21
|
-
return getProcessedBlock({
|
|
22
|
-
block: block,
|
|
23
|
-
state: context.state,
|
|
24
|
-
context: context.context,
|
|
25
|
-
shouldEvaluateBindings: true,
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
$: css = () => {
|
|
30
|
-
const styles = useBlock().responsiveStyles;
|
|
31
|
-
const largeStyles = styles?.large;
|
|
32
|
-
const mediumStyles = styles?.medium;
|
|
33
|
-
const smallStyles = styles?.small;
|
|
34
|
-
return `
|
|
35
|
-
${
|
|
36
|
-
largeStyles
|
|
37
|
-
? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}`
|
|
38
|
-
: ""
|
|
39
|
-
}
|
|
40
|
-
${
|
|
41
|
-
mediumStyles
|
|
42
|
-
? `${getMaxWidthQueryForSize("medium")} {
|
|
43
|
-
.${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
|
|
44
|
-
}`
|
|
45
|
-
: ""
|
|
46
|
-
}
|
|
47
|
-
${
|
|
48
|
-
smallStyles
|
|
49
|
-
? `${getMaxWidthQueryForSize("small")} {
|
|
50
|
-
.${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
|
|
51
|
-
}`
|
|
52
|
-
: ""
|
|
53
|
-
}
|
|
54
|
-
}`;
|
|
55
|
-
};
|
|
56
|
-
</script>
|
|
57
|
-
|
|
58
|
-
{#if TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}
|
|
59
|
-
<RenderInlinedStyles styles={css()} />
|
|
60
|
-
{/if}
|
|
File without changes
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export type RenderBlockProps = {
|
|
3
|
-
block: BuilderBlock;
|
|
4
|
-
context: BuilderContextInterface;
|
|
5
|
-
}; // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
import {
|
|
10
|
-
BuilderContextInterface,
|
|
11
|
-
RegisteredComponent,
|
|
12
|
-
} from "../../context/types.js";
|
|
13
|
-
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
14
|
-
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
15
|
-
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
16
|
-
import { getBlockStyles } from "../../functions/get-block-styles.js";
|
|
17
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
18
|
-
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
19
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
20
|
-
import { Nullable } from "../../types/typescript.js";
|
|
21
|
-
import { evaluate } from "../../functions/evaluate.js";
|
|
22
|
-
import BlockStyles from "./block-styles.svelte";
|
|
23
|
-
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
24
|
-
import RenderComponent, {
|
|
25
|
-
RenderComponentProps,
|
|
26
|
-
} from "./render-component.svelte";
|
|
27
|
-
import { RepeatData } from "./types.js";
|
|
28
|
-
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
29
|
-
|
|
30
|
-
export let block: RenderBlockProps["block"];
|
|
31
|
-
export let context: RenderBlockProps["context"];
|
|
32
|
-
|
|
33
|
-
$: component = () => {
|
|
34
|
-
const componentName = getProcessedBlock({
|
|
35
|
-
block: block,
|
|
36
|
-
state: context.state,
|
|
37
|
-
context: context.context,
|
|
38
|
-
shouldEvaluateBindings: false,
|
|
39
|
-
}).component?.name;
|
|
40
|
-
|
|
41
|
-
if (!componentName) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const ref = context.registeredComponents[componentName];
|
|
46
|
-
|
|
47
|
-
if (!ref) {
|
|
48
|
-
// TODO: Public doc page with more info about this message
|
|
49
|
-
console.warn(`
|
|
50
|
-
Could not find a registered component named "${componentName}".
|
|
51
|
-
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
52
|
-
return undefined;
|
|
53
|
-
} else {
|
|
54
|
-
return ref;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
$: componentInfo = () => {
|
|
59
|
-
if (component()) {
|
|
60
|
-
const { component: _, ...info } = component();
|
|
61
|
-
return info;
|
|
62
|
-
} else {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
$: componentRef = () => {
|
|
68
|
-
return component?.()?.component;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
$: tagName = () => {
|
|
72
|
-
return getBlockTag(useBlock());
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
$: useBlock = () => {
|
|
76
|
-
return repeatItemData()
|
|
77
|
-
? block
|
|
78
|
-
: getProcessedBlock({
|
|
79
|
-
block: block,
|
|
80
|
-
state: context.state,
|
|
81
|
-
context: context.context,
|
|
82
|
-
shouldEvaluateBindings: true,
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
$: attributes = () => {
|
|
87
|
-
return {
|
|
88
|
-
...getBlockProperties(useBlock()),
|
|
89
|
-
...getBlockActions({
|
|
90
|
-
block: useBlock(),
|
|
91
|
-
state: context.state,
|
|
92
|
-
context: context.context,
|
|
93
|
-
}),
|
|
94
|
-
style: getBlockStyles(useBlock()),
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
$: shouldWrap = () => {
|
|
99
|
-
return !componentInfo?.()?.noWrap;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
$: componentOptions = () => {
|
|
103
|
-
return {
|
|
104
|
-
...getBlockComponentOptions(useBlock()),
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
108
|
-
* they are provided to the component itself directly.
|
|
109
|
-
*/
|
|
110
|
-
...(shouldWrap()
|
|
111
|
-
? {}
|
|
112
|
-
: {
|
|
113
|
-
attributes: attributes(),
|
|
114
|
-
}),
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
$: renderComponentProps = () => {
|
|
119
|
-
return {
|
|
120
|
-
blockChildren: children(),
|
|
121
|
-
componentRef: componentRef(),
|
|
122
|
-
componentOptions: componentOptions(),
|
|
123
|
-
context: context,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
$: children = () => {
|
|
128
|
-
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
129
|
-
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
130
|
-
// but still receive and need to render children.
|
|
131
|
-
// return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
|
|
132
|
-
return useBlock().children ?? [];
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
$: childrenWithoutParentComponent = () => {
|
|
136
|
-
/**
|
|
137
|
-
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
138
|
-
* we render them outside of `componentRef`.
|
|
139
|
-
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
140
|
-
* blocks, and the children will be repeated within those blocks.
|
|
141
|
-
*/
|
|
142
|
-
const shouldRenderChildrenOutsideRef = !componentRef() && !repeatItemData();
|
|
143
|
-
return shouldRenderChildrenOutsideRef ? children() : [];
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
$: repeatItemData = () => {
|
|
147
|
-
/**
|
|
148
|
-
* we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
|
|
149
|
-
* which will not work if there is a repeat.
|
|
150
|
-
*/
|
|
151
|
-
const { repeat, ...blockWithoutRepeat } = block;
|
|
152
|
-
|
|
153
|
-
if (!repeat?.collection) {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const itemsArray = evaluate({
|
|
158
|
-
code: repeat.collection,
|
|
159
|
-
state: context.state,
|
|
160
|
-
context: context.context,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
if (!Array.isArray(itemsArray)) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const collectionName = repeat.collection.split(".").pop();
|
|
168
|
-
const itemNameToUse =
|
|
169
|
-
repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
170
|
-
const repeatArray = itemsArray.map((item, index) => ({
|
|
171
|
-
context: {
|
|
172
|
-
...context,
|
|
173
|
-
state: {
|
|
174
|
-
...context.state,
|
|
175
|
-
$index: index,
|
|
176
|
-
$item: item,
|
|
177
|
-
[itemNameToUse]: item,
|
|
178
|
-
[`$${itemNameToUse}Index`]: index,
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
block: blockWithoutRepeat,
|
|
182
|
-
}));
|
|
183
|
-
return repeatArray;
|
|
184
|
-
};
|
|
185
|
-
</script>
|
|
186
|
-
|
|
187
|
-
{#if shouldWrap()}
|
|
188
|
-
{#if !isEmptyHtmlElement(tagName())}
|
|
189
|
-
<svelte:element this={tagName()} {...attributes()}>
|
|
190
|
-
{#if repeatItemData()}
|
|
191
|
-
{#each repeatItemData() as data, index (index)}
|
|
192
|
-
<RenderRepeatedBlock
|
|
193
|
-
repeatContext={data.context}
|
|
194
|
-
block={data.block}
|
|
195
|
-
/>
|
|
196
|
-
{/each}
|
|
197
|
-
{/if}
|
|
198
|
-
|
|
199
|
-
{#if !repeatItemData()}
|
|
200
|
-
<RenderComponent {...renderComponentProps()} />
|
|
201
|
-
{/if}
|
|
202
|
-
|
|
203
|
-
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
204
|
-
<svelte:self block={child} {context} />
|
|
205
|
-
{/each}
|
|
206
|
-
|
|
207
|
-
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
208
|
-
<BlockStyles block={child} {context} />
|
|
209
|
-
{/each}
|
|
210
|
-
</svelte:element>
|
|
211
|
-
{:else}
|
|
212
|
-
<svelte:element this={tagName()} {...attributes()} />
|
|
213
|
-
{/if}
|
|
214
|
-
{:else}
|
|
215
|
-
<RenderComponent {...renderComponentProps()} {context} />
|
|
216
|
-
{/if}
|
|
File without changes
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export interface RenderComponentProps {
|
|
3
|
-
componentRef: any;
|
|
4
|
-
componentOptions: any;
|
|
5
|
-
blockChildren: BuilderBlock[];
|
|
6
|
-
context: BuilderContextInterface;
|
|
7
|
-
} // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<script lang="ts">
|
|
11
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
12
|
-
import BlockStyles from "./block-styles.svelte";
|
|
13
|
-
import RenderBlock from "./render-block.svelte";
|
|
14
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
15
|
-
import { markPropsMutable } from "../../functions/mark-mutable.js";
|
|
16
|
-
|
|
17
|
-
export let componentRef: RenderComponentProps["componentRef"];
|
|
18
|
-
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
19
|
-
export let blockChildren: RenderComponentProps["blockChildren"];
|
|
20
|
-
export let context: RenderComponentProps["context"];
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
{#if componentRef}
|
|
24
|
-
<svelte:component this={componentRef} {...markPropsMutable(componentOptions)}>
|
|
25
|
-
{#each blockChildren as child ("render-block-" + child.id)}
|
|
26
|
-
<RenderBlock block={child} {context} />
|
|
27
|
-
{/each}
|
|
28
|
-
|
|
29
|
-
{#each blockChildren as child ("block-style-" + child.id)}
|
|
30
|
-
<BlockStyles block={child} {context} />
|
|
31
|
-
{/each}
|
|
32
|
-
</svelte:component>
|
|
33
|
-
{/if}
|
|
File without changes
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
* We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
|
|
12
|
-
*
|
|
13
|
-
* ```vue
|
|
14
|
-
* <template>
|
|
15
|
-
* <slot></slot>
|
|
16
|
-
* </template>
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<script lang="ts">
|
|
22
|
-
import { getContext, setContext } from "svelte";
|
|
23
|
-
|
|
24
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
25
|
-
import RenderBlock from "./render-block.svelte";
|
|
26
|
-
|
|
27
|
-
export let block: Props["block"];
|
|
28
|
-
export let repeatContext: Props["repeatContext"];
|
|
29
|
-
|
|
30
|
-
setContext(BuilderContext.key, {
|
|
31
|
-
get content() {
|
|
32
|
-
return repeatContext.content;
|
|
33
|
-
},
|
|
34
|
-
get state() {
|
|
35
|
-
return repeatContext.state;
|
|
36
|
-
},
|
|
37
|
-
get context() {
|
|
38
|
-
return repeatContext.context;
|
|
39
|
-
},
|
|
40
|
-
get apiKey() {
|
|
41
|
-
return repeatContext.apiKey;
|
|
42
|
-
},
|
|
43
|
-
get registeredComponents() {
|
|
44
|
-
return repeatContext.registeredComponents;
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
</script>
|
|
48
|
-
|
|
49
|
-
<RenderBlock {block} context={repeatContext} />
|
|
File without changes
|