eddev 2.1.0 → 2.1.1
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/bin/eddev.js +1 -1
- package/dist/app/lib/integrations/gravityforms/createGravityFormComponent.d.ts +86 -0
- package/dist/app/lib/integrations/gravityforms/createGravityFormComponent.d.ts.map +1 -0
- package/dist/app/lib/integrations/gravityforms/createGravityFormComponent.js +127 -0
- package/dist/app/lib/integrations/gravityforms/field-types.d.ts +137 -0
- package/dist/app/lib/integrations/gravityforms/field-types.d.ts.map +1 -0
- package/dist/app/lib/integrations/gravityforms/field-types.js +449 -0
- package/dist/app/lib/integrations/gravityforms/index.d.ts +2 -0
- package/dist/app/lib/integrations/gravityforms/index.d.ts.map +1 -1
- package/dist/app/lib/integrations/gravityforms/index.js +2 -0
- package/dist/app/lib/integrations/gravityforms/types.d.ts +35 -116
- package/dist/app/lib/integrations/gravityforms/types.d.ts.map +1 -1
- package/dist/app/lib/integrations/gravityforms/useGravityForm.d.ts +44 -0
- package/dist/app/lib/integrations/gravityforms/useGravityForm.d.ts.map +1 -1
- package/dist/app/lib/integrations/gravityforms/useGravityForm.js +220 -121
- package/dist/node/cli/cli.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
// export type GFFieldTypes = {
|
|
4
|
+
// text: string
|
|
5
|
+
// textarea: string
|
|
6
|
+
// select: string
|
|
7
|
+
// number: number
|
|
8
|
+
// checkbox: string[]
|
|
9
|
+
// radio: string
|
|
10
|
+
// multi_choice: string | string[]
|
|
11
|
+
// image_choice: string | string[]
|
|
12
|
+
// name: GFNameData
|
|
13
|
+
// date: string
|
|
14
|
+
// time: string
|
|
15
|
+
// phone: string
|
|
16
|
+
// address: GFAddressData
|
|
17
|
+
// website: string
|
|
18
|
+
// email: string
|
|
19
|
+
// fileupload: File | FileList | File[]
|
|
20
|
+
// multiselect: string[]
|
|
21
|
+
// consent: boolean
|
|
22
|
+
// captcha: any
|
|
23
|
+
// html: void
|
|
24
|
+
// section: void
|
|
25
|
+
// }
|
|
26
|
+
function defineType(spec) {
|
|
27
|
+
return spec;
|
|
28
|
+
}
|
|
29
|
+
export const GF_BUILTIN_FIELDS = {
|
|
30
|
+
text: defineType({
|
|
31
|
+
getInitialValue: () => "",
|
|
32
|
+
getOptions: (field) => ({
|
|
33
|
+
placeholder: field.placeholder || "",
|
|
34
|
+
size: field.size || "large",
|
|
35
|
+
}),
|
|
36
|
+
defaultComponent(props) {
|
|
37
|
+
const id = useId();
|
|
38
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { id: id, type: "text", required: props.isRequired, name: `field_${props.id}`, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: props.value || "", onChange: (e) => props.set(e.currentTarget.value) }) }));
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
textarea: defineType({
|
|
42
|
+
getInitialValue: () => "",
|
|
43
|
+
getOptions: (field) => ({
|
|
44
|
+
placeholder: field.placeholder || "",
|
|
45
|
+
size: field.size || "large",
|
|
46
|
+
}),
|
|
47
|
+
defaultComponent(props) {
|
|
48
|
+
const id = useId();
|
|
49
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("textarea", { id: id, required: props.isRequired, name: `field_${props.id}`, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: props.value || "", onChange: (e) => props.set(e.currentTarget.value), rows: props.size === "small" ? 2 : props.size === "medium" ? 4 : 8 }) }));
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
select: defineType({
|
|
53
|
+
getInitialValue: (field) => field.choices.find((choice) => choice.isSelected)?.value,
|
|
54
|
+
getOptions: (field) => ({
|
|
55
|
+
choices: field.choices || [],
|
|
56
|
+
placeholder: field.placeholder || "",
|
|
57
|
+
}),
|
|
58
|
+
defaultComponent(props) {
|
|
59
|
+
const id = useId();
|
|
60
|
+
const isPlaceholder = props.value === "" || props.value == null || props.value === undefined;
|
|
61
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsxs("select", { id: id, name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, value: props.value || "", onChange: (e) => props.set(e.target.value), "data-is-placeholder": isPlaceholder ? "" : undefined, children: [isPlaceholder && _jsx("option", { value: "", children: props.placeholder ?? "" }), props.choices.map((choice, index) => (_jsx("option", { value: choice.value, children: choice.text }, index)))] }) }));
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
number: defineType({
|
|
65
|
+
getInitialValue: (field) => undefined,
|
|
66
|
+
getOptions: (field) => ({
|
|
67
|
+
rangeMin: field.rangeMin ? Number(field.rangeMin) : undefined,
|
|
68
|
+
rangeMax: field.rangeMax ? Number(field.rangeMax) : undefined,
|
|
69
|
+
numberFormat: field.numberFormat || "decimal_dot",
|
|
70
|
+
placeholder: field.placeholder || "",
|
|
71
|
+
size: field.size || "large",
|
|
72
|
+
}),
|
|
73
|
+
defaultComponent(props) {
|
|
74
|
+
const id = useId();
|
|
75
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { id: id, type: "number", required: props.isRequired, name: `field_${props.id}`, disabled: props.disabled, placeholder: props.placeholder || "", value: props.value !== undefined && props.value !== null ? props.value : "", min: props.rangeMin, max: props.rangeMax, onChange: (e) => {
|
|
76
|
+
const number = parseFloat(e.currentTarget.value);
|
|
77
|
+
props.set(String(number) === e.currentTarget.value ? number : e.currentTarget.value);
|
|
78
|
+
} }) }));
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
checkbox: defineType({
|
|
82
|
+
getInitialValue: (field) => field.choices.filter((choice) => choice.isSelected).map((choice) => choice.value) ?? [],
|
|
83
|
+
getOptions: (field) => ({
|
|
84
|
+
choices: field.choices || [],
|
|
85
|
+
enableOtherChoice: field.enableOtherChoice || false,
|
|
86
|
+
columns: field.columns ? Number(field.columns) : undefined,
|
|
87
|
+
}),
|
|
88
|
+
appendData(data, field, value, key) {
|
|
89
|
+
field.choices.forEach((choice, i) => {
|
|
90
|
+
let fieldKey = field.inputs[i].id;
|
|
91
|
+
data.append(`input_${fieldKey.toString()}`, value?.includes(choice.value) ? choice.value : "");
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
defaultComponent(props) {
|
|
95
|
+
return (_jsx(props.Wrapper, { children: _jsx("ul", { children: props.choices.map((choice, index) => (_jsx("li", { children: _jsxs("label", { children: [_jsx("input", { type: "checkbox", name: `field_${props.id}[]`, value: choice.value, disabled: props.disabled, checked: props.value?.includes(choice.value), onChange: (e) => {
|
|
96
|
+
if (e.target.checked) {
|
|
97
|
+
props.set([...(props.value || []), choice.value]);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
props.set((props.value || []).filter((v) => v !== choice.value));
|
|
101
|
+
}
|
|
102
|
+
} }), choice.text] }) }, index))) }) }));
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
radio: defineType({
|
|
106
|
+
getInitialValue: (field) => field.choices.filter((choice) => choice.isSelected).map((choice) => choice.value) ?? [],
|
|
107
|
+
getOptions: (field) => ({
|
|
108
|
+
choices: field.choices || [],
|
|
109
|
+
enableOtherChoice: field.enableOtherChoice || false,
|
|
110
|
+
columns: field.columns ? Number(field.columns) : undefined,
|
|
111
|
+
}),
|
|
112
|
+
defaultComponent(props) {
|
|
113
|
+
return (_jsx(props.Wrapper, { children: _jsx("ul", { children: props.choices.map((choice, index) => (_jsx("li", { children: _jsxs("label", { children: [_jsx("input", { type: "radio", name: `field_${props.id}`, value: choice.value, disabled: props.disabled, checked: props.value === choice.value, onChange: (e) => {
|
|
114
|
+
props.set(choice.value);
|
|
115
|
+
} }), _jsx("span", { children: choice.text })] }) }, index))) }) }));
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
multi_choice: defineType({
|
|
119
|
+
getInitialValue: () => undefined,
|
|
120
|
+
getOptions(field) {
|
|
121
|
+
return {
|
|
122
|
+
choices: field.choices || [],
|
|
123
|
+
placeholder: field.placeholder || "",
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
appendData(data, field, value, key) {
|
|
127
|
+
if (field.choiceLimit !== "single") {
|
|
128
|
+
field.choices.forEach((choice, i) => {
|
|
129
|
+
let fieldKey = field.inputs[i].id;
|
|
130
|
+
data.append(`input_${fieldKey}`, value?.includes(choice.value) ? choice.value : "");
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
data.append(key, value ? String(value) : "");
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
image_choice: defineType({
|
|
139
|
+
getInitialValue: () => undefined,
|
|
140
|
+
getOptions(field) {
|
|
141
|
+
return {
|
|
142
|
+
choices: field.choices || [],
|
|
143
|
+
placeholder: field.placeholder || "",
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
appendData(data, field, value, key) {
|
|
147
|
+
if (field.choiceLimit !== "single") {
|
|
148
|
+
field.choices.forEach((choice, i) => {
|
|
149
|
+
let fieldKey = field.inputs[i].id;
|
|
150
|
+
data.append(`input_${fieldKey}`, value?.includes(choice.value) ? choice.value : "");
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
data.append(key, value ? String(value) : "");
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
name: defineType({
|
|
159
|
+
getInitialValue: () => ({
|
|
160
|
+
prefix: "",
|
|
161
|
+
first: "",
|
|
162
|
+
middle: "",
|
|
163
|
+
last: "",
|
|
164
|
+
suffix: "",
|
|
165
|
+
}),
|
|
166
|
+
getOptions(field) {
|
|
167
|
+
function subfield(id, name) {
|
|
168
|
+
const item = field.inputs.find((input) => String(input.id).endsWith("." + id));
|
|
169
|
+
return {
|
|
170
|
+
name: name,
|
|
171
|
+
visible: !item?.isHidden,
|
|
172
|
+
placeholder: item?.placeholder,
|
|
173
|
+
label: item?.customLabel ?? item?.label,
|
|
174
|
+
autocomplete: item?.autocompleteAttribute,
|
|
175
|
+
choices: item?.choices,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
subfields: {
|
|
180
|
+
prefix: subfield(2, "prefix"),
|
|
181
|
+
first: subfield(3, "first"),
|
|
182
|
+
middle: subfield(4, "middle"),
|
|
183
|
+
last: subfield(6, "last"),
|
|
184
|
+
suffix: subfield(8, "suffix"),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
appendData(data, field, value, key) {
|
|
189
|
+
data.append(`${key}_2`, value?.prefix ?? "");
|
|
190
|
+
data.append(`${key}_3`, value?.first ?? "");
|
|
191
|
+
data.append(`${key}_4`, value?.middle ?? "");
|
|
192
|
+
data.append(`${key}_6`, value?.last ?? "");
|
|
193
|
+
data.append(`${key}_8`, value?.suffix ?? "");
|
|
194
|
+
},
|
|
195
|
+
defaultComponent(props) {
|
|
196
|
+
const id = useId();
|
|
197
|
+
const fields = [];
|
|
198
|
+
for (const subfield of Object.values(props.subfields)) {
|
|
199
|
+
if (!subfield.visible)
|
|
200
|
+
continue;
|
|
201
|
+
fields.push(_jsx(props.formComponents.SubFieldWrapper, { label: subfield.label, labelId: id + subfield.name, children: subfield.choices?.length ? (_jsxs("select", { id: id + subfield.name, name: `field_${props.id}_${subfield.name}`, disabled: props.disabled, value: props.value?.[subfield.name] || "", onChange: (e) => {
|
|
202
|
+
props.set({
|
|
203
|
+
...(props.value || {}),
|
|
204
|
+
[subfield.name]: e.target.value,
|
|
205
|
+
});
|
|
206
|
+
}, children: [_jsx("option", { value: "", children: subfield.placeholder }), subfield.choices.map((choice, index) => (_jsx("option", { value: choice.value, children: choice.text }, index)))] })) : (_jsx("input", { id: id + subfield.name, type: "text", name: `field_${props.id}_${subfield.name}`, disabled: props.disabled, placeholder: subfield.placeholder, value: props.value?.[subfield.name] || "", autoComplete: subfield.autocomplete, onChange: (e) => {
|
|
207
|
+
props.set({
|
|
208
|
+
...(props.value || {}),
|
|
209
|
+
[subfield.name]: e.currentTarget.value,
|
|
210
|
+
});
|
|
211
|
+
} }, subfield.name)) }, subfield.name));
|
|
212
|
+
}
|
|
213
|
+
return _jsx(props.formComponents.SubFieldRow, { children: fields });
|
|
214
|
+
},
|
|
215
|
+
}),
|
|
216
|
+
date: defineType({
|
|
217
|
+
getInitialValue: () => undefined,
|
|
218
|
+
getOptions() {
|
|
219
|
+
return {};
|
|
220
|
+
},
|
|
221
|
+
defaultComponent(props) {
|
|
222
|
+
const id = useId();
|
|
223
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { type: "date", id: id, name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: props.value || "", onChange: (e) => props.set(e.currentTarget.value) }) }));
|
|
224
|
+
},
|
|
225
|
+
}),
|
|
226
|
+
time: defineType({
|
|
227
|
+
getInitialValue: () => undefined,
|
|
228
|
+
getOptions() {
|
|
229
|
+
return {};
|
|
230
|
+
},
|
|
231
|
+
defaultComponent(props) {
|
|
232
|
+
const id = useId();
|
|
233
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { type: "time", id: id, name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: props.value || "", onChange: (e) => props.set(e.currentTarget.value) }) }));
|
|
234
|
+
},
|
|
235
|
+
}),
|
|
236
|
+
phone: defineType({
|
|
237
|
+
getInitialValue: () => undefined,
|
|
238
|
+
getOptions() {
|
|
239
|
+
return {};
|
|
240
|
+
},
|
|
241
|
+
defaultComponent(props) {
|
|
242
|
+
const id = useId();
|
|
243
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { type: "tel", id: id, name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: props.value || "", onChange: (e) => props.set(e.currentTarget.value) }) }));
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
address: defineType({
|
|
247
|
+
getInitialValue: () => ({
|
|
248
|
+
address1: "",
|
|
249
|
+
address2: "",
|
|
250
|
+
city: "",
|
|
251
|
+
state: "",
|
|
252
|
+
zip: "",
|
|
253
|
+
country: "",
|
|
254
|
+
}),
|
|
255
|
+
getOptions(field) {
|
|
256
|
+
function subfield(id, name) {
|
|
257
|
+
const item = field.inputs.find((input) => String(input.id).endsWith("." + id));
|
|
258
|
+
return {
|
|
259
|
+
name: name,
|
|
260
|
+
visible: !item?.isHidden,
|
|
261
|
+
placeholder: item?.placeholder,
|
|
262
|
+
label: item?.customLabel ?? item?.label,
|
|
263
|
+
autocomplete: item?.autocompleteAttribute,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
addressType: field.addressType,
|
|
268
|
+
defaultCountry: field.defaultCountry,
|
|
269
|
+
defaultState: field.defaultState,
|
|
270
|
+
subfields: {
|
|
271
|
+
address1: subfield(1, "address1"),
|
|
272
|
+
address2: subfield(2, "address2"),
|
|
273
|
+
city: subfield(3, "city"),
|
|
274
|
+
state: subfield(4, "state"),
|
|
275
|
+
zip: subfield(5, "zip"),
|
|
276
|
+
country: subfield(6, "country"),
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
appendData(data, field, value, key) {
|
|
281
|
+
data.append(`${key}_1`, value?.address1 ?? "");
|
|
282
|
+
data.append(`${key}_2`, value?.address2 ?? "");
|
|
283
|
+
data.append(`${key}_3`, value?.city ?? "");
|
|
284
|
+
data.append(`${key}_4`, value?.state ?? "");
|
|
285
|
+
data.append(`${key}_5`, value?.zip ?? "");
|
|
286
|
+
data.append(`${key}_6`, value?.country ?? "");
|
|
287
|
+
},
|
|
288
|
+
defaultComponent(props) {
|
|
289
|
+
const id = useId();
|
|
290
|
+
const fields = {};
|
|
291
|
+
for (const subfield of Object.values(props.subfields)) {
|
|
292
|
+
if (!subfield.visible)
|
|
293
|
+
continue;
|
|
294
|
+
fields[subfield.name] = (_jsx(props.formComponents.SubFieldWrapper, { label: subfield.label, labelId: id + subfield.name, children: _jsx("input", { id: id + subfield.name, type: "text", name: `field_${props.id}_${subfield.name}`, disabled: props.disabled, placeholder: subfield.placeholder, autoComplete: subfield.autocomplete, value: props.value?.[subfield.name] || "", "data-address-component": subfield.name, onChange: (e) => {
|
|
295
|
+
props.set({
|
|
296
|
+
...(props.value || {}),
|
|
297
|
+
[subfield.name]: e.currentTarget.value,
|
|
298
|
+
});
|
|
299
|
+
} }) }, subfield.name));
|
|
300
|
+
}
|
|
301
|
+
const rows = [[fields.address1], [fields.address2], [fields.city, fields.zip], [fields.state], [fields.country]];
|
|
302
|
+
return (_jsx(props.Wrapper, { children: _jsx(props.formComponents.SubFieldStack, { children: rows
|
|
303
|
+
.map((row) => row.filter(Boolean))
|
|
304
|
+
.filter(Boolean)
|
|
305
|
+
.map((row) => (_jsx(props.formComponents.SubFieldRow, { children: row }))) }) }));
|
|
306
|
+
},
|
|
307
|
+
}),
|
|
308
|
+
website: defineType({
|
|
309
|
+
getInitialValue: () => undefined,
|
|
310
|
+
getOptions() {
|
|
311
|
+
return {};
|
|
312
|
+
},
|
|
313
|
+
defaultComponent(props) {
|
|
314
|
+
const id = useId();
|
|
315
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { id: id, type: "url", name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: props.value || "", onChange: (e) => props.set(e.currentTarget.value) }) }));
|
|
316
|
+
},
|
|
317
|
+
}),
|
|
318
|
+
email: defineType({
|
|
319
|
+
getInitialValue: (field) => undefined,
|
|
320
|
+
getOptions: (field) => ({
|
|
321
|
+
confirmation: field.emailConfirmEnabled
|
|
322
|
+
? {
|
|
323
|
+
enabled: true,
|
|
324
|
+
emailLabel: field.inputs?.[0]?.label || "Enter Email",
|
|
325
|
+
emailPlaceholder: field.inputs?.[0]?.placeholder || "Enter Email",
|
|
326
|
+
confirmLabel: field.inputs?.[1]?.label || "Enter Email",
|
|
327
|
+
confirmPlaceholder: field.inputs?.[1]?.placeholder || "Enter Email",
|
|
328
|
+
labelPlacement: field.subLabelPlacement || "above",
|
|
329
|
+
}
|
|
330
|
+
: { enabled: false },
|
|
331
|
+
placeholder: field.placeholder || "",
|
|
332
|
+
size: field.size || "large",
|
|
333
|
+
}),
|
|
334
|
+
appendData(data, field, value, key) {
|
|
335
|
+
if (field.emailConfirmEnabled) {
|
|
336
|
+
data.append(key, typeof value === "object" ? value.email : value || "");
|
|
337
|
+
data.append(key + "_2", typeof value === "object" ? value.confirmEmail : value || "");
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
data.append(key, typeof value === "object" ? value.email : value || "");
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
defaultComponent(props) {
|
|
344
|
+
const id = useId();
|
|
345
|
+
if (props.confirmation.enabled) {
|
|
346
|
+
const value = typeof props.value === "object" ? props.value : { email: props.value || "", confirmEmail: "" };
|
|
347
|
+
return (_jsx(props.Wrapper, { children: _jsxs(props.formComponents.SubFieldRow, { children: [_jsx(props.formComponents.SubFieldWrapper, { label: props.confirmation.emailLabel || "Email", labelId: id + "_email", children: _jsx("input", { type: "email", id: id + "_email", required: props.isRequired, name: `field_${props.id}_email`, disabled: props.disabled, placeholder: props.confirmation.emailPlaceholder || "", value: typeof props.value === "object" ? props.value.email : props.value || "", onChange: (e) => {
|
|
348
|
+
props.set({
|
|
349
|
+
email: e.currentTarget.value,
|
|
350
|
+
confirmEmail: value.confirmEmail,
|
|
351
|
+
});
|
|
352
|
+
} }) }), _jsx(props.formComponents.SubFieldWrapper, { label: props.confirmation.confirmLabel || "Confirm Email", labelId: id + "_confirm", children: _jsx("input", { type: "email", id: id + "_confirm", required: props.isRequired, name: `field_${props.id}_email`, disabled: props.disabled, placeholder: props.confirmation.confirmPlaceholder || "", value: typeof props.value === "object" ? props.value.confirmEmail : props.value || "", onChange: (e) => {
|
|
353
|
+
props.set({
|
|
354
|
+
email: value.email,
|
|
355
|
+
confirmEmail: e.currentTarget.value,
|
|
356
|
+
});
|
|
357
|
+
} }) })] }) }));
|
|
358
|
+
}
|
|
359
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { type: "email", id: id, name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, placeholder: props.options?.placeholder || "", value: typeof props.value === "object" ? props.value.email : props.value || "", onChange: (e) => props.set(e.currentTarget.value) }) }));
|
|
360
|
+
},
|
|
361
|
+
}),
|
|
362
|
+
fileupload: defineType({
|
|
363
|
+
getInitialValue: () => undefined,
|
|
364
|
+
getOptions: (field) => ({
|
|
365
|
+
allowedExtensions: field.allowedExtensions?.split(/\s*,\s*/g) ?? [],
|
|
366
|
+
maxFileSize: field.maxFileSize ? parseFloat(field.maxFileSize) : undefined,
|
|
367
|
+
multiple: field.multipleFiles ? true : false,
|
|
368
|
+
maxFiles: field.maxFiles ? parseInt(field.maxFiles) : undefined,
|
|
369
|
+
}),
|
|
370
|
+
appendData(data, field, value, key) {
|
|
371
|
+
const keyName = field.maxFiles > 1 || field.multipleFiles ? `${key}[]` : key;
|
|
372
|
+
if (Array.isArray(value)) {
|
|
373
|
+
value.forEach((file) => {
|
|
374
|
+
data.append(keyName, file);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
else if (value instanceof FileList) {
|
|
378
|
+
for (let i = 0; i < value.length; i++) {
|
|
379
|
+
data.append(keyName, value.item(i));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else if (value) {
|
|
383
|
+
data.append(keyName, value);
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
defaultComponent(props) {
|
|
387
|
+
const id = useId();
|
|
388
|
+
return (_jsx(props.Wrapper, { labelId: id, children: _jsx("input", { type: "file", id: id, name: `field_${props.id}${props.multiple ? "[]" : ""}`, required: props.isRequired, disabled: props.disabled, multiple: props.multiple, accept: props.allowedExtensions?.map((ext) => `.${ext}`).join(","), onChange: (e) => {
|
|
389
|
+
if (props.multiple) {
|
|
390
|
+
props.set(e.currentTarget.files ?? undefined);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
props.set(e.currentTarget.files ? e.currentTarget.files[0] : undefined);
|
|
394
|
+
}
|
|
395
|
+
} }) }));
|
|
396
|
+
},
|
|
397
|
+
}),
|
|
398
|
+
multiselect: defineType({
|
|
399
|
+
getInitialValue: () => undefined,
|
|
400
|
+
getOptions() {
|
|
401
|
+
return {};
|
|
402
|
+
},
|
|
403
|
+
}),
|
|
404
|
+
consent: defineType({
|
|
405
|
+
getInitialValue: () => undefined,
|
|
406
|
+
getOptions(field) {
|
|
407
|
+
const text = field.consentText || field.description || "";
|
|
408
|
+
return {
|
|
409
|
+
checkboxLabel: field.checkboxLabel || "",
|
|
410
|
+
description: text,
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
appendData(data, field, value, key) {
|
|
414
|
+
data.append(`${key}.1`, value ? "1" : "");
|
|
415
|
+
data.append(`${key}.2`, field?.consentText ?? field?.checkboxLabel ?? "");
|
|
416
|
+
},
|
|
417
|
+
defaultComponent(props) {
|
|
418
|
+
const id = useId();
|
|
419
|
+
return (_jsx(props.Wrapper, { descriptionElement: null, showLabel: false, children: _jsxs("div", { className: "edgf-consent-field", children: [_jsx("input", { type: "checkbox", name: `field_${props.id}`, required: props.isRequired, disabled: props.disabled, checked: props.value || false, onChange: (e) => props.set(e.target.checked), id: id }), _jsx("label", { htmlFor: id, className: "edgf-consent-label", dangerouslySetInnerHTML: { __html: props.checkboxLabel || "I Agree" } }), !!props.description && (_jsx("div", { className: "edgf-consent-agreement", dangerouslySetInnerHTML: { __html: props.description || "" } }))] }) }));
|
|
420
|
+
},
|
|
421
|
+
}),
|
|
422
|
+
captcha: defineType({
|
|
423
|
+
getInitialValue: () => undefined,
|
|
424
|
+
getOptions() {
|
|
425
|
+
return {};
|
|
426
|
+
},
|
|
427
|
+
appendData(data, field, value, key) {
|
|
428
|
+
data.append("g-recaptcha-response", value);
|
|
429
|
+
},
|
|
430
|
+
}),
|
|
431
|
+
html: defineType({
|
|
432
|
+
getInitialValue: () => undefined,
|
|
433
|
+
getOptions() {
|
|
434
|
+
return {};
|
|
435
|
+
},
|
|
436
|
+
defaultComponent(props) {
|
|
437
|
+
return _jsx("div", { dangerouslySetInnerHTML: { __html: props.content || "" } });
|
|
438
|
+
},
|
|
439
|
+
}),
|
|
440
|
+
section: defineType({
|
|
441
|
+
getInitialValue: () => undefined,
|
|
442
|
+
getOptions() {
|
|
443
|
+
return {};
|
|
444
|
+
},
|
|
445
|
+
}),
|
|
446
|
+
};
|
|
447
|
+
export function getBuiltinType(type) {
|
|
448
|
+
return GF_BUILTIN_FIELDS[type];
|
|
449
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/app/lib/integrations/gravityforms/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/app/lib/integrations/gravityforms/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,YAAY,CAAA;AAC1B,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kBAAkB,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { ComponentType } from "react";
|
|
1
|
+
import type { ComponentProps, ComponentType, ReactNode } from "react";
|
|
2
2
|
import type { GravityFormsFieldState } from "./useGravityForm.js";
|
|
3
|
+
import { FormComponents } from "./createGravityFormComponent.js";
|
|
4
|
+
import { GFBuiltins, GFFieldTypeName } from "./field-types.js";
|
|
3
5
|
export type GravityFormsField = {
|
|
4
6
|
type: string;
|
|
5
7
|
id: number;
|
|
@@ -7,8 +9,12 @@ export type GravityFormsField = {
|
|
|
7
9
|
isRequired: boolean;
|
|
8
10
|
description: string;
|
|
9
11
|
showLabel: boolean;
|
|
10
|
-
visibility: "hidden" | "visible";
|
|
12
|
+
visibility: "hidden" | "visible" | "administrative";
|
|
13
|
+
labelPlacement?: "hidden_label" | "above" | "below" | "left" | "right";
|
|
14
|
+
descriptionPlacement?: "above" | "below";
|
|
15
|
+
layoutGridColumnSpan: number;
|
|
11
16
|
disabled: boolean;
|
|
17
|
+
className?: string;
|
|
12
18
|
} & {
|
|
13
19
|
[key: string]: any;
|
|
14
20
|
};
|
|
@@ -17,129 +23,42 @@ export type GravityFormData = {
|
|
|
17
23
|
fields: GravityFormsField[];
|
|
18
24
|
title: string;
|
|
19
25
|
description?: string;
|
|
26
|
+
descriptionPlacement?: "above" | "below";
|
|
20
27
|
revisionId: number;
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
pagination?: {
|
|
29
|
+
pages: string[];
|
|
30
|
+
type: string;
|
|
31
|
+
progressbar_complete_text?: string;
|
|
23
32
|
};
|
|
24
|
-
|
|
25
|
-
export type GFTextOptions = {
|
|
26
|
-
placeholder: string;
|
|
27
|
-
size: "small" | "medium" | "large";
|
|
28
|
-
};
|
|
29
|
-
export type GFGenericTextOptions = {
|
|
30
|
-
placeholder: string;
|
|
31
|
-
};
|
|
32
|
-
export type GFSelectOptions = {
|
|
33
|
-
placeholder: string;
|
|
34
|
-
choices: {
|
|
33
|
+
button: {
|
|
35
34
|
text: string;
|
|
36
|
-
value: string;
|
|
37
|
-
}[];
|
|
38
|
-
};
|
|
39
|
-
export type GFAddressData = {
|
|
40
|
-
address1?: string;
|
|
41
|
-
address2?: string;
|
|
42
|
-
city?: string;
|
|
43
|
-
state?: string;
|
|
44
|
-
zip?: string;
|
|
45
|
-
country?: string;
|
|
46
|
-
};
|
|
47
|
-
export type GFAddressOptions = {
|
|
48
|
-
addressType: "international" | "us";
|
|
49
|
-
defaultCountry: string;
|
|
50
|
-
defaultState: string;
|
|
51
|
-
subfields: {
|
|
52
|
-
[K in keyof GFAddressData]: {
|
|
53
|
-
name: K;
|
|
54
|
-
visible: boolean;
|
|
55
|
-
placeholder: string;
|
|
56
|
-
label: string;
|
|
57
|
-
autocomplete: string;
|
|
58
|
-
};
|
|
59
35
|
};
|
|
60
36
|
};
|
|
61
|
-
export type GFNameOptions = {
|
|
62
|
-
subfields: {
|
|
63
|
-
[K in keyof GFNameData]: {
|
|
64
|
-
name: K;
|
|
65
|
-
visible: boolean;
|
|
66
|
-
placeholder: string;
|
|
67
|
-
label: string;
|
|
68
|
-
autocomplete: string;
|
|
69
|
-
choices?: {
|
|
70
|
-
text: string;
|
|
71
|
-
value: string;
|
|
72
|
-
}[];
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
export type GFFileUploadOptions = {
|
|
77
|
-
allowedExtensions: string[];
|
|
78
|
-
multiple: boolean;
|
|
79
|
-
maxFileSize?: number;
|
|
80
|
-
maxFiles?: number;
|
|
81
|
-
};
|
|
82
|
-
export type GFNumberOptions = {
|
|
83
|
-
placeholder: string;
|
|
84
|
-
minRange: number;
|
|
85
|
-
maxRange: number;
|
|
86
|
-
};
|
|
87
|
-
export type GFNameData = {
|
|
88
|
-
prefix?: string;
|
|
89
|
-
first?: string;
|
|
90
|
-
middle?: string;
|
|
91
|
-
last?: string;
|
|
92
|
-
suffix?: string;
|
|
93
|
-
};
|
|
94
|
-
export type GFConsentOptions = {
|
|
95
|
-
checkboxLabel: string;
|
|
96
|
-
};
|
|
97
37
|
export type GFFieldTypes = {
|
|
98
|
-
|
|
99
|
-
textarea: string;
|
|
100
|
-
select: string;
|
|
101
|
-
number: number;
|
|
102
|
-
checkbox: string[];
|
|
103
|
-
radio: string;
|
|
104
|
-
multi_choice: string | string[];
|
|
105
|
-
image_choice: string | string[];
|
|
106
|
-
name: GFNameData;
|
|
107
|
-
date: string;
|
|
108
|
-
time: string;
|
|
109
|
-
phone: string;
|
|
110
|
-
address: GFAddressData;
|
|
111
|
-
website: string;
|
|
112
|
-
email: string;
|
|
113
|
-
fileupload: File | FileList | File[];
|
|
114
|
-
multiselect: string[];
|
|
115
|
-
consent: boolean;
|
|
116
|
-
captcha: any;
|
|
117
|
-
html: void;
|
|
118
|
-
section: void;
|
|
38
|
+
[K in keyof GFBuiltins]: GFBuiltins[K] extends GFFieldTypeSpec<infer TValue, any> ? TValue : never;
|
|
119
39
|
};
|
|
120
40
|
export type GFFieldOptions = {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
email: GFGenericTextOptions;
|
|
136
|
-
fileupload: GFFileUploadOptions;
|
|
137
|
-
multiselect: GFSelectOptions;
|
|
138
|
-
consent: GFConsentOptions;
|
|
41
|
+
[K in keyof GFBuiltins]: GFBuiltins[K] extends GFFieldTypeSpec<any, infer TOptions> ? TOptions : never;
|
|
42
|
+
};
|
|
43
|
+
export type GFFieldProps<TData, TOptions> = GravityFormsFieldState<TData, TOptions> & {
|
|
44
|
+
formComponents: FormComponents;
|
|
45
|
+
Wrapper: (props: Partial<ComponentProps<FormComponents["FieldWrapper"]>> & {
|
|
46
|
+
labelId?: string;
|
|
47
|
+
}) => ReactNode;
|
|
48
|
+
};
|
|
49
|
+
export type GFFieldComponent<TData, TOptions> = (props: GFFieldProps<TData, TOptions>) => ReactNode;
|
|
50
|
+
export type GFFieldTypeSpec<TData, TOptions> = {
|
|
51
|
+
getInitialValue(field: GravityFormsField): TData | undefined;
|
|
52
|
+
getOptions(field: GravityFormsField): TOptions;
|
|
53
|
+
defaultComponent?: NoInfer<GFFieldComponent<TData, TOptions>>;
|
|
54
|
+
appendData?(formData: FormData, field: GravityFormsField, value: TData, key: string): void;
|
|
139
55
|
};
|
|
140
|
-
export type GFFieldComponentProps<K extends
|
|
141
|
-
|
|
56
|
+
export type GFFieldComponentProps<K extends GFFieldTypeName> = GravityFormsFieldState<GFValue<K>, GFOptions<K>>;
|
|
57
|
+
/** Resolves the data type of a Gravity Form field type */
|
|
58
|
+
export type GFValue<TypeName extends GFFieldTypeName> = TypeName extends keyof GFFieldTypes ? GFFieldTypes[TypeName] : any;
|
|
59
|
+
/** Resolves the options of a Gravity Form field type */
|
|
60
|
+
export type GFOptions<TypeName extends GFFieldTypeName> = TypeName extends keyof GFFieldOptions ? GFFieldOptions[TypeName] : {};
|
|
142
61
|
export type GFFieldComponentSet = {
|
|
143
|
-
[
|
|
62
|
+
[TypeName in GFFieldTypeName]?: ComponentType<GravityFormsFieldState<GFValue<TypeName>, TypeName extends keyof GFFieldOptions ? GFFieldOptions[TypeName] : {}>>;
|
|
144
63
|
};
|
|
145
64
|
//# sourceMappingURL=types.d.ts.map
|