@01.software/sdk 0.2.0 → 0.2.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.
@@ -17,6 +17,26 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
20
40
 
21
41
  // src/components/RichTextContent/index.tsx
22
42
  import React from "react";
@@ -44,7 +64,678 @@ function RichTextContent({
44
64
  }
45
65
  );
46
66
  }
67
+
68
+ // src/components/FormRenderer/index.tsx
69
+ import React2, { useState, useCallback, useEffect, useRef } from "react";
70
+
71
+ // src/components/FormRenderer/countries.ts
72
+ var COUNTRIES = [
73
+ { value: "AF", label: "Afghanistan" },
74
+ { value: "AX", label: "\xC5land Islands" },
75
+ { value: "AL", label: "Albania" },
76
+ { value: "DZ", label: "Algeria" },
77
+ { value: "AS", label: "American Samoa" },
78
+ { value: "AD", label: "Andorra" },
79
+ { value: "AO", label: "Angola" },
80
+ { value: "AI", label: "Anguilla" },
81
+ { value: "AQ", label: "Antarctica" },
82
+ { value: "AG", label: "Antigua and Barbuda" },
83
+ { value: "AR", label: "Argentina" },
84
+ { value: "AM", label: "Armenia" },
85
+ { value: "AW", label: "Aruba" },
86
+ { value: "AU", label: "Australia" },
87
+ { value: "AT", label: "Austria" },
88
+ { value: "AZ", label: "Azerbaijan" },
89
+ { value: "BS", label: "Bahamas" },
90
+ { value: "BH", label: "Bahrain" },
91
+ { value: "BD", label: "Bangladesh" },
92
+ { value: "BB", label: "Barbados" },
93
+ { value: "BY", label: "Belarus" },
94
+ { value: "BE", label: "Belgium" },
95
+ { value: "BZ", label: "Belize" },
96
+ { value: "BJ", label: "Benin" },
97
+ { value: "BM", label: "Bermuda" },
98
+ { value: "BT", label: "Bhutan" },
99
+ { value: "BO", label: "Bolivia" },
100
+ { value: "BA", label: "Bosnia and Herzegovina" },
101
+ { value: "BW", label: "Botswana" },
102
+ { value: "BV", label: "Bouvet Island" },
103
+ { value: "BR", label: "Brazil" },
104
+ { value: "IO", label: "British Indian Ocean Territory" },
105
+ { value: "BN", label: "Brunei Darussalam" },
106
+ { value: "BG", label: "Bulgaria" },
107
+ { value: "BF", label: "Burkina Faso" },
108
+ { value: "BI", label: "Burundi" },
109
+ { value: "KH", label: "Cambodia" },
110
+ { value: "CM", label: "Cameroon" },
111
+ { value: "CA", label: "Canada" },
112
+ { value: "CV", label: "Cape Verde" },
113
+ { value: "KY", label: "Cayman Islands" },
114
+ { value: "CF", label: "Central African Republic" },
115
+ { value: "TD", label: "Chad" },
116
+ { value: "CL", label: "Chile" },
117
+ { value: "CN", label: "China" },
118
+ { value: "CX", label: "Christmas Island" },
119
+ { value: "CC", label: "Cocos (Keeling) Islands" },
120
+ { value: "CO", label: "Colombia" },
121
+ { value: "KM", label: "Comoros" },
122
+ { value: "CG", label: "Congo" },
123
+ { value: "CD", label: "Congo, Democratic Republic" },
124
+ { value: "CK", label: "Cook Islands" },
125
+ { value: "CR", label: "Costa Rica" },
126
+ { value: "CI", label: "C\xF4te d'Ivoire" },
127
+ { value: "HR", label: "Croatia" },
128
+ { value: "CU", label: "Cuba" },
129
+ { value: "CY", label: "Cyprus" },
130
+ { value: "CZ", label: "Czech Republic" },
131
+ { value: "DK", label: "Denmark" },
132
+ { value: "DJ", label: "Djibouti" },
133
+ { value: "DM", label: "Dominica" },
134
+ { value: "DO", label: "Dominican Republic" },
135
+ { value: "EC", label: "Ecuador" },
136
+ { value: "EG", label: "Egypt" },
137
+ { value: "SV", label: "El Salvador" },
138
+ { value: "GQ", label: "Equatorial Guinea" },
139
+ { value: "ER", label: "Eritrea" },
140
+ { value: "EE", label: "Estonia" },
141
+ { value: "ET", label: "Ethiopia" },
142
+ { value: "FK", label: "Falkland Islands" },
143
+ { value: "FO", label: "Faroe Islands" },
144
+ { value: "FJ", label: "Fiji" },
145
+ { value: "FI", label: "Finland" },
146
+ { value: "FR", label: "France" },
147
+ { value: "GF", label: "French Guiana" },
148
+ { value: "PF", label: "French Polynesia" },
149
+ { value: "TF", label: "French Southern Territories" },
150
+ { value: "GA", label: "Gabon" },
151
+ { value: "GM", label: "Gambia" },
152
+ { value: "GE", label: "Georgia" },
153
+ { value: "DE", label: "Germany" },
154
+ { value: "GH", label: "Ghana" },
155
+ { value: "GI", label: "Gibraltar" },
156
+ { value: "GR", label: "Greece" },
157
+ { value: "GL", label: "Greenland" },
158
+ { value: "GD", label: "Grenada" },
159
+ { value: "GP", label: "Guadeloupe" },
160
+ { value: "GU", label: "Guam" },
161
+ { value: "GT", label: "Guatemala" },
162
+ { value: "GG", label: "Guernsey" },
163
+ { value: "GN", label: "Guinea" },
164
+ { value: "GW", label: "Guinea-Bissau" },
165
+ { value: "GY", label: "Guyana" },
166
+ { value: "HT", label: "Haiti" },
167
+ { value: "VA", label: "Holy See (Vatican)" },
168
+ { value: "HN", label: "Honduras" },
169
+ { value: "HK", label: "Hong Kong" },
170
+ { value: "HU", label: "Hungary" },
171
+ { value: "IS", label: "Iceland" },
172
+ { value: "IN", label: "India" },
173
+ { value: "ID", label: "Indonesia" },
174
+ { value: "IR", label: "Iran" },
175
+ { value: "IQ", label: "Iraq" },
176
+ { value: "IE", label: "Ireland" },
177
+ { value: "IM", label: "Isle of Man" },
178
+ { value: "IL", label: "Israel" },
179
+ { value: "IT", label: "Italy" },
180
+ { value: "JM", label: "Jamaica" },
181
+ { value: "JP", label: "Japan" },
182
+ { value: "JE", label: "Jersey" },
183
+ { value: "JO", label: "Jordan" },
184
+ { value: "KZ", label: "Kazakhstan" },
185
+ { value: "KE", label: "Kenya" },
186
+ { value: "KI", label: "Kiribati" },
187
+ { value: "KP", label: "Korea, North" },
188
+ { value: "KR", label: "Korea, South" },
189
+ { value: "KW", label: "Kuwait" },
190
+ { value: "KG", label: "Kyrgyzstan" },
191
+ { value: "LA", label: "Laos" },
192
+ { value: "LV", label: "Latvia" },
193
+ { value: "LB", label: "Lebanon" },
194
+ { value: "LS", label: "Lesotho" },
195
+ { value: "LR", label: "Liberia" },
196
+ { value: "LY", label: "Libya" },
197
+ { value: "LI", label: "Liechtenstein" },
198
+ { value: "LT", label: "Lithuania" },
199
+ { value: "LU", label: "Luxembourg" },
200
+ { value: "MO", label: "Macao" },
201
+ { value: "MK", label: "North Macedonia" },
202
+ { value: "MG", label: "Madagascar" },
203
+ { value: "MW", label: "Malawi" },
204
+ { value: "MY", label: "Malaysia" },
205
+ { value: "MV", label: "Maldives" },
206
+ { value: "ML", label: "Mali" },
207
+ { value: "MT", label: "Malta" },
208
+ { value: "MH", label: "Marshall Islands" },
209
+ { value: "MQ", label: "Martinique" },
210
+ { value: "MR", label: "Mauritania" },
211
+ { value: "MU", label: "Mauritius" },
212
+ { value: "YT", label: "Mayotte" },
213
+ { value: "MX", label: "Mexico" },
214
+ { value: "FM", label: "Micronesia" },
215
+ { value: "MD", label: "Moldova" },
216
+ { value: "MC", label: "Monaco" },
217
+ { value: "MN", label: "Mongolia" },
218
+ { value: "ME", label: "Montenegro" },
219
+ { value: "MS", label: "Montserrat" },
220
+ { value: "MA", label: "Morocco" },
221
+ { value: "MZ", label: "Mozambique" },
222
+ { value: "MM", label: "Myanmar" },
223
+ { value: "NA", label: "Namibia" },
224
+ { value: "NR", label: "Nauru" },
225
+ { value: "NP", label: "Nepal" },
226
+ { value: "NL", label: "Netherlands" },
227
+ { value: "NC", label: "New Caledonia" },
228
+ { value: "NZ", label: "New Zealand" },
229
+ { value: "NI", label: "Nicaragua" },
230
+ { value: "NE", label: "Niger" },
231
+ { value: "NG", label: "Nigeria" },
232
+ { value: "NU", label: "Niue" },
233
+ { value: "NF", label: "Norfolk Island" },
234
+ { value: "MP", label: "Northern Mariana Islands" },
235
+ { value: "NO", label: "Norway" },
236
+ { value: "OM", label: "Oman" },
237
+ { value: "PK", label: "Pakistan" },
238
+ { value: "PW", label: "Palau" },
239
+ { value: "PS", label: "Palestine" },
240
+ { value: "PA", label: "Panama" },
241
+ { value: "PG", label: "Papua New Guinea" },
242
+ { value: "PY", label: "Paraguay" },
243
+ { value: "PE", label: "Peru" },
244
+ { value: "PH", label: "Philippines" },
245
+ { value: "PN", label: "Pitcairn" },
246
+ { value: "PL", label: "Poland" },
247
+ { value: "PT", label: "Portugal" },
248
+ { value: "PR", label: "Puerto Rico" },
249
+ { value: "QA", label: "Qatar" },
250
+ { value: "RE", label: "R\xE9union" },
251
+ { value: "RO", label: "Romania" },
252
+ { value: "RU", label: "Russian Federation" },
253
+ { value: "RW", label: "Rwanda" },
254
+ { value: "BL", label: "Saint Barth\xE9lemy" },
255
+ { value: "SH", label: "Saint Helena" },
256
+ { value: "KN", label: "Saint Kitts and Nevis" },
257
+ { value: "LC", label: "Saint Lucia" },
258
+ { value: "MF", label: "Saint Martin" },
259
+ { value: "PM", label: "Saint Pierre and Miquelon" },
260
+ { value: "VC", label: "Saint Vincent and the Grenadines" },
261
+ { value: "WS", label: "Samoa" },
262
+ { value: "SM", label: "San Marino" },
263
+ { value: "ST", label: "Sao Tome and Principe" },
264
+ { value: "SA", label: "Saudi Arabia" },
265
+ { value: "SN", label: "Senegal" },
266
+ { value: "RS", label: "Serbia" },
267
+ { value: "SC", label: "Seychelles" },
268
+ { value: "SL", label: "Sierra Leone" },
269
+ { value: "SG", label: "Singapore" },
270
+ { value: "SX", label: "Sint Maarten" },
271
+ { value: "SK", label: "Slovakia" },
272
+ { value: "SI", label: "Slovenia" },
273
+ { value: "SB", label: "Solomon Islands" },
274
+ { value: "SO", label: "Somalia" },
275
+ { value: "ZA", label: "South Africa" },
276
+ { value: "GS", label: "South Georgia" },
277
+ { value: "SS", label: "South Sudan" },
278
+ { value: "ES", label: "Spain" },
279
+ { value: "LK", label: "Sri Lanka" },
280
+ { value: "SD", label: "Sudan" },
281
+ { value: "SR", label: "Suriname" },
282
+ { value: "SJ", label: "Svalbard and Jan Mayen" },
283
+ { value: "SZ", label: "Eswatini" },
284
+ { value: "SE", label: "Sweden" },
285
+ { value: "CH", label: "Switzerland" },
286
+ { value: "SY", label: "Syria" },
287
+ { value: "TW", label: "Taiwan" },
288
+ { value: "TJ", label: "Tajikistan" },
289
+ { value: "TZ", label: "Tanzania" },
290
+ { value: "TH", label: "Thailand" },
291
+ { value: "TL", label: "Timor-Leste" },
292
+ { value: "TG", label: "Togo" },
293
+ { value: "TK", label: "Tokelau" },
294
+ { value: "TO", label: "Tonga" },
295
+ { value: "TT", label: "Trinidad and Tobago" },
296
+ { value: "TN", label: "Tunisia" },
297
+ { value: "TR", label: "Turkey" },
298
+ { value: "TM", label: "Turkmenistan" },
299
+ { value: "TC", label: "Turks and Caicos Islands" },
300
+ { value: "TV", label: "Tuvalu" },
301
+ { value: "UG", label: "Uganda" },
302
+ { value: "UA", label: "Ukraine" },
303
+ { value: "AE", label: "United Arab Emirates" },
304
+ { value: "GB", label: "United Kingdom" },
305
+ { value: "US", label: "United States" },
306
+ { value: "UM", label: "U.S. Minor Outlying Islands" },
307
+ { value: "UY", label: "Uruguay" },
308
+ { value: "UZ", label: "Uzbekistan" },
309
+ { value: "VU", label: "Vanuatu" },
310
+ { value: "VE", label: "Venezuela" },
311
+ { value: "VN", label: "Vietnam" },
312
+ { value: "VG", label: "Virgin Islands, British" },
313
+ { value: "VI", label: "Virgin Islands, U.S." },
314
+ { value: "WF", label: "Wallis and Futuna" },
315
+ { value: "EH", label: "Western Sahara" },
316
+ { value: "YE", label: "Yemen" },
317
+ { value: "ZM", label: "Zambia" },
318
+ { value: "ZW", label: "Zimbabwe" }
319
+ ];
320
+ var US_STATES = [
321
+ { value: "AL", label: "Alabama" },
322
+ { value: "AK", label: "Alaska" },
323
+ { value: "AZ", label: "Arizona" },
324
+ { value: "AR", label: "Arkansas" },
325
+ { value: "CA", label: "California" },
326
+ { value: "CO", label: "Colorado" },
327
+ { value: "CT", label: "Connecticut" },
328
+ { value: "DE", label: "Delaware" },
329
+ { value: "FL", label: "Florida" },
330
+ { value: "GA", label: "Georgia" },
331
+ { value: "HI", label: "Hawaii" },
332
+ { value: "ID", label: "Idaho" },
333
+ { value: "IL", label: "Illinois" },
334
+ { value: "IN", label: "Indiana" },
335
+ { value: "IA", label: "Iowa" },
336
+ { value: "KS", label: "Kansas" },
337
+ { value: "KY", label: "Kentucky" },
338
+ { value: "LA", label: "Louisiana" },
339
+ { value: "ME", label: "Maine" },
340
+ { value: "MD", label: "Maryland" },
341
+ { value: "MA", label: "Massachusetts" },
342
+ { value: "MI", label: "Michigan" },
343
+ { value: "MN", label: "Minnesota" },
344
+ { value: "MS", label: "Mississippi" },
345
+ { value: "MO", label: "Missouri" },
346
+ { value: "MT", label: "Montana" },
347
+ { value: "NE", label: "Nebraska" },
348
+ { value: "NV", label: "Nevada" },
349
+ { value: "NH", label: "New Hampshire" },
350
+ { value: "NJ", label: "New Jersey" },
351
+ { value: "NM", label: "New Mexico" },
352
+ { value: "NY", label: "New York" },
353
+ { value: "NC", label: "North Carolina" },
354
+ { value: "ND", label: "North Dakota" },
355
+ { value: "OH", label: "Ohio" },
356
+ { value: "OK", label: "Oklahoma" },
357
+ { value: "OR", label: "Oregon" },
358
+ { value: "PA", label: "Pennsylvania" },
359
+ { value: "RI", label: "Rhode Island" },
360
+ { value: "SC", label: "South Carolina" },
361
+ { value: "SD", label: "South Dakota" },
362
+ { value: "TN", label: "Tennessee" },
363
+ { value: "TX", label: "Texas" },
364
+ { value: "UT", label: "Utah" },
365
+ { value: "VT", label: "Vermont" },
366
+ { value: "VA", label: "Virginia" },
367
+ { value: "WA", label: "Washington" },
368
+ { value: "WV", label: "West Virginia" },
369
+ { value: "WI", label: "Wisconsin" },
370
+ { value: "WY", label: "Wyoming" },
371
+ { value: "DC", label: "District of Columbia" }
372
+ ];
373
+
374
+ // src/components/FormRenderer/index.tsx
375
+ function toSubmissionData(values) {
376
+ return Object.entries(values).map(([field, value]) => ({
377
+ field,
378
+ value: String(value)
379
+ }));
380
+ }
381
+ function getInitialValues(fields) {
382
+ var _a, _b;
383
+ const values = {};
384
+ if (!fields) return values;
385
+ for (const field of fields) {
386
+ if (field.blockType === "message") continue;
387
+ if (field.blockType === "checkbox") {
388
+ values[field.name] = (_a = field.defaultValue) != null ? _a : false;
389
+ } else if (field.blockType === "number" || field.blockType === "text" || field.blockType === "textarea" || field.blockType === "select") {
390
+ values[field.name] = (_b = field.defaultValue) != null ? _b : "";
391
+ } else {
392
+ values[field.name] = "";
393
+ }
394
+ }
395
+ return values;
396
+ }
397
+ function FormRenderer({
398
+ form,
399
+ onSubmit,
400
+ className,
401
+ fieldClassName,
402
+ buttonClassName,
403
+ renderField,
404
+ renderMessage,
405
+ renderButton
406
+ }) {
407
+ var _a;
408
+ const [values, setValues] = useState(
409
+ () => getInitialValues(form.fields)
410
+ );
411
+ const [isSubmitting, setIsSubmitting] = useState(false);
412
+ const submittingRef = useRef(false);
413
+ useEffect(() => {
414
+ setValues(getInitialValues(form.fields));
415
+ }, [form.id]);
416
+ const handleChange = useCallback(
417
+ (name, value) => {
418
+ setValues((prev) => __spreadProps(__spreadValues({}, prev), { [name]: value }));
419
+ },
420
+ []
421
+ );
422
+ const handleSubmit = (e) => __async(null, null, function* () {
423
+ e.preventDefault();
424
+ if (submittingRef.current) return;
425
+ submittingRef.current = true;
426
+ setIsSubmitting(true);
427
+ try {
428
+ yield onSubmit(values);
429
+ } finally {
430
+ submittingRef.current = false;
431
+ setIsSubmitting(false);
432
+ }
433
+ });
434
+ const wrapField = (field, style, input) => {
435
+ var _a2, _b;
436
+ const context = {
437
+ value: (_a2 = values[field.name]) != null ? _a2 : "",
438
+ onChange: (v) => handleChange(field.name, v)
439
+ };
440
+ const el = /* @__PURE__ */ React2.createElement(
441
+ "div",
442
+ {
443
+ key: (_b = field.id) != null ? _b : field.name,
444
+ className: fieldClassName,
445
+ style
446
+ },
447
+ field.label && /* @__PURE__ */ React2.createElement("label", { htmlFor: field.name }, field.label),
448
+ input
449
+ );
450
+ return renderField ? renderField(field, context, el) : el;
451
+ };
452
+ const renderSelectField = (field, style, options, placeholder) => {
453
+ var _a2, _b;
454
+ return wrapField(
455
+ field,
456
+ style,
457
+ /* @__PURE__ */ React2.createElement(
458
+ "select",
459
+ {
460
+ id: field.name,
461
+ name: field.name,
462
+ value: String((_a2 = values[field.name]) != null ? _a2 : ""),
463
+ required: (_b = field.required) != null ? _b : false,
464
+ onChange: (e) => handleChange(field.name, e.target.value)
465
+ },
466
+ /* @__PURE__ */ React2.createElement("option", { value: "" }, placeholder || "Select\u2026"),
467
+ options.map((opt) => /* @__PURE__ */ React2.createElement("option", { key: opt.value, value: opt.value }, opt.label))
468
+ )
469
+ );
470
+ };
471
+ const renderFieldElement = (field) => {
472
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
473
+ const style = field.blockType !== "message" && field.width ? { width: `${field.width}%` } : void 0;
474
+ switch (field.blockType) {
475
+ case "text":
476
+ return wrapField(
477
+ field,
478
+ style,
479
+ /* @__PURE__ */ React2.createElement(
480
+ "input",
481
+ {
482
+ type: "text",
483
+ id: field.name,
484
+ name: field.name,
485
+ value: String((_a2 = values[field.name]) != null ? _a2 : ""),
486
+ placeholder: (_b = field.placeholder) != null ? _b : void 0,
487
+ required: (_c = field.required) != null ? _c : false,
488
+ onChange: (e) => handleChange(field.name, e.target.value)
489
+ }
490
+ )
491
+ );
492
+ case "email":
493
+ return wrapField(
494
+ field,
495
+ style,
496
+ /* @__PURE__ */ React2.createElement(
497
+ "input",
498
+ {
499
+ type: "email",
500
+ id: field.name,
501
+ name: field.name,
502
+ value: String((_d = values[field.name]) != null ? _d : ""),
503
+ required: (_e = field.required) != null ? _e : false,
504
+ onChange: (e) => handleChange(field.name, e.target.value)
505
+ }
506
+ )
507
+ );
508
+ case "number":
509
+ return wrapField(
510
+ field,
511
+ style,
512
+ /* @__PURE__ */ React2.createElement(
513
+ "input",
514
+ {
515
+ type: "number",
516
+ id: field.name,
517
+ name: field.name,
518
+ value: String((_f = values[field.name]) != null ? _f : ""),
519
+ required: (_g = field.required) != null ? _g : false,
520
+ onChange: (e) => {
521
+ const v = e.target.value;
522
+ if (v === "") return handleChange(field.name, "");
523
+ const n = Number(v);
524
+ if (Number.isFinite(n)) handleChange(field.name, n);
525
+ }
526
+ }
527
+ )
528
+ );
529
+ case "textarea":
530
+ return wrapField(
531
+ field,
532
+ style,
533
+ /* @__PURE__ */ React2.createElement(
534
+ "textarea",
535
+ {
536
+ id: field.name,
537
+ name: field.name,
538
+ value: String((_h = values[field.name]) != null ? _h : ""),
539
+ required: (_i = field.required) != null ? _i : false,
540
+ onChange: (e) => handleChange(field.name, e.target.value)
541
+ }
542
+ )
543
+ );
544
+ case "checkbox": {
545
+ const context = {
546
+ value: (_j = values[field.name]) != null ? _j : false,
547
+ onChange: (v) => handleChange(field.name, v)
548
+ };
549
+ const el = /* @__PURE__ */ React2.createElement(
550
+ "div",
551
+ {
552
+ key: (_k = field.id) != null ? _k : field.name,
553
+ className: fieldClassName,
554
+ style
555
+ },
556
+ /* @__PURE__ */ React2.createElement("label", { htmlFor: field.name }, /* @__PURE__ */ React2.createElement(
557
+ "input",
558
+ {
559
+ type: "checkbox",
560
+ id: field.name,
561
+ name: field.name,
562
+ checked: Boolean(values[field.name]),
563
+ required: (_l = field.required) != null ? _l : false,
564
+ onChange: (e) => handleChange(field.name, e.target.checked)
565
+ }
566
+ ), field.label && /* @__PURE__ */ React2.createElement("span", null, field.label))
567
+ );
568
+ return renderField ? renderField(field, context, el) : el;
569
+ }
570
+ case "select":
571
+ return renderSelectField(
572
+ field,
573
+ style,
574
+ (_m = field.options) != null ? _m : [],
575
+ (_n = field.placeholder) != null ? _n : void 0
576
+ );
577
+ case "country":
578
+ return renderSelectField(field, style, COUNTRIES);
579
+ case "state":
580
+ return renderSelectField(field, style, US_STATES);
581
+ case "message":
582
+ if (renderMessage && field.message) {
583
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, { key: (_p = (_o = field.id) != null ? _o : field.blockName) != null ? _p : "message" }, renderMessage(field.message));
584
+ }
585
+ return null;
586
+ default:
587
+ return null;
588
+ }
589
+ };
590
+ const buttonLabel = form.submitButtonLabel || "Submit";
591
+ return /* @__PURE__ */ React2.createElement("form", { onSubmit: handleSubmit, className }, (_a = form.fields) == null ? void 0 : _a.map((field) => renderFieldElement(field)), renderButton ? renderButton({ isSubmitting, label: buttonLabel }) : /* @__PURE__ */ React2.createElement(
592
+ "button",
593
+ {
594
+ type: "submit",
595
+ disabled: isSubmitting,
596
+ className: buttonClassName
597
+ },
598
+ buttonLabel
599
+ ));
600
+ }
601
+
602
+ // src/components/Image/index.tsx
603
+ import React3, { useCallback as useCallback2, useState as useState2 } from "react";
604
+
605
+ // src/utils/image.ts
606
+ var IMAGE_SIZES = [384, 768, 1536];
607
+ function getImageSrcSet(image) {
608
+ const parts = [];
609
+ const sizes = image.sizes;
610
+ if (sizes) {
611
+ for (const size of IMAGE_SIZES) {
612
+ const entry = sizes[String(size)];
613
+ if ((entry == null ? void 0 : entry.url) && entry.width) {
614
+ parts.push(`${entry.url} ${entry.width}w`);
615
+ }
616
+ }
617
+ }
618
+ if (image.url && image.width) {
619
+ parts.push(`${image.url} ${image.width}w`);
620
+ }
621
+ return parts.join(", ");
622
+ }
623
+ function getImagePlaceholderStyle(image, options) {
624
+ var _a, _b, _c;
625
+ const type = (_a = options == null ? void 0 : options.type) != null ? _a : "blur";
626
+ const paletteColor = (_b = options == null ? void 0 : options.paletteColor) != null ? _b : "muted";
627
+ if (type === "none") return {};
628
+ const color = (_c = image.palette) == null ? void 0 : _c[paletteColor];
629
+ if (type === "blur") {
630
+ const lqip = image.lqip;
631
+ if (lqip) {
632
+ return {
633
+ backgroundImage: `url(${lqip})`,
634
+ backgroundSize: "cover",
635
+ backgroundPosition: "center"
636
+ };
637
+ }
638
+ if (color) {
639
+ return { backgroundColor: color };
640
+ }
641
+ return {};
642
+ }
643
+ if (color) {
644
+ return { backgroundColor: color };
645
+ }
646
+ return {};
647
+ }
648
+
649
+ // src/components/Image/index.tsx
650
+ function Image({
651
+ image,
652
+ width,
653
+ dpr = 1,
654
+ placeholder = "blur",
655
+ className,
656
+ style,
657
+ imgClassName,
658
+ imgStyle,
659
+ sizes,
660
+ loading = "lazy",
661
+ onLoad,
662
+ objectFit = "cover"
663
+ }) {
664
+ var _a, _b;
665
+ const [loaded, setLoaded] = useState2(false);
666
+ const aspectRatio = image.width && image.height ? `${image.width} / ${image.height}` : void 0;
667
+ const srcSet = getImageSrcSet(image);
668
+ const src = (_a = image.url) != null ? _a : void 0;
669
+ const placeholderStyle = getImagePlaceholderStyle(image, {
670
+ type: placeholder
671
+ });
672
+ const hasLqip = placeholder === "blur" && !!image.lqip;
673
+ const hasColorPlaceholder = !hasLqip && Object.keys(placeholderStyle).length > 0;
674
+ const imgRef = useCallback2(
675
+ (node) => {
676
+ if (node && node.complete && node.naturalWidth > 0) {
677
+ setLoaded(true);
678
+ onLoad == null ? void 0 : onLoad();
679
+ }
680
+ },
681
+ [onLoad]
682
+ );
683
+ const handleLoad = useCallback2(() => {
684
+ setLoaded(true);
685
+ onLoad == null ? void 0 : onLoad();
686
+ }, [onLoad]);
687
+ const containerStyle = __spreadValues(__spreadValues(__spreadValues({
688
+ position: "relative",
689
+ overflow: "hidden"
690
+ }, aspectRatio ? { aspectRatio } : {}), hasColorPlaceholder ? placeholderStyle : {}), style);
691
+ const imgBase = {
692
+ display: "block",
693
+ width: "100%",
694
+ height: "100%",
695
+ objectFit
696
+ };
697
+ const mainImgStyle = __spreadValues(__spreadProps(__spreadValues({}, imgBase), {
698
+ opacity: loaded ? 1 : 0,
699
+ transition: "opacity 0.3s ease"
700
+ }), imgStyle);
701
+ const lqipStyle = __spreadProps(__spreadValues({}, imgBase), {
702
+ position: "absolute",
703
+ top: 0,
704
+ left: 0,
705
+ filter: "blur(20px)",
706
+ transform: "scale(1.1)",
707
+ opacity: loaded ? 0 : 1,
708
+ transition: "opacity 0.3s ease",
709
+ pointerEvents: "none"
710
+ });
711
+ return /* @__PURE__ */ React3.createElement("div", { className, style: containerStyle }, hasLqip && /* @__PURE__ */ React3.createElement(
712
+ "img",
713
+ {
714
+ "aria-hidden": true,
715
+ alt: "",
716
+ src: image.lqip,
717
+ style: lqipStyle
718
+ }
719
+ ), /* @__PURE__ */ React3.createElement(
720
+ "img",
721
+ {
722
+ ref: imgRef,
723
+ alt: (_b = image.alt) != null ? _b : "",
724
+ src,
725
+ srcSet: srcSet || void 0,
726
+ sizes,
727
+ width: width ? width * dpr : void 0,
728
+ loading,
729
+ onLoad: handleLoad,
730
+ className: imgClassName,
731
+ style: mainImgStyle
732
+ }
733
+ ));
734
+ }
47
735
  export {
48
- RichTextContent
736
+ FormRenderer,
737
+ Image,
738
+ RichTextContent,
739
+ toSubmissionData
49
740
  };
50
741
  //# sourceMappingURL=components.js.map