@deot/vc-hooks 1.0.65 → 1.0.67

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.cjs CHANGED
@@ -1,72 +1,66 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const vue = require('vue');
6
-
7
- const useAttrs = (options) => {
8
- const attrs = vue.useAttrs();
9
- const { merge = true, exclude = [] } = options || {};
10
- return vue.computed(() => {
11
- if (merge && !exclude.length) return attrs;
12
- const result = Object.entries(attrs).reduce((pre, [key, val]) => {
13
- if (exclude.includes(key)) return pre;
14
- if (!merge && /^on([A-Z])/.test(key)) {
15
- pre.listeners[key] = val;
16
- } else if (!merge && /(class|style)/.test(key)) {
17
- pre[key] = val;
18
- } else {
19
- pre.attrs[key] = val;
20
- }
21
- return pre;
22
- }, {
23
- style: void 0,
24
- class: void 0,
25
- attrs: {},
26
- listeners: {}
27
- });
28
- return merge ? result.attrs : result;
29
- });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let vue = require("vue");
3
+ //#region packages/hooks/src/use-attrs.ts
4
+ /**
5
+ * Tips:
6
+ * 1. attrs: 未在emits和props中的值;
7
+ * 2. inheritAttrs只是取决于是否作用到根节点上
8
+ * @param options ~
9
+ * @returns ~
10
+ */
11
+ var useAttrs = (options) => {
12
+ const attrs = (0, vue.useAttrs)();
13
+ const { merge = true, exclude = [] } = options || {};
14
+ return (0, vue.computed)(() => {
15
+ if (merge && !exclude.length) return attrs;
16
+ const result = Object.entries(attrs).reduce((pre, [key, val]) => {
17
+ if (exclude.includes(key)) return pre;
18
+ if (!merge && /^on([A-Z])/.test(key)) pre.listeners[key] = val;
19
+ else if (!merge && /(class|style)/.test(key)) pre[key] = val;
20
+ else pre.attrs[key] = val;
21
+ return pre;
22
+ }, {
23
+ style: void 0,
24
+ class: void 0,
25
+ attrs: {},
26
+ listeners: {}
27
+ });
28
+ return merge ? result.attrs : result;
29
+ });
30
30
  };
31
-
32
- const useScrollbar = (visibleRef) => {
33
- let original = "";
34
- let isMounted = false;
35
- const setScrollBar = (v) => {
36
- if (!isMounted || original === "hidden") return;
37
- if (v) {
38
- document.body.style.overflow = "hidden";
39
- } else {
40
- document.body.style.removeProperty("overflow");
41
- }
42
- };
43
- vue.watch(
44
- () => visibleRef.value,
45
- (v) => {
46
- setScrollBar(v);
47
- },
48
- { immediate: false }
49
- );
50
- vue.onMounted(() => {
51
- isMounted = true;
52
- original = document.body.style.overflow;
53
- visibleRef.value && setScrollBar(true);
54
- });
55
- vue.onBeforeUnmount(() => {
56
- setScrollBar(false);
57
- });
31
+ //#endregion
32
+ //#region packages/hooks/src/use-scrollbar.ts
33
+ var useScrollbar = (visibleRef) => {
34
+ let original = "";
35
+ let isMounted = false;
36
+ const setScrollBar = (v) => {
37
+ if (!isMounted || original === "hidden") return;
38
+ if (v) document.body.style.overflow = "hidden";
39
+ else document.body.style.removeProperty("overflow");
40
+ };
41
+ (0, vue.watch)(() => visibleRef.value, (v) => {
42
+ setScrollBar(v);
43
+ }, { immediate: false });
44
+ (0, vue.onMounted)(() => {
45
+ isMounted = true;
46
+ original = document.body.style.overflow;
47
+ visibleRef.value && setScrollBar(true);
48
+ });
49
+ (0, vue.onBeforeUnmount)(() => {
50
+ setScrollBar(false);
51
+ });
58
52
  };
59
-
60
- const getInstance = (componentName, privateKey) => {
61
- const instance = vue.getCurrentInstance();
62
- const regex = new RegExp(`${componentName}$`);
63
- let parent = instance.parent;
64
- while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) {
65
- parent = parent.parent || parent?.type?.parent;
66
- }
67
- return parent;
53
+ //#endregion
54
+ //#region packages/hooks/src/get-instance.ts
55
+ var getInstance = (componentName, privateKey) => {
56
+ const instance = (0, vue.getCurrentInstance)();
57
+ const regex = new RegExp(`${componentName}$`);
58
+ let parent = instance.parent;
59
+ /* istanbul ignore next -- @preserve */
60
+ while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) parent = parent.parent || (parent?.type)?.parent;
61
+ return parent;
68
62
  };
69
-
63
+ //#endregion
70
64
  exports.getInstance = getInstance;
71
65
  exports.useAttrs = useAttrs;
72
66
  exports.useScrollbar = useScrollbar;
@@ -1,75 +1,68 @@
1
- var VcHooks = (function (exports, vue) {
2
- 'use strict';
3
-
4
- const useAttrs = (options) => {
5
- const attrs = vue.useAttrs();
6
- const { merge = true, exclude = [] } = options || {};
7
- return vue.computed(() => {
8
- if (merge && !exclude.length) return attrs;
9
- const result = Object.entries(attrs).reduce((pre, [key, val]) => {
10
- if (exclude.includes(key)) return pre;
11
- if (!merge && /^on([A-Z])/.test(key)) {
12
- pre.listeners[key] = val;
13
- } else if (!merge && /(class|style)/.test(key)) {
14
- pre[key] = val;
15
- } else {
16
- pre.attrs[key] = val;
17
- }
18
- return pre;
19
- }, {
20
- style: void 0,
21
- class: void 0,
22
- attrs: {},
23
- listeners: {}
24
- });
25
- return merge ? result.attrs : result;
26
- });
1
+ var VcHooks = (function(exports, vue) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ //#region packages/hooks/src/use-attrs.ts
4
+ /**
5
+ * Tips:
6
+ * 1. attrs: 未在emits和props中的值;
7
+ * 2. inheritAttrs只是取决于是否作用到根节点上
8
+ * @param options ~
9
+ * @returns ~
10
+ */
11
+ var useAttrs = (options) => {
12
+ const attrs = (0, vue.useAttrs)();
13
+ const { merge = true, exclude = [] } = options || {};
14
+ return (0, vue.computed)(() => {
15
+ if (merge && !exclude.length) return attrs;
16
+ const result = Object.entries(attrs).reduce((pre, [key, val]) => {
17
+ if (exclude.includes(key)) return pre;
18
+ if (!merge && /^on([A-Z])/.test(key)) pre.listeners[key] = val;
19
+ else if (!merge && /(class|style)/.test(key)) pre[key] = val;
20
+ else pre.attrs[key] = val;
21
+ return pre;
22
+ }, {
23
+ style: void 0,
24
+ class: void 0,
25
+ attrs: {},
26
+ listeners: {}
27
+ });
28
+ return merge ? result.attrs : result;
29
+ });
27
30
  };
28
-
29
- const useScrollbar = (visibleRef) => {
30
- let original = "";
31
- let isMounted = false;
32
- const setScrollBar = (v) => {
33
- if (!isMounted || original === "hidden") return;
34
- if (v) {
35
- document.body.style.overflow = "hidden";
36
- } else {
37
- document.body.style.removeProperty("overflow");
38
- }
39
- };
40
- vue.watch(
41
- () => visibleRef.value,
42
- (v) => {
43
- setScrollBar(v);
44
- },
45
- { immediate: false }
46
- );
47
- vue.onMounted(() => {
48
- isMounted = true;
49
- original = document.body.style.overflow;
50
- visibleRef.value && setScrollBar(true);
51
- });
52
- vue.onBeforeUnmount(() => {
53
- setScrollBar(false);
54
- });
31
+ //#endregion
32
+ //#region packages/hooks/src/use-scrollbar.ts
33
+ var useScrollbar = (visibleRef) => {
34
+ let original = "";
35
+ let isMounted = false;
36
+ const setScrollBar = (v) => {
37
+ if (!isMounted || original === "hidden") return;
38
+ if (v) document.body.style.overflow = "hidden";
39
+ else document.body.style.removeProperty("overflow");
40
+ };
41
+ (0, vue.watch)(() => visibleRef.value, (v) => {
42
+ setScrollBar(v);
43
+ }, { immediate: false });
44
+ (0, vue.onMounted)(() => {
45
+ isMounted = true;
46
+ original = document.body.style.overflow;
47
+ visibleRef.value && setScrollBar(true);
48
+ });
49
+ (0, vue.onBeforeUnmount)(() => {
50
+ setScrollBar(false);
51
+ });
55
52
  };
56
-
57
- const getInstance = (componentName, privateKey) => {
58
- const instance = vue.getCurrentInstance();
59
- const regex = new RegExp(`${componentName}$`);
60
- let parent = instance.parent;
61
- while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) {
62
- parent = parent.parent || parent?.type?.parent;
63
- }
64
- return parent;
53
+ //#endregion
54
+ //#region packages/hooks/src/get-instance.ts
55
+ var getInstance = (componentName, privateKey) => {
56
+ const instance = (0, vue.getCurrentInstance)();
57
+ const regex = new RegExp(`${componentName}$`);
58
+ let parent = instance.parent;
59
+ /* istanbul ignore next -- @preserve */
60
+ while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) parent = parent.parent || (parent?.type)?.parent;
61
+ return parent;
65
62
  };
66
-
63
+ //#endregion
67
64
  exports.getInstance = getInstance;
68
65
  exports.useAttrs = useAttrs;
69
66
  exports.useScrollbar = useScrollbar;
70
-
71
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
72
-
73
67
  return exports;
74
-
75
68
  })({}, Vue);
package/dist/index.js CHANGED
@@ -1,66 +1,63 @@
1
- import { useAttrs as useAttrs$1, computed, watch, onMounted, onBeforeUnmount, getCurrentInstance } from 'vue';
2
-
3
- const useAttrs = (options) => {
4
- const attrs = useAttrs$1();
5
- const { merge = true, exclude = [] } = options || {};
6
- return computed(() => {
7
- if (merge && !exclude.length) return attrs;
8
- const result = Object.entries(attrs).reduce((pre, [key, val]) => {
9
- if (exclude.includes(key)) return pre;
10
- if (!merge && /^on([A-Z])/.test(key)) {
11
- pre.listeners[key] = val;
12
- } else if (!merge && /(class|style)/.test(key)) {
13
- pre[key] = val;
14
- } else {
15
- pre.attrs[key] = val;
16
- }
17
- return pre;
18
- }, {
19
- style: void 0,
20
- class: void 0,
21
- attrs: {},
22
- listeners: {}
23
- });
24
- return merge ? result.attrs : result;
25
- });
1
+ import { computed, getCurrentInstance, onBeforeUnmount, onMounted, useAttrs as useAttrs$1, watch } from "vue";
2
+ //#region packages/hooks/src/use-attrs.ts
3
+ /**
4
+ * Tips:
5
+ * 1. attrs: 未在emits和props中的值;
6
+ * 2. inheritAttrs只是取决于是否作用到根节点上
7
+ * @param options ~
8
+ * @returns ~
9
+ */
10
+ var useAttrs = (options) => {
11
+ const attrs = useAttrs$1();
12
+ const { merge = true, exclude = [] } = options || {};
13
+ return computed(() => {
14
+ if (merge && !exclude.length) return attrs;
15
+ const result = Object.entries(attrs).reduce((pre, [key, val]) => {
16
+ if (exclude.includes(key)) return pre;
17
+ if (!merge && /^on([A-Z])/.test(key)) pre.listeners[key] = val;
18
+ else if (!merge && /(class|style)/.test(key)) pre[key] = val;
19
+ else pre.attrs[key] = val;
20
+ return pre;
21
+ }, {
22
+ style: void 0,
23
+ class: void 0,
24
+ attrs: {},
25
+ listeners: {}
26
+ });
27
+ return merge ? result.attrs : result;
28
+ });
26
29
  };
27
-
28
- const useScrollbar = (visibleRef) => {
29
- let original = "";
30
- let isMounted = false;
31
- const setScrollBar = (v) => {
32
- if (!isMounted || original === "hidden") return;
33
- if (v) {
34
- document.body.style.overflow = "hidden";
35
- } else {
36
- document.body.style.removeProperty("overflow");
37
- }
38
- };
39
- watch(
40
- () => visibleRef.value,
41
- (v) => {
42
- setScrollBar(v);
43
- },
44
- { immediate: false }
45
- );
46
- onMounted(() => {
47
- isMounted = true;
48
- original = document.body.style.overflow;
49
- visibleRef.value && setScrollBar(true);
50
- });
51
- onBeforeUnmount(() => {
52
- setScrollBar(false);
53
- });
30
+ //#endregion
31
+ //#region packages/hooks/src/use-scrollbar.ts
32
+ var useScrollbar = (visibleRef) => {
33
+ let original = "";
34
+ let isMounted = false;
35
+ const setScrollBar = (v) => {
36
+ if (!isMounted || original === "hidden") return;
37
+ if (v) document.body.style.overflow = "hidden";
38
+ else document.body.style.removeProperty("overflow");
39
+ };
40
+ watch(() => visibleRef.value, (v) => {
41
+ setScrollBar(v);
42
+ }, { immediate: false });
43
+ onMounted(() => {
44
+ isMounted = true;
45
+ original = document.body.style.overflow;
46
+ visibleRef.value && setScrollBar(true);
47
+ });
48
+ onBeforeUnmount(() => {
49
+ setScrollBar(false);
50
+ });
54
51
  };
55
-
56
- const getInstance = (componentName, privateKey) => {
57
- const instance = getCurrentInstance();
58
- const regex = new RegExp(`${componentName}$`);
59
- let parent = instance.parent;
60
- while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) {
61
- parent = parent.parent || parent?.type?.parent;
62
- }
63
- return parent;
52
+ //#endregion
53
+ //#region packages/hooks/src/get-instance.ts
54
+ var getInstance = (componentName, privateKey) => {
55
+ const instance = getCurrentInstance();
56
+ const regex = new RegExp(`${componentName}$`);
57
+ let parent = instance.parent;
58
+ /* istanbul ignore next -- @preserve */
59
+ while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) parent = parent.parent || (parent?.type)?.parent;
60
+ return parent;
64
61
  };
65
-
62
+ //#endregion
66
63
  export { getInstance, useAttrs, useScrollbar };
@@ -1,76 +1,69 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VcHooks = {}, global.Vue));
5
- })(this, (function (exports, vue) { 'use strict';
6
-
7
- const useAttrs = (options) => {
8
- const attrs = vue.useAttrs();
9
- const { merge = true, exclude = [] } = options || {};
10
- return vue.computed(() => {
11
- if (merge && !exclude.length) return attrs;
12
- const result = Object.entries(attrs).reduce((pre, [key, val]) => {
13
- if (exclude.includes(key)) return pre;
14
- if (!merge && /^on([A-Z])/.test(key)) {
15
- pre.listeners[key] = val;
16
- } else if (!merge && /(class|style)/.test(key)) {
17
- pre[key] = val;
18
- } else {
19
- pre.attrs[key] = val;
20
- }
21
- return pre;
22
- }, {
23
- style: void 0,
24
- class: void 0,
25
- attrs: {},
26
- listeners: {}
27
- });
28
- return merge ? result.attrs : result;
29
- });
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue")) : typeof define === "function" && define.amd ? define(["exports", "vue"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.VcHooks = {}, global.Vue));
3
+ })(this, function(exports, vue) {
4
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
+ //#region packages/hooks/src/use-attrs.ts
6
+ /**
7
+ * Tips:
8
+ * 1. attrs: 未在emits和props中的值;
9
+ * 2. inheritAttrs只是取决于是否作用到根节点上
10
+ * @param options ~
11
+ * @returns ~
12
+ */
13
+ var useAttrs = (options) => {
14
+ const attrs = (0, vue.useAttrs)();
15
+ const { merge = true, exclude = [] } = options || {};
16
+ return (0, vue.computed)(() => {
17
+ if (merge && !exclude.length) return attrs;
18
+ const result = Object.entries(attrs).reduce((pre, [key, val]) => {
19
+ if (exclude.includes(key)) return pre;
20
+ if (!merge && /^on([A-Z])/.test(key)) pre.listeners[key] = val;
21
+ else if (!merge && /(class|style)/.test(key)) pre[key] = val;
22
+ else pre.attrs[key] = val;
23
+ return pre;
24
+ }, {
25
+ style: void 0,
26
+ class: void 0,
27
+ attrs: {},
28
+ listeners: {}
29
+ });
30
+ return merge ? result.attrs : result;
31
+ });
30
32
  };
31
-
32
- const useScrollbar = (visibleRef) => {
33
- let original = "";
34
- let isMounted = false;
35
- const setScrollBar = (v) => {
36
- if (!isMounted || original === "hidden") return;
37
- if (v) {
38
- document.body.style.overflow = "hidden";
39
- } else {
40
- document.body.style.removeProperty("overflow");
41
- }
42
- };
43
- vue.watch(
44
- () => visibleRef.value,
45
- (v) => {
46
- setScrollBar(v);
47
- },
48
- { immediate: false }
49
- );
50
- vue.onMounted(() => {
51
- isMounted = true;
52
- original = document.body.style.overflow;
53
- visibleRef.value && setScrollBar(true);
54
- });
55
- vue.onBeforeUnmount(() => {
56
- setScrollBar(false);
57
- });
33
+ //#endregion
34
+ //#region packages/hooks/src/use-scrollbar.ts
35
+ var useScrollbar = (visibleRef) => {
36
+ let original = "";
37
+ let isMounted = false;
38
+ const setScrollBar = (v) => {
39
+ if (!isMounted || original === "hidden") return;
40
+ if (v) document.body.style.overflow = "hidden";
41
+ else document.body.style.removeProperty("overflow");
42
+ };
43
+ (0, vue.watch)(() => visibleRef.value, (v) => {
44
+ setScrollBar(v);
45
+ }, { immediate: false });
46
+ (0, vue.onMounted)(() => {
47
+ isMounted = true;
48
+ original = document.body.style.overflow;
49
+ visibleRef.value && setScrollBar(true);
50
+ });
51
+ (0, vue.onBeforeUnmount)(() => {
52
+ setScrollBar(false);
53
+ });
58
54
  };
59
-
60
- const getInstance = (componentName, privateKey) => {
61
- const instance = vue.getCurrentInstance();
62
- const regex = new RegExp(`${componentName}$`);
63
- let parent = instance.parent;
64
- while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) {
65
- parent = parent.parent || parent?.type?.parent;
66
- }
67
- return parent;
55
+ //#endregion
56
+ //#region packages/hooks/src/get-instance.ts
57
+ var getInstance = (componentName, privateKey) => {
58
+ const instance = (0, vue.getCurrentInstance)();
59
+ const regex = new RegExp(`${componentName}$`);
60
+ let parent = instance.parent;
61
+ /* istanbul ignore next -- @preserve */
62
+ while (parent && !(parent?.type?.name && regex.test(parent.type.name)) && (!privateKey || !parent?.[privateKey] || !parent?.proxy?.[privateKey])) parent = parent.parent || (parent?.type)?.parent;
63
+ return parent;
68
64
  };
69
-
65
+ //#endregion
70
66
  exports.getInstance = getInstance;
71
67
  exports.useAttrs = useAttrs;
72
68
  exports.useScrollbar = useScrollbar;
73
-
74
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
75
-
76
- }));
69
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/vc-hooks",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",