zf-dbs 2.0.1 → 2.0.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/dist/index.d.ts CHANGED
@@ -183,9 +183,32 @@ readonly appElement: HTMLElement | null;
183
183
  readonly appViewElement: HTMLElement | null;
184
184
  }>;
185
185
 
186
- export declare function usePolling<T, D = undefined, Config extends UsePollingConfig<T> = UsePollingConfig<T>>(listener: UsePollingListener<T>, defaultValue?: UsePollingDefaultValue<D>, config?: Config): UsePollingResponse<T, Config, D>;
186
+ /**
187
+ * 轮询 Hook
188
+ *
189
+ * 类型推导效果:
190
+ * - listener 返回 Promise<User>,state => User | D
191
+ * - defaultValue 不传,state => User | undefined
192
+ * - defaultValue 传 0,state => User | 0
193
+ *
194
+ * setConfig 只允许修改运行时安全项:
195
+ * - delay
196
+ * - leading
197
+ * - resetOnExecute
198
+ * - throwError
199
+ * - onError
200
+ * - onSuccess
201
+ *
202
+ * 不允许修改:
203
+ * - shallow
204
+ * - immediate
205
+ */
206
+ export declare function usePolling<TListener extends UsePollingListener<any>, D = undefined, TConfig extends UsePollingConfig<UsePollingResolvedValue<TListener>> = UsePollingConfig<UsePollingResolvedValue<TListener>>>(listener: TListener, defaultValue?: UsePollingDefaultValue<D>, config?: TConfig): UsePollingResponse<UsePollingResolvedValue<TListener>, TConfig, D>;
187
207
 
