@adminforth/i18n 1.3.3 → 1.3.4

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.
package/build.log CHANGED
@@ -11,10 +11,11 @@ custom/ListCell.vue
11
11
  custom/SingleMultiInput.vue
12
12
  custom/datepickerLocales.ts
13
13
  custom/dayjsLocales.ts
14
+ custom/eventBus.ts
14
15
  custom/langCommon.ts
15
16
  custom/package-lock.json
16
17
  custom/package.json
17
18
  custom/tsconfig.json
18
19
 
19
- sent 31,064 bytes received 229 bytes 62,586.00 bytes/sec
20
- total size is 30,197 speedup is 0.96
20
+ sent 32,174 bytes received 248 bytes 64,844.00 bytes/sec
21
+ total size is 31,254 speedup is 0.96
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="relative group flex items-center">
2
+ <div class="relative group flex items-center" ref="listCell">
3
3
  <!-- Normal value display -->
4
4
  <div v-if="column.editReadonly" class="flex items-center" :class="limitedText?.length > 50 ? 'min-w-48 max-w-full' : 'min-w-32'">
5
5
  {{ limitedText? limitedText : '-' }}
@@ -36,7 +36,7 @@
36
36
  </div>
37
37
 
38
38
  <!-- Edit mode -->
39
- <div v-else class="flex flex-col gap-2" @click.stop>
39
+ <div v-else class="flex flex-col gap-2 trans-editor" @click.stop>
40
40
  <div class="flex items-center max-w-full gap-2"
41
41
  :class="limitedText?.length > 50 ? 'min-w-72' : 'min-w-64'"
42
42
  ref="inputHolder"
@@ -86,7 +86,7 @@
86
86
  </template>
87
87
 
88
88
  <script setup lang="ts">
89
- import { ref, Ref, computed, nextTick } from 'vue';
89
+ import { ref, Ref, computed, nextTick, onMounted } from 'vue';
90
90
  import { IconPenSolid, IconCheckOutline, IconXOutline, IconQuestionCircleSolid } from '@iconify-prerendered/vue-flowbite';
91
91
  import { callAdminForthApi } from '@/utils';
92
92
  import { showErrorTost, showSuccesTost } from '@/composables/useFrontendApi';
@@ -94,7 +94,9 @@ import ColumnValueInputWrapper from '@/components/ColumnValueInputWrapper.vue';
94
94
  import { useI18n } from 'vue-i18n';
95
95
  import Tooltip from '@/afcl/Tooltip.vue';
96
96
  import Checkbox from '@/afcl/Checkbox.vue';
97
+ import { eventBus } from './eventBus'
97
98
 
99
+ const listCell = ref(null);
98
100
  const { t } = useI18n();
99
101
  const props = defineProps(['column', 'record', 'resource', 'adminUser', 'meta']);
100
102
  const isEditing = ref(false);
@@ -109,11 +111,23 @@ const unmasked = ref({});
109
111
  const inputHolder = ref(null);
110
112
 
111
113
  const limitedText = computed(() => {
114
+ if (props.column.name == props.meta?.enFieldName && anyEditorOpen.value) {
115
+ return props.record[props.column.name]; // keep english text
116
+ }
112
117
  const text = props.record[props.column.name];
113
118
  return text?.length > 50 ? text.slice(0, 50) + '...' : text;
114
119
  });
115
120
 
116
121
  const reviewed: Ref<boolean> = ref(false);
122
+ const anyEditorOpen = ref(false); // if any editor for lang page is open
123
+
124
+ onMounted(() => {
125
+ eventBus.on(`editing-changed-${props.record.id}`, async () => {
126
+ console.log('editing-changed', props.record.id);
127
+ await nextTick();
128
+ anyEditorOpen.value = listCell.value?.closest('tr')?.querySelector('.trans-editor') !== null;
129
+ });
130
+ });
117
131
 
118
132
 
