@builder.io/sdk-react-native 1.0.32 → 1.0.34
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/lib/browser/commonjs/blocks/text/text.js +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js +1 -1
- package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/browser/commonjs/functions/is-from-trusted-host.js +3 -0
- package/lib/browser/commonjs/functions/is-from-trusted-host.js.map +1 -1
- package/lib/browser/commonjs/helpers/cookie.js +12 -2
- package/lib/browser/commonjs/helpers/cookie.js.map +1 -1
- package/lib/browser/module/blocks/text/text.js +1 -1
- package/lib/browser/module/blocks/text/text.js.map +1 -1
- package/lib/browser/module/constants/sdk-version.js +1 -1
- package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/browser/module/functions/is-from-trusted-host.js +3 -0
- package/lib/browser/module/functions/is-from-trusted-host.js.map +1 -1
- package/lib/browser/module/helpers/cookie.js +11 -2
- package/lib/browser/module/helpers/cookie.js.map +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/browser/typescript/functions/is-from-trusted-host.d.ts.map +1 -1
- package/lib/browser/typescript/helpers/cookie.d.ts +1 -0
- package/lib/browser/typescript/helpers/cookie.d.ts.map +1 -1
- package/lib/edge/commonjs/blocks/text/text.js +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js +1 -1
- package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/edge/commonjs/functions/is-from-trusted-host.js +3 -0
- package/lib/edge/commonjs/functions/is-from-trusted-host.js.map +1 -1
- package/lib/edge/commonjs/helpers/cookie.js +12 -2
- package/lib/edge/commonjs/helpers/cookie.js.map +1 -1
- package/lib/edge/module/blocks/text/text.js +1 -1
- package/lib/edge/module/blocks/text/text.js.map +1 -1
- package/lib/edge/module/constants/sdk-version.js +1 -1
- package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/edge/module/functions/is-from-trusted-host.js +3 -0
- package/lib/edge/module/functions/is-from-trusted-host.js.map +1 -1
- package/lib/edge/module/helpers/cookie.js +11 -2
- package/lib/edge/module/helpers/cookie.js.map +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/edge/typescript/functions/is-from-trusted-host.d.ts.map +1 -1
- package/lib/edge/typescript/helpers/cookie.d.ts +1 -0
- package/lib/edge/typescript/helpers/cookie.d.ts.map +1 -1
- package/lib/node/commonjs/blocks/text/text.js +1 -1
- package/lib/node/commonjs/constants/sdk-version.js +1 -1
- package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/node/commonjs/functions/is-from-trusted-host.js +3 -0
- package/lib/node/commonjs/functions/is-from-trusted-host.js.map +1 -1
- package/lib/node/commonjs/helpers/cookie.js +12 -2
- package/lib/node/commonjs/helpers/cookie.js.map +1 -1
- package/lib/node/module/blocks/text/text.js +1 -1
- package/lib/node/module/blocks/text/text.js.map +1 -1
- package/lib/node/module/constants/sdk-version.js +1 -1
- package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/node/module/functions/is-from-trusted-host.js +3 -0
- package/lib/node/module/functions/is-from-trusted-host.js.map +1 -1
- package/lib/node/module/helpers/cookie.js +11 -2
- package/lib/node/module/helpers/cookie.js.map +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/node/typescript/functions/is-from-trusted-host.d.ts.map +1 -1
- package/lib/node/typescript/helpers/cookie.d.ts +1 -0
- package/lib/node/typescript/helpers/cookie.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/blocks/BaseText.tsx +17 -0
- package/src/blocks/accordion/accordion.tsx +181 -0
- package/src/blocks/accordion/accordion.types.ts +12 -0
- package/src/blocks/accordion/component-info.ts +124 -0
- package/src/blocks/accordion/helpers.ts +3 -0
- package/src/blocks/accordion/index.ts +1 -0
- package/src/blocks/button/button.tsx +56 -0
- package/src/blocks/button/button.types.ts +7 -0
- package/src/blocks/button/component-info.ts +35 -0
- package/src/blocks/button/index.ts +1 -0
- package/src/blocks/columns/columns.tsx +199 -0
- package/src/blocks/columns/columns.types.ts +14 -0
- package/src/blocks/columns/component-info.ts +219 -0
- package/src/blocks/columns/helpers.ts +3 -0
- package/src/blocks/columns/index.ts +1 -0
- package/src/blocks/custom-code/component-info.ts +24 -0
- package/src/blocks/custom-code/custom-code.tsx +71 -0
- package/src/blocks/custom-code/index.ts +1 -0
- package/src/blocks/embed/component-info.ts +38 -0
- package/src/blocks/embed/embed.tsx +62 -0
- package/src/blocks/embed/helpers.ts +2 -0
- package/src/blocks/embed/index.ts +1 -0
- package/src/blocks/form/form/component-info.ts +233 -0
- package/src/blocks/form/form/form.tsx +324 -0
- package/src/blocks/form/form/index.ts +1 -0
- package/src/blocks/form/input/component-info.ts +47 -0
- package/src/blocks/form/input/index.ts +1 -0
- package/src/blocks/form/input/input.tsx +49 -0
- package/src/blocks/form/select/component-info.ts +44 -0
- package/src/blocks/form/select/index.ts +1 -0
- package/src/blocks/form/select/select.tsx +54 -0
- package/src/blocks/form/submit-button/component-info.ts +27 -0
- package/src/blocks/form/submit-button/index.ts +1 -0
- package/src/blocks/form/submit-button/submit-button.tsx +34 -0
- package/src/blocks/fragment/component-info.ts +8 -0
- package/src/blocks/fragment/fragment.tsx +18 -0
- package/src/blocks/fragment/fragment.types.ts +5 -0
- package/src/blocks/fragment/index.ts +1 -0
- package/src/blocks/helpers.ts +43 -0
- package/src/blocks/image/component-info.ts +129 -0
- package/src/blocks/image/image.helpers.ts +47 -0
- package/src/blocks/image/image.tsx +65 -0
- package/src/blocks/image/image.types.ts +20 -0
- package/src/blocks/image/index.ts +1 -0
- package/src/blocks/img/component-info.ts +16 -0
- package/src/blocks/img/img.tsx +55 -0
- package/src/blocks/img/index.ts +1 -0
- package/src/blocks/raw-text/component-info.ts +11 -0
- package/src/blocks/raw-text/index.ts +1 -0
- package/src/blocks/raw-text/raw-text.tsx +1 -0
- package/src/blocks/section/component-info.ts +41 -0
- package/src/blocks/section/index.ts +1 -0
- package/src/blocks/section/section.tsx +39 -0
- package/src/blocks/section/section.types.ts +6 -0
- package/src/blocks/slot/component-info.ts +15 -0
- package/src/blocks/slot/index.ts +1 -0
- package/src/blocks/slot/slot.tsx +42 -0
- package/src/blocks/symbol/component-info.ts +35 -0
- package/src/blocks/symbol/index.ts +1 -0
- package/src/blocks/symbol/symbol.helpers.ts +47 -0
- package/src/blocks/symbol/symbol.tsx +100 -0
- package/src/blocks/symbol/symbol.types.ts +17 -0
- package/src/blocks/tabs/component-info.ts +139 -0
- package/src/blocks/tabs/index.ts +1 -0
- package/src/blocks/tabs/tabs.tsx +79 -0
- package/src/blocks/tabs/tabs.types.ts +13 -0
- package/src/blocks/text/component-info.ts +20 -0
- package/src/blocks/text/index.ts +1 -0
- package/src/blocks/text/text.tsx +105 -0
- package/src/blocks/text/text.types.ts +4 -0
- package/src/blocks/textarea/component-info.ts +38 -0
- package/src/blocks/textarea/index.ts +1 -0
- package/src/blocks/textarea/textarea.tsx +41 -0
- package/src/blocks/video/component-info.ts +83 -0
- package/src/blocks/video/index.ts +1 -0
- package/src/blocks/video/video.tsx +70 -0
- package/src/blocks/video/video.types.ts +21 -0
- package/src/components/block/animator.ts +220 -0
- package/src/components/block/block.helpers.ts +124 -0
- package/src/components/block/block.tsx +232 -0
- package/src/components/block/components/block-styles.tsx +136 -0
- package/src/components/block/components/block-wrapper.tsx +52 -0
- package/src/components/block/components/component-ref/component-ref.helpers.ts +55 -0
- package/src/components/block/components/component-ref/component-ref.tsx +66 -0
- package/src/components/block/components/interactive-element.tsx +53 -0
- package/src/components/block/components/repeated-block.tsx +37 -0
- package/src/components/block/types.ts +6 -0
- package/src/components/blocks/blocks-wrapper.tsx +93 -0
- package/src/components/blocks/blocks.tsx +57 -0
- package/src/components/blocks/blocks.types.ts +7 -0
- package/src/components/blocks/index.ts +1 -0
- package/src/components/content/components/enable-editor.tsx +472 -0
- package/src/components/content/components/styles.helpers.ts +101 -0
- package/src/components/content/components/styles.tsx +42 -0
- package/src/components/content/content.helpers.ts +40 -0
- package/src/components/content/content.tsx +150 -0
- package/src/components/content/content.types.ts +13 -0
- package/src/components/content/contentProps.types.ts +17 -0
- package/src/components/content/index.ts +1 -0
- package/src/components/content/wrap-component-ref.ts +6 -0
- package/src/components/content-variants/content-variants.tsx +146 -0
- package/src/components/content-variants/content-variants.types.ts +84 -0
- package/src/components/content-variants/helpers.ts +72 -0
- package/src/components/content-variants/index.ts +1 -0
- package/src/components/content-variants/inlined-fns.ts +22 -0
- package/src/components/dynamic-div.tsx +30 -0
- package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
- package/src/components/dynamic-renderer/dynamic-renderer.tsx +47 -0
- package/src/components/error-boundary.tsx +38 -0
- package/src/components/inlined-script.tsx +10 -0
- package/src/components/inlined-styles.tsx +10 -0
- package/src/constants/builder-registered-components.ts +59 -0
- package/src/constants/device-sizes.ts +59 -0
- package/src/constants/extra-components.ts +1 -0
- package/src/constants/sdk-version.ts +1 -0
- package/src/constants/target.ts +3 -0
- package/src/context/builder.context.ts +15 -0
- package/src/context/components.context.ts +3 -0
- package/src/context/index.ts +1 -0
- package/src/context/types.ts +38 -0
- package/src/functions/apply-patch-with-mutation.ts +61 -0
- package/src/functions/camel-to-kebab-case.ts +1 -0
- package/src/functions/deopt.ts +6 -0
- package/src/functions/evaluate/browser-runtime/browser.ts +61 -0
- package/src/functions/evaluate/browser-runtime/index.ts +1 -0
- package/src/functions/evaluate/choose-eval.ts +23 -0
- package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +2891 -0
- package/src/functions/evaluate/edge-runtime/edge-runtime.ts +89 -0
- package/src/functions/evaluate/edge-runtime/index.ts +1 -0
- package/src/functions/evaluate/evaluate.ts +76 -0
- package/src/functions/evaluate/helpers.ts +56 -0
- package/src/functions/evaluate/index.ts +1 -0
- package/src/functions/evaluate/node-runtime/index.ts +1 -0
- package/src/functions/evaluate/node-runtime/init.ts +33 -0
- package/src/functions/evaluate/node-runtime/node-runtime.ts +176 -0
- package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +14 -0
- package/src/functions/evaluate/placeholder-runtime.ts +4 -0
- package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +16 -0
- package/src/functions/event-handler-name.ts +4 -0
- package/src/functions/extract-text-styles.ts +24 -0
- package/src/functions/fast-clone.ts +4 -0
- package/src/functions/fetch-builder-props.ts +75 -0
- package/src/functions/get-block-actions-handler.ts +17 -0
- package/src/functions/get-block-actions.ts +35 -0
- package/src/functions/get-block-component-options.ts +7 -0
- package/src/functions/get-block-properties.ts +62 -0
- package/src/functions/get-builder-search-params/index.ts +33 -0
- package/src/functions/get-class-prop-name.ts +15 -0
- package/src/functions/get-content/generate-content-url.ts +88 -0
- package/src/functions/get-content/index.ts +99 -0
- package/src/functions/get-content/types.ts +157 -0
- package/src/functions/get-env.ts +5 -0
- package/src/functions/get-fetch.ts +11 -0
- package/src/functions/get-global-this.ts +16 -0
- package/src/functions/get-processed-block.ts +70 -0
- package/src/functions/get-style.ts +38 -0
- package/src/functions/get.ts +4 -0
- package/src/functions/is-browser.ts +3 -0
- package/src/functions/is-edge-runtime.ts +9 -0
- package/src/functions/is-editing.ts +8 -0
- package/src/functions/is-from-trusted-host.ts +11 -0
- package/src/functions/is-iframe.ts +4 -0
- package/src/functions/is-node-runtime.ts +8 -0
- package/src/functions/is-previewing.ts +16 -0
- package/src/functions/on-change.ts +29 -0
- package/src/functions/register-component.ts +30 -0
- package/src/functions/register.ts +44 -0
- package/src/functions/set-editor-settings.ts +15 -0
- package/src/functions/set.ts +14 -0
- package/src/functions/track/helpers.ts +51 -0
- package/src/functions/track/index.ts +131 -0
- package/src/functions/track/interaction.ts +63 -0
- package/src/functions/transform-block-properties.ts +33 -0
- package/src/functions/transform-block.ts +30 -0
- package/src/functions/transform-style-property.ts +296 -0
- package/src/helpers/ab-tests.ts +166 -0
- package/src/helpers/canTrack.ts +2 -0
- package/src/helpers/cookie.ts +109 -0
- package/src/helpers/css.ts +33 -0
- package/src/helpers/flatten.ts +41 -0
- package/src/helpers/localStorage.ts +36 -0
- package/src/helpers/logger.ts +7 -0
- package/src/helpers/nullable.ts +2 -0
- package/src/helpers/omit.ts +7 -0
- package/src/helpers/preview-lru-cache/get.ts +4 -0
- package/src/helpers/preview-lru-cache/helpers.ts +1 -0
- package/src/helpers/preview-lru-cache/init.ts +7 -0
- package/src/helpers/preview-lru-cache/set.ts +12 -0
- package/src/helpers/preview-lru-cache/types.ts +1 -0
- package/src/helpers/search/search.ts +18 -0
- package/src/helpers/sessionId.ts +37 -0
- package/src/helpers/subscribe-to-editor.ts +95 -0
- package/src/helpers/time.ts +2 -0
- package/src/helpers/url.ts +15 -0
- package/src/helpers/uuid.ts +17 -0
- package/src/helpers/visitorId.ts +37 -0
- package/src/index-helpers/blocks-exports.ts +16 -0
- package/src/index-helpers/top-of-file.ts +2 -0
- package/src/index.ts +15 -0
- package/src/scripts/init-editing.ts +119 -0
- package/src/server-index.ts +43 -0
- package/src/types/api-version.ts +2 -0
- package/src/types/builder-block.ts +89 -0
- package/src/types/builder-content.ts +47 -0
- package/src/types/builder-props.ts +12 -0
- package/src/types/can-track.ts +3 -0
- package/src/types/components.ts +119 -0
- package/src/types/deep-partial.ts +1 -0
- package/src/types/element.ts +57 -0
- package/src/types/enforced-partials.ts +19 -0
- package/src/types/input.ts +123 -0
- package/src/types/targets.ts +1 -0
- package/src/types/typescript.ts +9 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import BaseText from "../../blocks/BaseText";
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
ScrollView,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
Text,
|
|
10
|
+
Pressable,
|
|
11
|
+
TextInput,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
import { useState, useRef } from "react";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export type FormProps = BuilderDataProps &
|
|
20
|
+
BuilderComponentsProp &
|
|
21
|
+
BuilderLinkComponentProp & {
|
|
22
|
+
attributes?: any;
|
|
23
|
+
name?: string;
|
|
24
|
+
action?: string;
|
|
25
|
+
validate?: boolean;
|
|
26
|
+
method?: string;
|
|
27
|
+
sendSubmissionsTo?: string;
|
|
28
|
+
sendSubmissionsToEmail?: string;
|
|
29
|
+
sendWithJs?: boolean;
|
|
30
|
+
contentType?: string;
|
|
31
|
+
customHeaders?: {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
};
|
|
34
|
+
successUrl?: string;
|
|
35
|
+
previewState?: FormState;
|
|
36
|
+
successMessage?: BuilderBlock[];
|
|
37
|
+
errorMessage?: BuilderBlock[];
|
|
38
|
+
sendingMessage?: BuilderBlock[];
|
|
39
|
+
resetFormOnSubmit?: boolean;
|
|
40
|
+
errorMessagePath?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export type FormState = "unsubmitted" | "sending" | "success" | "error";
|
|
47
|
+
import Block from "../../../components/block/block";
|
|
48
|
+
import Blocks from "../../../components/blocks/blocks";
|
|
49
|
+
import { getEnv } from "../../../functions/get-env";
|
|
50
|
+
import { get } from "../../../functions/get";
|
|
51
|
+
import { isEditing } from "../../../functions/is-editing";
|
|
52
|
+
import { set } from "../../../functions/set";
|
|
53
|
+
import type { BuilderBlock } from "../../../types/builder-block";
|
|
54
|
+
import type {
|
|
55
|
+
BuilderComponentsProp,
|
|
56
|
+
BuilderDataProps,
|
|
57
|
+
BuilderLinkComponentProp,
|
|
58
|
+
} from "../../../types/builder-props";
|
|
59
|
+
import type { Dictionary } from "../../../types/typescript";
|
|
60
|
+
import { filterAttrs } from "../../helpers";
|
|
61
|
+
import { setAttrs } from "../../helpers";
|
|
62
|
+
|
|
63
|
+
function FormComponent(props: FormProps) {
|
|
64
|
+
const formRef = useRef<HTMLFormElement>(null);
|
|
65
|
+
const [formState, setFormState] = useState(() => "unsubmitted");
|
|
66
|
+
|
|
67
|
+
const [responseData, setResponseData] = useState(() => null);
|
|
68
|
+
|
|
69
|
+
const [formErrorMessage, setFormErrorMessage] = useState(() => "");
|
|
70
|
+
|
|
71
|
+
function mergeNewRootState(newData: Dictionary<any>) {
|
|
72
|
+
const combinedState = {
|
|
73
|
+
...props.builderContext.rootState,
|
|
74
|
+
...newData,
|
|
75
|
+
};
|
|
76
|
+
if (props.builderContext.rootSetState) {
|
|
77
|
+
props.builderContext.rootSetState?.(combinedState);
|
|
78
|
+
} else {
|
|
79
|
+
props.builderContext.rootState = combinedState;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function submissionState() {
|
|
84
|
+
return (isEditing() && props.previewState) || formState;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onSubmit(event: any) {
|
|
88
|
+
const sendWithJsProp =
|
|
89
|
+
props.sendWithJs || props.sendSubmissionsTo === "email";
|
|
90
|
+
if (props.sendSubmissionsTo === "zapier") {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
} else if (sendWithJsProp) {
|
|
93
|
+
if (!(props.action || props.sendSubmissionsTo === "email")) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
const el = event.currentTarget || event.target;
|
|
99
|
+
const headers = props.customHeaders || {};
|
|
100
|
+
let body: any;
|
|
101
|
+
const formData = new FormData(el);
|
|
102
|
+
|
|
103
|
+
// TODO: maybe support null
|
|
104
|
+
const formPairs: {
|
|
105
|
+
key: string;
|
|
106
|
+
value: File | boolean | number | string | FileList;
|
|
107
|
+
}[] = Array.from(el.querySelectorAll("input,select,textarea"))
|
|
108
|
+
.filter((el) => !!(el as HTMLInputElement).name)
|
|
109
|
+
.map((el) => {
|
|
110
|
+
let value: any;
|
|
111
|
+
const key = (el as HTMLImageElement).name;
|
|
112
|
+
if (el instanceof HTMLInputElement) {
|
|
113
|
+
if (el.type === "radio") {
|
|
114
|
+
if (el.checked) {
|
|
115
|
+
value = el.name;
|
|
116
|
+
return {
|
|
117
|
+
key,
|
|
118
|
+
value,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
} else if (el.type === "checkbox") {
|
|
122
|
+
value = el.checked;
|
|
123
|
+
} else if (el.type === "number" || el.type === "range") {
|
|
124
|
+
const num = el.valueAsNumber;
|
|
125
|
+
if (!isNaN(num)) {
|
|
126
|
+
value = num;
|
|
127
|
+
}
|
|
128
|
+
} else if (el.type === "file") {
|
|
129
|
+
// TODO: one vs multiple files
|
|
130
|
+
value = el.files;
|
|
131
|
+
} else {
|
|
132
|
+
value = el.value;
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
value = (el as HTMLInputElement).value;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
key,
|
|
139
|
+
value,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
let formContentType = props.contentType;
|
|
143
|
+
if (props.sendSubmissionsTo === "email") {
|
|
144
|
+
formContentType = "multipart/form-data";
|
|
145
|
+
}
|
|
146
|
+
Array.from(formPairs).forEach(({ value }) => {
|
|
147
|
+
if (
|
|
148
|
+
value instanceof File ||
|
|
149
|
+
(Array.isArray(value) && value[0] instanceof File) ||
|
|
150
|
+
value instanceof FileList
|
|
151
|
+
) {
|
|
152
|
+
formContentType = "multipart/form-data";
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// TODO: send as urlEncoded or multipart by default
|
|
157
|
+
// because of ease of use and reliability in browser API
|
|
158
|
+
// for encoding the form?
|
|
159
|
+
if (formContentType !== "application/json") {
|
|
160
|
+
body = formData;
|
|
161
|
+
} else {
|
|
162
|
+
// Json
|
|
163
|
+
const json = {};
|
|
164
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
165
|
+
set(json, key, value);
|
|
166
|
+
});
|
|
167
|
+
body = JSON.stringify(json);
|
|
168
|
+
}
|
|
169
|
+
if (formContentType && formContentType !== "multipart/form-data") {
|
|
170
|
+
if (
|
|
171
|
+
/* Zapier doesn't allow content-type header to be sent from browsers */ !(
|
|
172
|
+
sendWithJsProp && props.action?.includes("zapier.com")
|
|
173
|
+
)
|
|
174
|
+
) {
|
|
175
|
+
headers["content-type"] = formContentType;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const presubmitEvent = new CustomEvent("presubmit", { detail: { body } });
|
|
179
|
+
if (formRef.current) {
|
|
180
|
+
formRef.current.dispatchEvent(presubmitEvent);
|
|
181
|
+
if (presubmitEvent.defaultPrevented) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
setFormState("sending");
|
|
186
|
+
const formUrl = `${
|
|
187
|
+
getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"
|
|
188
|
+
}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
|
|
189
|
+
props.sendSubmissionsToEmail || ""
|
|
190
|
+
)}&name=${encodeURIComponent(props.name || "")}`;
|
|
191
|
+
fetch(
|
|
192
|
+
props.sendSubmissionsTo === "email"
|
|
193
|
+
? formUrl
|
|
194
|
+
: props.action! /* TODO: throw error if no action URL */,
|
|
195
|
+
{ body, headers, method: props.method || "post" }
|
|
196
|
+
).then(
|
|
197
|
+
async (res) => {
|
|
198
|
+
let body;
|
|
199
|
+
const contentType = res.headers.get("content-type");
|
|
200
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
201
|
+
body = await res.json();
|
|
202
|
+
} else {
|
|
203
|
+
body = await res.text();
|
|
204
|
+
}
|
|
205
|
+
if (!res.ok && props.errorMessagePath) {
|
|
206
|
+
/* TODO: allow supplying an error formatter function */ let message =
|
|
207
|
+
get(body, props.errorMessagePath);
|
|
208
|
+
if (message) {
|
|
209
|
+
if (typeof message !== "string") {
|
|
210
|
+
/* TODO: ideally convert json to yaml so it woul dbe like error: - email has been taken */ message =
|
|
211
|
+
JSON.stringify(message);
|
|
212
|
+
}
|
|
213
|
+
setFormErrorMessage(message);
|
|
214
|
+
mergeNewRootState({ formErrorMessage: message });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
setResponseData(body);
|
|
218
|
+
setFormState(res.ok ? "success" : "error");
|
|
219
|
+
if (res.ok) {
|
|
220
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
221
|
+
detail: { res, body },
|
|
222
|
+
});
|
|
223
|
+
if (formRef.current) {
|
|
224
|
+
formRef.current.dispatchEvent(submitSuccessEvent);
|
|
225
|
+
if (submitSuccessEvent.defaultPrevented) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
/* TODO: option to turn this on/off? */ if (
|
|
229
|
+
props.resetFormOnSubmit !== false
|
|
230
|
+
) {
|
|
231
|
+
formRef.current.reset();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/* TODO: client side route event first that can be preventDefaulted */ if (
|
|
235
|
+
props.successUrl
|
|
236
|
+
) {
|
|
237
|
+
if (formRef.current) {
|
|
238
|
+
const event = new CustomEvent("route", {
|
|
239
|
+
detail: { url: props.successUrl },
|
|
240
|
+
});
|
|
241
|
+
formRef.current.dispatchEvent(event);
|
|
242
|
+
if (!event.defaultPrevented) {
|
|
243
|
+
location.href = props.successUrl;
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
location.href = props.successUrl;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
(err) => {
|
|
252
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
253
|
+
detail: { error: err },
|
|
254
|
+
});
|
|
255
|
+
if (formRef.current) {
|
|
256
|
+
formRef.current.dispatchEvent(submitErrorEvent);
|
|
257
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
setResponseData(err);
|
|
262
|
+
setFormState("error");
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return (
|
|
268
|
+
<View
|
|
269
|
+
validate={props.validate}
|
|
270
|
+
ref={formRef}
|
|
271
|
+
action={!props.sendWithJs && props.action}
|
|
272
|
+
method={props.method}
|
|
273
|
+
name={props.name}
|
|
274
|
+
onSubmit={(event) => onSubmit(event)}
|
|
275
|
+
{...{}}
|
|
276
|
+
{...{}}
|
|
277
|
+
{...props.attributes}
|
|
278
|
+
>
|
|
279
|
+
{props.builderBlock && props.builderBlock.children ? (
|
|
280
|
+
<>
|
|
281
|
+
{props.builderBlock?.children?.map((block, idx) => (
|
|
282
|
+
<Block
|
|
283
|
+
key={`form-block-${idx}`}
|
|
284
|
+
block={block}
|
|
285
|
+
context={props.builderContext}
|
|
286
|
+
registeredComponents={props.builderComponents}
|
|
287
|
+
linkComponent={props.builderLinkComponent}
|
|
288
|
+
/>
|
|
289
|
+
))}
|
|
290
|
+
</>
|
|
291
|
+
) : null}
|
|
292
|
+
{submissionState() === "error" ? (
|
|
293
|
+
<Blocks
|
|
294
|
+
path="errorMessage"
|
|
295
|
+
blocks={props.errorMessage!}
|
|
296
|
+
context={props.builderContext}
|
|
297
|
+
/>
|
|
298
|
+
) : null}
|
|
299
|
+
{submissionState() === "sending" ? (
|
|
300
|
+
<Blocks
|
|
301
|
+
path="sendingMessage"
|
|
302
|
+
blocks={props.sendingMessage!}
|
|
303
|
+
context={props.builderContext}
|
|
304
|
+
/>
|
|
305
|
+
) : null}
|
|
306
|
+
{submissionState() === "error" && responseData ? (
|
|
307
|
+
<View style={styles.view1}>
|
|
308
|
+
<BaseText>{JSON.stringify(responseData, null, 2)}</BaseText>
|
|
309
|
+
</View>
|
|
310
|
+
) : null}
|
|
311
|
+
{submissionState() === "success" ? (
|
|
312
|
+
<Blocks
|
|
313
|
+
path="successMessage"
|
|
314
|
+
blocks={props.successMessage!}
|
|
315
|
+
context={props.builderContext}
|
|
316
|
+
/>
|
|
317
|
+
) : null}
|
|
318
|
+
</View>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
const styles = StyleSheet.create({
|
|
322
|
+
view1: { padding: 10, color: "red", textAlign: "center" },
|
|
323
|
+
});
|
|
324
|
+
export default FormComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './form'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../../types/components';
|
|
2
|
+
export const componentInfo: ComponentInfo = {
|
|
3
|
+
name: 'Form:Input',
|
|
4
|
+
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca',
|
|
5
|
+
inputs: [{
|
|
6
|
+
name: 'type',
|
|
7
|
+
type: 'text',
|
|
8
|
+
enum: ['text', 'number', 'email', 'url', 'checkbox', 'radio', 'range', 'date', 'datetime-local', 'search', 'tel', 'time', 'file', 'month', 'week', 'password', 'color', 'hidden'],
|
|
9
|
+
defaultValue: 'text'
|
|
10
|
+
}, {
|
|
11
|
+
name: 'name',
|
|
12
|
+
type: 'string',
|
|
13
|
+
required: true,
|
|
14
|
+
helperText: 'Every input in a form needs a unique name describing what it takes, e.g. "email"'
|
|
15
|
+
}, {
|
|
16
|
+
name: 'placeholder',
|
|
17
|
+
type: 'string',
|
|
18
|
+
defaultValue: 'Hello there',
|
|
19
|
+
helperText: 'Text to display when there is no value'
|
|
20
|
+
},
|
|
21
|
+
// TODO: handle value vs default value automatically like ng-model
|
|
22
|
+
{
|
|
23
|
+
name: 'defaultValue',
|
|
24
|
+
type: 'string'
|
|
25
|
+
}, {
|
|
26
|
+
name: 'value',
|
|
27
|
+
type: 'string',
|
|
28
|
+
advanced: true
|
|
29
|
+
}, {
|
|
30
|
+
name: 'required',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
helperText: 'Is this input required to be filled out to submit a form',
|
|
33
|
+
defaultValue: false
|
|
34
|
+
}],
|
|
35
|
+
noWrap: true,
|
|
36
|
+
static: true,
|
|
37
|
+
defaultStyles: {
|
|
38
|
+
paddingTop: '10px',
|
|
39
|
+
paddingBottom: '10px',
|
|
40
|
+
paddingLeft: '10px',
|
|
41
|
+
paddingRight: '10px',
|
|
42
|
+
borderRadius: '3px',
|
|
43
|
+
borderWidth: '1px',
|
|
44
|
+
borderStyle: 'solid',
|
|
45
|
+
borderColor: '#ccc'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './input'
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
FlatList,
|
|
4
|
+
ScrollView,
|
|
5
|
+
View,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Image,
|
|
8
|
+
Text,
|
|
9
|
+
Pressable,
|
|
10
|
+
TextInput,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface FormInputProps {
|
|
18
|
+
type?: string;
|
|
19
|
+
attributes?: any;
|
|
20
|
+
name?: string;
|
|
21
|
+
value?: string;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
defaultValue?: string;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
import { isEditing } from "../../../functions/is-editing";
|
|
28
|
+
import { filterAttrs } from "../../helpers";
|
|
29
|
+
import { setAttrs } from "../../helpers";
|
|
30
|
+
|
|
31
|
+
function FormInputComponent(props: FormInputProps) {
|
|
32
|
+
return (
|
|
33
|
+
<TextInput
|
|
34
|
+
{...{}}
|
|
35
|
+
{...props.attributes}
|
|
36
|
+
key={
|
|
37
|
+
isEditing() && props.defaultValue ? props.defaultValue : "default-key"
|
|
38
|
+
}
|
|
39
|
+
placeholder={props.placeholder}
|
|
40
|
+
type={props.type}
|
|
41
|
+
name={props.name}
|
|
42
|
+
value={props.value}
|
|
43
|
+
defaultValue={props.defaultValue}
|
|
44
|
+
required={props.required}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default FormInputComponent;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../../types/components';
|
|
2
|
+
export const componentInfo: ComponentInfo = {
|
|
3
|
+
name: 'Form:Select',
|
|
4
|
+
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F83acca093fb24aaf94dee136e9a4b045',
|
|
5
|
+
defaultStyles: {
|
|
6
|
+
alignSelf: 'flex-start'
|
|
7
|
+
},
|
|
8
|
+
inputs: [{
|
|
9
|
+
name: 'options',
|
|
10
|
+
type: 'list',
|
|
11
|
+
required: true,
|
|
12
|
+
subFields: [{
|
|
13
|
+
name: 'value',
|
|
14
|
+
type: 'text',
|
|
15
|
+
required: true
|
|
16
|
+
}, {
|
|
17
|
+
name: 'name',
|
|
18
|
+
type: 'text'
|
|
19
|
+
}],
|
|
20
|
+
defaultValue: [{
|
|
21
|
+
value: 'option 1'
|
|
22
|
+
}, {
|
|
23
|
+
value: 'option 2'
|
|
24
|
+
}]
|
|
25
|
+
}, {
|
|
26
|
+
name: 'name',
|
|
27
|
+
type: 'string',
|
|
28
|
+
required: true,
|
|
29
|
+
helperText: 'Every select in a form needs a unique name describing what it gets, e.g. "email"'
|
|
30
|
+
}, {
|
|
31
|
+
name: 'defaultValue',
|
|
32
|
+
type: 'string'
|
|
33
|
+
}, {
|
|
34
|
+
name: 'value',
|
|
35
|
+
type: 'string',
|
|
36
|
+
advanced: true
|
|
37
|
+
}, {
|
|
38
|
+
name: 'required',
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
defaultValue: false
|
|
41
|
+
}],
|
|
42
|
+
static: true,
|
|
43
|
+
noWrap: true
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './select'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import BaseText from "../../blocks/BaseText";
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
ScrollView,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
Text,
|
|
10
|
+
Pressable,
|
|
11
|
+
TextInput,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface FormSelectProps {
|
|
19
|
+
options?: {
|
|
20
|
+
name?: string;
|
|
21
|
+
value: string;
|
|
22
|
+
}[];
|
|
23
|
+
attributes?: any;
|
|
24
|
+
name?: string;
|
|
25
|
+
value?: string;
|
|
26
|
+
defaultValue?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
import { isEditing } from "../../../functions/is-editing";
|
|
30
|
+
import { filterAttrs } from "../../helpers";
|
|
31
|
+
import { setAttrs } from "../../helpers";
|
|
32
|
+
|
|
33
|
+
function SelectComponent(props: FormSelectProps) {
|
|
34
|
+
return (
|
|
35
|
+
<View
|
|
36
|
+
{...{}}
|
|
37
|
+
{...props.attributes}
|
|
38
|
+
value={props.value}
|
|
39
|
+
key={
|
|
40
|
+
isEditing() && props.defaultValue ? props.defaultValue : "default-key"
|
|
41
|
+
}
|
|
42
|
+
defaultValue={props.defaultValue}
|
|
43
|
+
name={props.name}
|
|
44
|
+
>
|
|
45
|
+
{props.options?.map((option, index) => (
|
|
46
|
+
<View key={`${option.name}-${index}`} value={option.value}>
|
|
47
|
+
<BaseText>{option.name || option.value}</BaseText>
|
|
48
|
+
</View>
|
|
49
|
+
))}
|
|
50
|
+
</View>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default SelectComponent;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../../types/components';
|
|
2
|
+
export const componentInfo: ComponentInfo = {
|
|
3
|
+
name: 'Form:SubmitButton',
|
|
4
|
+
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98',
|
|
5
|
+
defaultStyles: {
|
|
6
|
+
appearance: 'none',
|
|
7
|
+
paddingTop: '15px',
|
|
8
|
+
paddingBottom: '15px',
|
|
9
|
+
paddingLeft: '25px',
|
|
10
|
+
paddingRight: '25px',
|
|
11
|
+
backgroundColor: '#3898EC',
|
|
12
|
+
color: 'white',
|
|
13
|
+
borderRadius: '4px',
|
|
14
|
+
cursor: 'pointer'
|
|
15
|
+
},
|
|
16
|
+
inputs: [{
|
|
17
|
+
name: 'text',
|
|
18
|
+
type: 'text',
|
|
19
|
+
defaultValue: 'Click me'
|
|
20
|
+
}],
|
|
21
|
+
static: true,
|
|
22
|
+
noWrap: true
|
|
23
|
+
// TODO: optional children? maybe as optional form input
|
|
24
|
+
// that only shows if advanced setting is flipped
|
|
25
|
+
// TODO: defaultChildren
|
|
26
|
+
// canHaveChildren: true,
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './submit-button'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import BaseText from "../../blocks/BaseText";
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
ScrollView,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
Text,
|
|
10
|
+
Pressable,
|
|
11
|
+
TextInput,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface ButtonProps {
|
|
19
|
+
attributes?: any;
|
|
20
|
+
text?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
import { filterAttrs } from "../../helpers";
|
|
24
|
+
import { setAttrs } from "../../helpers";
|
|
25
|
+
|
|
26
|
+
function SubmitButton(props: ButtonProps) {
|
|
27
|
+
return (
|
|
28
|
+
<View type="submit" {...{}} {...props.attributes}>
|
|
29
|
+
<BaseText>{props.text}</BaseText>
|
|
30
|
+
</View>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default SubmitButton;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
FlatList,
|
|
4
|
+
ScrollView,
|
|
5
|
+
View,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Image,
|
|
8
|
+
Text,
|
|
9
|
+
Pressable,
|
|
10
|
+
TextInput,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import type { FragmentProps } from "./fragment.types";
|
|
13
|
+
|
|
14
|
+
function FragmentComponent(props: FragmentProps) {
|
|
15
|
+
return <View>{props.children}</View>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default FragmentComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './fragment'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function filterAttrs(attrs: {
|
|
2
|
+
[index: string]: any;
|
|
3
|
+
} = {}, prefix: string, isEvent: boolean) {
|
|
4
|
+
const result: typeof attrs = {};
|
|
5
|
+
for (const attr in attrs) {
|
|
6
|
+
if (!attrs[attr]) continue;
|
|
7
|
+
if (isEvent && !attr.startsWith(prefix)) continue;
|
|
8
|
+
const eventName = isEvent ? attr.replace(prefix, '') : attr;
|
|
9
|
+
result[eventName] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Svelte SDK: workaround to dynamically provide event handlers to components/elements.
|
|
16
|
+
* https://svelte.dev/repl/1246699e266f41218a8eeb45b9b58b54?version=3.24.1
|
|
17
|
+
*/
|
|
18
|
+
export function setAttrs(node: HTMLElement, attrs: Record<string, (event: Event) => void> = {}) {
|
|
19
|
+
const attrKeys = Object.keys(attrs);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {string} attr
|
|
24
|
+
*/
|
|
25
|
+
const setup = (attr: string) => node.addEventListener(attr, attrs[attr]);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {string} attr
|
|
30
|
+
*/
|
|
31
|
+
const teardown = (attr: string) => node.removeEventListener(attr, attrs[attr]);
|
|
32
|
+
attrKeys.forEach(setup);
|
|
33
|
+
return {
|
|
34
|
+
update(attrs = {}) {
|
|
35
|
+
const attrKeys = Object.keys(attrs);
|
|
36
|
+
attrKeys.forEach(teardown);
|
|
37
|
+
attrKeys.forEach(setup);
|
|
38
|
+
},
|
|
39
|
+
destroy() {
|
|
40
|
+
attrKeys.forEach(teardown);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|