@vxe-ui/core 3.4.42 → 3.5.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.
Files changed (161) hide show
  1. package/es/index.d.ts +124 -0
  2. package/es/index.esm.js +135 -122
  3. package/es/index.js +147 -0
  4. package/es/src/base-utils.d.ts +2 -0
  5. package/es/src/base-utils.js +40 -37
  6. package/es/src/clipboard.d.ts +2 -0
  7. package/es/src/clipboard.js +48 -45
  8. package/es/src/commands.d.ts +2 -0
  9. package/es/src/commands.js +47 -48
  10. package/es/src/config.d.ts +13 -0
  11. package/es/src/config.js +21 -23
  12. package/es/src/configStore.d.ts +2 -0
  13. package/es/src/configStore.js +8 -5
  14. package/es/src/core.d.ts +3 -0
  15. package/es/src/core.js +11 -7
  16. package/es/src/dataStore.d.ts +2 -0
  17. package/es/src/dataStore.js +4 -1
  18. package/es/src/db-utils.d.ts +2 -0
  19. package/es/src/db-utils.js +234 -0
  20. package/es/src/dom-utils.d.ts +2 -0
  21. package/es/src/dom-utils.js +65 -68
  22. package/es/src/event.d.ts +4 -0
  23. package/es/src/event.js +133 -147
  24. package/es/src/formats.d.ts +2 -0
  25. package/es/src/formats.js +47 -48
  26. package/es/src/i18n.d.ts +6 -0
  27. package/es/src/i18n.js +54 -47
  28. package/es/src/i18nStore.d.ts +5 -0
  29. package/es/src/i18nStore.js +11 -8
  30. package/es/src/icon.d.ts +6 -0
  31. package/es/src/icon.js +27 -21
  32. package/es/src/iconStore.d.ts +2 -0
  33. package/es/src/iconStore.js +4 -1
  34. package/es/src/interceptor.d.ts +2 -0
  35. package/es/src/interceptor.js +52 -54
  36. package/es/src/log.d.ts +2 -0
  37. package/es/src/log.js +14 -11
  38. package/es/src/menus.d.ts +2 -0
  39. package/es/src/menus.js +47 -48
  40. package/es/src/mixins.d.ts +36 -0
  41. package/es/src/mixins.js +229 -236
  42. package/es/src/permission.d.ts +3 -0
  43. package/es/src/permission.js +57 -55
  44. package/es/src/popper-utils.d.ts +2 -0
  45. package/es/src/popper-utils.js +159 -179
  46. package/es/src/renderer.d.ts +5 -0
  47. package/es/src/renderer.js +37 -42
  48. package/es/src/resize.d.ts +2 -0
  49. package/es/src/resize.js +60 -70
  50. package/es/src/scrollbar-utils.d.ts +2 -0
  51. package/es/src/scrollbar-utils.js +57 -54
  52. package/es/src/store.d.ts +13 -0
  53. package/es/src/store.js +43 -45
  54. package/es/src/theme.d.ts +3 -0
  55. package/es/src/theme.js +17 -13
  56. package/es/src/themeStore.d.ts +4 -0
  57. package/es/src/themeStore.js +5 -2
  58. package/es/src/validators.d.ts +2 -0
  59. package/es/src/validators.js +6 -3
  60. package/es/src/vm.d.ts +2 -0
  61. package/es/src/vm.js +9 -6
  62. package/es/src/z-index.d.ts +2 -0
  63. package/es/src/z-index.js +29 -26
  64. package/lib/index.common.js +132 -353
  65. package/lib/index.js +178 -0
  66. package/lib/index.umd.js +790 -3303
  67. package/lib/index.umd.min.js +1 -1
  68. package/lib/src/base-utils.js +39 -13
  69. package/lib/src/clipboard.js +50 -23
  70. package/lib/src/commands.js +46 -27
  71. package/lib/src/config.js +43 -23
  72. package/lib/src/configStore.js +24 -7
  73. package/lib/src/core.js +29 -11
  74. package/lib/src/dataStore.js +22 -5
  75. package/lib/src/db-utils.js +263 -0
  76. package/lib/src/dom-utils.js +40 -20
  77. package/lib/src/event.js +95 -102
  78. package/lib/src/formats.js +46 -27
  79. package/lib/src/i18n.js +54 -41
  80. package/lib/src/i18nStore.js +35 -9
  81. package/lib/src/icon.js +45 -21
  82. package/lib/src/iconStore.js +22 -5
  83. package/lib/src/interceptor.js +40 -18
  84. package/lib/src/log.js +29 -12
  85. package/lib/src/menus.js +46 -27
  86. package/lib/src/mixins.js +67 -83
  87. package/lib/src/permission.js +40 -17
  88. package/lib/src/popper-utils.js +71 -71
  89. package/lib/src/renderer.js +40 -21
  90. package/lib/src/resize.js +48 -42
  91. package/lib/src/scrollbar-utils.js +23 -6
  92. package/lib/src/store.js +44 -25
  93. package/lib/src/theme.js +31 -14
  94. package/lib/src/themeStore.js +24 -7
  95. package/lib/src/validators.js +34 -10
  96. package/lib/src/vm.js +34 -8
  97. package/lib/src/z-index.js +38 -12
  98. package/package.json +17 -3
  99. package/packages/index.ts +169 -166
  100. package/packages/src/base-utils.ts +42 -43
  101. package/packages/src/clipboard.ts +56 -56
  102. package/packages/src/commands.ts +56 -56
  103. package/packages/src/config.ts +30 -30
  104. package/packages/src/configStore.ts +8 -8
  105. package/packages/src/core.ts +11 -11
  106. package/packages/src/dataStore.ts +3 -4
  107. package/packages/src/db-utils.ts +267 -0
  108. package/packages/src/dom-utils.ts +86 -87
  109. package/packages/src/event.ts +161 -161
  110. package/packages/src/formats.ts +56 -56
  111. package/packages/src/i18n.ts +66 -66
  112. package/packages/src/i18nStore.ts +16 -16
  113. package/packages/src/icon.ts +32 -32
  114. package/packages/src/iconStore.ts +3 -3
  115. package/packages/src/interceptor.ts +64 -64
  116. package/packages/src/log.ts +19 -19
  117. package/packages/src/menus.ts +56 -56
  118. package/packages/src/mixins.ts +284 -292
  119. package/packages/src/permission.ts +61 -61
  120. package/packages/src/popper-utils.ts +197 -194
  121. package/packages/src/renderer.ts +50 -50
  122. package/packages/src/resize.ts +89 -89
  123. package/packages/src/scrollbar-utils.ts +58 -58
  124. package/packages/src/store.ts +47 -47
  125. package/packages/src/theme.ts +20 -20
  126. package/packages/src/themeStore.ts +7 -7
  127. package/packages/src/validators.ts +7 -7
  128. package/packages/src/vm.ts +10 -10
  129. package/packages/src/z-index.ts +30 -30
  130. package/types/core/db-utils.d.ts +44 -0
  131. package/types/core/global-config.d.ts +4 -6
  132. package/types/core/index.d.ts +7 -0
  133. package/lib/src/base-utils.min.js +0 -1
  134. package/lib/src/clipboard.min.js +0 -1
  135. package/lib/src/commands.min.js +0 -1
  136. package/lib/src/config.min.js +0 -1
  137. package/lib/src/configStore.min.js +0 -1
  138. package/lib/src/core.min.js +0 -1
  139. package/lib/src/dataStore.min.js +0 -1
  140. package/lib/src/dom-utils.min.js +0 -1
  141. package/lib/src/event.min.js +0 -1
  142. package/lib/src/formats.min.js +0 -1
  143. package/lib/src/i18n.min.js +0 -1
  144. package/lib/src/i18nStore.min.js +0 -1
  145. package/lib/src/icon.min.js +0 -1
  146. package/lib/src/iconStore.min.js +0 -1
  147. package/lib/src/interceptor.min.js +0 -1
  148. package/lib/src/log.min.js +0 -1
  149. package/lib/src/menus.min.js +0 -1
  150. package/lib/src/mixins.min.js +0 -1
  151. package/lib/src/permission.min.js +0 -1
  152. package/lib/src/popper-utils.min.js +0 -1
  153. package/lib/src/renderer.min.js +0 -1
  154. package/lib/src/resize.min.js +0 -1
  155. package/lib/src/scrollbar-utils.min.js +0 -1
  156. package/lib/src/store.min.js +0 -1
  157. package/lib/src/theme.min.js +0 -1
  158. package/lib/src/themeStore.min.js +0 -1
  159. package/lib/src/validators.min.js +0 -1
  160. package/lib/src/vm.min.js +0 -1
  161. package/lib/src/z-index.min.js +0 -1
