@hairy/uni-lib 1.46.0 → 1.49.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.
- package/LICENSE.md +21 -21
- package/README.md +36 -36
- package/dist/index.cjs +33 -60
- package/dist/{index.d.ts → index.d.cts} +10 -7
- package/dist/index.d.mts +34 -0
- package/dist/index.mjs +39 -0
- package/package.json +17 -18
- package/dist/index.global.js +0 -97
- package/dist/index.js +0 -40
package/LICENSE.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
# @hairy/vue-lib
|
|
2
|
-
|
|
3
|
-
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
-
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
-
[![bundle][bundle-src]][bundle-href]
|
|
6
|
-
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
7
|
-
[![License][license-src]][license-href]
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
ni @hairy/vue-lib
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## CDN
|
|
16
|
-
|
|
17
|
-
```html
|
|
18
|
-
<script src="https://unpkg.com/@hairy/vue-lib"></script>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## License
|
|
22
|
-
|
|
23
|
-
[MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
|
|
24
|
-
|
|
25
|
-
<!-- Badges -->
|
|
26
|
-
|
|
27
|
-
[npm-version-src]: https://img.shields.io/npm/v/@hairy/vue-lib?style=flat&colorA=080f12&colorB=1fa669
|
|
28
|
-
[npm-version-href]: https://npmjs.com/package/@hairy/vue-lib
|
|
29
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/vue-lib?style=flat&colorA=080f12&colorB=1fa669
|
|
30
|
-
[npm-downloads-href]: https://npmjs.com/package/@hairy/vue-lib
|
|
31
|
-
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/vue-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
32
|
-
[bundle-href]: https://bundlephobia.com/result?p=@hairy/vue-lib
|
|
33
|
-
[license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
34
|
-
[license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
|
|
35
|
-
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
36
|
-
[jsdocs-href]: https://www.jsdocs.io/package/@hairy/vue-lib
|
|
1
|
+
# @hairy/vue-lib
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![bundle][bundle-src]][bundle-href]
|
|
6
|
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
7
|
+
[![License][license-src]][license-href]
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
ni @hairy/vue-lib
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## CDN
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script src="https://unpkg.com/@hairy/vue-lib"></script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
[MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
|
|
24
|
+
|
|
25
|
+
<!-- Badges -->
|
|
26
|
+
|
|
27
|
+
[npm-version-src]: https://img.shields.io/npm/v/@hairy/vue-lib?style=flat&colorA=080f12&colorB=1fa669
|
|
28
|
+
[npm-version-href]: https://npmjs.com/package/@hairy/vue-lib
|
|
29
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/vue-lib?style=flat&colorA=080f12&colorB=1fa669
|
|
30
|
+
[npm-downloads-href]: https://npmjs.com/package/@hairy/vue-lib
|
|
31
|
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/vue-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
32
|
+
[bundle-href]: https://bundlephobia.com/result?p=@hairy/vue-lib
|
|
33
|
+
[license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
34
|
+
[license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
|
|
35
|
+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
36
|
+
[jsdocs-href]: https://www.jsdocs.io/package/@hairy/vue-lib
|
package/dist/index.cjs
CHANGED
|
@@ -1,69 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _hairy_utils = require("@hairy/utils");
|
|
3
|
+
let vue = require("vue");
|
|
19
4
|
|
|
20
|
-
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
createQuerySelector: () => createQuerySelector,
|
|
24
|
-
useQuerySelector: () => useQuerySelector,
|
|
25
|
-
useQuerySelectorAll: () => useQuerySelectorAll
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
|
-
// src/utils/index.ts
|
|
30
|
-
var import_utils = require("@hairy/utils");
|
|
31
|
-
var import_vue = require("vue");
|
|
5
|
+
//#region src/utils/index.ts
|
|
32
6
|
function createQuerySelector(type, mode = "select") {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(0, import_vue.onMounted)(ready.resolve);
|
|
52
|
-
return query;
|
|
7
|
+
const ready = new _hairy_utils.Deferred();
|
|
8
|
+
const instance = (0, vue.getCurrentInstance)();
|
|
9
|
+
function query(selector, fields = {}) {
|
|
10
|
+
const promise = new _hairy_utils.Deferred();
|
|
11
|
+
function resolve(value) {
|
|
12
|
+
const result = Array.isArray(value) ? value : [value];
|
|
13
|
+
const resolved = mode === "select" ? result[0] : result;
|
|
14
|
+
result.length ? promise.resolve(resolved) : promise.reject();
|
|
15
|
+
}
|
|
16
|
+
ready.then(() => {
|
|
17
|
+
const query = uni.createSelectorQuery().in(instance)[mode](selector);
|
|
18
|
+
if (type === "fields") query.fields(fields, resolve).exec();
|
|
19
|
+
else query[type](resolve).exec();
|
|
20
|
+
});
|
|
21
|
+
return promise;
|
|
22
|
+
}
|
|
23
|
+
(0, vue.onMounted)(ready.resolve);
|
|
24
|
+
return query;
|
|
53
25
|
}
|
|
54
26
|
|
|
55
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/hooks/useQuerySelector.ts
|
|
56
29
|
function useQuerySelector(...args) {
|
|
57
|
-
|
|
30
|
+
return createQuerySelector(args[0], "select");
|
|
58
31
|
}
|
|
59
32
|
|
|
60
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/hooks/useQuerySelectorAll.ts
|
|
61
35
|
function useQuerySelectorAll(...args) {
|
|
62
|
-
|
|
36
|
+
return createQuerySelector(args[0], "selectAll");
|
|
63
37
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.createQuerySelector = createQuerySelector;
|
|
41
|
+
exports.useQuerySelector = useQuerySelector;
|
|
42
|
+
exports.useQuerySelectorAll = useQuerySelectorAll;
|
|
@@ -1,31 +1,34 @@
|
|
|
1
|
+
//#region src/utils/index.d.ts
|
|
1
2
|
type QuerySelectorType = 'boundingClientRect' | 'context' | 'fields' | 'node' | 'scrollOffset';
|
|
2
3
|
type QuerySelectorMode = 'select' | 'selectAll';
|
|
3
4
|
type QuerySelectorResponse<M extends QuerySelectorMode, V = UniApp.NodeInfo> = M extends 'selectAll' ? V[] : V;
|
|
4
5
|
interface QuerySelectorNodeInfo<M extends QuerySelectorMode = 'select'> {
|
|
5
|
-
|
|
6
|
+
(selector: string): Promise<QuerySelectorResponse<M>>;
|
|
6
7
|
}
|
|
7
8
|
interface QuerySelectorNodeFields<M extends QuerySelectorMode = 'select'> {
|
|
8
|
-
|
|
9
|
+
(selector: string, fields?: UniApp.NodeField): Promise<QuerySelectorResponse<M>>;
|
|
9
10
|
}
|
|
10
11
|
interface QuerySelectorNode<M extends QuerySelectorMode = 'select'> {
|
|
11
|
-
|
|
12
|
+
(selector: string): Promise<QuerySelectorResponse<M, any>>;
|
|
12
13
|
}
|
|
13
14
|
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'boundingClientRect', mode?: M): QuerySelectorNodeInfo<M>;
|
|
14
15
|
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'context', mode?: M): QuerySelectorNodeInfo<M>;
|
|
15
16
|
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'scrollOffset', mode?: M): QuerySelectorNodeInfo<M>;
|
|
16
17
|
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'fields', mode?: M): QuerySelectorNodeFields<M>;
|
|
17
18
|
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'node', mode?: M): QuerySelectorNode<M>;
|
|
18
|
-
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/hooks/useQuerySelector.d.ts
|
|
19
21
|
declare function useQuerySelector(type: 'boundingClientRect'): QuerySelectorNodeInfo;
|
|
20
22
|
declare function useQuerySelector(type: 'context'): QuerySelectorNodeInfo;
|
|
21
23
|
declare function useQuerySelector(type: 'scrollOffset'): QuerySelectorNodeInfo;
|
|
22
24
|
declare function useQuerySelector(type: 'fields'): QuerySelectorNodeFields;
|
|
23
25
|
declare function useQuerySelector(type: 'node'): QuerySelectorNode;
|
|
24
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hooks/useQuerySelectorAll.d.ts
|
|
25
28
|
declare function useQuerySelectorAll(type: 'boundingClientRect'): QuerySelectorNodeInfo<'selectAll'>;
|
|
26
29
|
declare function useQuerySelectorAll(type: 'context'): QuerySelectorNodeInfo<'selectAll'>;
|
|
27
30
|
declare function useQuerySelectorAll(type: 'scrollOffset'): QuerySelectorNodeInfo<'selectAll'>;
|
|
28
31
|
declare function useQuerySelectorAll(type: 'fields'): QuerySelectorNodeFields<'selectAll'>;
|
|
29
32
|
declare function useQuerySelectorAll(type: 'node'): QuerySelectorNode<'selectAll'>;
|
|
30
|
-
|
|
31
|
-
export {
|
|
33
|
+
//#endregion
|
|
34
|
+
export { QuerySelectorMode, QuerySelectorNode, QuerySelectorNodeFields, QuerySelectorNodeInfo, QuerySelectorResponse, QuerySelectorType, createQuerySelector, useQuerySelector, useQuerySelectorAll };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/utils/index.d.ts
|
|
2
|
+
type QuerySelectorType = 'boundingClientRect' | 'context' | 'fields' | 'node' | 'scrollOffset';
|
|
3
|
+
type QuerySelectorMode = 'select' | 'selectAll';
|
|
4
|
+
type QuerySelectorResponse<M extends QuerySelectorMode, V = UniApp.NodeInfo> = M extends 'selectAll' ? V[] : V;
|
|
5
|
+
interface QuerySelectorNodeInfo<M extends QuerySelectorMode = 'select'> {
|
|
6
|
+
(selector: string): Promise<QuerySelectorResponse<M>>;
|
|
7
|
+
}
|
|
8
|
+
interface QuerySelectorNodeFields<M extends QuerySelectorMode = 'select'> {
|
|
9
|
+
(selector: string, fields?: UniApp.NodeField): Promise<QuerySelectorResponse<M>>;
|
|
10
|
+
}
|
|
11
|
+
interface QuerySelectorNode<M extends QuerySelectorMode = 'select'> {
|
|
12
|
+
(selector: string): Promise<QuerySelectorResponse<M, any>>;
|
|
13
|
+
}
|
|
14
|
+
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'boundingClientRect', mode?: M): QuerySelectorNodeInfo<M>;
|
|
15
|
+
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'context', mode?: M): QuerySelectorNodeInfo<M>;
|
|
16
|
+
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'scrollOffset', mode?: M): QuerySelectorNodeInfo<M>;
|
|
17
|
+
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'fields', mode?: M): QuerySelectorNodeFields<M>;
|
|
18
|
+
declare function createQuerySelector<M extends QuerySelectorMode = 'select'>(type: 'node', mode?: M): QuerySelectorNode<M>;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/hooks/useQuerySelector.d.ts
|
|
21
|
+
declare function useQuerySelector(type: 'boundingClientRect'): QuerySelectorNodeInfo;
|
|
22
|
+
declare function useQuerySelector(type: 'context'): QuerySelectorNodeInfo;
|
|
23
|
+
declare function useQuerySelector(type: 'scrollOffset'): QuerySelectorNodeInfo;
|
|
24
|
+
declare function useQuerySelector(type: 'fields'): QuerySelectorNodeFields;
|
|
25
|
+
declare function useQuerySelector(type: 'node'): QuerySelectorNode;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hooks/useQuerySelectorAll.d.ts
|
|
28
|
+
declare function useQuerySelectorAll(type: 'boundingClientRect'): QuerySelectorNodeInfo<'selectAll'>;
|
|
29
|
+
declare function useQuerySelectorAll(type: 'context'): QuerySelectorNodeInfo<'selectAll'>;
|
|
30
|
+
declare function useQuerySelectorAll(type: 'scrollOffset'): QuerySelectorNodeInfo<'selectAll'>;
|
|
31
|
+
declare function useQuerySelectorAll(type: 'fields'): QuerySelectorNodeFields<'selectAll'>;
|
|
32
|
+
declare function useQuerySelectorAll(type: 'node'): QuerySelectorNode<'selectAll'>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { QuerySelectorMode, QuerySelectorNode, QuerySelectorNodeFields, QuerySelectorNodeInfo, QuerySelectorResponse, QuerySelectorType, createQuerySelector, useQuerySelector, useQuerySelectorAll };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Deferred } from "@hairy/utils";
|
|
2
|
+
import { getCurrentInstance, onMounted } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/index.ts
|
|
5
|
+
function createQuerySelector(type, mode = "select") {
|
|
6
|
+
const ready = new Deferred();
|
|
7
|
+
const instance = getCurrentInstance();
|
|
8
|
+
function query(selector, fields = {}) {
|
|
9
|
+
const promise = new Deferred();
|
|
10
|
+
function resolve(value) {
|
|
11
|
+
const result = Array.isArray(value) ? value : [value];
|
|
12
|
+
const resolved = mode === "select" ? result[0] : result;
|
|
13
|
+
result.length ? promise.resolve(resolved) : promise.reject();
|
|
14
|
+
}
|
|
15
|
+
ready.then(() => {
|
|
16
|
+
const query = uni.createSelectorQuery().in(instance)[mode](selector);
|
|
17
|
+
if (type === "fields") query.fields(fields, resolve).exec();
|
|
18
|
+
else query[type](resolve).exec();
|
|
19
|
+
});
|
|
20
|
+
return promise;
|
|
21
|
+
}
|
|
22
|
+
onMounted(ready.resolve);
|
|
23
|
+
return query;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hooks/useQuerySelector.ts
|
|
28
|
+
function useQuerySelector(...args) {
|
|
29
|
+
return createQuerySelector(args[0], "select");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/hooks/useQuerySelectorAll.ts
|
|
34
|
+
function useQuerySelectorAll(...args) {
|
|
35
|
+
return createQuerySelector(args[0], "selectAll");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createQuerySelector, useQuerySelector, useQuerySelectorAll };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/uni-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.49.0",
|
|
5
5
|
"description": "Library for vue",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -14,13 +14,22 @@
|
|
|
14
14
|
"bugs": "https://github.com/hairyf/hairylib/issues",
|
|
15
15
|
"keywords": [],
|
|
16
16
|
"sideEffects": false,
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
20
23
|
},
|
|
24
|
+
"main": "./dist/index.mjs",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
21
27
|
"files": [
|
|
22
28
|
"dist"
|
|
23
29
|
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"jsdelivr": "./dist/index.iife.js"
|
|
32
|
+
},
|
|
24
33
|
"peerDependencies": {
|
|
25
34
|
"@vue/composition-api": "^1.0.0-rc.1",
|
|
26
35
|
"vue": "^2.0.0 || >=3.0.0"
|
|
@@ -35,7 +44,7 @@
|
|
|
35
44
|
"css-render": "^0.15.14",
|
|
36
45
|
"lodash": "^4.17.21",
|
|
37
46
|
"vue-demi": "latest",
|
|
38
|
-
"@hairy/utils": "1.
|
|
47
|
+
"@hairy/utils": "1.49.0"
|
|
39
48
|
},
|
|
40
49
|
"devDependencies": {
|
|
41
50
|
"@dcloudio/types": "^3.4.28",
|
|
@@ -43,19 +52,9 @@
|
|
|
43
52
|
"vue": "^3.2.29"
|
|
44
53
|
},
|
|
45
54
|
"scripts": {
|
|
46
|
-
"build": "
|
|
47
|
-
"dev": "
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"dev": "tsdown --watch",
|
|
48
57
|
"start": "tsx src/index.ts"
|
|
49
58
|
},
|
|
50
|
-
"
|
|
51
|
-
"types": "./dist/index.d.ts",
|
|
52
|
-
"unpkg": "./dist/index.global.js",
|
|
53
|
-
"exports": {
|
|
54
|
-
".": {
|
|
55
|
-
"import": "./dist/index.js",
|
|
56
|
-
"require": "./dist/index.cjs",
|
|
57
|
-
"types": "./dist/index.d.ts"
|
|
58
|
-
},
|
|
59
|
-
"./*": "./*"
|
|
60
|
-
}
|
|
59
|
+
"unpkg": "./dist/index.iife.js"
|
|
61
60
|
}
|
package/dist/index.global.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
(() => {
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
|
|
29
|
-
// globals:vue
|
|
30
|
-
var require_vue = __commonJS({
|
|
31
|
-
"globals:vue"(exports, module) {
|
|
32
|
-
"use strict";
|
|
33
|
-
module.exports = Vue;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// ../util-core/src/util/noop.ts
|
|
38
|
-
var noop = () => {
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// ../util-core/src/util/deferred.ts
|
|
42
|
-
var Deferred = class extends Promise {
|
|
43
|
-
resolve;
|
|
44
|
-
reject;
|
|
45
|
-
constructor(executor = noop) {
|
|
46
|
-
let _resolve, _reject;
|
|
47
|
-
super((resolve_, reject_) => {
|
|
48
|
-
_resolve = resolve_;
|
|
49
|
-
_reject = reject_;
|
|
50
|
-
return executor(resolve_, reject_);
|
|
51
|
-
});
|
|
52
|
-
this.resolve = (value) => {
|
|
53
|
-
_resolve(value);
|
|
54
|
-
return this;
|
|
55
|
-
};
|
|
56
|
-
this.reject = (reason) => {
|
|
57
|
-
_reject(reason);
|
|
58
|
-
return this;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/utils/index.ts
|
|
64
|
-
var import_vue = __toESM(require_vue(), 1);
|
|
65
|
-
function createQuerySelector(type, mode = "select") {
|
|
66
|
-
const ready = new Deferred();
|
|
67
|
-
const instance = (0, import_vue.getCurrentInstance)();
|
|
68
|
-
function query(selector, fields = {}) {
|
|
69
|
-
const promise = new Deferred();
|
|
70
|
-
function resolve(value) {
|
|
71
|
-
const result = Array.isArray(value) ? value : [value];
|
|
72
|
-
const resolved = mode === "select" ? result[0] : result;
|
|
73
|
-
result.length ? promise.resolve(resolved) : promise.reject();
|
|
74
|
-
}
|
|
75
|
-
ready.then(() => {
|
|
76
|
-
const query2 = uni.createSelectorQuery().in(instance)[mode](selector);
|
|
77
|
-
if (type === "fields")
|
|
78
|
-
query2.fields(fields, resolve).exec();
|
|
79
|
-
else
|
|
80
|
-
query2[type](resolve).exec();
|
|
81
|
-
});
|
|
82
|
-
return promise;
|
|
83
|
-
}
|
|
84
|
-
(0, import_vue.onMounted)(ready.resolve);
|
|
85
|
-
return query;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/hooks/useQuerySelector.ts
|
|
89
|
-
function useQuerySelector(...args) {
|
|
90
|
-
return createQuerySelector(args[0], "select");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/hooks/useQuerySelectorAll.ts
|
|
94
|
-
function useQuerySelectorAll(...args) {
|
|
95
|
-
return createQuerySelector(args[0], "selectAll");
|
|
96
|
-
}
|
|
97
|
-
})();
|
package/dist/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// src/utils/index.ts
|
|
2
|
-
import { Deferred } from "@hairy/utils";
|
|
3
|
-
import { getCurrentInstance, onMounted } from "vue";
|
|
4
|
-
function createQuerySelector(type, mode = "select") {
|
|
5
|
-
const ready = new Deferred();
|
|
6
|
-
const instance = getCurrentInstance();
|
|
7
|
-
function query(selector, fields = {}) {
|
|
8
|
-
const promise = new Deferred();
|
|
9
|
-
function resolve(value) {
|
|
10
|
-
const result = Array.isArray(value) ? value : [value];
|
|
11
|
-
const resolved = mode === "select" ? result[0] : result;
|
|
12
|
-
result.length ? promise.resolve(resolved) : promise.reject();
|
|
13
|
-
}
|
|
14
|
-
ready.then(() => {
|
|
15
|
-
const query2 = uni.createSelectorQuery().in(instance)[mode](selector);
|
|
16
|
-
if (type === "fields")
|
|
17
|
-
query2.fields(fields, resolve).exec();
|
|
18
|
-
else
|
|
19
|
-
query2[type](resolve).exec();
|
|
20
|
-
});
|
|
21
|
-
return promise;
|
|
22
|
-
}
|
|
23
|
-
onMounted(ready.resolve);
|
|
24
|
-
return query;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/hooks/useQuerySelector.ts
|
|
28
|
-
function useQuerySelector(...args) {
|
|
29
|
-
return createQuerySelector(args[0], "select");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// src/hooks/useQuerySelectorAll.ts
|
|
33
|
-
function useQuerySelectorAll(...args) {
|
|
34
|
-
return createQuerySelector(args[0], "selectAll");
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
createQuerySelector,
|
|
38
|
-
useQuerySelector,
|
|
39
|
-
useQuerySelectorAll
|
|
40
|
-
};
|