@builder.io/sdk-react-native 0.0.1-57 → 0.0.1-58

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.
@@ -1,36 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface ImgProps {
5
- attributes?: any;
6
- imgSrc?: string;
7
- altText?: string;
8
- backgroundSize?: "cover" | "contain";
9
- backgroundPosition?:
10
- | "center"
11
- | "top"
12
- | "left"
13
- | "right"
14
- | "bottom"
15
- | "top left"
16
- | "top right"
17
- | "bottom left"
18
- | "bottom right";
19
- }
20
-
21
- import { isEditing } from "../../functions/is-editing.js";
22
-
23
- export default function ImgComponent(props: ImgProps) {
24
- return (
25
- <View
26
- {...props.attributes}
27
- style={{
28
- objectFit: props.backgroundSize || "cover",
29
- objectPosition: props.backgroundPosition || "center",
30
- }}
31
- key={(isEditing() && props.imgSrc) || "default-key"}
32
- alt={props.altText}
33
- src={props.imgSrc}
34
- />
35
- );
36
- }
@@ -1,31 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface FormInputProps {
5
- type?: string;
6
- attributes?: any;
7
- name?: string;
8
- value?: string;
9
- placeholder?: string;
10
- defaultValue?: string;
11
- required?: boolean;
12
- }
13
-
14
- import { isEditing } from "../../functions/is-editing.js";
15
-
16
- export default function FormInputComponent(props: FormInputProps) {
17
- return (
18
- <View
19
- {...props.attributes}
20
- key={
21
- isEditing() && props.defaultValue ? props.defaultValue : "default-key"
22
- }
23
- placeholder={props.placeholder}
24
- type={props.type}
25
- name={props.name}
26
- value={props.value}
27
- defaultValue={props.defaultValue}
28
- required={props.required}
29
- />
30
- );
31
- }
@@ -1,11 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface RawTextProps {
5
- attributes?: any;
6
- text?: string; // builderBlock?: any;
7
- }
8
-
9
- export default function RawText(props: RawTextProps) {
10
- return <View dangerouslySetInnerHTML={{ __html: props.text || "" }} />;
11
- }
@@ -1,26 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface SectionProps {
5
- maxWidth?: number;
6
- attributes?: any;
7
- children?: any;
8
- builderBlock?: any;
9
- }
10
-
11
- export default function SectionComponent(props: SectionProps) {
12
- return (
13
- <View
14
- {...props.attributes}
15
- style={
16
- props.maxWidth && typeof props.maxWidth === "number"
17
- ? {
18
- maxWidth: props.maxWidth,
19
- }
20
- : undefined
21
- }
22
- >
23
- <Text>{props.children}</Text>
24
- </View>
25
- );
26
- }
@@ -1,35 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface FormSelectProps {
5
- options?: {
6
- name?: string;
7
- value: string;
8
- }[];
9
- attributes?: any;
10
- name?: string;
11
- value?: string;
12
- defaultValue?: string;
13
- }
14
-
15
- import { isEditing } from "../../functions/is-editing.js";
16
-
17
- export default function SelectComponent(props: FormSelectProps) {
18
- return (
19
- <View
20
- {...props.attributes}
21
- value={props.value}
22
- key={
23
- isEditing() && props.defaultValue ? props.defaultValue : "default-key"
24
- }
25
- defaultValue={props.defaultValue}
26
- name={props.name}
27
- >
28
- {props.options?.map((option) => (
29
- <View value={option.value}>
30
- <Text>{option.name || option.value}</Text>
31
- </View>
32
- ))}
33
- </View>
34
- );
35
- }
@@ -1,15 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface ButtonProps {
5
- attributes?: any;
6
- text?: string;
7
- }
8
-
9
- export default function SubmitButton(props: ButtonProps) {
10
- return (
11
- <View {...props.attributes} type="submit">
12
- <Text>{props.text}</Text>
13
- </View>
14
- );
15
- }
@@ -1,79 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext, useEffect } from "react";
4
-
5
- export interface SymbolInfo {
6
- model?: string;
7
- entry?: string;
8
- data?: any;
9
- content?: any;
10
- inline?: boolean;
11
- dynamic?: boolean;
12
- }
13
- export interface SymbolProps {
14
- symbol?: SymbolInfo;
15
- dataOnly?: boolean;
16
- dynamic?: boolean;
17
- builderBlock?: any; // TODO: BuilderElement
18
-
19
- attributes?: any;
20
- inheritState?: boolean;
21
- }
22
-
23
- import RenderContent from "../../components/render-content/render-content.lite";
24
- import BuilderContext from "../../context/builder.context";
25
- import { getContent } from "../../functions/get-content/index.js";
26
-
27
- export default function Symbol(props: SymbolProps) {
28
- const [className, setClassName] = useState(() => "builder-symbol");
29
-
30
- const [content, setContent] = useState(() => null);
31
-
32
- const builderContext = useContext(BuilderContext);
33
-
34
- useEffect(() => {
35
- setContent(props.symbol?.content);
36
- }, []);
37
-
38
- useEffect(() => {
39
- const symbolToUse = props.symbol;
40
-
41
- if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
42
- getContent({
43
- model: symbolToUse.model,
44
- apiKey: builderContext.apiKey,
45
- options: {
46
- entry: symbolToUse.entry,
47
- },
48
- }).then((response) => {
49
- setContent(response);
50
- });
51
- }
52
- }, [
53
- props.symbol?.content,
54
- props.symbol?.model,
55
- props.symbol?.entry,
56
- content,
57
- ]);
58
-
59
- return (
60
- <View
61
- {...props.attributes}
62
- dataSet={{
63
- class: className,
64
- }}
65
- >
66
- <RenderContent
67
- apiKey={builderContext.apiKey}
68
- context={builderContext.context}
69
- data={{
70
- ...props.symbol?.data,
71
- ...builderContext.state,
72
- ...props.symbol?.content?.data?.state,
73
- }}
74
- model={props.symbol?.model}
75
- content={content}
76
- />
77
- </View>
78
- );
79
- }
@@ -1,6 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function Text(props: { text: string }) {
5
- return <View dangerouslySetInnerHTML={{ __html: props.text }} />;
6
- }
@@ -1,22 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface TextareaProps {
5
- attributes?: any;
6
- name?: string;
7
- value?: string;
8
- defaultValue?: string;
9
- placeholder?: string;
10
- }
11
-
12
- export default function Textarea(props: TextareaProps) {
13
- return (
14
- <View
15
- {...props.attributes}
16
- placeholder={props.placeholder}
17
- name={props.name}
18
- value={props.value}
19
- defaultValue={props.defaultValue}
20
- />
21
- );
22
- }
@@ -1,53 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export interface VideoProps {
5
- attributes?: any;
6
- video?: string;
7
- autoPlay?: boolean;
8
- controls?: boolean;
9
- muted?: boolean;
10
- loop?: boolean;
11
- playsInline?: boolean;
12
- aspectRatio?: number;
13
- width?: number;
14
- height?: number;
15
- fit?: "contain" | "cover" | "fill";
16
- position?:
17
- | "center"
18
- | "top"
19
- | "left"
20
- | "right"
21
- | "bottom"
22
- | "top left"
23
- | "top right"
24
- | "bottom left"
25
- | "bottom right";
26
- posterImage?: string;
27
- lazyLoad?: boolean;
28
- }
29
-
30
- export default function Video(props: VideoProps) {
31
- return (
32
- <View
33
- {...props.attributes}
34
- preload="none"
35
- style={{
36
- width: "100%",
37
- height: "100%",
38
- ...props.attributes?.style,
39
- objectFit: props.fit,
40
- objectPosition: props.position,
41
- // Hack to get object fit to work as expected and
42
- // not have the video overflow
43
- borderRadius: 1,
44
- }}
45
- key={props.video || "no-src"}
46
- poster={props.posterImage}
47
- autoPlay={props.autoPlay}
48
- muted={props.muted}
49
- controls={props.controls}
50
- loop={props.loop}
51
- />
52
- );
53
- }
@@ -1,6 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function ErrorBoundary(props: any) {
5
- return <></>;
6
- }
@@ -1,61 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useContext } from "react";
4
-
5
- export type BlockStylesProps = {
6
- block: BuilderBlock;
7
- };
8
- import { TARGET } from "../../constants/target.js";
9
- import BuilderContext from "../../context/builder.context";
10
- import { getProcessedBlock } from "../../functions/get-processed-block.js";
11
- import RenderInlinedStyles from "../render-inlined-styles.lite";
12
-
13
- export default function BlockStyles(props: BlockStylesProps) {
14
- function useBlock() {
15
- return getProcessedBlock({
16
- block: props.block,
17
- state: builderContext.state,
18
- context: builderContext.context,
19
- });
20
- }
21
-
22
- function camelToKebabCase(string) {
23
- return string
24
- .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2")
25
- .toLowerCase();
26
- }
27
-
28
- function css() {
29
- // TODO: media queries
30
- const styleObject = useBlock().responsiveStyles?.large;
31
-
32
- if (!styleObject) {
33
- return "";
34
- }
35
-
36
- let str = `.${useBlock().id} {`;
37
-
38
- for (const key in styleObject) {
39
- const value = styleObject[key];
40
-
41
- if (typeof value === "string") {
42
- str += `${camelToKebabCase(key)}: ${value};`;
43
- }
44
- }
45
-
46
- str += "}";
47
- return str;
48
- }
49
-
50
- const builderContext = useContext(BuilderContext);
51
-
52
- return (
53
- <>
54
- {TARGET === "vue" || TARGET === "svelte" ? (
55
- <>
56
- <RenderInlinedStyles styles={css()} />
57
- </>
58
- ) : null}
59
- </>
60
- );
61
- }
@@ -1,153 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useContext } from "react";
4
-
5
- export type RenderBlockProps = {
6
- block: BuilderBlock;
7
- }; // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
8
-
9
- import BuilderContext from "../../context/builder.context";
10
- import { getBlockActions } from "../../functions/get-block-actions.js";
11
- import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
12
- import { getBlockProperties } from "../../functions/get-block-properties.js";
13
- import { getBlockStyles } from "../../functions/get-block-styles.js";
14
- import { getBlockTag } from "../../functions/get-block-tag.js";
15
- import { getProcessedBlock } from "../../functions/get-processed-block.js";
16
- import BlockStyles from "./block-styles.lite";
17
- import { isEmptyHtmlElement } from "./render-block.helpers.js";
18
- import RenderComponent from "./render-component.lite";
19
-
20
- export default function RenderBlock(props: RenderBlockProps) {
21
- function component() {
22
- const componentName = useBlock().component?.name;
23
-
24
- if (!componentName) {
25
- return null;
26
- }
27
-
28
- const ref = builderContext.registeredComponents[componentName];
29
-
30
- if (!ref) {
31
- // TODO: Public doc page with more info about this message
32
- console.warn(`
33
- Could not find a registered component named "${componentName}".
34
- If you registered it, is the file that registered it imported by the file that needs to render it?`);
35
- return undefined;
36
- } else {
37
- return ref;
38
- }
39
- }
40
-
41
- function componentInfo() {
42
- if (component()) {
43
- const { component: _, ...info } = component();
44
- return info;
45
- } else {
46
- return undefined;
47
- }
48
- }
49
-
50
- function componentRef() {
51
- return component?.()?.component;
52
- }
53
-
54
- function tagName() {
55
- return getBlockTag(useBlock());
56
- }
57
-
58
- function useBlock() {
59
- return getProcessedBlock({
60
- block: props.block,
61
- state: builderContext.state,
62
- context: builderContext.context,
63
- });
64
- }
65
-
66
- function attributes() {
67
- return {
68
- ...getBlockProperties(useBlock()),
69
- ...getBlockActions({
70
- block: useBlock(),
71
- state: builderContext.state,
72
- context: builderContext.context,
73
- }),
74
- style: getBlockStyles(useBlock()),
75
- };
76
- }
77
-
78
- function shouldWrap() {
79
- return !componentInfo?.()?.noWrap;
80
- }
81
-
82
- function componentOptions() {
83
- return {
84
- ...getBlockComponentOptions(useBlock()),
85
-
86
- /**
87
- * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
88
- * they are provided to the component itself directly.
89
- */
90
- ...(shouldWrap()
91
- ? {}
92
- : {
93
- attributes: attributes(),
94
- }),
95
- };
96
- }
97
-
98
- function children() {
99
- // TO-DO: When should `canHaveChildren` dictate rendering?
100
- // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
101
- // but still receive and need to render children.
102
- // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
103
- return useBlock().children ?? [];
104
- }
105
-
106
- function noCompRefChildren() {
107
- /**
108
- * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
109
- * we render them outside of `componentRef`
110
- */
111
- return componentRef() ? [] : children();
112
- }
113
-
114
- const builderContext = useContext(BuilderContext);
115
-
116
- const TagNameRef = tagName();
117
-
118
- return (
119
- <>
120
- {shouldWrap() ? (
121
- <>
122
- {!isEmptyHtmlElement(tagName()) ? (
123
- <>
124
- <TagNameRef {...attributes()}>
125
- <RenderComponent
126
- blockChildren={children()}
127
- componentRef={componentRef()}
128
- componentOptions={componentOptions()}
129
- />
130
-
131
- {noCompRefChildren()?.map((child) => (
132
- <RenderBlock key={"render-block-" + child.id} block={child} />
133
- ))}
134
-
135
- {noCompRefChildren()?.map((child) => (
136
- <BlockStyles key={"block-style-" + child.id} block={child} />
137
- ))}
138
- </TagNameRef>
139
- </>
140
- ) : (
141
- <TagNameRef {...attributes()} />
142
- )}
143
- </>
144
- ) : (
145
- <RenderComponent
146
- blockChildren={children()}
147
- componentRef={componentRef()}
148
- componentOptions={componentOptions()}
149
- />
150
- )}
151
- </>
152
- );
153
- }
@@ -1,32 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- type Props = {
5
- componentRef: any;
6
- componentOptions: any;
7
- blockChildren: BuilderBlock[];
8
- };
9
- import BlockStyles from "./block-styles.lite";
10
- import RenderBlock from "./render-block.lite";
11
-
12
- export default function RenderComponent(props: Props) {
13
- const ComponentRefRef = props.componentRef;
14
-
15
- return (
16
- <>
17
- {props.componentRef ? (
18
- <>
19
- <ComponentRefRef {...props.componentOptions}>
20
- {props.blockChildren?.map((child) => (
21
- <RenderBlock key={"render-block-" + child.id} block={child} />
22
- ))}
23
-
24
- {props.blockChildren?.map((child) => (
25
- <BlockStyles key={"block-style-" + child.id} block={child} />
26
- ))}
27
- </ComponentRefRef>
28
- </>
29
- ) : null}
30
- </>
31
- );
32
- }
@@ -1,80 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export type RenderBlockProps = {
5
- blocks?: BuilderBlock[];
6
- parent?: string;
7
- path?: string;
8
- };
9
- import { isEditing } from "../functions/is-editing.js";
10
- import BlockStyles from "./render-block/block-styles.lite";
11
- import RenderBlock from "./render-block/render-block.lite";
12
-
13
- export default function RenderBlocks(props: RenderBlockProps) {
14
- function className() {
15
- return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
16
- }
17
-
18
- function onClick() {
19
- if (isEditing() && !props.blocks?.length) {
20
- window.parent?.postMessage(
21
- {
22
- type: "builder.clickEmptyBlocks",
23
- data: {
24
- parentElementId: props.parent,
25
- dataPath: props.path,
26
- },
27
- },
28
- "*"
29
- );
30
- }
31
- }
32
-
33
- function onMouseEnter() {
34
- if (isEditing() && !props.blocks?.length) {
35
- window.parent?.postMessage(
36
- {
37
- type: "builder.hoverEmptyBlocks",
38
- data: {
39
- parentElementId: props.parent,
40
- dataPath: props.path,
41
- },
42
- },
43
- "*"
44
- );
45
- }
46
- }
47
-
48
- return (
49
- <View
50
- builder-path={props.path}
51
- builder-parent-id={props.parent}
52
- dataSet={{
53
- class: className(),
54
- }}
55
- onClick={(event) => onClick()}
56
- onMouseEnter={(event) => onMouseEnter()}
57
- style={styles.view1}
58
- >
59
- {props.blocks ? (
60
- <>
61
- {props.blocks?.map((block) => (
62
- <RenderBlock key={"render-block-" + block.id} block={block} />
63
- ))}
64
- </>
65
- ) : null}
66
-
67
- {props.blocks ? (
68
- <>
69
- {props.blocks?.map((block) => (
70
- <BlockStyles key={"block-style-" + block.id} block={block} />
71
- ))}
72
- </>
73
- ) : null}
74
- </View>
75
- );
76
- }
77
-
78
- const styles = StyleSheet.create({
79
- view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
80
- });