report-studio 0.0.1 → 1.0.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -4
  3. package/dist/designer.js +3209 -0
  4. package/dist/index.js +2 -4
  5. package/dist/viewer-D-c0lKzQ.js +1576 -0
  6. package/package.json +66 -33
  7. package/src/asset/images/icon.png +0 -0
  8. package/src/asset/images/logo.png +0 -0
  9. package/src/cli/index.js +282 -0
  10. package/src/cli/serve.js +135 -0
  11. package/src/designer/blank.js +53 -0
  12. package/src/designer/canvas.js +518 -0
  13. package/src/designer/designer.js +1900 -0
  14. package/src/designer/dialog.js +708 -0
  15. package/src/designer/fields.js +584 -0
  16. package/src/designer/geometry.js +154 -0
  17. package/src/designer/guides.js +370 -0
  18. package/src/designer/history.js +113 -0
  19. package/src/designer/icons.js +118 -0
  20. package/src/designer/index.html +28 -0
  21. package/src/designer/main.js +39 -0
  22. package/src/designer/menu.js +126 -0
  23. package/src/designer/panel.js +478 -0
  24. package/src/designer/preview.js +95 -0
  25. package/src/designer/rulers.js +231 -0
  26. package/src/designer/sample-data.js +240 -0
  27. package/src/designer/select.js +699 -0
  28. package/src/designer/structure.js +604 -0
  29. package/src/designer/styles.css +1616 -0
  30. package/src/designer/toast.js +62 -0
  31. package/src/designer/tokens.js +284 -0
  32. package/src/engine/csv.js +315 -0
  33. package/src/engine/group.js +304 -0
  34. package/src/engine/index.js +34 -0
  35. package/src/engine/measure.js +390 -0
  36. package/src/engine/paginate.js +861 -0
  37. package/src/engine/regions.js +175 -0
  38. package/src/engine/resolve.js +171 -0
  39. package/src/engine/search.js +129 -0
  40. package/src/engine/text-metrics.js +206 -0
  41. package/src/engine/validate.js +328 -0
  42. package/src/index.html +79 -0
  43. package/src/index.js +50 -0
  44. package/src/preview/chrome.css +505 -0
  45. package/src/preview/chrome.js +147 -0
  46. package/src/preview/index.html +28 -0
  47. package/src/preview/main.js +66 -0
  48. package/src/preview/styles.css +16 -0
  49. package/src/preview/viewer.js +745 -0
  50. package/src/render/items.js +425 -0
  51. package/src/render/render.js +98 -0
  52. package/src/render/report.css +202 -0
  53. package/src/server/routes.js +331 -0
  54. package/src/shared/brand.css +29 -0
  55. package/src/shared/dropdown.css +136 -0
  56. package/src/shared/dropdown.js +166 -0
  57. package/src/shared/modal.css +125 -0
  58. package/src/shared/prefix.js +13 -0
  59. package/src/shared/store.js +145 -0
  60. package/src/shared/theme.css +72 -0
  61. package/src/shared/window.js +138 -0
  62. package/src/vite/index.js +53 -0
  63. package/dist/react.js +0 -4
