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