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