@builder.io/sdk-react-native 0.0.1-56 → 0.0.1-59

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +4 -0
  3. package/package.json +1 -1
  4. package/src/blocks/custom-code/custom-code.js +1 -1
  5. package/src/blocks/embed/embed.js +1 -1
  6. package/src/blocks/form/form.js +1 -1
  7. package/src/components/render-block/block-styles.js +16 -18
  8. package/src/constants/device-sizes.js +3 -21
  9. package/src/functions/camel-to-kebab-case.js +5 -0
  10. package/src/helpers/css.js +13 -0
  11. package/src/blocks/button/button.lite.tsx +0 -25
  12. package/src/blocks/columns/columns.lite.tsx +0 -70
  13. package/src/blocks/custom-code/custom-code.lite.tsx +0 -59
  14. package/src/blocks/embed/embed.lite.tsx +0 -61
  15. package/src/blocks/form/form.lite.tsx +0 -254
  16. package/src/blocks/fragment/fragment.lite.tsx +0 -10
  17. package/src/blocks/image/image.lite.tsx +0 -67
  18. package/src/blocks/img/img.lite.tsx +0 -18
  19. package/src/blocks/input/input.lite.tsx +0 -20
  20. package/src/blocks/raw-text/raw-text.lite.tsx +0 -6
  21. package/src/blocks/section/section.lite.tsx +0 -19
  22. package/src/blocks/select/select.lite.tsx +0 -23
  23. package/src/blocks/submit-button/submit-button.lite.tsx +0 -10
  24. package/src/blocks/symbol/symbol.lite.tsx +0 -60
  25. package/src/blocks/text/text.lite.tsx +0 -6
  26. package/src/blocks/textarea/textarea.lite.tsx +0 -14
  27. package/src/blocks/video/video.lite.tsx +0 -27
  28. package/src/components/error-boundary.js +0 -25
  29. package/src/components/error-boundary.lite.tsx +0 -6
  30. package/src/components/render-block/block-styles.lite.tsx +0 -57
  31. package/src/components/render-block/render-block.lite.tsx +0 -148
  32. package/src/components/render-block/render-component.lite.tsx +0 -26
  33. package/src/components/render-blocks.lite.tsx +0 -74
  34. package/src/components/render-content/components/render-styles.lite.tsx +0 -70
  35. package/src/components/render-content/render-content.lite.tsx +0 -283
  36. package/src/components/render-inlined-styles.lite.tsx +0 -31
