@vxe-ui/core 3.5.0 → 3.5.2

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/es/index.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare function use(Plugin: VxeUIPluginObject, options: any[]): import("
35
35
  permission: import("../types").VxeGlobalPermission;
36
36
  zIndex: import("../types").VxeZIndex;
37
37
  baseUtils: import("../types").VxeBaseUtils;
38
+ dbUtils: import("../types").VxeDBUtils;
38
39
  domUtils: import("../types").VxeDomUtils;
39
40
  scrollbarUtils: import("../types").VxeScrollbarUtils;
40
41
  popperUtils: import("../types").VxePopperUtils;
@@ -82,6 +83,7 @@ export declare const VxeUI: import("../types").VxeUIExport & {
82
83
  permission: import("../types").VxeGlobalPermission;
83
84
  zIndex: import("../types").VxeZIndex;
84
85
  baseUtils: import("../types").VxeBaseUtils;
86
+ dbUtils: import("../types").VxeDBUtils;
85
87
  domUtils: import("../types").VxeDomUtils;
86
88
  scrollbarUtils: import("../types").VxeScrollbarUtils;
87
89
  popperUtils: import("../types").VxePopperUtils;
@@ -111,6 +113,7 @@ export * from './src/clipboard';
111
113
  export * from './src/permission';
112
114
  export * from './src/z-index';
113
115
  export * from './src/base-utils';
116
+ export * from './src/db-utils';
114
117
  export * from './src/dom-utils';
115
118
  export * from './src/scrollbar-utils';
116
119
  export * from './src/popper-utils';
package/es/index.esm.js CHANGED
@@ -16,6 +16,7 @@ import { clipboard } from "./src/clipboard";
16
16
  import { permission } from "./src/permission";
17
17
  import { zIndex } from "./src/z-index";
18
18
  import { baseUtils } from "./src/base-utils";
19
+ import { dbUtils } from "./src/db-utils";
19
20
  import { domUtils } from "./src/dom-utils";
20
21
  import { scrollbarUtils } from "./src/scrollbar-utils";
21
22
  import { popperUtils } from "./src/popper-utils";
@@ -94,6 +95,7 @@ const VxeUI = Object.assign(VxeCore, {
94
95
  permission,
95
96
  zIndex,
96
97
  baseUtils,
98
+ dbUtils,
97
99
  domUtils,
98
100
  scrollbarUtils,
99
101
  popperUtils,
@@ -124,6 +126,7 @@ export * from "./src/clipboard";
124
126
  export * from "./src/permission";
125
127
  export * from "./src/z-index";
126
128
  export * from "./src/base-utils";
129
+ export * from "./src/db-utils";
127
130
  export * from "./src/dom-utils";
128
131
  export * from "./src/scrollbar-utils";
129
132
  export * from "./src/popper-utils";
package/es/index.js CHANGED
@@ -16,6 +16,7 @@ import { clipboard } from "./src/clipboard";
16
16
  import { permission } from "./src/permission";
17
17
  import { zIndex } from "./src/z-index";
18
18
  import { baseUtils } from "./src/base-utils";
19
+ import { dbUtils } from "./src/db-utils";
19
20
  import { domUtils } from "./src/dom-utils";
20
21
  import { scrollbarUtils } from "./src/scrollbar-utils";
21
22
  import { popperUtils } from "./src/popper-utils";
@@ -94,6 +95,7 @@ const VxeUI = Object.assign(VxeCore, {
94
95
  permission,
95
96
  zIndex,
96
97
  baseUtils,
98
+ dbUtils,
97
99
  domUtils,
98
100
  scrollbarUtils,
99
101
  popperUtils,
@@ -124,6 +126,7 @@ export * from "./src/clipboard";
124
126
  export * from "./src/permission";
125
127
  export * from "./src/z-index";
126
128
  export * from "./src/base-utils";
129
+ export * from "./src/db-utils";
127
130
  export * from "./src/dom-utils";
128
131
  export * from "./src/scrollbar-utils";
129
132
  export * from "./src/popper-utils";
package/es/src/core.js CHANGED
@@ -1,4 +1,4 @@
1
- const coreVersion = "3.5.0";
1
+ const coreVersion = "3.5.2";
2
2
  const VxeCore = {
3
3
  coreVersion,
4
4
  uiVersion: "",
@@ -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", "vxe_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
+ };
package/es/src/log.js CHANGED
@@ -6,7 +6,7 @@ function createLog(type, name) {
6
6
  return msg;
7
7
  };
8
8
  }
9
- const version = "3.5.0";
9
+ const version = "3.5.2";
10
10
  const log = {
11
11
  create: createLog,
12
12
  warn: createLog("warn", `v${version}`),
@@ -57,6 +57,7 @@ var import_clipboard = require("./src/clipboard");
57
57
  var import_permission = require("./src/permission");
58
58
  var import_z_index = require("./src/z-index");
59
59
  var import_base_utils = require("./src/base-utils");
60
+ var import_db_utils = require("./src/db-utils");
60
61
  var import_dom_utils = require("./src/dom-utils");
61
62
  var import_scrollbar_utils = require("./src/scrollbar-utils");
62
63
  var import_popper_utils = require("./src/popper-utils");
@@ -81,6 +82,7 @@ __reExport(index_exports, require("./src/clipboard"), module.exports);
81
82
  __reExport(index_exports, require("./src/permission"), module.exports);
82
83
  __reExport(index_exports, require("./src/z-index"), module.exports);
83
84
  __reExport(index_exports, require("./src/base-utils"), module.exports);
85
+ __reExport(index_exports, require("./src/db-utils"), module.exports);
84
86
  __reExport(index_exports, require("./src/dom-utils"), module.exports);
85
87
  __reExport(index_exports, require("./src/scrollbar-utils"), module.exports);
86
88
  __reExport(index_exports, require("./src/popper-utils"), module.exports);
@@ -159,6 +161,7 @@ const VxeUI = Object.assign(import_core.VxeCore, {
159
161
  permission: import_permission.permission,
160
162
  zIndex: import_z_index.zIndex,
161
163
  baseUtils: import_base_utils.baseUtils,
164
+ dbUtils: import_db_utils.dbUtils,
162
165
  domUtils: import_dom_utils.domUtils,
163
166
  scrollbarUtils: import_scrollbar_utils.scrollbarUtils,
164
167
  popperUtils: import_popper_utils.popperUtils,
package/lib/index.js CHANGED
@@ -57,6 +57,7 @@ var import_clipboard = require("./src/clipboard");
57
57
  var import_permission = require("./src/permission");
58
58
  var import_z_index = require("./src/z-index");
59
59
  var import_base_utils = require("./src/base-utils");
60
+ var import_db_utils = require("./src/db-utils");
60
61
  var import_dom_utils = require("./src/dom-utils");
61
62
  var import_scrollbar_utils = require("./src/scrollbar-utils");
62
63
  var import_popper_utils = require("./src/popper-utils");
@@ -81,6 +82,7 @@ __reExport(index_exports, require("./src/clipboard"), module.exports);
81
82
  __reExport(index_exports, require("./src/permission"), module.exports);
82
83
  __reExport(index_exports, require("./src/z-index"), module.exports);
83
84
  __reExport(index_exports, require("./src/base-utils"), module.exports);
85
+ __reExport(index_exports, require("./src/db-utils"), module.exports);
84
86
  __reExport(index_exports, require("./src/dom-utils"), module.exports);
85
87
  __reExport(index_exports, require("./src/scrollbar-utils"), module.exports);
86
88
  __reExport(index_exports, require("./src/popper-utils"), module.exports);
@@ -159,6 +161,7 @@ const VxeUI = Object.assign(import_core.VxeCore, {
159
161
  permission: import_permission.permission,
160
162
  zIndex: import_z_index.zIndex,
161
163
  baseUtils: import_base_utils.baseUtils,
164
+ dbUtils: import_db_utils.dbUtils,
162
165
  domUtils: import_dom_utils.domUtils,
163
166
  scrollbarUtils: import_scrollbar_utils.scrollbarUtils,
164
167
  popperUtils: import_popper_utils.popperUtils,