@data-fair/lib-vue 1.22.0 → 1.23.1
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/concept-filters.d.ts +1 -0
- package/concept-filters.js +16 -12
- package/format/bytes.js +19 -17
- package/format/field.js +21 -14
- package/locale-dayjs.d.ts +2 -2
- package/locale-dayjs.js +2 -2
- package/package.json +1 -1
package/concept-filters.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export declare function getConceptFilters(searchParams: Record<string, string>, datasetId?: string): Record<string, string>;
|
|
1
2
|
export declare function useConceptFilters(reactiveSearchParams: Record<string, string>, datasetId?: string): Record<string, string>;
|
|
2
3
|
export default useConceptFilters;
|
package/concept-filters.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
// filter reactiveSearchParams to conceptFilters (params prefixed by _c_)
|
|
2
2
|
import { reactive, watch } from 'vue';
|
|
3
|
+
export function getConceptFilters(searchParams, datasetId) {
|
|
4
|
+
const conceptFilters = {};
|
|
5
|
+
const datasetFiltersPrefix = datasetId && `_d_${datasetId}_`;
|
|
6
|
+
for (const key of Object.keys(searchParams)) {
|
|
7
|
+
if (key.startsWith('_c_'))
|
|
8
|
+
conceptFilters[key] = searchParams[key];
|
|
9
|
+
if (datasetFiltersPrefix && key.startsWith(datasetFiltersPrefix)) {
|
|
10
|
+
conceptFilters[key.replace(datasetFiltersPrefix, '')] = searchParams[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return conceptFilters;
|
|
14
|
+
}
|
|
3
15
|
export function useConceptFilters(reactiveSearchParams, datasetId) {
|
|
4
16
|
const conceptFilters = reactive({});
|
|
5
|
-
|
|
17
|
+
// we use a watch and mutations on a reactive to prevent triggering reactivity on unrelated changes in reactive search params
|
|
6
18
|
watch(reactiveSearchParams, () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
conceptFilters[key] = reactiveSearchParams[key];
|
|
10
|
-
if (datasetFiltersPrefix && key.startsWith(datasetFiltersPrefix)) {
|
|
11
|
-
conceptFilters[key.replace(datasetFiltersPrefix, '')] = reactiveSearchParams[key];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
19
|
+
const newConceptFilters = getConceptFilters(reactiveSearchParams, datasetId);
|
|
20
|
+
Object.assign(conceptFilters, newConceptFilters);
|
|
14
21
|
for (const key of Object.keys(conceptFilters)) {
|
|
15
|
-
if (
|
|
16
|
-
delete conceptFilters[key];
|
|
17
|
-
if (datasetFiltersPrefix && !key.startsWith('_c_') && reactiveSearchParams[datasetFiltersPrefix + key] === undefined) {
|
|
22
|
+
if (!(key in newConceptFilters))
|
|
18
23
|
delete conceptFilters[key];
|
|
19
|
-
}
|
|
20
24
|
}
|
|
21
25
|
}, { immediate: true });
|
|
22
26
|
return conceptFilters;
|
package/format/bytes.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
const locales = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export function formatBytes
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
fr: [[0, 'octet'], [1, 'octets'], [1000, 'ko'], [1000 * 1000, 'Mo'], [1000 * 1000 * 1000, 'Go'], [1000 * 1000 * 1000 * 1000, 'To'], [1000 * 1000 * 1000 * 1000 * 1000, 'Po']],
|
|
3
|
+
en: [[0, 'byte'], [1, 'bytes'], [1000, 'kb'], [1000 * 1000, 'Mb'], [1000 * 1000 * 1000, 'Gb'], [1000 * 1000 * 1000 * 1000, 'Tb'], [1000 * 1000 * 1000 * 1000 * 1000, 'Pb']]
|
|
4
|
+
};
|
|
5
|
+
export function formatBytes(bytes, locale = 'fr') {
|
|
6
|
+
const bytesInt = Math.abs(typeof bytes === 'string' ? parseInt(bytes, 10) : bytes);
|
|
7
|
+
const def = locales[locale] ?? locales.en;
|
|
8
|
+
for (let i = 0; i < def.length; i++) {
|
|
9
|
+
const step = def[i][0];
|
|
10
|
+
if (bytesInt < step || i === def.length - 1) {
|
|
11
|
+
const value = bytesInt / (def[i - 1][0] || 1);
|
|
12
|
+
let digits = 2;
|
|
13
|
+
if (value > 1)
|
|
14
|
+
digits = 1;
|
|
15
|
+
if (value > 10)
|
|
16
|
+
digits = 0;
|
|
17
|
+
return value.toLocaleString(locale, { maximumFractionDigits: digits }) + ' ' + def[i - 1][1];
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
return '' // this is only for strict typing, but the code cannot go there, the return in the loop is always called
|
|
20
|
+
return ''; // this is only for strict typing, but the code cannot go there, the return in the loop is always called
|
|
19
21
|
}
|
|
20
|
-
export default formatBytes
|
|
22
|
+
export default formatBytes;
|
package/format/field.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
// TODO: use locale-dayjs for localization of date formats
|
|
2
|
-
import dayjs from 'dayjs'
|
|
3
|
-
export function formatField
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
export function formatField(item, field) {
|
|
4
|
+
const value = item[field.key];
|
|
5
|
+
if (value === undefined || value === null || value === '')
|
|
6
|
+
return '';
|
|
7
|
+
if (field['x-labels']?.['' + item[field.key]])
|
|
8
|
+
return field['x-labels']['' + item[field.key]];
|
|
9
|
+
if (field.type === 'number' || field.type === 'integer')
|
|
10
|
+
return value.toLocaleString('fr');
|
|
11
|
+
if (typeof value === 'boolean')
|
|
12
|
+
return value ? 'Oui' : 'Non';
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
if (field['x-refersTo'] === 'http://schema.org/Date' ||
|
|
11
15
|
field['x-refersTo'] === 'https://schema.org/startDate' ||
|
|
12
16
|
field['x-refersTo'] === 'https://schema.org/endDate' ||
|
|
13
17
|
field['x-refersTo'] === 'http://schema.org/dateCreated') {
|
|
14
|
-
|
|
18
|
+
if (field.format === 'date-time')
|
|
19
|
+
return dayjs(value).format('DD/MM/YYYY, HH[h]mm');
|
|
20
|
+
else
|
|
21
|
+
return dayjs(value).format('DD/MM/YYYY');
|
|
22
|
+
}
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
return '' + value
|
|
24
|
+
return '' + value;
|
|
18
25
|
}
|
|
19
|
-
export function getFieldLabel
|
|
20
|
-
|
|
26
|
+
export function getFieldLabel(field) {
|
|
27
|
+
return field.title || field['x-originalName'] || field.key;
|
|
21
28
|
}
|
package/locale-dayjs.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { App } from 'vue';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import 'dayjs/locale/fr';
|
|
4
|
-
import 'dayjs/locale/en';
|
|
3
|
+
import 'dayjs/locale/fr.js';
|
|
4
|
+
import 'dayjs/locale/en.js';
|
|
5
5
|
import { CreateDurationType } from 'dayjs/plugin/duration.js';
|
|
6
6
|
export type { ConfigType as DayjsConfigType } from 'dayjs';
|
|
7
7
|
declare module 'dayjs' {
|
package/locale-dayjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { inject } from 'vue';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import 'dayjs/locale/fr';
|
|
4
|
-
import 'dayjs/locale/en';
|
|
3
|
+
import 'dayjs/locale/fr.js';
|
|
4
|
+
import 'dayjs/locale/en.js';
|
|
5
5
|
import localizedFormat from 'dayjs/plugin/localizedFormat.js';
|
|
6
6
|
import relativeTime from 'dayjs/plugin/relativeTime.js';
|
|
7
7
|
import duration from 'dayjs/plugin/duration.js';
|