Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit c619740

Browse files
authored
Improve layouts and use translations
* make sure that the transition is vertical when the vertical option is true * make vertical option visible when showing the uischema * make vertical false the default * remove full-height that adds additional space * place the contact of the tabs when in horizontal mode to be inside v-col as well * remove full-height * check for null values for schema or data * use specific function from lodash to not bring every function from it * streamline types * add vuetify v-bind for v-tab and v-tab-item * allow more v elements to be customized, including button label translation and ability to override default values like color * allow default messages with parameters to be translated * add translations and use available message translations from jsonforms core * add vuetifyProps configuration
1 parent c44abe2 commit c619740

File tree

23 files changed

+272
-175
lines changed

23 files changed

+272
-175
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dependencies": {
1111
"@jsonforms/core": "3.1.0-alpha.2",
1212
"@jsonforms/vue2": "3.1.0-alpha.2",
13-
"@jsonforms/vue2-vuetify": "^3.1.0-alpha.2",
13+
"@jsonforms/vue2-vuetify": "3.1.0-alpha.2",
1414
"ajv-keywords": "^5.1.0",
1515
"core-js": "^3.9.1",
1616
"json-refs": "^3.0.15",

example/src/components/DemoForm.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151

5252
<script lang="ts">
5353
import { PropType } from 'vue';
54-
import { Example, ResolvedSchema } from '@/core/types';
55-
import { Ajv } from 'ajv';
54+
import { JsonExample, ResolvedSchema } from '@/core/types';
55+
import type Ajv from 'ajv';
5656
import {
5757
ValidationMode,
5858
JsonFormsUISchemaRegistryEntry,
@@ -71,7 +71,7 @@ export default {
7171
JsonForms,
7272
},
7373
props: {
74-
example: { type: Object as PropType<Example>, required: true },
74+
example: { type: Object as PropType<JsonExample>, required: true },
7575
renderers: {
7676
required: true,
7777
type: Array as PropType<JsonFormsRendererRegistryEntry[]>,
@@ -128,7 +128,7 @@ export default {
128128
watch: {
129129
example: {
130130
deep: true,
131-
handler(newExample: Example, oldExample: Example): void {
131+
handler(newExample: JsonExample, oldExample: JsonExample): void {
132132
this.resolveSchema(newExample.input.schema);
133133
this.i18n.translate = createTranslator(
134134
this.locale,

example/src/core/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,34 @@ import {
22
UISchemaElement,
33
JsonSchema,
44
JsonFormsRendererRegistryEntry,
5+
JsonFormsUISchemaRegistryEntry,
56
} from '@jsonforms/core';
67

78
export type Example = {
89
id: string;
910
title: string;
11+
note?: string;
1012
input: {
1113
schema?: JsonSchema;
1214
uischema?: UISchemaElement;
15+
uischemas?: JsonFormsUISchemaRegistryEntry[];
1316
data: string | number | boolean | any[] | Record<string, any>;
1417
i18n?: Record<string, any>;
1518
renderers?: JsonFormsRendererRegistryEntry[];
1619
};
1720
};
1821

22+
export type JsonExampleInput = Omit<Example['input'], 'uischemas'> & {
23+
uischemas?: {
24+
tester: string;
25+
uischema: UISchemaElement;
26+
}[];
27+
};
28+
29+
export type JsonExample = Omit<Example, 'input'> & {
30+
input: JsonExampleInput;
31+
};
32+
1933
export type ResolvedSchema = {
2034
schema?: JsonSchema;
2135
resolved: boolean;

example/src/examples/categorization-stepper-nav/uischema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
],
122122
"options": {
123123
"variant": "stepper",
124-
"showNavButtons": true
124+
"showNavButtons": true,
125+
"vertical": false
125126
}
126-
}
127+
}

example/src/examples/categorization-stepper/uischema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
}
121121
],
122122
"options": {
123-
"variant": "stepper"
123+
"variant": "stepper",
124+
"vertical": false
124125
}
125-
}
126+
}

example/src/examples/categorization/uischema.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,8 @@
118118
}
119119
}
120120
}
121-
]
122-
}
121+
],
122+
"options": {
123+
"vertical": false
124+
}
125+
}

example/src/examples/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ import { input as rule } from './rule';
4646
import { input as verticalLayout } from './vertical-layout';
4747
import { input as huge } from './huge';
4848
import { input as ifThenElse } from './if-then-else';
49+
import { JsonExample } from '@/core/types';
4950

