uview-pro 0.6.13 → 0.6.14
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/changelog.md +22 -3
- package/index.ts +100 -100
- package/package.json +2 -11
- package/plugins/root/README.md +161 -161
- package/plugins/root/dist/page.cjs +29 -11
- package/plugins/root/dist/page.mjs +29 -11
- package/plugins/root/dist/root.cjs +10 -2
- package/plugins/root/dist/root.mjs +10 -2
- package/plugins/root/dist/utils.cjs +1 -1
- package/plugins/root/dist/utils.mjs +1 -1
- package/plugins/root/index.ts +123 -123
- package/plugins/root/page.ts +77 -54
- package/plugins/root/root.ts +53 -35
- package/plugins/root/utils.ts +137 -133
- package/readme.md +2 -2
- package/types/index.d.ts +14 -19
package/plugins/root/utils.ts
CHANGED
|
@@ -1,133 +1,137 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { normalizePath } from 'vite';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Parse Vue SFC file, return descriptor
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { normalizePath } from 'vite';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse Vue SFC file, return descriptor
|
|
7
|
+
*
|
|
8
|
+
* When vue/compiler-sfc is not available (e.g. HBuilderX projects where
|
|
9
|
+
* vue is not in node_modules), returns null instead of throwing.
|
|
10
|
+
* Callers should fall back to regex-based matching.
|
|
11
|
+
*/
|
|
12
|
+
export async function parseSFC(code: string) {
|
|
13
|
+
try {
|
|
14
|
+
const { parse } = await import('vue/compiler-sfc');
|
|
15
|
+
return parse(code, { pad: 'space' }).descriptor;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Strip JSON comments (single-line and multi-line)
|
|
23
|
+
*/
|
|
24
|
+
export function stripJsonComments(str: string): string {
|
|
25
|
+
return str.replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Convert pages.json path to absolute file path
|
|
30
|
+
*/
|
|
31
|
+
export function formatPagePath(root: string, path: string) {
|
|
32
|
+
return normalizePath(`${join(root, path)}.vue`).replace(/^[A-Z]:/, match => match.toLowerCase());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Load pages.json and resolve all page paths (main + subPackages)
|
|
37
|
+
*/
|
|
38
|
+
export function loadPagesJson(path: string, rootPath: string): string[] {
|
|
39
|
+
const raw = readFileSync(path, 'utf-8');
|
|
40
|
+
const { pages = [], subPackages = [] } = JSON.parse(stripJsonComments(raw));
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
...pages.map((page: any) => formatPagePath(rootPath, page.path)),
|
|
44
|
+
...subPackages
|
|
45
|
+
.map(({ pages: subPages = [], root = '' }: any) => {
|
|
46
|
+
return subPages.map((page: any) => formatPagePath(join(rootPath, root), page.path));
|
|
47
|
+
})
|
|
48
|
+
.flat()
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* camelCase to kebab-case: PageMeta -> page-meta
|
|
54
|
+
*/
|
|
55
|
+
export function toKebabCase(str: string) {
|
|
56
|
+
return str
|
|
57
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
58
|
+
.replace(/[_\s]+/g, '-')
|
|
59
|
+
.toLowerCase();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* kebab-case to PascalCase: page-meta -> PageMeta
|
|
64
|
+
*/
|
|
65
|
+
export function toPascalCase(str: string) {
|
|
66
|
+
return str.replace(/(^\w|-+\w)/g, match => match.toUpperCase().replace(/-/g, ''));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface TagNode {
|
|
70
|
+
loc: {
|
|
71
|
+
source: string;
|
|
72
|
+
start: { offset: number };
|
|
73
|
+
end: { offset: number };
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Find a tag node in SFC template AST by tag name
|
|
79
|
+
* Supports both kebab-case and PascalCase
|
|
80
|
+
*/
|
|
81
|
+
export function findNode(sfc: any, rawTagName: string): TagNode | undefined {
|
|
82
|
+
const templateSource = sfc.template?.content;
|
|
83
|
+
if (!templateSource) return;
|
|
84
|
+
|
|
85
|
+
let tagName = '';
|
|
86
|
+
if (templateSource.includes(`<${toKebabCase(rawTagName)}`)) {
|
|
87
|
+
tagName = toKebabCase(rawTagName);
|
|
88
|
+
} else if (templateSource.includes(`<${toPascalCase(rawTagName)}`)) {
|
|
89
|
+
tagName = toPascalCase(rawTagName);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!tagName) return;
|
|
93
|
+
|
|
94
|
+
const nodeAst = sfc.template?.ast;
|
|
95
|
+
if (!nodeAst) return;
|
|
96
|
+
|
|
97
|
+
// Recursively traverse AST to find the target node
|
|
98
|
+
const traverse = (nodes: any): TagNode | undefined => {
|
|
99
|
+
for (const node of nodes) {
|
|
100
|
+
if (node.type === 1) {
|
|
101
|
+
if (node.tag === tagName) return node;
|
|
102
|
+
if (node.children?.length) {
|
|
103
|
+
const found = traverse(node.children);
|
|
104
|
+
if (found) return found;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return traverse(nodeAst.children);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Normalize platform-specific page paths (.mp-weixin.vue -> .vue)
|
|
116
|
+
*/
|
|
117
|
+
export function normalizePlatformPath(id: string) {
|
|
118
|
+
const platform = process.env.UNI_PLATFORM;
|
|
119
|
+
if (!platform) return id;
|
|
120
|
+
|
|
121
|
+
const regex = new RegExp(`\\.${platform}\\.vue$`);
|
|
122
|
+
if (regex.test(id)) {
|
|
123
|
+
return id.replace(`.${platform}.`, '.');
|
|
124
|
+
}
|
|
125
|
+
return id;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Debounce utility
|
|
130
|
+
*/
|
|
131
|
+
export function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {
|
|
132
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
133
|
+
return (...args: Parameters<T>) => {
|
|
134
|
+
if (timer) clearTimeout(timer);
|
|
135
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
136
|
+
};
|
|
137
|
+
}
|
package/readme.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<h3 align="center" style="margin: 30px 0 30px;font-weight: bold;font-size:40px;">uView Pro</h3>
|
|
5
5
|
<h3 align="center">uni-app Vue3 多平台快速开发的 UI 框架</h3>
|
|
6
6
|
|
|
7
|
-
[](https://gitee.com/anyup/uView-Pro)
|
|
8
|
-
[](https://gitee.com/anyup/uView-Pro)
|
|
7
|
+
[](https://gitee.com/anyup/uView-Pro)
|
|
8
|
+
[](https://gitee.com/anyup/uView-Pro)
|
|
9
9
|
[](https://github.com/anyup/uView-Pro)
|
|
10
10
|
[](https://github.com/anyup/uView-Pro)
|
|
11
11
|
[](https://github.com/anyup/uView-Pro/issues)
|
package/types/index.d.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
/// <reference path="./components.d.ts" />
|
|
2
|
-
/// <reference path="./uni-app.d.ts" />
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
$u: typeof $u;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export {};
|
|
1
|
+
/// <reference path="./components.d.ts" />
|
|
2
|
+
/// <reference path="./uni-app.d.ts" />
|
|
3
|
+
|
|
4
|
+
export * from './global';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Uni {
|
|
8
|
+
$u: typeof import('../libs').$u;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module 'uview-pro' {
|
|
13
|
+
export function install(): void;
|
|
14
|
+
}
|