@ks-web/use 0.0.1 → 0.0.4

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/README.md CHANGED
@@ -1,16 +1,16 @@
1
- # Vant Use
1
+ # Ks Use
2
2
 
3
- Built-in composition APIs of Vant.
3
+ Built-in composition APIs of ks.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```shell
8
8
  # with npm
9
- npm i @vant/use
9
+ npm i @ks-web/use
10
10
 
11
11
  # with yarn
12
- yarn add @vant/use
12
+ yarn add @ks-web/use
13
13
 
14
14
  # with pnpm
15
- pnpm add @vant/use
15
+ pnpm add @ks-web/use
16
16
  ```
package/dist/index.cjs.js CHANGED
@@ -38,6 +38,10 @@ var __copyProps = (to, from, except, desc) => {
38
38
  return to;
39
39
  };
40
40
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
41
+ // If the importer is in node compatibility mode or this is not an ESM
42
+ // file that has been converted to a CommonJS file using a Babel-
43
+ // compatible transform (i.e. "__esModule" has not been set), then set
44
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
45
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
46
  mod
43
47
  ));
@@ -251,6 +255,7 @@ var require_get_intrinsic = __commonJS({
251
255
  "%encodeURIComponent%": encodeURIComponent,
252
256
  "%Error%": Error,
253
257
  "%eval%": eval,
258
+ // eslint-disable-line no-eval
254
259
  "%EvalError%": EvalError,
255
260
  "%Float32Array%": typeof Float32Array === "undefined" ? undefined2 : Float32Array,
256
261
  "%Float64Array%": typeof Float64Array === "undefined" ? undefined2 : Float64Array,
@@ -1089,6 +1094,7 @@ var require_side_channel = __commonJS({
1089
1094
  node.value = value;
1090
1095
  } else {
1091
1096
  objects.next = {
1097
+ // eslint-disable-line no-param-reassign
1092
1098
  key,
1093
1099
  next: objects.next,
1094
1100
  value
@@ -1427,6 +1433,7 @@ var require_stringify = __commonJS({
1427
1433
  encodeValuesOnly: false,
1428
1434
  format: defaultFormat,
1429
1435
  formatter: formats.formatters[defaultFormat],
1436
+ // deprecated
1430
1437
  indices: false,
1431
1438
  serializeDate: function serializeDate(date) {
1432
1439
  return toISO.call(date);
@@ -1821,6 +1828,7 @@ var require_parse = __commonJS({
1821
1828
  comma: typeof opts.comma === "boolean" ? opts.comma : defaults2.comma,
1822
1829
  decoder: typeof opts.decoder === "function" ? opts.decoder : defaults2.decoder,
1823
1830
  delimiter: typeof opts.delimiter === "string" || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults2.delimiter,
1831
+ // eslint-disable-next-line no-implicit-coercion, no-extra-parens
1824
1832
  depth: typeof opts.depth === "number" || opts.depth === false ? +opts.depth : defaults2.depth,
1825
1833
  ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
1826
1834
  interpretNumericEntities: typeof opts.interpretNumericEntities === "boolean" ? opts.interpretNumericEntities : defaults2.interpretNumericEntities,
@@ -2643,8 +2651,12 @@ function useEventListener(type, listener, options = {}) {
2643
2651
  return;
2644
2652
  }
2645
2653
  const { target = window, passive = false, capture = false } = options;
2654
+ let cleaned = false;
2646
2655
  let attached;
2647
2656
  const add = (target2) => {
2657
+ if (cleaned) {
2658
+ return;
2659
+ }
2648
2660
  const element = (0, import_vue7.unref)(target2);
2649
2661
  if (element && !attached) {
2650
2662
  element.addEventListener(type, listener, {
@@ -2655,6 +2667,9 @@ function useEventListener(type, listener, options = {}) {
2655
2667
  }
2656
2668
  };
2657
2669
  const remove = (target2) => {
2670
+ if (cleaned) {
2671
+ return;
2672
+ }
2658
2673
  const element = (0, import_vue7.unref)(target2);
2659
2674
  if (element && attached) {
2660
2675
  element.removeEventListener(type, listener, capture);
@@ -2664,12 +2679,18 @@ function useEventListener(type, listener, options = {}) {
2664
2679
  (0, import_vue7.onUnmounted)(() => remove(target));
2665
2680
  (0, import_vue7.onDeactivated)(() => remove(target));
2666
2681
  onMountedOrActivated(() => add(target));
2682
+ let stopWatch;
2667
2683
  if ((0, import_vue7.isRef)(target)) {
2668
- (0, import_vue7.watch)(target, (val, oldVal) => {
2684
+ stopWatch = (0, import_vue7.watch)(target, (val, oldVal) => {
2669
2685
  remove(oldVal);
2670
2686
  add(val);
2671
2687
  });
2672
2688
  }
2689
+ return () => {
2690
+ stopWatch == null ? void 0 : stopWatch();
2691
+ remove(target);
2692
+ cleaned = true;
2693
+ };
2673
2694
  }
2674
2695
 
2675
2696
  // src/useClickAway/index.ts
@@ -3116,6 +3137,7 @@ var utils_default = {
3116
3137
  isHTMLForm,
3117
3138
  hasOwnProperty,
3118
3139
  hasOwnProp: hasOwnProperty,
3140
+ // an alias to avoid ESLint no-prototype-builtins detection
3119
3141
  reduceDescriptors,
3120
3142
  freezeMethods,
3121
3143
  toObjectSet,
@@ -3149,14 +3171,18 @@ function AxiosError(message, code, config, request, response) {
3149
3171
  utils_default.inherits(AxiosError, Error, {
3150
3172
  toJSON: function toJSON() {
3151
3173
  return {
3174
+ // Standard
3152
3175
  message: this.message,
3153
3176
  name: this.name,
3177
+ // Microsoft
3154
3178
  description: this.description,
3155
3179
  number: this.number,
3180
+ // Mozilla
3156
3181
  fileName: this.fileName,
3157
3182
  lineNumber: this.lineNumber,
3158
3183
  columnNumber: this.columnNumber,
3159
3184
  stack: this.stack,
3185
+ // Axios
3160
3186
  config: utils_default.toJSONObject(this.config),
3161
3187
  code: this.code,
3162
3188
  status: this.response && this.response.status ? this.response.status : null
@@ -3178,6 +3204,7 @@ var descriptors = {};
3178
3204
  "ERR_CANCELED",
3179
3205
  "ERR_NOT_SUPPORT",
3180
3206
  "ERR_INVALID_URL"
3207
+ // eslint-disable-next-line func-names
3181
3208
  ].forEach((code) => {
3182
3209
  descriptors[code] = { value: code };
3183
3210
  });
@@ -3267,6 +3294,7 @@ function toFormData(obj, formData, options) {
3267
3294
  key = removeBrackets(key);
3268
3295
  arr.forEach(function each(el, index) {
3269
3296
  !(utils_default.isUndefined(el) || el === null) && formData.append(
3297
+ // eslint-disable-next-line no-nested-ternary
3270
3298
  indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]",
3271
3299
  convertValue(el)
3272
3300
  );
@@ -3379,6 +3407,14 @@ var InterceptorManager = class {
3379
3407
  constructor() {
3380
3408
  this.handlers = [];
3381
3409
  }
3410
+ /**
3411
+ * Add a new interceptor to the stack
3412
+ *
3413
+ * @param {Function} fulfilled The function to handle `then` for a `Promise`
3414
+ * @param {Function} rejected The function to handle `reject` for a `Promise`
3415
+ *
3416
+ * @return {Number} An ID used to remove interceptor later
3417
+ */
3382
3418
  use(fulfilled, rejected, options) {
3383
3419
  this.handlers.push({
3384
3420
  fulfilled,
@@ -3388,16 +3424,38 @@ var InterceptorManager = class {
3388
3424
  });
3389
3425
  return this.handlers.length - 1;
3390
3426
  }
3427
+ /**
3428
+ * Remove an interceptor from the stack
3429
+ *
3430
+ * @param {Number} id The ID that was returned by `use`
3431
+ *
3432
+ * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
3433
+ */
3391
3434
  eject(id) {
3392
3435
  if (this.handlers[id]) {
3393
3436
  this.handlers[id] = null;
3394
3437
  }
3395
3438
  }
3439
+ /**
3440
+ * Clear all interceptors from the stack
3441
+ *
3442
+ * @returns {void}
3443
+ */
3396
3444
  clear() {
3397
3445
  if (this.handlers) {
3398
3446
  this.handlers = [];
3399
3447
  }
3400
3448
  }
3449
+ /**
3450
+ * Iterate over all the registered interceptors
3451
+ *
3452
+ * This method is particularly useful for skipping over any
3453
+ * interceptors that may have become `null` calling `eject`.
3454
+ *
3455
+ * @param {Function} fn The function to call for each interceptor
3456
+ *
3457
+ * @returns {void}
3458
+ */
3401
3459
  forEach(fn) {
3402
3460
  utils_default.forEach(this.handlers, function forEachHandler(h) {
3403
3461
  if (h !== null) {
@@ -3430,7 +3488,8 @@ var isStandardBrowserEnv = (() => {
3430
3488
  return typeof window !== "undefined" && typeof document !== "undefined";
3431
3489
  })();
3432
3490
  var isStandardBrowserWebWorkerEnv = (() => {
3433
- return typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope && typeof self.importScripts === "function";
3491
+ return typeof WorkerGlobalScope !== "undefined" && // eslint-disable-next-line no-undef
3492
+ self instanceof WorkerGlobalScope && typeof self.importScripts === "function";
3434
3493
  })();
3435
3494
  var browser_default = {
3436
3495
  isBrowser: true,
@@ -3593,6 +3652,10 @@ var defaults = {
3593
3652
  }
3594
3653
  return data;
3595
3654
  }],
3655
+ /**
3656
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
3657
+ * timeout is not created.
3658
+ */
3596
3659
  timeout: 0,
3597
3660
  xsrfCookieName: "XSRF-TOKEN",
3598
3661
  xsrfHeaderName: "X-XSRF-TOKEN",
@@ -3921,44 +3984,50 @@ function settle(resolve, reject, response) {
3921
3984
  }
3922
3985
 
3923
3986
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/cookies.js
3924
- var cookies_default = browser_default.isStandardBrowserEnv ? function standardBrowserEnv() {
3925
- return {
3926
- write: function write(name, value, expires, path, domain, secure) {
3927
- const cookie = [];
3928
- cookie.push(name + "=" + encodeURIComponent(value));
3929
- if (utils_default.isNumber(expires)) {
3930
- cookie.push("expires=" + new Date(expires).toGMTString());
3931
- }
3932
- if (utils_default.isString(path)) {
3933
- cookie.push("path=" + path);
3934
- }
3935
- if (utils_default.isString(domain)) {
3936
- cookie.push("domain=" + domain);
3937
- }
3938
- if (secure === true) {
3939
- cookie.push("secure");
3940
- }
3941
- document.cookie = cookie.join("; ");
3942
- },
3943
- read: function read(name) {
3944
- const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
3945
- return match ? decodeURIComponent(match[3]) : null;
3946
- },
3947
- remove: function remove(name) {
3948
- this.write(name, "", Date.now() - 864e5);
3949
- }
3950
- };
3951
- }() : function nonStandardBrowserEnv() {
3952
- return {
3953
- write: function write() {
3954
- },
3955
- read: function read() {
3956
- return null;
3957
- },
3958
- remove: function remove() {
3959
- }
3960
- };
3961
- }();
3987
+ var cookies_default = browser_default.isStandardBrowserEnv ? (
3988
+ // Standard browser envs support document.cookie
3989
+ function standardBrowserEnv() {
3990
+ return {
3991
+ write: function write(name, value, expires, path, domain, secure) {
3992
+ const cookie = [];
3993
+ cookie.push(name + "=" + encodeURIComponent(value));
3994
+ if (utils_default.isNumber(expires)) {
3995
+ cookie.push("expires=" + new Date(expires).toGMTString());
3996
+ }
3997
+ if (utils_default.isString(path)) {
3998
+ cookie.push("path=" + path);
3999
+ }
4000
+ if (utils_default.isString(domain)) {
4001
+ cookie.push("domain=" + domain);
4002
+ }
4003
+ if (secure === true) {
4004
+ cookie.push("secure");
4005
+ }
4006
+ document.cookie = cookie.join("; ");
4007
+ },
4008
+ read: function read(name) {
4009
+ const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
4010
+ return match ? decodeURIComponent(match[3]) : null;
4011
+ },
4012
+ remove: function remove(name) {
4013
+ this.write(name, "", Date.now() - 864e5);
4014
+ }
4015
+ };
4016
+ }()
4017
+ ) : (
4018
+ // Non standard browser env (web workers, react-native) lack needed support.
4019
+ function nonStandardBrowserEnv() {
4020
+ return {
4021
+ write: function write() {
4022
+ },
4023
+ read: function read() {
4024
+ return null;
4025
+ },
4026
+ remove: function remove() {
4027
+ }
4028
+ };
4029
+ }()
4030
+ );
3962
4031
 
3963
4032
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/isAbsoluteURL.js
3964
4033
  function isAbsoluteURL(url) {
@@ -3979,38 +4048,45 @@ function buildFullPath(baseURL, requestedURL) {
3979
4048
  }
3980
4049
 
3981
4050
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/isURLSameOrigin.js
3982
- var isURLSameOrigin_default = browser_default.isStandardBrowserEnv ? function standardBrowserEnv2() {
3983
- const msie = /(msie|trident)/i.test(navigator.userAgent);
3984
- const urlParsingNode = document.createElement("a");
3985
- let originURL;
3986
- function resolveURL(url) {
3987
- let href = url;
3988
- if (msie) {
4051
+ var isURLSameOrigin_default = browser_default.isStandardBrowserEnv ? (
4052
+ // Standard browser envs have full support of the APIs needed to test
4053
+ // whether the request URL is of the same origin as current location.
4054
+ function standardBrowserEnv2() {
4055
+ const msie = /(msie|trident)/i.test(navigator.userAgent);
4056
+ const urlParsingNode = document.createElement("a");
4057
+ let originURL;
4058
+ function resolveURL(url) {
4059
+ let href = url;
4060
+ if (msie) {
4061
+ urlParsingNode.setAttribute("href", href);
4062
+ href = urlParsingNode.href;
4063
+ }
3989
4064
  urlParsingNode.setAttribute("href", href);
3990
- href = urlParsingNode.href;
4065
+ return {
4066
+ href: urlParsingNode.href,
4067
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
4068
+ host: urlParsingNode.host,
4069
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
4070
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
4071
+ hostname: urlParsingNode.hostname,
4072
+ port: urlParsingNode.port,
4073
+ pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
4074
+ };
3991
4075
  }
3992
- urlParsingNode.setAttribute("href", href);
3993
- return {
3994
- href: urlParsingNode.href,
3995
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
3996
- host: urlParsingNode.host,
3997
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
3998
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
3999
- hostname: urlParsingNode.hostname,
4000
- port: urlParsingNode.port,
4001
- pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
4076
+ originURL = resolveURL(window.location.href);
4077
+ return function isURLSameOrigin(requestURL) {
4078
+ const parsed = utils_default.isString(requestURL) ? resolveURL(requestURL) : requestURL;
4079
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
4002
4080
  };
4003
- }
4004
- originURL = resolveURL(window.location.href);
4005
- return function isURLSameOrigin(requestURL) {
4006
- const parsed = utils_default.isString(requestURL) ? resolveURL(requestURL) : requestURL;
4007
- return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
4008
- };
4009
- }() : function nonStandardBrowserEnv2() {
4010
- return function isURLSameOrigin() {
4011
- return true;
4012
- };
4013
- }();
4081
+ }()
4082
+ ) : (
4083
+ // Non standard browser envs (web workers, react-native) lack needed support.
4084
+ function nonStandardBrowserEnv2() {
4085
+ return function isURLSameOrigin() {
4086
+ return true;
4087
+ };
4088
+ }()
4089
+ );
4014
4090
 
4015
4091
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/parseProtocol.js
4016
4092
  function parseProtocol(url) {
@@ -4455,6 +4531,14 @@ var Axios = class {
4455
4531
  response: new InterceptorManager_default()
4456
4532
  };
4457
4533
  }
4534
+ /**
4535
+ * Dispatch a request
4536
+ *
4537
+ * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
4538
+ * @param {?Object} config
4539
+ *
4540
+ * @returns {Promise} The Promise to be fulfilled
4541
+ */
4458
4542
  request(configOrUrl, config) {
4459
4543
  if (typeof configOrUrl === "string") {
4460
4544
  config = config || {};
@@ -4614,11 +4698,17 @@ var CancelToken = class {
4614
4698
  resolvePromise(token.reason);
4615
4699
  });
4616
4700
  }
4701
+ /**
4702
+ * Throws a `CanceledError` if cancellation has been requested.
4703
+ */
4617
4704
  throwIfRequested() {
4618
4705
  if (this.reason) {
4619
4706
  throw this.reason;
4620
4707
  }
4621
4708
  }
4709
+ /**
4710
+ * Subscribe to the cancel signal
4711
+ */
4622
4712
  subscribe(listener) {
4623
4713
  if (this.reason) {
4624
4714
  listener(this.reason);
@@ -4630,6 +4720,9 @@ var CancelToken = class {
4630
4720
  this._listeners = [listener];
4631
4721
  }
4632
4722
  }
4723
+ /**
4724
+ * Unsubscribe from the cancel signal
4725
+ */
4633
4726
  unsubscribe(listener) {
4634
4727
  if (!this._listeners) {
4635
4728
  return;
@@ -4639,6 +4732,10 @@ var CancelToken = class {
4639
4732
  this._listeners.splice(index, 1);
4640
4733
  }
4641
4734
  }
4735
+ /**
4736
+ * Returns an object that contains a new `CancelToken` and a function that, when called,
4737
+ * cancels the `CancelToken`.
4738
+ */
4642
4739
  static source() {
4643
4740
  let cancel;
4644
4741
  const token = new CancelToken(function executor(c) {
@@ -5091,6 +5188,7 @@ function mergeInterceptor(httpOptions, httpInterceptorMap) {
5091
5188
  var CancelToken3 = axios_default.CancelToken;
5092
5189
  var HttpClient = class {
5093
5190
  constructor(httpOptions) {
5191
+ // 通用请求客户端封装
5094
5192
  this.get = (url, param, requestOptions) => this.request(url, REQUEST_METHOD.get, param, requestOptions);
5095
5193
  this.post = (url, param, requestOptions) => this.request(url, REQUEST_METHOD.post, param, requestOptions);
5096
5194
  this.put = (url, param, requestOptions) => this.request(url, REQUEST_METHOD.put, param, requestOptions);
@@ -5273,7 +5371,7 @@ var customWatermark = (text = "KYE", el = ".ksui-container, .van-dialog, .ksui-c
5273
5371
  document.querySelector("head").appendChild(style);
5274
5372
  };
5275
5373
  function useWaterMark(employeeNumber, el = ".ksui-container, .van-dialog, .ksui-card, .ks-table", color = "#F0F3F9") {
5276
- let date = new Date();
5374
+ let date = /* @__PURE__ */ new Date();
5277
5375
  const f = (num) => {
5278
5376
  let str = String(num);
5279
5377
  return str.length === 1 ? "0" + str : str;
@@ -5321,7 +5419,7 @@ var debounce = (func, wait, options) => {
5321
5419
  return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
5322
5420
  }
5323
5421
  function timerExpired() {
5324
- var time = new Date().getTime();
5422
+ var time = (/* @__PURE__ */ new Date()).getTime();
5325
5423
  if (shouldInvoke(time)) {
5326
5424
  return trailingEdge(time);
5327
5425
  }
@@ -5343,10 +5441,10 @@ var debounce = (func, wait, options) => {
5343
5441
  lastArgs = lastCallTime = lastThis = timerId = void 0;
5344
5442
  }
5345
5443
  function flush() {
5346
- return timerId === void 0 ? result : trailingEdge(new Date().getTime());
5444
+ return timerId === void 0 ? result : trailingEdge((/* @__PURE__ */ new Date()).getTime());
5347
5445
  }
5348
5446
  function debounced() {
5349
- var time = new Date().getTime(), isInvoking = shouldInvoke(time);
5447
+ var time = (/* @__PURE__ */ new Date()).getTime(), isInvoking = shouldInvoke(time);
5350
5448
  lastArgs = arguments;
5351
5449
  lastThis = this;
5352
5450
  lastCallTime = time;
@@ -33,6 +33,10 @@ var __copyProps = (to, from, except, desc) => {
33
33
  return to;
34
34
  };
35
35
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
36
+ // If the importer is in node compatibility mode or this is not an ESM
37
+ // file that has been converted to a CommonJS file using a Babel-
38
+ // compatible transform (i.e. "__esModule" has not been set), then set
39
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
40
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
41
  mod
38
42
  ));
@@ -245,6 +249,7 @@ var require_get_intrinsic = __commonJS({
245
249
  "%encodeURIComponent%": encodeURIComponent,
246
250
  "%Error%": Error,
247
251
  "%eval%": eval,
252
+ // eslint-disable-line no-eval
248
253
  "%EvalError%": EvalError,
249
254
  "%Float32Array%": typeof Float32Array === "undefined" ? undefined2 : Float32Array,
250
255
  "%Float64Array%": typeof Float64Array === "undefined" ? undefined2 : Float64Array,
@@ -1083,6 +1088,7 @@ var require_side_channel = __commonJS({
1083
1088
  node.value = value;
1084
1089
  } else {
1085
1090
  objects.next = {
1091
+ // eslint-disable-line no-param-reassign
1086
1092
  key,
1087
1093
  next: objects.next,
1088
1094
  value
@@ -1421,6 +1427,7 @@ var require_stringify = __commonJS({
1421
1427
  encodeValuesOnly: false,
1422
1428
  format: defaultFormat,
1423
1429
  formatter: formats.formatters[defaultFormat],
1430
+ // deprecated
1424
1431
  indices: false,
1425
1432
  serializeDate: function serializeDate(date) {
1426
1433
  return toISO.call(date);
@@ -1815,6 +1822,7 @@ var require_parse = __commonJS({
1815
1822
  comma: typeof opts.comma === "boolean" ? opts.comma : defaults2.comma,
1816
1823
  decoder: typeof opts.decoder === "function" ? opts.decoder : defaults2.decoder,
1817
1824
  delimiter: typeof opts.delimiter === "string" || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults2.delimiter,
1825
+ // eslint-disable-next-line no-implicit-coercion, no-extra-parens
1818
1826
  depth: typeof opts.depth === "number" || opts.depth === false ? +opts.depth : defaults2.depth,
1819
1827
  ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
1820
1828
  interpretNumericEntities: typeof opts.interpretNumericEntities === "boolean" ? opts.interpretNumericEntities : defaults2.interpretNumericEntities,
@@ -2595,7 +2603,13 @@ function useCountDown(options) {
2595
2603
  import { unref as unref3 } from "vue";
2596
2604
 
2597
2605
  // src/useEventListener/index.ts
2598
- import { watch, isRef, unref as unref2, onUnmounted as onUnmounted2, onDeactivated as onDeactivated2 } from "vue";
2606
+ import {
2607
+ watch,
2608
+ isRef,
2609
+ unref as unref2,
2610
+ onUnmounted as onUnmounted2,
2611
+ onDeactivated as onDeactivated2
2612
+ } from "vue";
2599
2613
 
2600
2614
  // src/onMountedOrActivated/index.ts
2601
2615
  import { nextTick, onMounted, onActivated as onActivated2 } from "vue";
@@ -2620,8 +2634,12 @@ function useEventListener(type, listener, options = {}) {
2620
2634
  return;
2621
2635
  }
2622
2636
  const { target = window, passive = false, capture = false } = options;
2637
+ let cleaned = false;
2623
2638
  let attached;
2624
2639
  const add = (target2) => {
2640
+ if (cleaned) {
2641
+ return;
2642
+ }
2625
2643
  const element = unref2(target2);
2626
2644
  if (element && !attached) {
2627
2645
  element.addEventListener(type, listener, {
@@ -2632,6 +2650,9 @@ function useEventListener(type, listener, options = {}) {
2632
2650
  }
2633
2651
  };
2634
2652
  const remove = (target2) => {
2653
+ if (cleaned) {
2654
+ return;
2655
+ }
2635
2656
  const element = unref2(target2);
2636
2657
  if (element && attached) {
2637
2658
  element.removeEventListener(type, listener, capture);
@@ -2641,12 +2662,18 @@ function useEventListener(type, listener, options = {}) {
2641
2662
  onUnmounted2(() => remove(target));
2642
2663
  onDeactivated2(() => remove(target));
2643
2664
  onMountedOrActivated(() => add(target));
2665
+ let stopWatch;
2644
2666
  if (isRef(target)) {
2645
- watch(target, (val, oldVal) => {
2667
+ stopWatch = watch(target, (val, oldVal) => {
2646
2668
  remove(oldVal);
2647
2669
  add(val);
2648
2670
  });
2649
2671
  }
2672
+ return () => {
2673
+ stopWatch == null ? void 0 : stopWatch();
2674
+ remove(target);
2675
+ cleaned = true;
2676
+ };
2650
2677
  }
2651
2678
 
2652
2679
  // src/useClickAway/index.ts
@@ -3093,6 +3120,7 @@ var utils_default = {
3093
3120
  isHTMLForm,
3094
3121
  hasOwnProperty,
3095
3122
  hasOwnProp: hasOwnProperty,
3123
+ // an alias to avoid ESLint no-prototype-builtins detection
3096
3124
  reduceDescriptors,
3097
3125
  freezeMethods,
3098
3126
  toObjectSet,
@@ -3126,14 +3154,18 @@ function AxiosError(message, code, config, request, response) {
3126
3154
  utils_default.inherits(AxiosError, Error, {
3127
3155
  toJSON: function toJSON() {
3128
3156
  return {
3157
+ // Standard
3129
3158
  message: this.message,
3130
3159
  name: this.name,
3160
+ // Microsoft
3131
3161
  description: this.description,
3132
3162
  number: this.number,
3163
+ // Mozilla
3133
3164
  fileName: this.fileName,
3134
3165
  lineNumber: this.lineNumber,
3135
3166
  columnNumber: this.columnNumber,
3136
3167
  stack: this.stack,
3168
+ // Axios
3137
3169
  config: utils_default.toJSONObject(this.config),
3138
3170
  code: this.code,
3139
3171
  status: this.response && this.response.status ? this.response.status : null
@@ -3155,6 +3187,7 @@ var descriptors = {};
3155
3187
  "ERR_CANCELED",
3156
3188
  "ERR_NOT_SUPPORT",
3157
3189
  "ERR_INVALID_URL"
3190
+ // eslint-disable-next-line func-names
3158
3191
  ].forEach((code) => {
3159
3192
  descriptors[code] = { value: code };
3160
3193
  });
@@ -3244,6 +3277,7 @@ function toFormData(obj, formData, options) {
3244
3277
  key = removeBrackets(key);
3245
3278
  arr.forEach(function each(el, index) {
3246
3279
  !(utils_default.isUndefined(el) || el === null) && formData.append(
3280
+ // eslint-disable-next-line no-nested-ternary
3247
3281
  indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]",
3248
3282
  convertValue(el)
3249
3283
  );
@@ -3356,6 +3390,14 @@ var InterceptorManager = class {
3356
3390
  constructor() {
3357
3391
  this.handlers = [];
3358
3392
  }
3393
+ /**
3394
+ * Add a new interceptor to the stack
3395
+ *
3396
+ * @param {Function} fulfilled The function to handle `then` for a `Promise`
3397
+ * @param {Function} rejected The function to handle `reject` for a `Promise`
3398
+ *
3399
+ * @return {Number} An ID used to remove interceptor later
3400
+ */
3359
3401
  use(fulfilled, rejected, options) {
3360
3402
  this.handlers.push({
3361
3403
  fulfilled,
@@ -3365,16 +3407,38 @@ var InterceptorManager = class {
3365
3407
  });
3366
3408
  return this.handlers.length - 1;
3367
3409
  }
3410
+ /**
3411
+ * Remove an interceptor from the stack
3412
+ *
3413
+ * @param {Number} id The ID that was returned by `use`
3414
+ *
3415
+ * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
3416
+ */
3368
3417
  eject(id) {
3369
3418
  if (this.handlers[id]) {
3370
3419
  this.handlers[id] = null;
3371
3420
  }
3372
3421
  }
3422
+ /**
3423
+ * Clear all interceptors from the stack
3424
+ *
3425
+ * @returns {void}
3426
+ */
3373
3427
  clear() {
3374
3428
  if (this.handlers) {
3375
3429
  this.handlers = [];
3376
3430
  }
3377
3431
  }
3432
+ /**
3433
+ * Iterate over all the registered interceptors
3434
+ *
3435
+ * This method is particularly useful for skipping over any
3436
+ * interceptors that may have become `null` calling `eject`.
3437
+ *
3438
+ * @param {Function} fn The function to call for each interceptor
3439
+ *
3440
+ * @returns {void}
3441
+ */
3378
3442
  forEach(fn) {
3379
3443
  utils_default.forEach(this.handlers, function forEachHandler(h) {
3380
3444
  if (h !== null) {
@@ -3407,7 +3471,8 @@ var isStandardBrowserEnv = (() => {
3407
3471
  return typeof window !== "undefined" && typeof document !== "undefined";
3408
3472
  })();
3409
3473
  var isStandardBrowserWebWorkerEnv = (() => {
3410
- return typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope && typeof self.importScripts === "function";
3474
+ return typeof WorkerGlobalScope !== "undefined" && // eslint-disable-next-line no-undef
3475
+ self instanceof WorkerGlobalScope && typeof self.importScripts === "function";
3411
3476
  })();
3412
3477
  var browser_default = {
3413
3478
  isBrowser: true,
@@ -3570,6 +3635,10 @@ var defaults = {
3570
3635
  }
3571
3636
  return data;
3572
3637
  }],
3638
+ /**
3639
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
3640
+ * timeout is not created.
3641
+ */
3573
3642
  timeout: 0,
3574
3643
  xsrfCookieName: "XSRF-TOKEN",
3575
3644
  xsrfHeaderName: "X-XSRF-TOKEN",
@@ -3898,44 +3967,50 @@ function settle(resolve, reject, response) {
3898
3967
  }
3899
3968
 
3900
3969
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/cookies.js
3901
- var cookies_default = browser_default.isStandardBrowserEnv ? function standardBrowserEnv() {
3902
- return {
3903
- write: function write(name, value, expires, path, domain, secure) {
3904
- const cookie = [];
3905
- cookie.push(name + "=" + encodeURIComponent(value));
3906
- if (utils_default.isNumber(expires)) {
3907
- cookie.push("expires=" + new Date(expires).toGMTString());
3908
- }
3909
- if (utils_default.isString(path)) {
3910
- cookie.push("path=" + path);
3911
- }
3912
- if (utils_default.isString(domain)) {
3913
- cookie.push("domain=" + domain);
3914
- }
3915
- if (secure === true) {
3916
- cookie.push("secure");
3917
- }
3918
- document.cookie = cookie.join("; ");
3919
- },
3920
- read: function read(name) {
3921
- const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
3922
- return match ? decodeURIComponent(match[3]) : null;
3923
- },
3924
- remove: function remove(name) {
3925
- this.write(name, "", Date.now() - 864e5);
3926
- }
3927
- };
3928
- }() : function nonStandardBrowserEnv() {
3929
- return {
3930
- write: function write() {
3931
- },
3932
- read: function read() {
3933
- return null;
3934
- },
3935
- remove: function remove() {
3936
- }
3937
- };
3938
- }();
3970
+ var cookies_default = browser_default.isStandardBrowserEnv ? (
3971
+ // Standard browser envs support document.cookie
3972
+ function standardBrowserEnv() {
3973
+ return {
3974
+ write: function write(name, value, expires, path, domain, secure) {
3975
+ const cookie = [];
3976
+ cookie.push(name + "=" + encodeURIComponent(value));
3977
+ if (utils_default.isNumber(expires)) {
3978
+ cookie.push("expires=" + new Date(expires).toGMTString());
3979
+ }
3980
+ if (utils_default.isString(path)) {
3981
+ cookie.push("path=" + path);
3982
+ }
3983
+ if (utils_default.isString(domain)) {
3984
+ cookie.push("domain=" + domain);
3985
+ }
3986
+ if (secure === true) {
3987
+ cookie.push("secure");
3988
+ }
3989
+ document.cookie = cookie.join("; ");
3990
+ },
3991
+ read: function read(name) {
3992
+ const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
3993
+ return match ? decodeURIComponent(match[3]) : null;
3994
+ },
3995
+ remove: function remove(name) {
3996
+ this.write(name, "", Date.now() - 864e5);
3997
+ }
3998
+ };
3999
+ }()
4000
+ ) : (
4001
+ // Non standard browser env (web workers, react-native) lack needed support.
4002
+ function nonStandardBrowserEnv() {
4003
+ return {
4004
+ write: function write() {
4005
+ },
4006
+ read: function read() {
4007
+ return null;
4008
+ },
4009
+ remove: function remove() {
4010
+ }
4011
+ };
4012
+ }()
4013
+ );
3939
4014
 
3940
4015
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/isAbsoluteURL.js
3941
4016
  function isAbsoluteURL(url) {
@@ -3956,38 +4031,45 @@ function buildFullPath(baseURL, requestedURL) {
3956
4031
  }
3957
4032
 
3958
4033
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/isURLSameOrigin.js
3959
- var isURLSameOrigin_default = browser_default.isStandardBrowserEnv ? function standardBrowserEnv2() {
3960
- const msie = /(msie|trident)/i.test(navigator.userAgent);
3961
- const urlParsingNode = document.createElement("a");
3962
- let originURL;
3963
- function resolveURL(url) {
3964
- let href = url;
3965
- if (msie) {
4034
+ var isURLSameOrigin_default = browser_default.isStandardBrowserEnv ? (
4035
+ // Standard browser envs have full support of the APIs needed to test
4036
+ // whether the request URL is of the same origin as current location.
4037
+ function standardBrowserEnv2() {
4038
+ const msie = /(msie|trident)/i.test(navigator.userAgent);
4039
+ const urlParsingNode = document.createElement("a");
4040
+ let originURL;
4041
+ function resolveURL(url) {
4042
+ let href = url;
4043
+ if (msie) {
4044
+ urlParsingNode.setAttribute("href", href);
4045
+ href = urlParsingNode.href;
4046
+ }
3966
4047
  urlParsingNode.setAttribute("href", href);
3967
- href = urlParsingNode.href;
4048
+ return {
4049
+ href: urlParsingNode.href,
4050
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
4051
+ host: urlParsingNode.host,
4052
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
4053
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
4054
+ hostname: urlParsingNode.hostname,
4055
+ port: urlParsingNode.port,
4056
+ pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
4057
+ };
3968
4058
  }
3969
- urlParsingNode.setAttribute("href", href);
3970
- return {
3971
- href: urlParsingNode.href,
3972
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
3973
- host: urlParsingNode.host,
3974
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
3975
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
3976
- hostname: urlParsingNode.hostname,
3977
- port: urlParsingNode.port,
3978
- pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
4059
+ originURL = resolveURL(window.location.href);
4060
+ return function isURLSameOrigin(requestURL) {
4061
+ const parsed = utils_default.isString(requestURL) ? resolveURL(requestURL) : requestURL;
4062
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
3979
4063
  };
3980
- }
3981
- originURL = resolveURL(window.location.href);
3982
- return function isURLSameOrigin(requestURL) {
3983
- const parsed = utils_default.isString(requestURL) ? resolveURL(requestURL) : requestURL;
3984
- return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
3985
- };
3986
- }() : function nonStandardBrowserEnv2() {
3987
- return function isURLSameOrigin() {
3988
- return true;
3989
- };
3990
- }();
4064
+ }()
4065
+ ) : (
4066
+ // Non standard browser envs (web workers, react-native) lack needed support.
4067
+ function nonStandardBrowserEnv2() {
4068
+ return function isURLSameOrigin() {
4069
+ return true;
4070
+ };
4071
+ }()
4072
+ );
3991
4073
 
3992
4074
  // ../../node_modules/.pnpm/axios@1.3.3/node_modules/axios/lib/helpers/parseProtocol.js
3993
4075
  function parseProtocol(url) {
@@ -4432,6 +4514,14 @@ var Axios = class {
4432
4514
  response: new InterceptorManager_default()
4433
4515
  };
4434
4516
  }
4517
+ /**
4518
+ * Dispatch a request
4519
+ *
4520
+ * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
4521
+ * @param {?Object} config
4522
+ *
4523
+ * @returns {Promise} The Promise to be fulfilled
4524
+ */
4435
4525
  request(configOrUrl, config) {
4436
4526
  if (typeof configOrUrl === "string") {
4437
4527
  config = config || {};
@@ -4591,11 +4681,17 @@ var CancelToken = class {
4591
4681
  resolvePromise(token.reason);
4592
4682
  });
4593
4683
  }
4684
+ /**
4685
+ * Throws a `CanceledError` if cancellation has been requested.
4686
+ */
4594
4687
  throwIfRequested() {
4595
4688
  if (this.reason) {
4596
4689
  throw this.reason;
4597
4690
  }
4598
4691
  }
4692
+ /**
4693
+ * Subscribe to the cancel signal
4694
+ */
4599
4695
  subscribe(listener) {
4600
4696
  if (this.reason) {
4601
4697
  listener(this.reason);
@@ -4607,6 +4703,9 @@ var CancelToken = class {
4607
4703
  this._listeners = [listener];
4608
4704
  }
4609
4705
  }
4706
+ /**
4707
+ * Unsubscribe from the cancel signal
4708
+ */
4610
4709
  unsubscribe(listener) {
4611
4710
  if (!this._listeners) {
4612
4711
  return;
@@ -4616,6 +4715,10 @@ var CancelToken = class {
4616
4715
  this._listeners.splice(index, 1);
4617
4716
  }
4618
4717
  }
4718
+ /**
4719
+ * Returns an object that contains a new `CancelToken` and a function that, when called,
4720
+ * cancels the `CancelToken`.
4721
+ */
4619
4722
  static source() {
4620
4723
  let cancel;
4621
4724
  const token = new CancelToken(function executor(c) {
@@ -5068,6 +5171,7 @@ function mergeInterceptor(httpOptions, httpInterceptorMap) {
5068
5171
  var CancelToken3 = axios_default.CancelToken;
5069
5172
  var HttpClient = class {
5070
5173
  constructor(httpOptions) {
5174
+ // 通用请求客户端封装
5071
5175
  this.get = (url, param, requestOptions) => this.request(url, REQUEST_METHOD.get, param, requestOptions);
5072
5176
  this.post = (url, param, requestOptions) => this.request(url, REQUEST_METHOD.post, param, requestOptions);
5073
5177
  this.put = (url, param, requestOptions) => this.request(url, REQUEST_METHOD.put, param, requestOptions);
@@ -5250,7 +5354,7 @@ var customWatermark = (text = "KYE", el = ".ksui-container, .van-dialog, .ksui-c
5250
5354
  document.querySelector("head").appendChild(style);
5251
5355
  };
5252
5356
  function useWaterMark(employeeNumber, el = ".ksui-container, .van-dialog, .ksui-card, .ks-table", color = "#F0F3F9") {
5253
- let date = new Date();
5357
+ let date = /* @__PURE__ */ new Date();
5254
5358
  const f = (num) => {
5255
5359
  let str = String(num);
5256
5360
  return str.length === 1 ? "0" + str : str;
@@ -5298,7 +5402,7 @@ var debounce = (func, wait, options) => {
5298
5402
  return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
5299
5403
  }
5300
5404
  function timerExpired() {
5301
- var time = new Date().getTime();
5405
+ var time = (/* @__PURE__ */ new Date()).getTime();
5302
5406
  if (shouldInvoke(time)) {
5303
5407
  return trailingEdge(time);
5304
5408
  }
@@ -5320,10 +5424,10 @@ var debounce = (func, wait, options) => {
5320
5424
  lastArgs = lastCallTime = lastThis = timerId = void 0;
5321
5425
  }
5322
5426
  function flush() {
5323
- return timerId === void 0 ? result : trailingEdge(new Date().getTime());
5427
+ return timerId === void 0 ? result : trailingEdge((/* @__PURE__ */ new Date()).getTime());
5324
5428
  }
5325
5429
  function debounced() {
5326
- var time = new Date().getTime(), isInvoking = shouldInvoke(time);
5430
+ var time = (/* @__PURE__ */ new Date()).getTime(), isInvoking = shouldInvoke(time);
5327
5431
  lastArgs = arguments;
5328
5432
  lastThis = this;
5329
5433
  lastCallTime = time;
@@ -5,6 +5,6 @@ export type UseEventListenerOptions = {
5
5
  capture?: boolean;
6
6
  passive?: boolean;
7
7
  };
8
- export declare function useEventListener<K extends keyof DocumentEventMap>(type: K, listener: (event: DocumentEventMap[K]) => void, options?: UseEventListenerOptions): void;
8
+ export declare function useEventListener<K extends keyof DocumentEventMap>(type: K, listener: (event: DocumentEventMap[K]) => void, options?: UseEventListenerOptions): () => void;
9
9
  export declare function useEventListener(type: string, listener: EventListener, options?: UseEventListenerOptions): void;
10
10
  export {};
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@ks-web/use",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "description": "Vant Composition API",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.mjs",
7
7
  "typings": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.esm.mjs",
11
12
  "require": "./dist/index.cjs.js"
12
13
  }
@@ -40,18 +41,21 @@
40
41
  "@types/js-md5": "0.7.0",
41
42
  "@types/qs": "6.9.7",
42
43
  "axios": "1.3.3",
43
- "esbuild": "0.16.10",
44
+ "esbuild": "^0.17.12",
44
45
  "js-md5": "0.7.3",
45
46
  "qs": "6.11.0",
46
47
  "release-it": "^15.4.1",
47
- "rimraf": "^4.0.4",
48
- "typescript": "^4.8.2",
49
- "vue": "^3.2.45"
48
+ "rimraf": "^5.0.0",
49
+ "typescript": "^5.0.4",
50
+ "vue": "^3.3.4"
51
+ },
52
+ "peerDependencies": {
53
+ "vue": "^3.0.0"
50
54
  },
51
55
  "release-it": {
52
56
  "git": {
53
57
  "tag": false,
54
- "commitMessage": "release: @vant/use ${version}"
58
+ "commitMessage": "release: @ks-web/use v${version}"
55
59
  }
56
60
  }
57
61
  }