50-
export const examples = [
51+
export const examples: JsonExample[] = [
5152
{
5253
id: 'main',
5354
title: 'Main',

example/src/i18n/i18n.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export const createTranslator = (
2020
defaultMessage: string | undefined,
2121
values?: any
2222
): string | undefined => {
23-
if (!localeTranslations) return defaultMessage;
24-
25-
const message = get(localeTranslations, id);
23+
const message = localeTranslations
24+
? get(localeTranslations, id)
25+
: defaultMessage;
2626
if (message && values) {
2727
return translateWithParams(message, values) ?? defaultMessage;
2828
}

example/src/views/example/Example.vue

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247

248248
<script lang="ts">
249249
import { examples } from '@/examples';
250-
import { find } from 'lodash';
250+
import find from 'lodash/find';
251251
import { sync } from 'vuex-pathify';
252252
253253
import DemoForm from '@/components/DemoForm.vue';
@@ -259,7 +259,7 @@ import {
259259
EditorApi,
260260
getMonacoModelForUri,
261261
} from '@/core/jsonSchemaValidation';
262-
import { Example } from '@/core/types';
262+
import { JsonExample } from '@/core/types';
263263
import type { JsonFormsRendererRegistryEntry } from '@jsonforms/core';
264264
import { JsonFormsChangeEvent } from '@jsonforms/vue2';
265265
import {
@@ -286,7 +286,7 @@ export default {
286286
return {
287287
activeTab: 0,
288288
examples,
289-
example: undefined,
289+
example: undefined as JsonExample | undefined,
290290
errors: undefined as
291291
| ErrorObject<string, Record<string, any>, unknown>[]
292292
| undefined,
@@ -314,34 +314,34 @@ export default {
314314
return this.$route.query?.view === 'form-only';
315315
},
316316
},
317-
mounted() {
317+
mounted(): void {
318318
this.setExample(
319319
find(this.examples, (example) => example.id === this.$route.params.id)
320320
);
321321
},
322322
watch: {
323-
'$route.params.id'(id) {
323+
'$route.params.id'(id: string): void {
324324
this.setExample(find(this.examples, (example) => example.id === id));
325325
},
326326
},
327327
methods: {
328-
onChange(event: JsonFormsChangeEvent) {
328+
onChange(event: JsonFormsChangeEvent): void {
329329
this.$store.set(
330330
'app/monaco@dataModel',
331331
getMonacoModelForUri(
332-
monaco.Uri.parse(this.toDataUri(this.example.id)),
332+
monaco.Uri.parse(this.toDataUri(this.example!.id)),
333333
event.data ? JSON.stringify(event.data, null, 2) : ''
334334
)
335335
);
336336
this.errors = event.errors;
337337
},
338-
setExample(example: Example): void {
338+
setExample(example?: JsonExample): void {
339339
if (example) {
340340
this.example = cloneDeep(example);
341341
this.updateMonacoModels(this.example);
342342
}
343343
},
344-
reloadMonacoSchema() {
344+
reloadMonacoSchema(): void {
345345
const example = find(
346346
this.examples,
347347
(example) => example.id === this.$route.params.id
@@ -360,7 +360,7 @@ export default {
360360
this.toast('Original example schema loaded. Apply it to take effect.');
361361
}
362362
},
363-
saveMonacoSchema() {
363+
saveMonacoSchema(): void {
364364
const model = this.monacoSchemaModel as monaco.editor.ITextModel;
365365
const example = this.example;
366366
@@ -384,7 +384,7 @@ export default {
384384
}
385385
}
386386
},
387-
reloadMonacoUiSchema() {
387+
reloadMonacoUiSchema(): void {
388388
const example = find(
389389
this.examples,
390390
(example) => example.id === this.$route.params.id
@@ -405,7 +405,7 @@ export default {
405405
);
406406
}
407407
},
408-
saveMonacoUiSchema() {
408+
saveMonacoUiSchema(): void {
409409
const model = this.monacoUiSchemaModel as monaco.editor.ITextModel;
410410
const example = this.example;
411411
@@ -430,7 +430,7 @@ export default {
430430
}
431431
}
432432
},
433-
reloadMonacoData() {
433+
reloadMonacoData(): void {
434434
const example = find(
435435
this.examples,
436436
(example) => example.id === this.$route.params.id
@@ -449,7 +449,7 @@ export default {
449449
this.toast('Original example data loaded. Apply it to take effect.');
450450
}
451451
},
452-
saveMonacoData() {
452+
saveMonacoData(): void {
453453
const model = this.monacoDataModel as monaco.editor.ITextModel;
454454
const example = this.example;
455455
@@ -473,7 +473,7 @@ export default {
473473
}
474474
}
475475
},
476-
reloadMonacoI18N() {
476+
reloadMonacoI18N(): void {
477477
const example = find(
478478
this.examples,
479479
(example) => example.id === this.$route.params.id
@@ -492,7 +492,7 @@ export default {
492492
this.toast('Original example i18n loaded. Apply it to take effect.');
493493
}
494494
},
495-
saveMonacoI18N() {
495+
saveMonacoI18N(): void {
496496
const model = this.monacoI18NModel as monaco.editor.ITextModel;
497497
const example = this.example;
498498
@@ -517,7 +517,7 @@ export default {
517517
}
518518
}
519519
},
520-
registerValidations(editor: EditorApi) {
520+
registerValidations(editor: EditorApi): void {
521521
configureJsonSchemaValidation(editor, ['*.schema.json']);
522522
configureUISchemaValidation(editor, ['*.uischema.json']);
523523
for (let example of examples) {
@@ -536,7 +536,7 @@ export default {
536536
}
537537
}
538538
},
539-
updateMonacoModels(example) {
539+
updateMonacoModels(example: JsonExample): void {
540540
this.$store.set(
541541
'app/monaco@schemaModel',
542542
getMonacoModelForUri(

lerna.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"packages": [
3-
"vue2-vuetify",
4-
"example"
5-
],
2+
"packages": ["vue2-vuetify", "example"],
63
"version": "3.1.0-alpha.2"
74
}

0 commit comments

Comments
 (0)