aloha-vue 2.58.0 → 2.59.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloha-vue",
3
- "version": "2.58.0",
3
+ "version": "2.59.0",
4
4
  "description": "Aloha-vue is a JavaScript library that provides a wide range of accessible components and directives for Vue.js. Accessibility is of paramount importance to us, and we have designed all our components to meet accessibility compliance criteria. This library is a valuable tool for frontend developers and has already been used in three projects, including two large-scale ones",
5
5
  "keywords": [
6
6
  "accessibility compliance criteria",
@@ -64,6 +64,7 @@ export const AMultiselectOrderedPluginOptions = {
64
64
  ...AMultiselectOrderedPluginTexts,
65
65
  },
66
66
  translateData: false,
67
+ translateGroup: false,
67
68
  },
68
69
  };
69
70
 
@@ -38,10 +38,11 @@ export const ASelectPluginOptions = {
38
38
  slotName: undefined,
39
39
  sortOrder: undefined,
40
40
  sortOrderGroup: undefined,
41
- textDeselectAll: "_A_SELECT_DESELECT_ALL_",
42
- textSelectAll: "_A_SELECT_SELECT_ALL_",
43
- translateData: false,
44
- type: "select",
41
+ textDeselectAll: "_A_SELECT_DESELECT_ALL_",
42
+ textSelectAll: "_A_SELECT_SELECT_ALL_",
43
+ translateData: false,
44
+ translateGroup: false,
45
+ type: "select",
45
46
  },
46
47
  };
47
48
 
@@ -343,11 +343,16 @@ export default {
343
343
  search: "_A_CHECKBOX_SEARCH_",
344
344
  }),
345
345
  },
346
- translateData: {
347
- type: Boolean,
348
- required: false,
349
- default: undefined,
350
- },
346
+ translateData: {
347
+ type: Boolean,
348
+ required: false,
349
+ default: undefined,
350
+ },
351
+ translateGroup: {
352
+ type: Boolean,
353
+ required: false,
354
+ default: false,
355
+ },
351
356
  url: {
352
357
  type: String,
353
358
  required: false,
@@ -438,11 +438,16 @@ export default {
438
438
  required: false,
439
439
  default: () => AMultiselectOrderedPluginOptions.propsDefault.texts,
440
440
  },
441
- translateData: {
442
- type: Boolean,
443
- required: false,
444
- default: () => AMultiselectOrderedPluginOptions.propsDefault.translateData,
445
- },
441
+ translateData: {
442
+ type: Boolean,
443
+ required: false,
444
+ default: () => AMultiselectOrderedPluginOptions.propsDefault.translateData,
445
+ },
446
+ translateGroup: {
447
+ type: Boolean,
448
+ required: false,
449
+ default: () => AMultiselectOrderedPluginOptions.propsDefault.translateGroup,
450
+ },
446
451
  url: {
447
452
  type: String,
448
453
  required: false,
@@ -919,8 +924,9 @@ export default {
919
924
  searchTimeout: this.searchTimeout,
920
925
  searchTextInHtml: this.searchTextInHtml,
921
926
  selectMenuClass: this.selectMenuClass,
922
- slotName: this.slotName,
923
- type: "multiselect",
927
+ slotName: this.slotName,
928
+ translateGroup: this.translateGroup,
929
+ type: "multiselect",
924
930
  }, this.$slots),
925
931
  ]),
926
932
  ]),
@@ -354,11 +354,16 @@ export default {
354
354
  search: "_A_RADIO_SEARCH_",
355
355
  }),
356
356
  },
