aloha-vue 2.82.0 → 2.83.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.82.0",
3
+ "version": "2.83.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",
@@ -41,6 +41,16 @@ export default {
41
41
  required: false,
42
42
  default: undefined,
43
43
  },
44
+ classColumns: {
45
+ type: [String, Object],
46
+ required: false,
47
+ default: undefined,
48
+ },
49
+ classColumnDefault: {
50
+ type: [String, Object],
51
+ required: false,
52
+ default: undefined,
53
+ },
44
54
  classExtra: {
45
55
  type: [String, Object],
46
56
  required: false,
@@ -361,6 +371,8 @@ export default {
361
371
  }),
362
372
  this.hasDataForm && h(AForm, {
363
373
  alwaysTranslate: this.alwaysTranslate,
374
+ classColumns: this.classColumns,
375
+ classColumnDefault: this.classColumnDefault,
364
376
  modelValue: this.modelValue,
365
377
  data: this.dataForm,
366
378
  errors: this.errors,
@@ -386,6 +386,11 @@ export default {
386
386
  required: false,
387
387
  default: undefined,
388
388
  },
389
+ urlTemplateData: {
390
+ type: Object,
391
+ required: false,
392
+ default: undefined,
393
+ },
389
394
  },
390
395
  emits: [
391
396
  "focusin",
@@ -478,6 +478,11 @@ export default {
478
478
  required: false,
479
479
  default: undefined,
480
480
  },
481
+ urlTemplateData: {
482
+ type: Object,
483
+ required: false,
484
+ default: undefined,
485
+ },
481
486
  },
482
487
  emits: [
483
488
  "blur",
@@ -397,6 +397,11 @@ export default {
397
397
  required: false,
398
398
  default: undefined,
399
399
  },
400
+ urlTemplateData: {
401
+ type: Object,
402
+ required: false,
403
+ default: undefined,
404
+ },
400
405
  },
401
406
  emits: [
402
407
  "focusin",
@@ -537,6 +537,11 @@ export default {
537
537
  required: false,
538
538
  default: undefined,
539
539
  },
540
+ urlTemplateData: {
541
+ type: Object,
542
+ required: false,
543
+ default: undefined,
544
+ },
540
545
  },
541
546
  emits: [
542
547
  "blur",
@@ -6,6 +6,7 @@ import {
6
6
  } from "vue";
7
7
 
8
8
  import AHttpAPI from "../../compositionAPI/AHttpAPI";
9
+ import UiUrlAPI from "./UiUrlAPI";
9
10
 
10
11
  import {
11
12
  ADataRetrievePluginOptions,
@@ -48,11 +49,14 @@ export default function UiDataFromServerAPI(props, {
48
49
  const modelValue = toRef(props, "modelValue");
49
50
  const searchApiKey = toRef(props, "searchApiKey");
50
51
  const type = toRef(props, "type");
51
- const url = toRef(props, "url");
52
52
  const urlRetrieve = toRef(props, "urlRetrieve");
53
53
  const urlParams = toRef(props, "urlParams");
54
54
  const urlRetrieveParams = toRef(props, "urlRetrieveParams");
55
55
 
56
+ const {
57
+ urlLocal,
58
+ } = UiUrlAPI(props);
59
+
56
60
  const loadingSearchApi = ref(false);
57
61
  const loadingDataFromServer = ref(undefined);
58
62
  const loadingRequestCount = ref(0);
@@ -72,7 +76,7 @@ export default function UiDataFromServerAPI(props, {
72
76
  };
73
77
 
74
78
  const searchApiLocal = computed(() => {
75
- return !!(searchApi.value && searchApiKey.value && url.value);
79
+ return !!(searchApi.value && searchApiKey.value && urlLocal.value);
76
80
  });
77
81
 
78
82
  const retrieveCallback = computed(() => {
@@ -80,7 +84,7 @@ export default function UiDataFromServerAPI(props, {
80
84
  });
81
85
 
82
86
  const urlRetrieveLocal = computed(() => {
83
- return urlRetrieve.value || url.value;
87
+ return urlRetrieve.value || urlLocal.value;
84
88
  });
85
89
 
86
90
  const urlRetrieveParamsLocal = computed(() => {
@@ -97,7 +101,7 @@ export default function UiDataFromServerAPI(props, {
97
101
  const urlPropsComputed = computed(() => {
98
102
  return [
99
103
  apiSaveId.value,
100
- url.value,
104
+ urlLocal.value,
101
105
  urlParams.value,
102
106
  ];
103
107
  });
@@ -143,13 +147,13 @@ export default function UiDataFromServerAPI(props, {
143
147
  };
144
148
 
145
149
  const loadDataFromServer = () => {
146
- if (!url.value || searchApiLocal.value) {
150
+ if (!urlLocal.value || searchApiLocal.value) {
147
151
  dataFromServer.value = [];
148
152
  return;
149
153
  }
150
154
  startLoading();
151
155
  getListHttp({
152
- url: url.value,
156
+ url: urlLocal.value,
153
157
  urlParams: urlParams.value,
154
158
  apiSaveId: apiSaveId.value,
155
159
  }).then(
@@ -241,7 +245,7 @@ export default function UiDataFromServerAPI(props, {
241
245
 
242
246
  const isRetrieveInvalidEntries = computed(() => {
243
247
  return !searchApiLocal.value &&
244
- !!(url.value || data.value?.length);
248
+ !!(urlLocal.value || data.value?.length);
245
249
  });
246
250
 
247
251
  const prepareRetrieveResponse = ({ response = [] } = {}) => {
@@ -291,7 +295,7 @@ export default function UiDataFromServerAPI(props, {
291
295
  }
292
296
  loadingSearchApi.value = true;
293
297
  getListHttp({
294
- url: url.value,
298
+ url: urlLocal.value,
295
299
  urlParams: {
296
300
  ...(urlParams.value || {}),
297
301
  [searchApiKey.value]: search,
@@ -335,7 +339,7 @@ export default function UiDataFromServerAPI(props, {
335
339
  },
336
340
  };
337
341
  return getListHttp({
338
- url: url.value,
342
+ url: urlLocal.value,
339
343
  urlParams: URL_PARAMS,
340
344
  }).then(
341
345
  response => {
@@ -400,7 +404,7 @@ export default function UiDataFromServerAPI(props, {
400
404
  });
401
405
 
402
406
  watch(data, (newVal, oldVal) => {
403
- if (!url.value &&
407
+ if (!urlLocal.value &&
404
408
  !isEqual(newVal, oldVal)) {
405
409
  syncDataFromRetrieve();
406
410
  loadDataFromServerForRetrieve();
@@ -0,0 +1,30 @@
1
+ import {
2
+ computed,
3
+ toRef,
4
+ } from "vue";
5
+
6
+ import UtilsAPI from "../../ATranslation/compositionAPI/UtilsAPI";
7
+
8
+ export default function UiUrlAPI(props) {
9
+ const url = toRef(props, "url");
10
+ const urlTemplateData = toRef(props, "urlTemplateData");
11
+
12
+ const {
13
+ replaceText,
14
+ } = UtilsAPI();
15
+
16
+ const urlLocal = computed(() => {
17
+ if (!url.value?.includes("{{") || !url.value.includes("}}")) {
18
+ return url.value;
19
+ }
20
+
21
+ return replaceText({
22
+ text: url.value,
23
+ object: urlTemplateData.value,
24
+ });
25
+ });
26
+
27
+ return {
28
+ urlLocal,
29
+ };
30
+ }
@@ -0,0 +1,149 @@
1
+ import {
2
+ effectScope,
3
+ nextTick,
4
+ reactive,
5
+ watch,
6
+ } from "vue";
7
+ import {
8
+ afterEach,
9
+ describe,
10
+ expect,
11
+ it,
12
+ vi,
13
+ } from "vitest";
14
+ import {
15
+ flushPromises,
16
+ } from "@vue/test-utils";
17
+
18
+ import UiDataFromServerAPI from "../UiDataFromServerAPI";
19
+ import UiUrlAPI from "../UiUrlAPI";
20
+
21
+ const { getListHttp } = vi.hoisted(() => ({
22
+ getListHttp: vi.fn(() => Promise.resolve([])),
23
+ }));
24
+
25
+ vi.mock("../../../compositionAPI/AHttpAPI", () => ({
26
+ default: () => ({ getListHttp }),
27
+ }));
28
+
29
+ let scope;
30
+
31
+ afterEach(() => {
32
+ scope?.stop();
33
+ getListHttp.mockClear();
34
+ });
35
+
36
+ describe("UI URL templates", () => {
37
+ it.each([undefined, "", "foo/bar/", "foo/{{ id/"])("preserves URL %s without a complete placeholder", url => {
38
+ const props = reactive({ url, urlTemplateData: { id: 1 } });
39
+ const { urlLocal } = UiUrlAPI(props);
40
+
41
+ expect(urlLocal.value).toBe(url);
42
+ props.urlTemplateData.id = 2;
43
+ expect(urlLocal.value).toBe(url);
44
+ });
45
+
46
+ it("uses translation placeholders with nested paths and repeated values", () => {
47
+ const props = reactive({
48
+ url: "foo/{{ id }}/bar/{{ aloha.bar }}/{{id}}/",
49
+ urlTemplateData: { id: 0, aloha: { bar: false } },
50
+ });
51
+ const { urlLocal } = UiUrlAPI(props);
52
+
53
+ expect(urlLocal.value).toBe("foo/0/bar/false/0/");
54
+ props.urlTemplateData.aloha.bar = "baz";
55
+ expect(urlLocal.value).toBe("foo/0/bar/baz/0/");
56
+ });
57
+
58
+ it.each([false, true])("only calls the URL watcher when the resolved URL changes (deep: %s)", async deep => {
59
+ const props = reactive({
60
+ url: "foo/{{ id }}/bar/{{ aloha.bar }}/",
61
+ urlTemplateData: { id: 1, aloha: { bar: "baz" }, unused: 0 },
62
+ });
63
+ const callback = vi.fn();
64
+ let api;
65
+ scope = effectScope();
66
+ scope.run(() => {
67
+ api = UiDataFromServerAPI(props);
68
+ watch(api.urlPropsComputed, callback, { deep });
69
+ });
70
+
71
+ props.urlTemplateData.unused++;
72
+ await nextTick();
73
+ props.urlTemplateData = { id: 1, aloha: { bar: "baz" }, unused: 2 };
74
+ await nextTick();
75
+ props.urlTemplateData.id = "1";
76
+ await nextTick();
77
+ expect(callback).not.toHaveBeenCalled();
78
+
79
+ props.urlTemplateData.aloha.bar = "new";
80
+ await nextTick();
81
+ expect(callback).toHaveBeenCalledTimes(1);
82
+ expect(api.urlPropsComputed.value[1]).toBe("foo/1/bar/new/");
83
+
84
+ props.url = "other/{{ id }}/";
85
+ await nextTick();
86
+ expect(callback).toHaveBeenCalledTimes(2);
87
+ });
88
+
89
+ it("reloads using the resolved URL and resets the model only when it changes", async() => {
90
+ const props = reactive({
91
+ url: "foo/{{ id }}/",
92
+ urlTemplateData: { id: 1 },
93
+ urlParams: { limit: 10 },
94
+ });
95
+ const changeModel = vi.fn();
96
+ scope = effectScope();
97
+ scope.run(() => {
98
+ const api = UiDataFromServerAPI(props, { changeModel });
99
+ watch(api.urlPropsComputed, api.updateUrlPropsComputed);
100
+ api.loadDataFromServer();
101
+ });
102
+ await flushPromises();
103
+ expect(getListHttp).toHaveBeenLastCalledWith(expect.objectContaining({
104
+ url: "foo/1/",
105
+ urlParams: { limit: 10 },
106
+ }));
107
+
108
+ props.urlTemplateData = { id: 1, unused: true };
109
+ await flushPromises();
110
+ expect(getListHttp).toHaveBeenCalledTimes(1);
111
+ expect(changeModel).not.toHaveBeenCalled();
112
+
113
+ props.urlTemplateData.id = 2;
114
+ await flushPromises();
115
+ expect(getListHttp).toHaveBeenCalledTimes(2);
116
+ expect(getListHttp).toHaveBeenLastCalledWith(expect.objectContaining({ url: "foo/2/" }));
117
+ expect(changeModel).toHaveBeenCalledTimes(1);
118
+ });
119
+
120
+ it("uses the resolved URL for search and the retrieve fallback", async() => {
121
+ const props = reactive({
122
+ url: "foo/{{ id }}/",
123
+ urlTemplateData: { id: 1 },
124
+ searchApi: true,
125
+ searchApiKey: "search",
126
+ keyId: "pk",
127
+ modelValue: 42,
128
+ });
129
+ scope = effectScope();
130
+ const api = scope.run(() => UiDataFromServerAPI(props));
131
+
132
+ api.onSearchInApi({ search: "hello" });
133
+ await flushPromises();
134
+ expect(getListHttp).toHaveBeenLastCalledWith({
135
+ url: "foo/1/",
136
+ urlParams: { search: "hello" },
137
+ });
138
+
139
+ await api.loadDataFromServerForRetrieve();
140
+ expect(getListHttp).toHaveBeenLastCalledWith({
141
+ url: "foo/1/",
142
+ urlParams: { pk: [42], limit: 1 },
143
+ });
144
+
145
+ props.urlRetrieve = "retrieve/";
146
+ await flushPromises();
147
+ expect(getListHttp).toHaveBeenLastCalledWith(expect.objectContaining({ url: "retrieve/" }));
148
+ });
149
+ });