@@ -1,52 +1,55 @@
1
- import XEUtils from 'xe-utils';
1
+ import XEUtils from "xe-utils";
2
2
  let copyElem;
3
3
  const clipStore = {
4
- text: '',
5
- html: ''
4
+ text: "",
5
+ html: ""
6
6
  };
7
7
  function handleText(text) {
8
- if (!copyElem) {
9
- copyElem = document.createElement('textarea');
10
- copyElem.id = '$VxeCopy';
11
- const styles = copyElem.style;
12
- styles.width = '48px';
13
- styles.height = '24px';
14
- styles.position = 'fixed';
15
- styles.zIndex = '0';
16
- styles.left = '-500px';
17
- styles.top = '-500px';
18
- document.body.appendChild(copyElem);
19
- }
20
- copyElem.value = text;
8
+ if (!copyElem) {
9
+ copyElem = document.createElement("textarea");
10
+ copyElem.id = "$VxeCopy";
11
+ const styles = copyElem.style;
12
+ styles.width = "48px";
13
+ styles.height = "24px";
14
+ styles.position = "fixed";
15
+ styles.zIndex = "0";
16
+ styles.left = "-500px";
17
+ styles.top = "-500px";
18
+ document.body.appendChild(copyElem);
19
+ }
20
+ copyElem.value = text;
21
21
  }
