@adminforth/i18n 1.1.3-next.3 → 1.1.3-next.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
@@ -7,10 +7,12 @@ custom/
7
7
  custom/LanguageEveryPageLoader.vue
8
8
  custom/LanguageInUserMenu.vue
9
9
  custom/LanguageUnderLogin.vue
10
+ custom/ListCell.vue
11
+ custom/SingleMultiInput.vue
10
12
  custom/langCommon.ts
11
13
  custom/package-lock.json
12
14
  custom/package.json
13
15
  custom/tsconfig.json
14
16
 
15
- sent 9,498 bytes received 153 bytes 19,302.00 bytes/sec
16
- total size is 8,926 speedup is 0.92
17
+ sent 12,536 bytes received 191 bytes 25,454.00 bytes/sec
18
+ total size is 11,814 speedup is 0.93
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <div class="text-sm text-gray-900 dark:text-white min-w-32">
3
+ {{ limitedText }}
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed } from 'vue';
9
+ import { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common';
10
+
11
+
12
+ const limitedText = computed(() => {
13
+ const text = props.record[props.column.name];
14
+ return text?.length > 50 ? text.slice(0, 50) + '...' : text;
15
+ });
16
+
17
+ const props = defineProps<{
18
+ column: AdminForthResourceColumnCommon;
19
+ record: any;
20
+ meta: any;
21
+ resource: AdminForthResourceCommon;
22
+ adminUser: AdminUser;
23
+ }>();
24
+
25
+ </script>
@@ -0,0 +1,76 @@
1
+ <template>
2
+ <Input
3
+ ref="input"
4
+ v-if="shortValue"
5
+ class="w-full"
6
+ :modelValue="props.record[props.column.name]"
7
+ :disabled="props.column.editReadonly"
8
+ @update:modelValue="($event) => emit('update:value', $event)" />
9
+ <textarea
10
+ v-else
11
+ ref="textarea"
12
+ :disabled="props.column.editReadonly"
13
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5
14
+ dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
15
+ :value="props.record[props.column.name]"
16
+ @input="($event) => { autoResizeTextArea(); emit('update:value', $event.target.value) }" />
17
+
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import { Input } from "@/afcl";
22
+ import type {
23
+ AdminForthResourceColumnCommon,
24
+ AdminForthResourceCommon,
25
+ AdminUser,
26
+ } from "@/types/Common";
27
+ import { computed, defineProps, defineEmits, type Ref, watch, nextTick, ref, onMounted } from "vue";
28
+
29
+ const shortValue: Ref<boolean> = computed(() => (props.record[props.column.name]?.length || 0) < 50);
30
+
31
+ const props = defineProps<{
32
+ column: AdminForthResourceColumnCommon;
33
+ record: any;
34
+ meta: any;
35
+ resource: AdminForthResourceCommon;
36
+ adminUser: AdminUser;
37
+ }>();
38
+
39
+ const emit = defineEmits(["update:value"]);
40
+
41
+ const input: Ref<HTMLInputElement | HTMLTextAreaElement | null> = ref(null);
42
+ const textarea: Ref<HTMLInputElement | HTMLTextAreaElement | null> = ref(null);
43
+
44
+ // Auto resize function
45
+ const autoResizeTextArea = () => {
46
+ // Use nextTick to ensure the DOM update is done before measuring
47
+ nextTick(() => {
48
+ if (!textarea.value) return
49
+
50
+ // Reset the height to shrink if content is removed
51
+ textarea.value.style.height = 'auto'
52
+ // Set it to the scrollHeight to make it grow
53
+ textarea.value.style.height = textarea.value.scrollHeight + 3 + 'px'
54
+ })
55
+ }
56
+
57
+ watch(() => shortValue.value, async () => {
58
+ await nextTick();
59
+ if (shortValue.value) {
60
+ input.value?.focus();
61
+ } else {
62
+ textarea.value?.focus();
63
+ await nextTick();
64
+ autoResizeTextArea();
65
+ }
66
+ });
67
+
68
+
69
+ onMounted(async () => {
70
+ if (!shortValue.value) {
71
+ await nextTick();
72
+ autoResizeTextArea();
73
+ }
74
+ });
75
+ </script>
76
+
@@ -4,11 +4,11 @@
4
4
  "paths": {
5
5
  "@/*": [
6
6
  // "node_modules/adminforth/dist/spa/src/*"
7
- "../../../spa/src/*"
7
+ "../../../adminforth/spa/src/*"
8
8
  ],
9
9
  "*": [
10
10
  // "node_modules/adminforth/dist/spa/node_modules/*"
11
- "../../../spa/node_modules/*"
11
+ "../../../adminforth/spa/node_modules/*"
12
12
  ],
13
13
  "@@/*": [
14
14
  // "node_modules/adminforth/dist/spa/src/*"
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <div class="text-sm text-gray-900 dark:text-white min-w-32">
3
+ {{ limitedText }}
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed } from 'vue';
9
+ import { AdminForthResourceColumnCommon, AdminForthResourceCommon, AdminUser } from '@/types/Common';
10
+
11
+
12
+ const limitedText = computed(() => {
13
+ const text = props.record[props.column.name];
14
+ return text?.length > 50 ? text.slice(0, 50) + '...' : text;
15
+ });
16
+
17
+ const props = defineProps<{
18
+ column: AdminForthResourceColumnCommon;
19
+ record: any;
20
+ meta: any;
21
+ resource: AdminForthResourceCommon;
22
+ adminUser: AdminUser;
23
+ }>();
24
+
25
+ </script>
@@ -0,0 +1,76 @@
1
+ <template>
2
+ <Input
3
+ ref="input"
4
+ v-if="shortValue"
5
+ class="w-full"
6
+ :modelValue="props.record[props.column.name]"
7
+ :disabled="props.column.editReadonly"
8
+ @update:modelValue="($event) => emit('update:value', $event)" />
9
+ <textarea
10
+ v-else
11
+ ref="textarea"
12
+ :disabled="props.column.editReadonly"
13
+ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5
14
+ dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
15
+ :value="props.record[props.column.name]"
16
+ @input="($event) => { autoResizeTextArea(); emit('update:value', $event.target.value) }" />
17
+
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import { Input } from "@/afcl";
22
+ import type {
23
+ AdminForthResourceColumnCommon,
24
+ AdminForthResourceCommon,
25
+ AdminUser,
26
+ } from "@/types/Common";
27
+ import { computed, defineProps, defineEmits, type Ref, watch, nextTick, ref, onMounted } from "vue";
28
+
29
+ const shortValue: Ref<boolean> = computed(() => (props.record[props.column.name]?.length || 0) < 50);
30
+
31
+ const props = defineProps<{
32
+ column: AdminForthResourceColumnCommon;
33
+ record: any;
34
+ meta: any;
35
+ resource: AdminForthResourceCommon;
36
+ adminUser: AdminUser;
37
+ }>();
38
+
39
+ const emit = defineEmits(["update:value"]);
40
+
41
+ const input: Ref<HTMLInputElement | HTMLTextAreaElement | null> = ref(null);
42
+ const textarea: Ref<HTMLInputElement | HTMLTextAreaElement | null> = ref(null);
43
+
44
+ // Auto resize function
45
+ const autoResizeTextArea = () => {
46
+ // Use nextTick to ensure the DOM update is done before measuring
47
+ nextTick(() => {
48
+ if (!textarea.value) return
49
+
50
+ // Reset the height to shrink if content is removed
51
+ textarea.value.style.height = 'auto'
52
+ // Set it to the scrollHeight to make it grow
53
+ textarea.value.style.height = textarea.value.scrollHeight + 3 + 'px'
54
+ })
55
+ }
56
+
57
+ watch(() => shortValue.value, async () => {
58
+ await nextTick();
59
+ if (shortValue.value) {
60
+ input.value?.focus();
61
+ } else {
62
+ textarea.value?.focus();
63
+ await nextTick();
64
+ autoResizeTextArea();
65
+ }
66
+ });
67
+
68
+
69
+ onMounted(async () => {
70
+ if (!shortValue.value) {
71
+ await nextTick();
72
+ autoResizeTextArea();
73
+ }
74
+ });
75
+ </script>
76
+
@@ -4,11 +4,11 @@
4
4
  "paths": {
5
5
  "@/*": [
6
6
  // "node_modules/adminforth/dist/spa/src/*"
7
- "../../../spa/src/*"
7
+ "../../../adminforth/spa/src/*"
8
8
  ],
9
9
  "*": [
10
10
  // "node_modules/adminforth/dist/spa/node_modules/*"
11
- "../../../spa/node_modules/*"
11
+ "../../../adminforth/spa/node_modules/*"
12
12
  ],
13
13
  "@@/*": [
14
14
  // "node_modules/adminforth/dist/spa/src/*"
package/dist/index.js CHANGED
@@ -150,6 +150,18 @@ export default class I18nPlugin extends AdminForthPlugin {
150
150
  throw new Error(`Field ${this.trFieldNames[lang]} not found for storing translation for language ${lang}
151
151
  in resource ${resourceConfig.resourceId}, consider adding it to columns or change trFieldNames option to remap it to existing column`);
152
152
  }
153
+ column.components = column.components || {};
154
+ // set edit and create custom component - SingleMultiInput.vue
155
+ column.components.edit = {
156
+ file: this.componentPath('SingleMultiInput.vue'),
157
+ };
158
+ column.components.create = {
159
+ file: this.componentPath('SingleMultiInput.vue'),
160
+ };
161
+ // set ListCell for list
162
+ column.components.list = {
163
+ file: this.componentPath('ListCell.vue'),
164
+ };
153
165
  }
154
166
  this.enFieldName = this.trFieldNames['en'] || 'en_string';
155
167
  this.fullCompleatedFieldValue = this.options.supportedLanguages.reduce((acc, lang) => {
@@ -167,6 +179,16 @@ export default class I18nPlugin extends AdminForthPlugin {
167
179
  if (!enColumn) {
168
180
  throw new Error(`Field ${this.enFieldName} not found column to store english original string in resource ${resourceConfig.resourceId}`);
169
181
  }
182
+ enColumn.components = enColumn.components || {};
183
+ enColumn.components.edit = {
184
+ file: this.componentPath('SingleMultiInput.vue'),
185
+ };
186
+ enColumn.components.create = {
187
+ file: this.componentPath('SingleMultiInput.vue'),
188
+ };
189
+ enColumn.components.list = {
190
+ file: this.componentPath('ListCell.vue'),
191
+ };
170
192
  enColumn.editReadonly = true;
171
193
  // if sourceFieldName defined, check it exists
172
194
  if (this.options.sourceFieldName) {
package/index.ts CHANGED
@@ -165,6 +165,21 @@ export default class I18nPlugin extends AdminForthPlugin {
165
165
  throw new Error(`Field ${this.trFieldNames[lang]} not found for storing translation for language ${lang}
166
166
  in resource ${resourceConfig.resourceId}, consider adding it to columns or change trFieldNames option to remap it to existing column`);
167
167
  }
168
+
169
+ column.components = column.components || {};
170
+
171
+ // set edit and create custom component - SingleMultiInput.vue
172
+ column.components.edit = {
173
+ file: this.componentPath('SingleMultiInput.vue'),
174
+ };
175
+ column.components.create = {
176
+ file: this.componentPath('SingleMultiInput.vue'),
177
+ };
178
+
179
+ // set ListCell for list
180
+ column.components.list = {
181
+ file: this.componentPath('ListCell.vue'),
182
+ };
168
183
  }
169
184
 
170
185
  this.enFieldName = this.trFieldNames['en'] || 'en_string';
@@ -186,6 +201,16 @@ export default class I18nPlugin extends AdminForthPlugin {
186
201
  throw new Error(`Field ${this.enFieldName} not found column to store english original string in resource ${resourceConfig.resourceId}`);
187
202
  }
188
203
 
204
+ enColumn.components = enColumn.components || {};
205
+ enColumn.components.edit = {
206
+ file: this.componentPath('SingleMultiInput.vue'),
207
+ };
208
+ enColumn.components.create = {
209
+ file: this.componentPath('SingleMultiInput.vue'),
210
+ };
211
+ enColumn.components.list = {
212
+ file: this.componentPath('ListCell.vue'),
213
+ };
189
214
  enColumn.editReadonly = true;
190
215
 
191
216
  // if sourceFieldName defined, check it exists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "1.1.3-next.3",
3
+ "version": "1.1.3-next.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",