188
- declare type UsePollingConfig<T> = {
208
+ /**
209
+ * 原始配置
210
+ */
211
+ declare type UsePollingConfig<TResult> = {
189
212
  delay?: number;
190
213
  immediate?: boolean;
191
214
  leading?: boolean;
@@ -193,43 +216,95 @@ declare type UsePollingConfig<T> = {
193
216
  resetOnExecute?: boolean;
194
217
  throwError?: boolean;
195
218
  onError?: (error: unknown) => void;
196
- onSuccess?: (result: T) => void;
219
+ onSuccess?: (result: TResult) => void;
197
220
  };
198
221
 
222
+ /**
223
+ * 默认值
224
+ * 允许不传,也允许显式传 undefined
225
+ */
199
226
  declare type UsePollingDefaultValue<T = undefined> = T | undefined;
200
227
 
201
- declare type UsePollingListener<T> = () => Promise<T> | T;
228
+ /**
229
+ * 轮询监听器
230
+ * 支持同步值,也支持 Promise
231
+ */
232
+ declare type UsePollingListener<TResult> = () => TResult | Promise<TResult>;
202
233
 
203
- export declare function usePollingRef<T, D = undefined>(listener: () => Promise<T> | T, defaultValue?: D, config?: UsePollingConfig<T>): globalThis.Ref<UsePollingStateType<T, D>>;
234
+ /**
235
+ * 允许运行时修改的配置
236
+ * shallow / immediate 不允许改
237
+ */
238
+ declare type UsePollingMutableConfig<TResult> = Omit<UsePollingConfig<TResult>, 'shallow' | 'immediate'>;
239
+
240
+ /**
241
+ * 仅返回 state 的版本
242
+ * 参数、类型推导、默认值行为都和 usePolling 完全一致
243
+ */
244
+ export declare function usePollingRef<TListener extends UsePollingListener<any>, D = undefined, TConfig extends UsePollingConfig<Awaited<ReturnType<TListener>>> = UsePollingConfig<Awaited<ReturnType<TListener>>>>(listener: TListener, defaultValue?: UsePollingDefaultValue<D>, config?: TConfig): UsePollingResponse<Awaited<ReturnType<TListener>>, TConfig, D>['state'];
204
245
 
205
- declare type UsePollingResponse<T, Config extends UsePollingConfig<T>, D = undefined> = {
206
- state: UsePollingStateTypeRef<T, Config, D>;
246
+ /**
247
+ * listener 的最终返回值
248
+ * Promise<T> 会自动解包成 T
249
+ */
250
+ declare type UsePollingResolvedValue<TListener extends UsePollingListener<any>> = Awaited<ReturnType<TListener>>;
251
+
252
+ /**
253
+ * 对外返回值
254
+ */
255
+ declare type UsePollingResponse<TResult, TConfig extends UsePollingConfig<TResult>, D = undefined> = {
256
+ state: UsePollingStateTypeRef<TResult, TConfig, D>;
207
257
  isLoading: Ref_2<boolean>;
208
258
  error: Ref_2<unknown>;
209
- execute: UsePollingResponseExecute<T>;
259
+ execute: UsePollingResponseExecute<TResult>;
210
260
  pause: () => void;
211
261
  resume: UsePollingResponseResume;
212
262
  reset: () => void;
263
+ setConfig: (config: UsePollingSetConfig<TResult>) => void;
213
264
  };
214
265
 
215
- declare type UsePollingResponseExecute<T> = (config?: UsePollingResponseExecuteConfig<T>) => Promise<void>;
266
+ /**
267
+ * 主动执行
268
+ */
269
+ declare type UsePollingResponseExecute<TResult> = (config?: UsePollingResponseExecuteConfig<TResult>) => Promise<void>;
216
270
 
217
- declare type UsePollingResponseExecuteConfig<T> = {
271
+ /**
272
+ * 执行时可覆盖的配置
273
+ */
274
+ declare type UsePollingResponseExecuteConfig<TResult> = {
218
275
  resetOnExecute?: boolean;
219
276
  throwError?: boolean;
220
277
  onError?: (error: unknown) => void;
221
- onSuccess?: (result: T) => void;
278
+ onSuccess?: (result: TResult) => void;
222
279
  };
223
280
 
281
+ /**
282
+ * 继续轮询
283
+ */
224
284
  declare type UsePollingResponseResume = (config?: UsePollingResponseResumeConfig) => void;
225
285
 
286
+ /**
287
+ * 继续轮询时的配置
288
+ */
226
289
  declare type UsePollingResponseResumeConfig = {
227
290
  leading?: boolean;
228
291
  };
229
292
 
230
- declare type UsePollingStateType<T, D = undefined> = T | D | undefined;
293
+ /**
294
+ * setConfig 的入参
295
+ */
296
+ declare type UsePollingSetConfig<TResult> = Partial<UsePollingMutableConfig<TResult>>;
297
+
298
+ /**
299
+ * state 的值类型
300
+ * 结果类型 + 默认值类型
301
+ */
302
+ declare type UsePollingStateType<TResult, D = undefined> = TResult | D;
231
303
 
232
- declare type UsePollingStateTypeRef<T, Config extends UsePollingConfig<T>, D = undefined> = Config['shallow'] extends true ? ShallowRef<UsePollingStateType<T, D>> : Ref_2<UsePollingStateType<T, D>>;
304
+ /**
305
+ * shallow 模式下返回 ShallowRef,否则返回 Ref
306
+ */
307
+ declare type UsePollingStateTypeRef<TResult, TConfig extends UsePollingConfig<TResult>, D = undefined> = TConfig['shallow'] extends true ? ShallowRef<UsePollingStateType<TResult, D>> : Ref_2<UsePollingStateType<TResult, D>>;
233
308
 
234
309
  export declare const ZfApp: __VLS_WithTemplateSlots<DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<globalThis.ExtractPropTypes<{}>>, {}, {}>, {
235
310
  default?(_: {}): any;
package/dist/index.mjs CHANGED
@@ -1,22 +1,17 @@
1
- import { a as b, g as h, m as _, t as E, _ as y } from "./chunks/qN7meZTV.mjs";
2
- import { z as k, d as B, u as D, b as G } from "./chunks/qN7meZTV.mjs";
3
- import { _ as x } from "./chunks/Ck0Cdfr_.mjs";
4
- import { _ as C } from "./chunks/BHHE86vT.mjs";
5
- import { z as Q } from "./chunks/BHHE86vT.mjs";
6
- import { ref as a, shallowRef as O, onMounted as A } from "vue";
7
- import { ElNotification as q } from "element-plus";
8
- import { Z as X } from "./chunks/DbOTUn3A.mjs";
9
- const R = function(e) {
1
+ import { a as b, g as O, m as A, t as S, _ as q } from "./chunks/qN7meZTV.mjs";
2
+ import { z as X, d as Y, u as ee, b as oe } from "./chunks/qN7meZTV.mjs";
3
+ import { _ as j } from "./chunks/Ck0Cdfr_.mjs";
4
+ import { _ as N } from "./chunks/BHHE86vT.mjs";
5
+ import { z as ne } from "./chunks/BHHE86vT.mjs";
6
+ import { ref as i, shallowRef as z, onMounted as P, onBeforeUnmount as T } from "vue";
7
+ import { ElNotification as U } from "element-plus";
8
+ import { Z as se } from "./chunks/DbOTUn3A.mjs";
9
+ const L = function(e) {
10
10
  return e;
11
11
  };
12
- function S() {
13
- return new Promise((e) => {
14
- requestAnimationFrame(e);
15
- });
16
- }
17
- function j(e, t, o) {
18
- o = Object.assign({
19
- delay: 3e3,
12
+ function Z() {
13
+ return {
14
+ delay: b.value?.pollingInterval || 3e3,
20
15
  immediate: !0,
21
16
  leading: !0,
22
17
  resetOnExecute: !1,
@@ -26,146 +21,173 @@ function j(e, t, o) {
26
21
  },
27
22
  onSuccess: () => {
28
23
  }
29
- }, o);
30
- const n = a(0), r = o.shallow ? O(t) : a(t), s = a(!1), c = a(null), p = async (v) => {
31
- const f = Object.assign({}, o, v);
32
- n.value++;
33
- const w = n.value;
34
- s.value = !0, f?.resetOnExecute && (r.value = t);
24
+ };
25
+ }
26
+ function H() {
27
+ return new Promise((e) => {
28
+ requestAnimationFrame(() => e());
29
+ });
30
+ }
31
+ function I(e, o, t) {
32
+ const n = Object.assign(Z(), t ?? {}), r = i(0), f = o, p = n.shallow ? z(f) : i(f), d = i(!1), v = i(null), l = i(null), u = i(!0), m = () => {
33
+ l.value !== null && (clearTimeout(l.value), l.value = null);
34
+ }, C = (c) => {
35
+ Object.assign(n, c);
36
+ }, w = async (c) => {
37
+ const g = Object.assign(
38
+ {
39
+ resetOnExecute: n.resetOnExecute,
40
+ throwError: n.throwError,
41
+ onError: n.onError,
42
+ onSuccess: n.onSuccess
43
+ },
44
+ c ?? {}
45
+ );
46
+ r.value += 1;
47
+ const E = r.value;
48
+ d.value = !0, g.resetOnExecute && (p.value = o);
35
49
  try {
36
- const l = await Promise.resolve(e());
37
- w === n.value && (c.value = null, r.value = l, f?.onSuccess?.(l));
38
- } catch (l) {
39
- if (w === n.value && (c.value = l, f?.onError?.(l), f?.throwError))
40
- throw l;
50
+ const s = await Promise.resolve(e());
51
+ E === r.value && (v.value = null, p.value = s, g.onSuccess?.(s));
52
+ } catch (s) {
53
+ if (E === r.value && (v.value = s, g.onError?.(s), g.throwError))
54
+ throw s;
41
55
  } finally {
42
- w === n.value && (s.value = !1);
56
+ E === r.value && (d.value = !1);
43
57
  }
44
- }, i = a(null), d = () => {
45
- i.value && clearInterval(i.value), i.value = null;
46
- }, m = (v = { leading: o?.leading }) => {
47
- d(), v?.leading && p(), i.value || (i.value = setTimeout(async () => {
48
- try {
49
- await p(), await S();
50
- } finally {
51
- i.value && m({ leading: !1 });
52
- }
53
- }, o?.delay));
54
- }, g = () => {
55
- d(), n.value = 0, r.value = t, s.value = !1, c.value = null, o?.immediate && m();
58
+ }, _ = () => {
59
+ m(), !u.value && (l.value = setTimeout(async () => {
60
+ if (l.value = null, !u.value)
61
+ try {
62
+ await w();
63
+ } catch {
64
+ } finally {
65
+ await H(), u.value || _();
66
+ }
67
+ }, n.delay));
68
+ }, h = () => {
69
+ u.value = !0, m();
70
+ }, x = (c = { leading: n.leading }) => {
71
+ u.value = !1, m(), c.leading && w().catch(() => {
72
+ }), _();
73
+ }, y = () => {
74
+ h(), r.value = 0, p.value = o, d.value = !1, v.value = null, n.immediate && x();
56
75
  };
57
- return A(() => {
58
- g();
76
+ return P(() => {
77
+ y();
78
+ }), T(() => {
79
+ h();
59
80
  }), {
60
- state: r,
61
- isLoading: s,
62
- error: c,
63
- execute: p,
64
- pause: d,
65
- resume: m,
66
- reset: g
81
+ state: p,
82
+ isLoading: d,
83
+ error: v,
84
+ execute: w,
85
+ pause: h,
86
+ resume: x,
87
+ reset: y,
88
+ setConfig: C
67
89
  };
68
90
  }
69
- function T(e, t, o) {
70
- return j(e, t, o).state;
91
+ function k(e, o, t) {
92
+ return I(e, o, t).state;
71
93
  }
72
- function z() {
94
+ function R() {
73
95
  if (!b.value)
74
96
  throw new Error("请先调用 defineAppConfig 进行配置");
75
97
  return b.value;
76
98
  }
77
- const u = Object.assign(function(e) {
78
- return q({
99
+ const a = Object.assign(function(e) {
100
+ return U({
79
101
  ...e,
80
- appendTo: h().appViewElement || document.body || void 0
102
+ appendTo: O().appViewElement || document.body || void 0
81
103
  });
82
104
  }, {
83
105
  success(e) {
84
- return u({
106
+ return a({
85
107
  ...e,
86
108
  type: "success"
87
109
  });
88
110
  },
89
111
  info(e) {
90
- return u({
112
+ return a({
91
113
  ...e,
92
114
  type: "info"
93
115
  });
94
116
  },
95
117
  warning(e) {
96
- return u({
118
+ return a({
97
119
  ...e,
98
120
  type: "warning"
99
121
  });
100
122
  },
101
123
  error(e) {
102
- return u({
124
+ return a({
103
125
  ...e,
104
126
  type: "error"
105
127
  });
106
128
  }
107
- }), $ = _(() => {
108
- const e = z();
129
+ }), G = A(() => {
130
+ const e = R();
109
131
  return {
110
132
  ...e.request,
111
- errorHandle(t, o, n) {
112
- if (e.request.showErrorMessage && u.error({ message: o }), e.request.errorHandle)
113
- return e.request.errorHandle(t, o, n);
133
+ errorHandle(o, t, n) {
134
+ if (e.request.showErrorMessage && a.error({ message: t }), e.request.errorHandle)
135
+ return e.request.errorHandle(o, t, n);
114
136
  }
115
137
  };
116
138
  });
117
- class N extends E {
139
+ class $ extends S {
118
140
  /**
119
141
  * 发送事件
120
142
  * @param {string} name 事件名称
121
143
  * @param {unknown[]} args 参数
122
144
  */
123
- emit(t, ...o) {
124
- return o = o.map((n) => JSON.parse(JSON.stringify(n))), console.log(`%c发送UE事件 %c${t}`, "color: #529b2e; font-weight: bold;", "color: #337ecc", ...o), window?.ue?.web?.[t]?.(...o);
145
+ emit(o, ...t) {
146
+ return t = t.map((n) => JSON.parse(JSON.stringify(n))), console.log(`%c发送UE事件 %c${o}`, "color: #529b2e; font-weight: bold;", "color: #337ecc", ...t), window?.ue?.web?.[o]?.(...t);
125
147
  }
126
148
  /**
127
149
  * 注册事件
128
150
  * @param {string} name 事件名称
129
151
  * @param {UnknownFunction} listener 事件处理函数
130
152
  */
131
- on(t, o) {
132
- return console.log(`%c注册UE事件 %c${t}`, "color: #b88230; font-weight: bold;", "color: #337ecc"), window[t] || (window[t] = this.dispatchEvent.bind(this, t)), super.on(t, o);
153
+ on(o, t) {
154
+ return console.log(`%c注册UE事件 %c${o}`, "color: #b88230; font-weight: bold;", "color: #337ecc"), window[o] || (window[o] = this.dispatchEvent.bind(this, o)), super.on(o, t);
133
155
  }
134
156
  /**
135
157
  * 注销事件
136
158
  * @param {string} name 事件名称
137
159
  * @param {UnknownFunction} listener 事件处理函数
138
160
  */
139
- off(t, o) {
140
- console.log(`%c注销UE事件 %c${t}`, "color: #909399; font-weight: bold;", "color: #337ecc");
141
- const n = super.off(t, o);
142
- return this.listeners(t).length || delete window[t], n;
161
+ off(o, t) {
162
+ console.log(`%c注销UE事件 %c${o}`, "color: #909399; font-weight: bold;", "color: #337ecc");
163
+ const n = super.off(o, t);
164
+ return this.listeners(o).length || delete window[o], n;
143
165
  }
144
166
  }
145
- const F = new N(), J = {
167
+ const K = new $(), Q = {
146
168
  install(e) {
147
- Object.entries(/* @__PURE__ */ Object.assign({ "./components/zf-app/index.ts": y, "./components/zf-scale-container/index.ts": x, "./components/zf-tween-number/index.ts": C })).forEach(([o, n]) => {
148
- const r = n.default, s = o.split("/")[2];
149
- e.component(s, r);
169
+ Object.entries(/* @__PURE__ */ Object.assign({ "./components/zf-app/index.ts": q, "./components/zf-scale-container/index.ts": j, "./components/zf-tween-number/index.ts": N })).forEach(([t, n]) => {
170
+ const r = n.default, f = t.split("/")[2];
171
+ e.component(f, r);
150
172
  });
151
173
  }
152
174
  };
153
175
  export {
154
- N as Ue,
155
- k as ZfApp,
156
- X as ZfScaleContainer,
157
- Q as ZfTweenNumber,
158
- J as default,
159
- B as defineAppConfig,
160
- _ as defineRequest,
161
- R as defineService,
162
- z as getAppConfig,
163
- h as getAppInfo,
164
- u as notify,
165
- $ as request,
166
- F as ue,
167
- D as useAppConfig,
168
- G as useAppInfo,
169
- j as usePolling,
170
- T as usePollingRef
176
+ $ as Ue,
177
+ X as ZfApp,
178
+ se as ZfScaleContainer,
179
+ ne as ZfTweenNumber,
180
+ Q as default,
181
+ Y as defineAppConfig,
182
+ A as defineRequest,
183
+ L as defineService,
184
+ R as getAppConfig,
185
+ O as getAppInfo,
186
+ a as notify,
187
+ G as request,
188
+ K as ue,
189
+ ee as useAppConfig,
190
+ oe as useAppInfo,
191
+ I as usePolling,
192
+ k as usePollingRef
171
193
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "zf-dbs",
3
3
  "type": "module",
4
4
  "description": "",
5
- "version": "2.0.1",
5
+ "version": "2.0.2",
6
6
  "main": "./dist/index.mjs",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",