357
- translateData: {
358
- type: Boolean,
359
- required: false,
360
- default: undefined,
361
- },
357
+ translateData: {
358
+ type: Boolean,
359
+ required: false,
360
+ default: undefined,
361
+ },
362
+ translateGroup: {
363
+ type: Boolean,
364
+ required: false,
365
+ default: false,
366
+ },
362
367
  url: {
363
368
  type: String,
364
369
  required: false,
@@ -477,11 +477,16 @@ export default {
477
477
  required: false,
478
478
  default: () => ASelectPluginOptions.propsDefault.textSelectAll,
479
479
  },
480
- translateData: {
481
- type: Boolean,
482
- required: false,
483
- default: () => ASelectPluginOptions.propsDefault.translateData,
484
- },
480
+ translateData: {
481
+ type: Boolean,
482
+ required: false,
483
+ default: () => ASelectPluginOptions.propsDefault.translateData,
484
+ },
485
+ translateGroup: {
486
+ type: Boolean,
487
+ required: false,
488
+ default: () => ASelectPluginOptions.propsDefault.translateGroup,
489
+ },
485
490
  type: {
486
491
  type: String,
487
492
  required: false,
@@ -1064,9 +1069,10 @@ export default {
1064
1069
  keyGroupLabelCallback: this.keyGroupLabelCallback,
1065
1070
  labelNotFound: this.labelNotFound,
1066
1071
  showNotFound: this.showNotFound,
1067
- mode: this.mode,
1068
- slotName: this.slotName,
1069
- onChangeModelValue: this.onChangeModelValue,
1072
+ mode: this.mode,
1073
+ slotName: this.slotName,
1074
+ translateGroup: this.translateGroup,
1075
+ onChangeModelValue: this.onChangeModelValue,
1070
1076
  }, this.$slots);
1071
1077
  }),
1072
1078
  this.isModelLengthLimitExceeded && h(ASelectValueCloseable, {
@@ -1076,9 +1082,10 @@ export default {
1076
1082
  disabled: this.disabledLocal,
1077
1083
  keyGroup: this.keyGroup,
1078
1084
  keyGroupLabelCallback: this.keyGroupLabelCallback,
1079
- mode: this.mode,
1080
- hideDeleteButton: !this.exceededItemsDeletable,
1081
- onChangeModelValue: this.deleteExceededItems,
1085
+ mode: this.mode,
1086
+ hideDeleteButton: !this.exceededItemsDeletable,
1087
+ translateGroup: this.translateGroup,
1088
+ onChangeModelValue: this.deleteExceededItems,
1082
1089
  }),
1083
1090
  ]) :
