@builder.io/sdk-react-native 0.1.1 → 0.1.3
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/dist/blocks/BaseText.js +40 -0
- package/dist/blocks/button/button.js +39 -0
- package/dist/blocks/button/component-info.js +42 -0
- package/dist/blocks/columns/columns.js +149 -0
- package/dist/blocks/columns/component-info.js +244 -0
- package/dist/blocks/custom-code/component-info.js +32 -0
- package/dist/blocks/custom-code/custom-code.js +76 -0
- package/dist/blocks/embed/component-info.js +47 -0
- package/dist/blocks/embed/embed.js +67 -0
- package/dist/blocks/embed/helpers.js +10 -0
- package/dist/blocks/form/component-info.js +263 -0
- package/dist/blocks/form/form.js +232 -0
- package/dist/blocks/fragment/component-info.js +12 -0
- package/dist/blocks/fragment/fragment.js +36 -0
- package/dist/blocks/image/component-info.js +152 -0
- package/dist/blocks/image/image.helpers.js +49 -0
- package/dist/blocks/image/image.js +81 -0
- package/dist/blocks/img/component-info.js +21 -0
- package/dist/blocks/img/img.js +35 -0
- package/dist/blocks/input/component-info.js +75 -0
- package/dist/blocks/input/input.js +32 -0
- package/dist/blocks/raw-text/component-info.js +17 -0
- package/dist/blocks/raw-text/raw-text.js +31 -0
- package/dist/blocks/section/component-info.js +50 -0
- package/dist/blocks/section/section.js +49 -0
- package/dist/blocks/select/component-info.js +60 -0
- package/dist/blocks/select/select.js +38 -0
- package/dist/blocks/submit-button/component-info.js +29 -0
- package/dist/blocks/submit-button/submit-button.js +36 -0
- package/dist/blocks/symbol/component-info.js +44 -0
- package/dist/blocks/symbol/symbol.js +97 -0
- package/dist/blocks/text/component-info.js +25 -0
- package/dist/blocks/text/text.js +112 -0
- package/dist/blocks/textarea/component-info.js +48 -0
- package/dist/blocks/textarea/textarea.js +31 -0
- package/dist/blocks/util.js +9 -0
- package/dist/blocks/video/component-info.js +107 -0
- package/dist/blocks/video/video.js +81 -0
- package/dist/components/render-block/block-styles.js +79 -0
- package/dist/components/render-block/render-block.helpers.js +109 -0
- package/dist/components/render-block/render-block.js +154 -0
- package/dist/components/render-block/render-component-with-context.js +45 -0
- package/dist/components/render-block/render-component.js +50 -0
- package/dist/components/render-block/render-repeated-block.js +45 -0
- package/dist/components/render-block/types.js +1 -0
- package/dist/components/render-blocks.js +76 -0
- package/dist/components/render-content/builder-editing.js +31 -0
- package/dist/components/render-content/components/render-styles.js +91 -0
- package/dist/components/render-content/index.js +8 -0
- package/dist/components/render-content/render-content.js +325 -0
- package/dist/components/render-inlined-styles.js +42 -0
- package/dist/constants/builder-registered-components.js +46 -0
- package/dist/constants/device-sizes.js +49 -0
- package/dist/constants/target.js +5 -0
- package/dist/context/builder.context.js +13 -0
- package/dist/context/types.js +1 -0
- package/dist/functions/camel-to-kebab-case.js +5 -0
- package/dist/functions/evaluate.js +25 -0
- package/dist/functions/event-handler-name.js +8 -0
- package/dist/functions/extract-text-styles.js +23 -0
- package/dist/functions/fast-clone.js +5 -0
- package/dist/functions/get-block-actions-handler.js +12 -0
- package/dist/functions/get-block-actions.js +19 -0
- package/dist/functions/get-block-component-options.js +29 -0
- package/dist/functions/get-block-properties.js +51 -0
- package/dist/functions/get-block-tag.js +8 -0
- package/dist/functions/get-builder-search-params/fn.test.js +15 -0
- package/dist/functions/get-builder-search-params/index.js +39 -0
- package/dist/functions/get-content/ab-testing.js +89 -0
- package/dist/functions/get-content/generate-content-url.js +44 -0
- package/dist/functions/get-content/generate-content-url.test.js +33 -0
- package/dist/functions/get-content/index.js +68 -0
- package/dist/functions/get-content/types.js +1 -0
- package/dist/functions/get-fetch.js +15 -0
- package/dist/functions/get-global-this.js +19 -0
- package/dist/functions/get-processed-block.js +52 -0
- package/dist/functions/get-processed-block.test.js +34 -0
- package/dist/functions/get-react-native-block-styles.js +30 -0
- package/dist/functions/if-target.js +13 -0
- package/dist/functions/is-browser.js +7 -0
- package/dist/functions/is-editing.js +8 -0
- package/dist/functions/is-iframe.js +8 -0
- package/dist/functions/is-previewing.js +15 -0
- package/dist/functions/on-change.js +28 -0
- package/dist/functions/on-change.test.js +21 -0
- package/dist/functions/register-component.js +65 -0
- package/dist/functions/register.js +31 -0
- package/dist/functions/sanitize-react-native-block-styles.js +71 -0
- package/dist/functions/set-editor-settings.js +16 -0
- package/dist/functions/set.js +12 -0
- package/dist/functions/set.test.js +18 -0
- package/dist/functions/track/helpers.js +53 -0
- package/dist/functions/track/index.js +124 -0
- package/dist/functions/track/interaction.js +51 -0
- package/dist/functions/track.js +120 -0
- package/dist/functions/transform-block-properties.js +18 -0
- package/dist/functions/transform-block.js +38 -0
- package/dist/helpers/ab-tests.js +10 -0
- package/dist/helpers/cookie.js +70 -0
- package/dist/helpers/css.js +33 -0
- package/dist/helpers/flatten.js +35 -0
- package/dist/helpers/localStorage.js +31 -0
- package/dist/helpers/nullable.js +5 -0
- package/dist/helpers/sessionId.js +51 -0
- package/dist/helpers/time.js +6 -0
- package/dist/helpers/url.js +14 -0
- package/dist/helpers/url.test.js +23 -0
- package/dist/helpers/uuid.js +14 -0
- package/dist/helpers/visitorId.js +33 -0
- package/dist/index-helpers/blocks-exports.js +22 -0
- package/dist/index-helpers/top-of-file.js +3 -0
- package/dist/index.js +29 -0
- package/dist/scripts/init-editing.js +97 -0
- package/dist/types/builder-block.js +1 -0
- package/dist/types/builder-content.js +1 -0
- package/dist/types/can-track.js +1 -0
- package/dist/types/components.js +1 -0
- package/dist/types/deep-partial.js +1 -0
- package/dist/types/element.js +1 -0
- package/dist/types/targets.js +1 -0
- package/dist/types/typescript.js +1 -0
- package/package.json +13 -5
- package/src/blocks/BaseText.jsx +17 -0
- package/src/blocks/button/button.jsx +28 -0
- package/src/blocks/columns/{columns.js → columns.jsx} +59 -36
- package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +22 -15
- package/src/blocks/embed/{embed.js → embed.jsx} +12 -11
- package/src/blocks/form/form.jsx +251 -0
- package/src/blocks/fragment/fragment.jsx +11 -0
- package/src/blocks/image/image.jsx +78 -0
- package/src/blocks/img/img.jsx +18 -0
- package/src/blocks/input/input.jsx +20 -0
- package/src/blocks/raw-text/raw-text.jsx +6 -0
- package/src/blocks/section/section.jsx +29 -0
- package/src/blocks/select/select.jsx +24 -0
- package/src/blocks/submit-button/submit-button.jsx +11 -0
- package/src/blocks/symbol/symbol.jsx +86 -0
- package/src/blocks/text/text.jsx +100 -0
- package/src/blocks/textarea/textarea.jsx +14 -0
- package/src/blocks/video/video.jsx +70 -0
- package/src/components/render-block/block-styles.jsx +70 -0
- package/src/components/render-block/render-block.helpers.js +90 -0
- package/src/components/render-block/render-block.jsx +183 -0
- package/src/components/render-block/render-component.jsx +45 -0
- package/src/components/render-block/render-repeated-block.jsx +22 -0
- package/src/components/render-blocks.jsx +86 -0
- package/src/components/render-content/builder-editing.jsx +6 -0
- package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +21 -14
- package/src/components/render-content/render-content.jsx +373 -0
- package/src/components/render-inlined-styles.jsx +29 -0
- package/src/functions/track/helpers.js +50 -0
- package/src/functions/{track.js → track/index.js} +10 -6
- package/src/functions/track/interaction.js +53 -0
- package/src/helpers/localStorage.js +1 -0
- package/src/helpers/sessionId.js +4 -1
- package/src/helpers/url.js +3 -0
- package/src/helpers/url.test.js +6 -0
- package/src/helpers/visitorId.js +1 -0
- package/src/index.js +1 -1
- package/src/blocks/BaseText.js +0 -31
- package/src/blocks/button/button.js +0 -36
- package/src/blocks/form/form.js +0 -222
- package/src/blocks/fragment/fragment.js +0 -9
- package/src/blocks/image/image.js +0 -55
- package/src/blocks/img/img.js +0 -33
- package/src/blocks/input/input.js +0 -36
- package/src/blocks/raw-text/raw-text.js +0 -10
- package/src/blocks/section/section.js +0 -41
- package/src/blocks/select/select.js +0 -37
- package/src/blocks/submit-button/submit-button.js +0 -27
- package/src/blocks/symbol/symbol.js +0 -73
- package/src/blocks/text/text.js +0 -67
- package/src/blocks/textarea/textarea.js +0 -32
- package/src/blocks/video/video.js +0 -55
- package/src/components/render-block/block-styles.js +0 -50
- package/src/components/render-block/render-block.js +0 -202
- package/src/components/render-block/render-component-with-context.js +0 -35
- package/src/components/render-block/render-component.js +0 -35
- package/src/components/render-block/render-repeated-block.js +0 -33
- package/src/components/render-blocks.js +0 -63
- package/src/components/render-content/builder-editing.js +0 -8
- package/src/components/render-content/render-content.js +0 -296
- package/src/components/render-inlined-styles.js +0 -17
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const React = __importStar(require("react"));
|
|
27
|
+
const react_native_1 = require("react-native");
|
|
28
|
+
const react_1 = require("react");
|
|
29
|
+
const helpers_js_1 = require("./helpers.js");
|
|
30
|
+
function Embed(props) {
|
|
31
|
+
const elem = (0, react_1.useRef)(null);
|
|
32
|
+
const [scriptsInserted, setScriptsInserted] = (0, react_1.useState)(() => []);
|
|
33
|
+
const [scriptsRun, setScriptsRun] = (0, react_1.useState)(() => []);
|
|
34
|
+
const [ranInitFn, setRanInitFn] = (0, react_1.useState)(() => false);
|
|
35
|
+
function findAndRunScripts() {
|
|
36
|
+
if (!elem.current || !elem.current.getElementsByTagName)
|
|
37
|
+
return;
|
|
38
|
+
const scripts = elem.current.getElementsByTagName("script");
|
|
39
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
40
|
+
const script = scripts[i];
|
|
41
|
+
if (script.src && !scriptsInserted.includes(script.src)) {
|
|
42
|
+
scriptsInserted.push(script.src);
|
|
43
|
+
const newScript = document.createElement("script");
|
|
44
|
+
newScript.async = true;
|
|
45
|
+
newScript.src = script.src;
|
|
46
|
+
document.head.appendChild(newScript);
|
|
47
|
+
}
|
|
48
|
+
else if ((0, helpers_js_1.isJsScript)(script) && !scriptsRun.includes(script.innerText)) {
|
|
49
|
+
try {
|
|
50
|
+
scriptsRun.push(script.innerText);
|
|
51
|
+
new Function(script.innerText)();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.warn("`Embed`: Error running script:", error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
(0, react_1.useEffect)(() => {
|
|
60
|
+
if (elem.current && !ranInitFn) {
|
|
61
|
+
setRanInitFn(true);
|
|
62
|
+
findAndRunScripts();
|
|
63
|
+
}
|
|
64
|
+
}, [elem.current, ranInitFn]);
|
|
65
|
+
return (React.createElement(react_native_1.View, { ref: elem, dangerouslySetInnerHTML: { __html: props.content } }));
|
|
66
|
+
}
|
|
67
|
+
exports.default = Embed;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isJsScript = void 0;
|
|
4
|
+
const SCRIPT_MIME_TYPES = [
|
|
5
|
+
"text/javascript",
|
|
6
|
+
"application/javascript",
|
|
7
|
+
"application/ecmascript"
|
|
8
|
+
];
|
|
9
|
+
const isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
|
|
10
|
+
exports.isJsScript = isJsScript;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentInfo = void 0;
|
|
4
|
+
const componentInfo = {
|
|
5
|
+
name: "Form:Form",
|
|
6
|
+
builtIn: true,
|
|
7
|
+
defaults: {
|
|
8
|
+
responsiveStyles: {
|
|
9
|
+
large: {
|
|
10
|
+
marginTop: "15px",
|
|
11
|
+
paddingBottom: "15px"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fef36d2a846134910b64b88e6d18c5ca5",
|
|
16
|
+
inputs: [
|
|
17
|
+
{
|
|
18
|
+
name: "sendSubmissionsTo",
|
|
19
|
+
type: "string",
|
|
20
|
+
enum: [
|
|
21
|
+
{
|
|
22
|
+
label: "Send to email",
|
|
23
|
+
value: "email",
|
|
24
|
+
helperText: "Send form submissions to the email address of your choosing"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: "Custom",
|
|
28
|
+
value: "custom",
|
|
29
|
+
helperText: "Handle where the form requests go manually with a little code, e.g. to your own custom backend"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
defaultValue: "email"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "sendSubmissionsToEmail",
|
|
36
|
+
type: "string",
|
|
37
|
+
required: true,
|
|
38
|
+
defaultValue: "your@email.com",
|
|
39
|
+
showIf: 'options.get("sendSubmissionsTo") === "email"'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "sendWithJs",
|
|
43
|
+
type: "boolean",
|
|
44
|
+
helperText: "Set to false to use basic html form action",
|
|
45
|
+
defaultValue: true,
|
|
46
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "name",
|
|
50
|
+
type: "string",
|
|
51
|
+
defaultValue: "My form"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "action",
|
|
55
|
+
type: "string",
|
|
56
|
+
helperText: "URL to send the form data to",
|
|
57
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "contentType",
|
|
61
|
+
type: "string",
|
|
62
|
+
defaultValue: "application/json",
|
|
63
|
+
advanced: true,
|
|
64
|
+
enum: [
|
|
65
|
+
"application/json",
|
|
66
|
+
"multipart/form-data",
|
|
67
|
+
"application/x-www-form-urlencoded"
|
|
68
|
+
],
|
|
69
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "method",
|
|
73
|
+
type: "string",
|
|
74
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"',
|
|
75
|
+
defaultValue: "POST",
|
|
76
|
+
advanced: true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "previewState",
|
|
80
|
+
type: "string",
|
|
81
|
+
enum: ["unsubmitted", "sending", "success", "error"],
|
|
82
|
+
defaultValue: "unsubmitted",
|
|
83
|
+
helperText: 'Choose a state to edit, e.g. choose "success" to show what users see on success and edit the message',
|
|
84
|
+
showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "successUrl",
|
|
88
|
+
type: "url",
|
|
89
|
+
helperText: "Optional URL to redirect the user to on form submission success",
|
|
90
|
+
showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "resetFormOnSubmit",
|
|
94
|
+
type: "boolean",
|
|
95
|
+
showIf: "options.get('sendSubmissionsTo') === 'custom' && options.get('sendWithJs') === true",
|
|
96
|
+
advanced: true
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "successMessage",
|
|
100
|
+
type: "uiBlocks",
|
|
101
|
+
hideFromUI: true,
|
|
102
|
+
defaultValue: [
|
|
103
|
+
{
|
|
104
|
+
"@type": "@builder.io/sdk:Element",
|
|
105
|
+
responsiveStyles: {
|
|
106
|
+
large: {
|
|
107
|
+
marginTop: "10px"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
component: {
|
|
111
|
+
name: "Text",
|
|
112
|
+
options: {
|
|
113
|
+
text: "<span>Thanks!</span>"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "validate",
|
|
121
|
+
type: "boolean",
|
|
122
|
+
defaultValue: true,
|
|
123
|
+
advanced: true
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "errorMessagePath",
|
|
127
|
+
type: "text",
|
|
128
|
+
advanced: true,
|
|
129
|
+
helperText: 'Path to where to get the error message from in a JSON response to display to the user, e.g. "error.message" for a response like { "error": { "message": "this username is taken" }}'
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "errorMessage",
|
|
133
|
+
type: "uiBlocks",
|
|
134
|
+
hideFromUI: true,
|
|
135
|
+
defaultValue: [
|
|
136
|
+
{
|
|
137
|
+
"@type": "@builder.io/sdk:Element",
|
|
138
|
+
responsiveStyles: {
|
|
139
|
+
large: {
|
|
140
|
+
marginTop: "10px"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
bindings: {
|
|
144
|
+
"component.options.text": "state.formErrorMessage || block.component.options.text"
|
|
145
|
+
},
|
|
146
|
+
component: {
|
|
147
|
+
name: "Text",
|
|
148
|
+
options: {
|
|
149
|
+
text: "<span>Form submission error :( Please check your answers and try again</span>"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "sendingMessage",
|
|
157
|
+
type: "uiBlocks",
|
|
158
|
+
hideFromUI: true,
|
|
159
|
+
defaultValue: [
|
|
160
|
+
{
|
|
161
|
+
"@type": "@builder.io/sdk:Element",
|
|
162
|
+
responsiveStyles: {
|
|
163
|
+
large: {
|
|
164
|
+
marginTop: "10px"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
component: {
|
|
168
|
+
name: "Text",
|
|
169
|
+
options: {
|
|
170
|
+
text: "<span>Sending...</span>"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "customHeaders",
|
|
178
|
+
type: "map",
|
|
179
|
+
valueType: {
|
|
180
|
+
type: "string"
|
|
181
|
+
},
|
|
182
|
+
advanced: true,
|
|
183
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'
|
|
184
|
+
}
|
|
185
|
+
],
|
|
186
|
+
noWrap: true,
|
|
187
|
+
canHaveChildren: true,
|
|
188
|
+
defaultChildren: [
|
|
189
|
+
{
|
|
190
|
+
"@type": "@builder.io/sdk:Element",
|
|
191
|
+
responsiveStyles: {
|
|
192
|
+
large: {
|
|
193
|
+
marginTop: "10px"
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
component: {
|
|
197
|
+
name: "Text",
|
|
198
|
+
options: {
|
|
199
|
+
text: "<span>Enter your name</span>"
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"@type": "@builder.io/sdk:Element",
|
|
205
|
+
responsiveStyles: {
|
|
206
|
+
large: {
|
|
207
|
+
marginTop: "10px"
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
component: {
|
|
211
|
+
name: "Form:Input",
|
|
212
|
+
options: {
|
|
213
|
+
name: "name",
|
|
214
|
+
placeholder: "Jane Doe"
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"@type": "@builder.io/sdk:Element",
|
|
220
|
+
responsiveStyles: {
|
|
221
|
+
large: {
|
|
222
|
+
marginTop: "10px"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
component: {
|
|
226
|
+
name: "Text",
|
|
227
|
+
options: {
|
|
228
|
+
text: "<span>Enter your email</span>"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"@type": "@builder.io/sdk:Element",
|
|
234
|
+
responsiveStyles: {
|
|
235
|
+
large: {
|
|
236
|
+
marginTop: "10px"
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
component: {
|
|
240
|
+
name: "Form:Input",
|
|
241
|
+
options: {
|
|
242
|
+
name: "email",
|
|
243
|
+
placeholder: "jane@doe.com"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"@type": "@builder.io/sdk:Element",
|
|
249
|
+
responsiveStyles: {
|
|
250
|
+
large: {
|
|
251
|
+
marginTop: "10px"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
component: {
|
|
255
|
+
name: "Form:SubmitButton",
|
|
256
|
+
options: {
|
|
257
|
+
text: "Submit"
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
};
|
|
263
|
+
exports.componentInfo = componentInfo;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const BaseText_1 = __importDefault(require("../BaseText"));
|
|
30
|
+
const React = __importStar(require("react"));
|
|
31
|
+
const react_native_1 = require("react-native");
|
|
32
|
+
const react_1 = require("react");
|
|
33
|
+
const render_block_js_1 = __importDefault(require("../../components/render-block/render-block.js"));
|
|
34
|
+
const render_blocks_js_1 = __importDefault(require("../../components/render-blocks.js"));
|
|
35
|
+
const is_editing_js_1 = require("../../functions/is-editing.js");
|
|
36
|
+
function FormComponent(props) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const formRef = (0, react_1.useRef)(null);
|
|
39
|
+
const [formState, setFormState] = (0, react_1.useState)(() => "unsubmitted");
|
|
40
|
+
const [responseData, setResponseData] = (0, react_1.useState)(() => null);
|
|
41
|
+
const [formErrorMessage, setFormErrorMessage] = (0, react_1.useState)(() => "");
|
|
42
|
+
function submissionState() {
|
|
43
|
+
return ((0, is_editing_js_1.isEditing)() && props.previewState) || formState;
|
|
44
|
+
}
|
|
45
|
+
function onSubmit(event) {
|
|
46
|
+
var _a;
|
|
47
|
+
const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === "email";
|
|
48
|
+
if (props.sendSubmissionsTo === "zapier") {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
}
|
|
51
|
+
else if (sendWithJs) {
|
|
52
|
+
if (!(props.action || props.sendSubmissionsTo === "email")) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
const el = event.currentTarget;
|
|
58
|
+
const headers = props.customHeaders || {};
|
|
59
|
+
let body;
|
|
60
|
+
const formData = new FormData(el);
|
|
61
|
+
// TODO: maybe support null
|
|
62
|
+
const formPairs = Array.from(event.currentTarget.querySelectorAll("input,select,textarea"))
|
|
63
|
+
.filter((el) => !!el.name)
|
|
64
|
+
.map((el) => {
|
|
65
|
+
let value;
|
|
66
|
+
const key = el.name;
|
|
67
|
+
if (el instanceof HTMLInputElement) {
|
|
68
|
+
if (el.type === "radio") {
|
|
69
|
+
if (el.checked) {
|
|
70
|
+
value = el.name;
|
|
71
|
+
return {
|
|
72
|
+
key,
|
|
73
|
+
value,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (el.type === "checkbox") {
|
|
78
|
+
value = el.checked;
|
|
79
|
+
}
|
|
80
|
+
else if (el.type === "number" || el.type === "range") {
|
|
81
|
+
const num = el.valueAsNumber;
|
|
82
|
+
if (!isNaN(num)) {
|
|
83
|
+
value = num;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (el.type === "file") {
|
|
87
|
+
// TODO: one vs multiple files
|
|
88
|
+
value = el.files;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
value = el.value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
value = el.value;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
key,
|
|
99
|
+
value,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
let contentType = props.contentType;
|
|
103
|
+
if (props.sendSubmissionsTo === "email") {
|
|
104
|
+
contentType = "multipart/form-data";
|
|
105
|
+
}
|
|
106
|
+
Array.from(formPairs).forEach(({ value }) => {
|
|
107
|
+
if (value instanceof File ||
|
|
108
|
+
(Array.isArray(value) && value[0] instanceof File) ||
|
|
109
|
+
value instanceof FileList) {
|
|
110
|
+
contentType = "multipart/form-data";
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
// TODO: send as urlEncoded or multipart by default
|
|
114
|
+
// because of ease of use and reliability in browser API
|
|
115
|
+
// for encoding the form?
|
|
116
|
+
if (contentType !== "application/json") {
|
|
117
|
+
body = formData;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Json
|
|
121
|
+
const json = {};
|
|
122
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
123
|
+
set(json, key, value);
|
|
124
|
+
});
|
|
125
|
+
body = JSON.stringify(json);
|
|
126
|
+
}
|
|
127
|
+
if (contentType && contentType !== "multipart/form-data") {
|
|
128
|
+
if (
|
|
129
|
+
/* Zapier doesn't allow content-type header to be sent from browsers */ !(sendWithJs && ((_a = props.action) === null || _a === void 0 ? void 0 : _a.includes("zapier.com")))) {
|
|
130
|
+
headers["content-type"] = contentType;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const presubmitEvent = new CustomEvent("presubmit", { detail: { body } });
|
|
134
|
+
if (formRef.current) {
|
|
135
|
+
formRef.current.dispatchEvent(presubmitEvent);
|
|
136
|
+
if (presubmitEvent.defaultPrevented) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
setFormState("sending");
|
|
141
|
+
const formUrl = `${builder.env === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
|
|
142
|
+
fetch(props.sendSubmissionsTo === "email"
|
|
143
|
+
? formUrl
|
|
144
|
+
: props.action /* TODO: throw error if no action URL */, { body, headers, method: props.method || "post" }).then(async (res) => {
|
|
145
|
+
let body;
|
|
146
|
+
const contentType = res.headers.get("content-type");
|
|
147
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
148
|
+
body = await res.json();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
body = await res.text();
|
|
152
|
+
}
|
|
153
|
+
if (!res.ok && props.errorMessagePath) {
|
|
154
|
+
/* TODO: allow supplying an error formatter function */ let message = get(body, props.errorMessagePath);
|
|
155
|
+
if (message) {
|
|
156
|
+
if (typeof message !== "string") {
|
|
157
|
+
/* TODO: ideally convert json to yaml so it woul dbe like error: - email has been taken */ message =
|
|
158
|
+
JSON.stringify(message);
|
|
159
|
+
}
|
|
160
|
+
setFormErrorMessage(message);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
setResponseData(body);
|
|
164
|
+
setFormState(res.ok ? "success" : "error");
|
|
165
|
+
if (res.ok) {
|
|
166
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
167
|
+
detail: { res, body },
|
|
168
|
+
});
|
|
169
|
+
if (formRef.current) {
|
|
170
|
+
formRef.current.dispatchEvent(submitSuccessEvent);
|
|
171
|
+
if (submitSuccessEvent.defaultPrevented) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
/* TODO: option to turn this on/off? */ if (props.resetFormOnSubmit !== false) {
|
|
175
|
+
formRef.current.reset();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/* TODO: client side route event first that can be preventDefaulted */ if (props.successUrl) {
|
|
179
|
+
if (formRef.current) {
|
|
180
|
+
const event = new CustomEvent("route", {
|
|
181
|
+
detail: { url: props.successUrl },
|
|
182
|
+
});
|
|
183
|
+
formRef.current.dispatchEvent(event);
|
|
184
|
+
if (!event.defaultPrevented) {
|
|
185
|
+
location.href = props.successUrl;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
location.href = props.successUrl;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, (err) => {
|
|
194
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
195
|
+
detail: { error: err },
|
|
196
|
+
});
|
|
197
|
+
if (formRef.current) {
|
|
198
|
+
formRef.current.dispatchEvent(submitErrorEvent);
|
|
199
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
setResponseData(err);
|
|
204
|
+
setFormState("error");
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const builderContext = (0, react_1.useContext)(BuilderContext);
|
|
209
|
+
return (React.createElement(react_native_1.View, { validate: props.validate, ref: formRef, action: !props.sendWithJs && props.action, method: props.method, name: props.name, onSubmit: (event) => onSubmit(event), ...props.attributes },
|
|
210
|
+
" ",
|
|
211
|
+
props.builderBlock && props.builderBlock.children ? (React.createElement(React.Fragment, null, (_b = (_a = props.builderBlock) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.map((block) => (React.createElement(render_block_js_1.default, { block: block, context: builderContext }))))) : null,
|
|
212
|
+
" ",
|
|
213
|
+
submissionState() === "error" ? (React.createElement(React.Fragment, null,
|
|
214
|
+
React.createElement(render_blocks_js_1.default, { dataPath: "errorMessage", blocks: props.errorMessage }))) : null,
|
|
215
|
+
" ",
|
|
216
|
+
submissionState() === "sending" ? (React.createElement(React.Fragment, null,
|
|
217
|
+
React.createElement(render_blocks_js_1.default, { dataPath: "sendingMessage", blocks: props.sendingMessage }))) : null,
|
|
218
|
+
" ",
|
|
219
|
+
submissionState() === "error" && responseData ? (React.createElement(React.Fragment, null,
|
|
220
|
+
React.createElement(react_native_1.View, { style: styles.view1 },
|
|
221
|
+
" ",
|
|
222
|
+
React.createElement(BaseText_1.default, null, JSON.stringify(responseData, null, 2)),
|
|
223
|
+
" "))) : null,
|
|
224
|
+
" ",
|
|
225
|
+
submissionState() === "success" ? (React.createElement(React.Fragment, null,
|
|
226
|
+
React.createElement(render_blocks_js_1.default, { dataPath: "successMessage", blocks: props.successMessage }))) : null,
|
|
227
|
+
" "));
|
|
228
|
+
}
|
|
229
|
+
exports.default = FormComponent;
|
|
230
|
+
const styles = react_native_1.StyleSheet.create({
|
|
231
|
+
view1: { padding: 10, color: "red", textAlign: "center" },
|
|
232
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentInfo = void 0;
|
|
4
|
+
const componentInfo = {
|
|
5
|
+
name: "Fragment",
|
|
6
|
+
static: true,
|
|
7
|
+
hidden: true,
|
|
8
|
+
builtIn: true,
|
|
9
|
+
canHaveChildren: true,
|
|
10
|
+
noWrap: true
|
|
11
|
+
};
|
|
12
|
+
exports.componentInfo = componentInfo;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const BaseText_1 = __importDefault(require("../BaseText"));
|
|
30
|
+
const React = __importStar(require("react"));
|
|
31
|
+
const react_native_1 = require("react-native");
|
|
32
|
+
function FragmentComponent(props) {
|
|
33
|
+
return (React.createElement(react_native_1.View, null,
|
|
34
|
+
React.createElement(BaseText_1.default, null, props.children)));
|
|
35
|
+
}
|
|
36
|
+
exports.default = FragmentComponent;
|