@jsonforms/examples 3.6.0-alpha.1 → 3.6.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/examples",
3
- "version": "3.6.0-alpha.1",
3
+ "version": "3.6.0-beta.0",
4
4
  "description": "JSON Forms Example Data",
5
5
  "repository": "https://github.com/eclipsesource/jsonforms",
6
6
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
@@ -39,7 +39,7 @@
39
39
  "lodash": "^4.17.21"
40
40
  },
41
41
  "peerDependencies": {
42
- "@jsonforms/core": "3.6.0-alpha.1"
42
+ "@jsonforms/core": "3.6.0-beta.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^22.13.8",
@@ -58,7 +58,7 @@
58
58
  "tslib": "^2.5.0",
59
59
  "typedoc": "~0.25.3",
60
60
  "typescript": "~5.5.0",
61
- "@jsonforms/core": "3.6.0-alpha.1"
61
+ "@jsonforms/core": "3.6.0-beta.0"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "rollup -c rollup.config.js",
@@ -0,0 +1,50 @@
1
+ /*
2
+ The MIT License
3
+
4
+ Copyright (c) 2017-2019 EclipseSource Munich
5
+ https://github.com/eclipsesource/jsonforms
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+ */
25
+ import { registerExamples } from '../register';
26
+
27
+ export const schema = {
28
+ type: ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'],
29
+ additionalProperties: true,
30
+ items: {
31
+ type: ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'],
32
+ },
33
+ };
34
+
35
+ export const uischema = {
36
+ type: 'Control',
37
+ scope: '#/',
38
+ };
39
+
40
+ const data = undefined as any;
41
+
42
+ registerExamples([
43
+ {
44
+ name: 'json-editor',
45
+ label: 'JSON Editor',
46
+ data,
47
+ schema,
48
+ uischema,
49
+ },
50
+ ]);
@@ -0,0 +1,592 @@
1
+ /*
2
+ The MIT License
3
+
4
+ Copyright (c) 2017-2019 EclipseSource Munich
5
+ https://github.com/eclipsesource/jsonforms
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+ */
25
+ import {
26
+ type JsonFormsUISchemaRegistryEntry,
27
+ type JsonSchema,
28
+ NOT_APPLICABLE,
29
+ type UISchemaElement,
30
+ } from '@jsonforms/core';
31
+ import { registerExamples } from '../register';
32
+ import { StateProps } from '../example';
33
+
34
+ export const schema = {
35
+ $schema: 'http://json-schema.org/draft-07/schema#',
36
+ $id: 'http://json-schema.org/draft-07/schema#',
37
+ title: 'Core schema meta-schema',
38
+ definitions: {
39
+ schemaArray: {
40
+ type: 'array',
41
+ minItems: 1,
42
+ items: { $ref: '#' },
43
+ },
44
+ nonNegativeInteger: {
45
+ type: 'integer',
46
+ minimum: 0,
47
+ },
48
+ nonNegativeIntegerDefault0: {
49
+ allOf: [{ $ref: '#/definitions/nonNegativeInteger' }, { default: 0 }],
50
+ },
51
+ simpleTypes: {
52
+ type: 'string',
53
+ enum: [
54
+ 'array',
55
+ 'boolean',
56
+ 'integer',
57
+ 'null',
58
+ 'number',
59
+ 'object',
60
+ 'string',
61
+ ],
62
+ },
63
+ stringArray: {
64
+ type: 'array',
65
+ items: { type: 'string' },
66
+ uniqueItems: true,
67
+ default: [] as any,
68
+ },
69
+ },
70
+ type: ['object', 'boolean'],
71
+ properties: {
72
+ $id: {
73
+ type: 'string',
74
+ format: 'uri-reference',
75
+ },
76
+ $schema: {
77
+ type: 'string',
78
+ format: 'uri',
79
+ },
80
+ $ref: {
81
+ type: 'string',
82
+ format: 'uri-reference',
83
+ },
84
+ $comment: {
85
+ type: 'string',
86
+ },
87
+ title: {
88
+ type: 'string',
89
+ },
90
+ description: {
91
+ type: 'string',
92
+ },
93
+ default: true,
94
+ readOnly: {
95
+ type: 'boolean',
96
+ default: false,
97
+ },
98
+ writeOnly: {
99
+ type: 'boolean',
100
+ default: false,
101
+ },
102
+ examples: {
103
+ type: 'array',
104
+ items: true,
105
+ },
106
+ multipleOf: {
107
+ type: 'number',
108
+ exclusiveMinimum: 0,
109
+ },
110
+ maximum: {
111
+ type: 'number',
112
+ },
113
+ exclusiveMaximum: {
114
+ type: 'number',
115
+ },
116
+ minimum: {
117
+ type: 'number',
118
+ },
119
+ exclusiveMinimum: {
120
+ type: 'number',
121
+ },
122
+ maxLength: { $ref: '#/definitions/nonNegativeInteger' },
123
+ minLength: { $ref: '#/definitions/nonNegativeIntegerDefault0' },
124
+ pattern: {
125
+ type: 'string',
126
+ format: 'regex',
127
+ },
128
+ additionalItems: { $ref: '#' },
129
+ items: {
130
+ anyOf: [{ $ref: '#' }, { $ref: '#/definitions/schemaArray' }],
131
+ default: true,
132
+ },
133
+ maxItems: { $ref: '#/definitions/nonNegativeInteger' },
134
+ minItems: { $ref: '#/definitions/nonNegativeIntegerDefault0' },
135
+ uniqueItems: {
136
+ type: 'boolean',
137
+ default: false,
138
+ },
139
+ contains: { $ref: '#' },
140
+ maxProperties: { $ref: '#/definitions/nonNegativeInteger' },
141
+ minProperties: { $ref: '#/definitions/nonNegativeIntegerDefault0' },
142
+ required: { $ref: '#/definitions/stringArray' },
143
+ additionalProperties: { $ref: '#' },
144
+ definitions: {
145
+ type: 'object',
146
+ additionalProperties: { $ref: '#' },
147
+ default: {},
148
+ },
149
+ properties: {
150
+ type: 'object',
151
+ additionalProperties: { $ref: '#' },
152
+ default: {},
153
+ },
154
+ patternProperties: {
155
+ type: 'object',
156
+ additionalProperties: { $ref: '#' },
157
+ propertyNames: { format: 'regex' },
158
+ default: {},
159
+ },
160
+ dependencies: {
161
+ type: 'object',
162
+ additionalProperties: {
163
+ anyOf: [{ $ref: '#' }, { $ref: '#/definitions/stringArray' }],
164
+ },
165
+ },
166
+ propertyNames: { $ref: '#' },
167
+ const: true,
168
+ enum: {
169
+ type: 'array',
170
+ items: true,
171
+ minItems: 1,
172
+ uniqueItems: true,
173
+ },
174
+ type: {
175
+ anyOf: [
176
+ { $ref: '#/definitions/simpleTypes' },
177
+ {
178
+ type: 'array',
179
+ items: { $ref: '#/definitions/simpleTypes' },
180
+ minItems: 1,
181
+ uniqueItems: true,
182
+ },
183
+ ],
184
+ },
185
+ format: { type: 'string' },
186
+ contentMediaType: { type: 'string' },
187
+ contentEncoding: { type: 'string' },
188
+ if: { $ref: '#' },
189
+ then: { $ref: '#' },
190
+ else: { $ref: '#' },
191
+ allOf: { $ref: '#/definitions/schemaArray' },
192
+ anyOf: { $ref: '#/definitions/schemaArray' },
193
+ oneOf: { $ref: '#/definitions/schemaArray' },
194
+ not: { $ref: '#' },
195
+ },
196
+ default: true,
197
+ };
198
+
199
+ export const uischema: UISchemaElement = undefined as any as UISchemaElement;
200
+
201
+ export const data = {
202
+ type: 'object',
203
+ properties: {
204
+ name: {
205
+ type: 'string',
206
+ minLength: 3,
207
+ description: 'Please enter your name',
208
+ },
209
+ vegetarian: {
210
+ type: 'boolean',
211
+ },
212
+ birthDate: {
213
+ type: 'string',
214
+ format: 'date',
215
+ },
216
+ nationality: {
217
+ type: 'string',
218
+ enum: ['DE', 'IT', 'JP', 'US', 'RU', 'Other'],
219
+ },
220
+ personalData: {
221
+ type: 'object',
222
+ properties: {
223
+ age: {
224
+ type: 'integer',
225
+ description: 'Please enter your age.',
226
+ },
227
+ height: {
228
+ type: 'number',
229
+ },
230
+ drivingSkill: {
231
+ type: 'number',
232
+ maximum: 10,
233
+ minimum: 1,
234
+ default: 7,
235
+ },
236
+ },
237
+ required: ['age', 'height'],
238
+ },
239
+ occupation: {
240
+ type: 'string',
241
+ },
242
+ postalCode: {
243
+ type: 'string',
244
+ maxLength: 5,
245
+ },
246
+ },
247
+ required: ['occupation', 'nationality'],
248
+ };
249
+
250
+ const shouldContainTypeCondition = (type: string[]) => {
251
+ return {
252
+ scope: '#/properties/type',
253
+ schema: {
254
+ anyOf: [
255
+ {
256
+ type: 'string',
257
+ enum: type,
258
+ },
259
+ {
260
+ type: 'array',
261
+ items: {
262
+ type: 'string',
263
+ },
264
+ contains: {
265
+ type: 'string',
266
+ enum: type,
267
+ },
268
+ },
269
+ ],
270
+ },
271
+ };
272
+ };
273
+
274
+ const typeIsSpecifiedCondition = {
275
+ scope: '#/properties/type',
276
+ schema: {
277
+ oneOf: [
278
+ {
279
+ type: 'string',
280
+ enum: [
281
+ 'string',
282
+ 'number',
283
+ 'integer',
284
+ 'array',
285
+ 'object',
286
+ 'boolean',
287
+ 'null',
288
+ ],
289
+ },
290
+ {
291
+ type: 'array',
292
+ items: {
293
+ type: 'string',
294
+ enum: [
295
+ 'string',
296
+ 'number',
297
+ 'integer',
298
+ 'array',
299
+ 'object',
300
+ 'boolean',
301
+ 'null',
302
+ ],
303
+ },
304
+ minItems: 1,
305
+ uniqueItems: true,
306
+ },
307
+ ],
308
+ },
309
+ };
310
+
311
+ const properties = {
312
+ type: 'Control',
313
+ scope: '#/properties/properties',
314
+ };
315
+
316
+ const required = {
317
+ type: 'Control',
318
+ scope: '#/properties/required',
319
+ };
320
+
321
+ const constraintsLayout = {
322
+ type: 'Categorization',
323
+ elements: [
324
+ {
325
+ type: 'Category',
326
+ label: 'Number',
327
+ rule: {
328
+ effect: 'SHOW',
329
+ condition: shouldContainTypeCondition(['number', 'integer']),
330
+ },
331
+ elements: [
332
+ {
333
+ type: 'VerticalLayout',
334
+ elements: [
335
+ {
336
+ type: 'Control',
337
+ scope: '#/properties/multipleOf',
338
+ },
339
+ {
340
+ type: 'Control',
341
+ scope: '#/properties/maximum',
342
+ },
343
+ {
344
+ type: 'Control',
345
+ scope: '#/properties/exclusiveMaximum',
346
+ },
347
+ {
348
+ type: 'Control',
349
+ scope: '#/properties/minimum',
350
+ },
351
+ {
352
+ type: 'Control',
353
+ scope: '#/properties/exclusiveMinimum',
354
+ },
355
+ ],
356
+ },
357
+ ],
358
+ },
359
+ {
360
+ type: 'Category',
361
+ label: 'String',
362
+ rule: {
363
+ effect: 'SHOW',
364
+ condition: shouldContainTypeCondition(['string']),
365
+ },
366
+ elements: [
367
+ {
368
+ type: 'Control',
369
+ scope: '#/properties/maxLength',
370
+ },
371
+ {
372
+ type: 'Control',
373
+ scope: '#/properties/minLength',
374
+ },
375
+ {
376
+ type: 'Control',
377
+ scope: '#/properties/pattern',
378
+ },
379
+ ],
380
+ },
381
+ {
382
+ type: 'Category',
383
+ label: 'Array',
384
+ rule: {
385
+ effect: 'SHOW',
386
+ condition: shouldContainTypeCondition(['array']),
387
+ },
388
+ elements: [
389
+ {
390
+ type: 'Control',
391
+ scope: '#/properties/minItems',
392
+ },
393
+ {
394
+ type: 'Control',
395
+ scope: '#/properties/maxItems',
396
+ },
397
+ {
398
+ type: 'Control',
399
+ scope: '#/properties/uniqueItems',
400
+ },
401
+ ],
402
+ },
403
+ {
404
+ type: 'Category',
405
+ label: 'Object',
406
+ rule: {
407
+ effect: 'SHOW',
408
+ condition: shouldContainTypeCondition(['object']),
409
+ },
410
+ elements: [
411
+ {
412
+ type: 'Control',
413
+ scope: '#/properties/minProperties',
414
+ },
415
+ {
416
+ type: 'Control',
417
+ scope: '#/properties/maxProperties',
418
+ },
419
+ ],
420
+ },
421
+ ],
422
+ };
423
+
424
+ const controlLabel = (
425
+ controlSchemaPath: string,
426
+ controlLabel: string,
427
+ controlSchemaType: string | undefined = undefined
428
+ ) => {
429
+ return {
430
+ tester: (jsonSchema: JsonSchema, schemaPath: string, _path: string) => {
431
+ if (
432
+ controlSchemaPath === schemaPath &&
433
+ (controlSchemaType === undefined ||
434
+ controlSchemaType === jsonSchema.type)
435
+ ) {
436
+ return 2;
437
+ }
438
+ return NOT_APPLICABLE;
439
+ },
440
+ uischema: {
441
+ type: 'Control',
442
+ scope: '#',
443
+ label: controlLabel,
444
+ },
445
+ };
446
+ };
447
+
448
+ export const uischemas = [
449
+ controlLabel('#/properties/minItems', 'Min Items', 'number'),
450
+ controlLabel('#/properties/maxItems', 'Max Items'),
451
+ {
452
+ tester: (jsonSchema: JsonSchema, schemaPath: string, path: string) => {
453
+ if (
454
+ path === 'type' &&
455
+ schemaPath === '#/properties/type' &&
456
+ jsonSchema.type === 'array'
457
+ ) {
458
+ return 2;
459
+ }
460
+ return NOT_APPLICABLE;
461
+ },
462
+ uischema: {
463
+ type: 'Control',
464
+ scope: '#',
465
+ },
466
+ },
467
+ {
468
+ tester: (jsonSchema: JsonSchema, _schemaPath: string, _path: string) => {
469
+ return 'http://json-schema.org/draft-07/schema#' ===
470
+ (jsonSchema as any).$id && jsonSchema.type === 'object'
471
+ ? 2
472
+ : NOT_APPLICABLE;
473
+ },
474
+ uischema: {
475
+ type: 'Categorization',
476
+ elements: [
477
+ {
478
+ type: 'Category',
479
+ label: 'Basic',
480
+ elements: [
481
+ {
482
+ type: 'VerticalLayout',
483
+ elements: [
484
+ { type: 'Control', scope: '#/properties/$id' },
485
+ { type: 'Control', scope: '#/properties/$schema' },
486
+ { type: 'Control', scope: '#/properties/title' },
487
+ { type: 'Control', scope: '#/properties/description' },
488
+ ],
489
+ },
490
+ ],
491
+ },
492
+ {
493
+ type: 'Category',
494
+ label: 'Structure',
495
+ elements: [
496
+ {
497
+ type: 'VerticalLayout',
498
+ elements: [
499
+ {
500
+ type: 'Control',
501
+ scope: '#/properties/type',
502
+ options: {
503
+ 'label-0': 'Single Type',
504
+ 'label-1': 'Multiple Types',
505
+ },
506
+ },
507
+ {
508
+ type: 'Categorization',
509
+ rule: {
510
+ effect: 'SHOW',
511
+ condition: shouldContainTypeCondition(['object']),
512
+ },
513
+ elements: [
514
+ {
515
+ type: 'Category',
516
+ label: 'Properties',
517
+ elements: [properties],
518
+ },
519
+ {
520
+ type: 'Category',
521
+ label: 'Required',
522
+ elements: [required],
523
+ },
524
+ ],
525
+ },
526
+ ],
527
+ },
528
+ ],
529
+ },
530
+ {
531
+ type: 'Category',
532
+ label: 'Constraints',
533
+ rule: {
534
+ effect: 'SHOW',
535
+ condition: typeIsSpecifiedCondition,
536
+ },
537
+ elements: [constraintsLayout],
538
+ },
539
+ ],
540
+ options: {
541
+ variant: 'stepper',
542
+ showNavButtons: true,
543
+ },
544
+ },
545
+ },
546
+ {
547
+ tester: (jsonSchema: JsonSchema, _schemaPath: string, _path: string) => {
548
+ return 'http://json-schema.org/draft-07/schema#' ===
549
+ (jsonSchema as any).$id && jsonSchema.type === 'boolean'
550
+ ? 2
551
+ : NOT_APPLICABLE;
552
+ },
553
+ uischema: {
554
+ type: 'VerticalLayout',
555
+ elements: [{ type: 'Control', scope: '#/' }],
556
+ },
557
+ },
558
+ ];
559
+
560
+ const actions = [
561
+ {
562
+ label: 'Register UISchema',
563
+ apply: (props: StateProps) => {
564
+ return {
565
+ ...props,
566
+ uischemas: uischemas,
567
+ };
568
+ },
569
+ },
570
+ {
571
+ label: 'Unregister UISchema',
572
+ apply: (props: StateProps) => {
573
+ const uischemas: JsonFormsUISchemaRegistryEntry[] =
574
+ undefined as any as JsonFormsUISchemaRegistryEntry[];
575
+ return {
576
+ ...props,
577
+ uischemas: uischemas,
578
+ };
579
+ },
580
+ },
581
+ ];
582
+
583
+ registerExamples([
584
+ {
585
+ name: 'jsonschema',
586
+ label: 'JsonSchema',
587
+ data,
588
+ schema: schema as any as JsonSchema,
589
+ uischema,
590
+ actions,
591
+ },
592
+ ]);