@vunk/plus 1.2.2 → 1.3.0

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 (119) hide show
  1. package/components/SendOutlined.mjs +1 -1
  2. package/components/agent-chat-provider/index.mjs +789 -0
  3. package/components/avatar/index.mjs +2 -2
  4. package/components/broadcasting-markdown/index.css +3 -0
  5. package/components/broadcasting-markdown/index.mjs +637 -0
  6. package/components/bubble-list/index.css +18 -0
  7. package/components/bubble-list/index.mjs +386 -0
  8. package/components/bubble-templates/index.css +18 -0
  9. package/components/bubble-templates/index.mjs +258 -0
  10. package/components/chat-independent/index.css +47 -0
  11. package/components/chat-independent/index.mjs +184 -0
  12. package/components/index.mjs +35980 -0
  13. package/components/lottie-animation/index.mjs +2 -2
  14. package/components/monaco-editor/index.mjs +2 -2
  15. package/components/monaco-environment/index.mjs +1 -1
  16. package/components/recorder-button/index.css +7 -10
  17. package/components/recorder-button/index.mjs +115 -83
  18. package/components/routes-menu-content/index.mjs +5 -5
  19. package/components/sender/index.css +2 -5
  20. package/components/sender/index.mjs +31 -12
  21. package/components/speech-button/index.mjs +6 -13
  22. package/components/table-columns/index.mjs +3 -6
  23. package/components/tables-v1/index.mjs +3 -3
  24. package/components/tables-v1-checkbox/index.mjs +269 -33
  25. package/components/typing-markdown/index.mjs +128 -33
  26. package/components/vditor/index.mjs +5 -9
  27. package/composables/el-breakpoints/index.d.ts +1 -1
  28. package/composables/recorder/index.mjs +751 -182
  29. package/icons/_plugin-vue_export-helper.mjs +9 -0
  30. package/icons/end/index.d.ts +4 -0
  31. package/icons/end/index.mjs +36 -0
  32. package/icons/end/src/avatar.d.ts +12 -0
  33. package/icons/end/src/icon.d.ts +57 -0
  34. package/icons/keyboard/index.d.ts +4 -0
  35. package/icons/keyboard/index.mjs +36 -0
  36. package/icons/keyboard/src/avatar.d.ts +12 -0
  37. package/icons/keyboard/src/icon.d.ts +57 -0
  38. package/icons/start/index.d.ts +4 -0
  39. package/icons/start/index.mjs +36 -0
  40. package/icons/start/src/avatar.d.ts +12 -0
  41. package/icons/start/src/icon.d.ts +57 -0
  42. package/icons/voice/index.d.ts +4 -0
  43. package/icons/voice/index.mjs +51 -0
  44. package/icons/voice/src/avatar.d.ts +12 -0
  45. package/icons/voice/src/icon.d.ts +57 -0
  46. package/icons/voice/src/index.vue.d.ts +4 -0
  47. package/index.css +99 -15
  48. package/package.json +51 -7
  49. package/components/avatar/index.d.ts +0 -4
  50. package/components/avatar/src/ctx.d.ts +0 -18
  51. package/components/avatar/src/index.vue.d.ts +0 -180
  52. package/components/avatar/src/types.d.ts +0 -1
  53. package/components/lottie-animation/index.d.ts +0 -4
  54. package/components/lottie-animation/src/ctx.d.ts +0 -10
  55. package/components/lottie-animation/src/index.vue.d.ts +0 -21
  56. package/components/lottie-animation/src/types.d.ts +0 -4
  57. package/components/monaco-editor/index.d.ts +0 -5
  58. package/components/monaco-editor/src/ctx.d.ts +0 -23
  59. package/components/monaco-editor/src/index.vue.d.ts +0 -40
  60. package/components/monaco-editor/src/types.d.ts +0 -1
  61. package/components/monaco-environment/index.d.ts +0 -4
  62. package/components/monaco-environment/src/ctx.d.ts +0 -8
  63. package/components/monaco-environment/src/index.vue.d.ts +0 -2
  64. package/components/monaco-environment/src/types.d.ts +0 -1
  65. package/components/recorder-button/index.d.ts +0 -4
  66. package/components/recorder-button/src/ctx.d.ts +0 -19
  67. package/components/recorder-button/src/index.vue.d.ts +0 -309
  68. package/components/recorder-button/src/speech-to-text.d.ts +0 -1
  69. package/components/recorder-button/src/types.d.ts +0 -6
  70. package/components/routes-menu-content/index.d.ts +0 -4
  71. package/components/routes-menu-content/src/ctx.d.ts +0 -17
  72. package/components/routes-menu-content/src/index.vue.d.ts +0 -350
  73. package/components/routes-menu-content/src/item/core/ctx.d.ts +0 -18
  74. package/components/routes-menu-content/src/item/core/index.vue.d.ts +0 -185
  75. package/components/routes-menu-content/src/item/ctx.d.ts +0 -14
  76. package/components/routes-menu-content/src/item/index.vue.d.ts +0 -316
  77. package/components/routes-menu-content/src/types.d.ts +0 -1
  78. package/components/sender/index.d.ts +0 -4
  79. package/components/sender/src/SenderHeader.vue.d.ts +0 -270
  80. package/components/sender/src/ctx.d.ts +0 -38
  81. package/components/sender/src/index.vue.d.ts +0 -732
  82. package/components/sender/src/types.d.ts +0 -1
  83. package/components/speech-button/index.d.ts +0 -4
  84. package/components/speech-button/src/LoadingIcon.vue.d.ts +0 -2
  85. package/components/speech-button/src/RecordingIcon.vue.d.ts +0 -2
  86. package/components/speech-button/src/ctx.d.ts +0 -10
  87. package/components/speech-button/src/index.vue.d.ts +0 -22
  88. package/components/speech-button/src/types.d.ts +0 -1
  89. package/components/table-columns/index.d.ts +0 -5
  90. package/components/table-columns/src/ctx.d.ts +0 -66
  91. package/components/table-columns/src/el-ctx.d.ts +0 -63
  92. package/components/table-columns/src/index.vue.d.ts +0 -280
  93. package/components/table-columns/src/types.d.ts +0 -21
  94. package/components/tables-v1/index.d.ts +0 -5
  95. package/components/tables-v1/src/ctx.d.ts +0 -283
  96. package/components/tables-v1/src/el-ctx.d.ts +0 -272
  97. package/components/tables-v1/src/index.vue.d.ts +0 -2997
  98. package/components/tables-v1/src/types.d.ts +0 -4
  99. package/components/tables-v1-checkbox/index.d.ts +0 -5
  100. package/components/tables-v1-checkbox/src/ctx.d.ts +0 -323
  101. package/components/tables-v1-checkbox/src/index.vue.d.ts +0 -3788
  102. package/components/tables-v1-checkbox/src/types.d.ts +0 -1
  103. package/components/typing-markdown/index.d.ts +0 -4
  104. package/components/typing-markdown/src/core.d.ts +0 -3
  105. package/components/typing-markdown/src/ctx.d.ts +0 -33
  106. package/components/typing-markdown/src/index.vue.d.ts +0 -57
  107. package/components/typing-markdown/src/types.d.ts +0 -1
  108. package/components/vditor/index.d.ts +0 -5
  109. package/components/vditor/src/ctx.d.ts +0 -37
  110. package/components/vditor/src/handle-fullscreen.vue.d.ts +0 -18
  111. package/components/vditor/src/handle-value.vue.d.ts +0 -18
  112. package/components/vditor/src/index.vue.d.ts +0 -144
  113. package/components/vditor/src/types.d.ts +0 -9
  114. package/components/vditor/src/use.d.ts +0 -4
  115. package/fetch/PlusFetch/index.d.ts +0 -14
  116. package/fetch/PlusFetch/index.mjs +0 -638
  117. package/fetch/PlusFetch/types.d.ts +0 -54
  118. package/fetch/index.d.ts +0 -1
  119. package/fetch/index.mjs +0 -5
