Skip to content

Commit

Permalink
adapt vue-vuetify
Browse files Browse the repository at this point in the history
  • Loading branch information
sdirix committed Sep 13, 2024
1 parent 6d87d35 commit 10ed948
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
7 changes: 6 additions & 1 deletion packages/vue-vuetify/src/complex/ArrayControlRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,19 @@
<script lang="ts">
import {
Resolve,
arrayDefaultTranslations,
composePaths,
createDefaultValue,
defaultJsonFormsI18nState,
getArrayTranslations,
isObjectArrayControl,
isPrimitiveArrayControl,
or,
rankWith,
type ArrayTranslations,
type ControlElement,
type JsonFormsRendererRegistryEntry,
type JsonFormsSubStates,
type JsonSchema,
} from '@jsonforms/core';
import {
Expand All @@ -196,7 +201,7 @@ import {
type RendererProps,
} from '@jsonforms/vue';
import startCase from 'lodash/startCase';
import { defineComponent } from 'vue';
import { defineComponent, inject } from 'vue';
import {
VBtn,
VCard,
Expand Down
8 changes: 6 additions & 2 deletions packages/vue-vuetify/src/complex/OneOfRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ import {
VSpacer,
} from 'vuetify/components';
import { DisabledIconFocus } from '../controls/directives';
import { useTranslator, useVuetifyControl } from '../util';
import {
useCombinatorTranslations,
useTranslator,
useVuetifyControl,
} from '../util';
import { CombinatorProperties } from './components';
const controlRenderer = defineComponent({
Expand Down Expand Up @@ -128,7 +132,7 @@ const controlRenderer = defineComponent({
const t = useTranslator();
return {
...useVuetifyControl(input),
...useCombinatorTranslations(useVuetifyControl(input)),
selectedIndex,
selectIndex,
dialog,
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-vuetify/src/complex/OneOfTabRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {
VTabs,
VWindowItem,
} from 'vuetify/components';
import { useVuetifyControl } from '../util';
import { useCombinatorTranslations, useVuetifyControl } from '../util';
import { CombinatorProperties } from './components';
const controlRenderer = defineComponent({
Expand Down Expand Up @@ -123,7 +123,7 @@ const controlRenderer = defineComponent({
const dialog = ref(false);
return {
...useVuetifyControl(input),
...useCombinatorTranslations(useVuetifyControl(input)),
selectedIndex,
tabIndex,
dialog,
Expand Down
52 changes: 52 additions & 0 deletions packages/vue-vuetify/src/util/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import type { IconAliases } from '@/icons/icons';
import { aliases as mdiIcons } from '@/icons/mdi';
import {
Resolve,
arrayDefaultTranslations,
combinatorDefaultTranslations,
composePaths,
computeLabel,
defaultJsonFormsI18nState,
getArrayTranslations,
getCombinatorTranslations,
getFirstPrimitiveProp,
isDescriptionHidden,
type ControlElement,
Expand Down Expand Up @@ -223,6 +228,41 @@ export const useVuetifyControl = <
};
};

/**
* Adds styles, isFocused, appliedOptions and onChange
*/
export const useCombinatorTranslations = <
T extends {
i18nKeyPrefix: string;
label: string;
},
I extends {
control: ComputedRef<T>;
},
>(
input: I,
) => {
const jsonforms = inject<JsonFormsSubStates>('jsonforms');
const translations = getCombinatorTranslations(
jsonforms?.i18n?.translate ?? defaultJsonFormsI18nState.translate,
combinatorDefaultTranslations,
input.control.value.i18nKeyPrefix,
input.control.value.label,
);

const overwrittenControl = computed(() => {
return {
...input.control.value,
translations,
};
});

return {
...input,
control: overwrittenControl,
};
};

export const useJsonForms = () => {
const jsonforms = inject<JsonFormsSubStates>('jsonforms');

Expand Down Expand Up @@ -289,6 +329,7 @@ export const useVuetifyArrayControl = <
schema: JsonSchema;
data: any;
childErrors: ErrorObject[];
i18nKeyPrefix: string;
},
I extends {
control: ComputedRef<T>;
Expand Down Expand Up @@ -338,12 +379,23 @@ export const useVuetifyArrayControl = <
: input.control.value.childErrors;
return filtered;
});

const jsonforms = inject<JsonFormsSubStates>('jsonforms');
const translations = getArrayTranslations(
jsonforms?.i18n?.translate ?? defaultJsonFormsI18nState.translate,
arrayDefaultTranslations,
input.control.value.i18nKeyPrefix,
input.control.value.label,
);

const overwrittenControl = computed(() => {
return {
...input.control.value,
childErrors: filteredChildErrors.value,
translations,
};
});

return {
...input,
control: overwrittenControl,
Expand Down

0 comments on commit 10ed948

Please sign in to comment.