@builder.io/sdk-svelte 0.13.0 → 0.13.2
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/blocks/form/form/component-info.d.ts +2 -0
- package/lib/browser/blocks/form/form/form.svelte +302 -0
- package/lib/browser/blocks/form/input/component-info.d.ts +2 -0
- package/lib/browser/blocks/{input → form/input}/input.svelte +3 -3
- package/lib/browser/blocks/form/select/component-info.d.ts +2 -0
- package/lib/{node/blocks → browser/blocks/form}/select/select.svelte +3 -3
- package/lib/browser/blocks/form/submit-button/component-info.d.ts +2 -0
- package/lib/{node/blocks → browser/blocks/form}/submit-button/submit-button.svelte +2 -2
- package/lib/browser/blocks/slot/slot.svelte +1 -0
- package/lib/browser/blocks/slot/slot.svelte.d.ts +4 -7
- package/lib/browser/components/block/block.svelte +4 -2
- package/lib/browser/constants/builder-registered-components.js +5 -24
- package/lib/browser/constants/extra-components.d.ts +7 -0
- package/lib/browser/constants/extra-components.js +47 -0
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/get-env.d.ts +2 -0
- package/lib/browser/functions/get-env.js +5 -0
- package/lib/browser/functions/get.d.ts +1 -0
- package/lib/browser/functions/get.js +4 -0
- package/lib/browser/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/lib/browser/helpers/preview-lru-cache/helpers.js +1 -1
- package/lib/browser/helpers/preview-lru-cache/types.d.ts +1 -0
- package/lib/browser/helpers/preview-lru-cache/types.js +1 -1
- package/lib/edge/blocks/form/form/component-info.d.ts +2 -0
- package/lib/edge/blocks/form/form/form.svelte +302 -0
- package/lib/edge/blocks/form/input/component-info.d.ts +2 -0
- package/lib/{node/blocks → edge/blocks/form}/input/input.svelte +3 -3
- package/lib/edge/blocks/form/select/component-info.d.ts +2 -0
- package/lib/{browser/blocks → edge/blocks/form}/select/select.svelte +3 -3
- package/lib/edge/blocks/form/submit-button/component-info.d.ts +2 -0
- package/lib/edge/blocks/{submit-button → form/submit-button}/submit-button.svelte +2 -2
- package/lib/edge/blocks/slot/slot.svelte +1 -0
- package/lib/edge/blocks/slot/slot.svelte.d.ts +4 -7
- package/lib/edge/components/block/block.svelte +4 -2
- package/lib/edge/constants/builder-registered-components.js +5 -24
- package/lib/edge/constants/extra-components.d.ts +7 -0
- package/lib/edge/constants/extra-components.js +47 -0
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/get-env.d.ts +2 -0
- package/lib/edge/functions/get-env.js +5 -0
- package/lib/edge/functions/get.d.ts +1 -0
- package/lib/edge/functions/get.js +4 -0
- package/lib/edge/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/lib/edge/helpers/preview-lru-cache/helpers.js +1 -1
- package/lib/edge/helpers/preview-lru-cache/types.d.ts +1 -0
- package/lib/edge/helpers/preview-lru-cache/types.js +1 -1
- package/lib/node/blocks/form/form/component-info.d.ts +2 -0
- package/lib/node/blocks/form/form/form.svelte +302 -0
- package/lib/node/blocks/form/input/component-info.d.ts +2 -0
- package/lib/{edge/blocks → node/blocks/form}/input/input.svelte +3 -3
- package/lib/node/blocks/form/select/component-info.d.ts +2 -0
- package/lib/{edge/blocks → node/blocks/form}/select/select.svelte +3 -3
- package/lib/node/blocks/form/submit-button/component-info.d.ts +2 -0
- package/lib/{browser/blocks → node/blocks/form}/submit-button/submit-button.svelte +2 -2
- package/lib/node/blocks/slot/slot.svelte +1 -0
- package/lib/node/blocks/slot/slot.svelte.d.ts +4 -7
- package/lib/node/components/block/block.svelte +4 -2
- package/lib/node/constants/builder-registered-components.js +5 -24
- package/lib/node/constants/extra-components.d.ts +7 -0
- package/lib/node/constants/extra-components.js +47 -0
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/get-env.d.ts +2 -0
- package/lib/node/functions/get-env.js +5 -0
- package/lib/node/functions/get.d.ts +1 -0
- package/lib/node/functions/get.js +4 -0
- package/lib/node/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/lib/node/helpers/preview-lru-cache/helpers.js +1 -1
- package/lib/node/helpers/preview-lru-cache/types.d.ts +1 -0
- package/lib/node/helpers/preview-lru-cache/types.js +1 -1
- package/package.json +1 -1
- package/src/blocks/form/{component-info.ts → form/component-info.ts} +1 -1
- package/src/blocks/form/form/form.svelte +359 -0
- package/src/blocks/{input → form/input}/component-info.ts +1 -1
- package/src/blocks/{input → form/input}/input.svelte +3 -3
- package/src/blocks/{select → form/select}/component-info.ts +1 -1
- package/src/blocks/{select → form/select}/select.svelte +3 -3
- package/src/blocks/{submit-button → form/submit-button}/component-info.ts +1 -1
- package/src/blocks/{submit-button → form/submit-button}/submit-button.svelte +2 -2
- package/src/blocks/slot/slot.svelte +4 -6
- package/src/components/block/block.svelte +4 -2
- package/src/constants/builder-registered-components.ts +5 -24
- package/src/constants/extra-components.ts +49 -0
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/get-env.ts +5 -0
- package/src/functions/get.ts +4 -0
- package/src/helpers/preview-lru-cache/helpers.ts +1 -0
- package/src/helpers/preview-lru-cache/types.ts +1 -0
- package/lib/browser/blocks/form/component-info.d.ts +0 -2
- package/lib/browser/blocks/form/form.svelte +0 -2
- package/lib/browser/blocks/form/form.svelte.d.ts +0 -14
- package/lib/browser/blocks/input/component-info.d.ts +0 -2
- package/lib/browser/blocks/select/component-info.d.ts +0 -2
- package/lib/browser/blocks/submit-button/component-info.d.ts +0 -2
- package/lib/edge/blocks/form/component-info.d.ts +0 -2
- package/lib/edge/blocks/form/form.svelte +0 -2
- package/lib/edge/blocks/form/form.svelte.d.ts +0 -14
- package/lib/edge/blocks/input/component-info.d.ts +0 -2
- package/lib/edge/blocks/select/component-info.d.ts +0 -2
- package/lib/edge/blocks/submit-button/component-info.d.ts +0 -2
- package/lib/node/blocks/form/component-info.d.ts +0 -2
- package/lib/node/blocks/form/form.svelte +0 -2
- package/lib/node/blocks/form/form.svelte.d.ts +0 -14
- package/lib/node/blocks/input/component-info.d.ts +0 -2
- package/lib/node/blocks/select/component-info.d.ts +0 -2
- package/lib/node/blocks/submit-button/component-info.d.ts +0 -2
- package/src/blocks/form/form.svelte +0 -2
- /package/lib/browser/blocks/form/{component-info.js → form/component-info.js} +0 -0
- /package/lib/browser/blocks/{input → form/input}/component-info.js +0 -0
- /package/lib/browser/blocks/{select → form/select}/component-info.js +0 -0
- /package/lib/browser/blocks/{submit-button → form/submit-button}/component-info.js +0 -0
- /package/lib/browser/blocks/{submit-button → form/submit-button}/submit-button.svelte.d.ts +0 -0
- /package/lib/edge/blocks/form/{component-info.js → form/component-info.js} +0 -0
- /package/lib/edge/blocks/{input → form/input}/component-info.js +0 -0
- /package/lib/edge/blocks/{select → form/select}/component-info.js +0 -0
- /package/lib/edge/blocks/{submit-button → form/submit-button}/component-info.js +0 -0
- /package/lib/edge/blocks/{submit-button → form/submit-button}/submit-button.svelte.d.ts +0 -0
- /package/lib/node/blocks/form/{component-info.js → form/component-info.js} +0 -0
- /package/lib/node/blocks/{input → form/input}/component-info.js +0 -0
- /package/lib/node/blocks/{select → form/select}/component-info.js +0 -0
- /package/lib/node/blocks/{submit-button → form/submit-button}/component-info.js +0 -0
- /package/lib/node/blocks/{submit-button → form/submit-button}/submit-button.svelte.d.ts +0 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type FormProps = PropsWithBuilderData<
|
|
7
|
+
BuilderComponentsProp &
|
|
8
|
+
BuilderLinkComponentProp & {
|
|
9
|
+
attributes?: any;
|
|
10
|
+
name?: string;
|
|
11
|
+
action?: string;
|
|
12
|
+
validate?: boolean;
|
|
13
|
+
method?: string;
|
|
14
|
+
sendSubmissionsTo?: string;
|
|
15
|
+
sendSubmissionsToEmail?: string;
|
|
16
|
+
sendWithJs?: boolean;
|
|
17
|
+
contentType?: string;
|
|
18
|
+
customHeaders?: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
successUrl?: string;
|
|
22
|
+
previewState?: FormState;
|
|
23
|
+
successMessage?: BuilderBlock[];
|
|
24
|
+
errorMessage?: BuilderBlock[];
|
|
25
|
+
sendingMessage?: BuilderBlock[];
|
|
26
|
+
resetFormOnSubmit?: boolean;
|
|
27
|
+
errorMessagePath?: string;
|
|
28
|
+
}
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export type FormState = "unsubmitted" | "sending" | "success" | "error";
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<script lang="ts">
|
|
39
|
+
import Block from "../../../components/block/block.svelte";
|
|
40
|
+
import Blocks from "../../../components/blocks/blocks.svelte";
|
|
41
|
+
import { getEnv } from "../../../functions/get-env.js";
|
|
42
|
+
import { get } from "../../../functions/get.js";
|
|
43
|
+
import { isEditing } from "../../../functions/is-editing.js";
|
|
44
|
+
import { set } from "../../../functions/set.js";
|
|
45
|
+
import type { BuilderBlock } from "../../../types/builder-block.js";
|
|
46
|
+
import type {
|
|
47
|
+
BuilderComponentsProp,
|
|
48
|
+
BuilderLinkComponentProp,
|
|
49
|
+
PropsWithBuilderData,
|
|
50
|
+
} from "../../../types/builder-props.js";
|
|
51
|
+
import type { Dictionary } from "../../../types/typescript.js";
|
|
52
|
+
import { filterAttrs } from "../../helpers.js";
|
|
53
|
+
import { setAttrs } from "../../helpers.js";
|
|
54
|
+
|
|
55
|
+
export let js: FormProps["js"];
|
|
56
|
+
export let builderContext: FormProps["builderContext"];
|
|
57
|
+
export let previewState: FormProps["previewState"] = undefined;
|
|
58
|
+
export let sendWithJs: FormProps["sendWithJs"] = undefined;
|
|
59
|
+
export let sendSubmissionsTo: FormProps["sendSubmissionsTo"] = undefined;
|
|
60
|
+
export let action: FormProps["action"] = undefined;
|
|
61
|
+
export let customHeaders: FormProps["customHeaders"] = undefined;
|
|
62
|
+
export let contentType: FormProps["contentType"] = undefined;
|
|
63
|
+
export let sendSubmissionsToEmail: FormProps["sendSubmissionsToEmail"] =
|
|
64
|
+
undefined;
|
|
65
|
+
export let name: FormProps["name"] = undefined;
|
|
66
|
+
export let method: FormProps["method"] = undefined;
|
|
67
|
+
export let errorMessagePath: FormProps["errorMessagePath"] = undefined;
|
|
68
|
+
export let resetFormOnSubmit: FormProps["resetFormOnSubmit"] = undefined;
|
|
69
|
+
export let successUrl: FormProps["successUrl"] = undefined;
|
|
70
|
+
export let validate: FormProps["validate"] = undefined;
|
|
71
|
+
export let attributes: FormProps["attributes"] = undefined;
|
|
72
|
+
export let builderBlock: FormProps["builderBlock"];
|
|
73
|
+
export let builderComponents: FormProps["builderComponents"];
|
|
74
|
+
export let builderLinkComponent: FormProps["builderLinkComponent"] =
|
|
75
|
+
undefined;
|
|
76
|
+
export let errorMessage: FormProps["errorMessage"] = undefined;
|
|
77
|
+
export let sendingMessage: FormProps["sendingMessage"] = undefined;
|
|
78
|
+
export let successMessage: FormProps["successMessage"] = undefined;
|
|
79
|
+
|
|
80
|
+
function mergeNewRootState(newData: Dictionary<any>) {
|
|
81
|
+
const combinedState = {
|
|
82
|
+
...$builderContext.rootState,
|
|
83
|
+
...newData,
|
|
84
|
+
};
|
|
85
|
+
if ($builderContext.rootSetState) {
|
|
86
|
+
$builderContext.rootSetState?.(combinedState);
|
|
87
|
+
} else {
|
|
88
|
+
$builderContext.rootState = combinedState;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function submissionState() {
|
|
92
|
+
return (isEditing() && previewState) || formState;
|
|
93
|
+
}
|
|
94
|
+
function onSubmit(event: any) {
|
|
95
|
+
const sendWithJsProp = sendWithJs || sendSubmissionsTo === "email";
|
|
96
|
+
if (sendSubmissionsTo === "zapier") {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
} else if (sendWithJsProp) {
|
|
99
|
+
if (!(action || sendSubmissionsTo === "email")) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
const el = event.currentTarget;
|
|
105
|
+
const headers = customHeaders || {};
|
|
106
|
+
let body: any;
|
|
107
|
+
const formData = new FormData(el);
|
|
108
|
+
|
|
109
|
+
// TODO: maybe support null
|
|
110
|
+
const formPairs: {
|
|
111
|
+
key: string;
|
|
112
|
+
value: File | boolean | number | string | FileList;
|
|
113
|
+
}[] = Array.from(
|
|
114
|
+
event.currentTarget.querySelectorAll("input,select,textarea")
|
|
115
|
+
)
|
|
116
|
+
.filter((el) => !!(el as HTMLInputElement).name)
|
|
117
|
+
.map((el) => {
|
|
118
|
+
let value: any;
|
|
119
|
+
const key = (el as HTMLImageElement).name;
|
|
120
|
+
if (el instanceof HTMLInputElement) {
|
|
121
|
+
if (el.type === "radio") {
|
|
122
|
+
if (el.checked) {
|
|
123
|
+
value = el.name;
|
|
124
|
+
return {
|
|
125
|
+
key,
|
|
126
|
+
value,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
} else if (el.type === "checkbox") {
|
|
130
|
+
value = el.checked;
|
|
131
|
+
} else if (el.type === "number" || el.type === "range") {
|
|
132
|
+
const num = el.valueAsNumber;
|
|
133
|
+
if (!isNaN(num)) {
|
|
134
|
+
value = num;
|
|
135
|
+
}
|
|
136
|
+
} else if (el.type === "file") {
|
|
137
|
+
// TODO: one vs multiple files
|
|
138
|
+
value = el.files;
|
|
139
|
+
} else {
|
|
140
|
+
value = el.value;
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
value = (el as HTMLInputElement).value;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
key,
|
|
147
|
+
value,
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
let formContentType = contentType;
|
|
151
|
+
if (sendSubmissionsTo === "email") {
|
|
152
|
+
formContentType = "multipart/form-data";
|
|
153
|
+
}
|
|
154
|
+
Array.from(formPairs).forEach(({ value }) => {
|
|
155
|
+
if (
|
|
156
|
+
value instanceof File ||
|
|
157
|
+
(Array.isArray(value) && value[0] instanceof File) ||
|
|
158
|
+
value instanceof FileList
|
|
159
|
+
) {
|
|
160
|
+
formContentType = "multipart/form-data";
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// TODO: send as urlEncoded or multipart by default
|
|
165
|
+
// because of ease of use and reliability in browser API
|
|
166
|
+
// for encoding the form?
|
|
167
|
+
if (formContentType !== "application/json") {
|
|
168
|
+
body = formData;
|
|
169
|
+
} else {
|
|
170
|
+
// Json
|
|
171
|
+
const json = {};
|
|
172
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
173
|
+
set(json, key, value);
|
|
174
|
+
});
|
|
175
|
+
body = JSON.stringify(json);
|
|
176
|
+
}
|
|
177
|
+
if (formContentType && formContentType !== "multipart/form-data") {
|
|
178
|
+
if (
|
|
179
|
+
/* Zapier doesn't allow content-type header to be sent from browsers */
|
|
180
|
+
!(sendWithJsProp && action?.includes("zapier.com"))
|
|
181
|
+
) {
|
|
182
|
+
headers["content-type"] = formContentType;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const presubmitEvent = new CustomEvent("presubmit", {
|
|
186
|
+
detail: {
|
|
187
|
+
body,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
if (formRef) {
|
|
191
|
+
formRef.dispatchEvent(presubmitEvent);
|
|
192
|
+
if (presubmitEvent.defaultPrevented) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
formState = "sending";
|
|
197
|
+
const formUrl = `${
|
|
198
|
+
getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"
|
|
199
|
+
}/api/v1/form-submit?apiKey=${$builderContext.apiKey}&to=${btoa(
|
|
200
|
+
sendSubmissionsToEmail || ""
|
|
201
|
+
)}&name=${encodeURIComponent(name || "")}`;
|
|
202
|
+
fetch(
|
|
203
|
+
sendSubmissionsTo === "email"
|
|
204
|
+
? formUrl
|
|
205
|
+
: action! /* TODO: throw error if no action URL */,
|
|
206
|
+
{
|
|
207
|
+
body,
|
|
208
|
+
headers,
|
|
209
|
+
method: method || "post",
|
|
210
|
+
}
|
|
211
|
+
).then(
|
|
212
|
+
async (res) => {
|
|
213
|
+
let body;
|
|
214
|
+
const contentType = res.headers.get("content-type");
|
|
215
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
216
|
+
body = await res.json();
|
|
217
|
+
} else {
|
|
218
|
+
body = await res.text();
|
|
219
|
+
}
|
|
220
|
+
if (!res.ok && errorMessagePath) {
|
|
221
|
+
/* TODO: allow supplying an error formatter function */
|
|
222
|
+
let message = get(body, errorMessagePath);
|
|
223
|
+
if (message) {
|
|
224
|
+
if (typeof message !== "string") {
|
|
225
|
+
/* TODO: ideally convert json to yaml so it woul dbe like
|
|
226
|
+
error: - email has been taken */
|
|
227
|
+
message = JSON.stringify(message);
|
|
228
|
+
}
|
|
229
|
+
formErrorMessage = message;
|
|
230
|
+
mergeNewRootState({
|
|
231
|
+
formErrorMessage: message,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
responseData = body;
|
|
236
|
+
formState = res.ok ? "success" : "error";
|
|
237
|
+
if (res.ok) {
|
|
238
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
239
|
+
detail: {
|
|
240
|
+
res,
|
|
241
|
+
body,
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
if (formRef) {
|
|
245
|
+
formRef.dispatchEvent(submitSuccessEvent);
|
|
246
|
+
if (submitSuccessEvent.defaultPrevented) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
/* TODO: option to turn this on/off? */
|
|
250
|
+
if (resetFormOnSubmit !== false) {
|
|
251
|
+
formRef.reset();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* TODO: client side route event first that can be preventDefaulted */
|
|
256
|
+
if (successUrl) {
|
|
257
|
+
if (formRef) {
|
|
258
|
+
const event = new CustomEvent("route", {
|
|
259
|
+
detail: {
|
|
260
|
+
url: successUrl,
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
formRef.dispatchEvent(event);
|
|
264
|
+
if (!event.defaultPrevented) {
|
|
265
|
+
location.href = successUrl;
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
location.href = successUrl;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
(err) => {
|
|
274
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
275
|
+
detail: {
|
|
276
|
+
error: err,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
if (formRef) {
|
|
280
|
+
formRef.dispatchEvent(submitErrorEvent);
|
|
281
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
responseData = err;
|
|
286
|
+
formState = "error";
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let formRef;
|
|
293
|
+
|
|
294
|
+
let formState = "unsubmitted";
|
|
295
|
+
let responseData = null;
|
|
296
|
+
let formErrorMessage = "";
|
|
297
|
+
</script>
|
|
298
|
+
|
|
299
|
+
<form
|
|
300
|
+
{validate}
|
|
301
|
+
bind:this={formRef}
|
|
302
|
+
action={!sendWithJs && action}
|
|
303
|
+
{method}
|
|
304
|
+
{name}
|
|
305
|
+
on:submit={(event) => {
|
|
306
|
+
onSubmit(event);
|
|
307
|
+
}}
|
|
308
|
+
{...filterAttrs(attributes, "on:", false)}
|
|
309
|
+
use:setAttrs={filterAttrs(attributes, "on:", true)}
|
|
310
|
+
>
|
|
311
|
+
{#if builderBlock && builderBlock.children}
|
|
312
|
+
{#each builderBlock?.children as block, idx (`form-block-${idx}`)}
|
|
313
|
+
<Block
|
|
314
|
+
{block}
|
|
315
|
+
context={builderContext}
|
|
316
|
+
registeredComponents={builderComponents}
|
|
317
|
+
linkComponent={builderLinkComponent}
|
|
318
|
+
/>
|
|
319
|
+
{/each}
|
|
320
|
+
{/if}
|
|
321
|
+
|
|
322
|
+
{#if submissionState() === "error"}
|
|
323
|
+
<Blocks
|
|
324
|
+
path="errorMessage"
|
|
325
|
+
blocks={errorMessage}
|
|
326
|
+
context={builderContext}
|
|
327
|
+
/>
|
|
328
|
+
{/if}
|
|
329
|
+
|
|
330
|
+
{#if submissionState() === "sending"}
|
|
331
|
+
<Blocks
|
|
332
|
+
path="sendingMessage"
|
|
333
|
+
blocks={sendingMessage}
|
|
334
|
+
context={builderContext}
|
|
335
|
+
/>
|
|
336
|
+
{/if}
|
|
337
|
+
|
|
338
|
+
{#if submissionState() === "error" && responseData}
|
|
339
|
+
<pre class="builder-form-error-text pre">
|
|
340
|
+
{JSON.stringify(responseData, null, 2)}
|
|
341
|
+
</pre>
|
|
342
|
+
{/if}
|
|
343
|
+
|
|
344
|
+
{#if submissionState() === "success"}
|
|
345
|
+
<Blocks
|
|
346
|
+
path="successMessage"
|
|
347
|
+
blocks={successMessage}
|
|
348
|
+
context={builderContext}
|
|
349
|
+
/>
|
|
350
|
+
{/if}
|
|
351
|
+
</form>
|
|
352
|
+
|
|
353
|
+
<style>
|
|
354
|
+
.pre {
|
|
355
|
+
padding: 10px;
|
|
356
|
+
color: red;
|
|
357
|
+
text-align: center;
|
|
358
|
+
}
|
|
359
|
+
</style>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentInfo } from '
|
|
1
|
+
import type { ComponentInfo } from '../../../types/components.js';
|
|
2
2
|
export const componentInfo: ComponentInfo = {
|
|
3
3
|
name: 'Form:Input',
|
|
4
4
|
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca',
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
|
-
import { isEditing } from "
|
|
19
|
-
import { filterAttrs } from "
|
|
20
|
-
import { setAttrs } from "
|
|
18
|
+
import { isEditing } from "../../../functions/is-editing.js";
|
|
19
|
+
import { filterAttrs } from "../../helpers.js";
|
|
20
|
+
import { setAttrs } from "../../helpers.js";
|
|
21
21
|
|
|
22
22
|
export let attributes: FormInputProps["attributes"] = undefined;
|
|
23
23
|
export let defaultValue: FormInputProps["defaultValue"] = undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentInfo } from '
|
|
1
|
+
import type { ComponentInfo } from '../../../types/components.js';
|
|
2
2
|
export const componentInfo: ComponentInfo = {
|
|
3
3
|
name: 'Form:Select',
|
|
4
4
|
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F83acca093fb24aaf94dee136e9a4b045',
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<script lang="ts">
|
|
19
|
-
import { isEditing } from "
|
|
20
|
-
import { filterAttrs } from "
|
|
21
|
-
import { setAttrs } from "
|
|
19
|
+
import { isEditing } from "../../../functions/is-editing.js";
|
|
20
|
+
import { filterAttrs } from "../../helpers.js";
|
|
21
|
+
import { setAttrs } from "../../helpers.js";
|
|
22
22
|
|
|
23
23
|
export let attributes: FormSelectProps["attributes"] = undefined;
|
|
24
24
|
export let value: FormSelectProps["value"] = undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentInfo } from '
|
|
1
|
+
import type { ComponentInfo } from '../../../types/components.js';
|
|
2
2
|
export const componentInfo: ComponentInfo = {
|
|
3
3
|
name: 'Form:SubmitButton',
|
|
4
4
|
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98',
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<script lang="ts">
|
|
13
|
-
import { filterAttrs } from "
|
|
14
|
-
import { setAttrs } from "
|
|
13
|
+
import { filterAttrs } from "../../helpers.js";
|
|
14
|
+
import { setAttrs } from "../../helpers.js";
|
|
15
15
|
|
|
16
16
|
export let attributes: ButtonProps["attributes"] = undefined;
|
|
17
17
|
export let text: ButtonProps["text"] = undefined;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
|
-
export
|
|
2
|
+
export type DropzoneProps = PropsWithBuilderData<{
|
|
3
3
|
name: string;
|
|
4
|
-
builderBlock: BuilderBlock;
|
|
5
|
-
builderContext: Writable<BuilderContextInterface>;
|
|
6
4
|
attributes: any;
|
|
7
|
-
}
|
|
5
|
+
}>;
|
|
8
6
|
</script>
|
|
9
7
|
|
|
10
8
|
<script lang="ts">
|
|
11
9
|
import Blocks from "../../components/blocks/blocks.svelte";
|
|
12
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
13
10
|
import { deoptSignal } from "../../functions/deopt.js";
|
|
14
11
|
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
|
-
import type {
|
|
12
|
+
import type { PropsWithBuilderData } from "../../types/builder-props.js";
|
|
16
13
|
|
|
14
|
+
export let js: DropzoneProps["js"];
|
|
17
15
|
export let builderContext: DropzoneProps["builderContext"];
|
|
18
16
|
export let name: DropzoneProps["name"];
|
|
19
17
|
|
|
@@ -102,13 +102,15 @@
|
|
|
102
102
|
builderContext: context,
|
|
103
103
|
...(blockComponent?.()?.name === "Core:Button" ||
|
|
104
104
|
blockComponent?.()?.name === "Symbol" ||
|
|
105
|
-
blockComponent?.()?.name === "Columns"
|
|
105
|
+
blockComponent?.()?.name === "Columns" ||
|
|
106
|
+
blockComponent?.()?.name === "Form:Form"
|
|
106
107
|
? {
|
|
107
108
|
builderLinkComponent: linkComponent,
|
|
108
109
|
}
|
|
109
110
|
: {}),
|
|
110
111
|
...(blockComponent?.()?.name === "Symbol" ||
|
|
111
|
-
blockComponent?.()?.name === "Columns"
|
|
112
|
+
blockComponent?.()?.name === "Columns" ||
|
|
113
|
+
blockComponent?.()?.name === "Form:Form"
|
|
112
114
|
? {
|
|
113
115
|
builderComponents: registeredComponents,
|
|
114
116
|
}
|
|
@@ -2,16 +2,10 @@ import { default as Button } from '../blocks/button/button.svelte';
|
|
|
2
2
|
import { componentInfo as buttonComponentInfo } from '../blocks/button/component-info.js';
|
|
3
3
|
import { default as Columns } from '../blocks/columns/columns.svelte';
|
|
4
4
|
import { componentInfo as columnsComponentInfo } from '../blocks/columns/component-info.js';
|
|
5
|
-
import { componentInfo as customCodeInfo } from '../blocks/custom-code/component-info.js';
|
|
6
|
-
import { default as customCode } from '../blocks/custom-code/custom-code.svelte';
|
|
7
|
-
import { componentInfo as embedComponentInfo } from '../blocks/embed/component-info.js';
|
|
8
|
-
import { default as embed } from '../blocks/embed/embed.svelte';
|
|
9
5
|
import { componentInfo as fragmentComponentInfo } from '../blocks/fragment/component-info.js';
|
|
10
6
|
import { default as Fragment } from '../blocks/fragment/fragment.svelte';
|
|
11
7
|
import { componentInfo as imageComponentInfo } from '../blocks/image/component-info.js';
|
|
12
8
|
import { default as Image } from '../blocks/image/image.svelte';
|
|
13
|
-
import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.js';
|
|
14
|
-
import { default as Img } from '../blocks/img/img.svelte';
|
|
15
9
|
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info.js';
|
|
16
10
|
import { default as Section } from '../blocks/section/section.svelte';
|
|
17
11
|
import { componentInfo as slotComponentInfo } from '../blocks/slot/component-info.js';
|
|
@@ -20,9 +14,8 @@ import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component
|
|
|
20
14
|
import { default as Symbol } from '../blocks/symbol/symbol.svelte';
|
|
21
15
|
import { componentInfo as textComponentInfo } from '../blocks/text/component-info.js';
|
|
22
16
|
import { default as Text } from '../blocks/text/text.svelte';
|
|
23
|
-
import { componentInfo as videoComponentInfo } from '../blocks/video/component-info.js';
|
|
24
|
-
import { default as Video } from '../blocks/video/video.svelte';
|
|
25
17
|
import type { RegisteredComponent } from '../context/types.js';
|
|
18
|
+
import { getExtraComponents } from './extra-components.js';
|
|
26
19
|
|
|
27
20
|
/**
|
|
28
21
|
* Returns a list of all registered components.
|
|
@@ -34,34 +27,22 @@ export const getDefaultRegisteredComponents: () => RegisteredComponent[] = () =>
|
|
|
34
27
|
}, {
|
|
35
28
|
component: Columns,
|
|
36
29
|
...columnsComponentInfo
|
|
37
|
-
}, {
|
|
38
|
-
component: customCode,
|
|
39
|
-
...customCodeInfo
|
|
40
|
-
}, {
|
|
41
|
-
component: embed,
|
|
42
|
-
...embedComponentInfo
|
|
43
30
|
}, {
|
|
44
31
|
component: Fragment,
|
|
45
32
|
...fragmentComponentInfo
|
|
46
33
|
}, {
|
|
47
34
|
component: Image,
|
|
48
35
|
...imageComponentInfo
|
|
49
|
-
}, {
|
|
50
|
-
component: Img,
|
|
51
|
-
...imgComponentInfo
|
|
52
36
|
}, {
|
|
53
37
|
component: Section,
|
|
54
38
|
...sectionComponentInfo
|
|
39
|
+
}, {
|
|
40
|
+
component: Slot,
|
|
41
|
+
...slotComponentInfo
|
|
55
42
|
}, {
|
|
56
43
|
component: Symbol,
|
|
57
44
|
...symbolComponentInfo
|
|
58
45
|
}, {
|
|
59
46
|
component: Text,
|
|
60
47
|
...textComponentInfo
|
|
61
|
-
},
|
|
62
|
-
component: Video,
|
|
63
|
-
...videoComponentInfo
|
|
64
|
-
}, {
|
|
65
|
-
component: Slot,
|
|
66
|
-
...slotComponentInfo
|
|
67
|
-
}]
|
|
48
|
+
}, ...getExtraComponents()]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These are in a separate file because React Native does not support them (yet).
|
|
3
|
+
* Having them in a separate file allows us to override it to be empty in the
|
|
4
|
+
* React Native SDK.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { componentInfo as customCodeInfo } from '../blocks/custom-code/component-info.js';
|
|
8
|
+
import { default as customCode } from '../blocks/custom-code/custom-code.svelte';
|
|
9
|
+
import { componentInfo as embedComponentInfo } from '../blocks/embed/component-info.js';
|
|
10
|
+
import { default as embed } from '../blocks/embed/embed.svelte';
|
|
11
|
+
import { componentInfo as formComponentInfo } from '../blocks/form/form/component-info.js';
|
|
12
|
+
import { default as Form } from '../blocks/form/form/form.svelte';
|
|
13
|
+
import { componentInfo as formInputComponentInfo } from '../blocks/form/input/component-info.js';
|
|
14
|
+
import { default as FormInput } from '../blocks/form/input/input.svelte';
|
|
15
|
+
import { componentInfo as formSelectComponentInfo } from '../blocks/form/select/component-info.js';
|
|
16
|
+
import { default as FormSelect } from '../blocks/form/select/select.svelte';
|
|
17
|
+
import { componentInfo as formSubmitButtonComponentInfo } from '../blocks/form/submit-button/component-info.js';
|
|
18
|
+
import { default as FormSubmitButton } from '../blocks/form/submit-button/submit-button.svelte';
|
|
19
|
+
import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.js';
|
|
20
|
+
import { default as Img } from '../blocks/img/img.svelte';
|
|
21
|
+
import { componentInfo as videoComponentInfo } from '../blocks/video/component-info.js';
|
|
22
|
+
import { default as Video } from '../blocks/video/video.svelte';
|
|
23
|
+
import type { RegisteredComponent } from '../context/types.js';
|
|
24
|
+
import { TARGET } from './target.js';
|
|
25
|
+
export const getExtraComponents: () => RegisteredComponent[] = () => [{
|
|
26
|
+
component: customCode,
|
|
27
|
+
...customCodeInfo
|
|
28
|
+
}, {
|
|
29
|
+
component: embed,
|
|
30
|
+
...embedComponentInfo
|
|
31
|
+
}, ...(TARGET === 'rsc' ? [] : [{
|
|
32
|
+
component: Form,
|
|
33
|
+
...formComponentInfo
|
|
34
|
+
}, {
|
|
35
|
+
component: FormInput,
|
|
36
|
+
...formInputComponentInfo
|
|
37
|
+
}, {
|
|
38
|
+
component: FormSubmitButton,
|
|
39
|
+
...formSubmitButtonComponentInfo
|
|
40
|
+
}, {
|
|
41
|
+
component: FormSelect,
|
|
42
|
+
...formSelectComponentInfo
|
|
43
|
+
}]), {
|
|
44
|
+
component: Img,
|
|
45
|
+
...imgComponentInfo
|
|
46
|
+
}, {
|
|
47
|
+
component: Video,
|
|
48
|
+
...videoComponentInfo
|
|
49
|
+
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.13.
|
|
1
|
+
export const SDK_VERSION = "0.13.2"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const validEnvList = ['production', 'qa', 'test', 'development', 'dev', 'cdn-qa', 'cloud', 'fast', 'cdn2', 'cdn-prod'];
|
|
2
|
+
export const getEnv = (): string => {
|
|
3
|
+
const env = process.env.NODE_ENV || 'production';
|
|
4
|
+
return validEnvList.includes(env) ? env : 'production';
|
|
5
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const get = (obj: any, path: string, defaultValue?: any) => {
|
|
2
|
+
const result = String.prototype.split.call(path, /[,[\].]+?/).filter(Boolean).reduce((res, key) => res !== null && res !== undefined ? res[key] : res, obj);
|
|
3
|
+
return result === undefined || result === obj ? defaultValue : result;
|
|
4
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: Record<string, never>;
|
|
4
|
-
events: {
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
};
|
|
7
|
-
slots: {};
|
|
8
|
-
};
|
|
9
|
-
export type FormProps = typeof __propDef.props;
|
|
10
|
-
export type FormEvents = typeof __propDef.events;
|
|
11
|
-
export type FormSlots = typeof __propDef.slots;
|
|
12
|
-
export default class Form extends SvelteComponent<FormProps, FormEvents, FormSlots> {
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: Record<string, never>;
|
|
4
|
-
events: {
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
};
|
|
7
|
-
slots: {};
|
|
8
|
-
};
|
|
9
|
-
export type FormProps = typeof __propDef.props;
|
|
10
|
-
export type FormEvents = typeof __propDef.events;
|
|
11
|
-
export type FormSlots = typeof __propDef.slots;
|
|
12
|
-
export default class Form extends SvelteComponent<FormProps, FormEvents, FormSlots> {
|
|
13
|
-
}
|
|
14
|
-
export {};
|