@dative-gpi/foundation-shared-components 1.0.131-fix-trtf → 1.0.131-fix-trtf2

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.
@@ -77,7 +77,7 @@
77
77
  </template>
78
78
 
79
79
  <script lang="ts">
80
- import { defineComponent, type PropType, ref } from 'vue';
80
+ import { defineComponent, type PropType, ref, computed, watch } from 'vue';
81
81
 
82
82
  import { useAppLanguages } from "@dative-gpi/foundation-shared-services/composables";
83
83
 
@@ -134,26 +134,21 @@ export default defineComponent({
134
134
  setup(props, { emit }) {
135
135
  const { languages } = useAppLanguages();
136
136
 
137
- const innerTranslations = ref(props.translations.map((tranlation) => {
138
- if(typeof tranlation[props.property] === 'string'){
139
- return tranlation;
140
- }
141
- return {
142
- ...tranlation,
143
- [props.property]: JSON.stringify(tranlation[props.property])
144
- }
145
- }));
137
+ const innerTranslations = ref<{
138
+ languageCode: string;
139
+ [key: string]: string | object | null;
140
+ }[]>([]);
146
141
 
147
- const getTranslation = (languageCode: string): string | object => {
148
- if (!innerTranslations.value) {
149
- return emptyLexicalState;
150
- }
151
- const translation = innerTranslations.value.find((t) => t.languageCode === languageCode);
152
- if (!translation || !translation[props.property]) {
153
- return emptyLexicalState;
142
+ const getTranslation = computed(() => {
143
+ const translationsMap = new Map(
144
+ innerTranslations.value.map((t) => [t.languageCode, t[props.property]])
145
+ );
146
+
147
+ return (languageCode: string) => {
148
+ return translationsMap.get(languageCode) || emptyLexicalState;
154
149
  }
155
- return translation[props.property]!;
156
- };
150
+
151
+ });
157
152
 
158
153
  const setTranslation = (languageCode: string, value: string): void => {
159
154
  if (!innerTranslations.value) {
@@ -186,6 +181,18 @@ export default defineComponent({
186
181
  emit('update:translationsExpanded', false);
187
182
  };
188
183
 
184
+ watch(() => props.translations, (newTranslations) => {
185
+ innerTranslations.value = newTranslations.map((tranlation) => {
186
+ if(typeof tranlation[props.property] === 'string'){
187
+ return tranlation;
188
+ }
189
+ return {
190
+ ...tranlation,
191
+ [props.property]: JSON.stringify(tranlation[props.property])
192
+ }
193
+ });
194
+ }, { immediate: true });
195
+
189
196
  return {
190
197
  languages,
191
198
  onCancelTranslations,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-components",
3
3
  "sideEffects": false,
4
- "version": "1.0.131-fix-trtf",
4
+ "version": "1.0.131-fix-trtf2",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,8 +10,8 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-shared-domain": "1.0.131-fix-trtf",
14
- "@dative-gpi/foundation-shared-services": "1.0.131-fix-trtf"
13
+ "@dative-gpi/foundation-shared-domain": "1.0.131-fix-trtf2",
14
+ "@dative-gpi/foundation-shared-services": "1.0.131-fix-trtf2"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@dative-gpi/bones-ui": "^1.0.0",
@@ -35,5 +35,5 @@
35
35
  "sass": "1.71.1",
36
36
  "sass-loader": "13.3.2"
37
37
  },
38
- "gitHead": "fd7d416983cc298660ad9ae9f7c564d140e7c4f7"
38
+ "gitHead": "b2da671b3c2db4b23f6853554d61b3c348705c4e"
39
39
  }