@vxe-ui/core 4.4.42 → 4.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 (195) hide show
  1. package/dist/all.esm.js +1594 -1389
  2. package/dist/all.esm.min.js +1 -0
  3. package/es/index.d.ts +138 -0
  4. package/es/index.esm.js +138 -125
  5. package/es/index.js +150 -0
  6. package/es/src/base-utils.d.ts +2 -0
  7. package/es/src/base-utils.js +40 -37
  8. package/es/src/clipboard.d.ts +2 -0
  9. package/es/src/clipboard.js +48 -45
  10. package/es/src/commands.d.ts +2 -0
  11. package/es/src/commands.js +47 -48
  12. package/es/src/config.d.ts +13 -0
  13. package/es/src/config.js +21 -23
  14. package/es/src/configStore.d.ts +2 -0
  15. package/es/src/configStore.js +8 -5
  16. package/es/src/core.d.ts +3 -0
  17. package/es/src/core.js +11 -7
  18. package/es/src/dataStore.d.ts +2 -0
  19. package/es/src/dataStore.js +4 -1
  20. package/es/src/db-utils.d.ts +2 -0
  21. package/es/src/db-utils.js +234 -0
  22. package/es/src/dom-utils.d.ts +2 -0
  23. package/es/src/dom-utils.js +65 -68
  24. package/es/src/event.d.ts +4 -0
  25. package/es/src/event.js +133 -147
  26. package/es/src/formats.d.ts +2 -0
  27. package/es/src/formats.js +47 -48
  28. package/es/src/hooks.d.ts +2 -0
  29. package/es/src/hooks.js +5 -2
  30. package/es/src/i18n.d.ts +6 -0
  31. package/es/src/i18n.js +51 -44
  32. package/es/src/i18nStore.d.ts +5 -0
  33. package/es/src/i18nStore.js +7 -4
  34. package/es/src/icon.d.ts +9 -0
  35. package/es/src/icon.js +28 -22
  36. package/es/src/iconStore.d.ts +2 -0
  37. package/es/src/iconStore.js +4 -1
  38. package/es/src/interceptor.d.ts +2 -0
  39. package/es/src/interceptor.js +52 -54
  40. package/es/src/log.d.ts +2 -0
  41. package/es/src/log.js +14 -11
  42. package/es/src/menus.d.ts +2 -0
  43. package/es/src/menus.js +47 -48
  44. package/es/src/permission.d.ts +3 -0
  45. package/es/src/permission.js +57 -55
  46. package/es/src/popper-utils.d.ts +2 -0
  47. package/es/src/popper-utils.js +159 -179
  48. package/es/src/renderer.d.ts +5 -0
  49. package/es/src/renderer.js +37 -42
  50. package/es/src/resize.d.ts +2 -0
  51. package/es/src/resize.js +60 -70
  52. package/es/src/scrollbar-utils.d.ts +2 -0
  53. package/es/src/scrollbar-utils.js +57 -54
  54. package/es/src/store.d.ts +13 -0
  55. package/es/src/store.js +43 -45
  56. package/es/src/theme.d.ts +3 -0
  57. package/es/src/theme.js +17 -13
  58. package/es/src/themeStore.d.ts +4 -0
  59. package/es/src/themeStore.js +5 -2
  60. package/es/src/useFns.d.ts +40 -0
  61. package/es/src/useFns.js +212 -231
  62. package/es/src/validators.d.ts +2 -0
  63. package/es/src/validators.js +6 -3
  64. package/es/src/vm.d.ts +2 -0
  65. package/es/src/vm.js +9 -6
  66. package/es/src/z-index.d.ts +2 -0
  67. package/es/src/z-index.js +29 -26
  68. package/lib/index.common.js +136 -365
  69. package/lib/index.js +181 -0
  70. package/lib/index.umd.js +819 -3343
  71. package/lib/index.umd.min.js +1 -1
  72. package/lib/src/base-utils.js +39 -13
  73. package/lib/src/clipboard.js +50 -23
  74. package/lib/src/commands.js +46 -27
  75. package/lib/src/config.js +43 -23
  76. package/lib/src/configStore.js +24 -7
  77. package/lib/src/core.js +29 -11
  78. package/lib/src/dataStore.js +22 -5
  79. package/lib/src/db-utils.js +263 -0
  80. package/lib/src/dom-utils.js +40 -20
  81. package/lib/src/event.js +95 -102
  82. package/lib/src/formats.js +46 -27
  83. package/lib/src/hooks.js +33 -7
  84. package/lib/src/i18n.js +53 -38
  85. package/lib/src/i18nStore.js +25 -8
  86. package/lib/src/icon.js +46 -22
  87. package/lib/src/iconStore.js +22 -5
  88. package/lib/src/interceptor.js +40 -18
  89. package/lib/src/log.js +29 -12
  90. package/lib/src/menus.js +46 -27
  91. package/lib/src/permission.js +40 -17
  92. package/lib/src/popper-utils.js +71 -71
  93. package/lib/src/renderer.js +40 -21
  94. package/lib/src/resize.js +48 -42
  95. package/lib/src/scrollbar-utils.js +23 -6
  96. package/lib/src/store.js +44 -25
  97. package/lib/src/theme.js +31 -14
  98. package/lib/src/themeStore.js +24 -7
  99. package/lib/src/useFns.js +87 -124
  100. package/lib/src/validators.js +34 -10
  101. package/lib/src/vm.js +34 -8
  102. package/lib/src/z-index.js +38 -12
  103. package/package.json +14 -3
  104. package/packages/index.ts +171 -168
  105. package/packages/src/base-utils.ts +42 -43
  106. package/packages/src/clipboard.ts +56 -56
  107. package/packages/src/commands.ts +56 -56
  108. package/packages/src/config.ts +30 -30
  109. package/packages/src/configStore.ts +8 -8
  110. package/packages/src/core.ts +11 -11
  111. package/packages/src/dataStore.ts +3 -4
  112. package/packages/src/db-utils.ts +267 -0
  113. package/packages/src/dom-utils.ts +86 -87
  114. package/packages/src/event.ts +161 -161
  115. package/packages/src/formats.ts +56 -56
  116. package/packages/src/hooks.ts +5 -5
  117. package/packages/src/i18n.ts +63 -63
  118. package/packages/src/i18nStore.ts +11 -11
  119. package/packages/src/icon.ts +32 -32
  120. package/packages/src/iconStore.ts +3 -3
  121. package/packages/src/interceptor.ts +64 -64
  122. package/packages/src/log.ts +19 -19
  123. package/packages/src/menus.ts +56 -56
  124. package/packages/src/permission.ts +61 -61
  125. package/packages/src/popper-utils.ts +197 -194
  126. package/packages/src/renderer.ts +50 -50
  127. package/packages/src/resize.ts +89 -89
  128. package/packages/src/scrollbar-utils.ts +58 -58
  129. package/packages/src/store.ts +47 -47
  130. package/packages/src/theme.ts +20 -20
  131. package/packages/src/themeStore.ts +7 -7
  132. package/packages/src/useFns.ts +270 -275
  133. package/packages/src/validators.ts +7 -7
  134. package/packages/src/vm.ts +10 -10
  135. package/packages/src/z-index.ts +30 -30
  136. package/types/core/base-utils.d.ts +39 -40
  137. package/types/core/clipboard.d.ts +22 -22
  138. package/types/core/commands.d.ts +17 -19
  139. package/types/core/components.d.ts +5 -5
  140. package/types/core/db-utils.d.ts +44 -0
  141. package/types/core/dom-utils.d.ts +36 -37
  142. package/types/core/formats.d.ts +17 -19
  143. package/types/core/global-config.d.ts +67 -74
  144. package/types/core/global-data.d.ts +7 -7
  145. package/types/core/global-event.d.ts +48 -48
  146. package/types/core/global-icon.d.ts +10 -10
  147. package/types/core/global-lang.d.ts +28 -27
  148. package/types/core/global-resize.d.ts +3 -3
  149. package/types/core/global-theme.d.ts +1 -1
  150. package/types/core/hooks.d.ts +12 -14
  151. package/types/core/index.d.ts +343 -336
  152. package/types/core/interceptor.d.ts +20 -22
  153. package/types/core/log.d.ts +8 -8
  154. package/types/core/menus.d.ts +17 -19
  155. package/types/core/permission.d.ts +10 -10
  156. package/types/core/popper-utils.d.ts +44 -44
  157. package/types/core/renderer.d.ts +14 -14
  158. package/types/core/scrollbar-utils.d.ts +37 -38
  159. package/types/core/useFn.d.ts +121 -126
  160. package/types/core/validators.d.ts +17 -19
  161. package/types/core/z-index.d.ts +18 -18
  162. package/types/index.d.ts +13 -13
  163. package/types/tool/common.d.ts +146 -155
  164. package/types/tool/index.d.ts +2 -2
  165. package/types/tool/util.d.ts +4 -4
  166. package/lib/src/base-utils.min.js +0 -1
  167. package/lib/src/clipboard.min.js +0 -1
  168. package/lib/src/commands.min.js +0 -1
  169. package/lib/src/config.min.js +0 -1
  170. package/lib/src/configStore.min.js +0 -1
  171. package/lib/src/core.min.js +0 -1
  172. package/lib/src/dataStore.min.js +0 -1
  173. package/lib/src/dom-utils.min.js +0 -1
  174. package/lib/src/event.min.js +0 -1
  175. package/lib/src/formats.min.js +0 -1
  176. package/lib/src/hooks.min.js +0 -1
  177. package/lib/src/i18n.min.js +0 -1
  178. package/lib/src/i18nStore.min.js +0 -1
  179. package/lib/src/icon.min.js +0 -1
  180. package/lib/src/iconStore.min.js +0 -1
  181. package/lib/src/interceptor.min.js +0 -1
  182. package/lib/src/log.min.js +0 -1
  183. package/lib/src/menus.min.js +0 -1
  184. package/lib/src/permission.min.js +0 -1
  185. package/lib/src/popper-utils.min.js +0 -1
  186. package/lib/src/renderer.min.js +0 -1
  187. package/lib/src/resize.min.js +0 -1
  188. package/lib/src/scrollbar-utils.min.js +0 -1
  189. package/lib/src/store.min.js +0 -1
  190. package/lib/src/theme.min.js +0 -1
  191. package/lib/src/themeStore.min.js +0 -1
  192. package/lib/src/useFns.min.js +0 -1
  193. package/lib/src/validators.min.js +0 -1
  194. package/lib/src/vm.min.js +0 -1
  195. package/lib/src/z-index.min.js +0 -1
