@petrarca/sonnet-playground 0.1.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.
Files changed (41) hide show
  1. package/dist/PlayColorPalette-UFMTJTUB.js +8 -0
  2. package/dist/PlayColorPalette-UFMTJTUB.js.map +1 -0
  3. package/dist/PlayCoreComponents-7QCDFQLT.js +7 -0
  4. package/dist/PlayCoreComponents-7QCDFQLT.js.map +1 -0
  5. package/dist/PlayDataComponents-GZSRTW4F.js +7 -0
  6. package/dist/PlayDataComponents-GZSRTW4F.js.map +1 -0
  7. package/dist/PlayFormComponents-RJB6WZHD.js +7 -0
  8. package/dist/PlayFormComponents-RJB6WZHD.js.map +1 -0
  9. package/dist/PlayFormWidgets-OFV7TJKH.js +7 -0
  10. package/dist/PlayFormWidgets-OFV7TJKH.js.map +1 -0
  11. package/dist/PlayForms-24XX5DC6.js +7 -0
  12. package/dist/PlayForms-24XX5DC6.js.map +1 -0
  13. package/dist/PlayJsonEditor-4L5INQPU.js +7 -0
  14. package/dist/PlayJsonEditor-4L5INQPU.js.map +1 -0
  15. package/dist/PlayTypography-ID6DLFZD.js +8 -0
  16. package/dist/PlayTypography-ID6DLFZD.js.map +1 -0
  17. package/dist/chunk-5V27QDAY.js +617 -0
  18. package/dist/chunk-5V27QDAY.js.map +1 -0
  19. package/dist/chunk-A3IK3CVW.js +212 -0
  20. package/dist/chunk-A3IK3CVW.js.map +1 -0
  21. package/dist/chunk-CYNK2P2Q.js +411 -0
  22. package/dist/chunk-CYNK2P2Q.js.map +1 -0
  23. package/dist/chunk-FTN2A5YL.js +20 -0
  24. package/dist/chunk-FTN2A5YL.js.map +1 -0
  25. package/dist/chunk-GYKEPHHA.js +1154 -0
  26. package/dist/chunk-GYKEPHHA.js.map +1 -0
  27. package/dist/chunk-KAT24CQQ.js +125 -0
  28. package/dist/chunk-KAT24CQQ.js.map +1 -0
  29. package/dist/chunk-P7I5IDXA.js +432 -0
  30. package/dist/chunk-P7I5IDXA.js.map +1 -0
  31. package/dist/chunk-QIETZUEN.js +885 -0
  32. package/dist/chunk-QIETZUEN.js.map +1 -0
  33. package/dist/chunk-TZGJH7YS.js +837 -0
  34. package/dist/chunk-TZGJH7YS.js.map +1 -0
  35. package/dist/index.d.ts +160 -0
  36. package/dist/index.js +328 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/pages/index.d.ts +69 -0
  39. package/dist/pages/index.js +36 -0
  40. package/dist/pages/index.js.map +1 -0
  41. package/package.json +54 -0
