Skip to content

Commit e43a0dd

Browse files
committed
fix: expand original string with edited string
1 parent 6ab090b commit e43a0dd

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

custom/ListCell.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="relative group flex items-center">
2+
<div class="relative group flex items-center" ref="listCell">
33
<!-- Normal value display -->
44
<div v-if="column.editReadonly" class="flex items-center" :class="limitedText?.length > 50 ? 'min-w-48 max-w-full' : 'min-w-32'">
55
{{ limitedText? limitedText : '-' }}
@@ -36,7 +36,7 @@
3636
</div>
3737

3838
<!-- 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>
4040
<div class="flex items-center max-w-full gap-2"
4141
:class="limitedText?.length > 50 ? 'min-w-72' : 'min-w-64'"
4242
ref="inputHolder"
@@ -86,15 +86,17 @@
8686
</template>
8787

8888
<script setup lang="ts">
89-
import { ref, Ref, computed, nextTick } from 'vue';
89+
import { ref, Ref, computed, nextTick, onMounted } from 'vue';
9090
import { IconPenSolid, IconCheckOutline, IconXOutline, IconQuestionCircleSolid } from '@iconify-prerendered/vue-flowbite';
9191
import { callAdminForthApi } from '@/utils';
9292
import { showErrorTost, showSuccesTost } from '@/composables/useFrontendApi';
9393
import ColumnValueInputWrapper from '@/components/ColumnValueInputWrapper.vue';
9494
import { useI18n } from 'vue-i18n';
9595
import Tooltip from '@/afcl/Tooltip.vue';
9696
import Checkbox from '@/afcl/Checkbox.vue';
97+
import { eventBus } from './eventBus'
9798
99+
const listCell = ref(null);
98100
const { t } = useI18n();
99101
const props = defineProps(['column', 'record', 'resource', 'adminUser', 'meta']);
100102
const isEditing = ref(false);
@@ -109,11 +111,23 @@ const unmasked = ref({});
109111
const inputHolder = ref(null);
110112
111113
const limitedText = computed(() => {
114+
if (props.column.name == props.meta?.enFieldName && anyEditorOpen.value) {
115+
return props.record[props.column.name]; // keep english text
116+
}
112117
const text = props.record[props.column.name];
113118
return text?.length > 50 ? text.slice(0, 50) + '...' : text;
114119
});
115120
116121
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+
});
117131
118132
119133
const originalReviewed = ref(false);
@@ -134,11 +148,14 @@ async function startEdit() {
134148
if (inputHolder.value) {
135149
inputHolder.value.querySelector('input, textarea, select')?.focus();
136150
}
151+
eventBus.emit(`editing-changed-${props.record.id}`, null);
137152
}
138153
139154
function cancelEdit() {
140155
isEditing.value = false;
141156
editValue.value = null;
157+
eventBus.emit(`editing-changed-${props.record.id}`, null);
158+
142159
}
143160
144161
function setCurrentValue(field, value, arrayIndex = undefined) {
@@ -170,6 +187,8 @@ function setCurrentValue(field, value, arrayIndex = undefined) {
170187
currentValues.value[field] = value;
171188
editValue.value = value;
172189
}
190+
eventBus.emit(`editing-changed-${props.record.id}`, null);
191+
173192
}
174193
175194
async function saveEdit() {

custom/eventBus.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export default class I18nPlugin extends AdminForthPlugin {
188188
pluginInstanceId: this.pluginInstanceId,
189189
lang,
190190
reviewedCheckboxesFieldName: this.options.reviewedCheckboxesFieldName,
191+
enFieldName: this.enFieldName,
191192
},
192193
};
193194
}
@@ -220,6 +221,9 @@ export default class I18nPlugin extends AdminForthPlugin {
220221
};
221222
enColumn.components.list = {
222223
file: this.componentPath('ListCell.vue'),
224+
meta: {
225+
enFieldName: this.enFieldName,
226+
}
223227
};
224228
enColumn.editReadonly = true;
225229

0 commit comments

Comments
 (0)