119
133
  const originalReviewed = ref(false);
@@ -134,11 +148,14 @@ async function startEdit() {
134
148
  if (inputHolder.value) {
135
149
  inputHolder.value.querySelector('input, textarea, select')?.focus();
136
150
  }
151
+ eventBus.emit(`editing-changed-${props.record.id}`, null);
137
152
  }
138
153
 
139
154
  function cancelEdit() {
140
155
  isEditing.value = false;
141
156
  editValue.value = null;
157
+ eventBus.emit(`editing-changed-${props.record.id}`, null);
158
+
142
159
  }
143
160
 
144
161
  function setCurrentValue(field, value, arrayIndex = undefined) {
@@ -170,6 +187,8 @@ function setCurrentValue(field, value, arrayIndex = undefined) {
170
187
  currentValues.value[field] = value;
171
188
  editValue.value = value;
172
189
  }
190
+ eventBus.emit(`editing-changed-${props.record.id}`, null);
191
+
173
192
  }
174
193
 
175
194
  async function saveEdit() {
@@ -0,0 +1,12 @@
1
+ const handlers = {}
2
+ export const eventBus = {
3
+ on(event, fn) {
4
+ (handlers[event] ||= []).push(fn)
5
+ },
6
+ off(event, fn) {
7
+ handlers[event] = (handlers[event] || []).filter(f => f !== fn)
8
+ },
9
+ emit(event, data) {
10
+ (handlers[event] || []).forEach(fn => fn(data))
11
+ }
12
+ }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="relative group flex items-center">
2
+ <div class="relative group flex items-center" ref="listCell">
3
3
  <!-- Normal value display -->
4
4
  <div v-if="column.editReadonly" class="flex items-center" :class="limitedText?.length > 50 ? 'min-w-48 max-w-full' : 'min-w-32'">
5
5
  {{ limitedText? limitedText : '-' }}
@@ -36,7 +36,7 @@
36
36
  </div>
37
37
 
38
38
  <!-- Edit mode -->
39
- <div v-else class="flex flex-col gap-2" @click.stop>
39
+ <div v-else class="flex flex-col gap-2 trans-editor" @click.stop>
40
40
  <div class="flex items-center max-w-full gap-2"
41
41
  :class="limitedText?.length > 50 ? 'min-w-72' : 'min-w-64'"
42
42
  ref="inputHolder"
@@ -86,7 +86,7 @@
86
86
  </template>
87
87
 
88
88
  <script setup lang="ts">
89
- import { ref, Ref, computed, nextTick } from 'vue';
89
+ import { ref, Ref, computed, nextTick, onMounted } from 'vue';
90
90
  import { IconPenSolid, IconCheckOutline, IconXOutline, IconQuestionCircleSolid } from '@iconify-prerendered/vue-flowbite';
91
91
  import { callAdminForthApi } from '@/utils';
92
92
  import { showErrorTost, showSuccesTost } from '@/composables/useFrontendApi';
@@ -94,7 +94,9 @@ import ColumnValueInputWrapper from '@/components/ColumnValueInputWrapper.vue';
94
94
  import { useI18n } from 'vue-i18n';
95
95
  import Tooltip from '@/afcl/Tooltip.vue';
96
96
  import Checkbox from '@/afcl/Checkbox.vue';
97
+ import { eventBus } from './eventBus'
97
98
 
99
+ const listCell = ref(null);
98
100
  const { t } = useI18n();
99
101
  const props = defineProps(['column', 'record', 'resource', 'adminUser', 'meta']);
100
102
  const isEditing = ref(false);
@@ -109,11 +111,23 @@ const unmasked = ref({});
109
111
  const inputHolder = ref(null);
110
112
 
111
113
  const limitedText = computed(() => {
114
+ if (props.column.name == props.meta?.enFieldName && anyEditorOpen.value) {
115
+ return props.record[props.column.name]; // keep english text
116
+ }
112
117
  const text = props.record[props.column.name];
113
118
  return text?.length > 50 ? text.slice(0, 50) + '...' : text;
114
119
  });
115
120
 
116
121
  const reviewed: Ref<boolean> = ref(false);
122
+ const anyEditorOpen = ref(false); // if any editor for lang page is open
123
+
124
+ onMounted(() => {
125
+ eventBus.on(`editing-changed-${props.record.id}`, async () => {
126
+ console.log('editing-changed', props.record.id);
127
+ await nextTick();
128
+ anyEditorOpen.value = listCell.value?.closest('tr')?.querySelector('.trans-editor') !== null;
129
+ });
130
+ });
117
131
 
118
132
 
119
133
  const originalReviewed = ref(false);
@@ -134,11 +148,14 @@ async function startEdit() {
134
148
  if (inputHolder.value) {
135
149
  inputHolder.value.querySelector('input, textarea, select')?.focus();
136
150
  }
151
+ eventBus.emit(`editing-changed-${props.record.id}`, null);
137
152
  }
138
153
 
139
154
  function cancelEdit() {
140
155
  isEditing.value = false;
141
156
  editValue.value = null;
157
+ eventBus.emit(`editing-changed-${props.record.id}`, null);
158
+
142
159
  }
143
160
 
144
161
  function setCurrentValue(field, value, arrayIndex = undefined) {
@@ -170,6 +187,8 @@ function setCurrentValue(field, value, arrayIndex = undefined) {
170
187
  currentValues.value[field] = value;
171
188
  editValue.value = value;
172
189
  }
190
+ eventBus.emit(`editing-changed-${props.record.id}`, null);
191
+
173
192
  }
174
193
 
175
194
  async function saveEdit() {
@@ -0,0 +1,12 @@
1
+ const handlers = {}
2
+ export const eventBus = {
3
+ on(event, fn) {
4
+ (handlers[event] ||= []).push(fn)
5
+ },
6
+ off(event, fn) {
7
+ handlers[event] = (handlers[event] || []).filter(f => f !== fn)
8
+ },
9
+ emit(event, data) {
10
+ (handlers[event] || []).forEach(fn => fn(data))
11
+ }
12
+ }
package/dist/index.js CHANGED
@@ -166,6 +166,7 @@ export default class I18nPlugin extends AdminForthPlugin {
166
166
  pluginInstanceId: this.pluginInstanceId,
167
167
  lang,
168
168
  reviewedCheckboxesFieldName: this.options.reviewedCheckboxesFieldName,
169
+ enFieldName: this.enFieldName,
169
170
  },
170
171
  };
171
172
  }
@@ -194,6 +195,9 @@ export default class I18nPlugin extends AdminForthPlugin {
194
195
  };
195
196
  enColumn.components.list = {
196
197
  file: this.componentPath('ListCell.vue'),
198
+ meta: {
199
+ enFieldName: this.enFieldName,
200
+ }
197
201
  };
198
202
  enColumn.editReadonly = true;
199
203
  // if sourceFieldName defined, check it exists
package/index.ts CHANGED
@@ -188,6 +188,7 @@ export default class I18nPlugin extends AdminForthPlugin {
188
188
  pluginInstanceId: this.pluginInstanceId,
189
189
  lang,
190
190
  reviewedCheckboxesFieldName: this.options.reviewedCheckboxesFieldName,
191
+ enFieldName: this.enFieldName,
191
192
  },
192
193
  };
193
194
  }
@@ -220,6 +221,9 @@ export default class I18nPlugin extends AdminForthPlugin {
220
221
  };
221
222
  enColumn.components.list = {
222
223
  file: this.componentPath('ListCell.vue'),
224
+ meta: {
225
+ enFieldName: this.enFieldName,
226
+ }
223
227
  };
224
228
  enColumn.editReadonly = true;
225
229
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",