@ez-gform/codegen 0.1.0

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/dist/index.js ADDED
@@ -0,0 +1,582 @@
1
+ // src/generate-html.ts
2
+ import { formUrls } from "@ez-gform/core";
3
+ var escapeHtml = (value) => {
4
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
5
+ };
6
+ var attr = (name, value) => {
7
+ return `${name}="${escapeHtml(value)}"`;
8
+ };
9
+ var renderChoiceInputs = (question, inputType) => {
10
+ const options = question.options ?? [];
11
+ const rows = options.map((option) => {
12
+ if (option.isOther) {
13
+ return [
14
+ `<label><input type="${inputType}" ${attr("name", question.entryId)} value="__other_option__"> Other:</label>`,
15
+ `<input type="text" ${attr("name", `${question.entryId}.other_option_response`)}>`
16
+ ].join("\n ");
17
+ }
18
+ return `<label><input type="${inputType}" ${attr("name", question.entryId)} ${attr("value", option.value)}> ${escapeHtml(option.value)}</label>`;
19
+ });
20
+ return rows.join("\n ");
21
+ };
22
+ var renderGrid = (question) => {
23
+ const inputType = question.type === "checkbox_grid" ? "checkbox" : "radio";
24
+ const columns = question.options ?? [];
25
+ const rows = (question.rows ?? []).map((row) => {
26
+ const cells = columns.map((col) => {
27
+ return `<td><input type="${inputType}" ${attr("name", row.entryId)} ${attr("value", col.value)}></td>`;
28
+ }).join("");
29
+ return ` <tr><th>${escapeHtml(row.label)}</th>${cells}</tr>`;
30
+ }).join("\n");
31
+ return `<table>
32
+ ${rows}
33
+ </table>`;
34
+ };
35
+ var renderQuestion = (question) => {
36
+ const label = `<label>${escapeHtml(question.title)}${question.required ? " *" : ""}</label>`;
37
+ const requiredAttr = question.required ? " required" : "";
38
+ switch (question.type) {
39
+ case "short_answer":
40
+ return `${label}
41
+ <input type="text" ${attr("name", question.entryId)}${requiredAttr}>`;
42
+ case "paragraph":
43
+ return `${label}
44
+ <textarea ${attr("name", question.entryId)}${requiredAttr}></textarea>`;
45
+ case "multiple_choice":
46
+ return `${label}
47
+ ${renderChoiceInputs(question, "radio")}`;
48
+ case "checkboxes":
49
+ return `${label}
50
+ ${renderChoiceInputs(question, "checkbox")}`;
51
+ case "dropdown": {
52
+ const options = (question.options ?? []).map((option) => {
53
+ return ` <option ${attr("value", option.value)}>${escapeHtml(option.value)}</option>`;
54
+ }).join("\n");
55
+ return `${label}
56
+ <select ${attr("name", question.entryId)}${requiredAttr}>
57
+ ${options}
58
+ </select>`;
59
+ }
60
+ case "linear_scale": {
61
+ const min = question.scale?.min ?? 1;
62
+ const max = question.scale?.max ?? 5;
63
+ const inputs = [];
64
+ for (let value = min; value <= max; value++) {
65
+ inputs.push(
66
+ `<label><input type="radio" ${attr("name", question.entryId)} ${attr("value", String(value))}> ${value}</label>`
67
+ );
68
+ }
69
+ return `${label}
70
+ ${inputs.join("\n")}`;
71
+ }
72
+ case "grid":
73
+ case "checkbox_grid":
74
+ return `${label}
75
+ ${renderGrid(question)}`;
76
+ case "date": {
77
+ const inputs = [];
78
+ if (question.date?.includeYear !== false) {
79
+ inputs.push(
80
+ `<input type="number" ${attr("name", `${question.entryId}_year`)} placeholder="Year">`
81
+ );
82
+ }
83
+ inputs.push(
84
+ `<input type="number" ${attr("name", `${question.entryId}_month`)} placeholder="Month">`
85
+ );
86
+ inputs.push(
87
+ `<input type="number" ${attr("name", `${question.entryId}_day`)} placeholder="Day">`
88
+ );
89
+ if (question.date?.includeTime) {
90
+ inputs.push(
91
+ `<input type="number" ${attr("name", `${question.entryId}_hour`)} placeholder="Hour">`
92
+ );
93
+ inputs.push(
94
+ `<input type="number" ${attr("name", `${question.entryId}_minute`)} placeholder="Minute">`
95
+ );
96
+ }
97
+ return `${label}
98
+ ${inputs.join("\n")}`;
99
+ }
100
+ case "time":
101
+ return `${label}
102
+ <input type="number" ${attr("name", `${question.entryId}_hour`)} placeholder="Hour">
103
+ <input type="number" ${attr("name", `${question.entryId}_minute`)} placeholder="Minute">`;
104
+ case "file_upload":
105
+ return `${label}
106
+ <!-- file_upload is not supported by the Forms API without sign-in; no input rendered -->`;
107
+ default:
108
+ return label;
109
+ }
110
+ };
111
+ var generateHtmlForm = (schema) => {
112
+ const { formResponse } = formUrls(schema.formId || "REPLACE_WITH_FORM_ID");
113
+ const body = schema.questions.map(renderQuestion).join("\n\n");
114
+ const hiddenFields = [];
115
+ if (schema.multiPage) {
116
+ hiddenFields.push(
117
+ `<input type="hidden" ${attr("name", "fbzx")} ${attr("value", schema.fbzx ?? "")}>`
118
+ );
119
+ }
120
+ return `<!-- ${escapeHtml(schema.title)} -->
121
+ <form action="${escapeHtml(formResponse)}" method="POST">
122
+ ${hiddenFields.join("\n")}
123
+ ${body}
124
+
125
+ <button type="submit">Submit</button>
126
+ </form>
127
+ `;
128
+ };
129
+
130
+ // src/names.ts
131
+ var splitWords = (input) => {
132
+ return input.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/[^a-zA-Z0-9]+/g, " ").trim().split(/\s+/).filter((word) => {
133
+ return word.length > 0;
134
+ });
135
+ };
136
+ var toPascalCase = (input) => {
137
+ const words = splitWords(input);
138
+ const pascal = words.map((word) => {
139
+ const lower = word.toLowerCase();
140
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
141
+ }).join("");
142
+ return pascal.length > 0 ? pascal : "Form";
143
+ };
144
+ var RESERVED_WORDS = /* @__PURE__ */ new Set([
145
+ "break",
146
+ "case",
147
+ "catch",
148
+ "class",
149
+ "const",
150
+ "continue",
151
+ "debugger",
152
+ "default",
153
+ "delete",
154
+ "do",
155
+ "else",
156
+ "export",
157
+ "extends",
158
+ "finally",
159
+ "for",
160
+ "function",
161
+ "if",
162
+ "import",
163
+ "in",
164
+ "instanceof",
165
+ "new",
166
+ "return",
167
+ "super",
168
+ "switch",
169
+ "this",
170
+ "throw",
171
+ "try",
172
+ "typeof",
173
+ "var",
174
+ "void",
175
+ "while",
176
+ "with",
177
+ "enum",
178
+ "implements",
179
+ "interface",
180
+ "let",
181
+ "package",
182
+ "private",
183
+ "protected",
184
+ "public",
185
+ "static",
186
+ "yield",
187
+ "await",
188
+ "null",
189
+ "true",
190
+ "false"
191
+ ]);
192
+ var toIdentifier = (input) => {
193
+ const words = splitWords(input);
194
+ if (words.length === 0) return "Form";
195
+ const [first, ...rest] = words;
196
+ const camel = first.toLowerCase() + rest.map((word) => {
197
+ const lower = word.toLowerCase();
198
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
199
+ }).join("");
200
+ const prefixed = /^[0-9]/.test(camel) ? `_${camel}` : camel;
201
+ return RESERVED_WORDS.has(prefixed) ? `${prefixed}_` : prefixed;
202
+ };
203
+
204
+ // src/generate-react.ts
205
+ var JSX_TEXT_ESCAPES = {
206
+ "&": "&amp;",
207
+ "<": "&lt;",
208
+ ">": "&gt;",
209
+ "{": "&#123;",
210
+ "}": "&#125;"
211
+ };
212
+ var jsxEscape = (value) => {
213
+ return value.replace(/[&<>{}]/g, (ch) => {
214
+ return JSX_TEXT_ESCAPES[ch];
215
+ });
216
+ };
217
+ var q = (value) => {
218
+ return JSON.stringify(value);
219
+ };
220
+ var hasOtherOption = (question) => {
221
+ return question.options?.some((option) => {
222
+ return option.isOther;
223
+ }) ?? false;
224
+ };
225
+ var renderShortText = (question, multiline) => {
226
+ const tag = multiline ? "textarea" : "input";
227
+ const typeAttr = multiline ? "" : ' type="text"';
228
+ return `<${tag}${typeAttr} {...form.register(${q(question.entryId)})}${question.required ? " required" : ""} />`;
229
+ };
230
+ var renderRadioGroup = (question) => {
231
+ const entryId = q(question.entryId);
232
+ const options = (question.options ?? []).map((option) => {
233
+ if (option.isOther) {
234
+ return ` <label>
235
+ <input
236
+ type="radio"
237
+ name={form.register(${entryId}).name}
238
+ checked={typeof form.values[${entryId}] === "object"}
239
+ onChange={() => form.setValue(${entryId}, { other: "" })}
240
+ />
241
+ Other:
242
+ <input
243
+ type="text"
244
+ onChange={(e) => form.setValue(${entryId}, { other: e.target.value })}
245
+ />
246
+ </label>`;
247
+ }
248
+ const value = q(option.value);
249
+ return ` <label>
250
+ <input
251
+ type="radio"
252
+ name={form.register(${entryId}).name}
253
+ value={${value}}
254
+ checked={form.register(${entryId}).value === ${value}}
255
+ onChange={() => form.setValue(${entryId}, ${value})}
256
+ />
257
+ ${jsxEscape(option.value)}
258
+ </label>`;
259
+ }).join("\n");
260
+ return `<div role="radiogroup">
261
+ ${options}
262
+ </div>`;
263
+ };
264
+ var renderSelect = (question) => {
265
+ const options = (question.options ?? []).map((option) => {
266
+ return ` <option value={${q(option.value)}}>${jsxEscape(option.value)}</option>`;
267
+ }).join("\n");
268
+ return `<select {...form.register(${q(question.entryId)})}${question.required ? " required" : ""}>
269
+ <option value="">Select\u2026</option>
270
+ ${options}
271
+ </select>`;
272
+ };
273
+ var renderCheckboxGroup = (question) => {
274
+ const entryId = q(question.entryId);
275
+ const options = (question.options ?? []).map((option) => {
276
+ if (option.isOther) {
277
+ return ` <label>
278
+ <input
279
+ type="checkbox"
280
+ onChange={(e) => form.setValue(${entryId}, e.target.checked ? { other: "" } : undefined)}
281
+ />
282
+ Other:
283
+ <input
284
+ type="text"
285
+ onChange={(e) => form.setValue(${entryId}, { other: e.target.value })}
286
+ />
287
+ </label>`;
288
+ }
289
+ const value = q(option.value);
290
+ return ` <label>
291
+ <input type="checkbox" {...form.registerCheckbox(${entryId}, ${value})} />
292
+ ${jsxEscape(option.value)}
293
+ </label>`;
294
+ }).join("\n");
295
+ return `<div>
296
+ ${options}
297
+ </div>`;
298
+ };
299
+ var renderLinearScale = (question) => {
300
+ const entryId = q(question.entryId);
301
+ const min = question.scale?.min ?? 1;
302
+ const max = question.scale?.max ?? 5;
303
+ const items = [];
304
+ for (let value = min; value <= max; value++) {
305
+ items.push(` <label>
306
+ <input
307
+ type="radio"
308
+ name={form.register(${entryId}).name}
309
+ checked={form.register(${entryId}).value === ${q(String(value))}}
310
+ onChange={() => form.setValue(${entryId}, ${value})}
311
+ />
312
+ ${value}
313
+ </label>`);
314
+ }
315
+ const lowLabel = question.scale?.lowLabel;
316
+ const highLabel = question.scale?.highLabel;
317
+ return `<div role="radiogroup">
318
+ ${lowLabel ? `<span>${jsxEscape(lowLabel)}</span>` : ""}
319
+ ${items.join("\n")}
320
+ ${highLabel ? `<span>${jsxEscape(highLabel)}</span>` : ""}
321
+ </div>`;
322
+ };
323
+ var renderGrid2 = (question) => {
324
+ const isCheckbox = question.type === "checkbox_grid";
325
+ const columns = question.options ?? [];
326
+ const headerCells = columns.map((col) => {
327
+ return `<th key={${q(col.value)}}>${jsxEscape(col.value)}</th>`;
328
+ }).join("\n ");
329
+ const rows = (question.rows ?? []).map((row) => {
330
+ const entryId = q(row.entryId);
331
+ const cells = columns.map((col) => {
332
+ const value = q(col.value);
333
+ if (isCheckbox) {
334
+ return `<td key={${value}}><input type="checkbox" {...form.registerCheckbox(${entryId}, ${value})} /></td>`;
335
+ }
336
+ return `<td key={${value}}>
337
+ <input
338
+ type="radio"
339
+ name={form.register(${entryId}).name}
340
+ checked={form.register(${entryId}).value === ${value}}
341
+ onChange={() => form.setValue(${entryId}, ${value})}
342
+ />
343
+ </td>`;
344
+ }).join("\n ");
345
+ return ` <tr>
346
+ <th>${jsxEscape(row.label)}</th>
347
+ ${cells}
348
+ </tr>`;
349
+ }).join("\n");
350
+ return `<table>
351
+ <thead>
352
+ <tr>
353
+ <th />
354
+ ${headerCells}
355
+ </tr>
356
+ </thead>
357
+ <tbody>
358
+ ${rows}
359
+ </tbody>
360
+ </table>`;
361
+ };
362
+ var renderDate = (question) => {
363
+ const entryId = q(question.entryId);
364
+ return `<input
365
+ type="date"
366
+ required={${question.required ? "true" : "false"}}
367
+ onChange={(e) => {
368
+ const parts = e.target.value.split("-").map(Number);
369
+ const [year, month, day] = parts;
370
+ if (month === undefined || day === undefined) return;
371
+ form.setValue(${entryId}, { year, month, day });
372
+ }}
373
+ />`;
374
+ };
375
+ var renderTime = (question) => {
376
+ const entryId = q(question.entryId);
377
+ return `<input
378
+ type="time"
379
+ required={${question.required ? "true" : "false"}}
380
+ onChange={(e) => {
381
+ const parts = e.target.value.split(":").map(Number);
382
+ const [hour, minute] = parts;
383
+ if (hour === undefined || minute === undefined) return;
384
+ form.setValue(${entryId}, { hour, minute });
385
+ }}
386
+ />`;
387
+ };
388
+ var renderQuestion2 = (question) => {
389
+ const label = `<label>${jsxEscape(question.title)}${question.required ? " *" : ""}</label>`;
390
+ const description = question.description ? `
391
+ <p>${jsxEscape(question.description)}</p>` : "";
392
+ let field;
393
+ switch (question.type) {
394
+ case "short_answer":
395
+ field = renderShortText(question, false);
396
+ break;
397
+ case "paragraph":
398
+ field = renderShortText(question, true);
399
+ break;
400
+ case "multiple_choice":
401
+ field = renderRadioGroup(question);
402
+ break;
403
+ case "dropdown":
404
+ field = renderSelect(question);
405
+ break;
406
+ case "checkboxes":
407
+ field = renderCheckboxGroup(question);
408
+ break;
409
+ case "linear_scale":
410
+ field = renderLinearScale(question);
411
+ break;
412
+ case "grid":
413
+ case "checkbox_grid":
414
+ field = renderGrid2(question);
415
+ break;
416
+ case "date":
417
+ field = renderDate(question);
418
+ break;
419
+ case "time":
420
+ field = renderTime(question);
421
+ break;
422
+ case "file_upload":
423
+ field = `<p>"${jsxEscape(question.title)}" is a file upload question and is not supported by Google Forms submission without sign-in.</p>`;
424
+ break;
425
+ default:
426
+ field = `<input {...form.register(${q(question.entryId)})} />`;
427
+ }
428
+ return ` <div key={${q(question.id)}}>
429
+ ${label}${description}
430
+ ${field}
431
+ </div>`;
432
+ };
433
+ var renderSection = (section, questionsById) => {
434
+ const heading = section.title ? ` <h2>${jsxEscape(section.title)}</h2>
435
+ ` : "";
436
+ const description = section.description ? ` <p>${jsxEscape(section.description)}</p>
437
+ ` : "";
438
+ const body = section.questionIds.map((id) => {
439
+ return questionsById.get(id);
440
+ }).filter((question) => {
441
+ return question !== void 0;
442
+ }).map(renderQuestion2).join("\n");
443
+ return `${heading}${description}${body}`;
444
+ };
445
+ var usesOther = (question) => {
446
+ return hasOtherOption(question) && (question.type === "multiple_choice" || question.type === "checkboxes");
447
+ };
448
+ var generateReactComponent = (schema, options = {}) => {
449
+ const typescript = options.typescript ?? true;
450
+ const name = options.name ?? `${toPascalCase(schema.title)}Form`;
451
+ const schemaJson = JSON.stringify(schema, null, 2);
452
+ void usesOther;
453
+ const questionsById = new Map(
454
+ schema.questions.map((qn) => {
455
+ return [qn.id, qn];
456
+ })
457
+ );
458
+ const body = schema.sections.length > 1 || schema.sections[0]?.title && schema.sections[0].title.length > 0 ? schema.sections.map((section) => {
459
+ return renderSection(section, questionsById);
460
+ }).join("\n") : schema.questions.map(renderQuestion2).join("\n");
461
+ const schemaDeclaration = typescript ? `${schemaJson} as const satisfies FormSchema` : schemaJson;
462
+ const typeImport = typescript ? `import type { FormSchema } from "@ez-gform/core";
463
+ ` : "";
464
+ return `${typeImport}import { useGoogleForm } from "@ez-gform/react";
465
+
466
+ const schema = ${schemaDeclaration};
467
+
468
+ export function ${name}() {
469
+ const form = useGoogleForm({ formId: schema.formId, schema });
470
+
471
+ return (
472
+ <form
473
+ onSubmit={form.submit}
474
+ >
475
+ <h1>${jsxEscape(schema.title)}</h1>
476
+ ${schema.description ? `<p>${jsxEscape(schema.description)}</p>` : ""}
477
+ ${body}
478
+
479
+ <div>Status: {form.status}</div>
480
+ {form.errors && form.errors.length > 0 && (
481
+ <ul>
482
+ {form.errors.map((error, index) => (
483
+ <li key={index}>{error.message}</li>
484
+ ))}
485
+ </ul>
486
+ )}
487
+
488
+ <button type="submit" disabled={form.status === "submitting"}>
489
+ Submit
490
+ </button>
491
+ </form>
492
+ );
493
+ }
494
+ `;
495
+ };
496
+
497
+ // src/generate-types.ts
498
+ var quote = (value) => {
499
+ return JSON.stringify(value);
500
+ };
501
+ var hasOtherOption2 = (question) => {
502
+ return question.options?.some((option) => {
503
+ return option.isOther;
504
+ }) ?? false;
505
+ };
506
+ var fieldType = (question) => {
507
+ switch (question.type) {
508
+ case "short_answer":
509
+ case "paragraph":
510
+ return "string";
511
+ case "multiple_choice":
512
+ case "dropdown":
513
+ return hasOtherOption2(question) ? "string | { other: string }" : "string";
514
+ case "checkboxes":
515
+ return hasOtherOption2(question) ? "(string | { other: string })[]" : "string[]";
516
+ case "linear_scale":
517
+ return "number";
518
+ case "date":
519
+ return "DateValue";
520
+ case "time":
521
+ return "TimeValue";
522
+ case "grid":
523
+ case "checkbox_grid": {
524
+ const rowIds = (question.rows ?? []).map((row) => {
525
+ return quote(row.entryId);
526
+ });
527
+ const keyType = rowIds.length > 0 ? rowIds.join(" | ") : "string";
528
+ return `Record<${keyType}, string | string[]>`;
529
+ }
530
+ case "file_upload":
531
+ return void 0;
532
+ default:
533
+ return "string";
534
+ }
535
+ };
536
+ var generateTypes = (schema, options = {}) => {
537
+ const name = options.name ?? toPascalCase(schema.title);
538
+ const schemaJson = JSON.stringify(schema, null, 2);
539
+ const usesDate = schema.questions.some((q2) => {
540
+ return q2.type === "date";
541
+ });
542
+ const usesTime = schema.questions.some((q2) => {
543
+ return q2.type === "time";
544
+ });
545
+ const extraTypeImports = [
546
+ usesDate ? "DateValue" : void 0,
547
+ usesTime ? "TimeValue" : void 0
548
+ ].filter((t) => {
549
+ return t !== void 0;
550
+ });
551
+ const fields = [];
552
+ for (const question of schema.questions) {
553
+ const type = fieldType(question);
554
+ if (type === void 0) continue;
555
+ const optional = question.required ? "" : "?";
556
+ fields.push(` ${quote(question.entryId)}${optional}: ${type};`);
557
+ }
558
+ const importLine = ["FormSchema", ...extraTypeImports].sort().join(", ");
559
+ return `import type { ${importLine} } from "@ez-gform/core";
560
+
561
+ export const ${name}Schema = ${schemaJson} as const satisfies FormSchema;
562
+
563
+ export type ${name}Values = {
564
+ ${fields.join("\n")}
565
+ };
566
+ `;
567
+ };
568
+
569
+ // src/schema-json.ts
570
+ var generateSchemaJson = (schema, options = {}) => {
571
+ const pretty = options.pretty ?? true;
572
+ return pretty ? JSON.stringify(schema, null, 2) : JSON.stringify(schema);
573
+ };
574
+ export {
575
+ generateHtmlForm,
576
+ generateReactComponent,
577
+ generateSchemaJson,
578
+ generateTypes,
579
+ toIdentifier,
580
+ toPascalCase
581
+ };
582
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generate-html.ts","../src/names.ts","../src/generate-react.ts","../src/generate-types.ts","../src/schema-json.ts"],"sourcesContent":["import { formUrls } from \"@ez-gform/core\";\nimport type { FormSchema, Question } from \"@ez-gform/types\";\n\nconst escapeHtml = (value: string): string => {\n return value\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\");\n};\n\nconst attr = (name: string, value: string): string => {\n return `${name}=\"${escapeHtml(value)}\"`;\n};\n\nconst renderChoiceInputs = (\n question: Question,\n inputType: \"radio\" | \"checkbox\",\n): string => {\n const options = question.options ?? [];\n const rows = options.map((option) => {\n if (option.isOther) {\n return [\n `<label><input type=\"${inputType}\" ${attr(\"name\", question.entryId)} value=\"__other_option__\"> Other:</label>`,\n `<input type=\"text\" ${attr(\"name\", `${question.entryId}.other_option_response`)}>`,\n ].join(\"\\n \");\n }\n return `<label><input type=\"${inputType}\" ${attr(\"name\", question.entryId)} ${attr(\"value\", option.value)}> ${escapeHtml(option.value)}</label>`;\n });\n return rows.join(\"\\n \");\n};\n\nconst renderGrid = (question: Question): string => {\n const inputType = question.type === \"checkbox_grid\" ? \"checkbox\" : \"radio\";\n const columns = question.options ?? [];\n const rows = (question.rows ?? [])\n .map((row) => {\n const cells = columns\n .map((col) => {\n return `<td><input type=\"${inputType}\" ${attr(\"name\", row.entryId)} ${attr(\"value\", col.value)}></td>`;\n })\n .join(\"\");\n return ` <tr><th>${escapeHtml(row.label)}</th>${cells}</tr>`;\n })\n .join(\"\\n\");\n return `<table>\\n${rows}\\n</table>`;\n};\n\nconst renderQuestion = (question: Question): string => {\n const label = `<label>${escapeHtml(question.title)}${question.required ? \" *\" : \"\"}</label>`;\n const requiredAttr = question.required ? \" required\" : \"\";\n\n switch (question.type) {\n case \"short_answer\":\n return `${label}\\n<input type=\"text\" ${attr(\"name\", question.entryId)}${requiredAttr}>`;\n case \"paragraph\":\n return `${label}\\n<textarea ${attr(\"name\", question.entryId)}${requiredAttr}></textarea>`;\n case \"multiple_choice\":\n return `${label}\\n${renderChoiceInputs(question, \"radio\")}`;\n case \"checkboxes\":\n return `${label}\\n${renderChoiceInputs(question, \"checkbox\")}`;\n case \"dropdown\": {\n const options = (question.options ?? [])\n .map((option) => {\n return ` <option ${attr(\"value\", option.value)}>${escapeHtml(option.value)}</option>`;\n })\n .join(\"\\n\");\n return `${label}\\n<select ${attr(\"name\", question.entryId)}${requiredAttr}>\\n${options}\\n</select>`;\n }\n case \"linear_scale\": {\n const min = question.scale?.min ?? 1;\n const max = question.scale?.max ?? 5;\n const inputs: string[] = [];\n for (let value = min; value <= max; value++) {\n inputs.push(\n `<label><input type=\"radio\" ${attr(\"name\", question.entryId)} ${attr(\"value\", String(value))}> ${value}</label>`,\n );\n }\n return `${label}\\n${inputs.join(\"\\n\")}`;\n }\n case \"grid\":\n case \"checkbox_grid\":\n return `${label}\\n${renderGrid(question)}`;\n case \"date\": {\n const inputs: string[] = [];\n if (question.date?.includeYear !== false) {\n inputs.push(\n `<input type=\"number\" ${attr(\"name\", `${question.entryId}_year`)} placeholder=\"Year\">`,\n );\n }\n inputs.push(\n `<input type=\"number\" ${attr(\"name\", `${question.entryId}_month`)} placeholder=\"Month\">`,\n );\n inputs.push(\n `<input type=\"number\" ${attr(\"name\", `${question.entryId}_day`)} placeholder=\"Day\">`,\n );\n if (question.date?.includeTime) {\n inputs.push(\n `<input type=\"number\" ${attr(\"name\", `${question.entryId}_hour`)} placeholder=\"Hour\">`,\n );\n inputs.push(\n `<input type=\"number\" ${attr(\"name\", `${question.entryId}_minute`)} placeholder=\"Minute\">`,\n );\n }\n return `${label}\\n${inputs.join(\"\\n\")}`;\n }\n case \"time\":\n return `${label}\\n<input type=\"number\" ${attr(\"name\", `${question.entryId}_hour`)} placeholder=\"Hour\">\\n<input type=\"number\" ${attr(\"name\", `${question.entryId}_minute`)} placeholder=\"Minute\">`;\n case \"file_upload\":\n return `${label}\\n<!-- file_upload is not supported by the Forms API without sign-in; no input rendered -->`;\n default:\n return label;\n }\n};\n\n/**\n * Emits a plain HTML `<form>` (no JS framework required) posting directly to\n * the form's `formResponse` endpoint, with `name` attributes following every\n * `entry.N`(`_year`/`_month`/`_day`/`_hour`/`_minute`, `__other_option__`,\n * `.other_option_response`) encoding rule in\n * `docs/research/google-forms-internals.md` §3.\n */\nexport const generateHtmlForm = (schema: FormSchema): string => {\n const { formResponse } = formUrls(schema.formId || \"REPLACE_WITH_FORM_ID\");\n const body = schema.questions.map(renderQuestion).join(\"\\n\\n\");\n\n const hiddenFields: string[] = [];\n if (schema.multiPage) {\n hiddenFields.push(\n `<input type=\"hidden\" ${attr(\"name\", \"fbzx\")} ${attr(\"value\", schema.fbzx ?? \"\")}>`,\n );\n }\n\n return `<!-- ${escapeHtml(schema.title)} -->\n<form action=\"${escapeHtml(formResponse)}\" method=\"POST\">\n${hiddenFields.join(\"\\n\")}\n${body}\n\n<button type=\"submit\">Submit</button>\n</form>\n`;\n};\n","/** Splits a free-form string (a form title, question label, etc.) into word tokens. */\nconst splitWords = (input: string): string[] => {\n return (\n input\n // Insert boundaries between camelCase / acronym transitions.\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n // Replace anything that isn't a letter/digit with a space.\n .replace(/[^a-zA-Z0-9]+/g, \" \")\n .trim()\n .split(/\\s+/)\n .filter((word) => {\n return word.length > 0;\n })\n );\n};\n\n/** Converts a free-form string into `PascalCase`, safe for a TS identifier/type name. */\nexport const toPascalCase = (input: string): string => {\n const words = splitWords(input);\n const pascal = words\n .map((word) => {\n const lower = word.toLowerCase();\n return lower.charAt(0).toUpperCase() + lower.slice(1);\n })\n .join(\"\");\n return pascal.length > 0 ? pascal : \"Form\";\n};\n\n/**\n * JS/TS reserved words (keywords, future reserved words, and strict-mode\n * reserved words) that are not valid as a binding identifier. Guarded here\n * because `toIdentifier` output is emitted as a real variable/prop name in\n * generated code.\n */\nconst RESERVED_WORDS = new Set([\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"export\",\n \"extends\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"enum\",\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n \"yield\",\n \"await\",\n \"null\",\n \"true\",\n \"false\",\n]);\n\n/**\n * Converts a free-form string into a valid, sanitized JS identifier\n * (`camelCase`, no leading digit, and no collision with a JS/TS reserved\n * word — a trailing underscore is appended in that case).\n */\nexport const toIdentifier = (input: string): string => {\n const words = splitWords(input);\n if (words.length === 0) return \"Form\";\n const [first, ...rest] = words;\n const camel =\n first!.toLowerCase() +\n rest\n .map((word) => {\n const lower = word.toLowerCase();\n return lower.charAt(0).toUpperCase() + lower.slice(1);\n })\n .join(\"\");\n const prefixed = /^[0-9]/.test(camel) ? `_${camel}` : camel;\n return RESERVED_WORDS.has(prefixed) ? `${prefixed}_` : prefixed;\n};\n","import type {\n FormSchema,\n GenerateReactOptions,\n Question,\n Section,\n} from \"@ez-gform/types\";\nimport { toPascalCase } from \"./names.js\";\n\nexport type GenerateReactComponentOptions = GenerateReactOptions;\n\nconst JSX_TEXT_ESCAPES: Record<string, string> = {\n \"&\": \"&amp;\",\n \"<\": \"&lt;\",\n \">\": \"&gt;\",\n \"{\": \"&#123;\",\n \"}\": \"&#125;\",\n};\n\n/** Escapes text so it's safe to drop directly into JSX element children. */\nconst jsxEscape = (value: string): string => {\n return value.replace(/[&<>{}]/g, (ch) => {\n return JSX_TEXT_ESCAPES[ch]!;\n });\n};\n\nconst q = (value: string): string => {\n return JSON.stringify(value);\n};\n\nconst hasOtherOption = (question: Question): boolean => {\n return (\n question.options?.some((option) => {\n return option.isOther;\n }) ?? false\n );\n};\n\nconst renderShortText = (question: Question, multiline: boolean): string => {\n const tag = multiline ? \"textarea\" : \"input\";\n const typeAttr = multiline ? \"\" : ' type=\"text\"';\n return `<${tag}${typeAttr} {...form.register(${q(question.entryId)})}${\n question.required ? \" required\" : \"\"\n } />`;\n};\n\nconst renderRadioGroup = (question: Question): string => {\n const entryId = q(question.entryId);\n const options = (question.options ?? [])\n .map((option) => {\n if (option.isOther) {\n return ` <label>\n <input\n type=\"radio\"\n name={form.register(${entryId}).name}\n checked={typeof form.values[${entryId}] === \"object\"}\n onChange={() => form.setValue(${entryId}, { other: \"\" })}\n />\n Other:\n <input\n type=\"text\"\n onChange={(e) => form.setValue(${entryId}, { other: e.target.value })}\n />\n </label>`;\n }\n const value = q(option.value);\n return ` <label>\n <input\n type=\"radio\"\n name={form.register(${entryId}).name}\n value={${value}}\n checked={form.register(${entryId}).value === ${value}}\n onChange={() => form.setValue(${entryId}, ${value})}\n />\n ${jsxEscape(option.value)}\n </label>`;\n })\n .join(\"\\n\");\n return `<div role=\"radiogroup\">\n${options}\n </div>`;\n};\n\nconst renderSelect = (question: Question): string => {\n const options = (question.options ?? [])\n .map((option) => {\n return ` <option value={${q(option.value)}}>${jsxEscape(option.value)}</option>`;\n })\n .join(\"\\n\");\n return `<select {...form.register(${q(question.entryId)})}${\n question.required ? \" required\" : \"\"\n }>\n <option value=\"\">Select…</option>\n${options}\n </select>`;\n};\n\nconst renderCheckboxGroup = (question: Question): string => {\n const entryId = q(question.entryId);\n const options = (question.options ?? [])\n .map((option) => {\n if (option.isOther) {\n return ` <label>\n <input\n type=\"checkbox\"\n onChange={(e) => form.setValue(${entryId}, e.target.checked ? { other: \"\" } : undefined)}\n />\n Other:\n <input\n type=\"text\"\n onChange={(e) => form.setValue(${entryId}, { other: e.target.value })}\n />\n </label>`;\n }\n const value = q(option.value);\n return ` <label>\n <input type=\"checkbox\" {...form.registerCheckbox(${entryId}, ${value})} />\n ${jsxEscape(option.value)}\n </label>`;\n })\n .join(\"\\n\");\n return `<div>\n${options}\n </div>`;\n};\n\nconst renderLinearScale = (question: Question): string => {\n const entryId = q(question.entryId);\n const min = question.scale?.min ?? 1;\n const max = question.scale?.max ?? 5;\n const items: string[] = [];\n for (let value = min; value <= max; value++) {\n items.push(` <label>\n <input\n type=\"radio\"\n name={form.register(${entryId}).name}\n checked={form.register(${entryId}).value === ${q(String(value))}}\n onChange={() => form.setValue(${entryId}, ${value})}\n />\n ${value}\n </label>`);\n }\n const lowLabel = question.scale?.lowLabel;\n const highLabel = question.scale?.highLabel;\n return `<div role=\"radiogroup\">\n ${lowLabel ? `<span>${jsxEscape(lowLabel)}</span>` : \"\"}\n${items.join(\"\\n\")}\n ${highLabel ? `<span>${jsxEscape(highLabel)}</span>` : \"\"}\n </div>`;\n};\n\nconst renderGrid = (question: Question): string => {\n const isCheckbox = question.type === \"checkbox_grid\";\n const columns = question.options ?? [];\n const headerCells = columns\n .map((col) => {\n return `<th key={${q(col.value)}}>${jsxEscape(col.value)}</th>`;\n })\n .join(\"\\n \");\n const rows = (question.rows ?? [])\n .map((row) => {\n const entryId = q(row.entryId);\n const cells = columns\n .map((col) => {\n const value = q(col.value);\n if (isCheckbox) {\n return `<td key={${value}}><input type=\"checkbox\" {...form.registerCheckbox(${entryId}, ${value})} /></td>`;\n }\n return `<td key={${value}}>\n <input\n type=\"radio\"\n name={form.register(${entryId}).name}\n checked={form.register(${entryId}).value === ${value}}\n onChange={() => form.setValue(${entryId}, ${value})}\n />\n </td>`;\n })\n .join(\"\\n \");\n return ` <tr>\n <th>${jsxEscape(row.label)}</th>\n ${cells}\n </tr>`;\n })\n .join(\"\\n\");\n return `<table>\n <thead>\n <tr>\n <th />\n ${headerCells}\n </tr>\n </thead>\n <tbody>\n${rows}\n </tbody>\n </table>`;\n};\n\nconst renderDate = (question: Question): string => {\n const entryId = q(question.entryId);\n return `<input\n type=\"date\"\n required={${question.required ? \"true\" : \"false\"}}\n onChange={(e) => {\n const parts = e.target.value.split(\"-\").map(Number);\n const [year, month, day] = parts;\n if (month === undefined || day === undefined) return;\n form.setValue(${entryId}, { year, month, day });\n }}\n />`;\n};\n\nconst renderTime = (question: Question): string => {\n const entryId = q(question.entryId);\n return `<input\n type=\"time\"\n required={${question.required ? \"true\" : \"false\"}}\n onChange={(e) => {\n const parts = e.target.value.split(\":\").map(Number);\n const [hour, minute] = parts;\n if (hour === undefined || minute === undefined) return;\n form.setValue(${entryId}, { hour, minute });\n }}\n />`;\n};\n\nconst renderQuestion = (question: Question): string => {\n const label = `<label>${jsxEscape(question.title)}${\n question.required ? \" *\" : \"\"\n }</label>`;\n const description = question.description\n ? `\\n <p>${jsxEscape(question.description)}</p>`\n : \"\";\n\n let field: string;\n switch (question.type) {\n case \"short_answer\":\n field = renderShortText(question, false);\n break;\n case \"paragraph\":\n field = renderShortText(question, true);\n break;\n case \"multiple_choice\":\n field = renderRadioGroup(question);\n break;\n case \"dropdown\":\n field = renderSelect(question);\n break;\n case \"checkboxes\":\n field = renderCheckboxGroup(question);\n break;\n case \"linear_scale\":\n field = renderLinearScale(question);\n break;\n case \"grid\":\n case \"checkbox_grid\":\n field = renderGrid(question);\n break;\n case \"date\":\n field = renderDate(question);\n break;\n case \"time\":\n field = renderTime(question);\n break;\n case \"file_upload\":\n field = `<p>\"${jsxEscape(question.title)}\" is a file upload question and is not supported by Google Forms submission without sign-in.</p>`;\n break;\n default:\n field = `<input {...form.register(${q(question.entryId)})} />`;\n }\n\n return ` <div key={${q(question.id)}}>\n ${label}${description}\n ${field}\n </div>`;\n};\n\nconst renderSection = (\n section: Section,\n questionsById: Map<string, Question>,\n): string => {\n const heading = section.title\n ? ` <h2>${jsxEscape(section.title)}</h2>\\n`\n : \"\";\n const description = section.description\n ? ` <p>${jsxEscape(section.description)}</p>\\n`\n : \"\";\n const body = section.questionIds\n .map((id) => {\n return questionsById.get(id);\n })\n .filter((question): question is Question => {\n return question !== undefined;\n })\n .map(renderQuestion)\n .join(\"\\n\");\n return `${heading}${description}${body}`;\n};\n\nconst usesOther = (question: Question): boolean => {\n return (\n hasOtherOption(question) &&\n (question.type === \"multiple_choice\" || question.type === \"checkboxes\")\n );\n};\n\n/**\n * Generates a paste-ready React component wired to `useGoogleForm` from\n * `@ez-gform/react`. Renders every supported question type; `file_upload`\n * questions render a disabled note instead of an input (the Forms API can't\n * accept file uploads without a signed-in session).\n */\nexport const generateReactComponent = (\n schema: FormSchema,\n options: GenerateReactComponentOptions = {},\n): string => {\n const typescript = options.typescript ?? true;\n const name = options.name ?? `${toPascalCase(schema.title)}Form`;\n const schemaJson = JSON.stringify(schema, null, 2);\n void usesOther;\n\n const questionsById = new Map(\n schema.questions.map((qn) => {\n return [qn.id, qn];\n }),\n );\n const body =\n schema.sections.length > 1 ||\n (schema.sections[0]?.title && schema.sections[0].title.length > 0)\n ? schema.sections\n .map((section) => {\n return renderSection(section, questionsById);\n })\n .join(\"\\n\")\n : schema.questions.map(renderQuestion).join(\"\\n\");\n\n const schemaDeclaration = typescript\n ? `${schemaJson} as const satisfies FormSchema`\n : schemaJson;\n const typeImport = typescript\n ? `import type { FormSchema } from \"@ez-gform/core\";\\n`\n : \"\";\n\n return `${typeImport}import { useGoogleForm } from \"@ez-gform/react\";\n\nconst schema = ${schemaDeclaration};\n\nexport function ${name}() {\n const form = useGoogleForm({ formId: schema.formId, schema });\n\n return (\n <form\n onSubmit={form.submit}\n >\n <h1>${jsxEscape(schema.title)}</h1>\n ${schema.description ? `<p>${jsxEscape(schema.description)}</p>` : \"\"}\n${body}\n\n <div>Status: {form.status}</div>\n {form.errors && form.errors.length > 0 && (\n <ul>\n {form.errors.map((error, index) => (\n <li key={index}>{error.message}</li>\n ))}\n </ul>\n )}\n\n <button type=\"submit\" disabled={form.status === \"submitting\"}>\n Submit\n </button>\n </form>\n );\n}\n`;\n};\n","import type {\n FormSchema,\n GenerateTypesOptions,\n Question,\n} from \"@ez-gform/types\";\nimport { toPascalCase } from \"./names.js\";\n\nexport type { GenerateTypesOptions } from \"@ez-gform/types\";\n\nconst quote = (value: string): string => {\n return JSON.stringify(value);\n};\n\nconst hasOtherOption = (question: Question): boolean => {\n return (\n question.options?.some((option) => {\n return option.isOther;\n }) ?? false\n );\n};\n\n/** Returns the TS type text for a single question's value, or `undefined` to omit it entirely. */\nconst fieldType = (question: Question): string | undefined => {\n switch (question.type) {\n case \"short_answer\":\n case \"paragraph\":\n return \"string\";\n case \"multiple_choice\":\n case \"dropdown\":\n return hasOtherOption(question) ? \"string | { other: string }\" : \"string\";\n case \"checkboxes\":\n return hasOtherOption(question)\n ? \"(string | { other: string })[]\"\n : \"string[]\";\n case \"linear_scale\":\n return \"number\";\n case \"date\":\n return \"DateValue\";\n case \"time\":\n return \"TimeValue\";\n case \"grid\":\n case \"checkbox_grid\": {\n const rowIds = (question.rows ?? []).map((row) => {\n return quote(row.entryId);\n });\n const keyType = rowIds.length > 0 ? rowIds.join(\" | \") : \"string\";\n return `Record<${keyType}, string | string[]>`;\n }\n case \"file_upload\":\n // File uploads can't be submitted through the Forms API without\n // sign-in; there is no meaningful value type for them.\n return undefined;\n default:\n return \"string\";\n }\n};\n\n/**\n * Emits `const <Name>Schema = {...} as const satisfies FormSchema;` and a\n * companion `type <Name>Values = { \"entry.N\"?: ...; ... }` mapping every\n * question's entry id to its precise `FieldValue` subtype.\n */\nexport const generateTypes = (\n schema: FormSchema,\n options: GenerateTypesOptions = {},\n): string => {\n const name = options.name ?? toPascalCase(schema.title);\n const schemaJson = JSON.stringify(schema, null, 2);\n\n const usesDate = schema.questions.some((q) => {\n return q.type === \"date\";\n });\n const usesTime = schema.questions.some((q) => {\n return q.type === \"time\";\n });\n const extraTypeImports = [\n usesDate ? \"DateValue\" : undefined,\n usesTime ? \"TimeValue\" : undefined,\n ].filter((t): t is string => {\n return t !== undefined;\n });\n\n const fields: string[] = [];\n for (const question of schema.questions) {\n const type = fieldType(question);\n if (type === undefined) continue;\n const optional = question.required ? \"\" : \"?\";\n fields.push(` ${quote(question.entryId)}${optional}: ${type};`);\n }\n\n const importLine = [\"FormSchema\", ...extraTypeImports].sort().join(\", \");\n\n return `import type { ${importLine} } from \"@ez-gform/core\";\n\nexport const ${name}Schema = ${schemaJson} as const satisfies FormSchema;\n\nexport type ${name}Values = {\n${fields.join(\"\\n\")}\n};\n`;\n};\n","import type { FormSchema, GenerateSchemaJsonOptions } from \"@ez-gform/types\";\n\nexport type { GenerateSchemaJsonOptions } from \"@ez-gform/types\";\n\n/** Serializes a `FormSchema` back to JSON text. Round-trips structurally with `JSON.parse`. */\nexport const generateSchemaJson = (\n schema: FormSchema,\n options: GenerateSchemaJsonOptions = {},\n): string => {\n const pretty = options.pretty ?? true;\n return pretty ? JSON.stringify(schema, null, 2) : JSON.stringify(schema);\n};\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,IAAM,aAAa,CAAC,UAA0B;AAC5C,SAAO,MACJ,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ;AAC3B;AAEA,IAAM,OAAO,CAAC,MAAc,UAA0B;AACpD,SAAO,GAAG,IAAI,KAAK,WAAW,KAAK,CAAC;AACtC;AAEA,IAAM,qBAAqB,CACzB,UACA,cACW;AACX,QAAM,UAAU,SAAS,WAAW,CAAC;AACrC,QAAM,OAAO,QAAQ,IAAI,CAAC,WAAW;AACnC,QAAI,OAAO,SAAS;AAClB,aAAO;AAAA,QACL,uBAAuB,SAAS,KAAK,KAAK,QAAQ,SAAS,OAAO,CAAC;AAAA,QACnE,sBAAsB,KAAK,QAAQ,GAAG,SAAS,OAA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