uview-pro 0.6.11 → 0.6.13
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 +24 -3
- package/components/u-picker/u-picker.vue +16 -18
- package/components/u-select/u-select.vue +7 -6
- package/package.json +11 -1
- package/plugins/index.cjs +1 -0
- package/plugins/index.mjs +1 -0
- package/plugins/root/dist/index.cjs +111 -0
- package/plugins/root/dist/index.mjs +78 -0
- package/plugins/root/dist/page.cjs +58 -0
- package/plugins/root/dist/page.mjs +35 -0
- package/plugins/root/dist/root.cjs +45 -0
- package/plugins/root/dist/root.mjs +21 -0
- package/plugins/root/dist/utils.cjs +136 -0
- package/plugins/root/dist/utils.mjs +95 -0
package/changelog.md
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
## 0.6.
|
|
1
|
+
## 0.6.13(2026-07-28)
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
4
4
|
|
|
5
|
-
- **
|
|
5
|
+
- **u-picker:** 修复抖音小程序等平台picker数据加载,导致弹窗失败问题(#174) ([ead3cdc](https://github.com/anyup/uView-Pro/commit/ead3cdc18fc5be05a3022acac4485fc3e3e75faa))
|
|
6
|
+
- **u-select:** 修复抖音小程序select弹出问题(#174) ([c7a4c28](https://github.com/anyup/uView-Pro/commit/c7a4c2856f9790747ec234b0a6cc1154b560d701))
|
|
6
7
|
|
|
7
8
|
### 👥 Contributors
|
|
8
9
|
|
|
9
10
|
<a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a>
|
|
10
11
|
|
|
12
|
+
## 0.6.12(2026-07-24)
|
|
13
|
+
|
|
14
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
15
|
+
|
|
16
|
+
- **vite:** 修复vite插件root根组件在使用npm方式引入时导致无法被正确加载的问题 ([90561fa](https://github.com/anyup/uView-Pro/commit/90561fa406a8c9d8d49f8223cdda333cc662a42a))
|
|
17
|
+
|
|
18
|
+
### 👥 Contributors
|
|
19
|
+
|
|
20
|
+
<a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a>
|
|
21
|
+
|
|
22
|
+
## 0.6.11(2026-07-24)
|
|
23
|
+
|
|
24
|
+
### ✨ Features | 新功能
|
|
25
|
+
|
|
26
|
+
- **vite-plugin-uni-root:** 新增内置的 root vite 插件,实现全局根组件自动注入,无需自行引入第三方插件实现 ([f5359a9](https://github.com/anyup/uView-Pro/commit/f5359a92d93150a064f6814a8700cacf272d3556))
|
|
27
|
+
|
|
28
|
+
### 👥 Contributors
|
|
29
|
+
|
|
30
|
+
<a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a>
|
|
31
|
+
|
|
11
32
|
## 0.6.10(2026-07-23)
|
|
12
33
|
|
|
13
34
|
### ♻️ Code Refactoring | 代码重构
|
|
@@ -305,12 +305,12 @@ watch(
|
|
|
305
305
|
if (props.modelValue) {
|
|
306
306
|
// reinit while open
|
|
307
307
|
readyToRender.value = false;
|
|
308
|
-
|
|
308
|
+
init();
|
|
309
|
+
readyToRender.value = true;
|
|
309
310
|
// #ifdef APP-PLUS
|
|
311
|
+
await nextTick();
|
|
310
312
|
await new Promise(resolve => setTimeout(resolve, 20));
|
|
311
313
|
// #endif
|
|
312
|
-
await init();
|
|
313
|
-
readyToRender.value = true;
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
},
|
|
@@ -324,12 +324,12 @@ watch(
|
|
|
324
324
|
savedDefaultTime.value = n || null;
|
|
325
325
|
if (props.modelValue) {
|
|
326
326
|
readyToRender.value = false;
|
|
327
|
-
|
|
327
|
+
init();
|
|
328
|
+
readyToRender.value = true;
|
|
328
329
|
// #ifdef APP-PLUS
|
|
330
|
+
await nextTick();
|
|
329
331
|
await new Promise(resolve => setTimeout(resolve, 20));
|
|
330
332
|
// #endif
|
|
331
|
-
await init();
|
|
332
|
-
readyToRender.value = true;
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
}
|
|
@@ -342,12 +342,12 @@ watch(
|
|
|
342
342
|
savedDefaultRegion.value = n && (n as any[]).length ? (n as any[]).slice() : null;
|
|
343
343
|
if (props.modelValue) {
|
|
344
344
|
readyToRender.value = false;
|
|
345
|
-
|
|
345
|
+
init();
|
|
346
|
+
readyToRender.value = true;
|
|
346
347
|
// #ifdef APP-PLUS
|
|
348
|
+
await nextTick();
|
|
347
349
|
await new Promise(resolve => setTimeout(resolve, 20));
|
|
348
350
|
// #endif
|
|
349
|
-
await init();
|
|
350
|
-
readyToRender.value = true;
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
},
|
|
@@ -369,15 +369,15 @@ watch(
|
|
|
369
369
|
() => props.modelValue,
|
|
370
370
|
async n => {
|
|
371
371
|
if (n) {
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
372
|
+
// 同步调用 init(),确保 picker-view 列数据在渲染前就填充完毕
|
|
373
|
+
// 这对抖音等小程序平台至关重要:原生 picker-view 需要在创建时就有完整数据
|
|
374
|
+
init();
|
|
375
|
+
readyToRender.value = true;
|
|
376
|
+
// APP-PLUS 原生控件可能需要更长的原生初始化时间
|
|
375
377
|
// #ifdef APP-PLUS
|
|
378
|
+
await nextTick();
|
|
376
379
|
await new Promise(resolve => setTimeout(resolve, 20));
|
|
377
380
|
// #endif
|
|
378
|
-
// 初始化数据并在完成后再渲染 picker-view
|
|
379
|
-
await init();
|
|
380
|
-
readyToRender.value = true;
|
|
381
381
|
} else {
|
|
382
382
|
// 关闭时隐藏 picker,保留已保存的值
|
|
383
383
|
readyToRender.value = false;
|
|
@@ -461,7 +461,7 @@ function initTimeValue() {
|
|
|
461
461
|
/**
|
|
462
462
|
* 初始化picker各列数据
|
|
463
463
|
*/
|
|
464
|
-
|
|
464
|
+
function init() {
|
|
465
465
|
valueArr.value = [];
|
|
466
466
|
if (props.mode == 'time') {
|
|
467
467
|
initTimeValue();
|
|
@@ -509,8 +509,6 @@ async function init() {
|
|
|
509
509
|
valueArr.value = getEffectiveDefaultSelector();
|
|
510
510
|
multiSelectorValue.value = getEffectiveDefaultSelector();
|
|
511
511
|
}
|
|
512
|
-
// 等待 DOM 与 Vue 响应式更新完成,确保在原生组件挂载时数据已就绪
|
|
513
|
-
await nextTick();
|
|
514
512
|
}
|
|
515
513
|
/**
|
|
516
514
|
* 设置年份列
|
|
@@ -119,6 +119,7 @@ const defaultSelector = ref<number[]>([0]);
|
|
|
119
119
|
// picker-view的数据
|
|
120
120
|
const columnData = ref<SelectListItem[][]>([]);
|
|
121
121
|
// 控制 picker 是否渲染(等待初始化完成)
|
|
122
|
+
// 初始为 false,确保 picker-view 原生组件在数据就绪后才创建(抖音小程序等平台需要在创建时就有完整数据)
|
|
122
123
|
const readyToRender = ref(false);
|
|
123
124
|
// 保存用户上次确认的索引,如果用户未确认过,则为 null,首次打开会使用 props.defaultValue
|
|
124
125
|
const savedSelector = ref<number[] | null>(
|
|
@@ -148,17 +149,17 @@ watch(
|
|
|
148
149
|
() => props.modelValue,
|
|
149
150
|
async val => {
|
|
150
151
|
if (val) {
|
|
151
|
-
//
|
|
152
|
-
|
|
152
|
+
// 同步调用 init(),确保 columnData 在 picker-view 渲染前就填充完毕
|
|
153
|
+
// 这对抖音等小程序平台至关重要:原生 picker-view 需要在创建时就有完整数据
|
|
154
|
+
init();
|
|
155
|
+
readyToRender.value = true;
|
|
153
156
|
// 在 App(APP-PLUS)平台上,原生 picker 可能需要更长时间初始化
|
|
154
|
-
// 我们先执行 init,并在 init 完成后将 readyToRender 置为 true,保证 picker 在数据就绪后渲染
|
|
155
157
|
// #ifdef APP-PLUS
|
|
158
|
+
await nextTick();
|
|
156
159
|
await new Promise(resolve => setTimeout(resolve, 20));
|
|
157
160
|
// #endif
|
|
158
|
-
init();
|
|
159
|
-
readyToRender.value = true;
|
|
160
161
|
} else {
|
|
161
|
-
//
|
|
162
|
+
// 关闭弹窗时复位,下次打开时 picker-view 会重新创建,确保数据刷新
|
|
162
163
|
readyToRender.value = false;
|
|
163
164
|
}
|
|
164
165
|
},
|
package/package.json
CHANGED
|
@@ -2,11 +2,21 @@
|
|
|
2
2
|
"id": "uview-pro",
|
|
3
3
|
"name": "uview-pro",
|
|
4
4
|
"displayName": "【支持鸿蒙】uView Pro|基于Vue3+TS的高质量UI组件库,支持多主题、暗黑模式、多语言",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.13",
|
|
6
6
|
"description": "uView Pro是基于Vue3+TS的多平台UI框架,提供80+高质量组件、便捷工具和常用模板,支持多主题、暗黑模式、多语言,支持H5/APP/鸿蒙/小程序多端开发。已在鸿蒙应用商店上架,欢迎体验!",
|
|
7
7
|
"main": "index.ts",
|
|
8
8
|
"module": "index.ts",
|
|
9
9
|
"browser": "index.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./index.ts",
|
|
12
|
+
"./plugins": {
|
|
13
|
+
"types": "./plugins/index.ts",
|
|
14
|
+
"import": "./plugins/index.mjs",
|
|
15
|
+
"require": "./plugins/index.cjs",
|
|
16
|
+
"default": "./plugins/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./*": "./*"
|
|
19
|
+
},
|
|
10
20
|
"keywords": [
|
|
11
21
|
"uview-pro",
|
|
12
22
|
"vue3",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./root/dist/index.cjs");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./root/dist/index.mjs";
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var root_exports = {};
|
|
29
|
+
__export(root_exports, {
|
|
30
|
+
UniRoot: () => UniRoot,
|
|
31
|
+
default: () => root_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(root_exports);
|
|
34
|
+
var import_node_path = require("node:path");
|
|
35
|
+
var import_node_process = __toESM(require("node:process"));
|
|
36
|
+
var import_node_fs = require("node:fs");
|
|
37
|
+
var import_vite = require("vite");
|
|
38
|
+
var import_root = require("./root.cjs");
|
|
39
|
+
var import_page = require("./page.cjs");
|
|
40
|
+
var import_utils = require("./utils.cjs");
|
|
41
|
+
function normalizeId(id) {
|
|
42
|
+
return (0, import_vite.normalizePath)(id).replace(/^[A-Z]:/, (match) => match.toLowerCase());
|
|
43
|
+
}
|
|
44
|
+
function UniRoot(options) {
|
|
45
|
+
options = {
|
|
46
|
+
rootFileName: "App.root",
|
|
47
|
+
...options
|
|
48
|
+
};
|
|
49
|
+
const rootPath = import_node_process.default.env.UNI_INPUT_DIR || (0, import_node_path.join)(import_node_process.default.cwd(), "src");
|
|
50
|
+
const appRootPath = (0, import_node_path.resolve)(rootPath, `${options.rootFileName}.vue`);
|
|
51
|
+
const pagesPath = (0, import_node_path.resolve)(rootPath, "pages.json");
|
|
52
|
+
let pagesJson = (0, import_utils.loadPagesJson)(pagesPath, rootPath);
|
|
53
|
+
let watcher = null;
|
|
54
|
+
let hasPlatformPlugin = false;
|
|
55
|
+
const normalizedAppRoot = normalizeId(appRootPath);
|
|
56
|
+
return {
|
|
57
|
+
name: "vite-plugin-uni-root",
|
|
58
|
+
enforce: "pre",
|
|
59
|
+
// 在其他插件之前执行,确保页面模板先被包裹
|
|
60
|
+
configResolved({ plugins }) {
|
|
61
|
+
hasPlatformPlugin = plugins.some((v) => v.name === "vite-plugin-uni-platform");
|
|
62
|
+
},
|
|
63
|
+
configureServer(server) {
|
|
64
|
+
const reload = (0, import_utils.debounce)(() => {
|
|
65
|
+
try {
|
|
66
|
+
pagesJson = (0, import_utils.loadPagesJson)(pagesPath, rootPath);
|
|
67
|
+
server.ws.send({ type: "full-reload" });
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error("[vite-plugin-uni-root] pages.json reload failed:", e);
|
|
70
|
+
}
|
|
71
|
+
}, 100);
|
|
72
|
+
watcher = (0, import_node_fs.watch)(pagesPath, (eventType) => {
|
|
73
|
+
if (eventType === "change")
|
|
74
|
+
reload();
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
load(id) {
|
|
78
|
+
const normalizedId = normalizeId(id);
|
|
79
|
+
if (normalizedId === normalizedAppRoot) {
|
|
80
|
+
const code = (0, import_node_fs.readFileSync)(appRootPath, "utf-8");
|
|
81
|
+
return (0, import_root.rebuildRootApp)(code).code;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
async transform(code, id) {
|
|
85
|
+
const normalizedId = normalizeId(id);
|
|
86
|
+
const normalizedRootPath = normalizeId(rootPath);
|
|
87
|
+
if (normalizedId === `${normalizedRootPath}/main.ts` || normalizedId === `${normalizedRootPath}/main.js`) {
|
|
88
|
+
return (0, import_root.registerRootApp)(code, options.rootFileName);
|
|
89
|
+
}
|
|
90
|
+
if (normalizedId === normalizedAppRoot) {
|
|
91
|
+
return (0, import_root.rebuildRootApp)(code);
|
|
92
|
+
}
|
|
93
|
+
const pageId = hasPlatformPlugin ? (0, import_utils.normalizePlatformPath)(normalizedId) : normalizedId;
|
|
94
|
+
const isPage = pagesJson.some((p) => pageId === p || pageId.startsWith(`${p}?`));
|
|
95
|
+
if (isPage) {
|
|
96
|
+
return (0, import_page.transformPage)(code);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
buildEnd() {
|
|
100
|
+
if (watcher) {
|
|
101
|
+
watcher.close();
|
|
102
|
+
watcher = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
var root_default = UniRoot;
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
UniRoot
|
|
111
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { resolve, join } from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { watch, readFileSync } from "node:fs";
|
|
4
|
+
import { normalizePath } from "vite";
|
|
5
|
+
import { registerRootApp, rebuildRootApp } from "./root.mjs";
|
|
6
|
+
import { transformPage } from "./page.mjs";
|
|
7
|
+
import { loadPagesJson, normalizePlatformPath, debounce } from "./utils.mjs";
|
|
8
|
+
function normalizeId(id) {
|
|
9
|
+
return normalizePath(id).replace(/^[A-Z]:/, (match) => match.toLowerCase());
|
|
10
|
+
}
|
|
11
|
+
function UniRoot(options) {
|
|
12
|
+
options = {
|
|
13
|
+
rootFileName: "App.root",
|
|
14
|
+
...options
|
|
15
|
+
};
|
|
16
|
+
const rootPath = process.env.UNI_INPUT_DIR || join(process.cwd(), "src");
|
|
17
|
+
const appRootPath = resolve(rootPath, `${options.rootFileName}.vue`);
|
|
18
|
+
const pagesPath = resolve(rootPath, "pages.json");
|
|
19
|
+
let pagesJson = loadPagesJson(pagesPath, rootPath);
|
|
20
|
+
let watcher = null;
|
|
21
|
+
let hasPlatformPlugin = false;
|
|
22
|
+
const normalizedAppRoot = normalizeId(appRootPath);
|
|
23
|
+
return {
|
|
24
|
+
name: "vite-plugin-uni-root",
|
|
25
|
+
enforce: "pre",
|
|
26
|
+
// 在其他插件之前执行,确保页面模板先被包裹
|
|
27
|
+
configResolved({ plugins }) {
|
|
28
|
+
hasPlatformPlugin = plugins.some((v) => v.name === "vite-plugin-uni-platform");
|
|
29
|
+
},
|
|
30
|
+
configureServer(server) {
|
|
31
|
+
const reload = debounce(() => {
|
|
32
|
+
try {
|
|
33
|
+
pagesJson = loadPagesJson(pagesPath, rootPath);
|
|
34
|
+
server.ws.send({ type: "full-reload" });
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error("[vite-plugin-uni-root] pages.json reload failed:", e);
|
|
37
|
+
}
|
|
38
|
+
}, 100);
|
|
39
|
+
watcher = watch(pagesPath, (eventType) => {
|
|
40
|
+
if (eventType === "change")
|
|
41
|
+
reload();
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
load(id) {
|
|
45
|
+
const normalizedId = normalizeId(id);
|
|
46
|
+
if (normalizedId === normalizedAppRoot) {
|
|
47
|
+
const code = readFileSync(appRootPath, "utf-8");
|
|
48
|
+
return rebuildRootApp(code).code;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async transform(code, id) {
|
|
52
|
+
const normalizedId = normalizeId(id);
|
|
53
|
+
const normalizedRootPath = normalizeId(rootPath);
|
|
54
|
+
if (normalizedId === `${normalizedRootPath}/main.ts` || normalizedId === `${normalizedRootPath}/main.js`) {
|
|
55
|
+
return registerRootApp(code, options.rootFileName);
|
|
56
|
+
}
|
|
57
|
+
if (normalizedId === normalizedAppRoot) {
|
|
58
|
+
return rebuildRootApp(code);
|
|
59
|
+
}
|
|
60
|
+
const pageId = hasPlatformPlugin ? normalizePlatformPath(normalizedId) : normalizedId;
|
|
61
|
+
const isPage = pagesJson.some((p) => pageId === p || pageId.startsWith(`${p}?`));
|
|
62
|
+
if (isPage) {
|
|
63
|
+
return transformPage(code);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
buildEnd() {
|
|
67
|
+
if (watcher) {
|
|
68
|
+
watcher.close();
|
|
69
|
+
watcher = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var root_default = UniRoot;
|
|
75
|
+
export {
|
|
76
|
+
UniRoot,
|
|
77
|
+
root_default as default
|
|
78
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var page_exports = {};
|
|
19
|
+
__export(page_exports, {
|
|
20
|
+
transformPage: () => transformPage
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(page_exports);
|
|
23
|
+
var import_utils = require("./utils.cjs");
|
|
24
|
+
async function transformPage(code) {
|
|
25
|
+
const sfc = await (0, import_utils.parseSFC)(code);
|
|
26
|
+
if (!sfc.template)
|
|
27
|
+
return null;
|
|
28
|
+
const openMatch = code.match(/<template\b[^>]*>/);
|
|
29
|
+
if (!openMatch)
|
|
30
|
+
return null;
|
|
31
|
+
const closeTagStart = code.lastIndexOf("</template>");
|
|
32
|
+
if (closeTagStart === -1)
|
|
33
|
+
return null;
|
|
34
|
+
const openTagEnd = openMatch.index + openMatch[0].length;
|
|
35
|
+
const content = code.slice(openTagEnd, closeTagStart);
|
|
36
|
+
const pageMetaNode = (0, import_utils.findNode)(sfc, "PageMeta");
|
|
37
|
+
let pageMetaSource = "";
|
|
38
|
+
let newContent = content;
|
|
39
|
+
if (pageMetaNode) {
|
|
40
|
+
pageMetaSource = pageMetaNode.loc.source;
|
|
41
|
+
const metaStart = pageMetaNode.loc.start.offset;
|
|
42
|
+
const metaEnd = pageMetaNode.loc.end.offset;
|
|
43
|
+
const metaStartInContent = metaStart - openTagEnd;
|
|
44
|
+
const metaEndInContent = metaEnd - openTagEnd;
|
|
45
|
+
newContent = content.slice(0, metaStartInContent) + content.slice(metaEndInContent);
|
|
46
|
+
}
|
|
47
|
+
const wrappedContent = `
|
|
48
|
+
${pageMetaSource}
|
|
49
|
+
<global-root-view>${newContent}</global-root-view>
|
|
50
|
+
`;
|
|
51
|
+
return {
|
|
52
|
+
code: code.slice(0, openTagEnd) + wrappedContent + code.slice(closeTagStart)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
transformPage
|
|
58
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parseSFC, findNode } from "./utils.mjs";
|
|
2
|
+
async function transformPage(code) {
|
|
3
|
+
const sfc = await parseSFC(code);
|
|
4
|
+
if (!sfc.template)
|
|
5
|
+
return null;
|
|
6
|
+
const openMatch = code.match(/<template\b[^>]*>/);
|
|
7
|
+
if (!openMatch)
|
|
8
|
+
return null;
|
|
9
|
+
const closeTagStart = code.lastIndexOf("</template>");
|
|
10
|
+
if (closeTagStart === -1)
|
|
11
|
+
return null;
|
|
12
|
+
const openTagEnd = openMatch.index + openMatch[0].length;
|
|
13
|
+
const content = code.slice(openTagEnd, closeTagStart);
|
|
14
|
+
const pageMetaNode = findNode(sfc, "PageMeta");
|
|
15
|
+
let pageMetaSource = "";
|
|
16
|
+
let newContent = content;
|
|
17
|
+
if (pageMetaNode) {
|
|
18
|
+
pageMetaSource = pageMetaNode.loc.source;
|
|
19
|
+
const metaStart = pageMetaNode.loc.start.offset;
|
|
20
|
+
const metaEnd = pageMetaNode.loc.end.offset;
|
|
21
|
+
const metaStartInContent = metaStart - openTagEnd;
|
|
22
|
+
const metaEndInContent = metaEnd - openTagEnd;
|
|
23
|
+
newContent = content.slice(0, metaStartInContent) + content.slice(metaEndInContent);
|
|
24
|
+
}
|
|
25
|
+
const wrappedContent = `
|
|
26
|
+
${pageMetaSource}
|
|
27
|
+
<global-root-view>${newContent}</global-root-view>
|
|
28
|
+
`;
|
|
29
|
+
return {
|
|
30
|
+
code: code.slice(0, openTagEnd) + wrappedContent + code.slice(closeTagStart)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
transformPage
|
|
35
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var root_exports = {};
|
|
19
|
+
__export(root_exports, {
|
|
20
|
+
rebuildRootApp: () => rebuildRootApp,
|
|
21
|
+
registerRootApp: () => registerRootApp
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(root_exports);
|
|
24
|
+
function registerRootApp(code, fileName = "App.root") {
|
|
25
|
+
const importCode = `import GlobalRootView from "./${fileName}.vue";`;
|
|
26
|
+
const vueUseComponentCode = `app.component("global-root-view", GlobalRootView);`;
|
|
27
|
+
let newCode = importCode + "\n" + code;
|
|
28
|
+
const ssrAppMatch = newCode.match(/(const\s+app\s*=\s*createSSRApp\([^)]+\);)/);
|
|
29
|
+
if (ssrAppMatch) {
|
|
30
|
+
newCode = newCode.replace(/(const\s+app\s*=\s*createSSRApp\([^)]+\);)/, `$1
|
|
31
|
+
${vueUseComponentCode}`);
|
|
32
|
+
} else {
|
|
33
|
+
newCode = newCode.replace(/(createApp[\s\S]*?)(return\s*\{)/, `$1${vueUseComponentCode}
|
|
34
|
+
$2`);
|
|
35
|
+
}
|
|
36
|
+
return { code: newCode };
|
|
37
|
+
}
|
|
38
|
+
function rebuildRootApp(code) {
|
|
39
|
+
return { code };
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
rebuildRootApp,
|
|
44
|
+
registerRootApp
|
|
45
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function registerRootApp(code, fileName = "App.root") {
|
|
2
|
+
const importCode = `import GlobalRootView from "./${fileName}.vue";`;
|
|
3
|
+
const vueUseComponentCode = `app.component("global-root-view", GlobalRootView);`;
|
|
4
|
+
let newCode = importCode + "\n" + code;
|
|
5
|
+
const ssrAppMatch = newCode.match(/(const\s+app\s*=\s*createSSRApp\([^)]+\);)/);
|
|
6
|
+
if (ssrAppMatch) {
|
|
7
|
+
newCode = newCode.replace(/(const\s+app\s*=\s*createSSRApp\([^)]+\);)/, `$1
|
|
8
|
+
${vueUseComponentCode}`);
|
|
9
|
+
} else {
|
|
10
|
+
newCode = newCode.replace(/(createApp[\s\S]*?)(return\s*\{)/, `$1${vueUseComponentCode}
|
|
11
|
+
$2`);
|
|
12
|
+
}
|
|
13
|
+
return { code: newCode };
|
|
14
|
+
}
|
|
15
|
+
function rebuildRootApp(code) {
|
|
16
|
+
return { code };
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
rebuildRootApp,
|
|
20
|
+
registerRootApp
|
|
21
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var utils_exports = {};
|
|
29
|
+
__export(utils_exports, {
|
|
30
|
+
debounce: () => debounce,
|
|
31
|
+
findNode: () => findNode,
|
|
32
|
+
formatPagePath: () => formatPagePath,
|
|
33
|
+
loadPagesJson: () => loadPagesJson,
|
|
34
|
+
normalizePlatformPath: () => normalizePlatformPath,
|
|
35
|
+
parseSFC: () => parseSFC,
|
|
36
|
+
stripJsonComments: () => stripJsonComments,
|
|
37
|
+
toKebabCase: () => toKebabCase,
|
|
38
|
+
toPascalCase: () => toPascalCase
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(utils_exports);
|
|
41
|
+
var import_node_fs = require("node:fs");
|
|
42
|
+
var import_node_path = require("node:path");
|
|
43
|
+
var import_vite = require("vite");
|
|
44
|
+
async function parseSFC(code) {
|
|
45
|
+
try {
|
|
46
|
+
const { parse } = await import("vue/compiler-sfc");
|
|
47
|
+
return parse(code, { pad: "space" }).descriptor;
|
|
48
|
+
} catch {
|
|
49
|
+
throw new Error("[vite-plugin-uni-root] Vue version must be 3.2.13 or higher.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function stripJsonComments(str) {
|
|
53
|
+
return str.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
54
|
+
}
|
|
55
|
+
function formatPagePath(root, path) {
|
|
56
|
+
return (0, import_vite.normalizePath)(`${(0, import_node_path.join)(root, path)}.vue`).replace(/^[A-Z]:/, (match) => match.toLowerCase());
|
|
57
|
+
}
|
|
58
|
+
function loadPagesJson(path, rootPath) {
|
|
59
|
+
const raw = (0, import_node_fs.readFileSync)(path, "utf-8");
|
|
60
|
+
const { pages = [], subPackages = [] } = JSON.parse(stripJsonComments(raw));
|
|
61
|
+
return [
|
|
62
|
+
...pages.map((page) => formatPagePath(rootPath, page.path)),
|
|
63
|
+
...subPackages.map(({ pages: subPages = [], root = "" }) => {
|
|
64
|
+
return subPages.map((page) => formatPagePath((0, import_node_path.join)(rootPath, root), page.path));
|
|
65
|
+
}).flat()
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
function toKebabCase(str) {
|
|
69
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
function toPascalCase(str) {
|
|
72
|
+
return str.replace(/(^\w|-+\w)/g, (match) => match.toUpperCase().replace(/-/g, ""));
|
|
73
|
+
}
|
|
74
|
+
function findNode(sfc, rawTagName) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const templateSource = (_a = sfc.template) == null ? void 0 : _a.content;
|
|
77
|
+
if (!templateSource)
|
|
78
|
+
return;
|
|
79
|
+
let tagName = "";
|
|
80
|
+
if (templateSource.includes(`<${toKebabCase(rawTagName)}`)) {
|
|
81
|
+
tagName = toKebabCase(rawTagName);
|
|
82
|
+
} else if (templateSource.includes(`<${toPascalCase(rawTagName)}`)) {
|
|
83
|
+
tagName = toPascalCase(rawTagName);
|
|
84
|
+
}
|
|
85
|
+
if (!tagName)
|
|
86
|
+
return;
|
|
87
|
+
const nodeAst = (_b = sfc.template) == null ? void 0 : _b.ast;
|
|
88
|
+
if (!nodeAst)
|
|
89
|
+
return;
|
|
90
|
+
const traverse = (nodes) => {
|
|
91
|
+
var _a2;
|
|
92
|
+
for (const node of nodes) {
|
|
93
|
+
if (node.type === 1) {
|
|
94
|
+
if (node.tag === tagName)
|
|
95
|
+
return node;
|
|
96
|
+
if ((_a2 = node.children) == null ? void 0 : _a2.length) {
|
|
97
|
+
const found = traverse(node.children);
|
|
98
|
+
if (found)
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return void 0;
|
|
104
|
+
};
|
|
105
|
+
return traverse(nodeAst.children);
|
|
106
|
+
}
|
|
107
|
+
function normalizePlatformPath(id) {
|
|
108
|
+
const platform = process.env.UNI_PLATFORM;
|
|
109
|
+
if (!platform)
|
|
110
|
+
return id;
|
|
111
|
+
const regex = new RegExp(`\\.${platform}\\.vue$`);
|
|
112
|
+
if (regex.test(id)) {
|
|
113
|
+
return id.replace(`.${platform}.`, ".");
|
|
114
|
+
}
|
|
115
|
+
return id;
|
|
116
|
+
}
|
|
117
|
+
function debounce(fn, delay) {
|
|
118
|
+
let timer = null;
|
|
119
|
+
return (...args) => {
|
|
120
|
+
if (timer)
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
debounce,
|
|
128
|
+
findNode,
|
|
129
|
+
formatPagePath,
|
|
130
|
+
loadPagesJson,
|
|
131
|
+
normalizePlatformPath,
|
|
132
|
+
parseSFC,
|
|
133
|
+
stripJsonComments,
|
|
134
|
+
toKebabCase,
|
|
135
|
+
toPascalCase
|
|
136
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { normalizePath } from "vite";
|
|
4
|
+
async function parseSFC(code) {
|
|
5
|
+
try {
|
|
6
|
+
const { parse } = await import("vue/compiler-sfc");
|
|
7
|
+
return parse(code, { pad: "space" }).descriptor;
|
|
8
|
+
} catch {
|
|
9
|
+
throw new Error("[vite-plugin-uni-root] Vue version must be 3.2.13 or higher.");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function stripJsonComments(str) {
|
|
13
|
+
return str.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
14
|
+
}
|
|
15
|
+
function formatPagePath(root, path) {
|
|
16
|
+
return normalizePath(`${join(root, path)}.vue`).replace(/^[A-Z]:/, (match) => match.toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
function loadPagesJson(path, rootPath) {
|
|
19
|
+
const raw = readFileSync(path, "utf-8");
|
|
20
|
+
const { pages = [], subPackages = [] } = JSON.parse(stripJsonComments(raw));
|
|
21
|
+
return [
|
|
22
|
+
...pages.map((page) => formatPagePath(rootPath, page.path)),
|
|
23
|
+
...subPackages.map(({ pages: subPages = [], root = "" }) => {
|
|
24
|
+
return subPages.map((page) => formatPagePath(join(rootPath, root), page.path));
|
|
25
|
+
}).flat()
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
function toKebabCase(str) {
|
|
29
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
function toPascalCase(str) {
|
|
32
|
+
return str.replace(/(^\w|-+\w)/g, (match) => match.toUpperCase().replace(/-/g, ""));
|
|
33
|
+
}
|
|
34
|
+
function findNode(sfc, rawTagName) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const templateSource = (_a = sfc.template) == null ? void 0 : _a.content;
|
|
37
|
+
if (!templateSource)
|
|
38
|
+
return;
|
|
39
|
+
let tagName = "";
|
|
40
|
+
if (templateSource.includes(`<${toKebabCase(rawTagName)}`)) {
|
|
41
|
+
tagName = toKebabCase(rawTagName);
|
|
42
|
+
} else if (templateSource.includes(`<${toPascalCase(rawTagName)}`)) {
|
|
43
|
+
tagName = toPascalCase(rawTagName);
|
|
44
|
+
}
|
|
45
|
+
if (!tagName)
|
|
46
|
+
return;
|
|
47
|
+
const nodeAst = (_b = sfc.template) == null ? void 0 : _b.ast;
|
|
48
|
+
if (!nodeAst)
|
|
49
|
+
return;
|
|
50
|
+
const traverse = (nodes) => {
|
|
51
|
+
var _a2;
|
|
52
|
+
for (const node of nodes) {
|
|
53
|
+
if (node.type === 1) {
|
|
54
|
+
if (node.tag === tagName)
|
|
55
|
+
return node;
|
|
56
|
+
if ((_a2 = node.children) == null ? void 0 : _a2.length) {
|
|
57
|
+
const found = traverse(node.children);
|
|
58
|
+
if (found)
|
|
59
|
+
return found;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return void 0;
|
|
64
|
+
};
|
|
65
|
+
return traverse(nodeAst.children);
|
|
66
|
+
}
|
|
67
|
+
function normalizePlatformPath(id) {
|
|
68
|
+
const platform = process.env.UNI_PLATFORM;
|
|
69
|
+
if (!platform)
|
|
70
|
+
return id;
|
|
71
|
+
const regex = new RegExp(`\\.${platform}\\.vue$`);
|
|
72
|
+
if (regex.test(id)) {
|
|
73
|
+
return id.replace(`.${platform}.`, ".");
|
|
74
|
+
}
|
|
75
|
+
return id;
|
|
76
|
+
}
|
|
77
|
+
function debounce(fn, delay) {
|
|
78
|
+
let timer = null;
|
|
79
|
+
return (...args) => {
|
|
80
|
+
if (timer)
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
debounce,
|
|
87
|
+
findNode,
|
|
88
|
+
formatPagePath,
|
|
89
|
+
loadPagesJson,
|
|
90
|
+
normalizePlatformPath,
|
|
91
|
+
parseSFC,
|
|
92
|
+
stripJsonComments,
|
|
93
|
+
toKebabCase,
|
|
94
|
+
toPascalCase
|
|
95
|
+
};
|