@@ -0,0 +1,584 @@
1
+ /**
2
+ * fields.js says what can be edited about an item, and how a typed value gets
3
+ * onto it.
4
+ *
5
+ * It is plain data and pure functions, so the fiddly half - which fields a
6
+ * table has, what an empty box means, what happens when someone types "abc"
7
+ * into a font size - is specified without a browser. panel.js draws these and
8
+ * decides nothing, the same division select.js has with geometry.js.
9
+ *
10
+ * The paths ("style.fontSize") are the layout file's own shape from spec 3.3.
11
+ * Nothing here invents a field the engine does not read.
12
+ */
13
+
14
+
15
+ /**
16
+ * Spec 10 left the font list open, and closes it here: web-safe families only.
17
+ *
18
+ * The engine measures text with canvas measureText against this exact string
19
+ * (spec 4.3), so a family the browser does not have is measured as a fallback
20
+ * and paginates to a different page count than it prints. Web-safe stacks
21
+ * remove loading, embedding, and that whole class of bug at once.
22
+ */
23
+ export const FONT_STACKS = [
24
+ { label: 'Helvetica', value: 'Helvetica, Arial, sans-serif' },
25
+ { label: 'Arial', value: 'Arial, Helvetica, sans-serif' },
26
+ { label: 'Verdana', value: 'Verdana, Geneva, sans-serif' },
27
+ { label: 'Trebuchet', value: '"Trebuchet MS", Helvetica, sans-serif' },
28
+ { label: 'Georgia', value: 'Georgia, "Times New Roman", serif' },
29
+ { label: 'Times', value: '"Times New Roman", Times, serif' },
30
+ { label: 'Courier', value: '"Courier New", Courier, monospace' }
31
+ ];
32
+
33
+ const WEIGHTS = [
34
+ { label: 'Regular', value: 'normal' },
35
+ { label: 'Bold', value: 'bold' }
36
+ ];
37
+
38
+ const STYLES = [
39
+ { label: 'Upright', value: 'normal' },
40
+ { label: 'Italic', value: 'italic' }
41
+ ];
42
+
43
+ const ALIGNMENTS = [
44
+ { label: 'Left', value: 'left' },
45
+ { label: 'Centre', value: 'center' },
46
+ { label: 'Right', value: 'right' }
47
+ ];
48
+
49
+ const ORIENTATIONS = [
50
+ { label: 'Horizontal', value: 'horizontal' },
51
+ { label: 'Vertical', value: 'vertical' }
52
+ ];
53
+
54
+ /**
55
+ * The four CSS border styles that read as a rule. `double` needs 3px before a
56
+ * browser can draw two lines and a gap, which the thickness field allows for.
57
+ */
58
+ const LINE_STYLES = [
59
+ { label: 'Solid', value: 'solid' },
60
+ { label: 'Dashed', value: 'dashed' },
61
+ { label: 'Dotted', value: 'dotted' },
62
+ { label: 'Double', value: 'double' }
63
+ ];
64
+
65
+ /**
66
+ * The same, plus off. A table's grid is often better away entirely - a column
67
+ * of figures usually reads more easily without one - which is not a thing a
68
+ * line can be, so the two lists are not shared.
69
+ */
70
+ const RULE_STYLES = [...LINE_STYLES, { label: 'None', value: 'none' }];
71
+
72
+
73
+ const num = (key, label, extra = {}) =>
74
+ ({ key, label, type: 'number', ...extra });
75
+
76
+
77
+ /**
78
+ * The widest rule a table can be drawn with and still measure what it declares.
79
+ * The same figure items.js clamps to - see maxRuleWidth there for why half the
80
+ * shallowest row is where it stops.
81
+ *
82
+ * @param {object} item a table
83
+ * @returns {number} pixels
84
+ */
85
+ function maxRuleWidth(item) {
86
+ const rowHeight = item.rowHeight ?? 0;
87
+ const headerHeight = item.showHeader ? (item.headerHeight ?? rowHeight) : rowHeight;
88
+
89
+ const shallowest = Math.min(rowHeight || Infinity, headerHeight || Infinity);
90
+
91
+ return Number.isFinite(shallowest) ? Math.max(1, Math.floor(shallowest / 2)) : 1;
92
+ }
93
+
94
+
95
+ /**
96
+ * What a table column carries (spec 3.3). The same descriptor shape again, read
97
+ * and written against the column object rather than the item - which is all
98
+ * readField and writeField need, since they walk a path on whatever they get.
99
+ */
100
+ export const COLUMN_FIELDS = [
101
+ { key: 'field', label: 'Field', type: 'text' },
102
+ { key: 'label', label: 'Label', type: 'text' },
103
+ { key: 'width', label: 'Width', type: 'number', min: 1 },
104
+ { key: 'align', label: 'Align', type: 'choice', options: ALIGNMENTS }
105
+ ];
106
+
107
+
108
+ /**
109
+ * The editable properties of an item, grouped the way the panel shows them.
110
+ *
111
+ * A table has no height row: its height is the header plus its rows (spec 3.3),
112
+ * so a box to type one into would be a promise the layout file cannot keep -
113
+ * the same reason geometry.js gives it no south handle.
114
+ *
115
+ * @param {object} item a layout item
116
+ * @returns {object[]} `{ title, fields }` sections
117
+ */
118
+ export function fieldsFor(item) {
119
+ if (!item) return [];
120
+
121
+ const box = {
122
+ title: 'Position and size',
123
+ fields: [
124
+ num('x', 'X'),
125
+ num('y', 'Y'),
126
+ num('w', 'Width', { min: 1 }),
127
+ ...(item.type === 'table' ? [] : [num('h', 'Height', { min: 1 })])
128
+ ]
129
+ };
130
+
131
+ if (item.type === 'box') {
132
+ return [
133
+ box,
134
+ {
135
+ title: 'Border',
136
+ fields: [
137
+ {
138
+ key: 'style.borderStyle', label: 'Style', type: 'choice',
139
+ options: RULE_STYLES
140
+ },
141
+ num('style.borderWidth', 'Width', { min: 1 }),
142
+ { key: 'style.borderColor', label: 'Colour', type: 'color' },
143
+ num('style.radius', 'Corner', { min: 0 })
144
+ ]
145
+ },
146
+ {
147
+ title: 'Fill',
148
+ fields: [
149
+ {
150
+ key: 'style.background', label: 'Background', type: 'color',
151
+ hint: 'Leave a box unfilled to frame what is behind it'
152
+ }
153
+ ]
154
+ }
155
+ ];
156
+ }
157
+
158
+ if (item.type === 'line') {
159
+ return [
160
+ box,
161
+ {
162
+ title: 'Line',
163
+ fields: [
164
+ {
165
+ key: 'orientation', label: 'Runs', type: 'choice',
166
+ options: ORIENTATIONS
167
+ },
168
+ num('style.thickness', 'Thickness', { min: 1 }),
169
+ {
170
+ key: 'style.lineStyle', label: 'Style', type: 'choice',
171
+ options: LINE_STYLES
172
+ },
173
+ { key: 'style.color', label: 'Colour', type: 'color' }
174
+ ]
175
+ }
176
+ ];
177
+ }
178
+
179
+ if (item.type === 'table') {
180
+ return [
181
+ box,
182
+ {
183
+ title: 'Rows',
184
+ fields: [num('rowHeight', 'Row height', { min: 1 })]
185
+ },
186
+ {
187
+ /**
188
+ * The header is the part of a table anyone styles first, and
189
+ * its height was buried among the rows' - which is also the one
190
+ * figure that is not a row's, since the engine paginates a
191
+ * table as headerHeight + rows x rowHeight.
192
+ */
193
+ title: 'Header',
194
+ fields: [
195
+ { key: 'showHeader', label: 'Show header', type: 'toggle' },
196
+ num('headerHeight', 'Height', { min: 1 }),
197
+ { key: 'style.headerBackground', label: 'Fill', type: 'color' },
198
+ {
199
+ key: 'style.headerColor', label: 'Text', type: 'color',
200
+ hint: "Leave these alone to keep the stylesheet's own header"
201
+ }
202
+ ]
203
+ },
204
+ {
205
+ title: 'Appearance',
206
+ fields: [
207
+ {
208
+ key: 'style.fontFamily', label: 'Font', type: 'choice',
209
+ options: FONT_STACKS
210
+ },
211
+ num('style.fontSize', 'Font size', { min: 1 }),
212
+ { key: 'style.color', label: 'Text', type: 'color' },
213
+ {
214
+ key: 'wrap', label: 'Wrap cells', type: 'toggle',
215
+ hint: 'A cell wider than its column runs onto another ' +
216
+ 'line and the row grows; turn this off to keep ' +
217
+ 'every row one line, cut off with an ellipsis'
218
+ },
219
+ {
220
+ key: 'style.borderStyle', label: 'Borders', type: 'choice',
221
+ options: RULE_STYLES
222
+ },
223
+ num('style.borderWidth', 'Border width', {
224
+ min: 1,
225
+ /**
226
+ * A rule taller than half a row makes the cell grow, and
227
+ * a table that outgrows headerHeight + rows x rowHeight
228
+ * is a table pagination has measured wrongly. The rail
229
+ * will not offer the figure that does it.
230
+ */
231
+ max: maxRuleWidth(item)
232
+ }),
233
+ { key: 'style.borderColor', label: 'Border colour', type: 'color' }
234
+ ]
235
+ }
236
+ ];
237
+ }
238
+
239
+ return [
240
+ {
241
+ title: 'Content',
242
+ fields: [{
243
+ key: 'value', label: 'Value', type: 'textarea',
244
+ hint: 'Placeholders in braces: {customer.name}, {page}, {sum(amount)}'
245
+ }]
246
+ },
247
+ box,
248
+ {
249
+ title: 'Type',
250
+ fields: [
251
+ { key: 'style.fontFamily', label: 'Font', type: 'choice', options: FONT_STACKS },
252
+ num('style.fontSize', 'Size', { min: 1 }),
253
+ { key: 'style.fontWeight', label: 'Weight', type: 'choice', options: WEIGHTS },
254
+ { key: 'style.fontStyle', label: 'Style', type: 'choice', options: STYLES },
255
+ { key: 'style.align', label: 'Align', type: 'choice', options: ALIGNMENTS },
256
+ { key: 'style.color', label: 'Colour', type: 'color' }
257
+ ]
258
+ }
259
+ ];
260
+ }
261
+
262
+
263
+ /**
264
+ * Page sizes worth having by name. Spec 6.2: pixels throughout, and these are
265
+ * the two figures it gives - A4 and Letter at screen resolution, which is what
266
+ * browser print produces.
267
+ */
268
+ export const PAGE_PRESETS = [
269
+ { label: 'A2', width: 1587, height: 2245 },
270
+ { label: 'A3', width: 1123, height: 1587 },
271
+ { label: 'A4', width: 794, height: 1123 },
272
+ { label: 'A5', width: 559, height: 794 },
273
+ { label: 'A6', width: 397, height: 559 },
274
+ { label: 'Letter', width: 816, height: 1056 },
275
+ { label: 'Legal', width: 816, height: 1344 },
276
+ { label: 'Tabloid', width: 1056, height: 1632 }
277
+ ];
278
+
279
+ /** what the dropdown says for a page that is not one of them */
280
+ export const CUSTOM_PAPER = 'custom';
281
+
282
+
283
+ /**
284
+ * Which sheet a page is, by its size.
285
+ *
286
+ * Either way round, because a landscape A4 is still A4 - and a dropdown that
287
+ * said "Custom" the moment somebody turned the page would be one nobody could
288
+ * use to turn it back.
289
+ *
290
+ * Derived rather than stored: the size is the fact, the name is a reading of
291
+ * it. A layout hand-edited to 794 x 1123 reads as A4 without anyone having had
292
+ * to also write the word down, and the two can never disagree.
293
+ *
294
+ * The one thing that cannot be derived is somebody having *asked* for the
295
+ * boxes on a page that is currently a named size, so that alone is remembered.
296
+ * Only the absence of a name is ever written down - never a name - so the file
297
+ * has nothing in it that can contradict the size beside it.
298
+ *
299
+ * @param {object} page the layout's page
300
+ * @returns {string} a preset label, or CUSTOM_PAPER
301
+ */
302
+ export function paperOf(page) {
303
+ if (page?.paper === CUSTOM_PAPER) return CUSTOM_PAPER;
304
+
305
+ const w = page?.width;
306
+ const h = page?.height;
307
+
308
+ const found = PAGE_PRESETS.find(sheet =>
309
+ (sheet.width === w && sheet.height === h)
310
+ || (sheet.height === w && sheet.width === h));
311
+
312
+ return found ? found.label : CUSTOM_PAPER;
313
+ }
314
+
315
+
316
+ /** which way up it is, which only means anything once it has a size */
317
+ function orientationOf(page) {
318
+ return (page?.width ?? 0) > (page?.height ?? 0) ? 'landscape' : 'portrait';
319
+ }
320
+
321
+
322
+ /**
323
+ * Puts a named sheet on the layout, keeping the way up it already had.
324
+ *
325
+ * @param {object} layout mutated in place
326
+ * @param {string} label
327
+ * @returns {boolean} whether anything changed
328
+ */
329
+ function setPaper(layout, label) {
330
+ const sheet = PAGE_PRESETS.find(one => one.label === label);
331
+
332
+ /**
333
+ * Custom is not a size, it is the absence of one - so choosing it leaves the
334
+ * page exactly as it is and only reveals the two boxes. Throwing the
335
+ * dimensions away at the moment somebody asked to edit them would be a
336
+ * strange way to help.
337
+ *
338
+ * It has to stick, though. Without the flag, a page that happens to be A4
339
+ * would read as A4 again the instant the rail was rebuilt, and the boxes
340
+ * would vanish before anyone could type in them.
341
+ */
342
+ if (!sheet) {
343
+ if (layout.page.paper === CUSTOM_PAPER) return false;
344
+
345
+ layout.page.paper = CUSTOM_PAPER;
346
+ return true;
347
+ }
348
+
349
+ const landscape = orientationOf(layout.page) === 'landscape';
350
+
351
+ const width = landscape ? sheet.height : sheet.width;
352
+ const height = landscape ? sheet.width : sheet.height;
353
+
354
+ const wasCustom = layout.page.paper === CUSTOM_PAPER;
355
+
356
+ /** a named sheet is a name again; the flag is only ever the lack of one */
357
+ delete layout.page.paper;
358
+
359
+ if (layout.page.width === width && layout.page.height === height) {
360
+ return wasCustom;
361
+ }
362
+
363
+ layout.page.width = width;
364
+ layout.page.height = height;
365
+ return true;
366
+ }
367
+
368
+
369
+ /** turns the page, whatever size it is */
370
+ function setOrientation(layout, value) {
371
+ const wanted = value === 'landscape';
372
+
373
+ if (wanted === (orientationOf(layout.page) === 'landscape')) return false;
374
+
375
+ const { width, height } = layout.page;
376
+
377
+ layout.page.width = height;
378
+ layout.page.height = width;
379
+ return true;
380
+ }
381
+
382
+
383
+ /**
384
+ * The Page section: which sheet, which way up, and - only when the sheet is
385
+ * Custom - the two numbers themselves.
386
+ *
387
+ * The boxes are hidden rather than disabled for a named sheet, because a
388
+ * disabled 794 invites somebody to try to change it and then wonder why they
389
+ * cannot. The number is in the dropdown's own label instead, so nothing is
390
+ * hidden that anyone needed to read.
391
+ *
392
+ * @param {object} layout
393
+ * @returns {object[]}
394
+ */
395
+ function pageFields(layout) {
396
+ const custom = paperOf(layout.page) === CUSTOM_PAPER;
397
+
398
+ const paper = {
399
+ key: 'paper',
400
+ label: 'Paper',
401
+ type: 'choice',
402
+ /** the controls below it differ per sheet, so the rail is rebuilt */
403
+ rebuilds: true,
404
+ options: [
405
+ ...PAGE_PRESETS.map(sheet => ({
406
+ value: sheet.label,
407
+ label: `${sheet.label} ${sheet.width} x ${sheet.height}`
408
+ })),
409
+ { value: CUSTOM_PAPER, label: 'Custom' }
410
+ ],
411
+ read: (target) => paperOf(target.page),
412
+ write: (target, value) => setPaper(target, value)
413
+ };
414
+
415
+ const orientation = {
416
+ key: 'orientation',
417
+ label: 'Orientation',
418
+ type: 'choice',
419
+ rebuilds: true,
420
+ options: [
421
+ { value: 'portrait', label: 'Portrait' },
422
+ { value: 'landscape', label: 'Landscape' }
423
+ ],
424
+ read: (target) => orientationOf(target.page),
425
+ write: (target, value) => setOrientation(target, value)
426
+ };
427
+
428
+ return custom
429
+ ? [paper, num('page.width', 'Width', { min: 1 }),
430
+ num('page.height', 'Height', { min: 1 })]
431
+ : [paper, orientation];
432
+ }
433
+
434
+
435
+ /**
436
+ * The report's own properties - what the rail shows when no item is selected.
437
+ *
438
+ * Deliberately the same descriptor shape as an item's, so panel.js draws both
439
+ * with one set of controls. readField and writeField walk a path on whatever
440
+ * object they are handed, and a layout is just another object.
441
+ *
442
+ * @param {object|null} layout
443
+ * @returns {object[]} `{ title, fields }` sections
444
+ */
445
+ export function reportFields(layout) {
446
+ if (!layout) return [];
447
+
448
+ return [
449
+ {
450
+ title: 'Report',
451
+ fields: [
452
+ { key: 'name', label: 'Name', type: 'text' },
453
+ {
454
+ key: 'dataset', label: 'Dataset', type: 'text', nullable: true,
455
+ hint: 'The key in the data object that drives the rows'
456
+ },
457
+ {
458
+ key: 'groupBy', label: 'Group by', type: 'text', nullable: true,
459
+ hint: 'A field name, or blank for no grouping'
460
+ }
461
+ ]
462
+ },
463
+ {
464
+ title: 'Page',
465
+ fields: pageFields(layout)
466
+ },
467
+ {
468
+ title: 'Margins',
469
+ fields: [
470
+ num('page.margin.top', 'Top', { min: 0 }),
471
+ num('page.margin.right', 'Right', { min: 0 }),
472
+ num('page.margin.bottom', 'Bottom', { min: 0 }),
473
+ num('page.margin.left', 'Left', { min: 0 })
474
+ ]
475
+ }
476
+ ];
477
+ }
478
+
479
+
480
+ export function allReportFields(layout) {
481
+ return reportFields(layout).flatMap(section => section.fields);
482
+ }
483
+
484
+
485
+ /** every field of every section, flat */
486
+ export function allFields(item) {
487
+ return fieldsFor(item).flatMap(section => section.fields);
488
+ }
489
+
490
+
491
+ function pathOf(key) {
492
+ return key.split('.');
493
+ }
494
+
495
+
496
+ /**
497
+ * The value to show in a field's control.
498
+ * @param {object} item
499
+ * @param {object} field
500
+ * @returns {*} undefined when the item does not carry it
501
+ */
502
+ export function readField(item, field) {
503
+ /**
504
+ * A field that is a reading of the object rather than a place on it - the
505
+ * paper size is the width and the height, said as a name. It has no path to
506
+ * walk, so it says how to be read instead.
507
+ */
508
+ if (field.read) return field.read(item);
509
+
510
+ let node = item;
511
+
512
+ for (const step of pathOf(field.key)) {
513
+ if (node == null) return undefined;
514
+ node = node[step];
515
+ }
516
+
517
+ return node;
518
+ }
519
+
520
+
521
+ /**
522
+ * Puts a typed value onto an item, and says whether anything changed.
523
+ *
524
+ * Refusing a value rather than storing a bad one is deliberate: these controls
525
+ * are bound live, so an empty box is a half-typed number, not a request for
526
+ * NaN. The field keeps its last good value and the canvas stops flickering
527
+ * between drawn and blank while someone retypes a width.
528
+ *
529
+ * @param {object} item mutated in place; it is the layout the host will be given
530
+ * @param {object} field
531
+ * @param {*} raw whatever the control produced
532
+ * @returns {boolean} true when the item changed
533
+ */
534
+ export function writeField(item, field, raw) {
535
+ const value = coerce(field, raw);
536
+ if (value === undefined) return false;
537
+
538
+ /** the other half of a derived field: it says how to be written, too */
539
+ if (field.write) return field.write(item, value);
540
+
541
+ const path = pathOf(field.key);
542
+ const last = path.pop();
543
+
544
+ let node = item;
545
+ for (const step of path) {
546
+ if (node[step] == null || typeof node[step] !== 'object') node[step] = {};
547
+ node = node[step];
548
+ }
549
+
550
+ if (node[last] === value) return false;
551
+
552
+ node[last] = value;
553
+ return true;
554
+ }
555
+
556
+
557
+ /**
558
+ * @returns {*} undefined for a value the field will not accept
559
+ */
560
+ function coerce(field, raw) {
561
+ if (field.type === 'toggle') return Boolean(raw);
562
+
563
+ if (field.type === 'number') {
564
+ if (raw === '' || raw === null || raw === undefined) return undefined;
565
+
566
+ const value = Number(raw);
567
+ if (!Number.isFinite(value)) return undefined;
568
+
569
+ const floored = field.min != null ? Math.max(value, field.min) : value;
570
+
571
+ return field.max != null ? Math.min(floored, field.max) : floored;
572
+ }
573
+
574
+ if (raw === null || raw === undefined) return undefined;
575
+
576
+ /**
577
+ * `groupBy` and `dataset` are "a field name, or nothing" (spec 3.1), and
578
+ * nothing is null - an empty string would be a dataset named "", which the
579
+ * engine would then go looking for.
580
+ */
581
+ if (field.nullable && raw === '') return null;
582
+
583
+ return String(raw);
584
+ }