1084
1091
  h("span", {
@@ -63,6 +63,11 @@ export default {
63
63
  required: false,
64
64
  default: undefined,
65
65
  },
66
+ translateGroup: {
67
+ type: Boolean,
68
+ required: false,
69
+ default: false,
70
+ },
66
71
  },
67
72
  emits: [
68
73
  "changeModelValue",
@@ -3,15 +3,22 @@ import {
3
3
  toRef,
4
4
  } from "vue";
5
5
 
6
+ import {
7
+ getTranslatedText,
8
+ isPlaceholderTranslate,
9
+ } from "../../../../ATranslation/compositionAPI/UtilsAPI";
10
+
6
11
  import {
7
12
  get,
8
13
  } from "lodash-es";
9
14
 
10
15
  export default function GroupAPI(props) {
16
+ const alwaysTranslate = toRef(props, "alwaysTranslate");
11
17
  const data = toRef(props, "data");
12
18
  const keyGroup = toRef(props, "keyGroup");
13
19
  const keyGroupLabelCallback = toRef(props, "keyGroupLabelCallback");
14
20
  const mode = toRef(props, "mode");
21
+ const translateGroup = toRef(props, "translateGroup");
15
22
 
16
23
  const groupLabel = computed(() => {
17
24
  if (!mode.value === "one_per_group" || !keyGroup.value) {
@@ -22,11 +29,19 @@ export default function GroupAPI(props) {
22
29
  return undefined;
23
30
  }
24
31
 
32
+ let groupLabel = groupKey;
25
33
  if (keyGroupLabelCallback.value) {
26
- return keyGroupLabelCallback.value({ item: data.value, inDropdown: false, group: groupKey });
34
+ groupLabel = keyGroupLabelCallback.value({ item: data.value, inDropdown: false, group: groupKey });
35
+ }
36
+
37
+ if (translateGroup.value && isPlaceholderTranslate(groupLabel)) {
38
+ return getTranslatedText({
39
+ placeholder: groupLabel,
40
+ alwaysTranslate: alwaysTranslate.value,
41
+ });
27
42
  }
28
43
 
29
- return groupKey;
44
+ return groupLabel;
30
45
  });
31
46
 
32
47
  return {
@@ -3,6 +3,11 @@ import {
3
3
  toRef,
4
4
  } from "vue";
5
5
 
6
+ import {
7
+ getTranslatedText,
8
+ isPlaceholderTranslate,
9
+ } from "../../../ATranslation/compositionAPI/UtilsAPI";
10
+
6
11
  import {
7
12
  AKeyLabel,
8
13
  } from "../../../const/AKeys";
@@ -21,12 +26,14 @@ export default function SelectedTitleAPI(props, {
21
26
  modelValueLength,
22
27
  modelValueMultiselectFiltered = computed(() => []),
23
28
  }) {
29
+ const alwaysTranslate = toRef(props, "alwaysTranslate");
24
30
  const isSelectionCloseable = toRef(props, "isSelectionCloseable");
25
31
  const keyGroup = toRef(props, "keyGroup");
26
32
  const keyGroupLabelCallback = toRef(props, "keyGroupLabelCallback");
27
33
  const keyTitle = toRef(props, "keyTitle");
28
34
  const keyTitleCallback = toRef(props, "keyTitleCallback");
29
35
  const modelValue = toRef(props, "modelValue");
36
+ const translateGroup = toRef(props, "translateGroup");
30
37
 
31
38
  const getTitleForItem = ({ item, _isModeOnePerGroup }) => {
32
39
  if (isFunction(keyTitleCallback.value)) {
@@ -40,11 +47,19 @@ export default function SelectedTitleAPI(props, {
40
47
  if (_isModeOnePerGroup) {
41
48
  const groupKey = get(item, keyGroup.value);
42
49
  if (groupKey) {
50
+ let groupLabel = groupKey;
43
51
  if (isFunction(keyGroupLabelCallback.value)) {
44
- return `${ keyGroupLabelCallback.value({ item, inDropdown: false, group: groupKey }) }: ${ item[AKeyLabel] }`;
52
+ groupLabel = keyGroupLabelCallback.value({ item, inDropdown: false, group: groupKey });
53
+ }
54
+
55
+ if (translateGroup.value && isPlaceholderTranslate(groupLabel)) {
56
+ groupLabel = getTranslatedText({
57
+ placeholder: groupLabel,
58
+ alwaysTranslate: alwaysTranslate.value,
59
+ });
45
60
  }
46
61
 
47
- return `${ groupKey }: ${ item[AKeyLabel] }`;
62
+ return `${ groupLabel }: ${ item[AKeyLabel] }`;
48
63
  }
49
64
  }
50
65
 
@@ -325,12 +325,17 @@ export default {
325
325
  required: false,
326
326
  default: () => ASelectPluginOptions.propsDefault.textDeselectAll,
327
327
  },
328
- textSelectAll: {
329
- type: String,
330
- required: false,
331
- default: () => ASelectPluginOptions.propsDefault.textSelectAll,
332
- },
333
- type: {
328
+ textSelectAll: {
329
+ type: String,
330
+ required: false,
331
+ default: () => ASelectPluginOptions.propsDefault.textSelectAll,
332
+ },
333
+ translateGroup: {
334
+ type: Boolean,
335
+ required: false,
336
+ default: () => ASelectPluginOptions.propsDefault.translateGroup,
337
+ },
338
+ type: {
334
339
  type: String,
335
340
  required: false,
336
341
  default: () => ASelectPluginOptions.propsDefault.type,
@@ -329,12 +329,17 @@ export default {
329
329
  required: false,
330
330
  default: () => ASelectPluginOptions.propsDefault.textDeselectAll,
331
331
  },
332
- textSelectAll: {
333
- type: String,
334
- required: false,
335
- default: () => ASelectPluginOptions.propsDefault.textSelectAll,
336
- },
337
- type: {
332
+ textSelectAll: {
333
+ type: String,
334
+ required: false,
335
+ default: () => ASelectPluginOptions.propsDefault.textSelectAll,
336
+ },
337
+ translateGroup: {
338
+ type: Boolean,
339
+ required: false,
340
+ default: () => ASelectPluginOptions.propsDefault.translateGroup,
341
+ },
342
+ type: {
338
343
  type: String,
339
344
  required: false,
340
345
  default: () => ASelectPluginOptions.propsDefault.type,
@@ -1,34 +1,41 @@
1
- import {
2
- computed,
3
- toRef,
4
- } from "vue";
5
-
6
- import {
7
- aOrderBy,
8
- extractTextFromHtml,
9
- } from "../../utils/utils";
10
-
11
- import {
12
- AKeyId,
13
- } from "../../const/AKeys";
14
- import {
15
- cloneDeep,
16
- forEach,
17
- get,
18
- isArray,
19
- isFunction,
20
- isNil,
21
- isString,
22
- values,
1
+ import {
2
+ computed,
3
+ toRef,
4
+ } from "vue";
5
+
6
+ import {
7
+ aOrderBy,
8
+ extractTextFromHtml,
9
+ } from "../../utils/utils";
10
+
11
+ import {
12
+ getTranslatedText,
13
+ isPlaceholderTranslate,
14
+ } from "../../ATranslation/compositionAPI/UtilsAPI";
15
+
16
+ import {
17
+ AKeyId,
18
+ } from "../../const/AKeys";
19
+ import {
20
+ cloneDeep,
21
+ forEach,
22
+ get,
23
+ isArray,
24
+ isFunction,
25
+ isNil,
26
+ isString,
27
+ values,
23
28
  } from "lodash-es";
24
29
 
25
- export default function UIDataGroupAPI(props, {
26
- data = computed(() => []),
27
- }) {
28
- const keyGroup = toRef(props, "keyGroup");
29
- const keyGroupLabelCallback = toRef(props, "keyGroupLabelCallback");
30
- const searchTextInHtml = toRef(props, "searchTextInHtml");
31
- const sortOrderGroup = toRef(props, "sortOrderGroup");
30
+ export default function UIDataGroupAPI(props, {
31
+ data = computed(() => []),
32
+ }) {
33
+ const alwaysTranslate = toRef(props, "alwaysTranslate");
34
+ const keyGroup = toRef(props, "keyGroup");
35
+ const keyGroupLabelCallback = toRef(props, "keyGroupLabelCallback");
36
+ const searchTextInHtml = toRef(props, "searchTextInHtml");
37
+ const sortOrderGroup = toRef(props, "sortOrderGroup");
38
+ const translateGroup = toRef(props, "translateGroup");
32
39
 
33
40
  const keyGroupArray = computed(() => {
34
41
  if (isArray(keyGroup.value)) {
@@ -65,21 +72,27 @@ export default function UIDataGroupAPI(props, {
65
72
  }
66
73
  allGroupKeys += `${ allGroupKeys ? "_" : "" }${ group }`;
67
74
  if (!GROUPS_FOR_LEVER[leverIndex][allGroupKeys]) {
68
- const GROUP_LABEL = isFunction(keyGroupLabelCallback.value) ?
69
- keyGroupLabelCallback.value({ group: group, item }) :
70
- group;
71
- GROUPS_FOR_LEVER[leverIndex][allGroupKeys] = {
72
- groupKey: group,
73
- groupLabel: GROUP_LABEL,
75
+ let groupLabel = isFunction(keyGroupLabelCallback.value) ?
76
+ keyGroupLabelCallback.value({ group: group, item }) :
77
+ group;
78
+ if (translateGroup.value && isPlaceholderTranslate(groupLabel)) {
79
+ groupLabel = getTranslatedText({
80
+ placeholder: groupLabel,
81
+ alwaysTranslate: alwaysTranslate.value,
82
+ });
83
+ }
84
+ GROUPS_FOR_LEVER[leverIndex][allGroupKeys] = {
85
+ groupKey: group,
86
+ groupLabel,
74
87
  groupParentKey: groupParentKey,
75
88
  allGroupKeys: allGroupKeys,
76
89
  allParentKeys: cloneDeep(allParentKeys),
77
90
  data: [],
78
91
  dataKeyByKeyId: {},
79
- };
80
- if (searchTextInHtml.value) {
81
- GROUPS_FOR_LEVER[leverIndex][allGroupKeys].groupLabelSearch = extractTextFromHtml(GROUP_LABEL);
82
- }
92
+ };
93
+ if (searchTextInHtml.value) {
94
+ GROUPS_FOR_LEVER[leverIndex][allGroupKeys].groupLabelSearch = extractTextFromHtml(groupLabel);
95
+ }
83
96
  }
84
97
  GROUPS_FOR_LEVER[leverIndex][allGroupKeys].data.push(item);
85
98
  GROUPS_FOR_LEVER[leverIndex][allGroupKeys].dataKeyByKeyId[item[AKeyId]] = item;
@@ -0,0 +1,106 @@
1
+ import {
2
+ computed,
3
+ nextTick,
4
+ } from "vue";
5
+ import {
6
+ beforeAll,
7
+ describe,
8
+ expect,
9
+ it,
10
+ } from "@jest/globals";
11
+
12
+ import UIDataGroupAPI from "../UIDataGroupAPI";
13
+ import {
14
+ setI18n,
15
+ setLanguage,
16
+ } from "../../../ATranslation/compositionAPI/ATranslationAPI";
17
+
18
+ import {
19
+ AKeyId,
20
+ } from "../../../const/AKeys";
21
+
22
+ describe("UIDataGroupAPI", () => {
23
+ beforeAll(async() => {
24
+ setI18n({
25
+ uiDataGroupApiTest: {
26
+ _GROUP_: "Translated group",
27
+ _GROUP_FROM_CALLBACK_: "Translated callback group",
28
+ },
29
+ });
30
+ setLanguage("uiDataGroupApiTest");
31
+ await nextTick();
32
+ });
33
+
34
+ it("translates a group label without changing its key", () => {
35
+ const props = {
36
+ alwaysTranslate: true,
37
+ keyGroup: "group",
38
+ keyGroupLabelCallback: undefined,
39
+ searchTextInHtml: false,
40
+ sortOrderGroup: undefined,
41
+ translateGroup: true,
42
+ };
43
+ const data = computed(() => [{
44
+ [AKeyId]: "item_1",
45
+ group: "_GROUP_",
46
+ }]);
47
+
48
+ const {
49
+ groupsForLever,
50
+ } = UIDataGroupAPI(props, {
51
+ data,
52
+ });
53
+
54
+ expect(groupsForLever.value[0][0]).toEqual(expect.objectContaining({
55
+ allGroupKeys: "_GROUP_",
56
+ groupKey: "_GROUP_",
57
+ groupLabel: "Translated group",
58
+ }));
59
+ });
60
+
61
+ it("does not translate a group label when translateGroup is false", () => {
62
+ const props = {
63
+ alwaysTranslate: true,
64
+ keyGroup: "group",
65
+ keyGroupLabelCallback: undefined,
66
+ searchTextInHtml: false,
67
+ sortOrderGroup: undefined,
68
+ translateGroup: false,
69
+ };
70
+ const data = computed(() => [{
71
+ [AKeyId]: "item_1",
72
+ group: "_GROUP_",
73
+ }]);
74
+
75
+ const {
76
+ groupsForLever,
77
+ } = UIDataGroupAPI(props, {
78
+ data,
79
+ });
80
+
81
+ expect(groupsForLever.value[0][0].groupLabel).toBe("_GROUP_");
82
+ });
83
+
84
+ it("translates a group label returned by keyGroupLabelCallback", () => {
85
+ const props = {
86
+ alwaysTranslate: true,
87
+ keyGroup: "group",
88
+ keyGroupLabelCallback: () => "_GROUP_FROM_CALLBACK_",
89
+ searchTextInHtml: false,
90
+ sortOrderGroup: undefined,
91
+ translateGroup: true,
92
+ };
93
+ const data = computed(() => [{
94
+ [AKeyId]: "item_1",
95
+ group: "group_1",
96
+ }]);
97
+
98
+ const {
99
+ groupsForLever,
100
+ } = UIDataGroupAPI(props, {
101
+ data,
102
+ });
103
+
104
+ expect(groupsForLever.value[0][0].groupLabel).toBe("Translated callback group");
105
+ });
106
+ });