@pdfme/common 4.5.2-dev.2 → 4.5.2-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,6 +27,7 @@
27
27
 
28
28
  <p align="center">TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!</p>
29
29
 
30
+
30
31
  ## Features
31
32
 
32
33
  | Fast PDF Generator | Easy PDF template design | Simple JSON template |
@@ -70,6 +71,9 @@ npm i @pdfme/ui @pdfme/common
70
71
 
71
72
  \*You must install `@pdfme/common` regardless of which package you use.
72
73
 
74
+ On NPM stable releases are published to the `latest` tag, and pre-releases are published to the `next` tag.
75
+ On the `dev` tag you can find releases for every commit to the `main` branch.
76
+
73
77
  The following type, function and classes are available in pdfme.
74
78
 
75
79
  `@pdfme/common`
@@ -117,9 +121,8 @@ The following image is a good illustration of a template.
117
121
  **basePdf** can be given a `string`(base64), `ArrayBuffer`, or `Uint8Array`.
118
122
  A blank A4 PDF can be imported with `BLANK_PDF`. You can use it to check how it works.
119
123
 
120
- **schemas** can only utilize text by default, but you can load images and various barcodes like QR codes as plugins from the `@pdfme/schemas` package.
121
- Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above.
122
- Check detail about [Custom Schemas](https://pdfme.com/docs/custom-schemas) from here
124
+ **Schemas** can only utilize text by default, but you can load images and various barcodes like QR codes as plugins from the `@pdfme/schemas` package.
125
+ Additionally, you can create your own schemas, allowing you to render types other than the ones mentioned above. Check detail about [Custom Schemas](https://pdfme.com/docs/custom-schemas) from here.
123
126
 
124
127
  Let's take a look at some specific data.
125
128
  (If you are using TypeScript, you can import the Template type.)
@@ -132,26 +135,29 @@ import { Template, BLANK_PDF } from '@pdfme/common';
132
135
  const template: Template = {
133
136
  basePdf: BLANK_PDF,
134
137
  schemas: [
135
- {
136
- a: {
138
+ [
139
+ {
140
+ name: 'a',
137
141
  type: 'text',
138
142
  position: { x: 0, y: 0 },
139
143
  width: 10,
140
144
  height: 10,
141
145
  },
142
- b: {
146
+ {
147
+ name: 'a',
143
148
  type: 'text',
144
149
  position: { x: 10, y: 10 },
145
150
  width: 10,
146
151
  height: 10,
147
152
  },
148
- c: {
153
+ {
154
+ name: 'c',
149
155
  type: 'text',
150
156
  position: { x: 20, y: 20 },
151
157
  width: 10,
152
158
  height: 10,
153
159
  },
154
- },
160
+ ],
155
161
  ],
156
162
  };
157
163
  ```
@@ -193,7 +199,7 @@ Also, each element in the inputs array corresponds to a page in the PDF, you can
193
199
 
194
200
  ## UI
195
201
 
196
- The UI is composed of the Designer, Form, and Viewer classes.
202
+ The UI is composed of the [Designer](https://pdfme.com/docs/getting-started#designer), [Form](https://pdfme.com/docs/getting-started#form), and [Viewer](https://pdfme.com/docs/getting-started#viewer) classes.
197
203
 
198
204
  ### Designer
199
205
 
@@ -225,7 +231,6 @@ The designer instance can be manipulated with the following methods.
225
231
  - `saveTemplate`
226
232
  - `updateTemplate`
227
233
  - `getTemplate`
228
- - `getPageCursor`
229
234
  - `onChangeTemplate`
230
235
  - `onSaveTemplate`
231
236
  - `destroy`
@@ -286,6 +291,72 @@ const viewer = new Viewer({ domContainer, template, inputs });
286
291
 
287
292
  ![](https://raw.githubusercontent.com/pdfme/pdfme/main/website/static/img/viewer.png)
288
293
 
294
+ ### Using additional schemas and custom plugins
295
+
296
+ The examples so far use only the `text` schema type. There are many others built-in within the `@pdfme/schemas` package, and you can use your own:
297
+
298
+ Here's an example using additional schemas from built-in and custom plugins:
299
+
300
+ ```ts
301
+ import { Template, BLANK_PDF } from '@pdfme/common';
302
+ import { text, barcodes, image } from '@pdfme/schemas';
303
+ import myPlugin from './custom-plugins';
304
+
305
+ const template: Template = {
306
+ basePdf: BLANK_PDF,
307
+ schemas: [
308
+ [
309
+ {
310
+ name: 'example_text',
311
+ type: 'text',
312
+ position: { x: 0, y: 0 },
313
+ width: 40,
314
+ height: 10,
315
+ },
316
+ {
317
+ name: 'example_image',
318
+ type: 'image',
319
+ position: { x: 200, y: 200 },
320
+ width: 60,
321
+ height: 40,
322
+ },
323
+ {
324
+ name: 'example_qr_code',
325
+ type: 'qrcode',
326
+ position: { x: 100, y: 100 },
327
+ width: 50,
328
+ height: 50,
329
+ },
330
+ ],
331
+ ],
332
+ };
333
+
334
+ const plugins = {
335
+ Text: multiVariableText,
336
+ 'QR Code': barcodes.qrcode,
337
+ Image: image,
338
+ MyPlugin: myPlugin
339
+ }
340
+
341
+ const inputs = [{
342
+ example_text: 'a1',
343
+ example_image: 'data:image/png;base64,iVBORw0KG....',
344
+ example_qr_code: 'https://pdfme.com/'
345
+ }];
346
+
347
+ generate({ template, inputs, plugins }).then((pdf) => {
348
+ console.log(pdf);
349
+ });
350
+
351
+ ```
352
+
353
+
354
+
355
+ ## Examples using pdfme
356
+
357
+ If you are looking for code examples using pdfme to get started, please check out the [pdfme-playground](https://github.com/pdfme/pdfme-playground) repository
358
+ or look at the examples in the `websit/src/pages/` folder of this repository. Settings these up is covered in the [DEVELOPMENT.md](DEVELOPMENT.md) file.
359
+
289
360
  ## Special Thanks
290
361
 
291
362
  - [pdf-lib](https://pdf-lib.js.org/): Used in PDF generation.
@@ -297,7 +368,7 @@ const viewer = new Viewer({ domContainer, template, inputs });
297
368
  - [react-moveable](https://daybrush.com/moveable/), [react-selecto](https://github.com/daybrush/selecto), [@scena/react-guides](https://daybrush.com/guides/): Used in Designer UI.
298
369
  - [dnd-kit](https://github.com/clauderic/dnd-kit): Used in Designer UI.
299
370
 
300
- I definitely could not have created pdfme without these libraries. I am grateful to the developers of these libraries.
371
+ I definitely could not have created pdfme without these libraries. I am grateful to the developers of these libraries.
301
372
 
302
373
  If you want to contribute to pdfme, please check the [Development Guide](https://pdfme.com/docs/development-guide) page.
303
374
  We look forward to your contribution!
@@ -36,8 +36,9 @@ const getSampleFont = () => ({
36
36
  const getTemplate = () => ({
37
37
  basePdf: src_1.BLANK_PDF,
38
38
  schemas: [
39
- {
40
- a: {
39
+ [
40
+ {
41
+ name: 'a',
41
42
  content: 'a',
42
43
  type: 'text',
43
44
  fontName: 'SauceHanSansJP',
@@ -45,14 +46,15 @@ const getTemplate = () => ({
45
46
  width: 100,
46
47
  height: 100,
47
48
  },
48
- b: {
49
+ {
50
+ name: 'b',
49
51
  content: 'b',
50
52
  type: 'text',
51
53
  position: { x: 0, y: 0 },
52
54
  width: 100,
53
55
  height: 100,
54
56
  },
55
- },
57
+ ],
56
58
  ],
57
59
  });
58
60
  describe('mm2pt test', () => {
@@ -101,22 +103,24 @@ describe('checkFont test', () => {
101
103
  const _getTemplate = () => ({
102
104
  basePdf: src_1.BLANK_PDF,
103
105
  schemas: [
104
- {
105
- a: {
106
+ [
107
+ {
108
+ name: 'a',
106
109
  content: 'a',
107
110
  type: 'text',
108
111
  position: { x: 0, y: 0 },
109
112
  width: 100,
110
113
  height: 100,
111
114
  },
112
- b: {
115
+ {
116
+ name: 'b',
113
117
  content: 'b',
114
118
  type: 'text',
115
119
  position: { x: 0, y: 0 },
116
120
  width: 100,
117
121
  height: 100,
118
122
  },
119
- },
123
+ ],
120
124
  ],
121
125
  });
122
126
  try {
@@ -181,8 +185,9 @@ Check this document: https://pdfme.com/docs/custom-fonts#about-font-type`);
181
185
  const _getTemplate = () => ({
182
186
  basePdf: src_1.BLANK_PDF,
183
187
  schemas: [
184
- {
185
- a: {
188
+ [
189
+ {
190
+ name: 'a',
186
191
  type: 'text',
187
192
  content: 'a',
188
193
  fontName: 'SauceHanSansJP2',
@@ -190,14 +195,15 @@ Check this document: https://pdfme.com/docs/custom-fonts#about-font-type`);
190
195
  width: 100,
191
196
  height: 100,
192
197
  },
193
- b: {
198
+ {
199
+ name: 'b',
194
200
  type: 'text',
195
201
  content: 'b',
196
202
  position: { x: 0, y: 0 },
197
203
  width: 100,
198
204
  height: 100,
199
205
  },
200
- },
206
+ ],
201
207
  ],
202
208
  });
203
209
  try {
@@ -213,8 +219,9 @@ Check this document: https://pdfme.com/docs/custom-fonts`);
213
219
  const _getTemplate = () => ({
214
220
  basePdf: src_1.BLANK_PDF,
215
221
  schemas: [
216
- {
217
- a: {
222
+ [
223
+ {
224
+ name: 'a',
218
225
  type: 'text',
219
226
  content: 'a',
220
227
  fontName: 'SauceHanSansJP2',
@@ -222,7 +229,8 @@ Check this document: https://pdfme.com/docs/custom-fonts`);
222
229
  width: 100,
223
230
  height: 100,
224
231
  },
225
- b: {
232
+ {
233
+ name: 'b',
226
234
  type: 'text',
227
235
  content: 'b',
228
236
  fontName: 'SauceHanSerifJP2',
@@ -230,7 +238,7 @@ Check this document: https://pdfme.com/docs/custom-fonts`);
230
238
  width: 100,
231
239
  height: 100,
232
240
  },
233
- },
241
+ ],
234
242
  ],
235
243
  });
236
244
  try {
@@ -299,8 +307,8 @@ describe('checkPlugins test', () => {
299
307
  test('success test: type in Schemas(single)', () => {
300
308
  try {
301
309
  const template = getTemplate();
302
- template.schemas[0].a.type = 'myText';
303
- template.schemas[0].b.type = 'myText';
310
+ template.schemas[0][0].type = 'myText';
311
+ template.schemas[0][1].type = 'myText';
304
312
  (0, helper_1.checkPlugins)({ template, plugins });
305
313
  expect.anything();
306
314
  }
@@ -311,8 +319,8 @@ describe('checkPlugins test', () => {
311
319
  test('success test: type in Schemas(multiple)', () => {
312
320
  try {
313
321
  const template = getTemplate();
314
- template.schemas[0].a.type = 'myText';
315
- template.schemas[0].b.type = 'myImage';
322
+ template.schemas[0][0].type = 'myText';
323
+ template.schemas[0][1].type = 'myImage';
316
324
  (0, helper_1.checkPlugins)({ template, plugins });
317
325
  expect.anything();
318
326
  }
@@ -323,8 +331,8 @@ describe('checkPlugins test', () => {
323
331
  test('fail test: type in Schemas not found in plugins(single)', () => {
324
332
  try {
325
333
  const template = getTemplate();
326
- template.schemas[0].a.type = 'fail';
327
- template.schemas[0].b.type = 'myImage';
334
+ template.schemas[0][0].type = 'fail';
335
+ template.schemas[0][1].type = 'myImage';
328
336
  (0, helper_1.checkPlugins)({ template, plugins });
329
337
  fail();
330
338
  }
@@ -335,8 +343,8 @@ describe('checkPlugins test', () => {
335
343
  test('fail test: type in Schemas not found in plugins(multiple)', () => {
336
344
  try {
337
345
  const template = getTemplate();
338
- template.schemas[0].a.type = 'fail';
339
- template.schemas[0].b.type = 'fail2';
346
+ template.schemas[0][0].type = 'fail';
347
+ template.schemas[0][1].type = 'fail2';
340
348
  (0, helper_1.checkPlugins)({ template, plugins });
341
349
  fail();
342
350
  }
@@ -352,22 +360,24 @@ describe('getDynamicTemplate', () => {
352
360
  const padding = 10;
353
361
  const template = {
354
362
  schemas: [
355
- {
356
- a: {
363
+ [
364
+ {
365
+ name: 'a',
357
366
  content: 'a',
358
367
  type: 'a',
359
368
  position: { x: 10, y: aPositionY },
360
369
  width: 10,
361
370
  height,
362
371
  },
363
- b: {
372
+ {
373
+ name: 'b',
364
374
  content: 'b',
365
375
  type: 'b',
366
376
  position: { x: 10, y: bPositionY },
367
377
  width: 10,
368
378
  height,
369
379
  },
370
- },
380
+ ],
371
381
  ],
372
382
  basePdf: { width: 100, height: 100, padding: [padding, padding, padding, padding] },
373
383
  };
@@ -399,8 +409,10 @@ describe('getDynamicTemplate', () => {
399
409
  const dynamicTemplate = await (0, helper_1.getDynamicTemplate)(createGetDynamicTemplateArg(increaseHeights));
400
410
  verifyBasicStructure(dynamicTemplate);
401
411
  expect(dynamicTemplate.schemas.length).toBe(1);
402
- expect(dynamicTemplate.schemas[0].a.position.y).toEqual(aPositionY);
403
- expect(dynamicTemplate.schemas[0].b.position.y).toEqual(increaseHeights.reduce((a, b) => a + b, 0) - height + bPositionY);
412
+ expect(dynamicTemplate.schemas[0][0].position.y).toEqual(aPositionY);
413
+ expect(dynamicTemplate.schemas[0][0].name).toEqual('a');
414
+ expect(dynamicTemplate.schemas[0][1].position.y).toEqual(increaseHeights.reduce((a, b) => a + b, 0) - height + bPositionY);
415
+ expect(dynamicTemplate.schemas[0][1].name).toEqual('b');
404
416
  });
405
417
  });
406
418
  describe('Multiple page scenarios', () => {
@@ -409,19 +421,25 @@ describe('getDynamicTemplate', () => {
409
421
  const dynamicTemplate = await (0, helper_1.getDynamicTemplate)(createGetDynamicTemplateArg(increaseHeights));
410
422
  verifyBasicStructure(dynamicTemplate);
411
423
  expect(dynamicTemplate.schemas.length).toBe(2);
412
- expect(dynamicTemplate.schemas[0].a.position.y).toEqual(aPositionY);
413
- expect(dynamicTemplate.schemas[0].b).toBeUndefined();
414
- expect(dynamicTemplate.schemas[1].b.position.y).toEqual(padding);
424
+ expect(dynamicTemplate.schemas[0][0].position.y).toEqual(aPositionY);
425
+ expect(dynamicTemplate.schemas[0][0].name).toEqual('a');
426
+ expect(dynamicTemplate.schemas[0][1]).toBeUndefined();
427
+ expect(dynamicTemplate.schemas[1][0].name).toEqual('b');
428
+ expect(dynamicTemplate.schemas[1][0].position.y).toEqual(padding);
429
+ expect(dynamicTemplate.schemas[1][1]).toBeUndefined();
415
430
  });
416
431
  test('should handle page break with a on page 1 and 2, b on page 2', async () => {
417
432
  const increaseHeights = [20, 20, 20, 20, 20];
418
433
  const dynamicTemplate = await (0, helper_1.getDynamicTemplate)(createGetDynamicTemplateArg(increaseHeights));
419
434
  verifyBasicStructure(dynamicTemplate);
420
435
  expect(dynamicTemplate.schemas.length).toBe(2);
421
- expect(dynamicTemplate.schemas[0].a.position.y).toEqual(aPositionY);
422
- expect(dynamicTemplate.schemas[0].b).toBeUndefined();
423
- expect(dynamicTemplate.schemas[1].a.position.y).toEqual(padding);
424
- expect(dynamicTemplate.schemas[1].b.position.y).toEqual(increaseHeights.slice(3).reduce((a, b) => a + b, 0) - height + padding);
436
+ expect(dynamicTemplate.schemas[0][0].position.y).toEqual(aPositionY);
437
+ expect(dynamicTemplate.schemas[0][0].name).toEqual('a');
438
+ expect(dynamicTemplate.schemas[0][1]).toBeUndefined();
439
+ expect(dynamicTemplate.schemas[1][0].position.y).toEqual(padding);
440
+ expect(dynamicTemplate.schemas[1][0].name).toEqual('a');
441
+ expect(dynamicTemplate.schemas[1][1].position.y).toEqual(increaseHeights.slice(3).reduce((a, b) => a + b, 0) - height + padding);
442
+ expect(dynamicTemplate.schemas[1][1].name).toEqual('b');
425
443
  });
426
444
  test('should handle multiple page breaks', async () => {
427
445
  const increaseHeights = [50, 50, 50, 50, 50];
@@ -430,15 +448,17 @@ describe('getDynamicTemplate', () => {
430
448
  expect(dynamicTemplate.schemas.length).toBe(5);
431
449
  // Verify 'a' elements
432
450
  for (let i = 0; i < 4; i++) {
433
- expect(dynamicTemplate.schemas[i].a).toBeDefined();
434
- expect(dynamicTemplate.schemas[i].a.position.y).toEqual(i === 0 ? aPositionY : padding);
435
- expect(dynamicTemplate.schemas[i].a.height).toEqual(i === 3 ? 100 : 50);
436
- expect(dynamicTemplate.schemas[i].b).toBeUndefined();
451
+ expect(dynamicTemplate.schemas[i][0]).toBeDefined();
452
+ expect(dynamicTemplate.schemas[i][0].position.y).toEqual(i === 0 ? aPositionY : padding);
453
+ expect(dynamicTemplate.schemas[i][0].height).toEqual(i === 3 ? 100 : 50);
454
+ expect(dynamicTemplate.schemas[i][0].name).toEqual('a');
455
+ expect(dynamicTemplate.schemas[i][1]).toBeUndefined();
437
456
  }
438
457
  // Verify 'b' element
439
- expect(dynamicTemplate.schemas[4].b).toBeDefined();
440
- expect(dynamicTemplate.schemas[4].b.position.y).toEqual(padding);
441
- expect(dynamicTemplate.schemas[4].b.height).toEqual(10);
458
+ expect(dynamicTemplate.schemas[4][0]).toBeDefined();
459
+ expect(dynamicTemplate.schemas[4][0].name).toEqual('b');
460
+ expect(dynamicTemplate.schemas[4][0].position.y).toEqual(padding);
461
+ expect(dynamicTemplate.schemas[4][0].height).toEqual(10);
442
462
  });
443
463
  test('should handle both a and b on next page', async () => {
444
464
  const increaseHeights = [80, 10, 10];
@@ -446,16 +466,16 @@ describe('getDynamicTemplate', () => {
446
466
  verifyBasicStructure(dynamicTemplate);
447
467
  expect(dynamicTemplate.schemas.length).toBe(2);
448
468
  // Check first page
449
- expect(dynamicTemplate.schemas[0].a).toBeDefined();
450
- expect(dynamicTemplate.schemas[0].a.position.y).toEqual(aPositionY);
451
- expect(dynamicTemplate.schemas[0].a.height).toEqual(80);
452
- expect(dynamicTemplate.schemas[0].b).toBeUndefined();
469
+ expect(dynamicTemplate.schemas[0][0]).toBeDefined();
470
+ expect(dynamicTemplate.schemas[0][0].position.y).toEqual(aPositionY);
471
+ expect(dynamicTemplate.schemas[0][0].height).toEqual(80);
472
+ expect(dynamicTemplate.schemas[0][1]).toBeUndefined();
453
473
  // Check second page
454
- expect(dynamicTemplate.schemas[1].a).toBeDefined();
455
- expect(dynamicTemplate.schemas[1].a.position.y).toEqual(padding);
456
- expect(dynamicTemplate.schemas[1].a.height).toEqual(20);
457
- expect(dynamicTemplate.schemas[1].b).toBeDefined();
458
- expect(dynamicTemplate.schemas[1].b.position.y).toBeGreaterThanOrEqual(dynamicTemplate.schemas[1].a.position.y + dynamicTemplate.schemas[1].a.height);
474
+ expect(dynamicTemplate.schemas[1][0]).toBeDefined();
475
+ expect(dynamicTemplate.schemas[1][0].position.y).toEqual(padding);
476
+ expect(dynamicTemplate.schemas[1][0].height).toEqual(20);
477
+ expect(dynamicTemplate.schemas[1][1]).toBeDefined();
478
+ expect(dynamicTemplate.schemas[1][1].position.y).toBeGreaterThanOrEqual(dynamicTemplate.schemas[1][0].position.y + dynamicTemplate.schemas[1][0].height);
459
479
  });
460
480
  });
461
481
  describe('Element height modifications', () => {
@@ -466,14 +486,15 @@ describe('getDynamicTemplate', () => {
466
486
  verifyBasicStructure(dynamicTemplate);
467
487
  expect(dynamicTemplate.schemas.length).toBe(2);
468
488
  // Check 'a' element
469
- expect(dynamicTemplate.schemas[0].a).toBeDefined();
470
- expect(dynamicTemplate.schemas[0].a.position.y).toEqual(aPositionY);
471
- expect(dynamicTemplate.schemas[0].a.height).toEqual(50);
489
+ expect(dynamicTemplate.schemas[0][0]).toBeDefined();
490
+ expect(dynamicTemplate.schemas[0][0].position.y).toEqual(aPositionY);
491
+ expect(dynamicTemplate.schemas[0][0].height).toEqual(50);
492
+ expect(dynamicTemplate.schemas[0][0].name).toEqual('a');
472
493
  // Check 'b' element
473
- const bSchema = dynamicTemplate.schemas.find((schema) => schema.b);
474
- expect(bSchema).toBeDefined();
475
- expect(bSchema.b.position.y).toEqual(padding);
476
- expect(bSchema.b.height).toEqual(bHeight);
494
+ expect(dynamicTemplate.schemas[1][0]).toBeDefined();
495
+ expect(dynamicTemplate.schemas[1][0].position.y).toEqual(padding);
496
+ expect(dynamicTemplate.schemas[1][0].height).toEqual(bHeight);
497
+ expect(dynamicTemplate.schemas[1][0].name).toEqual('b');
477
498
  });
478
499
  });
479
500
  describe('Edge cases', () => {
@@ -482,8 +503,9 @@ describe('getDynamicTemplate', () => {
482
503
  const dynamicTemplate = await (0, helper_1.getDynamicTemplate)(createGetDynamicTemplateArg(increaseHeights));
483
504
  verifyBasicStructure(dynamicTemplate);
484
505
  expect(dynamicTemplate.schemas.length).toBe(1);
485
- expect(dynamicTemplate.schemas[0].a).toBeUndefined();
486
- expect(dynamicTemplate.schemas[0].b).toBeDefined();
506
+ expect(dynamicTemplate.schemas[0][0]).toBeDefined();
507
+ expect(dynamicTemplate.schemas[0][0].name).toEqual('b');
508
+ expect(dynamicTemplate.schemas[0][1]).toBeUndefined();
487
509
  });
488
510
  test('should handle very large increase heights', async () => {
489
511
  const increaseHeights = [1000, 1000];
@@ -493,4 +515,133 @@ describe('getDynamicTemplate', () => {
493
515
  });
494
516
  });
495
517
  });
518
+ describe('migrateTemplate', () => {
519
+ it('should convert LegacySchemaPageArray to SchemaPageArray', () => {
520
+ const legacyTemplate = {
521
+ schemas: [
522
+ {
523
+ "field1": {
524
+ "type": "text",
525
+ "content": "Field 1",
526
+ "width": 45,
527
+ "height": 10,
528
+ "position": {
529
+ "x": 0,
530
+ "y": 0
531
+ }
532
+ },
533
+ "field2": {
534
+ "type": "text",
535
+ "content": "Field 2",
536
+ "width": 45,
537
+ "height": 10,
538
+ "position": {
539
+ "x": 0,
540
+ "y": 0
541
+ }
542
+ }
543
+ },
544
+ {
545
+ "field3": {
546
+ "type": "text",
547
+ "content": "Field 3",
548
+ "width": 45,
549
+ "height": 10,
550
+ "position": {
551
+ "x": 0,
552
+ "y": 0
553
+ }
554
+ }
555
+ }
556
+ ]
557
+ };
558
+ (0, helper_1.migrateTemplate)(legacyTemplate);
559
+ const expectedSchemaPageArray = [
560
+ [
561
+ {
562
+ "name": "field1",
563
+ "type": "text",
564
+ "content": "Field 1",
565
+ "width": 45,
566
+ "height": 10,
567
+ "position": {
568
+ "x": 0,
569
+ "y": 0
570
+ }
571
+ },
572
+ {
573
+ "name": "field2",
574
+ "type": "text",
575
+ "content": "Field 2",
576
+ "width": 45,
577
+ "height": 10,
578
+ "position": {
579
+ "x": 0,
580
+ "y": 0
581
+ }
582
+ }
583
+ ],
584
+ [
585
+ {
586
+ "name": "field3",
587
+ "type": "text",
588
+ "content": "Field 3",
589
+ "width": 45,
590
+ "height": 10,
591
+ "position": {
592
+ "x": 0,
593
+ "y": 0
594
+ }
595
+ }
596
+ ]
597
+ ];
598
+ expect(legacyTemplate.schemas).toEqual(expectedSchemaPageArray);
599
+ });
600
+ it('should not modify already SchemaPageArray', () => {
601
+ const pagedTemplate = {
602
+ schemas: [
603
+ [
604
+ {
605
+ "name": "field1",
606
+ "type": "text",
607
+ "content": "Field 1",
608
+ "width": 45,
609
+ "height": 10,
610
+ "position": {
611
+ "x": 0,
612
+ "y": 0
613
+ }
614
+ },
615
+ {
616
+ "name": "field2",
617
+ "type": "text",
618
+ "content": "Field 2",
619
+ "width": 45,
620
+ "height": 10,
621
+ "position": {
622
+ "x": 0,
623
+ "y": 0
624
+ }
625
+ }
626
+ ],
627
+ [
628
+ {
629
+ "name": "field3",
630
+ "type": "text",
631
+ "content": "Field 3",
632
+ "width": 45,
633
+ "height": 10,
634
+ "position": {
635
+ "x": 0,
636
+ "y": 0
637
+ }
638
+ }
639
+ ]
640
+ ]
641
+ };
642
+ const before = JSON.parse(JSON.stringify(pagedTemplate));
643
+ (0, helper_1.migrateTemplate)(pagedTemplate);
644
+ expect(pagedTemplate.schemas).toEqual(before.schemas);
645
+ });
646
+ });
496
647
  //# sourceMappingURL=helper.test.js.map