22
- export const clipboard = {
23
- getStore() {
24
- return clipStore;
25
- },
26
- setStore(data) {
27
- Object.assign(clipStore, data || {});
28
- },
29
- /**
30
- * 复制内容到剪贴板
31
- *
32
- * @param {String} content Text 内容
33
- */
34
- copy(content) {
35
- let result = false;
36
- try {
37
- const text = XEUtils.toValueString(content);
38
- handleText(text);
39
- copyElem.select();
40
- copyElem.setSelectionRange(0, copyElem.value.length);
41
- result = document.execCommand('copy');
42
- copyElem.blur();
43
- clipStore.text = text;
44
- clipStore.html = '';
45
- }
46
- catch (e) { }
47
- return result;
48
- },
49
- getText() {
50
- return clipStore.text || '';
22
+ const clipboard = {
23
+ getStore() {
24
+ return clipStore;
25
+ },
26
+ setStore(data) {
27
+ Object.assign(clipStore, data || {});
28
+ },
29
+ /**
30
+ * 复制内容到剪贴板
31
+ *
32
+ * @param {String} content Text 内容
33
+ */
34
+ copy(content) {
35
+ let result = false;
36
+ try {
37
+ const text = XEUtils.toValueString(content);
38
+ handleText(text);
39
+ copyElem.select();
40
+ copyElem.setSelectionRange(0, copyElem.value.length);
41
+ result = document.execCommand("copy");
42
+ copyElem.blur();
43
+ clipStore.text = text;
44
+ clipStore.html = "";
45
+ } catch (e) {
51
46
  }
47
+ return result;
48
+ },
49
+ getText() {
50
+ return clipStore.text || "";
51
+ }
52
+ };
53
+ export {
54
+ clipboard
52
55
  };
@@ -0,0 +1,2 @@
1
+ import { VxeGlobalCommands } from '../../types';
2
+ export declare const commands: VxeGlobalCommands;
@@ -1,51 +1,50 @@
1
- import XEUtils from 'xe-utils';
2
- import { log } from './log';
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import XEUtils from "xe-utils";
5
+ import { log } from "./log";
3
6
  class VXECommandsStore {
4
- constructor() {
5
- Object.defineProperty(this, "store", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: {}
10
- });
11
- }
12
- mixin(options) {
13
- XEUtils.each(options, (item, key) => {
14
- this.add(key, item);
15
- });
16
- return this;
17
- }
18
- has(name) {
19
- return !!this.get(name);
20
- }
21
- get(name) {
22
- return this.store[name];
23
- }
24
- add(name, render) {
25
- const conf = this.store[name];
26
- // 兼容
27
- if (XEUtils.isFunction(render)) {
28
- log.warn('vxe.error.delProp', ['commands -> callback', 'commandMethod']);
29
- render = {
30
- commandMethod: render
31
- };
32
- }
33
- // 检测是否覆盖
34
- const confKeys = XEUtils.keys(conf);
35
- XEUtils.each(render, (item, key) => {
36
- if (confKeys.includes(key)) {
37
- log.warn('vxe.error.coverProp', [name, key]);
38
- }
39
- });
40
- this.store[name] = conf ? XEUtils.merge(conf, render) : render;
41
- return this;
42
- }
43
- delete(name) {
44
- delete this.store[name];
45
- }
46
- forEach(callback) {
47
- XEUtils.objectEach(this.store, callback);
7
+ constructor() {
8
+ __publicField(this, "store", {});
9
+ }
10
+ mixin(options) {
11
+ XEUtils.each(options, (item, key) => {
12
+ this.add(key, item);
13
+ });
14
+ return this;
15
+ }
16
+ has(name) {
17
+ return !!this.get(name);
18
+ }
19
+ get(name) {
20
+ return this.store[name];
21
+ }
22
+ add(name, render) {
23
+ const conf = this.store[name];
24
+ if (XEUtils.isFunction(render)) {
25
+ log.warn("vxe.error.delProp", ["commands -> callback", "commandMethod"]);
26
+ render = {
27
+ commandMethod: render
28
+ };
48
29
  }
30
+ const confKeys = XEUtils.keys(conf);
31
+ XEUtils.each(render, (item, key) => {
32
+ if (confKeys.includes(key)) {
33
+ log.warn("vxe.error.coverProp", [name, key]);
34
+ }
35
+ });
36
+ this.store[name] = conf ? XEUtils.merge(conf, render) : render;
37
+ return this;
38
+ }
39
+ delete(name) {
40
+ delete this.store[name];
41
+ }
42
+ forEach(callback) {
43
+ XEUtils.objectEach(this.store, callback);
44
+ }
49
45
  }
50
- export const commands = new VXECommandsStore();
51
- Object.assign(commands, { _name: 'Commands' });
46
+ const commands = new VXECommandsStore();
47
+ Object.assign(commands, { _name: "Commands" });
48
+ export {
49
+ commands
50
+ };
@@ -0,0 +1,13 @@
1
+ import { VxeGlobalConfig } from '../../types';
2
+ /**
3
+ * 全局参数设置
4
+ */
5
+ export declare function setConfig(options?: VxeGlobalConfig): import("../../types").VxeUIExport;
6
+ /**
7
+ * 获取全局参数
8
+ */
9
+ export declare function getConfig(key: keyof VxeGlobalConfig, defaultValue?: any): string | number | boolean | VxeGlobalConfig | ((key: string, args?: any) => string | number) | ((params: {
10
+ status: boolean;
11
+ code: number;
12
+ msg: string;
13
+ }) => void) | null | undefined;
package/es/src/config.js CHANGED
@@ -1,26 +1,24 @@
1
- import XEUtils from 'xe-utils';
2
- import DomZIndex from 'dom-zindex';
3
- import { VxeCore } from './core';
4
- import { globalConfigStore } from './configStore';
5
- import { setTheme } from './theme';
6
- /**
7
- * 全局参数设置
8
- */
9
- export function setConfig(options) {
10
- if (options) {
11
- if (options.zIndex) {
12
- DomZIndex.setCurrent(options.zIndex);
13
- }
14
- if (options.theme) {
15
- setTheme(options.theme);
16
- }
17
- XEUtils.merge(globalConfigStore, options);
1
+ import XEUtils from "xe-utils";
2
+ import DomZIndex from "dom-zindex";
3
+ import { VxeCore } from "./core";
4
+ import { globalConfigStore } from "./configStore";
5
+ import { setTheme } from "./theme";
6
+ function setConfig(options) {
7
+ if (options) {
8
+ if (options.zIndex) {
9
+ DomZIndex.setCurrent(options.zIndex);
18
10
  }
19
- return VxeCore;
11
+ if (options.theme) {
12
+ setTheme(options.theme);
13
+ }
14
+ XEUtils.merge(globalConfigStore, options);
15
+ }
16
+ return VxeCore;
20
17
  }
21
- /**
22
- * 获取全局参数
23
- */
24
- export function getConfig(key, defaultValue) {
25
- return arguments.length ? XEUtils.get(globalConfigStore, key, defaultValue) : globalConfigStore;
18
+ function getConfig(key, defaultValue) {
19
+ return arguments.length ? XEUtils.get(globalConfigStore, key, defaultValue) : globalConfigStore;
26
20
  }
21
+ export {
22
+ getConfig,
23
+ setConfig
24
+ };
@@ -0,0 +1,2 @@
1
+ import { VxeGlobalConfig } from '../../types';
2
+ export declare const globalConfigStore: VxeGlobalConfig;
@@ -1,6 +1,9 @@
1
- export const globalConfigStore = {
2
- size: '',
3
- version: 1,
4
- zIndex: 999,
5
- resizeInterval: 500
1
+ const globalConfigStore = {
2
+ size: "",
3
+ version: 1,
4
+ zIndex: 999,
5
+ resizeInterval: 500
6
+ };
7
+ export {
8
+ globalConfigStore
6
9
  };
@@ -0,0 +1,3 @@
1
+ import { VxeUIExport } from '../../types';
2
+ export declare const coreVersion: string;
3
+ export declare const VxeCore: VxeUIExport;
package/es/src/core.js CHANGED
@@ -1,8 +1,12 @@
1
- export const coreVersion = "3.4.42";
2
- export const VxeCore = {
3
- coreVersion,
4
- uiVersion: '',
5
- tableVersion: '',
6
- designVersion: '',
7
- ganttVersion: ''
1
+ const coreVersion = "3.5.1";
2
+ const VxeCore = {
3
+ coreVersion,
4
+ uiVersion: "",
5
+ tableVersion: "",
6
+ designVersion: "",
7
+ ganttVersion: ""
8
+ };
9
+ export {
10
+ VxeCore,
11
+ coreVersion
8
12
  };
@@ -0,0 +1,2 @@
1
+ import { VxeGlobalData } from '../../types';
2
+ export declare const globalStore: VxeGlobalData;
@@ -1 +1,4 @@
1
- export const globalStore = {};
1
+ const globalStore = {};
2
+ export {
3
+ globalStore
4
+ };
@@ -0,0 +1,2 @@
1
+ import type { VxeDBUtils } from '../../types';
2
+ export declare const dbUtils: VxeDBUtils;
@@ -0,0 +1,234 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import XEUtils from "xe-utils";
5
+ import { globalConfigStore } from "./configStore";
6
+ class IdbStore {
7
+ constructor(key, version) {
8
+ __publicField(this, "storeName", "Storage");
9
+ __publicField(this, "key");
10
+ __publicField(this, "version");
11
+ __publicField(this, "dbPromise", null);
12
+ __publicField(this, "dbName", "");
13
+ this.key = key;
14
+ this.version = version;
15
+ }
16
+ getDBName() {
17
+ return `${this.key}_${this.version}`;
18
+ }
19
+ /**
20
+ * 重置连接缓存,下次调用 openDB 会重新建立连接
21
+ */
22
+ resetDB() {
23
+ this.dbPromise = null;
24
+ this.dbName = "";
25
+ }
26
+ openDB() {
27
+ const name = this.getDBName();
28
+ if (this.dbPromise && this.dbName === name) {
29
+ return this.dbPromise;
30
+ }
31
+ this.dbName = name;
32
+ this.dbPromise = new Promise((resolve, reject) => {
33
+ const request = indexedDB.open(name, 1);
34
+ request.onupgradeneeded = () => {
35
+ const db = request.result;
36
+ if (!db.objectStoreNames.contains(this.storeName)) {
37
+ db.createObjectStore(this.storeName, { keyPath: "id" });
38
+ }
39
+ };
40
+ request.onsuccess = () => {
41
+ const db = request.result;
42
+ db.onversionchange = () => {
43
+ db.close();
44
+ this.resetDB();
45
+ };
46
+ db.onclose = () => {
47
+ this.resetDB();
48
+ };
49
+ resolve(db);
50
+ };
51
+ request.onerror = () => {
52
+ reject(request.error || new Error(`IdbStore open failed: ${name}`));
53
+ };
54
+ request.onblocked = () => {
55
+ console.warn(`[IdbStore] open blocked: ${name}`);
56
+ };
57
+ }).catch((err) => {
58
+ this.resetDB();
59
+ throw err;
60
+ });
61
+ return this.dbPromise;
62
+ }
63
+ getById(id) {
64
+ return this.openDB().then(
65
+ (db) => new Promise((resolve, reject) => {
66
+ const req = db.transaction(this.storeName, "readonly").objectStore(this.storeName).get(id);
67
+ req.onsuccess = () => resolve(req.result);
68
+ req.onerror = () => reject(req.error);
69
+ })
70
+ );
71
+ }
72
+ getAll() {
73
+ return this.openDB().then(
74
+ (db) => new Promise((resolve, reject) => {
75
+ const store = db.transaction(this.storeName, "readonly").objectStore(this.storeName);
76
+ if (XEUtils.isFunction(store.getAll)) {
77
+ const req2 = store.getAll();
78
+ req2.onsuccess = () => resolve(req2.result || []);
79
+ req2.onerror = () => reject(req2.error);
80
+ return;
81
+ }
82
+ const list = [];
83
+ const req = store.openCursor();
84
+ req.onsuccess = () => {
85
+ const cursor = req.result;
86
+ if (cursor) {
87
+ list.push(cursor.value);
88
+ cursor.continue();
89
+ } else {
90
+ resolve(list);
91
+ }
92
+ };
93
+ req.onerror = () => reject(req.error);
94
+ })
95
+ );
96
+ }
97
+ updateById(id, data) {
98
+ if (data == null) {
99
+ return this.deleteById(id);
100
+ }
101
+ return this.openDB().then(
102
+ (db) => new Promise((resolve, reject) => {
103
+ const tx = db.transaction(this.storeName, "readwrite");
104
+ tx.objectStore(this.storeName).put({ id, data });
105
+ tx.oncomplete = () => resolve();
106
+ tx.onerror = () => reject(tx.error);
107
+ })
108
+ );
109
+ }
110
+ deleteById(id) {
111
+ return this.openDB().then(
112
+ (db) => new Promise((resolve, reject) => {
113
+ const tx = db.transaction(this.storeName, "readwrite");
114
+ tx.objectStore(this.storeName).delete(id);
115
+ tx.oncomplete = () => resolve();
116
+ tx.onerror = () => reject(tx.error);
117
+ })
118
+ );
119
+ }
120
+ /**
121
+ * 清空当前库的数据
122
+ */
123
+ clear() {
124
+ return this.openDB().then(
125
+ (db) => new Promise((resolve, reject) => {
126
+ const tx = db.transaction(this.storeName, "readwrite");
127
+ tx.objectStore(this.storeName).clear();
128
+ tx.oncomplete = () => resolve();
129
+ tx.onerror = () => reject(tx.error);
130
+ })
131
+ );
132
+ }
133
+ /**
134
+ * 清理非当前版本的旧库
135
+ */
136
+ cleanupOldDBs() {
137
+ if (!indexedDB.databases) {
138
+ return Promise.resolve();
139
+ }
140
+ const current = this.getDBName();
141
+ const prefix = `${this.key}_`;
142
+ return indexedDB.databases().then((dbs) => {
143
+ dbs.forEach((db) => {
144
+ const n = db.name;
145
+ if (!n || n === current || !n.startsWith(prefix)) {
146
+ return;
147
+ }
148
+ const rest = n.slice(prefix.length);
149
+ if (!rest.includes("_")) {
150
+ indexedDB.deleteDatabase(n);
151
+ }
152
+ });
153
+ });
154
+ }
155
+ }
156
+ class LocalStorageStore {
157
+ constructor(key, version) {
158
+ __publicField(this, "key");
159
+ __publicField(this, "version");
160
+ this.key = key;
161
+ this.version = version;
162
+ }
163
+ readAll() {
164
+ const storageData = XEUtils.toStringJSON(localStorage.getItem(this.key) || "");
165
+ return storageData && String(storageData._v) === String(this.version) ? storageData : { _v: this.version };
166
+ }
167
+ writeAll(map) {
168
+ localStorage.setItem(this.key, XEUtils.toJSONString(map));
169
+ }
170
+ getById(id) {
171
+ const map = this.readAll();
172
+ const has = Object.prototype.hasOwnProperty.call(map, id);
173
+ return Promise.resolve(has && map[id] != null ? { id, data: map[id] } : void 0);
174
+ }
175
+ getAll() {
176
+ const map = this.readAll();
177
+ const list = [];
178
+ Object.keys(map).forEach((k) => {
179
+ if (k !== "_v" && map[k] != null) {
180
+ list.push({ id: k, data: map[k] });
181
+ }
182
+ });
183
+ return Promise.resolve(list);
184
+ }
185
+ updateById(id, data) {
186
+ if (data == null) {
187
+ return this.deleteById(id);
188
+ }
189
+ const map = this.readAll();
190
+ map[id] = data;
191
+ this.writeAll(map);
192
+ return Promise.resolve();
193
+ }
194
+ deleteById(id) {
195
+ const map = this.readAll();
196
+ delete map[id];
197
+ this.writeAll(map);
198
+ return Promise.resolve();
199
+ }
200
+ clear() {
201
+ this.writeAll({ _v: this.version });
202
+ return Promise.resolve();
203
+ }
204
+ cleanupOldDBs() {
205
+ const raw = localStorage.getItem(this.key);
206
+ if (!raw) {
207
+ return Promise.resolve();
208
+ }
209
+ const storageData = XEUtils.toStringJSON(raw);
210
+ if (!storageData || String(storageData._v) !== String(this.version)) {
211
+ localStorage.removeItem(this.key);
212
+ }
213
+ return Promise.resolve();
214
+ }
215
+ }
216
+ const dbUtils = {
217
+ /**
218
+ * 创建存储实例
219
+ * - driver = 'indexedDB' 且环境支持 => IdbStore
220
+ * - 其余情况(未传 / 不支持)=> LocalStorageStore
221
+ */
222
+ createStore(key, options) {
223
+ const opts = Object.assign({}, options);
224
+ const version = opts.version || globalConfigStore.version || 0;
225
+ const driver = opts.driver;
226
+ if ((!driver || driver === "indexedDB") && typeof indexedDB !== "undefined") {
227
+ return new IdbStore(key, version);
228
+ }
229
+ return new LocalStorageStore(key, version);
230
+ }
231
+ };
232
+ export {
233
+ dbUtils
234
+ };
@@ -0,0 +1,2 @@
1
+ import { VxeDomUtils } from '../../types';
2
+ export declare const domUtils: VxeDomUtils;