uview-plus 3.7.36 → 3.8.18
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/README.md +0 -1
- package/changelog.md +1993 -1820
- package/components/u-action-sheet/u-action-sheet.vue +54 -16
- package/components/u-agreement/u-agreement.vue +2 -1
- package/components/u-alert/u-alert.vue +8 -10
- package/components/u-button/u-button.vue +35 -5
- package/components/u-calendar/calendar.js +1 -0
- package/components/u-calendar/header.vue +98 -9
- package/components/u-calendar/month.vue +10 -7
- package/components/u-calendar/props.js +5 -0
- package/components/u-calendar/u-calendar.vue +109 -2
- package/components/u-car-keyboard/u-car-keyboard.vue +7 -7
- package/components/u-card/u-card.vue +6 -6
- package/components/u-cascader/u-cascader.vue +32 -12
- package/components/u-cate-tab/u-cate-tab.vue +49 -48
- package/components/u-cell/u-cell.vue +24 -4
- package/components/u-cell-group/u-cell-group.vue +10 -3
- package/components/u-checkbox/u-checkbox.vue +6 -6
- package/components/u-choose/u-choose.vue +9 -4
- package/components/u-city-locate/u-city-locate.vue +28 -22
- package/components/u-color-picker/u-color-picker.vue +15 -15
- package/components/u-datetime-picker/u-datetime-picker.vue +79 -10
- package/components/u-dragsort/u-dragsort.vue +3 -0
- package/components/u-dropdown/u-dropdown.vue +15 -2
- package/components/u-dropdown-item/u-dropdown-item.vue +3 -3
- package/components/u-form-item/u-form-item.vue +6 -1
- package/components/u-gap/u-gap.vue +5 -1
- package/components/u-goods-sku/u-goods-sku.vue +16 -15
- package/components/u-index-anchor/u-index-anchor.vue +13 -2
- package/components/u-index-list/u-index-list.vue +18 -5
- package/components/u-input/input.js +3 -3
- package/components/u-input/u-input.vue +27 -5
- package/components/u-keyboard/u-keyboard.vue +11 -6
- package/components/u-loading-page/loadingPage.js +1 -1
- package/components/u-loading-page/u-loading-page.vue +18 -12
- package/components/u-navbar/navbar.js +2 -3
- package/components/u-navbar/theme-vars.scss +21 -0
- package/components/u-navbar/u-navbar.vue +30 -6
- package/components/u-notice-bar/theme-vars.scss +25 -0
- package/components/u-notice-bar/u-notice-bar.vue +24 -5
- package/components/u-number-box/numberBox.js +4 -4
- package/components/u-number-box/u-number-box.vue +27 -13
- package/components/u-number-keyboard/u-number-keyboard.vue +6 -6
- package/components/u-picker/picker.js +43 -43
- package/components/u-picker/u-picker.vue +14 -2
- package/components/u-popup/popup.js +1 -1
- package/components/u-popup/u-popup.vue +14 -6
- package/components/u-pull-refresh/u-pull-refresh.vue +6 -6
- package/components/u-radio/u-radio.vue +6 -6
- package/components/u-rate/rate.js +2 -2
- package/components/u-rate/u-rate.vue +98 -21
- package/components/u-search/search.js +3 -3
- package/components/u-search/u-search.vue +29 -6
- package/components/u-select/u-select.vue +141 -73
- package/components/u-signature/u-signature.vue +35 -16
- package/components/u-skeleton/u-skeleton.vue +7 -2
- package/components/u-slider/u-slider.vue +30 -31
- package/components/u-steps-item/u-steps-item.vue +20 -17
- package/components/u-subsection/theme-vars.scss +41 -0
- package/components/u-subsection/u-subsection.vue +69 -16
- package/components/u-swipe-action-item/u-swipe-action-item.vue +11 -5
- package/components/u-switch/theme-vars.scss +41 -0
- package/components/u-switch/u-switch.vue +44 -15
- package/components/u-tabbar/u-tabbar.vue +5 -5
- package/components/u-tabbar-item/u-tabbar-item.vue +16 -5
- package/components/u-table/u-table.vue +18 -3
- package/components/u-table2/tableRow.vue +43 -41
- package/components/u-table2/u-table2.vue +56 -50
- package/components/u-tabs/u-tabs.vue +14 -1
- package/components/u-tag/theme-vars.scss +21 -0
- package/components/u-tag/u-tag.vue +17 -7
- package/components/u-td/u-td.vue +5 -3
- package/components/u-text/text.js +1 -1
- package/components/u-text/u-text.vue +15 -13
- package/components/u-textarea/props.js +2 -2
- package/components/u-textarea/textarea.js +1 -1
- package/components/u-textarea/u-textarea.vue +115 -61
- package/components/u-th/u-th.vue +5 -4
- package/components/u-title/u-title.vue +1 -0
- package/components/u-toast/u-toast.vue +8 -8
- package/components/u-tree/u-tree.vue +491 -51
- package/components/u-upload/u-upload.vue +34 -6
- package/index.js +178 -27
- package/index.scss +5 -1
- package/libs/config/color.js +1 -2
- package/libs/config/props.js +1 -1
- package/libs/css/theme-vars-core.scss +197 -0
- package/libs/css/theme-vars.scss +1 -0
- package/libs/function/index.js +7 -7
- package/libs/mixin/mixin.js +111 -4
- package/libs/root/index.js +175 -0
- package/libs/root/nvue-root.vue +72 -0
- package/libs/root/page.js +269 -0
- package/libs/root/root-toast-host.vue +31 -0
- package/libs/root/root.js +40 -0
- package/libs/root/runtime.js +11 -0
- package/libs/root/utils.js +115 -0
- package/libs/theme/runtime.js +391 -0
- package/libs/theme/theme.js +684 -0
- package/libs/util/gcanvas/bridge/bridge-weex.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStyleLinearGradient.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStylePattern.js +0 -0
- package/libs/util/gcanvas/context-2d/FillStyleRadialGradient.js +0 -0
- package/libs/util/gcanvas/context-2d/RenderingContext.js +0 -0
- package/libs/util/gcanvas/context-webgl/ActiveInfo.js +0 -0
- package/libs/util/gcanvas/context-webgl/Buffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/Framebuffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLenum.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLmethod.js +0 -0
- package/libs/util/gcanvas/context-webgl/GLtype.js +0 -0
- package/libs/util/gcanvas/context-webgl/Program.js +0 -0
- package/libs/util/gcanvas/context-webgl/Renderbuffer.js +0 -0
- package/libs/util/gcanvas/context-webgl/RenderingContext.js +0 -0
- package/libs/util/gcanvas/context-webgl/Shader.js +0 -0
- package/libs/util/gcanvas/context-webgl/ShaderPrecisionFormat.js +0 -0
- package/libs/util/gcanvas/context-webgl/Texture.js +0 -0
- package/libs/util/gcanvas/context-webgl/UniformLocation.js +0 -0
- package/libs/util/gcanvas/context-webgl/classUtils.js +0 -0
- package/libs/util/gcanvas/env/canvas.js +0 -0
- package/libs/util/gcanvas/env/image.js +0 -0
- package/libs/util/gcanvas/env/tool.js +0 -0
- package/libs/util/gcanvas/index.js +0 -0
- package/package.json +3 -2
- package/theme.scss +113 -32
- package/types/index.d.ts +41 -2
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { dirname, relative, resolve } from 'node:path'
|
|
2
|
+
import process from 'node:process'
|
|
3
|
+
import { existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs'
|
|
4
|
+
|
|
5
|
+
import { createFilter, normalizePath } from 'vite'
|
|
6
|
+
|
|
7
|
+
import { transformNvuePage, transformPage } from './page.js'
|
|
8
|
+
import { rebuildUpApp, registerUpApp } from './root.js'
|
|
9
|
+
import { loadPagesJson, normalizePlatformPath, toArray } from './utils.js'
|
|
10
|
+
|
|
11
|
+
export default function UniUpRoot(options = {}) {
|
|
12
|
+
const rootOptions = {
|
|
13
|
+
enabledVirtualHost: false,
|
|
14
|
+
enabledGlobalRef: false,
|
|
15
|
+
rootFileName: 'App.up',
|
|
16
|
+
autoCreateRootFile: true,
|
|
17
|
+
autoCreateViteConfig: true,
|
|
18
|
+
excludePages: [],
|
|
19
|
+
...options,
|
|
20
|
+
}
|
|
21
|
+
const rootFileName = String(rootOptions.rootFileName || 'App.up').replace(/\.vue$/i, '')
|
|
22
|
+
|
|
23
|
+
const detectProjectRoot = () => {
|
|
24
|
+
const cwd = normalizePath(process.env.INIT_CWD || process.cwd())
|
|
25
|
+
const envInputDir = process.env.UNI_INPUT_DIR ? normalizePath(process.env.UNI_INPUT_DIR) : ''
|
|
26
|
+
const cliRootPath = normalizePath(resolve(cwd, 'src'))
|
|
27
|
+
const hbuilderRootPath = cwd
|
|
28
|
+
|
|
29
|
+
const isPageRoot = (path) => existsSync(resolve(path, 'pages.json'))
|
|
30
|
+
|
|
31
|
+
if (envInputDir && isPageRoot(envInputDir)) {
|
|
32
|
+
const projectType = envInputDir.endsWith('/src') ? 'cli' : 'hbuilder'
|
|
33
|
+
return { rootPath: envInputDir, projectType }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isPageRoot(cliRootPath)) {
|
|
37
|
+
return { rootPath: cliRootPath, projectType: 'cli' }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isPageRoot(hbuilderRootPath)) {
|
|
41
|
+
return { rootPath: hbuilderRootPath, projectType: 'hbuilder' }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
rootPath: envInputDir || cliRootPath,
|
|
46
|
+
projectType: envInputDir && !envInputDir.endsWith('/src') ? 'hbuilder' : 'cli',
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const projectInfo = detectProjectRoot()
|
|
51
|
+
const rootPath = normalizePath(projectInfo.rootPath)
|
|
52
|
+
const appUpPath = normalizePath(resolve(rootPath, `${rootFileName}.vue`))
|
|
53
|
+
const nvueRootPath = normalizePath(resolve(rootPath, 'uni_modules/uview-plus/libs/root/nvue-root.vue'))
|
|
54
|
+
const themeRuntimePath = normalizePath(resolve(rootPath, 'uni_modules/uview-plus/libs/theme/runtime.js'))
|
|
55
|
+
const pagesPath = normalizePath(resolve(rootPath, 'pages.json'))
|
|
56
|
+
const projectBasePath = normalizePath(
|
|
57
|
+
projectInfo.projectType === 'cli' ? resolve(rootPath, '..') : rootPath
|
|
58
|
+
)
|
|
59
|
+
const viteConfigTsPath = normalizePath(resolve(projectBasePath, 'vite.config.ts'))
|
|
60
|
+
const viteConfigJsPath = normalizePath(resolve(projectBasePath, 'vite.config.js'))
|
|
61
|
+
const excludedPaths = toArray(rootOptions.excludePages)
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.map(path => normalizePath(resolve(rootPath, path)))
|
|
64
|
+
|
|
65
|
+
const mainFiles = [
|
|
66
|
+
normalizePath(resolve(rootPath, 'main.ts')),
|
|
67
|
+
normalizePath(resolve(rootPath, 'main.js')),
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
const getRelativeImportPath = (fromFile, toFile) => {
|
|
71
|
+
let importPath = normalizePath(relative(dirname(fromFile), toFile))
|
|
72
|
+
if (!importPath.startsWith('.')) {
|
|
73
|
+
importPath = `./${importPath}`
|
|
74
|
+
}
|
|
75
|
+
return importPath
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let pagesJson = []
|
|
79
|
+
let pagesJsonMtimeMs = 0
|
|
80
|
+
let hasPlatformPlugin = false
|
|
81
|
+
|
|
82
|
+
const ensureRootFile = () => {
|
|
83
|
+
if (!rootOptions.autoCreateRootFile) return
|
|
84
|
+
if (existsSync(appUpPath)) return
|
|
85
|
+
|
|
86
|
+
const defaultRootSfc = `<template>
|
|
87
|
+
\t<UpRootView />
|
|
88
|
+
</template>
|
|
89
|
+
`
|
|
90
|
+
|
|
91
|
+
mkdirSync(dirname(appUpPath), { recursive: true })
|
|
92
|
+
writeFileSync(appUpPath, defaultRootSfc, 'utf-8')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const ensureViteConfigFile = () => {
|
|
96
|
+
if (!rootOptions.autoCreateViteConfig) return
|
|
97
|
+
if (existsSync(viteConfigTsPath) || existsSync(viteConfigJsPath)) return
|
|
98
|
+
|
|
99
|
+
const template = `import { defineConfig } from "vite";
|
|
100
|
+
import uni from "@dcloudio/vite-plugin-uni";
|
|
101
|
+
import UniUpRoot from "./src/uni_modules/uview-plus/libs/root/index.js";
|
|
102
|
+
|
|
103
|
+
export default defineConfig({
|
|
104
|
+
plugins: [
|
|
105
|
+
UniUpRoot({
|
|
106
|
+
rootFileName: "${rootFileName}",
|
|
107
|
+
}),
|
|
108
|
+
uni(),
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
`
|
|
112
|
+
|
|
113
|
+
writeFileSync(viteConfigTsPath, template, 'utf-8')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const refreshPagesJson = () => {
|
|
117
|
+
if (!existsSync(pagesPath)) return
|
|
118
|
+
const mtimeMs = statSync(pagesPath).mtimeMs
|
|
119
|
+
if (mtimeMs === pagesJsonMtimeMs && pagesJson.length) return
|
|
120
|
+
pagesJson = loadPagesJson(pagesPath, rootPath)
|
|
121
|
+
pagesJsonMtimeMs = mtimeMs
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
name: 'vite-plugin-uni-up-root',
|
|
126
|
+
enforce: 'pre',
|
|
127
|
+
configResolved({ plugins }) {
|
|
128
|
+
hasPlatformPlugin = plugins.some(v => v.name === 'vite-plugin-uni-platform')
|
|
129
|
+
},
|
|
130
|
+
buildStart() {
|
|
131
|
+
ensureViteConfigFile()
|
|
132
|
+
ensureRootFile()
|
|
133
|
+
refreshPagesJson()
|
|
134
|
+
},
|
|
135
|
+
async transform(code, id) {
|
|
136
|
+
let ms = null
|
|
137
|
+
const isSfcBlock = id.includes('?')
|
|
138
|
+
const cleanId = normalizePath(id.split('?')[0])
|
|
139
|
+
|
|
140
|
+
const filterMain = createFilter(mainFiles)
|
|
141
|
+
if (filterMain(cleanId)) {
|
|
142
|
+
ms = await registerUpApp(code, rootFileName)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const filterUpRoot = createFilter(appUpPath)
|
|
146
|
+
if (filterUpRoot(cleanId)) {
|
|
147
|
+
ms = await rebuildUpApp(code, rootOptions.enabledVirtualHost)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
refreshPagesJson()
|
|
151
|
+
const pageId = hasPlatformPlugin ? normalizePlatformPath(cleanId) : cleanId
|
|
152
|
+
const filterPage = createFilter(pagesJson, excludedPaths)
|
|
153
|
+
if (!isSfcBlock && filterPage(pageId)) {
|
|
154
|
+
if (cleanId.endsWith('.nvue')) {
|
|
155
|
+
ms = await transformNvuePage(
|
|
156
|
+
code,
|
|
157
|
+
getRelativeImportPath(cleanId, nvueRootPath),
|
|
158
|
+
getRelativeImportPath(cleanId, themeRuntimePath),
|
|
159
|
+
rootOptions.enabledGlobalRef
|
|
160
|
+
)
|
|
161
|
+
} else {
|
|
162
|
+
ms = await transformPage(code, rootOptions.enabledGlobalRef)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (ms) {
|
|
167
|
+
return {
|
|
168
|
+
code: ms.toString(),
|
|
169
|
+
map: ms.generateMap({ hires: true }),
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null
|
|
173
|
+
},
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="up-nvue-root" :style="rootStyle">
|
|
3
|
+
<slot />
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import { applyNativeThemeUI, getThemePageStyle, getThemeVarsForStyle, syncThemeRuntimeFromStorage } from '../theme/runtime.js'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: 'UpNvueRoot',
|
|
12
|
+
data() {
|
|
13
|
+
return {
|
|
14
|
+
rootStyle: {
|
|
15
|
+
...getThemeVarsForStyle(),
|
|
16
|
+
...getThemePageStyle()
|
|
17
|
+
},
|
|
18
|
+
minPageHeight: '0px'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
created() {
|
|
22
|
+
this.syncPageHeight()
|
|
23
|
+
this.refreshRootStyle()
|
|
24
|
+
this.themeChangeHandler = () => {
|
|
25
|
+
this.refreshRootStyle()
|
|
26
|
+
}
|
|
27
|
+
if (typeof uni !== 'undefined' && typeof uni.$on === 'function') {
|
|
28
|
+
uni.$on('uThemeChange', this.themeChangeHandler)
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
mounted() {
|
|
32
|
+
this.refreshRootStyle()
|
|
33
|
+
},
|
|
34
|
+
beforeUnmount() {
|
|
35
|
+
if (this.themeChangeHandler && typeof uni !== 'undefined' && typeof uni.$off === 'function') {
|
|
36
|
+
uni.$off('uThemeChange', this.themeChangeHandler)
|
|
37
|
+
}
|
|
38
|
+
this.themeChangeHandler = null
|
|
39
|
+
},
|
|
40
|
+
methods: {
|
|
41
|
+
syncPageHeight() {
|
|
42
|
+
let windowHeight = 0
|
|
43
|
+
try {
|
|
44
|
+
if (typeof uni !== 'undefined' && typeof uni.getWindowInfo === 'function') {
|
|
45
|
+
windowHeight = Number((uni.getWindowInfo() || {}).windowHeight || 0)
|
|
46
|
+
} else if (typeof uni !== 'undefined' && typeof uni.getSystemInfoSync === 'function') {
|
|
47
|
+
windowHeight = Number((uni.getSystemInfoSync() || {}).windowHeight || 0)
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
windowHeight = 0
|
|
51
|
+
}
|
|
52
|
+
this.minPageHeight = `${windowHeight || 0}px`
|
|
53
|
+
},
|
|
54
|
+
refreshRootStyle() {
|
|
55
|
+
syncThemeRuntimeFromStorage()
|
|
56
|
+
this.rootStyle = {
|
|
57
|
+
...getThemeVarsForStyle(),
|
|
58
|
+
...getThemePageStyle(),
|
|
59
|
+
minHeight: this.minPageHeight,
|
|
60
|
+
width: '750rpx'
|
|
61
|
+
}
|
|
62
|
+
applyNativeThemeUI()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
.up-nvue-root {
|
|
70
|
+
width: 750rpx;
|
|
71
|
+
}
|
|
72
|
+
</style>
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { MagicString } from 'vue/compiler-sfc'
|
|
2
|
+
|
|
3
|
+
import { findNode, parseSFC } from './utils.js'
|
|
4
|
+
|
|
5
|
+
function getPageRootRefSource(sfc, enabledGlobalRef = false) {
|
|
6
|
+
const pageTempAttrs = sfc.template?.attrs
|
|
7
|
+
if (pageTempAttrs && pageTempAttrs.root) {
|
|
8
|
+
return `ref="${pageTempAttrs.root}"`
|
|
9
|
+
}
|
|
10
|
+
return enabledGlobalRef ? 'ref="uniUpRoot"' : ''
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function ensureNvueNavigationBar(pageMetaSource) {
|
|
14
|
+
const navigationBarSource = '<navigation-bar :front-color="upThemeNavFrontColor" :background-color="upThemeNavBgColor" />'
|
|
15
|
+
if (!pageMetaSource) return `<page-meta>${navigationBarSource}</page-meta>`
|
|
16
|
+
if (pageMetaSource.indexOf('navigation-bar') > -1 || pageMetaSource.indexOf('NavigationBar') > -1) {
|
|
17
|
+
return pageMetaSource
|
|
18
|
+
}
|
|
19
|
+
return pageMetaSource.replace(/<page-meta([^>]*)>/i, `<page-meta$1>${navigationBarSource}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function wrapTemplate(ms, sfc, tagName, rootRefSource = '', withNvueNavigationBar = false) {
|
|
23
|
+
const pageTempStart = sfc.template?.loc.start.offset
|
|
24
|
+
const pageTempEnd = sfc.template?.loc.end.offset
|
|
25
|
+
|
|
26
|
+
let pageMetaSource = ''
|
|
27
|
+
const pageMetaNode = findNode(sfc, 'PageMeta')
|
|
28
|
+
|
|
29
|
+
if (pageMetaNode) {
|
|
30
|
+
pageMetaSource = pageMetaNode.loc.source
|
|
31
|
+
const metaTempStart = pageMetaNode.loc.start.offset
|
|
32
|
+
const metaTempEnd = pageMetaNode.loc.end.offset
|
|
33
|
+
ms.remove(metaTempStart, metaTempEnd)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (withNvueNavigationBar) {
|
|
37
|
+
pageMetaSource = ensureNvueNavigationBar(pageMetaSource)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (pageTempStart != null && pageTempEnd != null) {
|
|
41
|
+
ms.appendLeft(pageTempStart, `\n${pageMetaSource}\n<${tagName} ${rootRefSource}>`)
|
|
42
|
+
ms.appendRight(pageTempEnd, `\n</${tagName}>\n`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function transformPage(code, enabledGlobalRef = false) {
|
|
47
|
+
const sfc = await parseSFC(code)
|
|
48
|
+
const ms = new MagicString(code)
|
|
49
|
+
|
|
50
|
+
wrapTemplate(ms, sfc, 'global-up-root', getPageRootRefSource(sfc, enabledGlobalRef))
|
|
51
|
+
|
|
52
|
+
return ms
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function ensureOptionsComponent(ms, scriptContent) {
|
|
56
|
+
if (scriptContent.includes('UpNvueRoot')) return
|
|
57
|
+
|
|
58
|
+
const componentsMatch = scriptContent.match(/components\s*:\s*\{/)
|
|
59
|
+
if (componentsMatch) {
|
|
60
|
+
ms.appendLeft(componentsMatch.index + componentsMatch[0].length, ' UpNvueRoot,')
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const exportDefaultMatch = scriptContent.match(/export\s+default\s+(?:defineComponent\s*\()?\s*\{/)
|
|
65
|
+
if (exportDefaultMatch) {
|
|
66
|
+
ms.appendLeft(
|
|
67
|
+
exportDefaultMatch.index + exportDefaultMatch[0].length,
|
|
68
|
+
'\n components: { UpNvueRoot },'
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function ensureOptionsThemeMixin(ms, scriptContent) {
|
|
74
|
+
if (scriptContent.includes('__upNvueThemeMixin')) return
|
|
75
|
+
|
|
76
|
+
const mixinsMatch = scriptContent.match(/mixins\s*:\s*\[/)
|
|
77
|
+
if (mixinsMatch) {
|
|
78
|
+
ms.appendLeft(mixinsMatch.index + mixinsMatch[0].length, ' __upNvueThemeMixin,')
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exportDefaultMatch = scriptContent.match(/export\s+default\s+(?:defineComponent\s*\()?\s*\{/)
|
|
83
|
+
if (exportDefaultMatch) {
|
|
84
|
+
ms.appendLeft(
|
|
85
|
+
exportDefaultMatch.index + exportDefaultMatch[0].length,
|
|
86
|
+
'\n mixins: [__upNvueThemeMixin],'
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getScriptSetupImports(componentImportPath, runtimeImportPath) {
|
|
92
|
+
return `import UpNvueRoot from '${componentImportPath}'
|
|
93
|
+
import { computed as __upComputed, onBeforeUnmount as __upOnBeforeUnmount, onMounted as __upOnMounted, ref as __upRef } from 'vue'
|
|
94
|
+
import { onShow as __upOnShow } from '@dcloudio/uni-app'
|
|
95
|
+
import {
|
|
96
|
+
applyNativeThemeUI as __upApplyNativeThemeUI,
|
|
97
|
+
applyNativeThemeUIDeferred as __upApplyNativeThemeUIDeferred,
|
|
98
|
+
getThemeCardStyle as __upGetThemeCardStyle,
|
|
99
|
+
getThemeIsDark as __upGetThemeIsDark,
|
|
100
|
+
getThemePageStyle as __upGetThemePageStyle,
|
|
101
|
+
getThemeVar as __upThemeVar,
|
|
102
|
+
syncThemeRuntimeFromStorage as __upSyncThemeRuntimeFromStorage
|
|
103
|
+
} from '${runtimeImportPath}'
|
|
104
|
+
|
|
105
|
+
const __upThemeVersion = __upRef(0)
|
|
106
|
+
let __upThemeChangeHandler = null
|
|
107
|
+
const __upReadThemeVersion = () => Number((typeof uni !== 'undefined' && uni.$u && uni.$u.theme && uni.$u.theme.version) || 0)
|
|
108
|
+
const __upSyncThemeVersion = (payload = {}) => {
|
|
109
|
+
const version = Number(payload.version || __upReadThemeVersion() || 0)
|
|
110
|
+
__upThemeVersion.value = version || Number(__upThemeVersion.value || 0) + 1
|
|
111
|
+
}
|
|
112
|
+
__upOnMounted(() => {
|
|
113
|
+
__upSyncThemeRuntimeFromStorage()
|
|
114
|
+
__upSyncThemeVersion()
|
|
115
|
+
__upApplyNativeThemeUI()
|
|
116
|
+
if (typeof uni !== 'undefined' && typeof uni.$on === 'function') {
|
|
117
|
+
__upThemeChangeHandler = (payload = {}) => {
|
|
118
|
+
__upSyncThemeRuntimeFromStorage()
|
|
119
|
+
__upSyncThemeVersion(payload)
|
|
120
|
+
__upApplyNativeThemeUI()
|
|
121
|
+
}
|
|
122
|
+
uni.$on('uThemeChange', __upThemeChangeHandler)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
__upOnShow(() => {
|
|
126
|
+
__upSyncThemeRuntimeFromStorage()
|
|
127
|
+
__upSyncThemeVersion()
|
|
128
|
+
__upApplyNativeThemeUIDeferred()
|
|
129
|
+
})
|
|
130
|
+
__upOnBeforeUnmount(() => {
|
|
131
|
+
if (typeof uni !== 'undefined' && typeof uni.$off === 'function' && __upThemeChangeHandler) {
|
|
132
|
+
uni.$off('uThemeChange', __upThemeChangeHandler)
|
|
133
|
+
__upThemeChangeHandler = null
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
const upThemeVar = (varName, fallbackColor) => {
|
|
137
|
+
__upThemeVersion.value
|
|
138
|
+
return __upThemeVar(varName, fallbackColor)
|
|
139
|
+
}
|
|
140
|
+
const upThemeCardStyle = __upComputed(() => {
|
|
141
|
+
__upThemeVersion.value
|
|
142
|
+
return __upGetThemeCardStyle()
|
|
143
|
+
})
|
|
144
|
+
const upThemePageStyle = __upComputed(() => {
|
|
145
|
+
__upThemeVersion.value
|
|
146
|
+
return __upGetThemePageStyle()
|
|
147
|
+
})
|
|
148
|
+
const upThemeIsDark = __upComputed(() => {
|
|
149
|
+
__upThemeVersion.value
|
|
150
|
+
return __upGetThemeIsDark()
|
|
151
|
+
})
|
|
152
|
+
const upThemeNavFrontColor = __upComputed(() => {
|
|
153
|
+
__upThemeVersion.value
|
|
154
|
+
return __upGetThemeIsDark() ? '#ffffff' : '#000000'
|
|
155
|
+
})
|
|
156
|
+
const upThemeNavBgColor = __upComputed(() => {
|
|
157
|
+
__upThemeVersion.value
|
|
158
|
+
return __upThemeVar('--up-navbar-bg-color', __upGetThemeIsDark() ? '#1c1c1e' : '#ffffff')
|
|
159
|
+
})
|
|
160
|
+
`
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function getOptionsImports(componentImportPath, runtimeImportPath) {
|
|
164
|
+
return `import UpNvueRoot from '${componentImportPath}'
|
|
165
|
+
import {
|
|
166
|
+
applyNativeThemeUI as __upApplyNativeThemeUI,
|
|
167
|
+
applyNativeThemeUIDeferred as __upApplyNativeThemeUIDeferred,
|
|
168
|
+
getThemeCardStyle as __upGetThemeCardStyle,
|
|
169
|
+
getThemeIsDark as __upGetThemeIsDark,
|
|
170
|
+
getThemePageStyle as __upGetThemePageStyle,
|
|
171
|
+
getThemeVar as __upThemeVar,
|
|
172
|
+
syncThemeRuntimeFromStorage as __upSyncThemeRuntimeFromStorage
|
|
173
|
+
} from '${runtimeImportPath}'
|
|
174
|
+
|
|
175
|
+
const __upNvueThemeMixin = {
|
|
176
|
+
data() {
|
|
177
|
+
return {
|
|
178
|
+
__upNvueThemeVersion: 0,
|
|
179
|
+
__upNvueThemeChangeHandler: null
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
created() {
|
|
183
|
+
__upSyncThemeRuntimeFromStorage()
|
|
184
|
+
this.__upSyncNvueThemeVersion()
|
|
185
|
+
__upApplyNativeThemeUI()
|
|
186
|
+
if (typeof uni !== 'undefined' && typeof uni.$on === 'function') {
|
|
187
|
+
this.__upNvueThemeChangeHandler = (payload = {}) => {
|
|
188
|
+
__upSyncThemeRuntimeFromStorage()
|
|
189
|
+
this.__upSyncNvueThemeVersion(payload)
|
|
190
|
+
__upApplyNativeThemeUI()
|
|
191
|
+
}
|
|
192
|
+
uni.$on('uThemeChange', this.__upNvueThemeChangeHandler)
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
onShow() {
|
|
196
|
+
__upSyncThemeRuntimeFromStorage()
|
|
197
|
+
this.__upSyncNvueThemeVersion()
|
|
198
|
+
__upApplyNativeThemeUIDeferred()
|
|
199
|
+
},
|
|
200
|
+
beforeUnmount() {
|
|
201
|
+
if (typeof uni !== 'undefined' && typeof uni.$off === 'function' && this.__upNvueThemeChangeHandler) {
|
|
202
|
+
uni.$off('uThemeChange', this.__upNvueThemeChangeHandler)
|
|
203
|
+
this.__upNvueThemeChangeHandler = null
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
computed: {
|
|
207
|
+
upThemeCardStyle() {
|
|
208
|
+
this.__upNvueThemeVersion
|
|
209
|
+
return __upGetThemeCardStyle()
|
|
210
|
+
},
|
|
211
|
+
upThemePageStyle() {
|
|
212
|
+
this.__upNvueThemeVersion
|
|
213
|
+
return __upGetThemePageStyle()
|
|
214
|
+
},
|
|
215
|
+
upThemeIsDark() {
|
|
216
|
+
this.__upNvueThemeVersion
|
|
217
|
+
return __upGetThemeIsDark()
|
|
218
|
+
},
|
|
219
|
+
upThemeNavFrontColor() {
|
|
220
|
+
this.__upNvueThemeVersion
|
|
221
|
+
return __upGetThemeIsDark() ? '#ffffff' : '#000000'
|
|
222
|
+
},
|
|
223
|
+
upThemeNavBgColor() {
|
|
224
|
+
this.__upNvueThemeVersion
|
|
225
|
+
return __upThemeVar('--up-navbar-bg-color', __upGetThemeIsDark() ? '#1c1c1e' : '#ffffff')
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
methods: {
|
|
229
|
+
__upReadNvueThemeVersion() {
|
|
230
|
+
return Number((typeof uni !== 'undefined' && uni.$u && uni.$u.theme && uni.$u.theme.version) || 0)
|
|
231
|
+
},
|
|
232
|
+
__upSyncNvueThemeVersion(payload = {}) {
|
|
233
|
+
const version = Number(payload.version || this.__upReadNvueThemeVersion() || 0)
|
|
234
|
+
this.__upNvueThemeVersion = version || Number(this.__upNvueThemeVersion || 0) + 1
|
|
235
|
+
},
|
|
236
|
+
upThemeVar(varName, fallbackColor) {
|
|
237
|
+
this.__upNvueThemeVersion
|
|
238
|
+
return __upThemeVar(varName, fallbackColor)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
`
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export async function transformNvuePage(
|
|
246
|
+
code,
|
|
247
|
+
componentImportPath,
|
|
248
|
+
runtimeImportPath,
|
|
249
|
+
enabledGlobalRef = false
|
|
250
|
+
) {
|
|
251
|
+
const sfc = await parseSFC(code)
|
|
252
|
+
const ms = new MagicString(code)
|
|
253
|
+
|
|
254
|
+
wrapTemplate(ms, sfc, 'UpNvueRoot', getPageRootRefSource(sfc, enabledGlobalRef), true)
|
|
255
|
+
|
|
256
|
+
if (sfc.scriptSetup) {
|
|
257
|
+
ms.appendLeft(sfc.scriptSetup.loc.start.offset, getScriptSetupImports(componentImportPath, runtimeImportPath))
|
|
258
|
+
} else if (sfc.script) {
|
|
259
|
+
ms.appendLeft(sfc.script.loc.start.offset, getOptionsImports(componentImportPath, runtimeImportPath))
|
|
260
|
+
ensureOptionsComponent(ms, sfc.script.content)
|
|
261
|
+
ensureOptionsThemeMixin(ms, sfc.script.content)
|
|
262
|
+
} else {
|
|
263
|
+
ms.append(
|
|
264
|
+
`\n<script>\n${getOptionsImports(componentImportPath, runtimeImportPath)}export default {\n components: { UpNvueRoot },\n mixins: [__upNvueThemeMixin]\n}\n</script>\n`
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return ms
|
|
269
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<up-toast ref="upGlobalToastRef" />
|
|
3
|
+
<up-notify ref="upGlobalNotifyRef" />
|
|
4
|
+
</template>
|
|
5
|
+
|
|
6
|
+
<script setup>
|
|
7
|
+
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
|
8
|
+
|
|
9
|
+
const upGlobalToastRef = ref(null)
|
|
10
|
+
const upGlobalNotifyRef = ref(null)
|
|
11
|
+
|
|
12
|
+
onMounted(() => {
|
|
13
|
+
if (typeof uni === 'undefined' || !uni.$u) return
|
|
14
|
+
if (typeof uni.$u.setRootToastRef === 'function') {
|
|
15
|
+
uni.$u.setRootToastRef(upGlobalToastRef.value)
|
|
16
|
+
}
|
|
17
|
+
if (typeof uni.$u.setRootNotifyRef === 'function') {
|
|
18
|
+
uni.$u.setRootNotifyRef(upGlobalNotifyRef.value)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
onBeforeUnmount(() => {
|
|
23
|
+
if (typeof uni === 'undefined' || !uni.$u) return
|
|
24
|
+
if (typeof uni.$u.setRootToastRef === 'function') {
|
|
25
|
+
uni.$u.setRootToastRef(null)
|
|
26
|
+
}
|
|
27
|
+
if (typeof uni.$u.setRootNotifyRef === 'function') {
|
|
28
|
+
uni.$u.setRootNotifyRef(null)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
</script>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MagicString } from 'vue/compiler-sfc'
|
|
2
|
+
|
|
3
|
+
import { parseSFC } from './utils.js'
|
|
4
|
+
|
|
5
|
+
export async function registerUpApp(code, fileName = 'App.up') {
|
|
6
|
+
const ms = new MagicString(code)
|
|
7
|
+
|
|
8
|
+
const importCode = `import GlobalUpRoot from "./${fileName}.vue";
|
|
9
|
+
import UpRootToastHost from "./uni_modules/uview-plus/libs/root/root-toast-host.vue";`
|
|
10
|
+
const vueUseComponentCode = 'app.component("global-up-root", GlobalUpRoot);\napp.component("ku-root-toast-host", UpRootToastHost);'
|
|
11
|
+
|
|
12
|
+
ms.prepend(`${importCode}\n`).replace(
|
|
13
|
+
/(createApp[\s\S]*?)(return\s\{\s*app)/,
|
|
14
|
+
`$1${vueUseComponentCode}\n$2`,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return ms
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function rebuildUpApp(code, enabledVirtualHost = false) {
|
|
21
|
+
const ms = new MagicString(code)
|
|
22
|
+
const rootTagNameRE = /<(UpRootView|up-root-view)(?:\s*\/>|><\/\1>)/
|
|
23
|
+
ms.replace(rootTagNameRE, '<slot />\n <ku-root-toast-host />')
|
|
24
|
+
|
|
25
|
+
if (enabledVirtualHost) {
|
|
26
|
+
const sfc = await parseSFC(code)
|
|
27
|
+
if (sfc.script) {
|
|
28
|
+
return ms
|
|
29
|
+
}
|
|
30
|
+
const langType = sfc.scriptSetup?.lang
|
|
31
|
+
ms.append(`<script ${langType ? `lang="${langType}"` : ''}>
|
|
32
|
+
export default {
|
|
33
|
+
options: {
|
|
34
|
+
virtualHost: true,
|
|
35
|
+
}
|
|
36
|
+
}\n</script>`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return ms
|
|
40
|
+
}
|