Skip to content

Commit d028de2

Browse files
authored
Merge branch 'master' into feat-rn-split-chunk-rnExternalRequests
2 parents 5d59871 + 094c644 commit d028de2

File tree

15 files changed

+126
-163
lines changed

15 files changed

+126
-163
lines changed

docs-vitepress/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const sidebar = {
1818
{ text: "快速开始", link: "/guide/basic/start" },
1919
{ text: "介绍", link: "/guide/basic/intro" },
2020
{ text: "单文件开发", link: "/guide/basic/single-file" },
21-
{ text: "IDE 高亮配置", link: "/guide/basic/ide" },
21+
{ text: "IDE 支持", link: "/guide/basic/ide" },
2222
{ text: "模板语法", link: "/guide/basic/template" },
2323
{ text: "CSS 处理", link: "/guide/basic/css" },
2424
{ text: "数据响应", link: "/guide/basic/reactive" },
63.5 KB
Loading
80.5 KB
Loading

docs-vitepress/guide/basic/ide.md

Lines changed: 18 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,33 @@
1-
# IDE 高亮配置
1+
# IDE 支持
22

3-
- [IntelliJ](ide.md#intellij)
4-
- [vscode](ide.md#vscode)
3+
## VS Code
54

6-
## IntelliJ
7-
8-
如果使用 IntelliJ 系 IDE 开发,可将 `.mpx` 后缀文件关联到 `vue` 模板类型,按 `vue` 模板解析。
9-
10-
![关联文件类型](../../assets/images/start-tips2.png)
11-
12-
但会报一个 `warning` 提示有重复的 `script` 标签,关闭该警告即可。
13-
14-
![关闭警告](../../assets/images/start-tips1.png)
15-
16-
## vscode
17-
18-
### 语法高亮插件
19-
20-
#### 下载
21-
22-
- [下载地址](https://marketplace.visualstudio.com/items?itemName=pagnkelly.mpx)(也可直接在 vscode 扩展处搜索 mpx 即可下载)
23-
- [git 地址](https://github.com/mpx-ecology/vscode-mpx)(有任何 vscode 插件的问题和需求可在仓库中提 issue)
24-
25-
#### 功能介绍
26-
27-
- 语法高亮
28-
- emmet
29-
- 跳转定义
30-
- 自动补全
31-
- eslint
32-
- 格式化
33-
34-
[视频介绍](https://gift-static.hongyibo.com.cn/static/kfpub/3227/vscodes.mp4)
35-
36-
#### 高亮
37-
38-
&ensp;&ensp;与其他语言插件无异,提供相应代码的高亮,因为 Mpx 分为四个模块,所以每个模块都有相应的语法高亮,还包括注释快捷键,也区分了相应模块,比如`<template>`中使用的是 html 的高亮,且注释是`<!-- -->`,而`<script>`中就是`js`的高亮,注释是`//`
39-
40-
![image](https://gift-static.hongyibo.com.cn/static/kfpub/3547/codelight.jpeg)
41-
42-
#### emmet
43-
44-
&ensp;&ensp;早在使用 sublime 时就在使用 emmet 插件,以提高写 HTML 的效率。
45-
46-
&ensp;&ensp;比如键入多个`<view>`标签:`view*n`
47-
48-
&ensp;&ensp;比如一些标签的快速键入,配合`tab`或者`Enter`键快速键入
49-
50-
&ensp;&ensp;不仅仅是`<template>`模块,css,scss,less,stylus,sass 模块也有相应的快捷指令
51-
52-
![image](https://gift-static.hongyibo.com.cn/static/kfpub/6168/QQ20210728-200258.gif)
53-
![image](https://gift-static.hongyibo.com.cn/static/kfpub/6168/QQ20210728-200331.gif)
54-
55-
提示组件标签
56-
57-
我们可以像编写 html 一样,只要输入对应的单词就会出现对应的标签,比如输入的是 view ,然后按下 tab 键,即可输入 `<view></view>` 标签。
58-
59-
<img src="https://gift-static.hongyibo.com.cn/static/kfpub/3547/tishi1_v2.png" width="500" alt="图片名称" />
60-
61-
组件指令提示
62-
63-
指令的提示类似于 vue 文件一样,只要输入对应的指令前缀就会出现对应的完整指令,比如输入的是 wx ,然后按下 tab 键,就可以输入 wx:if="" 指令。
5+
推荐使用的 IDE 是 [VS Code](https://code.visualstudio.com),配合官方维护的新版本 [**Mpx (Official)**](https://marketplace.visualstudio.com/items?itemName=mpxjs.mpx-official) 插件。该插件提供了语法高亮、TypeScript 支持,以及模板内表达式与组件 props 的智能提示,提供更好的开发体验。
646

65-
<img src="https://gift-static.hongyibo.com.cn/static/kfpub/3547/tishi2_v2.png" width="500" alt="图片名称" />
7+
::: tip 注意
8+
Mpx (Official) 现在取代了我们过去提供的插件 [mpx](https://marketplace.visualstudio.com/items?itemName=pagnkelly.mpx)[mpx-template-features](https://marketplace.visualstudio.com/items?itemName=wangshun.mpx-template-features)。历史插件将不再维护逐步废弃,请大家及时切换到新版插件。更多历史背景及功能差异请参考[说明](https://github.com/mpx-ecology/language-tools?tab=readme-ov-file#why-new-extension)
9+
:::
6610

67-
组件属性提示
11+
Mpx (Official) 插件一大亮点功能是为 `<template>` 模板中的变量支持 TS 智能提示,包括类型提示、类型检查、自动补全、定义跳转等等功能。如下图所示:
6812

69-
微信小程序的每个组件都有一些属性选项,在编写组件的时候输入前缀就会出现完整的属性,并且包含了属性的说明和属性的类型。
13+
![模板类型提示演示1](../../assets/images/ide-mpx-official-demo-1.png)
7014

71-
<img src="https://gift-static.hongyibo.com.cn/static/kfpub/3547/tishi3_v2.png" width="500" alt="图片名称" />
15+
![模板类型检查演示2](../../assets/images/ide-mpx-official-demo-2.png)
7216

73-
组件事件提示
17+
有关更多插件详细功能介绍和使用说明,请参阅我们的[插件文档](https://github.com/mpx-ecology/language-tools/wiki)
7418

75-
给组件绑定事件,也是只需要输入事件的前缀,就会出现完整的事件列表,然后按下 tab 键,即可输入 bindtap="" 类似的事件。
19+
## Open VSX 插件生态 IDE
7620

77-
<img src="https://gift-static.hongyibo.com.cn/static/kfpub/3547/tishi4_v2.png" width="500" alt="图片名称" />
21+
[Open VSX](https://open-vsx.org/) 是 Visual Studio Marketplace(VS Code 官方插件市场)的开源替代方案,可以为兼容 VS Code 的 IDE 提供插件市场支持。[Mpx (Official)](https://open-vsx.org/extension/mpxjs/mpx-official) 插件支持在 Open VSX 同步发版。
7822

79-
#### 跳转定义
23+
目前主流的 AI IDE 比如 [Cursor](https://cursor.com/cn)[Trae](https://www.trae.cn)[windsurf](https://windsurf.com/) 等等,基于都是 fork VS Code 开发,内部插件市场一般由 Open VSX 提供支持。如果您使用此类 IDE 或者其他支持 Open VSX 插件源的 IDE,可直接搜索安装 Mpx (Official)。
8024

81-
&ensp;&ensp;command + 鼠标左键 查看定义位置,也可以在当前文件查看内容,决定是否跳转
82-
83-
![image](https://gift-static.hongyibo.com.cn/static/kfpub/6168/QQ20210728-200848.gif)
84-
85-
#### 自动补全
86-
87-
&ensp;&ensp;毕竟 Mpx 是个小程序的框架,对于微信和支付宝的 api 快速补全 snippets 没有怎么能行,可在`<script>`中通过键入部分文字插入相应的代码块
88-
89-
![image](https://gift-static.hongyibo.com.cn/static/kfpub/6168/QQ20210728-201858.gif)
90-
91-
#### eslint
92-
93-
&ensp;&ensp;eslint 这块要分两部分来讲,一部分是插件实现了按照模块区分的简单的 eslint,另一部分是要配合 eslint 的 vscode 插件,配置.eslintrc 高阶的 eslint 检测。
94-
95-
部分一可通过配置开关
96-
97-
`<template>`是通过我们自己实现的 eslint 插件`eslint-plugin-mpx`,通过调 eslint 提供的引擎 api,返回 eslint 校验的结果,我们再进行展示。
98-
99-
`<script>`中是通过调用 typescript 提供的检测 js 代码的 api 来进行检测,返回
100-
的校验结果也是不太符合语法的,基础的检测,不会过于苛刻
101-
102-
`<style>`中会根据 lang 的设定进行相应的检测,此检测是 vscode 官方提供的库
103-
`vscode-css-languageservice`
104-
105-
`<json>`模块同 tempalte,用到了一个 eslint 插件`eslint-plugin-jsonc`来检测 json 的部分
106-
107-
![image](https://gift-static.hongyibo.com.cn/static/kfpub/3547/vscodeseting.png)
108-
109-
部分二可参照此[链接](https://github.com/mpx-ecology/vscode-mpx/issues/35)配置
110-
111-
#### 代码格式化
112-
113-
支持代码格式化 JavaScript (ts)· JSON · CSS (less/scss/stylus) · WXML,通过鼠标右键选择代码格式化文档。
114-
115-
<img src="https://gift-static.hongyibo.com.cn/static/kfpub/3547/format_v2.png" width="500" alt="图片名称" />
116-
117-
默认每个区块都是调用 Prettier 这个库来完成格式化的,当然也可以在设置中切换成使用其他库。
118-
119-
<img src="https://gift-static.hongyibo.com.cn/static/kfpub/3547/format2_v3.png" width="500" alt="图片名称" />
120-
121-
如果切换成 none 将会禁用格式化。
122-
123-
Prettier 支持从项目根目录读取 .prettierrc 配置文件。配置选项可以参考 [官方](https://prettier.io/docs/en/configuration.html) 文档。.prettierrc 文件可以使用 JSON 语法编写,比如下面这样:
124-
125-
```
126-
{
127-
"tabWidth": 4,
128-
"semi": false,
129-
"singleQuote": true
130-
}
131-
```
132-
133-
注意:由于 Prettier 这个库不支持格式化 stylus 语法,所以 stylus 的格式化使用另外一个 stylus-supremacy 库,配置 stylus 格式化规则只能在编辑器的 settings 中配置。
134-
135-
```
136-
"mpx.format.defaultFormatterOptions": {
137-
"stylus-supremacy": {
138-
"insertColons": false, // 不使用括号
139-
"insertSemicolons": false, // 不使用冒号
140-
"insertBraces": false, // 不使用分号
141-
"insertNewLineAroundImports": true, // import之后插入空行
142-
"insertNewLineAroundBlocks": false // 每个块不添加空行
143-
}
144-
}
145-
```
146-
147-
总结一下,配置格式化有两种方式,一种是使用 .prettierrc 文件的形式配置,另一种是在编辑器的 settings 中自行配置,通过 mpx.format.defaultFormatterOptions 选项。
148-
149-
### 模版增强插件
25+
## IntelliJ
15026

151-
#### 下载
27+
如果使用 IntelliJ 系 IDE 开发,可将 `.mpx` 后缀文件关联到 `vue` 模板类型,按 `vue` 模板解析。
15228

153-
- [下载地址](https://marketplace.visualstudio.com/items?itemName=wangshun.mpx-template-features)(也可直接在 vscode 扩展处搜索 Mpx Template Features 即可下载)
29+
![关联文件类型](../../assets/images/start-tips2.png)
15430

155-
#### 功能介绍
31+
但会报一个 `warning` 提示有重复的 `script` 标签,关闭该警告即可。
15632

157-
- 支持模板中的变量定义跳转
158-
- class 类名 hover 展示对应的 style 样式
159-
- stylus 一键转换为原子类 Unocss,支持自定义转换规则
160-
- 模板中变量自动补全
161-
- 支持拆分 SFC 文件为多个编辑视图
33+
![关闭警告](../../assets/images/start-tips1.png)

docs-vitepress/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ sixSection:
9797
details: 页面桥接
9898
icon: https://dpubstatic.udache.com/static/dpubimg/trdVxyR_5_/kaifa_icon_6.png
9999
actionLink: /api/extend.html#webview-bridge
100-
- title: '@mpxjs/vscode-plugin ide'
101-
details: 插件
100+
- title: 'Mpx language tools'
101+
details: IDE 插件等语言工具
102102
icon: https://dpubstatic.udache.com/static/dpubimg/PczNH3wywM/kaifa_icon_7.png
103-
actionLink: https://marketplace.visualstudio.com/items?itemName=pagnkelly.mpx
103+
actionLink: https://github.com/mpx-ecology/language-tools
104104
- title: '@mpxjs/es-check'
105105
details: 高级语法检查
106106
icon: https://dpubstatic.udache.com/static/dpubimg/qXb0ZEY4xN/kaifa_icon_8.png

packages/core/@types/index.d.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// <reference path="./global.d.ts" />
88
/// <reference path="./node.d.ts" />
99

10-
import { GetComputedType } from '@mpxjs/store'
10+
import type { GetComputedType } from '@mpxjs/store'
1111

1212
export * from '@mpxjs/store'
1313

@@ -255,11 +255,22 @@ interface AnyConstructor {
255255
prototype: any
256256
}
257257

258-
interface WebviewConfig {
258+
export interface WebviewConfig {
259259
hostWhitelists?: Array<string>
260260
apiImplementations?: object
261261
}
262262

263+
export interface RnConfig {
264+
onStateChange?: (state: any) => void
265+
parseAppProps?: (props: any) => ({ initialRouteName?: string, initialParams?: any } | undefined | null | void)
266+
/**
267+
* 外层可能会异常设置此配置,因此加载监听函数内部
268+
*/
269+
disableAppStateListener?: boolean
270+
/** 进入页面是否控制回退按钮的展示以及监听回退按钮的点击 */
271+
onStackTopBack?: () => void
272+
}
273+
263274
interface MpxConfig {
264275
useStrictDiff: boolean
265276
ignoreWarning: boolean | string | RegExp | ((msg: string, location: string, e: Error) => boolean)
@@ -272,8 +283,14 @@ interface MpxConfig {
272283
forceFlushSync: boolean,
273284
webRouteConfig: object,
274285
webConfig: object,
286+
/*
287+
* 支持两个属性
288+
* hostWhitelists Array 类型 支持h5域名白名单安全校验
289+
* apiImplementations webview JSSDK接口 例如getlocation
290+
*/
275291
webviewConfig: WebviewConfig,
276-
rnConfig: object,
292+
/** react-native 相关配置,用于挂载事件等,如 onShareAppMessage */
293+
rnConfig?: RnConfig,
277294
}
278295

279296
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
@@ -664,9 +681,15 @@ export const SERVERPREFETCH: string
664681
export const REACTHOOKSEXEC: string
665682

666683
declare global {
684+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
685+
// @ts-expect-error
667686
const defineProps: (<T extends Properties = {}>(props: T) => Readonly<GetPropsType<T>>) & (<T>() => Readonly<T>)
668687
const defineOptions: <D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], S extends AnyObject = {}, O extends AnyObject = {}> (opt: ThisTypedComponentOpt<D, P, C, M, Mi, S, O>) => void
688+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
689+
// @ts-expect-error
669690
const defineExpose: <E extends AnyObject = AnyObject>(exposed?: E) => void
670691
const useContext: () => Context
692+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
693+
// @ts-expect-error
671694
const withDefaults: <Props, Defaults extends InferDefaults<Props>>(props: Props, defaults: Defaults) => PropsWithDefaults<Props, Defaults>
672695
}

packages/core/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ function use (plugin, options = {}) {
115115

116116
APIs.use = use
117117

118+
/**
119+
* @returns {import('@mpxjs/core').Mpx}
120+
*/
118121
function factory () {
119122
// 作为原型挂载属性的中间层
120123
function Mpx () {
@@ -125,6 +128,9 @@ function factory () {
125128
return Mpx
126129
}
127130

131+
/**
132+
* @type {import('@mpxjs/core').Mpx}
133+
*/
128134
const Mpx = factory()
129135

130136
Mpx.config = {

packages/core/src/platform/builtInMixins/styleHelperMixin.ios.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { isObject, isArray, dash2hump, cached, isEmptyObject } from '@mpxjs/util
22
import { Dimensions, StyleSheet } from 'react-native'
33

44
let { width, height } = Dimensions.get('screen')
5+
// TODO 临时适配折叠屏场景适配
6+
const isLargeFoldableLike = (__mpx_mode__ === 'android') && (height / width < 1.5) && (width > 600)
7+
if (isLargeFoldableLike) width = width / 2
58

69
Dimensions.addEventListener('change', ({ screen }) => {
710
width = screen.width

packages/core/src/platform/env/nav.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,23 @@ export function innerNav ({ pageConfig, navigation }) {
9595
const safeAreaTop = useSafeAreaInsets()?.top || 0
9696
// 假设是栈导航,获取栈的长度
9797
const stackLength = navigation.getState()?.routes?.length
98-
// 用于外部注册打开RN容器之前的栈长度
99-
const beforeStackLength = Mpx.config?.rnConfig?.beforeStackLength || 0
98+
const onStackTopBack = Mpx.config?.rnConfig?.onStackTopBack
99+
const isHandleStackTopBack = typeof onStackTopBack === 'function'
100100

101101
// 回退按钮与图标
102-
const backElement = stackLength + beforeStackLength > 1
102+
const backElement = stackLength > 1 || isHandleStackTopBack
103103
? createElement(TouchableOpacity, {
104104
style: [styles.backButton],
105-
onPress: () => { navigation.goBack() }
105+
onPress: () => {
106+
if (stackLength <= 1) {
107+
if (isHandleStackTopBack) {
108+
onStackTopBack()
109+
}
110+
return
111+
}
112+
113+
navigation.goBack()
114+
}
106115
}, createElement(Image, {
107116
source: { uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABICAYAAACqT5alAAAA2UlEQVR4nO3bMQrCUBRE0Yla6AYEN2nnBrTL+izcitW3MRDkEUWSvPzJvfCqgMwhZbAppWhNbbIHzB1g9wATERFRVyvpkj1irlpJ5X326D7WHh1hbdFD2CLpLmmftm7kfsEe09aNHFiBrT+wAlt/YAW2/sAKbP2BFdj6Ayuwy+ufz6XPL893krZ//O6iu2n4LT8kndLWTRTo4EC7BDo40C6BDg60S6CDA+0S6OBAuwQ6uNWiD2nrJmoIfU7cNWkR2hbb1UfbY7uuWhGWiIg+a/iHuHmA3QPs3gu4JW9Gan+OJAAAAABJRU5ErkJggg==' },
108117
// 回退按钮的颜色与设置的title文案颜色一致

packages/core/src/platform/patch/getDefaultOptions.ios.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,14 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
304304

305305
if (type === 'page') {
306306
const props = propsRef.current
307-
proxy.callHook(ONLOAD, [props.route.params || {}])
307+
const loadParams = {}
308+
// 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
309+
if (isObject(props.route.params)) {
310+
for (const key in props.route.params) {
311+
loadParams[key] = encodeURIComponent(props.route.params[key])
312+
}
313+
}
314+
proxy.callHook(ONLOAD, [loadParams])
308315
}
309316

310317
Object.assign(proxy, {

0 commit comments

Comments
 (0)