提交 de8faa07 编写于 作者: fxy060608's avatar fxy060608

feat: transform event

上级 330fff9e
import { elemInArray } from '../../helpers/protocol' // import { elemInArray } from '../../helpers/protocol'
export const API_CREATE_ANIMATION = 'createAnimation' export const API_CREATE_ANIMATION = 'createAnimation'
export type API_TYPE_CREATE_ANIMATION = typeof uni.createAnimation export type API_TYPE_CREATE_ANIMATION = typeof uni.createAnimation
export type API_TYPE_CREATE_ANIMATION_Timing_Function = export type API_TYPE_CREATE_ANIMATION_Timing_Function =
UniApp.CreateAnimationOptions['timingFunction'] UniApp.CreateAnimationOptions['timingFunction']
const timingFunctions: API_TYPE_CREATE_ANIMATION_Timing_Function[] = [ // const timingFunctions: API_TYPE_CREATE_ANIMATION_Timing_Function[] = [
'linear', // 'linear',
'ease', // 'ease',
'ease-in', // 'ease-in',
'ease-in-out', // 'ease-in-out',
'ease-out', // 'ease-out',
'step-start', // 'step-start',
'step-end', // 'step-end',
] // ]
export const CreateAnimationOptions: ApiOptions<API_TYPE_CREATE_ANIMATION> = { export const CreateAnimationOptions: ApiOptions<API_TYPE_CREATE_ANIMATION> = {
// 目前参数校验不支持此api校验 // 目前参数校验不支持此api校验
......
...@@ -594,7 +594,7 @@ var safeAreaInsets = { ...@@ -594,7 +594,7 @@ var safeAreaInsets = {
onChange, onChange,
offChange offChange
}; };
var D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out = safeAreaInsets; var out = safeAreaInsets;
const onEventPrevent = /* @__PURE__ */ withModifiers(() => { const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
}, ["prevent"]); }, ["prevent"]);
const onEventStop = /* @__PURE__ */ withModifiers(() => { const onEventStop = /* @__PURE__ */ withModifiers(() => {
...@@ -606,10 +606,10 @@ function getWindowOffset() { ...@@ -606,10 +606,10 @@ function getWindowOffset() {
const left = parseInt(style.getPropertyValue("--window-left")); const left = parseInt(style.getPropertyValue("--window-left"));
const right = parseInt(style.getPropertyValue("--window-right")); const right = parseInt(style.getPropertyValue("--window-right"));
return { return {
top: top ? top + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top : 0, top: top ? top + out.top : 0,
bottom: bottom ? bottom + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom : 0, bottom: bottom ? bottom + out.bottom : 0,
left: left ? left + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left : 0, left: left ? left + out.left : 0,
right: right ? right + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right : 0 right: right ? right + out.right : 0
}; };
} }
function updateCssVar(cssVars) { function updateCssVar(cssVars) {
...@@ -1291,7 +1291,7 @@ function normalizePageMeta(pageMeta) { ...@@ -1291,7 +1291,7 @@ function normalizePageMeta(pageMeta) {
let offset = rpx2px(refreshOptions.offset); let offset = rpx2px(refreshOptions.offset);
const {type} = navigationBar; const {type} = navigationBar;
if (type !== "transparent" && type !== "none") { if (type !== "transparent" && type !== "none") {
offset += NAVBAR_HEIGHT + D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top; offset += NAVBAR_HEIGHT + out.top;
} }
refreshOptions.offset = offset; refreshOptions.offset = offset;
refreshOptions.height = rpx2px(refreshOptions.height); refreshOptions.height = rpx2px(refreshOptions.height);
...@@ -5760,7 +5760,6 @@ function useMovableViewState(props2, trigger, rootRef) { ...@@ -5760,7 +5760,6 @@ function useMovableViewState(props2, trigger, rootRef) {
_SFA.cancel(); _SFA.cancel();
} }
} }
onUnmounted(FAandSFACancel);
function _setX(val) { function _setX(val) {
if (xMove.value) { if (xMove.value) {
if (val + _scaleOffset.x === _translateX) { if (val + _scaleOffset.x === _translateX) {
...@@ -6153,6 +6152,9 @@ function useMovableViewState(props2, trigger, rootRef) { ...@@ -6153,6 +6152,9 @@ function useMovableViewState(props2, trigger, rootRef) {
removeMovableViewContext(context); removeMovableViewContext(context);
}); });
}); });
onUnmounted(() => {
FAandSFACancel();
});
return { return {
setParent setParent
}; };
...@@ -14879,7 +14881,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", () ...@@ -14879,7 +14881,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const windowWidth = getWindowWidth(screenWidth); const windowWidth = getWindowWidth(screenWidth);
let windowHeight = window.innerHeight; let windowHeight = window.innerHeight;
const language = navigator.language; const language = navigator.language;
const statusBarHeight = D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top; const statusBarHeight = out.top;
let osname; let osname;
let osversion; let osversion;
let model; let model;
...@@ -14992,12 +14994,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", () ...@@ -14992,12 +14994,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const system = `${osname} ${osversion}`; const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase(); const platform = osname.toLocaleLowerCase();
const safeArea = { const safeArea = {
left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left, left: out.left,
right: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, right: windowWidth - out.right,
top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top, top: out.top,
bottom: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom, bottom: windowHeight - out.bottom,
width: windowWidth - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, width: windowWidth - out.left - out.right,
height: windowHeight - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom height: windowHeight - out.top - out.bottom
}; };
const {top: windowTop, bottom: windowBottom} = getWindowOffset(); const {top: windowTop, bottom: windowBottom} = getWindowOffset();
windowHeight -= windowTop; windowHeight -= windowTop;
...@@ -15017,10 +15019,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", () ...@@ -15017,10 +15019,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
model, model,
safeArea, safeArea,
safeAreaInsets: { safeAreaInsets: {
top: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top, top: out.top,
right: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.right, right: out.right,
bottom: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.bottom, bottom: out.bottom,
left: D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left left: out.left
} }
}; };
}); });
......
...@@ -63,7 +63,7 @@ function generatePagesJsonCode( ...@@ -63,7 +63,7 @@ function generatePagesJsonCode(
const globalName = getGlobal(ssr) const globalName = getGlobal(ssr)
const pagesJson = normalizePagesJson(jsonStr, options.platform) const pagesJson = normalizePagesJson(jsonStr, options.platform)
const definePagesCode = generatePagesDefineCode(pagesJson, config) const definePagesCode = generatePagesDefineCode(pagesJson, config)
const uniRoutesCode = generateRoutes(globalName, pagesJson) const uniRoutesCode = generateRoutes(globalName, pagesJson, config)
const uniConfigCode = generateConfig(globalName, pagesJson, options) const uniConfigCode = generateConfig(globalName, pagesJson, options)
const manifestJsonPath = slash( const manifestJsonPath = slash(
path.resolve(options.inputDir, 'manifest.json.js') path.resolve(options.inputDir, 'manifest.json.js')
...@@ -173,9 +173,9 @@ function generatePagesDefineCode( ...@@ -173,9 +173,9 @@ function generatePagesDefineCode(
if (!define.__UNI_FEATURE_PAGES__) { if (!define.__UNI_FEATURE_PAGES__) {
// single page // single page
const pagePath = pagesJson.pages[0].path const pagePath = pagesJson.pages[0].path
return `import {default as ${normalizePageIdentifier( return `import ${normalizePageIdentifier(
pagePath pagePath
)}} from './${pagePath}.vue?mpType=page'` )} from './${pagePath}.vue?mpType=page'`
} }
const { pages } = pagesJson const { pages } = pagesJson
return ( return (
...@@ -222,28 +222,44 @@ function normalizePagesRoute(pagesJson: UniApp.PagesJson): PageRouteOptions[] { ...@@ -222,28 +222,44 @@ function normalizePagesRoute(pagesJson: UniApp.PagesJson): PageRouteOptions[] {
}) })
} }
function generatePageRoute({ name, path, meta }: PageRouteOptions) { function generatePageRoute(
{ name, path, meta }: PageRouteOptions,
config: ResolvedConfig
) {
const { isEntry } = meta const { isEntry } = meta
const alias = isEntry ? `\n alias:'/${path}',` : '' const alias = isEntry ? `\n alias:'/${path}',` : ''
return `{ return `{
path:'/${isEntry ? '' : path}',${alias} path:'/${isEntry ? '' : path}',${alias}
component:{render(){return renderPage(${name})}}, component:{render(){return renderPage(${name})}},
loader: ${normalizePageIdentifier(path)}Loader, loader: ${
config.define!.__UNI_FEATURE_PAGES__
? normalizePageIdentifier(path) + 'Loader'
: 'null'
},
meta: ${JSON.stringify(meta)} meta: ${JSON.stringify(meta)}
}` }`
} }
function generatePagesRoute(pagesRouteOptions: PageRouteOptions[]) { function generatePagesRoute(
return pagesRouteOptions.map((pageOptions) => generatePageRoute(pageOptions)) pagesRouteOptions: PageRouteOptions[],
config: ResolvedConfig
) {
return pagesRouteOptions.map((pageOptions) =>
generatePageRoute(pageOptions, config)
)
} }
function generateRoutes(globalName: string, pagesJson: UniApp.PagesJson) { function generateRoutes(
globalName: string,
pagesJson: UniApp.PagesJson,
config: ResolvedConfig
) {
return ` return `
function renderPage(component){ function renderPage(component){
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */})) return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */}))
} }
${globalName}.__uniRoutes=[${[ ${globalName}.__uniRoutes=[${[
...generatePagesRoute(normalizePagesRoute(pagesJson)), ...generatePagesRoute(normalizePagesRoute(pagesJson), config),
].join(',')}]` ].join(',')}]`
} }
......
...@@ -18,7 +18,8 @@ export function uniRenderjsPlugin(): Plugin { ...@@ -18,7 +18,8 @@ export function uniRenderjsPlugin(): Plugin {
const type = isWxs ? 'wxs' : 'renderjs' const type = isWxs ? 'wxs' : 'renderjs'
const { query } = parseVueRequest(id) const { query } = parseVueRequest(id)
debugRenderjs(id) debugRenderjs(id)
if (!(query as any).name) { const name: string = (query as any).name
if (!name) {
this.error( this.error(
`<script module="missing module name" lang="${type}"> `<script module="missing module name" lang="${type}">
${code} ${code}
...@@ -29,11 +30,22 @@ ${code} ...@@ -29,11 +30,22 @@ ${code}
code.replace(/module\.exports\s*=/, 'export default '), code.replace(/module\.exports\s*=/, 'export default '),
'_sfc_' + type '_sfc_' + type
)} )}
export default Comp => { ${type === 'renderjs' ? genRenderjsCode(name) : genWxsCode(name)}`
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['${(query as any).name}'] = this }})
Comp.mixins.push(_sfc_${type})
}`
}, },
} }
} }
function genRenderjsCode(name: string) {
return `export default Comp => {
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['${name}'] = this }})
Comp.mixins.push(_sfc_renderjs)
}`
}
function genWxsCode(name: string) {
return `export default Comp => {
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['${name}'] = _sfc_wxs }})
}`
}
...@@ -9,7 +9,14 @@ import { ...@@ -9,7 +9,14 @@ import {
ExportSpecifier, ExportSpecifier,
} from 'estree' } from 'estree'
import { Node, TextModes, NodeTypes, ElementNode } from '@vue/compiler-core' import {
Node,
TextModes,
NodeTypes,
ElementNode,
DirectiveNode,
SimpleExpressionNode,
} from '@vue/compiler-core'
import { parse } from '@vue/compiler-dom' import { parse } from '@vue/compiler-dom'
export const isProperty = (node: BaseNode): node is Property => export const isProperty = (node: BaseNode): node is Property =>
...@@ -70,3 +77,13 @@ export function parseVue(code: string, errors: SyntaxError[]) { ...@@ -70,3 +77,13 @@ export function parseVue(code: string, errors: SyntaxError[]) {
export function isElementNode(node: Node): node is ElementNode { export function isElementNode(node: Node): node is ElementNode {
return node.type === NodeTypes.ELEMENT return node.type === NodeTypes.ELEMENT
} }
export function isDirectiveNode(node: Node): node is DirectiveNode {
return node.type === NodeTypes.DIRECTIVE
}
export function isSimpleExpressionNode(
node: Node
): node is SimpleExpressionNode {
return node.type === NodeTypes.SIMPLE_EXPRESSION
}
...@@ -4,8 +4,9 @@ import { SFCTemplateCompileOptions } from '@vue/compiler-sfc' ...@@ -4,8 +4,9 @@ import { SFCTemplateCompileOptions } from '@vue/compiler-sfc'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared' import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import { EXTNAME_VUE_RE, parseCompatConfigOnce } from '@dcloudio/uni-cli-shared' import { EXTNAME_VUE_RE, parseCompatConfigOnce } from '@dcloudio/uni-cli-shared'
import { matchMedia } from './transforms/matchMedia' import { transformMatchMedia } from './transforms/transformMatchMedia'
import { VitePluginUniResolvedOptions } from '..' import { VitePluginUniResolvedOptions } from '..'
import { createTransformEvent } from './transforms/transformEvent'
function createUniVueTransformAssetUrls( function createUniVueTransformAssetUrls(
base: string base: string
...@@ -60,7 +61,11 @@ export function initPluginVueOptions(options: VitePluginUniResolvedOptions) { ...@@ -60,7 +61,11 @@ export function initPluginVueOptions(options: VitePluginUniResolvedOptions) {
compatConfig compatConfig
) )
compilerOptions.nodeTransforms.unshift(matchMedia) compilerOptions.nodeTransforms.unshift(createTransformEvent({}))
if (options.platform !== 'mp-weixin') {
compilerOptions.nodeTransforms.unshift(transformMatchMedia)
}
return vueOptions return vueOptions
} }
......
import { DirectiveNode, NodeTransform } from '@vue/compiler-core'
import { isElementNode, isSimpleExpressionNode } from '../../utils'
export function createTransformEvent(options: Record<string, string>) {
const transformEvent: NodeTransform = (node) => {
if (!isElementNode(node)) {
return
}
node.props.forEach((prop) => {
const { arg } = prop as DirectiveNode
if (arg && isSimpleExpressionNode(arg)) {
const eventType = options[arg.content]
if (eventType) {
// e.g tap => click
arg.content = eventType
}
}
})
}
return transformEvent
}
import { ElementNode, NodeTransform } from '@vue/compiler-core' import { ElementNode, NodeTransform } from '@vue/compiler-core'
export const matchMedia: NodeTransform = (node) => { export const transformMatchMedia: NodeTransform = (node) => {
if ( if ((node as ElementNode).tag === 'match-media') {
process.env.UNI_PLATFORM !== 'mp-weixin' &&
(node as ElementNode).tag === 'match-media'
) {
;(node as ElementNode).tag = 'uni-match-media' ;(node as ElementNode).tag = 'uni-match-media'
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册