@univa/core 0.0.3 → 0.0.5
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 +21 -0
- package/dist/hooks.cjs +83 -0
- package/dist/hooks.d.cts +36 -0
- package/dist/hooks.d.ts +36 -0
- package/dist/hooks.js +56 -0
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +5 -3
- package/package.json +26 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lianghang
|
|
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/dist/hooks.cjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/hooks.ts
|
|
21
|
+
var hooks_exports = {};
|
|
22
|
+
__export(hooks_exports, {
|
|
23
|
+
usePageContext: () => usePageContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
26
|
+
|
|
27
|
+
// src/hooks/usePageContext/index.ts
|
|
28
|
+
var import_uni_app = require("@dcloudio/uni-app");
|
|
29
|
+
var import_vue = require("vue");
|
|
30
|
+
function usePageContext(options = {}) {
|
|
31
|
+
const isMounted = (0, import_vue.ref)(false);
|
|
32
|
+
const univaRootRef = (0, import_vue.ref)();
|
|
33
|
+
const scrollTop = (0, import_vue.ref)(0);
|
|
34
|
+
const mountedCallbacks = [];
|
|
35
|
+
const unmountedCallbacks = [];
|
|
36
|
+
const showAfterMountedCallbacks = [];
|
|
37
|
+
const onPageShowAfterMounted = (callback) => {
|
|
38
|
+
showAfterMountedCallbacks.push(callback);
|
|
39
|
+
};
|
|
40
|
+
const onPageMounted = (callback) => {
|
|
41
|
+
mountedCallbacks.push(callback);
|
|
42
|
+
};
|
|
43
|
+
const onPageUnmounted = (callback) => {
|
|
44
|
+
unmountedCallbacks.push(callback);
|
|
45
|
+
};
|
|
46
|
+
(0, import_uni_app.onShow)(() => {
|
|
47
|
+
if (isMounted.value) {
|
|
48
|
+
showAfterMountedCallbacks.forEach((cb) => cb());
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
(0, import_uni_app.onPageScroll)((e) => {
|
|
52
|
+
scrollTop.value = e.scrollTop;
|
|
53
|
+
});
|
|
54
|
+
(0, import_vue.onMounted)(() => {
|
|
55
|
+
const pagesStack = getCurrentPages();
|
|
56
|
+
const pageStack = pagesStack[pagesStack.length - 1];
|
|
57
|
+
if (!pageStack?.$vm?.$refs?.univaRootRef) {
|
|
58
|
+
throw new Error('[usePageContext] univaRootRef not found. Make sure the page has <univa-root ref="univaRootRef" /> component.');
|
|
59
|
+
}
|
|
60
|
+
univaRootRef.value = pageStack.$vm.$refs.univaRootRef;
|
|
61
|
+
isMounted.value = true;
|
|
62
|
+
mountedCallbacks.forEach((cb) => cb());
|
|
63
|
+
});
|
|
64
|
+
(0, import_vue.onUnmounted)(() => {
|
|
65
|
+
isMounted.value = false;
|
|
66
|
+
unmountedCallbacks.forEach((cb) => cb());
|
|
67
|
+
mountedCallbacks.length = 0;
|
|
68
|
+
unmountedCallbacks.length = 0;
|
|
69
|
+
showAfterMountedCallbacks.length = 0;
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
isMounted,
|
|
73
|
+
univaRootRef,
|
|
74
|
+
scrollTop: (0, import_vue.computed)(() => scrollTop.value),
|
|
75
|
+
onPageMounted,
|
|
76
|
+
onPageUnmounted,
|
|
77
|
+
onPageShowAfterMounted
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
usePageContext
|
|
83
|
+
});
|
package/dist/hooks.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
|
|
3
|
+
interface PageContextOptions {
|
|
4
|
+
/**
|
|
5
|
+
* uniapp 必须在页面内检测到 onPageScroll 关键词才会注册事件。
|
|
6
|
+
* @see https://github.com/dcloudio/uni-app/issues/3099 让页面被正则捕获从而开启监听
|
|
7
|
+
*/
|
|
8
|
+
onPageScroll?: any;
|
|
9
|
+
}
|
|
10
|
+
interface PageContext {
|
|
11
|
+
isMounted: Ref<boolean>;
|
|
12
|
+
univaRootRef: Ref<any>;
|
|
13
|
+
scrollTop: ComputedRef<number>;
|
|
14
|
+
/**
|
|
15
|
+
* 页面挂载成功时执行
|
|
16
|
+
* @param callback
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
onPageMounted: (callback: () => void) => void;
|
|
20
|
+
/**
|
|
21
|
+
* 页面卸载时执行
|
|
22
|
+
* @param callback
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
onPageUnmounted: (callback: () => void) => void;
|
|
26
|
+
/**
|
|
27
|
+
* 页面挂载成功后的每次显示时执行
|
|
28
|
+
* @param callback
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
onPageShowAfterMounted: (callback: () => void) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function usePageContext(options?: PageContextOptions): PageContext;
|
|
35
|
+
|
|
36
|
+
export { usePageContext };
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
|
|
3
|
+
interface PageContextOptions {
|
|
4
|
+
/**
|
|
5
|
+
* uniapp 必须在页面内检测到 onPageScroll 关键词才会注册事件。
|
|
6
|
+
* @see https://github.com/dcloudio/uni-app/issues/3099 让页面被正则捕获从而开启监听
|
|
7
|
+
*/
|
|
8
|
+
onPageScroll?: any;
|
|
9
|
+
}
|
|
10
|
+
interface PageContext {
|
|
11
|
+
isMounted: Ref<boolean>;
|
|
12
|
+
univaRootRef: Ref<any>;
|
|
13
|
+
scrollTop: ComputedRef<number>;
|
|
14
|
+
/**
|
|
15
|
+
* 页面挂载成功时执行
|
|
16
|
+
* @param callback
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
onPageMounted: (callback: () => void) => void;
|
|
20
|
+
/**
|
|
21
|
+
* 页面卸载时执行
|
|
22
|
+
* @param callback
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
onPageUnmounted: (callback: () => void) => void;
|
|
26
|
+
/**
|
|
27
|
+
* 页面挂载成功后的每次显示时执行
|
|
28
|
+
* @param callback
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
onPageShowAfterMounted: (callback: () => void) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function usePageContext(options?: PageContextOptions): PageContext;
|
|
35
|
+
|
|
36
|
+
export { usePageContext };
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/hooks/usePageContext/index.ts
|
|
2
|
+
import { onPageScroll, onShow } from "@dcloudio/uni-app";
|
|
3
|
+
import { computed, onMounted, onUnmounted, ref } from "vue";
|
|
4
|
+
function usePageContext(options = {}) {
|
|
5
|
+
const isMounted = ref(false);
|
|
6
|
+
const univaRootRef = ref();
|
|
7
|
+
const scrollTop = ref(0);
|
|
8
|
+
const mountedCallbacks = [];
|
|
9
|
+
const unmountedCallbacks = [];
|
|
10
|
+
const showAfterMountedCallbacks = [];
|
|
11
|
+
const onPageShowAfterMounted = (callback) => {
|
|
12
|
+
showAfterMountedCallbacks.push(callback);
|
|
13
|
+
};
|
|
14
|
+
const onPageMounted = (callback) => {
|
|
15
|
+
mountedCallbacks.push(callback);
|
|
16
|
+
};
|
|
17
|
+
const onPageUnmounted = (callback) => {
|
|
18
|
+
unmountedCallbacks.push(callback);
|
|
19
|
+
};
|
|
20
|
+
onShow(() => {
|
|
21
|
+
if (isMounted.value) {
|
|
22
|
+
showAfterMountedCallbacks.forEach((cb) => cb());
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
onPageScroll((e) => {
|
|
26
|
+
scrollTop.value = e.scrollTop;
|
|
27
|
+
});
|
|
28
|
+
onMounted(() => {
|
|
29
|
+
const pagesStack = getCurrentPages();
|
|
30
|
+
const pageStack = pagesStack[pagesStack.length - 1];
|
|
31
|
+
if (!pageStack?.$vm?.$refs?.univaRootRef) {
|
|
32
|
+
throw new Error('[usePageContext] univaRootRef not found. Make sure the page has <univa-root ref="univaRootRef" /> component.');
|
|
33
|
+
}
|
|
34
|
+
univaRootRef.value = pageStack.$vm.$refs.univaRootRef;
|
|
35
|
+
isMounted.value = true;
|
|
36
|
+
mountedCallbacks.forEach((cb) => cb());
|
|
37
|
+
});
|
|
38
|
+
onUnmounted(() => {
|
|
39
|
+
isMounted.value = false;
|
|
40
|
+
unmountedCallbacks.forEach((cb) => cb());
|
|
41
|
+
mountedCallbacks.length = 0;
|
|
42
|
+
unmountedCallbacks.length = 0;
|
|
43
|
+
showAfterMountedCallbacks.length = 0;
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
isMounted,
|
|
47
|
+
univaRootRef,
|
|
48
|
+
scrollTop: computed(() => scrollTop.value),
|
|
49
|
+
onPageMounted,
|
|
50
|
+
onPageUnmounted,
|
|
51
|
+
onPageShowAfterMounted
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
usePageContext
|
|
56
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
COMPONENT_ASYNC_ROOT: () => COMPONENT_ASYNC_ROOT,
|
|
34
|
-
DTS_DIR: () => DTS_DIR,
|
|
35
33
|
Univa: () => Univa,
|
|
36
34
|
definePagesConfig: () => definePagesConfig,
|
|
37
35
|
presetUniva: () => presetUniva
|
|
@@ -56,7 +54,11 @@ function createAutoImportPlugin(options) {
|
|
|
56
54
|
imports: [
|
|
57
55
|
"vue",
|
|
58
56
|
"pinia",
|
|
59
|
-
"uni-app"
|
|
57
|
+
"uni-app",
|
|
58
|
+
{
|
|
59
|
+
from: "@univa/core/hooks",
|
|
60
|
+
imports: ["usePageContext"]
|
|
61
|
+
}
|
|
60
62
|
],
|
|
61
63
|
dirs: [
|
|
62
64
|
"src/hooks/**",
|
|
@@ -364,8 +366,6 @@ function Univa(config) {
|
|
|
364
366
|
}
|
|
365
367
|
// Annotate the CommonJS export names for ESM import in node:
|
|
366
368
|
0 && (module.exports = {
|
|
367
|
-
COMPONENT_ASYNC_ROOT,
|
|
368
|
-
DTS_DIR,
|
|
369
369
|
Univa,
|
|
370
370
|
definePagesConfig,
|
|
371
371
|
presetUniva
|
package/dist/index.d.cts
CHANGED
|
@@ -35,9 +35,6 @@ declare function definePagesConfig(config: DefinePagesConfig): DefinePagesConfig
|
|
|
35
35
|
|
|
36
36
|
declare function presetUniva(): Preset;
|
|
37
37
|
|
|
38
|
-
declare const DTS_DIR = "./.univa";
|
|
39
|
-
declare const COMPONENT_ASYNC_ROOT = "components-async";
|
|
40
|
-
|
|
41
38
|
declare function Univa(config?: UnivaUserConfig): PluginOption[];
|
|
42
39
|
|
|
43
|
-
export {
|
|
40
|
+
export { Univa, type UnivaOptions, type UnivaUserConfig, definePagesConfig, presetUniva };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,9 +35,6 @@ declare function definePagesConfig(config: DefinePagesConfig): DefinePagesConfig
|
|
|
35
35
|
|
|
36
36
|
declare function presetUniva(): Preset;
|
|
37
37
|
|
|
38
|
-
declare const DTS_DIR = "./.univa";
|
|
39
|
-
declare const COMPONENT_ASYNC_ROOT = "components-async";
|
|
40
|
-
|
|
41
38
|
declare function Univa(config?: UnivaUserConfig): PluginOption[];
|
|
42
39
|
|
|
43
|
-
export {
|
|
40
|
+
export { Univa, type UnivaOptions, type UnivaUserConfig, definePagesConfig, presetUniva };
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,11 @@ function createAutoImportPlugin(options) {
|
|
|
16
16
|
imports: [
|
|
17
17
|
"vue",
|
|
18
18
|
"pinia",
|
|
19
|
-
"uni-app"
|
|
19
|
+
"uni-app",
|
|
20
|
+
{
|
|
21
|
+
from: "@univa/core/hooks",
|
|
22
|
+
imports: ["usePageContext"]
|
|
23
|
+
}
|
|
20
24
|
],
|
|
21
25
|
dirs: [
|
|
22
26
|
"src/hooks/**",
|
|
@@ -323,8 +327,6 @@ function Univa(config) {
|
|
|
323
327
|
});
|
|
324
328
|
}
|
|
325
329
|
export {
|
|
326
|
-
COMPONENT_ASYNC_ROOT,
|
|
327
|
-
DTS_DIR,
|
|
328
330
|
Univa,
|
|
329
331
|
definePagesConfig,
|
|
330
332
|
presetUniva
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univa/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "",
|
|
6
|
-
"author": "",
|
|
4
|
+
"version": "0.0.5",
|
|
5
|
+
"description": "🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验",
|
|
6
|
+
"author": "lianghang <libre1103@163.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"keywords": [],
|
|
9
9
|
"exports": {
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
"default": "./dist/index.cjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
+
"./hooks": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/hooks.d.ts",
|
|
23
|
+
"default": "./dist/hooks.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/hooks.d.cts",
|
|
27
|
+
"default": "./dist/hooks.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
20
30
|
"./client": {
|
|
21
31
|
"types": "./src/client.d.ts"
|
|
22
32
|
}
|
|
@@ -25,6 +35,7 @@
|
|
|
25
35
|
"module": "./dist/index.js",
|
|
26
36
|
"types": "./dist/index.d.ts",
|
|
27
37
|
"files": [
|
|
38
|
+
"LICENSE",
|
|
28
39
|
"README.md",
|
|
29
40
|
"dist",
|
|
30
41
|
"src/client.d.ts",
|
|
@@ -38,6 +49,11 @@
|
|
|
38
49
|
"build": "tsup",
|
|
39
50
|
"dev": "tsup --watch"
|
|
40
51
|
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@dcloudio/uni-app": "^3.0.0-3090920231225001",
|
|
54
|
+
"vite": "^5.2.8",
|
|
55
|
+
"vue": "^3.4.21"
|
|
56
|
+
},
|
|
41
57
|
"dependencies": {
|
|
42
58
|
"@uni-helper/eslint-config": "0.7.3",
|
|
43
59
|
"@uni-helper/plugin-uni": "0.1.0",
|
|
@@ -49,19 +65,21 @@
|
|
|
49
65
|
"@uni-ku/bundle-optimizer": "2.1.2",
|
|
50
66
|
"@univa/manifest": "^0.0.1",
|
|
51
67
|
"@univa/root": "^0.0.1",
|
|
52
|
-
"@univa/tsconfig": "^0.0.
|
|
68
|
+
"@univa/tsconfig": "^0.0.2",
|
|
53
69
|
"@unocss/eslint-plugin": "66.6.7",
|
|
54
70
|
"@unocss/preset-legacy-compat": "66.0.0",
|
|
55
71
|
"eslint": "10.3.0",
|
|
56
72
|
"sass": "1.99.0",
|
|
57
73
|
"unocss": "66.0.0",
|
|
58
|
-
"unplugin-auto-import": "
|
|
74
|
+
"unplugin-auto-import": "20.0.0",
|
|
59
75
|
"vite-plugin-uni-polyfill": "0.1.0"
|
|
60
76
|
},
|
|
61
77
|
"devDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
78
|
+
"@dcloudio/uni-app": "^3.0.0-3090920231225001",
|
|
79
|
+
"c12": "3.3.4",
|
|
80
|
+
"tsup": "8.5.1",
|
|
64
81
|
"typescript": "^5.4.0",
|
|
65
|
-
"vite": "5.2.8"
|
|
82
|
+
"vite": "5.2.8",
|
|
83
|
+
"vue": "^3.4.21"
|
|
66
84
|
}
|
|
67
85
|
}
|