@builder.io/sdk-svelte 0.13.1 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/blocks/columns/columns.svelte +0 -1
- package/lib/browser/blocks/columns/columns.svelte.d.ts +8 -10
- package/lib/browser/blocks/columns/columns.types.d.ts +2 -2
- 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/blocks/symbol/symbol.svelte +0 -1
- package/lib/browser/blocks/symbol/symbol.svelte.d.ts +7 -9
- package/lib/browser/blocks/symbol/symbol.types.d.ts +2 -2
- package/lib/browser/components/block/block.svelte +4 -2
- package/lib/browser/components/block/components/block-wrapper.svelte.d.ts +4 -4
- package/lib/browser/components/block/components/component-ref/component-ref.helpers.d.ts +3 -3
- package/lib/browser/components/content/content.types.d.ts +1 -8
- package/lib/browser/components/content/contentProps.types.d.ts +12 -0
- package/lib/browser/components/content/contentProps.types.js +1 -0
- package/lib/browser/components/dynamic-renderer/dynamic-renderer.svelte +2 -0
- 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/types/builder-props.d.ts +1 -1
- package/lib/browser/types/input.d.ts +1 -0
- package/lib/browser/types/typescript.d.ts +0 -3
- package/lib/edge/blocks/columns/columns.svelte +0 -1
- package/lib/edge/blocks/columns/columns.svelte.d.ts +8 -10
- package/lib/edge/blocks/columns/columns.types.d.ts +2 -2
- 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/blocks/symbol/symbol.svelte +0 -1
- package/lib/edge/blocks/symbol/symbol.svelte.d.ts +7 -9
- package/lib/edge/blocks/symbol/symbol.types.d.ts +2 -2
- package/lib/edge/components/block/block.svelte +4 -2
- package/lib/edge/components/block/components/block-wrapper.svelte.d.ts +4 -4
- package/lib/edge/components/block/components/component-ref/component-ref.helpers.d.ts +3 -3
- package/lib/edge/components/content/content.types.d.ts +1 -8
- package/lib/edge/components/content/contentProps.types.d.ts +12 -0
- package/lib/edge/components/content/contentProps.types.js +1 -0
- package/lib/edge/components/dynamic-renderer/dynamic-renderer.svelte +2 -0
- 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/types/builder-props.d.ts +1 -1
- package/lib/edge/types/input.d.ts +1 -0
- package/lib/edge/types/typescript.d.ts +0 -3
- package/lib/node/blocks/columns/columns.svelte +0 -1
- package/lib/node/blocks/columns/columns.svelte.d.ts +8 -10
- package/lib/node/blocks/columns/columns.types.d.ts +2 -2
- 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/blocks/symbol/symbol.svelte +0 -1
- package/lib/node/blocks/symbol/symbol.svelte.d.ts +7 -9
- package/lib/node/blocks/symbol/symbol.types.d.ts +2 -2
- package/lib/node/components/block/block.svelte +4 -2
- package/lib/node/components/block/components/block-wrapper.svelte.d.ts +4 -4
- package/lib/node/components/block/components/component-ref/component-ref.helpers.d.ts +3 -3
- package/lib/node/components/content/content.types.d.ts +1 -8
- package/lib/node/components/content/contentProps.types.d.ts +12 -0
- package/lib/node/components/content/contentProps.types.js +1 -0
- package/lib/node/components/dynamic-renderer/dynamic-renderer.svelte +2 -0
- 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/types/builder-props.d.ts +1 -1
- package/lib/node/types/input.d.ts +1 -0
- package/lib/node/types/typescript.d.ts +0 -3
- package/package.json +1 -1
- package/src/blocks/columns/columns.svelte +8 -11
- package/src/blocks/columns/columns.types.ts +2 -2
- package/src/blocks/form/{component-info.ts → form/component-info.ts} +1 -1
- package/src/blocks/form/form/form.svelte +358 -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/blocks/symbol/symbol.svelte +7 -10
- package/src/blocks/symbol/symbol.types.ts +2 -2
- package/src/components/block/block.svelte +4 -2
- package/src/components/block/components/block-wrapper.svelte +4 -4
- package/src/components/block/components/component-ref/component-ref.helpers.ts +3 -3
- package/src/components/block/components/interactive-element.svelte +7 -9
- package/src/components/blocks/blocks-wrapper.svelte +7 -7
- package/src/components/content/content.types.ts +1 -7
- package/src/components/content/contentProps.types.ts +12 -0
- package/src/components/dynamic-renderer/dynamic-renderer.svelte +12 -16
- 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/types/builder-props.ts +1 -1
- package/src/types/input.ts +1 -0
- package/src/types/typescript.ts +1 -4
- 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/browser/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +0 -21
- 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/edge/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +0 -21
- 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/lib/node/components/dynamic-renderer/dynamic-renderer.svelte.d.ts +0 -21
- 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
|
@@ -8,7 +8,6 @@ import { TARGET } from "../../constants/target.js";
|
|
|
8
8
|
import "../../functions/deopt.js";
|
|
9
9
|
import { getClassPropName } from "../../functions/get-class-prop-name.js";
|
|
10
10
|
import { mapStyleObjToStrIfNeeded } from "../../functions/get-style.js";
|
|
11
|
-
export let js;
|
|
12
11
|
export let space = undefined;
|
|
13
12
|
export let columns = undefined;
|
|
14
13
|
export let stackColumnsAt = undefined;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { PropsWithBuilderData } from "../../types/builder-props.js";
|
|
3
2
|
import type { ColumnProps } from "./columns.types.js";
|
|
4
3
|
declare const __propDef: {
|
|
5
4
|
props: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
builderComponents: PropsWithBuilderData<ColumnProps>["builderComponents"];
|
|
5
|
+
space?: ColumnProps["space"];
|
|
6
|
+
columns?: ColumnProps["columns"];
|
|
7
|
+
stackColumnsAt?: ColumnProps["stackColumnsAt"];
|
|
8
|
+
reverseColumnsWhenStacked?: ColumnProps["reverseColumnsWhenStacked"];
|
|
9
|
+
builderContext: ColumnProps["builderContext"];
|
|
10
|
+
builderBlock: ColumnProps["builderBlock"];
|
|
11
|
+
builderLinkComponent?: ColumnProps["builderLinkComponent"];
|
|
12
|
+
builderComponents: ColumnProps["builderComponents"];
|
|
15
13
|
};
|
|
16
14
|
events: {
|
|
17
15
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../../types/builder-block.js';
|
|
2
|
-
import type { BuilderComponentsProp, BuilderLinkComponentProp } from '../../types/builder-props.js';
|
|
2
|
+
import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props.js';
|
|
3
3
|
type Column = {
|
|
4
4
|
blocks: BuilderBlock[];
|
|
5
5
|
width?: number;
|
|
6
6
|
link?: string;
|
|
7
7
|
};
|
|
8
8
|
type StackColumnsAt = 'tablet' | 'mobile' | 'never';
|
|
9
|
-
export interface ColumnProps extends BuilderComponentsProp, BuilderLinkComponentProp {
|
|
9
|
+
export interface ColumnProps extends BuilderComponentsProp, BuilderLinkComponentProp, BuilderDataProps {
|
|
10
10
|
columns?: Column[];
|
|
11
11
|
space?: number;
|
|
12
12
|
stackColumnsAt?: StackColumnsAt;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
<script context="module">/**
|
|
2
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
3
|
+
*/
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script>import Block from "../../../components/block/block.svelte";
|
|
7
|
+
import Blocks from "../../../components/blocks/blocks.svelte";
|
|
8
|
+
import { getEnv } from "../../../functions/get-env.js";
|
|
9
|
+
import { get } from "../../../functions/get.js";
|
|
10
|
+
import { isEditing } from "../../../functions/is-editing.js";
|
|
11
|
+
import { set } from "../../../functions/set.js";
|
|
12
|
+
import { filterAttrs } from "../../helpers.js";
|
|
13
|
+
import { setAttrs } from "../../helpers.js";
|
|
14
|
+
export let js;
|
|
15
|
+
export let builderContext;
|
|
16
|
+
export let previewState = undefined;
|
|
17
|
+
export let sendWithJs = undefined;
|
|
18
|
+
export let sendSubmissionsTo = undefined;
|
|
19
|
+
export let action = undefined;
|
|
20
|
+
export let customHeaders = undefined;
|
|
21
|
+
export let contentType = undefined;
|
|
22
|
+
export let sendSubmissionsToEmail = undefined;
|
|
23
|
+
export let name = undefined;
|
|
24
|
+
export let method = undefined;
|
|
25
|
+
export let errorMessagePath = undefined;
|
|
26
|
+
export let resetFormOnSubmit = undefined;
|
|
27
|
+
export let successUrl = undefined;
|
|
28
|
+
export let validate = undefined;
|
|
29
|
+
export let attributes = undefined;
|
|
30
|
+
export let builderBlock;
|
|
31
|
+
export let builderComponents;
|
|
32
|
+
export let builderLinkComponent = undefined;
|
|
33
|
+
export let errorMessage = undefined;
|
|
34
|
+
export let sendingMessage = undefined;
|
|
35
|
+
export let successMessage = undefined;
|
|
36
|
+
function mergeNewRootState(newData) {
|
|
37
|
+
const combinedState = {
|
|
38
|
+
...$builderContext.rootState,
|
|
39
|
+
...newData,
|
|
40
|
+
};
|
|
41
|
+
if ($builderContext.rootSetState) {
|
|
42
|
+
$builderContext.rootSetState?.(combinedState);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
$builderContext.rootState = combinedState;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function submissionState() {
|
|
49
|
+
return (isEditing() && previewState) || formState;
|
|
50
|
+
}
|
|
51
|
+
function onSubmit(event) {
|
|
52
|
+
const sendWithJsProp = sendWithJs || sendSubmissionsTo === "email";
|
|
53
|
+
if (sendSubmissionsTo === "zapier") {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
}
|
|
56
|
+
else if (sendWithJsProp) {
|
|
57
|
+
if (!(action || sendSubmissionsTo === "email")) {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const el = event.currentTarget;
|
|
63
|
+
const headers = customHeaders || {};
|
|
64
|
+
let body;
|
|
65
|
+
const formData = new FormData(el);
|
|
66
|
+
// TODO: maybe support null
|
|
67
|
+
const formPairs = Array.from(event.currentTarget.querySelectorAll("input,select,textarea"))
|
|
68
|
+
.filter((el) => !!el.name)
|
|
69
|
+
.map((el) => {
|
|
70
|
+
let value;
|
|
71
|
+
const key = el.name;
|
|
72
|
+
if (el instanceof HTMLInputElement) {
|
|
73
|
+
if (el.type === "radio") {
|
|
74
|
+
if (el.checked) {
|
|
75
|
+
value = el.name;
|
|
76
|
+
return {
|
|
77
|
+
key,
|
|
78
|
+
value,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (el.type === "checkbox") {
|
|
83
|
+
value = el.checked;
|
|
84
|
+
}
|
|
85
|
+
else if (el.type === "number" || el.type === "range") {
|
|
86
|
+
const num = el.valueAsNumber;
|
|
87
|
+
if (!isNaN(num)) {
|
|
88
|
+
value = num;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (el.type === "file") {
|
|
92
|
+
// TODO: one vs multiple files
|
|
93
|
+
value = el.files;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
value = el.value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
value = el.value;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
key,
|
|
104
|
+
value,
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
let formContentType = contentType;
|
|
108
|
+
if (sendSubmissionsTo === "email") {
|
|
109
|
+
formContentType = "multipart/form-data";
|
|
110
|
+
}
|
|
111
|
+
Array.from(formPairs).forEach(({ value }) => {
|
|
112
|
+
if (value instanceof File ||
|
|
113
|
+
(Array.isArray(value) && value[0] instanceof File) ||
|
|
114
|
+
value instanceof FileList) {
|
|
115
|
+
formContentType = "multipart/form-data";
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
// TODO: send as urlEncoded or multipart by default
|
|
119
|
+
// because of ease of use and reliability in browser API
|
|
120
|
+
// for encoding the form?
|
|
121
|
+
if (formContentType !== "application/json") {
|
|
122
|
+
body = formData;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Json
|
|
126
|
+
const json = {};
|
|
127
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
128
|
+
set(json, key, value);
|
|
129
|
+
});
|
|
130
|
+
body = JSON.stringify(json);
|
|
131
|
+
}
|
|
132
|
+
if (formContentType && formContentType !== "multipart/form-data") {
|
|
133
|
+
if (
|
|
134
|
+
/* Zapier doesn't allow content-type header to be sent from browsers */
|
|
135
|
+
!(sendWithJsProp && action?.includes("zapier.com"))) {
|
|
136
|
+
headers["content-type"] = formContentType;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const presubmitEvent = new CustomEvent("presubmit", {
|
|
140
|
+
detail: {
|
|
141
|
+
body,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
if (formRef) {
|
|
145
|
+
formRef.dispatchEvent(presubmitEvent);
|
|
146
|
+
if (presubmitEvent.defaultPrevented) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
formState = "sending";
|
|
151
|
+
const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${$builderContext.apiKey}&to=${btoa(sendSubmissionsToEmail || "")}&name=${encodeURIComponent(name || "")}`;
|
|
152
|
+
fetch(sendSubmissionsTo === "email"
|
|
153
|
+
? formUrl
|
|
154
|
+
: action /* TODO: throw error if no action URL */, {
|
|
155
|
+
body,
|
|
156
|
+
headers,
|
|
157
|
+
method: method || "post",
|
|
158
|
+
}).then(async (res) => {
|
|
159
|
+
let body;
|
|
160
|
+
const contentType = res.headers.get("content-type");
|
|
161
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
162
|
+
body = await res.json();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
body = await res.text();
|
|
166
|
+
}
|
|
167
|
+
if (!res.ok && errorMessagePath) {
|
|
168
|
+
/* TODO: allow supplying an error formatter function */
|
|
169
|
+
let message = get(body, errorMessagePath);
|
|
170
|
+
if (message) {
|
|
171
|
+
if (typeof message !== "string") {
|
|
172
|
+
/* TODO: ideally convert json to yaml so it woul dbe like
|
|
173
|
+
error: - email has been taken */
|
|
174
|
+
message = JSON.stringify(message);
|
|
175
|
+
}
|
|
176
|
+
formErrorMessage = message;
|
|
177
|
+
mergeNewRootState({
|
|
178
|
+
formErrorMessage: message,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
responseData = body;
|
|
183
|
+
formState = res.ok ? "success" : "error";
|
|
184
|
+
if (res.ok) {
|
|
185
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
186
|
+
detail: {
|
|
187
|
+
res,
|
|
188
|
+
body,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
if (formRef) {
|
|
192
|
+
formRef.dispatchEvent(submitSuccessEvent);
|
|
193
|
+
if (submitSuccessEvent.defaultPrevented) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
/* TODO: option to turn this on/off? */
|
|
197
|
+
if (resetFormOnSubmit !== false) {
|
|
198
|
+
formRef.reset();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/* TODO: client side route event first that can be preventDefaulted */
|
|
202
|
+
if (successUrl) {
|
|
203
|
+
if (formRef) {
|
|
204
|
+
const event = new CustomEvent("route", {
|
|
205
|
+
detail: {
|
|
206
|
+
url: successUrl,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
formRef.dispatchEvent(event);
|
|
210
|
+
if (!event.defaultPrevented) {
|
|
211
|
+
location.href = successUrl;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
location.href = successUrl;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}, (err) => {
|
|
220
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
221
|
+
detail: {
|
|
222
|
+
error: err,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
if (formRef) {
|
|
226
|
+
formRef.dispatchEvent(submitErrorEvent);
|
|
227
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
responseData = err;
|
|
232
|
+
formState = "error";
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
let formRef;
|
|
237
|
+
let formState = "unsubmitted";
|
|
238
|
+
let responseData = null;
|
|
239
|
+
let formErrorMessage = "";
|
|
240
|
+
</script>
|
|
241
|
+
|
|
242
|
+
<form
|
|
243
|
+
{validate}
|
|
244
|
+
bind:this={formRef}
|
|
245
|
+
action={!sendWithJs && action}
|
|
246
|
+
{method}
|
|
247
|
+
{name}
|
|
248
|
+
on:submit={(event) => {
|
|
249
|
+
onSubmit(event);
|
|
250
|
+
}}
|
|
251
|
+
{...filterAttrs(attributes, "on:", false)}
|
|
252
|
+
use:setAttrs={filterAttrs(attributes, "on:", true)}
|
|
253
|
+
>
|
|
254
|
+
{#if builderBlock && builderBlock.children}
|
|
255
|
+
{#each builderBlock?.children as block, idx (`form-block-${idx}`)}
|
|
256
|
+
<Block
|
|
257
|
+
{block}
|
|
258
|
+
context={builderContext}
|
|
259
|
+
registeredComponents={builderComponents}
|
|
260
|
+
linkComponent={builderLinkComponent}
|
|
261
|
+
/>
|
|
262
|
+
{/each}
|
|
263
|
+
{/if}
|
|
264
|
+
|
|
265
|
+
{#if submissionState() === "error"}
|
|
266
|
+
<Blocks
|
|
267
|
+
path="errorMessage"
|
|
268
|
+
blocks={errorMessage}
|
|
269
|
+
context={builderContext}
|
|
270
|
+
/>
|
|
271
|
+
{/if}
|
|
272
|
+
|
|
273
|
+
{#if submissionState() === "sending"}
|
|
274
|
+
<Blocks
|
|
275
|
+
path="sendingMessage"
|
|
276
|
+
blocks={sendingMessage}
|
|
277
|
+
context={builderContext}
|
|
278
|
+
/>
|
|
279
|
+
{/if}
|
|
280
|
+
|
|
281
|
+
{#if submissionState() === "error" && responseData}
|
|
282
|
+
<pre class="builder-form-error-text pre">
|
|
283
|
+
{JSON.stringify(responseData, null, 2)}
|
|
284
|
+
</pre>
|
|
285
|
+
{/if}
|
|
286
|
+
|
|
287
|
+
{#if submissionState() === "success"}
|
|
288
|
+
<Blocks
|
|
289
|
+
path="successMessage"
|
|
290
|
+
blocks={successMessage}
|
|
291
|
+
context={builderContext}
|
|
292
|
+
/>
|
|
293
|
+
{/if}
|
|
294
|
+
</form>
|
|
295
|
+
|
|
296
|
+
<style>
|
|
297
|
+
.pre {
|
|
298
|
+
padding: 10px;
|
|
299
|
+
color: red;
|
|
300
|
+
text-align: center;
|
|
301
|
+
}
|
|
302
|
+
</style>
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
|
-
<script>import { isEditing } from "
|
|
7
|
-
import { filterAttrs } from "
|
|
8
|
-
import { setAttrs } from "
|
|
6
|
+
<script>import { isEditing } from "../../../functions/is-editing.js";
|
|
7
|
+
import { filterAttrs } from "../../helpers.js";
|
|
8
|
+
import { setAttrs } from "../../helpers.js";
|
|
9
9
|
export let attributes = undefined;
|
|
10
10
|
export let defaultValue = undefined;
|
|
11
11
|
export let placeholder = undefined;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
|
-
<script>import { isEditing } from "
|
|
7
|
-
import { filterAttrs } from "
|
|
8
|
-
import { setAttrs } from "
|
|
6
|
+
<script>import { isEditing } from "../../../functions/is-editing.js";
|
|
7
|
+
import { filterAttrs } from "../../helpers.js";
|
|
8
|
+
import { setAttrs } from "../../helpers.js";
|
|
9
9
|
export let attributes = undefined;
|
|
10
10
|
export let value = undefined;
|
|
11
11
|
export let defaultValue = undefined;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
|
-
<script>import { filterAttrs } from "
|
|
7
|
-
import { setAttrs } from "
|
|
6
|
+
<script>import { filterAttrs } from "../../helpers.js";
|
|
7
|
+
import { setAttrs } from "../../helpers.js";
|
|
8
8
|
export let attributes = undefined;
|
|
9
9
|
export let text = undefined;
|
|
10
10
|
</script>
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
export
|
|
2
|
+
export type DropzoneProps = BuilderDataProps & {
|
|
3
3
|
name: string;
|
|
4
|
-
builderBlock: BuilderBlock;
|
|
5
|
-
builderContext: Writable<BuilderContextInterface>;
|
|
6
4
|
attributes: any;
|
|
7
|
-
}
|
|
8
|
-
import type {
|
|
9
|
-
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
10
|
-
import type { Writable } from "svelte/store";
|
|
5
|
+
};
|
|
6
|
+
import type { BuilderDataProps } from "../../types/builder-props.js";
|
|
11
7
|
declare const __propDef: {
|
|
12
8
|
props: {
|
|
9
|
+
js: any;
|
|
13
10
|
builderContext: DropzoneProps["builderContext"];
|
|
14
11
|
name: DropzoneProps["name"];
|
|
15
12
|
};
|
|
@@ -4,7 +4,6 @@ import { filterAttrs } from "../helpers.js";
|
|
|
4
4
|
import { getClassPropName } from "../../functions/get-class-prop-name.js";
|
|
5
5
|
import { setAttrs } from "../helpers.js";
|
|
6
6
|
import { fetchSymbolContent } from "./symbol.helpers.js";
|
|
7
|
-
export let js;
|
|
8
7
|
export let attributes = undefined;
|
|
9
8
|
export let symbol = undefined;
|
|
10
9
|
export let dynamic = undefined;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { PropsWithBuilderData } from "../../types/builder-props.js";
|
|
3
2
|
import type { SymbolProps } from "./symbol.types.js";
|
|
4
3
|
declare const __propDef: {
|
|
5
4
|
props: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
builderLinkComponent?: PropsWithBuilderData<SymbolProps>["builderLinkComponent"];
|
|
5
|
+
attributes?: SymbolProps["attributes"];
|
|
6
|
+
symbol?: SymbolProps["symbol"];
|
|
7
|
+
dynamic?: SymbolProps["dynamic"];
|
|
8
|
+
builderContext: SymbolProps["builderContext"];
|
|
9
|
+
builderBlock: SymbolProps["builderBlock"];
|
|
10
|
+
builderComponents: SymbolProps["builderComponents"];
|
|
11
|
+
builderLinkComponent?: SymbolProps["builderLinkComponent"];
|
|
14
12
|
};
|
|
15
13
|
events: {
|
|
16
14
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderContent } from '../../types/builder-content.js';
|
|
2
|
-
import type { BuilderComponentsProp, BuilderLinkComponentProp } from '../../types/builder-props.js';
|
|
2
|
+
import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props.js';
|
|
3
3
|
interface SymbolInfo {
|
|
4
4
|
model?: string;
|
|
5
5
|
entry?: string;
|
|
@@ -8,7 +8,7 @@ interface SymbolInfo {
|
|
|
8
8
|
inline?: boolean;
|
|
9
9
|
dynamic?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export interface SymbolProps extends BuilderComponentsProp, BuilderLinkComponentProp {
|
|
11
|
+
export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp {
|
|
12
12
|
symbol?: SymbolInfo;
|
|
13
13
|
dataOnly?: boolean;
|
|
14
14
|
dynamic?: boolean;
|
|
@@ -81,13 +81,15 @@ $: componentRefProps = () => {
|
|
|
81
81
|
builderContext: context,
|
|
82
82
|
...(blockComponent?.()?.name === "Core:Button" ||
|
|
83
83
|
blockComponent?.()?.name === "Symbol" ||
|
|
84
|
-
blockComponent?.()?.name === "Columns"
|
|
84
|
+
blockComponent?.()?.name === "Columns" ||
|
|
85
|
+
blockComponent?.()?.name === "Form:Form"
|
|
85
86
|
? {
|
|
86
87
|
builderLinkComponent: linkComponent,
|
|
87
88
|
}
|
|
88
89
|
: {}),
|
|
89
90
|
...(blockComponent?.()?.name === "Symbol" ||
|
|
90
|
-
blockComponent?.()?.name === "Columns"
|
|
91
|
+
blockComponent?.()?.name === "Columns" ||
|
|
92
|
+
blockComponent?.()?.name === "Form:Form"
|
|
91
93
|
? {
|
|
92
94
|
builderComponents: registeredComponents,
|
|
93
95
|
}
|
|
@@ -4,16 +4,16 @@ type BlockWrapperProps = {
|
|
|
4
4
|
block: BuilderBlock;
|
|
5
5
|
context: Writable<BuilderContextInterface>;
|
|
6
6
|
linkComponent: any;
|
|
7
|
+
children?: any;
|
|
7
8
|
};
|
|
8
9
|
import type { BuilderContextInterface } from "../../../context/types.js";
|
|
9
10
|
import type { BuilderBlock } from "../../../types/builder-block.js";
|
|
10
|
-
import type { PropsWithChildren } from "../../../types/typescript.js";
|
|
11
11
|
import type { Writable } from "svelte/store";
|
|
12
12
|
declare const __propDef: {
|
|
13
13
|
props: {
|
|
14
|
-
Wrapper:
|
|
15
|
-
block:
|
|
16
|
-
context:
|
|
14
|
+
Wrapper: BlockWrapperProps["Wrapper"];
|
|
15
|
+
block: BlockWrapperProps["block"];
|
|
16
|
+
context: BlockWrapperProps["context"];
|
|
17
17
|
};
|
|
18
18
|
events: {
|
|
19
19
|
[evt: string]: CustomEvent<any>;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import type { Writable } from "svelte/store";
|
|
3
3
|
import type { BuilderContextInterface, RegisteredComponents } from '../../../../context/types.js';
|
|
4
4
|
import type { BuilderBlock } from '../../../../types/builder-block.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { BuilderDataProps } from '../../../../types/builder-props.js';
|
|
6
6
|
import type { InteractiveElementProps } from '../interactive-element.svelte';
|
|
7
|
-
type ComponentOptions =
|
|
7
|
+
type ComponentOptions = BuilderDataProps & {
|
|
8
8
|
[index: string]: any;
|
|
9
9
|
attributes?: {
|
|
10
10
|
[index: string]: any;
|
|
11
11
|
};
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
export interface ComponentProps {
|
|
14
14
|
componentRef: any;
|
|
15
15
|
componentOptions: ComponentOptions;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { BuilderRenderState } from '../../context/types.js';
|
|
2
|
-
|
|
3
|
-
import type { ContentVariantsPrps } from '../content-variants/content-variants.types.js';
|
|
4
|
-
interface InternalRenderProps {
|
|
5
|
-
showContent: boolean;
|
|
6
|
-
isSsrAbTest: boolean;
|
|
7
|
-
}
|
|
8
|
-
export type ContentProps = InternalRenderProps & EnforcePartials<ContentVariantsPrps>;
|
|
2
|
+
export type { ContentProps } from './contentProps.types.js';
|
|
9
3
|
export interface BuilderComponentStateChange {
|
|
10
4
|
state: BuilderRenderState;
|
|
11
5
|
ref: {
|
|
@@ -17,4 +11,3 @@ export interface BuilderComponentStateChange {
|
|
|
17
11
|
};
|
|
18
12
|
};
|
|
19
13
|
}
|
|
20
|
-
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EnforcePartials } from '../../types/enforced-partials.js';
|
|
2
|
+
import type { ContentVariantsPrps } from '../content-variants/content-variants.types.js';
|
|
3
|
+
interface InternalRenderProps {
|
|
4
|
+
showContent: boolean;
|
|
5
|
+
isSsrAbTest: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* This is in a separate file so that we can override it (most notably in Vue,
|
|
9
|
+
* where prop types cannot be wrapped by generics like `EnforcePartials`).
|
|
10
|
+
*/
|
|
11
|
+
export type ContentProps = InternalRenderProps & EnforcePartials<ContentVariantsPrps>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,8 +14,7 @@ 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 {
|
|
24
|
-
import { default as Video } from '../blocks/video/video.svelte';
|
|
17
|
+
import { getExtraComponents } from './extra-components.js';
|
|
25
18
|
/**
|
|
26
19
|
* Returns a list of all registered components.
|
|
27
20
|
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
@@ -32,34 +25,22 @@ export const getDefaultRegisteredComponents = () => [{
|
|
|
32
25
|
}, {
|
|
33
26
|
component: Columns,
|
|
34
27
|
...columnsComponentInfo
|
|
35
|
-
}, {
|
|
36
|
-
component: customCode,
|
|
37
|
-
...customCodeInfo
|
|
38
|
-
}, {
|
|
39
|
-
component: embed,
|
|
40
|
-
...embedComponentInfo
|
|
41
28
|
}, {
|
|
42
29
|
component: Fragment,
|
|
43
30
|
...fragmentComponentInfo
|
|
44
31
|
}, {
|
|
45
32
|
component: Image,
|
|
46
33
|
...imageComponentInfo
|
|
47
|
-
}, {
|
|
48
|
-
component: Img,
|
|
49
|
-
...imgComponentInfo
|
|
50
34
|
}, {
|
|
51
35
|
component: Section,
|
|
52
36
|
...sectionComponentInfo
|
|
37
|
+
}, {
|
|
38
|
+
component: Slot,
|
|
39
|
+
...slotComponentInfo
|
|
53
40
|
}, {
|
|
54
41
|
component: Symbol,
|
|
55
42
|
...symbolComponentInfo
|
|
56
43
|
}, {
|
|
57
44
|
component: Text,
|
|
58
45
|
...textComponentInfo
|
|
59
|
-
},
|
|
60
|
-
component: Video,
|
|
61
|
-
...videoComponentInfo
|
|
62
|
-
}, {
|
|
63
|
-
component: Slot,
|
|
64
|
-
...slotComponentInfo
|
|
65
|
-
}];
|
|
46
|
+
}, ...getExtraComponents()];
|