sprintify-ui 0.8.61 → 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.
@@ -1107,7 +1107,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
1107
1107
  */
1108
1108
  storageKey: {
1109
1109
  type: StringConstructor;
1110
- default: string;
1110
+ default(): string;
1111
1111
  };
1112
1112
  }>, {
1113
1113
  fetch: typeof fetch;
@@ -1363,7 +1363,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
1363
1363
  */
1364
1364
  storageKey: {
1365
1365
  type: StringConstructor;
1366
- default: string;
1366
+ default(): string;
1367
1367
  };
1368
1368
  }>> & Readonly<{
1369
1369
  onDelete?: ((...args: any[]) => any) | undefined;
@@ -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
- declare const storageKeyPrefix = "sui.";
2
- export { storageKeyPrefix };
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.8.61",
3
+ "version": "0.8.63",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vue-tsc && vite build",
@@ -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
 
@@ -563,7 +562,9 @@ const props = defineProps({
563
562
  */
564
563
  storageKey: {
565
564
  type: String,
566
- default: window.location.pathname,
565
+ default() {
566
+ return window.location.pathname;
567
+ },
567
568
  },
568
569
  });
569
570
 
@@ -658,6 +659,7 @@ const onDelete = (row: CollectionItem) => {
658
659
  };
659
660
 
660
661
  const componentStorageKey = 'base_data_table.';
662
+ const settingsStorage = config.settingsStorage;
661
663
 
662
664
  /*
663
665
  |--------------------------------------------------------------------------
@@ -666,41 +668,42 @@ const componentStorageKey = 'base_data_table.';
666
668
  */
667
669
 
668
670
  const visibleColumns = ref<string[]>([]);
671
+ const visibleColumnsKey = componentStorageKey + props.storageKey + '.visible_columns';
669
672
 
670
- // Find visible columns in local storage
671
- const VISIBLE_COLUMNS_LOCAL_STORAGE_KEY = storageKeyPrefix + componentStorageKey + props.storageKey + '.visible_columns';
673
+ onMounted(async () => {
672
674
 
673
- const visibleColumnsFromStorage = JSON.parse(
674
- localStorage.getItem(VISIBLE_COLUMNS_LOCAL_STORAGE_KEY) + ''
675
- ) as string[];
675
+ const value = await settingsStorage.get(visibleColumnsKey);
676
676
 
677
- // If found, set visibleColumns
678
- if (
679
- visibleColumnsFromStorage &&
680
- isArray(visibleColumnsFromStorage) &&
681
- visibleColumnsFromStorage.length > 0
682
- ) {
683
- visibleColumns.value = visibleColumnsFromStorage;
684
- }
677
+ const visibleColumnsFromStorage = JSON.parse(value + '') as string[];
685
678
 
686
- // If nothing is found, set visibleColumns to all columns from table
687
- const unWatchTable = watch(
688
- () => table.value,
689
- () => {
690
- if (
691
- table.value &&
692
- table.value.newColumns.length &&
693
- visibleColumns.value.length == 0
694
- ) {
695
- visibleColumns.value = table.value.newColumns
696
- .filter((c) => c.toggle)
697
- .filter((c) => c.toggleDefault ?? true)
698
- .map((c) => c.newKey);
699
-
700
- unWatchTable();
701
- }
679
+ // If found, set visibleColumns
680
+ if (
681
+ visibleColumnsFromStorage &&
682
+ isArray(visibleColumnsFromStorage) &&
683
+ visibleColumnsFromStorage.length > 0
684
+ ) {
685
+ visibleColumns.value = visibleColumnsFromStorage;
702
686
  }
703
- );
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
+ });
704
707
 
705
708
  /**
706
709
  * Update local storage when check input update
@@ -709,8 +712,8 @@ function onUpdateVisibleColumn(columns: string[]) {
709
712
 
710
713
  visibleColumns.value = columns;
711
714
 
712
- localStorage.setItem(
713
- VISIBLE_COLUMNS_LOCAL_STORAGE_KEY,
715
+ settingsStorage.set(
716
+ visibleColumnsKey,
714
717
  JSON.stringify(visibleColumns.value)
715
718
  );
716
719
  }
@@ -723,12 +726,13 @@ function onUpdateVisibleColumn(columns: string[]) {
723
726
 
724
727
  const columnOrder = ref<string[]>([]);
725
728
 
726
- const COLUMN_ORDER_LOCAL_STORAGE_KEY = storageKeyPrefix + componentStorageKey + props.storageKey + '.column_order';
729
+ const columnOrderKey = componentStorageKey + props.storageKey + '.column_order';
730
+
731
+ onMounted(async () => {
732
+
733
+ const value = await settingsStorage.get(columnOrderKey);
727
734
 
728
- onMounted(() => {
729
- const columnOrderFromStorage = JSON.parse(
730
- localStorage.getItem(COLUMN_ORDER_LOCAL_STORAGE_KEY) + ''
731
- ) as string[];
735
+ const columnOrderFromStorage = JSON.parse(value + '') as string[];
732
736
 
733
737
  // If found, set columnOrder
734
738
  if (
@@ -749,8 +753,8 @@ function onUpdateColumnOrder(value: string[]) {
749
753
 
750
754
  columnOrder.value = value;
751
755
 
752
- localStorage.setItem(
753
- COLUMN_ORDER_LOCAL_STORAGE_KEY,
756
+ settingsStorage.set(
757
+ columnOrderKey,
754
758
  JSON.stringify(value)
755
759
  );
756
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
  }
@@ -1,3 +1,36 @@
1
1
  const storageKeyPrefix = 'sui.';
2
2
 
3
- export { storageKeyPrefix };
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 };