sprintify-ui 0.8.62 → 0.8.63
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/dist/sprintify-ui.es.js +3475 -3460
- package/dist/types/index.d.ts +3 -0
- package/dist/types/utils/storage.d.ts +10 -2
- package/package.json +1 -1
- package/src/components/BaseDataTable.vue +42 -40
- package/src/index.ts +7 -0
- package/src/utils/storage.ts +34 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -210,6 +210,7 @@ import { Locales } from './types';
|
|
|
210
210
|
import { Country } from './types/Country';
|
|
211
211
|
import { Region } from './types/Region';
|
|
212
212
|
import { Size } from './utils/sizes';
|
|
213
|
+
import { SettingsStorage } from './utils/storage';
|
|
213
214
|
export interface OptionProps {
|
|
214
215
|
size?: Size;
|
|
215
216
|
}
|
|
@@ -219,6 +220,7 @@ export interface Options {
|
|
|
219
220
|
locales?: Locales;
|
|
220
221
|
formatQueryString?: (params: Record<string, any>) => string;
|
|
221
222
|
parseQueryString?: (params: string) => Record<string, any>;
|
|
223
|
+
settingsStorage?: SettingsStorage;
|
|
222
224
|
countries?: Country[];
|
|
223
225
|
regions?: Region[];
|
|
224
226
|
props?: OptionProps;
|
|
@@ -229,6 +231,7 @@ declare const config: {
|
|
|
229
231
|
upload_url: string;
|
|
230
232
|
formatQueryString(params: Record<string, any>): string;
|
|
231
233
|
parseQueryString(params: string): Record<string, any>;
|
|
234
|
+
settingsStorage: SettingsStorage;
|
|
232
235
|
countries: Country[];
|
|
233
236
|
regions: Region[];
|
|
234
237
|
props: OptionProps | undefined;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type SettingsStorageGetFunction = (key: string) => Promise<string | null>;
|
|
2
|
+
type SettingsStorageSetFunction = (key: string, value: string) => Promise<void>;
|
|
3
|
+
declare class SettingsStorage {
|
|
4
|
+
private getFunction;
|
|
5
|
+
private setFunction;
|
|
6
|
+
constructor(getFunction?: SettingsStorageGetFunction, setFunction?: SettingsStorageSetFunction);
|
|
7
|
+
get(key: string): Promise<string | null>;
|
|
8
|
+
set(key: string, value: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export { SettingsStorage };
|
package/package.json
CHANGED
|
@@ -256,7 +256,6 @@ import { useInputSize } from '@/composables/inputSize';
|
|
|
256
256
|
import BaseButton from './BaseButton.vue';
|
|
257
257
|
import BaseDataTableTemplate from './BaseDataTableTemplate.vue';
|
|
258
258
|
import { customKeyActions } from '@/services/table/customKeyActions';
|
|
259
|
-
import { storageKeyPrefix } from '@/utils/storage';
|
|
260
259
|
|
|
261
260
|
const http = config.http;
|
|
262
261
|
|
|
@@ -660,6 +659,7 @@ const onDelete = (row: CollectionItem) => {
|
|
|
660
659
|
};
|
|
661
660
|
|
|
662
661
|
const componentStorageKey = 'base_data_table.';
|
|
662
|
+
const settingsStorage = config.settingsStorage;
|
|
663
663
|
|
|
664
664
|
/*
|
|
665
665
|
|--------------------------------------------------------------------------
|
|
@@ -668,41 +668,42 @@ const componentStorageKey = 'base_data_table.';
|
|
|
668
668
|
*/
|
|
669
669
|
|
|
670
670
|
const visibleColumns = ref<string[]>([]);
|
|
671
|
+
const visibleColumnsKey = componentStorageKey + props.storageKey + '.visible_columns';
|
|
671
672
|
|
|
672
|
-
|
|
673
|
-
const VISIBLE_COLUMNS_LOCAL_STORAGE_KEY = storageKeyPrefix + componentStorageKey + props.storageKey + '.visible_columns';
|
|
673
|
+
onMounted(async () => {
|
|
674
674
|
|
|
675
|
-
const
|
|
676
|
-
localStorage.getItem(VISIBLE_COLUMNS_LOCAL_STORAGE_KEY) + ''
|
|
677
|
-
) as string[];
|
|
675
|
+
const value = await settingsStorage.get(visibleColumnsKey);
|
|
678
676
|
|
|
679
|
-
|
|
680
|
-
if (
|
|
681
|
-
visibleColumnsFromStorage &&
|
|
682
|
-
isArray(visibleColumnsFromStorage) &&
|
|
683
|
-
visibleColumnsFromStorage.length > 0
|
|
684
|
-
) {
|
|
685
|
-
visibleColumns.value = visibleColumnsFromStorage;
|
|
686
|
-
}
|
|
677
|
+
const visibleColumnsFromStorage = JSON.parse(value + '') as string[];
|
|
687
678
|
|
|
688
|
-
// If
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
visibleColumns.value.length == 0
|
|
696
|
-
) {
|
|
697
|
-
visibleColumns.value = table.value.newColumns
|
|
698
|
-
.filter((c) => c.toggle)
|
|
699
|
-
.filter((c) => c.toggleDefault ?? true)
|
|
700
|
-
.map((c) => c.newKey);
|
|
701
|
-
|
|
702
|
-
unWatchTable();
|
|
703
|
-
}
|
|
679
|
+
// If found, set visibleColumns
|
|
680
|
+
if (
|
|
681
|
+
visibleColumnsFromStorage &&
|
|
682
|
+
isArray(visibleColumnsFromStorage) &&
|
|
683
|
+
visibleColumnsFromStorage.length > 0
|
|
684
|
+
) {
|
|
685
|
+
visibleColumns.value = visibleColumnsFromStorage;
|
|
704
686
|
}
|
|
705
|
-
|
|
687
|
+
|
|
688
|
+
// If nothing is found, set visibleColumns to all columns from table
|
|
689
|
+
const unWatchTable = watch(
|
|
690
|
+
() => table.value,
|
|
691
|
+
() => {
|
|
692
|
+
if (
|
|
693
|
+
table.value &&
|
|
694
|
+
table.value.newColumns.length &&
|
|
695
|
+
visibleColumns.value.length == 0
|
|
696
|
+
) {
|
|
697
|
+
visibleColumns.value = table.value.newColumns
|
|
698
|
+
.filter((c) => c.toggle)
|
|
699
|
+
.filter((c) => c.toggleDefault ?? true)
|
|
700
|
+
.map((c) => c.newKey);
|
|
701
|
+
|
|
702
|
+
unWatchTable();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
);
|
|
706
|
+
});
|
|
706
707
|
|
|
707
708
|
/**
|
|
708
709
|
* Update local storage when check input update
|
|
@@ -711,8 +712,8 @@ function onUpdateVisibleColumn(columns: string[]) {
|
|
|
711
712
|
|
|
712
713
|
visibleColumns.value = columns;
|
|
713
714
|
|
|
714
|
-
|
|
715
|
-
|
|
715
|
+
settingsStorage.set(
|
|
716
|
+
visibleColumnsKey,
|
|
716
717
|
JSON.stringify(visibleColumns.value)
|
|
717
718
|
);
|
|
718
719
|
}
|
|
@@ -725,12 +726,13 @@ function onUpdateVisibleColumn(columns: string[]) {
|
|
|
725
726
|
|
|
726
727
|
const columnOrder = ref<string[]>([]);
|
|
727
728
|
|
|
728
|
-
const
|
|
729
|
+
const columnOrderKey = componentStorageKey + props.storageKey + '.column_order';
|
|
730
|
+
|
|
731
|
+
onMounted(async () => {
|
|
732
|
+
|
|
733
|
+
const value = await settingsStorage.get(columnOrderKey);
|
|
729
734
|
|
|
730
|
-
|
|
731
|
-
const columnOrderFromStorage = JSON.parse(
|
|
732
|
-
localStorage.getItem(COLUMN_ORDER_LOCAL_STORAGE_KEY) + ''
|
|
733
|
-
) as string[];
|
|
735
|
+
const columnOrderFromStorage = JSON.parse(value + '') as string[];
|
|
734
736
|
|
|
735
737
|
// If found, set columnOrder
|
|
736
738
|
if (
|
|
@@ -751,8 +753,8 @@ function onUpdateColumnOrder(value: string[]) {
|
|
|
751
753
|
|
|
752
754
|
columnOrder.value = value;
|
|
753
755
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
+
settingsStorage.set(
|
|
757
|
+
columnOrderKey,
|
|
756
758
|
JSON.stringify(value)
|
|
757
759
|
);
|
|
758
760
|
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { Country } from './types/Country';
|
|
|
18
18
|
import { Region } from './types/Region';
|
|
19
19
|
import { useI18nStore } from './stores/i18n';
|
|
20
20
|
import { Size } from './utils/sizes';
|
|
21
|
+
import { SettingsStorage } from './utils/storage';
|
|
21
22
|
|
|
22
23
|
export interface OptionProps {
|
|
23
24
|
size?: Size;
|
|
@@ -31,6 +32,7 @@ export interface Options {
|
|
|
31
32
|
formatQueryString?: (params: Record<string, any>) => string;
|
|
32
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
34
|
parseQueryString?: (params: string) => Record<string, any>;
|
|
35
|
+
settingsStorage?: SettingsStorage;
|
|
34
36
|
countries?: Country[];
|
|
35
37
|
regions?: Region[];
|
|
36
38
|
props?: OptionProps
|
|
@@ -56,6 +58,7 @@ const config = {
|
|
|
56
58
|
//comma: true,
|
|
57
59
|
});
|
|
58
60
|
},
|
|
61
|
+
settingsStorage: new SettingsStorage(),
|
|
59
62
|
countries: [] as Country[],
|
|
60
63
|
regions: [] as Region[],
|
|
61
64
|
props: {
|
|
@@ -89,6 +92,10 @@ function install(app: App, options?: Options) {
|
|
|
89
92
|
config.parseQueryString = options.parseQueryString;
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
if (options?.settingsStorage) {
|
|
96
|
+
config.settingsStorage = options.settingsStorage;
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
if (options?.countries) {
|
|
93
100
|
config.countries = options.countries;
|
|
94
101
|
}
|
package/src/utils/storage.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
1
|
const storageKeyPrefix = 'sui.';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type SettingsStorageGetFunction = (key: string) => Promise<string | null>;
|
|
4
|
+
type SettingsStorageSetFunction = (key: string, value: string) => Promise<void>;
|
|
5
|
+
|
|
6
|
+
class SettingsStorage {
|
|
7
|
+
|
|
8
|
+
private getFunction: SettingsStorageGetFunction;
|
|
9
|
+
private setFunction: SettingsStorageSetFunction;
|
|
10
|
+
|
|
11
|
+
constructor(getFunction?: SettingsStorageGetFunction, setFunction?: SettingsStorageSetFunction) {
|
|
12
|
+
|
|
13
|
+
const localStorageGet = (key: string) => {
|
|
14
|
+
key = storageKeyPrefix + key;
|
|
15
|
+
return Promise.resolve(localStorage.getItem(key));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const localStorageSet = (key: string, value: string) => {
|
|
19
|
+
key = storageKeyPrefix + key;
|
|
20
|
+
return Promise.resolve(localStorage.setItem(key, value));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.getFunction = getFunction ? getFunction : localStorageGet;
|
|
24
|
+
this.setFunction = setFunction ? setFunction : localStorageSet;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get(key: string): Promise<string | null> {
|
|
28
|
+
return this.getFunction(key);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
set(key: string, value: string): Promise<void> {
|
|
32
|
+
return this.setFunction(key, value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { SettingsStorage };
|