From 1ebc5401480fac958e218cb413352093f8c23083 Mon Sep 17 00:00:00 2001 From: David Wolter Date: Mon, 5 Feb 2024 12:08:05 +0100 Subject: [PATCH 01/10] feat: add categorization renderer to Vue Vanilla Implemented also the stepper variant --- .../src/complex/Categorization.vue | 146 ++++++++++++++++++ packages/vue-vanilla/src/complex/index.ts | 3 + .../vue-vanilla/src/styles/defaultStyles.ts | 12 ++ packages/vue-vanilla/src/styles/styles.ts | 13 ++ packages/vue-vanilla/src/util/composition.ts | 24 ++- packages/vue-vanilla/vanilla.css | 14 ++ 6 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 packages/vue-vanilla/src/complex/Categorization.vue diff --git a/packages/vue-vanilla/src/complex/Categorization.vue b/packages/vue-vanilla/src/complex/Categorization.vue new file mode 100644 index 0000000000..a9afc84a82 --- /dev/null +++ b/packages/vue-vanilla/src/complex/Categorization.vue @@ -0,0 +1,146 @@ + + + + diff --git a/packages/vue-vanilla/src/complex/index.ts b/packages/vue-vanilla/src/complex/index.ts index 418e816cb9..4916b88e82 100644 --- a/packages/vue-vanilla/src/complex/index.ts +++ b/packages/vue-vanilla/src/complex/index.ts @@ -1,13 +1,16 @@ export { default as ObjectRenderer } from './ObjectRenderer.vue'; export { default as OneOfRenderer } from './OneOfRenderer.vue'; export { default as EnumArrayRenderer } from './EnumArrayRenderer.vue'; +export { default as CategorizationRenderer } from './Categorization.vue'; import { entry as objectRendererEntry } from './ObjectRenderer.vue'; import { entry as oneOfRendererEntry } from './OneOfRenderer.vue'; import { entry as enumArrayRendererEntry } from './EnumArrayRenderer.vue'; +import { entry as categorizationEntry } from './Categorization.vue'; export const complexRenderers = [ objectRendererEntry, oneOfRendererEntry, enumArrayRendererEntry, + categorizationEntry, ]; diff --git a/packages/vue-vanilla/src/styles/defaultStyles.ts b/packages/vue-vanilla/src/styles/defaultStyles.ts index 2c623c45a0..d8a2a5a233 100644 --- a/packages/vue-vanilla/src/styles/defaultStyles.ts +++ b/packages/vue-vanilla/src/styles/defaultStyles.ts @@ -57,4 +57,16 @@ export const defaultStyles: Styles = { oneOf: { root: 'one-of', }, + categorization: { + root: 'categorization', + category: 'categorization-category', + selected: 'categorization-selected', + panel: 'categorization-panel', + stepper: 'categorization-stepper', + stepperBadge: 'categorization-stepper-badge', + stepperLine: 'categorization-stepper-line', + stepperFooter: 'categorization-stepper-footer', + stepperButtonBack: 'categorization-stepper-button-back', + stepperButtonNext: 'categorization-stepper-button-next', + } }; diff --git a/packages/vue-vanilla/src/styles/styles.ts b/packages/vue-vanilla/src/styles/styles.ts index 8b8eeed940..8cb69adfc8 100644 --- a/packages/vue-vanilla/src/styles/styles.ts +++ b/packages/vue-vanilla/src/styles/styles.ts @@ -12,6 +12,7 @@ const createEmptyStyles = (): Styles => ({ label: {}, dialog: {}, oneOf: {}, + categorization: {}, }); export interface Styles { @@ -71,6 +72,18 @@ export interface Styles { oneOf: { root?: string; }; + categorization: { + root?: string; + category?: string; + selected?: string; + panel?: string; + stepper?: string; + stepperBadge?:string; + stepperLine?:string; + stepperFooter?:string; + stepperButtonBack?:string; + stepperButtonNext?:string; + }; } export const useStyles = (element?: UISchemaElement) => { diff --git a/packages/vue-vanilla/src/util/composition.ts b/packages/vue-vanilla/src/util/composition.ts index 89bc88e6d4..167607ba53 100644 --- a/packages/vue-vanilla/src/util/composition.ts +++ b/packages/vue-vanilla/src/util/composition.ts @@ -1,5 +1,5 @@ import { useStyles } from '../styles'; -import { computed, ref } from 'vue'; +import { computed, ref, inject } from 'vue'; import merge from 'lodash/merge'; import cloneDeep from 'lodash/cloneDeep'; import { @@ -7,6 +7,7 @@ import { findUISchema, getFirstPrimitiveProp, Resolve, + type JsonFormsSubStates } from '@jsonforms/core'; /** @@ -137,3 +138,24 @@ export const useVanillaArrayControl = ( childLabelForIndex, }; }; + +export const useTranslator = () => { + const jsonforms = inject('jsonforms'); + + if (!jsonforms) { + throw new Error( + "'jsonforms couldn't be injected. Are you within JSON Forms?" + ); + } + + if (!jsonforms.i18n || !jsonforms.i18n.translate) { + throw new Error( + "'jsonforms i18n couldn't be injected. Are you within JSON Forms?" + ); + } + + return computed(() => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return jsonforms.i18n!.translate!; + }); +}; diff --git a/packages/vue-vanilla/vanilla.css b/packages/vue-vanilla/vanilla.css index 725eb57d24..2273636ff5 100644 --- a/packages/vue-vanilla/vanilla.css +++ b/packages/vue-vanilla/vanilla.css @@ -77,3 +77,17 @@ .array-list-item-content.expanded { display: block; } + +.categorization .categorization-category, +.categorization .categorization-stepper { + display: flex; +} +.categorization .categorization-stepper-line { + flex-grow: 1; + height:1px; + border-width:0 0 1px 0; +} +.categorization .categorization-stepper-footer { + display: flex; + justify-content: flex-end; +} From 9ae7a5543e4793e6653223d82b6262e5ac254c6a Mon Sep 17 00:00:00 2001 From: David Wolter Date: Mon, 5 Feb 2024 13:53:41 +0100 Subject: [PATCH 02/10] call pnpm run lint:fix --- .../src/complex/Categorization.vue | 111 ++++++++++-------- .../vue-vanilla/src/styles/defaultStyles.ts | 2 +- packages/vue-vanilla/src/styles/styles.ts | 10 +- packages/vue-vanilla/src/util/composition.ts | 6 +- 4 files changed, 70 insertions(+), 59 deletions(-) diff --git a/packages/vue-vanilla/src/complex/Categorization.vue b/packages/vue-vanilla/src/complex/Categorization.vue index a9afc84a82..023099dc2f 100644 --- a/packages/vue-vanilla/src/complex/Categorization.vue +++ b/packages/vue-vanilla/src/complex/Categorization.vue @@ -1,57 +1,66 @@