@@ -1,638 +0,0 @@
1
- import { RestFetch } from '@vunk/shared/fetch';
2
- import { ElMessage, ElLoading, ElLoadingService } from 'element-plus';
3
- import { sleep } from '@vunk/shared/promise';
4
- import { isPlainObject } from '@vunk/shared/object';
5
-
6
- /** Detect free variable `global` from Node.js. */
7
- var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
8
-
9
- /** Detect free variable `self`. */
10
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
11
-
12
- /** Used as a reference to the global object. */
13
- var root = freeGlobal || freeSelf || Function('return this')();
14
-
15
- /** Built-in value references. */
16
- var Symbol = root.Symbol;
17
-
18
- /** Used for built-in method references. */
19
- var objectProto$1 = Object.prototype;
20
-
21
- /** Used to check objects for own properties. */
22
- var hasOwnProperty = objectProto$1.hasOwnProperty;
23
-
24
- /**
25
- * Used to resolve the
26
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
27
- * of values.
28
- */
29
- var nativeObjectToString$1 = objectProto$1.toString;
30
-
31
- /** Built-in value references. */
32
- var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined;
33
-
34
- /**
35
- * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
36
- *
37
- * @private
38
- * @param {*} value The value to query.
39
- * @returns {string} Returns the raw `toStringTag`.
40
- */
41
- function getRawTag(value) {
42
- var isOwn = hasOwnProperty.call(value, symToStringTag$1),
43
- tag = value[symToStringTag$1];
44
-
45
- try {
46
- value[symToStringTag$1] = undefined;
47
- var unmasked = true;
48
- } catch (e) {}
49
-
50
- var result = nativeObjectToString$1.call(value);
51
- if (unmasked) {
52
- if (isOwn) {
53
- value[symToStringTag$1] = tag;
54
- } else {
55
- delete value[symToStringTag$1];
56
- }
57
- }
58
- return result;
59
- }
60
-
61
- /** Used for built-in method references. */
62
- var objectProto = Object.prototype;
63
-
64
- /**
65
- * Used to resolve the
66
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
67
- * of values.
68
- */
69
- var nativeObjectToString = objectProto.toString;
70
-
71
- /**
72
- * Converts `value` to a string using `Object.prototype.toString`.
73
- *
74
- * @private
75
- * @param {*} value The value to convert.
76
- * @returns {string} Returns the converted string.
77
- */
78
- function objectToString(value) {
79
- return nativeObjectToString.call(value);
80
- }
81
-
82
- /** `Object#toString` result references. */
83
- var nullTag = '[object Null]',
84
- undefinedTag = '[object Undefined]';
85
-
86
- /** Built-in value references. */
87
- var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
88
-
89
- /**
90
- * The base implementation of `getTag` without fallbacks for buggy environments.
91
- *
92
- * @private
93
- * @param {*} value The value to query.
94
- * @returns {string} Returns the `toStringTag`.
95
- */
96
- function baseGetTag(value) {
97
- if (value == null) {
98
- return value === undefined ? undefinedTag : nullTag;
99
- }
100
- return (symToStringTag && symToStringTag in Object(value))
101
- ? getRawTag(value)
102
- : objectToString(value);
103
- }
104
-
105
- /**
106
- * Checks if `value` is object-like. A value is object-like if it's not `null`
107
- * and has a `typeof` result of "object".
108
- *
109
- * @static
110
- * @memberOf _
111
- * @since 4.0.0
112
- * @category Lang
113
- * @param {*} value The value to check.
114
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
115
- * @example
116
- *
117
- * _.isObjectLike({});
118
- * // => true
119
- *
120
- * _.isObjectLike([1, 2, 3]);
121
- * // => true
122
- *
123
- * _.isObjectLike(_.noop);
124
- * // => false
125
- *
126
- * _.isObjectLike(null);
127
- * // => false
128
- */
129
- function isObjectLike(value) {
130
- return value != null && typeof value == 'object';
131
- }
132
-
133
- /** `Object#toString` result references. */
134
- var symbolTag = '[object Symbol]';
135
-
136
- /**
137
- * Checks if `value` is classified as a `Symbol` primitive or object.
138
- *
139
- * @static
140
- * @memberOf _
141
- * @since 4.0.0
142
- * @category Lang
143
- * @param {*} value The value to check.
144
- * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
145
- * @example
146
- *
147
- * _.isSymbol(Symbol.iterator);
148
- * // => true
149
- *
150
- * _.isSymbol('abc');
151
- * // => false
152
- */
153
- function isSymbol(value) {
154
- return typeof value == 'symbol' ||
155
- (isObjectLike(value) && baseGetTag(value) == symbolTag);
156
- }
157
-
158
- /** Used to match a single whitespace character. */
159
- var reWhitespace = /\s/;
160
-
161
- /**
162
- * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
163
- * character of `string`.
164
- *
165
- * @private
166
- * @param {string} string The string to inspect.
167
- * @returns {number} Returns the index of the last non-whitespace character.
168
- */
169
- function trimmedEndIndex(string) {
170
- var index = string.length;
171
-
172
- while (index-- && reWhitespace.test(string.charAt(index))) {}
173
- return index;
174
- }
175
-
176
- /** Used to match leading whitespace. */
177
- var reTrimStart = /^\s+/;
178
-
179
- /**
180
- * The base implementation of `_.trim`.
181
- *
182
- * @private
183
- * @param {string} string The string to trim.
184
- * @returns {string} Returns the trimmed string.
185
- */
186
- function baseTrim(string) {
187
- return string
188
- ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
189
- : string;
190
- }
191
-
192
- /**
193
- * Checks if `value` is the
194
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
195
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
196
- *
197
- * @static
198
- * @memberOf _
199
- * @since 0.1.0
200
- * @category Lang
201
- * @param {*} value The value to check.
202
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
203
- * @example
204
- *
205
- * _.isObject({});
206
- * // => true
207
- *
208
- * _.isObject([1, 2, 3]);
209
- * // => true
210
- *
211
- * _.isObject(_.noop);
212
- * // => true
213
- *
214
- * _.isObject(null);
215
- * // => false
216
- */
217
- function isObject(value) {
218
- var type = typeof value;
219
- return value != null && (type == 'object' || type == 'function');
220
- }
221
-
222
- /** Used as references for various `Number` constants. */
223
- var NAN = 0 / 0;
224
-
225
- /** Used to detect bad signed hexadecimal string values. */
226
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
227
-
228
- /** Used to detect binary string values. */
229
- var reIsBinary = /^0b[01]+$/i;
230
-
231
- /** Used to detect octal string values. */
232
- var reIsOctal = /^0o[0-7]+$/i;
233
-
234
- /** Built-in method references without a dependency on `root`. */
235
- var freeParseInt = parseInt;
236
-
237
- /**
238
- * Converts `value` to a number.
239
- *
240
- * @static
241
- * @memberOf _
242
- * @since 4.0.0
243
- * @category Lang
244
- * @param {*} value The value to process.
245
- * @returns {number} Returns the number.
246
- * @example
247
- *
248
- * _.toNumber(3.2);
249
- * // => 3.2
250
- *
251
- * _.toNumber(Number.MIN_VALUE);
252
- * // => 5e-324
253
- *
254
- * _.toNumber(Infinity);
255
- * // => Infinity
256
- *
257
- * _.toNumber('3.2');
258
- * // => 3.2
259
- */
260
- function toNumber(value) {
261
- if (typeof value == 'number') {
262
- return value;
263
- }
264
- if (isSymbol(value)) {
265
- return NAN;
266
- }
267
- if (isObject(value)) {
268
- var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
269
- value = isObject(other) ? (other + '') : other;
270
- }
271
- if (typeof value != 'string') {
272
- return value === 0 ? value : +value;
273
- }
274
- value = baseTrim(value);
275
- var isBinary = reIsBinary.test(value);
276
- return (isBinary || reIsOctal.test(value))
277
- ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
278
- : (reIsBadHex.test(value) ? NAN : +value);
279
- }
280
-
281
- /**
282
- * Gets the timestamp of the number of milliseconds that have elapsed since
283
- * the Unix epoch (1 January 1970 00:00:00 UTC).
284
- *
285
- * @static
286
- * @memberOf _
287
- * @since 2.4.0
288
- * @category Date
289
- * @returns {number} Returns the timestamp.
290
- * @example
291
- *
292
- * _.defer(function(stamp) {
293
- * console.log(_.now() - stamp);
294
- * }, _.now());
295
- * // => Logs the number of milliseconds it took for the deferred invocation.
296
- */
297
- var now = function() {
298
- return root.Date.now();
299
- };
300
-
301
- /** Error message constants. */
302
- var FUNC_ERROR_TEXT$1 = 'Expected a function';
303
-
304
- /* Built-in method references for those with the same name as other `lodash` methods. */
305
- var nativeMax = Math.max,
306
- nativeMin = Math.min;
307
-
308
- /**
309
- * Creates a debounced function that delays invoking `func` until after `wait`
310
- * milliseconds have elapsed since the last time the debounced function was
311
- * invoked. The debounced function comes with a `cancel` method to cancel
312
- * delayed `func` invocations and a `flush` method to immediately invoke them.
313
- * Provide `options` to indicate whether `func` should be invoked on the
314
- * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
315
- * with the last arguments provided to the debounced function. Subsequent
316
- * calls to the debounced function return the result of the last `func`
317
- * invocation.
318
- *
319
- * **Note:** If `leading` and `trailing` options are `true`, `func` is
320
- * invoked on the trailing edge of the timeout only if the debounced function
321
- * is invoked more than once during the `wait` timeout.
322
- *
323
- * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
324
- * until to the next tick, similar to `setTimeout` with a timeout of `0`.
325
- *
326
- * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
327
- * for details over the differences between `_.debounce` and `_.throttle`.
328
- *
329
- * @static
330
- * @memberOf _
331
- * @since 0.1.0
332
- * @category Function
333
- * @param {Function} func The function to debounce.
334
- * @param {number} [wait=0] The number of milliseconds to delay.
335
- * @param {Object} [options={}] The options object.
336
- * @param {boolean} [options.leading=false]
337
- * Specify invoking on the leading edge of the timeout.
338
- * @param {number} [options.maxWait]
339
- * The maximum time `func` is allowed to be delayed before it's invoked.
340
- * @param {boolean} [options.trailing=true]
341
- * Specify invoking on the trailing edge of the timeout.
342
- * @returns {Function} Returns the new debounced function.
343
- * @example
344
- *
345
- * // Avoid costly calculations while the window size is in flux.
346
- * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
347
- *
348
- * // Invoke `sendMail` when clicked, debouncing subsequent calls.
349
- * jQuery(element).on('click', _.debounce(sendMail, 300, {
350
- * 'leading': true,
351
- * 'trailing': false
352
- * }));
353
- *
354
- * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
355
- * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
356
- * var source = new EventSource('/stream');
357
- * jQuery(source).on('message', debounced);
358
- *
359
- * // Cancel the trailing debounced invocation.
360
- * jQuery(window).on('popstate', debounced.cancel);
361
- */
362
- function debounce(func, wait, options) {
363
- var lastArgs,
364
- lastThis,
365
- maxWait,
366
- result,
367
- timerId,
368
- lastCallTime,
369
- lastInvokeTime = 0,
370
- leading = false,
371
- maxing = false,
372
- trailing = true;
373
-
374
- if (typeof func != 'function') {
375
- throw new TypeError(FUNC_ERROR_TEXT$1);
376
- }
377
- wait = toNumber(wait) || 0;
378
- if (isObject(options)) {
379
- leading = !!options.leading;
380
- maxing = 'maxWait' in options;
381
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
382
- trailing = 'trailing' in options ? !!options.trailing : trailing;
383
- }
384
-
385
- function invokeFunc(time) {
386
- var args = lastArgs,
387
- thisArg = lastThis;
388
-
389
- lastArgs = lastThis = undefined;
390
- lastInvokeTime = time;
391
- result = func.apply(thisArg, args);
392
- return result;
393
- }
394
-
395
- function leadingEdge(time) {
396
- // Reset any `maxWait` timer.
397
- lastInvokeTime = time;
398
- // Start the timer for the trailing edge.
399
- timerId = setTimeout(timerExpired, wait);
400
- // Invoke the leading edge.
401
- return leading ? invokeFunc(time) : result;
402
- }
403
-
404
- function remainingWait(time) {
405
- var timeSinceLastCall = time - lastCallTime,
406
- timeSinceLastInvoke = time - lastInvokeTime,
407
- timeWaiting = wait - timeSinceLastCall;
408
-
409
- return maxing
410
- ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
411
- : timeWaiting;
412
- }
413
-
414
- function shouldInvoke(time) {
415
- var timeSinceLastCall = time - lastCallTime,
416
- timeSinceLastInvoke = time - lastInvokeTime;
417
-
418
- // Either this is the first call, activity has stopped and we're at the
419
- // trailing edge, the system time has gone backwards and we're treating
420
- // it as the trailing edge, or we've hit the `maxWait` limit.
421
- return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
422
- (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
423
- }
424
-
425
- function timerExpired() {
426
- var time = now();
427
- if (shouldInvoke(time)) {
428
- return trailingEdge(time);
429
- }
430
- // Restart the timer.
431
- timerId = setTimeout(timerExpired, remainingWait(time));
432
- }
433
-
434
- function trailingEdge(time) {
435
- timerId = undefined;
436
-
437
- // Only invoke if we have `lastArgs` which means `func` has been
438
- // debounced at least once.
439
- if (trailing && lastArgs) {
440
- return invokeFunc(time);
441
- }
442
- lastArgs = lastThis = undefined;
443
- return result;
444
- }
445
-
446
- function cancel() {
447
- if (timerId !== undefined) {
448
- clearTimeout(timerId);
449
- }
450
- lastInvokeTime = 0;
451
- lastArgs = lastCallTime = lastThis = timerId = undefined;
452
- }
453
-
454
- function flush() {
455
- return timerId === undefined ? result : trailingEdge(now());
456
- }
457
-
458
- function debounced() {
459
- var time = now(),
460
- isInvoking = shouldInvoke(time);
461
-
462
- lastArgs = arguments;
463
- lastThis = this;
464
- lastCallTime = time;
465
-
466
- if (isInvoking) {
467
- if (timerId === undefined) {
468
- return leadingEdge(lastCallTime);
469
- }
470
- if (maxing) {
471
- // Handle invocations in a tight loop.
472
- clearTimeout(timerId);
473
- timerId = setTimeout(timerExpired, wait);
474
- return invokeFunc(lastCallTime);
475
- }
476
- }
477
- if (timerId === undefined) {
478
- timerId = setTimeout(timerExpired, wait);
479
- }
480
- return result;
481
- }
482
- debounced.cancel = cancel;
483
- debounced.flush = flush;
484
- return debounced;
485
- }
486
-
487
- /** Error message constants. */
488
- var FUNC_ERROR_TEXT = 'Expected a function';
489
-
490
- /**
491
- * Creates a throttled function that only invokes `func` at most once per
492
- * every `wait` milliseconds. The throttled function comes with a `cancel`
493
- * method to cancel delayed `func` invocations and a `flush` method to
494
- * immediately invoke them. Provide `options` to indicate whether `func`
495
- * should be invoked on the leading and/or trailing edge of the `wait`
496
- * timeout. The `func` is invoked with the last arguments provided to the
497
- * throttled function. Subsequent calls to the throttled function return the
498
- * result of the last `func` invocation.
499
- *
500
- * **Note:** If `leading` and `trailing` options are `true`, `func` is
501
- * invoked on the trailing edge of the timeout only if the throttled function
502
- * is invoked more than once during the `wait` timeout.
503
- *
504
- * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
505
- * until to the next tick, similar to `setTimeout` with a timeout of `0`.
506
- *
507
- * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
508
- * for details over the differences between `_.throttle` and `_.debounce`.
509
- *
510
- * @static
511
- * @memberOf _
512
- * @since 0.1.0
513
- * @category Function
514
- * @param {Function} func The function to throttle.
515
- * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
516
- * @param {Object} [options={}] The options object.
517
- * @param {boolean} [options.leading=true]
518
- * Specify invoking on the leading edge of the timeout.
519
- * @param {boolean} [options.trailing=true]
520
- * Specify invoking on the trailing edge of the timeout.
521
- * @returns {Function} Returns the new throttled function.
522
- * @example
523
- *
524
- * // Avoid excessively updating the position while scrolling.
525
- * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
526
- *
527
- * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
528
- * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
529
- * jQuery(element).on('click', throttled);
530
- *
531
- * // Cancel the trailing throttled invocation.
532
- * jQuery(window).on('popstate', throttled.cancel);
533
- */
534
- function throttle(func, wait, options) {
535
- var leading = true,
536
- trailing = true;
537
-
538
- if (typeof func != 'function') {
539
- throw new TypeError(FUNC_ERROR_TEXT);
540
- }
541
- if (isObject(options)) {
542
- leading = 'leading' in options ? !!options.leading : leading;
543
- trailing = 'trailing' in options ? !!options.trailing : trailing;
544
- }
545
- return debounce(func, wait, {
546
- 'leading': leading,
547
- 'maxWait': wait,
548
- 'trailing': trailing
549
- });
550
- }
551
-
552
- const defaultOnerror = throttle((err) => {
553
- let message = "\u7CFB\u7EDF\u9519\u8BEF";
554
- if (err instanceof Error) {
555
- const local = {
556
- "Failed to fetch": "\u8BF7\u6C42\u5931\u8D25",
557
- "The user aborted a request.": "\u8BF7\u6C42\u88AB\u7EC8\u6B62"
558
- };
559
- message = local[err.message] || err.message;
560
- if (err.name === "AbortError" && err.message.includes("user")) {
561
- return;
562
- }
563
- }
564
- if (typeof err === "string") {
565
- message = err;
566
- }
567
- if (isPlainObject(err)) {
568
- const msg = err?.msg;
569
- msg && (message = msg);
570
- }
571
- ElMessage({
572
- type: "error",
573
- message
574
- });
575
- }, 500, { trailing: false });
576
- class PlusFetch extends RestFetch {
577
- constructor(...args) {
578
- const opts = args[0];
579
- super(...args);
580
- this.onerror = opts.onerror ?? defaultOnerror;
581
- }
582
- async request(options, init, requestInit) {
583
- const fetchPromise = super.request(options, requestInit);
584
- const initOptions = {
585
- loading: false,
586
- loadingDelay: 400,
587
- ...init || {},
588
- error: init?.error ?? true,
589
- onerror: init?.onerror ?? this.onerror,
590
- successMessage: init?.successMessage
591
- };
592
- const loading = initOptions.loading;
593
- let loadingService = null;
594
- if (loading) {
595
- const preRes = await Promise.race([
596
- sleep(initOptions.loadingDelay),
597
- fetchPromise
598
- ]);
599
- if (!preRes) {
600
- if (ElLoading.service) {
601
- loadingService = ElLoading.service(
602
- typeof initOptions.loading === "boolean" ? {} : initOptions.loading
603
- );
604
- } else {
605
- loadingService = ElLoadingService(
606
- typeof initOptions.loading === "boolean" ? {} : initOptions.loading
607
- );
608
- }
609
- }
610
- }
611
- let res;
612
- try {
613
- res = await fetchPromise;
614
- } catch (err) {
615
- loadingService?.close();
616
- if (initOptions.error) {
617
- initOptions.onerror(err);
618
- }
619
- throw err;
620
- }
621
- loadingService?.close();
622
- if (!this.customOk(res)) {
623
- initOptions.error && this.onerror(res);
624
- if (initOptions.throwResErr) {
625
- return Promise.reject(res);
626
- }
627
- }
628
- if (initOptions.successMessage) {
629
- ElMessage({
630
- type: "success",
631
- message: typeof initOptions.successMessage === "string" ? initOptions.successMessage : "\u64CD\u4F5C\u6210\u529F"
632
- });
633
- }
634
- return res;
635
- }
636
- }
637
-
638
- export { PlusFetch, defaultOnerror };
@@ -1,54 +0,0 @@
1
- import { ReturnVoid } from '@vunk/core';
2
- import { RestFetchConstructorOptions } from '@vunk/shared/fetch';
3
- import { LoadingOptions } from 'element-plus';
4
- /**
5
- * Response: !response.ok
6
- * Error: request error, abort error
7
- */
8
- export type BaseErrorEvent = Response | Error;
9
- /**
10
- * Response: !response.ok
11
- * Error: request error, abort error
12
- * { msg: string }: 业务错误
13
- * string: 业务错误
14
- */
15
- export type ErrorEvent = BaseErrorEvent | {
16
- msg?: string;
17
- } | string;
18
- /**
19
- * 错误回调
20
- */
21
- export type Onerror<E = ErrorEvent> = (e: E) => ReturnVoid;
22
- export interface PlusFetchConstructorOptions extends RestFetchConstructorOptions {
23
- onerror?: Onerror;
24
- }
25
- export interface RequestInitOptions {
26
- /**
27
- * 是否显示 loading
28
- */
29
- loading?: boolean | LoadingOptions;
30
- /**
31
- * loading 延时出现
32
- */
33
- loadingDelay?: number;
34
- /**
35
- * 若为true 则在请求失败时,触发回调 onerror
36
- * @default true
37
- */
38
- error?: boolean;
39
- /**
40
- * fetch 请求错误时回调
41
- */
42
- onerror?: Onerror;
43
- /**
44
- * 请求成功 将提示 msg
45
- */
46
- successMessage?: boolean | string;
47
- /**
48
- * 后端有响应
49
- * 但是 code 不成功
50
- * 是否需要抛出异常
51
- * @default false
52
- */
53
- throwResErr?: boolean;
54
- }
package/fetch/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './PlusFetch';
package/fetch/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- export { PlusFetch, defaultOnerror } from './PlusFetch/index.mjs';
2
- import '@vunk/shared/fetch';
3
- import 'element-plus';
4
- import '@vunk/shared/promise';
5
- import '@vunk/shared/object';