From 05b9e68f5dc3a110dceb2d14cb4f3284f253f830 Mon Sep 17 00:00:00 2001 From: Alban Mouton Date: Thu, 28 Nov 2024 17:04:08 +0100 Subject: [PATCH] feat: use locale from vuetify as default --- lib/package.json | 2 +- lib/src/composables/use-vjsf.js | 6 ++++-- lib/src/options.js | 4 +++- package-lock.json | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/package.json b/lib/package.json index 035cdaeb..5ba96f29 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,6 +1,6 @@ { "name": "@koumoul/vjsf", - "version": "3.3.4", + "version": "3.4.0", "description": "Generate forms for the vuetify UI library (vuejs) based on annotated JSON schemas.", "scripts": { "test": "vitest", diff --git a/lib/src/composables/use-vjsf.js b/lib/src/composables/use-vjsf.js index b9233a82..03ee0c35 100644 --- a/lib/src/composables/use-vjsf.js +++ b/lib/src/composables/use-vjsf.js @@ -1,4 +1,4 @@ -import { useDefaults } from 'vuetify' +import { useDefaults, useLocale } from 'vuetify' import { StatefulLayout, produceCompileOptions } from '@json-layout/core' import { inject, toRaw, shallowRef, computed, ref, watch, useSlots, getCurrentInstance } from 'vue' import { useElementSize } from '@vueuse/core' @@ -104,7 +104,9 @@ export const useVjsf = (schema, modelValue, options, nodeComponents, emit, compi } } - const fullOptions = computed(() => getFullOptions(options.value, form, width.value, defaults?.global, slots, { ...nodeComponents }, onDataUpdate, onStatefulLayoutUpdate, onAutofocus)) + const locale = useLocale() + + const fullOptions = computed(() => getFullOptions(options.value, form, width.value, locale.current.value, defaults?.global, slots, { ...nodeComponents }, onDataUpdate, onStatefulLayoutUpdate, onAutofocus)) // do not use a simple computed here as we want to prevent recompiling the layout when the options are the same /** @type {import('vue').Ref} */ diff --git a/lib/src/options.js b/lib/src/options.js index f5f24d7f..c8c1a297 100644 --- a/lib/src/options.js +++ b/lib/src/options.js @@ -28,6 +28,7 @@ export const defaultOptions = { * @param {Partial | null} options * @param {any} form * @param {number} width + * @param {string} locale * @param {Record | undefined} globalDefaults * @param {import("vue").Slots} slots * @param {Record} defaultNodeComponents @@ -36,7 +37,7 @@ export const defaultOptions = { * @param {(key: string) => void} onAutofocus * @returns */ -export const getFullOptions = (options, form, width, globalDefaults, slots, defaultNodeComponents, onData, onUpdate, onAutofocus) => { +export const getFullOptions = (options, form, width, locale, globalDefaults, slots, defaultNodeComponents, onData, onUpdate, onAutofocus) => { const components = { ...options?.components } const nodeComponents = { ...defaultNodeComponents, ...options?.nodeComponents } if (options?.plugins) { @@ -52,6 +53,7 @@ export const getFullOptions = (options, form, width, globalDefaults, slots, defa ...defaultOptions, readOnly: !!(form && (form.isDisabled.value || form.isReadonly.value)), density: /** @type {import("./types.js").VjsfOptions['density']} */(globalDefaults?.density), + locale, ...options, onData, onUpdate, diff --git a/package-lock.json b/package-lock.json index 154816e9..8637220e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3478,7 +3478,7 @@ }, "lib": { "name": "@koumoul/vjsf", - "version": "3.3.4", + "version": "3.4.0", "license": "MIT", "dependencies": { "@json-layout/core": "~1.1.0",