@@ -1,67 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function Image(props) {
5
- return (
6
- <View style={styles.view1}>
7
- <View>
8
- <View
9
- loading="lazy"
10
- alt={props.altText}
11
- role={props.altText ? "presentation" : undefined}
12
- style={styles.view2}
13
- src={props.image}
14
- srcSet={props.srcset}
15
- sizes={props.sizes}
16
- />
17
-
18
- <View srcSet={props.srcset} />
19
- </View>
20
-
21
- {props.aspectRatio &&
22
- !(props.fitContent && props.builderBlock?.children?.length) ? (
23
- <View style={styles.view3}>
24
- <Text> </Text>
25
- </View>
26
- ) : null}
27
-
28
- {props.builderBlock?.children?.length && props.fitContent ? (
29
- <>
30
- <Text>{props.children}</Text>
31
- </>
32
- ) : null}
33
-
34
- {!props.fitContent ? (
35
- <>
36
- <View style={styles.view4}>
37
- <Text>{props.children}</Text>
38
- </View>
39
- </>
40
- ) : null}
41
- </View>
42
- );
43
- }
44
-
45
- const styles = StyleSheet.create({
46
- view1: { position: "relative" },
47
- view2: {
48
- opacity: 1,
49
- transition: "opacity 0.2s ease-in-out",
50
- position: "absolute",
51
- height: 100,
52
- width: 100,
53
- top: 0,
54
- left: 0,
55
- },
56
- view3: { width: 100, pointerEvents: "none", fontSize: 0 },
57
- view4: {
58
- display: "flex",
59
- flexDirection: "column",
60
- alignItems: "stretch",
61
- position: "absolute",
62
- top: 0,
63
- left: 0,
64
- width: 100,
65
- height: 100,
66
- },
67
- });
@@ -1,18 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { isEditing } from "../../functions/is-editing.js";
4
-
5
- export default function ImgComponent(props) {
6
- return (
7
- <View
8
- {...props.attributes}
9
- style={{
10
- objectFit: props.backgroundSize || "cover",
11
- objectPosition: props.backgroundPosition || "center",
12
- }}
13
- key={(isEditing() && props.imgSrc) || "default-key"}
14
- alt={props.altText}
15
- src={props.imgSrc}
16
- />
17
- );
18
- }
@@ -1,20 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { isEditing } from "../../functions/is-editing.js";
4
-
5
- export default function FormInputComponent(props) {
6
- return (
7
- <View
8
- {...props.attributes}
9
- key={
10
- isEditing() && props.defaultValue ? props.defaultValue : "default-key"
11
- }
12
- placeholder={props.placeholder}
13
- type={props.type}
14
- name={props.name}
15
- value={props.value}
16
- defaultValue={props.defaultValue}
17
- required={props.required}
18
- />
19
- );
20
- }
@@ -1,6 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function RawText(props) {
5
- return <View dangerouslySetInnerHTML={{ __html: props.text || "" }} />;
6
- }
@@ -1,19 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function SectionComponent(props) {
5
- return (
6
- <View
7
- {...props.attributes}
8
- style={
9
- props.maxWidth && typeof props.maxWidth === "number"
10
- ? {
11
- maxWidth: props.maxWidth,
12
- }
13
- : undefined
14
- }
15
- >
16
- <Text>{props.children}</Text>
17
- </View>
18
- );
19
- }
@@ -1,23 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { isEditing } from "../../functions/is-editing.js";
4
-
5
- export default function SelectComponent(props) {
6
- return (
7
- <View
8
- {...props.attributes}
9
- value={props.value}
10
- key={
11
- isEditing() && props.defaultValue ? props.defaultValue : "default-key"
12
- }
13
- defaultValue={props.defaultValue}
14
- name={props.name}
15
- >
16
- {props.options?.map((option) => (
17
- <View value={option.value}>
18
- <Text>{option.name || option.value}</Text>
19
- </View>
20
- ))}
21
- </View>
22
- );
23
- }
@@ -1,10 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function SubmitButton(props) {
5
- return (
6
- <View {...props.attributes} type="submit">
7
- <Text>{props.text}</Text>
8
- </View>
9
- );
10
- }
@@ -1,60 +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
- import RenderContent from "../../components/render-content/render-content.lite";
5
- import BuilderContext from "../../context/builder.context";
6
- import { getContent } from "../../functions/get-content/index.js";
7
-
8
- export default function Symbol(props) {
9
- const [className, setClassName] = useState(() => "builder-symbol");
10
-
11
- const [content, setContent] = useState(() => null);
12
-
13
- const builderContext = useContext(BuilderContext);
14
-
15
- useEffect(() => {
16
- setContent(props.symbol?.content);
17
- }, []);
18
-
19
- useEffect(() => {
20
- const symbolToUse = props.symbol;
21
-
22
- if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
23
- getContent({
24
- model: symbolToUse.model,
25
- apiKey: builderContext.apiKey,
26
- options: {
27
- entry: symbolToUse.entry,
28
- },
29
- }).then((response) => {
30
- setContent(response);
31
- });
32
- }
33
- }, [
34
- props.symbol?.content,
35
- props.symbol?.model,
36
- props.symbol?.entry,
37
- content,
38
- ]);
39
-
40
- return (
41
- <View
42
- {...props.attributes}
43
- dataSet={{
44
- class: className,
45
- }}
46
- >
47
- <RenderContent
48
- apiKey={builderContext.apiKey}
49
- context={builderContext.context}
50
- data={{
51
- ...props.symbol?.data,
52
- ...builderContext.state,
53
- ...props.symbol?.content?.data?.state,
54
- }}
55
- model={props.symbol?.model}
56
- content={content}
57
- />
58
- </View>
59
- );
60
- }
@@ -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) {
5
- return <View dangerouslySetInnerHTML={{ __html: props.text }} />;
6
- }
@@ -1,14 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function Textarea(props) {
5
- return (
6
- <View
7
- {...props.attributes}
8
- placeholder={props.placeholder}
9
- name={props.name}
10
- value={props.value}
11
- defaultValue={props.defaultValue}
12
- />
13
- );
14
- }
@@ -1,27 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function Video(props) {
5
- return (
6
- <View
7
- {...props.attributes}
8
- preload="none"
9
- style={{
10
- width: "100%",
11
- height: "100%",
12
- ...props.attributes?.style,
13
- objectFit: props.fit,
14
- objectPosition: props.position,
15
- // Hack to get object fit to work as expected and
16
- // not have the video overflow
17
- borderRadius: 1,
18
- }}
19
- key={props.video || "no-src"}
20
- poster={props.posterImage}
21
- autoPlay={props.autoPlay}
22
- muted={props.muted}
23
- controls={props.controls}
24
- loop={props.loop}
25
- />
26
- );
27
- }
@@ -1,25 +0,0 @@
1
- import React from "react";
2
- import { Text } from "react-native";
3
- class ErrorBoundary extends React.Component {
4
- constructor(props) {
5
- super(props);
6
- this.state = { hasError: false };
7
- }
8
- static getDerivedStateFromError(error) {
9
- return { hasError: true };
10
- }
11
- componentDidCatch(error, errorInfo) {
12
- console.error("Error rendering Builder.io block", error, errorInfo);
13
- }
14
- render() {
15
- if (this.state.hasError) {
16
- return /* @__PURE__ */ React.createElement(Text, {
17
- style: { color: "gray" }
18
- }, "Error rendering Builder.io block");
19
- }
20
- return this.props.children;
21
- }
22
- }
23
- export {
24
- ErrorBoundary as default
25
- };
@@ -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) {
5
- return <></>;
6
- }
@@ -1,57 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useContext } from "react";
4
- import { TARGET } from "../../constants/target.js";
5
- import BuilderContext from "../../context/builder.context";
6
- import { getProcessedBlock } from "../../functions/get-processed-block.js";
7
- import RenderInlinedStyles from "../render-inlined-styles.lite";
8
-
9
- export default function BlockStyles(props) {
10
- function useBlock() {
11
- return getProcessedBlock({
12
- block: props.block,
13
- state: builderContext.state,
14
- context: builderContext.context,
15
- });
16
- }
17
-
18
- function camelToKebabCase(string) {
19
- return string
20
- .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2")
21
- .toLowerCase();
22
- }
23
-
24
- function css() {
25
- // TODO: media queries
26
- const styleObject = useBlock().responsiveStyles?.large;
27
-
28
- if (!styleObject) {
29
- return "";
30
- }
31
-
32
- let str = `.${useBlock().id} {`;
33
-
34
- for (const key in styleObject) {
35
- const value = styleObject[key];
36
-
37
- if (typeof value === "string") {
38
- str += `${camelToKebabCase(key)}: ${value};`;
39
- }
40
- }
41
-
42
- str += "}";
43
- return str;
44
- }
45
-
46
- const builderContext = useContext(BuilderContext);
47
-
48
- return (
49
- <>
50
- {TARGET === "vue" || TARGET === "svelte" ? (
51
- <>
52
- <RenderInlinedStyles styles={css()} />
53
- </>
54
- ) : null}
55
- </>
56
- );
57
- }
@@ -1,148 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useContext } from "react";
4
- import BuilderContext from "../../context/builder.context";
5
- import { getBlockActions } from "../../functions/get-block-actions.js";
6
- import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
7
- import { getBlockProperties } from "../../functions/get-block-properties.js";
8
- import { getBlockStyles } from "../../functions/get-block-styles.js";
9
- import { getBlockTag } from "../../functions/get-block-tag.js";
10
- import { getProcessedBlock } from "../../functions/get-processed-block.js";
11
- import BlockStyles from "./block-styles.lite";
12
- import { isEmptyHtmlElement } from "./render-block.helpers.js";
13
- import RenderComponent from "./render-component.lite";
14
-
15
- export default function RenderBlock(props) {
16
- function component() {
17
- const componentName = useBlock().component?.name;
18
-
19
- if (!componentName) {
20
- return null;
21
- }
22
-
23
- const ref = builderContext.registeredComponents[componentName];
24
-
25
- if (!ref) {
26
- // TODO: Public doc page with more info about this message
27
- console.warn(`
28
- Could not find a registered component named "${componentName}".
29
- If you registered it, is the file that registered it imported by the file that needs to render it?`);
30
- return undefined;
31
- } else {
32
- return ref;
33
- }
34
- }
35
-
36
- function componentInfo() {
37
- if (component()) {
38
- const { component: _, ...info } = component();
39
- return info;
40
- } else {
41
- return undefined;
42
- }
43
- }
44
-
45
- function componentRef() {
46
- return component?.()?.component;
47
- }
48
-
49
- function tagName() {
50
- return getBlockTag(useBlock());
51
- }
52
-
53
- function useBlock() {
54
- return getProcessedBlock({
55
- block: props.block,
56
- state: builderContext.state,
57
- context: builderContext.context,
58
- });
59
- }
60
-
61
- function attributes() {
62
- return {
63
- ...getBlockProperties(useBlock()),
64
- ...getBlockActions({
65
- block: useBlock(),
66
- state: builderContext.state,
67
- context: builderContext.context,
68
- }),
69
- style: getBlockStyles(useBlock()),
70
- };
71
- }
72
-
73
- function shouldWrap() {
74
- return !componentInfo?.()?.noWrap;
75
- }
76
-
77
- function componentOptions() {
78
- return {
79
- ...getBlockComponentOptions(useBlock()),
80
-
81
- /**
82
- * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
83
- * they are provided to the component itself directly.
84
- */
85
- ...(shouldWrap()
86
- ? {}
87
- : {
88
- attributes: attributes(),
89
- }),
90
- };
91
- }
92
-
93
- function children() {
94
- // TO-DO: When should `canHaveChildren` dictate rendering?
95
- // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
96
- // but still receive and need to render children.
97
- // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
98
- return useBlock().children ?? [];
99
- }
100
-
101
- function noCompRefChildren() {
102
- /**
103
- * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
104
- * we render them outside of `componentRef`
105
- */
106
- return componentRef() ? [] : children();
107
- }
108
-
109
- const builderContext = useContext(BuilderContext);
110
-
111
- const TagNameRef = tagName();
112
-
113
- return (
114
- <>
115
- {shouldWrap() ? (
116
- <>
117
- {!isEmptyHtmlElement(tagName()) ? (
118
- <>
119
- <TagNameRef {...attributes()}>
120
- <RenderComponent
121
- blockChildren={children()}
122
- componentRef={componentRef()}
123
- componentOptions={componentOptions()}
124
- />
125
-
126
- {noCompRefChildren()?.map((child) => (
127
- <RenderBlock key={"render-block-" + child.id} block={child} />
128
- ))}
129
-
130
- {noCompRefChildren()?.map((child) => (
131
- <BlockStyles key={"block-style-" + child.id} block={child} />
132
- ))}
133
- </TagNameRef>
134
- </>
135
- ) : (
136
- <TagNameRef {...attributes()} />
137
- )}
138
- </>
139
- ) : (
140
- <RenderComponent
141
- blockChildren={children()}
142
- componentRef={componentRef()}
143
- componentOptions={componentOptions()}
144
- />
145
- )}
146
- </>
147
- );
148
- }
@@ -1,26 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import BlockStyles from "./block-styles.lite";
4
- import RenderBlock from "./render-block.lite";
5
-
6
- export default function RenderComponent(props) {
7
- const ComponentRefRef = props.componentRef;
8
-
9
- return (
10
- <>
11
- {props.componentRef ? (
12
- <>
13
- <ComponentRefRef {...props.componentOptions}>
14
- {props.blockChildren?.map((child) => (
15
- <RenderBlock key={"render-block-" + child.id} block={child} />
16
- ))}
17
-
18
- {props.blockChildren?.map((child) => (
19
- <BlockStyles key={"block-style-" + child.id} block={child} />
20
- ))}
21
- </ComponentRefRef>
22
- </>
23
- ) : null}
24
- </>
25
- );
26
- }
@@ -1,74 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { isEditing } from "../functions/is-editing.js";
4
- import BlockStyles from "./render-block/block-styles.lite";
5
- import RenderBlock from "./render-block/render-block.lite";
6
-
7
- export default function RenderBlocks(props) {
8
- function className() {
9
- return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
10
- }
11
-
12
- function onClick() {
13
- if (isEditing() && !props.blocks?.length) {
14
- window.parent?.postMessage(
15
- {
16
- type: "builder.clickEmptyBlocks",
17
- data: {
18
- parentElementId: props.parent,
19
- dataPath: props.path,
20
- },
21
- },
22
- "*"
23
- );
24
- }
25
- }
26
-
27
- function onMouseEnter() {
28
- if (isEditing() && !props.blocks?.length) {
29
- window.parent?.postMessage(
30
- {
31
- type: "builder.hoverEmptyBlocks",
32
- data: {
33
- parentElementId: props.parent,
34
- dataPath: props.path,
35
- },
36
- },
37
- "*"
38
- );
39
- }
40
- }
41
-
42
- return (
43
- <View
44
- builder-path={props.path}
45
- builder-parent-id={props.parent}
46
- dataSet={{
47
- class: className(),
48
- }}
49
- onClick={(event) => onClick()}
50
- onMouseEnter={(event) => onMouseEnter()}
51
- style={styles.view1}
52
- >
53
- {props.blocks ? (
54
- <>
55
- {props.blocks?.map((block) => (
56
- <RenderBlock key={"render-block-" + block.id} block={block} />
57
- ))}
58
- </>
59
- ) : null}
60
-
61
- {props.blocks ? (
62
- <>
63
- {props.blocks?.map((block) => (
64
- <BlockStyles key={"block-style-" + block.id} block={block} />
65
- ))}
66
- </>
67
- ) : null}
68
- </View>
69
- );
70
- }
71
-
72
- const styles = StyleSheet.create({
73
- view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
74
- });
@@ -1,70 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import RenderInlinedStyles from "../../render-inlined-styles.lite";
4
-
5
- export default function RenderContentStyles(props) {
6
- function getCssFromFont(font) {
7
- // TODO: compute what font sizes are used and only load those.......
8
- const family =
9
- font.family +
10
- (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
11
- const name = family.split(",")[0];
12
- const url = font.fileUrl ?? font?.files?.regular;
13
- let str = "";
14
-
15
- if (url && family && name) {
16
- str += `
17
- @font-face {
18
- font-family: "${family}";
19
- src: local("${name}"), url('${url}') format('woff2');
20
- font-display: fallback;
21
- font-weight: 400;
22
- }
23
- `.trim();
24
- }
25
-
26
- if (font.files) {
27
- for (const weight in font.files) {
28
- const isNumber = String(Number(weight)) === weight;
29
-
30
- if (!isNumber) {
31
- continue;
32
- } // TODO: maybe limit number loaded
33
-
34
- const weightUrl = font.files[weight];
35
-
36
- if (weightUrl && weightUrl !== url) {
37
- str += `
38
- @font-face {
39
- font-family: "${family}";
40
- src: url('${weightUrl}') format('woff2');
41
- font-display: fallback;
42
- font-weight: ${weight};
43
- }
44
- `.trim();
45
- }
46
- }
47
- }
48
-
49
- return str;
50
- }
51
-
52
- function getFontCss({ customFonts }) {
53
- // TODO: flag for this
54
- // if (!builder.allowCustomFonts) {
55
- // return '';
56
- // }
57
- // TODO: separate internal data from external
58
- return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
59
- }
60
-
61
- function injectedStyles() {
62
- return `
63
- ${props.cssCode || ""}
64
- ${getFontCss({
65
- customFonts: props.customFonts,
66
- })}`;
67
- }
68
-
69
- return <RenderInlinedStyles styles={injectedStyles()} />;
70
- }