-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudio.html
More file actions
1247 lines (1161 loc) · 62.8 KB
/
Copy pathstudio.html
File metadata and controls
1247 lines (1161 loc) · 62.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Parser Engine — Schema Studio</title>
<!-- Upstream libraries — self-hosted (no third-party requests). Versions pinned to the engine build. -->
<script src="assets/papaparse.min.js"></script>
<script src="assets/xlsx.full.min.js"></script>
<script src="assets/mammoth.browser.min.js"></script>
<script src="assets/fxparser.min.js"></script>
<script src="assets/jszip.min.js"></script>
<!-- DPE itself -->
<script src="dist/dpe.iife.js"></script>
<script src="dist/version.js"></script>
<script src="dist/studio-version.js"></script>
<!-- apply saved theme before paint (avoids flash); default is dark -->
<script>(function(){try{if(localStorage.getItem('dpe-studio-theme')==='light')document.documentElement.setAttribute('data-theme','light');}catch(e){}})();</script>
<style>
/* ---- self-hosted fonts (match the marketing site; no third-party requests) ---- */
@font-face{font-family:"Clash Display";font-style:normal;font-weight:600;font-display:swap;src:url("assets/fonts/clash-display-600.woff2") format("woff2")}
@font-face{font-family:"Clash Display";font-style:normal;font-weight:700;font-display:swap;src:url("assets/fonts/clash-display-700.woff2") format("woff2")}
@font-face{font-family:"General Sans";font-style:normal;font-weight:400;font-display:swap;src:url("assets/fonts/general-sans-400.woff2") format("woff2")}
@font-face{font-family:"General Sans";font-style:normal;font-weight:500;font-display:swap;src:url("assets/fonts/general-sans-500.woff2") format("woff2")}
@font-face{font-family:"General Sans";font-style:normal;font-weight:600;font-display:swap;src:url("assets/fonts/general-sans-600.woff2") format("woff2")}
@font-face{font-family:"JetBrains Mono";font-style:normal;font-weight:100 800;font-display:swap;src:url("assets/fonts/jetbrains-mono.woff2") format("woff2")}
/* ---- dark theme — site palette (ink + acid-chartreuse). Layout unchanged. ---- */
:root {
--bg: #0a0b0e;
--panel: #101319;
--panel-alt: #13161d;
--border: #262c39;
--border-soft: #1a1e28;
--text: #eef1f6;
--muted: #b6bfce;
--faint: #929cae;
--accent: #cdfb47;
--accent-hover: #aadb2c;
--accent-ink: #1a2106;
--cyan: #5cd6ff;
--ok: #7ee787;
--warn: #ffbe6b;
--err: #ff6f6f;
--code-bg: #0c0e13;
--code-fg: #d2d8e3;
--badge-ok-bg: rgba(126,231,135,0.13);
--badge-warn-bg: rgba(255,190,107,0.14);
--badge-err-bg: rgba(255,111,111,0.15);
--code-inline-bg: rgba(205,251,71,0.10);
--code-inline-fg: #e6f5b6;
--ok-ink: #0a0b0e;
--display: "Clash Display", system-ui, sans-serif;
--body: "General Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
--mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
/* light theme — the original Studio palette; user-selectable + persisted (default is dark) */
html[data-theme="light"] {
--bg: #f4f4f5;
--panel: #ffffff;
--panel-alt: #f7f7f8;
--border: #d4d4d8;
--border-soft: #e8e8eb;
--text: #18181b;
--muted: #71717a;
--faint: #94a3b8;
--accent: #2563eb;
--accent-hover: #1d4ed8;
--accent-ink: #ffffff;
--cyan: #0891b2;
--ok: #16a34a;
--warn: #d97706;
--err: #dc2626;
--code-bg: #1e1e2e;
--code-fg: #cdd6f4;
--badge-ok-bg: #dcfce7;
--badge-warn-bg: #fef3c7;
--badge-err-bg: #fee2e2;
--code-inline-bg: #f1f1f3;
--code-inline-fg: #18181b;
--ok-ink: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--body); }
body { padding: 16px; max-width: 1280px; margin: 0 auto; }
h1 { font-size: 1.3rem; margin: 0 0 12px; font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.0rem; margin: 16px 0 8px; font-family: var(--display); font-weight: 600; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--muted); margin: 14px 0 6px; }
select, input[type="text"], textarea, input[type="file"] {
width: 100%; padding: 6px 8px; font-size: 0.9rem; font-family: inherit;
border: 1px solid var(--border); border-radius: 4px; background: var(--panel-alt); color: var(--text);
}
select:focus, input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 0.82rem; min-height: 70px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; font-style: italic; }
.field-group { margin-bottom: 12px; }
.app-footer { margin-top: 24px; padding: 10px 0 4px; border-top: 1px solid var(--border);
text-align: center; font-size: 0.78rem; color: var(--muted); font-family: var(--mono); }
button {
background: var(--accent); color: var(--accent-ink); border: none; padding: 8px 16px;
font-size: 0.95rem; font-weight: 600; border-radius: 4px; cursor: pointer; font-family: var(--body);
}
button:hover { background: var(--accent-hover); }
button:disabled { background: var(--border); color: var(--faint); cursor: not-allowed; }
.row { display: flex; gap: 12px; align-items: center; }
.row > * { flex: 1; }
.radio-row { display: flex; gap: 16px; padding: 4px 0; }
.radio-row label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-weight: normal; color: var(--text); cursor: pointer; }
.radio-row input[type="radio"] { margin: 0; }
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.tab { padding: 6px 12px; cursor: pointer; border: none; background: none; font-size: 0.9rem; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.tab-content { display: none; }
.tab-content.active { display: block; }
pre { background: var(--code-bg); color: var(--code-fg); padding: 12px; border-radius: 6px;
overflow: auto; font-size: 0.8rem; line-height: 1.4; max-height: 480px; margin: 0; border: 1px solid var(--border-soft); font-family: var(--mono); }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
th { background: var(--panel-alt); font-weight: 600; color: var(--text); }
td { color: var(--muted); font-family: var(--mono); font-size: 0.82rem; }
.meta-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.9rem; }
.meta-grid dt { color: var(--muted); font-weight: 500; }
.meta-grid dd { margin: 0; font-family: var(--mono); color: var(--text); }
.badge { display: inline-block; padding: 2px 6px; font-size: 0.7rem; border-radius: 3px; margin-left: 6px; font-weight: 500; }
.badge.ok { background: var(--badge-ok-bg); color: var(--ok); }
.badge.warn { background: var(--badge-warn-bg); color: var(--warn); }
.badge.err { background: var(--badge-err-bg); color: var(--err); }
.error-list { font-size: 0.85rem; }
.error-list li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.error-list .sev { font-weight: 600; margin-right: 6px; }
.error-list .sev-error { color: var(--err); }
.error-list .sev-warning { color: var(--warn); }
.hint { font-size: 0.8rem; color: var(--muted); margin: 4px 0; }
.hidden { display: none; }
.field-group { padding: 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel-alt); margin-bottom: 8px; }
.field-group h3 { font-size: 0.85rem; margin: 0 0 6px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.tab-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.tab-toolbar .hint { margin: 0; }
.btn-small { background: var(--accent); color: var(--accent-ink); border: none; padding: 4px 10px;
font-size: 0.8rem; font-weight: 600; border-radius: 4px; cursor: pointer; font-family: var(--body); }
.btn-small:hover { background: var(--accent-hover); }
.btn-small.copied { background: var(--ok); color: var(--ok-ink); }
.btn-small:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-small:disabled:hover { background: var(--accent); }
.tab-toolbar-actions { display: flex; gap: 6px; flex-shrink: 0; }
.upload-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.nostore-note { margin-top: 8px; padding: 8px 10px; border: 1px solid var(--border);
border-radius: 4px; background: var(--panel-alt); font-size: 0.82rem; color: var(--muted); }
.app-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.app-header h1 { margin: 0; }
.app-header__actions { display: flex; align-items: center; gap: 10px; }
.theme-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; cursor: pointer;
font-weight: 500; font-size: 0.88rem; background: var(--panel); border: 1px solid var(--border);
border-radius: 6px; color: var(--text); font-family: var(--body); }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.reference-panel { position: relative; }
.reference-panel > summary {
display: inline-flex; align-items: center; gap: 4px;
padding: 6px 14px; cursor: pointer;
font-weight: 500; font-size: 0.88rem;
background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
color: var(--text); list-style: none; user-select: none;
}
.reference-panel > summary::-webkit-details-marker { display: none; }
.reference-panel > summary::before { content: '\25B8'; display: inline-block; }
.reference-panel[open] > summary::before { content: '\25BE'; }
.reference-panel[open] > summary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.reference-panel-body {
position: fixed; top: 0; right: 0; height: 100vh; width: min(640px, 92vw);
background: var(--panel); border-left: 1px solid var(--border);
box-shadow: -8px 0 24px rgba(0,0,0,0.10);
overflow-y: auto;
padding: 18px 22px 32px 64px;
font-size: 0.85rem; line-height: 1.5;
z-index: 50;
}
.reference-close-bar {
position: fixed; top: 0; height: 100vh; width: 28px;
left: calc(100vw - min(640px, 92vw));
background: var(--panel-alt, #f5f5f7); border-right: 1px solid var(--border);
display: flex; align-items: center; justify-content: center;
cursor: pointer; color: var(--muted);
font-size: 1rem; user-select: none;
transition: background 120ms, color 120ms;
z-index: 51;
}
.reference-close-bar:hover { background: var(--accent); color: var(--accent-ink); }
.reference-close-bar[hidden] { display: none; }
.reference-close {
position: absolute; top: 8px; right: 12px;
background: transparent; border: none; color: var(--muted);
font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 2px 8px;
}
.reference-close:hover { color: var(--text); background: transparent; }
.reference-panel-body h3 { font-size: 0.95rem; margin: 18px 0 4px; color: var(--text);
text-transform: none; letter-spacing: 0; border-bottom: 1px solid var(--border); padding-bottom: 2px; }
.reference-panel-body h3:first-child { margin-top: 4px; }
.reference-panel-body h4 { font-size: 0.85rem; margin: 12px 0 4px; color: var(--text); font-weight: 600; }
.reference-panel-body p { margin: 4px 0 8px; }
.reference-panel-body dl { margin: 4px 0 8px; }
.reference-panel-body dt { font-family: var(--mono); font-weight: 600; margin-top: 6px; font-size: 0.83rem; color: var(--text); }
.reference-panel-body dd { margin: 2px 0 4px 16px; color: var(--text); }
.reference-panel-body code { background: var(--code-inline-bg); color: var(--code-inline-fg); padding: 1px 4px; border-radius: 3px; font-size: 0.82rem; font-family: var(--mono); }
.reference-panel-body pre { background: var(--code-bg); color: var(--code-fg); padding: 10px;
border-radius: 4px; font-size: 0.78rem; max-height: none; overflow-x: auto; margin: 4px 0 10px; }
.reference-panel-body pre code { background: transparent; padding: 0; font-size: inherit; }
</style>
</head>
<body>
<div class="app-header">
<h1>Data Parser Engine — Schema Studio</h1>
<div class="app-header__actions">
<button class="theme-toggle" id="themeToggle" type="button" aria-label="Switch light/dark theme" title="Switch light/dark">☀ Light</button>
<details class="reference-panel" id="referencePanel">
<summary>Reference</summary>
<div class="reference-panel-body">
<button class="reference-close-bar" id="referenceCloseBar" type="button" aria-label="Close reference panel" title="Close">▶</button>
<button class="reference-close" id="referenceClose" type="button" aria-label="Close reference panel">×</button>
<h3>What is a schema?</h3>
<p>A small object that tells DPE what kind of file you're handing it and how to extract records from it. The engine reads the file, follows the schema, and returns mapped JSON records plus diagnostics.</p>
<p>The schema you build in this Studio is exactly what gets passed to <code>DataParser.parse(file, schema)</code> in production. The <strong>DPE schema</strong> output tab shows that object — copy it from there when you're done.</p>
<h3>The output pipeline</h3>
<p>A parse runs through four stages, each visible as its own output tab:</p>
<dl>
<dt>RAW input</dt><dd>The file's original text as received, byte-for-byte. ("Binary format" for spreadsheet / document files — RAW text isn't applicable.)</dd>
<dt>Post-filter</dt><dd>Text after <code>dropRegex</code> lines have been stripped. Identical to RAW if no <code>dropRegex</code> is set.</dd>
<dt>Pre-mapping</dt><dd>Records as the format parser produced them, before <code>mapping</code> reshapes the fields. This is what shows up at <code>result.raw</code>.</dd>
<dt>Data</dt><dd>The final mapped records (<code>result.data</code>). Identical to Pre-mapping if no <code>mapping</code> is defined.</dd>
</dl>
<p>A fifth tab, <strong>DPE schema</strong>, shows the schema object that was just submitted to the engine — the artifact this session is producing. It refreshes on Parse, not as you edit the form.</p>
<h3>Saving & loading your work</h3>
<p><strong>No accounts, nothing stored.</strong> DPE parses your files entirely in your browser — nothing is uploaded and nothing is kept on a server. You save your work as files on your own disk and reload them here. Every example you load exercises these controls.</p>
<dl>
<dt>Download schema</dt><dd>On the <strong>DPE schema</strong> tab, <code>Download</code> saves the schema as <code>dpe-schema.json</code> — the same object <code>Copy</code> produces. It's the portable engine schema: drop it into any DPE consumer, or re-upload it here later.</dd>
<dt>Upload schema</dt><dd>In <strong>1. Input</strong>, "upload a saved schema" reads a <code>dpe-schema.json</code> and repopulates the whole form (including the mapping). Then load a data file and Parse.</dd>
<dt>Download results</dt><dd>On the <strong>Data</strong> tab, after a parse: <code>Download JSON</code> saves the records losslessly (handles nested objects); <code>Download CSV</code> saves them as CSV.</dd>
<dt>CSV dialect</dt><dd>Header row of field names, every value double-quoted, comma-delimited, UTF-8. For other dialects — or nested data — use JSON export.</dd>
</dl>
<p>Round-trip: tune a schema → download it → next time, upload the schema, load the data file, Parse, download the results. Naming and file management are yours.</p>
<h3>Form options</h3>
<dl>
<dt>format</dt><dd><strong>Required.</strong> The file type. Extension is ignored. Choices: <code>csv</code>, <code>prn</code>, <code>txt</code>, <code>fixed</code>, <code>xml</code>, <code>json</code>, <code>passthrough</code>, <code>xls</code>, <code>xlsx</code>, <code>ods</code>, <code>docx</code>, <code>odt</code>.</dd>
<dt>layout</dt><dd>Only for <code>prn</code> and <code>txt</code>. <code>delimited</code> = fields separated by a character (comma, pipe, tab). <code>fixed</code> = fields at known column positions.</dd>
<dt>encoding</dt><dd>Character encoding for text formats. Default <code>utf-8</code>. Use <code>windows-1252</code>, <code>iso-8859-1</code>, <code>cp437</code>, etc. for legacy dumps.</dd>
<dt>dropRegex</dt><dd>One regex per line. Each is compiled with the <code>m</code> flag. Any line matching any pattern is removed before the parser sees the file. Use it to strip page headers, dates, banner separators, decorative <code>===</code> lines. Applies to all text formats; ignored (with a warning) for spreadsheets / documents.</dd>
<dt>mapping</dt><dd>Output shaping. Syntax: <code>output = input</code>, one per line or comma-separated. Source may be a field name (<code>sku</code>), a dot path on nested objects (<code>Material.Category</code>), an XML attribute (<code>@_id</code>), a text node (<code>Pricing.Buy.#text</code>), or a 1-indexed positional integer (<code>3</code>). Missing values become <code>null</code>.</dd>
<dt>mapping mode</dt><dd><code>replace</code> (default) — output contains <em>only</em> the mapped target keys. <code>extend</code> — output contains all source fields with mapped target keys overlaid on top.</dd>
<dt>strict mode</dt><dd>If on, any error rejects the parse instead of being collected into <code>result.errors</code>.</dd>
</dl>
<h3>Format-specific knobs</h3>
<h4>Delimited — csv, prn+delimited, txt+delimited</h4>
<dl>
<dt>delimiter</dt><dd>Single character. Use the literal (<code>,</code>, <code>|</code>, <code>;</code>), <code>\t</code> for tab, or <code>auto</code> to let PapaParse autodetect.</dd>
<dt>quote char</dt><dd>Encloses field values that contain the delimiter. Default <code>"</code>.</dd>
<dt>first row is headers</dt><dd>If yes, the first row's values become field names (records are objects). If no, records are arrays — pair with positional mapping.</dd>
</dl>
<h4>Fixed-width — fixed, prn+fixed, txt+fixed</h4>
<dl>
<dt>fieldDefinitions</dt><dd>JSON array, <strong>required</strong>. Each entry: <code>{ name, start, end, trim? }</code>. <code>start</code> inclusive, <code>end</code> exclusive, both 0-based. <code>trim</code> defaults <code>true</code>.</dd>
</dl>
<h4>XML / JSON</h4>
<dl>
<dt>rootPath</dt><dd>Dot path to the array (or single record) to extract from the parsed tree, e.g. <code>Envelope.Body.Records.Record</code>. Omit to use the root.</dd>
</dl>
<h4>Spreadsheet — xls, xlsx, ods</h4>
<dl>
<dt>sheetName</dt><dd>Defaults to the workbook's first sheet.</dd>
</dl>
<h4>Passthrough</h4>
<p>No knobs. Output is <code>[{ line, text }]</code>, one record per line, 1-indexed. Useful when you want to inspect (or positionally map) a text file DPE doesn't structurally parse — raw EDIFACT / X12 dumps, log files, anything line-oriented.</p>
<h3>Recipes</h3>
<h4>Messy delimited file with header/footer cruft</h4>
<pre>{
format: 'csv',
delimiter: '|',
dropRegex: ['^=', '^Generated:', '^-{3,}', '^END OF']
}</pre>
<p>The <code>dropRegex</code> patterns strip banner separators, date stamps, dash lines, and trailing summaries. The parser only sees actual data rows.</p>
<h4>Passthrough for EDIFACT / X12</h4>
<pre>{
format: 'passthrough',
mapping: { segment: 1, payload: 2 }
}</pre>
<p>Each line of the EDI dump becomes a record <code>{ line, text }</code>. The positional mapping renames those two fields by index (<code>1</code> = <code>line</code>, <code>2</code> = <code>text</code>).</p>
<h4>Positional mapping for headerless CSV</h4>
<pre>{
format: 'csv',
hasHeaders: false,
mapping: { sku: 1, name: 2, buy: 3, sell: 4 }
}</pre>
<p>With <code>hasHeaders: false</code>, PapaParse returns each row as an array. Positional sources (1-indexed) map array slots to target names.</p>
<h4>Nested XML with attribute and text-node mapping</h4>
<pre>{
format: 'xml',
rootPath: 'Envelope.Body.Records.Record',
mapping: {
id: '@_id',
category: 'Material.Category',
buy: 'Pricing.Buy.#text'
}
}</pre>
<p><code>rootPath</code> drills into the parsed tree. The <code>@_</code> prefix accesses XML attributes (fast-xml-parser convention). <code>#text</code> accesses the text node of an element that also has attributes.</p>
</div>
</details>
</div>
</div>
<div class="grid">
<!-- ============= INPUT PANEL ============= -->
<div class="panel">
<h2>1. Input</h2>
<label for="fileInput">Load a price file</label>
<input type="file" id="fileInput">
<p class="hint">Select the buyer's export file to tune a schema against.</p>
<label for="exampleSelect">Or load an example</label>
<select id="exampleSelect">
<option value="">— pick an example —</option>
</select>
<p class="hint">Loads a sample file from <code>samples/</code> and pre-fills the schema.</p>
<label class="radio-row" style="margin-top: 6px;">
<input type="checkbox" id="includeMappingPresets" checked> Include mapping presets
</label>
<p class="hint">When off, loading an example leaves the Mapping field empty so you can see the raw parser output before any mapping is applied.</p>
<label for="uploadSchemaInput" style="margin-top: 10px;">Or upload a saved schema</label>
<div class="upload-row">
<input type="file" id="uploadSchemaInput" accept=".json,application/json">
</div>
<p class="hint">Reads a <code>dpe-schema.json</code> (downloaded from the schema tab) and repopulates the whole form. Then load a data file above and Parse.</p>
<p class="nostore-note"><strong>No accounts, nothing stored.</strong> DPE parses your files entirely in your browser — we never receive or keep your data. That's why you save your work by downloading the schema (and results) and reload it by uploading, rather than storing it on our servers. Your files, your disk, your naming.</p>
<h2>2. Schema</h2>
<div class="field-group">
<h3>format & layout</h3>
<div class="row">
<div>
<label for="formatSelect">Format</label>
<select id="formatSelect">
<option value="csv">csv</option>
<option value="prn">prn</option>
<option value="txt">txt</option>
<option value="fixed">fixed</option>
<option value="xml">xml</option>
<option value="json">json</option>
<option value="passthrough">passthrough</option>
<option value="xls">xls</option>
<option value="xlsx">xlsx</option>
<option value="ods">ods</option>
<option value="docx">docx</option>
<option value="odt">odt</option>
</select>
<p class="hint">File type. Extension is ignored.</p>
</div>
<div id="layoutWrap" class="hidden">
<label>Layout</label>
<div class="radio-row">
<label><input type="radio" name="layout" value="delimited"> delimited</label>
<label><input type="radio" name="layout" value="fixed"> fixed</label>
</div>
<p class="hint">Delimited = separator-based. Fixed = column-based.</p>
</div>
</div>
</div>
<!-- Delimited options -->
<div id="delimitedOptions" class="field-group hidden">
<h3>delimited options</h3>
<div class="row">
<div>
<label for="delimiter">Delimiter</label>
<input type="text" id="delimiter" value="," placeholder=", | \t ; auto">
<p class="hint">Single char. <code>\t</code> for tab, <code>auto</code> to detect.</p>
</div>
<div>
<label for="quoteChar">Quote char</label>
<input type="text" id="quoteChar" value='"'>
<p class="hint">Encloses values that contain the delimiter.</p>
</div>
</div>
<div class="row">
<div>
<label for="hasHeaders">First row is headers</label>
<select id="hasHeaders">
<option value="true">yes</option>
<option value="false">no</option>
</select>
<p class="hint">If no, rows arrive as arrays — use positional mapping.</p>
</div>
<div></div>
</div>
</div>
<!-- Fixed-width options -->
<div id="fixedOptions" class="field-group hidden">
<h3>fixed-width fieldDefinitions (JSON)</h3>
<textarea id="fieldDefinitions" placeholder='[{"name":"id","start":0,"end":10},{"name":"name","start":10,"end":30}]'></textarea>
<p class="hint">Each entry <code>{ name, start, end, trim? }</code>. 0-based, <code>start</code> inclusive, <code>end</code> exclusive. <code>trim</code> defaults true.</p>
</div>
<!-- XML/JSON options -->
<div id="rootPathOptions" class="field-group hidden">
<h3>xml / json options</h3>
<label for="rootPath">rootPath (dot notation)</label>
<input type="text" id="rootPath" placeholder="e.g., Envelope.Body.Records.Record">
<p class="hint">Dot path to the array (or record) inside the parsed tree. Omit to use the root.</p>
</div>
<!-- Spreadsheet options -->
<div id="sheetOptions" class="field-group hidden">
<h3>spreadsheet options</h3>
<label for="sheetName">sheetName (blank = first sheet)</label>
<input type="text" id="sheetName" placeholder="">
</div>
<!-- Common options -->
<div class="field-group">
<h3>common</h3>
<label for="encoding">Encoding (text formats)</label>
<input type="text" id="encoding" value="utf-8" placeholder="utf-8, windows-1252, iso-8859-1, …">
<p class="hint">Default <code>utf-8</code>. Use <code>windows-1252</code>, <code>iso-8859-1</code>, <code>cp437</code> for legacy dumps.</p>
<label for="dropRegex">dropRegex (one regex per line)</label>
<textarea id="dropRegex" placeholder="^Page \d+ ^={3,}"></textarea>
<p class="hint">Lines matching any pattern are stripped before parsing. <code>m</code>-flag, line-anchored. Text formats only.</p>
<label for="mapping">Mapping</label>
<textarea id="mapping" placeholder='Syntax: target = source — one per line or comma-separated. Source: field name, dot path (a.b.c), @_attr, #text, or 1-indexed integer. Lines starting with # or // are comments and are ignored. Examples: product = sku price = buy sku = 1, name = 2, price = 3'></textarea>
<p class="hint">Syntax: <code>output = input</code>, one per line or comma-separated. Source may be a field name (with dot-path for nested), or a positive integer for positional access (1-indexed). Comments (<code>#</code>, <code>//</code>) supported.</p>
<label for="mappingMode">Mapping mode</label>
<select id="mappingMode">
<option value="replace">replace — only mapped fields in data</option>
<option value="extend">extend — source fields + mapped fields</option>
</select>
<p class="hint" id="mappingModeHint">Only applies when a mapping is defined above.</p>
<label class="radio-row" style="margin-top: 14px;">
<input type="checkbox" id="strict"> Strict mode (throw on any error)
</label>
<p class="hint">If on, any error rejects the parse instead of being collected in <code>result.errors</code>.</p>
<label class="radio-row" style="margin-top: 10px;">
<input type="checkbox" id="verboseSchema"> Write all options to schema (include defaults)
</label>
<p class="hint">When on, the schema sent to the engine includes every option relevant to the chosen format, even when at its default value. Useful for self-documenting schemas.</p>
</div>
<button id="parseBtn">Parse</button>
<span id="parseStatus" style="margin-left: 10px; font-size: 0.85rem;"></span>
</div>
<!-- ============= OUTPUT PANEL ============= -->
<div class="panel">
<h2>3. Output</h2>
<div class="tabs">
<button class="tab active" data-tab="rawinput">RAW input</button>
<button class="tab" data-tab="postfilter">Post-filter <span id="postFilterBadge" class="badge ok">0</span></button>
<button class="tab" data-tab="premapping">Pre-mapping <span id="preMappingBadge" class="badge ok">0</span></button>
<button class="tab" data-tab="data">Data <span id="dataBadge" class="badge ok">0</span></button>
<button class="tab" data-tab="errors">errors <span id="errorsBadge" class="badge">0</span></button>
<button class="tab" data-tab="meta">meta</button>
<button class="tab" data-tab="raw">raw JSON</button>
<button class="tab" data-tab="schema">DPE schema</button>
</div>
<div id="tab-rawinput" class="tab-content active">
<p class="hint">Stage 1 — original file content as received, before any processing.</p>
<div id="rawInputView"><p class="hint">Parse a file to see output.</p></div>
</div>
<div id="tab-postfilter" class="tab-content">
<p class="hint">Stage 2 — text after <code>dropRegex</code> stripping.</p>
<div id="postFilterView"></div>
</div>
<div id="tab-premapping" class="tab-content">
<p class="hint">Stage 3 — records as the format parser produced them, before <code>mapping</code> reshapes the fields.</p>
<div id="preMappingView"></div>
</div>
<div id="tab-data" class="tab-content">
<div class="tab-toolbar">
<p class="hint">Stage 4 — final mapped records (<code>result.data</code>). Download as JSON (lossless, nested-safe) or CSV (header row, every value double-quoted, comma-delimited, UTF-8).</p>
<span class="tab-toolbar-actions">
<button id="downloadResultsJsonBtn" class="btn-small" type="button" disabled>Download JSON</button>
<button id="downloadResultsCsvBtn" class="btn-small" type="button" disabled>Download CSV</button>
</span>
</div>
<div id="dataView"></div>
</div>
<div id="tab-errors" class="tab-content">
<ul id="errorList" class="error-list"></ul>
</div>
<div id="tab-meta" class="tab-content">
<dl id="metaView" class="meta-grid"></dl>
</div>
<div id="tab-raw" class="tab-content">
<pre id="rawView"></pre>
</div>
<div id="tab-schema" class="tab-content">
<div class="tab-toolbar">
<p class="hint">The schema object the engine just received — the artifact this Studio session is producing. Copy, or download as <code>dpe-schema.json</code> to reuse in any DPE consumer (or re-upload here later). Refreshes on Parse.</p>
<span class="tab-toolbar-actions">
<button id="copySchemaBtn" class="btn-small" type="button">Copy</button>
<button id="downloadSchemaBtn" class="btn-small" type="button" disabled>Download</button>
</span>
</div>
<pre id="schemaView"><span class="hint">Parse a file to see the schema.</span></pre>
</div>
</div>
</div>
<script>
// ============================================================================
// Example registry — pre-canned scenarios (sample file + suggested schema)
// ============================================================================
const EXAMPLES = [
{
label: 'csv — basic (basic.csv)',
file: 'samples/basic.csv',
schema: {
format: 'csv',
mapping: { product: 'id', label: 'name', buy_price: 'price', weight: 'weight_lbs' }
}
},
{
label: 'csv — pipe-delimited with header/footer cruft (messy-pipe.csv)',
file: 'samples/messy-pipe.csv',
schema: {
format: 'csv',
delimiter: '|',
dropRegex: ['^=', '^Generated:', '^-{3,}', '^END OF'],
mapping: { product: 'id', label: 'name', buy: 'price', weight: 'weight_lbs' }
}
},
{
label: 'prn delimited (pricelist-pipe.prn)',
file: 'samples/pricelist-pipe.prn',
schema: {
format: 'prn', layout: 'delimited',
delimiter: '|',
dropRegex: ['^SCRAP PRICE', '^Report Date:', '^Page ', '^=+$', '^End of'],
mapping: { product: 'sku', label: 'description', buy: 'buy_price', sell: 'sell_price' }
}
},
{
label: 'prn fixed-width (pricelist-columns.prn)',
file: 'samples/pricelist-columns.prn',
schema: {
format: 'prn', layout: 'fixed',
dropRegex: [
'^SCRAP PRICE', '^Report Date:', '^Page ',
'^=+$', '^-{3,}', '^SKU\\s', '^End of'
],
fieldDefinitions: [
{ name: 'sku', start: 0, end: 9 },
{ name: 'description', start: 9, end: 34 },
{ name: 'buy', start: 34, end: 43 },
{ name: 'sell', start: 43, end: 51 },
{ name: 'unit', start: 51, end: 60 }
],
mapping: { product: 'sku', label: 'description', buy_price: 'buy', sell_price: 'sell', uom: 'unit' }
}
},
{
label: 'txt delimited (inventory-tabs.txt, tab-separated)',
file: 'samples/inventory-tabs.txt',
schema: {
format: 'txt', layout: 'delimited', delimiter: '\t',
mapping: { product: 'item_code', kind: 'category', stock: 'on_hand_lbs', unit_price: 'unit_price' }
}
},
{
label: 'txt fixed-width (inventory-columns.txt)',
file: 'samples/inventory-columns.txt',
schema: {
format: 'txt', layout: 'fixed',
fieldDefinitions: [
{ name: 'item_code', start: 0, end: 10 },
{ name: 'category', start: 10, end: 22 },
{ name: 'on_hand', start: 22, end: 32 },
{ name: 'price', start: 32, end: 40 }
],
mapping: { product: 'item_code', kind: 'category', stock: 'on_hand', unit_price: 'price' }
}
},
{
label: 'xml with nested rootPath (nested.xml)',
file: 'samples/nested.xml',
schema: {
format: 'xml',
rootPath: 'Envelope.Body.Records.Record',
mapping: { id: '@_id', category: 'Material.Category', buy: 'Pricing.Buy.#text' }
}
},
{
label: 'json with rootPath + mapping (records.json)',
file: 'samples/records.json',
schema: {
format: 'json',
rootPath: 'data.prices',
mapping: { id: 'sku', price: 'buy' }
}
},
{
label: 'xlsx (workbook.xlsx)',
file: 'samples/workbook.xlsx',
schema: {
format: 'xlsx',
mapping: { product: 'sku', kind: 'category', buy_price: 'buy', sell_price: 'sell' }
}
},
{
label: 'ods (workbook.ods)',
file: 'samples/workbook.ods',
schema: {
format: 'ods',
mapping: { product: 'sku', kind: 'category', buy_price: 'buy', sell_price: 'sell' }
}
},
{
label: 'docx — paragraph extraction (doc.docx)',
file: 'samples/doc.docx',
schema: {
format: 'docx',
mapping: { line_num: 'index', body: 'text' }
}
},
{
label: 'odt — paragraphs + price table (doc.odt)',
file: 'samples/doc.odt',
schema: {
format: 'odt',
mapping: { line_num: 'index', body: 'text' }
}
},
{
label: 'passthrough — EDIFACT PRICAT (pricat.edi)',
file: 'samples/pricat.edi',
schema: {
format: 'passthrough',
mapping: { segment: 1, payload: 2 }
}
},
{
label: 'passthrough — X12 832 catalog (catalog-832.edi)',
file: 'samples/catalog-832.edi',
schema: {
format: 'passthrough',
mapping: { segment: 1, payload: 2 }
}
}
];
// ============================================================================
// Mapping DSL — UI-only convenience that compiles to/from {target: source}.
// Syntax: "output = input", one per line or comma-separated.
// RHS that is all digits → positive integer (1-indexed positional).
// Everything else → string (supports dot-paths and special chars like @_).
// ============================================================================
function mappingToDSL(obj) {
if (!obj || typeof obj !== 'object') return '';
return Object.entries(obj).map(([k, v]) => `${k} = ${v}`).join('\n');
}
function parseMappingDSL(text) {
const out = {};
const tokens = text.split(/[\n,]/).map(s => s.trim()).filter(Boolean);
for (const tok of tokens) {
if (tok.startsWith('#') || tok.startsWith('//')) continue;
const eq = tok.indexOf('=');
if (eq < 0) throw new Error(`mapping line missing '=': "${tok}"`);
const target = tok.slice(0, eq).trim();
const srcRaw = tok.slice(eq + 1).trim();
if (!target) throw new Error(`mapping line missing target: "${tok}"`);
if (!srcRaw) throw new Error(`mapping line missing source: "${tok}"`);
out[target] = /^\d+$/.test(srcRaw) ? parseInt(srcRaw, 10) : srcRaw;
}
return out;
}
// ============================================================================
// State
// ============================================================================
let currentPayload = null; // Blob | File loaded from file input or fetched example
let currentName = null;
let lastResult = null; // last parse result — backs the results-download buttons
// ============================================================================
// UI element refs
// ============================================================================
const $ = id => document.getElementById(id);
const exampleSelect = $('exampleSelect');
const fileInput = $('fileInput');
const formatSelect = $('formatSelect');
const layoutWrap = $('layoutWrap');
const delimitedOpts = $('delimitedOptions');
const fixedOpts = $('fixedOptions');
const rootPathOpts = $('rootPathOptions');
const sheetOpts = $('sheetOptions');
const parseBtn = $('parseBtn');
const parseStatus = $('parseStatus');
// ============================================================================
// Populate examples
// ============================================================================
for (const [i, ex] of EXAMPLES.entries()) {
const opt = document.createElement('option');
opt.value = String(i);
opt.textContent = ex.label;
exampleSelect.appendChild(opt);
}
// ============================================================================
// Wire up format/layout → adaptive options panels
// ============================================================================
const NEEDS_LAYOUT = new Set(['prn', 'txt']);
const TEXT_DELIMITED = new Set(['csv']);
const TEXT_FIXED = new Set(['fixed']);
const XML_JSON = new Set(['xml', 'json']);
const SPREADSHEET = new Set(['xls', 'xlsx', 'ods']);
const TEXT_FORMATS = new Set(['csv', 'prn', 'txt', 'fixed', 'xml', 'json', 'passthrough']);
function refreshOptionVisibility() {
const fmt = formatSelect.value;
const needsLayout = NEEDS_LAYOUT.has(fmt);
layoutWrap.classList.toggle('hidden', !needsLayout);
let effLayout = null;
if (TEXT_DELIMITED.has(fmt)) effLayout = 'delimited';
else if (TEXT_FIXED.has(fmt)) effLayout = 'fixed';
else if (needsLayout) {
const r = document.querySelector('input[name="layout"]:checked');
effLayout = r ? r.value : null;
}
delimitedOpts.classList.toggle('hidden', effLayout !== 'delimited');
fixedOpts.classList.toggle('hidden', effLayout !== 'fixed');
rootPathOpts.classList.toggle('hidden', !XML_JSON.has(fmt));
sheetOpts.classList.toggle('hidden', !SPREADSHEET.has(fmt));
}
formatSelect.addEventListener('change', refreshOptionVisibility);
document.querySelectorAll('input[name="layout"]').forEach(r => {
r.addEventListener('change', refreshOptionVisibility);
});
refreshOptionVisibility();
// ============================================================================
// mappingMode dropdown — only meaningful when a mapping is defined
// ============================================================================
function refreshMappingModeState() {
const hasMapping = $('mapping').value.trim().length > 0;
$('mappingMode').disabled = !hasMapping;
$('mappingModeHint').textContent = hasMapping
? 'Applied when building the data records.'
: 'Disabled — define a mapping above to enable.';
}
$('mapping').addEventListener('input', refreshMappingModeState);
refreshMappingModeState();
// ============================================================================
// File input
// ============================================================================
fileInput.addEventListener('change', e => {
const f = e.target.files[0];
if (f) {
currentPayload = f;
currentName = f.name;
parseStatus.textContent = `loaded: ${f.name} (${f.size} bytes)`;
}
});
// ============================================================================
// Example loader
// ============================================================================
exampleSelect.addEventListener('change', async e => {
const idx = parseInt(e.target.value, 10);
if (isNaN(idx)) return;
const ex = EXAMPLES[idx];
parseStatus.textContent = `fetching ${ex.file}…`;
try {
const r = await fetch(ex.file);
if (!r.ok) throw new Error(`HTTP ${r.status} fetching ${ex.file}`);
currentPayload = await r.blob();
currentName = ex.file;
const schemaToApply = $('includeMappingPresets').checked
? ex.schema
: { ...ex.schema, mapping: undefined, mappingMode: undefined };
applySchemaToUI(schemaToApply);
refreshOptionVisibility();
refreshMappingModeState();
parseStatus.textContent = `loaded: ${ex.file} (${currentPayload.size} bytes)`;
} catch (err) {
parseStatus.textContent = `failed: ${err.message}`;
}
});
function applySchemaToUI(schema) {
formatSelect.value = schema.format;
if (schema.layout) {
document.querySelector(`input[name="layout"][value="${schema.layout}"]`).checked = true;
} else {
document.querySelectorAll('input[name="layout"]').forEach(r => r.checked = false);
}
$('delimiter').value = schema.delimiter ?? ',';
$('quoteChar').value = schema.quoteChar ?? '"';
$('hasHeaders').value = (schema.hasHeaders === false) ? 'false' : 'true';
$('fieldDefinitions').value = schema.fieldDefinitions
? JSON.stringify(schema.fieldDefinitions, null, 2) : '';
$('rootPath').value = schema.rootPath ?? '';
$('sheetName').value = schema.sheetName ?? '';
$('encoding').value = schema.encoding ?? 'utf-8';
$('dropRegex').value = schema.dropRegex
? (Array.isArray(schema.dropRegex) ? schema.dropRegex : [schema.dropRegex]).join('\n')
: '';
$('mapping').value = schema.mapping ? mappingToDSL(schema.mapping) : '';
$('mappingMode').value = schema.mappingMode || 'replace';
$('strict').checked = !!schema.strict;
}
// ============================================================================
// Build schema from UI
// ============================================================================
function buildSchemaFromUI() {
const fmt = formatSelect.value;
const verbose = $('verboseSchema').checked;
const s = { format: fmt };
if (NEEDS_LAYOUT.has(fmt)) {
const r = document.querySelector('input[name="layout"]:checked');
if (r) s.layout = r.value;
}
let effLayout = null;
if (TEXT_DELIMITED.has(fmt)) effLayout = 'delimited';
else if (TEXT_FIXED.has(fmt)) effLayout = 'fixed';
else if (s.layout) effLayout = s.layout;
if (effLayout === 'delimited') {
const d = $('delimiter').value;
const q = $('quoteChar').value;
if (verbose) {
s.delimiter = (d === '\\t') ? '\t' : (d || ',');
s.quoteChar = q || '"';
s.hasHeaders = $('hasHeaders').value !== 'false';
} else {
if (d) s.delimiter = (d === '\\t') ? '\t' : d;
if (q && q !== '"') s.quoteChar = q;
if ($('hasHeaders').value === 'false') s.hasHeaders = false;
}
}
if (effLayout === 'fixed') {
const fd = $('fieldDefinitions').value.trim();
if (fd) {
try { s.fieldDefinitions = JSON.parse(fd); }
catch (e) { throw new Error('fieldDefinitions: ' + e.message); }
} else if (verbose) {
s.fieldDefinitions = [];
}
}
if (XML_JSON.has(fmt)) {
const rp = $('rootPath').value.trim();
if (rp) s.rootPath = rp;
else if (verbose) s.rootPath = '';
}
if (SPREADSHEET.has(fmt)) {
const sn = $('sheetName').value.trim();
if (sn) s.sheetName = sn;
else if (verbose) s.sheetName = '';
}
if (TEXT_FORMATS.has(fmt)) {
const enc = $('encoding').value.trim() || 'utf-8';
if (verbose) s.encoding = enc;
else if (enc !== 'utf-8') s.encoding = enc;
const dr = $('dropRegex').value.trim();
if (dr) {
const arr = dr.split('\n').map(l => l.trim()).filter(Boolean);
s.dropRegex = arr.length === 1 ? arr[0] : arr;
} else if (verbose) {
s.dropRegex = [];
}
}
const m = $('mapping').value.trim();
if (m) {
try { s.mapping = parseMappingDSL(m); }
catch (e) { throw new Error('mapping: ' + e.message); }
const mm = $('mappingMode').value;
if (mm && mm !== 'replace') s.mappingMode = mm;
else if (verbose) s.mappingMode = 'replace';
} else if (verbose) {
s.mapping = {};
s.mappingMode = $('mappingMode').value || 'replace';
}
if ($('strict').checked) s.strict = true;
else if (verbose) s.strict = false;
s.studioVersion = window.DPE_STUDIO_VERSION || 'unknown';
return s;
}
// ============================================================================
// Parse
// ============================================================================
parseBtn.addEventListener('click', async () => {
if (!currentPayload) {
parseStatus.textContent = 'load a file or pick an example first';
return;
}
parseBtn.disabled = true;
parseStatus.textContent = 'parsing…';
let schema, result;
try {
schema = buildSchemaFromUI();
} catch (e) {
parseStatus.textContent = 'schema error: ' + e.message;
parseBtn.disabled = false;
return;
}
try {
result = await DataParser.parse(currentPayload, schema);
parseStatus.textContent = `parsed ${result.data.length} record(s) in ${result.meta.durationMs}ms`;
} catch (e) {
parseStatus.textContent = 'parse error: ' + e.message;
renderResult({ data: [], errors: [{ severity: 'error', message: e.message }], meta: { format: schema.format } }, schema);
parseBtn.disabled = false;
return;
}
renderResult(result, schema);
parseBtn.disabled = false;
});
// ============================================================================
// Render output
// ============================================================================
function renderResult(result, schema) {
// ---- DPE schema: snapshot of what the engine just received -----------
lastResult = result;
if (schema) {
$('schemaView').textContent = JSON.stringify(schema, null, 2);
$('downloadSchemaBtn').disabled = false;
}
// ---- RAW input: original text (or binary metadata) -------------------
const rawView = $('rawInputView');
rawView.innerHTML = '';
if (result.inputText != null) {
const pre = document.createElement('pre');
pre.textContent = result.inputText;
rawView.appendChild(pre);
const note = document.createElement('p');
note.className = 'hint';
note.textContent = `${result.inputText.length} characters, ${result.inputText.split(/\r?\n/).length} lines`;
rawView.appendChild(note);
} else {
const p = document.createElement('p');
p.className = 'hint';
const bytes = currentPayload?.size ?? '?';
const name = currentName || '(unnamed)';
p.innerHTML = `<strong>Binary format</strong> — RAW text not applicable.<br>File: <code>${name}</code> (${bytes} bytes)`;
rawView.appendChild(p);
}
// ---- Post-filter: text after dropRegex --------------------------------
const pfView = $('postFilterView');
pfView.innerHTML = '';
if (result.filteredText != null) {
const same = result.filteredText === result.inputText;
if (same) {
const note = document.createElement('p');
note.className = 'hint';
note.textContent = '(no dropRegex applied — identical to RAW input)';