@@ -1,39 +1,42 @@
1
- import XEUtils from 'xe-utils';
2
- export const baseUtils = {
3
- /**
4
- * 转成字符串
5
- */
6
- toString(content) {
7
- if (XEUtils.eqNull(content)) {
8
- return '';
9
- }
10
- return '' + content;
11
- },
12
- /**
13
- * 判断值为:'' | null | undefined 时都属于空值
14
- */
15
- isEmpty(value) {
16
- return value === null || value === undefined || value === '';
17
- },
18
- /**
19
- * 获取配置值,如果存在则返回,如果不存在则使用默认值
20
- */
21
- getDefVal(value, defVal) {
22
- return XEUtils.eqNull(value) ? defVal : value;
23
- },
24
- /**
25
- * 判断是否启用
26
- */
27
- isEnabled(conf) {
28
- return !!(conf && conf.enabled !== false);
29
- },
30
- /**
31
- * 用于开关类型的配置项
32
- * 局部启用规则:conf={}
33
- * 局部禁用规则:conf={enabled:false}
34
- * 全局默认启用规则:conf.enabled=true
35
- */
36
- hasEnableConf(conf, opts) {
37
- return !!(opts && (conf ? opts.enabled !== false : opts.enabled));
1
+ import XEUtils from "xe-utils";
2
+ const baseUtils = {
3
+ /**
4
+ * 转成字符串
5
+ */
6
+ toString(content) {
7
+ if (XEUtils.eqNull(content)) {
8
+ return "";
38
9
  }
10
+ return "" + content;
11
+ },
12
+ /**
13
+ * 判断值为:'' | null | undefined 时都属于空值
14
+ */
15
+ isEmpty(value) {
16
+ return value === null || value === void 0 || value === "";
17
+ },
18
+ /**
19
+ * 获取配置值,如果存在则返回,如果不存在则使用默认值
20
+ */
21
+ getDefVal(value, defVal) {
22
+ return XEUtils.eqNull(value) ? defVal : value;
23
+ },
24
+ /**
25
+ * 判断是否启用
26
+ */
27
+ isEnabled(conf) {
28
+ return !!(conf && conf.enabled !== false);
29
+ },
30
+ /**
31
+ * 用于开关类型的配置项
32
+ * 局部启用规则:conf={}
33
+ * 局部禁用规则:conf={enabled:false}
34
+ * 全局默认启用规则:conf.enabled=true
35
+ */
36
+ hasEnableConf(conf, opts) {
37
+ return !!(opts && (conf ? opts.enabled !== false : opts.enabled));
38
+ }
39
+ };
40
+ export {
41
+ baseUtils
39
42
  };
@@ -0,0 +1,2 @@
1
+ import { VxeGlobalClipboard } from '../../types';
2
+ export declare const clipboard: VxeGlobalClipboard;
@@ -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 = "4.4.42";
2
- export const VxeCore = {
3
- coreVersion,
4
- uiVersion: '',
5
- tableVersion: '',
6
- designVersion: '',
7
- ganttVersion: ''
1
+ const coreVersion = "4.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;