@@ -0,0 +1,885 @@
1
+ // src/pages/PlayForms.tsx
2
+ import { useState, useCallback } from "react";
3
+ import {
4
+ SimpleStack,
5
+ SimpleGroup,
6
+ Tabs,
7
+ TabsContent,
8
+ TabsList,
9
+ TabsTrigger,
10
+ Card,
11
+ Badge,
12
+ SimpleTooltip,
13
+ Button
14
+ } from "@petrarca/sonnet-ui";
15
+ import {
16
+ FormSelect,
17
+ FormCheckbox,
18
+ JsonSchemaFormRenderer
19
+ } from "@petrarca/sonnet-forms";
20
+ import { JsonEditor } from "@petrarca/sonnet-ui/json-editor";
21
+ import {
22
+ ArrowRight,
23
+ ChevronLeft,
24
+ ChevronRight as ChevronRightIcon
25
+ } from "lucide-react";
26
+ import { jsx, jsxs } from "react/jsx-runtime";
27
+ var SAMPLE_SCHEMA = {
28
+ title: "Practitioner",
29
+ type: "object",
30
+ properties: {
31
+ name: { type: "string", title: "Full Name" },
32
+ npi: { type: "string", title: "NPI" },
33
+ specialty: {
34
+ type: "string",
35
+ title: "Specialty",
36
+ enum: ["cardiology", "neurology", "oncology", "radiology", "general"]
37
+ },
38
+ notes: {
39
+ type: "string",
40
+ title: "Notes",
41
+ "x-ui-widget": "textarea"
42
+ },
43
+ years_experience: {
44
+ type: "integer",
45
+ title: "Years of Experience",
46
+ minimum: 0,
47
+ maximum: 60
48
+ },
49
+ active: { type: "boolean", title: "Active" }
50
+ },
51
+ required: ["name", "npi"]
52
+ };
53
+ var NESTED_OBJECT_SCHEMA = {
54
+ title: "Patient",
55
+ type: "object",
56
+ properties: {
57
+ family_name: { type: "string", title: "Family Name" },
58
+ given_name: { type: "string", title: "Given Name" },
59
+ birth_date: { type: "string", title: "Date of Birth", format: "date" },
60
+ contact: {
61
+ type: "object",
62
+ title: "Contact",
63
+ properties: {
64
+ phone: { type: "string", title: "Phone" },
65
+ email: { type: "string", title: "Email", format: "email" },
66
+ address: { type: "string", title: "Address" },
67
+ city: { type: "string", title: "City" },
68
+ country: {
69
+ type: "string",
70
+ title: "Country",
71
+ enum: ["DE", "AT", "CH", "US", "GB"]
72
+ }
73
+ },
74
+ required: ["phone"]
75
+ }
76
+ },
77
+ required: ["family_name", "given_name"]
78
+ };
79
+ var ARRAY_OF_OBJECTS_SCHEMA = {
80
+ title: "Medication Request",
81
+ type: "object",
82
+ properties: {
83
+ patient_id: { type: "string", title: "Patient ID" },
84
+ prescriber: { type: "string", title: "Prescriber" },
85
+ medications: {
86
+ type: "array",
87
+ title: "Medications",
88
+ "x-ui-options": {
89
+ addLabel: "Add Medication",
90
+ emptyMessage: "No medications added",
91
+ orderable: true
92
+ },
93
+ items: {
94
+ type: "object",
95
+ properties: {
96
+ drug_name: { type: "string", title: "Drug Name" },
97
+ dose: { type: "string", title: "Dose" },
98
+ route: {
99
+ type: "string",
100
+ title: "Route",
101
+ enum: ["oral", "IV", "subcutaneous", "topical", "inhaled"]
102
+ },
103
+ frequency: { type: "string", title: "Frequency" },
104
+ active: { type: "boolean", title: "Active" }
105
+ },
106
+ required: ["drug_name", "dose"]
107
+ },
108
+ minItems: 1,
109
+ maxItems: 10
110
+ }
111
+ },
112
+ required: ["patient_id", "prescriber"]
113
+ };
114
+ var REF_SCHEMA = {
115
+ title: "Care Plan",
116
+ type: "object",
117
+ $defs: {
118
+ period: {
119
+ type: "object",
120
+ properties: {
121
+ start: { type: "string", title: "Start Date", format: "date" },
122
+ end: { type: "string", title: "End Date", format: "date" }
123
+ },
124
+ required: ["start"]
125
+ }
126
+ },
127
+ properties: {
128
+ patient_id: { type: "string", title: "Patient ID" },
129
+ title: { type: "string", title: "Plan Title" },
130
+ validity: {
131
+ $ref: "#/$defs/period",
132
+ title: "Validity Period"
133
+ },
134
+ activities: {
135
+ type: "array",
136
+ title: "Activities",
137
+ "x-ui-options": {
138
+ addLabel: "Add Activity",
139
+ orderable: true
140
+ },
141
+ items: {
142
+ type: "object",
143
+ properties: {
144
+ description: { type: "string", title: "Description" },
145
+ schedule: {
146
+ $ref: "#/$defs/period",
147
+ title: "Schedule"
148
+ }
149
+ },
150
+ required: ["description"]
151
+ },
152
+ maxItems: 5
153
+ }
154
+ },
155
+ required: ["patient_id", "title"]
156
+ };
157
+ var HORIZONTAL_ARRAY_SCHEMA = {
158
+ title: "Observation Panel",
159
+ type: "object",
160
+ properties: {
161
+ subject: { type: "string", title: "Subject ID" },
162
+ observations: {
163
+ type: "array",
164
+ title: "Observations",
165
+ "x-ui-layout": {
166
+ direction: "horizontal",
167
+ columns: "1fr 1fr 1fr 80px",
168
+ gap: 8,
169
+ compact: true
170
+ },
171
+ "x-ui-options": {
172
+ addLabel: "Add Observation",
173
+ emptyMessage: "No observations recorded",
174
+ orderable: true
175
+ },
176
+ items: {
177
+ type: "object",
178
+ properties: {
179
+ code: {
180
+ type: "string",
181
+ title: "LOINC Code",
182
+ enum: ["8310-5", "8867-4", "9279-1", "29463-7"]
183
+ },
184
+ value: { type: "string", title: "Value" },
185
+ unit: {
186
+ type: "string",
187
+ title: "Unit",
188
+ enum: ["Cel", "/min", "kg", "mmHg", "%"]
189
+ },
190
+ abnormal: { type: "boolean", title: "Abnormal" }
191
+ },
192
+ required: ["code", "value"]
193
+ },
194
+ minItems: 0,
195
+ maxItems: 20
196
+ }
197
+ },
198
+ required: ["subject"]
199
+ };
200
+ var HORIZONTAL_FULL_SCHEMA = {
201
+ title: "Allergy List",
202
+ type: "object",
203
+ properties: {
204
+ patient_id: { type: "string", title: "Patient ID" },
205
+ allergies: {
206
+ type: "array",
207
+ title: "Allergies",
208
+ "x-ui-layout": {
209
+ direction: "horizontal",
210
+ columns: "2fr 1fr 1fr",
211
+ gap: 12
212
+ },
213
+ "x-ui-options": {
214
+ addLabel: "Add Allergy",
215
+ emptyMessage: "No allergies recorded",
216
+ orderable: true
217
+ },
218
+ items: {
219
+ type: "object",
220
+ properties: {
221
+ substance: { type: "string", title: "Substance" },
222
+ severity: {
223
+ type: "string",
224
+ title: "Severity",
225
+ enum: ["mild", "moderate", "severe"]
226
+ },
227
+ reaction: { type: "string", title: "Reaction" }
228
+ },
229
+ required: ["substance"]
230
+ }
231
+ }
232
+ },
233
+ required: ["patient_id"]
234
+ };
235
+ var MIXED_SCHEMA = {
236
+ title: "Healthcare Organization",
237
+ type: "object",
238
+ properties: {
239
+ name: { type: "string", title: "Name" },
240
+ type: {
241
+ type: "string",
242
+ title: "Type",
243
+ enum: ["hospital", "clinic", "lab", "pharmacy"]
244
+ },
245
+ active: { type: "boolean", title: "Active" },
246
+ location: {
247
+ type: "object",
248
+ title: "Location",
249
+ "x-ui-options": { variant: "card" },
250
+ properties: {
251
+ address: { type: "string", title: "Address" },
252
+ city: { type: "string", title: "City" },
253
+ postal_code: { type: "string", title: "Postal Code" },
254
+ country: {
255
+ type: "string",
256
+ title: "Country",
257
+ enum: ["DE", "AT", "CH", "US", "GB"]
258
+ }
259
+ },
260
+ required: ["address", "city"]
261
+ },
262
+ contacts: {
263
+ type: "array",
264
+ title: "Contacts",
265
+ "x-ui-options": {
266
+ addLabel: "Add Contact",
267
+ orderable: true,
268
+ emptyMessage: "No contacts defined"
269
+ },
270
+ items: {
271
+ type: "object",
272
+ properties: {
273
+ name: { type: "string", title: "Name" },
274
+ role: {
275
+ type: "string",
276
+ title: "Role",
277
+ enum: ["admin", "clinical", "billing", "technical"]
278
+ },
279
+ email: { type: "string", title: "Email", format: "email" },
280
+ phone: { type: "string", title: "Phone" }
281
+ },
282
+ required: ["name", "email"]
283
+ },
284
+ minItems: 1
285
+ }
286
+ },
287
+ required: ["name", "type"]
288
+ };
289
+ var ROW_LAYOUT_SCHEMA = {
290
+ title: "Practitioner Registration",
291
+ type: "object",
292
+ properties: {
293
+ given_name: { type: "string", title: "Given Name" },
294
+ family_name: { type: "string", title: "Family Name" },
295
+ npi: { type: "string", title: "NPI" },
296
+ specialty: {
297
+ type: "string",
298
+ title: "Specialty",
299
+ enum: ["cardiology", "neurology", "oncology", "radiology", "general"]
300
+ },
301
+ email: { type: "string", title: "Email", format: "email" },
302
+ phone: { type: "string", title: "Phone" },
303
+ start_date: { type: "string", title: "Start Date" },
304
+ end_date: { type: "string", title: "End Date" },
305
+ notes: { type: "string", title: "Notes", "x-ui-widget": "textarea" },
306
+ active: { type: "boolean", title: "Active" }
307
+ },
308
+ required: ["given_name", "family_name", "npi"]
309
+ };
310
+ var ROW_LAYOUT_UISCHEMA = {
311
+ "x-ui-layout": {
312
+ rows: [
313
+ { fields: ["given_name", "family_name"], columns: "1fr 1fr" },
314
+ { fields: ["npi", "specialty"], columns: "1fr 1fr" },
315
+ { fields: ["email", "phone"], columns: "1fr 1fr" },
316
+ { fields: ["start_date", "end_date"], columns: "1fr 1fr" }
317
+ ]
318
+ }
319
+ };
320
+ var sampleSchemas = {
321
+ flat: SAMPLE_SCHEMA,
322
+ nested_object: NESTED_OBJECT_SCHEMA,
323
+ array_of_objects: ARRAY_OF_OBJECTS_SCHEMA,
324
+ ref_defs: REF_SCHEMA,
325
+ mixed: MIXED_SCHEMA,
326
+ horizontal_array: HORIZONTAL_ARRAY_SCHEMA,
327
+ horizontal_full: HORIZONTAL_FULL_SCHEMA,
328
+ row_layout: ROW_LAYOUT_SCHEMA
329
+ };
330
+ var sampleUiSchemas = {
331
+ empty: "{}",
332
+ hideLabels: JSON.stringify(
333
+ {
334
+ "x-ui-globalOptions": {
335
+ label: false
336
+ }
337
+ },
338
+ null,
339
+ 2
340
+ ),
341
+ disableAll: JSON.stringify(
342
+ {
343
+ "x-ui-globalOptions": {
344
+ disabled: true
345
+ }
346
+ },
347
+ null,
348
+ 2
349
+ ),
350
+ readonlyAll: JSON.stringify(
351
+ {
352
+ "x-ui-globalOptions": {
353
+ readonly: true
354
+ }
355
+ },
356
+ null,
357
+ 2
358
+ ),
359
+ fieldOverride: JSON.stringify(
360
+ {
361
+ "x-ui-globalOptions": {
362
+ disabled: true
363
+ },
364
+ name: {
365
+ "x-ui-options": {
366
+ disabled: false
367
+ // Override: enable this field
368
+ }
369
+ }
370
+ },
371
+ null,
372
+ 2
373
+ ),
374
+ customWidget: JSON.stringify(
375
+ {
376
+ description: {
377
+ "x-ui-widget": "textarea",
378
+ "x-ui-options": {
379
+ rows: 5
380
+ }
381
+ }
382
+ },
383
+ null,
384
+ 2
385
+ )
386
+ };
387
+ function usePlayFormsState() {
388
+ const [schemaText, setSchemaText] = useState(
389
+ JSON.stringify(SAMPLE_SCHEMA, null, 2)
390
+ );
391
+ const [uiSchemaText, setUiSchemaText] = useState("{}");
392
+ const [activeSchema, setActiveSchema] = useState(
393
+ SAMPLE_SCHEMA
394
+ );
395
+ const [activeUiSchema, setActiveUiSchema] = useState({});
396
+ const [dataText, setDataText] = useState("{}");
397
+ const [formData, setFormData] = useState({});
398
+ const [validationErrors, setValidationErrors] = useState([]);
399
+ const [isValid, setIsValid] = useState(true);
400
+ const [schemaError, setSchemaError] = useState("");
401
+ const [uiSchemaError, setUiSchemaError] = useState("");
402
+ const [dataError, setDataError] = useState("");
403
+ const [activeTab, setActiveTab] = useState("schema");
404
+ const [deferStateUpdates, setDeferStateUpdates] = useState(false);
405
+ const [dataCollapsed, setDataCollapsed] = useState(false);
406
+ const [lastDiff, setLastDiff] = useState(null);
407
+ const toggleDataPanel = useCallback(() => setDataCollapsed((v) => !v), []);
408
+ const loadSchemaPreset = useCallback(
409
+ (value) => {
410
+ if (!value || !sampleSchemas[value]) return;
411
+ const text = JSON.stringify(sampleSchemas[value], null, 2);
412
+ setSchemaText(text);
413
+ setActiveSchema(sampleSchemas[value]);
414
+ setSchemaError("");
415
+ setFormData({});
416
+ setDataText("{}");
417
+ const pairedUi = value === "row_layout" ? ROW_LAYOUT_UISCHEMA : {};
418
+ setUiSchemaText(JSON.stringify(pairedUi, null, 2));
419
+ setActiveUiSchema(pairedUi);
420
+ setUiSchemaError("");
421
+ },
422
+ [setSchemaText, setActiveSchema]
423
+ );
424
+ const loadUiSchemaPreset = useCallback(
425
+ (value) => {
426
+ if (!value) return;
427
+ setUiSchemaText(sampleUiSchemas[value]);
428
+ setUiSchemaError("");
429
+ },
430
+ [setUiSchemaText]
431
+ );
432
+ return {
433
+ schemaText,
434
+ uiSchemaText,
435
+ activeSchema,
436
+ activeUiSchema,
437
+ dataText,
438
+ formData,
439
+ validationErrors,
440
+ isValid,
441
+ schemaError,
442
+ uiSchemaError,
443
+ dataError,
444
+ activeTab,
445
+ deferStateUpdates,
446
+ dataCollapsed,
447
+ lastDiff,
448
+ setSchemaText,
449
+ setUiSchemaText,
450
+ setActiveSchema,
451
+ setActiveUiSchema,
452
+ setDataText,
453
+ setFormData,
454
+ setValidationErrors,
455
+ setIsValid,
456
+ setSchemaError,
457
+ setUiSchemaError,
458
+ setDataError,
459
+ setActiveTab,
460
+ setDeferStateUpdates,
461
+ toggleDataPanel,
462
+ setLastDiff,
463
+ loadSchemaPreset,
464
+ loadUiSchemaPreset
465
+ };
466
+ }
467
+ function tryParseAndSet(value, setError, errorMessage = "Invalid JSON") {
468
+ try {
469
+ JSON.parse(value);
470
+ setError("");
471
+ } catch {
472
+ setError(errorMessage);
473
+ }
474
+ }
475
+ function tryParseAndLoad(text, onSuccess, onError) {
476
+ try {
477
+ onSuccess(JSON.parse(text));
478
+ onError("");
479
+ } catch {
480
+ onError("Invalid JSON - cannot load to form");
481
+ }
482
+ }
483
+ function SchemaEditorColumn({
484
+ state
485
+ }) {
486
+ const handleSchemaTextChange = (value) => {
487
+ state.setSchemaText(value);
488
+ tryParseAndSet(value, state.setSchemaError);
489
+ };
490
+ const handleUiSchemaTextChange = (value) => {
491
+ state.setUiSchemaText(value);
492
+ tryParseAndSet(value, state.setUiSchemaError);
493
+ };
494
+ const handleLoadSchemaToForm = () => {
495
+ tryParseAndLoad(
496
+ state.schemaText,
497
+ (parsed) => {
498
+ state.setActiveSchema(parsed);
499
+ state.setFormData({});
500
+ state.setDataText("{}");
501
+ state.setValidationErrors([]);
502
+ state.setIsValid(true);
503
+ state.setLastDiff(null);
504
+ },
505
+ state.setSchemaError
506
+ );
507
+ };
508
+ const handleLoadUiSchemaToForm = () => {
509
+ tryParseAndLoad(
510
+ state.uiSchemaText,
511
+ state.setActiveUiSchema,
512
+ state.setUiSchemaError
513
+ );
514
+ };
515
+ return /* @__PURE__ */ jsxs(
516
+ "div",
517
+ {
518
+ style: {
519
+ flex: 1,
520
+ position: "relative",
521
+ display: "flex",
522
+ flexDirection: "column",
523
+ minWidth: 0
524
+ },
525
+ children: [
526
+ /* @__PURE__ */ jsx(Card, { className: "border shadow-sm p-4 flex-1 min-h-0 flex flex-col", children: /* @__PURE__ */ jsxs(
527
+ Tabs,
528
+ {
529
+ value: state.activeTab,
530
+ onValueChange: state.setActiveTab,
531
+ style: {
532
+ flex: 1,
533
+ minHeight: 0,
534
+ display: "flex",
535
+ flexDirection: "column"
536
+ },
537
+ children: [
538
+ /* @__PURE__ */ jsxs(TabsList, { className: "mb-1", children: [
539
+ /* @__PURE__ */ jsx(TabsTrigger, { value: "schema", children: "JSON Schema" }),
540
+ /* @__PURE__ */ jsx(TabsTrigger, { value: "uischema", children: "UI Schema" })
541
+ ] }),
542
+ /* @__PURE__ */ jsxs(
543
+ TabsContent,
544
+ {
545
+ value: "schema",
546
+ className: "flex-1 min-h-0 flex flex-col mt-0",
547
+ children: [
548
+ /* @__PURE__ */ jsx(
549
+ FormSelect,
550
+ {
551
+ placeholder: "Load example schema...",
552
+ options: SCHEMA_PRESET_OPTIONS,
553
+ onChange: state.loadSchemaPreset,
554
+ className: "text-xs",
555
+ wrapperClassName: "mb-2"
556
+ }
557
+ ),
558
+ state.schemaError && /* @__PURE__ */ jsx(Badge, { variant: "destructive", className: "text-xs mb-2", children: state.schemaError }),
559
+ /* @__PURE__ */ jsx(
560
+ JsonEditor,
561
+ {
562
+ value: state.schemaText,
563
+ editablePaths: ["/"],
564
+ onChange: handleSchemaTextChange,
565
+ height: "100%",
566
+ className: "flex-1 min-h-0 rounded-md border overflow-hidden"
567
+ }
568
+ )
569
+ ]
570
+ }
571
+ ),
572
+ /* @__PURE__ */ jsxs(
573
+ TabsContent,
574
+ {
575
+ value: "uischema",
576
+ className: "flex-1 min-h-0 flex flex-col mt-0",
577
+ children: [
578
+ /* @__PURE__ */ jsx(
579
+ FormSelect,
580
+ {
581
+ placeholder: "Load example...",
582
+ options: UISCHEMA_PRESET_OPTIONS,
583
+ onChange: state.loadUiSchemaPreset,
584
+ className: "text-xs",
585
+ wrapperClassName: "mb-2"
586
+ }
587
+ ),
588
+ state.uiSchemaError && /* @__PURE__ */ jsx(Badge, { variant: "destructive", className: "text-xs mb-2", children: state.uiSchemaError }),
589
+ /* @__PURE__ */ jsx(
590
+ JsonEditor,
591
+ {
592
+ value: state.uiSchemaText,
593
+ editablePaths: ["/"],
594
+ onChange: handleUiSchemaTextChange,
595
+ height: "100%",
596
+ className: "flex-1 min-h-0 rounded-md border overflow-hidden"
597
+ }
598
+ )
599
+ ]
600
+ }
601
+ )
602
+ ]
603
+ }
604
+ ) }),
605
+ /* @__PURE__ */ jsx(
606
+ SimpleTooltip,
607
+ {
608
+ label: state.activeTab === "schema" ? "Load Schema to Form" : "Load UI Schema to Form",
609
+ children: /* @__PURE__ */ jsx(
610
+ Button,
611
+ {
612
+ variant: "default",
613
+ size: "icon",
614
+ className: "absolute -right-5 top-1/2 -translate-y-1/2 z-[100]",
615
+ onClick: state.activeTab === "schema" ? handleLoadSchemaToForm : handleLoadUiSchemaToForm,
616
+ children: /* @__PURE__ */ jsx(ArrowRight, { size: 20 })
617
+ }
618
+ )
619
+ }
620
+ )
621
+ ]
622
+ }
623
+ );
624
+ }
625
+ var SCHEMA_PRESET_OPTIONS = [
626
+ { value: "flat", label: "Practitioner (flat fields)" },
627
+ { value: "nested_object", label: "Patient (nested object)" },
628
+ { value: "array_of_objects", label: "Medication Request (array)" },
629
+ { value: "ref_defs", label: "Care Plan ($ref / $defs)" },
630
+ { value: "mixed", label: "Organization (mixed)" },
631
+ { value: "horizontal_array", label: "Observations (horizontal, compact)" },
632
+ { value: "horizontal_full", label: "Allergies (horizontal, full height)" },
633
+ { value: "row_layout", label: "Registration (row layout)" }
634
+ ];
635
+ var UISCHEMA_PRESET_OPTIONS = [
636
+ { value: "empty", label: "Empty (no customization)" },
637
+ { value: "hideLabels", label: "Hide all labels" },
638
+ { value: "disableAll", label: "Disable all fields" },
639
+ { value: "readonlyAll", label: "Readonly all fields" },
640
+ { value: "fieldOverride", label: "Field-level override" },
641
+ { value: "customWidget", label: "Custom widget" }
642
+ ];
643
+ function FormColumn({
644
+ state
645
+ }) {
646
+ const handleUpdate = (data, _changedFields, diff) => {
647
+ state.setDataText(JSON.stringify(data, null, 2));
648
+ state.setFormData(data);
649
+ state.setLastDiff(diff);
650
+ };
651
+ const handleCancel = () => {
652
+ state.setFormData({});
653
+ state.setDataText("{}");
654
+ state.setValidationErrors([]);
655
+ state.setIsValid(true);
656
+ state.setLastDiff(null);
657
+ };
658
+ const handleValidationChange = (errors, valid) => {
659
+ state.setValidationErrors(errors);
660
+ state.setIsValid(valid);
661
+ };
662
+ const handleLoadDataToForm = () => {
663
+ tryParseAndLoad(state.dataText, state.setFormData, state.setDataError);
664
+ };
665
+ return /* @__PURE__ */ jsxs(
666
+ "div",
667
+ {
668
+ style: {
669
+ flex: 1,
670
+ position: "relative",
671
+ display: "flex",
672
+ flexDirection: "column",
673
+ minWidth: 0
674
+ },
675
+ children: [
676
+ /* @__PURE__ */ jsx(Card, { className: "border shadow-sm p-4 flex-1 min-h-0 flex flex-col", children: /* @__PURE__ */ jsxs(
677
+ SimpleStack,
678
+ {
679
+ gap: "md",
680
+ style: {
681
+ flex: 1,
682
+ minHeight: 0,
683
+ display: "flex",
684
+ flexDirection: "column"
685
+ },
686
+ children: [
687
+ /* @__PURE__ */ jsxs("div", { children: [
688
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold mb-1", children: "Rendered Form" }),
689
+ /* @__PURE__ */ jsxs(SimpleGroup, { gap: "xs", align: "center", className: "mb-1", children: [
690
+ /* @__PURE__ */ jsx(
691
+ Badge,
692
+ {
693
+ variant: state.isValid ? "default" : "destructive",
694
+ className: "text-xs",
695
+ children: state.isValid ? "Valid" : "Invalid"
696
+ }
697
+ ),
698
+ /* @__PURE__ */ jsx(
699
+ FormCheckbox,
700
+ {
701
+ label: "Defer state updates (change on blur)",
702
+ checked: state.deferStateUpdates,
703
+ onChange: (checked) => {
704
+ if (checked !== "indeterminate") {
705
+ state.setDeferStateUpdates(checked);
706
+ }
707
+ }
708
+ }
709
+ )
710
+ ] }),
711
+ state.validationErrors.length > 0 && /* @__PURE__ */ jsx("div", { style: { marginTop: "4px" }, children: state.validationErrors.map((err, idx) => /* @__PURE__ */ jsx("p", { className: "text-xs text-red-600", children: err }, idx)) })
712
+ ] }),
713
+ /* @__PURE__ */ jsxs(
714
+ "div",
715
+ {
716
+ style: {
717
+ flex: 1,
718
+ minHeight: 0,
719
+ overflowY: "auto",
720
+ paddingRight: "4px"
721
+ },
722
+ children: [
723
+ state.activeSchema && /* @__PURE__ */ jsx(
724
+ JsonSchemaFormRenderer,
725
+ {
726
+ schema: state.activeSchema,
727
+ data: state.formData,
728
+ onUpdate: handleUpdate,
729
+ onCancel: handleCancel,
730
+ onValidationChange: handleValidationChange,
731
+ showActions: true,
732
+ deferStateUpdates: state.deferStateUpdates,
733
+ saveLabel: "Save Changes",
734
+ cancelLabel: "Reset",
735
+ showExtraProperties: true,
736
+ uiSchema: state.activeUiSchema
737
+ }
738
+ ),
739
+ !state.activeSchema && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground text-center mt-8", children: "Edit the JSON Schema on the left and click the arrow to load it" })
740
+ ]
741
+ }
742
+ )
743
+ ]
744
+ }
745
+ ) }),
746
+ !state.dataCollapsed && /* @__PURE__ */ jsx(SimpleTooltip, { label: "Load JSON Data into Form", children: /* @__PURE__ */ jsx(
747
+ Button,
748
+ {
749
+ variant: "default",
750
+ size: "icon",
751
+ className: "absolute -right-5 top-1/2 -translate-y-1/2 z-[100]",
752
+ onClick: handleLoadDataToForm,
753
+ children: /* @__PURE__ */ jsx(ArrowRight, { size: 20, className: "scale-x-[-1]" })
754
+ }
755
+ ) })
756
+ ]
757
+ }
758
+ );
759
+ }
760
+ function DataColumn({
761
+ state
762
+ }) {
763
+ const handleDataTextChange = (value) => {
764
+ state.setDataText(value);
765
+ tryParseAndSet(value, state.setDataError);
766
+ };
767
+ return /* @__PURE__ */ jsxs(
768
+ "div",
769
+ {
770
+ style: {
771
+ flex: state.dataCollapsed ? "0 0 2.25rem" : 1,
772
+ display: "flex",
773
+ flexDirection: "column",
774
+ minWidth: 0,
775
+ gap: "0.75rem",
776
+ transition: "flex 200ms ease"
777
+ },
778
+ children: [
779
+ /* @__PURE__ */ jsxs(
780
+ Card,
781
+ {
782
+ className: "border shadow-sm min-h-0 flex flex-col overflow-hidden",
783
+ style: { flex: "1 1 50%" },
784
+ children: [
785
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3 shrink-0", children: [
786
+ !state.dataCollapsed && /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold", children: "JSON Data" }),
787
+ /* @__PURE__ */ jsx(
788
+ SimpleTooltip,
789
+ {
790
+ label: state.dataCollapsed ? "Expand JSON data" : "Collapse JSON data",
791
+ children: /* @__PURE__ */ jsx(
792
+ Button,
793
+ {
794
+ variant: "ghost",
795
+ size: "compact",
796
+ onClick: state.toggleDataPanel,
797
+ className: "ml-auto",
798
+ children: state.dataCollapsed ? /* @__PURE__ */ jsx(ChevronLeft, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(ChevronRightIcon, { className: "h-4 w-4" })
799
+ }
800
+ )
801
+ }
802
+ )
803
+ ] }),
804
+ !state.dataCollapsed && /* @__PURE__ */ jsxs("div", { className: "flex-1 min-h-0 flex flex-col px-4 pb-4", children: [
805
+ state.dataError && /* @__PURE__ */ jsx(Badge, { variant: "destructive", className: "text-xs mb-2", children: state.dataError }),
806
+ /* @__PURE__ */ jsx(
807
+ JsonEditor,
808
+ {
809
+ value: state.dataText,
810
+ editablePaths: ["/"],
811
+ onChange: handleDataTextChange,
812
+ height: "100%",
813
+ className: "flex-1 min-h-0 rounded-md border overflow-hidden"
814
+ }
815
+ )
816
+ ] })
817
+ ]
818
+ }
819
+ ),
820
+ !state.dataCollapsed && /* @__PURE__ */ jsxs(
821
+ Card,
822
+ {
823
+ className: "border shadow-sm min-h-0 flex flex-col overflow-hidden",
824
+ style: { flex: "1 1 50%" },
825
+ children: [
826
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-4 py-3 shrink-0", children: /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold", children: "Diff" }) }),
827
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 flex flex-col px-4 pb-4", children: /* @__PURE__ */ jsx(
828
+ JsonEditor,
829
+ {
830
+ value: JSON.stringify(state.lastDiff ?? [], null, 2),
831
+ editablePaths: ["/"],
832
+ height: "100%",
833
+ className: "flex-1 min-h-0 rounded-md border overflow-hidden"
834
+ }
835
+ ) })
836
+ ]
837
+ }
838
+ )
839
+ ]
840
+ }
841
+ );
842
+ }
843
+ function PlayForms() {
844
+ const state = usePlayFormsState();
845
+ return /* @__PURE__ */ jsxs(
846
+ "div",
847
+ {
848
+ style: {
849
+ width: "100%",
850
+ height: "100vh",
851
+ display: "flex",
852
+ flexDirection: "column",
853
+ overflow: "hidden"
854
+ },
855
+ children: [
856
+ /* @__PURE__ */ jsxs("div", { style: { padding: "1rem 1rem 0 1rem" }, children: [
857
+ /* @__PURE__ */ jsx("h1", { children: "Forms Playground" }),
858
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mb-3", children: "Test and experiment with JsonSchemaFormRenderer. Edit the JSON Schema on the left, then load it into the form." })
859
+ ] }),
860
+ /* @__PURE__ */ jsxs(
861
+ "div",
862
+ {
863
+ style: {
864
+ flex: 1,
865
+ minHeight: 0,
866
+ padding: "0 1rem 1rem 1rem",
867
+ display: "flex",
868
+ gap: "1.5rem"
869
+ },
870
+ children: [
871
+ /* @__PURE__ */ jsx(SchemaEditorColumn, { state }),
872
+ /* @__PURE__ */ jsx(FormColumn, { state }),
873
+ /* @__PURE__ */ jsx(DataColumn, { state })
874
+ ]
875
+ }
876
+ )
877
+ ]
878
+ }
879
+ );
880
+ }
881
+
882
+ export {
883
+ PlayForms
884
+ };
885
+ //# sourceMappingURL=chunk-QIETZUEN.js.map