@builder.io/sdk-solid 0.0.5 → 0.0.8-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -2
- package/src/blocks/button/button.jsx +13 -0
- package/src/blocks/button/button.lite.tsx +20 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/button/index.js +7 -0
- package/src/blocks/columns/columns.jsx +91 -0
- package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +32 -26
- package/src/blocks/columns/component-info.js +217 -0
- package/src/blocks/columns/index.js +7 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/{custom-code.js → custom-code/custom-code.jsx} +5 -26
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +3 -1
- package/src/blocks/custom-code/index.js +7 -0
- package/src/blocks/embed/component-info.js +24 -0
- package/src/blocks/embed/embed.jsx +51 -0
- package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +3 -1
- package/src/blocks/embed/index.js +7 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/form/form.jsx +253 -0
- package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +14 -8
- package/src/blocks/form/index.js +7 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.jsx +5 -0
- package/src/blocks/fragment/fragment.lite.tsx +5 -0
- package/src/blocks/fragment/index.js +7 -0
- package/src/blocks/image/component-info.js +104 -0
- package/src/blocks/image/image.jsx +54 -0
- package/src/blocks/image/image.lite.tsx +83 -0
- package/src/blocks/image/index.js +7 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.jsx +10 -0
- package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +4 -2
- package/src/blocks/img/index.js +7 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/index.js +7 -0
- package/src/blocks/input/input.jsx +7 -0
- package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +4 -2
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/index.js +7 -0
- package/src/blocks/raw-text/raw-text.jsx +5 -0
- package/src/blocks/{raw-text.lite.tsx → raw-text/raw-text.lite.tsx} +3 -1
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/index.js +7 -0
- package/src/blocks/section/section.jsx +9 -0
- package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +3 -1
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/index.js +7 -0
- package/src/blocks/select/select.jsx +16 -0
- package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +10 -5
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/index.js +7 -0
- package/src/blocks/submit-button/submit-button.jsx +7 -0
- package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +3 -1
- package/src/blocks/symbol/component-info.js +42 -0
- package/src/blocks/symbol/index.js +7 -0
- package/src/blocks/symbol/symbol.jsx +24 -0
- package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +6 -4
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/index.js +7 -0
- package/src/blocks/{text.lite.tsx → text/text.jsx} +3 -1
- package/src/blocks/text/text.lite.tsx +5 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/index.js +7 -0
- package/src/blocks/textarea/textarea.jsx +5 -0
- package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +3 -1
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/index.js +7 -0
- package/src/blocks/video/video.jsx +14 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +3 -1
- package/src/components/error-boundary.jsx +5 -0
- package/src/components/error-boundary.lite.tsx +3 -1
- package/src/components/render-block/block-styles.jsx +36 -0
- package/src/components/render-block/block-styles.lite.tsx +38 -0
- package/src/components/render-block/render-block.jsx +117 -0
- package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +24 -13
- package/src/components/render-blocks.jsx +57 -0
- package/src/components/render-blocks.lite.tsx +9 -6
- package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +8 -15
- package/src/components/render-content/components/render-styles.lite.tsx +10 -4
- package/src/components/render-content/{render-content.js → render-content.jsx} +42 -94
- package/src/components/render-content/render-content.lite.tsx +23 -20
- package/src/components/render-inlined-styles.jsx +23 -0
- package/src/components/render-inlined-styles.lite.tsx +26 -0
- package/src/functions/evaluate.js +2 -2
- package/src/functions/get-block-actions.js +2 -2
- package/src/functions/get-builder-search-params/fn.test.js +1 -1
- package/src/functions/get-content/index.js +3 -2
- package/src/functions/get-fetch.js +29 -7
- package/src/functions/get-processed-block.js +3 -3
- package/src/functions/get-processed-block.test.js +1 -1
- package/src/functions/if-target.js +1 -1
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +2 -2
- package/src/functions/on-change.test.js +1 -1
- package/src/functions/previewing-model-name.js +1 -1
- package/src/functions/register-component.js +1 -1
- package/src/functions/register.js +1 -1
- package/src/functions/set-editor-settings.js +1 -1
- package/src/functions/set.test.js +1 -1
- package/src/functions/track.js +3 -3
- package/src/index-helpers/blocks-exports.js +8 -8
- package/src/index.js +10 -13
- package/src/scripts/init-editing.js +72 -63
- package/src/blocks/button.js +0 -32
- package/src/blocks/button.lite.tsx +0 -12
- package/src/blocks/columns.js +0 -133
- package/src/blocks/embed.js +0 -62
- package/src/blocks/form.js +0 -355
- package/src/blocks/fragment.js +0 -15
- package/src/blocks/fragment.lite.tsx +0 -3
- package/src/blocks/image.js +0 -211
- package/src/blocks/image.lite.tsx +0 -169
- package/src/blocks/img.js +0 -39
- package/src/blocks/input.js +0 -45
- package/src/blocks/raw-text.js +0 -25
- package/src/blocks/section.js +0 -24
- package/src/blocks/select.js +0 -57
- package/src/blocks/submit-button.js +0 -18
- package/src/blocks/symbol.js +0 -69
- package/src/blocks/text.js +0 -15
- package/src/blocks/textarea.js +0 -34
- package/src/blocks/video.js +0 -54
- package/src/components/block-styles.js +0 -3
- package/src/components/block-styles.lite.tsx +0 -3
- package/src/components/error-boundary.js +0 -3
- package/src/components/render-block.js +0 -154
- package/src/components/render-blocks.js +0 -104
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createMutable } from "solid-js/store";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function Embed(props) {
|
|
4
4
|
const state = createMutable({
|
|
5
5
|
scriptsInserted: [],
|
|
6
6
|
scriptsRun: [],
|
|
@@ -55,3 +55,5 @@ export default function Embed(props) {
|
|
|
55
55
|
|
|
56
56
|
return <div ref={elem} innerHTML={props.content}></div>;
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
export default Embed;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerComponent } from "../../functions/register-component.js";
|
|
2
|
+
import { componentInfo } from "./component-info.js";
|
|
3
|
+
import component from "./embed";
|
|
4
|
+
var stdin_default = registerComponent(component, componentInfo);
|
|
5
|
+
export {
|
|
6
|
+
stdin_default as default
|
|
7
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
const componentInfo = {
|
|
2
|
+
name: "Form:Form",
|
|
3
|
+
builtIn: true,
|
|
4
|
+
defaults: {
|
|
5
|
+
responsiveStyles: {
|
|
6
|
+
large: {
|
|
7
|
+
marginTop: "15px",
|
|
8
|
+
paddingBottom: "15px"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fef36d2a846134910b64b88e6d18c5ca5",
|
|
13
|
+
inputs: [
|
|
14
|
+
{
|
|
15
|
+
name: "sendSubmissionsTo",
|
|
16
|
+
type: "string",
|
|
17
|
+
enum: [
|
|
18
|
+
{
|
|
19
|
+
label: "Send to email",
|
|
20
|
+
value: "email",
|
|
21
|
+
helperText: "Send form submissions to the email address of your choosing"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: "Custom",
|
|
25
|
+
value: "custom",
|
|
26
|
+
helperText: "Handle where the form requests go manually with a little code, e.g. to your own custom backend"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
defaultValue: "email"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "sendSubmissionsToEmail",
|
|
33
|
+
type: "string",
|
|
34
|
+
required: true,
|
|
35
|
+
defaultValue: "your@email.com",
|
|
36
|
+
showIf: 'options.get("sendSubmissionsTo") === "email"'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "sendWithJs",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
helperText: "Set to false to use basic html form action",
|
|
42
|
+
defaultValue: true,
|
|
43
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "name",
|
|
47
|
+
type: "string",
|
|
48
|
+
defaultValue: "My form"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "action",
|
|
52
|
+
type: "string",
|
|
53
|
+
helperText: "URL to send the form data to",
|
|
54
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "contentType",
|
|
58
|
+
type: "string",
|
|
59
|
+
defaultValue: "application/json",
|
|
60
|
+
advanced: true,
|
|
61
|
+
enum: [
|
|
62
|
+
"application/json",
|
|
63
|
+
"multipart/form-data",
|
|
64
|
+
"application/x-www-form-urlencoded"
|
|
65
|
+
],
|
|
66
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "method",
|
|
70
|
+
type: "string",
|
|
71
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"',
|
|
72
|
+
defaultValue: "POST",
|
|
73
|
+
advanced: true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "previewState",
|
|
77
|
+
type: "string",
|
|
78
|
+
enum: ["unsubmitted", "sending", "success", "error"],
|
|
79
|
+
defaultValue: "unsubmitted",
|
|
80
|
+
helperText: 'Choose a state to edit, e.g. choose "success" to show what users see on success and edit the message',
|
|
81
|
+
showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "successUrl",
|
|
85
|
+
type: "url",
|
|
86
|
+
helperText: "Optional URL to redirect the user to on form submission success",
|
|
87
|
+
showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "resetFormOnSubmit",
|
|
91
|
+
type: "boolean",
|
|
92
|
+
showIf: "options.get('sendSubmissionsTo') === 'custom' && options.get('sendWithJs') === true",
|
|
93
|
+
advanced: true
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "successMessage",
|
|
97
|
+
type: "uiBlocks",
|
|
98
|
+
hideFromUI: true,
|
|
99
|
+
defaultValue: [
|
|
100
|
+
{
|
|
101
|
+
"@type": "@builder.io/sdk:Element",
|
|
102
|
+
responsiveStyles: {
|
|
103
|
+
large: {
|
|
104
|
+
marginTop: "10px"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
component: {
|
|
108
|
+
name: "Text",
|
|
109
|
+
options: {
|
|
110
|
+
text: "<span>Thanks!</span>"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "validate",
|
|
118
|
+
type: "boolean",
|
|
119
|
+
defaultValue: true,
|
|
120
|
+
advanced: true
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "errorMessagePath",
|
|
124
|
+
type: "text",
|
|
125
|
+
advanced: true,
|
|
126
|
+
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" }}'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "errorMessage",
|
|
130
|
+
type: "uiBlocks",
|
|
131
|
+
hideFromUI: true,
|
|
132
|
+
defaultValue: [
|
|
133
|
+
{
|
|
134
|
+
"@type": "@builder.io/sdk:Element",
|
|
135
|
+
responsiveStyles: {
|
|
136
|
+
large: {
|
|
137
|
+
marginTop: "10px"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
bindings: {
|
|
141
|
+
"component.options.text": "state.formErrorMessage || block.component.options.text"
|
|
142
|
+
},
|
|
143
|
+
component: {
|
|
144
|
+
name: "Text",
|
|
145
|
+
options: {
|
|
146
|
+
text: "<span>Form submission error :( Please check your answers and try again</span>"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "sendingMessage",
|
|
154
|
+
type: "uiBlocks",
|
|
155
|
+
hideFromUI: true,
|
|
156
|
+
defaultValue: [
|
|
157
|
+
{
|
|
158
|
+
"@type": "@builder.io/sdk:Element",
|
|
159
|
+
responsiveStyles: {
|
|
160
|
+
large: {
|
|
161
|
+
marginTop: "10px"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
component: {
|
|
165
|
+
name: "Text",
|
|
166
|
+
options: {
|
|
167
|
+
text: "<span>Sending...</span>"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "customHeaders",
|
|
175
|
+
type: "map",
|
|
176
|
+
valueType: {
|
|
177
|
+
type: "string"
|
|
178
|
+
},
|
|
179
|
+
advanced: true,
|
|
180
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
noWrap: true,
|
|
184
|
+
canHaveChildren: true,
|
|
185
|
+
defaultChildren: [
|
|
186
|
+
{
|
|
187
|
+
"@type": "@builder.io/sdk:Element",
|
|
188
|
+
responsiveStyles: {
|
|
189
|
+
large: {
|
|
190
|
+
marginTop: "10px"
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
component: {
|
|
194
|
+
name: "Text",
|
|
195
|
+
options: {
|
|
196
|
+
text: "<span>Enter your name</span>"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"@type": "@builder.io/sdk:Element",
|
|
202
|
+
responsiveStyles: {
|
|
203
|
+
large: {
|
|
204
|
+
marginTop: "10px"
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
component: {
|
|
208
|
+
name: "Form:Input",
|
|
209
|
+
options: {
|
|
210
|
+
name: "name",
|
|
211
|
+
placeholder: "Jane Doe"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"@type": "@builder.io/sdk:Element",
|
|
217
|
+
responsiveStyles: {
|
|
218
|
+
large: {
|
|
219
|
+
marginTop: "10px"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
component: {
|
|
223
|
+
name: "Text",
|
|
224
|
+
options: {
|
|
225
|
+
text: "<span>Enter your email</span>"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"@type": "@builder.io/sdk:Element",
|
|
231
|
+
responsiveStyles: {
|
|
232
|
+
large: {
|
|
233
|
+
marginTop: "10px"
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
component: {
|
|
237
|
+
name: "Form:Input",
|
|
238
|
+
options: {
|
|
239
|
+
name: "email",
|
|
240
|
+
placeholder: "jane@doe.com"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"@type": "@builder.io/sdk:Element",
|
|
246
|
+
responsiveStyles: {
|
|
247
|
+
large: {
|
|
248
|
+
marginTop: "10px"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
component: {
|
|
252
|
+
name: "Form:SubmitButton",
|
|
253
|
+
options: {
|
|
254
|
+
text: "Submit"
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
};
|
|
260
|
+
export {
|
|
261
|
+
componentInfo
|
|
262
|
+
};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { Show, For } from "solid-js";
|
|
2
|
+
import { createMutable } from "solid-js/store";
|
|
3
|
+
import { css } from "solid-styled-components";
|
|
4
|
+
import RenderBlock from "../../components/render-block/render-block";
|
|
5
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
6
|
+
|
|
7
|
+
function FormComponent(props) {
|
|
8
|
+
const state = createMutable({
|
|
9
|
+
formState: "unsubmitted",
|
|
10
|
+
responseData: null,
|
|
11
|
+
formErrorMessage: "",
|
|
12
|
+
|
|
13
|
+
get submissionState() {
|
|
14
|
+
return isEditing() && props.previewState || state.formState;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
onSubmit(event) {
|
|
18
|
+
const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === "email";
|
|
19
|
+
|
|
20
|
+
if (props.sendSubmissionsTo === "zapier") {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
} else if (sendWithJs) {
|
|
23
|
+
if (!(props.action || props.sendSubmissionsTo === "email")) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
const el = event.currentTarget;
|
|
30
|
+
const headers = props.customHeaders || {};
|
|
31
|
+
let body;
|
|
32
|
+
const formData = new FormData(el); // TODO: maybe support null
|
|
33
|
+
|
|
34
|
+
const formPairs = Array.from(event.currentTarget.querySelectorAll("input,select,textarea")).filter(el => !!el.name).map(el => {
|
|
35
|
+
let value;
|
|
36
|
+
const key = el.name;
|
|
37
|
+
|
|
38
|
+
if (el instanceof HTMLInputElement) {
|
|
39
|
+
if (el.type === "radio") {
|
|
40
|
+
if (el.checked) {
|
|
41
|
+
value = el.name;
|
|
42
|
+
return {
|
|
43
|
+
key,
|
|
44
|
+
value
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
} else if (el.type === "checkbox") {
|
|
48
|
+
value = el.checked;
|
|
49
|
+
} else if (el.type === "number" || el.type === "range") {
|
|
50
|
+
const num = el.valueAsNumber;
|
|
51
|
+
|
|
52
|
+
if (!isNaN(num)) {
|
|
53
|
+
value = num;
|
|
54
|
+
}
|
|
55
|
+
} else if (el.type === "file") {
|
|
56
|
+
// TODO: one vs multiple files
|
|
57
|
+
value = el.files;
|
|
58
|
+
} else {
|
|
59
|
+
value = el.value;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
value = el.value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
key,
|
|
67
|
+
value
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
let contentType = props.contentType;
|
|
71
|
+
|
|
72
|
+
if (props.sendSubmissionsTo === "email") {
|
|
73
|
+
contentType = "multipart/form-data";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Array.from(formPairs).forEach(({
|
|
77
|
+
value
|
|
78
|
+
}) => {
|
|
79
|
+
if (value instanceof File || Array.isArray(value) && value[0] instanceof File || value instanceof FileList) {
|
|
80
|
+
contentType = "multipart/form-data";
|
|
81
|
+
}
|
|
82
|
+
}); // TODO: send as urlEncoded or multipart by default
|
|
83
|
+
// because of ease of use and reliability in browser API
|
|
84
|
+
// for encoding the form?
|
|
85
|
+
|
|
86
|
+
if (contentType !== "application/json") {
|
|
87
|
+
body = formData;
|
|
88
|
+
} else {
|
|
89
|
+
// Json
|
|
90
|
+
const json = {};
|
|
91
|
+
Array.from(formPairs).forEach(({
|
|
92
|
+
value,
|
|
93
|
+
key
|
|
94
|
+
}) => {
|
|
95
|
+
set(json, key, value);
|
|
96
|
+
});
|
|
97
|
+
body = JSON.stringify(json);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (contentType && contentType !== "multipart/form-data") {
|
|
101
|
+
if (
|
|
102
|
+
/* Zapier doesn't allow content-type header to be sent from browsers */
|
|
103
|
+
!(sendWithJs && props.action?.includes("zapier.com"))) {
|
|
104
|
+
headers["content-type"] = contentType;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const presubmitEvent = new CustomEvent("presubmit", {
|
|
109
|
+
detail: {
|
|
110
|
+
body
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (formRef) {
|
|
115
|
+
formRef.dispatchEvent(presubmitEvent);
|
|
116
|
+
|
|
117
|
+
if (presubmitEvent.defaultPrevented) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
state.formState = "sending";
|
|
123
|
+
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 || "")}`;
|
|
124
|
+
fetch(props.sendSubmissionsTo === "email" ? formUrl : props.action,
|
|
125
|
+
/* TODO: throw error if no action URL */
|
|
126
|
+
{
|
|
127
|
+
body,
|
|
128
|
+
headers,
|
|
129
|
+
method: props.method || "post"
|
|
130
|
+
}).then(async res => {
|
|
131
|
+
let body;
|
|
132
|
+
const contentType = res.headers.get("content-type");
|
|
133
|
+
|
|
134
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
135
|
+
body = await res.json();
|
|
136
|
+
} else {
|
|
137
|
+
body = await res.text();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!res.ok && props.errorMessagePath) {
|
|
141
|
+
/* TODO: allow supplying an error formatter function */
|
|
142
|
+
let message = get(body, props.errorMessagePath);
|
|
143
|
+
|
|
144
|
+
if (message) {
|
|
145
|
+
if (typeof message !== "string") {
|
|
146
|
+
/* TODO: ideally convert json to yaml so it woul dbe like
|
|
147
|
+
error: - email has been taken */
|
|
148
|
+
message = JSON.stringify(message);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
state.formErrorMessage = message;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
state.responseData = body;
|
|
156
|
+
state.formState = res.ok ? "success" : "error";
|
|
157
|
+
|
|
158
|
+
if (res.ok) {
|
|
159
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
160
|
+
detail: {
|
|
161
|
+
res,
|
|
162
|
+
body
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (formRef) {
|
|
167
|
+
formRef.dispatchEvent(submitSuccessEvent);
|
|
168
|
+
|
|
169
|
+
if (submitSuccessEvent.defaultPrevented) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
/* TODO: option to turn this on/off? */
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
if (props.resetFormOnSubmit !== false) {
|
|
176
|
+
formRef.reset();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/* TODO: client side route event first that can be preventDefaulted */
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
if (props.successUrl) {
|
|
183
|
+
if (formRef) {
|
|
184
|
+
const event = new CustomEvent("route", {
|
|
185
|
+
detail: {
|
|
186
|
+
url: props.successUrl
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
formRef.dispatchEvent(event);
|
|
190
|
+
|
|
191
|
+
if (!event.defaultPrevented) {
|
|
192
|
+
location.href = props.successUrl;
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
location.href = props.successUrl;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, err => {
|
|
200
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
201
|
+
detail: {
|
|
202
|
+
error: err
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (formRef) {
|
|
207
|
+
formRef.dispatchEvent(submitErrorEvent);
|
|
208
|
+
|
|
209
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
state.responseData = err;
|
|
215
|
+
state.formState = "error";
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
});
|
|
221
|
+
const formRef = useRef();
|
|
222
|
+
return <form {...props.attributes} validate={props.validate} ref={formRef} action={!props.sendWithJs && props.action} method={props.method} name={props.name} onSubmit={event => state.onSubmit(event)}>
|
|
223
|
+
<Show when={props.builderBlock && props.builderBlock.children}>
|
|
224
|
+
<For each={props.builderBlock?.children}>
|
|
225
|
+
{(block, _index) => {
|
|
226
|
+
const index = _index();
|
|
227
|
+
|
|
228
|
+
return <RenderBlock block={block}></RenderBlock>;
|
|
229
|
+
}}
|
|
230
|
+
</For>
|
|
231
|
+
</Show>
|
|
232
|
+
<Show when={state.submissionState === "error"}>
|
|
233
|
+
<BuilderBlocks dataPath="errorMessage" blocks={props.errorMessage}></BuilderBlocks>
|
|
234
|
+
</Show>
|
|
235
|
+
<Show when={state.submissionState === "sending"}>
|
|
236
|
+
<BuilderBlocks dataPath="sendingMessage" blocks={props.sendingMessage}></BuilderBlocks>
|
|
237
|
+
</Show>
|
|
238
|
+
<Show when={state.submissionState === "error" && state.responseData}>
|
|
239
|
+
<pre class={css({
|
|
240
|
+
padding: "10px",
|
|
241
|
+
color: "red",
|
|
242
|
+
textAlign: "center"
|
|
243
|
+
})}>
|
|
244
|
+
{JSON.stringify(state.responseData, null, 2)}
|
|
245
|
+
</pre>
|
|
246
|
+
</Show>
|
|
247
|
+
<Show when={state.submissionState === "success"}>
|
|
248
|
+
<BuilderBlocks dataPath="successMessage" blocks={props.successMessage}></BuilderBlocks>
|
|
249
|
+
</Show>
|
|
250
|
+
</form>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export default FormComponent;
|
|
@@ -3,15 +3,16 @@ import { Show, For } from "solid-js";
|
|
|
3
3
|
import { createMutable } from "solid-js/store";
|
|
4
4
|
import { css } from "solid-styled-components";
|
|
5
5
|
|
|
6
|
-
import RenderBlock from "
|
|
6
|
+
import RenderBlock from "../../components/render-block/render-block.lite";
|
|
7
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
function FormComponent(props) {
|
|
9
10
|
const state = createMutable({
|
|
10
|
-
|
|
11
|
+
formState: "unsubmitted",
|
|
11
12
|
responseData: null,
|
|
12
13
|
formErrorMessage: "",
|
|
13
14
|
get submissionState() {
|
|
14
|
-
return (
|
|
15
|
+
return (isEditing() && props.previewState) || state.formState;
|
|
15
16
|
},
|
|
16
17
|
onSubmit(
|
|
17
18
|
event: Event & {
|
|
@@ -130,7 +131,7 @@ export default function FormComponent(props) {
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
state.
|
|
134
|
+
state.formState = "sending";
|
|
134
135
|
const formUrl = `${
|
|
135
136
|
builder.env === "dev" ? "http://localhost:5000" : "https://builder.io"
|
|
136
137
|
}/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(
|
|
@@ -171,7 +172,7 @@ export default function FormComponent(props) {
|
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
state.responseData = body;
|
|
174
|
-
state.
|
|
175
|
+
state.formState = res.ok ? "success" : "error";
|
|
175
176
|
|
|
176
177
|
if (res.ok) {
|
|
177
178
|
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
@@ -229,7 +230,7 @@ export default function FormComponent(props) {
|
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
state.responseData = err;
|
|
232
|
-
state.
|
|
233
|
+
state.formState = "error";
|
|
233
234
|
}
|
|
234
235
|
);
|
|
235
236
|
}
|
|
@@ -250,7 +251,10 @@ export default function FormComponent(props) {
|
|
|
250
251
|
>
|
|
251
252
|
<Show when={props.builderBlock && props.builderBlock.children}>
|
|
252
253
|
<For each={props.builderBlock?.children}>
|
|
253
|
-
{(block,
|
|
254
|
+
{(block, _index) => {
|
|
255
|
+
const index = _index();
|
|
256
|
+
return <RenderBlock block={block}></RenderBlock>;
|
|
257
|
+
}}
|
|
254
258
|
</For>
|
|
255
259
|
</Show>
|
|
256
260
|
<Show when={state.submissionState === "error"}>
|
|
@@ -285,3 +289,5 @@ export default function FormComponent(props) {
|
|
|
285
289
|
</form>
|
|
286
290
|
);
|
|
287
291
|
}
|
|
292
|
+
|
|
293
|
+
export default FormComponent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerComponent } from "../../functions/register-component.js";
|
|
2
|
+
import { componentInfo } from "./component-info.js";
|
|
3
|
+
import component from "./form";
|
|
4
|
+
var stdin_default = registerComponent(component, componentInfo);
|
|
5
|
+
export {
|
|
6
|
+
stdin_default as default
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerComponent } from "../../functions/register-component.js";
|
|
2
|
+
import { componentInfo } from "./component-info.js";
|
|
3
|
+
import component from "./fragment";
|
|
4
|
+
var stdin_default = registerComponent(component, componentInfo);
|
|
5
|
+
export {
|
|
6
|
+
stdin_default as default
|
|
7
|
+
};
|